

|Mc           @   s  d  Z  d d l Z d d l m Z d d l m Z m Z m Z d d l m	 Z	 m
 Z
 m Z d d% d     YZ d e f d	     YZ d
 e f d     YZ d d& d     YZ d e f d     YZ d e f d     YZ d d' d     YZ e j e
 j    Z e j   d e f d     YZ d e j f d     YZ e j e e	 j e	 j  d e j f d     YZ e j e e	 j e	 j  d e f d     YZ d d( d     YZ d e f d     YZ  d  e  f d!     YZ! d" d) d#     YZ" d d d d$ d d d" d d d d  d g Z# d S(*   s   
Standard implementations of Twisted protocol-related interfaces.

Start here if you are looking to write a new protocol implementation for
Twisted.  The Protocol class contains some introductory material.

Maintainer: Itamar Shtull-Trauring
iN(   t
   implements(   t   logt   failuret
   components(   t
   interfacest   errort   defert   Factoryc           B   sZ   e  Z d  Z e e j  d Z d Z e	 Z
 d   Z d   Z d   Z d   Z d   Z RS(   s   This is a factory which produces protocols.

    By default, buildProtocol will create a protocol of the class given in
    self.protocol.
    i    c         C   sG   |  j  s3 |  j r& t j d |   n  |  j   n  |  j  d |  _  d S(   sc   Make sure startFactory is called.

        Users should not call this function themselves!
        s   Starting factory %ri   N(   t   numPortst   noisyR   t   msgt   startFactory(   t   self(    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   doStart%   s
    		c         C   sZ   |  j  d k r d S|  j  d |  _  |  j  sV |  j rI t j d |   n  |  j   n  d S(   sb   Make sure stopFactory is called.

        Users should not call this function themselves!
        i    Ni   s   Stopping factory %r(   R   R	   R   R
   t   stopFactory(   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   doStop0   s    		c         C   s   d S(   sp  This will be called before I begin listening on a Port or Connector.

        It will only be called once, even if the factory is connected
        to multiple ports.

        This can be used to perform 'unserialization' tasks that
        are best put off until things are actually running, such
        as connecting to a database, opening files, etcetera.
        N(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR   ?   s    c         C   s   d S(   s}  This will be called before I stop listening on all Ports/Connectors.

        This can be overridden to perform 'shutdown' tasks such as disconnecting
        database connections, closing files, etc.

        It will be called, for example, before an application shuts down,
        if it was connected to a port. User code should not call this function
        directly.
        N(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR   J   s    c         C   s   |  j    } |  | _ | S(   sv  Create an instance of a subclass of Protocol.

        The returned instance will handle input on an incoming server
        connection, and an attribute "factory" pointing to the creating
        factory.

        Override this method to alter how Protocol instances get created.

        @param addr: an object implementing L{twisted.internet.interfaces.IAddress}
        (   t   protocolt   factory(   R   t   addrt   p(    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   buildProtocolU   s    	N(   t   __name__t
   __module__t   __doc__R    R   t   IProtocolFactoryt   NoneR   R   t   TrueR	   R   R   R   R   R   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR      s   				t   ClientFactoryc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   sx   A Protocol factory for clients.

    This can be used together with the various connectXXX methods in
    reactors.
    c         C   s   d S(   s   Called when a connection has been started.

        You can call connector.stopConnecting() to stop the connection attempt.

        @param connector: a Connector object.
        N(    (   R   t	   connector(    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   startedConnectingl   s    c         C   s   d S(   s   Called when a connection has failed to connect.

        It may be useful to call connector.connect() - this will reconnect.

        @type reason: L{twisted.python.failure.Failure}
        N(    (   R   R   t   reason(    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   clientConnectionFailedt   s    c         C   s   d S(   s   Called when an established connection is lost.

        It may be useful to call connector.connect() - this will reconnect.

        @type reason: L{twisted.python.failure.Failure}
        N(    (   R   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   clientConnectionLost|   s    (   R   R   R   R   R   R    (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR   e   s   		t   _InstanceFactoryc           B   sG   e  Z d  Z e Z d Z d   Z d   Z d   Z	 d   Z
 d   Z RS(   sP  
    Factory used by ClientCreator.

    @ivar deferred: The L{Deferred} which represents this connection attempt and
        which will be fired when it succeeds or fails.

    @ivar pending: After a connection attempt succeeds or fails, a delayed call
        which will fire the L{Deferred} representing this connection attempt.
    c         C   s   | |  _  | |  _ | |  _ d  S(   N(   t   reactort   instancet   deferred(   R   R"   R#   R$   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   __init__   s    		c         C   s   d |  j  f S(   Ns   <ClientCreator factory: %r>(   R#   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   __repr__   s    c         C   s:   |  j  j d |  j |  j j |  j  |  _ d |  _ |  j S(   s   
        Return the pre-constructed protocol instance and arrange to fire the
        waiting L{Deferred} to indicate success establishing the connection.
        i    N(   R"   t	   callLatert   fireR$   t   callbackR#   t   pendingR   (   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR      s    	!	c         C   s4   |  j  j d |  j |  j j |  |  _ d |  _ d S(   s   
        Arrange to fire the waiting L{Deferred} with the given failure to
        indicate the connection could not be established.
        i    N(   R"   R'   R(   R$   t   errbackR*   R   (   R   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR      s    	c         C   s   d |  _ | |  d S(   sw   
        Clear C{self.pending} to avoid a reference cycle and then invoke the
        callable with the value.
        N(   R   R*   (   R   t   callablet   value(    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR(      s    	N(   R   R   R   t   FalseR	   R   R*   R%   R&   R   R   R(   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR!      s   					
t   ClientCreatorc           B   sM   e  Z d  Z d   Z d   Z d d d  Z d e d  Z d d d  Z	 RS(   s  
    Client connections that do not require a factory.

    The various connect* methods create a protocol instance using the given
    protocol class and arguments, and connect it, returning a Deferred of the
    resulting protocol instance.

    Useful for cases when we don't really need a factory.  Mainly this
    is when there is no shared state between protocol instances, and no need
    to reconnect.

    The C{connectTCP}, C{connectUNIX}, and C{connectSSL} methods each return a
    L{Deferred} which will fire with an instance of the protocol class passed to
    L{ClientCreator.__init__}.  These Deferred can be cancelled to abort the
    connection attempt (in a very unlikely case, cancelling the Deferred may not
    prevent the protocol from being instantiated and connected to a transport;
    if this happens, it will be disconnected immediately afterwards and the
    Deferred will still errback with L{CancelledError}).
    c         O   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   R"   t   protocolClasst   argst   kwargs(   R   R"   R0   R1   R2   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR%      s    			c            sa      f d   } t  j |  } t |  j |  j |  j |  j   |    | d   | |   | S(   s3  
        Initiate a connection attempt.

        @param method: A callable which will actually start the connection
            attempt.  For example, C{reactor.connectTCP}.

        @param *args: Positional arguments to pass to C{method}, excluding the
            factory.

        @param **kwargs: Keyword arguments to pass to C{method}.

        @return: A L{Deferred} which fires with an instance of the protocol
            class passed to this L{ClientCreator}'s initializer or fails if the
            connection cannot be set up for some reason.
        c            s-     j     j d  k	 r)  j j   n  d  S(   N(   t
   disconnectR*   R   t   cancel(   R$   (   R   t   f(    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   cancelConnect   s    
R   (   R   t   DeferredR!   R"   R0   R1   R2   (   R   t   methodR1   R2   R6   t   d(    (   R5   R   s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   _connect   s    $i   c         C   s%   |  j  |  j j | | d | d | S(   s  
        Connect to a TCP server.

        The parameters are all the same as to L{IReactorTCP.connectTCP} except
        that the factory parameter is omitted.

        @return: A L{Deferred} which fires with an instance of the protocol
            class passed to this L{ClientCreator}'s initializer or fails if the
            connection cannot be set up for some reason.
        t   timeoutt   bindAddress(   R:   R"   t
   connectTCP(   R   t   hostt   portR;   R<   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR=      s    c         C   s"   |  j  |  j j | d | d | S(   s  
        Connect to a Unix socket.

        The parameters are all the same as to L{IReactorUNIX.connectUNIX} except
        that the factory parameter is omitted.

        @return: A L{Deferred} which fires with an instance of the protocol
            class passed to this L{ClientCreator}'s initializer or fails if the
            connection cannot be set up for some reason.
        R;   t   checkPID(   R:   R"   t   connectUNIX(   R   t   addressR;   R@   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRA     s    c      
   C   s+   |  j  |  j j | | d | d | d | S(   s  
        Connect to an SSL server.

        The parameters are all the same as to L{IReactorSSL.connectSSL} except
        that the factory parameter is omitted.

        @return: A L{Deferred} which fires with an instance of the protocol
            class passed to this L{ClientCreator}'s initializer or fails if the
            connection cannot be set up for some reason.
        t   contextFactoryR;   R<   (   R:   R"   t
   connectSSL(   R   R>   R?   RC   R;   R<   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRD     s    N(
   R   R   R   R%   R:   R   R=   R.   RA   RD   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR/      s   		t   ReconnectingClientFactoryc           B   s   e  Z d  Z d Z d Z d Z d Z e Z d Z d Z
 d Z d Z d Z d Z d   Z d   Z d d	  Z d
   Z d   Z d   Z RS(   s  
    Factory which auto-reconnects clients with an exponential back-off.

    Note that clients should call my resetDelay method after they have
    connected successfully.

    @ivar maxDelay: Maximum number of seconds between connection attempts.
    @ivar initialDelay: Delay for the first reconnection attempt.
    @ivar factor: A multiplicitive factor by which the delay grows
    @ivar jitter: Percentage of randomness to introduce into the delay length
        to prevent stampeding.
    @ivar clock: The clock used to schedule reconnection. It's mainly useful to
        be parametrized in tests. If the factory is serialized, this attribute
        will not be serialized, and the default value (the reactor) will be
        restored when deserialized.
    @type clock: L{IReactorTime}
    @ivar maxRetries: Maximum number of consecutive unsuccessful connection
        attempts, after which no further connection attempts will be made. If
        this is not explicitly set, no maximum is applied.
    i  g      ?giW
@gȉ4؟?i    i   c         C   s#   |  j  r | |  _ |  j   n  d  S(   N(   t   continueTryingR   t   retry(   R   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR   O  s    		c         C   s#   |  j  r | |  _ |  j   n  d  S(   N(   RF   R   RG   (   R   R   t   unused_reason(    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR    U  s    		c            s    j  s-   j r) t j d  f  n  d S d k rc   j d k rW t d   qc   j  n    j d 7_   j d k	 r   j   j k r   j r t j d    j f  n  d St	   j
   j   j    _
   j r
t j   j
   j
   j    _
 n    j r0t j d    j
 f  n     f d   }   j d k rmd d	 l m } |   _ n    j j   j
 |    _ d S(
   sL   
        Have this connector connect again, after a suitable delay.
        s!   Abandoning %s on explicit requestNs   no connector to retryi   s   Abandoning %s after %d retries.s   %s will retry in %d secondsc              s   d   _   j   d  S(   N(   R   t   _callIDt   connect(    (   R   R   (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   reconnectory  s    	i(   R"   (   RF   R	   R   R
   R   R   t
   ValueErrort   retriest
   maxRetriest   mint   delayt   factort   maxDelayt   jittert   randomt   normalvariatet   clockt   twisted.internetR"   R'   RI   (   R   R   RK   R"   (    (   R   R   s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRG   [  s2    		!				c         C   sc   |  j  r" |  j  j   d |  _  n  d |  _ |  j r_ y |  j j   Wq_ t j k
 r[ q_ Xn  d S(   sE   
        Put a stop to any attempt to reconnect in progress.
        i    N(   RI   R4   R   RF   R   t   stopConnectingR   t   NotConnectingError(   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt
   stopTrying  s    			c         C   s+   |  j  |  _ d |  _ d |  _ d |  _ d S(   st   
        Call this method after a successful connection: it resets the delay and
        the retry counter.
        i    i   N(   t   initialDelayRP   RM   R   RI   RF   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt
   resetDelay  s    		c         C   sL   |  j  j   } x6 d d d d d d g D] } | | k r( | | =q( q( W| S(   s-  
        Remove all of the state which is mutated by connection attempts and
        failures, returning just the state which describes how reconnections
        should be attempted.  This will make the unserialized instance
        behave just as this one did when it was first instantiated.
        R   RM   RP   RF   RI   RV   (   t   __dict__t   copy(   R   t   statet   key(    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   __getstate__  s    N(   R   R   R   RR   R[   RQ   RS   RP   RM   R   RN   RI   R   RV   RF   R   R    RG   RZ   R\   Ra   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRE   %  s$   		'		t   ServerFactoryc           B   s   e  Z d  Z RS(   sU   Subclass this to indicate that your protocol.Factory is only usable for servers.
    (   R   R   R   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRb     s   t   BaseProtocolc           B   s,   e  Z d  Z d Z d Z d   Z d   Z RS(   s  This is the abstract superclass of all protocols.

    If you are going to write a new protocol for Twisted, start here.  The
    docstrings of this class explain how you can get started.  Any protocol
    implementation, either client or server, should be a subclass of me.

    My API is quite simple.  Implement dataReceived(data) to handle both
    event-based and synchronous input; output can be sent through the
    'transport' attribute, which is to be an instance that implements
    L{twisted.internet.interfaces.ITransport}.

    Some subclasses exist already to help you write common types of protocols:
    see the L{twisted.protocols.basic} module for a few of them.
    i    c         C   s    d |  _  | |  _ |  j   d S(   s   Make a connection to a transport and a server.

        This sets the 'transport' attribute of this Protocol, and calls the
        connectionMade() callback.
        i   N(   t	   connectedt	   transportt   connectionMade(   R   Re   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   makeConnection  s    		c         C   s   d S(   s  Called when a connection is made.

        This may be considered the initializer of the protocol, because
        it is called when the connection is completed.  For clients,
        this is called once the connection to the server has been
        established; for servers, this is called after an accept() call
        stops blocking and a socket has been received.  If you need to
        send any greeting or initial message, do it here.
        N(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRf     s    N(   R   R   R   Rd   R   Re   Rg   Rf   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRc     s
   	
t   Protocolc           B   s*   e  Z e e j  d    Z e d  Z RS(   c         C   s   d S(   s=  Called whenever data is received.

        Use this method to translate to a higher-level message.  Usually, some
        callback will be made upon the receipt of each complete protocol
        message.

        @param data: a string of indeterminate length.  Please keep in mind
            that you will probably need to buffer some data, as partial
            (or multiple) protocol messages may be received!  I recommend
            that unit tests for protocols call through to this method with
            differing chunk sizes, down to one byte at a time.
        N(    (   R   t   data(    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   dataReceived  s    c         C   s   d S(   s   Called when the connection is shut down.

        Clear any circular references here, and any external references
        to this Protocol.  The connection has been closed.

        @type reason: L{twisted.python.failure.Failure}
        N(    (   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   connectionLost  s    (   R   R   R    R   t	   IProtocolRj   t   connectionDoneRk   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRh     s   	t   ProtocolToConsumerAdapterc           B   s0   e  Z e e j  d    Z d   Z d   Z RS(   c         C   s   |  j  j |  d  S(   N(   t   originalRj   (   R   Ri   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   write  s    c         C   s   d  S(   N(    (   R   t   producert	   streaming(    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   registerProducer   s    c         C   s   d  S(   N(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   unregisterProducer  s    (   R   R   R    R   t	   IConsumerRp   Rs   Rt   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRn     s   		t   ConsumerToProtocolAdapterc           B   s9   e  Z e e j  d    Z d   Z d   Z d   Z RS(   c         C   s   |  j  j |  d  S(   N(   Ro   Rp   (   R   Ri   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRj     s    c         C   s   d  S(   N(    (   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRk     s    c         C   s   d  S(   N(    (   R   Re   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRg     s    c         C   s   d  S(   N(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRf     s    (	   R   R   R    R   Rl   Rj   Rk   Rg   Rf   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRv   	  s
   			t   ProcessProtocolc           B   sl   e  Z d  Z e e j  d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z d	   Z RS(
   s   
    Base process protocol implementation which does simple dispatching for
    stdin, stdout, and stderr file descriptors.
    c         C   s<   | d k r |  j  |  n | d k r8 |  j |  n  d  S(   Ni   i   (   t   outReceivedt   errReceived(   R   t   childFDRi   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   childDataReceived"  s    c         C   s   d S(   s5   
        Some data was received from stdout.
        N(    (   R   Ri   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRx   )  s    c         C   s   d S(   s5   
        Some data was received from stderr.
        N(    (   R   Ri   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRy   /  s    c         C   sO   | d k r |  j    n2 | d k r2 |  j   n | d k rK |  j   n  d  S(   Ni    i   i   (   t   inConnectionLostt   outConnectionLostt   errConnectionLost(   R   Rz   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   childConnectionLost5  s    c         C   s   d S(   s;   
        This will be called when stdin is closed.
        N(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR|   >  s    c         C   s   d S(   s<   
        This will be called when stdout is closed.
        N(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR}   D  s    c         C   s   d S(   s<   
        This will be called when stderr is closed.
        N(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR~   J  s    c         C   s   d S(   sy   
        This will be called when the subprocess exits.

        @type reason: L{twisted.python.failure.Failure}
        N(    (   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   processExitedP  s    c         C   s   d S(   s   
        This will be called when the subprocess is finished.

        @type reason: L{twisted.python.failure.Failure}
        N(    (   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   processEndedX  s    (   R   R   R   R    R   t   IProcessProtocolR{   Rx   Ry   R   R|   R}   R~   R   R   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRw     s   									t   AbstractDatagramProtocolc           B   s_   e  Z d  Z d	 Z d Z e Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z d   Z RS(
   sV   
    Abstract protocol for datagram-oriented transports, e.g. IP, ICMP, ARP, UDP.
    i    c         C   s   |  j  j   } d  | d <| S(   NRe   (   R]   R^   R   (   R   R9   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRa   j  s    
c         C   sG   |  j  s3 |  j r& t j d |   n  |  j   n  |  j  d |  _  d S(   sw   Make sure startProtocol is called.

        This will be called by makeConnection(), users should not call it.
        s   Starting protocol %si   N(   R   R	   R   R
   t   startProtocol(   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR   o  s
    		c         C   se   |  j  d k s t  |  j  d |  _  d |  _ |  j  sa |  j rT t j d |   n  |  j   n  d S(   sn   Make sure stopProtocol is called.

        This will be called by the port, users should not call it.
        i    i   s   Stopping protocol %sN(   R   t   AssertionErrorR   Re   R	   R   R
   t   stopProtocol(   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR   z  s    			c         C   s   d S(   s   Called when a transport is connected to this protocol.

        Will only be called once, even if multiple ports are connected.
        N(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR     s    c         C   s   d S(   sx   Called when the transport is disconnected.

        Will only be called once, after all ports are disconnected.
        N(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR     s    c         C   s,   |  j  d k s t  | |  _  |  j   d S(   s   Make a connection to a transport and a server.

        This sets the 'transport' attribute of this DatagramProtocol, and calls the
        doStart() callback.
        N(   Re   R   R   R   (   R   Re   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRg     s    	c         C   s   d S(   s   Called when a datagram is received.

        @param datagram: the string received from the transport.
        @param addr: tuple of source of datagram.
        N(    (   R   t   datagramR   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   datagramReceived  s    N(   R   R   R   R   Re   R   R   R	   Ra   R   R   R   R   Rg   R   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR   a  s   						
t   DatagramProtocolc           B   s   e  Z d  Z d   Z RS(   s   
    Protocol for datagram-oriented transport, e.g. UDP.

    @type transport: C{NoneType} or
        L{IUDPTransport<twisted.internet.interfaces.IUDPTransport>} provider
    @ivar transport: The transport with which this protocol is associated,
        if it is associated with one.
    c         C   s   d S(   s   Called due to error from write in connected mode.

        Note this is a result of ICMP message generated by *previous*
        write.
        N(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   connectionRefused  s    (   R   R   R   R   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR     s   t   ConnectedDatagramProtocolc           B   s    e  Z d  Z d   Z d   Z RS(   sZ   Protocol for connected datagram-oriented transport.

    No longer necessary for UDP.
    c         C   s   d S(   sn   Called when a datagram is received.

        @param datagram: the string received from the transport.
        N(    (   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR     s    c         C   s   d S(   s`   Called if connecting failed.

        Usually this will be due to a DNS lookup failure.
        N(    (   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   connectionFailed  s    (   R   R   R   R   R   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR     s   	t   FileWrapperc           B   s   e  Z d  Z e e j  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 d   Z d   Z d   Z d   Z RS(   s   A wrapper around a file-like object to make it behave as a Transport.

    This doesn't actually stream the file to the attached protocol,
    and is thus useful mainly as a utility for debugging protocols.
    i    c         C   s   | |  _  d  S(   N(   t   file(   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR%     s    c         C   s,   y |  j  j |  Wn |  j   n Xd  S(   N(   R   Rp   t   handleException(   R   Ri   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRp     s    c         C   s   |  j  r |  j  j   n  d  S(   N(   Rq   t   resumeProducing(   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   _checkProducer  s    	c         C   s)   | |  _  | |  _ | s% | j   n  d S(   s%   From abstract.FileDescriptor
        N(   Rq   t   streamingProducerR   (   R   Rq   Rr   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRs     s    		c         C   s   d  |  _ d  S(   N(   R   Rq   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyRt     s    c         C   s   |  j    |  j   d  S(   N(   Rt   t   loseConnection(   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   stopConsuming  s    
c         C   s   |  j  d j |   d  S(   Nt    (   Rp   t   join(   R   t   iovec(    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   writeSequence  s    c         C   sB   d |  _  y |  j j   Wn! t t f k
 r= |  j   n Xd  S(   Ni   (   t   closedR   t   closet   IOErrort   OSErrorR   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR     s
    	c         C   s   d S(   NR   (   s   files   file(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   getPeer  s    c         C   s   d S(   NR   (    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   getHost  s    c         C   s   d  S(   N(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR   
  s    c         C   s   d  S(   N(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR     s    c         C   s   d  S(   N(    (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   pauseProducing  s    c         C   s   |  j    d  S(   N(   R   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   stopProducing  s    N(   R   R   R   R    R   t
   ITransportR   t   disconnectingR   Rq   R   R%   Rp   R   Rs   Rt   R   R   R   R   R   R   R   R   R   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyR     s(   													Rm   (    (    (    (    (    ($   R   RT   t   zope.interfaceR    t   twisted.pythonR   R   R   RW   R   R   R   R   R   R!   R/   RE   Rb   Rc   t   Failuret   ConnectionDoneRm   t   cleanFailureRh   t   AdapterRn   t   registerAdapterRl   Ru   Rv   Rw   R   R   R   R   t   __all__(    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/internet/protocol.pyt   <module>   s:   O 7i(


FDN	