ó
æNXc           @   s<   d  Z  d d l Z d d l m Z d e f d „  ƒ  YZ d S(   s>   String dispatch class to match regexps and dispatch commands.
iÿÿÿÿN(   t   CommandChainDispatchert   StrDispatchc           B   sS   e  Z d  Z d „  Z d d „ Z d d „ Z d „  Z d „  Z d „  Z d „  Z	 RS(	   s  Dispatch (lookup) a set of strings / regexps for match.

    Example:

    >>> dis = StrDispatch()
    >>> dis.add_s('hei',34, priority = 4)
    >>> dis.add_s('hei',123, priority = 2)
    >>> dis.add_re('h.i', 686)
    >>> print(list(dis.flat_matches('hei')))
    [123, 34, 686]
    c         C   s   i  |  _  i  |  _ d  S(   N(   t   strst   regexs(   t   self(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/strdispatch.pyt   __init__   s    	i    c         C   s9   |  j  j | t ƒ  ƒ } | j | | ƒ | |  j  | <d S(   s(    Adds a target 'string' for dispatching N(   R   t   getR    t   add(   R   t   st   objt   priorityt   chain(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/strdispatch.pyt   add_s   s    c         C   s9   |  j  j | t ƒ  ƒ } | j | | ƒ | |  j  | <d S(   s&    Adds a target regexp for dispatching N(   R   R   R    R   (   R   t   regexR	   R
   R   (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/strdispatch.pyt   add_re#   s    c         c   s\   | |  j  k r |  j  | Vn  x7 |  j j ƒ  D]& \ } } t j | | ƒ r. | Vq. q. Wd S(   s2    Get a seq of Commandchain objects that match key N(   R   R   t   itemst   ret   match(   R   t   keyt   rR	   (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/strdispatch.pyt   dispatch*   s    c         C   s   d |  j  |  j f S(   Ns   <Strdispatch %s, %s>(   R   R   (   R   (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/strdispatch.pyt   __repr__6   s    c         c   s8   | |  j  k r d  Sx |  j  | D] } | d Vq! Wd  S(   Ni   (   R   (   R   R   t   el(    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/strdispatch.pyt	   s_matches9   s    c         c   s8   x1 |  j  | ƒ D]  } x | D] } | d Vq Wq Wd S(   s-    Yield all 'value' targets, without priority i   N(   R   (   R   R   t   valR   (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/strdispatch.pyt   flat_matches?   s    (
   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   (    (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/strdispatch.pyR      s   				(   R   R   t   IPython.core.hooksR    t   objectR   (    (    (    sQ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/strdispatch.pyt   <module>   s   