a
    e=icq=                  	   @   s   d Z ddlmZmZ ddlZddlZddlZddlZddlmZ i Z	dd Z
ej D ]H\ZZee
eZzee
ej W n ey   Y n0 eee	e< qV[dd Zd	d
 ZdddZdd Zejdd fddZG dd deZedkre  dS )zCommand line script to generate (Micro) QR codes with Segno.

"QR Code" and "Micro QR Code" are registered trademarks of DENSO WAVE INCORPORATED.
    )absolute_importunicode_literalsN)writersc                 C   sF   t | dd p| j}t | dd p"| j}|jd |j }|t| d  S )N	func_codeZfunc_defaults)getattr__code____defaults__co_varnamesco_argcountlen)funcr   defaultsargs r   Z/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/segno/cli.py	_get_args   s    r   c                  C   sr  dd } t jddtjd}|jdddd	d
 |jddddddd d |jddddddd d |jdddd |jddddd |jd d!dd"d |jd#d$d%d	dtd& |jd'd(d)d"d |jd*d+d,dd |jd-d.d/dtd0 |jd1d2d3dtd0 |jd4d5d6d7| d0 |jd8d9d:d	d
 |d;d<}|jd=d>d? |jd@dAd? |jdBdCd? |jdDdEd? |jdFdGd? |jdHdId? |jdJdKd? |jdLdMd? |jdNdOd? |jdPdQdRdS |jdTdUdVdS |jdWdXd? |jdYdZd? |jd[d\d? |jd]d^d? |jd_d`d? |jdadbd? |dcdd}|jdedfddg |jdhdidjd"d |jdkdldmd"d |jdndodpd"d |jdqdrd? |jdsdtd? |jdudvd? |jdwdxd? |jdydzd? |jd{d|d}dd |jd~dd? |jddtd |jdddd |jddddg |dd}|jddtd |dd}|jddddg |	 jdddddtjd |jdddd |S )z)    Returns the command line parser.
    c                 S   s    t | } | t| kr| S t| S N)floatint)valr   r   r   _convert_scale2   s    z#make_parser.<locals>._convert_scalesegnoz5Segno QR Code and Micro QR Code generator version {0})progdescriptionz	--versionz-vz:(Micro) QR Code version: 1 .. 40 or "M1", "M2", "M3", "M4"F)helprequiredz--errorz-ez{Error correction level: "L": 7%% (default), "M": 15%%, "Q": 25%%, "H": 30%%, "-": no error correction (used for M1 symbols))LMQH-Nc                 S   s   |   S r   )upperxr   r   r   <lambda>?       zmake_parser.<locals>.<lambda>)r   choicesdefaulttypez--modez-mzNMode. If unspecified (default), an optimal mode is chosen for the given input.)numericZalphanumericbyteZkanjiZhanzic                 S   s   |   S r   )lowerr"   r   r   r   r$   D   r%   z
--encodingzSSets the encoding of the input. If not set (default), a minimal encoding is chosen.)r   r'   z--microz$Allow the creation of Micro QR Codesmicro
store_true)r   destactionz
--no-microz-Disallow creation of Micro QR Codes (default)store_falsez	--patternz-pzMask pattern to use. If unspecified (default), an optimal mask pattern is used. Valid values for QR Codes: 0 .. 7. Valid values for Micro QR Codes: 0 .. 3)r   r   r'   r(   z--no-error-boostzDisables the automatic error correction level incrementation. By default, the maximal error correction level is used (without changing the version).boost_errorz--seqzaCreates a sequence of QR Codes (Structured Append mode). Version or symbol count must be providedseqz--symbol-countz-sczNumber of symbols to create)r   r'   r(   z--borderz-bzSize of the border / quiet zone of the output. By default, the standard border (4 modules for QR Codes, 2 modules for Micro QR Codes) will be used. A value of 0 omits the borderz--scalez-szScaling factor. By default, a scaling factor of 1 is used. That may lead into too small images. Some output formats, i.e. SVG, accept a decimal value.   z--outputz-ozEOutput file. If not specified, the QR Code is printed to the terminalzModule ColorszArguments to specify the module colors. Multiple colors are supported for SVG and PNG. The module color support varies between the serialization formats. Most serializers support at least "--dark" and "--light". Unsupported arguments are ignored.z--darka@  Color of the dark modules. The color may be specified as web color name, i.e. "red" or as hexadecimal value, i.e. "#0033cc". Some serializers, i.e. SVG and PNG, support alpha channels (8-digit hexadecimal value) and some support "transparent" / "trans" as color value for alpha transparency. The standard color is black.)r   z--lightzoColor of the light modules. See "dark" for a description of possible values. The standard light color is white.z--finder-darkz)Sets the color of the dark finder modulesz--finder-lightz*Sets the color of the light finder modulesz--separatorz'Sets the color of the separator modulesz--data-darkz'Sets the color of the dark data modulesz--data-lightz(Sets the color of the light data modulesz--timing-darkz)Sets the color of the dark timing modulesz--timing-lightz*Sets the color of the light timing modulesz--align-darkz,Sets the color of the dark alignment modulesalignment_dark)r   r.   z--align-lightz-Sets the color of the light alignment modulesalignment_lightz--quiet-zonez)Sets the color of the quiet zone (border)z--dark-modulez!Sets the color of the dark modulez--format-darkz5Sets the color of the dark format information modulesz--format-lightz6Sets the color of the light format information modulesz--version-darkz6Sets the color of the dark version information modulesz--version-lightz7Sets the color of the light version information modulesZSVGzSVG specific optionsz--no-classeszOmits the (default) SVG classes)r   r/   z--no-xmldeclz Omits the XML declaration headerZxmldeclz--no-namespacezHIndicates that the SVG document should have no SVG namespace declarationZsvgnsz--no-newlinez?Indicates that the SVG document should have no trailing newlinenlz--titlez'Specifies the title of the SVG documentz--descz-Specifies the description of the SVG documentz--svgidz&Indicates the ID of the <svg/> elementz
--svgclasszSIndicates the CSS class of the <svg/> element. An empty string omits the attribute.z--lineclasszUIndicates the CSS class of the <path/> elements. An empty string omits the attribute.z	--no-sizezOIndicates that the SVG document should not have "width" and "height" attributesZomitsizez--unitz$Indicates SVG coordinate system unitz--svgversionzIndicates the SVG version)r   r(   z--svgencodingz&Specifies the encoding of the documentutf-8z--draw-transparentz0Indicates that transparent paths should be drawnZPNGzPNG specific optionsz--dpiz"Sets the DPI value of the PNG fileZTerminalzTerminal specific optionsz	--compactzEIndicates that the QR code should be printed in a more compact mannerz--verz-VzShows Segno's versionversionz	Segno {0})r   r/   r8   content+zThe content to encode)nargsr   )
argparseArgumentParserformatr   __version__add_argumentr   add_argument_groupr   add_mutually_exclusive_group)r   parserZcolor_groupZ	svg_groupZ	png_groupZterminal_groupr   r   r   make_parser-   s    








rD   c                 C   st   t  }t| s |  td || }|jdkr:d|_|j}|durTt|	 }|j
sh|dv rhd|_
tt|S )z5    Parses the arguments and returns the result.
    r3   r    N)ZM1ZM2ZM3ZM4)rD   r   
print_helpsysexit
parse_argserrorr8   strr!   r,   	_AttrDictvars)r   rC   Zparsed_argsr8   r   r   r   parse   s    


rM   c                    s   dD ].}  |d}|dv r&d |< q|r| |< qdD ] } |ddu r8  |d q8  ddrvd d< d d<   d	d
 d< |dur||dd d  }|dkrd}t|d fdd D   S )a      Builds a configuration and returns it.

    The config contains only keywords which are supported by the serializer.
    Unsupported values are removed.

    :param dict config: The configuration / dict returned by the :py:func:`parse` function.
    :param filename: Optional filename. If not ``None`` (default), the `filename`
                     must provide a supported extension to identify the serializer.
    :return: A (maybe) modified configuration.
    )darklightZfinder_darkZfinder_lightZformat_darkZformat_lightr4   r5   Ztiming_darkZtiming_lightZ	data_darkZ
data_lightZversion_darkZversion_lightZ
quiet_zoneZdark_module	separatorN)transparentZtrans)Zsvgidsvgclass	lineclassZ
no_classesFrR   rS   Zsvgencodingr7   encoding.r3   Zsvgzsvgr   c                    s   i | ]}|v r| | qS r   r   ).0kconfigZsupported_argsr   r   
<dictcomp>   r%   z build_config.<locals>.<dictcomp>)popgetrfindr+   _EXT_TO_KW_MAPPING)rZ   filenameZclrr   nameextr   rY   r   build_config   s(    

rc   c              	   C   s   t j}t| d| d| d| d| d| dd}| dr^t j}| d	|d	< n| d
|d
< |d| dfi |S )aA      Creates the (Micro) QR Code (Sequence).

    Configuration parameters used for creating the Micro QR Code, QR Code
    or QR Code Sequence are removed from the configuration.

    :param config: Configuration, see :py:func:`build_config`
    :return: :py:class:`segno.QRCode` or :py:class:`segno.QRCodeSequence`.
    moderI   r8   patternrT   r1   )rd   rI   r8   maskrT   r1   r2   Zsymbol_countr,    r9   )r   makedictr\   Zmake_sequencejoin)rZ   rh   kwr   r   r   	make_code  s    

rl   r3   c              
   C   s   t | }zt|}W nD tyX } z,tjt|tjg t	dW  Y d }~S d }~0 0 |
d}|d u r|j|d |ddd n|j|fi t||d dS )	Nr3   outputbordercompactF)rn   ro   )r`   r   )rM   rl   
ValueErrorrF   stderr
writelinesrJ   oslineseprG   r\   Zterminalr]   saverc   )r   rZ   Zqrexrm   r   r   r   main  s     
rw   c                       s    e Zd ZdZ fddZ  ZS )rK   z    Internal helper class.
    c                    s    t t| j|i | | | _d S r   )superrK   __init____dict__)selfr   kwargs	__class__r   r   ry   +  s    z_AttrDict.__init__)__name__
__module____qualname____doc__ry   __classcell__r   r   r}   r   rK   '  s   rK   __main__)N)r   
__future__r   r   rs   rF   r<   r   r   r_   r   Z_VALID_SERIALIZERSitemsrb   r   setkwsupdate__wrapped__AttributeError	frozensetrD   rM   rc   rl   argvrw   ri   rK   r   r   r   r   r   <module>
   s2    
.	