summary refs log tree commit diff
path: root/synapse/util/stringutils.py
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2017-04-25 17:22:02 +0100
committerGitHub <noreply@github.com>2017-04-25 17:22:02 +0100
commit22f935ab7cdeca19cc6b4b8c2c0f574710cffae4 (patch)
tree42a740b7758e6b98914ffc4212dc76fea3abd4e1 /synapse/util/stringutils.py
parentMerge pull request #2149 from enckse/develop (diff)
parentfix up (diff)
downloadsynapse-22f935ab7cdeca19cc6b4b8c2c0f574710cffae4.tar.xz
Merge pull request #2159 from matrix-org/erikj/reduce_join_cache_size
Reduce size of joined_user cache
Diffstat (limited to '')
-rw-r--r--synapse/util/stringutils.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/synapse/util/stringutils.py b/synapse/util/stringutils.py

index a100f151d4..95a6168e16 100644 --- a/synapse/util/stringutils.py +++ b/synapse/util/stringutils.py
@@ -40,3 +40,17 @@ def is_ascii(s): return False else: return True + + +def to_ascii(s): + """Converts a string to ascii if it is ascii, otherwise leave it alone. + + If given None then will return None. + """ + if s is None: + return None + + try: + return s.encode("ascii") + except UnicodeEncodeError: + return s