ó
—ã=Pc           @   sb   d  Z  d d l m Z d d l Td d l j Z d d l m 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  |  _ |  j ƒ  |  j ƒ  |  j ƒ  |  j	 ƒ  |  j
 ƒ  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   (    (    s.   suds-0.3.7-py2.6.egg/suds/servicedefinition.pyt   __init__,   s    						



c         C   s6   x/ |  j  D]$ } |  j j j | 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(    (    s.   suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR   ?   s    c         C   sÙ   t  j ƒ  } | j ƒ  x² |  j j D]¤ } |  j | ƒ } x~ | j j j ƒ  D]j } | d j	 | j
 ƒ } | j j } | j
 | j | ƒ f } | d j | ƒ t  j j d | j
 | ƒ qK W| d j ƒ  q# W| j ƒ  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   (    (    s.   suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR
   G   s    
c         C   sH   x% |  j  D] } | d | k r
 | Sq
 W| g  f } |  j  j | ƒ | 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&   (    (    s.   suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR   [   s    	 c   	      C   sO  g  } xù |  j  |  j f D]å } xÜ | D]Ô \ } } | j ƒ  } | d d k rT q& n  | d | k rj q& n  t j | ƒ s& t j | ƒ rŽ q& n  | j | d ƒ | | k r± q& n  | j ƒ  } | d d k rÓ q& n  | d | k ré q& n  | j | d ƒ q& Wq Wd } | j ƒ  x6 | D]. } |  j	 ƒ  } | | f } |  j
 j | ƒ 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&   (    (    s.   suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR   j   s2         
c         C   s«   x¤ g  |  j  D] } | d ^ q D]‚ } xy g  | D] } | d ^ q1 D]Z } xQ | D]I } | d |  j k rq qR n  | d | d j ƒ  f } |  j j | ƒ qR WqE Wq! Wd S(   s    get all parameter types i   N(   R   R   t   resolveR   (   R   R&   R(   t   pdt   item(    (    s.   suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR   ƒ   s    '$ c         C   s†   xc |  j  j j j ƒ  D]L } | |  j k r1 q n  | |  j k rF q n  | | f } |  j j | ƒ q Wd „  } |  j j d | ƒ d S(   s    get all public types c         S   s   t  |  d j | d j ƒ S(   Ni    (   t   cmpR   (   t   xt   y(    (    s.   suds-0.3.7-py2.6.egg/suds/servicedefinition.pyt   <lambda>“   s    R7   N(   R   t   schemaR   R   R   R   R"   (   R   R0   R6   t   tc(    (    s.   suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR   Œ   s      	c         C   s”   g  |  j  D] } | d ^ q
 } | g  |  j j j j ƒ  D] } | d ^ q9 7} x1 t d d ƒ D]  } d | } | | k r` | Sq` 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   R   t   usedt   nR&   (    (    s.   suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR-   –   s     0
c         C   sl   x) t  j D] } | | d k r
 | d Sq
 Wx) |  j D] } | | d k r6 | d Sq6 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	   R@   (   R   R3   R   (    (    s.   suds-0.3.7-py2.6.egg/suds/servicedefinition.pyt	   getprefix¤   s      c         C   s~   | j  ƒ  } | j } | j ƒ  r. | d 7} n  | j ƒ  } | d |  j j d k rX | S|  j | d ƒ } d j | | 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   tnsRD   t   join(   R   t   typet   resolvedR   R   t   prefix(    (    s.   suds-0.3.7-py2.6.egg/suds/servicedefinition.pyt   xlate²   s    	c         C   s”  g  } d „  } | j  d |  j j |  j j d f ƒ | j  | d ƒ ƒ | j  d t |  j ƒ ƒ x5 |  j D]* } | j  | d ƒ ƒ | j  d | ƒ qm W| j  | d ƒ ƒ | j  d t |  j ƒ ƒ x¯|  j D]¤} | j  | d ƒ ƒ | j  d | d	 j ƒ | j  | d
 ƒ ƒ | j  d t | d ƒ ƒ xÔ | d D]È } g  } | j  | d ƒ ƒ | j  | d	 ƒ | j  d ƒ xW | d D]K } | j  |  j | d ƒ ƒ | j  d ƒ | j  | d	 ƒ | j  d ƒ q„W| j  d ƒ y | j  d j	 | ƒ ƒ Wq<q<Xq<W| j  | d
 ƒ ƒ | j  d t |  j
 ƒ ƒ x> |  j
 D]3 } | j  | d ƒ ƒ | j  |  j | d	 ƒ ƒ q?WqÒ W| j  d ƒ d j	 | ƒ 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(   Ns   
%*si   t    (    (   RB   (    (    s.   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   (RM   s   , t   )t    s   Types (%d):s   

(   R   R   R   R   RG   t   lenR	   R   RL   RH   R   (   R   t   st   indentR&   R(   t   sigR0   (    (    s.   suds-0.3.7-py2.6.egg/suds/servicedefinition.pyt   descriptionÄ   sJ    	'"c         C   s   t  |  ƒ j d ƒ S(   Ns   utf-8(   t   unicodet   encode(   R   (    (    s.   suds-0.3.7-py2.6.egg/suds/servicedefinition.pyt   __str__ð   s    c         C   s;   y |  j  ƒ  SWn  t k
 r0 } t j | ƒ n Xt | ƒ S(   N(   RU   R@   R    t	   exceptiont   tostr(   R   t   e(    (    s.   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-   RD   RL   RU   RX   R\   (    (    (    s.   suds-0.3.7-py2.6.egg/suds/servicedefinition.pyR      s   								
				,	(    (   R_   t   loggingR    t   sudst   suds.metricsR   t   suds.saxR   R]   R    R   (    (    (    s.   suds-0.3.7-py2.6.egg/suds/servicedefinition.pyt   <module>   s   
