mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2025-05-04 13:44:58 -04:00
Port over enough to get some sytests running on Python 3 (#3668)
This commit is contained in:
parent
cf6f9a8b53
commit
324525f40c
12 changed files with 91 additions and 40 deletions
|
@ -16,6 +16,7 @@
|
|||
import random
|
||||
import string
|
||||
|
||||
from six import PY3
|
||||
from six.moves import range
|
||||
|
||||
_string_with_symbols = (
|
||||
|
@ -34,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:
|
||||
|
@ -49,6 +61,9 @@ def to_ascii(s):
|
|||
|
||||
If given None then will return None.
|
||||
"""
|
||||
if PY3:
|
||||
return s
|
||||
|
||||
if s is None:
|
||||
return None
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue