o
    Wgi                     @   s$  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d Z	dd Z
d,ddZd,ddZ				d-ddZ				d-ddZedjZ						d.ddZ						d.ddZd d! Zd"d# Zd/d$d%Zd/d&d'Z		d0d(d)Z		d0d*d+ZdS )1a  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                 C      t | tS z~    Escapes ``\``, ``;``, ``"`` and ``:`` in the provided string.

    :param str s: The string to escape.
    :rtype str
    )str	translate_MECARD_ESCAPEs r   J/var/www/rescue_company/venv/lib/python3.10/site-packages/segno/helpers.py_escape_mecard%      r   c                 C   r   r	   )r
   r   _VCARD_ESCAPEr   r   r   r   _escape_vcard/   r   r   Fc                 C   sv   t }d}|r|d|dkr| n| d7 }|d||  d7 }|dur.|d|| d7 }||r6d7 }|S d7 }|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:NzP:zH:true;)r   upper)ssidpasswordsecurityhiddenescapedatar   r   r   make_wifi_data9   s    r   c                 C   s   t 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   r   r   r   	make_wifiS   s   r    c                    s8   fdd}t  d |  dg}|r|d | d ||d| ||d| ||d| |rC|d	 | d |r_z|d
}W n	 tyU   Y nw |d| d ||d| |	|
|||||f}t|r fdd|D }|dj|  |r|d | d |d d|S )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                    ,   |sdS t |tr|f} fdd|D S )Nr   c                    s    g | ]} d  | dqS )r   r   r   .0ir   namer   r   
<listcomp>   s     z=make_mecard_data.<locals>.make_multifield.<locals>.<listcomp>
isinstancer
   r&   valr   r&   r   make_multifield   
   
z)make_mecard_data.<locals>.make_multifieldz	MECARD:N:r   zSOUND:TELTELAVEMAIL	NICKNAME:z%Y%m%dBDAY:URLc                       g | ]} |pd qS  r   r"   r,   r   r   r'          z$make_mecard_data.<locals>.<listcomp>z ADR:{0},{1},{2},{3},{4},{5},{6};zMEMO:r8   )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_propertiesadr_datar   r,   r   make_mecard_datae   s4   )

rR   c                 C   sp   t 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&   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   Nr   )r   r   rR   )r&   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   r   r   r   make_mecard   s:   )rS   zB^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:(?:-?\d{2}:\d{2})|Z)?)?$c                    sb   fdd}t  ddd|  d | g}|r"|d |  ||d| ||d	| ||d
| ||d| ||d| ||d| ||d| ||d|	 ||d| ||d| |r~|d |  |
|||||f}t|r fdd|D }|dj|  |rz|d}W n	 ty   Y nw t|trt	|st
d|d|  |r|r|r|st
d|r|r|d| d|  |r|d |  |r|d |  |r"z|d}W n
 ty
   Y nw t|trt	|st
d|d|  |d  |d! d"|S )#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                    r!   )Nr   c                    s   g | ]} d  | qS )r   r   r"   r%   r   r   r'   ,  s    z<make_vcard_data.<locals>.make_multifield.<locals>.<listcomp>r(   r*   r,   r-   r   r.   '  r/   z(make_vcard_data.<locals>.make_multifieldzBEGIN:VCARDzVERSION:3.0zN:zFN:zORG:r2   r0   zTEL;TYPE=FAXzTEL;TYPE=VIDEOzTEL;TYPE=CELLzTEL;TYPE=HOMEzTEL;TYPE=WORKr5   TITLEzPHOTO;VALUE=urir3   c                    r6   r7   r   r"   r,   r   r   r'   B  r9   z#make_vcard_data.<locals>.<listcomp>zADR:{0};;{1};{2};{3};{4};{5}z%Y-%m-%dzG"birthday" does not seem to be a valid date or date/time representationr4   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:VCARDr8   z
)r   r:   r;   r>   r?   r<   r=   r)   r
   _looks_like_datetime
