a
    Sicݷ                     @   s   d Z ddlmZmZ ddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
 zeZW n eyj   eZY n0 dZd	ZeZdddZdddZdddZdddZG dd dZG dd deZdS )zQR Code and Micro QR Code implementation.

"QR Code" and "Micro QR Code" are registered trademarks of DENSO WAVE INCORPORATED.
    )absolute_importunicode_literalsN   )encoder)DataOverflowError)writersutilsz1.5.2)makemake_qr
make_micromake_sequenceQRCodeQRCodeSequencer   FTc	           	      C   s    t tj| ||||||||d	S )uw      Creates a (Micro) QR Code.

    This is main entry point to create QR Codes and Micro QR Codes.

    Aside from `content`, all parameters are optional and an optimal (minimal)
    (Micro) QR code with a maximal error correction level is generated.

    :param content: The data to encode. Either a Unicode string, an integer or
            bytes. If bytes are provided, the `encoding` parameter should be
            used to specify the used encoding.
    :type content: str, int, bytes
    :param error: Error correction level. If ``None`` (default), error
            correction level ``L`` is used (note: Micro QR Code version M1 does
            not support any error correction. If an explicit error correction
            level is used, a M1 QR code won't be generated).
            Valid values: ``None`` (allowing generation of M1 codes or use error
            correction level "L" or better see :paramref:`boost_error <segno.make.boost_error>`),
            "L", "M", "Q", "H" (error correction level "H" isn't available for
            Micro QR Codes).

            =====================================   ===========================
            Error correction level                  Error correction capability
            =====================================   ===========================
            L (Segno's default unless version M1)   recovers  7% of data
            M                                       recovers 15% of data
            Q                                       recovers 25% of data
            H (not available for Micro QR Codes)    recovers 30% of data
            =====================================   ===========================

            Higher error levels may require larger QR codes (see also
            :paramref:`version <segno.make.version>` parameter).

            The `error` parameter is case insensitive.

            See also the :paramref:`boost_error <segno.make.boost_error>` parameter.
    :type error: str or None
    :param version: QR Code version. If the value is ``None`` (default), the
            minimal version which fits for the input data will be used.
            Valid values: "M1", "M2", "M3", "M4" (for Micro QR codes) or an
            integer between 1 and 40 (for QR codes).
            The `version` parameter is case insensitive.
    :type version: int, str or None
    :param mode: "numeric", "alphanumeric", "byte", "kanji" or "hanzi".
            If the value is ``None`` (default) the appropriate mode will
            automatically be determined.
            If `version` refers to a Micro QR code, this function may raise a
            :py:exc:`ValueError` if the provided `mode` is not supported.

            The `mode` parameter is case insensitive.

            ============    =======================
            Mode            (Micro) QR Code Version
            ============    =======================
            numeric         1 - 40, M1, M2, M3, M4
            alphanumeric    1 - 40,     M2, M3, M4
            byte            1 - 40,         M3, M4
            kanji           1 - 40,         M3, M4
            hanzi           1 - 40
            ============    =======================

            .. note::
                The Hanzi mode may not be supported by all QR code readers since
                it is not part of ISO/IEC 18004:2015(E).
                For this reason, this mode must be specified explicitly by the
                user::

                    import segno
                    qrcode = segno.make('书读百遍其义自现', mode='hanzi')

    :type mode: str or None
    :param mask: Data mask. If the value is ``None`` (default), the
            appropriate data mask is chosen automatically. If the `mask`
            parameter is provided, this function may raise a :py:exc:`ValueError`
            if the mask is invalid.
    :type mask: int or None
    :param encoding: Indicates the encoding in mode "byte". By default
            (`encoding` is ``None``) the implementation tries to use the
            standard conform ISO/IEC 8859-1 encoding and if it does not fit, it
            will use UTF-8. Note that no ECI mode indicator is inserted by
            default (see :paramref:`eci <segno.make.eci>`).
            The `encoding` parameter is case insensitive.
    :type encoding: str or None
    :param bool eci: Indicates if binary data which does not use the default
            encoding (ISO/IEC 8859-1) should enforce the ECI mode. Since a lot
            of QR code readers do not support the ECI mode, this feature is
            disabled by default and the data is encoded in the provided
            `encoding` using the usual "byte" mode. Set `eci` to ``True`` if
            an ECI header should be inserted into the QR Code. Note that
            the implementation may not know the ECI designator for the provided
            `encoding` and may raise an exception if the ECI designator cannot
            be found.
            The ECI mode is not supported by Micro QR Codes.
    :param micro: If :paramref:`version <segno.make.version>` is ``None`` (default)
            this parameter can be used to allow the creation of a Micro QR code.
            If set to ``False``, a QR code is generated. If set to
            ``None`` (default) a Micro QR code may be generated if applicable.
            If set to ``True`` the algorithm generates a Micro QR Code or
            raises an exception if the `mode` is not compatible or the `content`
            is too large for Micro QR codes.
    :type micro: bool or None
    :param bool boost_error: Indicates if the error correction level may be
            increased if it does not affect the version (default: ``True``).
            If set to ``True``, the :paramref:`error <segno.make.error>`
            parameter is interpreted as minimum error level. If set to ``False``,
            the resulting (Micro) QR code uses the provided `error` level
            (or the default error correction level, if error is ``None``)
    :raises: :py:exc:`ValueError` or :py:exc:`DataOverflowError`: In case the
             data does not fit into a (Micro) QR Code or it does not fit into
             the provided :paramref:`version`.
    :rtype: QRCode
    )boost_error)r   r   encode)	contenterrorversionmodemaskencodingecimicror    r   J/var/www/html/django/DPS/env/lib/python3.9/site-packages/segno/__init__.pyr	   "   s    rr	   c                 C   s   t | ||||||d|d	S )z    Creates a QR code (never a Micro QR code).

    See :py:func:`make` for a description of the parameters.

    :rtype: QRCode
    F)r   r   r   r   r   r   r   r   r	   )r   r   r   r   r   r   r   r   r   r   r   r
      s    	r
   c              
   C   s   t | |||||d|dS )a      Creates a Micro QR code.

    See :py:func:`make` for a description of the parameters.

    Note: Error correction level "H" isn't available for Micro QR codes. If
    used, this function raises a :py:class:`segno.ErrorLevelError`.

    :rtype: QRCode
    T)r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r      s    r   c                 C   s$   t tttj| |||||||dS )a[      Creates a sequence of QR codes using the Structured Append mode.

    If the content fits into one QR code and neither ``version`` nor
    ``symbol_count`` is provided, this function may return a sequence with
    one QR Code which does not use the Structured Append mode. Otherwise a
    sequence of 2 .. n  (max. n = 16) QR codes is returned which use the
    Structured Append mode.

    The Structured Append mode allows to split the content over a number
    (max. 16) QR Codes.

    The Structured Append mode isn't available for Micro QR Codes, therefor
    the returned sequence contains QR codes, only.

    Since this function returns an iterable object, it may be used as follows:

    .. code-block:: python

        for i, qrcode in enumerate(segno.make_sequence(data, symbol_count=2)):
             qrcode.save('seq-%d.svg' % i, scale=10, color='darkblue')

    The number of QR codes is determined by the `version` or `symbol_count`
    parameter.

    See :py:func:`make` for a description of the other parameters.

    :param int symbol_count: Number of symbols.
    :rtype: QRCodeSequence
    )r   r   r   r   r   r   symbol_count)r   mapr   r   Zencode_sequence)r   r   r   r   r   r   r   r   r   r   r   r      s     r   c                   @   s   e Zd ZdZdZdd Zedd Zedd Zed	d
 Z	edd Z
