aboutsummaryrefslogtreecommitdiff
path: root/src/utils/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/__init__.py')
-rw-r--r--src/utils/__init__.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/utils/__init__.py b/src/utils/__init__.py
index 24b3d71d..738541d5 100644
--- a/src/utils/__init__.py
+++ b/src/utils/__init__.py
@@ -190,12 +190,15 @@ def is_ip(s: str) -> bool:
return False
return True
-def encode_truncate(s: str, encoding: str, byte_max: int) -> bytes:
+def encode_truncate(s: str, encoding: str, byte_max: int
+ ) -> typing.Tuple[bytes, str]:
encoded = b""
- for character in s:
+ truncated = ""
+ for i, character in enumerate(s):
encoded_character = character.encode(encoding)
if len(encoded + encoded_character) > byte_max:
+ truncated = s[i:]
break
else:
encoded += encoded_character
- return encoded
+ return encoded, truncated