o
    µ„j  ã                   @   sZ   d Z ddlZddlZddlmZ ddlZddlmZ dd„ Zdd„ Z	d	d
„ Z
ddd„ZdS )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                  C   s¾  g d¢} t jdddd�}|jdddd	� |jd
ddddd� |jdddddd� |jddtjd� | d¡}|jdddd| d d d d!„ | D ƒ¡¡d"� |jd#d$dd%| d& d d'd!„ | D ƒ¡¡d"� |jd(d)d*d+d,d-gd.d"� |jd/d0ddd1d� |jd2d3d4ddd5d� |jd6d7d8td9d:� |jd;d<ddd=d� |jd>d?ddd@d� |jdAdBdddCdD� |jdEdFdddGdD� |jdHdIdJtdKd:� |jdLdMdt	dNd:� |jdOdPdt	dQd:� |jdRdSdTdUdV� |S )WN)Ú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                 s   ó   � | ]	}d |› d �V  qdS ©ú"N© ©Ú.0Úxr   r   úJ/var/www/html/django_cbt/venv/lib/python3.10/site-packages/sqlparse/cli.pyÚ	<genexpr>G   ó   € z create_parser.<locals>.<genexpr>)r   r   Úchoicesr   z-iz--identifiersÚidentifier_casez/change case of identifiers, CHOICE is one of {}c                 s   r   r   r   r   r   r   r!   r"   O   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Úgroupr   r   r!   Úcreate_parser   s  üýüûý
ÿûÿûûûûûûûüüûûûürB   c                 C   s   t j d| › d�¡ dS )z5Print msg and optionally exit with return code exit_.z[ERROR] Ú
é   )ÚsysÚstderrÚwrite)Úmsgr   r   r!   Ú_error¦   s   rI   c           
   
   C   s
  | dkr|j rtdƒS | dkr(ttjj|jd�}z
| ¡ }W | ¡  nB| ¡  w z t	| |jd��}d 
| ¡ ¡}W d  ƒ n1 sBw   Y  W n tyd } ztd| › d|› �ƒW  Y d}~S d}~ww d}|j r“zt	| d	|jd�}d
}W nM ty’ } ztd| › d|› �ƒW  Y d}~S d}~ww |jrÁzt	|jd	|jd�}d
}W n  tyÀ } ztd|j› d|› �ƒW  Y d}~S d}~ww tj}t|ƒ}ztj |¡}W n tyé } ztd|› �ƒW  Y d}~S d}~ww tj|fi |¤Ž}	| |	¡ | ¡  |�r| ¡  dS )zdProcess a single file with the given formatting options.

    Returns 0 on success, 1 on error.
    ú-z Cannot use --in-place with stdin)r4   Ú NzFailed to read z: FÚwTzFailed to open zInvalid options: r   )r   rI   r   rE   ÚstdinÚbufferr4   ÚreadÚdetachÚopenr<   Ú	readlinesÚOSErrorr   ÚstdoutÚvarsr8   Ú	formatterÚvalidate_optionsr   r;   rG   ÚflushÚclose)
r   ÚargsÚwrapperÚdataÚfÚeÚclose_streamÚstreamÚformatter_optsÚsr   r   r!   Ú_process_file¬   s^   
ÿ€ €ÿ €ÿ"€ÿ€ÿ
rc   c                 C   sd   t ƒ }| | ¡} t| jƒdkr| jrtdƒS | jstdƒS d}| jD ]}t|| ƒ}|dkr/|}q"|S )NrD   z+Cannot use -o/--outfile with multiple filesz&Multiple files require --in-place flagr   )rB   Ú
parse_argsÚlenr   r   rI   r   rc   )rZ   r@   Ú	exit_coder   Úresultr   r   r!   Úmainã   s   


€rh   )N)Ú__doc__r5   rE   Úior   r8   Úsqlparse.exceptionsr   rB   rI   rc   rh   r   r   r   r!   Ú<module>   s    	7