
    Pf                    r   d Z ddlZddlZddlZddlZddlZddlZddlmZm	Z	 ddl
mZ ddlmZmZ ddlZddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlZddlmZ ddlmZmZmZmZm Z m!Z!m"Z" ddlm#Z# ddl$m%Z% dZ&dZ'ed^d            Z(d Z)d Z* e)dd          	 	 	 	 d_d            Z+ e ej,        d          j-        d          Z.	 	 	 	 	 	 d`d Z/	 	 	 dad#Z0dbd$Z1	 	 dcd&Z2 e)dd'          ddd(            Z3	 	 ded)Z4dfd,Z5dgd-Z6dhd.Z7 e)dd'          did/            Z8	 	 djd1Z9dkd2Z:dld5Z;d^d6Z<d^d7Z=d^d8Z>dmd9Z?dnd:Z@d; ZAd< ZBd= ZCd> ZDdmd?ZEdmd@ZFdAdBdCdDdEdFdGZGdH ZHdI ZIi dJdKdLdMdNdOdPdQdRdSdTdUdVdWd3dXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidji dkdldmdndodpdqdOdrdsdtdudvdwdxdydzd{d|dyd}d~ddddddddddddi ddddddddddddddddddddddddddddd"dddddi ddddddddddddddddddddddddddddēddƓddȓddʓi dd̓ddΓddГddғddԓddғddדddٓddۓddݓddߓddߓddddddddddi ddddddddddddddddddddddd ddddddddd	d
di ddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-i d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdGdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZZJ	 	 	 	 	 	 	 	 dod[ZKe+e3e1e5e4e<e6e7e8e;e:e9d\ZLd^d]ZMdS (p  a   Standard serializers and utility functions for serializers.

DOES NOT belong to the public API.

The serializers are independent of the :py:class:`segno.QRCode` (and the
:py:class:`segno.encoder.Code`) class; they just need a matrix (tuple of
bytearrays).
    N)	quoteattrescapepack)chainrepeat)partialreduce)
itemgetter)contextmanager)defaultdict   )consts)matrix_to_linesget_symbol_size
get_bordercheck_valid_scalecheck_valid_bordermatrix_itermatrix_iter_verbose)zip_longest)quote)writable	write_svg	write_png	write_eps	write_pdf	write_txt	write_pbm	write_pam	write_ppm	write_xpm	write_xbm	write_texwrite_terminalz'Segno <https://pypi.org/project/segno/>c              #     K   | }d}	 | j          | t          j        |          |           }n$# t          $ r t	          | ||          }d}Y nw xY w	 |V  |r|                                 dS dS # |r|                                 w w xY w)a      Returns a writable file-like object.

    Usage::

        with writable(file_name_or_path, 'wb') as f:
            ...


    :param file_or_path: Either a file-like object or a filename.
    :param str mode: String indicating the writing mode (i.e. ``'wb'``)
    FNencodingT)writecodecs	getwriterAttributeErroropenclose)file_or_pathmoder)   f
must_closes        ?/var/www/html/env/lib/python3.11/site-packages/segno/writers.pyr   r   0   s       	AJ* **<88A   th777


 	GGIIIII	 	: 	GGIIII	s   &/ AAA2 2Bc                       fd}|S )zX    Decorator to inject a module type -> color mapping into the decorated function.
    c                 l     t          j                   dddddddddddddddf fd	            }|S )NFc                     t          |i d|d|d|d|d|d|d|	d|
