From 44d96530bb52642a52e2a14921ebda6af0f7afc5 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Fri, 20 Oct 2023 15:39:04 +0200 Subject: [PATCH] remove python2 support --- routes/mapper.py | 27 +++++------- routes/route.py | 12 +++-- routes/util.py | 44 +++++++++---------- setup.py | 13 ++---- tests/test_functional/test_generation.py | 3 +- tests/test_functional/test_nonminimization.py | 2 +- tests/test_functional/test_recognition.py | 3 +- 7 files changed, 45 insertions(+), 59 deletions(-) diff --git a/routes/mapper.py b/routes/mapper.py index 72981cb..9de7e60 100644 --- a/routes/mapper.py +++ b/routes/mapper.py @@ -5,7 +5,6 @@ import threading from repoze.lru import LRUCache -import six from routes import request_config from routes.util import ( @@ -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 @@ -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, {}) @@ -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) @@ -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) @@ -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 @@ -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, {}) @@ -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: @@ -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 @@ -1196,7 +1191,7 @@ def requirements_for(meth): requirements_regexp = '[^\\/]+(?=0.3" ], extras_require=extras_require, diff --git a/tests/test_functional/test_generation.py b/tests/test_functional/test_generation.py index b461b5f..cb6732d 100644 --- a/tests/test_functional/test_generation.py +++ b/tests/test_functional/test_generation.py @@ -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 * diff --git a/tests/test_functional/test_nonminimization.py b/tests/test_functional/test_nonminimization.py index 1b152c4..7f2d0e1 100644 --- a/tests/test_functional/test_nonminimization.py +++ b/tests/test_functional/test_nonminimization.py @@ -1,5 +1,5 @@ """Test non-minimization recognition""" -from six.moves import urllib +import urllib from nose.tools import eq_ diff --git a/tests/test_functional/test_recognition.py b/tests/test_functional/test_recognition.py index 03fe6a7..6295979 100644 --- a/tests/test_functional/test_recognition.py +++ b/tests/test_functional/test_recognition.py @@ -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