Ë
    ÚŠ±jö ã                   ó®  — d Z ddlmZmZmZmZ ddlmZmZ ddl	m
Z
mZmZ ddlZddlZddlZddlmZ ddlmZ dd	l	mZ ddlZej,                  Z[d
Z G d„ de«      Z edd«      Z	 	 dFd„Z	 	 dGd„ZdHd„ZdId„ZdId„Z d„ Z!d„ Z"d„ Z#dZ$d„ Z%d„ Z&d„ Z'd„ Z(d„ Z)d„ Z*dHd„Z+d„ Z,d „ Z-d!„ Z.d"„ Z/d#„ Z0d$„ Z1d%„ Z2d&„ Z3d'„ Z4dHd(„Z5dJd)„Z6d*„ Z7d+„ Z8d,„ Z9dId-„Z:d.„ Z;d/„ Z<d0„ Z= ej|                  d1 ej~                  ej€                  «      z   d2z   «      ZAd3„ ZBd4„ ZCd5„ ZDdId6„ZEd7„ ZFd8„ ZGd9„ ZHd:„ ZId;„ ZJd<„ ZKd=„ ZL G d>„ d?«      ZM G d@„ dAeN«      ZO G dB„ dC«      ZP G dD„ dEeN«      ZQy)KzœQR Code and Micro QR Code encoder.

DOES NOT belong to the public API.

"QR Code" and "Micro QR Code" are registered trademarks of DENSO WAVE INCORPORATED.
é    )Ú
itemgetterÚgtÚltÚxor)ÚpartialÚreduce)ÚisliceÚchainÚproductN)Ú
namedtupleé   )Úconsts)Úzip_longest)ÚencodeÚencode_sequenceÚDataOverflowErrorc                   ó   — e Zd ZdZy)r   ab      Indicates a problem that the provided data does not fit into the
    provided QR Code version or the data is too large in general.

    This exception is inherited from :py:exc:`ValueError` and is only raised
    if the data does not fit into the provided (Micro) QR Code version.

    Basically it is sufficient to catch a :py:exc:`ValueError`.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úR/var/www/io.vulcan-creative.com/venv/lib/python3.12/site-packages/segno/encoder.pyr   r      s   „ òr   r   ÚCodez"matrix version error mask segmentsc	                 ó,  — t        |«      }|s,|�*|t        j                  v rt        dt	        |«      › d�«      ‚|r,|�*|t        j                  vrt        dt	        |«      › d�«      ‚t        |d¬«      }t        |«      }|�2|�0t        ||«      s$t        dt        |«      › dt	        |«      › d�«      ‚|t        j                  k(  r|s|t        j                  v rt        d	«      ‚|r|s|t        j                  v rt        d
«      ‚t        | ||«      }	t        |	|||¬«      }
|€|
}n(|
|kD  r#t        dt	        |«      › dt	        |
«      › �«      ‚|€#|t        j                  k7  rt        j                  }|dk  }t        ||«      }t!        |	|||||«      S )aÊ      Creates a (Micro) QR code.

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

    Contrary to ``make`` this function returns a named tuple:
    ``(matrix, version, error, mask, segments)``

    Note that ``version`` is always an integer referring
    to the values of the :py:mod:`segno.consts` constants. ``error`` is ``None``
    iff a M1 QR Code was generated, otherwise it is always an integer.

    :rtype: namedtuple
    zA Micro QR Code version ("z-") is provided but parameter "micro" is FalsezIllegal Micro QR Code version "ú"T©Úaccept_nonezMode "z" is not available in version "z>Error correction level "H" is not available for Micro QR Codesz0The ECI mode is not available for Micro QR Codes©ÚeciÚmicroz-The provided data does not fit into version "z"Proposal: version r   )Únormalize_versionr   ÚMICRO_VERSIONSÚ
ValueErrorÚget_version_nameÚnormalize_errorlevelÚnormalize_modeÚis_mode_supportedÚget_mode_nameÚERROR_LEVEL_HÚprepare_dataÚfind_versionr   Ú
VERSION_M1ÚERROR_LEVEL_LÚnormalize_maskÚ_encode)ÚcontentÚerrorÚversionÚmodeÚmaskÚencodingr!   r"   Úboost_errorÚsegmentsÚguessed_versionÚis_micros               r   r   r   -   sÇ  € ô    Ó(€GÙ�UÐ&¨7´f×6KÑ6KÑ+KÜÐ5Ô6FÀwÓ6OÐ5Pð QFð Fó Gð 	Gá�Ð$¨¼×8MÑ8MÑ)MÜÐ:Ô;KÈGÓ;TÐ:UÐUVÐWÓXÐXÜ  °DÔ9€EÜ˜$Ó€DØÐ˜GÐ/Ü% d¨GÔ4Ü˜6¤-°Ó"5Ð!6Ð6UÔVfÐgnÓVoÐUpÐpqÐrÓsÐsØ”×$Ñ$Ò$©%°7¼f×>SÑ>SÑ3SÜÐYÓZÐZÙ
‘˜¤F×$9Ñ$9Ñ9ÜÐKÓLÐLÜ˜G T¨8Ó4€HÜ" 8¨U¸À5ÔI€OØ€Ø!‰Ø	˜7Ò	"ÜÐ"OÔP`ÐahÓPiÐOjð k5Ü5EÀoÓ5VÐ4Wð!Yó Zð 	Zà€}˜¤F×$5Ñ$5Ò5Ü×$Ñ$ˆØ˜‰{€HÜ˜$ Ó)€DÜ�8˜U G¨T°3¸ÓDÐDr   c	                 ó^  ‡‡‡— ˆfd„}	d„ }
	 	 dd„Šˆˆˆfd„}t        |«      }|�|dk  r%t        dt        |«      › d	�«      ‚|€t        d
«      ‚|�"d|cxk  rdk  st        d«      ‚ t        d«      ‚t        |d¬«      }|€t        j
                  }t        |«      }t        |d¬«      }t        | |‰«      }d}|€1	 t        ||‰d¬«      }|r||xs |k  rt        |||xs ||‰|¬«      gS t        |j                  «      dkD  rt        d«      ‚|j                  d   }|t        j                  k(  rt        | «      } |�t        | «      |k  rt        d|› d�«      ‚t!        | «      }|xs d}|� || |||«      }|dkD  rt        d|› �«      ‚ |
| |«      }|�( |	t#        |t        ¬«      |«      }t        ||‰dd¬«      }t%        t&        t        |«      dz
  |¬«      }t)        |«      D ��cg c]$  \  }}t         |	||«      |||‰| ||«      ¬«      ‘Œ& c}}S # t        $ r Y �ŒYw xY wc c}}w )z›    EXPERIMENTAL: Creates a sequence of QR codes in Structured Append mode.

    :return: Iterable of named tuples, see :py:func:`encode` for details.
    c                 óV   •— t        «       }|j                  t        | |‰¬«      «       |S )z;        Creates a Segments sequence with one item.
        )r5   r7   )ÚSegmentsÚadd_segmentÚmake_segment)Úchunkr5   Úsegsr7   s      €r   Úone_item_segmentsz*encode_sequence.<locals>.one_item_segmentsa   s(   ø€ ô ‹zˆØ×Ñœ e°$ÀÔJÔKØˆr   c           
      óÀ   — t        t        | «      |«      \  }}t        |«      D �cg c]-  }| ||z  t        ||«      z   |dz   |z  t        |dz   |«      z    ‘Œ/ c}S c c}w ©Nr   )ÚdivmodÚlenÚrangeÚmin)ÚdataÚnumÚkÚmÚis        r   Údivide_into_chunksz+encode_sequence.<locals>.divide_into_chunksi   s\   € Ü”c˜$“i Ó%‰ˆˆ1ÜMRÐSVËZÖXÈ��Q˜‘UœS  A›YÑ&¨¨A©°¡{´S¸¸Q¹À³]Ñ'BÒCÒXÐXùÒXs   ¦2ANFc                 ó*  — d}|t         j                  |   |   z  }|r0|t         j                  k(  r|t         j                  k7  r
|dz  }|dz  }|r|dz  }d}|t         j                  k(  r&t        | d«      \  }}	||dz  |	dk(  rdndz   z  }||z   S |t         j                  k(  r#t        | d	«      \  }}	||d
z  |	rdndz   z  }||z   S |t         j                  k(  r|| dz  z  }||z   S |t         j                  t         j                  fv r|| dz  z  }||z   S )Né   é   é   r   é   é
   r   é   é   é   é   é   )	r   ÚCHAR_COUNT_INDICATOR_LENGTHÚ	MODE_BYTEÚDEFAULT_BYTE_ENCODINGÚMODE_NUMERICrF   ÚMODE_ALPHANUMERICÚ
MODE_KANJIÚ
MODE_HANZI)
Ú
char_countÚ	ver_ranger5   r7   Úis_eciÚis_saÚoverheadÚbitsrK   Ú	remainders
             r   Úcalc_qrcode_bit_lengthz/encode_sequence.<locals>.calc_qrcode_bit_lengthm   sI  € àˆà”F×6Ñ6°tÑ<¸YÑGÑGˆÙ�dœf×.Ñ.Ò.°8¼v×?[Ñ?[Ò3[Ø˜‰MˆHØ˜‰MˆHÙð ˜ÑˆHØˆØ”6×&Ñ&Ò&Ü# J°Ó2‰NˆC�Ø�C˜"‘H Y°!¢^¡¸Ñ;Ñ;ˆDð ˜$‰Ðð ”V×-Ñ-Ò-Ü# J°Ó2‰NˆC�Ø�C˜"‘H¡Y¡°AÑ6Ñ6ˆDð
 ˜$‰Ðð	 ”V×%Ñ%Ò%Ø�J ‘NÑ"ˆDð ˜$‰Ðð ”f×'Ñ'¬×):Ñ):Ð;Ñ;Ø�J ‘OÑ#ˆDØ˜$‰Ðr   c                 ó,  •— t        | «      }t        |«      } ‰	|||‰‰
d¬«      }t        j                  |   |   }t	        t        j                  ||z  «      «      }|d|dz
  z  ‰
rd|dz
  z  ndz   z  }t	        t        j                  ||z  «      «      S )zH        Returns the number of symbols for the provided version.
        T)rd   re   rS   r   é   r   )rG   Úversion_ranger   ÚSYMBOL_CAPACITYÚintÚmathÚceil)r2   r4   r3   r5   Úlengthrc   Ú
bit_lengthÚcapacityÚcntri   r!   r7   s            €€€r   Únumber_of_symbols_by_versionz5encode_sequence.<locals>.number_of_symbols_by_version†   sš   ø€ ô �W“ˆÜ! 'Ó*ˆ	Ù+¨F°I¸tÀXØ36¸dôDˆ
ä×)Ñ)¨'Ñ2°5Ñ9ˆä”$—)‘)˜J¨Ñ1Ó2Ó3ˆà�e˜s Q™wÑ'¹S¨2°°q±ª>ÀaÑHÑHˆ
Ü”4—9‘9˜Z¨(Ñ2Ó3Ó4Ð4r   r   zAThis function does not accept Micro QR Code versions. Provided: "r   z;Please provide either a QR Code version or the symbol counté   z)The symbol count must be in range 1 .. 16Tr   )r;   r    )r3   r4   r6   r!   r8   z<This function cannot handle more than one mode (yet). Sorry.r   z2The content is not long enough to be divided into z symbolsz5The data does not fit into Structured Append version )Úkey)r!   r"   re   )ÚtotalÚparity)r3   r4   r6   r!   r8   Úsa_info)NFF)r#   r%   r&   r'   r   r/   r(   r0   r,   r-   r   r1   rG   Úmodesr^   ÚstrÚcalc_structured_append_parityÚmaxr   Ú_StructuredAppendInfoÚ	enumerate)r2   r3   r4   r5   r6   r7   r!   r8   Úsymbol_countrC   rO   ru   r9   r:   Úsa_parity_dataÚnum_symbolsÚchunksrz   rN   rA   ri   s        ``             @r   r   r   Z   s£  ú€ ôòYð FJØ38óö25ô   Ó(€GØÐØ�QŠ;Üð +Ü+;¸GÓ+DÐ*EÀQðHó Ið Ià	Ð	ÜÐVÓWÐWØÐ¨¨\Ô(?¸RÒ(?ÜÐDÓEÐEð )@ÜÐDÓEÐEÜ  °DÔ9€EØ€}Ü×$Ñ$ˆÜ˜$Ó€DÜ˜$¨Ô/€DÜ˜G T¨8Ó4€HØ€OØÐð	ä*¨8°UÀÈ5ÔQˆOñ
 ˜°7Ò3M¸oÒNä˜H¨E¸GÒ<VÀØ!%¨3¸KôIð Jð Jä
ˆ8�>‰>Ó˜QÒÜÐWÓXÐXØ�>‰>˜!Ñ€DàŒv×"Ñ"Ò"Ü�g“,ˆØÐ¤C¨£L°<Ò$?ÜÐMÈlÈ^Ð[cÐdÓeÐeÜ2°7Ó;€NØÒ$ "€KØÐÙ2°7¸GÀUÈDÓQˆØ�RÒÜÐ"WÐX_ÐW`Ð aÓbÐbÙ ¨Ó5€FØÐÙ$¤S¨´SÔ%9¸4Ó@ˆÜ˜x¨°C¸uÈDÔQˆÜÔ+´3°v³;À±?Ø+ô-€Gô 9BÀ&Ó8I÷Ká,4¨A¨uô Ñ% e¨TÓ2¸%ÈØ 3°KÙ# A›Jö(ó Kð Køô9 !ò 	ò ð	üó8Ks   Â=H Ç,)H)È	H&È%H&c                 óÔ  — |dk  }|du}t        «       }	|}
|}|sd}
t        |«      }|rt        ||| ||¬«      }|r8|dd D ]  }|	j                  |d«       Œ |	j                  |j                  d«       | D ]  }t        |	||
||«       Œ t        j                  |   |   }t        |	||
t        |	«      «       t        |	|t        |	«      «       t        |	||t        |	«      «       t        |||	«      }	t        |«      }|}t        ||«      }t        |||«       t!        |||«       t#        ||	|«       t%        ||||«      \  }}t'        ||||«       t)        ||«       t+        ||||| «      S )zŒ    Creates a (Micro) QR code.

    NOTE: This function does not check if the input is valid and does not belong
    to the public API.
    r   N©re   rT   rQ   rR   )ÚBufferrl   Úboost_error_levelÚappend_bitsry   Úwrite_segmentr   rm   Úwrite_terminatorrG   Úwrite_padding_bitsÚwrite_pad_codewordsÚmake_final_messageÚcalc_matrix_sizeÚmake_matrixÚadd_finder_patternsÚadd_alignment_patternsÚadd_codewordsÚfind_and_apply_best_maskÚadd_format_infoÚadd_version_infor   )r9   r3   r4   r6   r!   r8   rz   r;   Úsa_modeÚbuffÚverrc   rN   Úsegmentrs   ÚwidthÚheightÚmatrixs                     r   r1   r1   Ê   s�  € ð ˜‰{€HØ˜TÐ!€GÜ‹8€DØ
€CØ€IÙØˆÜ! 'Ó*ˆ	ÙÜ! '¨5°(¸CÀwÔOˆÙà˜˜!�ò 	#ˆAØ×Ñ˜Q Õ"ð	#à×Ñ˜Ÿ™¨Ô+àò :ˆÜ�d˜G S¨)°SÕ9ð:ä×%Ñ% gÑ.¨uÑ5€Hä�T˜8 S¬#¨d«)Ô4ä�t˜W¤c¨$£iÔ0ä˜˜g x´°T³Ô;ä˜g u¨dÓ3€Dä˜WÓ%€EØ€FÜ˜ Ó'€Fä˜  vÔ.ä˜6 5¨&Ô1ä�&˜$ Ô(ô ,¨F°E¸6À4ÓH�L€Dˆ&ä�F˜G U¨DÔ1ä�V˜WÔ%Ü�˜ ¨¨hÓ7Ð7r   c                 óÒ  — |t         j                  dfvrÒt        |«      dk(  rÄt         j                  t         j                  t         j
                  t         j                  g}| dk  r3|j                  «        | t         j                  k  r|j                  «        |j                  | ||¬«      }||j                  |«      dz   d D ]   }t         j                  |    |   |k\  r|}Œ |S  |S )aç      Increases the error correction level if possible.

    Returns either the provided or a better error correction level which works
    while keeping the (Micro) QR Code version.

    :param int version: Version constant.
    :param int|None error: Error level constant or ``None``
    :param Segments segments: Instance of :py:class:`Segments`
    :param bool eci: Indicates if ECI designator should be written.
    :param bool is_sa: Indicates if Structured Append mode is used.
    Nr   r†   )r   r+   rG   r/   ÚERROR_LEVEL_MÚERROR_LEVEL_QÚpopÚ
VERSION_M4Úbit_length_with_overheadÚindexrm   )r4   r3   r9   r!   re   ÚlevelsÚdata_lengthÚerror_levels           r   rˆ   rˆ      sÚ   € ð ”V×)Ñ)¨4Ð0Ñ0´S¸³]ÀaÒ5GÜ×&Ñ&¬×(<Ñ(<Ü×&Ñ&¬×(<Ñ(<ð>ˆà�QŠ;Ø�J‰JŒLØœ×*Ñ*Ò*Ø—
‘
”Ø×7Ñ7¸ÀÈEÐ7ÓRˆØ! &§,¡,¨uÓ"5¸Ñ"9Ð":Ð;ò 	ˆKÜ×%Ñ% gÑ.¨{Ñ;¸{ÒJØ#‘àØ€Lð	ð
 €Lr   c                 ó6  — |j                   }| j                  }|rc|t        j                  k(  rP|j                  t        j
                  k7  r3 |t        j                  d«        |t        |j                  «      d«       |€( ||d«       |t        j                  k(  r<d} ||d«       n0|t        j                  kD  r |t        j                  |   |dz   «        ||j                  t        j                  |   |   «       | j                  |j                  «       y)a…      Writes a segment.

    :param buff: The byte buffer.
    :param _Segment segment: The segment to serialize.
    :param ver: ``None`` if a QR Code is written, "M1", "M2", "M3", or "M4" if a
            Micro QR Code is written.
    :param ver_range: "M1", "M2", "M3", or "M4" if a Micro QR Code is written,
            otherwise a constant representing a range of QR Code versions.
    rQ   rR   Nr   rT   )r5   r‰   r   r\   r7   r]   ÚMODE_ECIÚget_eci_assignment_numberra   r.   ÚMODE_TO_MICRO_MODE_MAPPINGrb   r[   Úextendrg   )r˜   rš   r™   rc   r!   r5   r‰   Úsubsets           r   rŠ   rŠ     sç   € ð �<‰<€DØ×"Ñ"€Ká
ˆt”v×'Ñ'Ò'Ø× Ñ ¤F×$@Ñ$@Ò@Ù”F—O‘O QÔ'ÙÔ-¨g×.>Ñ.>Ó?ÀÔCØ
€{Ù�D˜!ÔØ”6×$Ñ$Ò$ØˆFÙ˜ Õ"Ø	Œv× Ñ Ò	 Ù”F×5Ñ5°dÑ;¸SÀ1¹WÔEá�×"Ñ"Ü×2Ñ2°4Ñ8¸ÑCôEà‡K�K�—‘Õr   c                 ój   — | j                  dgt        ||z
  t        j                  |   «      z  «       y)a      Writes the terminator.

    :param buff: The byte buffer.
    :param capacity: Symbol capacity.
    :param ver: ``None`` if a QR Code is written, "M1", "M2", "M3", or "M4" if a
            Micro QR Code is written.
    :param length: Length of the data bit stream.
    r   N)r¬   rI   r   ÚTERMINATOR_LENGTH)r˜   rs   r™   rq   s       r   r‹   r‹   <  s.   € ð 	‡K�K��”c˜( VÑ+¬V×-EÑ-EÀcÑ-JÓKÑKÕLr   c                 ó€   — |t         j                  t         j                  fvr| j                  dgd|dz  z
  z  «       yy)z¢    Writes padding bits if the data stream does not meet the codeword boundary.

    :param buff: The byte buffer.
    :param int length: Data stream length.
    r   rR   N)r   r.   Ú
VERSION_M3r¬   )r˜   r4   rq   s      r   rŒ   rŒ   J  s>   € ð ”v×(Ñ(¬&×*;Ñ*;Ð<Ñ<Ø�‰�Q�C˜1 ¨¡
Ñ+Ñ,Õ-ð =r   c                 óÒ   — | j                   }|t        j                  t        j                  fv r |dg||z
  z  «       yd}t	        |dz  |dz  z
  «      D ]  } |||dz     «       Œ y)a=      Writes the pad codewords iff the data does not fill the capacity of the
    symbol.

    :param buff: The byte buffer.
    :param int version: The (Micro) QR Code version.
    :param int capacity: The total capacity of the symbol (incl. error correction)
    :param int length: Length of the data bit stream.
    r   ))r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   rR   rW   N)r¬   r   r.   r±   rH   )r˜   r4   rs   rq   ÚwriteÚpad_codewordsrN   s          r   r�   r�   ]  sq   € ð$ �K‰K€EØ”6×$Ñ$¤f×&7Ñ&7Ð8Ñ8Ùˆqˆc�X Ñ&Ñ'Õ(àLˆÜ�x 1‘} v°¡{Ñ2Ó3ò 	(ˆAÙ�-  A¡Ñ&Õ'ñ	(r   )	©	r   r   r   r   r   r   r   r   r   ©	r   r   r   r   r   r   r   r   r   ©	r   r   r   r   r   r   r   r   r   ©	r   r   r   r   r   r   r   r   r   r¸   r¸   r·   r¶   rµ   c                 óÞ   — ||k(  }ddt        | «      dz
  fdf}|r|dk  rd}t        d«      }|D ]<  \  }}|dk(  rdnd}|dk7  rdnd}	|D ]   }
t        ||
z      |	|	dz    | ||
z      ||dz    Œ" Œ> y)	a…      Adds the finder pattern(s) with the separators to the matrix.

    QR Codes get three finder patterns, Micro QR Codes have just one finder
    pattern.

    ISO/IEC 18004:2015(E) -- 6.3.3 Finder pattern (page 16)
    ISO/IEC 18004:2015(E) -- 6.3.4 Separator (page 17)

    :param matrix: The matrix.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    ©r   r   r   rR   )éøÿÿÿr   é   )rº   r   N)rG   rH   Ú_FINDER_PATTERN)r�   r›   rœ   Ú	is_squareÚcornersÚfinder_rangerN   ÚjÚoffsetÚ	sepoffsetÚrs              r   r‘   r‘   „  sª   € ð ˜‘€IØ˜œ3˜v›;¨™?Ð+¨WÐ5€GÙ�U˜R’ZØˆÜ˜“8€LØò Z‰ˆˆ1Ø˜1’f‘ !ˆØ˜aš‘A Qˆ	Øò 	ZˆAÜ%4°V¸a±ZÑ%@ÀÈ9ÐWXÉ=Ð%YˆF�1�q‘5‰M˜!˜A ™EÑ"ñ	ZñZr   c                 óœ   — |rdt        | «      fndt        | «      dz
  f\  }}| |   }d}t        d|«      D ]  }|| |   |<   |||<   |dz  }Œ y)a4      Adds the (horizontal and vertical) timinig pattern to the provided `matrix`.

    ISO/IEC 18004:2015(E) -- 6.3.5 Timing pattern (page 17)

    :param matrix: Matrix to add the timing pattern into.
    :param bool is_micro: Indicates if the timing pattern for a Micro QR Code
        should be added.
    r   rY   rR   r   N)rG   rH   )r�   r;   rÁ   ÚstopÚcolÚbitrN   s          r   Úadd_timing_patternrÉ   �  si   € ñ #+ˆq”#�f“+Ñ°´C¸³KÀ!±OÐ0D�G€A€tØ
�‰)€CØ
€CÜ�1�d‹^ò ˆØˆˆq‰	�!‰ØˆˆA‰Øˆs‰
‰ñr   c                 ó,  — ||k(  }|dz
  dz  }|r|dk  ryd}t         j                  |dz
     }t        d«      }|d   }|d   }	||f||	f|	|ff}
t        |d¬	«      D ]7  \  }}||f|
v rŒ|dz
  |dz
  }}|D ]  }||dz  |dz  dz    | ||z      ||dz    Œ Œ9 y)
ai      Adds the adjustment patterns to the matrix. For versions < 2 this is a
    no-op.

    ISO/IEC 18004:2015(E) -- 6.3.6 Alignment patterns (page 17)
    ISO/IEC 18004:2015(E) -- Annex E Position of alignment patterns (page 83)

    :param matrix: An iterable of bytearrays.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    é   rQ   rW   N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   é   r   éÿÿÿÿ)Úrepeat)r   ÚALIGNMENT_POSrH   r   )r�   r›   rœ   r¾   r4   ÚpatternÚ	positionsÚalignment_rangeÚmin_posÚmax_posÚfinder_positionsÚxÚyrN   rÁ   rÄ   s                   r   r’   r’   °  sð   € ð ˜‘€IØ�r‰z˜aÑ€GÙ�W˜q’[Øð(€Gô
 ×$Ñ$ W¨q¡[Ñ1€IÜ˜A“h€OØ˜‰l€GØ˜‰m€GØ  'Ð*¨W°gÐ,>ÀÈ'Ð@RÐSÐÜ˜	¨!Ô,ò >‰ˆˆ1Øˆqˆ6Ð%Ñ%Øà�1‰u�a˜!‘eˆ1ˆØ ò 	>ˆAØ%,¨Q°©U°1°q±5¸1±9Ð%=ˆF�1�q‘5‰M˜!˜A ™EÑ"ñ	>ñ>r   c                 óð  — t        | «      }|dk  }|t        j                  t        j                  fvrdnd}d}t        |«      }t	        d«      }t	        |dz
  dd«      D ]l  }	|s
|	dk  r|	dz  }	t	        |«      D ]P  }
|D ]I  }|	|z
  }|	|z   dz  dk(  }|s||dk  z  }|r|dz
  |
z
  n|
}| |   }||   dk(  sŒ7||k  sŒ=||   ||<   |dz  }ŒK ŒR Œn |t        |«      k7  rt        d|› dt        |«      › d�«      ‚y	)
a7      Adds the codewords (data and error correction) to the provided matrix.

    ISO/IEC 18004:2015(E) -- 7.7.3 Symbol character placement (page 46)

    :param matrix: The matrix to add the codewords into.
    :param codewords: Sequence of bits
    :param int version: The (Micro) QR Code version constant.
    r   r   rW   éþÿÿÿrY   z9Internal error: Adding codewords to matrix failed. Added z of z
 codewordsN)rG   r   r.   r±   rH   r%   )r�   Ú	codewordsr4   Úmatrix_sizer;   ÚincÚidxÚcodeword_lengthÚ	range_twoÚrightÚverticalÚzrÁ   ÚupwardsrN   Úrows                   r   r“   r“   Ò  sP  € ô �f“+€KØ˜‰{€Hð œv×0Ñ0´&×2CÑ2CÐDÑD‰!È!€CØ
€Cô ˜)“n€OÜ�a“€IÜ�{ Q‘¨¨2Ó.ò ˆÙ˜E QšJØ�Q‰JˆEÜ˜kÓ*ò 
	ˆHØò 	�Ø˜A‘I�Ø! C™K¨1Ñ,°Ñ2�ÙØ˜q 1™uÑ$�GÙ4;�[ 1‘_ xÒ/À�Ø˜Q‘i�Ø�q‘6˜S“= S¨?Ó%:Ø& s™^�C˜‘FØ˜1‘H‘Cñ	ñ
	ðð Œc�)‹nÒÜð "Ø"%  d¬3¨y«>Ð*:¸*ðFó Gð 	Gð r   c                 ón  — dd„}t         j                  |    |   }t        ||«      \  }}d}| t         j                  t         j                  fv r ||d   j                  d«      dz	  d«      }t        «       }|j                  t        t        |d„ t        j                  t        |Ž «      D «       «      Ž «       |�|j                  |«       |j                  t        t        |d„ t        j                  t        |Ž «      D «       «      Ž «       d}	| dv rd	}	n| d
v rd}	n| dv rd}	|j                  d|	z  «       |S )ad      Constructs the final message (codewords incl. error correction).

    ISO/IEC 18004:2015(E) -- 7.6 Constructing the final message codeword sequence (page 45)

    :param int version: (Micro) QR Code version constant.
    :param int error: Error level constant.
    :param buff: Byte buffer.
    :return: Byte buffer representing the final message.
    c                 ó>   ‡ — ˆ fd„t        t        |«      «      D «       S )Nc              3   ó.   •K  — | ]  }‰|z	  d z  –— Œ y­w©r   Nr   ©Ú.0rN   Úvals     €r   ú	<genexpr>z8make_final_message.<locals>.to_binary.<locals>.<genexpr>	  s   øè ø€ Ò@ 1�˜‘˜Q•Ñ@ùó   ƒ)ÚreversedrH   )rë   rq   s   ` r   Ú	to_binaryz%make_final_message.<locals>.to_binary  s   ø€ Û@¬´°v³Ó(?Ô@Ð@r   Nr   rÍ   rQ   c              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­w©Nr   ©rê   rÖ   s     r   rì   z%make_final_message.<locals>.<genexpr>  s   è ø€ Ò%q¨AÐcdÑcp¤aÑ%qùó   ‚Šc              3   ó&   K  — | ]	  }|€Œ|–— Œ y ­wrñ   r   rò   s     r   rì   z%make_final_message.<locals>.<genexpr>  s   è ø€ Ò%r¨AÐdeÑdq¤aÑ%rùró   )rW   rT   rQ   rÌ   rY   rV   )é   é   rv   rË   é   é   rS   é   é   é   é   é    é!   é"   rT   )r¼   é   é   é   é   é   é   ó    )rR   )r   ÚECCÚmake_blocksr.   r±   r¡   r‡   r¬   r
   ÚmapÚfrom_iterabler   )
r4   r3   r˜   rï   Úec_infosÚdata_blocksÚerror_blocksÚcw_fourÚresrh   s
             r   rŽ   rŽ   ý  s+  € óAô �z‰z˜'Ñ" 5Ñ)€HÜ +¨H°dÓ ;Ñ€K�Ø€GØ”6×$Ñ$¤f×&7Ñ&7Ð8Ñ8ñ
 ˜K¨™N×.Ñ.¨rÓ2°aÑ7¸Ó;ˆÜ
‹(€Cà‡J�JŒu”c˜)Ñ%q´×1DÑ1DÄ[ÐR]ÐE^Ó1_Ô%qÓrÐsÔtØÐØ�
‰
�7Ôà‡J�JŒu”c˜)Ñ%r´×1DÑ1DÄ[ÐR^ÐE_Ó1`Ô%rÓsÐtÔuð €IØ�/Ñ!Ø‰	Ø	ÐLÑ	LØ‰	Ø	Ð0Ñ	0Øˆ	Ø‡J�Jˆu�yÑ Ô!Ø€Jr   c                 ó’  — |j                  «       }g g }}|j                  }|j                  }t        j                  }t        j                  }| D ]ó  }	|	j
                  |	j                  z
  }
t        j                  |
   }t        |
«      }t        |	j                  «      D ]¢  }t        t        ||	j                  «      «      } ||«       t        |«      }t        |«      }|j                  dg|
z  «       t        |«      D ]5  }||   }|dk7  sŒ||   }|D ]  }|||z   dz   xx   ||||   z      z  cc<   Œ  Œ7  |||d «       Œ¤ Œõ ||fS )z{    Returns the data and error blocks.

    :param ec_infos: Iterable of ECC information
    :param buff: Byte buffer.
    r   r   N)ÚtointsÚappendr   Ú
GALIOS_LOGÚ
GALIOS_EXPÚ	num_totalÚnum_dataÚGEN_POLYrH   Ú
num_blocksÚ	bytearrayr	   rG   r¬   )r  r˜   rÚ   r  r  Úappend_data_blockÚappend_error_blockÚgen_logÚgen_expÚec_infoÚnum_error_wordsÚgenÚrange_error_wordsrN   ÚblockÚlen_dataÚerror_blockrL   ÚcoefÚlcoefÚns                        r   r  r  ,  sg  € ð —‘“€IØ " B�€KØ#×*Ñ*ÐØ%×,Ñ,ÐÜ×Ñ€GÜ×Ñ€GØò 7ˆØ!×+Ñ+¨g×.>Ñ.>Ñ>ˆÜ�o‰o˜oÑ.ˆÜ! /Ó2ÐÜ�w×)Ñ)Ó*ò 	7ˆAÜœf Y°×0@Ñ0@ÓAÓBˆEÙ˜eÔ$Ü˜5“zˆHÜ# EÓ*ˆKØ×Ñ ˜s _Ñ4Ô5ä˜8“_ò J�Ø" 1‘~�Ø˜1“9Ø# D™M�EØ.ò J˜Ø# A¨¡E¨A¡IÓ.°'¸%À#ÀaÁ&¹.Ñ2IÑIÔ.ñJð	Jñ ˜{¨8¨9Ð5Õ6ñ	7ð	7ð$ ˜Ð$Ð$r   c                 óÔ  ‡— t         }t        }t        }||k(  xr |dk  }|rt        }d}t        }t        ||«      Št        ‰||«       t        ‰||«       |sd‰d   d<   ˆfd„}t        |«      }	|�t        | |	|   |||«       || fS d}
t        |	«      D ]I  \  }}| D �cg c]  }|dd ‘Œ	 }}t        |||||«        ||||«      } |||«      sŒ;|}|}t        |«      }
ŒK |
fS c c}w )aÁ      Applies all mask patterns against the provided QR Code matrix and returns
    the best matrix and best pattern.

    ISO/IEC 18004:2015(E) -- 7.8.2 Data mask patterns (page 50)
    ISO/IEC 18004:2015(E) -- 7.8.3 Evaluation of data masking results (page 53)
    ISO/IEC 18004:2015(E) -- 7.8.3.1 Evaluation of QR Code symbols (page 53/54)
    ISO/IEC 18004:2015(E) -- 7.8.3.2 Evaluation of Micro QR Code symbols (page 54/55)

    :param matrix: A matrix.
    :param tuple(int, int) matrix_size: Tuple of width and height of the matrix.
    :param proposed_mask: Optional int to indicate the preferred mask.
    :rtype: tuple
    :return: A tuple of the best matrix and best data mask pattern index.
    r¼   rÍ   r   r»   rR   c                 ó   •— ‰|    |   dkD  S rE   r   )rN   rÁ   Úfunction_matrixs     €r   Úis_encoding_regionz4find_and_apply_best_mask.<locals>.is_encoding_regiont  s   ø€ Ø˜qÑ! !Ñ$ sÑ*Ð*r   N)r   Ú_MAX_PENALTY_SCOREÚevaluate_maskr   Úevaluate_micro_maskr�   r‘   r’   Úget_data_mask_functionsÚ
apply_maskr€   Útuple)r�   r›   rœ   Úproposed_maskÚ	is_betterÚ
best_scoreÚ	eval_maskr;   r+  Úmask_patternsÚbest_matrixÚmask_numberÚmask_patternÚbarM   ÚscoreÚbest_patternr*  s                    @r   r”   r”   N  s1  ø€ ô& €IÜ#€JÜ€IØ˜‰Ò- 5¨2¡:€HÙô ˆ	Øˆ
Ü'ˆ	ô " %¨Ó0€OÜ˜¨°Ô7Ü˜?¨E°6Ô:ÙØ!$ˆ˜Ñ˜AÑô+ô ,¨HÓ5€MàÐ Ü�6˜=¨Ñ7¸ÀØ%ô	'à˜fÐ$Ð$à€KÜ%.¨}Ó%=ò 	#Ñ!ˆ�\Ø#Ö$�rˆR‘ŠUÐ$ˆÐ$Ü�1�l E¨6Ð3EÔFñ ˜!˜U FÓ+ˆÙ�U˜JÕ'ØˆJØ&ˆLÜ ›(‰Kð	#ð ˜Ð$Ð$ùò %s   ÂC%c           	      óŽ   — t        |«      }t        |«      D ],  }| |   }|D ]   } |||«      sŒ||xx    |||«      z  cc<   Œ" Œ. y)a¢      Applies the provided mask pattern on the `matrix`.

    ISO/IEC 18004:2015(E) -- 7.8.2 Data mask patterns (page 50)

    :param tuple matrix: A tuple of bytearrays
    :param mask_pattern: A mask pattern (a function)
    :param int matrix_size: width or height of the matrix
    :param is_encoding_region: A function which returns ``True`` iff the
            row index / col index belongs to the data region.
    N)rH   )	r�   r9  r›   rœ   r+  Úwidth_rangerN   rä   rÁ   s	            r   r0  r0  Œ  sW   € ô ˜“,€KÜ�6‹]ò -ˆØ�Q‰iˆØò 	-ˆAÙ! ! QÕ'Ø�A“™, q¨!Ó,Ñ,”ñ	-ñ-r   c                 ó.   — t        t        | ||«      «      S )a!      Evaluates the provided `matrix` of a QR code.

    ISO/IEC 18004:2015(E) -- 7.8.3 Evaluation of data masking results (page 53)

    :param matrix: The matrix to evaluate
    :param matrix_size: The width (or height) of the matrix.
    :return int: The penalty score of the matrix.
    )ÚsumÚmask_scores)r�   r›   rœ   s      r   r-  r-     s   € ô Œ{˜6 5¨&Ó1Ó2Ð2r   c                 ón  ‡‡— t        d«      Šˆˆfd„}d}d}d}||k(  sJ ‚|Št        ‰«      }d}d}	t        ‰«      }
|D ]¾  }| |   }d}d}d}d}|D ]w  }||   }| |   |   }||
|<   ||z  }||k(  r|dz  }n|dk\  r||dz
  z  }d}||k(  r|dz  }n|dk\  r||dz
  z  }d}|	r$|r"||cxk(  r|	|   cxk(  r|	|dz
     k(  rn n|d	z  }|}|}Œy |}	| ||«      z  }| ||
«      z  }|dk\  r||dz
  z  }|dk\  sŒ·||dz
  z  }ŒÀ t        |«      ‰dz  z  }d
t        t	        |dz  dz
  «      dz  «      z  }||||fS )u°      Returns the penalty score features of the matrix.

    The returned value is a tuple of all penalty scores (N1, N2, N3, N4).
    Use :py:func:`evaluate_mask` for a single value (sum of all scores).


    ISO/IEC 18004:2015(E) -- 7.8.3 Evaluation of data masking results - Table 11 (page 54)

    ============================================   ====================================   ===============
    Feature                                        Evaluation condition                   Points
    ============================================   ====================================   ===============
    Adjacent modules in row/column in same color   No. of modules = (5 + i)               N1 + i
    Block of modules in same color                 Block size = m Ã— n                     N2 Ã—(m-1)Ã—(n-1)
    1 : 1 : 3 : 1 : 1 ratio                        Existence of the pattern               N3
    (dark:light:dark:light:dark) pattern in
    row/column, preceded or followed by light
    area 4 modules wide
    Proportion of dark modules in entire symbol    50 Ã— (5 Ã— k)% to 50 Ã— (5 Ã— (k + 1))%   N4 Ã— k
    ============================================   ====================================   ===============

    N1 = 3
    N2 = 3
    N3 = 40
    N4 = 10

    :param matrix: The matrix to evaluate
    :param matrix_size: The width (or height) of the matrix.
    :return tuple: A tuple of penalty scores (ints): ``(n1, n2, n3, n4)``.
    )r   r   r   r   r   r   r   c                 ó.  •— d}| j                  ‰«      }|dk7  r{|dz   }|d‰dz
  fv sJt        | t        |dz
  d«      t        |‰«       «      r%t        | t        |d«      t        |dz   ‰«       «      s|dz  }n|dz   }| j                  ‰|«      }|dk7  rŒ{|S )Nr   rÍ   rV   rQ   é(   )ÚfindÚanyr~   rI   )ÚseqÚcountrÝ   rÂ   Ú
