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

Method _truncate_string

awscli/botocore/useragent.py:218–236  ·  view source on GitHub ↗

Pop ``delimiter``-separated values until encoded string is less than or equal to ``max_size``.

(self, string, max_size, delimiter)

Source from the content-addressed store, hash-verified

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
239class RawStringUserAgentComponent:

Callers 1

to_stringMethod · 0.95

Calls 1

encodeMethod · 0.45

Tested by

no test coverage detected