diff options
| author | Michael Merickel <michael@merickel.org> | 2018-11-12 23:16:09 -0600 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2018-11-12 23:16:09 -0600 |
| commit | b1a257bacc1c4ac2c1401ed02c51d9c6c03685d2 (patch) | |
| tree | a3024d0d24f192d1dd8c24eab6e9ec4b39169489 | |
| parent | 6b0e4625da2c53a1e3fdb4857fc7c6ba6ce562cf (diff) | |
| download | pyramid-b1a257bacc1c4ac2c1401ed02c51d9c6c03685d2.tar.gz pyramid-b1a257bacc1c4ac2c1401ed02c51d9c6c03685d2.tar.bz2 pyramid-b1a257bacc1c4ac2c1401ed02c51d9c6c03685d2.zip | |
get rid of type aliases
| -rw-r--r-- | src/pyramid/asset.py | 4 | ||||
| -rw-r--r-- | src/pyramid/authentication.py | 12 | ||||
| -rw-r--r-- | src/pyramid/compat.py | 24 | ||||
| -rw-r--r-- | src/pyramid/config/__init__.py | 13 | ||||
| -rw-r--r-- | src/pyramid/config/tweens.py | 4 | ||||
| -rw-r--r-- | src/pyramid/config/views.py | 12 | ||||
| -rw-r--r-- | src/pyramid/encode.py | 10 | ||||
| -rw-r--r-- | src/pyramid/httpexceptions.py | 12 | ||||
| -rw-r--r-- | src/pyramid/path.py | 8 | ||||
| -rw-r--r-- | src/pyramid/renderers.py | 6 | ||||
| -rw-r--r-- | src/pyramid/scripts/proutes.py | 3 | ||||
| -rw-r--r-- | src/pyramid/settings.py | 4 | ||||
| -rw-r--r-- | src/pyramid/static.py | 7 | ||||
| -rw-r--r-- | src/pyramid/testing.py | 4 | ||||
| -rw-r--r-- | src/pyramid/traversal.py | 72 | ||||
| -rw-r--r-- | src/pyramid/url.py | 5 | ||||
| -rw-r--r-- | src/pyramid/urldispatch.py | 24 | ||||
| -rw-r--r-- | src/pyramid/util.py | 8 | ||||
| -rw-r--r-- | tests/test_authentication.py | 12 | ||||
| -rw-r--r-- | tests/test_config/test_factories.py | 2 | ||||
| -rw-r--r-- | tests/test_config/test_views.py | 13 | ||||
| -rw-r--r-- | tests/test_httpexceptions.py | 4 | ||||
| -rw-r--r-- | tests/test_traversal.py | 15 | ||||
| -rw-r--r-- | tests/test_view.py | 3 |
24 files changed, 99 insertions, 182 deletions
diff --git a/src/pyramid/asset.py b/src/pyramid/asset.py index 0d7575a85..a32babe6c 100644 --- a/src/pyramid/asset.py +++ b/src/pyramid/asset.py @@ -1,13 +1,11 @@ import os import pkg_resources -from pyramid.compat import string_types - from pyramid.path import package_path, package_name def resolve_asset_spec(spec, pname='__main__'): - if pname and not isinstance(pname, string_types): + if pname and not isinstance(pname, str): pname = pname.__name__ # as package if os.path.isabs(spec): return None, spec diff --git a/src/pyramid/authentication.py b/src/pyramid/authentication.py index 7cb6b6811..7810745b5 100644 --- a/src/pyramid/authentication.py +++ b/src/pyramid/authentication.py @@ -13,9 +13,6 @@ from zope.interface import implementer from webob.cookies import CookieProfile from pyramid.compat import ( - long, - text_type, - binary_type, url_unquote, url_quote, bytes_, @@ -857,9 +854,8 @@ class AuthTktCookieHelper(object): userid_type_encoders = { int: ('int', str), - long: ('int', str), - text_type: ('b64unicode', lambda x: b64encode(utf_8_encode(x)[0])), - binary_type: ('b64str', lambda x: b64encode(x)), + str: ('b64unicode', lambda x: b64encode(utf_8_encode(x)[0])), + bytes: ('b64str', lambda x: b64encode(x)), } def __init__( @@ -1048,7 +1044,7 @@ class AuthTktCookieHelper(object): "type provided.".format(type(userid)), RuntimeWarning, ) - encoding, encoder = self.userid_type_encoders.get(text_type) + encoding, encoder = self.userid_type_encoders.get(str) userid = str(userid) userid = encoder(userid) @@ -1056,7 +1052,7 @@ class AuthTktCookieHelper(object): new_tokens = [] for token in tokens: - if isinstance(token, text_type): + if isinstance(token, str): try: token = ascii_native_(token) except UnicodeEncodeError: diff --git a/src/pyramid/compat.py b/src/pyramid/compat.py index 77e9bea98..47e842fbb 100644 --- a/src/pyramid/compat.py +++ b/src/pyramid/compat.py @@ -13,48 +13,40 @@ except BaseException: # pragma: no cover __pypy__ = None PYPY = False -from functools import lru_cache import pickle -string_types = (str,) -integer_types = (int,) -class_types = (type,) -text_type = str -binary_type = bytes -long = int - def text_(s, encoding='latin-1', errors='strict'): - """ If ``s`` is an instance of ``binary_type``, return + """ If ``s`` is an instance of ``bytes``, return ``s.decode(encoding, errors)``, otherwise return ``s``""" - if isinstance(s, binary_type): + if isinstance(s, bytes): return s.decode(encoding, errors) return s def bytes_(s, encoding='latin-1', errors='strict'): - """ If ``s`` is an instance of ``text_type``, return + """ If ``s`` is an instance of ``str``, return ``s.encode(encoding, errors)``, otherwise return ``s``""" - if isinstance(s, text_type): + if isinstance(s, str): return s.encode(encoding, errors) return s def ascii_native_(s): """ - If ``s`` is an instance of ``text_type``, return + If ``s`` is an instance of ``str``, return ``s.encode('ascii')``, otherwise return ``str(s, 'ascii', 'strict')`` """ - if isinstance(s, text_type): + if isinstance(s, str): s = s.encode('ascii') return str(s, 'ascii', 'strict') def native_(s, encoding='latin-1', errors='strict'): - """ If ``s`` is an instance of ``text_type``, return + """ If ``s`` is an instance of ``str``, return ``s``, otherwise return ``str(s, encoding, errors)`` """ - if isinstance(s, text_type): + if isinstance(s, str): return s return str(s, encoding, errors) diff --git a/src/pyramid/config/__init__.py b/src/pyramid/config/__init__.py index 475f0d9a2..198532e0c 100644 --- a/src/pyramid/config/__init__.py +++ b/src/pyramid/config/__init__.py @@ -19,8 +19,6 @@ from pyramid.asset import resolve_asset_spec from pyramid.authorization import ACLAuthorizationPolicy -from pyramid.compat import text_, string_types - from pyramid.events import ApplicationCreated from pyramid.exceptions import ConfigurationError @@ -59,7 +57,6 @@ from pyramid.config.zca import ZCAConfiguratorMixin from pyramid.path import DottedNameResolver -empty = text_('') _marker = object() not_ = not_ # api @@ -367,7 +364,7 @@ class Configurator( self._set_settings(settings) - if isinstance(debug_logger, string_types): + if isinstance(debug_logger, str): debug_logger = logging.getLogger(debug_logger) if debug_logger is None: @@ -489,11 +486,7 @@ class Configurator( if not hasattr(_registry, 'registerSelfAdapter'): def registerSelfAdapter( - required=None, - provided=None, - name=empty, - info=empty, - event=True, + required=None, provided=None, name='', info='', event=True ): return _registry.registerAdapter( lambda x: x, @@ -759,7 +752,7 @@ class Configurator( when generating an absolute asset specification. If the provided ``relative_spec`` argument is already absolute, or if the ``relative_spec`` is not a string, it is simply returned.""" - if not isinstance(relative_spec, string_types): + if not isinstance(relative_spec, str): return relative_spec return self._make_spec(relative_spec) diff --git a/src/pyramid/config/tweens.py b/src/pyramid/config/tweens.py index 7fc786a97..7f00c5f4f 100644 --- a/src/pyramid/config/tweens.py +++ b/src/pyramid/config/tweens.py @@ -2,7 +2,7 @@ from zope.interface import implementer from pyramid.interfaces import ITweens -from pyramid.compat import string_types, is_nonstr_iter +from pyramid.compat import is_nonstr_iter from pyramid.exceptions import ConfigurationError @@ -105,7 +105,7 @@ class TweensConfiguratorMixin(object): @action_method def _add_tween(self, tween_factory, under=None, over=None, explicit=False): - if not isinstance(tween_factory, string_types): + if not isinstance(tween_factory, str): raise ConfigurationError( 'The "tween_factory" argument to add_tween must be a ' 'dotted name to a globally importable object, not %r' diff --git a/src/pyramid/config/views.py b/src/pyramid/config/views.py index 0c4a17376..718ea8bf3 100644 --- a/src/pyramid/config/views.py +++ b/src/pyramid/config/views.py @@ -32,13 +32,7 @@ from pyramid.interfaces import ( from pyramid import renderers from pyramid.asset import resolve_asset_spec -from pyramid.compat import ( - string_types, - urlparse, - url_quote, - WIN, - is_nonstr_iter, -) +from pyramid.compat import urlparse, url_quote, WIN, is_nonstr_iter from pyramid.decorator import reify @@ -889,7 +883,7 @@ class ViewsConfiguratorMixin(object): if not IInterface.providedBy(r_context): r_context = implementedBy(r_context) - if isinstance(renderer, string_types): + if isinstance(renderer, str): renderer = renderers.RendererHelper( name=renderer, package=self.package, registry=self.registry ) @@ -1582,7 +1576,7 @@ class ViewsConfiguratorMixin(object): ): view = self.maybe_dotted(view) mapper = self.maybe_dotted(mapper) - if isinstance(renderer, string_types): + if isinstance(renderer, str): renderer = renderers.RendererHelper( name=renderer, package=self.package, registry=self.registry ) diff --git a/src/pyramid/encode.py b/src/pyramid/encode.py index 2cf2247da..428bd0c08 100644 --- a/src/pyramid/encode.py +++ b/src/pyramid/encode.py @@ -1,6 +1,4 @@ from pyramid.compat import ( - text_type, - binary_type, is_nonstr_iter, url_quote as _url_quote, url_quote_plus as _quote_plus, @@ -9,9 +7,9 @@ from pyramid.compat import ( def url_quote(val, safe=''): # bw compat api cls = val.__class__ - if cls is text_type: + if cls is str: val = val.encode('utf-8') - elif cls is not binary_type: + elif cls is not bytes: val = str(val).encode('utf-8') return _url_quote(val, safe=safe) @@ -19,9 +17,9 @@ def url_quote(val, safe=''): # bw compat api # bw compat api (dnr) def quote_plus(val, safe=''): cls = val.__class__ - if cls is text_type: + if cls is str: val = val.encode('utf-8') - elif cls is not binary_type: + elif cls is not bytes: val = str(val).encode('utf-8') return _quote_plus(val, safe=safe) diff --git a/src/pyramid/httpexceptions.py b/src/pyramid/httpexceptions.py index 959a45f37..7e83f783f 100644 --- a/src/pyramid/httpexceptions.py +++ b/src/pyramid/httpexceptions.py @@ -137,7 +137,7 @@ from zope.interface import implementer from webob import html_escape as _html_escape from webob.acceptparse import create_accept_header -from pyramid.compat import class_types, text_type, binary_type, text_ +from pyramid.compat import text_ from pyramid.interfaces import IExceptionResponse from pyramid.response import Response @@ -146,13 +146,13 @@ from pyramid.response import Response def _no_escape(value): if value is None: return '' - if not isinstance(value, text_type): + if not isinstance(value, str): if hasattr(value, '__unicode__'): value = value.__unicode__() - if isinstance(value, binary_type): + if isinstance(value, bytes): value = text_(value, 'utf-8') else: - value = text_type(value) + value = str(value) return value @@ -326,7 +326,7 @@ ${body}''' args[k.lower()] = escape(v) body = body_tmpl.substitute(args) page = page_template.substitute(status=self.status, body=body) - if isinstance(page, text_type): + if isinstance(page, str): page = page.encode(self.charset if self.charset else 'UTF-8') self.app_iter = [page] self.body = page @@ -1331,7 +1331,7 @@ status_map = {} code = None for name, value in list(globals().items()): if ( - isinstance(value, class_types) + isinstance(value, type) and issubclass(value, HTTPException) and value not in {HTTPClientError, HTTPServerError} and not name.startswith('_') diff --git a/src/pyramid/path.py b/src/pyramid/path.py index c70be99db..47877ce5d 100644 --- a/src/pyramid/path.py +++ b/src/pyramid/path.py @@ -7,8 +7,6 @@ from zope.interface import implementer from pyramid.interfaces import IAssetDescriptor -from pyramid.compat import string_types - ignore_types = [imp.C_EXTENSION, imp.C_BUILTIN] init_names = [ '__init__%s' % x[0] @@ -101,7 +99,7 @@ class Resolver(object): if package in (None, CALLER_PACKAGE): self.package = package else: - if isinstance(package, string_types): + if isinstance(package, str): try: __import__(package) except ImportError: @@ -307,7 +305,7 @@ class DottedNameResolver(Resolver): v = r.resolve('xml') # v is the xml module """ - if not isinstance(dotted, string_types): + if not isinstance(dotted, str): raise ValueError('%r is not a string' % (dotted,)) package = self.package if package is CALLER_PACKAGE: @@ -328,7 +326,7 @@ class DottedNameResolver(Resolver): v = r.maybe_resolve(xml) # v is the xml module; no exception raised """ - if isinstance(dotted, string_types): + if isinstance(dotted, str): package = self.package if package is CALLER_PACKAGE: package = caller_package() diff --git a/src/pyramid/renderers.py b/src/pyramid/renderers.py index a8e3ec16f..832369fd4 100644 --- a/src/pyramid/renderers.py +++ b/src/pyramid/renderers.py @@ -8,8 +8,6 @@ from zope.interface.registry import Components from pyramid.interfaces import IJSONAdapter, IRendererFactory, IRendererInfo -from pyramid.compat import string_types, text_type - from pyramid.csrf import get_csrf_token from pyramid.decorator import reify @@ -169,7 +167,7 @@ def get_renderer(renderer_name, package=None, registry=None): def string_renderer_factory(info): def _render(value, system): - if not isinstance(value, string_types): + if not isinstance(value, str): value = str(value) request = system.get('request') if request is not None: @@ -485,7 +483,7 @@ class RendererHelper(object): response = response_factory(request) if result is not None: - if isinstance(result, text_type): + if isinstance(result, str): response.text = result elif isinstance(result, bytes): response.body = result diff --git a/src/pyramid/scripts/proutes.py b/src/pyramid/scripts/proutes.py index 2bce7d1de..78c2295d5 100644 --- a/src/pyramid/scripts/proutes.py +++ b/src/pyramid/scripts/proutes.py @@ -7,7 +7,6 @@ import re from zope.interface import Interface from pyramid.paster import bootstrap -from pyramid.compat import string_types from pyramid.interfaces import IRouteRequest from pyramid.config import not_ @@ -188,7 +187,7 @@ def get_route_data(route, registry): view_request_methods[view_module] = [] view_request_methods_order.append(view_module) - if isinstance(request_method, string_types): + if isinstance(request_method, str): request_method = (request_method,) elif isinstance(request_method, not_): request_method = ('!%s' % request_method.value,) diff --git a/src/pyramid/settings.py b/src/pyramid/settings.py index af9433840..d1eb4ff14 100644 --- a/src/pyramid/settings.py +++ b/src/pyramid/settings.py @@ -1,5 +1,3 @@ -from pyramid.compat import string_types - truthy = frozenset(('t', 'true', 'y', 'yes', 'on', '1')) falsey = frozenset(('f', 'false', 'n', 'no', 'off', '0')) @@ -17,7 +15,7 @@ def asbool(s): def aslist_cronly(value): - if isinstance(value, string_types): + if isinstance(value, str): value = filter(None, [x.strip() for x in value.splitlines()]) return list(value) diff --git a/src/pyramid/static.py b/src/pyramid/static.py index 58ad97a46..b300df9ee 100644 --- a/src/pyramid/static.py +++ b/src/pyramid/static.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from functools import lru_cache import json import os @@ -8,8 +9,6 @@ from pkg_resources import resource_exists, resource_filename, resource_isdir from pyramid.asset import abspath_from_asset_spec, resolve_asset_spec -from pyramid.compat import lru_cache, text_ - from pyramid.httpexceptions import HTTPNotFound, HTTPMovedPermanently from pyramid.path import caller_package @@ -18,8 +17,6 @@ from pyramid.response import _guess_type, FileResponse from pyramid.traversal import traversal_path_info -slash = text_('/') - class static_view(object): """ An instance of this class is a callable which can act as a @@ -160,7 +157,7 @@ def _secure_path(path_tuple): return None if any([_contains_slash(item) for item in path_tuple]): return None - encoded = slash.join(path_tuple) # will be unicode + encoded = '/'.join(path_tuple) # will be unicode return encoded diff --git a/src/pyramid/testing.py b/src/pyramid/testing.py index 5fe8f8a62..af8008e45 100644 --- a/src/pyramid/testing.py +++ b/src/pyramid/testing.py @@ -8,7 +8,7 @@ from zope.interface import implementer, alsoProvides from pyramid.interfaces import IRequest, ISession -from pyramid.compat import PYPY, class_types, text_ +from pyramid.compat import PYPY, text_ from pyramid.config import Configurator from pyramid.decorator import reify @@ -642,7 +642,7 @@ def skip_on(*platforms): # pragma: no cover skip = True def decorator(func): - if isinstance(func, class_types): + if isinstance(func, type): if skip: return None else: diff --git a/src/pyramid/traversal.py b/src/pyramid/traversal.py index f46937d73..5ff8d22ad 100644 --- a/src/pyramid/traversal.py +++ b/src/pyramid/traversal.py @@ -1,3 +1,4 @@ +from functools import lru_cache from zope.interface import implementer from zope.interface.interfaces import IInterface @@ -10,14 +11,10 @@ from pyramid.interfaces import ( from pyramid.compat import ( native_, - text_, ascii_native_, - text_type, - binary_type, is_nonstr_iter, decode_path_info, unquote_bytes_to_wsgi, - lru_cache, ) from pyramid.encode import url_quote @@ -28,7 +25,7 @@ from pyramid.threadlocal import get_current_registry PATH_SEGMENT_SAFE = "~!$&'()*+,;=:@" # from webob PATH_SAFE = PATH_SEGMENT_SAFE + "/" -empty = text_('') +empty = '' def find_root(resource): @@ -93,7 +90,7 @@ def find_resource(resource, path): :func:`pyramid.traversal.resource_path_tuple` can always be resolved by ``find_resource``. """ - if isinstance(path, text_type): + if isinstance(path, str): path = ascii_native_(path) D = traverse(resource, path) view_name = D['view_name'] @@ -445,7 +442,7 @@ def traversal_path(path): not. A :exc:`UnicodeEncodeError` will be raised if the Unicode cannot be encoded directly to ASCII. """ - if isinstance(path, text_type): + if isinstance(path, str): # must not possess characters outside ascii path = path.encode('ascii') # we unquote this path exactly like a PEP 3333 server would @@ -550,37 +547,36 @@ def split_path_info(path): _segment_cache = {} -quote_path_segment_doc = """ \ -Return a quoted representation of a 'path segment' (such as -the string ``__name__`` attribute of a resource) as a string. If the -``segment`` passed in is a unicode object, it is converted to a -UTF-8 string, then it is URL-quoted using Python's -``urllib.quote``. If the ``segment`` passed in is a string, it is -URL-quoted using Python's :mod:`urllib.quote`. If the segment -passed in is not a string or unicode object, an error will be -raised. The return value of ``quote_path_segment`` is always a -string, never Unicode. - -You may pass a string of characters that need not be encoded as -the ``safe`` argument to this function. This corresponds to the -``safe`` argument to :mod:`urllib.quote`. - -.. note:: - - The return value for each segment passed to this - function is cached in a module-scope dictionary for - speed: the cached version is returned when possible - rather than recomputing the quoted version. No cache - emptying is ever done for the lifetime of an - application, however. If you pass arbitrary - user-supplied strings to this function (as opposed to - some bounded set of values from a 'working set' known to - your application), it may become a memory leak. -""" - def quote_path_segment(segment, safe=PATH_SEGMENT_SAFE): - """ %s """ % quote_path_segment_doc + """ + Return a quoted representation of a 'path segment' (such as + the string ``__name__`` attribute of a resource) as a string. If the + ``segment`` passed in is a unicode object, it is converted to a + UTF-8 string, then it is URL-quoted using Python's + ``urllib.quote``. If the ``segment`` passed in is a string, it is + URL-quoted using Python's :mod:`urllib.quote`. If the segment + passed in is not a string or unicode object, an error will be + raised. The return value of ``quote_path_segment`` is always a + string, never Unicode. + + You may pass a string of characters that need not be encoded as + the ``safe`` argument to this function. This corresponds to the + ``safe`` argument to :mod:`urllib.quote`. + + .. note:: + + The return value for each segment passed to this + function is cached in a module-scope dictionary for + speed: the cached version is returned when possible + rather than recomputing the quoted version. No cache + emptying is ever done for the lifetime of an + application, however. If you pass arbitrary + user-supplied strings to this function (as opposed to + some bounded set of values from a 'working set' known to + your application), it may become a memory leak. + + """ # The bit of this code that deals with ``_segment_cache`` is an # optimization: we cache all the computation of URL path segments # in this module-scope dictionary with the original string (or @@ -589,7 +585,7 @@ def quote_path_segment(segment, safe=PATH_SEGMENT_SAFE): try: return _segment_cache[(segment, safe)] except KeyError: - if segment.__class__ not in (text_type, binary_type): + if segment.__class__ not in (str, bytes): segment = str(segment) result = url_quote(native_(segment, 'utf-8'), safe) # we don't need a lock to mutate _segment_cache, as the below @@ -598,7 +594,7 @@ def quote_path_segment(segment, safe=PATH_SEGMENT_SAFE): return result -slash = text_('/') +slash = '/' @implementer(ITraverser) diff --git a/src/pyramid/url.py b/src/pyramid/url.py index 00dd13bfe..730b7de23 100644 --- a/src/pyramid/url.py +++ b/src/pyramid/url.py @@ -1,10 +1,11 @@ """ Utility functions for dealing with URLs in pyramid """ +from functools import lru_cache import os from pyramid.interfaces import IResourceURL, IRoutesMapper, IStaticURLInfo -from pyramid.compat import bytes_, lru_cache, string_types +from pyramid.compat import bytes_ from pyramid.encode import url_quote, urlencode from pyramid.path import caller_package from pyramid.threadlocal import get_current_registry @@ -45,7 +46,7 @@ def parse_url_overrides(request, kw): qs = '' if query: - if isinstance(query, string_types): + if isinstance(query, str): qs = '?' + url_quote(query, QUERY_SAFE) else: qs = '?' + urlencode(query, doseq=True) diff --git a/src/pyramid/urldispatch.py b/src/pyramid/urldispatch.py index 1d3f8d91b..c1db3c969 100644 --- a/src/pyramid/urldispatch.py +++ b/src/pyramid/urldispatch.py @@ -3,15 +3,7 @@ from zope.interface import implementer from pyramid.interfaces import IRoutesMapper, IRoute -from pyramid.compat import ( - native_, - text_, - text_type, - string_types, - binary_type, - is_nonstr_iter, - decode_path_info, -) +from pyramid.compat import native_, text_, is_nonstr_iter, decode_path_info from pyramid.exceptions import URLDecodeError @@ -126,7 +118,7 @@ def _compile_route(route): # 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 route.__class__ is not text_type: + if route.__class__ is not str: try: route = text_(route, 'ascii') except UnicodeDecodeError: @@ -173,7 +165,7 @@ def _compile_route(route): name, reg = name.split(':', 1) else: reg = '[^/]+' - gen.append('%%(%s)s' % native_(name)) # native + gen.append('%%(%s)s' % name) # native name = '(?P<%s>%s)' % (name, reg) # unicode rpat.append(name) s = pat.pop() # unicode @@ -188,7 +180,7 @@ def _compile_route(route): if remainder: rpat.append('(?P<%s>.*?)' % remainder) # unicode - gen.append('%%(%s)s' % native_(remainder)) # native + gen.append('%%(%s)s' % remainder) # native pattern = ''.join(rpat) + '$' # unicode @@ -201,7 +193,7 @@ def _compile_route(route): # 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 text_type: + if path.__class__ is not str: path = text_(path, 'ascii') m = match(path) if m is None: @@ -226,7 +218,7 @@ def _compile_route(route): def generator(dict): newdict = {} for k, v in dict.items(): - if v.__class__ is binary_type: + if v.__class__ is bytes: # url_quote below needs a native string, not bytes on Py3 v = v.decode('utf-8') @@ -235,11 +227,11 @@ def _compile_route(route): if is_nonstr_iter(v): v = '/'.join([q(x) for x in v]) # native else: - if v.__class__ not in string_types: + if v.__class__ is not str: v = str(v) v = q(v) else: - if v.__class__ not in string_types: + if v.__class__ is not str: v = str(v) # v may be bytes (py2) or native string (py3) v = q(v) diff --git a/src/pyramid/util.py b/src/pyramid/util.py index 39b67471e..d3e5d1578 100644 --- a/src/pyramid/util.py +++ b/src/pyramid/util.py @@ -10,8 +10,6 @@ from pyramid.compat import ( getargspec, im_func, is_nonstr_iter, - integer_types, - string_types, bytes_, text_, native_, @@ -30,7 +28,7 @@ class DottedNameResolver(_DottedNameResolver): def is_string_or_iterable(v): - if isinstance(v, string_types): + if isinstance(v, str): return True if hasattr(v, '__iter__'): return True @@ -324,9 +322,9 @@ def object_description(object): is a boolean, an integer, a list, a tuple, a set, or ``None``, a (possibly shortened) string representation is returned. """ - if isinstance(object, string_types): + if isinstance(object, str): return text_(object) - if isinstance(object, integer_types): + if isinstance(object, int): return text_(str(object)) if isinstance(object, (bool, float, type(None))): return text_(str(object)) diff --git a/tests/test_authentication.py b/tests/test_authentication.py index fc3e60587..87b7da5a8 100644 --- a/tests/test_authentication.py +++ b/tests/test_authentication.py @@ -1272,18 +1272,6 @@ class TestAuthTktCookieHelper(unittest.TestCase): self.assertEqual(val['userid'], '1') self.assertEqual(val['user_data'], 'userid_type:int') - def test_remember_long_userid(self): - from pyramid.compat import long - - helper = self._makeOne('secret') - request = self._makeRequest() - result = helper.remember(request, long(1)) - values = self._parseHeaders(result) - self.assertEqual(len(result), 3) - val = self._cookieValue(values[0]) - self.assertEqual(val['userid'], '1') - self.assertEqual(val['user_data'], 'userid_type:int') - def test_remember_unicode_userid(self): import base64 diff --git a/tests/test_config/test_factories.py b/tests/test_config/test_factories.py index cca528275..bbc38b6cd 100644 --- a/tests/test_config/test_factories.py +++ b/tests/test_config/test_factories.py @@ -160,7 +160,7 @@ class TestFactoriesMixin(unittest.TestCase): config = self._makeOne(autocommit=True) self.assertRaises(AttributeError, config.add_request_method) - def test_add_request_method_with_text_type_name(self): + def test_add_request_method_with_text_name(self): from pyramid.exceptions import ConfigurationError config = self._makeOne(autocommit=True) diff --git a/tests/test_config/test_views.py b/tests/test_config/test_views.py index b72b9b36a..aa5b67050 100644 --- a/tests/test_config/test_views.py +++ b/tests/test_config/test_views.py @@ -2795,15 +2795,6 @@ class TestViewsConfigurationMixin(unittest.TestCase): request = self._makeRequest(config) self.assertRaises(PredicateMismatch, wrapper, context, request) - # Since Python 3 has to be all cool and fancy and different... - def _assertBody(self, response, value): - from pyramid.compat import text_type - - if isinstance(value, text_type): # pragma: no cover - self.assertEqual(response.text, value) - else: # pragma: no cover - self.assertEqual(response.body, value) - def test_add_notfound_view_with_renderer(self): from zope.interface import implementedBy from pyramid.interfaces import IRequest @@ -2820,7 +2811,7 @@ class TestViewsConfigurationMixin(unittest.TestCase): request_iface=IRequest, ) result = view(None, request) - self._assertBody(result, '{}') + self.assertEqual(result.text, '{}') def test_add_forbidden_view_with_renderer(self): from zope.interface import implementedBy @@ -2838,7 +2829,7 @@ class TestViewsConfigurationMixin(unittest.TestCase): request_iface=IRequest, ) result = view(None, request) - self._assertBody(result, '{}') + self.assertEqual(result.text, '{}') def test_set_view_mapper(self): from pyramid.interfaces import IViewMapperFactory diff --git a/tests/test_httpexceptions.py b/tests/test_httpexceptions.py index 4c13e096d..195496e2e 100644 --- a/tests/test_httpexceptions.py +++ b/tests/test_httpexceptions.py @@ -1,6 +1,6 @@ import unittest -from pyramid.compat import bytes_, string_types, text_ +from pyramid.compat import bytes_, text_ class Test_exception_response(unittest.TestCase): @@ -406,7 +406,7 @@ class TestHTTPException(unittest.TestCase): def test_allow_detail_non_str(self): exc = self._makeOne(detail={'error': 'This is a test'}) - self.assertIsInstance(exc.__str__(), string_types) + self.assertIsInstance(exc.__str__(), str) class TestRenderAllExceptionsWithoutArguments(unittest.TestCase): diff --git a/tests/test_traversal.py b/tests/test_traversal.py index b517fa646..ed5e0031e 100644 --- a/tests/test_traversal.py +++ b/tests/test_traversal.py @@ -3,7 +3,7 @@ import unittest from pyramid.testing import cleanUp -from pyramid.compat import text_, native_, text_type, url_quote +from pyramid.compat import text_, native_, url_quote class TraversalPathTests(unittest.TestCase): @@ -71,8 +71,8 @@ class TraversalPathInfoTests(unittest.TestCase): def test_segments_are_unicode(self): result = self._callFUT('/foo/bar') - self.assertEqual(type(result[0]), text_type) - self.assertEqual(type(result[1]), text_type) + self.assertEqual(type(result[0]), str) + self.assertEqual(type(result[1]), str) def test_same_value_returned_if_cached(self): result1 = self._callFUT('/foo/bar') @@ -870,15 +870,6 @@ class QuotePathSegmentTests(unittest.TestCase): result = self._callFUT(s) self.assertEqual(result, '12345') - def test_long(self): - from pyramid.compat import long - import sys - - s = long(sys.maxsize + 1) - result = self._callFUT(s) - expected = str(s) - self.assertEqual(result, expected) - def test_other(self): class Foo(object): def __str__(self): diff --git a/tests/test_view.py b/tests/test_view.py index f82480169..de40df1d5 100644 --- a/tests/test_view.py +++ b/tests/test_view.py @@ -417,12 +417,11 @@ class RenderViewToIterableTests(BaseTest, unittest.TestCase): from pyramid.request import Request from pyramid.config import Configurator from pyramid.view import render_view - from webob.compat import text_type config = Configurator(settings={}) def view(request): - request.response.text = text_type('<body></body>') + request.response.text = '<body></body>' return request.response config.add_view(name='test', view=view) |
