ó
±xYc           @  sK  d  Z  d d l m Z d d l 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‘ Z e Z d Z e j d e j d ƒ d ƒ Z e j d e j d ƒ d ƒ Z e j d e j d ƒ d ƒ Z e j d e j d ƒ d ƒ Z d e f d „  ƒ  YZ iu e j d 6e j d 6e j d 6e j d 6e j d 6e j d 6e j  d 6e j! d 6e j" d 6e j# d 6e j$ d 6e j% d 6e j& d  6e j' d! 6e j( d" 6e j) d# 6e j* d$ 6e j+ d% 6e j, d& 6e j- d' 6e j. d( 6e j/ d) 6e j0 d* 6e j1 d+ 6e j2 d, 6e j3 d- 6e j4 d. 6e j5 d/ 6e j6 d0 6e j7 d1 6e j8 d2 6e j9 d3 6e j: d4 6e j; d5 6e j< d6 6e j= d7 6e j> d8 6e j? d9 6e j? d: 6e j@ d; 6e j@ d< 6e jA d= 6e jB d> 6e jC d? 6e j? d@ 6e j@ dA 6e jD dB 6e jE dC 6e j? dD 6e j@ dE 6e jF dF 6e jG dG 6e jH dH 6e jI dI 6e jJ dJ 6e jK dK 6e jH dL 6e jI dM 6e jJ dN 6e jK dO 6e jL dP 6e jH dQ 6e jI dR 6e jJ dS 6e jK dT 6e jL dU 6e jM dV 6e jN dW 6e jO dX 6e jP dY 6e jQ dZ 6e jR d[ 6e jS d\ 6e jT d] 6e jU d^ 6e jV d_ 6e jW d` 6e jX da 6e jY db 6e jZ dc 6e j[ dd 6e jT de 6e jU df 6e jW dg 6e jX dh 6e jY di 6e jZ dj 6e j[ dk 6e j\ dl 6e j] dm 6e j^ dn 6e j_ do 6e j` dp 6e ja dq 6e jb dr 6e jc ds 6e jd dt 6e je du 6e jf dv 6e jg dw 6e j; dx 6e j< dy 6e j= dz 6e j> d{ 6e j` d| 6e ja d} 6e jb d~ 6e jc d 6e jb d€ 6e jc d 6e jh d‚ 6e j e j> f dƒ 6e j e j= f d„ 6e j e j; f d… 6e j e j< f d† 6e ji d‡ 6e ji dˆ 6Zj d‰ ek f dŠ „  ƒ  YZl el ƒ  Zm d‹ e f dŒ „  ƒ  YZn d e f dŽ „  ƒ  YZo d eo f d „  ƒ  YZp d S(’   u    
Parser for VT100 input stream.
iÿÿÿÿ(   t   unicode_literalsN(   t   rangei   (   t   Keys(   t   KeyPressu   InputStreamu   raw_modeu   cooked_modeu   prompt-toolkit-render-input.logu   ^u   [u
   \d+;\d+R\Zu   (<?[\d;]+[mM]|M...)\Zu   [\d;]*\Zu   (<?[\d;]*|M.{0,2})\Zt   _Flushc           B  s   e  Z d  Z RS(   u:    Helper object to indicate flush operation to the parser. (   t   __name__t
   __module__t   __doc__(    (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyR   ,   s   u   u    u   u   u   u   u   u   u   u   u   	u   
u   u   u   u   u   u   u   u   u   u   u   u   u   u   u   u   u   u   u   u   u   u   [Au   [Bu   [Cu   [Du   [Hu   OHu   [Fu   OFu   [3~u   [3;2~u   [3;5~u   [1~u   [4~u   [5~u   [6~u   [7~u   [8~u   [Zu   [2~u   OPu   OQu   ORu   OSu   [[Au   [[Bu   [[Cu   [[Du   [[Eu   [11~u   [12~u   [13~u   [14~u   [15~u   [17~u   [18~u   [19~u   [20~u   [21~u   [23~u   [24~u   [25~u   [26~u   [28~u   [29~u   [31~u   [32~u   [33~u   [34~u   [1;2Pu   [1;2Qu   [1;2Su   [15;2~u   [17;2~u   [18;2~u   [19;2~u   [20;2~u   [21;2~u   [23;2~u   [24;2~u   [1;5Au   [1;5Bu   [1;5Cu   [1;5Du   [1;2Au   [1;2Bu   [1;2Cu   [1;2Du   OAu   OBu   OCu   ODu   [5Au   [5Bu   [5Cu   [5Du   Ocu   Odu   [200~u   [1;3Du   [1;3Cu   [1;3Au   [1;3Bu   [Eu   [Gt   _IsPrefixOfLongerMatchCachec           B  s   e  Z d  Z d „  Z RS(   u‚   
    Dictiory that maps input sequences to a boolean indicating whether there is
    any key that start with this characters.
    c           sW   t  j ˆ  ƒ s t j ˆ  ƒ r' t } n" t ‡  f d †  t j ƒ  Dƒ ƒ } | |  ˆ  <| S(   Nc         3  s6   |  ], \ } } | j  ˆ  ƒ r | ˆ  k r | Vq d  S(   N(   t
   startswith(   t   .0t   kt   v(   t   prefix(    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pys	   <genexpr>Ó   s    (   t   _cpr_response_prefix_ret   matcht   _mouse_event_prefix_ret   Truet   anyt   ANSI_SEQUENCESt   items(   t   selfR   t   result(    (   R   sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyt   __missing__Ì   s
    	"
(   R   R   R   R   (    (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyR   Ç   s   t   InputStreamc           B  sb   e  Z d  Z d „  Z e d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z RS(
   uh  
    Parser for VT100 input stream.

    Feed the data through the `feed` method and the correct callbacks of the
    `input_processor` will be called.

    ::

        def callback(key):
            pass
        i = InputStream(callback)
        i.feed('data...')

    :attr input_processor: :class:`~prompt_toolkit.key_binding.InputProcessor` instance.
    c         C  sD   t  | ƒ s t ‚ | |  _ |  j ƒ  t r@ t t d ƒ |  _ n  d  S(   Nu   ab(   t   callablet   AssertionErrort   feed_key_callbackt   resett   _DEBUG_RENDERER_INPUTt   opent   _DEBUG_RENDERER_INPUT_FILENAMEt   LOG(   R   R   (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyt   __init__ï   s
    	
c         C  s   t  |  _ |  j ƒ  d  S(   N(   t   Falset   _in_bracketed_pastet   _start_parser(   R   t   request(    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyR   ø   s    	c         C  s#   |  j  ƒ  |  _ |  j j d ƒ d S(   u-   
        Start the parser coroutine.
        N(   t   _input_parser_generatort   _input_parsert   sendt   None(   R   (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyR$   ü   s    c         C  sQ   t  j | ƒ r t j St j | ƒ r, t j Sy t | SWn t k
 rL d SXd S(   u:   
        Return the key that maps to this prefix.
        N(	   t   _cpr_response_reR   R   t   CPRResponset   _mouse_event_ret   Vt100MouseEventR   t   KeyErrorR)   (   R   R   (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyt
   _get_match  s    c   	      c  s]  d } t  } t  } xDt rXt  } | r0 t  } n& d V} | t k rL t } n
 | | 7} | r t | } |  j | ƒ } | s‚ | r¡ | r¡ |  j | | ƒ d } qU| s® | rU| rUt  } t } x` t t | ƒ d d ƒ D]F } |  j | |  ƒ } | rÚ |  j | | |  ƒ | | } t } qÚ qÚ W| sR|  j | d | d ƒ | d } qRqUq q Wd S(   uA   
        Coroutine (state machine) for the input parser.
        u    Ni    iÿÿÿÿi   (   R"   R   R   t    _IS_PREFIX_OF_LONGER_MATCH_CACHER/   t   _call_handlerR   t   len(	   R   R   t   retryt   flusht   ct   is_prefix_of_longer_matchR   t   foundt   i(    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyR&     s:    			

	
c         C  sq   t  | t ƒ r3 x[ | D] } |  j | | ƒ q Wn: | t j k rW t |  _ d |  _ n |  j t	 | | ƒ ƒ d S(   u&   
        Callback to handler.
        u    N(
   t
   isinstancet   tupleR1   R   t   BracketedPasteR   R#   t   _paste_bufferR   R   (   R   t   keyt   insert_textR   (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyR1   H  s    	c         C  sV  t  | t j ƒ s t ‚ t rQ |  j j t | ƒ j d ƒ d ƒ |  j j	 ƒ  n  |  j
 rò |  j | 7_ d } | |  j k rR|  j j | ƒ } |  j |  } |  j t t j | ƒ ƒ t |  _
 |  j | t | ƒ } d |  _ |  j | ƒ qRn` x] t | ƒ D]O \ } } |  j
 r)|  j | | ƒ Pqÿ | d k r>d } n  |  j j | ƒ qÿ Wd S(   uV   
        Feed the input stream.

        :param data: Input string (unicode).
        u   utf-8s   
u   [201~u    u   u   
N(   R9   t   sixt	   text_typeR   R   R    t   writet   reprt   encodeR4   R#   R<   t   indexR   R   R   R;   R"   R2   t   feedt	   enumerateR'   R(   (   R   t   datat   end_markt	   end_indext   paste_contentt	   remainingR8   R5   (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyRE   V  s,    #					c         C  s   |  j  j t ƒ d S(   u<  
        Flush the buffer of the input stream.

        This will allow us to handle the escape key (or maybe meta) sooner.
        The input received by the escape key is actually the same as the first
        characters of e.g. Arrow-Up, so without knowing what follows the escape
        sequence, we don't know whether escape has been pressed, or whether
        it's something else. This flush function should be called after a
        timeout, and processes everything that's still in the buffer as-is, so
        without assuming any characters will folow.
        N(   R'   R(   R   (   R   (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyR4     s    c         C  s   |  j  | ƒ |  j ƒ  d S(   u8   
        Wrapper around ``feed`` and ``flush``.
        N(   RE   R4   (   R   RG   (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyt   feed_and_flushž  s    (   R   R   R   R!   R"   R   R$   R/   R&   R1   RE   R4   RL   (    (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyR   Ü   s   					2		:	t   raw_modec           B  sG   e  Z d  Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z d „  Z RS(   u©   
    ::

        with raw_mode(stdin):
            ''' the pseudo-terminal stdin is now used in raw mode '''

    We ignore errors when executing `tcgetattr` fails.
    c         C  sC   | |  _  y t j | ƒ |  _ Wn t j k
 r> d  |  _ n Xd  S(   N(   t   filenot   termiost	   tcgetattrt   attrs_beforet   errorR)   (   R   RN   (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyR!   ½  s
    	c         C  s«   y t  j |  j ƒ } Wn t  j k
 r, n{ X|  j | t j ƒ | t j <|  j | t j ƒ | t j <d | t j	 t  j
 <t  j |  j t  j | ƒ t j |  j d ƒ d  S(   Ni   s   [?1l(   RO   RP   RN   RR   t   _patch_lflagt   ttyt   LFLAGt   _patch_iflagt   IFLAGt   CCt   VMINt	   tcsetattrt   TCSANOWt   osRA   (   R   t   newattr(    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyt	   __enter__Å  s    c         C  s!   | t  j t  j Bt  j Bt  j B@S(   N(   RO   t   ECHOt   ICANONt   IEXTENt   ISIG(   t   clst   attrs(    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyRS   Û  s    c         C  s(   | t  j t  j Bt  j Bt  j Bt  j B@S(   N(   RO   t   IXONt   IXOFFt   ICRNLt   INLCRt   IGNCR(   Rc   Rd   (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyRV   ß  s    c         O  sM   |  j  d  k	 rI y  t j |  j t j |  j  ƒ WqI t j k
 rE qI Xn  d  S(   N(   RQ   R)   RO   RZ   RN   R[   RR   (   R   t   at   kw(    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyt   __exit__ë  s
     (	   R   R   R   R!   R^   t   classmethodRS   RV   Rl   (    (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyRM   ¦  s   		t   cooked_modec           B  s,   e  Z d  Z e d „  ƒ Z e d „  ƒ Z RS(   u  
    The opposide of ``raw_mode``, used when we need cooked mode inside a
    `raw_mode` block.  Used in `CommandLineInterface.run_in_terminal`.::

        with cooked_mode(stdin):
            ''' the pseudo-terminal stdin is now used in cooked mode. '''
    c         C  s    | t  j t  j Bt  j Bt  j BBS(   N(   RO   R_   R`   Ra   Rb   (   Rc   Rd   (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyRS   þ  s    c         C  s   | t  j BS(   N(   RO   Rg   (   Rc   Rd   (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyRV     s    (   R   R   R   Rm   RS   RV   (    (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyRn   ö  s   (   u   InputStreamu   raw_modeu   cooked_mode(q   R   t
   __future__R    R\   t   reR?   RO   RT   t	   six.movesR   t   keysR   t   key_binding.input_processorR   t   __all__R"   R   R   t   compilet   escapeR*   R,   R   R   t   objectR   t   Escapet   ControlSpacet   ControlAt   ControlBt   ControlCt   ControlDt   ControlEt   ControlFt   ControlGt   ControlHt   ControlIt   ControlJt   ControlKt   ControlLt   ControlMt   ControlNt   ControlOt   ControlPt   ControlQt   ControlRt   ControlSt   ControlTt   ControlUt   ControlVt   ControlWt   ControlXt   ControlYt   ControlZt   ControlBackslasht   ControlSquareCloset   ControlCircumflext   ControlUnderscoret	   Backspacet   Upt   Downt   Rightt   Leftt   Homet   Endt   Deletet   ShiftDeletet   ControlDeletet   PageUpt   PageDownt   BackTabt   Insertt   F1t   F2t   F3t   F4t   F5t   F6t   F7t   F8t   F9t   F10t   F11t   F12t   F13t   F14t   F15t   F16t   F17t   F18t   F19t   F20t   F21t   F22t   F23t   F24t	   ControlUpt   ControlDownt   ControlRightt   ControlLeftt   ShiftUpt	   ShiftDownt
   ShiftRightt	   ShiftLeftR;   t   IgnoreR   t   dictR   R0   R   RM   Rn   (    (    (    sB   lib/python2.7/site-packages/prompt_toolkit/terminal/vt100_input.pyt   <module>   s        















































































































	ÊP