Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions routes/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import threading

from repoze.lru import LRUCache
import six

from routes import request_config
from routes.util import (
Expand Down Expand Up @@ -168,7 +167,7 @@ def connect(self, routename, path=None, **kwargs):
newkargs = {}
_routename = routename
_path = path
for key, value in six.iteritems(self.kwargs):
for key, value in self.kwargs.items():
if key == 'path_prefix':
if path is not None:
# if there's a name_prefix, add it to the route name
Expand Down Expand Up @@ -595,7 +594,7 @@ def _create_gens(self):
if 'controller' in route.hardcoded:
clist = [route.defaults['controller']]
if 'action' in route.hardcoded:
alist = [six.text_type(route.defaults['action'])]
alist = [str(route.defaults['action'])]
for controller in clist:
for action in alist:
actiondict = gendict.setdefault(controller, {})
Expand Down Expand Up @@ -625,7 +624,7 @@ def _create_regs(self, clist=None):
else:
clist = self.controller_scan

for key, val in six.iteritems(self.maxkeys):
for key, val in self.maxkeys.items():
for route in val:
route.makeregexp(clist)

Expand Down Expand Up @@ -801,15 +800,11 @@ def generate(self, *args, **kargs):
# If the URL didn't depend on the SCRIPT_NAME, we'll cache it
# keyed by just by kargs; otherwise we need to cache it with
# both SCRIPT_NAME and kargs:
cache_key = six.text_type(args).encode('utf8') + \
six.text_type(kargs).encode('utf8')
cache_key = str(args).encode('utf8') + str(kargs).encode('utf8')

if self.urlcache is not None:
if six.PY3:
cache_key_script_name = b':'.join((script_name.encode('utf-8'),
cache_key))
else:
cache_key_script_name = '%s:%s' % (script_name, cache_key)
cache_key_script_name = b':'.join((script_name.encode('utf-8'),
cache_key))

# Check the url cache to see if it exists, use it if it does
val = self.urlcache.get(cache_key_script_name, self)
Expand All @@ -829,7 +824,7 @@ def generate(self, *args, **kargs):

keys = frozenset(kargs.keys())
cacheset = False
cachekey = six.text_type(keys)
cachekey = str(keys)
cachelist = sortcache.get(cachekey)
if args:
keylist = args
Expand Down Expand Up @@ -1110,7 +1105,7 @@ def resource(self, member_name, collection_name, **kwargs):
def swap(dct, newdct):
"""Swap the keys and values in the dict, and uppercase the values
from the dict during the swap."""
for key, val in six.iteritems(dct):
for key, val in dct.items():
newdct.setdefault(val.upper(), []).append(key)
return newdct
collection_methods = swap(collection, {})
Expand Down Expand Up @@ -1153,7 +1148,7 @@ def requirements_for(meth):
return opts

# Add the routes for handling collection methods
for method, lst in six.iteritems(collection_methods):
for method, lst in collection_methods.items():
primary = (method != 'GET' and lst.pop(0)) or None
route_options = requirements_for(method)
for action in lst:
Expand All @@ -1177,7 +1172,7 @@ def requirements_for(meth):
action='index', conditions={'method': ['GET']}, **options)

# Add the routes that deal with new resource methods
for method, lst in six.iteritems(new_methods):
for method, lst in new_methods.items():
route_options = requirements_for(method)
for action in lst:
name = "new_" + member_name
Expand All @@ -1196,7 +1191,7 @@ def requirements_for(meth):
requirements_regexp = '[^\\/]+(?<!\\\\)'

# Add the routes that deal with member methods of a resource
for method, lst in six.iteritems(member_methods):
for method, lst in member_methods.items():
route_options = requirements_for(method)
route_options['requirements'] = {'id': requirements_regexp}
if method not in ['POST', 'GET', 'any']:
Expand Down
12 changes: 5 additions & 7 deletions routes/route.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import re
import sys

