CVS: Products/ParsedXML - CHANGES.txt:1.23 ManageableDOM.py:1.119 ParsedXML.py:1.47

Martijn Faassen <[email protected]> Wed, 28 Apr 2004 10:55:18 -0400
Newsgroups gmane.comp.web.zope.parsed-xml
Message-ID <[email protected]>
Update of /cvs-repository/Products/ParsedXML
In directory cvs.zope.org:/tmp/cvs-serv12897

Modified Files:
	CHANGES.txt ManageableDOM.py ParsedXML.py 
Log Message:
Switched to new style security declarations and added a few.


=== Products/ParsedXML/CHANGES.txt 1.22 => 1.23 ===
--- Products/ParsedXML/CHANGES.txt:1.22	Wed Apr 28 08:09:13 2004
+++ Products/ParsedXML/CHANGES.txt	Wed Apr 28 10:55:07 2004
@@ -21,6 +21,9 @@
         complex. If you have XML text in a non-UTF-8 encoding upload
         it as a file rather than copy and paste it.
 
+      - Switched over to new-style security declarations and added a
+        few.
+
     Bugs Fixed
 
       - Cleaned out tests so they all pass. This was done


=== Products/ParsedXML/ManageableDOM.py 1.118 => 1.119 ===
--- Products/ParsedXML/ManageableDOM.py:1.118	Wed Apr 28 08:09:13 2004
+++ Products/ParsedXML/ManageableDOM.py	Wed Apr 28 10:55:08 2004
@@ -14,6 +14,7 @@
 """
 Zope management support for DOM classes.
 """
+from AccessControl import ClassSecurityInfo
 
 import Globals
 import Acquisition
@@ -23,26 +24,20 @@
 from DateTime import DateTime # for manage_edit cookie expire
 import marshal # for ftp
 from Globals import DTMLFile
-
 import DOMProxy
 import DOM
 import ExtraDOM
-
 import string
 from xml.parsers import expat
-
 import xml.dom
 import types
-
 from StringIO import StringIO
-
 from NodePath import registry
 
 parserr=('Sorry, an XML parsing error occurred.  Check '
          'your XML document for well-formedness and try '
          'to upload it again after modification.<br><br>')
 
-
 # 
 # Management mixin classes
 #
@@ -50,7 +45,9 @@
 class DOMTraversable(Traversable):
     "Mixin class for DOM classes to provide Zope traversability."
 
-    getPhysicalPath__roles__ = None # Public
+    security = ClassSecurityInfo()
+
+    security.declarePublic('getPhysicalPath')
     def getPhysicalPath(self):
         """Returns a path that can be used to access this object again
         later."""
@@ -63,7 +60,8 @@
             return path + (nodepath,)
         else:
             return path
-
+        
+    security.declarePublic('getNodePath')
     def getNodePath(self, scheme_name):
         """Create a node path for this node.
         FIXME: this has the same name but other signature as the
@@ -87,7 +85,9 @@
             if parent == self:
                 return parent
         return self
-    
+
+Globals.InitializeClass(DOMTraversable)
+
 class DOMPublishable(DOMTraversable):
     "Mixin class for DOM classes to provide Zope publishability."
     # tree tag methods
@@ -172,63 +172,7 @@
     def manage_FTPget(self):
         """Returns the source content of an object. For example, the
         source text of a Document, or the data of a file."""
-        return self.__str__()
-        
-    #def manage_FTPstat(self,REQUEST):
-    #    """Returns a stat-like tuple. (marshalled to a string) Used by
-    #    FTP for directory listings, and MDTM and SIZE"""
-    #    # mode = 0100000 | 0004 | 0002 XXX open
-    #    from AccessControl.User import nobody
-    #    mode=0100000
-    #    
-    #    # read permissions
-    #    if (hasattr(self.aq_base,'manage_FTPget') and 
-    #        hasattr(self.manage_FTPget, '__roles__')):
-    #        try:
-    #            if getSecurityManager().validateValue(self.manage_FTPget):
-    #                mode=mode | 0440
-    #        except: pass
-    #        if nobody.allowed(self.manage_FTPget,
-    #                          self.manage_FTPget.__roles__):
-    #            mode=mode | 0004
-    #            
-    #    # write permissions
-    #    if hasattr(self.aq_base,'PUT') and hasattr(self.PUT, '__roles__'):
-    #        try:
-    #            if getSecurityManager().validateValue(self.PUT):
-    #                mode=mode | 0220
-    #        except: pass
-    #        
-    #        if nobody.allowed(self.PUT, self.PUT.__roles__):
-    #            mode=mode | 0002
-    #    
-    #    size = len(self.manage_FTPget())
-    #    # modification time
-    #    mtime = self.bobobase_modification_time().timeTime()
-    #    # owner and group
-    #    owner = group = 'Zope'
-    #    for user, roles in self.get_local_roles():
-    #        if 'Owner' in roles:
-    #            owner=user
-    #            break
-    #    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."""
-    #    # check to see if we are being acquiring or not
-    #    ob=self
-    #    while 1:
-    #        if App.Common.is_acquired(ob):
-    #            raise ValueError('FTP List not supported on acquired objects')
-    #        if not hasattr(ob,'aq_parent'):
-    #            break
-    #        ob=ob.aq_parent
-    #        
-    #    stat=marshal.loads(self.manage_FTPstat(REQUEST))
-    #    id = self.getId()
-    #    return marshal.dumps((id,stat))
-        
+        return self.__str__()        
 
 class DOMIO:
     "Mixin class for DOM classes to provide parsing, writing."
