
    1yii              	       d   d Z ddlZddlZddlZddlmZ  ed      d ed      d ed      d	 ed
      diZ ed      d ed      diZd Z	d Z
ddZddZ	 	 	 	 ddZ	 	 	 	 ddZ ej                  d      j                   Z	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZd Zd Zd dZd dZ	 	 d!dZ	 	 d!dZy)"a  Additional factory functions for common QR codes.

Aside from  :py:func:`make_epc_qr`, the factory functions return a QR code
with the minimum error correction level "L" (or better).

To create a (Micro) QR code which should use a specific error correction level
or version etc., use the "_data" factory functions which return a string which
can be used as input for :py:func:`segno.make()`.
    N)quote\z\\;z\;:z\:"z\",z\,c                 >    t        |       j                  t              S z~    Escapes ``\``, ``;``, ``"`` and ``:`` in the provided string.

    :param str s: The string to escape.
    :rtype str
    )str	translate_MECARD_ESCAPEss    M/var/www/api/v1/venv_fitandmore/lib/python3.12/site-packages/segno/helpers.py_escape_mecardr   %   s     q6N++    c                 >    t        |       j                  t              S r
   )r   r   _VCARD_ESCAPEr   s    r   _escape_vcardr   /   s     q6M**r   c                     t         }d}|r|d|dk7  r|j                         n| dz  }|d ||        dz  }||d ||       dz  }||rdz  }|S dz  }|S )a      Creates WIFI configuration string.

    :param str ssid: The SSID of the network.
    :param password: The password.
    :type password: str or None
    :param security: Authentication type; the value should be "WEP" or "WPA".
            Set to ``None`` to omit the value.
            "nopass" is equivalent to setting the value to ``None`` but in
            the former case, the value is not omitted.
    :type security: str or None
    :param bool hidden: Indicates if the network is hidden (default: ``False``)
    :rtype: str
    zWIFI:zT:nopassr   zS:zP:zH:true;)r   upper)ssidpasswordsecurityhiddenescapedatas         r   make_wifi_datar   9   s     FD"X)=X^^%8LANNba  D"VH%&a((I(DK &)(DKr   c                 D    t        j                  t        | |||            S )a(      Creates a WIFI configuration QR code.

    :param str ssid: The SSID of the network.
    :param password: The password.
    :type password: str or None
    :param security: Authentication type; the value should be "WEP" or "WPA".
            Set to ``None`` to omit the value.
            "nopass" is equivalent to setting the value to ``None`` but in
            the former case, the value is not omitted.
    :type security: str or None
    :param bool hidden: Indicates if the network is hidden (default: ``False``)
    :rtype: segno.QRCode
    )segnomake_qrr   )r   r   r   r   s       r   	make_wifir#   S   s     ==h&IJJr   c                    fd}t         d |        dg}|r|j                  d |       d       |j                   |d|             |j                   |d|             |j                   |d|             |r|j                  d |       d       |r'	 |j                  d	      }|j                  d
| d       |j                   |d|             |	|
|||||f}t        |      r7|D cg c]  } |xs d       }}|j                   dj                  |        |r|j                  d |       d       |j                  d       dj                  |      S # t        $ r Y w xY wc c}w )a      Creates a string encoding the contact information as MeCard.

    :param str name: Name. If it contains a comma, the first part
            is treated as lastname and the second part is treated as forename.
    :param reading: Designates a text string to be set as the kana name in the phonebook
    :type reading: str or None
    :param email: E-mail address. Multiple values are allowed.
    :type email: str, iterable of strings, or None
    :param phone: Phone number. Multiple values are allowed.
    :type phone: str, iterable of strings, or None
    :param videophone: Phone number for video calls. Multiple values are allowed.
    :type videophone: str, iterable of strings, or None
    :param memo: A notice for the contact.
    :type memo: str or None
    :param nickname: Nickname.
    :type nickname: str or None
    :param birthday: Birthday. If a string is provided, it should encode the date as YYYYMMDD value.
    :type birthday: str, datetime.date or None
    :param url: Homepage. Multiple values are allowed.
    :type url: str, iterable of strings, or None
    :param pobox: P.O. box (address information).
    :type pobox: str or None
    :param roomno: Room number (address information).
    :type roomno: str or None
    :param houseno: House number (address information).
    :type houseno: str or None
    :param city: City (address information).
    :type city: str or None
    :param prefecture: Prefecture (address information).
    :type prefecture: str or None
    :param zipcode: Zip code (address information).
    :type zipcode: str or None
    :param country: Country (address information).
    :type country: str or None
    :rtype: str
    c                 r    |syt        |t              r|f}|D cg c]  }|  d |       d c}S c c}w )N r   r   
