[MOBY-guts] biomoby commit

Yan Wong yanwong at pub.open-bio.org
Wed Feb 2 16:52:31 UTC 2005


yanwong
Wed Feb  2 11:52:31 EST 2005
Update of /home/repository/moby/moby-live/Python/bioMoby
In directory pub.open-bio.org:/tmp/cvs-serv20774

Modified Files:
	mobyDataTypes.py 
Log Message:


moby-live/Python/bioMoby mobyDataTypes.py,1.10,1.11
===================================================================
RCS file: /home/repository/moby/moby-live/Python/bioMoby/mobyDataTypes.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- /home/repository/moby/moby-live/Python/bioMoby/mobyDataTypes.py	2005/02/01 14:33:49	1.10
+++ /home/repository/moby/moby-live/Python/bioMoby/mobyDataTypes.py	2005/02/02 16:52:31	1.11
@@ -87,7 +87,7 @@
         
         self.content=content
         
-                
+    
     def toMoby(self):
         """Deserializes the content in XML api
         """
@@ -98,7 +98,7 @@
         for attribute in __ATTRIBUTES__:
             if hasattr(self, attribute) and getattr(self, attribute):
                 beginTag.append("%s:%s=\"%s\""%(self.__prefix__, attribute, getattr(self,attribute)))
-
+            
         #Retrieve only object's attributes that are public.
         filterFunc=lambda x: x[0] != "_" and not callable(getattr(self, x)) and x !="content" and x not in __ATTRIBUTES__
         
@@ -107,13 +107,13 @@
         mobyObjects=filter(filterFunc, dir(self))
         
         #If none, return the tag closed
-        if len(mobyObjects)==0 and (not hasattr(self, "__cross__") or len(self.__cross__)==0) and (not hasattr(self, "__PIB__") or len(self.__PIB__)==0) and (not hasattr(self, "content") or self.content==None or self.content==""):
+        if len(mobyObjects)==0 and (not hasattr(self, "__cross__") or len(self.__cross__)==0) and (not hasattr(self, "__PIB__") or len(self.__PIB__)==0) and (not hasattr(self, "content") or self.content is None or self.content==""):
             beginTag.append("/>")
             return " ".join(beginTag)
-
+        
         #Else, end begin tag and serialize the associated objects
         beginTag.append(">")
-
+        
         result=[" ".join(beginTag)]
         
         #Serialize Cross references
@@ -162,8 +162,8 @@
         elem=xml
         
         if isinstance(xml, str):
-            doc=parseString(xmlstring)
-        
+            doc=parseString(xml)
+            
             elem=doc.firstChild
         
         self.__tag__=elem.localName
@@ -195,10 +195,10 @@
                 else:
                     #Do the same for the other objects
                     associatedObjectName=child.getAttribute("moby:articleName")
-                
+                    
                     if not associatedObjectName:
                         associatedObjectName=child.getAttribute("articleName")
-                
+                        
                     if not associatedObjectName:
                         associatedObjectName="associated"
                     
@@ -252,7 +252,7 @@
         doc=xml
         
         uri=doc.namespaceURI
-    
+        
         MobyObject.fromMoby(self, doc)
         
         self.authURI=doc.getAttributeNS(uri, "authURI")
@@ -260,7 +260,6 @@
         self.evidenceCode=doc.getAttributeNS(uri, "evidenceCode")
         self.xrefType=doc.getAttributeNS(uri, "xrefType")
 
-        
 class MobyInteger(MobyObject):
     """Use this object to serialize/deserialize integers
     """
@@ -311,30 +310,30 @@
         """
         from mobyMarshal import MobyMarshaller
         m=MobyMarshaller()        
-
+        
         result=['<?xml version="1.0" encoding="UTF-8"?><moby:MOBY xmlns:moby="http://www.biomoby.org/moby"><moby:mobyContent']
-                
+        
         if self.authority !="":
             result.append(' moby:authority="'+self.authority+'"')
-                    
+        
         result.append('>')
-                    
+        
         if self.servicenotes !="":
             result.append('<moby:serviceNotes>'+self.servicenotes+'</moby:serviceNotes>')
-
+        
         for queryKey in self.queryData:
             result.append("<moby:mobyData moby:queryID='"+queryKey+"'>")
-
+            
             #For serialization, use the MobyMarshaller object
             
             for queryObject in self.queryData[queryKey]:
                 #if the Collection ('CollectionName',[MobyObjects])
                 if queryObject.__class__ is tuple:
                     result.append("<moby:Collection moby:articleName='"+queryObject[0]+"'>")
-
+                    
                     for aSimple in queryObject[1]:
                         result.append('<moby:Simple>'+m.dumps(aSimple)+'</moby:Simple>')
-                    
+                        
                     result.append("</moby:Collection>")
                 #If it is a parameter
                 elif queryObject.__class__ is Parameter:
@@ -342,13 +341,13 @@
                 #Or a simple object
                 else: 
                     result.append("<moby:Simple>"+m.dumps(queryObject)+"</moby:Simple>")
-
+                
             result.append("</moby:mobyData>")
-
+            
         result.append('</moby:mobyContent></moby:MOBY>')
-
+        
         del MobyMarshaller
-
+        
         return "".join(result)
 
     def fromMoby(self, xmlObject):
@@ -357,7 +356,7 @@
         from bioMoby import MobyUnmarshaller
         
         um=MobyUnmarshaller()
-
+        
         self.queryData={}
         
         doc=xmlObject
@@ -366,35 +365,35 @@
             doc=parseString(xmlObject)
         
         mdl=doc.getElementsByTagName('mobyData')
-
+        
         if not mdl:
             mdl=doc.getElementsByTagName('moby:mobyData')
-
+        
         #For each query            
         for elt in mdl:
             #Get the ID
             queryID=str(elt.getAttribute('queryID'))
-
+            
             if not queryID:
                 queryID=str(elt.getAttribute('moby:queryID'))
-
+            
             #Collect the data
             data=[]
-
+            
             #for each datum translate it in MobyObject, and put it in the list
             for datum in elt.childNodes:
                 #If it is a collection
                 if datum.nodeType==datum.ELEMENT_NODE and datum.localName=="Collection":
                     articleName=datum.getAttribute('moby:articleName')
-        
+                    
                     articles=[]
-        
+                    
                     for article in datum.childNodes:
                         if article.nodeType==article.ELEMENT_NODE and article.localName=="Simple":
                             for child in article.childNodes:
                                 if child.nodeType==child.ELEMENT_NODE:
                                     articles.append(um.loadn(child))
-
+                                    
                     data.append((articleName, articles))
                 #if it is a Simple object
                 elif datum.nodeType==datum.ELEMENT_NODE and datum.localName=="Simple":
@@ -442,7 +441,6 @@
             queries["%s-%s"%(queryName, queryID)]=aSimple
             
         return queries
-                
         
     def getObject(self, queryName, objectName):
         """Get an object from a query with its name
@@ -451,8 +449,7 @@
         
         for obj in filter(filterfunc, self.queryData[queryName]):
             return obj
-
-                
+            
     def getObjects(self, queryName):
         """Retrieve objects from a query
         """
@@ -470,7 +467,7 @@
             result[param.articleName]=param.value
                 
         return result
-
+        
     def getParameter(self, queryName, parameterName):
         """Retrieve a parameter from a query and his name
         """
@@ -484,4 +481,4 @@
     def __repr__(self):
         """put the xml of the Content
         """
-        return self.__str__()
+        return self.__str__()
\ No newline at end of file




More information about the MOBY-guts mailing list