diff options
| author | Gael Pasgrimaud <gael@gawel.org> | 2011-08-25 23:12:53 +0200 |
|---|---|---|
| committer | Gael Pasgrimaud <gael@gawel.org> | 2011-08-25 23:12:53 +0200 |
| commit | 8a07dddbd9704631640d979e67a2ee3767122943 (patch) | |
| tree | aedfe9cdae7ab3bc4d746f8f7ca207ae981ee0c2 /webtest/compat.py | |
| parent | 87d90402e5b4bbb878eee735d1b12b39e72f574c (diff) | |
| download | webtest-8a07dddbd9704631640d979e67a2ee3767122943.tar.gz | |
py3 compat. only 4 errors remaining
Diffstat (limited to 'webtest/compat.py')
| -rw-r--r-- | webtest/compat.py | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/webtest/compat.py b/webtest/compat.py index f12e86a..873c1f1 100644 --- a/webtest/compat.py +++ b/webtest/compat.py @@ -6,12 +6,11 @@ if sys.version_info[0] > 2: string_types = (str,) text_type = str binary_type = bytes - DictType = dict - StringType = bytes - TupleType = tuple - ListType = list from io import StringIO + from io import BytesIO from urllib.parse import urlencode + from urllib.parse import splittype + from urllib.parse import splithost import urllib.parse as urlparse from http.client import HTTPConnection from http.client import CannotSendRequest @@ -19,12 +18,28 @@ if sys.version_info[0] > 2: from http.server import SimpleHTTPRequestHandler from http.cookies import SimpleCookie, CookieError from http.cookies import _quote as cookie_quote + + def to_bytes(s): + if isinstance(s, bytes): + return s + return s.encode('ISO-8859-1') + + def to_string(s): + if isinstance(s, str): + return s + return str(s, 'ISO-8859-1') + + def join_bytes(sep, l): + l = [to_bytes(e) for e in l] + return to_bytes(sep).join(l) + else: PY3 = False string_types = basestring text_type = unicode binary_type = str - from types import DictType, StringType, TupleType, ListType + from urllib import splittype + from urllib import splithost from urllib import urlencode from httplib import HTTPConnection from httplib import CannotSendRequest @@ -36,9 +51,18 @@ else: from cStringIO import StringIO except ImportError: from StringIO import StringIO + BytesIO = StringIO import urlparse + def to_bytes(s): + return str(s) + + def to_string(s): + return str(s) + def join_bytes(sep, l): + l = [e for e in l] + return sep.join(l) def print_stderr(value): if PY3: |
