3
gP                 @   sR   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	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  dddg} t jdddd}|jd |jd	d
dddd |jddtjd |jd}|jdddd| djdjdd | D d |jdddd| djdjd d | D d |jd!d"d#d$d%d&gd'd |jd(d)d*d+d,d- |jd.d/d0d*d+d1d- |jd2d3d4td5d6 |jd7d8d*d+d9d- |jd:d;d*d+d<d- |jd=d>d*d+d?d@ |jdAdBd*d+dCd@ |jdDdEdFtdGd6 |jdHdId+t	dJd6 |jdKdLdMdNdO |S )PNupperlower
capitalizeZ	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
--keywordsZCHOICEZkeyword_casez,change case of keywords, CHOICE is one of {}z, c             s   s   | ]}d j |V  qdS )z"{}"N)format).0x r   J/var/www/tester-filtro-web/env/lib/python3.6/site-packages/sqlparse/cli.py	<genexpr>?   s    z create_parser.<locals>.<genexpr>)r   r   choicesr   z-iz--identifiersZidentifier_casez/change case of identifiers, CHOICE is one of {}c             s   s   | ]}d j |V  qdS )z"{}"N)r   )r   r   r   r   r   r   G   s    z-lz
--languageLANGZoutput_formatpythonZ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
--reindentZreindentzreindent statementsz--indent_widthZindent_width   z(indentation width (defaults to 2 spaces))r   r   typer   z--indent_after_firstZindent_after_firstz2indent after first line of statement (e.g. SELECT)z--indent_columnsZ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_afterZ
wrap_afterr   z*Column after which lists should be wrappedz--comma_firstZ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)Z_CASE_CHOICESparsergroupr   r   r   create_parser    s    



r,   c             C   s   t jjdj|  dS )z5Print msg and optionally exit with return code exit_.z[ERROR] {}
   )sysstderrwriter   )msgr   r   r   _error   s    r2   c       
   -   C   s|  t  }|j| } | jdkrFttjj| jd}z|j }W d |j	  X n^y.t
| j| jd}dj|j }W d Q R X W n. tk
r } ztdj| j|S d }~X nX d}| j ryt
| jd| jd}d}W n0 tk
 r } ztdj| j|S d }~X nX ntj}t| }ytjj|}W n, tk
rH } ztd	j|S d }~X nX tj|f|}	|j|	 |j  |rx|j  d
S )N-)r     zFailed to read {}: {}FwTzFailed to open {}: {}zInvalid options: {}r   )r,   
parse_argsr
   r   r.   stdinbufferr    readdetachopenr'   	readlinesOSErrorr2   r   r   stdoutvarsr$   	formatterZvalidate_optionsr   r0   flushclose)
argsr*   wrapperdatafeZclose_streamstreamZformatter_optssr   r   r   main   s@    

 
rJ   )N)__doc__r!   r.   ior   r$   Zsqlparse.exceptionsr   r,   r2   rJ   r   r   r   r   <module>   s   w