Commit 139e1102 authored by 's avatar

Some cosmetic changes (in preparation for creating z3 interfaces):

- docstring cleanup
- whitespace cleanup
- import cleanup
parent e2dae3e0
...@@ -19,6 +19,7 @@ import Globals, urlparse, SpecialUsers, ExtensionClass ...@@ -19,6 +19,7 @@ import Globals, urlparse, SpecialUsers, ExtensionClass
from AccessControl import getSecurityManager, Unauthorized from AccessControl import getSecurityManager, Unauthorized
from Acquisition import aq_get, aq_parent, aq_base from Acquisition import aq_get, aq_parent, aq_base
UnownableOwner=[] UnownableOwner=[]
def ownableFilter(self): def ownableFilter(self):
_owner = aq_get(self, '_owner', None, 1) _owner = aq_get(self, '_owner', None, 1)
...@@ -137,9 +138,11 @@ class Owned(ExtensionClass.Base): ...@@ -137,9 +138,11 @@ class Owned(ExtensionClass.Base):
changeOwnership__roles__=() changeOwnership__roles__=()
def changeOwnership(self, user, recursive=0): def changeOwnership(self, user, recursive=0):
"""Change the ownership to the given user. If 'recursive' is """Change the ownership to the given user.
true then also take ownership of all sub-objects, otherwise
sub-objects retain their ownership information.""" If 'recursive' is true then also take ownership of all sub-objects,
otherwise sub-objects retain their ownership information.
"""
new=ownerInfo(user) new=ownerInfo(user)
if new is None: return # Special user! if new is None: return # Special user!
...@@ -167,9 +170,9 @@ class Owned(ExtensionClass.Base): ...@@ -167,9 +170,9 @@ class Owned(ExtensionClass.Base):
return security.checkPermission('Take ownership', self) return security.checkPermission('Take ownership', self)
def manage_takeOwnership(self, REQUEST, RESPONSE, recursive=0): def manage_takeOwnership(self, REQUEST, RESPONSE, recursive=0):
""" """Take ownership (responsibility) for an object.
Take ownership (responsibility) for an object. If 'recursive'
is true, then also take ownership of all sub-objects. If 'recursive' is true, then also take ownership of all sub-objects.
""" """
security=getSecurityManager() security=getSecurityManager()
want_referer=REQUEST['URL1']+'/manage_owner' want_referer=REQUEST['URL1']+'/manage_owner'
...@@ -261,13 +264,16 @@ class Owned(ExtensionClass.Base): ...@@ -261,13 +264,16 @@ class Owned(ExtensionClass.Base):
except: pass except: pass
if s is None: object._p_deactivate() if s is None: object._p_deactivate()
Globals.default__class_init__(Owned) Globals.default__class_init__(Owned)
class EmergencyUserCannotOwn(Exception): class EmergencyUserCannotOwn(Exception):
"The emergency user cannot own anything" "The emergency user cannot own anything"
class EditUnowned(Exception): class EditUnowned(Exception):
"Can't edit unowned executables" "Can't edit unowned executables"
......
...@@ -15,15 +15,21 @@ ...@@ -15,15 +15,21 @@
Sometimes, we need an object's permissions to be remapped to other permissions Sometimes, we need an object's permissions to be remapped to other permissions
when the object is used in specual ways. This is rather hard, since we when the object is used in specual ways. This is rather hard, since we
need the object's ordinary permissions intact so we can manage it. need the object's ordinary permissions intact so we can manage it.
$Id$
""" """
from cgi import escape
import ExtensionClass, Acquisition import ExtensionClass, Acquisition
from Permission import pname
from Owned import UnownableOwner
from Globals import InitializeClass from Globals import InitializeClass
from cgi import escape
from Owned import UnownableOwner
from Permission import pname
class RoleManager: class RoleManager:
def manage_getPermissionMapping(self): def manage_getPermissionMapping(self):
"""Return the permission mapping for the object """Return the permission mapping for the object
...@@ -96,6 +102,8 @@ class RoleManager: ...@@ -96,6 +102,8 @@ class RoleManager:
base=getattr(p, 'aq_base', None) base=getattr(p, 'aq_base', None)
return type(base) is PermissionMapper return type(base) is PermissionMapper
InitializeClass(RoleManager)
def getPermissionMapping(name, obj, st=type('')): def getPermissionMapping(name, obj, st=type('')):
obj=getattr(obj, 'aq_base', obj) obj=getattr(obj, 'aq_base', obj)
...@@ -148,5 +156,3 @@ class Rewrapper(ExtensionClass.Base): ...@@ -148,5 +156,3 @@ class Rewrapper(ExtensionClass.Base):
Acquisition.ImplicitAcquisitionWrapper( Acquisition.ImplicitAcquisitionWrapper(
w, parent)) w, parent))
return apply(self, args, kw) return apply(self, args, kw)
InitializeClass(RoleManager)
...@@ -14,12 +14,14 @@ ...@@ -14,12 +14,14 @@
$Id$ $Id$
""" """
from cgi import escape
from Globals import DTMLFile, MessageDialog, Dictionary from Globals import DTMLFile, MessageDialog, Dictionary
from Acquisition import Implicit, Acquired, aq_get from Acquisition import Implicit, Acquired, aq_get
import Globals, ExtensionClass, PermissionMapping, Products import Globals, ExtensionClass, PermissionMapping, Products
from Permission import Permission
from App.Common import aq_base from App.Common import aq_base
from cgi import escape
from Permission import Permission
DEFAULTMAXLISTUSERS=250 DEFAULTMAXLISTUSERS=250
...@@ -30,7 +32,9 @@ def _isBeingUsedAsAMethod(self): ...@@ -30,7 +32,9 @@ def _isBeingUsedAsAMethod(self):
def _isNotBeingUsedAsAMethod(self): def _isNotBeingUsedAsAMethod(self):
return not aq_get(self, '_isBeingUsedAsAMethod_', 0) return not aq_get(self, '_isBeingUsedAsAMethod_', 0)
class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
"""An object that has configurable permissions""" """An object that has configurable permissions"""
__ac_permissions__=( __ac_permissions__=(
...@@ -89,9 +93,10 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -89,9 +93,10 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
return tuple(r) return tuple(r)
def permission_settings(self, permission=None): def permission_settings(self, permission=None):
"""Return user-role permission settings. If 'permission' """Return user-role permission settings.
is passed to the method then only the settings for 'permission'
is returned. If 'permission' is passed to the method then only the settings for
'permission' is returned.
""" """
result=[] result=[]
valid=self.valid_roles() valid=self.valid_roles()
...@@ -127,7 +132,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -127,7 +132,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
help_product='OFSP') help_product='OFSP')
def manage_role(self, role_to_manage, permissions=[], REQUEST=None): def manage_role(self, role_to_manage, permissions=[], REQUEST=None):
"Change the permissions given to the given role" """Change the permissions given to the given role.
"""
self._isBeingUsedAsAMethod(REQUEST, 0) self._isBeingUsedAsAMethod(REQUEST, 0)
for p in self.ac_inherited_permissions(1): for p in self.ac_inherited_permissions(1):
name, value = p[:2] name, value = p[:2]
...@@ -142,7 +148,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -142,7 +148,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
help_product='OFSP') help_product='OFSP')
def manage_acquiredPermissions(self, permissions=[], REQUEST=None): def manage_acquiredPermissions(self, permissions=[], REQUEST=None):
"Change the permissions that acquire" """Change the permissions that acquire.
"""
self._isBeingUsedAsAMethod(REQUEST, 0) self._isBeingUsedAsAMethod(REQUEST, 0)
for p in self.ac_inherited_permissions(1): for p in self.ac_inherited_permissions(1):
name, value = p[:2] name, value = p[:2]
...@@ -161,11 +168,12 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -161,11 +168,12 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
def manage_permission(self, permission_to_manage, def manage_permission(self, permission_to_manage,
roles=[], acquire=0, REQUEST=None): roles=[], acquire=0, REQUEST=None):
"""Change the settings for the given permission """Change the settings for the given permission.
If optional arg acquire is true, then the roles for the permission If optional arg acquire is true, then the roles for the permission
are acquired, in addition to the ones specified, otherwise the are acquired, in addition to the ones specified, otherwise the
permissions are restricted to only the designated roles.""" permissions are restricted to only the designated roles.
"""
self._isBeingUsedAsAMethod(REQUEST, 0) self._isBeingUsedAsAMethod(REQUEST, 0)
for p in self.ac_inherited_permissions(1): for p in self.ac_inherited_permissions(1):
name, value = p[:2] name, value = p[:2]
...@@ -186,7 +194,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -186,7 +194,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
_method_manage_access=DTMLFile('dtml/methodAccess', globals()) _method_manage_access=DTMLFile('dtml/methodAccess', globals())
def manage_access(self, REQUEST, **kw): def manage_access(self, REQUEST, **kw):
"Return an interface for making permissions settings" """Return an interface for making permissions settings.
"""
if hasattr(self, '_isBeingUsedAsAMethod') and \ if hasattr(self, '_isBeingUsedAsAMethod') and \
self._isBeingUsedAsAMethod(): self._isBeingUsedAsAMethod():
return apply(self._method_manage_access,(), kw) return apply(self._method_manage_access,(), kw)
...@@ -194,7 +203,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -194,7 +203,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
return apply(self._normal_manage_access,(), kw) return apply(self._normal_manage_access,(), kw)
def manage_changePermissions(self, REQUEST): def manage_changePermissions(self, REQUEST):
"Change all permissions settings, called by management screen" """Change all permissions settings, called by management screen.
"""
self._isBeingUsedAsAMethod(REQUEST, 0) self._isBeingUsedAsAMethod(REQUEST, 0)
valid_roles=self.valid_roles() valid_roles=self.valid_roles()
indexes=range(len(valid_roles)) indexes=range(len(valid_roles))
...@@ -223,9 +233,9 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -223,9 +233,9 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
message='Your changes have been saved', message='Your changes have been saved',
action ='manage_access') action ='manage_access')
def permissionsOfRole(self, role): def permissionsOfRole(self, role):
"used by management screen" """Used by management screen.
"""
r=[] r=[]
for p in self.ac_inherited_permissions(1): for p in self.ac_inherited_permissions(1):
name, value = p[:2] name, value = p[:2]
...@@ -237,7 +247,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -237,7 +247,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
return r return r
def rolesOfPermission(self, permission): def rolesOfPermission(self, permission):
"used by management screen" """Used by management screen.
"""
valid_roles=self.valid_roles() valid_roles=self.valid_roles()
for p in self.ac_inherited_permissions(1): for p in self.ac_inherited_permissions(1):
name, value = p[:2] name, value = p[:2]
...@@ -255,7 +266,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -255,7 +266,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
"The permission <em>%s</em> is invalid." % escape(permission)) "The permission <em>%s</em> is invalid." % escape(permission))
def acquiredRolesAreUsedBy(self, permission): def acquiredRolesAreUsedBy(self, permission):
"used by management screen" """Used by management screen.
"""
for p in self.ac_inherited_permissions(1): for p in self.ac_inherited_permissions(1):
name, value = p[:2] name, value = p[:2]
if name==permission: if name==permission:
...@@ -380,14 +392,12 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -380,14 +392,12 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
stat='Your changes have been saved.' stat='Your changes have been saved.'
return self.manage_listLocalRoles(self, REQUEST, stat=stat) return self.manage_listLocalRoles(self, REQUEST, stat=stat)
#------------------------------------------------------------ #------------------------------------------------------------
access_debug_info__roles__=() access_debug_info__roles__=()
def access_debug_info(self): def access_debug_info(self):
"Return debug info" """Return debug info.
"""
clas=class_attrs(self) clas=class_attrs(self)
inst=instance_attrs(self) inst=instance_attrs(self)
data=[] data=[]
...@@ -407,7 +417,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -407,7 +417,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
return data return data
def valid_roles(self): def valid_roles(self):
"Return list of valid roles" """Return list of valid roles.
"""
obj=self obj=self
dict={} dict={}
dup =dict.has_key dup =dict.has_key
...@@ -427,7 +438,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -427,7 +438,8 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
return tuple(roles) return tuple(roles)
def validate_roles(self, roles): def validate_roles(self, roles):
"Return true if all given roles are valid" """Return true if all given roles are valid.
"""
valid=self.valid_roles() valid=self.valid_roles()
for role in roles: for role in roles:
if role not in valid: if role not in valid:
...@@ -435,16 +447,17 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -435,16 +447,17 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
return 1 return 1
def userdefined_roles(self): def userdefined_roles(self):
"Return list of user-defined roles" """Return list of user-defined roles.
"""
roles=list(self.__ac_roles__) roles=list(self.__ac_roles__)
for role in classattr(self.__class__,'__ac_roles__'): for role in classattr(self.__class__,'__ac_roles__'):
try: roles.remove(role) try: roles.remove(role)
except: pass except: pass
return tuple(roles) return tuple(roles)
def manage_defined_roles(self, submit=None, REQUEST=None):
def manage_defined_roles(self,submit=None,REQUEST=None): """Called by management screen.
"""Called by management screen.""" """
if submit=='Add Role': if submit=='Add Role':
role=reqattr(REQUEST, 'role') role=reqattr(REQUEST, 'role')
...@@ -473,7 +486,6 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -473,7 +486,6 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
if REQUEST is not None: if REQUEST is not None:
return self.manage_access(REQUEST) return self.manage_access(REQUEST)
def _delRoles(self, roles, REQUEST=None): def _delRoles(self, roles, REQUEST=None):
if not roles: if not roles:
return MessageDialog( return MessageDialog(
...@@ -488,21 +500,19 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -488,21 +500,19 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
if REQUEST is not None: if REQUEST is not None:
return self.manage_access(REQUEST) return self.manage_access(REQUEST)
def _has_user_defined_role(self, role): def _has_user_defined_role(self, role):
return role in self.__ac_roles__ return role in self.__ac_roles__
# Compatibility names only!! # Compatibility names only!!
smallRolesWidget=selectedRoles=aclAChecked=aclPChecked=aclEChecked='' smallRolesWidget=selectedRoles=aclAChecked=aclPChecked=aclEChecked=''
validRoles=valid_roles validRoles=valid_roles
#manage_rolesForm=manage_access #manage_rolesForm=manage_access
def manage_editRoles(self,REQUEST,acl_type='A',acl_roles=[]): def manage_editRoles(self, REQUEST, acl_type='A', acl_roles=[]):
pass pass
def _setRoles(self,acl_type,acl_roles): def _setRoles(self, acl_type, acl_roles):
pass pass
def possible_permissions(self): def possible_permissions(self):
...@@ -520,7 +530,6 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager): ...@@ -520,7 +530,6 @@ class RoleManager(ExtensionClass.Base, PermissionMapping.RoleManager):
return d return d
Globals.default__class_init__(RoleManager) Globals.default__class_init__(RoleManager)
......
...@@ -15,33 +15,37 @@ ...@@ -15,33 +15,37 @@
$Id$ $Id$
""" """
import Globals,Folder,os,sys,App.Product, App.ProductRegistry, misc_ import os, sys, traceback
import time, traceback, os, Products
from DateTime import DateTime
from AccessControl.User import UserFolder
from App.ApplicationManager import ApplicationManager
from webdav.NullResource import NullResource
from FindSupport import FindSupport
from cgi import escape from cgi import escape
from urllib import quote
from StringIO import StringIO from StringIO import StringIO
from AccessControl.PermissionRole import PermissionRole
import Globals, Products, App.Product, App.ProductRegistry, misc_
import transaction
from AccessControl.User import UserFolder
from Acquisition import aq_base
from App.ApplicationManager import ApplicationManager
from App.config import getConfiguration
from App.Product import doInstall
from App.ProductContext import ProductContext from App.ProductContext import ProductContext
from DateTime import DateTime
from HelpSys.HelpSys import HelpSys
from misc_ import Misc_ from misc_ import Misc_
import ZDOM from webdav.NullResource import NullResource
from zLOG import LOG, ERROR, WARNING, INFO
from zExceptions import Redirect as RedirectException, Forbidden from zExceptions import Redirect as RedirectException, Forbidden
from HelpSys.HelpSys import HelpSys from zLOG import LOG, ERROR, WARNING, INFO
from Acquisition import aq_base
from App.Product import doInstall import Folder
from App.config import getConfiguration import ZDOM
import transaction from FindSupport import FindSupport
class Application(Globals.ApplicationDefaultPermissions, class Application(Globals.ApplicationDefaultPermissions,
ZDOM.Root, Folder.Folder, ZDOM.Root, Folder.Folder,
App.ProductRegistry.ProductRegistry, FindSupport): App.ProductRegistry.ProductRegistry, FindSupport):
"""Top-level system object""" """Top-level system object"""
title ='Zope'
title ='Zope'
#__roles__=['Manager', 'Anonymous'] #__roles__=['Manager', 'Anonymous']
__defined_roles__=('Manager','Anonymous','Owner') __defined_roles__=('Manager','Anonymous','Owner')
web__form__method='GET' web__form__method='GET'
...@@ -70,9 +74,6 @@ class Application(Globals.ApplicationDefaultPermissions, ...@@ -70,9 +74,6 @@ class Application(Globals.ApplicationDefaultPermissions,
_initializer_registry = None _initializer_registry = None
def title_and_id(self): return self.title
def title_or_id(self): return self.title
def __init__(self): def __init__(self):
# Initialize users # Initialize users
uf=UserFolder() uf=UserFolder()
...@@ -89,14 +90,22 @@ class Application(Globals.ApplicationDefaultPermissions, ...@@ -89,14 +90,22 @@ class Application(Globals.ApplicationDefaultPermissions,
try: return self.REQUEST['SCRIPT_NAME'][1:] try: return self.REQUEST['SCRIPT_NAME'][1:]
except: return self.title except: return self.title
def __class_init__(self): Globals.default__class_init__(self) def title_and_id(self):
return self.title
def title_or_id(self):
return self.title
def PrincipiaRedirect(self,destination,URL1): def __class_init__(self):
Globals.default__class_init__(self)
def PrincipiaRedirect(self, destination, URL1):
"""Utility function to allow user-controlled redirects""" """Utility function to allow user-controlled redirects"""
if destination.find('//') >= 0: if destination.find('//') >= 0:
raise RedirectException, destination raise RedirectException, destination
raise RedirectException, ("%s/%s" % (URL1, destination)) raise RedirectException, ("%s/%s" % (URL1, destination))
Redirect=ZopeRedirect=PrincipiaRedirect
Redirect = ZopeRedirect = PrincipiaRedirect
def __bobo_traverse__(self, REQUEST, name=None): def __bobo_traverse__(self, REQUEST, name=None):
...@@ -117,7 +126,8 @@ class Application(Globals.ApplicationDefaultPermissions, ...@@ -117,7 +126,8 @@ class Application(Globals.ApplicationDefaultPermissions,
def PrincipiaTime(self, *args): def PrincipiaTime(self, *args):
"""Utility function to return current date/time""" """Utility function to return current date/time"""
return apply(DateTime, args) return apply(DateTime, args)
ZopeTime=PrincipiaTime
ZopeTime = PrincipiaTime
ZopeAttributionButton__roles__=None ZopeAttributionButton__roles__=None
def ZopeAttributionButton(self): def ZopeAttributionButton(self):
...@@ -139,10 +149,11 @@ class Application(Globals.ApplicationDefaultPermissions, ...@@ -139,10 +149,11 @@ class Application(Globals.ApplicationDefaultPermissions,
raise Forbidden, 'This resource cannot be moved.' raise Forbidden, 'This resource cannot be moved.'
test_url___allow_groups__=None test_url___allow_groups__=None
test_url=ZopeAttributionButton test_url = ZopeAttributionButton
def absolute_url(self, relative=0): def absolute_url(self, relative=0):
'''The absolute URL of the root object is BASE1 or "/".''' """The absolute URL of the root object is BASE1 or "/".
"""
if relative: return '' if relative: return ''
try: try:
# Take advantage of computed URL cache # Take advantage of computed URL cache
...@@ -151,26 +162,32 @@ class Application(Globals.ApplicationDefaultPermissions, ...@@ -151,26 +162,32 @@ class Application(Globals.ApplicationDefaultPermissions,
return '/' return '/'
def absolute_url_path(self): def absolute_url_path(self):
'''The absolute URL path of the root object is BASEPATH1 or "/".''' """The absolute URL path of the root object is BASEPATH1 or "/".
"""
try: try:
return self.REQUEST['BASEPATH1'] or '/' return self.REQUEST['BASEPATH1'] or '/'
except (AttributeError, KeyError): except (AttributeError, KeyError):
return '/' return '/'
def virtual_url_path(self): def virtual_url_path(self):
'''The virtual URL path of the root object is empty.''' """The virtual URL path of the root object is empty.
"""
return '' return ''
def getPhysicalRoot(self):
return self
def getPhysicalPath(self): def getPhysicalPath(self):
'''Returns a path that can be used to access this object again """Get the physical path of the object.
later, for example in a copy/paste operation. Designed to
be used with getPhysicalRoot(). Returns a path (an immutable sequence of strings) that can be used to
''' access this object again later, for example in a copy/paste operation.
getPhysicalRoot() and getPhysicalPath() are designed to operate
together.
"""
# We're at the base of the path. # We're at the base of the path.
return ('',) return ('',)
def getPhysicalRoot(self): return self
fixupZClassDependencies__roles__=() fixupZClassDependencies__roles__=()
def fixupZClassDependencies(self, rebuild=0): def fixupZClassDependencies(self, rebuild=0):
# Note that callers should not catch exceptions from this method # Note that callers should not catch exceptions from this method
...@@ -258,7 +275,9 @@ class Application(Globals.ApplicationDefaultPermissions, ...@@ -258,7 +275,9 @@ class Application(Globals.ApplicationDefaultPermissions,
reg = {} reg = {}
return reg.get(flag) return reg.get(flag)
class Expired(Globals.Persistent): class Expired(Globals.Persistent):
icon='p_/broken' icon='p_/broken'
def __setstate__(self, s={}): def __setstate__(self, s={}):
...@@ -279,7 +298,9 @@ def initialize(app): ...@@ -279,7 +298,9 @@ def initialize(app):
initializer = AppInitializer(app) initializer = AppInitializer(app)
initializer.initialize() initializer.initialize()
class AppInitializer: class AppInitializer:
""" Initialze an Application object (called at startup) """ """ Initialze an Application object (called at startup) """
def __init__(self, app): def __init__(self, app):
...@@ -880,9 +901,8 @@ def reimport_product(product_name): ...@@ -880,9 +901,8 @@ def reimport_product(product_name):
def removeProductMetaTypes(pid): def removeProductMetaTypes(pid):
''' """Unregisters the meta types registered by a product.
Unregisters the meta types registered by a product. """
'''
meta_types = Products.meta_types meta_types = Products.meta_types
new_mts = [] new_mts = []
changed = 0 changed = 0
......
...@@ -14,27 +14,32 @@ ...@@ -14,27 +14,32 @@
$Id$ $Id$
""" """
import re, sys, Globals, Moniker, tempfile, ExtensionClass
import re, sys, tempfile
from cgi import escape
from marshal import loads, dumps from marshal import loads, dumps
from urllib import quote, unquote from urllib import quote, unquote
from zlib import compress, decompress from zlib import compress, decompress
import Globals, Moniker, ExtensionClass
import transaction
from App.Dialogs import MessageDialog from App.Dialogs import MessageDialog
from AccessControl import getSecurityManager from AccessControl import getSecurityManager
from AccessControl.Permissions import delete_objects as DeleteObjects from AccessControl.Permissions import delete_objects as DeleteObjects
from Acquisition import aq_base, aq_inner, aq_parent from Acquisition import aq_base, aq_inner, aq_parent
from zExceptions import Unauthorized, BadRequest from zExceptions import Unauthorized, BadRequest
from webdav.Lockable import ResourceLockedError from webdav.Lockable import ResourceLockedError
from cgi import escape
import transaction
CopyError='Copy Error' CopyError='Copy Error'
copy_re = re.compile('^copy([0-9]*)_of_(.*)') copy_re = re.compile('^copy([0-9]*)_of_(.*)')
_marker=[] _marker=[]
class CopyContainer(ExtensionClass.Base): class CopyContainer(ExtensionClass.Base):
"""Interface for containerish objects which allow cut/copy/paste""" """Interface for containerish objects which allow cut/copy/paste"""
__ac_permissions__=( __ac_permissions__=(
...@@ -48,8 +53,12 @@ class CopyContainer(ExtensionClass.Base): ...@@ -48,8 +53,12 @@ class CopyContainer(ExtensionClass.Base):
# The following three methods should be overridden to store sub-objects # The following three methods should be overridden to store sub-objects
# as non-attributes. # as non-attributes.
def _setOb(self, id, object): setattr(self, id, object) def _setOb(self, id, object):
def _delOb(self, id): delattr(self, id) setattr(self, id, object)
def _delOb(self, id):
delattr(self, id)
def _getOb(self, id, default=_marker): def _getOb(self, id, default=_marker):
if hasattr(aq_base(self), id): if hasattr(aq_base(self), id):
return getattr(self, id) return getattr(self, id)
...@@ -136,9 +145,11 @@ class CopyContainer(ExtensionClass.Base): ...@@ -136,9 +145,11 @@ class CopyContainer(ExtensionClass.Base):
def manage_pasteObjects(self, cb_copy_data=None, REQUEST=None): def manage_pasteObjects(self, cb_copy_data=None, REQUEST=None):
"""Paste previously copied objects into the current object. """Paste previously copied objects into the current object.
If calling manage_pasteObjects from python code, pass
the result of a previous call to manage_cutObjects or If calling manage_pasteObjects from python code, pass the result of a
manage_copyObjects as the first argument.""" previous call to manage_cutObjects or manage_copyObjects as the first
argument.
"""
cp=None cp=None
if cb_copy_data is not None: if cb_copy_data is not None:
cp=cb_copy_data cp=cb_copy_data
...@@ -421,6 +432,7 @@ Globals.default__class_init__(CopyContainer) ...@@ -421,6 +432,7 @@ Globals.default__class_init__(CopyContainer)
class CopySource(ExtensionClass.Base): class CopySource(ExtensionClass.Base):
"""Interface for objects which allow themselves to be copied.""" """Interface for objects which allow themselves to be copied."""
# declare a dummy permission for Copy or Move here that we check # declare a dummy permission for Copy or Move here that we check
...@@ -430,14 +442,18 @@ class CopySource(ExtensionClass.Base): ...@@ -430,14 +442,18 @@ class CopySource(ExtensionClass.Base):
) )
def _canCopy(self, op=0): def _canCopy(self, op=0):
"""Called to make sure this object is copyable. The op var """Called to make sure this object is copyable.
is 0 for a copy, 1 for a move."""
The op var is 0 for a copy, 1 for a move.
"""
return 1 return 1
def _notifyOfCopyTo(self, container, op=0): def _notifyOfCopyTo(self, container, op=0):
"""Overide this to be pickly about where you go! If you dont """Overide this to be pickly about where you go!
want to go there, raise an exception. The op variable is
0 for a copy, 1 for a move.""" If you dont want to go there, raise an exception. The op variable is 0
for a copy, 1 for a move.
"""
pass pass
def _getCopy(self, container): def _getCopy(self, container):
......
...@@ -14,31 +14,32 @@ ...@@ -14,31 +14,32 @@
$Id$ $Id$
""" """
import App.Management, Acquisition, Globals, CopySupport, Products
import os, App.FactoryDispatcher, re, Products import sys, fnmatch, copy, os, re
from OFS.Traversable import Traversable import marshal
from OFS import SimpleItem from cgi import escape
from cStringIO import StringIO
from types import StringType, UnicodeType
import App.Management, Acquisition, Globals, Products
import App.FactoryDispatcher, Products
from Globals import DTMLFile, Persistent from Globals import DTMLFile, Persistent
from Globals import MessageDialog, default__class_init__ from Globals import MessageDialog, default__class_init__
from Globals import REPLACEABLE, NOT_REPLACEABLE, UNIQUE from Globals import REPLACEABLE, NOT_REPLACEABLE, UNIQUE
from webdav.NullResource import NullResource from webdav.NullResource import NullResource
from webdav.Collection import Collection from webdav.Collection import Collection
from Acquisition import aq_base from Acquisition import aq_base
from AccessControl.SecurityInfo import ClassSecurityInfo
from webdav.Lockable import ResourceLockedError from webdav.Lockable import ResourceLockedError
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from urllib import quote
from cStringIO import StringIO
import marshal
import App.Common import App.Common
from App.config import getConfiguration from App.config import getConfiguration
from AccessControl import getSecurityManager from AccessControl import getSecurityManager
from AccessControl.ZopeSecurityPolicy import getRoles from AccessControl.ZopeSecurityPolicy import getRoles
from zLOG import LOG, ERROR from zLOG import LOG, ERROR
from zExceptions import BadRequest from zExceptions import BadRequest
import sys,fnmatch,copy
from cgi import escape from OFS.Traversable import Traversable
from types import StringType, UnicodeType import CopySupport
# the name BadRequestException is relied upon by 3rd-party code # the name BadRequestException is relied upon by 3rd-party code
BadRequestException = BadRequest BadRequestException = BadRequest
...@@ -92,10 +93,20 @@ def checkValidId(self, id, allow_dup=0): ...@@ -92,10 +93,20 @@ def checkValidId(self, id, allow_dup=0):
raise BadRequest, ( raise BadRequest, (
'The id "%s" contains characters illegal in URLs.' % id) 'The id "%s" contains characters illegal in URLs.' % id)
class BeforeDeleteException( Exception ): pass # raise to veto deletion
class BreakoutException ( Exception ): pass # raised to break out of loops class BeforeDeleteException(Exception):
pass # raise to veto deletion
class BreakoutException(Exception):
pass # raised to break out of loops
_marker=[] _marker=[]
class ObjectManager( class ObjectManager(
CopySupport.CopyContainer, CopySupport.CopyContainer,
App.Management.Navigation, App.Management.Navigation,
...@@ -105,6 +116,7 @@ class ObjectManager( ...@@ -105,6 +116,7 @@ class ObjectManager(
Collection, Collection,
Traversable, Traversable,
): ):
"""Generic object manager """Generic object manager
This class provides core behavior for collections of heterogeneous objects. This class provides core behavior for collections of heterogeneous objects.
...@@ -125,11 +137,11 @@ class ObjectManager( ...@@ -125,11 +137,11 @@ class ObjectManager(
) )
meta_type ='Object Manager' meta_type = 'Object Manager'
meta_types=() # Sub-object types that are specific to this object meta_types=() # Sub-object types that are specific to this object
_objects =() _objects = ()
manage_main=DTMLFile('dtml/main', globals()) manage_main=DTMLFile('dtml/main', globals())
manage_index_main=DTMLFile('dtml/index_main', globals()) manage_index_main=DTMLFile('dtml/index_main', globals())
...@@ -232,8 +244,12 @@ class ObjectManager( ...@@ -232,8 +244,12 @@ class ObjectManager(
_checkId = checkValidId _checkId = checkValidId
def _setOb(self, id, object): setattr(self, id, object) def _setOb(self, id, object):
def _delOb(self, id): delattr(self, id) setattr(self, id, object)
def _delOb(self, id):
delattr(self, id)
def _getOb(self, id, default=_marker): def _getOb(self, id, default=_marker):
# FIXME: what we really need to do here is ensure that only # FIXME: what we really need to do here is ensure that only
# sub-items are returned. That could have a measurable hit # sub-items are returned. That could have a measurable hit
...@@ -245,7 +261,7 @@ class ObjectManager( ...@@ -245,7 +261,7 @@ class ObjectManager(
raise AttributeError, id raise AttributeError, id
return default return default
def _setObject(self,id,object,roles=None,user=None, set_owner=1): def _setObject(self, id, object, roles=None, user=None, set_owner=1):
v=self._checkId(id) v=self._checkId(id)
if v is not None: id=v if v is not None: id=v
try: t=object.meta_type try: t=object.meta_type
...@@ -353,14 +369,12 @@ class ObjectManager( ...@@ -353,14 +369,12 @@ class ObjectManager(
return set return set
return [ o['id'] for o in self._objects ] return [ o['id'] for o in self._objects ]
def objectValues(self, spec=None): def objectValues(self, spec=None):
# Returns a list of actual subobjects of the current object. # Returns a list of actual subobjects of the current object.
# If 'spec' is specified, returns only objects whose meta_type # If 'spec' is specified, returns only objects whose meta_type
# match 'spec'. # match 'spec'.
return [ self._getOb(id) for id in self.objectIds(spec) ] return [ self._getOb(id) for id in self.objectIds(spec) ]
def objectItems(self, spec=None): def objectItems(self, spec=None):
# Returns a list of (id, subobject) tuples of the current object. # Returns a list of (id, subobject) tuples of the current object.
# If 'spec' is specified, returns only objects whose meta_type match # If 'spec' is specified, returns only objects whose meta_type match
...@@ -371,7 +385,7 @@ class ObjectManager( ...@@ -371,7 +385,7 @@ class ObjectManager(
# Return a tuple of mappings containing subobject meta-data # Return a tuple of mappings containing subobject meta-data
return tuple(map(lambda dict: dict.copy(), self._objects)) return tuple(map(lambda dict: dict.copy(), self._objects))
def objectIds_d(self,t=None): def objectIds_d(self, t=None):
if hasattr(self, '_reserved_names'): n=self._reserved_names if hasattr(self, '_reserved_names'): n=self._reserved_names
else: n=() else: n=()
if not n: return self.objectIds(t) if not n: return self.objectIds(t)
...@@ -381,17 +395,17 @@ class ObjectManager( ...@@ -381,17 +395,17 @@ class ObjectManager(
if id not in n: a(id) if id not in n: a(id)
return r return r
def objectValues_d(self,t=None): def objectValues_d(self, t=None):
return map(self._getOb, self.objectIds_d(t)) return map(self._getOb, self.objectIds_d(t))
def objectItems_d(self,t=None): def objectItems_d(self, t=None):
r=[] r=[]
a=r.append a=r.append
g=self._getOb g=self._getOb
for id in self.objectIds_d(t): a((id, g(id))) for id in self.objectIds_d(t): a((id, g(id)))
return r return r
def objectMap_d(self,t=None): def objectMap_d(self, t=None):
if hasattr(self, '_reserved_names'): n=self._reserved_names if hasattr(self, '_reserved_names'): n=self._reserved_names
else: n=() else: n=()
if not n: return self._objects if not n: return self._objects
...@@ -401,7 +415,7 @@ class ObjectManager( ...@@ -401,7 +415,7 @@ class ObjectManager(
if d['id'] not in n: a(d.copy()) if d['id'] not in n: a(d.copy())
return r return r
def superValues(self,t): def superValues(self, t):
# Return all of the objects of a given type located in # Return all of the objects of a given type located in
# this object and containing objects. # this object and containing objects.
if type(t)==type('s'): t=(t,) if type(t)==type('s'): t=(t,)
...@@ -584,11 +598,12 @@ class ObjectManager( ...@@ -584,11 +598,12 @@ class ObjectManager(
listing += [f for f in os.listdir(directory) listing += [f for f in os.listdir(directory)
if f.endswith('.zexp') or f.endswith('.xml')] if f.endswith('.zexp') or f.endswith('.xml')]
return listing return listing
# FTP support methods # FTP support methods
def manage_FTPlist(self, REQUEST): def manage_FTPlist(self, REQUEST):
"Directory listing for FTP" """Directory listing for FTP.
"""
out=() out=()
# check to see if we are being acquiring or not # check to see if we are being acquiring or not
...@@ -650,9 +665,9 @@ class ObjectManager( ...@@ -650,9 +665,9 @@ class ObjectManager(
if not REQUEST['id'] in self.objectIds(): if not REQUEST['id'] in self.objectIds():
raise KeyError(REQUEST['id']) raise KeyError(REQUEST['id'])
def manage_FTPstat(self,REQUEST): def manage_FTPstat(self,REQUEST):
"Psuedo stat used for FTP listings" """Psuedo stat, used by FTP for directory listings.
"""
mode=0040000 mode=0040000
from AccessControl.User import nobody from AccessControl.User import nobody
# check to see if we are acquiring our objectValues or not # check to see if we are acquiring our objectValues or not
...@@ -678,7 +693,6 @@ class ObjectManager( ...@@ -678,7 +693,6 @@ class ObjectManager(
break break
return marshal.dumps((mode,0,0,1,owner,group,0,mtime,mtime,mtime)) return marshal.dumps((mode,0,0,1,owner,group,0,mtime,mtime,mtime))
def __getitem__(self, key): def __getitem__(self, key):
v=self._getOb(key, None) v=self._getOb(key, None)
if v is not None: return v if v is not None: return v
...@@ -689,6 +703,7 @@ class ObjectManager( ...@@ -689,6 +703,7 @@ class ObjectManager(
return NullResource(self, key, request).__of__(self) return NullResource(self, key, request).__of__(self)
raise KeyError, key raise KeyError, key
def findChildren(obj,dirname=''): def findChildren(obj,dirname=''):
""" recursive walk through the object hierarchy to """ recursive walk through the object hierarchy to
find all children of an object (ajung) find all children of an object (ajung)
...@@ -703,7 +718,9 @@ def findChildren(obj,dirname=''): ...@@ -703,7 +718,9 @@ def findChildren(obj,dirname=''):
return lst return lst
class IFAwareObjectManager: class IFAwareObjectManager:
def all_meta_types(self, interfaces=None): def all_meta_types(self, interfaces=None):
if interfaces is None: if interfaces is None:
......
...@@ -14,19 +14,23 @@ ...@@ -14,19 +14,23 @@
$Id$ $Id$
""" """
from cgi import escape
from types import ListType
import ExtensionClass, Globals import ExtensionClass, Globals
import ZDOM
from PropertySheets import DefaultPropertySheets, vps
from ZPublisher.Converters import type_converters from ZPublisher.Converters import type_converters
from Globals import DTMLFile, MessageDialog from Globals import DTMLFile, MessageDialog
from Acquisition import Implicit, aq_base from Acquisition import aq_base
from Globals import Persistent from Globals import Persistent
from zExceptions import BadRequest from zExceptions import BadRequest
from cgi import escape
from types import ListType import ZDOM
from PropertySheets import DefaultPropertySheets, vps
class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes): class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes):
""" """
The PropertyManager mixin class provides an object with The PropertyManager mixin class provides an object with
transparent property management. An object which wants to transparent property management. An object which wants to
...@@ -128,22 +132,28 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes): ...@@ -128,22 +132,28 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes):
return 1 return 1
def hasProperty(self, id): def hasProperty(self, id):
"""Return true if object has a property 'id'""" """Return true if object has a property 'id'.
"""
for p in self._properties: for p in self._properties:
if id==p['id']: if id==p['id']:
return 1 return 1
return 0 return 0
def getProperty(self, id, d=None): def getProperty(self, id, d=None):
"""Get the property 'id', returning the optional second """Get the property 'id'.
argument or None if no such property is found."""
Returns the optional second argument or None if no such property is
found.
"""
if self.hasProperty(id): if self.hasProperty(id):
return getattr(self, id) return getattr(self, id)
return d return d
def getPropertyType(self, id): def getPropertyType(self, id):
"""Get the type of property 'id', returning None if no """Get the type of property 'id'.
such property exists"""
Returns None if no such property exists.
"""
for md in self._properties: for md in self._properties:
if md['id']==id: if md['id']==id:
return md.get('type', 'string') return md.get('type', 'string')
...@@ -207,24 +217,28 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes): ...@@ -207,24 +217,28 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes):
self._properties)) self._properties))
def propertyIds(self): def propertyIds(self):
"""Return a list of property ids """ """Return a list of property ids.
"""
return map(lambda i: i['id'], self._properties) return map(lambda i: i['id'], self._properties)
def propertyValues(self): def propertyValues(self):
"""Return a list of actual property objects """ """Return a list of actual property objects.
"""
return map(lambda i,s=self: getattr(s,i['id']), self._properties) return map(lambda i,s=self: getattr(s,i['id']), self._properties)
def propertyItems(self): def propertyItems(self):
"""Return a list of (id,property) tuples """ """Return a list of (id,property) tuples.
"""
return map(lambda i,s=self: (i['id'],getattr(s,i['id'])), return map(lambda i,s=self: (i['id'],getattr(s,i['id'])),
self._properties) self._properties)
def _propertyMap(self): def _propertyMap(self):
"""Return a tuple of mappings, giving meta-data for properties """ """Return a tuple of mappings, giving meta-data for properties.
"""
return self._properties return self._properties
def propertyMap(self): def propertyMap(self):
""" """Return a tuple of mappings, giving meta-data for properties.
Return a tuple of mappings, giving meta-data for properties.
Return copies of the real definitions for security. Return copies of the real definitions for security.
""" """
return tuple(map(lambda dict: dict.copy(), self._propertyMap())) return tuple(map(lambda dict: dict.copy(), self._propertyMap()))
...@@ -247,8 +261,10 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes): ...@@ -247,8 +261,10 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes):
# Web interface # Web interface
def manage_addProperty(self, id, value, type, REQUEST=None): def manage_addProperty(self, id, value, type, REQUEST=None):
"""Add a new property via the web. Sets a new property with """Add a new property via the web.
the given id, type, and value."""
Sets a new property with the given id, type, and value.
"""
if type_converters.has_key(type): if type_converters.has_key(type):
value=type_converters[type](value) value=type_converters[type](value)
self._setProperty(id.strip(), value, type) self._setProperty(id.strip(), value, type)
...@@ -257,6 +273,7 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes): ...@@ -257,6 +273,7 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes):
def manage_editProperties(self, REQUEST): def manage_editProperties(self, REQUEST):
"""Edit object properties via the web. """Edit object properties via the web.
The purpose of this method is to change all property values, The purpose of this method is to change all property values,
even those not listed in REQUEST; otherwise checkboxes that even those not listed in REQUEST; otherwise checkboxes that
get turned off will be ignored. Use manage_changeProperties() get turned off will be ignored. Use manage_changeProperties()
...@@ -346,7 +363,4 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes): ...@@ -346,7 +363,4 @@ class PropertyManager(ExtensionClass.Base, ZDOM.ElementWithAttributes):
if REQUEST is not None: if REQUEST is not None:
return self.manage_propertiesForm(self, REQUEST) return self.manage_propertiesForm(self, REQUEST)
Globals.default__class_init__(PropertyManager) Globals.default__class_init__(PropertyManager)
...@@ -19,50 +19,59 @@ item types. ...@@ -19,50 +19,59 @@ item types.
$Id$ $Id$
""" """
import re, sys, Globals, App.Management, Acquisition, App.Undo
import marshal, re, sys, time
import Globals, App.Management, Acquisition, App.Undo
import AccessControl.Role, AccessControl.Owned, App.Common import AccessControl.Role, AccessControl.Owned, App.Common
from webdav.Resource import Resource from webdav.Resource import Resource
from ExtensionClass import Base from ExtensionClass import Base
from CopySupport import CopySource
from types import InstanceType, StringType
from ComputedAttribute import ComputedAttribute from ComputedAttribute import ComputedAttribute
from AccessControl import getSecurityManager, Unauthorized from AccessControl import getSecurityManager, Unauthorized
from Traversable import Traversable from AccessControl.ZopeSecurityPolicy import getRoles
from Acquisition import aq_base, aq_parent, aq_inner, aq_acquire from Acquisition import aq_base, aq_parent, aq_inner, aq_acquire
from DocumentTemplate.ustr import ustr from DocumentTemplate.ustr import ustr
from zExceptions.ExceptionFormatter import format_exception from zExceptions.ExceptionFormatter import format_exception
from zExceptions import Redirect from zExceptions import Redirect
import time
from zLOG import LOG, BLATHER from zLOG import LOG, BLATHER
from AccessControl.ZopeSecurityPolicy import getRoles
import marshal from CopySupport import CopySource
from Traversable import Traversable
import ZDOM import ZDOM
HTML=Globals.HTML HTML=Globals.HTML
StringType=type('')
class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
ZDOM.Element, ZDOM.Element,
AccessControl.Owned.Owned, AccessControl.Owned.Owned,
App.Undo.UndoSupport, App.Undo.UndoSupport,
): ):
"""A common base class for simple, non-container objects.""" """A common base class for simple, non-container objects."""
isPrincipiaFolderish=0 isPrincipiaFolderish=0
isTopLevelPrincipiaApplicationObject=0 isTopLevelPrincipiaApplicationObject=0
def manage_afterAdd(self, item, container): pass def manage_afterAdd(self, item, container):
def manage_beforeDelete(self, item, container): pass pass
def manage_afterClone(self, item): pass
def manage_beforeDelete(self, item, container):
pass
def manage_afterClone(self, item):
pass
# Direct use of the 'id' attribute is deprecated - use getId() # Direct use of the 'id' attribute is deprecated - use getId()
id='' id=''
getId__roles__=None getId__roles__=None
def getId(self): def getId(self):
"""Return the id of the object as a string. This method """Return the id of the object as a string.
should be used in preference to accessing an id attribute
of an object directly. The getId method is public.""" This method should be used in preference to accessing an id attribute
of an object directly. The getId method is public.
"""
name=getattr(self, 'id', None) name=getattr(self, 'id', None)
if callable(name): if callable(name):
return name() return name()
...@@ -99,11 +108,8 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -99,11 +108,8 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
# Allow (reluctantly) access to unprotected attributes # Allow (reluctantly) access to unprotected attributes
__allow_access_to_unprotected_subobjects__=1 __allow_access_to_unprotected_subobjects__=1
def title_or_id(self): def title_or_id(self):
""" """Return the title if it is not blank and the id otherwise.
Utility that returns the title if it is not blank and the id
otherwise.
""" """
title=self.title title=self.title
if callable(title): if callable(title):
...@@ -112,10 +118,9 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -112,10 +118,9 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
return self.getId() return self.getId()
def title_and_id(self): def title_and_id(self):
""" """Return the title if it is not blank and the id otherwise.
Utility that returns the title if it is not blank and the id
otherwise. If the title is not blank, then the id is included If the title is not blank, then the id is included in parens.
in parens.
""" """
title=self.title title=self.title
if callable(title): if callable(title):
...@@ -222,7 +227,8 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -222,7 +227,8 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
tb=None tb=None
def manage(self, URL1): def manage(self, URL1):
" " """
"""
raise Redirect, "%s/manage_main" % URL1 raise Redirect, "%s/manage_main" % URL1
# This keeps simple items from acquiring their parents # This keeps simple items from acquiring their parents
...@@ -234,7 +240,8 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -234,7 +240,8 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
# FTP support methods # FTP support methods
def manage_FTPstat(self,REQUEST): def manage_FTPstat(self,REQUEST):
"psuedo stat, used by FTP for directory listings" """Psuedo stat, used by FTP for directory listings.
"""
from AccessControl.User import nobody from AccessControl.User import nobody
mode=0100000 mode=0100000
...@@ -245,7 +252,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -245,7 +252,7 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
mode=mode | 0440 mode=mode | 0440
except Unauthorized: except Unauthorized:
pass pass
if nobody.allowed( if nobody.allowed(
self.manage_FTPget, self.manage_FTPget,
getRoles(self, 'manage_FTPget', self.manage_FTPget, ()), getRoles(self, 'manage_FTPget', self.manage_FTPget, ()),
...@@ -288,8 +295,11 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -288,8 +295,11 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
return marshal.dumps((mode,0,0,1,owner,group,size,mtime,mtime,mtime)) return marshal.dumps((mode,0,0,1,owner,group,size,mtime,mtime,mtime))
def manage_FTPlist(self,REQUEST): def manage_FTPlist(self,REQUEST):
"""Directory listing for FTP. In the case of non-Foldoid objects, """Directory listing for FTP.
the listing should contain one object, the object itself."""
In the case of non-Foldoid objects, the listing should contain one
object, the object itself.
"""
# check to see if we are being acquiring or not # check to see if we are being acquiring or not
ob=self ob=self
while 1: while 1:
...@@ -306,25 +316,27 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable, ...@@ -306,25 +316,27 @@ class Item(Base, Resource, CopySource, App.Management.Tabs, Traversable,
def __len__(self): def __len__(self):
return 1 return 1
Globals.default__class_init__(Item) Globals.default__class_init__(Item)
class Item_w__name__(Item): class Item_w__name__(Item):
"""Mixin class to support common name/id functions""" """Mixin class to support common name/id functions"""
def getId(self): def getId(self):
"""Returns the id""" """Return the id of the object as a string.
"""
return self.__name__ return self.__name__
def title_or_id(self): def title_or_id(self):
"""Utility that returns the title if it is not blank and the id """Return the title if it is not blank and the id otherwise.
otherwise.""" """
return self.title or self.__name__ return self.title or self.__name__
def title_and_id(self): def title_and_id(self):
"""Utility that returns the title if it is not blank and the id """Return the title if it is not blank and the id otherwise.
otherwise. If the title is not blank, then the id is included
in parens.""" If the title is not blank, then the id is included in parens.
"""
t=self.title t=self.title
return t and ("%s (%s)" % (t,self.__name__)) or self.__name__ return t and ("%s (%s)" % (t,self.__name__)) or self.__name__
...@@ -332,11 +344,13 @@ class Item_w__name__(Item): ...@@ -332,11 +344,13 @@ class Item_w__name__(Item):
self.__name__=id self.__name__=id
def getPhysicalPath(self): def getPhysicalPath(self):
'''Returns a path (an immutable sequence of strings) """Get the physical path of the object.
that can be used to access this object again
later, for example in a copy/paste operation. getPhysicalRoot() Returns a path (an immutable sequence of strings) that can be used to
and getPhysicalPath() are designed to operate together. access this object again later, for example in a copy/paste operation.
''' getPhysicalRoot() and getPhysicalPath() are designed to operate
together.
"""
path = (self.__name__,) path = (self.__name__,)
p = aq_parent(aq_inner(self)) p = aq_parent(aq_inner(self))
...@@ -356,6 +370,7 @@ class SimpleItem(Item, Globals.Persistent, ...@@ -356,6 +370,7 @@ class SimpleItem(Item, Globals.Persistent,
Acquisition.Implicit, Acquisition.Implicit,
AccessControl.Role.RoleManager, AccessControl.Role.RoleManager,
): ):
# Blue-plate special, Zope Masala # Blue-plate special, Zope Masala
"""Mix-in class combining the most common set of basic mix-ins """Mix-in class combining the most common set of basic mix-ins
""" """
......
...@@ -14,23 +14,24 @@ ...@@ -14,23 +14,24 @@
$Id$ $Id$
""" """
from urllib import quote
from Acquisition import Acquired, aq_inner, aq_parent, aq_base from Acquisition import Acquired, aq_inner, aq_parent, aq_base
from AccessControl import getSecurityManager from AccessControl import getSecurityManager
from AccessControl import Unauthorized from AccessControl import Unauthorized
from AccessControl.ZopeGuards import guarded_getattr from AccessControl.ZopeGuards import guarded_getattr
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from urllib import quote
from zExceptions import NotFound from zExceptions import NotFound
_marker = object() _marker = object()
class Traversable: class Traversable:
absolute_url__roles__=None # Public absolute_url__roles__=None # Public
def absolute_url(self, relative=0): def absolute_url(self, relative=0):
""" """Return the absolute URL of the object.
Return the absolute URL of the object.
This a canonical URL based on the object's physical This a canonical URL based on the object's physical
containment path. It is affected by the virtual host containment path. It is affected by the virtual host
...@@ -57,8 +58,7 @@ class Traversable: ...@@ -57,8 +58,7 @@ class Traversable:
absolute_url_path__roles__=None # Public absolute_url_path__roles__=None # Public
def absolute_url_path(self): def absolute_url_path(self):
""" """Return the path portion of the absolute URL of the object.
Return the path portion of the absolute URL of the object.
This includes the leading slash, and can be used as an This includes the leading slash, and can be used as an
'absolute-path reference' as defined in RFC 2396. 'absolute-path reference' as defined in RFC 2396.
...@@ -72,8 +72,7 @@ class Traversable: ...@@ -72,8 +72,7 @@ class Traversable:
virtual_url_path__roles__=None # Public virtual_url_path__roles__=None # Public
def virtual_url_path(self): def virtual_url_path(self):
""" """Return a URL for the object, relative to the site root.
Return a URL for the object, relative to the site root.
If a virtual host is configured, the URL is a path relative to If a virtual host is configured, the URL is a path relative to
the virtual host's root object. Otherwise, it is the physical the virtual host's root object. Otherwise, it is the physical
...@@ -91,11 +90,13 @@ class Traversable: ...@@ -91,11 +90,13 @@ class Traversable:
getPhysicalPath__roles__=None # Public getPhysicalPath__roles__=None # Public
def getPhysicalPath(self): def getPhysicalPath(self):
'''Returns a path (an immutable sequence of strings) """Get the physical path of the object.
that can be used to access this object again
later, for example in a copy/paste operation. getPhysicalRoot() Returns a path (an immutable sequence of strings) that can be used to
and getPhysicalPath() are designed to operate together. access this object again later, for example in a copy/paste operation.
''' getPhysicalRoot() and getPhysicalPath() are designed to operate
together.
"""
path = (self.getId(),) path = (self.getId(),)
p = aq_parent(aq_inner(self)) p = aq_parent(aq_inner(self))
...@@ -106,26 +107,26 @@ class Traversable: ...@@ -106,26 +107,26 @@ class Traversable:
unrestrictedTraverse__roles__=() # Private unrestrictedTraverse__roles__=() # Private
def unrestrictedTraverse(self, path, default=_marker, restricted=0): def unrestrictedTraverse(self, path, default=_marker, restricted=0):
"""Lookup an object by path, """Lookup an object by path.
path -- The path to the object. May be a sequence of strings or a slash path -- The path to the object. May be a sequence of strings or a slash
separated string. If the path begins with an empty path element separated string. If the path begins with an empty path element
(i.e., an empty string or a slash) then the lookup is performed (i.e., an empty string or a slash) then the lookup is performed
from the application root. Otherwise, the lookup is relative to from the application root. Otherwise, the lookup is relative to
self. Two dots (..) as a path element indicates an upward traversal self. Two dots (..) as a path element indicates an upward traversal
to the acquisition parent. to the acquisition parent.
default -- If provided, this is the value returned if the path cannot default -- If provided, this is the value returned if the path cannot
be traversed for any reason (i.e., no object exists at that path or be traversed for any reason (i.e., no object exists at that path or
the object is inaccessible). the object is inaccessible).
restricted -- If false (default) then no security checking is performed. restricted -- If false (default) then no security checking is performed.
If true, then all of the objects along the path are validated with If true, then all of the objects along the path are validated with
the security machinery. Usually invoked using restrictedTraverse(). the security machinery. Usually invoked using restrictedTraverse().
""" """
if not path: if not path:
return self return self
_getattr = getattr _getattr = getattr
_none = None _none = None
marker = _marker marker = _marker
......
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
"""WebDAV support - collection objects.
"""WebDAV support - collection objects.""" $Id$
"""
__version__='$Revision: 1.27 $'[11:-2]
import Globals, davcmds, Lockable import Globals, davcmds, Lockable
from common import urlfix, rfc1123_date from common import urlfix, rfc1123_date
...@@ -23,6 +23,7 @@ from urllib import unquote ...@@ -23,6 +23,7 @@ from urllib import unquote
from zExceptions import MethodNotAllowed, NotFound from zExceptions import MethodNotAllowed, NotFound
from webdav.common import Locked, PreconditionFailed from webdav.common import Locked, PreconditionFailed
class Collection(Resource): class Collection(Resource):
"""The Collection class provides basic WebDAV support for """The Collection class provides basic WebDAV support for
collection objects. It provides default implementations collection objects. It provides default implementations
...@@ -131,8 +132,5 @@ class Collection(Resource): ...@@ -131,8 +132,5 @@ class Collection(Resource):
if objectValues is not None: if objectValues is not None:
return objectValues() return objectValues()
return [] return []
Globals.default__class_init__(Collection) Globals.default__class_init__(Collection)
...@@ -10,14 +10,19 @@ ...@@ -10,14 +10,19 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
"""Etag support.
__version__ = "$Revision: 1.11 $"[11:-2] $Id$
"""
import time
from Interface import Interface
import time, Interface
from webdav.common import PreconditionFailed from webdav.common import PreconditionFailed
class EtagBaseInterface(Interface.Base):
class EtagBaseInterface(Interface):
"""\ """\
Basic Etag support interface, meaning the object supports generating Basic Etag support interface, meaning the object supports generating
an Etag that can be used by certain HTTP and WebDAV Requests. an Etag that can be used by certain HTTP and WebDAV Requests.
...@@ -53,6 +58,7 @@ class EtagBaseInterface(Interface.Base): ...@@ -53,6 +58,7 @@ class EtagBaseInterface(Interface.Base):
Thus, Etags need to be refreshed manually when an object changes. Thus, Etags need to be refreshed manually when an object changes.
""" """
class EtagSupport: class EtagSupport:
"""\ """\
This class is the basis for supporting Etags in Zope. It's main This class is the basis for supporting Etags in Zope. It's main
......
...@@ -10,16 +10,21 @@ ...@@ -10,16 +10,21 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
"""WebDAV support - lockable item.
__version__ = "$Revision: 1.10 $"[11:-2] $Id$
"""
from WriteLockInterface import WriteLockInterface, LockItemInterface
from EtagSupport import EtagSupport
from LockItem import LockItem
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Globals import InitializeClass
from Globals import PersistentMapping from Globals import PersistentMapping
import Acquisition import Acquisition
from EtagSupport import EtagSupport
from WriteLockInterface import LockItemInterface
from WriteLockInterface import WriteLockInterface
class ResourceLockedError(Exception): pass class ResourceLockedError(Exception): pass
class LockableItem(EtagSupport): class LockableItem(EtagSupport):
...@@ -134,9 +139,7 @@ class LockableItem(EtagSupport): ...@@ -134,9 +139,7 @@ class LockableItem(EtagSupport):
if hasattr(Acquisition.aq_base(self), '__no_valid_write_locks__'): if hasattr(Acquisition.aq_base(self), '__no_valid_write_locks__'):
self.__no_valid_write_locks__() self.__no_valid_write_locks__()
InitializeClass(LockableItem)
import Globals
Globals.default__class_init__(LockableItem)
### Utility functions ### Utility functions
......
...@@ -10,14 +10,18 @@ ...@@ -10,14 +10,18 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
"""Write lock interfaces.
__version__='$Revision: 1.6 $'[11:-2] $Id$
"""
import Interface from Interface import Interface
class LockItemInterface(Interface.Base):
"""\ class LockItemInterface(Interface):
A LockItem contains information about a lock. This includes: """A LockItem contains information about a lock.
This includes:
o The locktoken uri (used to identify the lock by WebDAV) o The locktoken uri (used to identify the lock by WebDAV)
...@@ -36,7 +40,7 @@ class LockItemInterface(Interface.Base): ...@@ -36,7 +40,7 @@ class LockItemInterface(Interface.Base):
""" """
# XXX: WAAAA! What is a ctor doing in the interface? # XXX: WAAAA! What is a ctor doing in the interface?
def __init__(self, creator, owner, depth=0, timeout='Infinity', def __init__(creator, owner, depth=0, timeout='Infinity',
locktype='write', lockscope='exclusive', token=None): locktype='write', lockscope='exclusive', token=None):
"""\ """\
If any of the following are untrue, a **ValueError** exception If any of the following are untrue, a **ValueError** exception
...@@ -139,10 +143,9 @@ class LockItemInterface(Interface.Base): ...@@ -139,10 +143,9 @@ class LockItemInterface(Interface.Base):
""" Render a full XML representation of a lock for WebDAV, """ Render a full XML representation of a lock for WebDAV,
used when returning the value of a newly created lock. """ used when returning the value of a newly created lock. """
class WriteLockInterface(Interface.Base):
"""\ class WriteLockInterface(Interface):
This represents the basic protocol needed to support the write lock """Basic protocol needed to support the write lock machinery.
machinery.
It must be able to answer the questions: It must be able to answer the questions:
...@@ -170,10 +173,8 @@ class WriteLockInterface(Interface.Base): ...@@ -170,10 +173,8 @@ class WriteLockInterface(Interface.Base):
**All methods in the WriteLock interface that deal with checking valid **All methods in the WriteLock interface that deal with checking valid
locks MUST check the timeout values on the lockitem (ie, by calling locks MUST check the timeout values on the lockitem (ie, by calling
'lockitem.isValid()'), and DELETE the lock if it is no longer valid** 'lockitem.isValid()'), and DELETE the lock if it is no longer valid**
""" """
def wl_lockItems(killinvalids=0): def wl_lockItems(killinvalids=0):
""" Returns (key, value) pairs of locktoken, lock. """ Returns (key, value) pairs of locktoken, lock.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment