changeset 26:a19575be96e8

getDRI reshuffled, works on python 2.6. now.
author casties
date Mon, 30 Jul 2012 19:43:23 +0200
parents 64b703d1b8a4
children a0d273542509
files MetaData.py MetaDataFolder.py version.txt
diffstat 3 files changed, 16 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/MetaData.py	Fri Jul 27 12:53:51 2012 +0200
+++ b/MetaData.py	Mon Jul 30 19:43:23 2012 +0200
@@ -150,36 +150,6 @@
         return data
             
 
-    def getDRI(self,path=None,type="escidoc",dom=None):
-        """returns the DRI of an document, i.e. the content of the dri tag with the given type."""
-        
-        #logging.debug("getData(path=%s, dom=%s)"%(path,dom))
-        
-        
-        if path is None and dom is None:
-            return None
-        
-        
-        if dom is None:
-            # get from server
-            dom = self.getDomFromPathOrUrl(path)
-                
-        # ElementTree doesn't like absolute paths
-        # lets assume dom is rooted in the first element
-        
-        xpath = '.' + self.getXmlPath(omitRoot=True)+'/dri[@type="%s"]'%type
-        logging.debug("getSubDom looking for %s in %s"%(xpath, dom))
-       
-        
-        elem = dom.find(xpath)
-            
-      
-        if elem is None:
-            return None
-        
-        
-        return getText(elem)
-        
     def getData(self, path=None, dom=None, normalizeNames=True, all=False, recursive=0, allText=0):
         """Returns dict with attributes and child elements from corresponding tag.
         
@@ -355,7 +325,6 @@
             return tp(mdmap=fields, md=data)
 
 
-                
     def correctPath(self,path,remove=None,prefix=None,cut=0):
         """convinience method um einen pfad zu veraendern"""
         if remove is not None:
--- a/MetaDataFolder.py	Fri Jul 27 12:53:51 2012 +0200
+++ b/MetaDataFolder.py	Mon Jul 30 19:43:23 2012 +0200
@@ -130,7 +130,6 @@
     def getXmlPathObj(self, xmlpath):
         """returns object at xmlpath"""
         # make xmlpath relative for Zope
-        logging.debug("XMlPAth:"+xmlpath)
         if xmlpath[0] == '/':
             xmlpath = xmlpath[1:]
             
@@ -207,13 +206,25 @@
     def getContextData(self, path=None, dom=None, all=True):
         """returns contents of context tag as dict"""
         # information is two tags deep - recursive=1
-        
         return self.getXmlPathData('resource/meta/context', path=path, dom=dom,  all=all)
         
     
-    def getDRI(self,path=None,type="escidoc",dom=None):
+    def getDRI(self, path=None, dom=None, type="escidoc"):
         """returns the DRI of the document"""
-        return self.resource.meta.getDRI(path=path, dom=dom)
+        dris = self.getXmlPathData('resource/meta/dri', path=path, dom=dom, all=True)
+        logging.debug("getDRI: dris=%s"%repr(dris))
+        if dris is None:
+            return None
+        
+        for dri in dris:
+            logging.debug("getDRI: dri=%s"%dri)
+            att = dri.get('@attr', None)
+            if att is not None:
+                if (att.get('type', None) == type):
+                    return dri.get('@text', None)
+        
+        return None
+        #return self.resource.meta.getDRI(path=path, dom=dom, type=type)
     
     def getBibData(self, path=None, dom=None):
         """returns contents of bib tag as dict"""
--- a/version.txt	Fri Jul 27 12:53:51 2012 +0200
+++ b/version.txt	Mon Jul 30 19:43:23 2012 +0200
@@ -1,1 +1,1 @@
-2.0.1
\ No newline at end of file
+2.0.2
\ No newline at end of file