Skip to content

Commit

Permalink
Add support for Python 3.7, 3.8 and 3.9.
Browse files Browse the repository at this point in the history
Drop support for Python 3.3 and 3.4.
Lint the code.
  • Loading branch information
Michael Howitz committed Dec 19, 2020
1 parent 7de62d2 commit 6583021
Show file tree
Hide file tree
Showing 29 changed files with 183 additions and 159 deletions.
6 changes: 4 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
Changes
=======

4.0.1 (unreleased)
4.1.0 (unreleased)
------------------

- Nothing changed yet.
- Add support for Python 3.7, 3.8 and 3.9.

- Drop support for Python 3.3 and 3.4.


4.0.0 (2017-05-02)
Expand Down
38 changes: 19 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@
# When developing and releasing this package, please follow the documented
# Zope Toolkit policies as described by this documentation.
##############################################################################
"""Setup for zope.app.authentication package
$Id$
"""
"""Setup for zope.app.authentication package."""
import os
from setuptools import setup, find_packages


def read(*rnames):
with open(os.path.join(os.path.dirname(__file__), *rnames)) as f:
return f.read()


tests_require = [
'zope.app.security >= 4.0',
'zope.app.rotterdam >= 4.0',
Expand All @@ -49,22 +48,22 @@ def read(*rnames):
]

setup(name='zope.app.authentication',
version='4.0.1.dev0',
version='4.1.0.dev0',
author='Zope Corporation and Contributors',
author_email='zope-dev@zope.org',
description=('Principals and groups management for '
'the pluggable authentication utility'),
long_description=(
read('README.rst')
+ '\n\n.. contents::\n\n' +
read('src', 'zope', 'app', 'authentication', 'README.rst')
+ '\n\n' +
read('src', 'zope', 'app', 'authentication', 'principalfolder.rst')
+ '\n\n' +
read('src', 'zope', 'app', 'authentication', 'vocabulary.rst')
+ '\n\n' +
read('CHANGES.rst')
),
read('README.rst')
+ '\n\n.. contents::\n\n' +
read('src', 'zope', 'app', 'authentication', 'README.rst')
+ '\n\n' +
read('src', 'zope', 'app', 'authentication', 'principalfolder.rst')
+ '\n\n' +
read('src', 'zope', 'app', 'authentication', 'vocabulary.rst')
+ '\n\n' +
read('CHANGES.rst')
),
url='http://github.com/zopefoundation/zope.app.authentication',
license='ZPL 2.1',
classifiers=[
Expand All @@ -76,10 +75,11 @@ def read(*rnames):
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: Implementation',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
Expand Down Expand Up @@ -116,7 +116,7 @@ def read(*rnames):
# Needed for browser code.
'zope.app.container >= 4.0.0',
'zope.app.component >= 4.0.0',
],
],
include_package_data=True,
zip_safe=False,
)
)
2 changes: 1 addition & 1 deletion src/zope/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__import__('pkg_resources').declare_namespace(__name__) # pragma: no cover
__import__('pkg_resources').declare_namespace(__name__) # pragma: no cover
2 changes: 1 addition & 1 deletion src/zope/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__import__('pkg_resources').declare_namespace(__name__) # pragma: no cover
__import__('pkg_resources').declare_namespace(__name__) # pragma: no cover
18 changes: 10 additions & 8 deletions src/zope/app/authentication/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,30 @@
from zope.location.interfaces import ILocation
from zope.app.authentication import interfaces

### BBB using zope.pluggableauth
from zope.pluggableauth import PluggableAuthentication
# BBB using zope.pluggableauth
from zope.pluggableauth import PluggableAuthentication # noqa: F401 BBB
from zope.pluggableauth.interfaces import (
IQueriableAuthenticator, IPluggableAuthentication)


@component.adapter(
interfaces.IQuerySchemaSearch,
IPluggableAuthentication)
interfaces.IQuerySchemaSearch,
IPluggableAuthentication)
@zope.interface.implementer(
ILocation,
IQueriableAuthenticator,
interfaces.IQuerySchemaSearch)
ILocation,
IQueriableAuthenticator,
interfaces.IQuerySchemaSearch)
class QuerySchemaSearchAdapter(object):
"""Performs schema-based principal searches on behalf of a PAU.
Delegates the search to the adapted authenticator (which also provides
IQuerySchemaSearch) and prepends the PAU prefix to the resulting principal
IDs.
"""

def __init__(self, authplugin, pau):
if (ILocation.providedBy(authplugin) and
authplugin.__parent__ is not None):
authplugin.__parent__ is not None):
# Checking explicitly for the parent, because providing ILocation
# basically means that the object *could* be located. It doesn't
# say the object must be located.
Expand Down
1 change: 1 addition & 0 deletions src/zope/app/authentication/browser/adding.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from zope.traversing.browser.absoluteurl import absoluteURL


class Adding(zope.app.container.browser.adding.Adding):

def nextURL(self):
Expand Down
20 changes: 10 additions & 10 deletions src/zope/app/authentication/browser/granting.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class GrantWidget(RadioWidget):
_tdTemplate = (
u'\n<td class="%s">\n<center>\n<label for="%s" title="%s">\n'
u'%s\n</label>\n</center>\n</td>\n'
)
)

def __call__(self):
"""See IBrowserWidget."""
Expand All @@ -87,7 +87,7 @@ def renderItem(self, index, text, value, name, cssClass):
id=id,
cssClass=cssClass,
type='radio',
extra = 'onclick="changeMatrix(this);"')
extra='onclick="changeMatrix(this);"')
return self._tdTemplate % (tdClass, id, text, elem)

def renderSelectedItem(self, index, text, value, name, cssClass):
Expand All @@ -106,15 +106,15 @@ def renderSelectedItem(self, index, text, value, name, cssClass):
cssClass=cssClass,
checked="checked",
type='radio',
extra = 'onclick="changeMatrix(this);"')
extra='onclick="changeMatrix(this);"')
return self._tdTemplate % (tdClass, id, text, elem)

def renderItems(self, value):
# check if we want to select first item, the previously selected item
# or the "no value" item.
if (value == self.context.missing_value
and getattr(self, 'firstItem', False)
and len(self.vocabulary) > 0):
and len(self.vocabulary) > 0):
if self.context.required:
# Grab the first item from the iterator:
values = [next(iter(self.vocabulary)).value]
Expand All @@ -131,13 +131,12 @@ def renderValue(self, value):
return " ".join(rendered_items)



class Granting(object):

principal = None

principal_field = zope.schema.Choice(
__name__ = 'principal',
__name__='principal',
source=PrincipalSource(),
required=True)

Expand All @@ -162,7 +161,8 @@ def status(self):
# Make sure we can use the principal id in a form by base64ing it
principal_str = text_type(principal)
principal_bytes = principal_str.encode('utf-8')
principal_token = base64.b64encode(principal_bytes).strip().replace(b'=', b'_')
principal_token = base64.b64encode(
principal_bytes).strip().replace(b'=', b'_')
if not isinstance(principal_token, str):
principal_token = principal_token.decode('utf-8')

