
    k"gg                     `    d Z ddlZddlmZ ddlmZ ddlmZmZ ddl	m
Z
  G d d      Zd
d	Zy)z	SQL Lexer    N)Lock)
TextIOBase)tokenskeywords)consumec                   X    e Zd ZdZdZ e       Zed        Zd Z	d Z
d Zd Zd Zd
d	Zy)LexerzrThe Lexer supports configurable syntax.
    To add support for additional keywords, use the `add_keywords` method.Nc                     | j                   5  | j                  & |        | _        | j                  j                          ddd       | j                  S # 1 sw Y   | j                  S xY w)zRReturns the lexer instance used internally
        by the sqlparse core functions.N)_lock_default_instancedefault_initialization)clss    G/var/www/html/djangosite/lib/python3.12/site-packages/sqlparse/lexer.pyget_default_instancezLexer.get_default_instance0   s_     YY 	?$$,(+%%%<<>	? $$$		? $$$s   3AA(c                    | j                          | j                  t        j                         | j	                  t        j
                         | j	                  t        j                         | j	                  t        j                         | j	                  t        j                         | j	                  t        j                         | j	                  t        j                         | j	                  t        j                         | j	                  t        j                         | j	                  t        j                         y)zlInitialize the lexer with default dictionaries.
        Useful if you need to revert custom syntax settings.N)clearset_SQL_REGEXr   	SQL_REGEXadd_keywordsKEYWORDS_COMMONKEYWORDS_ORACLEKEYWORDS_MYSQLKEYWORDS_PLPGSQLKEYWORDS_HQLKEYWORDS_MSACCESSKEYWORDS_SNOWFLAKEKEYWORDS_BIGQUERYKEYWORDSselfs    r   r   zLexer.default_initialization:   s     	

8--.(223(223(112(334(//0(445(556(445(++,    c                      g | _         g | _        y)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	_keywordsr   s    r   r   zLexer.clearI   s    
 r!   c                     t         j                  t         j                  z  }|D cg c]'  \  }}t        j                  ||      j                  |f) c}}| _        yc c}}w )z.Set the list of regex that will parse the SQL.N)re
IGNORECASEUNICODEcompilematchr#   )r    r   FLAGSrxtts        r   r   zLexer.set_SQL_REGEXQ   sO    

* $
B ZZE"(("-
 
s   ,Ac                 :    | j                   j                  |       y)zhAdd keyword dictionaries. Keywords are looked up in the same order
        that dictionaries were added.N)r$   append)r    r   s     r   r   zLexer.add_keywordsY   s     	h'r!   c                     |j                         }| j                  D ]  }||v s||   |fc S  t        j                  |f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.
        )upperr$   r   Name)r    valuevalkwdicts       r   
is_keywordzLexer.is_keyword^   sI     kkmnn 	&Ff}c{E))	& ;;%%r!   c              #     K   t        |t              r|j                         }t        |t              rnZt        |t              r'|r|j                  |      }n6	 |j                  d      }n#t        dj                  t        |                  t        |      }|D ]  \  }}| j                  D ]  \  }} |||      }|st        |t        j                        r||j                         f n3|t        j                   u r!| j#                  |j                                t%        ||j'                         |z
  dz
           t        j(                  |f  y# t        $ r |j                  d      }Y w xY ww)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   
_TokenTypegroupr   PROCESS_AS_KEYWORDr6   r   endError)	r    textencodingiterableposcharrexmatchactionms	            r   
get_tokenszLexer.get_tokensk   sP     dJ'99;DdC e${{8,9;;w/D I"F4:.0 0 T?! 	)IC$(OO ) &T3'(9(9: !'')++x::://!'')44!%%'C-!"34) llD((	) * 9;;'78D9s+   AE;E *C1E;E85E;7E88E;N)__name__
__module____qualname____doc__r   r   r   classmethodr   r   r   r   r   r6   rP    r!   r   r	   r	      sI    N FE( % %-
(
&-)r!   r	   c                 J    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   rP   )sqlrI   s     r   tokenizerZ      s      %%'223AAr!   rQ   )rU   r&   	threadingr   ior   sqlparser   r   sqlparse.utilsr   r	   rZ   rW   r!   r   <module>r_      s.     	   % "A) A)HBr!   