@@ -266,7 +210,7 @@
         outStr = string.replace(outStr, '>', '&gt;') 
         return outStr
 
-    def index_html(self, REQUEST = None, RESPONSE = None):
+    def index_html(self, REQUEST=None, RESPONSE=None):
         "Returns publishable source according to content type"
         # set content type header for raw XML if necessary
         if RESPONSE:
@@ -299,11 +243,18 @@
 class DOMManageable(DOMIO, DOMPublishable, App.Management.Tabs):
     "Mixin class for DOM classes to provide Zope management interfaces."
 
+    security = ClassSecurityInfo()
+    security.setPermissionDefault('View DOM hierarchy', ['Manager'])    
+    
     # the UI of ParsedXML is UTF-8
     management_page_charset = 'UTF-8'
-    
+
+    security.declareProtected('View management screens',
+                              'manage_editForm')
     manage_editForm = Globals.DTMLFile('dtml/transEdit', globals(),
                                        __name__='manage_editForm')
+    security.declareProtected('View DOM hierarchy',
+                              'manage_DOMTree')
     manage_DOMTree = Globals.DTMLFile('dtml/DOMTree', globals(),
                                       __name__='manage_DOMTree')
  
@@ -369,6 +320,7 @@
         return self.manage_editForm(self, REQUEST,
                                     dtpref_cols = cols, dtpref_rows = rows)
 
+    security.declareProtected('Edit ParsedXML', 'manage_edit')
     def manage_edit(self, data, title = '', contentType = None,
                     useNamespaces = 1,
                     SUBMIT = 'Change',
@@ -418,6 +370,7 @@
                                            management_view="Edit",
                                            manage_tabs_message=message)
 
+    security.declareProtected('Edit ParsedXML', 'manage_upload')
     def manage_upload(self, file, REQUEST=None):
         "Parse the given file and handle the result."
         try:
@@ -436,10 +389,11 @@
                     action = 'manage_editForm')
             raise
         if REQUEST:
-            return newNode.manage_editForm(self, REQUEST,
-                                           manage_tabs_message='Saved changes.')
+            return newNode.manage_editForm(
+                self, REQUEST,
+                manage_tabs_message='Saved changes.')
 
-Globals.default__class_init__(DOMManageable) # activate perms
+Globals.InitializeClass(DOMManageable)
 
 #
 # And finally, classes to mix management and DOM proxies.


