[MOBY-guts] biomoby commit

Yan Wong yanwong at pub.open-bio.org
Thu Jan 27 08:44:05 UTC 2005


yanwong
Thu Jan 27 03:44:05 EST 2005
Update of /home/repository/moby/moby-live/Python/bioMoby
In directory pub.open-bio.org:/tmp/cvs-serv14606/bioMoby

Modified Files:
	mobyDataTypes.py mobyMarshal.py 
Log Message:


moby-live/Python/bioMoby mobyDataTypes.py,1.2,1.3 mobyMarshal.py,1.2,1.3
===================================================================
RCS file: /home/repository/moby/moby-live/Python/bioMoby/mobyDataTypes.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Python/bioMoby/mobyDataTypes.py	2005/01/18 13:46:22	1.2
+++ /home/repository/moby/moby-live/Python/bioMoby/mobyDataTypes.py	2005/01/27 08:44:05	1.3
@@ -46,7 +46,11 @@
     def fromMoby(self, xml):
         """Get the attributes from a XML string
         """
-        xmlelt=parseString(xml).firstChild
+	xmlelt=xml
+	
+	if isinstance(xml, str):
+	    xmlelt=parseString(xml).firstChild
+	    
         self.articleName=xmlelt.getAttribute('moby:articleName')
 	l=xmlelt.getElementsByTagName("value")
 	if len(l)==0:
@@ -152,13 +156,15 @@
 	
 	return "".join(result)
 	
-    def fromMoby(self, xmlstring):
+    def fromMoby(self, xml):
 	"""Deserialization method
 	"""
+	elem=xml
 	
-	doc=parseString(xmlstring)
+	if isinstance(xml, str):
+	    doc=parseString(xmlstring)
 	
-	elem=doc.firstChild
+	    elem=doc.firstChild
 	
 	self.__tag__=elem.localName
 	
@@ -240,9 +246,12 @@
     def fromMoby(self, xml):
         """Deserialize the Xref Object
         """
-        MobyObject.fromMoby(self, xml)
-        
-        doc=parseString(xml)
+	if isinstance(xml, str):
+	    doc=parseString(xml)
+	
+	doc=xml
+	    
+	MobyObject.fromMoby(self, doc.firstChild)
         
         self.authURI=doc.firstChild.getAttribute("authURI")
         self.serviceName=doc.firstChild.getAttribute("serviceName")
@@ -256,8 +265,8 @@
     def __init__(self, value=0, *args, **kw):
 	MobyObject.__init__(self, content=value, tag="Integer", *args, **kw)
 
-    def fromMoby(self, xmlstring):
-	MobyObject.fromMoby(self, xmlstring)
+    def fromMoby(self, xml):
+	MobyObject.fromMoby(self, xml)
 	self.content = int(self.content)
 	
 class MobyFloat(MobyObject):
@@ -266,8 +275,8 @@
     def __init__(self, value=0, *args, **kw):
 	MobyObject.__init__(self, content=value, tag="Float", *args, **kw)
 	
-    def fromMoby(self, xmlstring):
-	MobyObject.fromMoby(self, xmlstring)
+    def fromMoby(self, xml):
+	MobyObject.fromMoby(self, xml)
 	self.content=float(self.content)
 	
 
@@ -340,18 +349,24 @@
 
         return "".join(result)
 
-    def fromMoby(self, xmlstring):
+    def fromMoby(self, xmlObject):
 	"""fill the properties from an XML
         """
-	from bioMoby import MobyUnmarshaller
+        from bioMoby import MobyUnmarshaller
 	
 	um=MobyUnmarshaller()
-	
+
         self.queryData={}
-        mdl=parseString(xmlstring).getElementsByTagName('mobyData')
+	
+	doc=xmlObject
+	
+	if isinstance(xmlObject, str):
+	    doc=parseString(xmlObject)
+	
+        mdl=doc.getElementsByTagName('mobyData')
 
         if not mdl:
-            mdl=parseString(xmlstring).getElementsByTagName('moby:mobyData')
+            mdl=doc.getElementsByTagName('moby:mobyData')
 
         #For each query            
         for elt in mdl:
@@ -376,19 +391,19 @@
                         if article.nodeType==article.ELEMENT_NODE and article.localName=="Simple":
 			    for child in article.childNodes:
 				if child.nodeType==child.ELEMENT_NODE:
-                                    articles.append(um.loads(child.toxml()))
+                                    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":
 		    for elt in datum.childNodes:
                         if elt.nodeType==elt.ELEMENT_NODE:
-		            o=um.loads(elt.toxml())
+		            o=um.loadn(elt)
 		            data.append(o)
 	        elif datum.nodeType==datum.ELEMENT_NODE and datum.localName=="Parameter":
 		    #It is a Parameter
 		    p=Parameter()
-		    p.fromMoby(datum.toxml())
+		    p.fromMoby(datum)
 		    data.append(p)
                     
             self.queryData[queryID]=data

===================================================================
RCS file: /home/repository/moby/moby-live/Python/bioMoby/mobyMarshal.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Python/bioMoby/mobyMarshal.py	2005/01/18 13:46:22	1.2
+++ /home/repository/moby/moby-live/Python/bioMoby/mobyMarshal.py	2005/01/27 08:44:05	1.3
@@ -188,28 +188,13 @@
 
         return "".join(t)
 
-
-    def loads(self, xml):
-	""" Deserializes an xml string and return a bioMoby-Python object
+    def loadn(self, xmlNode):
+	"""Deserializes an XML node and return a Python Object
 	"""
-        if xml=="":
-            return None    
-
-#	_typesmodule=["bioMoby.mobyDataTypes", "bioMoby.ontology"]
-	    
 	import bioMoby.mobyDataTypes
 	import bioMoby.ontology
-
-        doc=parseString(xml)
-        
-        mcl=doc.getElementsByTagNameNS('http://www.biomoby.org/moby','mobyContent')
-        
-        if len(mcl)!=0:
-            return self.m_MobyContent(doc)
-            
-        element=doc.firstChild
-        
-	nn=element.localName
+	
+	nn=xmlNode.localName
 	
         #Try to see if this object got a deserializer
         object2build=self._cleanName(nn)
@@ -219,12 +204,12 @@
 	if hasattr(bioMoby.mobyDataTypes, "Moby%s"%objectName):
 	    o=getattr(bioMoby.mobyDataTypes, "Moby%s"%objectName)()
 	    if hasattr(o, "fromMoby"):
-		o.fromMoby(xml)
+		o.fromMoby(xmlNode)
 	    return o
 	elif hasattr(bioMoby.ontology, "Moby%s"%objectName):
 	    o=getattr(bioMoby.ontology, "Moby%s"%objectName)()
 	    if hasattr(o, "fromMoby"):
-		o.fromMoby(xml)
+		o.fromMoby(xmlNode)
 	    return o
 	    
         methodName=str('m_'+nn)
@@ -233,13 +218,33 @@
             methodName="m_Object"
 		
 #	try:
-        return getattr(self,methodName)(element)
+        return getattr(self,methodName)(xmlNode)
 #        except:
 #	    #if not, Raise an invalid moby XML :-(
 #	    from bioMoby.mobyExceptions import EInvalidMobyXML    
 	    
 #            raise EInvalidMobyXML
 
+	
+    def loads(self, xmlString):
+	""" Deserializes an xml string and return a bioMoby-Python object
+	"""
+        if xmlString=="":
+            return None    
+
+#	_typesmodule=["bioMoby.mobyDataTypes", "bioMoby.ontology"]
+	    
+        doc=parseString(xmlString)
+        
+        mcl=doc.getElementsByTagNameNS('http://www.biomoby.org/moby','mobyContent')
+        
+        if len(mcl)!=0:
+            return self.m_MobyContent(doc)
+            
+        element=doc.firstChild
+        
+	self.loadn(element)
+
     def m_Integer(self, value):
 	"""Turn a Integer XML element into an integer
 	"""
@@ -338,7 +343,7 @@
 	
 	mc=MobyContent({})
 	
-	mc.fromMoby(value.toxml())
+	mc.fromMoby(value)
 	
 	del MobyContent
 	




More information about the MOBY-guts mailing list