isinstancer   namevalir   s      r   make_multifieldz)make_mecard_data.<locals>.make_multifield   sC    c3&C03414&&)A&444s   4z	MECARD:N:r   zSOUND:TELTELAVEMAIL	NICKNAME:z%Y%m%dBDAY:URL z ADR:{0},{1},{2},{3},{4},{5},{6};zMEMO:)r   appendextendstrftimeAttributeErroranyformatjoin)r*   readingemailphone
videophonememonicknamebirthdayurlpoboxroomnohousenocity
prefecturezipcodecountryr-   r   adr_propertiesr,   adr_datar   s                        @r   make_mecard_datarM   e   s|   R5 Ft~Q'(DfVG_-Q/0KKu-.KK45KK/0ix 0134	((2H 	eH:Q'(KKs+,VWdJQN
>-;<^F17O^<=6==xHIeF4L>+,KK774=  		 =s   E' 5E6'	E32E3c                     t        j                  t        di d| d|d|d|d|d|d|d|d	|d
|	d|
d|d|d|d|d|      S )a      Returns a QR code which encodes a `MeCard <https://en.wikipedia.org/wiki/MeCard>`_

    :param str name: Name. If it contains a comma, the first part
            is treated as lastname and the second part is treated as forename.
    :param reading: Designates a text string to be set as the kana name in the phonebook
    :type reading: str or None
    :param email: E-mail address. Multiple values are allowed.
    :type email: str, iterable of strings, or None
    :param phone: Phone number. Multiple values are allowed.
    :type phone: str, iterable of strings, or None
    :param videophone: Phone number for video calls. Multiple values are allowed.
    :type videophone: str, iterable of strings, or None
    :param memo: A notice for the contact.
    :type memo: str or None
    :param nickname: Nickname.
    :type nickname: str or None
    :param birthday: Birthday. If a string is provided, it should encode the date as YYYYMMDD value.
    :type birthday: str, datetime.date or None
    :param url: Homepage. Multiple values are allowed.
    :type url: str, iterable of strings, or None
    :param pobox: P.O. box (address information).
    :type pobox: str or None
    :param roomno: Room number (address information).
    :type roomno: str or None
    :param houseno: House number (address information).
    :type houseno: str or None
    :param city: City (address information).
    :type city: str or None
    :param prefecture: Prefecture (address information).
    :type prefecture: str or None
    :param zipcode: Zip code (address information).
    :type zipcode: str or None
    :param country: Country (address information).
    :type country: str or None
    :rtype: segno.QRCode
    r*   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   r&   )r!   r"   rM   )r*   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   s                   r   make_mecardrO      s    R ==) ;t ;W ;05;=B;5?;FJ; 4<; GO; /2	; :?	; HN	;
 3:;
 AE; 6@; JQ; 3:; < <r   zB^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:(?:-?\d{2}:\d{2})|Z)?)?$c                    fd}t         ddd|  d |       g}|r|j                  d |              |j                   |d|             |j                   |d|             |j                   |d	|             |j                   |d