n3_patternÚqr_sizes       €€r   Ún3_pattern_occurrencesz+mask_scores.<locals>.n3_pattern_occurrencesÎ  s«   ø€ ØˆØ�h‰h�zÓ"ˆØ�RŠiØ˜1‘WˆFØ�q˜' A™+Ð&Ñ&Ü˜s¤3 s¨Q¡w°£?´3°s¸GÓ3DÐEÔFÜ˜s¤3 v¨q£>´#°f¸q±jÀ'Ó2JÐKÔLØ˜‘‘ð ˜q™�Ø—(‘(˜: vÓ.ˆCð �R‹ið ˆr   r   NrÍ   r   rÌ   rW   rT   rU   éd   é2   )r  rH   Úfloatrn   Úabs)r�   r›   rœ   rK  Úscore_n1Úscore_n2Úscore_n3Úqr_module_rangeÚdark_module_counterÚlast_rowÚ	n3_columnrN   rä   Úrow_prev_bitÚcol_prev_bitÚn1_row_counterÚn1_col_counterrÁ   Úrow_current_bitÚcol_current_bitÚpercentÚscore_n4rI  rJ  s                         @@r   rA  rA  ­  sî  ù€ ô> Ð>Ó?€Jõð& €HØ€HØ€HØ�FŠ?Ðˆ?Ø€GÜ˜G“n€OØÐØ€Hä˜'Ó"€IØò '+ˆØ�Q‰iˆØˆØˆàˆØˆØ ò 	+ˆAØ! !™fˆOØ$ Q™i¨™lˆOØ*ˆI�a‰LØ ?Ñ2Ðà ,Ò.Ø !Ñ#‘à! QÒ&Ø °Ñ 2Ñ2�HØ!"�à ,Ò.Ø !Ñ#‘à! QÒ&Ø °Ñ 2Ñ2�HØ!"�á™A /°\Ô"cÀXÈaÁ[Ô"cÐT\Ð]^ÐabÑ]bÑTcÕ"cØ˜A‘�Ø*ˆLØ*‰Lð/	+ð0 ˆàÑ*¨3Ó/Ñ/ˆØÑ*¨9Ó5Ñ5ˆà˜QÒØ˜¨Ñ*Ñ*ˆHØ˜QÓØ˜¨Ñ*Ñ*‰HðO'+ôR Ð'Ó(¨G°q©LÑ9€GØ”Cœ˜G c™M¨BÑ.Ó/°!Ñ3Ó4Ñ4€HØ�X˜x¨Ð1Ð1r   c                 ó¢   ‡ ‡— t        d|«      }‰ d   Št        ˆ fd„|D «       «      }t        ˆfd„|D «       «      }||k  r|dz  |z   S |dz  |z   S )a*      Evaluates the provided `matrix` of a Micro QR code.

    ISO/IEC 18004:2015(E) -- 7.8.3.2 Evaluation of Micro QR Code symbols (page 54)

    :param matrix: The matrix to evaluate
    :param matrix_size: The width (or height) of the matrix.
    :return int: The penalty score of the matrix.
    r   rÍ   c              3   ó.   •K  — | ]  }‰|   d    –— Œ y­w)rÍ   Nr   )rê   rN   r�   s     €r   rì   z&evaluate_micro_mask.<locals>.<genexpr>%  s   øè ø€ Ò3 ˆv�a‰y˜�}Ñ3ùrí   c              3   ó(   •K  — | ]	  }‰|   –— Œ y ­wrñ   r   )rê   rN   rU  s     €r   rì   z&evaluate_micro_mask.<locals>.<genexpr>&  s   øè ø€ Ò1˜qˆx˜�{Ñ1ùs   ƒrv   )rH   r@  )r�   r›   rœ   Úmodule_rangeÚsum1Úsum2rU  s   `     @r   r.  r.    s\   ù€ ô ˜˜E“?€LØ�b‰z€HÜÓ3 lÔ3Ó3€DÜÓ1 LÔ1Ó1€DØ# tš|ˆ4�"‰9�tÑÐA°¸±¸TÑ1AÐAr   c                 ó0  — |}| dkD  r_|t         j                  k(  r|dz  }n1|t         j                  k(  r|dz  }n|t         j                  k(  r|dz  }t         j                  |   }|S |t         j
                  |    |   dz  z  }t         j                  |   }|S )uz      Returns the format information for the provided error level and mask patttern.

    ISO/IEC 18004:2015(E) -- 7.9 Format information (page 55)
    ISO/IEC 18004:2015(E) -- Table C.1 â€” Valid format information bit sequences (page 80)

    :param int version: Version constant
    :param int error: Error level constant.
    :param int mask_pattern: Mask pattern number.
    r   rR   rv   r  rW   )r   r/   r+   r    ÚFORMAT_INFOÚERROR_LEVEL_TO_MICRO_MAPPINGÚFORMAT_INFO_MICRO)r4   r3   r9  ÚfmtÚformat_infos        r   Úcalc_format_infork  *  s¤   € ð €CØ�‚{Ø”F×(Ñ(Ò(Ø�4‰K‰CØ”f×*Ñ*Ò*Ø�4‰K‰CØ”f×*Ñ*Ò*Ø�4‰KˆCÜ×(Ñ(¨Ñ-ˆð Ðð 	Œv×2Ñ2°7Ñ;¸EÑBÀaÑGÑGˆÜ×.Ñ.¨sÑ3ˆØÐr   c                 ó  — |dk  }t        |||«      }t        |«      }|}| d   }t        d«      D ]L  }	||	z	  dz  }
|d|	z
  z	  dz  }|	dk(  r	|s|dz  }d}|
| |	|z      d<   |||	|z   <   |rŒ:|
|d|	z
  <   || d|	z
     d<   ŒN |s	d| d   d<   yy)a�      Adds the format information into the provided matrix.

    ISO/IEC 18004:2015(E) -- 7.9 Format information (page 55)
    ISO/IEC 18004:2015(E) -- 7.9.1 QR Code symbols
    ISO/IEC 18004:2015(E) -- 7.9.2 Micro QR Code symbols

    :param matrix: The matrix.
    :param int version: Version constant
    :param int error: Error level constant.
    :param int mask_pattern: Mask pattern number.
    r   rR   rõ   rY   rÍ   r»   N)rk  rn   rH   )r�   r4   r3   r9  r;   rj  ÚvoffsetÚhoffsetÚ	row_eightrN   ÚvbitÚhbits               r   r•   r•   D  sÚ   € ðJ ˜‰{€HÜ" 7¨E°<Ó@€KÜ�(‹m€GØ€GØ�q‘	€IÜ�1‹Xò %ˆØ˜qÑ  DÑ(ˆØ  Q¡Ñ'¨4Ñ/ˆØ�Š6™(Ø�q‰LˆGØˆGà!%ˆˆq�7‰{Ñ˜AÑà!%ˆ	�!�g‘+ÑÚà $ˆI�b˜1‘fÑà $ˆF�2˜‘6‰N˜1Òð%ñ àˆˆr‰
�1Šð r   c                 ó  — |dk  ryt         j                  |dz
     }t        d«      D ]U  }||dz  z	  dz  }||dz  dz   z	  dz  }||dz  dz   z	  dz  }|| d   |<   || d   |<   || d	   |<   | |   }||d<   ||d<   ||d	<   ŒW y)
z—    Adds the version information to the matrix, for versions < 7 this is a no-op.

    ISO/IEC 18004:2015(E) -- 7.10 Version information (page 58)
    rV   NrY   rT   r   rW   éõÿÿÿéöÿÿÿé÷ÿÿÿ)r   ÚVERSION_INFOrH   )r�   r4   Úversion_inforN   Úbit1Úbit2Úbit3rä   s           r   r–   r–   ‚  sÁ   € ð* �‚{ØÜ×&Ñ& w°¡{Ñ3€LÜ�1‹Xò ˆØ  Q¡Ñ'¨4Ñ/ˆØ ! a¡%¨1¡Ñ-°Ñ5ˆØ ! a¡%¨1¡Ñ-°Ñ5ˆàˆˆs‰�A‰Øˆˆs‰�A‰Øˆˆr‰
�1‰à�Q‰iˆØˆˆC‰ØˆˆC‰ØˆˆBŠñr   c                 óX  — t        «       }|j                  }t        | t        t        t
        f«      r |t        | ||«      «       |S | D ]^  }|||}}}t        |t        «      r3|d   }t        |«      dkD  r	|d   xs |}t        |«      dkD  r	|d   xs |} |t        |||«      «       Œ` |S )a©      Returns an iterable of `Segment` instances.

    If `content` is a string, an integer, or bytes, the returned tuple will
    have a single item. If `content` is a list or a tuple, a tuple of
    `Segment` instances of the same length is returned.

    :param content: Either a string, bytes, an integer or an iterable.
    :type content: str, bytes, int, tuple, list or any iterable
    :param mode: The global mode. If `content` is list/tuple, the `Segment`
            instances may have a different mode.
    :param encoding: The global encoding. If `content` is a list or a tuple,
            the `Segment` instances may have a different encoding.
    :rtype: Segments
    r   r   rW   )	r>   r?   Ú
isinstancer|   Úbytesrn   r@   r1  rG   )	r2   r5   r7   r9   r?   ÚitemÚseg_contentÚseg_modeÚseg_encodings	            r   r,   r,   ©  s·   € ô  ‹z€HØ×&Ñ&€KÜ�'œC¤¬Ð,Ô-Ù”L ¨$°Ó9Ô:ØˆØò GˆØ.2°D¸(˜|�XˆÜ�dœEÔ"Ø˜q™'ˆKÜ�4‹y˜1Š}Ø ™7š? d�Ü�4‹y˜1Š}Ø# A™wÒ2¨(�Ù”L ¨h¸ÓEÕFðGð €Or   c                 ó¨  — t        | t        «      r | t        | «      |xs t        j                  fS t        | «      } |�| j                  |«      } n"	 t        j                  }| j                  |«      } | t        | «      |fS # t        $ rH 	 t        j                  }| j                  |«      } n"# t        $ r d}| j                  |«      } Y nw xY wY Œ^w xY w)aò      Converts the provided data into bytes. If the data is already a byte
    sequence, it will be left unchanged.

    This function tries to use the provided `encoding` (if not ``None``)
    or the default encoding (ISO/IEC 8859-1). It uses UTF-8 as fallback.

    Returns the (byte) data, the length of the data and the encoding of the data.

    :param data: The data to encode
    :type data: str or bytes
    :param encoding: str or ``None``
    :rtype: tuple: data, data length, encoding
    úutf-8)	r|  r}  rG   r   r]   r|   r   ÚUnicodeErrorÚKANJI_ENCODING)rJ   r7   s     r   Údata_to_bytesr†  Ê  sÉ   € ô �$œÔØ”S˜“Y Ò H¬F×,HÑ,HÐHÐHÜˆt‹9€DØÐà�{‰{˜8Ó$‰ð	-ä×3Ñ3ˆHØ—;‘;˜xÓ(ˆDð ”�T“˜HÐ$Ð$øô ò 	-ð-ä!×0Ñ0�Ø—{‘{ 8Ó,‘øÜò -à"�Ø—{‘{ 8Ó,’ð-üð	-ús6   Á!B  Â 	CÂ
!B,Â+CÂ,CÃCÃ
CÃCÃCc           
      óÞ  — |t         j                  k(  rt         j                  }t        | |«      \  }}}|}|t         j                  k7  rt        |«      nt         j                  }|�+||k  r(t        dt        |«      › d|›dt        |«      › �«      ‚|}|t         j                  k7  rd}|t         j                  t         j                  fvr|n|dz  }t        «       }	|	j                  }
|t         j                  k(  r=t        d|d«      D ]+  }|||dz    } |
t        |«      t        |«      dz  dz   «       Œ- �nœ|t         j                  k(  rut         j                   j"                  }t        d|d«      D ]I  }|||dz    }t        |«      dkD  r" |
 ||d   «      d	z   ||d   «      z   d
«       Œ; |
 ||«      d«       ŒK �n|t         j                  k(  r|D ]  } |
|d«       Œ nð|t         j                  k(  rot        d|d«      D ]^  }||   dz  ||dz      z  }d|cxk  rdk  r	n n|dz
  }n"d|cxk  rdk  r	n n|dz
  }nt        d|› �«      ‚ |
|dz	  dz  |dz  z   d«       Œ` nnt        d|d«      D ]^  }||   dz  ||dz      z  }d|cxk  rdk  r	n n|dz
  }n"d|cxk  rdk  r	n n|dz
  }nt        d|› �«      ‚ |
|dz	  dz  |dz  z   d«       Œ` t%        |	j'                  «       |||«      S )z�    Creates a :py:class:`Segment`.

    :param data: The segment data
    :param mode: The mode.
    :param encoding: The encoding.
    :rtype: _Segment
    NzThe provided mode "z" is not applicable for z. Proposal: rW   r   rT   r   é-   rX   rY   rR   i¡¡  iþª  i¡°  iþú  i¡¦  zInvalid Hanzi bytes: é`   éÿ   rZ   é@�  éüŸ  é@à  é¿ë  i@Á  zInvalid Kanji bytes: éÀ   )r   ra   ÚHANZI_ENCODINGr†  r\   Ú	find_moder%   r*   r`   r‡   r‰   r^   rH   rn   rG   r_   ÚALPHANUMERIC_CHARSrE  Ú_SegmentÚgetbits)rJ   r5   r7   Úsegment_dataÚsegment_lengthÚsegment_encodingÚsegment_modeÚguessed_moderb   r˜   r‰   rN   rA   Úto_byteÚbÚcodeÚdiffs                    r   r@   r@   ð  sZ  € ð Œv× Ñ Ò Ü×(Ñ(ˆÜ5BÀ4ÈÓ5RÑ2€L�.Ð"2Ø€Lð
 /;¼f×>NÑ>NÒ.N”9˜\Ô*ÔTZ×TdÑTd€LØÐà˜,Ò&ÜÐ2´=ÀÓ3NÐ2Oð P6Ø6BÐ5Eð F*Ü*7¸Ó*EÐ)FðHó Ið Ið $ˆØ”v×'Ñ'Ò'ØÐØ#/¼×8IÑ8IÌ6×K\ÑK\Ð7]Ñ#]‘ÐcqÐuvÑcv€JÜ‹8€DØ×"Ñ"€KØ”v×*Ñ*Ò*ô �q˜.¨!Ó,ò 	8ˆAØ   1 q¡5Ð)ˆEÙœ˜E›
¤C¨£J°¡N°QÑ$6Õ7ò	8ð 
œ×1Ñ1Ò	1ä×+Ñ+×0Ñ0ˆÜ�q˜.¨!Ó,ò 	/ˆAØ   1 q¡5Ð)ˆEô �5‹z˜AŠ~Ù™G E¨!¡HÓ-°Ñ2±W¸UÀ1¹XÓ5FÑFÈÕKñ
 ™G E›N¨AÕ.ò	/ð 