d	|d
|d|d|d|d|d|d|d|} | |||fi |S )Ndarklightfinder_darkfinder_light	data_dark
data_lightversion_darkversion_lightformat_darkformat_lightalignment_darkalignment_lighttiming_darktiming_light	separatordark_module
quiet_zone)_make_colormap)matrixmatrix_sizeoutr8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   kwcmr2   s                         r4   wrapperz+colorful.<locals>.decorate.<locals>.wrapperS   s      P44 Puu PR]R] P-9\PENYP+5:PDPLP /<mP JUP .:\	P KY.	P
 1@P
 NY[P .:\P FOYP -8KP EOJPB 1V[#r88R888    )	functoolswraps)r2   rO   r8   r9   s   ` r4   decoratezcolorful.<locals>.decorateR   sj    			37uRWfk#EY^ %E%af %EUX]$		9 	9 	9 	9 	9 
		9 rP    )r8   r9   rS   s   `` r4   colorfulrU   N   s)         " OrP   c                     t          |           t          |           t          | |          }t          | ||          \  }}|||fS )u   "    Validates the scale and border and returns the width, height and the border.
    If the border is ``None´` the default border is returned.

    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    )r   r   r   r   )rK   scaleborderwidthheights        r4   _valid_width_height_and_borderr[   f   sQ     evV,,F#K??ME6&&  rP   #000)r8   r9   TsegnoqrlineFutf-8c                 
   ./ .fd} fd}t          |          \  }}|pd}|r$|r"t          d                    |                    |du }|rd}|duo|dk    .t          t	                                                              dk    }| ot          j                 duo| }|d	k    o|p|}|r |            }n6d
z   }}t          j                 //fdt           ||          D             }t          d           }t          t                    }|D ]B\  } \  }!}"}#||          \  }}||                              |!|z
  |#|z
  |"|!z
  f           |"|#f|| <   C|rdd||z  fg|t          j                 <   |s	 |d= n# t          $ r Y nw xY wi }$|d	k    rd                    |          nd}%d                    |s|%nd|sdn!d                    t          |                              }&|                                D ]\  }'}(|&}) ||'          } | ud}*t!          | t"                    r| \  } }*|)d                    t          |                     z  })|*2|)d                    t          t%          |*                              z  })|)dz  })|)d                    d t)          |(          D                       z  })|)dz  })|)|$|'<   |rst          j                 }+t+          j        dd|$|+                             dd                              dd                    ||z  ||z                                |$|+<   d},|r1|,dz  },|s%|,d                    t          |                    z  },|,dz  },|,dz  },|r|,dz  },|8|dk     r2|,d                    t          t%          |                              z  },|s|,d                     |||          z  },|s|r|,d!                    ||          z  },|
r%|,d"                    t          |
                    z  },|r%|,d                    t          |                    z  },|,d#z  },|%|,d$                    t1          |                    z  },|	%|,d%                    t1          |	                    z  },|r|,d&                    |%          z  },|,d                    t3          |$                                t          '                    z  },|r|,d(z  },|,d)z  },|r|,d*z  },t5          |d+|,          5 }-|-                    |,           ddd           dS # 1 swxY w Y   dS )-a      Serializes the QR code as SVG document.

    :param matrix: The matrix to serialize.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param out: Filename or a file-like object supporting to write bytes.
    :param scale: Indicates the size of a single module (default: 1 which
            corresponds to 1 x 1 pixel per module).
    :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 a Micro QR Codes).
    :param bool xmldecl: Inidcates if the XML declaration header should be
            written (default: ``True``)
    :param bool svgns: Indicates if the SVG namespace should be written
            (default: ``True``).
    :param str title: Optional title of the generated SVG document.
    :param str desc: Optional description of the generated SVG document.
    :param svgid: The ID of the SVG document (if set to ``None`` (default),
            the SVG element won't have an ID).
    :param svgclass: The CSS class of the SVG document
            (if set to ``None``, the SVG element won't have a class).
    :param lineclass: The CSS class of the path element (which draws the
            "black" modules (if set to ``None``, the path won't have a class).
    :param bool 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.
    :param str unit: 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
    :param str encoding: Encoding of the XML document. "utf-8" by default.
    :param float svgversion: SVG version (default: None)
    :param bool nl: Indicates if the document should have a trailing newline
            (default: ``True``)
    :param bool draw_transparent: Indicates if transparent SVG paths should be
            added to the graphic (default: ``False``)
    c                 .    | t          |           nd S )N)allow_css3_colors)_color_to_webcolor)clrrb   s    r4   	svg_colorzwrite_svg.<locals>.svg_color   s"    OR!#9JKKKKdhhrP   c               3      K   d} d}t          	
d          D ]F}|}d\  }}| dz  } fd|D             D ] }||k    r||k    r|||| ffV  |}|dz  }|}!|||| ffV  Gd S )Ng      r   rW   rX   r   r   c              3   (   K   | ]}|         V  d S NrT   .0mtcolormaps     r4   	<genexpr>z=write_svg.<locals>.matrix_to_lines_verbose.<locals>.<genexpr>   s'      11rhrl111111rP   )r   )jinvalid_colorrow
last_colorx1x2crX   ro   rJ   rK   s          r4   matrix_to_lines_verbosez*write_svg.<locals>.matrix_to_lines_verbose   s      &v{!FSSS 
	* 
	*C&JFBFA1111S111  ..:??$r2qk1111Ba

r2qk)))))
	* 
	*rP    zFThe unit "{}" has no effect if the size (width and height) is omitted.Nr_   g       @   r         ?c              3   8   K   | ]\  \  }}\  }}|||ffV  d S rk   rT   )rm   ru   y1rv   y2r8   s        r4   rp   zwrite_svg.<locals>.<genexpr>   s;      ^^*<(2rHR$R%^^^^^^rP   c                      dS )Nri   rT   rT   rP   r4   <lambda>zwrite_svg.<locals>.<lambda>   s    V rP   r   z transform="scale({})"z	<path{}{}z	 class={}z
 stroke={}z stroke-opacity={}z d="c           	   3      K   | ]N\  }\  }}}d                      |dk    rdnd||t          |          |k    rt          |          n|          V  OdS )z{moveto}{x} {y}h{l}r   mM)movetoxlyN)formatint)rm   ir   r   lengths        r4   rp   zwrite_svg.<locals>.<genexpr>   s       C C .A~1f .44AEESSs78FBEa&&A++AST 5 W W C C C C C CrP   z"/>z\sclass="[^"]+"strokefillzv{0}h-{1}z"/>z<?xml version="1.0"z encoding={}z?>
z<svgz# xmlns="http://www.w3.org/2000/svg"z version={}z width="{0}{2}" height="{1}{2}"z viewBox="0 0 {} {}"z id={}>z<title>{}</title>z<desc>{}</desc>z<g{}>keyz</g>z</svg>
wtr(   )r[   
ValueErrorr   lensetvaluesr   TYPE_QUIET_ZONETYPE_DATA_DARKr   r   listappendKeyErrorr   items
isinstancetuplestrjoin	enumerateresubreplacer   sortedr   r*   )0rJ   rK   rL   ro   rW   rX   xmldeclsvgnstitledescsvgidsvgclass	lineclassomitsizeunitr)   
svgversionnldraw_transparentre   rx   rY   rZ   omit_encodingis_multicolorneed_backgroundneed_svg_groupmiterr   r   xycoordinatesrd   ru   rv   r}   paths
scale_infopcolorcoordpathopacityksvgr2   rb   r8   s0   `` ` `                                        @@r4   r   r   t   s   Ti i i i i* * * * * * * * ;;vVVE66:2D H H ::@&,,H H 	H$M "$.D:3DHOO--..//!3M''qHV5K,LTX,Xqaq]qOaZF_%EN _''))v{1-.^^^^PVXY[\@]@]^^^	^^	$	$Bd##K"  \b"b#w1Caab 9:::b&3 Q ;<Q9O8PHV345 	D!! 	 	 	D	E;@A::)007772J^C::%.\22K4F4FyQZG[G[4\4\	^ 	^A#))++  ui?G#u%% #"WL''	#777D",33Ic'll4K4KLLL C C 2;51A1AC C C C C 	C 	e l V+,6,b(**8V<<#*75/2H2HSXZ_chZh2i2i#j#jl la C $$ 	>>((8)<)<===Cv6MC 544*s"2"2}##Ic*oo$>$>??? M077vtLLL <4 <%,,UF;;; 1xy//000 7{!!)H"5"56663JC"))&--888 ''t555 *w~~j)))2776%,,..c222333C v8OC	 t	#th	/	/	/ 1	                 s$   F 
FFT??UUs   (=)"([^"]+)"s   \1'\2'ry   c                 J   |st          t          d          nt          t          d          }t          j                    }t	          | ||f|||||||	|
||||||d| d                    |sd|z   nd |t          |                                                              S )a      Converts the matrix to a SVG data URI.

    The XML declaration is omitted by default (set ``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 and the different ``xmldecl``
    and ``nl`` default values and the additional parameter ``encode_minimal``
    and ``omit_charset`` this function uses the same parameters as the
    usual SVG serializer.

    :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)
    :rtype: str
    rP   )safes    :/=')rW   rX   r   r   r   r   r   r   r   r)   r   r   r   r   zdata:image/svg+xml{0},{1}z	;charset=ry   )r	   r   ioBytesIOr   r   _replace_quotesgetvalue)rJ   rK   rW   rX   r   r   r   r   r   r   r   r   r   r)   r   r   encode_minimalomit_charsetrM   encodebuffs                        r4   as_svg_data_urir     s    0 .<^WU%%%%U]A^A^A^F:<<Dfk4 JuVWTH!HxJ J GIJ J J 'FE;))2 6/$--//::;;= ==rP      fuchsiac           
         ddddddd}||                     |           t          |||          \  }	}
}|\  }}t          |d	d
          5 }g }|j        } |d            |d                    |	|
                      |d            |d                    |                     t          |          D ]}||z   }t          |          D ]i}||z   }| |         |         }|r|dvr|                    |||f           |                    ||          } |d                    |||                     j|D ],\  }}} |d                    |dz   |dz   |                     - |d           ddd           dS # 1 swxY w Y   dS )a      Internal SVG serializer which is useful for debugging purposes.

    This function is not exposed to the QRCode class by intention and the
    resulting SVG document is very inefficient (a lot of ``<rect/>`` elements).
    Dark modules are black and light modules are white by default. Provide
    a custom `colormap` to override these defaults.
    Unknown modules are red by default.

    :param matrix: The matrix
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param out: binary file-like object or file name
    :param scale: Scaling factor
    :param border: Quiet zone
    :param fallback_color: Color which is used for modules which are not 0x0 or 0x1
                and for which no entry in `color_mapping` is defined.
    :param colormap: dict of module values to color mapping (optional)
    :param bool add_legend: Indicates if the bit values should be added to the
                matrix (default: True)
    #fffr\   redorangegoldgreen)r   r   rz            Nr   r_   r(   z'<?xml version="1.0" encoding="utf-8"?>
z><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {0} {1}">zj<style type="text/css"><![CDATA[ text { font-size: 1px; font-family: Helvetica, Arial, sans; } ]]></style>z<g transform="scale({0})">r   r   z7<rect x="{0}" y="{1}" width="1" height="1" fill="{2}"/>z <text x="{0}" y="{1}">{2}</text>g?g?z</g></svg>
)updater[   r   r*   r   ranger   get)rJ   rK   rL   rW   rX   fallback_colorro   
add_legendclr_mappingrY   rZ   matrix_widthmatrix_heightr2   legendr*   r   r   rq   r   bitr   vals                          r4   write_svg_debugr   :  sf   0  K 8$$$:;vVVE66"-L-	#tg	.	.	. !8999NUUV[]cddeee C 	D 	D 	D*11%88999}%% 	d 	dAF
A<(( d dJQil /#Z"7"7MM1a+..."sN;;OVVWXZ[]abbccccd   	R 	RIAq#E4;;AFAFCPPQQQQn)                 s   D'FFFc                    ddl fd}d }t          |||          \  }	}
}t          |          }|r|n
 ||          }t          |d          5 }t	          ||j                  } |d            |d                    t                                |d                    t          j	        d	                                |d
            |d                    |	|
                      |d            |d           |) | dj         ||                      |r |d           |s | dj        |            |dk    r |d                    |                      |d           t          |dd          d         |z   dz
  }t          | ||d          }t          |          \  \  }}\  }}d                    ||||z
            g}|j        }|}|D ]E\  \  }}\  }} |d                    ||z
  t          ||z
            ||z
                       ||}}F |d                    |                      |d            |d           ddd           dS # 1 swxY w Y   dS )a      Serializes the QR code as EPS document.

    :param matrix: The matrix to serialize.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param out: Filename or a file-like object supporting to write strings.
    :param scale: Indicates the size of a single module (default: 1 which
            corresponds to 1 point (1/72 inch) per module).
    :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 dark: Color of the modules (default: black). The
            color can be provided as ``(R, G, B)`` tuple (this method
            acceppts floats as R, G, B values), as web color name (like
            "red") or in hexadecimal format (``#RGB`` or ``#RRGGBB``).
    :param light: Optional background color (default: ``None`` = no
            background color). See `color` for valid values.
    r   Nc                 f                         |d          D ]} | |            | d           dS )z-        Writes `content` and ``LF``.
           r   N)wrap)	writemethcontentlinetextwraps      r4   
write_linezwrite_eps.<locals>.write_line  sH    
 MM'3// 	 	DIdOOOIdOOOO	 	rP   c                 Z    d t          fdt          |           D                       S )zp        Converts the provided color into an acceptable format for Postscript's
         ``setrgbcolor``
        c                     t          | t                    r3d| cxk    rdk    s$n t          d                    |                     | S | dk    rd| z  n| S N              ?z(Invalid color "{0}". Not in range 0 .. 1r   gp?r   floatr   r   rw   s    r4   to_floatz2write_eps.<locals>.rgb_to_floats.<locals>.to_float  f    !U## a3$%O&,fQii1 1 1$%FF9q==1rP   c                 &    g | ]} |          S rT   rT   rm   r   r   s     r4   
<listcomp>z4write_eps.<locals>.rgb_to_floats.<locals>.<listcomp>  !    >>>ahhqkk>>>rP   r   _color_to_rgbrd   r   s    @r4   rgb_to_floatsz write_eps.<locals>.rgb_to_floats  s?    
	2 	2 	2 >>>>=+=+=>>>???rP   r   z%!PS-Adobe-3.0 EPSF-3.0z%%Creator: {0}z%%CreationDate: {0}z%Y-%m-%d %H:%M:%Sz%%DocumentData: Clean7Bitz%%BoundingBox: 0 0 {0} {1}z/m { rmoveto } bind defz/l { rlineto } bind defz+{0:f} {1:f} {2:f} setrgbcolor clippath fillz0 0 0 setrgbcolorz{0:f} {1:f} {2:f} setrgbcolorr   z{0} {0} scalenewpathrh   r{   rg   incbyz{0} {1} moveto {2} 0 lz {0} {1} m {2} 0 lry   r   z%%EOF)r   r[   _color_is_blackr   r	   r*   r   CREATORtimestrftimer   r   nextr   r   r   )rJ   rK   rL   rW   rX   r8   r9   r   r   rY   rZ   stroke_color_is_blackstroke_colorr2   	writeliner   	line_iterru   r}   rv   r~   r   append_coordr   r   s                           @r4   r   r   t  sl   & OOO    @ @ @ ;;vVVE66+D110I44mmD6I6IL	#t		 &J00		+,,,	"))'22333	'..t}=P/Q/QRRSSS	-...	.55eVDDEEE	+,,,	+,,,I C}}U335 6 6 6$ / 	-...$ 	MI<5<lKLLLA::Io,,U33444	) Kq;;;A>G"L#FFAR@@@	 ")__R(2r)00RbAAB|"+ 	 	HRhr2L-44R!VSa[["r'RRSSSrqAA	"''%..!!!	(	'M& & & & & & & & & & & & & & & & & &s   HI**I.1I.	   c                     t          j                    }t          | ||f|||d| d                    t	          j        |                                                              d                    S )z    Converts the provided matrix into a PNG data URI.

    See :func:`write_png` for a description of supported parameters.

    :rtype: str
    )rW   rX   compresslevelzdata:image/png;base64,{0}ascii)r   r   r   r   base64	b64encoder   decode)rJ   rK   rW   rX   r  rM   r   s          r4   as_png_data_urir    sj     :<<Dfk4guVS`ggdfggg&--f.>t}}.O.O.V.VW^._._```rP   r   c                 
   !"#$%& $fd#d }fd}	d/"fd	}
t                    t          ||          \  }}}|r6t          |          }|dk     rt          d          t          |dz            }d	d
&d$t          j        }t          j        }#fdD             }t          t          |                                          t          ddd                    !$!v }t          !          }|dk    ot          $&fd!D                       }|rdnd}d"d}|s|dk    r
|dk     rdnd"!                    t          d           |rd}t          !d                   dk    rt                                          n"d t                                          D             }t          !fd|D                       %%!d<   |                    $%fd|                                D                        n|r!v r$g!!                    $          }|dk    r4t%          | |dd          }!fd|                                D              nct'          |           }|!                    ||                   i                       |         !                    ||                   d            fd|D             }d}d}|dk    r0 |         } |
t)          ||                    |z  z  }|g|z  z  }d}dk    r1 |
t)          d|          d           dz
  z  }t+          |	|          }t-          |          }|D ]$}| |
t/          |||                    z  }||z  }%||z  }t1          |d!          5 }|j        } |d"            | |d#t5          d$||"|ddd                               |r% | |d%t5          d&||d                               |s | |d'd                    d( !D                                            t          !d                   dk    r3 | |d)d                    d* !D                                            nK|r# | |d)t5          d+|                               n%|r# | |d)t5          d,|                                | |d-t9          j        ||                                | |d.d                     ddd           dS # 1 swxY w Y   dS )0a      Serializes the QR code as PNG image.

    By default, the generated PNG will be a greyscale image (black / white)
    with a bit depth of 1. If different colors are provided, an indexed-color
    image with the same bit depth is generated unless more than two colors
    are provided. This may require a bit depth of of 2 or 4.

    :param matrix: The matrix to serialize.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param out: Filename or a file-like object supporting to write bytes.
    :param scale: Indicates the size of a single module (default: 1 which
            corresponds to 1 x 1 pixel per module).
    :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 int dpi: Optional DPI setting. By default (``None``), the PNG won't
            have any DPI information. Note that the DPI value is converted into
            meters since PNG does not support any DPI information.
    :param int compresslevel: Integer indicating the compression level
            (default: 9). 1 is fastest and produces the least
            compression, 9 is slowest and produces the most.
            0 is no compression.
    :param dict colormap: Optional module type -> color mapping. If provided, the
            `color` and `background` arguments are ignored. All undefined module
            types will have the default colors (light: white, dark: black).
            See `color` for valid color values. ``None`` is accepted as valid
            color value as well (becomes transparent).
    c                 .    | t          | d          nS )NFalpha_float)_color_to_rgb_or_rgba)rd   transparents    r4   	png_colorzwrite_png.<locals>.png_color  s!    @C$Se<<<<U``rP   c                     | |z   }t          dt          |                    |z   t          dt          j        |          dz            z   S )z3        Returns a PNG chunk with checksum.
        s   >Il    )r   r   zlibcrc32)namedata
chunk_heads      r4   chunkzwrite_png.<locals>.chunk  sI     D[
 E3t99%%
2T%JAWAWZdAd5e5eeerP   c                 .    t          fd| D              S )z2        Returns each pixel `scale` times.
        c              3   8   K   | ]}t          |          V  d S rk   )r   )rm   brW   s     r4   rp   z6write_png.<locals>.scale_row_x_axis.<locals>.<genexpr>  s-      55Ava''555555rP   )r   )rs   rW   s    r4   scale_row_x_axisz#write_png.<locals>.scale_row_x_axis  s%     555555566rP       c                     t          t          |fdt          t          |           gdz  z  ddiD                                 S )z+        Returns a single scanline.
        c              3   >   K   | ]}t          fd |          V  dS )c                     | z  |z   S rk   rT   )r   r   png_bit_depths     r4   r   z7write_png.<locals>.scanline.<locals>.<genexpr>.<lambda>  s    Q-5G14L rP   Nr
   )rm   er+  s     r4   rp   z.write_png.<locals>.scanline.<locals>.<genexpr>  sS        j  j$% !''L'L'L'La P P  j  j  j  j  j  jrP      	fillvaluer   )	bytearrayr   r   iter)rs   filter_typer+  s     r4   scanlinezwrite_png.<locals>.scanline  sw     { j  j  j  j)4tCyykQ-EW6X)hdg)h)h j  j  jk k l l 	lrP   r   zDPI value must not be negativeg
F%u?r   r   r      r5  r5  )rg   rg   rg   rg   c                 4    i | ]}| |                   S rT   rT   )rm   r   ro   r  s     r4   
<dictcomp>zwrite_png.<locals>.<dictcomp>$  s)    ;;;Qq))HQK((;;;rP   r   rz   r   c              3   &   K   | ]}|fv V  d S rk   rT   )rm   rd   blackr  whites     r4   rp   zwrite_png.<locals>.<genexpr>*  s0      0g0gX[eU8S1S0g0g0g0g0g0grP   r   Nr   r   T)r   reversec              3       K   | ]	}|d z   V  
dS )r   NrT   rm   rd   s     r4   rp   zwrite_png.<locals>.<genexpr>6  s(      IsIsY\#PT*IsIsIsIsIsIsrP   c              3   $   K   | ]
}|v|V  d S rk   rT   )rm   rd   palettes     r4   rp   zwrite_png.<locals>.<genexpr>8  s-      $U$US#WBTBTSBTBTBTBT$U$UrP   c                 (    i | ]\  }}|k    |S rT   rT   )rm   module_typerd   r  transparent_colors      r4   r7  zwrite_png.<locals>.<dictcomp>;  s7     [ [ [ 0SskGYGY ():GYGYGYrP   rh   c                 B    i | ]\  }}|                     |          S rT   )index)rm   rB  rd   r@  s      r4   r7  zwrite_png.<locals>.<dictcomp>E  s,    ___;K;{GMM#$6$6___rP   r   c              3   4   K   | ]}fd |D             V  dS )c              3   (   K   | ]}|         V  d S rk   rT   )rm   r%  color_indexs     r4   rp   z&write_png.<locals>.<genexpr>.<genexpr>M  s'      ((k!n((((((rP   NrT   )rm   rrH  s     r4   rp   zwrite_png.<locals>.<genexpr>M  s8      88Q((((a(((888888rP   rP      )r1  wbs   PNG

s   IHDRs   >2I5Bs   pHYss   >LLBs   PLTEc              3   @   K   | ]}t          d g|dd         R  V  dS )   >3BNr   r   r>  s     r4   rp   zwrite_png.<locals>.<genexpr>l  s:      )T)TS$v*@BQB*@*@*@)T)T)T)T)T)TrP   s   tRNSc              3   h   K   | ]-}t          |          d k    t          d|d                    V  .dS )r      >BN)r   r   r>  s     r4   rp   zwrite_png.<locals>.<genexpr>o  sE      -e-ecX[\_X`X`cdXdXdd5#a&.A.AXdXdXdXd-e-erP   rO  s   >1Hs   IDATs   IEND)r'  )r   r[   r   r   TYPE_FINDER_PATTERN_DARKr   r   r   r   r   r   allsort	_NAME2RGBr  r   r   rE  r   r0  r   mapr/  r   r   r*   r   r   r  compress)'rJ   rK   rL   ro   rW   rX   r  dpir"  r&  r2  rY   rZ   dark_idxqz_idxclr_mapis_transparentnumber_of_colorsis_greyscalepng_color_typepng_trans_idx
rgb_valuesr   horizontal_bordervertical_borderqz_valuesame_as_aboveidatrs   r2   r*   r9  rH  r@  r+  r  r  rC  r:  s'      ``                          @@@@@@@@r4   r   r     s   @a a a a af f f7 7 7 7 7l l l l l l JJE:;vVVE66
 !#hh77=>>>#-  EE"K.H#F;;;;;(;;;GS))**
1a0C0CDDDG G+N7||#q(gS0g0g0g0g0g0g_f0g0g0g-g-gL&-QQANMM 3a "2A!5!5AA1Md+++ 	\M/271:!/C/C))+++IsIs`i`p`p`r`rIsIsIsJ $$U$U$U$UJ$U$U$U U U*GAJNN [ [ [ [ [4;MMOO[ [ [ \ \ \	 3Gk*Gk22!#FKqKKK____w}}___ Vw}}WV_==>{62&}}WX->??A A 	B 	B 	B8888%888EOzzv&$HVHe%<%<==FN#*v-5 Mqyy U!3!3GGG5ST9U$e,,&''D  _EEFFFD	#t		 #"### 	eeGT(E6=.Z[]^`abbccddd 	>E%%gsC!;!;<<=== 	?E%%)T)TG)T)T)T!T!TUUVVV71:""eeGSXX-e-eW-e-e-e%e%effgggg BeeGT%%?%?@@AAA 	? E%%fm!<!<==>>>eeGT]4??@@AAAeeGS!!"""+# # # # # # # # # # # # # # # # # #s   
E+TT	Tc           	         d }d }	t          |||          \  }
}}d                    t          j        d          t          j        dz  t          t          j                  dz            }g }|j        }|dk    r |d                    |                     |F | d
j         |	|                       |d                    |
|                      |d           t          |          s | dj         |	|                      t          |dd          d         |z   dz
  } |d                    ||                     t          | ddd          }|
                    d |D                         |d           t          j        d                    |                              d          |          }t          |d          5 }|j        }t#          ||          }g } |d           ddd                    |
