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