|             |j                   |d|             |j                   |d|             |j                   |d|             |j                   |d|	             |j                   |d|             |j                   |d|             |r|j                  d |              |
|||||f}t        |      r7|D cg c]  } |xs d       }}|j                   dj                  |        |rL	 |j                  d      }t        |t              rt        |      st        d      |j                  d|        |r|r|r|st        d      |r|r|j                  d| d|        |r|j                  d |              |r|j                  d |              |rL	 |j                  d      }t        |t              rt        |      st        d      |j                  d|        |j                  d       |j                  d       dj                  |      S c c}w # t        $ r Y 2w xY w# t        $ r Y w xY w) a
      Creates a string encoding the contact information as vCard 3.0.

    Only a subset of available `vCard 3.0 properties <https://tools.ietf.org/html/rfc2426>`
    is supported.

    :param str name: The name. If it contains a semicolon, , the first part
            is treated as lastname and the second part is treated as forename.
    :param str displayname: Common name.
    :param email: E-mail address. Multiple values are allowed.
    :type email: str, iterable of strings, or None
    :param phone: Phone number. Multiple values are allowed.
    :type phone: str, iterable of strings, or None
    :param fax: Fax number. Multiple values are allowed.
    :type fax: str, iterable of strings, or None
    :param videophone: Phone number for video calls. Multiple values are allowed.
    :type videophone: str, iterable of strings, or None
    :param memo: A notice for the contact.
    :type memo: str or None
    :param nickname: Nickname.
    :type nickname: str or None
    :param birthday: Birthday. If a string is provided, it should encode the
                     date as ``YYYY-MM-DD`` value.
    :type birthday: str, datetime.date or None
    :param url: Homepage. Multiple values are allowed.
    :type url: str, iterable of strings, or None
    :param pobox: P.O. box (address information).
    :type pobox: str or None
    :param street: Street address.
    :type street: str or None
    :param city: City (address information).
    :type city: str or None
    :param region: Region (address information).
    :type region: str or None
    :param zipcode: Zip code (address information).
    :type zipcode: str or None
    :param country: Country (address information).
    :type country: str or None
    :param org: Company / organization name.
    :type org: str or None
    :param lat: Latitude.
    :type lat: float or None
    :param lng: Longitude.
    :type lng: float or None
    :param source: URL where to obtain the vCard.
    :type source: str or None
    :param rev: Revision of the vCard / last modification date.
    :type rev: str, datetime.date or None
    :param title: Job Title. Multiple values are allowed.
    :type title: str, iterable of strings, or None
    :param photo_uri: Photo URI. Multiple values are allowed.
    :type photo_uri: str, iterable of strings, or None
    :param cellphone: Cell phone number. Multiple values are allowed.
    :type cellphone: str, iterable of strings, or None
    :param homephone: Home phone number. Multiple values are allowed.
    :type homephone: str, iterable of strings, or None
    :param workphone: Work phone number. Multiple values are allowed.
    :type workphone: str, iterable of strings, or None
    :rtype: str
    c                 p    |syt        |t              r|f}|D cg c]  }|  d |        c}S c c}w )Nr&   r   r'   r)   s      r   r-   z(make_vcard_data.<locals>.make_multifield'  sA    c3&C/23s!4&&)%s333s   3zBEGIN:VCARDzVERSION:3.0zN:zFN:zORG:r0   r.   zTEL;TYPE=FAXzTEL;TYPE=VIDEOzTEL;TYPE=CELLzTEL;TYPE=HOMEzTEL;TYPE=WORKr3   TITLEzPHOTO;VALUE=urir1   r4   zADR:{0};;{1};{2};{3};{4};{5}z%Y-%m-%dzG"birthday" does not seem to be a valid date or date/time representationr2   zBIncomplete geo information, please specify latitude and longitude.zGEO:r   zSOURCE:zNOTE:zB"rev" does not seem to be a valid date or date/time representationzREV:z	END:VCARDz
)r   r5   r6   r9   r:   r7   r8   r(   r   _looks_like_datetime
ValueErrorr;   ) r*   displaynamer=   r>   faxr?   r@   rA   rB   rC   rD   streetrG   regionrI   rJ   orglatlngsourcerevtitle	photo_uri	cellphone	homephone	workphoner-   r   rK   r,   rL   r   s                                   @r   make_vcard_datarc      s   D4 F=K&%&')D d6#;-()KK/0KKu-.KK45KK 0*=>KK;<KK;<KK;<KKs+,KK/0KK 19=>ix 0123VT67GDN
>-;<^F17O^<92998DE	((4H (C(0DX0NfggeH:&'CS]^^
sd3%q&'gfVn-./eF4L>*+
	,,z*C #s#+?+Dabbd3%L!KKKKO;;t9 =
  		   		s*   KK K 	KK	K'&K'c                     t        j                  t        | |f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|      S )a
      Creates a QR code which encodes a `vCard <https://en.wikipedia.org/wiki/VCard>`_
    version 3.0.

    Only a subset of available `vCard 3.0 properties <https://tools.ietf.org/html/rfc2426>`
    is supported.

    :param str name: The name. If it contains a semicolon, , the first part
            is treated as lastname and the second part is treated as forename.
    :param str displayname: Common name.
    :param email: E-mail address. Multiple values are allowed.
    :type email: str, iterable of strings, or None
    :param phone: Phone number. Multiple values are allowed.
    :type phone: str, iterable of strings, or None
    :param fax: Fax number. Multiple values are allowed.
    :type fax: str, iterable of strings, or None
    :param videophone: Phone number for video calls. Multiple values are allowed.
    :type videophone: str, iterable of strings, or None
    :param memo: A notice for the contact.
    :type memo: str or None
    :param nickname: Nickname.
    :type nickname: str or None
    :param birthday: Birthday. If a string is provided, it should encode the
                     date as ``YYYY-MM-DD`` value.
    :type birthday: str, datetime.date or None
    :param url: Homepage. Multiple values are allowed.
    :type url: str, iterable of strings, or None
    :param pobox: P.O. box (address information).
    :type pobox: str or None
    :param street: Street address.
    :type street: str or None
    :param city: City (address information).
    :type city: str or None
    :param region: Region (address information).
    :type region: str or None
    :param zipcode: Zip code (address information).
    :type zipcode: str or None
    :param country: Country (address information).
    :type country: str or None
    :param org: Company / organization name.
    :type org: str or None
    :param lat: Latitude.
    :type lat: float or None
    :param lng: Longitude.
    :type lng: float or None
    :param source: URL where to obtain the vCard.
    :type source: str or None
    :param rev: Revision of the vCard / last modification date.
    :type rev: str, datetime.date or None
    :param title: Job Title. Multiple values are allowed.
    :type title: str, iterable of strings, or None
    :param photo_uri: Photo URI. Multiple values are allowed.
    :type photo_uri: str, iterable of strings, or None
    :param cellphone: Cell phone number. Multiple values are allowed.
    :type cellphone: str, iterable of strings, or None
    :param homephone: Home phone number. Multiple values are allowed.
    :type homephone: str, iterable of strings, or None
    :param workphone: Work phone number. Multiple values are allowed.
    :type workphone: str, iterable of strings, or None
    :rtype: segno.QRCode
    r=   r>   rV   r?   r@   rA   rB   rC   rD   rW   rG   rX   rI   rJ   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   )r!   r"   rc   )r*   rU   r=   r>   rV   r?   r@   rA   rB   rC   rD   rW   rG   rX   rI   rJ   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   s                             r   
make_vcardre   a  s   F =={ >% >/4>:=>4>>EI> 3;> FN> .1	> 9>	> GM	>
 /3>
 <B> 29> CJ> .1> 7:> @C> 17> =@> HM> 4=> 4=> 4=> 4=> ? ?r   c                 0    d }d ||        d ||       S )zt    Creates a geo location URI.

    :param float lat: Latitude
    :param float lng: Longitude
    :rtype: str
    c                 F    | dj                  d      j                  d      S )Nz.8f0.)rstrip)fs    r   float_to_strz#make_geo_data.<locals>.float_to_str  s"    C  %,,S11r   zgeo:r   r&   )rZ   r[   rl   s      r   make_geo_datarm     s(    2 ,s#$Al3&7%899r   c                 @    t        j                  t        | |            S )z    Returns a QR code which encodes geographic location using the ``geo`` URI
    scheme.

    :param float lat: Latitude
    :param float lng: Longitude
    :rtype: segno.QRCode
    )r!   r"   rm   )rZ   r[   s     r   make_georo     s     ==sC011r   c                    d }d}dg}| st        d      |j                  dj                   ||                    d|fd|ffD ]9  \  }}	 ||	      }
