Skip to content

Commit

Permalink
Merge pull request #63 from zopefoundation/apply-hotfix-20160419-rebased
Browse files Browse the repository at this point in the history
Apply hotfix 20160419 rebased
  • Loading branch information
hannosch committed Jul 17, 2016
2 parents 0b382a6 + cc6c0ee commit 547be40
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 176 deletions.
4 changes: 3 additions & 1 deletion doc/CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ http://docs.zope.org/zope2/
2.13.25 (unreleased)
--------------------

- Removed docstrings from some methods to avoid publishing them. From
Products.PloneHotfix20160419. [maurits]

- Optimized the `OFS.ObjectManager.__contains__` method to do the
least amount of work necessary.


2.13.24 (2016-02-29)
--------------------

Expand Down
14 changes: 7 additions & 7 deletions src/OFS/Application.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ def getPhysicalRoot(self):
return self

def getPhysicalPath(self):
"""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.
"""
# 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 ('',)

Expand Down
4 changes: 1 addition & 3 deletions src/OFS/Cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ def ZCacheable_isCachingEnabled(self):

security.declarePrivate('ZCacheable_getObAndView')
def ZCacheable_getObAndView(self, view_name):
"""
Returns self and view_name unchanged.
"""
# Returns self and view_name unchanged.
return self, view_name

