Skip to content

Commit

Permalink
Merge e723334 into d2e3173
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Apr 17, 2020
2 parents d2e3173 + e723334 commit 3538143
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 227 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ python:
- 3.7
- 3.6
- 3.5
- 3.4
- nightly
- pypy3
env: TOXENV=py,coveralls

jobs:
include:
- python: "3.8"
env: TOXENV=stylecheck,docs-html
- python: "2.7"
env: TOXENV=py27,coveralls
env: TOXENV=stylecheck,docs-html,coveralls
allow_failures:
- python: nightly
- python: pypy3
Expand Down
2 changes: 0 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# WTForms documentation build configuration file, created by
# sphinx-quickstart on Fri Aug 01 15:29:36 2008.
#
Expand Down
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ directory = src/wtforms/locale/
domain = wtforms
statistics = 1

[bdist_wheel]
universal = 1

[tool:pytest]
testpaths = tests

Expand Down
10 changes: 2 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ class BDistWheel(CompileCatalogMixin, BaseBDistWheel):
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
Expand All @@ -98,12 +95,9 @@ class BDistWheel(CompileCatalogMixin, BaseBDistWheel):
packages=find_packages("src"),
package_dir={"": "src"},
include_package_data=True,
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
python_requires=">=3.5",
setup_requires=["Babel>=2.6.0"],
install_requires=["MarkupSafe"],
extras_require={
"ipaddress": ['ipaddress;python_version<"3.3"'],
"email": ["email_validator"],
},
extras_require={"email": ["email_validator"]},
cmdclass=command_classes,
)
38 changes: 0 additions & 38 deletions src/wtforms/compat.py

This file was deleted.

6 changes: 2 additions & 4 deletions src/wtforms/csrf/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
validates with the hmac of the random value + expiration time, and the
expiration time is not passed, the CSRF validation will pass.
"""
from __future__ import unicode_literals

import hmac
import os

Expand Down Expand Up @@ -49,15 +47,15 @@ def generate_csrf_token(self, csrf_token_field):

if self.time_limit:
expires = (self.now() + self.time_limit).strftime(self.TIME_FORMAT)
csrf_build = "%s%s" % (session["csrf"], expires)
csrf_build = "{}{}".format(session["csrf"], expires)
else:
expires = ""
csrf_build = session["csrf"]

hmac_csrf = hmac.new(
meta.csrf_secret, csrf_build.encode("utf8"), digestmod=sha1
)
return "%s##%s" % (expires, hmac_csrf.hexdigest())
return "{}##{}".format(expires, hmac_csrf.hexdigest())

def validate_csrf_token(self, form, field):
meta = self.form_meta
Expand Down
43 changes: 14 additions & 29 deletions src/wtforms/fields/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import datetime
import decimal
import itertools
Expand All @@ -8,7 +6,6 @@
from markupsafe import Markup, escape

from wtforms import widgets
from wtforms.compat import izip, text_type
from wtforms.i18n import DummyTranslations
from wtforms.utils import unset_value
from wtforms.validators import StopValidation
Expand Down Expand Up @@ -147,13 +144,6 @@ def __init__(
for f in flags:
setattr(self.flags, f, True)

def __unicode__(self):
"""
Returns a HTML representation of the field. For more powerful rendering,
see the `__call__` method.
"""
return self()

def __str__(self):
"""
Returns a HTML representation of the field. For more powerful rendering,
Expand Down Expand Up @@ -405,10 +395,8 @@ def bind(self, form, name, prefix="", translations=None, **kwargs):
return self.field_class(*self.args, **kw)

