U
    ;g                     @   s   d Z ddlZddlZddlZddlmZmZmZmZm	Z	m
Z
 ddlZddlmZmZ ejdrpddlZe  dddd	d
ddZejejejejdZdddZee
e dddZedddZdee edddZedkre  dS )z
qr - Convert stdin (or the first argument) to a QR Code.

When stdout is a tty the QR Code is printed to the terminal and when stdout is
a pipe to a file an image is written. The default image format is PNG.
    N)DictIterableNoReturnOptionalSetType)	BaseImageDrawerAliases)wincygwinzqrcode.image.pil.PilImagezqrcode.image.pure.PyPNGImagezqrcode.image.svg.SvgImagez!qrcode.image.svg.SvgFragmentImagezqrcode.image.svg.SvgPathImagezqrcode.image.pure.PymagingImage)ZpilZpngsvgzsvg-fragmentzsvg-pathZpymaging)LMQHc              
      s  | d krt jdd  } ddlm} |dj}tjtp6d |d t	t
d fdd	} jd
dtt dd  jddt  dd  jdtdd  jddtt ddd  jdddd  jddd  | \}} |jr8t|j|j}zt|}W n0 tk
r4 } z|t	| W 5 d }~X Y nX nd }tjt|j |d}| rl| d }	|	jdd }	nt jj }	|jd kr||	 n|j|	|jd! |j r|! }
t"|j d"}|
#| W 5 Q R X n|d krt$%t j&' s|j(r|j)|j( d# d S i }t*|j+d$d }|j,rt|s4|d% |j,|krX||j, d&t|  ||j, \}}|f ||d'< |j!f |}
t j&-  |
#t j&j d S )(N   r   )get_distributionqrcode )usageversion)msgreturnc                    s     |   d S )N)error)r   parser :/tmp/pip-unpacked-wheel-ij2mbwps/qrcode/console_scripts.pyraise_error1   s    
zmain.<locals>.raise_errorz	--factoryzFull python path to the image factory class to create the image with. You can use the following shortcuts to the built-in image factory classes: .)helpz--factory-drawerzUse an alternate drawer. z
--optimizezOptimize the data by looking for chunks of at least this many characters that could use a more efficient encoding method. Use 0 to turn off chunk optimization.)typer    z--error-correctionchoicer   z^The error correction level to use. Choices are L (7%), M (15%, default), Q (25%), and H (30%).)r!   choicesdefaultr    z--asciiz'Print as ascii even if stdout is piped.
store_true)r    actionz--outputzLThe output file. If not specified, the image is sent to the standard output.)error_correctionimage_factorysurrogateescape)errors)optimizewb)ttydrawer_aliasesz+The selected factory has no drawer aliases.z$ factory drawer not found. Expected Zmodule_drawer).sysargvpkg_resourcesr   r   optparseOptionParser__doc__stripstrr   
add_optioncommasdefault_factoriesget_drawer_helpintsortedr'   keys
parse_argsfactorygetget_factory
ValueErrorr   ZQRCodeencodestdinbufferreadr+   Zadd_dataoutputZ
make_imageopensaveosisattystdoutfilenoasciiZprint_asciigetattrr(   Zfactory_drawerflush)argsr   r   r   optsmoduler(   eZqrdataimgoutkwargsaliasesZ
drawer_clsZdrawer_kwargsr   r   r   main(   s    

   $  
rZ   )rS   r   c                 C   s:   d| krt d| dd\} }t| i i |g}t||S )Nr   z+The image factory is not a full python pathr   )rB   rsplit
__import__rO   )rS   nameimpr   r   r   rA      s
    rA   )r   c               	   C   s   i } t  D ]\\}}zt|}W n tk
r8   Y qY nX t|dd }|sLq| t|t }|| qd	dd |  D S )Nr.   z. c                 s   s(   | ] \}}d t |d d| V  qdS )zFor andz, use: N)r8   ).0rY   	factoriesr   r   r   	<genexpr>   s   z"get_drawer_help.<locals>.<genexpr>)
r9   itemsrA   ImportErrorrO   
setdefaultr8   setaddjoin)r    aliasrS   imagerY   ra   r   r   r   r:      s    

r:   or)rc   r   c                 C   sJ   t | } | sdS t| dkr$| d S d| d d  d| d| d  S )Nr   r   r   z,  )tuplelenrh   )rc   joinerr   r   r   r8      s    r8   __main__)N)rk   )r4   r2   rJ   r/   typingr   r   r   r   r   r   r   Zqrcode.image.baser   r	   platform
startswithcoloramainitr9   ZERROR_CORRECT_LZERROR_CORRECT_MZERROR_CORRECT_QZERROR_CORRECT_Hr'   rZ   r6   rA   r:   r8   __name__r   r   r   r   <module>   s6    
f	