summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjortel <devnull@localhost>2010-09-01 18:40:40 +0000
committerjortel <devnull@localhost>2010-09-01 18:40:40 +0000
commitcd67cdbe0033c5da748f3c02ff0bf5915545efb0 (patch)
tree98b94776c881260be8bf53ba177cd95c92937c44
parent92ecdb75a8e9882a3b8917888a90ebab1082e808 (diff)
downloadsuds-cd67cdbe0033c5da748f3c02ff0bf5915545efb0.tar.gz
Add DocumentPlugin.loaded() hook per ticket 347.
-rw-r--r--suds/plugin.py20
-rw-r--r--suds/reader.py8
-rw-r--r--tests/axis1.py10
3 files changed, 30 insertions, 8 deletions
diff --git a/suds/plugin.py b/suds/plugin.py
index 219a7da..f05e22f 100644
--- a/suds/plugin.py
+++ b/suds/plugin.py
@@ -44,8 +44,10 @@ class InitContext(Context):
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
@@ -101,13 +103,23 @@ class DocumentPlugin(Plugin):
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
@@ -252,7 +264,7 @@ class Method:
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)
diff --git a/suds/reader.py b/suds/reader.py
index fbd8760..1184f12 100644
--- a/suds/reader.py
+++ b/suds/reader.py
@@ -78,7 +78,7 @@ class DocumentReader(Reader):
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):
@@ -93,8 +93,12 @@ class DocumentReader(Reader):
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):
"""
diff --git a/tests/axis1.py b/tests/axis1.py
index 3a0ebd4..e221fae 100644
--- a/tests/axis1.py
+++ b/tests/axis1.py
@@ -45,10 +45,13 @@ class MyInitPlugin(InitPlugin):
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):
@@ -68,7 +71,10 @@ 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)