diff options
author | Erik Johnston <erikj@jki.re> | 2017-04-25 17:22:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-25 17:22:02 +0100 |
commit | 22f935ab7cdeca19cc6b4b8c2c0f574710cffae4 (patch) | |
tree | 42a740b7758e6b98914ffc4212dc76fea3abd4e1 /synapse/util | |
parent | Merge pull request #2149 from enckse/develop (diff) | |
parent | fix up (diff) | |
download | synapse-22f935ab7cdeca19cc6b4b8c2c0f574710cffae4.tar.xz |
Merge pull request #2159 from matrix-org/erikj/reduce_join_cache_size
Reduce size of joined_user cache
Diffstat (limited to 'synapse/util')
-rw-r--r-- | synapse/util/stringutils.py | 14 |
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 |