|          d                    t%          |                    fD ]U}|                    |                                            |d                    t%          |          |                     V ||            |d           |                    |                                            |d                     t%          |          |t(                               |                    |                                           |                                } |d!                    t%          |          dz                        |D ]!} |d"                    |d                     " |d#                    t%          |          dz                         |d$                    |                     d	d	d	           d	S # 1 swxY w Y   d	S )%a      Serializes the QR code as PDF document.

    :param matrix: The matrix to serialize.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param out: Filename or a file-like object supporting to write bytes.
    :param scale: Indicates the size of a single module (default: 1 which
            corresponds to 1 x 1 pixel per module).
    :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 dark: Color of the modules (default: black). The
            color can be provided as ``(R, G, B)`` tuple, as web color name
            (like "red") or in hexadecimal format (``#RGB`` or ``#RRGGBB``).
    :param light: Optional background color (default: ``None`` = no
            background color). See `color` for valid values.
    :param int compresslevel: Integer indicating the compression level
            (default: 9). 1 is fastest and produces the least
            compression, 9 is slowest and produces the most.
            0 is no compression.
    c                 B     | |                     d                     d S )Nr  )r   )r   ss     r4   write_stringzwrite_pdf.<locals>.write_string  s$    	!((7##$$$$$rP   c                 Z    d t          fdt          |           D                       S )zq        Converts the provided color into an acceptable format for PDF's
        "DeviceRGB" color space.
        c                     t          | t                    r3d| cxk    rdk    s$n t          d                    |                     | S | dk    rd| z  n| S r   r   r   s    r4   r   z1write_pdf.<locals>.to_pdf_color.<locals>.to_float  r   rP   c                 &    g | ]} |          S rT   rT   r   s     r4   r   z3write_pdf.<locals>.to_pdf_color.<locals>.<listcomp>  r   rP   r   r   s    @r4   to_pdf_colorzwrite_pdf.<locals>.to_pdf_color  s?    
	2 	2 	2 >>>>=+=+=>>>???rP   z{0}{1:+03d}'{2:02d}'z%Y%m%d%H%M%Si  <   r   z{0} 0 0 {0} 0 0 cmNz{} {} {} rgz0 0 {} {} rezf qz{} {} {} RGr   rh   r{   z1 0 0 1 {0} {1} cmrg   r  c              3   V   K   | ]$\  \  }}\  }}d                      |||          V  %dS )z{0} {1} m {2} {1} lNr   )rm   ru   r}   rv   r~   s        r4   rp   zwrite_pdf.<locals>.<genexpr>  sB      YY=OXb"xB%,,RR88YYYYYYrP   S r  rK  s   %PDF-1.4%
