ó
[³XMc           @   sK  d  Z  d d l Z e j d e d d ƒy d d l m Z Wn! e k
 r_ d d l m Z n Xd d l m Z d d l	 m
 Z
 e d	 ƒ Z e d
 Z e d Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z  e d ƒ Z! e d ƒ Z" e d  ƒ Z# e d! ƒ Z$ e d" ƒ Z% e d# ƒ Z& e d$ ƒ Z' e d% ƒ Z( e d& ƒ Z) e d' ƒ Z* e d( ƒ Z+ i d) e$ 6d* e% 6d+ e" 6d, e# 6d- e 6Z, d. „  Z- d/ e
 j. f d0 „  ƒ  YZ/ d S(1   s<   TELNET implementation, with line-oriented command handling.
iÿÿÿÿNst   As of Twisted 2.1, twisted.protocols.telnet is deprecated.  See twisted.conch.telnet for the current, supported API.t
   stackleveli   (   t   StringIO(   t	   copyright(   t   protocoli   s   [1ms   [mi    i
   i   i   i   i	   i   i   ið   iñ   iò   ió   iô   iõ   iö   i÷   iø   iù   iú   iû   iü   iý   iþ   iÿ   i   i   i"   i…   iƒ   t   DOt   DONTt   WILLt   WONTt   IPc         C   s3   x, | j  ƒ  D] \ } } |  j | | ƒ }  q W|  S(   N(   t   itemst   replace(   t   stt   dctt   kt   v(    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt   multireplace   s    t   Telnetc           B   s×   e  Z d  Z d Z d Z d Z d Z d Z d d g 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 d „  Z RS(   su  I am a Protocol for handling Telnet connections. I have two
    sets of special methods, telnet_* and iac_*.

    telnet_* methods get called on every line sent to me. The method
    to call is decided by the current mode. The initial mode is 'User';
    this means that telnet_User is the first telnet_* method to be called.
    All telnet_* methods should return a string which specifies the mode
    to go into next; thus dictating which telnet_* method to call next.
    For example, the default telnet_User method returns 'Password' to go
    into Password mode, and the default telnet_Password method returns
    'Command' to go into Command mode.

    The iac_* methods are less-used; they are called when an IAC telnet
    byte is received. You can define iac_DO, iac_DONT, iac_WILL, iac_WONT,
    and iac_IP methods to do what you want when one of these bytes is
    received.i    t    s   
s    t   Userc         C   s   |  j  j | ƒ d S(   s&   Send the given data over my transport.N(   t	   transportt   write(   t   selft   data(    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyR   ­   s    c         C   s!   |  j  |  j ƒ  |  j ƒ  ƒ d S(   s<   I will write a welcomeMessage and loginPrompt to the client.N(   R   t   welcomeMessaget   loginPrompt(   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt   connectionMade²   s    c         C   s-   |  j  j } d | j d | j d t j S(   sU   Override me to return a string which will be sent to the client
        before login.s   
t   .s   
Twisted %s
(   t   factoryt	   __class__t
   __module__t   __name__R   t   version(   R   t   x(    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyR   ¶   s    c         C   s   d S(   s-   Override me to return a 'login:'-type prompt.s
   username: (    (   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyR   ¾   s    c         C   s   d  S(   N(    (   R   t   chunk(    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt
   iacSBchunkÂ   s    c         C   s   d  S(   N(    (   R   t   feature(    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt   iac_DOÅ   s    c         C   s   d  S(   N(    (   R   R#   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt   iac_DONTÈ   s    c         C   s   d  S(   N(    (   R   R#   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt   iac_WILLË   s    c         C   s   d  S(   N(    (   R   R#   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt   iac_WONTÎ   s    c         C   s   d  S(   N(    (   R   R#   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt   iac_IPÑ   s    c         C   s8   t  |  d |  j ƒ | ƒ } | d k	 r4 | |  _ n  d S(   sç   I call a method that looks like 'telnet_*' where '*' is filled
        in by the current mode. telnet_* methods should return a string which
        will become the new mode.  If None is returned, the mode will not change.
        t   telnet_N(   t   getattrt   modet   None(   R   t   lineR+   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt   processLineÔ   s    c         C   s&   | |  _  |  j t t t d ƒ d S(   s  I take a username, set it to the 'self.username' attribute,
        print out a password prompt, and switch to 'Password' mode. If
        you want to do something else when the username is received (ie,
        create a new user if the user doesn't exist), override me.s
   password: t   Password(   t   usernameR   t   IACR   t   ECHO(   R   t   user(    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt   telnet_UserÝ   s    	c         C   sU   |  j  t t t d ƒ y |  j |  j | ƒ } Wn d SX| sG d S|  j ƒ  d S(   s‘   I accept a password as an argument, and check it with the
        checkUserAndPass method. If the login is successful, I call
        loggedIn().s   *****
t   Donet   Command(   R   R1   R   R2   t   checkUserAndPassR0   t   loggedIn(   R   t   paswdt   checked(    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt   telnet_Passwordæ   s    
c         C   s   d S(   sP   The default 'command processing' mode. You probably want to
        override me.R6   (    (   R   t   cmd(    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt   telnet_Commandô   s    c         C   sá   |  j  | |  _  x3 |  j D]( } |  j  j | ƒ } | d k r Pq q Wx” | d k rÜ |  j  |  |  j  | d } |  _  |  j | ƒ |  j d k r£ |  j j ƒ  n  x3 |  j D]( } |  j  j | ƒ } | d k r­ Pq­ q­ WqI Wd S(   s   I take a chunk of data and delegate out to telnet_* methods
        by way of processLine. If the current mode is 'Done', I'll close
        the connection. iÿÿÿÿi   R5   N(   t   buffert
   delimiterst   findR.   R+   R   t   loseConnection(   R   R!   t   delimt   idxt   buf(    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt   processChunkù   s    "c         C   sa  t  ƒ  } x#| D]} |  j rÏ |  j rÃ |  j t k r~ | t k rn |  j | j ƒ  ƒ t  ƒ  } |  ` |  ` qÀ | j | ƒ qÌ y" t |  d t	 |  j ƒ | ƒ Wn t
 k
 r³ n X|  ` |  ` q+| |  _ q | t k r| j ƒ  } | r|  j | ƒ } | r| St  ƒ  } n  d |  _ q | j | ƒ q W| j ƒ  } | r]|  j | ƒ } | r]| Sn  d  S(   Ns   iac_%si   (   R   t   gotIACt   iacBytet   SBt   SER"   t   getvalueR   R*   t   iacBytest   KeyErrorR1   RE   (   R   R   R!   t   chart   ct   why(    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt   dataReceived  s@    					"	c         C   s   d S(   s^   Called after the user succesfully logged in.
        
        Override in subclasses.
        N(    (   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyR8   @  s    N(   R   R   t   __doc__RF   R,   RG   t   lastLineR>   t   echoR?   R+   R   R   R   R   R"   R$   R%   R&   R'   R(   R.   R4   R;   R=   RE   RP   R8   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyR   ’   s2   																		0(0   RQ   t   warningst   warnt   DeprecationWarningt	   cStringIOR   t   ImportErrort   twistedR   t   twisted.internetR   t   chrt   ESCt   BOLD_MODE_ONt   BOLD_MODE_OFFt   NULLt   LFt   CRt   BELt   BSt   HTt   VTt   FFRI   t   NOPt   DMt   BRKR   t   AOt   AYTt   ECt   ELt   GARH   R   R   R   R   R1   R2   t   SUPGAt   LINEMODEt   HIDEt   NOECHORK   R   t   ProtocolR   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt   <module>   sf   



	