œ×)Ñ)Ò	)àò 	ˆAÙ˜˜1Õñ	à	œ×*Ñ*Ò	*ô �q˜.¨!Ó,ò 	BˆAØ  ‘O qÑ(¨L¸¸Q¹Ñ,?Ñ?ˆDØ˜Ô' Õ'ð ˜f‘}‘Ø˜4Ô) 6Õ)ð ˜f‘}‘ä Ð#8¸¸Ð!?Ó@Ð@ñ ˜$ !™) tÑ+°°t±Ñ<¸bÕAñ	Bô$ �q˜.¨!Ó,ò 	BˆAØ  ‘O qÑ(¨L¸¸Q¹Ñ,?Ñ?ˆDØ˜Ô' Õ'ð ˜f‘}‘Ø˜4Ô) 6Õ)ð ˜f‘}‘ä Ð#8¸¸Ð!?Ó@Ð@ñ ˜$ !™) tÑ+°°t±Ñ<¸bÕAð	Bô  �D—L‘L“N J°Ð>NÓOÐOr   c                 óx  ‡	— | |k(  }|xr | dk  }dg| z  Š	t        ˆ	fd„t        |«      D «       «      }|rw|rA| dkD  r<t        d«      D ].  }||   Š	d‰	d<   d‰	d<   d‰	d	<   d|d   |<   d|d   |<   d|d	   |<   Œ0 |d
   }t        d«      D ]!  }d||   d
<   d||<   |rŒd||    d
<   d|| <   Œ# |rt        ||«       |S )aH      Creates a matrix of the provided `size` (w x h) initialized with the
    (illegal) value 0x2.

    The "timing pattern" is already added to the matrix and the version
    and format areas are initialized with 0x0.

    :param int width: Matrix width
    :param int height: Matrix height.
    :rtype: tuple of bytearrays
    r¼   rW   c              3   ó4   •K  — | ]  }t        ‰«      –— Œ y ­wrñ   )r  )rê   rN   rä   s     €r   rì   zmake_matrix.<locals>.<genexpr>d  s   øè ø€ Ò9 a”9˜S—>Ñ9ùs   ƒé)   rY   r   rs  rt  ru  rR   é	   )r1  rH   rÉ   )
r›   rœ   Úreserve_regionsÚ
add_timingr¾   r;   r�   rN   ro  rä   s
            @r   r�   r�   U  s
  ø€ ð ˜‘€IØÒ'˜U R™Z€HØˆ%�%‰-€CÜÓ9¬5°«=Ô9Ó9€FÙÙ˜ šä˜1“Xò 	$�Ø˜Q‘i�à��C‘Ø��C‘Ø��B‘à!$��s‘˜A‘Ø!$��s‘˜A‘Ø #��r‘
˜1’ð	$ð ˜1‘Iˆ	Ü�q“ò 	$ˆAØˆF�1‰I�a‰LØˆI�a‰LÚØ #�˜�r‘
˜1‘Ø #�	˜1˜"’ð	$ñ ä˜6 8Ô,Ø€Mr   c                 óž  — | €yd}	 t        | «      } | dk  }|sd| cxk  rdk  sZn | t        j                  vrFt        d| › dd	j                  t        t        j                  j                  «       «      «      › d
�«      ‚| S # t        t        f$ r= 	 t        j                  | j                  «          } n# t        t        f$ r d}Y nw xY wY Œ´w xY w)a¢      Canonicalization of the provided `version`.

    If the `version` is ``None``, this function returns ``None``. Otherwise
    this function checks if `version` is an integer or a Micro QR Code version.
    In case the string represents a Micro QR Code version, an uppercased
    string identifier is returned.

    If the `version` does not represent a valid version identifier (aside of
    ``None``) a :py:exc:`ValueError` is raised.

    :param version: An integer, a string or ``None``.
    :raises: :py:exc:`ValueError`: In case the version is not ``None`` and does not
                represent a valid (Micro) QR Code version.
    :rtype: int, str or ``None``
    NFr   Tr   r   zUnsupported version "z". Supported: ú, z and 1 .. 40)rn   r%   Ú	TypeErrorr   ÚMICRO_VERSION_MAPPINGÚupperÚKeyErrorÚAttributeErrorr$   ÚjoinÚsortedÚkeys)r4   r3   s     r   r#   r#   €  sÜ   € ð" €ØØ€EðÜ�g“,ˆà˜!‘ˆñ �Q˜Ô% 2Ô%¨'¼×9NÑ9NÑ*NÜÐ0°°	ð :'Ø'+§y¡y´¼×8TÑ8T×8YÑ8YÓ8[Ó1\Ó']Ð&^Ð^jðló mð 	mà€Nøô œ	Ð"ò ð	Ü×2Ñ2°7·=±=³?ÑC‰GøÜœ.Ð)ò 	ØŠEð	üðús5   ‡B  Â CÂ!B2Â1CÂ2CÃCÃCÃCÃCc                 ó>  — | � | t         j                  j                  «       v r| S 	 t         j                  | j                  «          S # t        t
        f$ rF t        d| › ddj                  t        t         j                  j                  «       «      «      › �«      ‚w xY w)a      Returns a (Micro) QR Code mode constant which is equivalent to the
    provided `mode`.

    In case the provided `mode` is ``None``, this function returns ``None``.
    Otherwise a mode constant is returned unless the provided parameter cannot
    be mapped to a valid mode. In the latter case, a :py:exc:`ValueError` is raised.

    :param mode: An integer or string or ``None``.
    :raises: :py:exc:`ValueError` In case the provided `mode` does not represent a valid
             QR Code mode.
    :rtype: int or None
    zIllegal mode "z". Supported values: r¥  )
r   ÚMODE_MAPPINGÚvaluesÚlowerr©  rª  r%   r«  r¬  r­  )r5   s    r   r(   r(   £  sš   € ð €|�tœv×2Ñ2×9Ñ9Ó;Ñ;Øˆð_Ü×"Ñ" 4§:¡:£<Ñ0Ð0øÜ”nÐ%ò _Ü˜>¨$¨ð 0.Ø.2¯i©i¼¼v×?RÑ?R×?WÑ?WÓ?YÓ8ZÓ.[Ð-\ð^ó _ð 	_ð_ús   ¦ A ÁABc                 óÔ   — | €y	 t        | «      } |rd| cxk  rdk  sn t        d| › d�«      ‚| S d| cxk  rdk  sn t        d| › d�«      ‚| S # t        $ r t        d| › d�«      ‚w xY w)	a      Normalizes the (user specified) mask.

    :param mask: A mask constant
    :type mask: int or None
    :param bool is_micro: Indicates if the mask is meant to be used for a
            Micro QR Code.
    :raises: :py:exc:`ValueError` in case of an invalid mask.
    :rtype: int
    NzInvalid data mask "zD". Must be an integer or a string which represents an integer value.r   rQ   z," for Micro QR Code. Must be in range 0 .. 3rR   z". Must be in range 0 .. 7)rn   r%   )r6   r;   s     r   r0   r0   º  s¥   € ð €|Øð^Ü�4‹yˆñ Ø�DŒ}˜1Œ}ÜÐ2°4°&Ð8dÐeÓfÐfð €Kð �DŒ}˜1Œ}ÜÐ2°4°&Ð8RÐSÓTÐTØ€Køô ò ^ÜÐ.¨t¨fð 5]ð ]ó ^ð 	^ð^ús   …A ÁA'c                 óô   — | €|st        d«      ‚| S 	 t        j                  | j                  «          S # t        t
        f$ r4 | t        j                  j                  «       v r| cY S t        d| › d�«      ‚w xY w)a4      Returns a constant for the provided error level.

    This function returns ``None`` if the provided parameter is ``None`` and
    `accept_none` is set to ``True`` (default: ``False``). If `error` is ``None``
    and `accept_none` is ``False`` or if the provided parameter cannot be
    mapped to a valid QR Code error level, a :py:exc:`ValueError` is raised.

    :param error: String or ``None``.
    :param bool accept_none: Indicates if ``None`` is accepted as error level.
    :raises: :py:exc:`ValueError` in case of an invalid mode.
    :rtype: int
    z The error level must be providedz!Illegal error correction level: "z". Supported levels: L, M, Q, H)r%   r   ÚERROR_MAPPINGr¨  r©  rª  r°  )r3   r   s     r   r'   r'   Õ  s‚   € ð €}ÙÜÐ?Ó@Ð@ØˆðeÜ×#Ñ# E§K¡K£MÑ2Ð2øÜ”nÐ%ò eØ”F×(Ñ(×/Ñ/Ó1Ñ1ØŠLÜÐ<¸U¸GÐCbÐcÓdÐdðeús   “ 4 ´1A7Á'A7c                 ó~   — t         j                  j                  «       D ]  \  }}|| k(  sŒ|c S  t        d| › d�«      ‚)zã    Returns the mode name for the provided mode constant.

    :param int mode_const: The mode constant (see :py:module:`segno.consts`)
    :raises: :py:exc:`ValueError` in case of an unknown mode constant.
    :rtype: str
    úUnknown mode "r   )r   r¯  Úitemsr%   )Ú
mode_constÚnamerë   s      r   r*   r*   ï  sI   € ô ×(Ñ(×.Ñ.Ó0ò ‰	ˆˆcØ�*ÓØŠKðô �~ j \°Ð3Ó
4Ð4r   c                 ó~   — t         j                  j                  «       D ]  \  }}|| k(  sŒ|c S  t        d| › d�«      ‚)zð    Returns the error name for the provided error constant.

    :param int error_const: The error constant (see :py:module:`segno.consts`)
    :raises: :py:exc:`ValueError` in case of an unknown error correction level.
    :rtype: str
    zUnknown error level "r   )r   r´  r·  r%   )Úerror_constr¹  rë   s      r   Úget_error_namer¼  ý  sJ   € ô ×)Ñ)×/Ñ/Ó1ò ‰	ˆˆcØ�+ÓØŠKðô Ð,¨[¨M¸Ð;Ó
<Ð<r   c                 óš   — d| cxk  rdk  r| S  t         j                  j                  «       D ]  \  }}|| k(  sŒ|c S  t        d| › d�«      ‚)a      Returns the version name.

    For version 1 .. 40 it returns the version as integer, for Micro QR Codes
    it returns a string like ``M1`` etc.

    :raises: :py:exc:`VersionError`: In case the `version_constant` is unknown.
    :rtype: str or int
    r   r   zUnknown version constant "r   )r   r§  r·  r%   )Úversion_constr¹  Úvs      r   r&   r&     sb   € ð 	ˆ=Ô˜2ÒØÐð ä×/Ñ/×5Ñ5Ó7ò ‰ˆˆaØ�ÓØŠKðô Ð1°-°ÀÐBÓ
CÐCr   s   ^[s   ]+\Zc                 ó,   — t         j                  | «      S )zŠ    Returns if the provided `data` can be encoded in "alphanumeric" mode.

    :param bytes data: The data to check.
    :rtype: bool
    )Ú_ALPHANUMERIC_PATTERNÚmatch©rJ   s    r   Úis_alphanumericrÄ     s   € ô !×&Ñ& tÓ,Ð,r   c                 óÔ   — t        | «      }|r|dz  ryt        | «      }t        d|d«      D ]:  }t        |«      dz  t        |«      z  }d|cxk  rdk  rŒ)n d|cxk  rdk  rŒ7 y  y y	)
