Skip to content

Commit a20fd11

Browse files
chore(asm): migrate appsec handlers to drop python2 compatibility (#7137)
drop python 2 and six dependency in `appsec/_handlers.py` follows #7136 ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [ ] Title is accurate. - [ ] No unnecessary changes are introduced. - [ ] Description motivates each change. - [ ] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Testing strategy adequately addresses listed risk(s). - [ ] Change is maintainable (easy to change, telemetry, documentation). - [ ] Release note makes sense to a user of the library. - [ ] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [ ] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) - [ ] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [ ] This PR doesn't touch any of that.
1 parent 6d0b9d1 commit a20fd11

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

ddtrace/appsec/_handlers.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import functools
2+
import io
23
import json
34

4-
from six import BytesIO
55
from wrapt import wrap_function_wrapper as _w
66
from wrapt.importer import when_imported
77
import xmltodict
@@ -16,12 +16,6 @@
1616
from ddtrace.internal.logger import get_logger
1717

1818

19-
try:
20-
from json import JSONDecodeError
21-
except ImportError:
22-
# handling python 2.X import error
23-
JSONDecodeError = ValueError # type: ignore
24-
2519
log = get_logger(__name__)
2620
_BODY_METHODS = {"POST", "PUT", "DELETE", "PATCH"}
2721

@@ -43,7 +37,7 @@ def _on_request_span_modifier(
4337
if not seekable:
4438
content_length = int(environ.get("CONTENT_LENGTH", 0))
4539
body = wsgi_input.read(content_length) if content_length else wsgi_input.read()
46-
environ["wsgi.input"] = BytesIO(body)
40+
environ["wsgi.input"] = io.BytesIO(body)
4741

4842
try:
4943
if content_type == "application/json" or content_type == "text/json":
@@ -64,7 +58,7 @@ def _on_request_span_modifier(
6458
RuntimeError,
6559
TypeError,
6660
ValueError,
67-
JSONDecodeError,
61+
json.JSONDecodeError,
6862
xmltodict.expat.ExpatError,
6963
xmltodict.ParsingInterrupted,
7064
):
@@ -75,7 +69,7 @@ def _on_request_span_modifier(
7569
if seekable:
7670
wsgi_input.seek(0)
7771
else:
78-
environ["wsgi.input"] = BytesIO(body)
72+
environ["wsgi.input"] = io.BytesIO(body)
7973
return req_body
8074

8175

0 commit comments

Comments
 (0)