=== Products/ParsedXML/ParsedXML.py 1.46 => 1.47 ===
--- Products/ParsedXML/ParsedXML.py:1.46	Wed Apr 28 08:09:13 2004
+++ Products/ParsedXML/ParsedXML.py	Wed Apr 28 10:55:08 2004
@@ -16,66 +16,23 @@
 """
 
 from OFS.SimpleItem import SimpleItem
+from AccessControl import ClassSecurityInfo
 from AccessControl.Role import RoleManager
 from Persistence import Persistent
 from Acquisition import Implicit
 from OFS.Cache import Cacheable
 import Globals
 from Globals import DTMLFile
-
 from ManageableDOM import ManageableDocument, DOMManageable, \
-     theDOMImplementation
+     theDOMImplementation, parserr
 from StringIO import StringIO
 from xml.parsers import expat
 import DOM, ExtraDOM
 import helpers
-
-from types import FileType, StringType
-from urllib import quote
-
+from types import StringType
 from NodePath import registry
 
-_marker = []  # dummy default object for cache return
-
-parserr=('Sorry, an XML parsing error occurred.  Check '
-         'your XML document for well-formedness and try '
-         'to upload it again after modification.<br><br>')
-
-def manage_addParsedXML(context, id, title='', file='',
-                        useNamespaces=1, contentType="text/xml",
-                        REQUEST=None):
-    "Add a Parsed XML instance with optional file content."
-    
-    if not file or not isinstance(file, StringType):
-        file ='<?xml version = "1.0"?><emptydocumentElement/>'
-    try:
-        ob = ParsedXML(id, file, useNamespaces, contentType)
-    except expat.error, e:
-        if REQUEST is not None:
-            err = "%s%s" % (parserr, '<font color="red">%s</font>'
-                            % getattr(e, 'args', ''))
-            return Globals.MessageDialog(
-                title= 'XML Parsing Error',
-                message = err,
-                action='manage_main')
-        raise
-    ob.title = str(title)
-    context._setObject(id, ob)
-    helpers.add_and_edit(context, id, REQUEST, 'manage_editForm')
-
-manage_addParsedXMLForm = DTMLFile('dtml/documentAdd', globals(),
-                                   __name__='manage_addParsedXMLForm')
-
-
-def createDOMDocument(XMLstring = None, namespaces = 1):
-    "Helper function to create a DOM document, without any proxy wrappers."
-    if XMLstring:
-        XMLstring=StringIO(XMLstring)
-        # more efficient to not use ExtraDOM here
-        return DOM.ExpatBuilder.parse(XMLstring, namespaces)
-    # we use DOM.theDOMImplementation, not ManageableDOMs, for efficiency
-    return DOM.theDOMImplementation.createDocument(
-        None, "mydocument", None)
+MARKER = []  # dummy default object for cache return
 
 contentTypes = ['text/html', 'application/html', 'text/xml']
     
@@ -84,25 +41,18 @@
      
     meta_type = 'Parsed XML'
 
-    manage_editForm = DTMLFile('dtml/persEdit', globals(),
-                               __name__='manage_editForm')
+    security = ClassSecurityInfo()
     
     manage_options = (DOMManageable.manage_options +
                       RoleManager.manage_options +
                       Cacheable.manage_options)
 
-    __ac_permissions__ = (('View management screens', ('manage_editForm',),
-                           ('Manager',)),
-                          ('View DOM hierarchy', ('manage_DOMTree',),
-                           ('Manager',)),
-                          ('Edit ParsedXML', ('manage_editForm',),
-                           ('Manager',)),
-                          ('View source', ('index_html',),
-                           ('Manager',)),
-                          ('Access contents information',
-                           ('objectIds', 'objectValues', 'objectItems',
-                            ''),
-                           ('Manager',)),)
+    security.setPermissionDefault('Edit ParsedXML', ['Manager'])
+
+    security.declareProtected('Edit ParsedXML',
+                              'manage_editForm')
+    manage_editForm = DTMLFile('dtml/persEdit', globals(),
+                               __name__='manage_editForm')
 
     icon = 'misc_/ParsedXML/pxml.gif'
 
@@ -125,7 +75,7 @@
             self._lenCache = len(str(self))
         self._lenCorrect = 1
 
-    initFromDOMDocument__roles__ = ()  # Private
+    security.declarePrivate('initFromDOMDocument')
     def initFromDOMDocument(self, DOMdoc):
         "Initialize a Parsed XML from a DOM Document"
         # inherit from ManageableDocument
@@ -153,19 +103,22 @@
         self._p_changed = 1
 
     # wrap DOMIO to provide cacheing
+    security.declareProtected('View management screens', 'index_html')
     def index_html(self, REQUEST = None, RESPONSE = None):
         "Returns publishable source according to content type"
         if RESPONSE:
             RESPONSE.setHeader('Content-type', self.contentType)
-        data = self.ZCacheable_get(default = _marker)
-        if data is not _marker:
+        data = self.ZCacheable_get(default = MARKER)
+        if data is not MARKER:
+            print "getting it from the cache"
             return data
         # inherit from DOMIO
         data = ParsedXML.inheritedAttribute('index_html')(self,
                                                           REQUEST, RESPONSE)
         self.ZCacheable_set(data)
         return data
-    
+
+    security.declareProtected('View management screens', 'get_size')
     def get_size(self):
         "Length of the XML string representing this node in characters."
         if not getattr(self, '_lenCorrect', 0):
@@ -175,17 +128,21 @@
 
     # methods that override ZDOM methods that are incorrect
     #
-    
+
+    security.declareProtected('Access contents information',
+                              'getElementsByTagName')
     def getElementsByTagName(self, tagName):
         return self.__getattr__("getElementsByTagName")(tagName)
 
+    security.declareProtected('Access contents information',
+                              'hasChildNodes')
     def hasChildNodes(self):
         return self.__getattr__("hasChildNodes")()
 
     # 
     # methods that override SimpleItem; sigh, multiple inheritance.
     #
-
+    security.declareProtected('Access contents information', 'objectValues')
     def objectValues(self, spec=None):
         """
         Returns a list of actual subobjects of the current object.
