Port over enough to get some sytests running on Python 3 (#3668)

This commit is contained in:
Amber Brown 2018-08-20 23:54:49 +10:00 committed by GitHub
parent cf6f9a8b53
commit 324525f40c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 91 additions and 40 deletions

View file

@ -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