Permalink
Browse files

specify exceptions and versions in backward-compat codes

  • Loading branch information...
puzzlet committed Nov 2, 2012
1 parent 3c4cf2f commit 9b3db088333f0a1023846aeb67cac72adc112dcd
View
@@ -14,7 +14,7 @@
try:
from io import BytesIO
except ImportError:
- from cStringIO import StringIO as BytesIO
+ from cStringIO import StringIO as BytesIO # Python < 2.6
from Cookie import SimpleCookie, Morsel, CookieError
from time import gmtime
from datetime import datetime, date
@@ -62,7 +62,7 @@ def get_sidebar(user):
try:
from hashlib import md5
except ImportError:
- from md5 import new as md5
+ from md5 import new as md5 # Python < 2.5
from itertools import izip
from time import time
from werkzeug.posixemulation import rename
@@ -71,7 +71,7 @@ def get_sidebar(user):
try:
import cPickle as pickle
except ImportError:
- import pickle
+ import pickle # Python >= 3
def _items(mappingorseq):
@@ -99,8 +99,8 @@ def application(environ, start_response):
try:
bytes
-except:
- bytes = str
+except NameError:
+ bytes = str # Python < 2.6
from hashlib import sha1 as _default_hash
@@ -17,8 +17,8 @@
try:
bytes
-except:
- bytes = str
+except NameError:
+ bytes = str # Python < 2.6
_local = Local()
View
@@ -19,13 +19,13 @@
try:
from collections import deque
except ImportError: # pragma: no cover
- deque = None
+ deque = None # Python < 2.4
from werkzeug.utils import escape
try:
bytes
-except:
- bytes = str
+except NameError:
+ bytes = str # Python < 2.6
missing = object()
View
@@ -15,7 +15,7 @@
try:
from io import BytesIO
except ImportError:
- from cStringIO import StringIO as BytesIO
+ from cStringIO import StringIO as BytesIO # Python < 2.6
from tempfile import TemporaryFile
from itertools import chain, repeat
from functools import update_wrapper
@@ -28,8 +28,8 @@
from werkzeug.http import parse_options_header
try:
bytes
-except:
- bytes = str
+except NameError:
+ bytes = str # Python < 2.6
#: an iterator that yields empty strings
View
@@ -23,24 +23,25 @@
try:
from email.utils import parsedate_tz
except ImportError: # pragma: no cover
- from email.Utils import parsedate_tz
+ from email.Utils import parsedate_tz # Python < 2.5
try:
from urllib.request import parse_http_list as _parse_list_header
except ImportError:
- from urllib2 import parse_http_list as _parse_list_header
+ # not automatically converted by 2to3
+ from urllib2 import parse_http_list as _parse_list_header # Python < 3
from datetime import datetime, timedelta
try:
from hashlib import md5
except ImportError: # pragma: no cover
- from md5 import new as md5
+ from md5 import new as md5 # Python < 2.5
try:
bytes
-except:
- bytes = str
+except NameError:
+ bytes = str # Python < 2.6
try:
next
-except:
- next = lambda _: _.next()
+except NameError:
+ next = lambda _: _.next() # Python < 2.6
#: HTTP_STATUS_CODES is "exported" from this module.
View
@@ -54,8 +54,8 @@
try:
bytes
-except:
- bytes = str
+except NameError:
+ bytes = str # Python < 2.6
class WSGIRequestHandler(BaseHTTPRequestHandler, object):
View
@@ -18,6 +18,8 @@
if sys.version_info > (3, ):
from io import BytesIO
else:
+ # Python < 2.6
+ # also needed in order to pass test_environ_builder_stream_switch
from cStringIO import StringIO as BytesIO
from cookielib import CookieJar
from urllib2 import Request as U2Request
@@ -32,8 +34,8 @@
try:
bytes
-except:
- bytes = str
+except NameError:
+ bytes = str # Python < 2.6
def stream_encode_multipart(values, use_tempfile=True, threshold=1024 * 500,
@@ -16,7 +16,7 @@
try:
from io import BytesIO
except ImportError:
- from StringIO import StringIO as BytesIO
+ from StringIO import StringIO as BytesIO # Python < 2.6
from os.path import join, dirname
from werkzeug.testsuite import WerkzeugTestCase
@@ -16,7 +16,7 @@
try:
from io import BytesIO
except ImportError:
- from cStringIO import StringIO as BytesIO
+ from cStringIO import StringIO as BytesIO # Python < 2.6
from werkzeug.testsuite import WerkzeugTestCase
@@ -13,8 +13,8 @@
import sys
try:
from io import BytesIO
-except:
- from StringIO import StringIO as BytesIO
+except ImportError:
+ from StringIO import StringIO as BytesIO # Python < 2.6
from datetime import datetime
from werkzeug.testsuite import WerkzeugTestCase
@@ -16,7 +16,7 @@
try:
from io import BytesIO
except ImportError:
- from cStringIO import StringIO as BytesIO
+ from cStringIO import StringIO as BytesIO # Python < 2.6
from werkzeug.testsuite import WerkzeugTestCase
View
@@ -10,15 +10,18 @@
"""
import sys
import urlparse
-try:
+if sys.version_info >= (3, ):
from io import TextIOBase
-except ImportError:
- pass
from werkzeug._internal import _b, _decode_unicode
from werkzeug.datastructures import MultiDict, iter_multi_items
from werkzeug.wsgi import make_chunk_iter
+try:
+ bytes
+except NameError:
+ bytes = str # Python < 2.6
+
#: list of characters that are always safe in URLs.
_always_safe = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
@@ -37,15 +40,12 @@
_hextochr = dict((a + b, chr(int(a + b, 16)))
for a in _hexdig for b in _hexdig)
-try:
- bytes
-except:
- bytes = str
if sys.version_info >= (3, ):
_always_safe = _always_safe.encode('ascii')
_safe_map = dict((ord(k), _safe_map[k]) for k in _safe_map)
_hextochr = dict((k, _hextochr[k].encode('latin1')) for k in _hextochr)
+
def _enforce_in_out(in_type, out_type):
def decorator(f):
def new_f(*args, **kwargs):
View
@@ -47,8 +47,8 @@
_patch_wrapper, _get_environ
try:
bytes
-except:
- bytes = str
+except NameError:
+ bytes = str # Python < 2.6
def _run_wsgi_app(*args):

0 comments on commit 9b3db08

Please sign in to comment.