|
s|j                  | | ddj                  |
              d	}; d
|fd|ffD ]9  \  }}	|	0|j                  | | dt        |	j	                  d                    d	}; dj                  |      S )a|      Creates either a simple "mailto:" URL or complete e-mail message with
    (blind) carbon copies and a subject and a body.

    :param to: The email address (recipient). Multiple values are allowed.
    :type to: str or iterable of strings
    :param cc: The carbon copy recipient. Multiple values are allowed.
    :type cc: str, iterable of strings, or None
    :param bcc: The blind carbon copy recipient. Multiple values are allowed.
    :type bcc: str, iterable of strings, or None
    :param subject: The subject.
    :type subject: str or None
    :param body: The message body.
    :type body: str or None
    :rtype: str
    c                 D    | syt        | t              r| fS t        |       S )Nr&   )r(   r   tuple)r+   s    r   multiz#make_make_email_data.<locals>.multi  s#    c36MSzr   ?zmailto:z"to" must not be empty or Noner   ccbcc=&subjectbodyutf-8r4   )rT   r5   r;   r   encode)toru   rv   ry   rz   rs   delimr   keyr+   valss              r   make_make_email_datar     s    " E;D9::KKr#$BZ%.SSzKK5'#a'789E	 /
  )FD>:S?KK5'#acjj.A(B'CDE ; 774=r   c           	      H    t        j                  t        | ||||            S )a      Encodes either a simple e-mail address or a complete message with
    (blind) carbon copies and a subject and a body.

    :param to: The email address (recipient). Multiple values are allowed.
    :type to: str or iterable of strings
    :param cc: The carbon copy recipient. Multiple values are allowed.
    :type cc: str, iterable of strings, or None
    :param bcc: The blind carbon copy recipient. Multiple values are allowed.
    :type bcc: str, iterable of strings, or None
    :param subject: The subject.
    :type subject: str or None
    :param body: The message body.
    :type body: str or None
    :rtype: segno.QRCode
    r}   ru   rv   ry   rz   )r!   r"   r   r   s        r   
