Commit 547be401 authored by Hanno Schlichting's avatar Hanno Schlichting Committed by GitHub

Merge pull request #63 from zopefoundation/apply-hotfix-20160419-rebased

Apply hotfix 20160419 rebased
parents 0b382a60 cc6c0ee9
...@@ -8,10 +8,12 @@ http://docs.zope.org/zope2/ ...@@ -8,10 +8,12 @@ http://docs.zope.org/zope2/
2.13.25 (unreleased) 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 - Optimized the `OFS.ObjectManager.__contains__` method to do the
least amount of work necessary. least amount of work necessary.
2.13.24 (2016-02-29) 2.13.24 (2016-02-29)
-------------------- --------------------
......
...@@ -202,13 +202,13 @@ class Application(ApplicationDefaultPermissions, ...@@ -202,13 +202,13 @@ class Application(ApplicationDefaultPermissions,
return self return self
def getPhysicalPath(self): 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 # 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. # access this object again later, for example in a copy/paste
getPhysicalRoot() and getPhysicalPath() are designed to operate # operation. getPhysicalRoot() and getPhysicalPath() are designed to
together. # operate together.
""" #
# We're at the base of the path. # We're at the base of the path.
return ('',) return ('',)
......
...@@ -144,9 +144,7 @@ class Cacheable: ...@@ -144,9 +144,7 @@ class Cacheable:
security.declarePrivate('ZCacheable_getObAndView') security.declarePrivate('ZCacheable_getObAndView')
def ZCacheable_getObAndView(self, view_name): def ZCacheable_getObAndView(self, view_name):
""" # Returns self and view_name unchanged.
Returns self and view_name unchanged.
"""
return self, view_name return self, view_name
security.declarePrivate('ZCacheable_get') security.declarePrivate('ZCacheable_get')
......
...@@ -201,14 +201,12 @@ class DTMLMethod(RestrictedDTML, ...@@ -201,14 +201,12 @@ class DTMLMethod(RestrictedDTML,
security.declareProtected(change_dtml_methods, 'getCacheNamespaceKeys') security.declareProtected(change_dtml_methods, 'getCacheNamespaceKeys')
def getCacheNamespaceKeys(self): def getCacheNamespaceKeys(self):
""" Return the cacheNamespaceKeys. # Return the cacheNamespaceKeys.
"""
return self._cache_namespace_keys return self._cache_namespace_keys
security.declareProtected(change_dtml_methods, 'setCacheNamespaceKeys') security.declareProtected(change_dtml_methods, 'setCacheNamespaceKeys')
def setCacheNamespaceKeys(self, keys, REQUEST=None): 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 = [] ks = []
for key in keys: for key in keys:
key = str(key).strip() key = str(key).strip()
...@@ -356,14 +354,12 @@ class DTMLMethod(RestrictedDTML, ...@@ -356,14 +354,12 @@ class DTMLMethod(RestrictedDTML,
security.declareProtected(view_management_screens, 'PrincipiaSearchSource') security.declareProtected(view_management_screens, 'PrincipiaSearchSource')
def PrincipiaSearchSource(self): def PrincipiaSearchSource(self):
""" Support for searching - the document's contents are searched. # Support for searching - the document's contents are searched.
"""
return self.read() return self.read()
security.declareProtected(view_management_screens, 'document_src') security.declareProtected(view_management_screens, 'document_src')
def document_src(self, REQUEST=None, RESPONSE=None): def document_src(self, REQUEST=None, RESPONSE=None):
""" Return unprocessed document source. # Return unprocessed document source.
"""
if RESPONSE is not None: if RESPONSE is not None:
RESPONSE.setHeader('Content-Type', 'text/plain') RESPONSE.setHeader('Content-Type', 'text/plain')
return self.read() return self.read()
......
...@@ -436,8 +436,7 @@ class File(Persistent, Implicit, PropertyManager, ...@@ -436,8 +436,7 @@ class File(Persistent, Implicit, PropertyManager,
security.declareProtected(View, 'PrincipiaSearchSource') security.declareProtected(View, 'PrincipiaSearchSource')
def PrincipiaSearchSource(self): def PrincipiaSearchSource(self):
""" Allow file objects to be searched. # Allow file objects to be searched.
"""
if self.content_type.startswith('text/'): if self.content_type.startswith('text/'):
return str(self.data) return str(self.data)
return '' return ''
...@@ -600,10 +599,8 @@ class File(Persistent, Implicit, PropertyManager, ...@@ -600,10 +599,8 @@ class File(Persistent, Implicit, PropertyManager,
security.declareProtected(View, 'get_size') security.declareProtected(View, 'get_size')
def get_size(self): def get_size(self):
"""Get the size of a file or image. # Get the size of a file or image.
# Returns the size of the file or image.
Returns the size of the file or image.
"""
size=self.size size=self.size
if size is None: size=len(self.data) if size is None: size=len(self.data)
return size return size
...@@ -613,10 +610,8 @@ class File(Persistent, Implicit, PropertyManager, ...@@ -613,10 +610,8 @@ class File(Persistent, Implicit, PropertyManager,
security.declareProtected(View, 'getContentType') security.declareProtected(View, 'getContentType')
def getContentType(self): def getContentType(self):
"""Get the content 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.
Returns the content type (MIME type) of a file or image.
"""
return self.content_type return self.content_type
......
...@@ -303,12 +303,11 @@ class ObjectManager(CopyContainer, ...@@ -303,12 +303,11 @@ class ObjectManager(CopyContainer,
security.declareProtected(access_contents_information, 'hasObject') security.declareProtected(access_contents_information, 'hasObject')
def hasObject(self, id): def hasObject(self, id):
"""Indicate whether the folder has an item by ID. # Indicate whether the folder has an item by ID.
#
This doesn't try to be more intelligent than _getOb, and doesn't # This doesn't try to be more intelligent than _getOb, and doesn't
consult _objects (for performance reasons). The common use case # consult _objects (for performance reasons). The common use case
is to check that an object does *not* exist. # is to check that an object does *not* exist.
"""
if (id in ('.', '..') or if (id in ('.', '..') or
id.startswith('_') or id.startswith('_') or
id.startswith('aq_') or id.startswith('aq_') or
......
...@@ -132,8 +132,7 @@ class OrderSupport(object): ...@@ -132,8 +132,7 @@ class OrderSupport(object):
security.declareProtected(manage_properties, 'moveObjectsByDelta') security.declareProtected(manage_properties, 'moveObjectsByDelta')
def moveObjectsByDelta(self, ids, delta, subset_ids=None, def moveObjectsByDelta(self, ids, delta, subset_ids=None,
suppress_events=False): suppress_events=False):
""" Move specified sub-objects by delta. # Move specified sub-objects by delta.
"""
if isinstance(ids, basestring): if isinstance(ids, basestring):
ids = (ids,) ids = (ids,)
min_position = 0 min_position = 0
...@@ -183,32 +182,27 @@ class OrderSupport(object): ...@@ -183,32 +182,27 @@ class OrderSupport(object):
security.declareProtected(manage_properties, 'moveObjectsUp') security.declareProtected(manage_properties, 'moveObjectsUp')
def moveObjectsUp(self, ids, delta=1, subset_ids=None): 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) return self.moveObjectsByDelta(ids, -delta, subset_ids)
security.declareProtected(manage_properties, 'moveObjectsDown') security.declareProtected(manage_properties, 'moveObjectsDown')
def moveObjectsDown(self, ids, delta=1, subset_ids=None): 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) return self.moveObjectsByDelta(ids, delta, subset_ids)
security.declareProtected(manage_properties, 'moveObjectsToTop') security.declareProtected(manage_properties, 'moveObjectsToTop')
def moveObjectsToTop(self, ids, subset_ids=None): 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 ) return self.moveObjectsByDelta( ids, -len(self._objects), subset_ids )
security.declareProtected(manage_properties, 'moveObjectsToBottom') security.declareProtected(manage_properties, 'moveObjectsToBottom')
def moveObjectsToBottom(self, ids, subset_ids=None): 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 ) return self.moveObjectsByDelta( ids, len(self._objects), subset_ids )
security.declareProtected(manage_properties, 'orderObjects') security.declareProtected(manage_properties, 'orderObjects')
def orderObjects(self, key, reverse=None): 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(), ids = [ id for id, obj in sort( self.objectItems(),
( (key, 'cmp', 'asc'), ) ) ] ( (key, 'cmp', 'asc'), ) ) ]
if reverse: if reverse:
...@@ -218,8 +212,7 @@ class OrderSupport(object): ...@@ -218,8 +212,7 @@ class OrderSupport(object):
security.declareProtected(access_contents_information, security.declareProtected(access_contents_information,
'getObjectPosition') 'getObjectPosition')
def getObjectPosition(self, id): 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() ids = self.objectIds()
if id in ids: if id in ids:
return ids.index(id) return ids.index(id)
...@@ -227,22 +220,19 @@ class OrderSupport(object): ...@@ -227,22 +220,19 @@ class OrderSupport(object):
security.declareProtected(manage_properties, 'moveObjectToPosition') security.declareProtected(manage_properties, 'moveObjectToPosition')
def moveObjectToPosition(self, id, position, suppress_events=False): 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) delta = position - self.getObjectPosition(id)
return self.moveObjectsByDelta(id, delta, return self.moveObjectsByDelta(id, delta,
suppress_events=suppress_events) suppress_events=suppress_events)
security.declareProtected(access_contents_information, 'getDefaultSorting') security.declareProtected(access_contents_information, 'getDefaultSorting')
def getDefaultSorting(self): def getDefaultSorting(self):
""" Get default sorting key and direction. # Get default sorting key and direction.
"""
return self._default_sort_key, self._default_sort_reverse return self._default_sort_key, self._default_sort_reverse
security.declareProtected(manage_properties, 'setDefaultSorting') security.declareProtected(manage_properties, 'setDefaultSorting')
def setDefaultSorting(self, key, reverse): 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_key = key
self._default_sort_reverse = reverse and 1 or 0 self._default_sort_reverse = reverse and 1 or 0
......
...@@ -114,8 +114,8 @@ class PropertySheet(Traversable, Persistent, Implicit): ...@@ -114,8 +114,8 @@ class PropertySheet(Traversable, Persistent, Implicit):
__reserved_ids= ('values','items') __reserved_ids= ('values','items')
def property_extensible_schema__(self): def property_extensible_schema__(self):
"""Return a flag indicating whether new properties may be # Return a flag indicating whether new properties may be
added or removed.""" # added or removed.
return self._extensible return self._extensible
def __init__(self, id, md=None): def __init__(self, id, md=None):
...@@ -171,8 +171,8 @@ class PropertySheet(Traversable, Persistent, Implicit): ...@@ -171,8 +171,8 @@ class PropertySheet(Traversable, Persistent, Implicit):
security.declareProtected(access_contents_information, 'getPropertyType') security.declareProtected(access_contents_information, 'getPropertyType')
def getPropertyType(self, id): def getPropertyType(self, id):
"""Get the type of property 'id', returning None if no # Get the type of property 'id', returning None if no
such property exists""" # such property exists.
pself=self.p_self() pself=self.p_self()
for md in pself._properties: for md in pself._properties:
if md['id']==id: if md['id']==id:
......
...@@ -108,13 +108,13 @@ class Traversable: ...@@ -108,13 +108,13 @@ class Traversable:
security.declarePublic('getPhysicalPath') security.declarePublic('getPhysicalPath')
def getPhysicalPath(self): 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(),) path = (self.getId(),)
p = aq_parent(aq_inner(self)) p = aq_parent(aq_inner(self))
......
...@@ -95,61 +95,61 @@ class Node: ...@@ -95,61 +95,61 @@ class Node:
security.declareProtected(access_contents_information, 'getNodeName') security.declareProtected(access_contents_information, 'getNodeName')
def getNodeName(self): def getNodeName(self):
"""The name of this node, depending on its type""" # The name of this node, depending on its type.
return None return None
security.declareProtected(access_contents_information, 'getNodeValue') security.declareProtected(access_contents_information, 'getNodeValue')
def getNodeValue(self): def getNodeValue(self):
"""The value of this node, depending on its type""" # The value of this node, depending on its type.
return None return None
security.declareProtected(access_contents_information, 'getParentNode') security.declareProtected(access_contents_information, 'getParentNode')
def getParentNode(self): def getParentNode(self):
"""The parent of this node. All nodes except Document # The parent of this node. All nodes except Document,
DocumentFragment and Attr may have a parent""" # DocumentFragment and Attr may have a parent.
return None return None
security.declareProtected(access_contents_information, 'getChildNodes') security.declareProtected(access_contents_information, 'getChildNodes')
def getChildNodes(self): def getChildNodes(self):
"""Returns a NodeList that contains all children of this node. # Returns a NodeList that contains all children of this node.
If there are no children, this is a empty NodeList""" # If there are no children, this is a empty NodeList
return NodeList() return NodeList()
security.declareProtected(access_contents_information, 'getFirstChild') security.declareProtected(access_contents_information, 'getFirstChild')
def getFirstChild(self): def getFirstChild(self):
"""The first child of this node. If there is no such node # The first child of this node. If there is no such node
this returns None.""" # this returns None.
return None return None
security.declareProtected(access_contents_information, 'getLastChild') security.declareProtected(access_contents_information, 'getLastChild')
def getLastChild(self): def getLastChild(self):
"""The last child of this node. If there is no such node # The last child of this node. If there is no such node
this returns None.""" # this returns None.
return None return None
security.declareProtected(access_contents_information, security.declareProtected(access_contents_information,
'getPreviousSibling') 'getPreviousSibling')
def getPreviousSibling(self): def getPreviousSibling(self):
"""The node immediately preceding this node. If # The node immediately preceding this node.
there is no such node, this returns None.""" # If there is no such node, this returns None.
return None return None
security.declareProtected(access_contents_information, 'getNextSibling') security.declareProtected(access_contents_information, 'getNextSibling')
def getNextSibling(self): def getNextSibling(self):
"""The node immediately preceding this node. If # The node immediately preceding this node.
there is no such node, this returns None.""" # If there is no such node, this returns None.
return None return None
security.declareProtected(access_contents_information, 'getAttributes') security.declareProtected(access_contents_information, 'getAttributes')
def getAttributes(self): def getAttributes(self):
"""Returns a NamedNodeMap containing the attributes # Returns a NamedNodeMap containing the attributes
of this node (if it is an element) or None otherwise.""" # of this node (if it is an element) or None otherwise.
return None return None
security.declareProtected(access_contents_information, 'getOwnerDocument') security.declareProtected(access_contents_information, 'getOwnerDocument')
def getOwnerDocument(self): def getOwnerDocument(self):
"""The Document object associated with this node. # The Document object associated with this node.
When this is a document this is None""" # When this is a document this is None.
node = self node = self
if hasattr(node, 'aq_parent'): if hasattr(node, 'aq_parent'):
node = aq_parent(self) node = aq_parent(self)
...@@ -161,8 +161,8 @@ class Node: ...@@ -161,8 +161,8 @@ class Node:
security.declareProtected(access_contents_information, 'hasChildNodes') security.declareProtected(access_contents_information, 'hasChildNodes')
def hasChildNodes(self): def hasChildNodes(self):
"""Returns true if the node has any children, false # Returns true if the node has any children, false
if it doesn't. """ # if it doesn't.
return len(self.objectIds()) return len(self.objectIds())
InitializeClass(Node) InitializeClass(Node)
...@@ -180,63 +180,57 @@ class Document(Explicit, Node): ...@@ -180,63 +180,57 @@ class Document(Explicit, Node):
security.declareProtected(access_contents_information, 'getImplementation') security.declareProtected(access_contents_information, 'getImplementation')
def getImplementation(self): def getImplementation(self):
""" # The DOMImplementation object that handles this document.
The DOMImplementation object that handles this document.
"""
return DOMImplementation() return DOMImplementation()
security.declareProtected(access_contents_information, 'getDoctype') security.declareProtected(access_contents_information, 'getDoctype')
def getDoctype(self): def getDoctype(self):
""" # The Document Type Declaration associated with this document.
The Document Type Declaration associated with this document. # For HTML documents as well as XML documents without
For HTML documents as well as XML documents without # a document type declaration this returns null.
a document type declaration this returns null.
"""
return None return None
security.declareProtected(access_contents_information, security.declareProtected(access_contents_information,
'getDocumentElement') 'getDocumentElement')
def getDocumentElement(self): def getDocumentElement(self):
""" # This is a convenience attribute that allows direct access to
This is a convenience attribute that allows direct access to # the child node that is the root element of the document.
the child node that is the root element of the document.
"""
return aq_parent(self) return aq_parent(self)
# Node Methods # Node Methods
# ------------ # ------------
def getNodeName(self): def getNodeName(self):
"""The name of this node, depending on its type""" # The name of this node, depending on its type.
return '#document' return '#document'
def getNodeType(self): def getNodeType(self):
"""A code representing the type of the node.""" # A code representing the type of the node.
return DOCUMENT_NODE return DOCUMENT_NODE
def getOwnerDocument(self): def getOwnerDocument(self):
"""The Document object associated with this node. # The Document object associated with this node.
When this is a document this is None""" # When this is a document this is None.
return self return self
def getChildNodes(self): def getChildNodes(self):
"""Returns a NodeList that contains all children of this node. # Returns a NodeList that contains all children of this node.
If there are no children, this is a empty NodeList""" # If there are no children, this is a empty NodeList.
return NodeList([aq_parent(self)]) return NodeList([aq_parent(self)])
def getFirstChild(self): def getFirstChild(self):
"""The first child of this node. If there is no such node # The first child of this node. If there is no such node
this returns None.""" # this returns None.
return aq_parent(self) return aq_parent(self)
def getLastChild(self): def getLastChild(self):
"""The last child of this node. If there is no such node # The last child of this node. If there is no such node
this returns None.""" # this returns None.
return aq_parent(self) return aq_parent(self)
def hasChildNodes(self): def hasChildNodes(self):
"""Returns true if the node has any children, false # Returns true if the node has any children, false
if it doesn't. """ # if it doesn't.
return 1 return 1
InitializeClass(Document) InitializeClass(Document)
...@@ -283,49 +277,49 @@ class Element(Node): ...@@ -283,49 +277,49 @@ class Element(Node):
security.declareProtected(access_contents_information, 'getTagName') security.declareProtected(access_contents_information, 'getTagName')
def getTagName(self): def getTagName(self):
"""The name of the element""" # The name of the element.
return self.__class__.__name__ return self.__class__.__name__
# Node Attributes # Node Attributes
# --------------- # ---------------
def getNodeName(self): def getNodeName(self):
"""The name of this node, depending on its type""" # The name of this node, depending on its type.
return self.getTagName() return self.getTagName()
def getNodeType(self): def getNodeType(self):
"""A code representing the type of the node.""" # A code representing the type of the node.
return ELEMENT_NODE return ELEMENT_NODE
def getParentNode(self): def getParentNode(self):
"""The parent of this node. All nodes except Document # The parent of this node. All nodes except Document,
DocumentFragment and Attr may have a parent""" # DocumentFragment and Attr may have a parent.
return getattr(self, 'aq_parent', None) return getattr(self, 'aq_parent', None)
def getChildNodes(self): def getChildNodes(self):
"""Returns a NodeList that contains all children of this node. # Returns a NodeList that contains all children of this node.
If there are no children, this is a empty NodeList""" # If there are no children, this is a empty NodeList.
return NodeList(self.objectValues()) return NodeList(self.objectValues())
def getFirstChild(self): def getFirstChild(self):
"""The first child of this node. If there is no such node # The first child of this node. If there is no such node
this returns None""" # this returns None
children = self.getChildNodes() children = self.getChildNodes()
if children: if children:
return children._data[0] return children._data[0]
return None return None
def getLastChild(self): def getLastChild(self):
"""The last child of this node. If there is no such node # The last child of this node. If there is no such node
this returns None.""" # this returns None.
children = self.getChildNodes() children = self.getChildNodes()
if children: if children:
return children._data[-1] return children._data[-1]
return None return None
def getPreviousSibling(self): def getPreviousSibling(self):
"""The node immediately preceding this node. If # The node immediately preceding this node.
there is no such node, this returns None.""" # If there is no such node, this returns None.
if hasattr(self, 'aq_parent'): if hasattr(self, 'aq_parent'):
parent = aq_parent(self) parent = aq_parent(self)
ids=list(parent.objectIds()) ids=list(parent.objectIds())
...@@ -338,8 +332,8 @@ class Element(Node): ...@@ -338,8 +332,8 @@ class Element(Node):
return None return None
def getNextSibling(self): def getNextSibling(self):
"""The node immediately preceding this node. If # The node immediately preceding this node.
there is no such node, this returns None.""" # If there is no such node, this returns None.
if hasattr(self, 'aq_parent'): if hasattr(self, 'aq_parent'):
parent = aq_parent(self) parent = aq_parent(self)
ids=list(parent.objectIds()) ids=list(parent.objectIds())
...@@ -356,24 +350,23 @@ class Element(Node): ...@@ -356,24 +350,23 @@ class Element(Node):
security.declareProtected(access_contents_information, 'getAttribute') security.declareProtected(access_contents_information, 'getAttribute')
def getAttribute(self, name): def getAttribute(self, name):
"""Retrieves an attribute value by name.""" # Retrieves an attribute value by name.
return None return None
security.declareProtected(access_contents_information, 'getAttributeNode') security.declareProtected(access_contents_information, 'getAttributeNode')
def getAttributeNode(self, name): def getAttributeNode(self, name):
""" Retrieves an Attr node by name or None if # Retrieves an Attr node by name or None if
there is no such attribute. """ # there is no such attribute.
return None return None
security.declareProtected(access_contents_information, security.declareProtected(access_contents_information,
'getElementsByTagName') 'getElementsByTagName')
def getElementsByTagName(self, tagname): def getElementsByTagName(self, tagname):
""" Returns a NodeList of all the Elements with a given tag # Returns a NodeList of all the Elements with a given tag
name in the order in which they would be encountered in a # name in the order in which they would be encountered in a
preorder traversal of the Document tree. Parameter: tagname # preorder traversal of the Document tree. Parameter: tagname
The name of the tag to match (* = all tags). Return Value: A new # The name of the tag to match (* = all tags). Return Value: A new
NodeList object containing all the matched Elements. # NodeList object containing all the matched Elements.
"""
nodeList = [] nodeList = []
for child in self.objectValues(): for child in self.objectValues():
if (child.getNodeType()==ELEMENT_NODE and \ if (child.getNodeType()==ELEMENT_NODE and \
...@@ -395,8 +388,8 @@ class ElementWithAttributes(Element): ...@@ -395,8 +388,8 @@ class ElementWithAttributes(Element):
""" """
def getAttributes(self): def getAttributes(self):
"""Returns a NamedNodeMap containing the attributes # Returns a NamedNodeMap containing the attributes
of this node (if it is an element) or None otherwise.""" # of this node (if it is an element) or None otherwise.
attribs={} attribs={}
for p in self._properties: for p in self._properties:
if p['type'] == 'string': if p['type'] == 'string':
...@@ -406,13 +399,13 @@ class ElementWithAttributes(Element): ...@@ -406,13 +399,13 @@ class ElementWithAttributes(Element):
return NamedNodeMap(attribs) return NamedNodeMap(attribs)
def getAttribute(self, name): def getAttribute(self, name):
"""Retrieves an attribute value by name.""" # Retrieves an attribute value by name.
if self.getPropertyType(name) == 'string': if self.getPropertyType(name) == 'string':
return self.getProperty(name,'') return self.getProperty(name,'')
def getAttributeNode(self, name): def getAttributeNode(self, name):
"""Retrieves an Attr node by name or None if # Retrieves an Attr node by name or None if
there is no such attribute. """ # there is no such attribute.
if self.getPropertyType(name) == 'string': if self.getPropertyType(name) == 'string':
return Attr(name, self.getProperty(name,'')).__of__(self) return Attr(name, self.getProperty(name,'')).__of__(self)
return None return None
...@@ -426,22 +419,22 @@ class ElementWithTitle(Element): ...@@ -426,22 +419,22 @@ class ElementWithTitle(Element):
""" """
def getAttributes(self): def getAttributes(self):
"""Returns a NamedNodeMap containing the attributes # Returns a NamedNodeMap containing the attributes
of this node (if it is an element) or None otherwise.""" # of this node (if it is an element) or None otherwise.
title = self.getAttributeNode('title') title = self.getAttributeNode('title')
if title is not None: if title is not None:
return NamedNodeMap({'title':title}) return NamedNodeMap({'title':title})
return NamedNodeMap() return NamedNodeMap()
def getAttribute(self, name): def getAttribute(self, name):
"""Retrieves an attribute value by name.""" # Retrieves an attribute value by name.
if name=='title' and hasattr(aq_base(self), 'title'): if name=='title' and hasattr(aq_base(self), 'title'):
return self.title return self.title
return '' return ''
def getAttributeNode(self, name): def getAttributeNode(self, name):
"""Retrieves an Attr node by name or None if # Retrieves an Attr node by name or None if
there is no such attribute. """ # there is no such attribute.
value=self.getAttribute(name) value=self.getAttribute(name)
if value: if value:
return Attr(name, value).__of__(self) return Attr(name, value).__of__(self)
...@@ -454,8 +447,6 @@ class Root(ElementWithAttributes): ...@@ -454,8 +447,6 @@ class Root(ElementWithAttributes):
""" """
def getOwnerDocument(self): def getOwnerDocument(self):
"""
"""
return Document().__of__(self) return Document().__of__(self)
...@@ -479,12 +470,12 @@ class NodeList: ...@@ -479,12 +470,12 @@ class NodeList:
return self._data[index] return self._data[index]
def item(self, index): def item(self, index):
"""Returns the index-th item in the collection""" # Returns the index-th item in the collection.
try: return self._data[index] try: return self._data[index]
except IndexError: return None except IndexError: return None
def getLength(self): def getLength(self):
"""The length of the NodeList""" # The length of the NodeList.
return len(self._data) return len(self._data)
__len__=getLength __len__=getLength
...@@ -508,7 +499,7 @@ class NamedNodeMap: ...@@ -508,7 +499,7 @@ class NamedNodeMap:
self._data = data self._data = data
def item(self, index): def item(self, index):
"""Returns the index-th item in the map""" # Returns the index-th item in the map.
try: return self._data.values()[index] try: return self._data.values()[index]
except IndexError: return None except IndexError: return None
...@@ -519,17 +510,16 @@ class NamedNodeMap: ...@@ -519,17 +510,16 @@ class NamedNodeMap:
return self._data[key] return self._data[key]
def getLength(self): def getLength(self):
"""The length of the NodeList""" # The length of the NodeList.
return len(self._data) return len(self._data)
__len__ = getLength __len__ = getLength
def getNamedItem(self, name): def getNamedItem(self, name):
"""Retrieves a node specified by name. Parameters: # Retrieves a node specified by name. Parameters:
name Name of a node to retrieve. Return Value A Node (of any # name Name of a node to retrieve. Return Value A Node (of any
type) with the specified name, or None if the specified name # type) with the specified name, or None if the specified name
did not identify any node in the map. # did not identify any node in the map.
"""
if self._data.has_key(name): if self._data.has_key(name):
return self._data[name] return self._data[name]
return None return None
...@@ -547,22 +537,22 @@ class Attr(Implicit, Node): ...@@ -547,22 +537,22 @@ class Attr(Implicit, Node):
self.specified = 1 self.specified = 1
def getNodeName(self): def getNodeName(self):
"""The name of this node, depending on its type""" # The name of this node, depending on its type.
return self.name return self.name
def getName(self): def getName(self):
"""Returns the name of this attribute.""" # Returns the name of this attribute.
return self.name return self.name
def getNodeValue(self): def getNodeValue(self):
"""The value of this node, depending on its type""" # The value of this node, depending on its type.
return self.value return self.value
def getNodeType(self): def getNodeType(self):
"""A code representing the type of the node.""" # A code representing the type of the node.
return ATTRIBUTE_NODE return ATTRIBUTE_NODE
def getSpecified(self): def getSpecified(self):
"""If this attribute was explicitly given a value in the # If this attribute was explicitly given a value in the
original document, this is true; otherwise, it is false.""" # original document, this is true; otherwise, it is false.
return self.specified return self.specified
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