def __repr__(self):
return "<UnboundField(%s, %r, %r)>" % (
self.field_class.__name__,
self.args,
self.kwargs,
return "<UnboundField({}, {!r}, {!r})>".format(
self.field_class.__name__, self.args, self.kwargs,
)


Expand Down Expand Up @@ -444,9 +432,6 @@ def __init__(self, field_id, text):
def __str__(self):
return self()

def __unicode__(self):
return self()

def __html__(self):
return self()

Expand All @@ -458,10 +443,10 @@ def __call__(self, text=None, **kwargs):

attributes = widgets.html_params(**kwargs)
text = escape(text or self.text)
return Markup("<label %s>%s</label>" % (attributes, text))
return Markup("<label {}>{}</label>".format(attributes, text))

def __repr__(self):
return "Label(%r, %r)" % (self.field_id, self.text)
return "Label({!r}, {!r})".format(self.field_id, self.text)


class SelectFieldBase(Field):
Expand Down Expand Up @@ -501,7 +486,7 @@ class _Option(Field):
checked = False

def _value(self):
return text_type(self.data)
return str(self.data)


class SelectField(SelectFieldBase):
Expand All @@ -511,7 +496,7 @@ def __init__(
self,
label=None,
validators=None,
coerce=text_type,
coerce=str,
choices=None,
validate_choice=True,
**kwargs
Expand Down Expand Up @@ -622,7 +607,7 @@ def process_formdata(self, valuelist):
self.data = valuelist[0]

def _value(self):
return text_type(self.data) if self.data is not None else ""
return str(self.data) if self.data is not None else ""


class LocaleAwareNumberField(Field):
Expand Down Expand Up @@ -677,7 +662,7 @@ def _value(self):
if self.raw_data:
return self.raw_data[0]
elif self.data is not None:
return text_type(self.data)
return str(self.data)
else:
return ""

Expand Down Expand Up @@ -740,22 +725,22 @@ def _value(self):
return self.raw_data[0]
elif self.data is not None:
if self.use_locale:
return text_type(self._format_decimal(self.data))
return str(self._format_decimal(self.data))
elif self.places is not None:
if hasattr(self.data, "quantize"):
exp = decimal.Decimal(".1") ** self.places
if self.rounding is None:
quantized = self.data.quantize(exp)
else:
quantized = self.data.quantize(exp, rounding=self.rounding)
return text_type(quantized)
return str(quantized)
else:
# If for some reason, data is a float or int, then format
# as we would for floats using string formatting.
format = "%%0.%df" % self.places
return format % self.data
else:
return text_type(self.data)
return str(self.data)
else:
return ""

Expand Down Expand Up @@ -786,7 +771,7 @@ def _value(self):
if self.raw_data:
return self.raw_data[0]
elif self.data is not None:
return text_type(self.data)
return str(self.data)
else:
return ""

Expand Down Expand Up @@ -830,7 +815,7 @@ def process_formdata(self, valuelist):

def _value(self):
if self.raw_data:
return text_type(self.raw_data[0])
return str(self.raw_data[0])
else:
return "y"

Expand Down Expand Up @@ -1109,7 +1094,7 @@ def populate_obj(self, obj, name):
candidates = itertools.chain(ivalues, itertools.repeat(None))
_fake = type(str("_fake"), (object,), {})
output = []
for field, data in izip(self.entries, candidates):
for field, data in zip(self.entries, candidates):
fake_obj = _fake()
fake_obj.data = data
field.populate_obj(fake_obj, "data")
Expand Down
21 changes: 10 additions & 11 deletions src/wtforms/form.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections import OrderedDict
import itertools

from wtforms.compat import iteritems, itervalues, with_metaclass
from wtforms.meta import DefaultMeta

__all__ = ("BaseForm", "Form")
Expand Down Expand Up @@ -50,7 +49,7 @@ def __init__(self, fields, prefix="", meta=_default_meta):

def __iter__(self):
"""Iterate form fields in creation order."""
return iter(itervalues(self._fields))
return iter(self._fields.values())

def __contains__(self, name):
""" Returns `True` if the named field is a member of this form. """
Expand All @@ -76,7 +75,7 @@ def populate_obj(self, obj):
:note: This is a destructive operation; Any attribute with the same name
as a field will be overridden. Use with caution.
"""
for name, field in iteritems(self._fields):
for name, field in self._fields.items():
field.populate_obj(obj, name)

def process(self, formdata=None, obj=None, data=None, **kwargs):
Expand Down Expand Up @@ -107,7 +106,7 @@ def process(self, formdata=None, obj=None, data=None, **kwargs):
# Temporarily, this can simply be merged with kwargs.
kwargs = dict(data, **kwargs)

for name, field in iteritems(self._fields):
for name, field in self._fields.items():
if obj is not None and hasattr(obj, name):
field.process(formdata, getattr(obj, name))
elif name in kwargs:
Expand All @@ -128,7 +127,7 @@ def validate(self, extra_validators=None):
"""
self._errors = None
success = True
for name, field in iteritems(self._fields):
for name, field in self._fields.items():
if extra_validators is not None and name in extra_validators:
extra = extra_validators[name]
else:
Expand All @@ -139,14 +138,14 @@ def validate(self, extra_validators=None):

@property
def data(self):
return dict((name, f.data) for name, f in iteritems(self._fields))
return {name: f.data for name, f in self._fields.items()}

@property
def errors(self):
if self._errors is None:
self._errors = dict(
(name, f.errors) for name, f in iteritems(self._fields) if f.errors
)
self._errors = {
name: f.errors for name, f in self._fields.items() if f.errors
}
return self._errors


Expand Down Expand Up @@ -218,7 +217,7 @@ def __delattr__(cls, name):
type.__delattr__(cls, name)


class Form(with_metaclass(FormMeta, BaseForm)):
class Form(BaseForm, metaclass=FormMeta):
"""
Declarative Form base class. Extends BaseForm's core behaviour allowing
fields to be defined on Form subclasses as class attributes.
Expand Down Expand Up @@ -261,7 +260,7 @@ def __init__(
meta_obj.update_values(meta)
super(Form, self).__init__(self._unbound_fields, meta=meta_obj, prefix=prefix)

for name, field in iteritems(self._fields):
for name, field in self._fields.items():
# Set all the fields to attributes so that they obscure the class
# attributes with the same names.
setattr(self, name, field)
Expand Down

0 comments on commit 3538143

Please sign in to comment.