edd Zedd Zdd ZdZd,ddZd-ddZd.ddZd/d d!Zd"d# Zd$d% Zd0d&d'Zd1d(d)Zd*d+ ZdS )2r   z&    Represents a (Micro) QR Code.
    )matrixr   _version_error_modec                 C   sD   |j | _ |j| _|j| _|j| _t|jdkr:|jd jnd| _	dS )z        Initializes the QR Code object.

        :param code: An object with a ``matrix``, ``version``, ``error``,
            ``mask`` and ``segments`` attribute.
        r   r   N)
r   r   r   r   r   r    lensegmentsr   r!   )selfcoder   r   r   __init__   s
    zQRCode.__init__c                 C   s   t | jS )z        (Micro) QR Code version. Either a string ("M1", "M2", "M3", "M4") or
        an integer in the range of 1 .. 40.

        :rtype: str or int
        )r   Zget_version_namer   r$   r   r   r   r      s    zQRCode.versionc                 C   s   | j du rdS t| j S )z        Error correction level; either a string ("L", "M", "Q", "H") or ``None``
        if the QR code provides no error correction (Micro QR Code version M1)

        :rtype: str
        N)r    r   Zget_error_namer'   r   r   r   r     s    
zQRCode.errorc                 C   s   | j durt| j S dS )z        String indicating the mode ("numeric", "alphanumeric", "byte", "kanji",
        or "hanzi").
        May be ``None`` if multiple modes are used.

        :rtype: str or None
        N)r!   r   Zget_mode_namer'   r   r   r   r     s    	
