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)
| 137 | |
| 138 | |
| 139 | def 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 | |
| 159 | class UserAgentComponentSizeConfig: |
no outgoing calls