Commits

Felipe Prenholato  committed d1b585f

Try to load files from WSDL_URL + FILE_NAME if not found in url or local.

  • Participants
  • Parent commits cf3dcd7

Comments (0)

Files changed (3)

         schemas = types_section.findall('./{%s}schema' %xmlnamespace.NS_XSD)
         xtypes = {}
         for schema in schemas:
-            parser = xmlschema.XMLSchemaParser(schema)
+            parser = xmlschema.XMLSchemaParser(schema, wsdl_url=self.wsdl_url)
             xtypes.update(parser.get_list_of_defined_types())
         types =  xmlschema.XMLSchemaParser.convert_xmltypes_to_python(xtypes)
         xmltypes.XMLAny._types.update(types)

File osa/xmlparser.py

                                 element.attrib[a] = "{%s}%s" %(ns[1], vlist[1])
     return root
 
-def parse_qualified_from_url(url, attr = None):
+def parse_qualified_from_url(url, attr = None, wsdl_url=None):
     """
         The same as `parse_qualified`, but xml is given by its url.
 
     # parse it into xml
     if url[0] == "/" or url.find(":") == -1: #file without file: in front
         url = "file:"+url
-    page_handler = urllib2.urlopen(url)
+    try:
+        if url[:7] == "http://":
+            page_handler = urllib2.urlopen(url)
+        else:
+            page_handler = open(url, "r")
+    except IOError:
+        # and if file is not found remote or local, try to found it remote 
+        # again, but with wsdl url.
+        orig_url = url
+        url = wsdl_url.rsplit('/', 1)[0] + '/' + url
+        try:
+            page_handler = urllib2.urlopen(url)
+        except urllib2.HTTPError:
+            raise ValueError("Can not found '%s'. Locations tried was '%s' "
+                             "and '%s'." % (orig_url, url))
+
     root = parse_qualified(page_handler, attr=attr)
     page_handler.close()
     del page_handler

File osa/xmlschema.py

     """
         Parser to get types from an XML Schema.
     """
-    def __init__(self, root):
+    def __init__(self, root, wsdl_url):
         """
             Initialize parser.
 
             wsdl_url : xml schema, i.e. <schema ...> ... </schema>
                 The schema to parse
         """
+	self.wsdl_url = wsdl_url
         #check we have a schema
         if root.tag != "{%s}schema" %xmlnamespace.NS_XSD:
             raise ValueError("Supplied root node '%s'"\
                        xmlnamespace.NS_XSI):
                 continue
             #try getting the schema
-            parser = XMLSchemaParser(xmlparser.parse_qualified_from_url(loc))
+            parser = XMLSchemaParser(xmlparser.parse_qualified_from_url(loc, wsdl_url=wsdl_url), wsdl_url=wsdl_url)
             #check if want to change the schema namespace
             ns = schema.get("namespace", None)
             if ns is not None: