ó
Nä²Wc           @@  s\  d  d l  m Z d  d l Z y d  d l m Z Wn! e k
 rS d  d l m Z n Xd d l m Z d Z	 d Z
 d	 Z e d
 ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z d e f d „  ƒ  YZ d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ e ƒ  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d  „  ƒ  YZ e ƒ  Z d! e _ d" e _  d# „  Z! d$ „  Z" d% „  Z# d& „  Z$ e$ d' ƒ Z% d( e% _ d) e% _  d d* „ Z' d+ „  Z( d, „  Z) d- „  Z* d. „  Z+ e e	 ƒ Z, d/ e, _ d0 e, _  e e
 ƒ Z- d1 e- _ d2 e- _  e e ƒ Z. d3 e. _ d4 e. _  d S(5   i    (   t   absolute_importN(   t   maxsize(   t   maxinti   (   t   Errorst   bolt   eolt   eofs   
c         C@  sÀ   t  |  ƒ } | j ƒ  d } t | ƒ } g  } x‹ | | k  r» t | | ƒ } | d } | d 7} x: | | k  r | t | | ƒ k r | d 7} | d 7} qd W| j | ƒ | j | ƒ q1 W| S(   s’   
    Return a list of character codes consisting of pairs
    [code1a, code1b, code2a, code2b,...] which cover all
    the characters in |s|.
    i    i   (   t   listt   sortt   lent   ordt   append(   t   st	   char_listt   it   nt   resultt   code1t   code2(    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   chars_to_ranges"   s    


%
c         C@  sj   t  |  t d ƒ ƒ } t | t d ƒ d ƒ } | | k  rb t d ƒ t d ƒ } | | | | f Sd Sd S(   sŠ   
    If the range of characters from code1 to code2-1 includes any
    lower case letters, return the corresponding upper case range.
    t   at   zi   t   AN(   t   maxR
   t   mint   None(   R   R   t   code3t   code4t   d(    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   uppercase_range9   s    c         C@  sj   t  |  t d ƒ ƒ } t | t d ƒ d ƒ } | | k  rb t d ƒ t d ƒ } | | | | f Sd Sd S(   sŠ   
    If the range of characters from code1 to code2-1 includes any
    upper case letters, return the corresponding lower case range.
    R   t   Zi   R   N(   R   R
   R   R   (   R   R   R   R   R   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   lowercase_rangeG   s    c         C@  sJ   g  t  d t |  ƒ d ƒ D]! } t |  | |  | d ƒ ^ q } t | Œ  S(   sƒ   
    Given a list of codes as returned by chars_to_ranges, return
    an RE which will match a character in any of the ranges.
    i    i   i   (   t   rangeR	   t	   CodeRanget   Alt(   t	   code_listR   t   re_list(    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt
   CodeRangesU   s    @c         C@  sS   |  t  k o | k  n rB t t |  t  ƒ t t t  d | ƒ ƒ St |  | ƒ Sd S(   s   
    CodeRange(code1, code2) is an RE which matches any character
    with a code |c| in the range |code1| <= |c| < |code2|.
    i   N(   t   nl_codeR"   t   RawCodeRanget
   RawNewline(   R   R   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR!   ^   s
    t   REc           B@  sq   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 RS(   s  RE is the base class for regular expression constructors.
    The following operators are defined on REs:

         re1 + re2         is an RE which matches |re1| followed by |re2|
         re1 | re2         is an RE which matches either |re1| or |re2|
    i   c         C@  s   t  d |  j j ƒ ‚ d S(   sM  
        This method should add states to |machine| to implement this
        RE, starting at |initial_state| and ending at |final_state|.
        If |match_bol| is true, the RE must be able to match at the
        beginning of a line. If nocase is true, upper and lower case
        letters should be treated as equivalent.
        s    %s.build_machine not implementedN(   t   NotImplementedErrort	   __class__t   __name__(   t   selft   machinet   initial_statet   final_statet	   match_bolt   nocase(    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   build_machine{   s    	c         C@  s-   | j  ƒ  } | j | ƒ | j | | ƒ | S(   s~   
        Given a state |s| of machine |m|, return a new state
        reachable from |s| on character |c| or epsilon.
        (   t	   new_statet   link_tot   add_transition(   R-   t   mR/   t   cR   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt	   build_opt‡   s    c         C@  s   t  |  | ƒ S(   N(   t   Seq(   R-   t   other(    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   __add__‘   s    c         C@  s   t  |  | ƒ S(   N(   R"   (   R-   R;   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   __or__”   s    c         C@  s   |  j  r |  j  S|  j ƒ  Sd  S(   N(   t   strt   calc_str(   R-   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   __str__—   s    	c         C@  s)   t  | t ƒ s% |  j | | d ƒ n  d  S(   Ns   Plex.RE instance(   t
   isinstanceR)   t
   wrong_type(   R-   t   numt   value(    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   check_re   s    c         C@  s2   t  | ƒ t  d ƒ k r. |  j | | d ƒ n  d  S(   Nt    t   string(   t   typeRB   (   R-   RC   RD   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   check_string¡   s    c         C@  sQ   |  j  | | ƒ t | ƒ d k rM t j d | |  j j t | ƒ f ƒ ‚ n  d  S(   Ni   sO   Invalid value for argument %d of Plex.%s.Expected a string of length 1, got: %s(   RI   R	   R   t   PlexValueErrorR+   R,   t   repr(   R-   RC   RD   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt
   check_char¥   s    	c         C@  sl   t  | ƒ t j k r4 d | j j | j j f } n t  | ƒ j } t j d | |  j j | | f ƒ ‚ d  S(   Ns   %s.%s instances<   Invalid type for argument %d of Plex.%s (expected %s, got %s(   RH   t   typest   InstanceTypeR+   t
   __module__R,   R   t   PlexTypeError(   R-   RC   RD   t   expectedt   got(    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyRB   ¬   s    	N(   R,   RO   t   __doc__t   nullablet   match_nlR   R>   R3   R9   R<   R=   R@   RE   RI   RL   RB   (    (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR)   o   s   		
						c         C@  sW   t  |  ƒ d k r4 t t |  ƒ t |  ƒ d ƒ } n t |  ƒ } d t |  ƒ | _ | S(   s;   
    Char(c) is an RE which matches the character |c|.
    i   s   Char(%s)(   R	   R!   R
   t   SpecialSymbolRK   R>   (   R8   R   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   CharÝ   s
    "R'   c           B@  sG   e  Z d  Z d Z d Z d Z d Z d Z d „  Z	 d „  Z
 d „  Z RS(   sÒ   
    RawCodeRange(code1, code2) is a low-level RE which matches any character
    with a code |c| in the range |code1| <= |c| < |code2|, where the range
    does not include newline. For internal use only.
    i    c         C@  s7   | | f |  _  t | | ƒ |  _ t | | ƒ |  _ d  S(   N(   R    R   R   (   R-   R   R   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   __init__õ   s    c         C@  s|   | r |  j  | | t ƒ } n  | j |  j | ƒ | rx |  j rV | j |  j | ƒ n  |  j rx | j |  j | ƒ qx n  d  S(   N(   R9   t   BOLR6   R    R   R   (   R-   R7   R/   R0   R1   R2   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR3   ú   s    		c         C@  s   d |  j  |  j f S(   Ns   CodeRange(%d,%d)(   R   R   (   R-   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR?     s    N(   R,   RO   RS   RT   RU   R   R    R   R   RX   R3   R?   (    (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR'   é   s   		
t   _RawNewlinec           B@  s#   e  Z d  Z d Z d Z d „  Z RS(   sd   
    RawNewline is a low-level RE which matches a newline character.
    For internal use only.
    i    i   c         C@  sQ   | r |  j  | | t ƒ } n  |  j  | | t ƒ } | j t t d f | ƒ d  S(   Ni   (   R9   RY   t   EOLR6   R&   (   R-   R7   R/   R0   R1   R2   R   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR3     s    (   R,   RO   RS   RT   RU   R3   (    (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyRZ     s   RV   c           B@  s2   e  Z d  Z d Z d Z d Z d „  Z d „  Z RS(   sx   
    SpecialSymbol(sym) is an RE which matches the special input
    symbol |sym|, which is one of BOL, EOL or EOF.
    i    c         C@  s   | |  _  d  S(   N(   t   sym(   R-   R\   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyRX   #  s    c         C@  sD   | r- |  j  t k r- |  j | | t ƒ } n  | j |  j  | ƒ d  S(   N(   R\   R[   R9   RY   R6   (   R-   R7   R/   R0   R1   R2   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR3   &  s    N(	   R,   RO   RS   RT   RU   R   R\   RX   R3   (    (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyRV     s   	R:   c           B@  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s]   Seq(re1, re2, re3...) is an RE which matches |re1| followed by
    |re2| followed by |re3|...c         G@  s´   d } x9 t  | ƒ D]+ \ } } |  j | | ƒ | o; | j } q W| |  _ | |  _ t | ƒ } d } x> | r¦ | d 8} | | } | j r– d } Pn  | j si Pqi qi W| |  _ d  S(   Ni   i    (   t	   enumerateRE   RT   R$   R	   RU   (   R-   R$   RT   R   t   reRU   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyRX   2  s"    			

		c         C@  sº   |  j  } t | ƒ d k r+ | j | ƒ n‹ | } t | ƒ } xv t | ƒ D]h \ }	 }
 |	 | d k  ru | j ƒ  } n | } |
 j | | | | | ƒ | } |
 j p¯ | o¯ |
 j } qJ Wd  S(   Ni    i   (   R$   R	   R5   R]   R4   R3   RU   RT   (   R-   R7   R/   R0   R1   R2   R$   t   s1R   R   R^   t   s2(    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR3   E  s    	c         C@  s   d d j  t t |  j ƒ ƒ S(   Ns   Seq(%s)t   ,(   t   joint   mapR>   R$   (   R-   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR?   U  s    (   R,   RO   RS   RX   R3   R?   (    (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR:   .  s   		R"   c           B@  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sR   Alt(re1, re2, re3...) is an RE which matches either |re1| or
    |re2| or |re3|...c         G@  s¸   | |  _  d } d } g  } g  } d } xf | D]^ } |  j | | ƒ | j rc | j | ƒ d } n | j | ƒ | j r‚ d } n  | d 7} q. W| |  _ | |  _ | |  _ | |  _ d  S(   Ni    i   (   R$   RE   RT   R   RU   t   nullable_rest   non_nullable_res(   R-   R$   RT   RU   Rd   Re   R   R^   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyRX   ]  s&    								c         C@  sˆ   x* |  j  D] } | j | | | | | ƒ q
 W|  j r„ | rT |  j | | t ƒ } n  x- |  j D] } | j | | | d | ƒ q^ Wn  d  S(   Ni    (   Rd   R3   Re   R9   RY   (   R-   R7   R/   R0   R1   R2   R^   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR3   s  s    	c         C@  s   d d j  t t |  j ƒ ƒ S(   Ns   Alt(%s)Ra   (   Rb   Rc   R>   R$   (   R-   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR?   |  s    (   R,   RO   RS   RX   R3   R?   (    (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR"   Y  s   			t   Rep1c           B@  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s@   Rep1(re) is an RE which matches one or more repetitions of |re|.c         C@  s5   |  j  d | ƒ | |  _ | j |  _ | j |  _ d  S(   Ni   (   RE   R^   RT   RU   (   R-   R^   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyRX   ƒ  s    	c         C@  sk   | j  ƒ  } | j  ƒ  } | j | ƒ |  j j | | | | pF |  j j | ƒ | j | ƒ | j | ƒ d  S(   N(   R4   R5   R^   R3   RU   (   R-   R7   R/   R0   R1   R2   R_   R`   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR3   ‰  s    (c         C@  s   d |  j  S(   Ns   Rep1(%s)(   R^   (   R-   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR?   ‘  s    (   R,   RO   RS   RX   R3   R?   (    (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyRf   €  s   		t
   SwitchCasec           B@  s5   e  Z d  Z d Z d Z d „  Z d „  Z d „  Z RS(   sÓ   
    SwitchCase(re, nocase) is an RE which matches the same strings as RE,
    but treating upper and lower case letters according to |nocase|. If
    |nocase| is true, case is ignored, otherwise it is not.
    c         C@  s.   | |  _  | |  _ | j |  _ | j |  _ d  S(   N(   R^   R2   RT   RU   (   R-   R^   R2   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyRX   ž  s    		c         C@  s#   |  j  j | | | | |  j ƒ d  S(   N(   R^   R3   R2   (   R-   R7   R/   R0   R1   R2   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR3   ¤  s    c         C@  s)   |  j  r d } n d } d | |  j f S(   Nt   NoCaset   Cases   %s(%s)(   R2   R^   (   R-   t   name(    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyR?   ¨  s    		N(	   R,   RO   RS   R   R^   R2   RX   R3   R?   (    (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyRg   •  s   		s8   
    Empty is an RE which matches the empty string.
    t   Emptyc         C@  s2   t  t t t |  ƒ ƒ Œ  } d t |  ƒ | _ | S(   s@   
    Str1(s) is an RE which matches the literal string |s|.
    s   Str(%s)(   R:   t   tupleRc   RW   RK   R>   (   R   R   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   Str1¾  s    c          G@  sb   t  |  ƒ d k r  t |  d ƒ St t t t |  ƒ ƒ Œ  } d d j t t |  ƒ ƒ | _ | Sd S(   sŽ   
    Str(s) is an RE which matches the literal string |s|.
    Str(s1, s2, s3, ...) is an RE which matches any of |s1| or |s2| or |s3|...
    i   i    s   Str(%s)Ra   N(   R	   Rm   R"   Rl   Rc   Rb   RK   R>   (   t   strsR   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   StrÇ  s
    c         C@  s)   t  t |  ƒ ƒ } d t |  ƒ | _ | S(   sH   
    Any(s) is an RE which matches any character in the string |s|.
    s   Any(%s)(   R%   R   RK   R>   (   R   R   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   AnyÔ  s    c         C@  sM   t  |  ƒ } | j d t ƒ | j t ƒ t | ƒ } d t |  ƒ | _ | S(   sp   
    AnyBut(s) is an RE which matches any character (including
    newline) which is not in the string |s|.
    i    s
   AnyBut(%s)(   R   t   insertR   R   R%   RK   R>   (   R   t   rangesR   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   AnyButÞ  s    RF   sT   
    AnyChar is an RE which matches any single character (including a newline).
    t   AnyCharc         C@  s¹   | r; t  t |  ƒ t | ƒ d ƒ } d |  | f | _ nz g  } xR t d t |  ƒ d ƒ D]8 } | j t  t |  | ƒ t |  | d ƒ d ƒ ƒ qZ Wt | Œ  } d t |  ƒ | _ | S(   s  
    Range(c1, c2) is an RE which matches any single character in the range
    |c1| to |c2| inclusive.
    Range(s) where |s| is a string of even length is an RE which matches
    any single character in the ranges |s[0]| to |s[1]|, |s[2]| to |s[3]|,...
    i   s   Range(%s,%s)i    i   s	   Range(%s)(   R!   R
   R>   R    R	   R   R"   RK   (   R_   R`   R   Rr   R   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   Rangeó  s    6c         C@  s    t  |  t ƒ } d |  | _ | S(   sI   
    Opt(re) is an RE which matches either |re| or the empty string.
    s   Opt(%s)(   R"   Rk   R>   (   R^   R   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   Opt  s    c         C@  s#   t  t |  ƒ ƒ } d |  | _ | S(   sJ   
    Rep(re) is an RE which matches zero or more repetitions of |re|.
    s   Rep(%s)(   Rv   Rf   R>   (   R^   R   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   Rep  s    c         C@  s   t  |  d d ƒS(   s€   
    NoCase(re) is an RE which matches the same strings as RE, but treating
    upper and lower case letters as equivalent.
    R2   i   (   Rg   (   R^   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyRh     s    c         C@  s   t  |  d d ƒS(   s¶   
    Case(re) is an RE which matches the same strings as RE, but treating
    upper and lower case letters as distinct, i.e. it cancels the effect
    of any enclosing NoCase().
    R2   i    (   Rg   (   R^   (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyRi      s    s=   
    Bol is an RE which matches the beginning of a line.
    t   Bols7   
    Eol is an RE which matches the end of a line.
    t   Eols9   
    Eof is an RE which matches the end of the file.
    t   Eof(/   t
   __future__R    RM   t   sysR   R   t   ImportErrorRF   R   RY   R[   t   EOFR
   R&   R   R   R   R%   R!   t   objectR)   RW   R'   RZ   R(   RV   R:   R"   Rf   Rg   Rk   RS   R>   Rm   Ro   Rp   Rs   Rt   R   Ru   Rv   Rw   Rh   Ri   Rx   Ry   Rz   (    (    (    s6   /bar/jli/Chip-seq/script/cython/Cython/Plex/Regexps.pyt   <module>	   sb   						n		+'!							
														