import six
from six.moves.urllib import parse as urlparse
from urllib import parse as urlparse

from routes.util import _url_quote as url_quote, _str_encode, as_unicode

Expand Down Expand Up @@ -97,7 +95,7 @@ def _setup_route(self):

# Build a req list with all the regexp requirements for our args
self.req_regs = {}
for key, val in six.iteritems(self.reqs):
for key, val in self.reqs.items():
self.req_regs[key] = re.compile('^' + val + '$')
# Update our defaults and set new default keys if needed. defaults
# needs to be saved
Expand Down Expand Up @@ -133,14 +131,14 @@ def make_full_route(self):

def make_unicode(self, s):
"""Transform the given argument into a unicode string."""
if isinstance(s, six.text_type):
if isinstance(s, str):
return s
elif isinstance(s, bytes):
return s.decode(self.encoding)
elif callable(s):
return s
else:
return six.text_type(s)
return str(s)

def _pathkeys(self, routepath):
"""Utility function to walk the route, and pull out the valid
Expand Down Expand Up @@ -567,7 +565,7 @@ def match(self, url, environ=None, sub_domains=False,
matchdict = match.groupdict()
result = {}
extras = self._default_keys - frozenset(matchdict.keys())
for key, val in six.iteritems(matchdict):
for key, val in matchdict.items():
if key != 'path_info' and self.encoding:
# change back into python unicode objects from the URL
# representation
Expand Down
44 changes: 21 additions & 23 deletions routes/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"""
import os
import re

import six
from six.moves import urllib
import urllib

from routes import request_config

Expand All @@ -34,8 +32,8 @@ def _screenargs(kargs, mapper, environ, force_explicit=False):
"""
# Coerce any unicode args with the encoding
encoding = mapper.encoding
for key, val in six.iteritems(kargs):
if isinstance(val, six.text_type):
for key, val in kargs.items():
if isinstance(val, str):
kargs[key] = val.encode(encoding)

if mapper.explicit and mapper.sub_domains and not force_explicit:
Expand All @@ -60,7 +58,7 @@ def _screenargs(kargs, mapper, environ, force_explicit=False):
memory_kargs = {}

# Remove keys from memory and kargs if kargs has them as None
empty_keys = [key for key, value in six.iteritems(kargs) if value is None]
empty_keys = [key for key, value in kargs.items() if value is None]
for key in empty_keys:
del kargs[key]
memory_kargs.pop(key, None)
Expand All @@ -79,7 +77,7 @@ def _subdomain_check(kargs, mapper, environ):
on the current subdomain or lack therof."""
if mapper.sub_domains:
subdomain = kargs.pop('sub_domain', None)
if isinstance(subdomain, six.text_type):
if isinstance(subdomain, str):
subdomain = str(subdomain)

fullhost = environ.get('HTTP_HOST') or environ.get('SERVER_NAME')
Expand Down Expand Up @@ -112,27 +110,27 @@ def _subdomain_check(kargs, mapper, environ):
def _url_quote(string, encoding):
"""A Unicode handling version of urllib.quote."""
if encoding:
if isinstance(string, six.text_type):
if isinstance(string, str):
s = string.encode(encoding)
elif isinstance(string, six.text_type):
elif isinstance(string, str):
# assume the encoding is already correct
s = string
else:
s = six.text_type(string).encode(encoding)
s = str(string).encode(encoding)
else:
s = str(string)
return urllib.parse.quote(s, '/')


def _str_encode(string, encoding):
if encoding:
if isinstance(string, six.text_type):
if isinstance(string, str):
s = string.encode(encoding)
elif isinstance(string, six.text_type):
elif isinstance(string, str):
# assume the encoding is already correct
s = string
else:
s = six.text_type(string).encode(encoding)
s = str(string).encode(encoding)
return s