zz    Returns if the `data` can be encoded in "kanji" mode.

    :param bytes data: The data to check.
    :rtype: bool
    rW   Fr   rR   r‹  rŒ  r�  rŽ  T)rG   ÚiterrH   Únext)rJ   Údata_lenÚ	data_iterrN   rœ  s        r   Úis_kanjirÊ  *  s{   € ô �4‹y€HÙ�x !’|ØÜ�T“
€IÜ�1�h Ó"ò ˆÜ�Y“ 1Ñ$¬¨Y«Ñ7ˆØ˜$Ô( &Õ(¨F°dÔ,D¸fÓ,DÙð -EÙðð r   c                 óÎ   — | j                  «       rt        j                  S t        | «      rt        j                  S t        | «      rt        j                  S t        j                  S )z—    Returns the appropriate QR Code mode (an integer constant) for the
    provided `data`.

    :param bytes data: Data to check.
    :rtype: int
    )Úisdigitr   r^   rÄ  r_   rÊ  r`   r\   rÃ  s    r   r‘  r‘  <  sL   € ð ‡|�|„~Ü×"Ñ"Ð"Ü�tÔÜ×'Ñ'Ð'Ü�„~Ü× Ñ Ð Ü×ÑÐr   c                 ó$  — |r|rJ ‚|xs |du }|rt         j                  nd}|rt         j                  nd}|dk  r,t        | j                  D �cg c]  }t        |«      ‘Œ c}«      }|�|rt         j                  }t        ||dz   «      D ]V  }	|€#|	t         j                  k7  rt         j                  }	 t         j                  |	   |   | j                  |	||«      k\  r|	c S ŒX d}
|€d}
n|rd}
t        d|
› d�«      ‚c c}w # t        $ r Y Œƒw xY w)	a)      Returns the minimal (Micro) QR Code version constant for the provided input.

    :param segments: Iterable of Segment instances.
    :param error: The error correction level constant.
    :type error: int or None
    :param bool eci: Indicates if the ECI mode should be used.
    :param micro: Boolean value if a Micro QR Code should be created or ``None``
    :type micro: bool or None
    :param bool is_sa: Indicator if Structured Append is used.
    :raises: :py:exc:`ValueError` if the content does not fit into a QR Code.
    :rtype: int
    Nr   rD  Ú z(Micro) zMicro zData too large. No z$QR Code can handle the provided data)r   r.   r¢   r~   r{   Úfind_minimum_version_for_modeÚ
VERSION_M2rH   r/   rm   r£   r©  r   )r9   r3   r!   r"   re   Úmicro_allowedÚmin_versionÚmax_versionr5   r4   Úhelp_txts              r   r-   r-   M  s.  € ñ ™ÐÐØÒ*˜U d˜]€MÙ'4”&×#Ò#¸!€KÙ',”&×#Ò#°"€KØ�Q‚ÜÈ8Ï>É>ÖZÀ4Ô8¸Õ>ÒZÓ[ˆØÐ™]Ü×'Ñ'ˆÜ˜ k°A¡oÓ6ò ˆØˆ=˜W¬×(9Ñ(9Ò9Ü×(Ñ(ˆEð	Ü×%Ñ% gÑ.¨uÑ5¸×9ZÑ9ZÐ[bÐdgÐinÓ9oÒoØ’ð pð	ð €HØ€}Ø‰Ù	ØˆÜ
Ð1°(°Ð;_Ð`Ó
aÐaùò! [øô ò 	Ùð	ús   ÁC>Â4+DÄ	DÄDc                 ó2   — | dkD  r| dz  dz   S | dz   dz  dz   S )a.      Returns the matrix size according to the provided `version`.

    Note: This function does not check if `version` is actually a valid
    (Micro) QR Code version. Invalid versions like ``41`` may return a
    size as well.

    :param int ver: (Micro) QR Code version constant.
    :rtype: int
    r   rQ   rË   rW   r¡  r   )r™   s    r   r�   r�   s  s*   € ð  š7ˆ3�‰7�R‰<Ð9¨¨q©°A©¸Ñ(9Ð9r   c                 ó  — t        | t        «      st        | «      } 	 | j                  d«      }t        t        |«      S # t        $ r< 	 | j                  d«      }n&# t        t        f$ r | j                  d«      }Y nw xY wY ŒTw xY w)zy    Calculates the parity data for the Structured Append mode.

    :param str content: The content.
    :rtype: int
    z
iso-8859-1z	shift-jisrƒ  )r|  r|   r   r„  ÚLookupErrorr   r   )r2   rJ   s     r   r}   r}   �  s   € ô �gœsÔ#Ü�g“,ˆð+Ø�~‰~˜lÓ+ˆô ”#�tÓÐøô ò +ð	+Ø—>‘> +Ó.‰DøÜœ\Ð*ò 	+Ø—>‘> 'Ó*ŠDð	+üð+ús3   �> ¾	BÁAÁBÁ A=Á:BÁ<A=Á=BÂBc                 óx   — |dkD  rdn|}	 |t         j                  |    v S # t        $ r t        d| › d�«      ‚w xY w)aR      Returns if `mode` is supported by `version`.

    Note: This function does not check if `version` is actually a valid
    (Micro) QR Code version. Invalid versions like ``41`` may return an illegal
    value.

    :param int mode: Canonicalized mode.
    :param int or None ver: (Micro) QR Code version constant.
    :rtype: bool
    r   Nr¶  r   )r   ÚSUPPORTED_MODESr©  r%   )r5   r™   s     r   r)   r)   ”  sO   € ð ˜’'‰$˜s€Cð3Ø”f×,Ñ,¨TÑ2Ð2Ð2øÜò 3Ü˜>¨$¨¨qÐ1Ó2Ð2ð3ús   ‹   9c                 óN   — t         j                  D ]  }t        | |«      sŒ|c S  y)zŽ    Returns the minimum Micro QR Code version which supports the provided mode.

    :param int mode: Canonicalized mode.
    :rtype: int
    r   )r   r$   r)   )r5   r¿  s     r   rÏ  rÏ  §  s-   € ô ×"Ñ"ò ˆÜ˜T 1Õ%ØŠHðð r   c                 óÈ   — d| cxk  rdk  rt         j                  S  d| cxk  rdk  rt         j                  S  d| cxk  rdk  rt         j                  S  t	        d| › d�«      ‚)	z¯    Returns the version range for the provided version. This applies to QR Code
    versions, only.

    :param int version: The QR Code version (1 .. 40)
    :rtype: int
    r   rU   r¡  r  r  r   zUnknown version "r   )r   ÚVERSION_RANGE_01_09ÚVERSION_RANGE_10_26ÚVERSION_RANGE_27_40r%   )r4   s    r   rl   rl   ´  ss   € ð 	ˆ7Ô�RÒÜ×)Ñ)Ð)ð à	
ˆWÔ	�rÒ	Ü×)Ñ)Ð)ð 
à	ˆgÔ	˜Ò	Ü×)Ñ)Ð)ð 
ä
Ð(¨¨	°Ð3Ó
4Ð4r   c                 óœ   — 	 t         j                  t        j                  | «      j                     S # t
        $ r t        d| › d�«      ‚w xY w)z…    Returns the ECI number for the provided encoding.

    :param str encoding: A encoding name
    :return str: The ECI number.
    z,Unknown ECI assignment number for encoding "z".)r   ÚECI_ASSIGNMENT_NUMÚcodecsÚlookupr¹  r©  r%   )r7   s    r   rª   rª   Ç  sO   € ðVÜ×(Ñ(¬¯©°xÓ)@×)EÑ)EÑFÐFøÜò VÜÐGÈÀzÐQSÐTÓUÐUðVús	   ‚/2 ²Ac                 óV   — d„ }d„ }d„ }d„ }d„ }d„ }d„ }d„ }| r||||fS ||||||||fS )	uÁ  
    Returns the data mask functions.

    ISO/IEC 18004:2015(E) -- 7.8.2 Data mask patterns (page 50)
    Table 10 â€” Data mask pattern generation conditions (page 50)

    ===============     =====================   =====================================
    QR Code Pattern     Micro QR Code Patternï¿¼  Condition
    ===============     =====================   =====================================
    000                                         (i + j) mod 2 = 0
    001                 00                      i mod 2 = 0
    010                                         j mod 3 = 0
    011                                         (i + j) mod 3 = 0
    100                 01                      ((i div 2) + (j div 3)) mod 2 = 0
    101                                         (i j) mod 2 + (i j) mod 3 = 0
    110                 10                      ((i j) mod 2 + (i j) mod 3) mod 2 = 0
    111                 11                      ((i+j) mod 2 + (i j) mod 3) mod 2 = 0
    ===============     =====================   =====================================

    :param is_micro: Indicates if data mask functions for a Micro QR Code
            should be returned
    :return: A tuple of functions
    c                 ó   — | |z   dz  dk(  S ©Nr   r   r   ©rN   rÁ   s     r   Úfn0z$get_data_mask_functions.<locals>.fn0í  s   € Ø�A‘˜‰} Ñ!Ð!r   c                 ó   — | dz  dk(  S rå  r   ræ  s     r   Úfn1z$get_data_mask_functions.<locals>.fn1ð  s   € Ø�3‰w˜!‰|Ðr   c                 ó   — |dz  dk(  S ©NrT   r   r   ræ  s     r   Úfn2z$get_data_mask_functions.<locals>.fn2ó  s   € Ø�1‰u˜‰zÐr   c                 ó   — | |z   dz  dk(  S rë  r   ræ  s     r   Úfn3z$get_data_mask_functions.<locals>.fn3ö  s   € Ø�A‘˜‰{˜aÑÐr   c                 ó$   — | dz  |dz  z   dz  dk(  S )NrW   rT   r   r   r   ræ  s     r   Úfn4z$get_data_mask_functions.<locals>.fn4ù  s   € Ø�Q‘˜˜a™‘ 3Ñ&¨!Ñ+Ð+r   c                 ó(   — | |z  }|dz  |dz  z   dk(  S ©Nr   rT   r   r   ©rN   rÁ   Útmps      r   Úfn5z$get_data_mask_functions.<locals>.fn5ü  s#   € Ø�!‰eˆØ�c‘	˜c A™gÑ&¨!Ñ+Ð+r   c                 ó.   — | |z  }|dz  |dz  z   dz  dk(  S rò  r   ró  s      r   Úfn6z$get_data_mask_functions.<locals>.fn6   s(   € Ø�!‰eˆØ�s‘˜s Q™wÑ'¨3Ñ.°!Ñ3Ð3r   c                 ó0   — | |z   dz  | |z  dz  z   dz  dk(  S rò  r   ræ  s     r   Úfn7z$get_data_mask_functions.<locals>.fn7  s'   € Ø�a‘%˜3‘ 1 q¡5¨A¡+Ñ-°Ñ4¸Ñ9Ð9r   r   )	r;   rç  ré  rì  rî  rð  rõ  r÷  rù  s	            r   r/  r/  Ô  sU   € ò2"òòò ò,ò,ò4ò:ñ Ø�C˜˜cÐ!Ð!Ø��S˜#˜s C¨¨cÐ1Ð1r   c                   ó:   — e Zd ZdZdZd„ Zd„ Zd„ Zd„ Zd„ Z	d
d„Z
y	)r>   z¤    Represents a sequence of `Segment` instances.

    Note: len(segments) returns the number of Segments and not the data length;
    use segments.data_length
    )rr   r{   r9   c                 ó.   — g | _         d| _        g | _        y )Nr   )r9   rr   r{   ©Úselfs    r   Ú__init__zSegments.__init__  s   € ØˆŒØˆŒØˆ�
r   c                 ó’  — | j                   rÓ| j                   d   }|j                  |j                  k(  r«|j                  |j                  k(  r’t        |j                  |j                  z   |j
                  |j
                  z   |j                  |j                  «      }| xj                  t        |j                  «      z  c_        | j                   d= | j                  d= | j                   j                  |«       | xj                  t        |j                  «      z  c_        | j                  j                  |j                  «       y)z:
        :param _Segment segment: Segment to add.
        rÍ   N)
r9   r5   r7   r“  rg   rb   rr   rG   r{   r  )rý  rš   Úprev_segs      r   r?   zSegments.add_segment  sè   € ð
 �=Š=Ø—}‘} RÑ(ˆHØ�}‰} §¡Ò,°×1BÑ1BÀg×FVÑFVÒ1Vä" 8§=¡=°7·<±<Ñ#?Ø#+×#6Ñ#6¸×9KÑ9KÑ#KØ#*§<¡<°×1AÑ1AóC�ð —’¤3 x§}¡}Ó#5Ñ5•Ø—M‘M "Ð%Ø—J‘J˜r�NØ�‰×Ñ˜WÔ%Ø�Šœ3˜wŸ|™|Ó,Ñ,�Ø�
