ó
[³XMc           @   s  d  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	 „  ƒ  YZ d
 d d „  ƒ  YZ d d d „  ƒ  YZ d d d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e j f d „  ƒ  YZ d „  Z d S(   s   
Utility classes for spread.
iÿÿÿÿ(   t   defer(   t   Failure(   t   pb(   t   basic(   t
   interfaces(   t
   implementst   LocalMethodc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | |  _  | |  _ d  S(   N(   t   localt   name(   t   selfR   R   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyt   __init__   s    	c         O   s   |  j  j |  j | | Ž S(   N(   R   t
   callRemoteR   (   R	   t   argst   kw(    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyt   __call__   s    (   t   __name__t
   __module__R
   R   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyR      s   	t   LocalAsRemotec           B   s&   e  Z d  Z d Z d „  Z d „  Z RS(   sN   
    A class useful for emulating the effects of remote behavior locally.
    i   c         O   s‘   t  |  d | ƒ r- t |  d | ƒ | | Ž  Sy- t |  d | ƒ } t j | | | Ž  ƒ SWn0 t ƒ  } |  j r | j ƒ  n  t j | ƒ SXd S(   sx  
        Call a specially-designated local method.

        self.callRemote('x') will first try to invoke a method named
        sync_x and return its result (which should probably be a
        Deferred).  Second, it will look for a method called async_x,
        which will be called and then have its result (or Failure)
        automatically wrapped in a Deferred.
        t   sync_t   async_N(   t   hasattrt   getattrR    t   succeedR   t   reportAllTracebackst   printTracebackt   fail(   R	   R   R   R   t   methodt   f(    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyR   #   s    
		c         C   s   t  |  | ƒ S(   N(   R   (   R	   R   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyt   remoteMethod8   s    (   R   R   t   __doc__R   R   R   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyR      s   	t   LocalAsyncForwarderc           B   s,   e  Z d  Z d d „ Z d „  Z d „  Z RS(   sD   
    A class useful for forwarding a locally-defined interface.
    i    c         C   s4   | j  | ƒ s t ‚ | |  _ | |  _ | |  _ d  S(   N(   t
   providedByt   AssertionErrort	   forwardedt   interfaceClasst   failWhenNotImplemented(   R	   R!   R"   R#   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyR
   A   s    		c         O   s   t  |  j | ƒ | | Ž  S(   N(   R   R!   (   R	   R   R   R   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyt   _callMethodG   s    c         O   se   |  j  j | ƒ r1 t j |  j | | | Ž } | S|  j rT t j t t d | ƒ ƒ St j	 d  ƒ Sd  S(   Ns   No Such Method in Interface: %s(   R"   t   queryDescriptionForR    t   maybeDeferredR$   R#   R   R   t   NotImplementedErrorR   t   None(   R	   R   R   R   t   result(    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyR   J   s    	(   R   R   R   R
   R$   R   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyR   <   s   	t   Pagerc           B   s>   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z RS(   s5   
    I am an object which pages out information.
    c         O   sY   t  | ƒ r* | |  _ | |  _ | |  _ n	 d |  _ d |  _ | |  _ | j j |  ƒ d S(   sƒ   
        Create a pager with a Reference to a remote collector and
        an optional callable to invoke upon completion.
        i   N(	   t   callablet   callbackt   callbackArgst   callbackKeywordR(   t   _stillPagingt	   collectort   brokert   registerPageProducer(   R	   R0   R,   R   R   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyR
   Z   s    					c         C   sK   |  j  sD |  j j d ƒ |  j d k	 rD |  j |  j |  j Ž  qD n  |  j  S(   s5   
        (internal) Method called by Broker.
        t   endedPagingN(   R/   R0   R   R,   R(   R-   R.   (   R	   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyt   stillPagingi   s
    	c         C   s   |  j  j d |  j ƒ  ƒ d S(   s5   
        (internal) Method called by Broker.
        t   gotPageN(   R0   R   t   nextPage(   R	   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyt   sendNextPages   s    c         C   s   t  ƒ  ‚ d S(   sO   
        Override this to return an object to be sent to my collector.
        N(   R'   (   R	   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyR6   y   s    c         C   s   d |  _  d S(   s4   
        Call this when you're done paging.
        i    N(   R/   (   R	   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyt
   stopPaging   s    N(	   R   R   R   R(   R
   R4   R7   R6   R8   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyR*   V   s   	
		t   StringPagerc           B   s&   e  Z d  Z d d d „ Z d „  Z RS(   s:   
    A simple pager that splits a string into chunks.
    i    c         O   s8   | |  _  d |  _ | |  _ t j |  | | | | Ž d  S(   Ni    (   t   stringt   pointert	   chunkSizeR*   R
   (   R	   R0   t   stR<   R,   R   R   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyR
   Š   s    			c         C   sX   |  j  |  j |  j |  j !} |  j |  j 7_ |  j t |  j  ƒ k rT |  j ƒ  n  | S(   N(   R:   R;   R<   t   lenR8   (   R	   t   val(    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyR6      s
    N(   R   R   R   R(   R
   R6   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyR9   †   s   t	   FilePagerc           B   sT   e  Z d  Z e e j ƒ d d „ Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z RS(   sC   
    Reads a file in chunks and sends the chunks as they come.
    c         O   s3   g  |  _  t j |  | | | | Ž |  j | ƒ d  S(   N(   t   chunksR*   R
   t   startProducing(   R	   R0   t   fdR,   R   R   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyR
   ž   s    	c            s8   t  j ƒ  j | ˆ  ƒ ˆ  _ ˆ  j j ‡  f d †  ƒ d  S(   Nc            s
   ˆ  j  ƒ  S(   N(   R8   (   t   x(   R	   (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyt   <lambda>¥   s    (   R   t
   FileSendert   beginFileTransfert   deferredt   addBoth(   R	   RC   (    (   R	   s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyRB   £   s    c         C   s#   | |  _  | s |  j  j ƒ  n  d  S(   N(   t   producert   resumeProducing(   R	   RJ   t	   streaming(    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyt   registerProducer§   s    	c         C   s   d  |  _ d  S(   N(   R(   RJ   (   R	   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyt   unregisterProducer¬   s    c         C   s   |  j  j | ƒ d  S(   N(   RA   t   append(   R	   t   chunk(    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyt   write¯   s    c         C   sC   |  j  s d S|  j  j d ƒ } |  j j ƒ  |  j j d | ƒ d S(   sD   
        Get the first chunk read and send it to collector.
        Ni    R5   (   RA   t   popRJ   RK   R0   R   (   R	   R?   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyR7   ²   s
    	N(   R   R   R   R   R   t	   IConsumerR(   R
   RB   RM   RN   RQ   R7   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyR@   ˜   s   				t   CallbackPageCollectorc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sµ   
    I receive pages from the peer. You may instantiate a Pager with a
    remote reference to me. I will call the callback with a list of pages
    once they are all received.
    c         C   s   g  |  _  | |  _ d  S(   N(   t   pagesR,   (   R	   R,   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyR
   Ä   s    	c         C   s   |  j  j | ƒ d  S(   N(   RU   RO   (   R	   t   page(    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyt   remote_gotPageÈ   s    c         C   s   |  j  |  j ƒ d  S(   N(   R,   RU   (   R	   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyt   remote_endedPagingË   s    (   R   R   R   R
   RW   RX   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyRT   ¾   s   		c         O   s/   t  j ƒ  } |  j | t | j ƒ | | Ž | S(   sr   
    A utility method that will call a remote method which expects a
    PageCollector as the first argument.
    (   R    t   DeferredR   RT   R,   (   t   referenceablet
   methodNameR   R   t   d(    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyt   getAllPagesÏ   s    N(    (    (    (    (   R   t   twisted.internetR    t   twisted.python.failureR   t   twisted.spreadR   t   twisted.protocolsR   R   t   zope.interfaceR   R   R   R   R*   R9   R@   t   ReferenceableRT   R]   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/spread/util.pyt   <module>	   s   	0&