ó
P'—^c           @@ s˜  d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l Z d d l Z d d l	 m
 Z
 d d l m Z d d l m Z d d l m Z d d l m Z d d	 l m Z d d
 l m Z d d d d g Z i e e 6Z d j ƒ  Z d Z e
 e d e j ƒZ d e  f d „  ƒ  YZ! d „  Z" d „  Z# d e j$ f d „  ƒ  YZ% d e  f d „  ƒ  YZ& d e f d „  ƒ  YZ' d „  Z( e) d k r”e( ƒ  n  d S(   u@   
The :program:`celery amqp` command.

.. program:: celery amqp

i    (   t   absolute_importt   print_functiont   unicode_literalsN(   t   partial(   t   count(   t   safe_str(   t   padlist(   t   Command(   t   string_t(   t	   strtoboolu	   AMQPAdminu   AMQShellu   Specu   amqpu   
Commands
--------
u-   
Example:
    -> queue.delete myqueue yes no
t   filet   Specc           B@ sG   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z	 RS(   uþ  AMQP Command specification.

    Used to convert arguments to Python values and display various help
    and tooltips.

    :param args: see :attr:`args`.
    :keyword returns: see :attr:`returns`.

    .. attribute args::

        List of arguments this command takes. Should
        contain `(argument_name, argument_type)` tuples.

    .. attribute returns:

        Helpful human string representation of what this command returns.
        May be :const:`None`, to signify the return type is unknown.

    c         O@ s   | |  _  | j d ƒ |  _ d  S(   Nu   returns(   t   argst   gett   returns(   t   selfR   t   kwargs(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   __init__@   s    	c         C@ s-   |  j  | } | d } t j | | ƒ | ƒ S(   u#   Coerce value for argument at index.i   (   R   t   COERCER   (   R   t   indext   valuet   arg_infot   arg_type(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   coerceD   s    
c         @ s    t  ‡  f d †  t | ƒ Dƒ ƒ S(   uî   Process list of string arguments to values according to spec.

        e.g:

            >>> spec = Spec([('queue', str), ('if_unused', bool)])
            >>> spec.str_args_to_python('pobox', 'true')
            ('pobox', True)

        c         3@ s'   |  ] \ } } ˆ  j  | | ƒ Vq d  S(   N(   R   (   t   .0R   R   (   R   (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pys	   <genexpr>W   s    (   t   tuplet	   enumerate(   R   t   arglist(    (   R   s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   str_args_to_pythonL   s    
c         C@ sI   |  j  s | d k r d S| St |  j  ƒ r9 |  j  | ƒ S|  j  j | ƒ S(   u@   Format the return value of this command in a human-friendly way.u   ok.N(   R   t   Nonet   callablet   format(   R   t   response(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   format_responseY   s
    	c         C@ s    | d  k	 r d j | | ƒ S| S(   Nu   {0}:{1}(   R   R   (   R   t   namet   typet   default_value(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt
   format_arga   s    c         @ s    d j  ‡  f d †  ˆ  j Dƒ ƒ S(   Nu    c         3@ s-   |  ]# } ˆ  j  t t | ƒ d  ƒ Œ  Vq d S(   i   N(   R%   R   t   list(   R   t   arg(   R   (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pys	   <genexpr>g   s   (   t   joinR   (   R   (    (   R   s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   format_signaturef   s    N(
   t   __name__t
   __module__t   __doc__R   R   R   R!   R   R%   R)   (    (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyR   ,   s   				c         C@ s2   |  d  k r d Si |  j d 6|  j d 6|  j d 6S(   Nu.   No messages in queue. basic.publish something.u   bodyu
   propertiesu   delivery_info(   R   t   bodyt
   propertiest   delivery_info(   t   message(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   dump_messagek   s
    
c         C@ s   d j  |  Œ  S(   Nu)   ok. queue:{0} messages:{1} consumers:{2}.(   R   (   t   ret(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   format_declare_queues   s    t   AMQShellc        
   B@ s  e  Z d  Z d8 Z d8 Z d Z d Z e _	 e
 Z d Z e d ƒ Z i d d 6d d 6d d	 6Z i	 e d
 e f d e f d e d f d e d f d e d f d e d f ƒ d 6e d
 e f d e f ƒ d 6e d e f d
 e f d e f ƒ d 6e d e f d e d f d e d f d e d f d e d f d e ƒd 6e d e f d e d f d e d f d d ƒd 6e d e f d d ƒd 6e d e f d e d f d e ƒd  6e d! e f d
 e f d e f d" e d f d# e d f ƒ d$ 6e d% e f ƒ d& 6Z d' „  Z d( „  Z d) „  Z d* „  Z d+ „  Z d, „  Z e
 d- „ Z d. „  Z d/ „  Z d0 „  Z  d1 „  Z! d2 „  Z" d3 „  Z# d4 „  Z$ d5 „  Z% d6 „  Z& e' d7 „  ƒ Z( RS(9   u½  AMQP API Shell.

    :keyword connect: Function used to connect to the server, must return
        connection object.

    :keyword silent: If :const:`True`, the commands won't have annoying
                     output not relevant when running in non-shell mode.


    .. attribute: builtins

        Mapping of built-in command names -> method names

    .. attribute:: amqp

        Mapping of AMQP API commands and their :class:`Spec`.

    u   {self.counter}> u   .i   i   u   do_exitu   EOFu   exitu   do_helpu   helpu   exchangeu   typeu   passiveu   nou   durableu   auto_deleteu   internalu   exchange.declareu	   if_unusedu   exchange.deleteu   queueu   routing_keyu
   queue.bindu	   exclusiveR   u   queue.declareu   if_emptyu   ok. {0} messages deleted.u   queue.deleteu   queue.purgeu   no_acku   offu	   basic.getu   msgu	   mandatoryu	   immediateu   basic.publishu   delivery_tagu	   basic.ackc         C@ sr   d d l  m } m } t | j | ƒ rn t d | f d t f d t f d t d f d t d f ƒ |  j  d	 <n  d  S(
   Ni    (   t
   Connectiont   Messageu   msgu   exchangeu   routing_keyu	   mandatoryu   nou	   immediateu   basic.publish(   t   amqpR5   R6   t
   isinstancet
   connectionR   t   strt   bool(   R   t   connR5   R6   (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   _prepare_spec¹   s    		c         O@ sc   | j  d ƒ |  _ | j  d t ƒ |  _ | j  d t j ƒ |  _ t j j	 |  | | Ž |  j
 ƒ  d  S(   Nu   connectu   silentu   out(   t   popt   connectt   Falset   silentt   syst   stderrt   outt   cmdt   CmdR   t
   _reconnect(   R   R   R   (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyR   Ã   s
    c         C@ s#   |  j  s t | d |  j ƒn  d S(   u6   Say something to the user. Disabled if :attr:`silent`.R
   N(   RA   t   sayRD   (   R   t   m(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   noteÊ   s    	c         C@ s   t  | d |  j ƒd  S(   NR
   (   RH   RD   (   R   RI   (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyRH   Ï   s    c         C@ s`   |  j  | } | j | ƒ } | j d d ƒ } |  j rD |  j ƒ  n  t |  j | ƒ | | j f S(   uã   With a command name and a list of arguments, convert the arguments
        to Python values and find the corresponding method on the AMQP channel
        object.

        :returns: tuple of `(method, processed_args)`.

        u   .u   _(   R7   R   t   replacet   needs_reconnectRG   t   getattrt   chanR!   (   R   RE   R   t   specR   t	   attr_name(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   get_amqp_api_commandÒ   s    	c         G@ s   |  j  d ƒ t j d ƒ d S(   u   The `'exit'` command.u   
-> please, don't leave!i    N(   RJ   RB   t   exit(   R   R   (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   do_exitá   s    c         C@ s0   |  j  | } |  j d j | | j ƒ  ƒ ƒ d  S(   Nu   {0} {1}(   R7   RH   R   R)   (   R   RE   t   shortRO   (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   display_command_helpæ   s    c         G@ s_   | sJ |  j  t ƒ x$ |  j D] } |  j | d t ƒq W|  j  t ƒ n |  j | d ƒ d  S(   NRT   i    (   RH   t   HELP_HEADERR7   RU   t   Truet   EXAMPLE_TEXT(   R   R   t   cmd_name(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   do_helpê   s    c         C@ s   |  j  d j | ƒ ƒ d  S(   Nu-   unknown syntax: {0!r}. how about some 'help'?(   RH   R   (   R   t   line(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   defaultó   s    c         C@ s   t  |  j ƒ t  |  j ƒ BS(   N(   t   sett   builtinsR7   (   R   (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt	   get_namesö   s    c         G@ s}   |  j  ƒ  } g  | D]' } | j | j d d ƒ ƒ r | ^ q } | rJ | Sg  | D]( } | j d ƒ d j | ƒ rQ | ^ qQ S(   u=   Return all commands starting with `text`, for tab-completion.u   _u   .i   (   R_   t
   startswithRK   t	   partition(   R   t   textt   ignoredt   namesRE   t   first(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   completenamesù   s    'c         C@ si   t  j t | ƒ ƒ } | |  j k r> t |  |  j | ƒ | Œ  S|  j | | ƒ \ } } } | | | Œ  ƒ S(   ug   Dispatch and execute the command.

        Lookup order is: :attr:`builtins` -> :attr:`amqp`.

        (   t   shlext   splitR   R^   RM   RQ   (   R   RE   t   arglineR   t   funR   t	   formatter(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   dispatch  s
    c         C@ s=   | j  ƒ  } | r0 | d d j | d ƒ | f Sd d | f S(   uy   Parse input line.

        :returns: tuple of three items:
            `(command_name, arglist, original_line)`

        i    u    i   u    (   Rh   R(   (   R   R[   t   parts(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt	   parseline  s    c         C@ sµ   |  j  | ƒ \ } } } | s( |  j ƒ  S| |  _ t |  j ƒ |  _ y |  j |  j | | ƒ ƒ WnN t t	 f k
 rˆ } |  j
 | ƒ n) t k
 r° } |  j | ƒ t |  _ n Xd S(   u   Parse line and execute command.N(   Rn   t	   emptylinet   lastcmdt   nextt   inc_countert   countert   respondRl   t   AttributeErrort   KeyErrorR\   t	   ExceptionRH   RW   RL   (   R   R[   RE   R'   t   exc(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   onecmd  s    
	c         C@ sH   | d k	 rD t | t ƒ r+ |  j | ƒ qD |  j t j | ƒ ƒ n  d S(   u.   What to do with the return value of a command.N(   R   R8   R   RH   t   pprintt   pformat(   R   t   retval(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyRt   *  s    c         C@ sA   |  j  |  j ƒ |  _ |  j |  j ƒ |  j j |  _ t |  _ d S(   u+   Re-establish connection to the AMQP server.N(   R?   R<   R=   t   default_channelRN   R@   RL   (   R   (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyRG   2  s    c         C@ s   |  j  j d |  ƒ S(   NR   (   t
   prompt_fmtR   (   R   (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   prompt9  s    N()   R*   R+   R,   R   R<   RN   R~   t
   identcharsRE   t
   IDENTCHARSR@   RL   Rs   R   Rr   R^   R   R:   R;   R3   R1   t   intR7   R=   R   RJ   RH   RQ   RS   RU   RZ   R\   R_   Rf   Rl   Rn   Ry   Rt   RG   t   propertyR   (    (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyR4   w   sz   

		



			
										
					t	   AMQPAdminc           B@ s;   e  Z d  Z e Z d „  Z d d „ Z d „  Z d „  Z	 RS(   u*   The celery :program:`celery amqp` utility.c         O@ sD   | d |  _  | j d t j ƒ |  _ | j d ƒ |  _ | |  _ d  S(   Nu   appu   outu   silent(   t   appt
   setdefaultRB   RC   RD   R   RA   R   (   R   R   R   (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyR   B  s    c         C@ sY   | r | j  ƒ  n  |  j j ƒ  } |  j d j | j ƒ  ƒ ƒ | j ƒ  |  j d ƒ | S(   Nu   -> connecting to {0}.u   -> connected.(   t   closeR…   R9   RJ   R   t   as_uriR?   (   R   R<   (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyR?   H  s    
c         C@ ss   |  j  d |  j d |  j ƒ } |  j r@ | j d j |  j ƒ ƒ Sy | j ƒ  SWn t k
 rn |  j d ƒ n Xd  S(   NR?   RD   u    u   (bibi)(	   t   ShellR?   RD   R   Ry   R(   t   cmdloopt   KeyboardInterruptRJ   (   R   t   shell(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   runQ  s    	c         C@ s#   |  j  s t | d |  j ƒn  d  S(   NR
   (   RA   RH   RD   (   R   RI   (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyRJ   [  s    	N(
   R*   R+   R,   R4   R‰   R   R   R?   R   RJ   (    (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyR„   >  s   			
R7   c           B@ s   e  Z d  Z d „  Z RS(   u{  AMQP Administration Shell.

    Also works for non-amqp transports (but not ones that
    store declarations in memory).

    Examples::

        celery amqp
            start shell mode
        celery amqp help
            show list of commands

        celery amqp exchange.delete name
        celery amqp queue.delete queue
        celery amqp queue.delete queue yes yes

    c         O@ s    |  j  | d <t | | Ž  j ƒ  S(   Nu   app(   R…   R„   R   (   R   R   t   options(    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyR   s  s    (   R*   R+   R,   R   (    (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyR7   `  s   c           C@ s   t  ƒ  j ƒ  d  S(   N(   R7   t   execute_from_commandline(    (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   mainx  s    u   __main__(*   R,   t
   __future__R    R   R   RE   RB   Rg   Rz   t	   functoolsR   t	   itertoolsR   t   kombu.utils.encodingR   t   celery.utils.functionalR   t   celery.bin.baseR   t   celery.fiveR   t   celery.utilsR	   t   __all__R;   R   t   rstripRV   RX   t   printRC   RH   t   objectR   R1   R3   RF   R4   R„   R7   R   R*   (    (    (    s1   /tmp/pip-unpacked-wheel-gV1wwp/celery/bin/amqp.pyt   <module>   s4   ?		Ç"	