[MOBY-guts] biomoby commit
Yan Wong
yanwong at pub.open-bio.org
Tue Feb 1 08:41:38 UTC 2005
yanwong
Tue Feb 1 03:52:15 EST 2005
Update of /home/repository/moby/moby-live/Python/bioMoby
In directory pub.open-bio.org:/tmp/cvs-serv12609
Modified Files:
mobyClient.py mobyDataTypes.py mobyExceptions.py
mobyMarshal.py mobyRegister.py mobyService.py
Log Message:
moby-live/Python/bioMoby mobyClient.py,1.2,1.3 mobyDataTypes.py,1.5,1.6 mobyExceptions.py,1.2,1.3 mobyMarshal.py,1.3,1.4 mobyRegister.py,1.2,1.3 mobyService.py,1.2,1.3
===================================================================
RCS file: /home/repository/moby/moby-live/Python/bioMoby/mobyClient.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Python/bioMoby/mobyClient.py 2005/01/18 13:46:22 1.2
+++ /home/repository/moby/moby-live/Python/bioMoby/mobyClient.py 2005/02/01 08:52:15 1.3
@@ -22,10 +22,10 @@
from SOAPpy import SOAPProxy
self.server=SOAPProxy(self.url, namespace=self.ns)
-
- if debug:
- self.server.config.debug=1
-
+
+ if debug:
+ self.server.config.debug=1
+
del SOAPProxy
@@ -68,28 +68,28 @@
def retrieveObjectDefinition(self, objectName):
"""Retrieves a list of object's definitions
"""
- dc={"urn:lsid:biomoby.org:objectrelation:isa":"ISA",
- "urn:lsid:biomoby.org:objectrelation:hasa":"HASA",
- "urn:lsid:biomoby.org:objectrelation:has":"HAS"
- }
+ dc={"urn:lsid:biomoby.org:objectrelation:isa":"ISA",
+ "urn:lsid:biomoby.org:objectrelation:hasa":"HASA",
+ "urn:lsid:biomoby.org:objectrelation:has":"HAS"
+ }
- definition={}
- definition["Relationship"]={}
+ definition={}
+ definition["Relationship"]={}
xmlinput="<retrieveObjectDefinition><objectType>"+objectName+"</objectType></retrieveObjectDefinition>"
doc=parseString(self.call_method("retrieveObjectDefinition", xmlinput))
-
- for child in doc.firstChild.childNodes:
- if child.nodeType==child.ELEMENT_NODE and child.nodeName=="Relationship":
- definition["Relationship"][dc[child.getAttribute("relationshipType")]]=[]
- for elem in child.childNodes:
- if elem.nodeType==elem.ELEMENT_NODE and elem.nodeName=="objectType" and elem.firstChild:
- definition["Relationship"][dc[child.getAttribute("relationshipType")]].append((elem.getAttribute("articleName"), elem.firstChild.nodeValue))
-
- elif child.nodeType==child.ELEMENT_NODE:
- if child.firstChild:
- definition[str(child.nodeName)]=child.firstChild.nodeValue
-
+
+ for child in doc.firstChild.childNodes:
+ if child.nodeType==child.ELEMENT_NODE and child.nodeName=="Relationship":
+ definition["Relationship"][dc[child.getAttribute("relationshipType")]]=[]
+ for elem in child.childNodes:
+ if elem.nodeType==elem.ELEMENT_NODE and elem.nodeName=="objectType" and elem.firstChild:
+ definition["Relationship"][dc[child.getAttribute("relationshipType")]].append((elem.getAttribute("articleName"), elem.firstChild.nodeValue))
+
+ elif child.nodeType==child.ELEMENT_NODE:
+ if child.firstChild:
+ definition[str(child.nodeName)]=child.firstChild.nodeValue
+
return definition
def retrieveObjectSchema(self, objectName):
@@ -260,6 +260,6 @@
raise ETypeMismatch
def __init__(self, url="http://mobycentral.cbr.nrc.ca/cgi-bin/MOBY05/mobycentral.pl", ns="http://mobycentral.cbr.nrc.ca/MOBY/Central"):
- """Constructor for class Client
- """
+ """Constructor for class Client
+ """
Central.__init__(self, url, ns)
===================================================================
RCS file: /home/repository/moby/moby-live/Python/bioMoby/mobyDataTypes.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- /home/repository/moby/moby-live/Python/bioMoby/mobyDataTypes.py 2005/01/27 13:46:57 1.5
+++ /home/repository/moby/moby-live/Python/bioMoby/mobyDataTypes.py 2005/02/01 08:52:15 1.6
@@ -26,7 +26,7 @@
def __init__(self, articleName="", value=""):
self.articleName=articleName
self.value=value
- self.__isSecondary__=True
+ self.__isSecondary__=True
def toMoby(self):
"""Returns the object as a XML
@@ -34,199 +34,199 @@
return "<moby:Parameter moby:articleName='"+self.articleName+"'><moby:value>"+str(self.value)+"</moby:value></moby:Parameter>"
def __str__(self):
- """Return the Parameter in its XML form
- """
+ """Return the Parameter in its XML form
+ """
return self.toMoby()
def __repr__(self):
- """Print the XML on the python command line.
- """
+ """Print the XML on the python command line.
+ """
return self.toMoby()
def fromMoby(self, xml):
"""Get the attributes from a XML string
"""
- xmlelt=xml
-
- if isinstance(xml, str):
- 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:
- l=xmlelt.getElementsByTagName("moby:value")
+ l=xmlelt.getElementsByTagName("value")
+ if len(l)==0:
+ l=xmlelt.getElementsByTagName("moby:value")
- self.value=l[0].firstChild.nodeValue
-
+ self.value=l[0].firstChild.nodeValue
+
class MobyGeneric(object):
"""A Generic object (to use with the Marshaller)
"""
def __init__(self, namespace="", id="", articleName="", *args, **kw):
- """Class constructor, basic attributes are namespace,
- identifier and the article's name
- """
- self.namespace=namespace
- self.id=id
- self.articleName=articleName
-
- for name, value in kw.items():
+ """Class constructor, basic attributes are namespace,
+ identifier and the article's name
+ """
+ self.namespace=namespace
+ self.id=id
+ self.articleName=articleName
+
+ for name, value in kw.items():
setattr(self, name, value)
-
+
class MobyObject(MobyGeneric):
"""Define a Moby XML Object
It has methods toMoby and fromMoby
"""
def __init__(self, prefix="moby", tag="Object", content="", *args, **kw):
- """Class constructor for a bioMoby Object
- """
- MobyGeneric.__init__(self, *args, **kw)
- self.__prefix__=prefix
- self.__tag__=tag
- self.__cross__=[]
- self.__PIB__=[]
-
- self.content=content
-
-
+ """Class constructor for a bioMoby Object
+ """
+ MobyGeneric.__init__(self, *args, **kw)
+ self.__prefix__=prefix
+ self.__tag__=tag
+ self.__cross__=[]
+ self.__PIB__=[]
+
+ self.content=content
+
+
def toMoby(self):
- """Deserializes the content in XML api
- """
-
- beginTag=["<%s:%s"%(self.__prefix__,self.__tag__)]
-
- #First see if the object has an identifier, a namepsace and a name
- 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__
-
- #Retrieve the associated objects
- #In MobyObject, associated objects are object's attributes
- 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 not self.content):
- beginTag.append("/>")
- return " ".join(beginTag)
+ """Deserializes the content in XML api
+ """
+
+ beginTag=["<%s:%s"%(self.__prefix__,self.__tag__)]
+
+ #First see if the object has an identifier, a namepsace and a name
+ for attribute in __ATTRIBUTES__:
+ if hasattr(self, attribute) and getattr(self, attribute):
+ beginTag.append("%s:%s=\"%s\""%(self.__prefix__, attribute, getattr(self,attribute)))
- #Else, end begin tag and serialize the associated objects
+ #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__
+
+ #Retrieve the associated objects
+ #In MobyObject, associated objects are object's attributes
+ 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 not self.content):
+ beginTag.append("/>")
+ return " ".join(beginTag)
+
+ #Else, end begin tag and serialize the associated objects
beginTag.append(">")
- result=[" ".join(beginTag)]
-
- #Serialize Cross references
- if hasattr(self, "__cross__") and self.__cross__:
- result.append("<CrossReference>")
-
- for aCross in self.__cross__:
- result.append(aCross.toMoby())
-
- result.append("</CrossReference>")
-
+ result=[" ".join(beginTag)]
+
+ #Serialize Cross references
+ if hasattr(self, "__cross__") and self.__cross__:
+ result.append("<CrossReference>")
+
+ for aCross in self.__cross__:
+ result.append(aCross.toMoby())
+
+ result.append("</CrossReference>")
+
#Serialize PIB
- if hasattr(self, "__PIB__") and self.__PIB__:
- result.append("<ProvisionInformation>")
-
- for aPIB in self.__PIB__:
- result.append(aPIB.toMoby())
-
- result.append("</ProvisionInformation>")
-
- #Serialize the other attibutes
- #If the attributes has a toMoby method, then use it
- #Else, use a MobyMarshaller object to serialize
- for mobyObject in mobyObjects:
- if hasattr(getattr(self,mobyObject), "toMoby"):
+ if hasattr(self, "__PIB__") and self.__PIB__:
+ result.append("<ProvisionInformation>")
+
+ for aPIB in self.__PIB__:
+ result.append(aPIB.toMoby())
+
+ result.append("</ProvisionInformation>")
+
+ #Serialize the other attibutes
+ #If the attributes has a toMoby method, then use it
+ #Else, use a MobyMarshaller object to serialize
+ for mobyObject in mobyObjects:
+ if hasattr(getattr(self,mobyObject), "toMoby"):
getattr(self, mobyObject).__articleName__=mobyObject
result.append(getattr(self, mobyObject).toMoby())
- else:
- from bioMoby import MobyMarshaller
- m=MobyMarshaller()
- result.append(m.dumps(getattr(self, mobyObject), articleName=mobyObject))
-
- #Put the raw content of the object
- #If you want to put your special object, then then you should write
- #a __str__ method
- if hasattr(self, "content") and self.content:
- result.append("%s"%(self.content))
-
- result.append("</%s:%s>"%(self.__prefix__, self.__tag__))
-
- return "".join(result)
-
+ else:
+ from bioMoby import MobyMarshaller
+ m=MobyMarshaller()
+ result.append(m.dumps(getattr(self, mobyObject), articleName=mobyObject))
+
+ #Put the raw content of the object
+ #If you want to put your special object, then then you should write
+ #a __str__ method
+ if hasattr(self, "content") and self.content:
+ result.append("%s"%(self.content))
+
+ result.append("</%s:%s>"%(self.__prefix__, self.__tag__))
+
+ return "".join(result)
+
def fromMoby(self, xml):
- """Deserialization method
- """
- elem=xml
-
- if isinstance(xml, str):
- doc=parseString(xmlstring)
-
- elem=doc.firstChild
-
- self.__tag__=elem.localName
-
- self.__prefix__="moby"
-
- self.content=[]
-
- if elem.nodeName.split(":")>1:
- self.__prefix__=elem.nodeName.split(":")[0]
-
- #Set the object's attributes
- for attribute in elem.attributes.values():
- setattr(self, attribute.localName, str(attribute.nodeValue))
-
- for child in elem.childNodes:
- if child.nodeType==child.ELEMENT_NODE:
- #deserializes the cross references
- if child.localName=="CrossReference":
- for aCross in child.childNodes:
- if aCross.localName=="Xref":
- aXref=MobyXref()
- aXref.fromMoby(aCross)
- self.__cross__.append(aXref)
- if aCross.localName=="Object":
- anObj=MobyObject()
- anObj.fromMoby(aCross)
- self.__cross__.append(anObj)
- 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"
-
- #Create an object
- o=MobyObject()
- o.fromMoby(child)
-
- #if there is already an object, then store it inside a list and
- #append the other objects in the list
- if hasattr(self, associatedObjectName):
- if type(getattr(self, associatedObjectName)) is list:
- getattr(self, associatedObjectName).append(o)
- else:
- setattr(self, associatedObjectName, [o])
- else:
+ """Deserialization method
+ """
+ elem=xml
+
+ if isinstance(xml, str):
+ doc=parseString(xmlstring)
+
+ elem=doc.firstChild
+
+ self.__tag__=elem.localName
+
+ self.__prefix__="moby"
+
+ self.content=[]
+
+ if elem.nodeName.split(":")>1:
+ self.__prefix__=elem.nodeName.split(":")[0]
+
+ #Set the object's attributes
+ for attribute in elem.attributes.values():
+ setattr(self, attribute.localName, str(attribute.nodeValue))
+
+ for child in elem.childNodes:
+ if child.nodeType==child.ELEMENT_NODE:
+ #deserializes the cross references
+ if child.localName=="CrossReference":
+ for aCross in child.childNodes:
+ if aCross.localName=="Xref":
+ aXref=MobyXref()
+ aXref.fromMoby(aCross)
+ self.__cross__.append(aXref)
+ if aCross.localName=="Object":
+ anObj=MobyObject()
+ anObj.fromMoby(aCross)
+ self.__cross__.append(anObj)
+ 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"
+
+ #Create an object
+ o=MobyObject()
+ o.fromMoby(child)
+
+ #if there is already an object, then store it inside a list and
+ #append the other objects in the list
+ if hasattr(self, associatedObjectName):
+ if type(getattr(self, associatedObjectName)) is list:
+ getattr(self, associatedObjectName).append(o)
+ else:
+ setattr(self, associatedObjectName, [o])
+ else:
setattr(self, associatedObjectName, o)
else:
- self.content.append(child.nodeValue)
-
- self.content="".join(self.content)
-
+ self.content.append(child.nodeValue)
+
+ self.content="".join(self.content)
+
def __str__(self):
- return self.toMoby()
-
+ return self.toMoby()
+
def __repr__(self):
- return self.toMoby()
-
+ return self.toMoby()
+
class MobyXref(MobyObject):
"""Describes an Xref
@@ -246,48 +246,48 @@
def fromMoby(self, xml):
"""Deserialize the Xref Object
"""
- if isinstance(xml, str):
- doc=parseString(xml).firstChild
-
- doc=xml
-
+ if isinstance(xml, str):
+ doc=parseString(xml).firstChild
+
+ doc=xml
+
uri=doc.namespaceURI
- MobyObject.fromMoby(self, doc)
+ MobyObject.fromMoby(self, doc)
self.authURI=doc.getAttributeNS(uri, "authURI")
self.serviceName=doc.getAttributeNS(uri, "serviceName")
self.evidenceCode=doc.getAttributeNS(uri, "evidenceCode")
self.xrefType=doc.getAttributeNS(uri, "xrefType")
-
+
class MobyInteger(MobyObject):
"""Use this object to serialize/deserialize integers
"""
def __init__(self, value=0, *args, **kw):
- MobyObject.__init__(self, content=value, tag="Integer", *args, **kw)
+ MobyObject.__init__(self, content=value, tag="Integer", *args, **kw)
def fromMoby(self, xml):
- MobyObject.fromMoby(self, xml)
- self.content = int(self.content)
-
+ MobyObject.fromMoby(self, xml)
+ self.content = int(self.content)
+
class MobyFloat(MobyObject):
"""Serialize/deserialize floating point numbers
"""
def __init__(self, value=0, *args, **kw):
- MobyObject.__init__(self, content=value, tag="Float", *args, **kw)
-
+ MobyObject.__init__(self, content=value, tag="Float", *args, **kw)
+
def fromMoby(self, xml):
- MobyObject.fromMoby(self, xml)
- self.content=float(self.content)
-
+ MobyObject.fromMoby(self, xml)
+ self.content=float(self.content)
+
class MobyString(MobyObject):
"""String Moby object
"""
def __init__(self, content="", *args, **kw):
- MobyObject.__init__(self, content=content, *args, **kw)
- self.__tag__="String"
+ MobyObject.__init__(self, content=content, *args, **kw)
+ self.__tag__="String"
class MobyContent:
"""The class describes a Moby Content (for queries or answers)
@@ -302,10 +302,10 @@
self.queryData=queryData
def __str__(self):
- """return the XML form of the Moby Content object
- """
- return self.toMoby()
-
+ """return the XML form of the Moby Content object
+ """
+ return self.toMoby()
+
def toMoby(self):
"""The XML reprentation of the content
"""
@@ -325,8 +325,8 @@
for queryKey in self.queryData:
result.append("<moby:mobyData moby:queryID='"+queryKey+"'>")
- #For serialization, use the MobyMarshaller object
-
+ #For serialization, use the MobyMarshaller object
+
for queryObject in self.queryData[queryKey]:
#if the Collection ('CollectionName',[MobyObjects])
if queryObject.__class__ is tuple:
@@ -352,19 +352,19 @@
return "".join(result)
def fromMoby(self, xmlObject):
- """fill the properties from an XML
+ """fill the properties from an XML
"""
from bioMoby import MobyUnmarshaller
-
- um=MobyUnmarshaller()
+
+ um=MobyUnmarshaller()
self.queryData={}
-
- doc=xmlObject
-
- if isinstance(xmlObject, str):
- doc=parseString(xmlObject)
-
+
+ doc=xmlObject
+
+ if isinstance(xmlObject, str):
+ doc=parseString(xmlObject)
+
mdl=doc.getElementsByTagName('mobyData')
if not mdl:
@@ -373,115 +373,115 @@
#For each query
for elt in mdl:
#Get the ID
- queryID=str(elt.getAttribute('queryID'))
+ queryID=str(elt.getAttribute('queryID'))
if not queryID:
queryID=str(elt.getAttribute('moby:queryID'))
- #Collect the data
+ #Collect the data
data=[]
- #for each datum translate it in MobyObject, and put it in the list
+ #for each datum translate it in MobyObject, and put it in the list
for datum in elt.childNodes:
- #If it is a collection
+ #If it is a collection
if datum.nodeType==datum.ELEMENT_NODE and datum.localName=="Collection":
- articleName=datum.getAttribute('moby:articleName')
+ 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:
+ 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
+ #if it is a Simple object
elif datum.nodeType==datum.ELEMENT_NODE and datum.localName=="Simple":
- for elt in datum.childNodes:
+ for elt in datum.childNodes:
if elt.nodeType==elt.ELEMENT_NODE:
- 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)
- data.append(p)
+ 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)
+ data.append(p)
self.queryData[queryID]=data
-
+
def __getitem__(self, key):
- """Get a query from his name
+ """Get a query from his name
"""
return self.queryData[key]
def __setitem__(self, key, item):
- """Store a query in the dictionary
- """
+ """Store a query in the dictionary
+ """
self.queryData[key]=item
def __len__(self):
- """Return the number of elements inside the dictionary
- """
+ """Return the number of elements inside the dictionary
+ """
return len(self.queryData)
def keys(self):
- """Return all queries's name
- """
+ """Return all queries's name
+ """
return self.queryData.keys()
-
+
def collectionToQueries(self, aCollection):
- """Turn a collection of object into a set of queries
- """
- queries={}
- queryName=aCollection[0]
-
- queryID=1
-
- for aSimple in aCollection[1]:
- queries["%s-%s"%(queryName, queryID)]=aSimple
-
- return queries
-
-
+ """Turn a collection of object into a set of queries
+ """
+ queries={}
+ queryName=aCollection[0]
+
+ queryID=1
+
+ for aSimple in aCollection[1]:
+ queries["%s-%s"%(queryName, queryID)]=aSimple
+
+ return queries
+
+
def getObject(self, queryName, objectName):
- """Get an object from a query with its name
- """
- filterfunc=lambda obj: not hasattr(obj,'__isSecondary__') and hasattr(obj, "articleName") and obj.articleName==objectName
-
- for obj in filter(filterfunc, self.queryData[queryName]):
+ """Get an object from a query with its name
+ """
+ filterfunc=lambda obj: not hasattr(obj,'__isSecondary__') and hasattr(obj, "articleName") and obj.articleName==objectName
+
+ for obj in filter(filterfunc, self.queryData[queryName]):
return obj
-
+
def getObjects(self, queryName):
- """Retrieve objects from a query
- """
- filterfunc=lambda obj: not hasattr(obj, "__isSecondary__")
-
- return filter(filterfunc, self.queryData[queryName])
-
+ """Retrieve objects from a query
+ """
+ filterfunc=lambda obj: not hasattr(obj, "__isSecondary__")
+
+ return filter(filterfunc, self.queryData[queryName])
+
def getParameters(self, queryName):
- """Retrieve parameters from a query
- """
- filterfunc=lambda param: hasattr(param, "__isSecondary__")
-
- result={}
- for param in filter(filterfunc, self.queryData[queryName]):
- result[param.articleName]=param.value
-
- return result
+ """Retrieve parameters from a query
+ """
+ filterfunc=lambda param: hasattr(param, "__isSecondary__")
+
+ result={}
+ for param in filter(filterfunc, self.queryData[queryName]):
+ result[param.articleName]=param.value
+
+ return result
def getParameter(self, queryName, parameterName):
- """Retrieve a parameter from a query and his name
- """
- filterfunc=lambda param: hasattr(param, "__isSecondary__") and hasattr(param, "articleName") and param.articleName==parameterName
-
- l=filter(filterfunc, self.queryData[queryName])
-
- if l:
- return l[0]
-
+ """Retrieve a parameter from a query and his name
+ """
+ filterfunc=lambda param: hasattr(param, "__isSecondary__") and hasattr(param, "articleName") and param.articleName==parameterName
+
+ l=filter(filterfunc, self.queryData[queryName])
+
+ if l:
+ return l[0]
+
def __repr__(self):
- """put the xml of the Content
- """
- return self.__str__()
+ """put the xml of the Content
+ """
+ return self.__str__()
===================================================================
RCS file: /home/repository/moby/moby-live/Python/bioMoby/mobyExceptions.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Python/bioMoby/mobyExceptions.py 2005/01/18 13:46:22 1.2
+++ /home/repository/moby/moby-live/Python/bioMoby/mobyExceptions.py 2005/02/01 08:52:15 1.3
@@ -41,4 +41,4 @@
"""A XML input is not a Moby XML Object.
"""
def __str__(self):
- return "The bioMoby XML object couldn't be parsed"
\ No newline at end of file
+ return "The bioMoby XML object couldn't be parsed"
\ No newline at end of file
===================================================================
RCS file: /home/repository/moby/moby-live/Python/bioMoby/mobyMarshal.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Python/bioMoby/mobyMarshal.py 2005/01/27 08:44:05 1.3
+++ /home/repository/moby/moby-live/Python/bioMoby/mobyMarshal.py 2005/02/01 08:52:15 1.4
@@ -10,7 +10,7 @@
01/17/2005: MobyMarshaller and MobyUnmarshaller can operate on all objects
serialisation and deserialisation are done only on public (no _ prefix) non callable attributes
- The serialisation and deserialisation is recursive.
+ The serialisation and deserialisation is recursive.
"""
from xml.dom.minidom import parseString
@@ -20,8 +20,8 @@
"""
def _marshal(self, value, articleName=""):
- """this method do the serialization of the object
- """
+ """this method do the serialization of the object
+ """
if type(value).__name__=='NoneType':
return ""
@@ -29,9 +29,9 @@
method="m_"+tvalue
- if hasattr(value, "toMoby"):
- return value.toMoby()
-
+ if hasattr(value, "toMoby"):
+ return value.toMoby()
+
if hasattr(self, method):
return getattr(self,method)(value,articleName=articleName)
@@ -46,8 +46,8 @@
return str(m)
def m_unicode(self, value, articleName=""):
- """Turn a unicode string into a mobyString object
- """
+ """Turn a unicode string into a mobyString object
+ """
return self.m_str(str(value), articleName)
def m_string(self, value, articleName=""):
@@ -59,18 +59,18 @@
"""Turn an integer into a Moby XML object
"""
from bioMoby.mobyDataTypes import MobyInteger
- m=MobyInteger(value, namespace=namespace, id=id, articleName=articleName)
-
- return m.toMoby()
-
+ m=MobyInteger(value, namespace=namespace, id=id, articleName=articleName)
+
+ return m.toMoby()
+
def m_float(self, value, namespace="", id="", articleName=""):
"""Turn a float into a Moby XML object
"""
from bioMoby.mobyDataTypes import MobyFloat
- m=MobyFloat(value, namespace=namespace, id=id, articleName=articleName)
-
- return m.toMoby()
-
+ m=MobyFloat(value, namespace=namespace, id=id, articleName=articleName)
+
+ return m.toMoby()
+
def m_list(self, value, articleName=""):
"""Turn a list into a Moby XML object
"""
@@ -113,50 +113,50 @@
def _compoundObject(self, value, articleName=""):
"""transforms an object and all properties into a XML
"""
-
- result=[]
-
- properties=[]
-
- filterfunc=lambda x: x[0] != "_" and not callable(getattr(value, x)) and x !="content" and x not in ["id", "namespace", "articleName", "content"]
- attribfunc= lambda x: hasattr(value, x)
-
- tagName="moby:%s"%type(value).__name__
-
- if hasattr(value, "__tag__") and value.__tag__:
- tagName="moby:%s"%value.__tag__
-
- header=["<%s"%tagName]
-
- for attribute in filter(attribfunc, ["id", "namespace", "articleName"]):
- header.append("moby:%s=\"%s\""%(attribute,getattr(value,attribute)))
-
- for prop in filter(filterfunc, dir(value)):
- properties.append(self._marshal(getattr(value, prop), articleName=prop))
-
- if not properties and not (hasattr(value, "content") and value.content):
- header.append("/>")
- else:
- header.append(">")
-
- result.append(" ".join(header))
-
- if properties:
- result.append("".join(properties))
-
- if hasattr(value, "content") and value.content:
- result.append("<![CDATA[%s]]>"%value.content)
-
- if properties:
- result.append("</%s>"%tagName)
-
-
- return r"".join(result)
-
-
+
+ result=[]
+
+ properties=[]
+
+ filterfunc=lambda x: x[0] != "_" and not callable(getattr(value, x)) and x !="content" and x not in ["id", "namespace", "articleName", "content"]
+ attribfunc= lambda x: hasattr(value, x)
+
+ tagName="moby:%s"%type(value).__name__
+
+ if hasattr(value, "__tag__") and value.__tag__:
+ tagName="moby:%s"%value.__tag__
+
+ header=["<%s"%tagName]
+
+ for attribute in filter(attribfunc, ["id", "namespace", "articleName"]):
+ header.append("moby:%s=\"%s\""%(attribute,getattr(value,attribute)))
+
+ for prop in filter(filterfunc, dir(value)):
+ properties.append(self._marshal(getattr(value, prop), articleName=prop))
+
+ if not properties and not (hasattr(value, "content") and value.content):
+ header.append("/>")
+ else:
+ header.append(">")
+
+ result.append(" ".join(header))
+
+ if properties:
+ result.append("".join(properties))
+
+ if hasattr(value, "content") and value.content:
+ result.append("<![CDATA[%s]]>"%value.content)
+
+ if properties:
+ result.append("</%s>"%tagName)
+
+
+ return r"".join(result)
+
+
def dumps(self, value, articleName=""):
- """Serialize the object into a Moby XML object
- """
+ """Serialize the object into a Moby XML object
+ """
return self._marshal(value, articleName)
@@ -169,8 +169,8 @@
"""
import re
- aName=str(aName)
-
+ aName=str(aName)
+
if aName=="":
return ""
@@ -189,51 +189,51 @@
return "".join(t)
def loadn(self, xmlNode):
- """Deserializes an XML node and return a Python Object
- """
- import bioMoby.mobyDataTypes
- import bioMoby.ontology
-
- nn=xmlNode.localName
-
+ """Deserializes an XML node and return a Python Object
+ """
+ import bioMoby.mobyDataTypes
+ import bioMoby.ontology
+
+ nn=xmlNode.localName
+
#Try to see if this object got a deserializer
object2build=self._cleanName(nn)
objectName=str.upper(object2build[0])+object2build[1:]
-
- if hasattr(bioMoby.mobyDataTypes, "Moby%s"%objectName):
- o=getattr(bioMoby.mobyDataTypes, "Moby%s"%objectName)()
- if hasattr(o, "fromMoby"):
- 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(xmlNode)
- return o
-
+
+ if hasattr(bioMoby.mobyDataTypes, "Moby%s"%objectName):
+ o=getattr(bioMoby.mobyDataTypes, "Moby%s"%objectName)()
+ if hasattr(o, "fromMoby"):
+ 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(xmlNode)
+ return o
+
methodName=str('m_'+nn)
-
- if not hasattr(self, methodName):
+
+ if not hasattr(self, methodName):
methodName="m_Object"
-
-# try:
+
+# try:
return getattr(self,methodName)(xmlNode)
# except:
-# #if not, Raise an invalid moby XML :-(
-# from bioMoby.mobyExceptions import EInvalidMobyXML
-
+# #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
- """
+ """ Deserializes an xml string and return a bioMoby-Python object
+ """
if xmlString=="":
return None
-# _typesmodule=["bioMoby.mobyDataTypes", "bioMoby.ontology"]
-
+# _typesmodule=["bioMoby.mobyDataTypes", "bioMoby.ontology"]
+
doc=parseString(xmlString)
mcl=doc.getElementsByTagNameNS('http://www.biomoby.org/moby','mobyContent')
@@ -243,109 +243,109 @@
element=doc.firstChild
- self.loadn(element)
+ self.loadn(element)
def m_Integer(self, value):
- """Turn a Integer XML element into an integer
- """
- value.normalize()
-
- if value.firstChild:
- return int(value.firstChild.nodeValue.replace("\n","").replace("\t","").replace(" ",""))
- else:
- return 0
-
+ """Turn a Integer XML element into an integer
+ """
+ value.normalize()
+
+ if value.firstChild:
+ return int(value.firstChild.nodeValue.replace("\n","").replace("\t","").replace(" ",""))
+ else:
+ return 0
+
def m_Float(self, value):
- """Turn a Float XML element into a float number
- """
- value.normalize()
- if value.firstChild:
- return float(value.firstChild.nodeValue.replace("\n","").replace("\t","").replace(" ",""))
+ """Turn a Float XML element into a float number
+ """
+ value.normalize()
+ if value.firstChild:
+ return float(value.firstChild.nodeValue.replace("\n","").replace("\t","").replace(" ",""))
return 0.0
-
+
def m_String(self, value):
- """Turn a Moby XML String element into a String object
- """
-
- cnt=[]
- value.normalize()
-
- for aChild in value.childNodes:
- if aChild.nodeType==aChild.TEXT_NODE or aChild.nodeType==aChild.CDATA_SECTION_NODE:
- cnt.append(aChild.wholeText)
-
- return r"".join(cnt)
-
+ """Turn a Moby XML String element into a String object
+ """
+
+ cnt=[]
+ value.normalize()
+
+ for aChild in value.childNodes:
+ if aChild.nodeType==aChild.TEXT_NODE or aChild.nodeType==aChild.CDATA_SECTION_NODE:
+ cnt.append(aChild.wholeText)
+
+ return r"".join(cnt)
+
def m_Object(self, value):
- """Turn any XML into a generic object
- """
- filterFunc= lambda x: x.nodeType==x.ELEMENT_NODE
-
- typeName="GMoby%s"%str(value.localName)
-
- from bioMoby.mobyDataTypes import MobyGeneric
-
- NewType=type(typeName, (MobyGeneric,), {})
-
- anObject=NewType()
-
- anObject.__prefix__="moby"
- anObject.__tag__=str(value.localName)
-
- for tupleAttribute in value.attributes.itemsNS():
- #First item, second field:
- setattr(anObject, str(tupleAttribute[0][1]), str(tupleAttribute[1]))
-
- i=0
- for elem in filter(filterFunc, value.childNodes):
- methodName="m_%s"%str(elem.localName)
-
- articleName=elem.getAttribute("moby:articleName")
-
- if not articleName:
- articleName=elem.getAttribute("articleName")
-
- if not articleName:
- articleName="attribute_%s"%i
-
- if hasattr(self, methodName):
- prop=getattr(self, methodName)(elem)
- else:
- prop=self.m_Object(elem)
-
- if hasattr(anObject, articleName):
- t=prop
- if not type(getattr(anObject, articleName)) is list:
- t=getattr(anObject, articleName)
- setattr(anObject, articleName, [])
- getattr(anObject, articleName).append(t)
- else:
- setattr(anObject, articleName, prop)
- i+=1
-
- content=[]
-
- isContentNode= lambda x: x.nodeType==x.TEXT_NODE or x.nodeType==x.CDATA_SECTION_NODE
-
- for elem in filter(isContentNode, value.childNodes):
- content.append(str(elem.nodeValue))
-
- if content:
- anObject.content(r"".join(content))
-
- return anObject
+ """Turn any XML into a generic object
+ """
+ filterFunc= lambda x: x.nodeType==x.ELEMENT_NODE
+
+ typeName="GMoby%s"%str(value.localName)
+
+ from bioMoby.mobyDataTypes import MobyGeneric
+
+ NewType=type(typeName, (MobyGeneric,), {})
+
+ anObject=NewType()
+
+ anObject.__prefix__="moby"
+ anObject.__tag__=str(value.localName)
+
+ for tupleAttribute in value.attributes.itemsNS():
+ #First item, second field:
+ setattr(anObject, str(tupleAttribute[0][1]), str(tupleAttribute[1]))
+
+ i=0
+ for elem in filter(filterFunc, value.childNodes):
+ methodName="m_%s"%str(elem.localName)
+
+ articleName=elem.getAttribute("moby:articleName")
+
+ if not articleName:
+ articleName=elem.getAttribute("articleName")
+
+ if not articleName:
+ articleName="attribute_%s"%i
+
+ if hasattr(self, methodName):
+ prop=getattr(self, methodName)(elem)
+ else:
+ prop=self.m_Object(elem)
+
+ if hasattr(anObject, articleName):
+ t=prop
+ if not type(getattr(anObject, articleName)) is list:
+ t=getattr(anObject, articleName)
+ setattr(anObject, articleName, [])
+ getattr(anObject, articleName).append(t)
+ else:
+ setattr(anObject, articleName, prop)
+ i+=1
+
+ content=[]
+
+ isContentNode= lambda x: x.nodeType==x.TEXT_NODE or x.nodeType==x.CDATA_SECTION_NODE
+
+ for elem in filter(isContentNode, value.childNodes):
+ content.append(str(elem.nodeValue))
+
+ if content:
+ anObject.content(r"".join(content))
+
+ return anObject
def m_MobyContent(self, value):
- """Turn an MobyContentXML into a MobyContent object
- """
- from bioMoby.mobyDataTypes import MobyContent
-
- mc=MobyContent({})
-
- mc.fromMoby(value)
-
- del MobyContent
-
- return mc
-
+ """Turn an MobyContentXML into a MobyContent object
+ """
+ from bioMoby.mobyDataTypes import MobyContent
+
+ mc=MobyContent({})
+
+ mc.fromMoby(value)
+
+ del MobyContent
+
+ return mc
+
===================================================================
RCS file: /home/repository/moby/moby-live/Python/bioMoby/mobyRegister.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Python/bioMoby/mobyRegister.py 2005/01/18 13:46:22 1.2
+++ /home/repository/moby/moby-live/Python/bioMoby/mobyRegister.py 2005/02/01 08:52:15 1.3
@@ -19,9 +19,9 @@
self.success=0
self.id=""
self.message=""
- self.RDF=""
+ self.RDF=""
- #Parse the document, retrieve the success, id, message and RDF fields
+ #Parse the document, retrieve the success, id, message and RDF fields
doc=parseString(xmlInput)
if len(doc.getElementsByTagName("success")[0].childNodes)>0:
@@ -32,9 +32,9 @@
self.message=doc.getElementsByTagName("message")[0].childNodes[0].nodeValue
try:
if len(doc.getElementsByTagName("RDF"))>0:
- self.RDF=doc.getElementsByTagName("RDF")[0].firstChild.toprettyxml()
- except:
- pass
+ self.RDF=doc.getElementsByTagName("RDF")[0].firstChild.toprettyxml()
+ except:
+ pass
def __str__(self):
"""Return the moby xml of the instance
@@ -63,7 +63,7 @@
self.authURI=authURI
self.description=description
#it uses a central object for registration
- from mobyClient import Central
+ from mobyClient import Central
self.central=Central()
del Central
@@ -78,8 +78,8 @@
self.serviceType=serviceType
GeneralInformations.__init__(self, contact=contactEmail, authURI=authURI, description=description)
self.relationship=relationship
- self.serviceType=serviceType
-
+ self.serviceType=serviceType
+
def __str__(self):
"""Return the instance as a Moby XML
"""
===================================================================
RCS file: /home/repository/moby/moby-live/Python/bioMoby/mobyService.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Python/bioMoby/mobyService.py 2005/01/18 13:46:22 1.2
+++ /home/repository/moby/moby-live/Python/bioMoby/mobyService.py 2005/02/01 08:52:15 1.3
@@ -6,7 +6,7 @@
Author: Wong Yan
01/17/2004: Service can be executed as a Thread, thus several queries can be made
- in the same time.
+ in the same time.
"""
from mobyRegister import GeneralInformations
@@ -244,7 +244,7 @@
self.type=""
self.category=""
self.url=""
- self.signatureURL=""
+ self.signatureURL=""
self.authoritative=0
self.inputObjects=[]
self.outputObjects=[]
@@ -264,8 +264,8 @@
self.type=arg[key]
elif key=='url':
self.url=arg['url']
- elif key=='signatureURL':
- self.signatureURL=arg['signatureURL']
+ elif key=='signatureURL':
+ self.signatureURL=arg['signatureURL']
elif key=='authoritative':
self.authoritative=arg[key]
elif key=='contactEmail':
@@ -311,7 +311,7 @@
from SOAPpy import SOAPProxy
- webservice=SOAPProxy(self.url,namespace=self.namespace)
+ webservice=SOAPProxy(self.url,namespace=self.namespace)
if method=="":
if len(self.methods)==0:
@@ -325,9 +325,9 @@
webservice.soapaction=self.namespace+"#"+method
- if debug:
- webservice.config.debug=1
-
+ if debug:
+ webservice.config.debug=1
+
toQuery=str(query)
del SOAPProxy
@@ -339,13 +339,13 @@
#try to return a MobyContent Object instead
from bioMoby.mobyDataTypes import MobyContent
- mc=MobyContent()
- mc.fromMoby(result)
+ mc=MobyContent()
+ mc.fromMoby(result)
del MobyContent
return mc
-
+
def __str__(self):
"""Returns The moby xml form of the web service
"""
@@ -354,7 +354,7 @@
result.append("<serviceType>"+self.type+"</serviceType>")
result.append("<authURI>"+self.authURI+"</authURI>")
result.append("<URL>"+self.url+"</URL>")
- result.append("<signatureURL>"+self.signatureURL+"</signatureURL>")
+ result.append("<signatureURL>"+self.signatureURL+"</signatureURL>")
result.append("<contactEmail>"+self.contact+"</contactEmail>")
result.append("<authoritativeService>"+`self.authoritative`+"</authoritativeService>")
result.append("<Description><![CDATA["+self.description+"]]></Description>")
@@ -367,10 +367,10 @@
elif inputObject.__class__ is dict:
result.append('<Collection articleName="'+inputObject.keys()[0]+'">')
- for aSimple in inputObject[inputObject.keys()[0]]:
+ for aSimple in inputObject[inputObject.keys()[0]]:
result.append(str(aSimple))
- result.append("</Collection>")
+ result.append("</Collection>")
else:
from mobyExceptions import EInvalidArgument
raise EInvalidArgument, "Bad input object"
@@ -385,10 +385,10 @@
elif output.__class__ is dict:
result.append('<Collection articleName="'+output.keys()[0]+'">')
- for aSimple in output[output.keys()[0]]:
+ for aSimple in output[output.keys()[0]]:
result.append(str(aSimple))
-
- result.append("</Collection>")
+
+ result.append("</Collection>")
else:
from mobyExceptions import EInvalidArgument
raise EInvalidArgument, "Bad output object"
@@ -410,10 +410,10 @@
"""Register the service on the Moby server
has been added here a code to verify that signatureURL is not empty :)
"""
- if self.signatureURL=="":
- from mobyExceptions import EInvalidArgument
- raise EInvalidArgument, "field signatureURL cannot be empty"
-
+ if self.signatureURL=="":
+ from mobyExceptions import EInvalidArgument
+ raise EInvalidArgument, "field signatureURL cannot be empty"
+
xmlinput="<registerService>"+str(self)+"</registerService>"
from mobyRegister import RegistrationObject
@@ -431,32 +431,32 @@
return result
def _executeThread(self, mobyContent):
- """Execute the service, store the result in a field
- """
-
- self.results=self.execute(mobyContent, returnXml=(mobyContent.__class__ is str))
-
-
+ """Execute the service, store the result in a field
+ """
+
+ self.results=self.execute(mobyContent, returnXml=(mobyContent.__class__ is str))
+
+
def start(self, mobycontent, timeout=-1):
- """Start the service as it was a thread
- """
- from threading import Thread
-
-
- if timeout != -1:
- self._execThread=Thread(target=self._executeThread, args=(mobycontent,))
- else:
- self._execThread=Thread(target=self._executeThread, args=(mobycontent,), timeout=timeout)
+ """Start the service as it was a thread
+ """
+ from threading import Thread
+
+
+ if timeout != -1:
+ self._execThread=Thread(target=self._executeThread, args=(mobycontent,))
+ else:
+ self._execThread=Thread(target=self._executeThread, args=(mobycontent,), timeout=timeout)
- self._execThread.start()
-
+ self._execThread.start()
+
def join(self):
- """Same as Thread.join
- """
- self._execThread.join()
-
-
-
+ """Same as Thread.join
+ """
+ self._execThread.join()
+
+
+
class ServiceList:
"""Class representing a service's list
"""
@@ -502,17 +502,17 @@
for childNode in node.childNodes:
if childNode.nodeName=="datatype":
- if childNode.firstChild:
+ if childNode.firstChild:
secondary.type=childNode.firstChild.nodeValue
elif childNode.nodeName=="default":
if childNode.firstChild:
- secondary.default=childNode.firstChild.nodeValue
+ secondary.default=childNode.firstChild.nodeValue
elif childNode.nodeName=="min":
if childNode.firstChild:
- secondary.min=childNode.firstChild.nodeValue
+ secondary.min=childNode.firstChild.nodeValue
elif childNode.nodeName=="max":
if childNode.firstChild:
- secondary.max=childNode.firstChild.nodeValue
+ secondary.max=childNode.firstChild.nodeValue
elif childNode.nodeName=="enum":
if childNode.firstChild:
secondary.enums.append(childNode.firstChild.nodeValue)
@@ -547,7 +547,7 @@
service.contact=child.firstChild.nodeValue
elif child.nodeName=="URL" and child.firstChild:
service.url=child.firstChild.nodeValue
- elif child.nodeName=="signatureURL" and child.firstChild:
+ elif child.nodeName=="signatureURL" and child.firstChild:
service.signatureURL=child.firstChild.nodeValue
elif child.nodeName=="Input":
for article in child.childNodes:
More information about the MOBY-guts
mailing list