z-obj <</Type /Catalog /Pages 2 0 R>>
endobj
z5obj <</Type /Pages /Kids [3 0 R] /Count 1>>
endobj
zSobj <</Type /Page /Parent 2 0 R /MediaBox [0 0 {0} {1}] /Contents 4 0 R>>
endobj
z2obj <</Length {0} /Filter /FlateDecode>>
stream
z	{0} 0 {1}s   
endstream
endobj
zJ{0} 0 obj <</CreationDate(D:{1})/Producer({2})/Creator({2})
>>
endofbj
z!xref
0 {0}
0000000000 65535 f
z{0:010d} {1:05d} n
z-trailer <</Size {0}/Root 1 0 R/Info 5 0 R>>
zstartxref
{0}
%%EOF
)r[   r   r  r  timezoneabsr   r  r   r   extendr  rU  r   r   r   r*   r	   r   tellr  )rJ   rK   rL   rW   rX   r8   r9   r  rh  rl  rY   rZ   creation_datecmds
append_cmdr   r   graphicr2   r*   writestr
object_posobjxref_locationposs                            r4   r   r   {  sn   0% % %@ @ @ ;;vVVE66*11$-2O2O26-42G25dm2D2Dr2IK KM DJqyy
'..u55666
'='e)<)<=>>>
>((77888
54   >
'='d););<=== 	1Q777:VCbHAJ#**6155666FAq333EKKYYSXYYYYYYJsOOOmSXXd^^33G<<mLLG	#t		 H<//
0111GOmVE6**LSSTWX_T`T`aa	c 	? 	?C
 affhh'''H[''J==>>>>g,---!&&((###c&Z-AA	C 	C 	C!&&((###:AA#j//TUBUVVWWW 	> 	>CH-44S!<<====BII#j//\]J]^^___077FFGGG/H H H H H H H H H H H H H H H H H Hs   G=OO"O10c                 @  
 t          | |d|          }t          |          t          |          f
t          |d          5 }|j        }|D ]7}	 |d                    
fd|	D                                   |d           8	 ddd           dS # 1 swxY w Y   dS )aX      Serializes QR code in a text format.

    :param matrix: The matrix to serialize.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param out: Filename or a file-like object supporting to write text.
    :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 dark: Character to use for the black modules (default: '1')
    :param light: Character to use for the white modules (default: '0')
    r   rh   r   ry   c              3   (   K   | ]}|         V  d S rk   rT   )rm   r   colourss     r4   rp   zwrite_txt.<locals>.<genexpr>  s'      22'!*222222rP   r   N)r   r   r   r*   r   )rJ   rK   rL   rX   r8   r9   row_iterr2   r*   rs   r  s             @r4   r   r     s     6;aGGGH5zz3t99%G	#t		  	 	CE"''2222c22222333E$KKKK	                 s   ABBBc           	         d }t          |||          \  }}}t          | |||          }	t          |d          5 }
|
j        } |d                    |sdndt
          ||                              d                     |s'|	D ]#} |t           ||                               $n8|	D ]5} |d                    d |D                                   |d	           6d
d
d
           d
S # 1 swxY w Y   d
S )a      Serializes the matrix as `PBM <http://netpbm.sourceforge.net/doc/pbm.html>`_
    image.

    :param matrix: The matrix to serialize.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param out: Filename or a file-like object supporting to write binary data.
    :param scale: Indicates the size of a single module (default: 1 which
            corresponds to 1 x 1 pixel per module).
    :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 plain: Indicates if a P1 (ASCII encoding) image should be
            created (default: False). By default a (binary) P4 image is created.
    c                 P    d t          t          |           gdz  ddiD             S )z0        Packs eight bits into one byte.
        c              3   8   K   | ]}t          d  |          V  dS )c                     | dz  |z   S Nr   rT   r   r   s     r4   r   z7write_pbm.<locals>.pack_row.<locals>.<genexpr>.<lambda>  s    Q!VqL rP   Nr
   )rm   r,  s     r4   rp   z.write_pbm.<locals>.pack_row.<locals>.<genexpr>  sL       L L 00!44 L L L L L LrP   r-  r.  r   )r   r0  )iterables    r4   pack_rowzwrite_pbm.<locals>.pack_row  sD    L L$tH~~&6&:JcJJL L L 	LrP   rK  z{0}
# Created by {1}
{2} {3}
P4P1r  rP   c              3   Z   K   | ]&}t          |                              d           V  'dS )r  N)r   r   rm   r   s     r4   rp   zwrite_pbm.<locals>.<genexpr>  s4      CC!s1vv}}W55CCCCCCrP      
N)	r[   r   r   r*   r   r  r   r/  r   )rJ   rK   rL   rW   rX   plainr  rY   rZ   r  r2   r*   rs   s                r4   r    r      s    L L L ;;vVVE666;v>>H	#t		   v52ttdWeVLLVVT[__	^ 	^ 	^  	 0 0i..////0    chhCCsCCCCCDDDe                 s   B&C..C25C2c                 F   d }d }|s"t          d                    |                    t          |||          \  }	}
}t          | |||          }d\  }}}d}t	          |d          }|t	          |d          nd}t          |          pt          |           }|=|sdnd	}d
}t          |dd                   }|dz  }t          |          dk    r|dz  }n"|st          |          st          |          sd}|	                    d          }d}|s|rd}d}ng|ret          t          ||                    }|sdnd}d                    |                              d          }t          |g|R  t          |g|R  f}||nt          ||          }t          |d          5 }|j        } |d                    t"          |	|
|||                              d                     |D ]} | ||                     	 ddd           dS # 1 swxY w Y   dS )a      Serializes the matrix as `PAM <http://netpbm.sourceforge.net/doc/pam.html>`_
    image.

    :param matrix: The matrix to serialize.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param out: Filename or a file-like object supporting to write binary data.
    :param scale: Indicates the size of a single module (default: 1 which
            corresponds to 1 x 1 pixel per module).
    :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 dark: Color of the modules (default: black). The
            color can be provided as ``(R, G, B)`` tuple, as web color name
            (like "red") or in hexadecimal format (``#RGB`` or ``#RRGGBB``).
    :param light: Optional background color (default: white).
            See `color` for valid values. In addition, ``None`` is
            accepted which indicates a transparent background.
    c                 4    t          d | D                       S )z4        Inverts the row bits 0 -> 1, 1 -> 0
        c                     g | ]}|d z  S )r   rT   rm   r%  s     r4   r   z6write_pam.<locals>.invert_row_bits.<locals>.<listcomp>.  s    ///a!c'///rP   )r/  )rs   s    r4   invert_row_bitsz"write_pam.<locals>.invert_row_bits*  s!     //3///000rP   c                 F    d                     fd| D                       S )NrP   c              3   (   K   | ]}|         V  d S rk   rT   )rm   r%  r  s     r4   rp   z9write_pam.<locals>.row_to_color_values.<locals>.<genexpr>1  s'      00q
000000rP   )r   )rs   r  s    `r4   row_to_color_valuesz&write_pam.<locals>.row_to_color_values0  s*    xx0000C000000rP   zInvalid stroke color "{0}")r   r   BLACKANDWHITEFr  NGRAYSCALE_ALPHA	RGB_ALPHATr   r=  r   r5  RGBrz   )s    s    z>{0}Br  )r  rK  zRP7
# Created by {0}
WIDTH {1}
HEIGHT {2}
DEPTH {3}
MAXVAL {4}
TUPLTYPE {5}
ENDHDR
)r   r   r[   r   r  r  _color_is_white_invert_colorr   
startswithmaxr   r   r   r	   r   r*   r  )rJ   rK   rL   rW   rX   r8   r9   r  r  rY   rZ   r  depthmaxval
tuple_typetransparencyr	  bg_colorcolored_strokeis_rgbr  fmt
row_filterr2   r*   rs   s                             r4   r!   r!     s
   (1 1 11 1 1  D5<<TBBCCC:;vVVE666;v>>H 5E6:L(5AAALBGBS$U>>>>Y]H),77X?<;X;XYN.<M&&+
 bqb!122D|!!F"L	  9 9 _X=V=V 
""5))FG Cl C,	 CU<2233%,1nnU##**733'h'''c)AL)A)A)AB$+OAT^e9f9f9fJ	#t		 #   vzRRSYSYZaSbSb	d 	d 	d  	# 	#CE**S//""""	## # # # # # # # # # # # # # # # # #s   ,AHHHc                 F   t          |          }t          |||          \  }}}d                                v rt          d                                          D ]\  }}	t          |	          |<   t          | |||          }
t          |d          5 }|j        } |d	                    t          ||                              d                     |
D ],} |d                    fd|D                                  -	 ddd           dS # 1 swxY w Y   dS )a      Serializes the matrix as `PPM <http://netpbm.sourceforge.net/doc/ppm.html>`_
    image.

    :param matrix: The matrix to serialize.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param out: Filename or a file-like object supporting to write binary data.
    :param scale: Indicates the size of a single module (default: 1 which
            corresponds to 1 x 1 pixel per module).
    :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).
    NzTransparency is not supportedrK  z P6 # Created by {0}
{1} {2} 255
r  rP   c              3   >   K   | ]}t          d g|         R  V  dS )rM  Nr   rl   s     r4   rp   zwrite_ppm.<locals>.<genexpr>y  s7      EE246"666EEEEEErP   )r   r[   r   r   r   r   r   r   r*   r   r  r   r   )rJ   rK   rL   ro   rW   rX   rY   rZ   rn   rd   r  r2   r*   rs   s      `          r4   r"   r"   ^  s    JJE:;vVVE66x    8999>>## * *C$S))"6;vFFH	#t		 G2vguf--ffWoo	? 	? 	? 	G 	GCE#((EEEEEEEEEFFFF	G	G G G G G G G G G G G G G G G G G Gs   A/DDDimgc                 2   t          |||          \  }}	}t          | |||          }
|t          |          nd}|t          |          nd}t          |d          5 }|j        } |d                    |||	||                     t          |
          D ]\\  }} |d                    t          dgd |D             d                    ||	d	z
  k     rd