zQRCode.modec                 C   s&   t | j}d| jr|| jfn|fS )z        Returns the version and error correction level as string `V-E` where
        `V` represents the version number and `E` the error level.

        :rtype: str
        -)strr   joinr   )r$   r   r   r   r   
designator  s    
zQRCode.designatorc                 C   s   t | jS )z        Indicates the default border size aka quiet zone.

        QR Codes have a quiet zone of four light modules, while Micro QR Codes
        have a quiet zone of two light modules.

        :rtype: int
        )r   Zget_default_border_sizer   r'   r   r   r   default_border_size'  s    
zQRCode.default_border_sizec                 C   s
   | j dk S )zS        Indicates if this QR code is a Micro QR code

        :rtype: bool
        r   )r   r'   r   r   r   is_micro3  s    zQRCode.is_microc                 C   s   | j |j ko| j|jkS N)	__class__r   )r$   otherr   r   r   __eq__<  s    zQRCode.__eq__Nr   c                 C   s   t j| j||dS )a          Returns the symbol size (width x height) with the provided border and
        scaling factor.

        :param scale: Indicates the size of a single module (default: 1).
                The size of a module depends on the used output format; i.e.
                in a PNG context, a scaling factor of 2 indicates that a module
                has a size of 2 x 2 pixel. Some outputs (i.e. SVG) accept
                floating point values.
        :type scale: int or float
        :param int border: The border size or ``None`` to specify the
                default quiet zone (4 for QR Codes, 2 for Micro QR Codes).
        :rtype: tuple (width, height)
        )scaleborder)r   Zget_symbol_sizer   )r$   r2   r3   r   r   r   symbol_sizeA  s    zQRCode.symbol_sizeFc                 C   s"   |r
t jnt j}|| j| j||S )a\          Returns an iterator over the matrix which includes the border.

        The border is returned as sequence of light modules.
        Dark modules are reported as ``0x1``, light modules have the value
        ``0x0``.

        The following example converts the QR code matrix into a list of
        lists which use boolean values for the modules (True = dark module,
        False = light module)::

            >>> import segno
            >>> qrcode = segno.make('The Beatles')
            >>> width, height = qrcode.symbol_size(scale=2)
            >>> res = []
            >>> # Scaling factor 2, default border
            >>> for row in qrcode.matrix_iter(scale=2):
            >>>     res.append([col == 0x1 for col in row])
            >>> width == len(res[0])
            True
            >>> height == len(res)
            True

        If `verbose` is ``True``, the iterator returns integer constants which
        indicate the type of the module, i.e. ``segno.consts.TYPE_FINDER_PATTERN_DARK``,
        ``segno.consts.TYPE_FINDER_PATTERN_LIGHT``, ``segno.consts.TYPE_QUIET_ZONE`` etc.

        To check if the returned module type is dark or light, use::

            if mt >> 8:
                print('dark module')

            if not mt >> 8:
                print('light module')


        :param int scale: The scaling factor (default: ``1``).
        :param int border: The size of border / quiet zone or ``None`` to
                indicate the default border.
        :param bool verbose: Indicates if the type of the module should be returned
                instead of ``0x1`` and ``0x0`` values.
                See :py:mod:`segno.consts` for the return values.
                This feature is currently in EXPERIMENTAL state.
        :raises: :py:exc:`ValueError` if the scaling factor or the border is
                invalid (i.e. negative).
        )r   Zmatrix_iter_verbosematrix_iterr   r   )r$   r2   r3   verboseZiterfnr   r   r   r5   R  s    /zQRCode.matrix_iter   
   #000#fffc                    s  ddl ddlddl}ddl}ddl}zddlm}	 ddlm}
 W n* t	yn   ddl
m}	 ddlm}
 Y n0  fdd}|jddd	d
}z| j|||||d W n"   |  |j  Y n0 |  ||	d|
|j  dur|j||jfd}|  dS )a          Displays this QR code.

        This method is mainly intended for debugging purposes.

        This method saves the QR code as an image (by default with a scaling
        factor of 10) to a temporary file and opens it with the standard PNG
        viewer application or within the standard webbrowser.
        The temporary file is deleted afterwards (unless
        :paramref:`delete_after <segno.QRCode.show.delete_after>` is set to ``None``).

        If this method does not show any result, try to increase the
        :paramref:`delete_after <segno.QRCode.show.delete_after>` value or set
        it to ``None``

        :param delete_after: Time in seconds to wait till the temporary file is
                deleted.
        :type delete_after: int or None
        :param int scale: Integer indicating the size of a single module.
        :param border: Integer indicating the size of the quiet zone.
                If set to ``None`` (default), the recommended border size
                will be used.
        :type border: int or None
        :param dark: The color of the dark modules (default: black).
        :param light: The color of the light modules (default: white).
        r   N)urljoin)pathname2urlc                    s0      z|  W n ty*   Y n0 d S r.   )sleepunlinkOSError)namedelete_afterostimer   r   delete_file  s
    
