a
    Sicl                     @   s4  d Z ddlmZmZ ddlZddlZddlZzddlmZ e	Z
W n& eyf   ddlmZ eZ	eZ
Y n0 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d0ddZedjZd1ddZd2dd Zd!d" Zd#d$ Zd3d%d&Zd4d'd(Z d5d)d*Z!d6d+d,Z"dS )7a  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()`.
    )absolute_importunicode_literalsN)quote\z\\;z\;:z\:"z\",z\,c                 C   s   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   I/var/www/html/django/DPS/env/lib/python3.9/site-packages/segno/helpers.py_escape_mecard-   s    r   c                 C   s   t | tS r
   )r   r   _VCARD_ESCAPEr   r   r   r   _escape_vcard7   s    r   Fc                 C   sj   t }d}|r*|d|dkr"| n|7 }|d|| 7 }|durV|d||7 }||r`dn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:{0};nopasszS:{0};NzP:{0};zH:true;r   )r   formatupper)ssidpasswordsecurityhiddenescapedatar   r   r   make_wifi_dataA   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_wifi[   s    r!   c                    s2   fdd}t  d | g}|r8|d | ||d| ||d| ||d| |r|d | |rz|d	}W n ty   Y n0 |d
| ||d| |	|
|||||f}t|r fdd|D }|dj|  |r|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                    s0   |d u rdS t |tr|f} fdd|D S )Nr   c                    s   g | ]}d   |qS )z{0}:{1};r   .0ir   namer   r   
<listcomp>       z=make_mecard_data.<locals>.make_multifield.<locals>.<listcomp>
isinstancestr_typer'   valr   r'   r   make_multifield   s
    
z)make_mecard_data.<locals>.make_multifieldzMECARD:N:{0};z
SOUND:{0};TELZTELAVEMAILzNICKNAME:{0};z%Y%m%dz	BDAY:{0};URLc                    s   g | ]} |pd qS  r   r#   r/   r   r   r(      r)   z$make_mecard_data.<locals>.<listcomp>z ADR:{0},{1},{2},{3},{4},{5},{6};z	MEMO:{0};r   r6   )r   r   appendextendstrftimeAttributeErroranyjoin)r'   readingemailphone
videophonememonicknamebirthdayurlpoboxroomnohousenocity
prefecturezipcodecountryr1   r   adr_propertiesadr_datar   r/   r   make_mecard_datam   s2    )