nd          g                               ] |d           ddd           dS # 1 swxY w Y   dS )aR      Serializes the matrix as `XPM <https://en.wikipedia.org/wiki/X_PixMap>`_ image.

    :param matrix: The matrix to serialize.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param out: Filename or a file-like object supporting to write binary data.
    :param scale: Indicates the size of a single module (default: 1 which
            corresponds to 1 x 1 pixel per module).
    :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 dark: Color of the modules (default: black). The
            color can be provided as ``(R, G, B)`` tuple, as web color name
            (like "red") or in hexadecimal format (``#RGB`` or ``#RRGGBB``).
    :param light: Optional background color (default: white).
            See `color` for valid values. ``None`` indicates a transparent
            background.
    :param str name: Name of the image (must be a valid C-identifier).
            Default: "img".
    NNoner   zG/* XPM */
static char *{0}[] = {{
"{1} {2} 2 1",
"  c {3}",
"X c {4}",
ry   "c              3   "   K   | ]
}|sd ndV  dS )rq  XNrT   r  s     r4   rp   zwrite_xpm.<locals>.<genexpr>  s+      'K'K!1(=#'K'K'K'K'K'KrP   z"{0}
r   ,};
)	r[   r   color_to_rgb_hexr   r*   r   r   r   r   )rJ   rK   rL   rW   rX   r8   r9   r  rY   rZ   r  r	  r  r2   r*   r   rs   s                    r4   r#   r#   |  s   , ;;vVVE666;v>>H-1-=#D)))6L*/*;&&&H	#t		 
  $VD%<PP		R 	R 	R
  )) 	T 	TFAsE"''%'K'Ks'K'K'K!)FQJB!O!O PR R S S T T T Tf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   B!DDDc                    t          |||          \  }}}t          | |||          }t          |d          5 }	|	j        }
 |
d                    |||                     t          |d          D ]j\  }}t          t          |          gdz  ddi}d |D             } |
d	            |
d
                    |                      |
||k     rdnd           k |
d           ddd           dS # 1 swxY w Y   dS )ad      Serializes the matrix as `XBM <https://en.wikipedia.org/wiki/X_BitMap>`_ image.

    :param matrix: The matrix to serialize.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param out: Filename or a file-like object supporting to write text data.
    :param scale: Indicates the size of a single module (default: 1 which
            corresponds to 1 x 1 in the provided unit per module).
    :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 name: Prefix for the variable names. Default: "img".
                 The prefix is used to construct the variable names:
                 ```#define <prefix>_width``` ```static unsigned char <prefix>_bits[]```
    r   zR#define {0}_width {1}
#define {0}_height {2}
static unsigned char {0}_bits[] = {{
r   )startr-  r.  r   c                 h    g | ]/}d                      t          d |ddd                             0S )z	0x{0:02x}c                     | dz  |z   S r  rT   r  s     r4   r   z&write_xbm.<locals>.<listcomp>.<lambda>  s    AFa< rP   Nrg   )r   r   )rm   bitss     r4   r   zwrite_xbm.<locals>.<listcomp>  s@    hhhZ^K&&v.G.GddPRd'T'TUUhhhrP   z    z, z,
r   r  N)	r[   r   r   r*   r   r   r   r0  r   )rJ   rK   rL   rW   rX   r  rY   rZ   r  r2   r*   r   rs   iter_r  s                  r4   r$   r$     s{     ;;vVVE666;v>>H	#t		  77=vdE67R7R	T 	T 	T  222 	1 	1FAs$s))q@C@@EhhbghhhDE&MMME$))D//"""E1v::%%40000f                 s   B/C44C8;C8r9  ptc                    fd}t          |           t          |           t          ||          }t          |d          5 }	|	j        }
 |
d                    t                                |
d                    t          j        d                               |r |
d                    |                      |
d            |
d                    |                     |r$|d	k    r |
d
                    |                     || }}t          | ||d          D ]g\  \  }}\  }} |