‰
×Ñ˜'Ÿ,™,Õ'r   c                 ó,   — t        | j                  «      S rñ   )rG   r9   rü  s    r   Ú__len__zSegments.__len__-  s   € Ü�4—=‘=Ó!Ð!r   c                 ó    — | j                   |   S rñ   )r9   ©rý  r~  s     r   Ú__getitem__zSegments.__getitem__0  s   € Ø�}‰}˜TÑ"Ð"r   c                 ó,   — t        | j                  «      S rñ   )rÆ  r9   rü  s    r   Ú__iter__zSegments.__iter__3  s   € Ü�D—M‘MÓ"Ð"r   c                 óš  ‡— d}|r,t        d„ | j                  D «       «      }||dz  z  }||dz  z  }|r|dz  }|dkD  r|t        | j                  «      dz  z  }n1|t        j
                  kD  r|t        | j                  «      |dz   z  z  }|dkD  rt        |«      n|Š|t        ˆfd„| j                  D «       «      z  }|| j                  z   S )Nr   c              3   ó”   K  — | ]@  }|j                   t        j                  k(  r!|j                  t        j                  k7  rd –— ŒB y­wrè   )r5   r   r\   r7   r]   )rê   rš   s     r   rì   z4Segments.bit_length_with_overhead.<locals>.<genexpr>:  s?   è ø€ ò $Z¨'Ø'.§|¡|´v×7GÑ7GÒ'GØ(/×(8Ñ(8¼F×<XÑ<XÒ(Xô %&ñ $Zùs   ‚AArQ   rR   rS   rT   c              3   óJ   •K  — | ]  }t         j                  |   ‰   –— Œ y ­wrñ   )r   r[   )rê   r5   rc   s     €r   rì   z4Segments.bit_length_with_overhead.<locals>.<genexpr>J  s"   øè ø€ ÒcÐPTœ×:Ñ:¸4Ñ@ÀÕKÑcùs   ƒ #)r@  r9   rG   r{   r   r.   rl   rr   )rý  r4   r!   re   rf   Úno_eci_indicatorsrc   s         @r   r£   z!Segments.bit_length_with_overhead6  sÞ   ø€ ØˆáÜ #ñ $Z°T·]±]ô $Zó !ZÐð Ð)¨AÑ-Ñ-ˆHØÐ)¨AÑ-Ñ-ˆHÙð ˜ÑˆHà�QŠ;Øœ˜DŸJ™J›¨!Ñ+Ñ+‰HØ”v×(Ñ(Ò(Øœ˜DŸJ™J›¨7°Q©;Ñ7Ñ7ˆHà.5¸ªk”M 'Ô*¸wˆ	Ø”CÓcÐX\×XbÑXbÔcÓcÑcˆØ˜$Ÿ/™/Ñ)Ð)r   N©F)r   r   r   r   Ú	__slots__rþ  r?   r  r  r  r£   r   r   r   r>   r>     s,   „ ñð 4€Iòò
(ò&"ò#ò#ô*r   r>   c                   óŒ   — e Zd ZdZdZd	d„Z e ed«      «      Z e ed«      «      Z	 e ed«      «      Z
 e ed«      «      Zy)
r“  aN      Represents a data segment.

    A segment provides the (encoding specific) byte data, the data length,
    the QR Code mode, and the used encoding. The latter is ``None`` iff mode
    is not "byte".

    Note that `data_length` may not be equal to len(data)!

    See also ISO/IEC 18004:2015(E) - 7.4.7 Mixing modes (page 30)
    r   Nc                 ó6   — t         j                  | ||||f«      S rñ   )r1  Ú__new__)Úclsrg   rb   r5   r7   s        r   r  z_Segment.__new__\  s   € Ü�}‰}˜S 4¨°T¸8Ð"DÓEÐEr   r   r   rW   rT   rñ   )r   r   r   r   r  r  Úpropertyr   rg   rb   r5   r7   r   r   r   r“  r“  N  sN   „ ñ
ð €IóFñ ‘J˜q“MÓ"€DÙ™* Q›-Ó(€JÙ‘J˜q“MÓ"€DÙ™
 1›Ó&�Hr   r“  c                   óB   — e Zd ZdZdgZdd„Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zy
)r‡   zO    Wraps a :cls:`bytearray` and provides some useful methods to add bits.
    Ú_datac                 ó$   — t        |«      | _        y rñ   )r  r  ©rý  Úiterables     r   rþ  zBuffer.__init__k  s   € Ü˜xÓ(ˆ�
r   c                 ó:   — | j                   j                  |«       y rñ   )r  r¬   r  s     r   r¬   zBuffer.extendn  s   € Ø�
‰
×Ñ˜(Õ#r   c                 ór   ‡— | j                   j                  ˆfd„t        t        |«      «      D «       «       y )Nc              3   ó.   •K  — | ]  }‰|z	  d z  –— Œ y­wrè   r   ré   s     €r   rì   z%Buffer.append_bits.<locals>.<genexpr>r  s   øè ø€ ÒJ¨Q˜3 !™8 q�.ÑJùrí   )r  r¬   rî   rH   )rý  rë   rq   s    ` r   r‰   zBuffer.append_bitsq  s$   ø€ Ø�
‰
×ÑÓJ´(¼5À»=Ó2IÔJÕJr   c                 ó   — | j                   S rñ   ©r  rü  s    r   r”  zBuffer.getbitst  s   € Ø�z‰zÐr   c                 óT   — d„ t        t        | j                  «      gdz  ddiŽD «       S )z…        Returns an iterable of integers interpreting the content of `seq`
        as sequence of binary numbers of length 8.
        c           	   3   ón   K  — | ]-  }t        d j                  t        t        |«      «      d«      –— Œ/ y­w)rÎ  rW   N)rn   r«  r	  r|   )rê   Úgs     r   rì   z Buffer.toints.<locals>.<genexpr>|  s&   è ø€ Òh°”�B—G‘GœC¤ Q›KÓ(¨!×,Ñhùs   ‚35rR   Ú	fillvaluer   )r   rÆ  r  rü  s    r   r  zBuffer.tointsw  s-   € ñ
 i´kÄDÈÏÉÓDTÐCUÐXYÑCYÐ6gÐefÑ6gÔhÐhr   c                 ó,   — t        | j                  «      S rñ   )rG   r  rü  s    r   r  zBuffer.__len__~  s   € Ü�4—:‘:‹Ðr   c                 ó    — | j                   |   S rñ   r  r  s     r   r  zBuffer.__getitem__�  s   € Ø�z‰z˜$ÑÐr   N)r   )r   r   r   r   r  rþ  r¬   r‰   r”  r  r  r  r   r   r   r‡   r‡   e  s5   „ ñð �	€Ió)ò$òKòòiòó r   r‡   c                   ó–   ‡ — e Zd ZdZdZˆ fd„Z e ed«      «      Z e ed«      «      Z	 e ed«      «      Z
 e ed«      «      Zˆ xZS )r   zù    Represents Structured Append information.

    Note: This class provides the Structured Append header information in
    correct order (incl. Structured Append mode indicator); cf.
    ISO/IEC 18004:2015(E) -- 8 Structured Append (page 59).
    r   c                 óH   •— t         ‰| �  | t        j                  |||f«      S )z¢        :param int number: Symbol number ``[0 .. 15]``
        :param int total: Total symbol count ``[2 .. 15]``
        :param int parity: Parity data.
        )Úsuperr  r   ÚMODE_STRUCTURED_APPEND)r  Únumberrx   ry   Ú	__class__s       €r   r  z_StructuredAppendInfo.__new__�  s&   ø€ ô ‰w‰˜s¤V×%BÑ%BÀFÈEÐSYÐ$ZÓ[Ð[r   r   r   rW   rT   )r   r   r   r   r  r  r  r   r5   r'  rx   ry   Ú__classcell__)r(  s   @r   r   r   …  sO   ø„ ñð €Iô\ñ ‘J˜q“MÓ"€DÙ‘j “mÓ$€FÙ‘Z “]Ó#€EÙ‘j “mÓ$„Fr   r   )NNNNNFNT)NNNNNFTNrñ   r  )TT)Rr   Úoperatorr   r   r   r   Ú	functoolsr   r   Ú	itertoolsr	   r
   r   Úrero   rá  Úcollectionsr   rÎ  r   r   ÚsysÚmaxsizer,  Ú__all__r%   r   r   r   r   r1   rˆ   rŠ   r‹   rŒ   r�   r½   r‘   rÉ   r’   r“   rŽ   r  r”   r0  r-  rA  r.  rk  r•   r–   r,   r†  r@   r�   r#   r(   r0   r'   r*   r¼  r&   ÚcompileÚescaper’  rÁ  rÄ  rÊ  r‘  r-   r�   r}   r)   rÏ  rl   rª   r/  r>   r1  r“  r‡   r   r   r   r   ú<module>r4     sÒ  ðñ÷ -Ó ,ß %ß ,Ñ ,Û 	Û Û Ý "Ý Ý !Û 
Ø—[‘[Ð Øà
<€ô	˜
ô 	ñ �&Ð>Ó?€ð ?CØ=Aó*EðZ HLØMQómKó`38óló:ò>Mò.ò&(ð8B€òZò2ò&>òD(GòV,ò^%óD;%ò|-ò(
3òi2òXBò"ò4;ò|$òNòB#%óLbPóJ(òV òF_ò.ó6eò45ò=òDð$ #˜Ÿ
™
 6¨I¨B¯I©I°f×6OÑ6OÓ,PÑ#PÐS[Ñ#[Ó\Ð ò-òò$ó"#bòL:òò&3ò&
ò5ò&
Vò52÷p?*ñ ?*ôD'ˆuô '÷. ñ  ô@%˜Eõ %r   