ValueErrorr@   )r&   displaynamerB   rC   faxrD   rE   rF   rG   rH   rI   streetrL   regionrN   rO   orglatlngsourcerevtitle	photo_uri	cellphone	homephone	workphoner.   r   rP   rQ   r   r,   r   make_vcard_data   sj   B


re   c                 C   s   t 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
    rB   rC   rX   rD   rE   rF   rG   rH   rI   rY   rL   rZ   rN   rO   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   )r   r   re   )r&   rW   rB   rC   rX   rD   rE   rF   rG   rH   rI   rY   rL   rZ   rN   rO   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   r   r   r   
make_vcarda  s^   C	
rf   c                 C   s    dd }d||  d|| S )zt    Creates a geo location URI.

    :param float lat: Latitude
    :param float lng: Longitude
    :rtype: str
    c                 S   s   | d d dS )Nz.8f0.)rstrip)fr   r   r   float_to_str  s   z#make_geo_data.<locals>.float_to_strzgeo:r   r   )r\   r]   rk   r   r   r   make_geo_data  s   rl   c                 C   s   t 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   rl   )r\   r]   r   r   r   make_geo  s   	rm   c              
   C   s   dd }d}dg}| st d|d||  d|fd|ffD ]\}}	||	}
|
r<|| | d	d|
  d
}q!d|fd|ffD ]\}}	|	dur^|| | d	t|	d  d
}qEd|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                 S   s    | sdS t | tr| fS t| S )Nr   )r)   r
   tuple)r+   r   r   r   multi  s
   
z#make_make_email_data.<locals>.multi?zmailto:z"to" must not be empty or Noner   ccbcc=&subjectbodyNutf-8r8   )rV   r:   r@   r   encode)torq   rr   ru   rv   ro   delimr   keyr+   valsr   r   r   make_make_email_data  s"   "
r}   c              	   C   s   t t| ||||d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
    ry   rq   rr   ru   rv   )r   r   r}   r~   r   r   r   
make_email  s   r   c              
   C   sD  d}t d}	t d}
|r| n|}|r| n|}|r"| n|}| r*|  n| } |durlt|trRz|| d }W n+ tyQ   td| d| w t|t	rdd|  krct
|ksln td| d	|sp|rt|rx|rxtd
|rdt
|  k rdksn tdt
| d	|rdt
|  k rdksn tdt
| d	| du sdt
|   k rdksn td|  d	|du sdt
|  k rdksn td| d	|rt
|dvrtd| d	|rt
|dkrtd| d	t |}|	|  kr|
ksn td|	 d|
 dddd|p d| |d|dd d!|p1d|p5dg
}|r?|| d"|}|du rKd#n|}|dk rvt|dd d$d%D ]\}}z
|| |}W  n tyu   Y q\w |dk r}d}t||d$< d"|||d  }t
|d&krtd't
| d(|S ))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.
    )rw   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002r8   SCTEURz.2frg   rh   
   )startiK  z0Payload is too big: Max. 331 bytes allowed, got z bytes)decimalDecimalri   stripr)   r
   indexlowerrV   intlenr:   r@   	enumeraterx   UnicodeEncodeError)r&   ibanamounttext	referencebicpurposeencoding	encodings
min_amount
max_amounttmp_datar   charsetidxencr   r   r   _make_epc_qr_data  s   


$
""





r   c           	   
   C   sB   t jt| |||||||ddd}|jdk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   versionrV   
designator)	r&   r   r   r   r   r   r   r   qrr   r   r   make_epc_qrY  s   +
r   )NNF)NNNNNNNNNNNNNNN)NNNNNNNNNNNNNNNNNNNNNNNN)NNNN)NNNNN)__doc__rer   r   urllib.parser   ordr   r   r   r   r   r    rR   rS   compilematchrU   re   rf   rl   rm   r}   r   r   r   r   r   r   r   <module>   sh   
	




J
3
|
R

)
N