Pop ``delimiter``-separated values until encoded string is less than or equal to ``max_size``.
(self, string, max_size, delimiter)
| 216 | return clean_string |
| 217 | |
| 218 | def _truncate_string(self, string, max_size, delimiter): |
| 219 | """ |
| 220 | Pop ``delimiter``-separated values until encoded string is less than or |
| 221 | equal to ``max_size``. |
| 222 | """ |
| 223 | orig = string |
| 224 | while len(string.encode('utf-8')) > max_size: |
| 225 | parts = string.split(delimiter) |
| 226 | parts.pop() |
| 227 | string = delimiter.join(parts) |
| 228 | |
| 229 | if string == '': |
| 230 | logger.debug( |
| 231 | f"User agent component `{orig}` could not be truncated to " |
| 232 | f"`{max_size}` bytes with delimiter " |
| 233 | f"`{delimiter}` without losing all contents. " |
| 234 | f"Value will be omitted from user agent string." |
| 235 | ) |
| 236 | return string |
| 237 | |
| 238 | |
| 239 | class RawStringUserAgentComponent: |