diff options
author | Amber Brown <hawkowl@atleastfornow.net> | 2018-09-03 21:08:35 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-03 21:08:35 +1000 |
commit | 4fc4b881c58fd638db5f4dac0863721111b67af0 (patch) | |
tree | cc1604f5e3b4e0a263e0e11a55b62ef4006a64a1 /synapse/util/stringutils.py | |
parent | The project `matrix-synapse-auto-deploy` does not seem to be maintained anymore. (diff) | |
parent | Merge pull request #3777 from matrix-org/neilj/fix_register_user_registration (diff) | |
download | synapse-4fc4b881c58fd638db5f4dac0863721111b67af0.tar.xz |
Merge branch 'develop' into develop
Diffstat (limited to 'synapse/util/stringutils.py')
-rw-r--r-- | synapse/util/stringutils.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/synapse/util/stringutils.py b/synapse/util/stringutils.py index b98b9dc6e4..6f318c6a29 100644 --- a/synapse/util/stringutils.py +++ b/synapse/util/stringutils.py @@ -15,6 +15,8 @@ import random import string + +from six import PY3 from six.moves import range _string_with_symbols = ( @@ -33,6 +35,17 @@ def random_string_with_symbols(length): def is_ascii(s): + + if PY3: + if isinstance(s, bytes): + try: + s.decode('ascii').encode('ascii') + except UnicodeDecodeError: + return False + except UnicodeEncodeError: + return False + return True + try: s.encode("ascii") except UnicodeEncodeError: @@ -48,6 +61,9 @@ def to_ascii(s): If given None then will return None. """ + if PY3: + return s + if s is None: return None |