ó
±xYc           @  s£   d  Z  d d l m Z d d l m Z m Z d d l m Z d Z d	 e	 f d
 „  ƒ  YZ
 d e	 f d „  ƒ  YZ d e e e	 ƒ f d „  ƒ  YZ d „  Z d „  Z d S(   u   
iÿÿÿÿ(   t   unicode_literals(   t   ABCMetat   abstractmethod(   t   with_metaclassu
   Completionu	   Completeru   CompleteEventu   get_common_complete_suffixt
   Completionc           B  sV   e  Z d  Z d d d d d „ Z d „  Z d „  Z d „  Z e d „  ƒ Z	 d „  Z
 RS(	   u‹  
    :param text: The new string that will be inserted into the document.
    :param start_position: Position relative to the cursor_position where the
        new text will start. The text will be inserted between the
        start_position and the original cursor position.
    :param display: (optional string) If the completion has to be displayed
        differently in the completion menu.
    :param display_meta: (Optional string) Meta information about the
        completion, e.g. the path or source where it's coming from.
    :param get_display_meta: Lazy `display_meta`. Retrieve meta information
        only when meta is displayed.
    i    c         C  s^   | |  _  | |  _ | |  _ | |  _ | d  k r< | |  _ n	 | |  _ |  j d k sZ t ‚ d  S(   Ni    (   t   textt   start_positiont   _display_metat   _get_display_metat   Nonet   displayt   AssertionError(   t   selfR   R   R
   t   display_metat   get_display_meta(    (    s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyt   __init__   s    					c         C  sV   |  j  |  j k r/ d |  j j |  j |  j f Sd |  j j |  j |  j |  j  f Sd  S(   Nu   %s(text=%r, start_position=%r)u*   %s(text=%r, start_position=%r, display=%r)(   R
   R   t	   __class__t   __name__R   (   R   (    (    s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyt   __repr__*   s    c         C  sF   |  j  | j  k oE |  j | j k oE |  j | j k oE |  j | j k S(   N(   R   R   R
   R   (   R   t   other(    (    s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyt   __eq__3   s    c         C  s"   t  |  j |  j |  j |  j f ƒ S(   N(   t   hashR   R   R
   R   (   R   (    (    s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyt   __hash__:   s    c         C  s=   |  j  d  k	 r |  j  S|  j r5 |  j ƒ  |  _  |  j  Sd Sd  S(   Nu    (   R   R	   R   (   R   (    (    s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyR   =   s    	c      	   C  s^   t  | t ƒ r" | |  j d k s( t ‚ t d |  j | |  j d |  j d |  j d |  j ƒ S(   uà   
        (Only for internal use!)
        Get a new completion by splitting this one. Used by
        `CommandLineInterface` when it needs to have a list of new completions
        after inserting the common prefix.
        i    R   R
   R   R   (	   t
   isinstancet   intR   R   R   R   R
   R   R   (   R   t   position(    (    s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyt   new_completion_from_positionJ   s    (		N(   R   t
   __module__t   __doc__R	   R   R   R   R   t   propertyR   R   (    (    (    s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyR      s   					t   CompleteEventc           B  s&   e  Z d  Z e e d „ Z d „  Z RS(   u6  
    Event that called the completer.

    :param text_inserted: When True, it means that completions are requested
        because of a text insert. (`Buffer.complete_while_typing`.)
    :param completion_requested: When True, it means that the user explicitely
        pressed the `Tab` key in order to view the completions.

    These two flags can be used for instance to implemented a completer that
    shows some completions when ``Tab`` has been pressed, but not
    automatically when the user presses a space. (Because of
    `complete_while_typing`.)
    c         C  s)   | o	 | s t  ‚ | |  _ | |  _ d  S(   N(   R   t   text_insertedt   completion_requested(   R   R   R    (    (    s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyR   h   s    	c         C  s   d |  j  j |  j |  j f S(   Nu-   %s(text_inserted=%r, completion_requested=%r)(   R   R   R   R    (   R   (    (    s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyR   q   s    (   R   R   R   t   FalseR   R   (    (    (    s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyR   Z   s   	t	   Completerc           B  s   e  Z d  Z e d „  ƒ Z RS(   u3   
    Base class for completer implementations.
    c         c  s   x t  r d Vq Wd S(   uÇ   
        Yield :class:`.Completion` instances.

        :param document: :class:`~prompt_toolkit.document.Document` instance.
        :param complete_event: :class:`.CompleteEvent` instance.
        N(   R!   (   R   t   documentt   complete_event(    (    s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyt   get_completionsz   s    	(   R   R   R   R   R%   (    (    (    s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyR"   v   s   c           s|   ‡  f d †  } g  | D] } | | ƒ r | ^ q } t  | ƒ t  | ƒ k rP d Sd „  } t g  | D] } | | ƒ ^ qc ƒ S(   u7   
    Return the common prefix for all completions.
    c           s!   |  j  |  j  } ˆ  j j | ƒ S(   N(   R   R   t   text_before_cursort   endswith(   t
   completiont   end(   R#   (    s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyt   doesnt_change_before_cursor‹   s    u    c         S  s   |  j  |  j S(   N(   R   R   (   R(   (    (    s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyt
   get_suffix—   s    (   t   lent   _commonprefix(   R#   t   completionsR*   t   ct   completions2R+   (    (   R#   s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyt   get_common_complete_suffix†   s    %	c         C  s_   |  s
 d St  |  ƒ } t |  ƒ } x2 t | ƒ D]$ \ } } | | | k r/ | |  Sq/ W| Sd  S(   Nu    (   t   mint   maxt	   enumerate(   t   stringst   s1t   s2t   iR/   (    (    s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyR-      s    N(   u
   Completionu	   Completeru   CompleteEventu   get_common_complete_suffix(   R   t
   __future__R    t   abcR   R   t   sixR   t   __all__t   objectR   R   R"   R1   R-   (    (    (    s8   lib/python2.7/site-packages/prompt_toolkit/completion.pyt   <module>   s      K	