Update of /cvsroot/webware/Webware/UserKit
In directory usw-pr-cvs1:/tmp/cvs-serv18045/UserKit
Modified Files:
HierRole.py Properties.py Role.py RoleUser.py
RoleUserManager.py RoleUserManagerMixIn.py
RoleUserManagerToFile.py RoleUserManagerToMiddleKit.py User.py
UserManager.py UserManagerToFile.py UserManagerToMiddleKit.py
__init__.py
Log Message:
Changed doc strings to use ''' instead of """
Index: HierRole.py
===================================================================
RCS file: /cvsroot/webware/Webware/UserKit/HierRole.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** HierRole.py 10 Apr 2001 22:24:29 -0000 1.1
--- HierRole.py 20 Jun 2002 17:48:04 -0000 1.2
***************
*** 3,10 ****
class HierRole(Role):
! '''
HierRole is a hierarchical role. It points to its parent roles.
The hierarchy cannot have cycles.
! '''
def __init__(self, name, description=None, superRoles=[]):
--- 3,10 ----
class HierRole(Role):
! """
HierRole is a hierarchical role. It points to its parent roles.
The hierarchy cannot have cycles.
! """
def __init__(self, name, description=None, superRoles=[]):
***************
*** 15,21 ****
def playsRole(self, role):
! '''
Returns 1 if the receiving role plays the role that is passed in. This implementation provides for the inheritance that HierRole supports.
! '''
if self==role:
return 1
--- 15,21 ----
def playsRole(self, role):
! """
Returns 1 if the receiving role plays the role that is passed in. This implementation provides for the inheritance that HierRole supports.
! """
if self==role:
return 1
Index: Properties.py
===================================================================
RCS file: /cvsroot/webware/Webware/UserKit/Properties.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Properties.py 30 Mar 2002 14:37:22 -0000 1.8
--- Properties.py 20 Jun 2002 17:48:04 -0000 1.9
***************
*** 12,14 ****
requiredPyVersion = (2, 0, 0)
! synopsis = '''UserKit provides for the management of users including passwords, user data, server-side archiving and caching.'''
--- 12,14 ----
requiredPyVersion = (2, 0, 0)
! synopsis = """UserKit provides for the management of users including passwords, user data, server-side archiving and caching."""
Index: Role.py
===================================================================
RCS file: /cvsroot/webware/Webware/UserKit/Role.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Role.py 10 Apr 2001 22:21:33 -0000 1.2
--- Role.py 20 Jun 2002 17:48:04 -0000 1.3
***************
*** 1,4 ****
class Role:
! '''
Roles are used in conjuction with RoleUser to provide role-based security. All roles have a name and a description and respond to playsRole().
--- 1,4 ----
class Role:
! """
Roles are used in conjuction with RoleUser to provide role-based security. All roles have a name and a description and respond to playsRole().
***************
*** 11,15 ****
* class HierRole
* class RoleUser
! '''
## Init ##
--- 11,15 ----
* class HierRole
* class RoleUser
! """
## Init ##
***************
*** 47,51 ****
def playsRole(self, role):
! ''' Returns true if the receiving role plays the role passed in. For Role, this is simply a test of equality. Subclasses may override this method to provide richer semantics (such as hierarchical roles). '''
assert isinstance(role, Role)
return self==role
--- 47,51 ----
def playsRole(self, role):
! """ Returns true if the receiving role plays the role passed in. For Role, this is simply a test of equality. Subclasses may override this method to provide richer semantics (such as hierarchical roles). """
assert isinstance(role, Role)
return self==role
Index: RoleUser.py
===================================================================
RCS file: /cvsroot/webware/Webware/UserKit/RoleUser.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** RoleUser.py 16 Apr 2001 21:18:33 -0000 1.4
--- RoleUser.py 20 Jun 2002 17:48:05 -0000 1.5
***************
*** 4,8 ****
class RoleUser(User):
! '''
RoleUser, in conjunction with Role, provides for role-based users and security.
--- 4,8 ----
class RoleUser(User):
! """
RoleUser, in conjunction with Role, provides for role-based users and security.
***************
*** 14,18 ****
* class Role
* class HierRole
! '''
--- 14,18 ----
* class Role
* class HierRole
! """
***************
*** 28,44 ****
def roles(self):
! ''' Returns a direct list of the user's roles. Do not modify. '''
return self._roles
def setRoles(self, listOfRoles):
! '''
Sets all the roles for the user. Each role in the list may be a valid role name or a Role object.
Implementation note: depends on addRoles().
! '''
self._roles = []
self.addRoles(listOfRoles)
def addRoles(self, listOfRoles):
! ''' Adds additional roles for the user. Each role in the list may be a valid role name or a Role object. '''
start = len(self._roles)
self._roles.extend(listOfRoles)
--- 28,44 ----
def roles(self):
! """ Returns a direct list of the user's roles. Do not modify. """
return self._roles
def setRoles(self, listOfRoles):
! """
Sets all the roles for the user. Each role in the list may be a valid role name or a Role object.
Implementation note: depends on addRoles().
! """
self._roles = []
self.addRoles(listOfRoles)
def addRoles(self, listOfRoles):
! """ Adds additional roles for the user. Each role in the list may be a valid role name or a Role object. """
start = len(self._roles)
self._roles.extend(listOfRoles)
***************
*** 56,65 ****
def playsRole(self, roleOrName):
! '''
Returns 1 if the user plays the given role. More specifically, if any of the user's roles return true for role.playsRole(otherRole), this method returns true.
The application of this popular method often looks like this:
if user.playsRole('admin'):
self.displayAdminMenuItems()
! '''
if type(roleOrName) is types.StringType:
roleOrName = self._manager.roleForName(roleOrName)
--- 56,65 ----
def playsRole(self, roleOrName):
! """
Returns 1 if the user plays the given role. More specifically, if any of the user's roles return true for role.playsRole(otherRole), this method returns true.
The application of this popular method often looks like this:
if user.playsRole('admin'):
self.displayAdminMenuItems()
! """
if type(roleOrName) is types.StringType:
roleOrName = self._manager.roleForName(roleOrName)
Index: RoleUserManager.py
===================================================================
RCS file: /cvsroot/webware/Webware/UserKit/RoleUserManager.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** RoleUserManager.py 10 Apr 2001 23:14:27 -0000 1.4
--- RoleUserManager.py 20 Jun 2002 17:48:05 -0000 1.5
***************
*** 4,10 ****
class RoleUserManager(UserManager, RoleUserManagerMixIn):
! '''
See the base classes for more information.
! '''
def __init__(self, userClass=None):
--- 4,10 ----
class RoleUserManager(UserManager, RoleUserManagerMixIn):
! """
See the base classes for more information.
! """
def __init__(self, userClass=None):
Index: RoleUserManagerMixIn.py
===================================================================
RCS file: /cvsroot/webware/Webware/UserKit/RoleUserManagerMixIn.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** RoleUserManagerMixIn.py 10 Apr 2001 23:14:27 -0000 1.1
--- RoleUserManagerMixIn.py 20 Jun 2002 17:48:05 -0000 1.2
***************
*** 5,11 ****
class RoleUserManagerMixIn:
! '''
RoleUserManagerMixIn adds the functionality of keeping a dictionary mapping names to role instances. Several accessor methods are provided for this.
! '''
--- 5,11 ----
class RoleUserManagerMixIn:
! """
RoleUserManagerMixIn adds the functionality of keeping a dictionary mapping names to role instances. Several accessor methods are provided for this.
! """
***************
*** 17,24 ****
def initUserClass(self):
! '''
Invoked by __init__ to set the default user class to
RoleUser.
! '''
self.setUserClass(RoleUser)
--- 17,24 ----
def initUserClass(self):
! """
Invoked by __init__ to set the default user class to
RoleUser.
! """
self.setUserClass(RoleUser)
Index: RoleUserManagerToFile.py
===================================================================
RCS file: /cvsroot/webware/Webware/UserKit/RoleUserManagerToFile.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** RoleUserManagerToFile.py 10 Apr 2001 23:14:27 -0000 1.1
--- RoleUserManagerToFile.py 20 Jun 2002 17:48:05 -0000 1.2
***************
*** 4,10 ****
class RoleUserManagerToFile(UserManagerToFile, RoleUserManagerMixIn):
! '''
See the base classes for more information.
! '''
def __init__(self, userClass=None):
--- 4,10 ----
class RoleUserManagerToFile(UserManagerToFile, RoleUserManagerMixIn):
! """
See the base classes for more information.
! """
def __init__(self, userClass=None):
Index: RoleUserManagerToMiddleKit.py
===================================================================
RCS file: /cvsroot/webware/Webware/UserKit/RoleUserManagerToMiddleKit.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** RoleUserManagerToMiddleKit.py 10 Apr 2001 23:14:27 -0000 1.1
--- RoleUserManagerToMiddleKit.py 20 Jun 2002 17:48:05 -0000 1.2
***************
*** 4,10 ****
class RoleUserManagerToMiddleKit(UserManagerToMiddleKit, RoleUserManagerMixIn):
! '''
See the base classes for more information.
! '''
def __init__(self, userClass=None, store=None, useSQL=None):
--- 4,10 ----
class RoleUserManagerToMiddleKit(UserManagerToMiddleKit, RoleUserManagerMixIn):
! """
See the base classes for more information.
! """
def __init__(self, userClass=None, store=None, useSQL=None):
***************
*** 13,20 ****
def initUserClass(self):
! '''
Overridden to pass on the semantics we inherit from
RoleUsersManagerMixIn. The user class is a MiddleKit issue
for us.
! '''
pass
--- 13,20 ----
def initUserClass(self):
! """
Overridden to pass on the semantics we inherit from
RoleUsersManagerMixIn. The user class is a MiddleKit issue
for us.
! """
pass
Index: User.py
===================================================================
RCS file: /cvsroot/webware/Webware/UserKit/User.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** User.py 12 Nov 2001 13:00:16 -0000 1.7
--- User.py 20 Jun 2002 17:48:05 -0000 1.8
***************
*** 5,11 ****
class User:
! '''
@@ 2001-02-19 ce: docs
! '''
--- 5,11 ----
class User:
! """
@@ 2001-02-19 ce: docs
! """
***************
*** 35,39 ****
def setManager(self, manager):
! ''' Sets the manager, which can only be done once. '''
assert self._manager is None
from UserManager import UserManager
--- 35,39 ----
def setManager(self, manager):
! """ Sets the manager, which can only be done once. """
assert self._manager is None
from UserManager import UserManager
***************
*** 65,69 ****
def setName(self, name):
! ''' Sets the name, which can only be done once. '''
assert self._name is None
self._name = name
--- 65,69 ----
def setName(self, name):
! """ Sets the name, which can only be done once. """
assert self._name is None
self._name = name
***************
*** 96,100 ****
def login(self, password, fromMgr=0):
! ''' Returns self if the login is successful and None otherwise. '''
if not fromMgr:
# Our manager needs to know about this
--- 96,100 ----
def login(self, password, fromMgr=0):
! """ Returns self if the login is successful and None otherwise. """
if not fromMgr:
# Our manager needs to know about this
Index: UserManager.py
===================================================================
RCS file: /cvsroot/webware/Webware/UserKit/UserManager.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** UserManager.py 26 Jul 2001 01:19:20 -0000 1.3
--- UserManager.py 20 Jun 2002 17:48:05 -0000 1.4
***************
*** 5,9 ****
class UserManager:
! '''
A UserManager manages a set of users including authentication, indexing and persistence. Keep in mind that UserManager is abstract; you will always use one of the concrete subclasses (but please read the rest of this doc string):
* UserManagerToFile
--- 5,9 ----
class UserManager:
! """
A UserManager manages a set of users including authentication, indexing and persistence. Keep in mind that UserManager is abstract; you will always use one of the concrete subclasses (but please read the rest of this doc string):
* UserManagerToFile
***************
*** 76,80 ****
Please read the method doc strings and other class documentation to fully understand UserKit.
! '''
## Init ##
--- 76,80 ----
Please read the method doc strings and other class documentation to fully understand UserKit.
! """
## Init ##
***************
*** 93,97 ****
def shutDown(self):
! ''' Performs any tasks necessary to shut down the user manager. Subclasses may override and must invoke super as their *last* step. '''
pass
--- 93,97 ----
def shutDown(self):
! """ Performs any tasks necessary to shut down the user manager. Subclasses may override and must invoke super as their *last* step. """
pass
***************
*** 100,104 ****
def userClass(self):
! ''' Returns the userClass, which is used by createUser. The default value is UserKit.User.User. '''
if self._userClass is None:
from User import User
--- 100,104 ----
def userClass(self):
! """ Returns the userClass, which is used by createUser. The default value is UserKit.User.User. """
if self._userClass is None:
from User import User
***************
*** 107,111 ****
def setUserClass(self, userClass):
! ''' Sets the userClass, which cannot be None and must inherit from User. See also: userClass(). '''
assert type(userClass) is types.ClassType
from User import User
--- 107,111 ----
def setUserClass(self, userClass):
! """ Sets the userClass, which cannot be None and must inherit from User. See also: userClass(). """
assert type(userClass) is types.ClassType
from User import User
***************
*** 135,144 ****
def createUser(self, name, password, userClass=None):
! '''
Returns a newly created user that is added to the manager. If userClass is not specified, the manager's default user class is instantiated.
This not imply that the user is logged in.
This method invokes self.addUser().
See also: userClass(), setUserClass()
! '''
if userClass is None:
userClass = self.userClass()
--- 135,144 ----
def createUser(self, name, password, userClass=None):
! """
Returns a newly created user that is added to the manager. If userClass is not specified, the manager's default user class is instantiated.
This not imply that the user is logged in.
This method invokes self.addUser().
See also: userClass(), setUserClass()
! """
if userClass is None:
userClass = self.userClass()
***************
*** 154,178 ****
def userForSerialNum(self, serialNum, default=NoDefault):
! ''' Returns the user with the given serialNum, pulling that user record into memory if needed. '''
raise SubclassResponsibilityError
def userForExternalId(self, externalId, default=NoDefault):
! ''' Returns the user with the given external id, pulling that user record into memory if needed. '''
raise SubclassResponsibilityError
def userForName(self, name, default=NoDefault):
! ''' Returns the user with the given name, pulling that user record into memory if needed. '''
raise SubclassResponsibilityError
def users(self):
! ''' Returns a list of all users (regardless of login status). '''
raise SubclassResponsibilityError
def numActiveUsers(self):
! ''' Returns the number of active users, e.g., users that are logged in. '''
return self._numActive
def activeUsers(self):
! ''' Returns a list of all active users. '''
raise SubclassResponsibilityError
--- 154,178 ----
def userForSerialNum(self, serialNum, default=NoDefault):
! """ Returns the user with the given serialNum, pulling that user record into memory if needed. """
raise SubclassResponsibilityError
def userForExternalId(self, externalId, default=NoDefault):
! """ Returns the user with the given external id, pulling that user record into memory if needed. """
raise SubclassResponsibilityError
def userForName(self, name, default=NoDefault):
! """ Returns the user with the given name, pulling that user record into memory if needed. """
raise SubclassResponsibilityError
def users(self):
! """ Returns a list of all users (regardless of login status). """
raise SubclassResponsibilityError
def numActiveUsers(self):
! """ Returns the number of active users, e.g., users that are logged in. """
return self._numActive
def activeUsers(self):
! """ Returns a list of all active users. """
raise SubclassResponsibilityError
***************
*** 184,188 ****
def login(self, user, password):
! ''' Returns the user if the login is successful, otherwise returns None. '''
assert isinstance(user, User)
result = user.login(password, fromMgr=1)
--- 184,188 ----
def login(self, user, password):
! """ Returns the user if the login is successful, otherwise returns None. """
assert isinstance(user, User)
result = user.login(password, fromMgr=1)
***************
*** 221,228 ****
def clearCache(self):
! '''
Clears the cache of the manager. Use with extreme caution. If your program maintains a reference to a user object, but the manager loads in a new copy later on, then consistency problems could occur.
The most popular use of this method is in the regression test suite.
! '''
self._cachedUsers = []
self._cachedUsersBySerialNum = {}
--- 221,228 ----
def clearCache(self):
! """
Clears the cache of the manager. Use with extreme caution. If your program maintains a reference to a user object, but the manager loads in a new copy later on, then consistency problems could occur.
The most popular use of this method is in the regression test suite.
! """
self._cachedUsers = []
self._cachedUsersBySerialNum = {}
Index: UserManagerToFile.py
===================================================================
RCS file: /cvsroot/webware/Webware/UserKit/UserManagerToFile.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** UserManagerToFile.py 10 Apr 2001 20:55:44 -0000 1.4
--- UserManagerToFile.py 20 Jun 2002 17:48:06 -0000 1.5
***************
*** 7,15 ****
class UserManagerToFile(UserManager):
! '''
When using this user manager, make sure you invoke setUserDir() and that this directory is writeable by your application. It will contain 1 file per user with the user's serial number as the main filename and an extension of '.user'.
The default user directory is the current working directory, but relying on the current directory is often a bad practice.
! '''
baseOfUserManagerToFile = UserManager
--- 7,15 ----
class UserManagerToFile(UserManager):
! """
When using this user manager, make sure you invoke setUserDir() and that this directory is writeable by your application. It will contain 1 file per user with the user's serial number as the main filename and an extension of '.user'.
The default user directory is the current working directory, but relying on the current directory is often a bad practice.
! """
baseOfUserManagerToFile = UserManager
***************
*** 53,64 ****
def setUserDir(self, userDir):
! ''' Sets the directory where user information is stored. You should strongly consider invoking initNextSerialNum() afterwards. '''
self._userDir = userDir
def loadUser(self, serialNum, default=NoDefault):
! '''
Loads the user with the given serial number from disk.
If there is no such user, a KeyError will be raised unless a default value was passed, in which case that value is returned.
! '''
filename = str(serialNum)+'.user'
filename = os.path.join(self.userDir(), filename)
--- 53,64 ----
def setUserDir(self, userDir):
! """ Sets the directory where user information is stored. You should strongly consider invoking initNextSerialNum() afterwards. """
self._userDir = userDir
def loadUser(self, serialNum, default=NoDefault):
! """
Loads the user with the given serial number from disk.
If there is no such user, a KeyError will be raised unless a default value was passed, in which case that value is returned.
! """
filename = str(serialNum)+'.user'
filename = os.path.join(self.userDir(), filename)
***************
*** 77,83 ****
def scanSerialNums(self):
! '''
Returns a list of all the serial numbers of users found on disk. Serial numbers are always integers.
! '''
chopIndex = -len('.user')
nums = glob(os.path.join(self.userDir(), '*.user'))
--- 77,83 ----
def scanSerialNums(self):
! """
Returns a list of all the serial numbers of users found on disk. Serial numbers are always integers.
! """
chopIndex = -len('.user')
nums = glob(os.path.join(self.userDir(), '*.user'))
***************
*** 91,95 ****
def setUserClass(self, userClass):
! ''' Overridden to mix in UserMixIn to the class that is passed in. '''
from MiscUtils.MixIn import MixIn
MixIn(userClass, UserMixIn)
--- 91,95 ----
def setUserClass(self, userClass):
! """ Overridden to mix in UserMixIn to the class that is passed in. """
from MiscUtils.MixIn import MixIn
MixIn(userClass, UserMixIn)
Index: UserManagerToMiddleKit.py
===================================================================
RCS file: /cvsroot/webware/Webware/UserKit/UserManagerToMiddleKit.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** UserManagerToMiddleKit.py 16 Apr 2001 21:18:33 -0000 1.5
--- UserManagerToMiddleKit.py 20 Jun 2002 17:48:06 -0000 1.6
***************
*** 1,5 ****
! '''
UserManagerToMiddleKit.py
! '''
from UserManager import UserManager
--- 1,5 ----
! """
UserManagerToMiddleKit.py
! """
from UserManager import UserManager
***************
*** 11,15 ****
class UserManagerToMiddleKit(UserManager):
! '''
UserManagerToMiddleKit stores the users in a given MiddleKit object store.
--- 11,15 ----
class UserManagerToMiddleKit(UserManager):
! """
UserManagerToMiddleKit stores the users in a given MiddleKit object store.
***************
*** 35,39 ****
from MyUser import MyUser
userMgr = UserManagerToMiddleKit(userClass=MyUser, store=store)
! '''
--- 35,39 ----
from MyUser import MyUser
userMgr = UserManagerToMiddleKit(userClass=MyUser, store=store)
! """
***************
*** 41,47 ****
def __init__(self, userClass=None, store=None, useSQL=None):
! '''
@@ 2001-02-18 ce: docs
! '''
# If no userClass was specified, try to pull 'User'
# out of the object model.
--- 41,47 ----
def __init__(self, userClass=None, store=None, useSQL=None):
! """
@@ 2001-02-18 ce: docs
! """
# If no userClass was specified, try to pull 'User'
# out of the object model.
***************
*** 91,95 ****
def setUserClass(self, userClass):
! ''' Overridden to verify that our userClass is really a MiddleObject. '''
from MiddleKit.Run.MiddleObject import MiddleObject
assert issubclass(userClass, MiddleObject)
--- 91,95 ----
def setUserClass(self, userClass):
! """ Overridden to verify that our userClass is really a MiddleObject. """
from MiddleKit.Run.MiddleObject import MiddleObject
assert issubclass(userClass, MiddleObject)
Index: __init__.py
===================================================================
RCS file: /cvsroot/webware/Webware/UserKit/__init__.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** __init__.py 10 Apr 2001 23:14:27 -0000 1.4
--- __init__.py 20 Jun 2002 17:48:06 -0000 1.5
***************
*** 8,12 ****
def dont_use_combineManagerClasses(*classesOrNamesThereof):
! '''
----
While this was a nice idea that nearly worked, it broke on keyword arguments to __init__ methods. Fixing it seemed nastier than the next solution: Split RoleUserManager's methods out into RoleUserManagerMixIn, which inherits nothing. Then use the mix-in for the various manager classes, taking care of problems manually in the classes.
--- 8,12 ----
def dont_use_combineManagerClasses(*classesOrNamesThereof):
! """
----
While this was a nice idea that nearly worked, it broke on keyword arguments to __init__ methods. Fixing it seemed nastier than the next solution: Split RoleUserManager's methods out into RoleUserManagerMixIn, which inherits nothing. Then use the mix-in for the various manager classes, taking care of problems manually in the classes.
***************
*** 45,49 ****
self.baseOfFoo.someMethod(self, arg1, arg2)
Yes, that's a little weird. But it's minimal and it empowers this function to create a combination class from orthogonal subclasses of UserManager. I think that if Python had a true "super" feature like Smalltalk and Objective-C, these conventions wouldn't be necessary.
! '''
import types
--- 45,49 ----
self.baseOfFoo.someMethod(self, arg1, arg2)
Yes, that's a little weird. But it's minimal and it empowers this function to create a combination class from orthogonal subclasses of UserManager. I think that if Python had a true "super" feature like Smalltalk and Objective-C, these conventions wouldn't be necessary.
! """
import types
|