Expand Down Expand Up @@ -216,16 +214,16 @@ def url_for(*args, **kargs):
if kargs:
url += '?'
query_args = []
for key, val in six.iteritems(kargs):
for key, val in kargs.items():
if isinstance(val, (list, tuple)):
for value in val:
query_args.append("%s=%s" % (
urllib.parse.quote(six.text_type(key).encode(encoding)),
urllib.parse.quote(six.text_type(value).encode(encoding))))
urllib.parse.quote(str(key).encode(encoding)),
urllib.parse.quote(str(value).encode(encoding))))
else:
query_args.append("%s=%s" % (
urllib.parse.quote(six.text_type(key).encode(encoding)),
urllib.parse.quote(six.text_type(val).encode(encoding))))
urllib.parse.quote(str(key).encode(encoding)),
urllib.parse.quote(str(val).encode(encoding))))
url += '&'.join(query_args)
environ = getattr(config, 'environ', {})
if 'wsgiorg.routing_args' not in environ:
Expand Down Expand Up @@ -366,16 +364,16 @@ def __call__(self, *args, **kargs):
if kargs:
url += '?'
query_args = []
for key, val in six.iteritems(kargs):
for key, val in kargs.items():
if isinstance(val, (list, tuple)):
for value in val:
query_args.append("%s=%s" % (
urllib.parse.quote(six.text_type(key).encode(encoding)),
urllib.parse.quote(six.text_type(value).encode(encoding))))
urllib.parse.quote(str(key).encode(encoding)),
urllib.parse.quote(str(value).encode(encoding))))
else:
query_args.append("%s=%s" % (
urllib.parse.quote(six.text_type(key).encode(encoding)),
urllib.parse.quote(six.text_type(val).encode(encoding))))
urllib.parse.quote(str(key).encode(encoding)),
urllib.parse.quote(str(val).encode(encoding))))
url += '&'.join(query_args)
if not static:
route_args = []
Expand Down
13 changes: 4 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
README = f.read()
with io.open(os.path.join(here, 'CHANGELOG.rst'), encoding='utf8') as f:
CHANGES = f.read()
PY3 = sys.version_info[0] == 3

extra_options = {
"packages": find_packages(),
Expand All @@ -24,11 +23,10 @@
}
extras_require['docs'] = ['Sphinx'] + extras_require['middleware']

if PY3:
if "test" in sys.argv or "develop" in sys.argv:
for root, directories, files in os.walk("tests"):
for directory in directories:
extra_options["packages"].append(os.path.join(root, directory))
if "test" in sys.argv or "develop" in sys.argv:
for root, directories, files in os.walk("tests"):
for directory in directories:
extra_options["packages"].append(os.path.join(root, directory))

setup(name="Routes",
version=__version__,
Expand All @@ -42,8 +40,6 @@
"Programming Language :: Python :: Implementation :: PyPy",
"Programming Language :: Python :: Implementation :: CPython",
'Programming Language :: Python',
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
Expand All @@ -67,7 +63,6 @@
zip_safe=False,
tests_require=["soupsieve<2.0", 'nose', 'webtest', 'webob', 'coverage'],
install_requires=[
"six",
"repoze.lru>=0.3"
],
extras_require=extras_require,
Expand Down
3 changes: 1 addition & 2 deletions tests/test_functional/test_generation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""test_generation"""
import sys, time, unittest
from six.moves import urllib
import sys, time, unittest, urllib

from nose.tools import eq_, assert_raises
from routes import *
Expand Down
2 changes: 1 addition & 1 deletion tests/test_functional/test_nonminimization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Test non-minimization recognition"""
from six.moves import urllib
import urllib

from nose.tools import eq_

Expand Down
3 changes: 2 additions & 1 deletion tests/test_functional/test_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import sys
import time
import unittest
from six.moves import urllib
import urllib

from nose.tools import eq_, assert_raises
from routes import *
from routes.util import RoutesException
Expand Down