Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyar authored and kamyar committed May 7, 2015
1 parent b129d31 commit f291087
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 40 deletions.
26 changes: 16 additions & 10 deletions suds/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,24 @@ def __init__(self, url, **kwargs):
if "cache" not in kwargs:
kwargs["cache"] = suds.cache.ObjectCache(days=1)
self.set_options(**kwargs)
reader = DefinitionsReader(options, Definitions)
asyncio.async(reader.open(url))
self.wsdl = reader.wsdl
plugins = PluginContainer(options.plugins)
plugins.init.initialized(wsdl=self.wsdl)
self.url = url


@asyncio.coroutine
def connect(self):
df = Definitions(self.url, self.options)
yield from df.connect()
self.reader = DefinitionsReader(self.options, df.parse)
yield from self.reader.open(self.url)
self.wsdl = yield from self.reader.open(self.url)
self.factory = Factory(self.wsdl)
self.service = ServiceSelector(self, self.wsdl.services)
self.sd = []
self.sd_list = []
for s in self.wsdl.services:
sd = ServiceDefinition(self.wsdl, s)
self.sd.append(sd)

self.sd_list.append(sd)
plugins = PluginContainer(self.options.plugins)
plugins.init.initialized(wsdl=self.wsdl)


def set_options(self, **kwargs):
Expand Down Expand Up @@ -186,7 +192,7 @@ def __init__(self):
clone.wsdl = self.wsdl
clone.factory = self.factory
clone.service = ServiceSelector(clone, self.wsdl.services)
clone.sd = self.sd
clone.sd_list = self.sd_list
return clone

def __str__(self):
Expand All @@ -195,7 +201,7 @@ def __str__(self):
s.append(" version: %s" % (suds.__version__,))
if suds.__build__:
s.append(" build: %s" % (suds.__build__,))
for sd in self.sd:
for sd in self.sd_list:
s.append("\n\n%s" % (str(sd),))
return "".join(s)

Expand Down
2 changes: 1 addition & 1 deletion suds/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def open(self, url):
id = self.mangle(url, "wsdl")
wsdl = cache.get(id)
if wsdl is None:
wsdl = yield from self.fn(url, self.options)
wsdl = self.fn(url, self.options)
print(wsdl)
cache.put(id, wsdl)
else:
Expand Down
68 changes: 43 additions & 25 deletions suds/wsdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import re
from suds import soaparray
from urllib.parse import urljoin
import asyncio

from logging import getLogger
log = getLogger(__name__)
Expand All @@ -53,28 +54,27 @@ class WObject(Object):
"""

def __init__(self, root):
def __init__(self):
"""
@param root: An XML root element.
@type root: L{Element}
"""
Object.__init__(self)
self.root = root
pmd = Metadata()
pmd.excludes = ["root"]
pmd.wrappers = dict(qname=repr)
self.__metadata__.__print__ = pmd

def resolve(self, definitions):
def parse(self, definitions):
"""
Resolve named references to other WSDL objects.
@param definitions: A definitions object.
@type definitions: L{Definitions}
"""
pass
pmd = Metadata()
pmd.excludes = ["root"]
pmd.wrappers = dict(qname=repr)
self.__metadata__.__print__ = pmd



class NamedObject(WObject):
Expand All @@ -96,13 +96,18 @@ def __init__(self, root, definitions):
@type definitions: L{Definitions}
"""
WObject.__init__(self, root)
self.name = root.get("name")
WObject.__init__(self)
self.root = root

def parse(self, definitions):
super().parse(definitions)
self.name = self.root.get("name")
self.qname = (self.name, definitions.tns[1])
pmd = self.__metadata__.__print__
pmd.wrappers["qname"] = repr



class Definitions(WObject):
"""
I{Root} container for all the WSDL objects defined by <wsdl:definitions/>.
Expand Down Expand Up @@ -135,22 +140,12 @@ class Definitions(WObject):
Tag = "definitions"

def __init__(self, url, options):
"""
@param url: A URL to the WSDL.
@type url: str
@param options: An options dictionary.
@type options: L{options.Options}
"""
super().__init__()
log.debug("reading WSDL at: %s ...", url)
reader = DocumentReader(options)
d = reader.open(url)
root = d.root()
WObject.__init__(self, root)
self.url = url
self.reader = DocumentReader(options)
self.id = objid(self)
self.options = options
self.url = url
self.tns = self.mktns(root)
self.types = []
self.schema = None
self.children = []
Expand All @@ -159,8 +154,28 @@ def __init__(self, url, options):
self.port_types = {}
self.bindings = {}
self.services = []



def __call__(self):
"""
@param url: A URL to the WSDL.
@type url: str
@param options: An options dictionary.
@type options: L{options.Options}
"""
pass


@asyncio.coroutine
def connect(self):
d = yield from self.reader.open(self.url)
self.root = d.root()
self.tns = self.mktns(self.root)
self.add_children(self.root)
self.children.sort()

pmd = self.__metadata__.__print__
pmd.excludes.append("children")
pmd.excludes.append("wsdl")
Expand All @@ -171,7 +186,10 @@ def __init__(self, url, options):
self.set_wrapped()
for s in self.services:
self.add_methods(s)
log.debug("WSDL at '%s' loaded:\n%s", url, self)
log.debug("WSDL at '%s' loaded:\n%s", self.url, self)




def mktns(self, root):
"""Get/create the target namespace."""
Expand Down Expand Up @@ -371,7 +389,7 @@ def __init__(self, root, definitions):
@type definitions: L{Definitions}
"""
WObject.__init__(self, root)
WObject.__init__(self)
self.definitions = definitions

def contents(self):
Expand Down
10 changes: 6 additions & 4 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
from suds.client import Client


# @asyncio.coroutine
# def Test():
c=Client('https://sep.shaparak.ir/Payments/InitPayment.asmx?wsdl')
@asyncio.coroutine
def Test():
c=Client('https://sep.shaparak.ir/Payments/InitPayment.asmx?wsdl')
yield from c.connect()


# asyncio.get_event_loop().run_until_complete(Test())

asyncio.get_event_loop().run_until_complete(Test())

0 comments on commit f291087

Please sign in to comment.