desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Process L{Types} objects and create the schema collection'
| def build_schema(self):
| container = SchemaCollection(self)
for t in [t for t in self.types if t.local()]:
for root in t.contents():
schema = Schema(root, self.url, self.options, container)
container.add(schema)
if (not len(container)):
root = Element.buildPath(self.root, 'types/schema')
... |
'Build method view for service'
| def add_methods(self, service):
| bindings = {'document/literal': Document(self), 'rpc/literal': RPC(self), 'rpc/encoded': Encoded(self)}
for p in service.ports:
binding = p.binding
ptype = p.binding.type
operations = p.binding.type.operations.values()
for name in [op.name for op in operations]:
m = F... |
'set (wrapped|bare) flag on messages'
| def set_wrapped(self):
| for b in self.bindings.values():
for op in b.operations.values():
for body in (op.soap.input.body, op.soap.output.body):
body.wrapped = False
if (len(body.parts) != 1):
continue
for p in body.parts:
if (p.ele... |
'@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}'
| def __init__(self, root, definitions):
| WObject.__init__(self, root, definitions)
self.location = root.get('location')
self.ns = root.get('namespace')
self.imported = None
pmd = self.__metadata__.__print__
pmd.wrappers['imported'] = repr
|
'Load the object by opening the URL'
| def load(self, definitions):
| url = self.location
log.debug('importing (%s)', url)
if ('://' not in url):
url = urljoin(definitions.url, url)
options = definitions.options
d = Definitions(url, options)
if d.root.match(Definitions.Tag, wsdlns):
self.import_definitions(definitions, d)
return
if d... |
'import/merge wsdl definitions'
| def import_definitions(self, definitions, d):
| definitions.types += d.types
definitions.messages.update(d.messages)
definitions.port_types.update(d.port_types)
definitions.bindings.update(d.bindings)
self.imported = d
log.debug('imported (WSDL):\n%s', d)
|
'import schema as <types/> content'
| def import_schema(self, definitions, d):
| if (not len(definitions.types)):
types = Types.create(definitions)
definitions.types.append(types)
else:
types = definitions.types[(-1)]
types.root.append(d.root)
log.debug('imported (XSD):\n%s', d.root)
|
'@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}'
| def __init__(self, root, definitions):
| WObject.__init__(self, root, definitions)
self.definitions = definitions
|
'@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}'
| def __init__(self, root, definitions):
| NamedObject.__init__(self, root, definitions)
pmd = Metadata()
pmd.wrappers = dict(element=repr, type=repr)
self.__metadata__.__print__ = pmd
tns = definitions.tns
self.element = self.__getref('element', tns)
self.type = self.__getref('type', tns)
|
'Get the qualified value of attribute named \'a\'.'
| def __getref(self, a, tns):
| s = self.root.get(a)
if (s is None):
return s
else:
return qualify(s, self.root, tns)
|
'@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}'
| def __init__(self, root, definitions):
| NamedObject.__init__(self, root, definitions)
self.parts = []
for p in root.getChildren('part'):
part = Part(p, definitions)
self.parts.append(part)
|
'@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}'
| def __init__(self, root, definitions):
| NamedObject.__init__(self, root, definitions)
self.operations = {}
for c in root.getChildren('operation'):
op = Facade('Operation')
op.name = c.get('name')
op.tns = definitions.tns
input = c.getChild('input')
if (input is None):
op.input = None
els... |
'Resolve named references to other WSDL objects.
@param definitions: A definitions object.
@type definitions: L{Definitions}'
| def resolve(self, definitions):
| for op in self.operations.values():
if (op.input is None):
op.input = Message(Element('no-input'), definitions)
else:
qref = qualify(op.input, self.root, definitions.tns)
msg = definitions.messages.get(qref)
if (msg is None):
raise Exce... |
'Shortcut used to get a contained operation by name.
@param name: An operation name.
@type name: str
@return: The named operation.
@rtype: Operation
@raise L{MethodNotFound}: When not found.'
| def operation(self, name):
| try:
return self.operations[name]
except Exception as e:
raise MethodNotFound(name)
|
'@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}'
| def __init__(self, root, definitions):
| NamedObject.__init__(self, root, definitions)
self.operations = {}
self.type = root.get('type')
sr = self.soaproot()
if (sr is None):
self.soap = None
log.debug('binding: "%s" not a soap binding', self.name)
return
soap = Facade('soap')
self.soap = soap... |
'get the soap:binding'
| def soaproot(self):
| for ns in (soapns, soap12ns):
sr = self.root.getChild('binding', ns=ns)
if (sr is not None):
return sr
return None
|
'Add <operation/> children'
| def add_operations(self, root, definitions):
| dsop = Element('operation', ns=soapns)
for c in root.getChildren('operation'):
op = Facade('Operation')
op.name = c.get('name')
sop = c.getChild('operation', default=dsop)
soap = Facade('soap')
soap.action = ('"%s"' % sop.get('soapAction', default=''))
soap.style ... |
'add the input/output body properties'
| def body(self, definitions, body, root):
| if (root is None):
body.use = 'literal'
body.namespace = definitions.tns
body.parts = ()
return
parts = root.get('parts')
if (parts is None):
body.parts = ()
else:
body.parts = re.split('[\\s,]', parts)
body.use = root.get('use', default='literal')
... |
'add the input/output header properties'
| def header(self, definitions, parent, root):
| if (root is None):
return
header = Facade('Header')
parent.headers.append(header)
header.use = root.get('use', default='literal')
ns = root.get('namespace')
if (ns is None):
header.namespace = definitions.tns
else:
prefix = root.findPrefix(ns, 'h0')
header.nam... |
'Resolve named references to other WSDL objects. This includes
cross-linking information (from) the portType (to) the I{soap}
protocol information on the binding for each operation.
@param definitions: A definitions object.
@type definitions: L{Definitions}'
| def resolve(self, definitions):
| self.resolveport(definitions)
for op in self.operations.values():
self.resolvesoapbody(definitions, op)
self.resolveheaders(definitions, op)
self.resolvefaults(definitions, op)
|
'Resolve port_type reference.
@param definitions: A definitions object.
@type definitions: L{Definitions}'
| def resolveport(self, definitions):
| ref = qualify(self.type, self.root, definitions.tns)
port_type = definitions.port_types.get(ref)
if (port_type is None):
raise Exception(("portType '%s', not-found" % self.type))
else:
self.type = port_type
|
'Resolve soap body I{message} parts by
cross-referencing with operation defined in port type.
@param definitions: A definitions object.
@type definitions: L{Definitions}
@param op: An I{operation} object.
@type op: I{operation}'
| def resolvesoapbody(self, definitions, op):
| ptop = self.type.operation(op.name)
if (ptop is None):
raise Exception, ("operation '%s' not defined in portType" % op.name)
soap = op.soap
parts = soap.input.body.parts
if len(parts):
pts = []
for p in ptop.input.parts:
if (p.name in parts):
... |
'Resolve soap header I{message} references.
@param definitions: A definitions object.
@type definitions: L{Definitions}
@param op: An I{operation} object.
@type op: I{operation}'
| def resolveheaders(self, definitions, op):
| soap = op.soap
headers = (soap.input.headers + soap.output.headers)
for header in headers:
mn = header.message
ref = qualify(mn, self.root, definitions.tns)
message = definitions.messages.get(ref)
if (message is None):
raise Exception, ("message'%s', not-found"... |
'Resolve soap fault I{message} references by
cross-referencing with operation defined in port type.
@param definitions: A definitions object.
@type definitions: L{Definitions}
@param op: An I{operation} object.
@type op: I{operation}'
| def resolvefaults(self, definitions, op):
| ptop = self.type.operation(op.name)
if (ptop is None):
raise Exception, ("operation '%s' not defined in portType" % op.name)
soap = op.soap
for fault in soap.faults:
for f in ptop.faults:
if (f.name == fault.name):
fault.parts = f.message.parts
... |
'Shortcut used to get a contained operation by name.
@param name: An operation name.
@type name: str
@return: The named operation.
@rtype: Operation
@raise L{MethodNotFound}: When not found.'
| def operation(self, name):
| try:
return self.operations[name]
except:
raise MethodNotFound(name)
|
'@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}
@param service: A service object.
@type service: L{Service}'
| def __init__(self, root, definitions, service):
| NamedObject.__init__(self, root, definitions)
self.__service = service
self.binding = root.get('binding')
address = root.getChild('address')
if (address is None):
self.location = None
else:
self.location = address.get('location').encode('utf-8')
self.methods = {}
|
'Get a method defined in this portType by name.
@param name: A method name.
@type name: str
@return: The requested method object.
@rtype: I{Method}'
| def method(self, name):
| return self.methods.get(name)
|
'@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}'
| def __init__(self, root, definitions):
| NamedObject.__init__(self, root, definitions)
self.ports = []
for p in root.getChildren('port'):
port = Port(p, definitions, self)
self.ports.append(port)
|
'Locate a port by name.
@param name: A port name.
@type name: str
@return: The port object.
@rtype: L{Port}'
| def port(self, name):
| for p in self.ports:
if (p.name == name):
return p
return None
|
'Override the invocation location (url) for service method.
@param url: A url location.
@type url: A url.
@param names: A list of method names. None=ALL
@type names: [str,..]'
| def setlocation(self, url, names=None):
| for p in self.ports:
for m in p.methods.values():
if ((names is None) or (m.name in names)):
m.location = url
|
'Resolve named references to other WSDL objects.
Ports without soap bindings are discarded.
@param definitions: A definitions object.
@type definitions: L{Definitions}'
| def resolve(self, definitions):
| filtered = []
for p in self.ports:
ref = qualify(p.binding, self.root, definitions.tns)
binding = definitions.bindings.get(ref)
if (binding is None):
raise Exception(("binding '%s', not-found" % p.binding))
if (binding.soap is None):
log.debug('bindi... |
'Create an object based on the root tag name.
@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}
@return: The created object.
@rtype: L{WObject}'
| @classmethod
def create(cls, root, definitions):
| fn = cls.tags.get(root.name)
if (fn is not None):
return fn(root, definitions)
else:
return None
|
'Process an object graph representation of the xml I{node}.
@param content: The current content being unmarshalled.
@type content: L{Content}
@return: A suds object.
@rtype: L{Object}'
| def process(self, content):
| self.reset()
return self.append(content)
|
'Process the specified node and convert the XML document into
a I{suds} L{object}.
@param content: The current content being unmarshalled.
@type content: L{Content}
@return: A I{append-result} tuple as: (L{Object}, I{value})
@rtype: I{append-result}
@note: This is not the proper entry point.
@see: L{process()}'
| def append(self, content):
| self.start(content)
self.append_attributes(content)
self.append_children(content)
self.append_text(content)
self.end(content)
return self.postprocess(content)
|
'Perform final processing of the resulting data structure as follows:
- Mixed values (children and text) will have a result of the I{content.node}.
- Simi-simple values (attributes, no-children and text) will have a result of a
property object.
- Simple values (no-attributes, no-children with text nodes) will have a st... | def postprocess(self, content):
| node = content.node
if (len(node.children) and node.hasText()):
return node
attributes = AttrList(node.attributes)
if (attributes.rlen() and (not len(node.children)) and node.hasText()):
p = Factory.property(node.name, node.getText())
return merge(content.data, p)
if len(cont... |
'Append attribute nodes into L{Content.data}.
Attributes in the I{schema} or I{xml} namespaces are skipped.
@param content: The current content being unmarshalled.
@type content: L{Content}'
| def append_attributes(self, content):
| attributes = AttrList(content.node.attributes)
for attr in attributes.real():
name = attr.name
value = attr.value
self.append_attribute(name, value, content)
|
'Append an attribute name/value into L{Content.data}.
@param name: The attribute name
@type name: basestring
@param value: The attribute\'s value
@type value: basestring
@param content: The current content being unmarshalled.
@type content: L{Content}'
| def append_attribute(self, name, value, content):
| key = name
key = ('_%s' % reserved.get(key, key))
setattr(content.data, key, value)
|
'Append child nodes into L{Content.data}
@param content: The current content being unmarshalled.
@type content: L{Content}'
| def append_children(self, content):
| for child in content.node:
cont = Content(child)
cval = self.append(cont)
key = reserved.get(child.name, child.name)
if (key in content.data):
v = getattr(content.data, key)
if isinstance(v, list):
v.append(cval)
else:
... |
'Append text nodes into L{Content.data}
@param content: The current content being unmarshalled.
@type content: L{Content}'
| def append_text(self, content):
| if content.node.hasText():
content.text = content.node.getText()
|
'Processing on I{node} has started. Build and return
the proper object.
@param content: The current content being unmarshalled.
@type content: L{Content}
@return: A subclass of Object.
@rtype: L{Object}'
| def start(self, content):
| content.data = Factory.object(content.node.name)
|
'Processing on I{node} has ended.
@param content: The current content being unmarshalled.
@type content: L{Content}'
| def end(self, content):
| pass
|
'Get whether the content is bounded (not a list).
@param content: The current content being unmarshalled.
@type content: L{Content}
@return: True if bounded, else False
@rtype: boolean'
| def bounded(self, content):
| return (not self.unbounded(content))
|
'Get whether the object is unbounded (a list).
@param content: The current content being unmarshalled.
@type content: L{Content}
@return: True if unbounded, else False
@rtype: boolean'
| def unbounded(self, content):
| return False
|
'Get whether the object is nillable.
@param content: The current content being unmarshalled.
@type content: L{Content}
@return: True if nillable, else False
@rtype: boolean'
| def nillable(self, content):
| return False
|
'@param schema: A schema object.
@type schema: L{xsd.schema.Schema}'
| def __init__(self, schema):
| self.resolver = NodeResolver(schema)
|
'Process an object graph representation of the xml L{node}.
@param node: An XML tree.
@type node: L{sax.element.Element}
@param type: The I{optional} schema type.
@type type: L{xsd.sxbase.SchemaObject}
@return: A suds object.
@rtype: L{Object}'
| def process(self, node, type):
| content = Content(node)
content.type = type
return Core.process(self, content)
|
'Append an attribute name/value into L{Content.data}.
@param name: The attribute name
@type name: basestring
@param value: The attribute\'s value
@type value: basestring
@param content: The current content being unmarshalled.
@type content: L{Content}'
| def append_attribute(self, name, value, content):
| type = self.resolver.findattr(name)
if (type is None):
log.warn('attribute (%s) type, not-found', name)
else:
value = self.translated(value, type)
Core.append_attribute(self, name, value, content)
|
'Append text nodes into L{Content.data}
Here is where the I{true} type is used to translate the value
into the proper python type.
@param content: The current content being unmarshalled.
@type content: L{Content}'
| def append_text(self, content):
| Core.append_text(self, content)
known = self.resolver.top().resolved
content.text = self.translated(content.text, known)
|
'translate using the schema type'
| def translated(self, value, type):
| if (value is not None):
resolved = type.resolve()
return resolved.translate(value)
else:
return value
|
'Grab the (aty) soap-enc:arrayType and attach it to the
content for proper array processing later in end().
@param content: The current content being unmarshalled.
@type content: L{Content}
@return: self
@rtype: L{Encoded}'
| def setaty(self, content):
| name = 'arrayType'
ns = (None, 'http://schemas.xmlsoap.org/soap/encoding/')
aty = content.node.get(name, ns)
if (aty is not None):
content.aty = aty
parts = aty.split('[')
ref = parts[0]
if (len(parts) == 2):
self.applyaty(content, ref)
else:
... |
'Apply the type referenced in the I{arrayType} to the content
(child nodes) of the array. Each element (node) in the array
that does not have an explicit xsi:type attribute is given one
based on the I{arrayType}.
@param content: An array content.
@type content: L{Content}
@param xty: The XSI type reference.
@type xty:... | def applyaty(self, content, xty):
| name = 'type'
ns = Namespace.xsins
parent = content.node
for child in parent.getChildren():
ref = child.get(name, ns)
if (ref is None):
parent.addPrefix(ns[0], ns[1])
attr = ':'.join((ns[0], name))
child.set(attr, xty)
return self
|
'Promote (replace) the content.data with the first attribute
of the current content.data that is a I{list}. Note: the
content.data may be empty or contain only _x attributes.
In either case, the content.data is assigned an empty list.
@param content: An array content.
@type content: L{Content}'
| def promote(self, content):
| for (n, v) in content.data:
if isinstance(v, list):
content.data = v
return
content.data = []
|
'Process an object graph representation of the xml I{node}.
@param node: An XML tree.
@type node: L{sax.element.Element}
@return: A suds object.
@rtype: L{Object}'
| def process(self, node):
| content = Content(node)
return Core.process(self, content)
|
'@param attributes: A list of attributes
@type attributes: list'
| def __init__(self, attributes):
| self.raw = attributes
|
'Get list of I{real} attributes which exclude xs and xml attributes.
@return: A list of I{real} attributes.
@rtype: I{generator}'
| def real(self):
| for a in self.raw:
if self.skip(a):
continue
(yield a)
|
'Get the number of I{real} attributes which exclude xs and xml attributes.
@return: A count of I{real} attributes.
@rtype: L{int}'
| def rlen(self):
| n = 0
for a in self.real():
n += 1
return n
|
'Get list of I{filtered} attributes which exclude xs.
@return: A list of I{filtered} attributes.
@rtype: I{generator}'
| def lang(self):
| for a in self.raw:
if (a.qname() == 'xml:lang'):
return a.value
return None
|
'Get whether to skip (filter-out) the specified attribute.
@param attr: An attribute.
@type attr: I{Attribute}
@return: True if should be skipped.
@rtype: bool'
| def skip(self, attr):
| ns = attr.namespace()
skip = (Namespace.xmlns[1], 'http://schemas.xmlsoap.org/soap/encoding/', 'http://schemas.xmlsoap.org/soap/envelope/', 'http://www.w3.org/2003/05/soap-envelope')
return (Namespace.xs(ns) or (ns[1] in skip))
|
'@param wsdl: A wsdl object
@type wsdl: L{Definitions}
@param service: A service B{name}.
@type service: str'
| def __init__(self, wsdl, service):
| self.wsdl = wsdl
self.service = service
self.ports = []
self.params = []
self.types = []
self.prefixes = []
self.addports()
self.paramtypes()
self.publictypes()
self.getprefixes()
self.pushprefixes()
|
'Add our prefixes to the wsdl so that when users invoke methods
and reference the prefixes, the will resolve properly.'
| def pushprefixes(self):
| for ns in self.prefixes:
self.wsdl.root.addPrefix(ns[0], ns[1])
|
'Look through the list of service ports and construct a list of tuples where
each tuple is used to describe a port and it\'s list of methods as:
(port, [method]). Each method is tuple: (name, [pdef,..] where each pdef is
a tuple: (param-name, type).'
| def addports(self):
| timer = metrics.Timer()
timer.start()
for port in self.service.ports:
p = self.findport(port)
for op in port.binding.operations.values():
m = p[0].method(op.name)
binding = m.binding.input
method = (m.name, binding.param_defs(m))
p[1].append(me... |
'Find and return a port tuple for the specified port.
Created and added when not found.
@param port: A port.
@type port: I{service.Port}
@return: A port tuple.
@rtype: (port, [method])'
| def findport(self, port):
| for p in self.ports:
if (p[0] == p):
return p
p = (port, [])
self.ports.append(p)
return p
|
'Add prefixes foreach namespace referenced by parameter types.'
| def getprefixes(self):
| namespaces = []
for l in (self.params, self.types):
for (t, r) in l:
ns = r.namespace()
if (ns[1] is None):
continue
if (ns[1] in namespaces):
continue
if (Namespace.xs(ns) or Namespace.xsd(ns)):
continue
... |
'get all parameter types'
| def paramtypes(self):
| for m in [p[1] for p in self.ports]:
for p in [p[1] for p in m]:
for pd in p:
if (pd[1] in self.params):
continue
item = (pd[1], pd[1].resolve())
self.params.append(item)
|
'get all public types'
| def publictypes(self):
| for t in self.wsdl.schema.types.values():
if (t in self.params):
continue
if (t in self.types):
continue
item = (t, t)
self.types.append(item)
tc = (lambda x, y: cmp(x[0].name, y[0].name))
self.types.sort(cmp=tc)
|
'Get the next available prefix. This means a prefix starting with \'ns\' with
a number appended as (ns0, ns1, ..) that is not already defined on the
wsdl document.'
| def nextprefix(self):
| used = [ns[0] for ns in self.prefixes]
used += [ns[0] for ns in self.wsdl.root.nsprefixes.items()]
for n in range(0, 1024):
p = ('ns%d' % n)
if (p not in used):
return p
raise Exception('prefixes exhausted')
|
'Get the prefix for the specified namespace (uri)
@param u: A namespace uri.
@type u: str
@return: The namspace.
@rtype: (prefix, uri).'
| def getprefix(self, u):
| for ns in Namespace.all:
if (u == ns[1]):
return ns[0]
for ns in self.prefixes:
if (u == ns[1]):
return ns[0]
raise Exception(('ns (%s) not mapped' % u))
|
'Get a (namespace) translated I{qualified} name for specified type.
@param type: A schema type.
@type type: I{suds.xsd.sxbasic.SchemaObject}
@return: A translated I{qualified} name.
@rtype: str'
| def xlate(self, type):
| resolved = type.resolve()
name = resolved.name
if type.unbounded():
name += '[]'
ns = resolved.namespace()
if (ns[1] == self.wsdl.tns[1]):
return name
prefix = self.getprefix(ns[1])
return ':'.join((prefix, name))
|
'Get a textual description of the service for which this object represents.
@return: A textual description.
@rtype: str'
| def description(self):
| s = []
indent = (lambda n: ('\n%*s' % ((n * 3), ' ')))
s.append(('Service ( %s ) tns="%s"' % (self.service.name, self.wsdl.tns[1])))
s.append(indent(1))
s.append(('Prefixes (%d)' % len(self.prefixes)))
for p in self.prefixes:
s.append(indent(2))
s.append(('%s ... |
'@param schema: A schema object.
@type schema: L{xsd.schema.Schema}'
| def __init__(self, schema):
| self.schema = schema
|
'Get the definition object for the schema object by name.
@param name: The name of a schema object.
@type name: basestring
@param resolved: A flag indicating that the fully resolved type
should be returned.
@type resolved: boolean
@return: The found schema I{type}
@rtype: L{xsd.sxbase.SchemaObject}'
| def find(self, name, resolved=True):
| log.debug('searching schema for (%s)', name)
qref = qualify(name, self.schema.root, self.schema.tns)
query = BlindQuery(qref)
result = query.execute(self.schema)
if (result is None):
log.error('(%s) not-found', name)
return None
log.debug('found (%s) as (%s)'... |
'@param wsdl: A schema object.
@type wsdl: L{wsdl.Definitions}
@param ps: The path separator character
@type ps: char'
| def __init__(self, wsdl, ps='.'):
| Resolver.__init__(self, wsdl.schema)
self.wsdl = wsdl
self.altp = re.compile('({)(.+)(})(.+)')
self.splitp = re.compile(('({.+})*[^\\%s]+' % ps[0]))
|
'Get the definition object for the schema type located at the specified path.
The path may contain (.) dot notation to specify nested types.
Actually, the path separator is usually a (.) but can be redefined
during contruction.
@param path: A (.) separated path to a schema type.
@type path: basestring
@param resolved: ... | def find(self, path, resolved=True):
| result = None
parts = self.split(path)
try:
result = self.root(parts)
if (len(parts) > 1):
result = result.resolve(nobuiltin=True)
result = self.branch(result, parts)
result = self.leaf(result, parts)
if resolved:
result = result.resolv... |
'Find the path root.
@param parts: A list of path parts.
@type parts: [str,..]
@return: The root.
@rtype: L{xsd.sxbase.SchemaObject}'
| def root(self, parts):
| result = None
name = parts[0]
log.debug('searching schema for (%s)', name)
qref = self.qualify(parts[0])
query = BlindQuery(qref)
result = query.execute(self.schema)
if (result is None):
log.error('(%s) not-found', name)
raise PathResolver.BadPath(name)
else:
... |
'Traverse the path until the leaf is reached.
@param parts: A list of path parts.
@type parts: [str,..]
@param root: The root.
@type root: L{xsd.sxbase.SchemaObject}
@return: The end of the branch.
@rtype: L{xsd.sxbase.SchemaObject}'
| def branch(self, root, parts):
| result = root
for part in parts[1:(-1)]:
name = splitPrefix(part)[1]
log.debug('searching parent (%s) for (%s)', Repr(result), name)
(result, ancestry) = result.get_child(name)
if (result is None):
log.error('(%s) not-found', name)
raise Pat... |
'Find the leaf.
@param parts: A list of path parts.
@type parts: [str,..]
@param parent: The leaf\'s parent.
@type parent: L{xsd.sxbase.SchemaObject}
@return: The leaf.
@rtype: L{xsd.sxbase.SchemaObject}'
| def leaf(self, parent, parts):
| name = splitPrefix(parts[(-1)])[1]
if name.startswith('@'):
(result, path) = parent.get_attribute(name[1:])
else:
(result, ancestry) = parent.get_child(name)
if (result is None):
raise PathResolver.BadPath(name)
return result
|
'Qualify the name as either:
- plain name
- ns prefixed name (eg: ns0:Person)
- fully ns qualified name (eg: {http://myns-uri}Person)
@param name: The name of an object in the schema.
@type name: str
@return: A qualifed name.
@rtype: qname'
| def qualify(self, name):
| m = self.altp.match(name)
if (m is None):
return qualify(name, self.wsdl.root, self.wsdl.tns)
else:
return (m.group(4), m.group(2))
|
'Split the string on (.) while preserving any (.) inside the
\'{}\' alternalte syntax for full ns qualification.
@param s: A plain or qualifed name.
@type s: str
@return: A list of the name\'s parts.
@rtype: [str,..]'
| def split(self, s):
| parts = []
b = 0
while 1:
m = self.splitp.match(s, b)
if (m is None):
break
(b, e) = m.span()
parts.append(s[b:e])
b = (e + 1)
return parts
|
'@param schema: A schema object.
@type schema: L{xsd.schema.Schema}'
| def __init__(self, schema):
| Resolver.__init__(self, schema)
self.stack = Stack()
|
'Reset the resolver\'s state.'
| def reset(self):
| self.stack = Stack()
|
'Push an I{object} onto the stack.
@param x: An object to push.
@type x: L{Frame}
@return: The pushed frame.
@rtype: L{Frame}'
| def push(self, x):
| if isinstance(x, Frame):
frame = x
else:
frame = Frame(x)
self.stack.append(frame)
log.debug('push: (%s)\n%s', Repr(frame), Repr(self.stack))
return frame
|
'Get the I{frame} at the top of the stack.
@return: The top I{frame}, else None.
@rtype: L{Frame}'
| def top(self):
| if len(self.stack):
return self.stack[(-1)]
else:
return Frame.Empty()
|
'Pop the frame at the top of the stack.
@return: The popped frame, else None.
@rtype: L{Frame}'
| def pop(self):
| if len(self.stack):
popped = self.stack.pop()
log.debug('pop: (%s)\n%s', Repr(popped), Repr(self.stack))
return popped
else:
log.debug('stack empty, not-popped')
return None
|
'Get the current stack depth.
@return: The current stack depth.
@rtype: int'
| def depth(self):
| return len(self.stack)
|
'get a child by name'
| def getchild(self, name, parent):
| log.debug('searching parent (%s) for (%s)', Repr(parent), name)
if name.startswith('@'):
return parent.get_attribute(name[1:])
else:
return parent.get_child(name)
|
'@param schema: A schema object.
@type schema: L{xsd.schema.Schema}'
| def __init__(self, schema):
| TreeResolver.__init__(self, schema)
|
'@param node: An xml node to be resolved.
@type node: L{sax.element.Element}
@param resolved: A flag indicating that the fully resolved type should be
returned.
@type resolved: boolean
@param push: Indicates that the resolved type should be
pushed onto the stack.
@type push: boolean
@return: The found schema I{type}
@r... | def find(self, node, resolved=False, push=True):
| name = node.name
parent = self.top().resolved
if (parent is None):
(result, ancestry) = self.query(name, node)
else:
(result, ancestry) = self.getchild(name, parent)
known = self.known(node)
if (result is None):
return result
if push:
frame = Frame(result, res... |
'Find an attribute type definition.
@param name: An attribute name.
@type name: basestring
@param resolved: A flag indicating that the fully resolved type should be
returned.
@type resolved: boolean
@return: The found schema I{type}
@rtype: L{xsd.sxbase.SchemaObject}'
| def findattr(self, name, resolved=True):
| name = ('@%s' % name)
parent = self.top().resolved
if (parent is None):
(result, ancestry) = self.query(name, node)
else:
(result, ancestry) = self.getchild(name, parent)
if (result is None):
return result
if resolved:
result = result.resolve()
return result
|
'blindly query the schema by name'
| def query(self, name, node):
| log.debug('searching schema for (%s)', name)
qref = qualify(name, node, node.namespace())
query = BlindQuery(qref)
result = query.execute(self.schema)
return (result, [])
|
'resolve type referenced by @xsi:type'
| def known(self, node):
| ref = node.get('type', Namespace.xsins)
if (ref is None):
return None
qref = qualify(ref, node, node.namespace())
query = BlindQuery(qref)
return query.execute(self.schema)
|
'@param schema: A schema object.
@type schema: L{xsd.schema.Schema}'
| def __init__(self, schema):
| TreeResolver.__init__(self, schema)
|
'@param name: The name of the object to be resolved.
@type name: basestring
@param object: The name\'s value.
@type object: (any|L{Object})
@param resolved: A flag indicating that the fully resolved type
should be returned.
@type resolved: boolean
@param push: Indicates that the resolved type should be
pushed onto the ... | def find(self, name, object, resolved=False, push=True):
| known = None
parent = self.top().resolved
if (parent is None):
(result, ancestry) = self.query(name)
else:
(result, ancestry) = self.getchild(name, parent)
if (result is None):
return None
if isinstance(object, Object):
known = self.known(object)
if push:
... |
'blindly query the schema by name'
| def query(self, name):
| log.debug('searching schema for (%s)', name)
schema = self.schema
wsdl = self.wsdl()
if (wsdl is None):
qref = qualify(name, schema.root, schema.tns)
else:
qref = qualify(name, wsdl.root, wsdl.tns)
query = BlindQuery(qref)
result = query.execute(schema)
return (r... |
'get the wsdl'
| def wsdl(self):
| container = self.schema.container
if (container is None):
return None
else:
return container.wsdl
|
'get the type specified in the object\'s metadata'
| def known(self, object):
| try:
md = object.__metadata__
known = md.sxtype
return known
except:
pass
|
'get s string representation of object'
| def tostr(self, object, indent=(-2)):
| history = []
return self.process(object, history, indent)
|
'print object using the specified indent (n) and newline (nl).'
| def process(self, object, h, n=0, nl=False):
| if (object is None):
return 'None'
if isinstance(object, Object):
if (len(object) == 0):
return '<empty>'
else:
return self.print_object(object, h, (n + 2), nl)
if isinstance(object, dict):
if (len(object) == 0):
return '<empty>'
el... |
'print complex using the specified indent (n) and newline (nl).'
| def print_object(self, d, h, n, nl=False):
| s = []
cls = d.__class__
md = d.__metadata__
if (d in h):
s.append('(')
s.append(cls.__name__)
s.append(')')
s.append('...')
return ''.join(s)
h.append(d)
if nl:
s.append('\n')
s.append(self.indent(n))
if (cls != Object):
s.appe... |
'print complex using the specified indent (n) and newline (nl).'
| def print_dictionary(self, d, h, n, nl=False):
| if (d in h):
return '{}...'
h.append(d)
s = []
if nl:
s.append('\n')
s.append(self.indent(n))
s.append('{')
for item in d.items():
s.append('\n')
s.append(self.indent((n + 1)))
if isinstance(item[1], (list, tuple)):
s.append(tostr(item[... |
'print collection using the specified indent (n) and newline (nl).'
| def print_collection(self, c, h, n):
| if (c in h):
return '[]...'
h.append(c)
s = []
for item in c:
s.append('\n')
s.append(self.indent(n))
s.append(self.process(item, h, (n - 2)))
s.append(',')
h.pop()
return ''.join(s)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.