d                     |||z  ||z                                  |
d                     |||z  ||z                                 h |
d            |
d                    |sdnd                     ddd           dS # 1 swxY w Y   dS )a`      Serializes the matrix as LaTeX PGF picture.

    Requires the `PGF/TikZ <https://en.wikipedia.org/wiki/PGF/TikZ>`_ package
    (i.e. ``\usepackage{pgf}``) in the LaTeX source.

    :param matrix: The matrix to serialize.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param out: Filename or a file-like object supporting to write text data.
    :param scale: Indicates the size of a single module (default: 1 which
            corresponds to 1 x 1 in the provided unit per module).
    :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 str dark: LaTeX color name. The color name is taken at it is, so
            ensure that it refers either to a default color name or that the
            color was defined previously.
    :param unit: Unit of the drawing (default: ``pt``)
    :param url: Optional URL where the QR code should point to. Requires the
            "hyperref" package. Default: ``None``.
    c                 2    d                     | |          S )Nz\pgfqpoint{{{0}{2}}}{{{1}{2}}}ro  )r   r   r   s     r4   pointzwrite_tex.<locals>.point  s    0771dCCCrP   r   z% Creator:  {0}
z% Date:     {0}
z%Y-%m-%dT%H:%M:%Sz\href{{{0}}}{{z\begin{pgfpicture}
z  \pgfsetlinewidth{{{0}{1}}}
r9  z  \color{{{0}}}
rg   r  z  \pgfpathmoveto{{{0}}}
z  \pgfpathlineto{{{0}}}
z  \pgfusepath{stroke}
z\end{{pgfpicture}}{0}
ry   }N)
r   r   r   r   r*   r   r  r  r  r   )rJ   rK   rL   rW   rX   r8   r   urlr  r2   r*   r   r   ru   r}   rv   r~   s         `          r4   r%   r%     s   ,D D D D D evV,,F	#t		 I!((11222!((7J)K)KLLMMM 	1E#**3//000%&&&/66udCCDDD 	5DGOOE&--d33444w1"1&!Qb"I"I"I 	V 	VHRhr2E.55eeBJU
6S6STTUUUE.55eeBJU
6S6STTUUUU()))(//#0F3GGHHHI I I I I I I I I I I I I I I I I Is   E8G

GGc                    t          |d          5 }|j        }d dD             }t          | |d|          D ]~}d}d}	|D ]>}
|
|k    r|	dz  }	|	r* |||                     |d|	z              |d	           |
}d}	?|	r* |||                     |d|	z              |d	            |d
           	 ddd           dS # 1 swxY w Y   dS )a      Function to write to a terminal which supports ANSI escape codes.

    :param matrix: The matrix to serialize.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param out: Filename or a file-like object supporting to write text.
    :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).
    r   c                 8    g | ]}d                      |          S )z[{0}mro  r  s     r4   r   z"write_terminal.<locals>.<listcomp>  s&    :::Q;%%a((:::rP   )   1   r   rh   rg   r     z[0mr   N)r   r*   r   )rJ   rK   rL   rX   r2   r*   r  rs   prev_bitcntr   s              r4   r&   r&     s~    
#t		 ::':::v{!FKKK 	 	CHC 	 	(??1HCC )gh/000dSj)))i((("HCC !gh'(((dSj!!!i   E$KKKK#	                 s   B&CC	C	c                    ddl }ddl}ddl}|j        j        }|j        j                            d          }|                    d          }|j        j        	                    ||          }	|	st          d          |                    d|j                  d         }
t          |j        j        j        |          }d|
f}t          | |d	|
          D ]s}d}d}|D ]3}||k    r|d	z  }|r |||                     |d|z             |}d	}4|r |||                     |d|z              ||
            |d           tdS )a      Function to write a QR code to a MS Windows terminal.

    :param matrix: The matrix to serialize.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :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).
    r   Ni   zKCannot find information about the console. Not running on the command line?s   hhhhHhhhhhhr      r   rh   rg   r  r   )sysstructctypesstdoutr*   windllkernel32GetStdHandlecreate_string_bufferGetConsoleScreenBufferInfoOSErrorunpackrawr	   SetConsoleTextAttributer   )rJ   rK   rX   r  r  r  r*   std_outcsbiresdefault_color	set_colorr  rs   r  r  r   s                    r4   write_terminal_winr    s    JJJMMMMMMJEm$11#66G&&r**D
-
 
;
;GT
J
JC : 9 : : 	:MM.$(;;A>M.FPPIM"G6;aGGG   	 	Chq &Igh/000E$*%%% 	Igh'(((E$*	-   d! rP   c                 j  	 ddddd	t          | |d|          gdz  }t          |d	          5 }|j        }t          |d
t	          d          iD ]H\  }} |d                    	fdt          ||          D                                   |d           I	 ddd           dS # 1 swxY w Y   dS )a      Function to write a QR code to a terminal using unicode half-block characters.
    Custom colors are not used.

    :param matrix: The matrix to serialize.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param out: Filename or a file-like object supporting to write text.
    :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).
    rq  u   ▀u   ▄u   █))r   r   r   )r   r   ri   r   rh   rz   r   r.  ry   c              3   (   K   | ]}|         V  d S rk   rT   )rm   pairblockss     r4   rp   z)write_terminal_compact.<locals>.<genexpr>S  s'      LL4&,LLLLLLrP   r   N)r   r   r*   r   r   r   zip)
rJ   rK   rL   rX   itr2   r*   top_row
bottom_rowr  s
            @r4   write_terminal_compactr  >  s+     F
 fk6
B
B
B	Ca	GB	#t		 #.#HfQii#H#H 	 	GZE"''LLLL3w
3K3KLLLLLMMME$KKKK	                 s   A*B((B,/B,c                 P    t          | |          }|d         dv r
|dd         S |S )a<      Returns the provided color as ``(R, G, B)`` or ``(R, G, B, A)`` tuple.

    If the alpha value is opaque, an RGB tuple is returned, otherwise an RGBA
    tuple.

    :param color: A web color name (i.e. ``darkblue``) or a hexadecimal value
            (``#RGB`` or ``#RRGGBB``) or a RGB(A) tuple (i.e. ``(R, G, B)`` or
            ``(R, G, B, A)``)
    :param bool alpha_float: Indicates if the alpha value should be returned as
            float value. If ``False``, the alpha value is an integer value in
            the range of ``0 .. 254``.
    :rtype: tuple
    r  r   )r   r5  N)_color_to_rgba)r   r  rgbas      r4   r  r  W  s7     %[999DAw*BQBxKrP   c                    t          |           rdS t          |           rdS t          |           }d}t          |          dk    r|r
 dj        | S |d         }|dd         } dj        | }|rq|dk    rd	}nh|d
k    rd}n_|d         |d         k    rM|d         |d         k    r;|d         |d         k    r)d                    |d         |d         |d                   }||n||fS )a{      Returns either a hexadecimal code or a color name.

    :param color: A web color name (i.e. ``darkblue``) or a hexadecimal value
            (``#RGB`` or ``#RRGGBB``) or a RGB(A) tuple (i.e. ``(R, G, B)`` or
            ``(R, G, B, A)``)
    :param bool allow_css3_colors: Indicates if a CSS3 color value like
            rgba(R G, B, A) is an acceptable result.
    :param bool optimize: Inidcates if the shortest possible color value should
            be returned (default: ``True``).
    :rtype: str
    :return: The provided color as web color: ``#RGB``, ``#RRGGBB``,
            ``rgba(R, G, B, A)``, or web color name.
    r\   r   Nr   zrgba({0},{1},{2},{3})r   #{0:02x}{1:02x}{2:02x}z#d2b48ctanz#ff0000r   r   rz   r      z
#{0}{1}{2})r  r  r  r   r   )r   rb   optimizerd   alpha_channelhxs         r4   rc   rc   l  s    u v			 v

&
&CM
3xx1}} 	81*1377A"1"g	(	!	(#	.B :??BB9__BBUbe^^1A2a5BqE>>$$RUBqE2a599B&22R,??rP   c                 0     dj         t          |            S )a      Returns the provided color in hexadecimal representation.

    :param color: A web color name (i.e. ``darkblue``) or a hexadecimal value
            (``#RGB`` or ``#RRGGBB``) or a RGB(A) tuple (i.e. ``(R, G, B)`` or
            ``(R, G, B, A)``)
    :returns: ``#RRGGBB``.
    r  )r   r   r   s    r4   r  r    s     +#*M%,@,@AArP   c                 V    	 |                                  } n# t          $ r Y nw xY w| dv S )a?      Returns if the provided color represents "black".

    :param color: A web color name (i.e. ``darkblue``) or a hexadecimal value
            (``#RGB`` or ``#RRGGBB``) or a RGB(A) tuple (i.e. ``(R, G, B)`` or
            ``(R, G, B, A)``)
    :return: ``True`` if color is represents black, otherwise ``False``.
    )r\   z#000000r9  r3  )r   r   r   r5  )r   r   r   r   lowerr-   r  s    r4   r  r    sH        % % %    
$$c                 V    	 |                                  } n# t          $ r Y nw xY w| dv S )a?      Returns if the provided color represents "black".

    :param color: A web color name (i.e. ``darkblue``) or a hexadecimal value
            (``#RGB`` or ``#RRGGBB``) or a RGB(A) tuple (i.e. ``(R, G, B)`` or
            ``(R, G, B, A)``)
    :return: ``True`` if color is represents white, otherwise ``False``.
    )r   z#ffffffr:  r4  )r5  r5  r5  r5  )r5  r5  r5  r   r  r  s    r4   r  r    sK        A A Ar  c                     t          |           }t          |          dk    r)t          d                    |d         |                     |S )aX      Converts web color names like "red" or hexadecimal values like "#36c",
    "#FFFFFF" and RGB tuples like ``(255, 255 255)`` into a (R, G, B) tuple.

    :param color: A web color name (i.e. ``darkblue``) or a hexadecimal value
            (``#RGB`` or ``#RRGGBB``) or a RGB tuple (i.e. ``(R, G, B)``))
    :return: ``(R, G, B)`` tuple.
    r   z?The alpha channel {0} in color "{1}" cannot be converted to RGB)r  r   r   r   )r   rgbs     r4   r   r     sR      
&
&C
3xx1}} ,,2F3q65,A,AC C 	CJrP   c                 8   g }|rdnd}t          | t                    rt          |           }d}d|cxk    rdk    rn nt          | dd                   D ]4\  }}d|cxk    odk    nc }|                    |           |r|d	k    r n5|rK|dk    r*|                    t          | d         |                     n|                    |d                    |rt          |          S t          d
                    |                     	 t          | 	                                         |z   S # t          $ ra 	 t          | |          }t          |          dk    r|cY S ||z   cY S # t          $ r# t          d                    |                     w xY ww xY w)a      Returns a (R, G, B, A) tuple.

    :param color: A web color name (i.e. ``darkblue``) or a hexadecimal value
            (``#RGB`` or ``#RRGGBB``) or a RGB(A) tuple (i.e. ``(R, G, B)`` or
            ``(R, G, B, A)``)
    :param bool alpha_float: Indicates if the alpha value should be returned as
            float value. If ``False``, the alpha value is an integer value in
            the range of ``0 .. 254``.
    :return: ``(R, G, B, A)`` tuple.
    )r   r  Fr   r   Nr   r5  rz   zUnsupported color "{0}"r  zZUnsupported color "{0}". Neither a known web color name nor a color in hexadecimal format.)r   r   r   r   r   _alpha_valuer   r   rS  r  r   _hex_to_rgb_or_rgba)	r   r  r  r  
col_lengthis_validr   partrd   s	            r4   r  r    s    C)5FFvM% BZZ

a$U2A2Y//  4++++++++

4    166E $* 1??JJ|E!HkBBCCCCJJ}Q/000 	::299%@@AAA-'-77 
- 
- 
-		-%eEEEC3xx1}}


]**** 	- 	- 	- M$fUmm- - -	-
-s0   !D. .
F9%E(F!E(%F(-FFc                      d         dk    r
 dd          dt                     cxk     rdk     r>n n;d                     fdt          t                               D                        t                     }|d	vr"t          d
                                         t           fdt          d|d          D                       }|r(|dk    r"|dd         t          |d         |          fz   }|S )a9      Helper function to convert a color provided in hexadecimal format (``#RGB``
    or ``#RRGGBB``) to a RGB(A) tuple.

    :param str color: Hexadecimal color name.
    :param bool alpha_float: Indicates if the alpha value should be returned as
            float value. If ``False``, the alpha value is an integer value in
            the range of ``0 .. 254``.
    :return: Tuple of integer values representing a RGB(A) color.
    :rtype: tuple
    :raises: :py:exc:`ValueError` in case the provided string could not
                converted into a RGB(A) tuple
    r   #r   Nrz   r   ry   c                 &    g | ]}|         d z  S )rz   rT   rm   r   r   s     r4   r   z'_hex_to_rgb_or_rgba.<locals>.<listcomp>  s!    AAA!qAAAArP   )r  r-  z4Input #{0} is not in #RRGGBB nor in #RRGGBBAA formatc                 F    g | ]}t          ||d z            d          S )rz      )r   r  s     r4   r   z'_hex_to_rgb_or_rgba.<locals>.<listcomp>  s/    IIIQU1QU7^R((IIIrP   r-  r   )r   r   r   r   r   r   r  )r   r  	color_lenr  s   `   r4   r  r    s    Qx3abb	3u::AAAAuSZZ/@/@AAABBE

