Skip to content

Commit

Permalink
Drop support for Python 2.7 up to 3.6.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Feb 3, 2023
1 parent a27fbfb commit 6ac0489
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 179 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def read(*rnames):
name='z3c.password',
version='2.0.dev0',
author="Stephan Richter, Roger Ineichen and the Zope Community",
author_email="zope3-dev@zope.org",
author_email="zope3-dev@zope.dev",
description="Password generation and verification utility for Zope3",
long_description=(
read('README.rst')
Expand Down Expand Up @@ -60,6 +60,7 @@ def read(*rnames):
include_package_data=True,
package_dir={'': 'src'},
namespace_packages=['z3c'],
python_requires='>=3.7',
extras_require=dict(
test=[
'z3c.coverage',
Expand Down
8 changes: 1 addition & 7 deletions src/z3c/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
# this is a namespace package
try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)
__import__('pkg_resources').declare_namespace(__name__) # pragma: no cover
47 changes: 23 additions & 24 deletions src/z3c/password/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ letters, digits, punctuation, other), and the maximum similarity score.
...
TooManyGroupCharacters: Password contains too many characters of one group (should have at most 6).

>>> from z3c.password._compat import unichr
>>> pwd.verify(unichr(0x0e1)*8)
>>> pwd.verify(chr(0x0e1)*8)
Traceback (most recent call last):
...
TooManyGroupCharacters: Password contains too many characters of one group (should have at most 6).
Expand Down Expand Up @@ -256,17 +255,17 @@ We want to have at least 5 others in the password:
>>> pwd = password.HighSecurityPasswordUtility(seed=8)
>>> pwd.minOthers = 5

>>> pwd.verify('foobar'+unichr(0x0c3)+unichr(0x0c4))
>>> pwd.verify('foobar'+chr(0x0c3)+chr(0x0c4))
Traceback (most recent call last):
...
TooFewGroupCharactersOthers: Password does not contain enough characters of other characters (should have at least 5).

>>> pwd.verify('foobar'+unichr(0x0c3)+unichr(0x0c4)+unichr(0x0e1))
>>> pwd.verify('foobar'+chr(0x0c3)+chr(0x0c4)+chr(0x0e1))
Traceback (most recent call last):
...
TooFewGroupCharactersOthers: Password does not contain enough characters of other characters (should have at least 5).

>>> pwd.verify('fOO'+unichr(0x0e1)*5)
>>> pwd.verify('fOO'+chr(0x0e1)*5)


Generating passwords with others not yet supported
Expand Down Expand Up @@ -339,13 +338,13 @@ Let's now create the field:

>>> pwdField = field.Password(
... __name__='password',
... title=u'Password',
... title='Password',
... checker=pwd)

Let's validate a value:

>>> pwdField.validate(u'fooBar12')
>>> pwdField.validate(u'fooBar')
>>> pwdField.validate('fooBar12')
>>> pwdField.validate('fooBar')
Traceback (most recent call last):
...
TooShortPassword: Password is too short (minimum length: 8).
Expand All @@ -361,29 +360,29 @@ Let's now create a principal:
... principalfolder.InternalPrincipal):
... pass

>>> user = MyPrincipal('srichter', '123123', u'Stephan Richter')
>>> user = MyPrincipal('srichter', '123123', 'Stephan Richter')

Bind the field:

>>> bound = pwdField.bind(user)

>>> bound.validate(u'fooBar12')
>>> bound.validate(u'fooBar')
>>> bound.validate('fooBar12')
>>> bound.validate('fooBar')
Traceback (most recent call last):
...
TooShortPassword: Password is too short (minimum length: 8).

Let's create a principal without the PrincipalMixIn:

>>> user = principalfolder.InternalPrincipal('srichter', '123123',
... u'Stephan Richter')
... 'Stephan Richter')

Bind the field:

>>> bound = pwdField.bind(user)

>>> bound.validate(u'fooBar12')
>>> bound.validate(u'fooBar')
>>> bound.validate('fooBar12')
>>> bound.validate('fooBar')
Traceback (most recent call last):
...
TooShortPassword: Password is too short (minimum length: 8).
Expand All @@ -398,13 +397,13 @@ Recreate the field:

>>> pwdField = field.Password(
... __name__='password',
... title=u'Password',
... title='Password',
... checker='my password checker')

Let's validate a value:

>>> pwdField.validate(u'fooBar12')
>>> pwdField.validate(u'fooBar')
>>> pwdField.validate('fooBar12')
>>> pwdField.validate('fooBar')
Traceback (most recent call last):
...
TooShortPassword: Password is too short (minimum length: 8).
Expand All @@ -416,23 +415,23 @@ No checker specified.

>>> pwdField = field.Password(
... __name__='password',
... title=u'Password')
... title='Password')

Validation silently succeeds with a checker:

>>> pwdField.validate(u'fooBar12')
>>> pwdField.validate(u'fooBar')
>>> pwdField.validate('fooBar12')
>>> pwdField.validate('fooBar')

Bad utility name.

>>> pwdField = field.Password(
... __name__='password',
... title=u'Password',
... title='Password',
... checker='foobar password checker')

Burps on the utility lookup as expected:

>>> pwdField.validate(u'fooBar12')
>>> pwdField.validate('fooBar12')
Traceback (most recent call last):
...
ComponentLookupError:...
Expand All @@ -441,11 +440,11 @@ Bound object does not have the property:

>>> pwdField = field.Password(
... __name__='foobar',
... title=u'Password',
... title='Password',
... checker=pwd)

>>> bound = pwdField.bind(user)

Validation silently succeeds:

>>> bound.validate(u'fooBar12')
>>> bound.validate('fooBar12')
29 changes: 0 additions & 29 deletions src/z3c/password/_compat.py

This file was deleted.

7 changes: 3 additions & 4 deletions src/z3c/password/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,20 @@
import zope.schema

from z3c.password import interfaces
from z3c.password._compat import string_types


class Password(zope.schema.Password):

def __init__(self, checker=None, ignoreEmpty=False, **kw):
self._checker = checker
self._ignoreEmpty = ignoreEmpty
super(Password, self).__init__(**kw)
super().__init__(**kw)

@property
def checker(self):
if self._checker is None:
return None
if not isinstance(self._checker, string_types):
if not isinstance(self._checker, str):
return self._checker
return zope.component.getUtility(
interfaces.IPasswordUtility, self._checker)
Expand All @@ -43,7 +42,7 @@ def validate(self, value):
# but we would want to leave the old password in place
return

super(Password, self).validate(value)
super().validate(value)
old = None
if self.context is not None:
try:
Expand Down
Loading

0 comments on commit 6ac0489

Please sign in to comment.