make_emailr     s+    " ==-6=DJ K Kr   c                 ~   d}t        j                  d      }	t        j                  d      }
|r|j                         n|}|r|j                         n|}|r|j                         n|}| r| j                         n| } |it	        |t
              r$	 |j                  |j                               dz   }n5t	        |t              rd|cxk  rt        |      k  sn t        d| d	      |s|r|r|rt        d
      |r.dt        |      cxk  rdk  sn t        dt        |       d	      |r.dt        |      cxk  rdk  sn t        dt        |       d	      | dt        |       cxk  rdk  sn t        d|  d	      |dt        |      cxk  rdk  sn t        d| d	      |rt        |      dvrt        d| d	      |rt        |      dk7  rt        d| d	      t        j                  |      }|	|cxk  r|
k  sn t        d|	 d|
       dddd|xs d| |d|dj                  d       j                  d!      |xs d|xs dg
}|r|j                  |       d"j                  |      }|d#n|}|dk  r-t        |dd d$%      D ]  \  }}	 |j                  |       |} n |dk  rd}t        |      |d$<   d"j                  |      j                  ||dz
           }t        |      d&kD  rt        d't        |       d(      |S # t        $ r t        d| d|       w xY w# t        $ r Y w xY w))z    Validates the input and creates the data for an EPC QR Code.

    DOES NOT belong to the public API, kept separate from make_epc_qr to apply
    tests on the raw data.

    See :py:func:`make_epc_qr` for a description of the parameters.
    )r{   z
iso-8859-1z
iso-8859-2z
iso-8859-4z
iso-8859-5z
iso-8859-7ziso-8859-10ziso-8859-15z0.01z999999999.99N   zInvalid encoding "z", use one of z6Invalid encoding number only 1 .. 8 are allowed, got "r   zBEither a text or a creditor reference (ISO 11649) must be providedr      z4Invalid text, max. 140 characters are allowed, got "#   zMInvalid creditor reference (ISO 11649), max. 35 characters are allowed, got "F   z3Invalid name, max. 70 characters are allowed, got "   "   z>Invalid IBAN, min. 5 and max. 34 characters are allowed, got ")      z5Invalid BIC, should be 8 or 11 characters long, got "z0Invalid purpose, 4 characters are allowed, got "z+Invalid amount, must be in bigger or equal z and less or equal BCD002r4   SCTEURz.2frh   ri   
   )startiK  z0Payload is too big: Max. 331 bytes allowed, got z bytes)decimalDecimalrj   stripr(   r   indexlowerrT   intlenr5   r;   	enumerater|   UnicodeEncodeError)r*   ibanamounttext	referencebicpurposeencoding	encodings