z QRCode.show.<locals>.delete_filewbz.pngF)suffixdelete)r2   darklightr3   zfile:)targetargs)rC   rD   tempfile
webbrowser	threadingurllib.parser;   urllib.requestr<   ImportErrorurlparseurllibNamedTemporaryFilesavecloser>   r@   Zopen_new_tabThreadstart)r$   rB   r2   r3   rI   rJ   rM   rN   rO   r;   r<   rE   ftr   rA   r   show  s0    
zQRCode.showc                 K   s"   t j| j| jf||||d|S )a          Converts the QR code into an SVG data URI.

        The XML declaration is omitted by default (set
        :paramref:`xmldecl <segno.QRCode.svg_data_uri.xmldecl>` to ``True``
        to enable it), further the newline is omitted by default (set ``nl`` to
        ``True`` to enable it).

        Aside from the missing `out` parameter, the different `xmldecl` and
        `nl` default values, and the additional parameters
        :paramref:`encode_minimal <segno.QRCode.svg_data_uri.encode_minimal>`
        and :paramref:`omit_charset <segno.QRCode.svg_data_uri.omit_charset>`,
        this method uses the same parameters as the usual SVG serializer, see
        :py:func:`save` and the available `SVG parameters <#svg>`_

        .. note::
            In order to embed a SVG image in HTML without generating a file, the
            :py:func:`svg_inline` method could serve better results, as it
            usually produces a smaller output.

        :param bool xmldecl: Indicates if the XML declaration should be
                        serialized (default: ``False``)
        :param bool encode_minimal: Indicates if the resulting data URI should
                        use minimal percent encoding (disabled by default).
        :param bool omit_charset: Indicates if the ``;charset=...`` should be omitted
                        (disabled by default)
        :param bool nl: Indicates if the document should have a trailing newline
                        (default: ``False``)
        :rtype: str
        )xmldeclnlencode_minimalomit_charset)r   Zas_svg_data_urir   r   )r$   r]   r_   r`   r^   kwr   r   r   svg_data_uri  s     zQRCode.svg_data_uric                 K   s:   t  }| j|fddddd| | |ddS )a          Returns an SVG representation which is embeddable into HTML5 contexts.

        Due to the fact that HTML5 directly supports SVG, various elements of
        an SVG document can or should be suppressed (i.e. the XML declaration and
        the SVG namespace).

        This method returns a string that can be used in an HTML context.

        This method uses the same parameters as the usual SVG serializer, see
        :py:func:`save` and the available `SVG parameters <#svg>`_ (the ``out``
        and ``kind`` parameters are not supported).

        The returned string can be used directly in
        `Jinja <https://jinja.palletsprojects.com/>`_ and
        `Django <https://www.djangoproject.com/>`_ templates, provided the
        ``safe`` filter is used which marks a string as not requiring further
        HTML escaping prior to output.
        ::

            <div>{{ qr.svg_inline(dark='#228b22', scale=3) | safe }}</div>

        :rtype: str
        svgF)kindr]   Zsvgnsr^   r   zutf-8)ioBytesIOrV   getvaluedecodeget)r$   ra   buffr   r   r   
