summary refs log tree commit diff
path: root/synapse/util/stringutils.py
diff options
context:
space:
mode:
authorDan Callahan <danc@element.io>2021-05-14 10:58:52 +0100
committerGitHub <noreply@github.com>2021-05-14 10:58:52 +0100
commitbd918d874f4eb459b9c2f9af6e8e994b6b19d264 (patch)
treedcd02db35a185356070ec7340def13c02dea0dca /synapse/util/stringutils.py
parentUse Python's secrets module instead of random (#9984) (diff)
downloadsynapse-bd918d874f4eb459b9c2f9af6e8e994b6b19d264.tar.xz
Simplify exception handling in is_ascii. (#9985)
We can get away with just catching UnicodeError here.

    ⋮
    +-- ValueError
    |    +-- UnicodeError
    |         +-- UnicodeDecodeError
    |         +-- UnicodeEncodeError
    |         +-- UnicodeTranslateError
    ⋮

https://docs.python.org/3/library/exceptions.html#exception-hierarchy

Signed-off-by: Dan Callahan <danc@element.io>
Diffstat (limited to 'synapse/util/stringutils.py')
-rw-r--r--synapse/util/stringutils.py4
1 files changed, 1 insertions, 3 deletions
diff --git a/synapse/util/stringutils.py b/synapse/util/stringutils.py

index 40cd51a8ca..f029432191 100644 --- a/synapse/util/stringutils.py +++ b/synapse/util/stringutils.py
@@ -55,9 +55,7 @@ def random_string_with_symbols(length: int) -> str: def is_ascii(s: bytes) -> bool: try: s.decode("ascii").encode("ascii") - except UnicodeDecodeError: - return False - except UnicodeEncodeError: + except UnicodeError: return False return True