Skip to content

Commit

Permalink
Lint the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Feb 3, 2021
1 parent fc04af0 commit a1b7ec8
Show file tree
Hide file tree
Showing 27 changed files with 66 additions and 191 deletions.
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -59,7 +59,8 @@ def _package_doc(name):
'Products.PluggableAuthService'),
},
license='ZPL 2.1 (http://www.zope.org/Resources/License/ZPL-2.1)',
packages=find_packages(),
packages=find_packages('src'),
package_dir={'': 'src'},
include_package_data=True,
namespace_packages=['Products'],
zip_safe=False,
Expand Down
3 changes: 0 additions & 3 deletions src/Products/PluggableAuthService/Extensions/basic_auth.py
Expand Up @@ -16,7 +16,6 @@


def extraction(self, request):

""" Fetch HTTP Basic Auth credentials from the request.
"""
creds = request._authUserPW()
Expand All @@ -30,7 +29,6 @@ def extraction(self, request):


def authentication(self, credentials):

""" Authenticate against nested acl_users.
"""
real_user_folder = self.simple_uf.acl_users
Expand All @@ -44,7 +42,6 @@ def authentication(self, credentials):


def authorize(self, user):

""" Fetch user roles from nested acl_users.
"""
real_user_folder = self.simple_uf.acl_users
Expand Down
22 changes: 4 additions & 18 deletions src/Products/PluggableAuthService/PluggableAuthService.py
Expand Up @@ -113,7 +113,6 @@ class DumbHTTPExtractor(Implicit):

@security.private
def extractCredentials(self, request):

""" Pull HTTP credentials out of the request.
"""
creds = {}
Expand Down Expand Up @@ -146,7 +145,6 @@ class EmergencyUserAuthenticator(Implicit):

@security.private
def authenticateCredentials(self, credentials):

""" Check credentials against the emergency user.
"""
if isinstance(credentials, dict):
Expand Down Expand Up @@ -195,7 +193,7 @@ class PluggableAuthService(Folder, Cacheable):
dict(id='title', type='string', mode='w', label='Title'),
dict(id='login_transform', type='string', mode='w',
label='Transform to apply to login name'),
)
)

def getId(self):

Expand All @@ -206,7 +204,6 @@ def getId(self):
#
@security.protected(ManageUsers)
def getUser(self, name):

""" See IUserFolder.
"""
plugins = self._getOb('plugins')
Expand All @@ -221,7 +218,6 @@ def getUser(self, name):

@security.protected(ManageUsers)
def getUserById(self, id, default=None):

""" See IUserFolder.
"""
plugins = self._getOb('plugins')
Expand All @@ -235,7 +231,6 @@ def getUserById(self, id, default=None):

@security.public
def validate(self, request, auth='', roles=_noroles):

""" See IUserFolder.
"""
plugins = self._getOb('plugins')
Expand Down Expand Up @@ -511,7 +506,6 @@ def _getBatchLink(self, qs, old_start, new_start):
#
@security.private
def _isNotCompetent(self, request, plugins):

""" return true when this user folder should not try authentication.
Never called for top level user folder.
Expand All @@ -535,7 +529,6 @@ def _isNotCompetent(self, request, plugins):

@security.private
def _extractUserIds(self, request, plugins):

""" request -> [validated_user_id]
o For each set of extracted credentials, try to authenticate
Expand Down Expand Up @@ -585,7 +578,7 @@ def _extractUserIds(self, request, plugins):
# First try to authenticate against the emergency
# user and return immediately if authenticated
user_id, name = self._tryEmergencyUserAuthentication(
credentials)
credentials)

if user_id is not None:
return [(user_id, name)]
Expand Down Expand Up @@ -616,7 +609,7 @@ def _extractUserIds(self, request, plugins):
except _SWALLOWABLE_PLUGIN_EXCEPTIONS:
reraise(auth)
msg = 'AuthenticationPlugin %s error' % (
authenticator_id,)
authenticator_id,)
logger.debug(msg, exc_info=True)
continue

Expand All @@ -631,7 +624,7 @@ def _extractUserIds(self, request, plugins):

# Emergency user via HTTP basic auth always wins
user_id, name = self._tryEmergencyUserAuthentication(
DumbHTTPExtractor().extractCredentials(request))
DumbHTTPExtractor().extractCredentials(request))

if user_id is not None:
return [(user_id, name)]
Expand All @@ -640,7 +633,6 @@ def _extractUserIds(self, request, plugins):

@security.private
def _tryEmergencyUserAuthentication(self, credentials):

