Commits

Anonymous committed cdd5fd5

Add DocumentPlugin.loaded() hook per ticket 347.

Comments (0)

Files changed (3)

 class DocumentContext(Context):
     """
     The XML document load context.
-    @ivar root: The loaded xsd document root.
-    @type root: L{sax.Element}
+    @ivar url: The URL.
+    @type url: str
+    @ivar document: Either the XML text or the B{parsed} document root.
+    @type document: (str|L{sax.Element})
     """
     pass
 
     The base class for suds I{document} plugins.
     """
     
+    def loaded(self, context): 
+        """
+        Suds has loaded a WSDL/XSD document.  Provides the plugin 
+        with an opportunity to inspect/modify the unparsed document. 
+        Called after each WSDL/XSD document is loaded. 
+        @param context: The document context. 
+        @type context: L{DocumentContext} 
+        """
+        pass 
+    
     def parsed(self, context):
         """
         Suds has parsed a WSDL/XSD document.  Provides the plugin
         with an opportunity to inspect/modify the parsed document.
         Called after each WSDL/XSD document is parsed.
         @param context: The document context.
-        @type context: L{LDocumentContext}
+        @type context: L{DocumentContext}
         """
         pass
 
         for plugin in self.domain.plugins:
             try:
                 method = getattr(plugin, self.name, None)
-                if method:
+                if method and callable(method):
                     method(ctx)
             except Exception, pe:
                 log.exception(pe)
         if d is None:
             d = self.download(url)
             cache.put(id, d)
-        self.plugins.document.parsed(root=d.root())
+        self.plugins.document.parsed(url=url, document=d.root())
         return d
     
     def download(self, url):
         fp = store.open(url)
         if fp is None:
             fp = self.options.transport.open(Request(url))
+        content = fp.read()
+        fp.close()
+        ctx = self.plugins.document.loaded(url=url, document=content)
+        content = ctx.document 
         sax = Parser()
-        return sax.parse(file=fp)
+        return sax.parse(string=content)
     
     def cache(self):
         """
 
     
 class MyDocumentPlugin(DocumentPlugin):
-
+    
     def loaded(self, context):
         print 'PLUGIN (document): loaded: ctx=%s' % context.__dict__
 
+    def parsed(self, context):
+        print 'PLUGIN (document): parsed: ctx=%s' % context.__dict__
+
         
 class MyMessagePlugin(MessagePlugin):
         
         print 'PLUGIN: (massage): unmarshalled: ctx=%s' % context.__dict__
         
         
-myplugins = (MyInitPlugin(), MyDocumentPlugin(), MyMessagePlugin(),)
+myplugins = (
+    MyInitPlugin(),
+    MyDocumentPlugin(),
+    MyMessagePlugin(),)
 
 
 #logging.getLogger('suds.client').setLevel(logging.DEBUG)