Skip to content

Housekeeping: Remove traces of python2.7 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion doc/parsing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ It looks for two arguments in the :attr:`flask.Request.values` dict: an integer
.. note ::

The default argument type is a unicode string.
This will be ``str`` in python3 and ``unicode`` in python2.
This will be ``str``.

If you specify the ``help`` value,
it will be rendered as the error message when a type error is raised while parsing it.
Expand Down
1 change: 0 additions & 1 deletion flask_restplus/__about__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = '0.13.1.dev'
__description__ = 'Fully featured framework for fast, easy and documented API development with Flask'
3 changes: 0 additions & 3 deletions flask_restplus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

from . import fields, reqparse, apidoc, inputs, cors
from .api import Api # noqa
from .marshalling import marshal, marshal_with, marshal_with_field # noqa
Expand Down
1 change: 0 additions & 1 deletion flask_restplus/_http.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
"""
This file is backported from Python 3.5 http built-in module.
"""
Expand Down
16 changes: 4 additions & 12 deletions flask_restplus/api.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import difflib
import inspect
from itertools import chain
import logging
import operator
import re
import six
import sys

try:
from collections.abc import OrderedDict
except ImportError:
# TODO Remove this to drop Python2 support
from collections import OrderedDict
from collections import OrderedDict
from functools import wraps, partial
from types import MethodType

Expand Down Expand Up @@ -439,7 +431,7 @@ def add_namespace(self, ns, path=None):
urls = self.ns_urls(ns, r.urls)
self.register_resource(ns, r.resource, *urls, **r.kwargs)
# Register models
for name, definition in six.iteritems(ns.models):
for name, definition in ns.models.items():
self.models[name] = definition
if not self.blueprint and self.app is not None:
self._configure_namespace_logger(self.app, ns)
Expand Down Expand Up @@ -511,7 +503,7 @@ def _own_and_child_error_handlers(self):
rv = {}
rv.update(self.error_handlers)
for ns in self.namespaces:
for exception, handler in six.iteritems(ns.error_handlers):
for exception, handler in ns.error_handlers.items():
rv[exception] = handler
return rv

Expand Down Expand Up @@ -626,7 +618,7 @@ def handle_error(self, e):

headers = Headers()

for typecheck, handler in six.iteritems(self._own_and_child_error_handlers):
for typecheck, handler in self._own_and_child_error_handlers.items():
if isinstance(e, typecheck):
result = handler(e)
default_data, code, headers = unpack(result, HTTPStatus.INTERNAL_SERVER_ERROR)
Expand Down
3 changes: 0 additions & 3 deletions flask_restplus/apidoc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from flask import url_for, Blueprint, render_template


Expand Down
3 changes: 0 additions & 3 deletions flask_restplus/cors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from datetime import timedelta
from flask import make_response, request, current_app
from functools import update_wrapper
Expand Down
3 changes: 0 additions & 3 deletions flask_restplus/errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import flask

from werkzeug.exceptions import HTTPException
Expand Down
30 changes: 12 additions & 18 deletions flask_restplus/fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import re
import fnmatch
import inspect
Expand All @@ -10,8 +7,7 @@
from decimal import Decimal, ROUND_HALF_EVEN
from email.utils import formatdate

from six import iteritems, itervalues, text_type, string_types
from six.moves.urllib.parse import urlparse, urlunparse
from urllib.parse import urlparse, urlunparse

from flask import url_for, request
from werkzeug.utils import cached_property
Expand All @@ -35,7 +31,7 @@ class MarshallingError(RestError):
def __init__(self, underlying_exception):
# just put the contextual representation of the error to hint on what
# went wrong without exposing internals
super(MarshallingError, self).__init__(text_type(underlying_exception))
super(MarshallingError, self).__init__(str(underlying_exception))


def is_indexable_but_not_string(obj):
Expand Down Expand Up @@ -366,9 +362,7 @@ def schema(self):

class String(StringMixin, Raw):
'''
Marshal a value as a string. Uses ``six.text_type`` so values will
be converted to :class:`unicode` in python2 and :class:`str` in
python3.
Marshal a value as a string.
'''
def __init__(self, *args, **kwargs):
self.enum = kwargs.pop('enum', None)
Expand All @@ -378,7 +372,7 @@ def __init__(self, *args, **kwargs):