""" credentials -> emergency_user or None
"""
try:
Expand Down Expand Up @@ -677,7 +669,6 @@ def _getGroupsForPrincipal(self, principal, request=None, plugins=None,

@security.private
def _createAnonymousUser(self, plugins):

""" Allow IAnonymousUserFactoryPlugins to create or fall back.
"""
factories = plugins.listPlugins(IAnonymousUserFactoryPlugin)
Expand All @@ -693,7 +684,6 @@ def _createAnonymousUser(self, plugins):

@security.private
def _createUser(self, plugins, user_id, name):

""" Allow IUserFactoryPlugins to create, or fall back to default.
"""
name = self.applyTransform(name)
Expand All @@ -710,7 +700,6 @@ def _createUser(self, plugins, user_id, name):

@security.private
def _findUser(self, plugins, user_id, name=None, request=None):

""" user_id -> decorated_user
"""
if user_id == self._emergency_user.getUserName():
Expand Down Expand Up @@ -807,7 +796,6 @@ def _verifyUser(self, plugins, user_id=None, login=None):
@security.private
def _authorizeUser(self, user, accessed, container, name, value,
roles=_noroles):

""" -> boolean (whether user has roles).
o Add the user to the SM's stack, if successful.
Expand Down Expand Up @@ -837,7 +825,6 @@ def _authorizeUser(self, user, accessed, container, name, value,

@security.private
def _isTop(self):

""" Are we the user folder in the root object?
"""
try:
Expand All @@ -850,7 +837,6 @@ def _isTop(self):

@security.private
def _getObjectContext(self, v, request):

""" request -> (a, c, n, v)
o 'a 'is the object the object was accessed through
Expand Down
16 changes: 3 additions & 13 deletions src/Products/PluggableAuthService/PropertiedUser.py
Expand Up @@ -29,6 +29,7 @@ class PropertiedUser(BasicUser):

""" User objects which manage propertysheets, obtained from decorators.
"""

def __init__(self, id, login=None):

self._id = id
Expand All @@ -46,19 +47,16 @@ def __init__(self, id, login=None):
# BasicUser's public interface
#
def getId(self):

""" -> user ID
"""
return self._id

def getUserName(self):

""" -> login name
"""
return self._login

def getRoles(self):

""" -> [role]
o Include only "global" roles.
Expand All @@ -73,7 +71,6 @@ def getGroups(self):
return list(self._groups.keys())

def getDomains(self):

""" -> [domain]
o The list represents the only domains from which the user is
Expand All @@ -82,7 +79,6 @@ def getDomains(self):
return ()

def getRolesInContext(self, object):

""" Return the list of roles assigned to the user.
o Include local roles assigned in context of the passed-in object.
Expand All @@ -102,7 +98,7 @@ def getRolesInContext(self, object):
local = {}
object = aq_inner(object)

while 1:
while True:

local_roles = getattr(object, '__ac_local_roles__', None)

Expand Down Expand Up @@ -136,7 +132,6 @@ def getRolesInContext(self, object):
return list(self.getRoles()) + list(local.keys())

def allowed(self, object, object_roles=None):

""" Check whether the user has access to object.
o The user must have one of the roles in object_roles to allow access.
Expand Down Expand Up @@ -189,7 +184,7 @@ def allowed(self, object, object_roles=None):
principal_ids = list(group_ids)
principal_ids.insert(0, user_id)

while 1:
while True:

local_roles = getattr(inner_obj, '__ac_local_roles__', None)

Expand Down Expand Up @@ -234,7 +229,6 @@ def allowed(self, object, object_roles=None):
# Interfaces to allow user folder plugins to annotate the user.
#
def _addGroups(self, groups=()):

""" Extend our set of groups.
o Don't complain about duplicates.
Expand All @@ -243,7 +237,6 @@ def _addGroups(self, groups=()):
self._groups[group] = 1

def _addRoles(self, roles=()):

""" Extend our set of roles.
o Don't complain about duplicates.
Expand All @@ -255,13 +248,11 @@ def _addRoles(self, roles=()):
# Propertysheet management
#
def listPropertysheets(self):

""" -> [propertysheet_id]
"""
return list(self._propertysheets.keys())

def getPropertysheet(self, id):

""" id -> sheet
o Raise KeyError if no such seet exists.
Expand All @@ -271,7 +262,6 @@ def getPropertysheet(self, id):
__getitem__ = getPropertysheet

def addPropertysheet(self, id, data):

""" Add a new propertysheet.
o Raise KeyError if a sheet of the given ID already exists.
Expand Down
8 changes: 0 additions & 8 deletions src/Products/PluggableAuthService/UserPropertySheet.py
Expand Up @@ -112,33 +112,28 @@ def __init__(self, id, schema=None, **kw):
# IPropertySheet implementation
#
def getId(self):

""" See IPropertySheet.
"""
return self._id

def hasProperty(self, id):

""" See IPropertySheet.
"""
return id in self.propertyIds()

def getProperty(self, id, default=None):

""" See IPropertySheet.
"""
return self._properties.get(id, default)

def getPropertyType(self, id):

""" See IPropertySheet.
"""
found = [x[1] for x in self._schema if x[0] == id]

return found and found[0] or None

def propertyInfo(self, id):

""" See IPropertySheet.
"""
for schema_id, ptype in self._schema:
Expand All @@ -149,7 +144,6 @@ def propertyInfo(self, id):
return None

def propertyMap(self):

""" See IPropertySheet.
"""
result = []
Expand All @@ -160,13 +154,11 @@ def propertyMap(self):
return tuple(result)

def propertyIds(self):

""" See IPropertySheet.
"""
return [x[0] for x in self._schema]

def propertyValues(self):

""" See IPropertySheet.
"""
return [self._properties.get(x) for x in self.propertyIds()]
Expand Down

0 comments on commit a1b7ec8

Please sign in to comment.