ó sJc@sdZddlZddlmZddlTddlmZmZddlm Z ddl m Z m Z m Z eeƒZddd „ƒYZd efd „ƒYZd efd „ƒYZdefd„ƒYZdefd„ƒYZddd„ƒYZdefd„ƒYZdS(sf The I{resolver} module provides a collection of classes that provide wsdl/xsd named type resolution. iÿÿÿÿN(t getLogger(t*(t splitPrefixt Namespace(tObject(t BlindQueryt TypeQuerytqualifytResolvercBs#eZdZd„Zed„ZRS(sx An I{abstract} schema-type resolver. @ivar schema: A schema object. @type schema: L{xsd.schema.Schema} cCs ||_dS(s\ @param schema: A schema object. @type schema: L{xsd.schema.Schema} N(tschema(tselfR ((s1/usr/lib/python2.7/site-packages/suds/resolver.pyt__init__'scCsžtjd|ƒt||jj|jjƒ}t|ƒ}|j|jƒ}|dkrltj d|ƒdStjd|t |ƒƒ|rš|j ƒ}n|S(sx 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} ssearching schema for (%s)s(%s) not-foundsfound (%s) as (%s)N( tlogtdebugRR trootttnsRtexecutetNoneterrortReprtresolve(R tnametresolvedtqreftquerytresult((s1/usr/lib/python2.7/site-packages/suds/resolver.pytfind.s   (t__name__t __module__t__doc__R tTrueR(((s1/usr/lib/python2.7/site-packages/suds/resolver.pyR s t PathResolvercBsieZdZdd„Zed„Zd„Zd„Zd„Zd„Z d„Z d e fd „ƒYZ RS( sâ Resolveds the definition object for the schema type located at the specified path. The path may contain (.) dot notation to specify nested types. @ivar wsdl: A wsdl object. @type wsdl: L{wsdl.Definitions} t.cCsLtj||jƒ||_tjdƒ|_tjd|dƒ|_dS(sž @param wsdl: A schema object. @type wsdl: L{wsdl.Definitions} @param ps: The path separator character @type ps: char s({)(.+)(})(.+)s({.+})*[^\%s]+iN(RR R twsdltretcompiletaltptsplitp(R R!tps((s1/usr/lib/python2.7/site-packages/suds/resolver.pyR Ns cCsºd}|j|ƒ}yy|j|ƒ}t|ƒdkrr|jdtƒ}|j||ƒ}|j||ƒ}n|r|jdtƒ}nWn%tj k rµt j d|ƒnX|S(sD 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: 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} it nobuiltinspath: "%s", not-foundN( RtsplitRtlenRRtbranchtleafRtBadPathR R(R tpathRRtparts((s1/usr/lib/python2.7/site-packages/suds/resolver.pyRZscCsœd}|d}tjd|ƒ|j|dƒ}t|ƒ}|j|jƒ}|dkrtjd|ƒtj |ƒ‚ntjd|t |ƒƒ|S(sµ Find the path root. @param parts: A list of path parts. @type parts: [str,..] @return: The root. @rtype: L{xsd.sxbase.SchemaObject} issearching schema for (%s)s(%s) not-foundsfound (%s) as (%s)N( RR R RRRR RRR,R(R R.RRRR((s1/usr/lib/python2.7/site-packages/suds/resolver.pyRvs   cCs¹|}x¬|dd!D]}t|ƒd}tjdt|ƒ|ƒ|j|ƒ\}}|dkr†tjd|ƒtj|ƒ‚q|j dt ƒ}tjd|t|ƒƒqW|S(s) 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} iiÿÿÿÿssearching parent (%s) for (%s)s(%s) not-foundR'sfound (%s) as (%s)N( RR R Rt get_childRRRR,RR(R RR.RtpartRtancestry((s1/usr/lib/python2.7/site-packages/suds/resolver.pyR*‹s  cCsvt|dƒd}|jdƒr?|j|dƒ\}}n|j|ƒ\}}|dkrrtj|ƒ‚n|S(s  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} iÿÿÿÿit@N(Rt startswitht get_attributeR/RRR,(R tparentR.RRR-R1((s1/usr/lib/python2.7/site-packages/suds/resolver.pyR+¢s  cCsZ|jj|ƒ}|dkr:t||jj|jjƒS|jdƒ|jdƒfSdS(s> 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 iiN(R$tmatchRRR!RRtgroup(R Rtm((s1/usr/lib/python2.7/site-packages/suds/resolver.pyRµs  cCskg}d}xX|jj||ƒ}|dkr4Pn|jƒ\}}|j|||!ƒ|d}q|S(s 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,..] iiN(R%R6Rtspantappend(R tsR.tbR8te((s1/usr/lib/python2.7/site-packages/suds/resolver.pyR(Æs   R,cBseZRS((RR(((s1/usr/lib/python2.7/site-packages/suds/resolver.pyR,Ús( RRRR RRRR*R+RR(t ExceptionR,(((s1/usr/lib/python2.7/site-packages/suds/resolver.pyRFs      t TreeResolvercBsMeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z RS(sû The tree resolver is a I{stateful} tree resolver used to resolve each node in a tree. As such, it mirrors the tree structure to ensure that nodes are resolved in context. @ivar stack: The context stack. @type stack: list cCs tj||ƒtƒ|_dS(s\ @param schema: A schema object. @type schema: L{xsd.schema.Schema} N(RR tStacktstack(R R ((s1/usr/lib/python2.7/site-packages/suds/resolver.pyR çscCstƒ|_dS(s- Reset the resolver's state. N(R@RA(R ((s1/usr/lib/python2.7/site-packages/suds/resolver.pytresetïscCsZt|tƒr|}n t|ƒ}|jj|ƒtjdt|ƒt|jƒƒ|S(s® Push an I{object} onto the stack. @param x: An object to push. @type x: L{Frame} @return: The pushed frame. @rtype: L{Frame} s push: (%s) %s(t isinstancetFrameRAR:R R R(R txtframe((s1/usr/lib/python2.7/site-packages/suds/resolver.pytpushõs   "cCs(t|jƒr|jdStjƒSdS(s‚ Get the I{frame} at the top of the stack. @return: The top I{frame}, else None. @rtype: L{Frame} iÿÿÿÿN(R)RARDtEmpty(R ((s1/usr/lib/python2.7/site-packages/suds/resolver.pyttops cCsUt|jƒrD|jjƒ}tjdt|ƒt|jƒƒ|StjdƒdS(s Pop the frame at the top of the stack. @return: The popped frame, else None. @rtype: L{Frame} s pop: (%s) %ssstack empty, not-poppedN(R)RAtpopR R RR(R tpopped((s1/usr/lib/python2.7/site-packages/suds/resolver.pyRJs " cCs t|jƒS(sl Get the current stack depth. @return: The current stack depth. @rtype: int (R)RA(R ((s1/usr/lib/python2.7/site-packages/suds/resolver.pytdepthscCsJtjdt|ƒ|ƒ|jdƒr9|j|dƒS|j|ƒSdS(s get a child by name ssearching parent (%s) for (%s)R2iN(R R RR3R4R/(R RR5((s1/usr/lib/python2.7/site-packages/suds/resolver.pytgetchild&s( RRRR RBRGRIRJRLRM(((s1/usr/lib/python2.7/site-packages/suds/resolver.pyR?Ýs     t NodeResolvercBsDeZdZd„Zeed„Zed„Zd„Zd„Z RS(sÉ The node resolver is a I{stateful} XML document resolver used to resolve each node in a tree. As such, it mirrors the tree structure to ensure that nodes are resolved in context. cCstj||ƒdS(s\ @param schema: A schema object. @type schema: L{xsd.schema.Schema} N(R?R (R R ((s1/usr/lib/python2.7/site-packages/suds/resolver.pyR 7sc Cs¿|j}|jƒj}|dkr?|j||ƒ\}}n|j||ƒ\}}|j|ƒ}|dkrv|S|r¦t|d|d|ƒ} |j| ƒ} n|r»|j ƒ}n|S(sÁ @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} @rtype: L{xsd.sxbase.SchemaObject} RR1N( RRIRRRRMtknownRDRGR( R tnodeRRGRR5RR1RORFtpushed((s1/usr/lib/python2.7/site-packages/suds/resolver.pyR>s   cCsd|}|jƒj}|dkr@|j|tƒ\}}n|j||ƒ\}}|dkrh|S|r}|jƒ}n|S(sX 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} s@%sN(RIRRRRPRMR(R RRR5RR1((s1/usr/lib/python2.7/site-packages/suds/resolver.pytfindattr[s   cCsPtjd|ƒt|||jƒƒ}t|ƒ}|j|jƒ}|gfS(s" blindly query the schema by name ssearching schema for (%s)(R R Rt namespaceRRR (R RRPRRR((s1/usr/lib/python2.7/site-packages/suds/resolver.pyRrs  cCsY|jdtjƒ}|dkr%dSt|||jƒƒ}t|ƒ}|j|jƒS(s& resolve type referenced by @xsi:type ttypeN( tgetRtxsinsRRRSRRR (R RPtrefRR((s1/usr/lib/python2.7/site-packages/suds/resolver.pyROzs   ( RRRR tFalseRRRRRRO(((s1/usr/lib/python2.7/site-packages/suds/resolver.pyRN/s    t GraphResolvercBsAeZdZd„Zeed„Zd„Zd„Zd„Z RS(sÍ The graph resolver is a I{stateful} L{Object} graph resolver used to resolve each node in a tree. As such, it mirrors the tree structure to ensure that nodes are resolved in context. cCstj||ƒdS(s\ @param schema: A schema object. @type schema: L{xsd.schema.Schema} N(R?R (R R ((s1/usr/lib/python2.7/site-packages/suds/resolver.pyR Œsc Csàd}|jƒj}|dkr9|j|ƒ\}}n|j||ƒ\}}|dkradSt|tƒr‚|j|ƒ}n|r²t|d|d|ƒ} |j | ƒ} n|rÜ|dkrÓ|j ƒ}qÜ|}n|S(s @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 stack. @type push: boolean @return: The found schema I{type} @rtype: L{xsd.sxbase.SchemaObject} RR1N( RRIRRRMRCRRORDRGR( R RtobjectRRGROR5RR1RFRQ((s1/usr/lib/python2.7/site-packages/suds/resolver.pyR“s"    cCs‰tjd|ƒ|j}|jƒ}|dkrLt||j|jƒ}nt||j|jƒ}t|ƒ}|j |ƒ}|gfS(s" blindly query the schema by name ssearching schema for (%s)N( R R R R!RRRRRR(R RR R!RRR((s1/usr/lib/python2.7/site-packages/suds/resolver.pyR¶s    cCs'|jj}|dkrdS|jSdS(s get the wsdl N(R t containerRR!(R R[((s1/usr/lib/python2.7/site-packages/suds/resolver.pyR!Ãs  cCs(y|j}|j}|SWnnXdS(s1 get the type specified in the object's metadata N(t __metadata__tsxtype(R RZtmdRO((s1/usr/lib/python2.7/site-packages/suds/resolver.pyROËs   ( RRRR RXRRRR!RO(((s1/usr/lib/python2.7/site-packages/suds/resolver.pyRY„s  # RDcBs3eZddd„Zd„Zddd„ƒYZRS(cCs@||_|dkr$|jƒ}n|jƒ|_||_dS(N(RTRRRR1(R RTRR1((s1/usr/lib/python2.7/site-packages/suds/resolver.pyR Ös   cCs?dt|jƒt|jƒg|jD]}t|ƒ^q%fS(Ns%s %s %s(RRTRR1(R tt((s1/usr/lib/python2.7/site-packages/suds/resolver.pyt__str__Ýs  RHcBseZd„ZRS(cCs|dkrdSdSdS(NR1((R(R R((s1/usr/lib/python2.7/site-packages/suds/resolver.pyt __getattr__äs (RRRa(((s1/usr/lib/python2.7/site-packages/suds/resolver.pyRHãsN(((RRRR R`RH(((s1/usr/lib/python2.7/site-packages/suds/resolver.pyRDÕs R@cBseZd„ZRS(cCs7g}x!|D]}|jt|ƒƒq Wdj|ƒS(Ns (R:treprtjoin(R Rtitem((s1/usr/lib/python2.7/site-packages/suds/resolver.pyt__repr__ìs (RRRe(((s1/usr/lib/python2.7/site-packages/suds/resolver.pyR@ës(((RR"tloggingRtsudstsuds.saxRRtsuds.sudsobjectRtsuds.xsd.queryRRRRR RRR?RNRYRDtlistR@(((s1/usr/lib/python2.7/site-packages/suds/resolver.pyts   &—RUQ