py::qo::backend::BackendResponse Class Reference

List of all members.

Public Member Functions

def __init__
def __str__
def hasError
def getErrors
def get
def open
def open_element

Public Attributes

 parent
 doc
 content
 response

Static Public Attributes

list error_elements = [ "error", "runtime-error", "runtime-exception" ]


Member Function Documentation

def py::qo::backend::BackendResponse::__init__ (   self,
  parent,
  content 
)

00099                                               :
00100                 self.parent = parent
00101                 try :
00102                         data = email.message_from_string( content )
00103                         part = data.get_payload()
00104                         if not data.is_multipart() :
00105                                 self.doc = xml.dom.minidom.parseString( part )
00106                         else :
00107                                 # check xop+xml header validity
00108                                 data_type = data.get_param("type")
00109                                 start_info = data.get_param("start-info")
00110                                 start_cid = data.get_param('start')
00111                                 if data_type not in [ 'application/xop+xml' ] :
00112                                         raise Exception( "Unsupported '%s' multipart response" % data_type )
00113                                 if start_info not in [ "text/xml" ] :
00114                                         raise Exception( "Unsupported '%s' start-info in multipart response" % start_info )
00115 
00116                                 # find start_cid and indexes other parts
00117                                 self.content = {}
00118                                 for p in part :
00119                                         cid = p['content-id']
00120                                         if cid is None :
00121                                                 continue
00122                                         cid = cid.strip()
00123                                         if cid == start_cid :
00124                                                 self.doc = xml.dom.minidom.parseString( p.get_payload() )
00125                                         else :
00126                                                 self.content[ cid ] = p
00127                 except :
00128                         #print content
00129                         raise
00130                 self.response = self.doc.documentElement
00131 
        def __str__( self ) :

def py::qo::backend::BackendResponse::__str__ (   self  ) 

00132                             :
00133                 return self.doc.toxml('utf-8')
00134         
        def hasError( self ) :

def py::qo::backend::BackendResponse::hasError (   self  ) 

00135                              :
00136                 for e in self.error_elements :
00137                         if self.doc.getElementsByTagName( e ).length > 0 :
00138                                 return True
00139                 return False
00140         
        def getErrors( self ) :

def py::qo::backend::BackendResponse::getErrors (   self  ) 

00141                               :
00142                 ret = []
00143                 for e in [ "runtime-error", "runtime-exception" ] :
00144                         for error in self.doc.getElementsByTagName( e ) :
00145                                 ret.append( error.toxml() )
00146                 for error in self.doc.getElementsByTagName( "error" ) :
00147                         ret.append( { "type" : error.getAttribute("type"), "message" : error.firstChild.nodeValue } )
00148                 return ret
00149         
        def get( self, name ) :

def py::qo::backend::BackendResponse::get (   self,
  name 
)

00150                               :
00151                 ret = None
00152                 e = self.response.firstChild
00153                 while e is not None and ret is None :
00154                         if e.nodeName == name :
00155                                 ret = e
00156                         e = e.nextSibling
00157                 return ret
00158         
        def open( self, cid ) :

def py::qo::backend::BackendResponse::open (   self,
  cid 
)

Returns a read-only file descriptor to the attached file <cid>
00159                               :
00160                 """Returns a read-only file descriptor to the attached file <cid>"""
00161                 idx = "<%s>" % cid
00162                 if self.content.has_key( idx ) :
00163                         return cStringIO.StringIO( self.content[ idx ].get_payload() )
00164                 return None
00165         
        def open_element( self, e ) :

def py::qo::backend::BackendResponse::open_element (   self,
  e 
)

00166                                     :
00167                 e = e.firstChild
00168                 cid = None
00169                 while e is not None and cid is None :
00170                         if e.nodeType is xml.dom.Node.ELEMENT_NODE :
00171                                 err = True
00172                                 if e.namespaceURI.lower() in [ "http://www.w3.org/2004/08/xop/include" ] and e.localName == "Include" :
00173                                         href = e.getAttribute("href")
00174                                         if href.startswith("cid:") :
00175                                                 err = False
00176                                                 cid = href[4:]
00177                                 if err :
00178                                         raise Exception("Cannot open element: no xop+xml found")
00179                         e = e.nextSibling
00180 
00181                 ret = None
00182                 if cid is not None :
00183                         ret = self.open( cid )
00184                 return ret
00185 
class Session :


Member Data Documentation

list py::qo::backend::BackendResponse::error_elements = [ "error", "runtime-error", "runtime-exception" ] [static]

py::qo::backend::BackendResponse::parent

py::qo::backend::BackendResponse::doc

py::qo::backend::BackendResponse::content

py::qo::backend::BackendResponse::response


The documentation for this class was generated from the following file:
Generated on Tue Oct 9 20:40:30 2007 for Qomics by  doxygen 1.5.3