
    EȂi                     T    S r SSKrSSKrSSKJr  SSKrSSKJr  S rS r	S r
S	S jrg)
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)SQLParseErrorc                     / SQn [         R                  " SSSS9nUR                  SSSS	9  UR                  S
SSSSS9  UR                  SSSSSS9  UR                  SS[        R                  S9  UR                  S5      nUR                  SSSSU SR                  SR                  S  U  5       5      5      S!9  UR                  S"S#SS$U S%R                  SR                  S& U  5       5      5      S!9  UR                  S'S(S)S*S+S,/S-S!9  UR                  S.S/SSS0S9  UR                  S1S2S3SSS4S9  UR                  S5S6S7[        S8S99  UR                  S:S;SSS<S9  UR                  S=S>SSS?S9  UR                  S@SASSSBSC9  UR                  SDSESSSFSC9  UR                  SGSHSI[        SJS99  UR                  SKSLS[        SMS99  UR                  SNSOS[        SPS99  UR                  SQSRSSSTSU9  U$ )VN)upperlower
capitalize	sqlformatzEFormat FILE according to OPTIONS. Use "-" as FILE to read from stdin.z"%(prog)s [OPTIONS] FILE [FILE ...])progdescriptionusagefilename+z%file(s) to format (use "-" for stdin))nargshelpz-oz	--outfileoutfileFILEz)write output to FILE (defaults to stdout))destmetavarr   z
--in-placeinplace
store_trueFz0format files in-place (overwrite existing files))r   actiondefaultr   z	--versionversion)r   r   zFormatting Optionsz-kz
--keywordsCHOICEkeyword_casez,change case of keywords, CHOICE is one of {}z, c              3   ,   #    U H  nS U S 3v   M     g7f"N .0xs     =D:\sksbv-state-backend\venv\Lib\site-packages\sqlparse/cli.py	<genexpr> create_parser.<locals>.<genexpr>G        61!Ah   )r   r   choicesr   z-iz--identifiersidentifier_casez/change case of identifiers, CHOICE is one of {}c              3   ,   #    U H  nS U S 3v   M     g7fr   r   r    s     r#   r$   r%   O   r&   r'   z-lz
--languageLANGoutput_formatpythonphpzJoutput a snippet in programming language LANG, choices are "python", "php"z--strip-commentsstrip_commentszremove commentsz-rz
--reindentreindentzreindent statementsz--indent_widthindent_width   z(indentation width (defaults to 2 spaces))r   r   typer   z--indent_after_firstindent_after_firstz2indent after first line of statement (e.g. SELECT)z--indent_columnsindent_columnsz<indent all columns by indent_width instead of keyword lengthz-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	--compactcompactz2Try to produce more compact output (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_groupformatjoinintbool)_CASE_CHOICESparsergroups      r#   create_parserrG      s   4M$$*2	F 4  6
 k8	  : ?  A $$  &
 %%&:;E	l;BBII6668  9 
o>EEII6668  9 
l5!+  , 
    
l"  $ 
7  9 
!A  C 
K  M 
"4	  6 
,9	  ; 
9  ; 
<  > 
A  C 
9	  ; M    c                 J    [         R                  R                  SU  S35        g)z5Print msg and optionally exit with return code exit_.z[ERROR] 
   )sysstderrwrite)msgs    r#   _errorrP      s     JJxuB'(rH   c                    U S:X  a  UR                   (       a  [        S5      $ U S:X  aN  [        [        R                  R
                  UR                  S9n UR                  5       nUR                  5         O< [        XR                  S9 nSR                  UR                  5       5      nSSS5        SnUR                   (       a   [        U S	UR                  S9nS
nODUR                  (       a#   [        UR                  S	UR                  S9nS
nO[        R                  n[        U5      n [         R"                  R%                  U5      n[         R(                  " W40 UD6n	UR+                  U	5        UR-                  5         U(       a  UR/                  5         g! UR                  5         f = f! , (       d  f       GN= f! [         a  n[        SU  SU 35      s SnA$ SnAff = f! [         a  n[        SU  SU 35      s SnA$ SnAff = f! [         a%  n[        SUR                   SU 35      s SnA$ SnAff = f! [&         a  n[        SU 35      s SnA$ SnAff = f)z\Process a single file with the given formatting options.

Returns 0 on success, 1 on error.
-z Cannot use --in-place with stdin)r9    NzFailed to read z: FwTzFailed to open zInvalid options: r   )r   rP   r   rL   stdinbufferr9   readdetachopenrA   	readlinesOSErrorr   stdoutvarsr=   	formattervalidate_optionsr   r@   rN   flushclose)
r   argswrapperdatafeclose_streamstreamformatter_optsss
             r#   _process_filerk      s    34<<899 3		 0 04==I	<<>DNN	=h71wwq{{}- 8 L||	=(C$--@FL 
	A$,,dmmDFL  $ZN/!++<<^L 	//A
LLO
LLNK NN 87 	=OH:Rs;<<	=  	=OH:Rs;<<	=  	AODLL>A3?@@	A  /)!-../s   F 8G  F3+G G- 1!H /I F03
G=G G 
G*G%G*%G*-
H7HHH
IH?9I?I
I)I$I)$I)c                 2   [        5       nUR                  U 5      n [        U R                  5      S:  a8  U R                  (       a  [        S5      $ U R                  (       d  [        S5      $ SnU R                   H  n[        X05      nUS:w  d  M  UnM     U$ )NrK   z+Cannot use -o/--outfile with multiple filesz&Multiple files require --in-place flagr   )rG   
parse_argslenr   r   rP   r   rk   )rb   rE   	exit_coder   results        r#   mainrq      s    _FT"D 4==A<<GHH||BCC IMMx.Q;I " rH   )N)__doc__r:   rL   ior   r=   sqlparse.exceptionsr   rG   rP   rk   rq   r   rH   r#   <module>ru      s2     
   -
EP4nrH   