rN   c                 C   s.   t t| |||||||||	|
|||||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@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   )r   r    rN   rO   r   r   r   make_mecard   s    )
rP   zB^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:(?:-?\d{2}:\d{2})|Z)?)?$c                    sx   fdd}t  ddd| d |g}|rD|d | ||d| ||d	| ||d
| ||d| ||d| ||d| ||d| ||d|	 ||d| ||d| |r|d | |
|||||f}t|r8 fdd|D }|dj|  |rz|d}W n ty`   Y n0 t|trxt	|st
d|d| |r|r|r|st
d|r|r|d|| |r|d | |r|d | |rZz|d}W n ty*   Y n0 t|trBt	|sJt
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                    s0   |d u rdS t |tr|f} fdd|D S )Nr   c                    s   g | ]}d   |qS )z{0}:{1}r"   r#   r&   r   r   r(   4  r)   z<make_vcard_data.<locals>.make_multifield.<locals>.<listcomp>r*   r-   r/   r0   r   r1   /  s
    
z(make_vcard_data.<locals>.make_multifieldzBEGIN:VCARDzVERSION:3.0zN:{0}zFN:{0}zORG:{0}r3   r2   zTEL;TYPE=FAXzTEL;TYPE=VIDEOzTEL;TYPE=CELLzTEL;TYPE=HOMEzTEL;TYPE=WORKr4   ZTITLEzPHOTO;VALUE=urizNICKNAME:{0}c                    s   g | ]} |pd qS r5   r   r#   r/   r   r   r(   J  r)   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 representationzBDAY:{0}zBIncomplete geo information, please specify latitude and longitude.zGEO:{0};{1}z
SOURCE:{0}zNOTE:{0}zB"rev" does not seem to be a valid date or date/time representationzREV:{0}z	END:VCARDr6   z
)r   r   r7   r8   r;   r9   r:   r+   r,   _looks_like_datetime
ValueErrorr<   )r'   displaynamer>   r?   faxr@   rA   rB   rC   rD   rE   streetrH   regionrJ   rK   orglatlngsourcerevtitle	photo_uri	cellphone	homephone	workphoner1   r   rL   rM   r   r/   r   make_vcard_data   sf    B


ra   c                 C   sB   t t| |||||||||	|
|||||||||||||||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?   rT   r@   rA   rB   rC   rD   rE   rU   rH   rV   rJ   rK   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   )r   r    ra   )r'   rS   r>   r?   rT   r@   rA   rB   rC   rD   rE   rU   rH   rV   rJ   rK   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   r   r   r   
make_vcardi  s    Crb   c                 C   s   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S )Nz{0:.8f}0)r   rstrip)fr   r   r   float_to_str  s    z#make_geo_data.<locals>.float_to_strzgeo:{0},{1}r"   )rX   rY   rf   r   r   r   make_geo_data  s    rg   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    rg   )rX   rY   r   r   r   make_geo  s    	rh   c                 C   s   dd }d}dg}| st d|d||  d|fd|ffD ]2\}}	||	}
|
rB|d	||d|
 d
}qBd|fd|ffD ]2\}}	|	dur|d	||t|	d d
}qd|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bccz
{0}{1}={2}&subjectbodyNutf-8r6   )rR   r7   r<   r   r   encode)torl   rm   ro   rp   rj   delimr   keyr.   valsr   r   r   make_make_email_data  s     rw   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
    rs   rl   rm   ro   rp   )r   r    rw   rx   r   r   r   
make_email  s    ry   c              
   C   sZ  d}t d}	t d}
|r$| n|}|r4| n|}|rD| n|}| rT|  n| } |durt|trz|| d }W q ty   td	||Y q0 n2t|t
rd|  krt|ksn td	||s|r|r|rtd|r(d	t|  k rd
ks(n td	t|n6|r^d	t|  k rJdks^n td	t|| du sd	t|   k rdksn td	| |du sdt|  k rdksn td	||rt|dvrtd	||rt|dkrtd	|t |}|	|  kr0|
ksBn td	|	|
dddd|pRd| |d	|dd|prd|pzdg
}|r|| d|}|du rdn|}|d	k rt|dd d d!D ]:\}}z|| |}W  qW n ty   Y n0 q|d	k rd}t||d < d|||d  }t|d"krVtd#	t||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.
    )rq   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 "{0}", use one of {1}z9Invalid encoding number only 1 .. 8 are allowed, got "{}"zBEither a text or a creditor reference (ISO 11649) must be providedr      z7Invalid text, max. 140 characters are allowed, got "{}"#   zPInvalid creditor reference (ISO 11649), max. 35 characters are allowed, got "{}"F   z6Invalid name, max. 70 characters are allowed, got "{}"   "   zAInvalid IBAN, min. 5 and max. 34 characters are allowed, got "{}")      z8Invalid BIC, should be 8 or 11 characters long, got "{}"z3Invalid purpose, 4 characters are allowed, got "{}"zBInvalid amount, must be in bigger or equal {} and less or equal {}ZBCDZ002r6   ZSCTz	EUR{:.2f}rc   .
   )startiK  z8Payload is too big: Max. 331 bytes allowed, got {} bytes)decimalDecimalrd   stripr+   r,   indexlowerrR   r   intlenr7   r<   	enumeraterr   UnicodeEncodeErrorr   )r'   ibanamounttext	referencebicpurposeencoding	encodingsZ
min_amountZ
max_amountZtmp_datar   charsetidxencr   r   r   _make_epc_qr_data  s    


$$$((






r   c           	   
   C   s@   t jt| |||||||ddd}|jdkr<td|j|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   zAInvalid EPC QR Code, max. QR Code version 13 is allowed, got "{}")r   r    r   versionrR   r   
designator)	r'   r   r   r   r   r   r   r   qrr   r   r   make_epc_qrb  s    +
r   )NNF)NNF)NNNNNNNNNNNNNNN)NNNNNNNNNNNNNNN)NNNNNNNNNNNNNNNNNNNNNNNN)NNNNNNNNNNNNNNNNNNNNNNNN)NNNN)NNNN)NNNNN)NNNNN)#__doc__
__future__r   r   rer   r   urllib.parser   r   r,   ImportErrorurllibunicode
basestringordr   r   r   r   r   r!   rN   rP   compilematchrQ   ra   rb   rg   rh   rw   ry   r   r   r   r   r   r   <module>   st   

	



    
J    
3      
|      
R
)
  
O  