min_amount
max_amounttmp_datar   charsetidxencs                   r   _make_epc_qr_datar     s|   KI(J0J 4;;=dD&/	  "YI#))+#C4::<TDh$[$??8>>+;<q@ Hc*!x2Q3y>2QUV^U__`abb]^^AD	(S(OPSTXPY{Z[\]]	1s9~33 !!$Y 03 4 	4|1s4y.B.NtfTUVWW|1s4y.B.YZ^Y__`abb
s3xw&PQTPUUVWXX3w<1$KG9TUVWW__V$F-:-FzlRefpeqrss	rfS\"))#.55c:2R
H 99XD$b(G{!)AB-q9HCC 	 : {g,HQK99X%%i!&<=D
4y3KCPTI;V\]^^Ki  [ #5hZ~i[!YZZ[V & s   "L L0L-0	L<;L<c                     t        j                  t        | |||||||      dd      }|j                  dkD  rt	        d|j
                   d      |S )a      Creates and returns an European Payments Council Quick Response Code
    (EPC QR Code) version 002.

    The returned :py:class:`segno.QRCode` uses always the error correction level
    "M" and utilizes max. version 13 to fulfill the constraints of the EPC QR
    Code standard.

    .. note::

        Either the ``text`` or ``reference`` must be provided but not both

    .. note::

        Neither the IBAN, BIC, nor remittance reference number or any other
        information is validated (aside from checks regarding the allowed string
        lengths).

    :param str name: Name of the recipient.
    :param str iban: International Bank Account Number (IBAN)
    :param amount: The amount (in EUR) to transfer.
            The currency is always Euro, no other currencies are supported.
    :type amount: int, float, decimal.Decimal
    :param str text: Remittance Information (unstructured)
    :param str reference: Remittance Information (structured)
    :param str bic: Bank Identifier Code (BIC). Optional, only required
                for non-EEA countries.
    :param str purpose: SEPA purpose code.
    :param encoding: By default, this function tries to find the best,
                minimal encoding. If another encoding should be used, the encoding
                name or the encoding constant (an integer) can be provided:
                ``1``: "UTF-8", ``2``: "ISO 8859-1", ``3``: "ISO 8859-2",
                ``4``: "ISO 8859-4", ``5``: "ISO 8859-5", ``6``: "ISO 8859-7",
                ``7``: "ISO 8859-10", ``8``: "ISO 8859-15"

                The encoding is case-insensitive.
    :type encoding: str or int
    :rtype: segno.QRCode
    mF)errorboost_error   z>Invalid EPC QR Code, max. QR Code version 13 is allowed, got "r   )r!   r"   r   versionrT   
designator)	r*   r   r   r   r   r   r   r   qrs	            r   make_epc_qrr   Y  sb    V 
(tVT9),gxA e
5B 
zzBYZ\ZgZgYhhijkkIr   )NNF)NNNNNNNNNNNNNNN)NNNNNNNNNNNNNNNNNNNNNNNN)NNNN)NNNNN)__doc__rer   r!   urllib.parser   ordr   r   r   r   r   r#   rM   rO   compilematchrS   rc   re   rm   ro   r   r   r   r   r&   r   r   <module>r      s+  	 
    IvHeHeHe	 HeHe,+4K$ MQBFAE<@GT HLIMAE&*0<f "rzz"ghnn  DHHLIMHLAE>Byx ?CCGDHCG<@9=O?d:	2&RK* JN-1K\ DH'+1r   