MCPcopy Create free account
hub / github.com/aws/aws-cli / sanitize_user_agent_string_component

Function sanitize_user_agent_string_component

awscli/botocore/useragent.py:139–156  ·  view source on GitHub ↗

Replaces all not allowed characters in the string with a dash ("-"). Allowed characters are ASCII alphanumerics and ``!$%&'*+-.^_`|~,``. If ``allow_hash`` is ``True``, "#"``" is also allowed. :type raw_str: str :param raw_str: The input string to be sanitized. :type allow_hash

(raw_str, allow_hash)

Source from the content-addressed store, hash-verified

137
138
139def sanitize_user_agent_string_component(raw_str, allow_hash):
140 """Replaces all not allowed characters in the string with a dash ("-").
141
142 Allowed characters are ASCII alphanumerics and ``!$%&'*+-.^_`|~,``. If
143 ``allow_hash`` is ``True``, "#"``" is also allowed.
144
145 :type raw_str: str
146 :param raw_str: The input string to be sanitized.
147
148 :type allow_hash: bool
149 :param allow_hash: Whether "#" is considered an allowed character.
150 """
151 return ''.join(
152 c
153 if c in _USERAGENT_ALLOWED_CHARACTERS or (allow_hash and c == '#')
154 else '-'
155 for c in raw_str
156 )
157
158
159class UserAgentComponentSizeConfig:

Callers 3

to_stringMethod · 0.85
_build_app_idMethod · 0.85

Calls

no outgoing calls

Tested by 1