Ñò
—ã=Pc           @   sb   d  Z  d d k l Z d d k Td d k i Z d d k l Z e e ƒ Z	 d d d „  ƒ  YZ
 d S(	   sK   
The I{service definition} provides a textual representation of a service.
iÿÿÿÿ(   t	   getLogger(   t   *N(   t	   Namespacet   ServiceDefinitionc           B   sƒ   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   sý  
    A service definition provides an object used to generate a textual description
    of a service.
    @ivar wsdl: A wsdl.
    @type wsdl: L{wsdl.Definitions}
    @ivar service: The service object.
    @type service: L{suds.wsdl.Service}
    @ivar ports: A list of port-tuple: (port, [(method-name, pdef)])
    @type ports: [port-tuple,..]
    @ivar prefixes: A list of remapped prefixes.
    @type prefixes: [(prefix,uri),..]
    @ivar types: A list of type definitions
    @type types: [I{Type},..] 
    c         C   sl   | |  _  | |  _ g  |  _ g  |  _ g  |  _ g  |  _ |  i ƒ  |  i ƒ  |  i ƒ  |  i	 ƒ  |  i
 ƒ  d S(   s•   
        @param wsdl: A wsdl object
        @type wsdl: L{Definitions}
        @param service: A service B{name}.
        @type service: str
        N(   t   wsdlt   servicet   portst   paramst   typest   prefixest   addportst
   paramtypest   publictypest   getprefixest   pushprefixes(   t   selfR   R   (    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyt   __init__,   s    						



c         C   s6   x/ |  i  D]$ } |  i i i | d | d ƒ q
 Wd S(   s   
        Add our prefixes to the wsdl so that when users invoke methods
        and reference the prefixes, the will resolve properly.
        i    i   N(   R	   R   t   roott	   addPrefix(   R   t   ns(    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR   ?   s    
 c         C   sÙ   t  i ƒ  } | i ƒ  x² |  i i D]¤ } |  i | ƒ } x~ | i i i ƒ  D]j } | d i	 | i
 ƒ } | i i } | i
 | i | ƒ f } | d i | ƒ t  i i d | i
 | ƒ qK W| d i ƒ  q# W| i ƒ  d S(   s"  
        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).
        i    i   s   method '%s' created: %sN(   t   metricst   Timert   startR   R   t   findportt   bindingt
   operationst   valuest   methodt   namet   inputt
   param_defst   appendt   logt   debugt   sortt   stop(   R   t   timert   portt   pt   opt   mR   R   (    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR
   G   s    
  c         C   sJ   x' |  i  D] } | d | j o | Sq
 W| g  f } |  i  i | ƒ | S(   sñ   
        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])
        i    (   R   R   (   R   R%   R&   (    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR   [   s    	
  	c   	      C   s\  g  } x|  i  |  i f D]ò } xé | D]á \ } } | i ƒ  } | d d j o q& n | d | j o q& n t i | ƒ p t i | ƒ o q& n | i | d ƒ | | j o q& n | i ƒ  } | d d j o q& n | d | j o q& n | i | d ƒ q& Wq Wd } | i ƒ  x6 | D]. } |  i	 ƒ  } | | f } |  i
 i | ƒ q&Wd S(   sO   
        Add prefixes foreach namespace referenced by parameter types.
        i   i    N(   R   R   t	   namespacet   NoneR   t   xst   xsdR   R"   t
   nextprefixR	   (	   R   t
   namespacest   lt   tt   rR   t   it   uR&   (    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR   j   s8            
 c      
   C   s½   x¶ g  } |  i  D] } | | d q ~ D]Œ } xƒ g  } | D] } | | d q= ~ D]\ } xS | D]K } | d |  i j o qb n | d | d i ƒ  f } |  i i | ƒ qb WqU Wq) Wd S(   s    get all parameter types i   N(   R   R   t   resolveR   (   R   t   _[1]R&   R(   t   _[2]t   pdt   item(    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR   ƒ   s    ) &   c         C   sŠ   xg |  i  i i i ƒ  D]P } | |  i j o q n | |  i j o q n | | f } |  i i | ƒ q Wd „  } |  i i d | ƒ d S(   s    get all public types c         S   s   t  |  d  i | d  i ƒ S(   i    (   t   cmpR   (   t   xt   y(    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyt   <lambda>“   s    R9   N(   R   t   schemaR   R   R   R   R"   (   R   R0   R8   t   tc(    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR   Œ   s       	c         C   s¦   g  } |  i  D] } | | d q ~ } | g  } |  i i i i ƒ  D] } | | d qE ~ 7} x3 t d d ƒ D]" } d | } | | j o | Sqp Wt d ƒ ‚ d S(   sÃ   
        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.
        i    i   s   ns%ds   prefixes exhaustedN(   R	   R   R   t
   nsprefixest   itemst   ranget	   Exception(   R   R5   R   t   usedR6   t   nR&   (    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR-   –   s    (8 
	c         C   sp   x+ t  i D]  } | | d j o	 | d Sq
 Wx+ |  i D]  } | | d j o	 | d Sq8 Wt d | ƒ ‚ d S(   s¸   
        Get the prefix for the specified namespace (uri)
        @param u: A namespace uri.
        @type u: str
        @return: The namspace.
        @rtype: (prefix, uri).
        i   i    s   ns (%s) not mappedN(   R   t   allR	   RB   (   R   R3   R   (    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyt	   getprefix¤   s    
  
  c         C   s‚   | i  ƒ  } | i } | i ƒ  o | d 7} n | i ƒ  } | d |  i i d j o | S|  i | d ƒ } d i | | f ƒ S(   sò   
        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
        s   []i   t   :(   R4   R   t	   unboundedR)   R   t   tnsRF   t   join(   R   t   typet   resolvedR   R   t   prefix(    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyt   xlate²   s    	c         C   s”  g  } d „  } | i  d |  i i |  i i d f ƒ | i  | d ƒ ƒ | i  d t |  i ƒ ƒ x5 |  i D]* } | i  | d ƒ ƒ | i  d | ƒ qm W| i  | d ƒ ƒ | i  d t |  i ƒ ƒ x¯|  i D]¤} | i  | d ƒ ƒ | i  d | d	 i ƒ | i  | d
 ƒ ƒ | i  d t | d ƒ ƒ xÔ | d D]È } g  } | i  | d ƒ ƒ | i  | d	 ƒ | i  d ƒ xW | d D]K } | i  |  i | d ƒ ƒ | i  d ƒ | i  | d	 ƒ | i  d ƒ q„W| i  d ƒ y | i  d i	 | ƒ ƒ Wq<q<Xq<W| i  | d
 ƒ ƒ | i  d t |  i
 ƒ ƒ x> |  i
 D]3 } | i  | d ƒ ƒ | i  |  i | d	 ƒ ƒ q?WqÒ W| i  d ƒ d i	 | ƒ S(   s˜   
        Get a textual description of the service for which this object represents.
        @return: A textual description.
        @rtype: str
        c         S   s   d  |  d d f S(   s   
%*si   t    (    (   RD   (    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR<   Ë   s    s   Service ( %s ) tns="%s"i   s   Prefixes (%d)i   s	   %s = "%s"s   Ports (%d):s   (%s)i    i   s   Methods (%d):i   t   (RO   s   , t   )t    s   Types (%d):s   

(   R   R   R   R   RI   t   lenR	   R   RN   RJ   R   (   R   t   st   indentR&   R(   t   sigR0   (    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyt   descriptionÄ   sT    	'
 
   
 "c         C   s   t  |  ƒ i d ƒ S(   Ns   utf-8(   t   unicodet   encode(   R   (    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyt   __str__ð   s    c         C   s=   y |  i  ƒ  SWn" t j
 o } t i | ƒ n Xt | ƒ S(   N(   RW   RB   R    t	   exceptiont   tostr(   R   t   e(    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyt   __unicode__ó   s
    (   t   __name__t
   __module__t   __doc__R   R   R
   R   R   R   R   R-   RF   RN   RW   RZ   R^   (    (    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR      s   								
				,	(    (   Ra   t   loggingR    t   sudst   suds.metricsR   t   suds.saxR   R_   R    R   (    (    (    sU   /usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/servicedefinition.pyt   <module>   s   
