
    h                     h    d Z ddlZddlZddlmZ ddlmZmZ ddlZddl	m
Z
 ddlmZ d Zd Zd
d	Zy)ae  Module that contains the command line app.

Why does this file exist, and why not put this in __main__?
  You might be tempted to import things from __main__ later, but that will
  cause problems: the code will get executed twice:
  - When you run `python -m sqlparse` python will execute
    ``__main__.py`` as a script. That means there won't be any
    ``sqlparse.__main__`` in ``sys.modules``.
  - When you import __main__ it will get executed again (as a module) because
    there's no ``sqlparse.__main__`` in ``sys.modules``.
  Also see (1) from http://click.pocoo.org/5/setuptools/#setuptools-integration
    N)TextIOWrapper)open	getreader)PY2)SQLParseErrorc                     g d} t        j                  ddd      }|j                  d       |j                  ddd	d
d       |j                  ddt        j                         |j                  d      }|j                  dddd| dj                  dj                  d | D                           |j                  dddd| dj                  dj                  d | D                           |j                  ddd d!d"d#gd$       |j                  d%d&d'd(d)*       |j                  d+d,d-d'd(d.*       |j                  d/d0d1t        d23       |j                  d4d5d'd(d67       |j                  d8d9d'd(d:7       |j                  d;d<d=t        d>3       |j                  d?d@d(t        dA3       |j                  dBdCdDdEF       |S )GN)upperlower
capitalize	sqlformatzEFormat FILE according to OPTIONS. Use "-" as FILE to read from stdin.z%(prog)s  [OPTIONS] FILE, ...)progdescriptionusagefilenamez-oz	--outfileoutfileFILEz)write output to FILE (defaults to stdout))destmetavarhelpz	--versionversion)actionr   zFormatting Optionsz-kz
--keywordsCHOICEkeyword_casez-change case of keywords, CHOICE is one of {0}z, c              3   >   K   | ]  }d j                  |        ywz"{0}"Nformat.0xs     O/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/sqlparse/cli.py	<genexpr>z create_parser.<locals>.<genexpr>A        ?AgnnQ'?   )r   r   choicesr   z-iz--identifiersidentifier_casez0change case of identifiers, CHOICE is one of {0}c              3   >   K   | ]  }d j                  |        ywr   r   r   s     r!   r"   z create_parser.<locals>.<genexpr>I   r#   r$   z-lz
--languageLANGoutput_formatpythonphpzJoutput a snippet in programming language LANG, choices are "python", "php"z--strip-commentsstrip_comments
store_trueFzremove comments)r   r   defaultr   z-rz
--reindentreindentzreindent statementsz--indent_widthindent_width   z(indentation width (defaults to 2 spaces))r   r.   typer   z-az--reindent_alignedz%reindent statements to aligned format)r   r.   r   z-sz--use_space_around_operatorsz*place spaces around mathematical operatorsz--wrap_after
wrap_afterr   z*Column after which lists should be wrappedz--comma_firstcomma_firstz-Insert linebreak before comma (default False)z
--encodingencodingzutf-8z*Specify the input encoding (default utf-8))r   r.   r   )
argparseArgumentParseradd_argumentsqlparse__version__add_argument_groupr   joinintbool)_CASE_CHOICESparsergroups      r!   create_parserrB   "   se   4M$$*-	F 
#
k8	  : $$  &
 %%&:;E	l<CCII???A  B 
o?FFII???A  B 
l5!+  , 
    
l"  $ 
7  9 
"4	  6 
,9	  ; 
9  ; 
<  > 
9	  ; M    c                 `    t         j                  j                  dj                  |              y)z5Print msg and optionally exit with return code exit_.z[ERROR] {0}
   )sysstderrwriter   )msgs    r!   _errorrJ      s#    JJ%,,S12rC   c                    t               }|j                  |       } | j                  dk(  r|t        r8 t	        | j
                        t        j                        j                         }nt        t        j                  j                  | j
                        j                         }nJ	 t        | j                  d| j
                        5 }dj                  |j                               }d d d        d}| j"                  r%	 t        | j"                  d| j
                        }d}nt        j$                  }t'        |       }	 t(        j*                  j-                  |      }t)        j                   fi |}|j1                  |       |j3                          |r|j5                          y# 1 sw Y   xY w# t        $ r/}t        dj!                  | j                  |            cY d }~S d }~ww xY w# t        $ r/}t        d	j!                  | j"                  |            cY d }~S d }~ww xY w# t.        $ r$}t        d
j!                  |            cY d }~S d }~ww xY w)N-)r5   r zFailed to read {0}: {1}FwTzFailed to open {0}: {1}zInvalid options: {0}r   )rB   
parse_argsr   r   r   r5   rF   stdinreadr   bufferr   r<   	readlinesIOErrorrJ   r   r   stdoutvarsr9   	formattervalidate_optionsr   rH   flushclose)	argsr@   datafeclose_streamstreamformatter_optsss	            r!   mainrd      s   _FT"D}}+9T]]+CII6;;=D 		  4==::>$& 	EdmmS$--8 .Awwq{{}-. L||	N$,,T]];FL $ZN9!++<<^L 	//A
LLO
LLN7. . 	E*11$--CE E	E  	N4;;DLL!LMM	N  9-44Q7889sr   (!F5 	 F))F5  #G0  H+ )F2.F5 5	G->$G("G-(G-0	H(9$H#H(#H(+	I4III)N)__doc__r6   rF   ior   codecsr   r   r9   sqlparse.compatr   sqlparse.exceptionsr   rB   rJ   rd    rC   r!   <module>rk      s2     
  "   -
fR'rC   