3
g                 @   sP   d Z ddlZddlmZ ddlmZmZ ddlmZ G dd dZ	d
dd	Z
dS )z	SQL Lexer    N)
TextIOBase)tokenskeywords)consumec               @   sR   e Zd ZdZdZedd Zdd Zdd Zd	d
 Z	dd Z
dd ZdddZdS )LexerzrThe Lexer supports configurable syntax.
    To add support for additional keywords, use the `add_keywords` method.Nc             C   s"   | j dkr|  | _ | j j  | j S )zRReturns the lexer instance used internally
        by the sqlparse core functions.N)_default_intancedefault_initialization)cls r
   L/var/www/tester-filtro-web/env/lib/python3.6/site-packages/sqlparse/lexer.pyget_default_instance.   s    

zLexer.get_default_instancec             C   s`   | j   | jtj | jtj | jtj | jtj | jtj | jtj	 | jtj
 dS )zlInitialize the lexer with default dictionaries.
        Useful if you need to revert custom syntax settings.N)clearset_SQL_REGEXr   	SQL_REGEXadd_keywordsZKEYWORDS_COMMONZKEYWORDS_ORACLEZKEYWORDS_PLPGSQLZKEYWORDS_HQLZKEYWORDS_MSACCESSZKEYWORDS)selfr
   r
   r   r   7   s    zLexer.default_initializationc             C   s   g | _ g | _dS )zClear all syntax configurations.
        Useful if you want to load a reduced set of syntax configurations.
        After this call, regexps and keyword dictionaries need to be loaded
        to make the lexer functional again.N)
_SQL_REGEX	_keywords)r   r
   r
   r   r   C   s    zLexer.clearc                s$   t jt jB   fdd|D | _dS )z.Set the list of regex that will parse the SQL.c                s"   g | ]\}}t j| j|fqS r
   )recompilematch).0rxtt)FLAGSr
   r   
<listcomp>O   s   z'Lexer.set_SQL_REGEX.<locals>.<listcomp>N)r   
IGNORECASEUNICODEr   )r   r   r
   )r   r   r   K   s    
zLexer.set_SQL_REGEXc             C   s   | j j| dS )zhAdd keyword dictionaries. Keywords are looked up in the same order
        that dictionaries were added.N)r   append)r   r   r
   r
   r   r   S   s    zLexer.add_keywordsc             C   s:   |j  }x,| jD ]}||kr|| |fS qW tj|fS dS )zChecks for a keyword.

        If the given value is in one of the KEYWORDS_* dictionary
        it's considered a keyword. Otherwise, tokens.Name is returned.
        N)upperr   r   Name)r   valuevalZkwdictr
   r
   r   
is_keywordX   s
    zLexer.is_keywordc       	      c   s  t |tr|j }t |trn\t |trh|r8|j|}qzy|jd}W qz tk
rd   |jd}Y qzX ntdjt	|t
|}x|D ]\}}x~| jD ]h\}}|||}|sqn6t |tjr||j fV  n|tjkr| j|j V  t||j | d  P qW tj|fV  qW dS )a  
        Return an iterable of (tokentype, value) pairs generated from
        `text`. If `unfiltered` is set to `True`, the filtering mechanism
        is bypassed even if filters are defined.

        Also preprocess the text, i.e. expand tabs and strip it if
        wanted and applies registered filters.

        Split ``text`` into (tokentype, text) pairs.

        ``stack`` is the initial stack (default: ``['root']``)
        zutf-8zunicode-escapez+Expected text or file-like object, got {!r}   N)
isinstancer   readstrbytesdecodeUnicodeDecodeError	TypeErrorformattype	enumerater   r   Z
_TokenTypegroupr   ZPROCESS_AS_KEYWORDr#   r   endError)	r   textencodingiterableposcharZrexmatchactionmr
   r
   r   
get_tokense   s4    




zLexer.get_tokens)N)__name__
__module____qualname____doc__r   classmethodr   r   r   r   r   r#   r9   r
   r
   r
   r   r      s   	r   c             C   s   t j j| |S )zTokenize sql.

    Tokenize *sql* using the :class:`Lexer` and return a 2-tuple stream
    of ``(token type, value)`` items.
    )r   r   r9   )Zsqlr3   r
   r
   r   tokenize   s    r?   )N)r=   r   ior   Zsqlparser   r   Zsqlparse.utilsr   r   r?   r
   r
   r
   r   <module>   s   