
vÅÏ^µ  ã               @   sß   d  d l  Z  d  d l Z d  d l m Z d  d l m Z d  d l m Z e j d e j	 ƒ Z
 e j d ƒ Z d d „  Z d	 d
 „  Z d d „  Z d d d d d „ Z d d „  Z e d  d d „ ƒ Z e d d d „ ƒ Z d S)é    N)Údeque)Úcontextmanager)Ú	text_typeaZ  
(
 (?:                     # Start of non-capturing group
  (?:\r\n|\r|\n)      |  # Match any single newline, or
  [^\r\n'"]+          |  # Match any character series without quotes or
                         # newlines, or
  "(?:[^"\\]|\\.)*"   |  # Match double-quoted strings, or
  '(?:[^'\\]|\\.)*'      # Match single quoted strings
 )
)
z(\r\n|\r|\n)c             C   sr   t  |  ƒ } t j | ƒ } d g } xG | D]? } | s= q+ q+ t j | ƒ r\ | j d ƒ q+ | d | 7<q+ W| S)z™Split a string on all unquoted newlines.

    Unlike str.splitlines(), this will ignore CR/LF/CR+LF if the requisite
    character is inside of a string.Ú é   éÿÿÿÿ)r   ÚSPLIT_REGEXÚsplitÚ
LINE_MATCHÚmatchÚappend)ÚstmtÚtextÚlinesZoutputlinesÚline© r   ú2/tmp/pip-build-8lau8j11/sqlparse/sqlparse/utils.pyÚsplit_unquoted_newlines&   s    	r   c             C   sH   |  d k r d S|  d d k rD |  d |  d k rD |  d d … }  |  S)	z4Helper that removes surrounding quotes from strings.Nr   ú"ú'r   )r   r   r   r   r   )Úvalr   r   r   Úremove_quotes8   s
    $r   c                 s   ‡  f d d †  } | S)zqFunction decorator to help with recursion

    :param cls: Classes to not recurse over
    :return: function
    c                s   ‡ ‡  ‡ f d d †  ‰ ˆ S)Nc                s>   x- |  j  ƒ  D] } t | ˆ  ƒ s ˆ | ƒ q Wˆ |  ƒ d  S)N)Zget_sublistsÚ
isinstance)ZtlistZsgroup)ÚclsÚfÚ	wrapped_fr   r   r   H   s    z(recurse.<locals>.wrap.<locals>.wrapped_fr   )r   )r   )r   r   r   ÚwrapG   s    zrecurse.<locals>.wrapr   )r   r   r   )r   r   ÚrecurseA   s    	r   c                sÓ   | } | r% t  | t ƒ r% | g n | } | rJ t  | t ƒ rJ | g n | } ˆ  d k r` d S| ry t  ˆ  | ƒ ry d S| r¢ t ‡  f d d †  | Dƒ ƒ r¢ d S| rË t ‡  f d d †  | Dƒ ƒ rË d Sd Sd S)a  Helper function to simplify comparisons Instance, Match and TokenType
    :param token:
    :param i: Class or Tuple/List of Classes
    :param m: Tuple of TokenType & Value. Can be list of Tuple for multiple
    :param t: TokenType or Tuple/List of TokenTypes
    :return:  bool
    NFTc             3   s   |  ] } ˆ  j  | Œ  Vq d  S)N)r   )Ú.0Úpattern)Útokenr   r   ú	<genexpr>c   s    zimt.<locals>.<genexpr>c             3   s   |  ] } ˆ  j  | k Vq d  S)N)Úttype)r   r"   )r    r   r   r!   e   s    )r   ÚlistÚany)r    ÚiÚmÚtZclssÚtypesZ	mpatternsr   )r    r   ÚimtS   s    %%%%r)   c             C   s    t  t j |  | ƒ d d ƒd S)zCAdvance the iterator n-steps ahead. If n is none, consume entirely.Úmaxlenr   N)r   Ú	itertoolsÚislice)ÚiteratorÚnr   r   r   Úconsumek   s    r/   c             c   s'   |  j  | 7_  d  V|  j  | 8_  d  S)N)Úoffset)Úfilter_r.   r   r   r   r0   p   s    r0   r   c             c   s'   |  j  | 7_  d  V|  j  | 8_  d  S)N)Úindent)r1   r.   r   r   r   r2   w   s    r2   )r+   ÚreÚcollectionsr   Ú
contextlibr   Zsqlparse.compatr   ÚcompileÚVERBOSEr   r
   r   r   r   r)   r/   r0   r2   r   r   r   r   Ú<module>	   s    

	