IOVVW\]]^^^
IIII%9a2H2HIII
J
JC =yA~~"1"gc!fk::<<JrP   r   r{   g      ?g      ?g      ?r   )r5     @       r  r   c                    |rgt          | t                    s?d| cxk    rdk    r1n nt                              | t          d| dz  z                      S nPd| cxk    rdk    rn n@| S n=t          | t                    sd| cxk    rdk    rn n| S nd| cxk    rdk    rn n| dz  S t	          d                    |                     )Nr   r5  z%.02fg     o@r   z Invalid alpha channel value: {0})r   r   _ALPHA_COMMONSr   r   r   )r   r  s     r4   r  r    s#    %%'' 	E    S     %))%w%%-7P1Q1QRRR ! E    S      ! %'' 	%E    S      ! E    S     u}$
7>>uEE
F
FFrP   c                 4    t          d | D                       S )z    Returns the inverse color for the provided color.

    This function does not check if the color is a valid RGB / RGBA color.

    :param rgb: (R, G, B) or (R, G, B, A) tuple.
    c                     g | ]}d |z
  S r  rT   )rm   rw   s     r4   r   z!_invert_color.<locals>.<listcomp>6  s    ///a#'///rP   )r   )rgb_or_rgbas    r4   r  r  .  s!     //;///000rP   	aliceblue)r     r5  antiquewhite)         aqua)r   r5  r5  
aquamarine)   r5     azure)r  r5  r5  beige)   r     bisque)r5        r3  blanchedalmond)r5  r     blue)r   r   r5  
blueviolet)   +      brown)   *   r,  	burlywood)         	cadetblue)_         
chartreuse)r  r5  r   	chocolate)   i      coral)r5  r  P   cornflowerblue)d         cornsilk)r5  r  r  crimson)r     rm  cyandarkblue)r   r      darkcyan)r   rE  rE  darkgoldenrod)r/        darkgray)   rK  rK  	darkgreen)r   r=  r   darkgrey	darkkhaki)      k   darkmagenta)rE  r   rE  darkolivegreen)U   rQ  /   
darkorange)r5     r   
darkorchid)   2      darkred)rE  r   r   
darksalmon)      z   darkseagreen)      rb  darkslateblue)H   =   rE  darkslategray)rU  O   rh  darkslategreydarkturquoise)r         
darkviolet)   r      deeppink)r5  rB     deepskyblue)r      r5  dimgray)r8  r8  r8  dimgrey
dodgerblue)r9     r5  	firebrick)   "   rz  floralwhite)r5  r  r  forestgreen)rz  rE  rz  )r5  r   r5  	gainsboro)r  r  r  
ghostwhite)r  r  r5  r   )r5  r  r   	goldenrod)   r+  r  gray)r
  r
  r
  r   )r   r
  r   greenyellow)   r5  rU  greyhoneydew)r  r5  r  hotpink)r5  r8     	indianred)r$  \   r  indigo)K   r      ivory)r5  r5  r  khaki)r     rW  lavender)r  r  r  lavenderblush)r5  r  r  	lawngreen)|      r   lemonchiffon)r5  r  r$  	lightblue)r     r  
lightcoral)r  r
  r
  	lightcyan)   r5  r5  lightgoldenrodyellow)r  r  r7  	lightgray)ro  ro  ro  
lightgreen)rw     rw  	lightgrey	lightpink)r5        lightsalmon)r5  r4  r`  lightseagreen)r  ry     lightskyblue)r0  rk  r  lightslategray)w      rY  lightslategreylightsteelblue)   r"  r.  lightyellow)r5  r5  r  lime)r   r5  r   	limegreen)rZ  r$  rZ  linen)r  r  r  magentamaroon)r
  r   r   mediumaquamarine)f   r$  r  
mediumblue)r   r   r$  mediumorchid)   rT  ro  mediumpurple)rq  p      mediumseagreen)rm     q   mediumslateblue){   h   r  mediumspringgreen)r   r     mediumturquoise)re  rl  r[  mediumvioletred)         midnightblue)   r  r  	mintcream)r  r5  r  	mistyrose)r5  r!     moccasin)r5  r!     navajowhite)r5  r.  r  navy)r   r   r
  oldlace)   r  r  olive)r
  r
  r   	olivedrab)rQ     #   r   )r5  r+  r   	orangered)r5  E   r   orchid)r  r     palegoldenrod)r     r  	palegreen)      r  paleturquoise)   r  r  palevioletred)r  r  rq  
papayawhip)r5        	peachpuff)r5  r     peru)r$  r  ?   pink)r5        plum)   r4  r  
powderblue)r  r  r  purple)r
  r   r
  r   )r5  r   r   	rosybrown)rc  rb  rb  	royalblue)A   r8  r  saddlebrown)rE  r     salmon)r  r
  r   
sandybrown)      `   seagreen).   rE  W   seashell)r5  r  r  sienna)r4  R   -   silver)r  r  r  skyblue)r0  rk  r  	slateblue)j   Z   r$  	slategray)r  r
  rw  	slategreysnow)r5  r  r  springgreen)r   r5  r  	steelblue)F   r  r  )r7  r  rW  )r   r
  r
  )r  rs  r  )r5  c   G   )r  r     )r  r  r  )r  r.  r  r4  )r  r  r  )r5  r5  r   )r  r$  rZ  )r  tealthistletomato	turquoisevioletwheatr:  