svg_inline  s    zQRCode.svg_inlinec                 K   s   t j| j| jfi |S )z        Converts the QR code into a PNG data URI.

        Uses the same keyword parameters as the usual PNG serializer,
        see :py:func:`save` and the available `PNG parameters <#png>`_

        :rtype: str
        )r   Zas_png_data_urir   r   )r$   ra   r   r   r   png_data_uri  s    	zQRCode.png_data_uric              	   C   s   |r t | j| j|ptj| nn|du rttjdkrtzt | j| j| W q typ   t 	| j| jtj| Y q0 nt 	| j| j|ptj| dS )a`          Serializes the matrix as ANSI escape code or Unicode Block Elements
        (if ``compact`` is ``True``).

        Under Windows, no ANSI escape sequence is generated but the Windows
        API is used *unless* :paramref:`out <segno.QRCode.terminal.out>`
        is a writable object or using WinAPI fails or if ``compact`` is ``True``.

        :param out: Filename or a file-like object supporting to write text.
                If ``None`` (default), the matrix is written to :py:class:`sys.stdout`.
        :param int border: Integer indicating the size of the quiet zone.
                If set to ``None`` (default), the recommended border size
                will be used (``4`` for QR Codes, ``2`` for Micro QR Codes).
        :param bool compact: Indicates if a more compact QR code should be shown
                (default: ``False``).
        Nwin32)
r   Zwrite_terminal_compactr   r   sysstdoutplatformZwrite_terminal_winr?   Zwrite_terminal)r$   outr3   compactr   r   r   terminal  s    zQRCode.terminalc                 K   s    t j| j| j||fi | dS )aP          Serializes the QR code in one of the supported formats.
        The serialization format depends on the filename extension.

        .. _common_keywords:

        **Common keywords**

        ==========    ==============================================================
        Name          Description
        ==========    ==============================================================
        scale         Integer or float indicating the size of a single module.
                      Default: 1. The interpretation of the scaling factor depends
                      on the serializer. For pixel-based output (like :ref:`PNG <png>`)
                      the scaling factor is interpreted as pixel-size (1 = 1 pixel).
                      :ref:`EPS <eps>` interprets ``1`` as 1 point (1/72 inch) per
                      module.
                      Some serializers (like :ref:`SVG <svg>`) accept float values.
                      If the serializer does not accept float values, the value will be
                      converted to an integer value (note: int(1.6) == 1).
        border        Integer indicating the size of the quiet zone.
                      If set to ``None`` (default), the recommended border size
                      will be used (``4`` for QR codes, ``2`` for a Micro QR codes).
                      A value of ``0`` indicates that border should be omitted.
        dark          A string or tuple representing a color value for the dark
                      modules. The default value is "black".  The color can be
                      provided as ``(R, G, B)`` tuple, as web color name
                      (like "red") or in hexadecimal format (``#RGB`` or
                      ``#RRGGBB``). Some serializers (i.e. :ref:`SVG <svg>` and
                      :ref:`PNG <png>`) accept an alpha transparency value like
                      ``#RRGGBBAA``.
        light         A string or tuple representing a color for the light modules.
                      See `dark` for valid values.
                      The default value depends on the serializer. :ref:`SVG <svg>`
                      uses no color (``None``) for light modules by default, other
                      serializers, like :ref:`PNG <png>`, use "white" as default
                      light color.
        ==========    ==============================================================


        .. _module_colors:

        **Module Colors**

        ===============    =======================================================
        Name               Description
        ===============    =======================================================
        finder_dark        Color of the dark modules of the finder patterns
                           Default: undefined, use value of "dark"
        finder_light       Color of the light modules of the finder patterns
                           Default: undefined, use value of "light"
        data_dark          Color of the dark data modules
                           Default: undefined, use value of "dark"
        data_light         Color of the light data modules.
                           Default: undefined, use value of "light".
        version_dark       Color of the dark modules of the version information.
                           Default: undefined, use value of "dark".
        version_light      Color of the light modules of the version information,
                           Default: undefined, use value of "light".
        format_dark        Color of the dark modules of the format information.
                           Default: undefined, use value of "dark".
        format_light       Color of the light modules of the format information.
                           Default: undefined, use value of "light".
        alignment_dark     Color of the dark modules of the alignment patterns.
                           Default: undefined, use value of "dark".
        alignment_light    Color of the light modules of the alignment patterns.
                           Default: undefined, use value of "light".
        timing_dark        Color of the dark modules of the timing patterns.
                           Default: undefined, use value of "dark".
        timing_light       Color of the light modules of the timing patterns.
                           Default: undefined, use value of "light".
        separator          Color of the separator.
                           Default: undefined, use value of "light".
        dark_module        Color of the dark module (a single dark module which
                           occurs in all QR Codes but not in Micro QR Codes.
                           Default: undefined, use value of "dark".
        quiet_zone         Color of the quiet zone / border.
                           Default: undefined, use value of "light".
        ===============    =======================================================


        .. _svg:

        **Scalable Vector Graphics (SVG)**

        All :ref:`common keywords <common_keywords>` and :ref:`module colors <module_colors>`
        are supported.

        ================ ==============================================================
        Name             Description
        ================ ==============================================================
        out              Filename or :py:class:`io.BytesIO`
        kind             "svg" or "svgz" (to create a gzip compressed SVG)
        scale            integer or float
        dark             Default: "#000" (black)
                         ``None`` is a valid value. If set to ``None``, the resulting
                         path won't have a "stroke" attribute. The "stroke" attribute
                         may be defined via CSS (external).
                         If an alpha channel is defined, the output depends of the
                         used SVG version. For SVG versions >= 2.0, the "stroke"
                         attribute will have a value like "rgba(R, G, B, A)", otherwise
                         the path gets another attribute "stroke-opacity" to emulate
                         the alpha channel.
                         To minimize the document size, the SVG serializer uses
                         automatically the shortest color representation: If
                         a value like "#000000" is provided, the resulting
                         document will have a color value of "#000". If the color
                         is "#FF0000", the resulting color is not "#F00", but
                         the web color name "red".
        light            Default value ``None``. If this parameter is set to another
                         value, the resulting image will have another path which
                         is used to define the color of the light modules.
                         If an alpha channel is used, the resulting path may
                         have a "fill-opacity" attribute (for SVG version < 2.0)
                         or the "fill" attribute has a "rgba(R, G, B, A)" value.
        xmldecl          Boolean value (default: ``True``) indicating whether the
                         document should have an XML declaration header.
                         Set to ``False`` to omit the header.
        svgns            Boolean value (default: ``True``) indicating whether the
                         document should have an explicit SVG namespace declaration.
                         Set to ``False`` to omit the namespace declaration.
                         The latter might be useful if the document should be
                         embedded into a HTML 5 document where the SVG namespace
                         is implicitly defined.
        title            String (default: ``None``) Optional title of the generated
                         SVG document.
        desc             String (default: ``None``) Optional description of the
                         generated SVG document.
        svgid            A string indicating the ID of the SVG document
                         (if set to ``None`` (default), the SVG element won't have
                         an ID).
        svgclass         Default: "segno". The CSS class of the SVG document
                         (if set to ``None``, the SVG element won't have a class).
        lineclass        Default: "qrline". The CSS class of the path element
                         (which draws the dark modules (if set to ``None``, the path
                         won't have a class).
        omitsize         Indicates if width and height attributes should be
                         omitted (default: ``False``). If these attributes are
                         omitted, a ``viewBox`` attribute will be added to the
                         document.
        unit             Default: ``None``
                         Indicates the unit for width / height and other coordinates.
                         By default, the unit is unspecified and all values are
                         in the user space.
                         Valid values: em, ex, px, pt, pc, cm, mm, in, and percentages
                         (any string is accepted, this parameter is not validated
                         by the serializer)
        encoding         Encoding of the XML document. "utf-8" by default.
        svgversion       SVG version (default: ``None``). If specified (a float),
                         the resulting document has an explicit "version" attribute.
                         If set to ``None``, the document won't have a "version"
                         attribute. This parameter is not validated.
        compresslevel    Default: 9. This parameter is only valid, if a compressed
                         SVG document should be created (file extension "svgz").
                         1 is fastest and produces the least compression, 9 is slowest
                         and produces the most. 0 is no compression.
        draw_transparent Indicates if transparent SVG paths should be
                         added to the graphic (default: ``False``)
        nl               Indicates if the document should have a trailing newline
                         (default: ``True``)
        ================ ==============================================================


        .. _png:

        **Portable Network Graphics (PNG)**

        This writes either a grayscale (maybe with transparency) PNG (color type 0)
        or a palette-based (maybe with transparency) image (color type 3).
        If the dark / light values are ``None``, white or black, the serializer
        chooses the more compact grayscale mode, in all other cases a palette-based
        image is written.

        All :ref:`common keywords <common_keywords>` and :ref:`module colors <module_colors>`
        are supported.

        ===============    ==============================================================
        Name               Description
        ===============    ==============================================================
        out                Filename or :py:class:`io.BytesIO`
        kind               "png"
        scale              integer
        dark               Default: "#000" (black)
                           ``None`` is a valid value iff light is not ``None``.
                           If set to ``None``, the dark modules become transparent.
        light              Default value "#fff" (white)
                           See keyword "dark" for further details.
        compresslevel      Default: 9. Integer indicating the compression level
                           for the ``IDAT`` (data) chunk.
                           1 is fastest and produces the least compression, 9 is slowest
                           and produces the most. 0 is no compression.
        dpi                Default: ``None``. Specifies the DPI value for the image.
                           By default, the DPI value is unspecified. Please note
                           that the DPI value is converted into meters (maybe with
                           rounding errors) since PNG does not support the unit
                           "dots per inch".
        ===============    ==============================================================


        .. _eps:

        **Encapsulated PostScript (EPS)**

        All :ref:`common keywords <common_keywords>` are supported.

        =============    ==============================================================
        Name             Description
        =============    ==============================================================
        out              Filename or :py:class:`io.StringIO`
        kind             "eps"
        scale            integer or float
        dark             Default: "#000" (black)
        light            Default value: ``None`` (transparent light modules)
        =============    ==============================================================


        .. _pdf:

        **Portable Document Format (PDF)**

        All :ref:`common keywords <common_keywords>` are supported.

        =============    ==============================================================
        Name             Description
        =============    ==============================================================
        out              Filename or :py:class:`io.BytesIO`
        kind             "pdf"
        scale            integer or float
        dark             Default: "#000" (black)
        light            Default value: ``None`` (transparent light modules)
        compresslevel    Default: 9. Integer indicating the compression level.
                         1 is fastest and produces the least compression, 9 is slowest
                         and produces the most. 0 is no compression.
        =============    ==============================================================


        .. _txt:

        **Text (TXT)**

        Aside of "scale", all :ref:`common keywords <common_keywords>` are supported.

        =============    ==============================================================
        Name             Description
        =============    ==============================================================
        out              Filename or :py:class:`io.StringIO`
        kind             "txt"
        dark             Default: "1"
        light            Default: "0"
        =============    ==============================================================


        .. _ansi:

        **ANSI escape code**

        Supports the "border" keyword, only!

        =============    ==============================================================
        Name             Description
        =============    ==============================================================
        out              Filename or :py:class:`io.StringIO`
        kind             "ans"
        =============    ==============================================================


        .. _pbm:

        **Portable Bitmap (PBM)**

        All :ref:`common keywords <common_keywords>` are supported.

        =============    ==============================================================
        Name             Description
        =============    ==============================================================
        out              Filename or :py:class:`io.BytesIO`
        kind             "pbm"
        scale            integer
        plain            Default: False. Boolean to switch between the P4 and P1 format.
                         If set to ``True``, the (outdated) P1 serialization format is
                         used.
        =============    ==============================================================


        .. _pam:

        **Portable Arbitrary Map (PAM)**

        All :ref:`common keywords <common_keywords>` are supported.

        =============    ==============================================================
        Name             Description
        =============    ==============================================================
        out              Filename or :py:class:`io.BytesIO`
        kind             "pam"
        scale            integer
        dark             Default: "#000" (black).
        light            Default value "#fff" (white). Use ``None`` for transparent
                         light modules.
        =============    ==============================================================


        .. _ppm:

        **Portable Pixmap (PPM)**

        All :ref:`common keywords <common_keywords>` and :ref:`module colors <module_colors>`
        are supported.

        =============    ==============================================================
        Name             Description
        =============    ==============================================================
        out              Filename or :py:class:`io.BytesIO`
        kind             "ppm"
        scale            integer
        dark             Default: "#000" (black).
        light            Default value "#fff" (white).
        =============    ==============================================================



        .. _latex:

        **LaTeX / PGF/TikZ**

        To use the output of this serializer, the ``PGF/TikZ`` (and optionally
        ``hyperref``) package is required in the LaTeX environment. The
        serializer itself does not depend on any external packages.

        All :ref:`common keywords <common_keywords>` are supported.

        =============    ==============================================================
        Name             Description
        =============    ==============================================================
        out              Filename or :py:class:`io.StringIO`
        kind             "tex"
        scale            integer or float
        dark             LaTeX color name (default: "black"). The color is written
                         "at it is", please ensure that the color is a standard color
                         or it has been defined in the enclosing LaTeX document.
        url              Default: ``None``. Optional URL where the QR code should
                         point to. Requires the ``hyperref`` package in the LaTeX
                         environment.
        =============    ==============================================================


        .. _xbm:

        **X BitMap (XBM)**

        All :ref:`common keywords <common_keywords>` are supported.

        =============    ==============================================================
        Name             Description
        =============    ==============================================================
        out              Filename or :py:class:`io.StringIO`
        kind             "xbm"
        scale            integer
        name             Name of the variable (default: "img")
        =============    ==============================================================


        .. _xpm:

        **X PixMap (XPM)**

        All :ref:`common keywords <common_keywords>` are supported.

        =============    ==============================================================
        Name             Description
        =============    ==============================================================
        out              Filename or :py:class:`io.StringIO`
        kind             "xpm"
        scale            integer
        dark             Default: "#000" (black).
                         ``None`` indicates transparent dark modules.
        light            Default value "#fff" (white)
                         ``None`` indicates transparent light modules.
        name             Name of the variable (default: "img")
        =============    ==============================================================


        :param out: A filename or a writable file-like object with a
                ``name`` attribute. Use the :paramref:`kind <segno.QRCode.save.kind>`
                parameter if `out` is a :py:class:`io.BytesIO` or
                :py:class:`io.StringIO` stream which don't have a ``name``
                attribute.
        :param str kind: Default ``None``.
                If the desired output format cannot be determined from
                the :paramref:`out <segno.QRCode.save.out>` parameter, this
                parameter can be used to indicate the serialization format
                (i.e. "svg" to enforce SVG output). The value is case
                insensitive.
        :param kw: Any of the supported keywords by the specific serializer.
        N)r   rV   r   r   )r$   rq   rd   ra   r   r   r   rV   ,  s       zQRCode.savec                 C   sf   | drPddlm} ddlm} |d|dd dD ]}| }|||   S td	| j|dS )
aV          This is used to plug-in external serializers.

        When a "to_<name>" method is invoked, this method tries to find
        a ``segno.plugin.converter`` plugin with the provided ``<name>``.
        If such a plugin exists, a callable function is returned. The result
        of invoking the function depends on the plugin.
        Zto_r   )iter_entry_points)partialzsegno.plugin.converter   N)groupr@   z{0} object has no attribute {1})	
startswithpkg_resourcesrt   	functoolsru   loadAttributeErrorformatr/   )r$   r@   rt   ru   eppluginr   r   r   __getattr__  s    	


zQRCode.__getattr__)r   N)r   NF)r7   r8   Nr9   r:   )FFFF)NNF)N)__name__
__module____qualname____doc__	__slots__r&   propertyr   r   r   r+   r,   r-   r1   __hash__r4   r5   r\   rb   rk   rl   rs   rV   r   r   r   r   r   r      sB   
	







2  
<  
%

   r   c                       s@   e Zd ZdZdZ fddZdddZdd	d
Zdd Z  Z	S )r   z    Represents a sequence of  1 .. n (max. n = 16) :py:class:`QRCode` instances.

    Iff this sequence contains only one item, it behaves like :py:class:`QRCode`.
    r   c                    s   t t| | |S r.   )superr   __new__)clsZqrcodesr/   r   r   r     s    zQRCodeSequence.__new__NFc                 C   s   | D ]}|j |||d qdS )z        Serializes the sequence of QR codes as ANSI escape code.

        See :py:meth:`QRCode.terminal()` for details.
        )rq   r3   rr   N)rs   )r$   rq   r3   rr   qrcoder   r   r   rs     s    zQRCodeSequence.terminalc                    s   dd }t |   dkr\t|tr\|d}|dkr\|d| d ||d  } fdd}t| dd	D ]$\}}|j|||fd
|i| qhdS )aY          Saves the sequence of QR codes to `out`.

        If `out` is a filename, this method modifies the filename and adds
        ``<Number of QR codes>-<Current QR code>`` to it.
        ``structured-append.svg`` becomes (if the sequence contains two QR codes):
        ``structured-append-02-01.svg`` and ``structured-append-02-02.svg``

        Please note that using a file or file-like object may result into an
        invalid serialization format since all QR codes are written to the same
        output.

        See :py:meth:`QRCode.save()` for a detailed enumeration of options.
        c                 S   s   | S r.   r   onr   r   r   <lambda>      z%QRCodeSequence.save.<locals>.<lambda>r   .Nz-{0:02d}-{1:02d}c                    s   |   |S r.   )r}   r   mr   r   r     r   )rY   rd   )r"   
isinstancestr_typerfind	enumeraterV   )r$   rq   rd   ra   filenamedot_idxr   r   r   r   r   rV     s    
zQRCodeSequence.savec                 C   s0   t | dkrt| d |S td| j|dS )zZ        Behaves like :py:class:`QRCode` iff this sequence contains a single item.
        r   r   z!{0} object has no attribute '{1}'N)r"   getattrr|   r}   r/   )r$   itemr   r   r   r     s
    zQRCodeSequence.__getattr__)NNF)N)
r   r   r   r   r   r   rs   rV   r   __classcell__r   r   r   r   r     s   
	
r   )NNNNNFNT)NNNNNFT)NNNNNT)NNNNNTN)r   
__future__r   r   rn   re    r   r   r   r   
basestringr   	NameErrorr)   __version____all__type__metaclass__r	   r
   r   r   r   tupler   r   r   r   r   <module>   s@   
  
v  
  
  
)     u