summaryrefslogtreecommitdiff
path: root/swift/common/utils/__init__.py
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2023-05-17 23:20:30 +0000
committerGerrit Code Review <review@openstack.org>2023-05-17 23:20:30 +0000
commit4c7b2e3bb573a451ee7b2c0dec9e0a8da9d94129 (patch)
tree28274904f8ea2a27ed834b91df0755621bc66f3a /swift/common/utils/__init__.py
parent667f733cb938ddf5e5f46732463c46d030d0603d (diff)
parent0a4e41701dbb5795ff4cab7a2c68a41c90bd51e7 (diff)
downloadswift-master.tar.gz
Merge "Add cap_length helper"HEADmaster
Diffstat (limited to 'swift/common/utils/__init__.py')
-rw-r--r--swift/common/utils/__init__.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/swift/common/utils/__init__.py b/swift/common/utils/__init__.py
index 596b888cc..ef6b0180e 100644
--- a/swift/common/utils/__init__.py
+++ b/swift/common/utils/__init__.py
@@ -5717,6 +5717,15 @@ def strict_b64decode(value, allow_line_breaks=False):
raise ValueError
+def cap_length(value, max_length):
+ if value and len(value) > max_length:
+ if isinstance(value, bytes):
+ return value[:max_length] + b'...'
+ else:
+ return value[:max_length] + '...'
+ return value
+
+
MD5_BLOCK_READ_BYTES = 4096