σ
Nδ²Wc           @@  sΣ   d  d l  m Z d  d l Z d d l m Z y d  d l m Z Wn! e k
 rc d  d l m Z n Xy e Wn e	 k
 r e
 Z n Xe Z d e f d     YZ d	 e f d
     YZ d e f d     YZ d S(   i    (   t   absolute_importNi   (   t   TransitionMap(   t   maxsize(   t   maxintt   Machinec           B@  s_   e  Z d  Z d	 Z d Z d	 Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z RS(
   s1   A collection of Nodes representing an NFA or DFA.i   c         C@  s   g  |  _  i  |  _ d  S(   N(   t   statest   initial_states(   t   self(    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyt   __init__"   s    	c         C@  s"   x |  j  D] } | j   q
 Wd  S(   N(   R   t   destroy(   R   t   state(    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyt   __del__&   s    c         C@  s<   t    } |  j } | d |  _ | | _ |  j j |  | S(   s-   Add a new state to the machine and return it.i   (   t   Nodet   next_state_numbert   numberR   t   append(   R   t   st   n(    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyt	   new_state+   s    			c         C@  s    |  j    } |  j | |  | S(   N(   R   t   make_initial_state(   R   t   nameR
   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyt   new_initial_state4   s    c         C@  s   | |  j  | <d  S(   N(   R   (   R   R   R
   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyR   9   s    c         C@  s   |  j  | S(   N(   R   (   R   R   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyt   get_initial_state<   s    c         C@  s   | j  d  |  j d  k	 rl | j  d  x@ t |  j j    D]& \ } } | j  d | | j f  q? Wn  x |  j D] } | j |  qv Wd  S(   Ns   Plex.Machine:
s      Initial states:
s         '%s': %d
(   t   writeR   t   Nonet   sortedt   itemsR   R   t   dump(   R   t   fileR   R
   R   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyR   ?   s    "!N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R   R   R   R   (    (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyR      s   							R   c           B@  s   e  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 state of an NFA or DFA.i    c         C@  s   t    |  _ t |  _ d  S(   N(   R   t   transitionst   LOWEST_PRIORITYt   action_priority(   R   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyR   Q   s    c         C@  s   d  |  _ d  |  _ d  |  _ d  S(   N(   R   R    t   actiont   epsilon_closure(   R   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyR	   X   s    		c         C@  s   |  j  j | |  d  S(   N(   R    t   add(   R   t   eventR   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyt   add_transition^   s    c         C@  s   |  j  d |  d S(   s5   Add an epsilon-move from this state to another state.t    N(   R'   (   R   R
   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyt   link_toa   s    c         C@  s(   | |  j  k r$ | |  _ | |  _  n  d S(   s   Make this an accepting state with the given action. If
        there is already an action, choose the action with highest
        priority.N(   R"   R#   (   R   R#   t   priority(    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyt
   set_actione   s    	c         C@  s   |  j  S(   N(   R#   (   R   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyt
   get_actionm   s    c         C@  s   |  j  S(   N(   R"   (   R   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyt   get_action_priorityp   s    c         C@  s   |  j  d  k	 S(   N(   R#   R   (   R   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyt   is_acceptings   s    c         C@  s   d |  j  S(   Ns   State %d(   R   (   R   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyt   __str__v   s    c         C@  s`   | j  d |  j  |  j j |  |  j } |  j } | d  k	 r\ | j  d | | f  n  d  S(   Ns      State %d:
s         %s [priority %d]
(   R   R   R    R   R#   R"   R   (   R   R   R#   R*   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyR   y   s    		c         C@  s   |  j  | j  k  S(   N(   R   (   R   t   other(    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyt   __lt__   s    N(   R   R   R   R   R    R#   R"   R   R$   R   R	   R'   R)   R+   R,   R-   R.   R/   R   R1   (    (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyR   I   s"   										t   FastMachinec           B@  s»   e  Z d  Z d Z d Z d Z i d d 6d d 6d d 6d d 6d d 6Z d   Z d   Z	 d d	  Z
 d
   Z e d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   sd   
    FastMachine is a deterministic machine represented in a way that
    allows fast scanning.
    i   R(   t   bolt   eolt   eoft   elsec         C@  s   i  |  _  g  |  _ d  S(   N(   R   R   (   R   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyR      s    	c         C@  s"   x |  j  D] } | j   q
 Wd  S(   N(   R   t   clear(   R   R
   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyR      s    c         C@  sM   |  j  } | d |  _  |  j j   } | | d <| | d <|  j j |  | S(   Ni   R   R#   (   t   next_numbert   new_state_templatet   copyR   R   (   R   R#   R   t   result(    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyR      s    	

c         C@  s   | |  j  | <d  S(   N(   R   (   R   R   R
   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyR   §   s    c         C@  s   t  |  t k rw | \ } } | | k r8 | | d <q | | k r x- | | k  rp | | t |  <| d 7} qG Wq n
 | | | <d  S(   NR6   i   (   t   typet   tuplet   unichr(   R   R
   R&   R   R   t   code0t   code1(    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyt   add_transitionsͺ   s    c         C@  s   |  j  | S(   N(   R   (   R   R   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyR   Ά   s    c         C@  s   | j  d  | j  d  xD t |  j j    D]- \ } } | j  d t |  | d f  q0 Wx! |  j D] } |  j | |  qk Wd  S(   Ns   Plex.FastMachine:
s      Initial states:
s         %s: %s
R   (   R   R   R   R   t   reprR   t
   dump_state(   R   R   R   R
   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyR   Ή   s    "%c         C@  sS   | j  d | d  |  j | |  | d } | d  k	 rO | j  d |  n  d  S(   Ns      State %d:
R   R#   s	         %s
(   R   t   dump_transitionsR   (   R   R
   R   R#   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyRC   Α   s
    
c         C@  s‘  i  } i  } x | j    D] \ } } t |  d k r | j t |  d   } | d  k rt g  } | | t |  <n  | j |  q t |  d k r | | | <q q Wi  } xK |  j D]@ } | j t |  d   }	 |	 r· |  j |	  }
 | | |
 <q· q· W| j   } | j	   xB | D]: }
 |  j
 |
  } | |
 } | j d | | d f  qWxD d	 D]< } | j | d   } | r]| j d | | d f  q]q]Wd  S(
   Ni   i   s         %s --> State %d
R   R3   R4   R5   R6   (   R3   s   eols   eofs   else(   R   t   lent   gett   idR   R   R   t   chars_to_rangest   keyst   sortt   ranges_to_stringR   (   R   R
   R   t   chars_leading_to_statet   special_to_statet   cR   t   charst   ranges_to_statet	   char_listt   rangest   ranges_listt   key(    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyRD   Λ   s6    

c         C@  sΏ   | j    d } t |  } g  } x | | k  r΄ t | |  } | } | d 7} x> | | k  r t | |  | d k r | d 7} | d 7} qT W| j t |  t |  f  q% Wt |  S(   Ni    i   (   RJ   RE   t   ordR   t   chrR=   (   R   RQ   t   iR   R;   t   c1t   c2(    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyRH   θ   s    

)
#c         C@  s   d j  t |  j |   S(   Nt   ,(   t   joint   mapt   range_to_string(   R   t
   range_list(    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyRK   χ   s    c         C@  s@   | \ } } | | k r" t  |  Sd t  |  t  |  f Sd  S(   Ns   %s..%s(   RB   (   R   t   range_tupleRX   RY   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyR]   ϊ   s    
N(   R   R   R   R   R   R   R8   R9   R   R   R   R   R   RA   R   R   RC   RD   RH   RK   R]   (    (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyR2      s$   &							
			(   t
   __future__R    t   syst   TransitionsR   R   R   t   ImportErrorR>   t	   NameErrorRV   R!   t   objectR   R   R2   (    (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Machines.pyt   <module>	   s   
-@