def format(self, value):
try:
return text_type(value)
return str(value)
except ValueError as ve:
raise MarshallingError(ve)

Expand Down Expand Up @@ -431,7 +425,7 @@ class Arbitrary(NumberMixin, Raw):
'''

def format(self, value):
return text_type(Decimal(value))
return str(Decimal(value))


ZERO = Decimal()
Expand All @@ -449,7 +443,7 @@ def format(self, value):
dvalue = Decimal(value)
if not dvalue.is_normal() and dvalue != ZERO:
raise MarshallingError('Invalid Fixed precision number.')
return text_type(dvalue.quantize(self.precision, rounding=ROUND_HALF_EVEN))
return str(dvalue.quantize(self.precision, rounding=ROUND_HALF_EVEN))


class Boolean(Raw):
Expand Down Expand Up @@ -484,7 +478,7 @@ def __init__(self, dt_format='iso8601', **kwargs):
def parse(self, value):
if value is None:
return None
elif isinstance(value, string_types):
elif isinstance(value, str):
parser = datetime_from_iso8601 if self.dt_format == 'iso8601' else datetime_from_rfc822
return parser(value)
elif isinstance(value, datetime):
Expand Down Expand Up @@ -553,7 +547,7 @@ def __init__(self, **kwargs):
def parse(self, value):
if value is None:
return None
elif isinstance(value, string_types):
elif isinstance(value, str):
return date_from_iso8601(value)
elif isinstance(value, datetime):
return value.date()
Expand Down Expand Up @@ -612,7 +606,7 @@ class FormattedString(StringMixin, Raw):
'''
def __init__(self, src_str, **kwargs):
super(FormattedString, self).__init__(**kwargs)
self.src_str = text_type(src_str)
self.src_str = str(src_str)

def output(self, key, obj, **kwargs):
try:
Expand Down Expand Up @@ -660,7 +654,7 @@ class Polymorph(Nested):
'''
def __init__(self, mapping, required=False, **kwargs):
self.mapping = mapping
parent = self.resolve_ancestor(list(itervalues(mapping)))
parent = self.resolve_ancestor(list(mapping.values()))
super(Polymorph, self).__init__(parent, allow_null=not required, **kwargs)

def output(self, key, obj, ordered=False, **kwargs):
Expand All @@ -676,7 +670,7 @@ def output(self, key, obj, ordered=False, **kwargs):
if not hasattr(value, '__class__'):
raise ValueError('Polymorph field only accept class instances')

candidates = [fields for cls, fields in iteritems(self.mapping) if type(value) == cls]
candidates = [fields for cls, fields in self.mapping.items() if type(value) == cls]

if len(candidates) <= 0:
raise ValueError('Unknown class: ' + value.__class__.__name__)
Expand Down Expand Up @@ -741,7 +735,7 @@ def _flatten(self, obj):
if obj == self._obj and self._flat is not None:
return self._flat
if isinstance(obj, dict):
self._flat = [x for x in iteritems(obj)]
self._flat = [x for x in obj.items()]
else:

def __match_attributes(attribute):
Expand Down
5 changes: 1 addition & 4 deletions flask_restplus/inputs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
'''
This module provide some helpers for advanced types parsing.

Expand All @@ -16,14 +15,12 @@ def my_type(value):

