mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-11-26 07:19:13 -05:00
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>
This commit is contained in:
parent
498084228b
commit
bd918d874f
2 changed files with 2 additions and 3 deletions
1
changelog.d/9985.misc
Normal file
1
changelog.d/9985.misc
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Simplify a few helper functions.
|
||||||
|
|
@ -55,9 +55,7 @@ def random_string_with_symbols(length: int) -> str:
|
||||||
def is_ascii(s: bytes) -> bool:
|
def is_ascii(s: bytes) -> bool:
|
||||||
try:
|
try:
|
||||||
s.decode("ascii").encode("ascii")
|
s.decode("ascii").encode("ascii")
|
||||||
except UnicodeDecodeError:
|
except UnicodeError:
|
||||||
return False
|
|
||||||
except UnicodeEncodeError:
|
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue