diff --git a/examples/demo/demo.py b/examples/demo/demo.py index 69f6cdc..0b1bd00 100644 --- a/examples/demo/demo.py +++ b/examples/demo/demo.py @@ -16,17 +16,15 @@ from wsme.types import File import bottle -from six import u - import logging class Person(object): id = int - firstname = unicode - lastname = unicode + firstname = str + lastname = str - hobbies = [unicode] + hobbies = [str] def __repr__(self): return "Person(%s, %s %s, %s)" % ( @@ -47,7 +45,7 @@ class DemoRoot(WSRoot): def echofile(self, afile): return afile - @expose(unicode) + @expose(str) def helloworld(self): return u"Здраво, свете (<- Hello World in Serbian !)" @@ -55,25 +53,25 @@ class DemoRoot(WSRoot): def getperson(self): p = Person() p.id = 12 - p.firstname = u'Ross' - p.lastname = u'Geler' + p.firstname = 'Ross' + p.lastname = 'Geler' p.hobbies = [] - print p + print(p) return p @expose([Person]) def listpersons(self): p = Person() p.id = 12 - p.firstname = u('Ross') - p.lastname = u('Geler') + p.firstname = 'Ross' + p.lastname = 'Geler' r = [p] p = Person() p.id = 13 - p.firstname = u('Rachel') - p.lastname = u('Green') + p.firstname = 'Rachel' + p.lastname = 'Green' r.append(p) - print r + print(r) return r @expose(Person) @@ -84,7 +82,7 @@ class DemoRoot(WSRoot): @expose([Person]) @validate([Person]) def setpersons(self, persons): - print persons + print(persons) return persons diff --git a/requirements.txt b/requirements.txt index ffb3942..cf4d31b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -six>=1.9.0 WebOb>=1.8.0 simplegeneric pytz diff --git a/tests/pecantest/test/controllers/ws.py b/tests/pecantest/test/controllers/ws.py index b35a0c6..049e380 100644 --- a/tests/pecantest/test/controllers/ws.py +++ b/tests/pecantest/test/controllers/ws.py @@ -6,8 +6,6 @@ from wsme.types import Base, text, wsattr import wsme import wsmeext.pecan -import six - class Author(Base): id = int @@ -78,7 +76,7 @@ class AuthorsController(RestController): books = BooksController() - @wsmeext.pecan.wsexpose([Author], [six.text_type], [Criterion]) + @wsmeext.pecan.wsexpose([Author], [str], [Criterion]) def get_all(self, q=None, r=None): if q: return [ diff --git a/tests/pecantest/test/tests/test_ws.py b/tests/pecantest/test/tests/test_ws.py index ae06650..3b5617e 100644 --- a/tests/pecantest/test/tests/test_ws.py +++ b/tests/pecantest/test/tests/test_ws.py @@ -1,8 +1,8 @@ -from six.moves import http_client -from test.tests import FunctionalTest +from http import client as http_client import json + import pecan -import six +from test.tests import FunctionalTest used_status_codes = [400, 401, 403, 404, 500] @@ -240,8 +240,5 @@ class TestWS(FunctionalTest): assert book['author']['id'] == 1 def test_no_content_type_if_no_return_type(self): - if six.PY3: - self.skipTest( - "This test does not work in Python 3 until https://review.openstack.org/#/c/48439/ is merged") res = self.app.delete('/authors/4') assert "Content-Type" not in res.headers, res.headers['Content-Type'] diff --git a/wsme/api.py b/wsme/api.py index b2ddf6e..b4d728a 100644 --- a/wsme/api.py +++ b/wsme/api.py @@ -1,8 +1,7 @@ -import traceback import functools import inspect import logging -import six +import traceback import wsme.exc import wsme.types @@ -26,10 +25,7 @@ def wrapfunc(f): def getargspec(f): f = getattr(f, '_wsme_original_func', f) - if six.PY2: - return inspect.getargspec(f) - else: - return inspect.getfullargspec(f) + return inspect.getfullargspec(f) class FunctionArgument(object): @@ -220,7 +216,7 @@ def format_exception(excinfo, debug=False): code = getattr(error, 'code', None) if code and utils.is_valid_code(code) and utils.is_client_error(code): faultstring = (error.faultstring if hasattr(error, 'faultstring') - else six.text_type(error)) + else str(error)) faultcode = getattr(error, 'faultcode', 'Client') r = dict(faultcode=faultcode, faultstring=faultstring) @@ -228,7 +224,7 @@ def format_exception(excinfo, debug=False): r['debuginfo'] = None return r else: - faultstring = six.text_type(error) + faultstring = str(error) debuginfo = "\n".join(traceback.format_exception(*excinfo)) log.error('Server-side error: "%s". Detail: \n%s' % ( diff --git a/wsme/exc.py b/wsme/exc.py index e70db65..f698f65 100644 --- a/wsme/exc.py +++ b/wsme/exc.py @@ -1,5 +1,3 @@ -import six - from wsme.utils import _ @@ -14,10 +12,10 @@ class ClientSideError(RuntimeError): def faultstring(self): if self.msg is None: return str(self) - elif isinstance(self.msg, six.text_type): + elif isinstance(self.msg, str): return self.msg else: - return six.u(self.msg) + return str(self.msg) class InvalidInput(ClientSideError): @@ -28,9 +26,9 @@ class InvalidInput(ClientSideError): @property def faultstring(self): - return _(six.u( - "Invalid input for field/attribute %s. Value: '%s'. %s") - ) % (self.fieldname, self.value, self.msg) + return _("Invalid input for field/attribute %s. Value: '%s'. %s") % ( + self.fieldname, self.value, self.msg, + ) class MissingArgument(ClientSideError): @@ -40,8 +38,9 @@ class MissingArgument(ClientSideError): @property def faultstring(self): - return _(six.u('Missing argument: "%s"%s')) % ( - self.argname, self.msg and ": " + self.msg or "") + return _('Missing argument: "%s"%s') % ( + self.argname, self.msg and ": " + self.msg or "", + ) class UnknownArgument(ClientSideError): @@ -51,8 +50,9 @@ class UnknownArgument(ClientSideError): @property def faultstring(self): - return _(six.u('Unknown argument: "%s"%s')) % ( - self.argname, self.msg and ": " + self.msg or "") + return _('Unknown argument: "%s"%s') % ( + self.argname, self.msg and ": " + self.msg or "", + ) class UnknownFunction(ClientSideError): @@ -62,7 +62,7 @@ class UnknownFunction(ClientSideError): @property def faultstring(self): - return _(six.u("Unknown function name: %s")) % (self.name) + return _("Unknown function name: %s") % (self.name) class UnknownAttribute(ClientSideError): diff --git a/wsme/rest/args.py b/wsme/rest/args.py index 9dc16c7..855b51a 100644 --- a/wsme/rest/args.py +++ b/wsme/rest/args.py @@ -11,8 +11,6 @@ from wsme.types import UserType, ArrayType, DictType, File from wsme.utils import parse_isodate, parse_isotime, parse_isodatetime import wsme.runtime -from six import moves - ARRAY_MAX_SIZE = 1000 @@ -116,7 +114,7 @@ def array_from_params(datatype, params, path, hit_paths): if len(value) < len(attrvalues): value[-1:] = [ datatype.item_type() - for i in moves.range(len(attrvalues) - len(value)) + for i in range(len(attrvalues) - len(value)) ] for i, attrvalue in enumerate(attrvalues): setattr( diff --git a/wsme/rest/json.py b/wsme/rest/json.py index cf8727c..f91dd1e 100644 --- a/wsme/rest/json.py +++ b/wsme/rest/json.py @@ -6,7 +6,6 @@ import decimal import json from simplegeneric import generic -import six import wsme.exc import wsme.types @@ -180,12 +179,12 @@ def dict_fromjson(datatype, value): for item in value.items())) -@fromjson.when_object(six.binary_type) +@fromjson.when_object(bytes) def str_fromjson(datatype, value): - if (isinstance(value, six.string_types) or - isinstance(value, six.integer_types) or + if (isinstance(value, str) or + isinstance(value, int) or isinstance(value, float)): - return six.text_type(value).encode('utf8') + return str(value).encode('utf8') @fromjson.when_object(wsme.types.text) @@ -195,7 +194,7 @@ def text_fromjson(datatype, value): return value -@fromjson.when_object(*six.integer_types + (float,)) +@fromjson.when_object(int, float) def numeric_fromjson(datatype, value): """Convert string object to built-in types int, long or float.""" if value is None: @@ -208,7 +207,7 @@ def bool_fromjson(datatype, value): """Convert to bool, restricting strings to just unambiguous values.""" if value is None: return None - if isinstance(value, six.integer_types + (bool,)): + if isinstance(value, (int, bool,)): return bool(value) if value in ENUM_TRUE: return True @@ -248,7 +247,7 @@ def datetime_fromjson(datatype, value): def parse(s, datatypes, bodyarg, encoding='utf8'): jload = json.load if not hasattr(s, 'read'): - if six.PY3 and isinstance(s, six.binary_type): + if isinstance(s, bytes): s = s.decode(encoding) jload = json.loads try: diff --git a/wsme/rest/xml.py b/wsme/rest/xml.py index 286afa7..60c8796 100644 --- a/wsme/rest/xml.py +++ b/wsme/rest/xml.py @@ -2,8 +2,6 @@ from __future__ import absolute_import import datetime -import six - import xml.etree.ElementTree as et from simplegeneric import generic @@ -69,7 +67,7 @@ def toxml(datatype, key, value): el.append(toxml(attrdef.datatype, attrdef.name, attrvalue)) else: - el.text = six.text_type(value) + el.text = str(value) return el @@ -213,7 +211,7 @@ def dict_fromxml(datatype, element): def unicode_fromxml(datatype, element): if element.get('nil') == 'true': return None - return wsme.types.text(element.text) if element.text else six.u('') + return wsme.types.text(element.text) if element.text else '' @fromxml.when_object(datetime.date) diff --git a/wsme/root.py b/wsme/root.py index ed89148..1d03fba 100644 --- a/wsme/root.py +++ b/wsme/root.py @@ -2,9 +2,6 @@ import logging import sys import weakref -from six import u, b -import six - import webob from wsme.exc import ClientSideError, UnknownFunction @@ -15,7 +12,7 @@ import wsme.types log = logging.getLogger(__name__) -html_body = u(""" +html_body = """