security.declarePrivate('ZCacheable_get')
Expand Down
14 changes: 5 additions & 9 deletions src/OFS/DTMLMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class func_code:
security.declareProtected(View, '__call__')
def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
"""Render using the given client object
o If client is not passed, we are being called as a sub-template:
don't do any error propagation.
Expand Down Expand Up @@ -201,14 +201,12 @@ def ZDocumentTemplate_afterRender(self, md, result):

security.declareProtected(change_dtml_methods, 'getCacheNamespaceKeys')
def getCacheNamespaceKeys(self):
""" Return the cacheNamespaceKeys.
"""
# Return the cacheNamespaceKeys.
return self._cache_namespace_keys

security.declareProtected(change_dtml_methods, 'setCacheNamespaceKeys')
def setCacheNamespaceKeys(self, keys, REQUEST=None):
""" Set the list of names looked up to provide a cache key.
"""
# Set the list of names looked up to provide a cache key.
ks = []
for key in keys:
key = str(key).strip()
Expand Down Expand Up @@ -356,14 +354,12 @@ def manage_proxy(self, roles=(), REQUEST=None):

security.declareProtected(view_management_screens, 'PrincipiaSearchSource')
def PrincipiaSearchSource(self):
""" Support for searching - the document's contents are searched.
"""
# Support for searching - the document's contents are searched.
return self.read()

security.declareProtected(view_management_screens, 'document_src')
def document_src(self, REQUEST=None, RESPONSE=None):
""" Return unprocessed document source.
"""
# Return unprocessed document source.
if RESPONSE is not None:
RESPONSE.setHeader('Content-Type', 'text/plain')
return self.read()
Expand Down
43 changes: 19 additions & 24 deletions src/OFS/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,23 @@ def manage_addFile(self, id, file='', title='', precondition='',
precondition = str(precondition)

id, title = cookId(id, title, file)

self=self.this()

# First, we create the file without data:
self._setObject(id, File(id,title,'',content_type, precondition))

newFile = self._getOb(id)

# Now we "upload" the data. By doing this in two steps, we
# can use a database trick to make the upload more efficient.
if file:
newFile.manage_upload(file)
if content_type:
newFile.content_type=content_type

notify(ObjectCreatedEvent(newFile))

if REQUEST is not None:
REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main')

Expand Down Expand Up @@ -436,8 +436,7 @@ def view_image_or_file(self, URL1):

security.declareProtected(View, 'PrincipiaSearchSource')
def PrincipiaSearchSource(self):
""" Allow file objects to be searched.
"""
# Allow file objects to be searched.
if self.content_type.startswith('text/'):
return str(self.data)
return ''
Expand Down Expand Up @@ -473,9 +472,9 @@ def manage_edit(self, title, content_type, precondition='',
self.update_data(filedata, content_type, len(filedata))
else:
self.ZCacheable_invalidate()

notify(ObjectModifiedEvent(self))

if REQUEST:
message="Saved changes."
return self.manage_main(self,REQUEST,manage_tabs_message=message)
Expand All @@ -494,9 +493,9 @@ def manage_upload(self,file='',REQUEST=None):
content_type=self._get_content_type(file, data, self.__name__,
'application/octet-stream')
self.update_data(data, content_type, size)

notify(ObjectModifiedEvent(self))

if REQUEST:
message="Saved changes."
return self.manage_main(self,REQUEST,manage_tabs_message=message)
Expand Down Expand Up @@ -600,10 +599,8 @@ def PUT(self, REQUEST, RESPONSE):

security.declareProtected(View, 'get_size')
def get_size(self):
"""Get the size of a file or image.
Returns the size of the file or image.
"""
# Get the size of a file or image.
# Returns the size of the file or image.
size=self.size
if size is None: size=len(self.data)
return size
Expand All @@ -613,10 +610,8 @@ def get_size(self):

security.declareProtected(View, 'getContentType')
def getContentType(self):
"""Get the content type of a file or image.
Returns the content type (MIME type) of a file or image.
"""
# Get the content type of a file or image.
# Returns the content type (MIME type) of a file or image.
return self.content_type


Expand Down Expand Up @@ -677,18 +672,18 @@ def manage_addImage(self, id, file, title='', precondition='', content_type='',

# First, we create the image without data:
self._setObject(id, Image(id,title,'',content_type, precondition))

newFile = self._getOb(id)

# Now we "upload" the data. By doing this in two steps, we
# can use a database trick to make the upload more efficient.
if file:
newFile.manage_upload(file)
if content_type:
newFile.content_type=content_type

notify(ObjectCreatedEvent(newFile))

if REQUEST is not None:
try: url=self.DestinationURL()
except: url=REQUEST['URL1']
Expand Down Expand Up @@ -812,7 +807,7 @@ def update_data(self, data, content_type=None, size=None):
if isinstance(data, unicode):
raise TypeError('Data can only be str or file-like. '
'Unicode objects are expressly forbidden.')

if size is None: size=len(data)

self.size=size
Expand Down
11 changes: 5 additions & 6 deletions src/OFS/ObjectManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,11 @@ def _getOb(self, id, default=_marker):

security.declareProtected(access_contents_information, 'hasObject')
def hasObject(self, id):
"""Indicate whether the folder has an item by ID.
This doesn't try to be more intelligent than _getOb, and doesn't
consult _objects (for performance reasons). The common use case
is to check that an object does *not* exist.
"""
# Indicate whether the folder has an item by ID.
#
# This doesn't try to be more intelligent than _getOb, and doesn't
# consult _objects (for performance reasons). The common use case
# is to check that an object does *not* exist.
if (id in ('.', '..') or
id.startswith('_') or
id.startswith('aq_') or
Expand Down
30 changes: 10 additions & 20 deletions src/OFS/OrderSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ def manage_set_default_sorting(self, REQUEST, key, reverse):
security.declareProtected(manage_properties, 'moveObjectsByDelta')
def moveObjectsByDelta(self, ids, delta, subset_ids=None,
suppress_events=False):
""" Move specified sub-objects by delta.
"""
# Move specified sub-objects by delta.
if isinstance(ids, basestring):
ids = (ids,)
min_position = 0
Expand Down Expand Up @@ -183,32 +182,27 @@ def moveObjectsByDelta(self, ids, delta, subset_ids=None,

security.declareProtected(manage_properties, 'moveObjectsUp')
def moveObjectsUp(self, ids, delta=1, subset_ids=None):
""" Move specified sub-objects up by delta in container.
"""
# Move specified sub-objects up by delta in container.
return self.moveObjectsByDelta(ids, -delta, subset_ids)

security.declareProtected(manage_properties, 'moveObjectsDown')
def moveObjectsDown(self, ids, delta=1, subset_ids=None):
""" Move specified sub-objects down by delta in container.
"""
# Move specified sub-objects down by delta in container.
return self.moveObjectsByDelta(ids, delta, subset_ids)

security.declareProtected(manage_properties, 'moveObjectsToTop')
def moveObjectsToTop(self, ids, subset_ids=None):
""" Move specified sub-objects to top of container.
"""
# Move specified sub-objects to top of container.
return self.moveObjectsByDelta( ids, -len(self._objects), subset_ids )

security.declareProtected(manage_properties, 'moveObjectsToBottom')
def moveObjectsToBottom(self, ids, subset_ids=None):
""" Move specified sub-objects to bottom of container.
"""
# Move specified sub-objects to bottom of container.
return self.moveObjectsByDelta( ids, len(self._objects), subset_ids )

security.declareProtected(manage_properties, 'orderObjects')
def orderObjects(self, key, reverse=None):
""" Order sub-objects by key and direction.
"""
# Order sub-objects by key and direction.
ids = [ id for id, obj in sort( self.objectItems(),
( (key, 'cmp', 'asc'), ) ) ]
if reverse:
Expand All @@ -218,31 +212,27 @@ def orderObjects(self, key, reverse=None):
security.declareProtected(access_contents_information,
'getObjectPosition')
def getObjectPosition(self, id):
""" Get the position of an object by its id.
"""
# Get the position of an object by its id.
ids = self.objectIds()
if id in ids:
return ids.index(id)
raise ValueError('The object with the id "%s" does not exist.' % id)

security.declareProtected(manage_properties, 'moveObjectToPosition')
def moveObjectToPosition(self, id, position, suppress_events=False):
""" Move specified object to absolute position.
"""
# Move specified object to absolute position.
delta = position - self.getObjectPosition(id)
return self.moveObjectsByDelta(id, delta,
suppress_events=suppress_events)

security.declareProtected(access_contents_information, 'getDefaultSorting')
def getDefaultSorting(self):
""" Get default sorting key and direction.
"""
# Get default sorting key and direction.
return self._default_sort_key, self._default_sort_reverse

security.declareProtected(manage_properties, 'setDefaultSorting')
def setDefaultSorting(self, key, reverse):
""" Set default sorting key and direction.
"""
# Set default sorting key and direction.
self._default_sort_key = key
self._default_sort_reverse = reverse and 1 or 0

Expand Down
10 changes: 5 additions & 5 deletions src/OFS/PropertySheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ class PropertySheet(Traversable, Persistent, Implicit):
__reserved_ids= ('values','items')

def property_extensible_schema__(self):
"""Return a flag indicating whether new properties may be
added or removed."""
# Return a flag indicating whether new properties may be
# added or removed.
return self._extensible

def __init__(self, id, md=None):
Expand Down Expand Up @@ -171,8 +171,8 @@ def getProperty(self, id, default=None):

security.declareProtected(access_contents_information, 'getPropertyType')
def getPropertyType(self, id):
"""Get the type of property 'id', returning None if no
such property exists"""
# Get the type of property 'id', returning None if no
# such property exists.
pself=self.p_self()
for md in pself._properties:
if md['id']==id:
Expand Down Expand Up @@ -707,7 +707,7 @@ def manage_delPropertySheets(self, ids=(), REQUEST=None):
raise BadRequest(
'attempt to delete undeletable property sheet: ' + id)
self.delPropertySheet(id)
if REQUEST is not None:
if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage' % self.absolute_url())

def __len__(self):
Expand Down
12 changes: 6 additions & 6 deletions src/OFS/Traversable.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ def virtual_url_path(self):

security.declarePublic('getPhysicalPath')
def getPhysicalPath(self):
"""Get the physical path of the object.
# 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.

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))
Expand Down

0 comments on commit 547be40

Please sign in to comment.