@@ -193,7 +150,8 @@
         match 'spec'.
         """
         return ManageableDocument.objectValues(self, spec)
-    
+
+    security.declareProtected('Access contents information', 'objectIds')
     def objectIds(self, spec=None):
         """
         Returns a list of subobject ids of the current object.
@@ -201,7 +159,8 @@
         matches 'spec'.
         """
         return ManageableDocument.objectIds(self, spec)
-
+    
+    security.declareProtected('Access contents information', 'objectItems')
     def objectItems(self, spec=None):
         """
         Returns a list of (id, subobject) tuples of the current object.
@@ -210,12 +169,14 @@
         """
         return ManageableDocument.objectItems(self, spec)
     
+    security.declareProtected('Access contents information', 'tpValues')   
     def tpValues(self):
         "Return a list of immediate subobjects.  Used by the dtml-tree tag."
         return ManageableDocument.tpValues(self)
 
     # override ManageableDocument's method; we can't persist new DOM node by
     # hanging off of parents
+    security.declareProtected('Edit ParsedXML', 'parseXML')
     def parseXML(self, file):
         "parse file as XML, replace DOM node with resulting tree, return self"
         namespaces = not self.noNamespaces
@@ -224,11 +185,15 @@
         self.__changed__(1)
         return self
 
+    security.declareProtected('Access contents information',
+                              'getDOM')
     def getDOM(self):
         """Get the Document node of the DOM tree.
         """
         return self
 
+    security.declareProtected('Access contents information',
+                              'getNodePath')
     def getNodePath(self, scheme_name, node):
         """Create the node path for a particular node in the tree.
         """
@@ -237,7 +202,9 @@
             return 'scheme_name'
         # otherwise ask for nodepath of node
         return node.getNodePath(scheme_name)
-        
+
+    security.declareProtected('Access contents information',
+                              'resolveNodePath')
     def resolveNodePath(self, path):
         """Resolve node path from top of the tree to node.
         """
@@ -263,5 +230,40 @@
         if result is None:
             raise KeyError, "Could not resolve node path."
         return result
+
+Globals.InitializeClass(ParsedXML)
+
+def createDOMDocument(XMLstring = None, namespaces = 1):
+    "Helper function to create a DOM document, without any proxy wrappers."
+    if XMLstring:
+        XMLstring=StringIO(XMLstring)
+        # more efficient to not use ExtraDOM here
+        return DOM.ExpatBuilder.parse(XMLstring, namespaces)
+    # we use DOM.theDOMImplementation, not ManageableDOMs, for efficiency
+    return DOM.theDOMImplementation.createDocument(
+        None, "mydocument", None)
+
+def manage_addParsedXML(context, id, title='', file='',
+                        useNamespaces=1, contentType="text/xml",
+                        REQUEST=None):
+    "Add a Parsed XML instance with optional file content."
     
-Globals.default__class_init__(ParsedXML) # activate perms
+    if not file or not isinstance(file, StringType):
+        file ='<?xml version = "1.0"?><emptydocumentElement/>'
+    try:
+        ob = ParsedXML(id, file, useNamespaces, contentType)
+    except expat.error, e:
+        if REQUEST is not None:
+            err = "%s%s" % (parserr, '<font color="red">%s</font>'
+                            % getattr(e, 'args', ''))
+            return Globals.MessageDialog(
+                title= 'XML Parsing Error',
+                message = err,
+                action='manage_main')
+        raise
+    ob.title = str(title)
+    context._setObject(id, ob)
+    helpers.add_and_edit(context, id, REQUEST, 'manage_editForm')
+
+manage_addParsedXMLForm = DTMLFile('dtml/documentAdd', globals(),
+                                   __name__='manage_addParsedXMLForm')