From 78dcc6dff88829831ead187804ac9233eafab52e Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Wed, 14 Nov 2018 21:26:39 -0600 Subject: remove several places supporting bytes for py2 --- src/pyramid/response.py | 4 +--- src/pyramid/urldispatch.py | 11 +---------- src/pyramid/util.py | 27 ++++++++++++--------------- 3 files changed, 14 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/pyramid/response.py b/src/pyramid/response.py index 38f9fa1ce..8a2ba8929 100644 --- a/src/pyramid/response.py +++ b/src/pyramid/response.py @@ -100,14 +100,12 @@ class FileIter(object): def __iter__(self): return self - def next(self): + def __next__(self): val = self.file.read(self.block_size) if not val: raise StopIteration return val - __next__ = next # py3 - def close(self): self.file.close() diff --git a/src/pyramid/urldispatch.py b/src/pyramid/urldispatch.py index 6348ae7e2..97626c5dd 100644 --- a/src/pyramid/urldispatch.py +++ b/src/pyramid/urldispatch.py @@ -188,14 +188,6 @@ def _compile_route(route): match = re.compile(pattern).match def matcher(path): - # This function really wants to consume Unicode patterns natively, - # but if someone passes us a bytestring, we allow it by converting it - # to Unicode using the ASCII decoding. We decode it using ASCII - # because we don't want to accept bytestrings with high-order - # characters in them here as we have no idea what the encoding - # represents. - if path.__class__ is not str: - path = text_(path, 'ascii') m = match(path) if m is None: return None @@ -216,7 +208,7 @@ def _compile_route(route): newdict = {} for k, v in dict.items(): if v.__class__ is bytes: - # url_quote below needs a native string, not bytes on Py3 + # url_quote below needs a native string v = v.decode('utf-8') if k == remainder: @@ -230,7 +222,6 @@ def _compile_route(route): else: if v.__class__ is not str: v = str(v) - # v may be bytes (py2) or native string (py3) v = q(v) # at this point, the value will be a native string diff --git a/src/pyramid/util.py b/src/pyramid/util.py index 6cd8225aa..0688e67d3 100644 --- a/src/pyramid/util.py +++ b/src/pyramid/util.py @@ -603,10 +603,7 @@ def takes_one_arg(callee, attr=None, argname=None): if inspect.isroutine(callee): fn = callee elif inspect.isclass(callee): - try: - fn = callee.__init__ - except AttributeError: - return False + fn = callee.__init__ ismethod = hasattr(fn, '__call__') else: try: @@ -614,15 +611,11 @@ def takes_one_arg(callee, attr=None, argname=None): except AttributeError: return False - try: - argspec = inspect.getfullargspec(fn) - except TypeError: - return False - + argspec = inspect.getfullargspec(fn) args = argspec[0] if hasattr(fn, '__func__') or ismethod: - # it's an instance method (or unbound method on py2) + # it's an instance method if not args: return False args = args[1:] @@ -676,8 +669,12 @@ def is_unbound_method(fn): def reraise(tp, value, tb=None): - if value is None: - value = tp - if value.__traceback__ is not tb: - raise value.with_traceback(tb) - raise value + try: + if value is None: + value = tp() + if value.__traceback__ is not tb: + raise value.with_traceback(tb) + raise value + finally: + value = None + tb = None -- cgit v1.2.3