Skip to content

Commit 6d0b9d1

Browse files
chore(asm): migrate appsec utils to drop python2 compatibility (#7136)
drop python 2 and ddtrace.internal.compat dependency in appsec/_utils.py follows #7135 ## 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 0dd944f commit 6d0b9d1

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

ddtrace/appsec/_utils.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
import os
2-
from typing import TYPE_CHECKING
2+
from typing import Any
3+
from typing import Dict
4+
from typing import List
5+
from typing import Union
6+
from urllib import parse
37

48
from ddtrace.appsec import _asm_request_context
59
from ddtrace.appsec._constants import API_SECURITY
610
from ddtrace.constants import APPSEC_ENV
7-
from ddtrace.internal.compat import parse
811
from ddtrace.internal.logger import get_logger
912
from ddtrace.internal.utils.http import _get_blocked_template # noqa
1013
from ddtrace.settings import _config as config
1114

1215

13-
if TYPE_CHECKING: # pragma: no cover
14-
from typing import Any
15-
16-
from ddtrace.internal.compat import text_type as unicode
17-
18-
1916
log = get_logger(__name__)
2017

2118

22-
def parse_form_params(body):
23-
# type: (unicode) -> dict[unicode, unicode|list[unicode]]
19+
def parse_form_params(body: str) -> Dict[str, Union[str, List[str]]]:
2420
"""Return a dict of form data after HTTP form parsing"""
2521
body_params = body.replace("+", " ")
26-
req_body = dict() # type: dict[unicode, unicode|list[unicode]]
22+
req_body: Dict[str, Union[str, List[str]]] = dict()
2723
for item in body_params.split("&"):
2824
key, equal, val = item.partition("=")
2925
if equal:
@@ -39,8 +35,7 @@ def parse_form_params(body):
3935
return req_body
4036

4137

42-
def parse_form_multipart(body):
43-
# type: (unicode) -> dict[unicode, Any]
38+
def parse_form_multipart(body: str) -> Dict[str, Any]:
4439
"""Return a dict of form data after HTTP form parsing"""
4540
import email
4641
import json
@@ -122,14 +117,13 @@ def access_body(bd):
122117
return req_body
123118

124119

125-
def _appsec_rc_features_is_enabled():
126-
# type: () -> bool
120+
def _appsec_rc_features_is_enabled() -> bool:
127121
if config._remote_config_enabled:
128122
return APPSEC_ENV not in os.environ
129123
return False
130124

131125

132-
class _UserInfoRetriever(object):
126+
class _UserInfoRetriever:
133127
def __init__(self, user):
134128
self.user = user
135129

0 commit comments

Comments
 (0)