The last line allows you to document properly the type in the Swagger documentation.
'''
from __future__ import unicode_literals

import re
import socket

from datetime import datetime, time, timedelta
from email.utils import parsedate_tz, mktime_tz
from six.moves.urllib.parse import urlparse
from urllib.parse import urlparse

import aniso8601
import pytz
Expand Down
12 changes: 2 additions & 10 deletions flask_restplus/marshalling.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

try:
from collections.abc import OrderedDict
except ImportError:
# TODO Remove this to drop Python2 support
from collections import OrderedDict
from collections import OrderedDict
from functools import wraps
from six import iteritems

from flask import request, current_app, has_app_context

Expand Down Expand Up @@ -181,7 +173,7 @@ def __format_field(key, val):
(k, marshal(data, v, skip_none=skip_none, ordered=ordered))
if isinstance(v, dict)
else __format_field(k, v)
for k, v in iteritems(fields)
for k, v in fields.items()
)

if skip_none:
Expand Down
18 changes: 5 additions & 13 deletions flask_restplus/mask.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import

import logging
import re
import six

try:
from collections.abc import OrderedDict
except ImportError:
# TODO Remove this to drop Python2 support
from collections import OrderedDict
from collections import OrderedDict
from inspect import isclass

from .errors import RestError
Expand Down Expand Up @@ -38,7 +30,7 @@ class Mask(OrderedDict):
'''
def __init__(self, mask=None, skip=False, **kwargs):
self.skip = skip
if isinstance(mask, six.string_types):
if isinstance(mask, str):
super(Mask, self).__init__()
self.parse(mask)
elif isinstance(mask, (dict, OrderedDict)):
Expand Down Expand Up @@ -141,7 +133,7 @@ def filter_data(self, data):

'''
out = {}
for field, content in six.iteritems(self):
for field, content in self.items():
if field == '*':
continue
elif isinstance(content, Mask):
Expand All @@ -158,15 +150,15 @@ def filter_data(self, data):
out[field] = data.get(field, None)

if '*' in self.keys():
for key, value in six.iteritems(data):
for key, value in data.items():
if key not in out:
out[key] = value
return out

def __str__(self):
return '{{{0}}}'.format(','.join([
''.join((k, str(v))) if isinstance(v, Mask) else k
for k, v in six.iteritems(self)
for k, v in self.items()
]))


Expand Down
16 changes: 4 additions & 12 deletions flask_restplus/model.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import copy
import re
import warnings

try:
from collections.abc import OrderedDict, MutableMapping
except ImportError:
# TODO Remove this to drop Python2 support
from collections import OrderedDict, MutableMapping
from six import iteritems, itervalues
from collections import OrderedDict, MutableMapping
from werkzeug.utils import cached_property

from .mask import Mask
Expand Down Expand Up @@ -146,7 +138,7 @@ def _schema(self):
properties = self.wrapper()
required = set()
discriminator = None
for name, field in iteritems(self):
for name, field in self.items():
field = instance(field)
properties[name] = field.__schema__
if field.required:
Expand Down Expand Up @@ -175,7 +167,7 @@ def resolved(self):
resolved.update(parent.resolved)

# Handle discriminator
candidates = [f for f in itervalues(resolved) if getattr(f, 'discriminator', None)]
candidates = [f for f in resolved.values() if getattr(f, 'discriminator', None)]
# Ensure the is only one discriminator
if len(candidates) > 1:
raise ValueError('There can only be one discriminator by schema')
Expand Down Expand Up @@ -223,7 +215,7 @@ def clone(cls, name, *parents):

def __deepcopy__(self, memo):
obj = self.__class__(self.name,
[(key, copy.deepcopy(value, memo)) for key, value in iteritems(self)],
[(key, copy.deepcopy(value, memo)) for key, value in self.items()],
mask=self.__mask__)
obj.__parents__ = self.__parents__
return obj
Expand Down
10 changes: 3 additions & 7 deletions flask_restplus/namespace.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import inspect
import warnings
import logging
from collections import namedtuple

import six
from flask import request
from flask.views import http_method_funcs

Expand Down Expand Up @@ -118,7 +114,7 @@ def _build_doc(self, cls, doc):

def doc(self, shortcut=None, **kwargs):
'''A decorator to add some api documentation to the decorated object'''
if isinstance(shortcut, six.text_type):
if isinstance(shortcut, str):
kwargs['id'] = shortcut
show = shortcut if isinstance(shortcut, bool) else True

Expand Down Expand Up @@ -334,8 +330,8 @@ def payload(self):

def unshortcut_params_description(data):
if 'params' in data:
for name, description in six.iteritems(data['params']):
if isinstance(description, six.string_types):
for name, description in data['params'].items():
if isinstance(description, str):
data['params'][name] = {'description': description}


Expand Down
Loading