Expand All @@ -173,7 +173,7 @@ def status(self):
self.roles = []
for role in roles:
name = principal_token + '.role.' + role.id
field = zope.schema.Choice(__name__= name,
field = zope.schema.Choice(__name__=name,
title=role.title,
vocabulary=settings_vocabulary)
setUpWidget(self, name, field, IInputWidget,
Expand Down Expand Up @@ -206,7 +206,7 @@ def status(self):
if role_widget.hasInput():
try:
setting = role_widget.getInputValue()
except MissingInputError: # pragma: no cover
except MissingInputError: # pragma: no cover
pass
else:
# Arrgh!
Expand All @@ -228,7 +228,7 @@ def status(self):
if perm_widget.hasInput():
try:
setting = perm_widget.getInputValue()
except MissingInputError: # pragma: no cover
except MissingInputError: # pragma: no cover
pass
else:
# Arrgh!
Expand Down
3 changes: 2 additions & 1 deletion src/zope/app/authentication/browser/loginform.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""
from zope.authentication.interfaces import IUnauthenticatedPrincipal


class LoginForm(object):
"""Mix-in class to implement login form logic"""

Expand Down Expand Up @@ -43,4 +44,4 @@ def __call__(self):
request.response.redirect(camefrom or '.')
return ''

return self.index() # call template
return self.index() # call template
1 change: 1 addition & 0 deletions src/zope/app/authentication/browser/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from zope.app.component.browser.registration import AddUtilityRegistration
from zope.authentication.interfaces import IAuthentication


class AddAuthenticationRegistration(AddUtilityRegistration):

label = _("Register a pluggable authentication utility")
Expand Down
18 changes: 11 additions & 7 deletions src/zope/app/authentication/browser/rolepermissionview.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from zope.securitypolicy.interfaces import Unset, Allow, Deny
from zope.securitypolicy.interfaces import IRole, IRolePermissionManager


class RolePermissionView(object):

_pagetip = _("""For each permission you want to grant (or deny) to a role,
Expand Down Expand Up @@ -92,21 +93,22 @@ def roleForID(self, rid):
role = getUtility(IRole, rid)
return RolePermissions(role, self.context.__parent__, permissions)


def update(self, testing=None):
status = ''
changed = False

if 'SUBMIT' in self.request:
roles = [r.id for r in self.roles()]
roles = [r.id for r in self.roles()]
permissions = [p.id for p in self.permissions()]
prm = IRolePermissionManager(self.context.__parent__)
prm = IRolePermissionManager(self.context.__parent__)
for ip in range(len(permissions)):
rperm = self.request.get("p%s" % ip)
if rperm not in permissions: continue
if rperm not in permissions:
continue
for ir in range(len(roles)):
rrole = self.request.get("r%s" % ir)
if rrole not in roles: continue
if rrole not in roles:
continue
setting = self.request.get("p%sr%s" % (ip, ir), None)
if setting is not None:
if setting == Unset.getName():
Expand All @@ -116,7 +118,8 @@ def update(self, testing=None):
elif setting == Deny.getName():
prm.denyPermissionToRole(rperm, rrole)
else:
raise ValueError("Incorrect setting: %s" % setting) # pragma: no cover
raise ValueError("Incorrect setting: %s" %
setting) # pragma: no cover
changed = True

if 'SUBMIT_PERMS' in self.request:
Expand Down Expand Up @@ -149,7 +152,7 @@ def update(self, testing=None):
permission.title, context=self.request)
msg = _('You choose both allow and deny for permission'
' "${permission}". This is not allowed.',
mapping = {'permission': permission_translated})
mapping={'permission': permission_translated})
raise UserError(msg)
if rperm in allowed:
prm.grantPermissionToRole(rperm, role_id)
Expand Down Expand Up @@ -201,6 +204,7 @@ def roleSettings(self):
nosetting = Unset.getName()
return [settings.get(role.id, nosetting) for role in self._roles]


@implementer(IRole)
class RolePermissions(object):

Expand Down
11 changes: 6 additions & 5 deletions src/zope/app/authentication/browser/schemasearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
source_label = _(u"Source path")
source_title = _(u"Path to the source utility")


@implementer(ISourceQueryView)
class QuerySchemaSearchView(object):

Expand Down Expand Up @@ -82,7 +83,7 @@ def render(self, name):
html.append(' <div class="field">')
html.append(' %s' % widget())

if widget.error(): # pragma: no cover
if widget.error(): # pragma: no cover
html.append(' <div class="error">')
html.append(' %s' % widget.error())
html.append(' </div>')
Expand All @@ -94,7 +95,7 @@ def render(self, name):
html.append('<div class="row">')
html.append(' <div class="field">')
html.append(' <input type="submit" name="%s" value="%s" />'
% (name+'.search',
% (name+'.search',
translate(search_label, context=self.request)))
html.append(' </div>')
html.append('</div>')
Expand All @@ -116,11 +117,11 @@ def results(self, name):
if widget.hasInput():
try:
data[widget_name] = widget.getInputValue()
except InputErrors as error: # pragma: no cover
except InputErrors as error: # pragma: no cover
errors.append(error)
elif field.required: # pragma: no cover
elif field.required: # pragma: no cover
errors.append(MissingInputError(
widget_name, widget.label, 'the field is required'))
if errors: # pragma: no cover
if errors: # pragma: no cover
raise WidgetsError(errors, widgetsData=data)
return self.context.search(data)
6 changes: 6 additions & 0 deletions src/zope/app/authentication/browser/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def provideUtility(provided, utility, name=''):
gsm = component.getGlobalSiteManager()
gsm.registerUtility(utility, provided, name, event=False)


stypes = list, tuple


def provideAdapter(required, provided, factory, name='', using=None, **kw):
assert 'with' not in kw
assert not isinstance(factory, stypes), "Factory cannot be a list or tuple"
Expand All @@ -37,16 +40,19 @@ def provideAdapter(required, provided, factory, name='', using=None, **kw):

gsm.registerAdapter(factory, required, provided, name, event=False)


def browserView(for_, name, factory, layer=IDefaultBrowserLayer,
providing=Interface):
"""Define a global browser view
"""
provideAdapter(for_, providing, factory, name, (layer,))


def browserViewProviding(for_, factory, providing, layer=IDefaultBrowserLayer):
"""Define a view providing a particular interface."""
return browserView(for_, '', factory, layer, providing)


def provideMultiView(for_, type, providing, name, factory, layer=None):
if layer is None:
layer = type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from zope.securitypolicy.interfaces import IRolePermissionMap
from zope.securitypolicy.securitymap import SecurityMap


@implementer(IRolePermissionManager, IRolePermissionMap)
class RolePermissionManager(object):
"""
Expand Down
Loading

0 comments on commit 6583021

Please sign in to comment.