whitesmokeyellowyellowgreenc                    d| |k    }|sUt           j        t           j        t           j        g| dk     r+                    t           j        t           j        f           nZ| dk     rTt           j        t           j        g| dk     r6                    t           j        t           j        t           j        g           t           j        |dur|n|t           j        |dur|n|t           j	        |dur|n|t           j
        |dur|n|t           j        |dur|n|t           j        |	dur|	n|t           j        |dur|n|t           j        |dur|n|t           j        |dur|n|t           j        |dur|n|t           j        |
dur|
n|t           j        |dur|n|t           j        |dur|n|t           j        |dur|n|t           j        |dur|n|i}fd|                                D             S )a      Creates and returns a module type -> color map.

    The result can be used for serializers which support more than two colors.

    Examples

    .. code-block:: python

        # All dark modules (data, version, ...) will be dark red, the dark
        # modules of the finder patterns will be blue
        # The light modules will be rendered in the serializer's default color
        # (usually white)
        cm = colormap(dark='darkred', finder_dark='blue')

        # Use the serializer's default colors for dark / light modules
        # (usually black and white) but the dark modules of the timing patterns
        # will be brown
        cm = colormap(timing_dark=(165, 42, 42))

    :param int matrix_width: Matrix width
    :param int matrix_height: Matrix height
    :param dark: Default color of dark modules
    :param light: Default color of light modules
    :param finder_dark: Color of the dark modules of the finder patterns.
    :param finder_light: Color of the light modules of the finder patterns.
    :param data_dark: Color of the dark data modules.
    :param data_light: Color of the light data modules.
    :param version_dark: Color of the dark modules of the version information.
    :param version_light: Color of the light modules of the version information.
    :param format_dark: Color of the dark modules of the format information.
    :param format_light: Color of the light modules of the format information.
    :param alignment_dark: Color of the dark modules of the alignment patterns.
    :param alignment_light: Color of the light modules of the alignment patterns.
    :param timing_dark: Color of the dark modules of the timing patterns.
    :param timing_light: Color of the light modules of the timing patterns.
    :param separator: Color of the separator.
    :param dark_module: Color of the dark module.
    :param quiet_zone: Color of the quiet zone / border.
    :rtype: dict
    rT   r(  r  r  Fc                 $    i | ]\  }}|v	||S rT   rT   )rm   rn   r   unsupporteds      r4   r7  z"_make_colormap.<locals>.<dictcomp>   s)    MMMCr7L7LB7L7L7LrP   )r   TYPE_DARKMODULETYPE_VERSION_DARKTYPE_VERSION_LIGHTrt  TYPE_ALIGNMENT_PATTERN_DARKTYPE_ALIGNMENT_PATTERN_LIGHTrP  TYPE_FINDER_PATTERN_LIGHTr   TYPE_DATA_LIGHTTYPE_TIMING_DARKTYPE_TIMING_LIGHTTYPE_FORMAT_DARKTYPE_FORMAT_LIGHTTYPE_SEPARATORr   r   )r   r   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   	is_squaremt2colorr  s                        @r4   rI   rI     s:   d K-I 	F-v/GIbc" BFDghiii			/1JK" 6 & B & C E F F F 	'58P8PVZ(,e:S:S,,Y^IU,B,Byyj.E.E

5 ,e2K2K,,QU!M4N4N==TY*nTY>Y>YNN_c+W\@\@\__bg50H0Hd ,e2K2K,,QV50H0Hd ,e2K2K,,QVIU,B,Byy{%/G/GTj.E.E

5H" NMMM8>>#3#3MMMMrP   )r   pngepstxtpdfanspbmpamppmtexxbmxpmc                 *   d}|P	 |j         }d}n# t          $ r |}Y nw xY w||                    d          dz   d                                         }n|                                }| o|dk    }	 t          |s|nd         }	n0# t
          $ r# t          d                    |                    w xY w|rQt          j	        |d	|
                    d
d                    5 }
 |	| ||
fi | ddd           dS # 1 swxY w Y   dS  |	| ||fi | dS )a"      Serializes the matrix in any of the supported formats.

    :param matrix: The matrix to serialize.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param out: A filename or a writable file-like object with a
            ``name`` attribute. If a stream like :py:class:`io.ByteIO` or
            :py:class:`io.StringIO` object without a ``name`` attribute is
            provided, use the `kind` parameter to specify the serialization
            format.
    :param kind: If the desired output format cannot be extracted from
            the filename, this parameter can be used to indicate the
            serialization format (i.e. "svg" to enforce SVG output)
    :param kw: Any of the supported keywords by the specific serialization
            method.
    FNT.r   svgzr   zUnknown file extension ".{0}"rK  r  r  )r  )r  r-   rfindr  _VALID_SERIALIZERSr   r   r   gzipr.   pop)rJ   rK   rL   kindrM   	is_streamfnameextis_svgz
serializerr2   s              r4   saverC  3  s   " I|	HEII 	 	 	EEE	EKK$$q())*0022jjllm-vGF'7(EF

 F F F8??DDEEEF 3YsD0J0JKKK 	5qJv{A44444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	
6;22r22222s*   	 3B -B2"C;;C?C?rk   )r   NTTNNNr]   r^   FNr_   NTF)r   NFTNNNr]   r^   Fry   r_   NFFF)r   Nr   NT)r   Nr\   N)r   Nr  )r   Nr  N)r   Nr\   Nr  )Nr  r  )r   NF)r   Nr\   r   )r   N)r   Nr\   r   r  )r   Nr  )r   Nr9  r  N)T)TT)FFFFFFFFFFFFFFF)N__doc__r   r   r  r+   r  r;  xml.sax.saxutilsr   r   r  r   	itertoolsr   r   rQ   r	   r   operatorr   
contextlibr   collectionsr   r  ry   r   utilsr   r   r   r   r   r   r   r   urllib.parser   __all__r  r   rU   r[   r   compiler   r   r   r   r   r  r   r   r   r    r!   r"   r#   r$   r%   r&   r  r  r  rc   r  r  r  r   r  r  r  r  r  rS  rI   r:  rC  rT   rP   r4   <module>rN     s    
			 				     . . . . . . . .       # # # # # # # #                       % % % % % % # # # # # #       L L L L L L L L L L L L L L L L L L ! ! ! ! ! !      7
 4    :  0! ! ! 
vT"""PTFMFM9>Z Z Z #"Zz '*"*%566:JGG :>594;=?:?7<"= "= "= "=J @D7;#7 7 7 7tV V V Vr :>"#a a a a 
vV$$$\# \# \# %$\#~ DJ()ZH ZH ZH ZHz   ,% % % %PE# E# E# E#P 
vV$$$G G G %$G: DJ!&$ $ $ $N   B+I +I +I +I\   D' ' ' 'T   2   *"@ "@ "@ "@J	B 	B 	B% % %"A A A"   +- +- +- +-\   8 $DSIIG G G$1 1 1TTOT MT /	T
 _T _T oT YT oT KT .T ]T T T -T  !T" ^#T T$ o%T& 'T( })T* M+T, -T. /T0 ^1T2 3T4 5T6 7T8 9T: =;T< m=T> -?T@ .ATB {CTD /ET T TF OGTH ]ITJ \KTL \MTN ]OTP -QTR STT =UTV WTX YTZ .[T\ ]T^ ?_T` =aTb }cTd eTf /gT T Th MiTj kTl OmTn [oTp >qTr OsTt uTv wTx yTz l{T| _}T~ _T@ ATB _CTD ETF OGTH IT T TJ /KTL MTN OOTP QTR /STT UTV WTX ?YTZ ^[T\ O]T^ o_T` oaTb ocTd ?eTf KgTh iTj _kT T Tl }mTn koTp qTr +sTt NuTv OwTx nyTz {T| }T~ ~T@ ~ATB MCTD ETF GTH ITJ ?KTL KMT T TN OTP ]QTR STT mUTV WTX oYTZ _[T\ ]T^ __T` _aTb /cTd eTf NgTh OiTj OkTl /mTn moT T Tp 
;qTr sTt uTv =wTx oyTz .{T| }T~ T@ mATB oCTD ETF GTH ITJ KTL OMTN =OTP QT TR !!gT T T	p 49/45:389>3805#ON ON ON ONf    $3 $3 $3 $3 $3 $3rP   