a
    Sic                     @   s  d 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m	Z	 ddl
mZmZmZmZmZmZ ddlZddlmZ dd	lmZ dd
lmZ ddlmZmZmZmZ ddlmZ G dd dZ ee!dddZ"G dd de	Z#G dd de	Z$G dd de	Z%eG dd dZ&eG dd dZ'G dd dZ(eG dd dZ)eG d d! d!Z*eG d"d# d#Z+eG d$d% d%Z,ee-d&d'd(Z.ee-d&d)d*Z/e-e-d+d,d-Z0e-e-d.d/d0Z1eG d1d2 d2Z2eee- ee- d3d4d5Z3dS )6zcUtility classes and functions for configuring and setting up the content and the look of a QR code.    N)
namedtuple)asdict)date)Enum)OptionalAnyUnionSequenceListTupleescape)validate_arguments)	dataclass)DEFAULT_MODULE_SIZE	SIZE_DICTDEFAULT_ERROR_CORRECTIONDEFAULT_IMAGE_FORMAT)helpersc                    @   s  e Zd ZdZeedddedddddd	dddddddddddddddfeee	df eeee	df e	e	e
e	 eeeeee	edf eee	edf eee	edf eee	edf eee	edf eee	edf eee	edf eee	edf eee	edf eee	edf eee	edf eee	edf eee	edf eee	edf eee	edf eee	edf eee	edf dd
ddZdd Zdd Zdd Zdd Zedd Zedd Zedd Zedd Zedd Zedd  Zed!d" Zed#d$ Zed%d& ZdS )'QRCodeOptionszC
    Represents the options used to create and draw a QR code.
       Nsvgutf-8TF#000#fff)sizeborderversionimage_formaterror_correctionencodingboost_errormicroeci
dark_colorlight_colorfinder_dark_colorfinder_light_colordata_dark_colordata_light_colorversion_dark_colorversion_light_colorformat_dark_colorformat_light_coloralignment_dark_coloralignment_light_colortiming_dark_colortiming_light_colorseparator_colordark_module_colorquiet_zone_colorreturnc                 C   s   || _ t|| _t|r<t|}d|  kr4dksVn d}n|dv rR| }d}nd}|| _|| _|	| _z| }|dv r~|nt| _	W n t
y   t| _	Y n0 || _|dkrdn|| _z| }|dv r|nt| _W n t
y   t| _Y n0 t|
||||||||||||||||d	| _dS )
uM  
        :param size: The size of the QR code as an integer or a string. Default is *'m'*.
        :type: str or int
        :param int border: The size of the border (blank space around the code).
        :param version: The version of the QR code gives the size of the matrix.
            Default is *None* which mean automatic in order to avoid data overflow.
        :param version: QR Code version. If the value is ``None`` (default), the
            minimal version which fits for the input data will be used.
            Valid values: "M1", "M2", "M3", "M4" (for Micro QR codes) or an
            integer between 1 and 40 (for QR codes).
            The `version` parameter is case insensitive.
        :type version: int, str or None
        :param str image_format: The graphics format used to render the QR code.
            It can be either *'svg'* or *'png'*. Default is *'svg'*.
        :param str error_correction: How much error correction that might be required
            to read the code. It can be either *'L'*, *'M'*, *'Q'*, or *'H'*. Default is *'M'*.
        :param bool boost_error: Tells whether the QR code encoding engine tries to increase the error correction level
            if it does not affect the version. Error correction level is not increased when it impacts the version of
            the code.
        :param bool micro: Indicates if a Micro QR Code should be created. Default: False
        :param encoding: Indicates the encoding in mode "byte". By default
            `encoding` is ``UTF-8``. When set to ``None``, the implementation tries to use the standard conform
            ISO/IEC 8859-1 encoding and if it does not fit, it will use UTF-8. Note that no ECI mode indicator is
            inserted by default (see :paramref:`eci`).
            The `encoding` parameter is case-insensitive.
        :type encoding: str or None
        :param bool eci: Indicates if binary data which does not use the default
            encoding (ISO/IEC 8859-1) should enforce the ECI mode. Since a lot
            of QR code readers do not support the ECI mode, this feature is
            disabled by default and the data is encoded in the provided
            `encoding` using the usual "byte" mode. Set `eci` to ``True`` if
            an ECI header should be inserted into the QR Code. Note that
            the implementation may not know the ECI designator for the provided
            `encoding` and may raise an exception if the ECI designator cannot
            be found.
            The ECI mode is not supported by Micro QR Codes.
        :param dark_color: Color of the dark modules (default: black). The
            color can be provided as ``(R, G, B)`` tuple, as hexadecimal
            format (``#RGB``, ``#RRGGBB`` ``RRGGBBAA``), or web color
            name (i.e. ``red``). If alpha transparency is supported (i.e. PNG and SVG), hexadecimal values like #RRGGBBAA are accepted.
        :param light_color: Color of the light modules (default: white).
            See `color` for valid values. If light is set to ``None`` the
            light modules will be transparent.
        :param finder_dark_color: Color of the dark finder modules (default: same as ``dark_color``)
        :param finder_light_color: Color of the light finder modules (default: same as ``light_color``)
        :param data_dark_color: Color of the dark data modules (default: same as ``dark_color``)
        :param data_light_color: Color of the light data modules (default: same as ``light_color``)
        :param version_dark_color: Color of the dark version modules (default: same as ``dark_color``)
        :param version_light_color: Color of the light version modules (default: same as ``light_color``)
        :param format_dark_color: Color of the dark format modules (default: same as ``dark_color``)
        :param format_light_color: Color of the light format modules (default: same as ``light_color``)
        :param alignment_dark_color: Color of the dark alignment modules (default: same as ``dark_color``)
        :param alignment_light_color: Color of the light alignment modules (default: same as ``light_color``)
        :param timing_dark_color: Color of the dark timing pattern modules (default: same as ``dark_color``)
        :param timing_light_color: Color of the light timing pattern modules (default: same as ``light_color``)
        :param separator_color: Color of the separator (default: same as ``light_color``)
        :param dark_module_color: Color of the dark module (default: same as ``dark_color``)
        :param quiet_zone_color: Color of the quiet zone modules (default: same as ``light_color``)

        The *size* parameter gives the size of each module of the QR code matrix. It can be either a positive integer or one of the following letters:
            * t or T: tiny (value: 6)
            * s or S: small (value: 12)
            * m or M: medium (value: 18)
            * l or L: large (value: 30)
            * h or H: huge (value: 48)

        For PNG image format the size unit is in pixels, while the unit is 0.1 mm for SVG format.

        The *border* parameter controls how many modules thick the border should be (blank space around the code).
        The default is 4, which is the minimum according to the specs.

        The *version* parameter is an integer from 1 to 40 that controls the size of the QR code matrix. Set to None to
        determine this automatically. The smallest, version 1, is a 21 x 21 matrix. The biggest, version 40, is
        177 x 177 matrix.
        The size grows by 4 modules/side.
        For Micro QR codes, valid values are "M1", "M2", "M3", "M4".

        There are 4 error correction levels used for QR codes, with each one adding different amounts of "backup" data
        depending on how much damage the QR code is expected to suffer in its intended environment, and hence how much
        error correction may be required. The correction level can be configured with the *error_correction* parameter as follow:
            * l or L: error correction level L – up to 7% damage
            * m or M: error correction level M – up to 15% damage
            * q or Q: error correction level Q – up to 25% damage
            * h or H: error correction level H – up to 30% damage

        You may enforce the creation of a Micro QR Code with `micro=True`. The `micro` option defaults to `False`.

        The `encoding` option controls the text encoding used in mode "byte" (used for any general text content). By default `encoding` is ``UTF-8``. When set to ``None``, the implementation (based on Segno) tries to use the standard conform ISO/IEC 8859-1 encoding and if it does not fit, it will use UTF-8. Note that no ECI mode indicator is inserted by default (see `eci` option). The `encoding` parameter is case-insensitive.

        The `boost_error` indicates whether the QR code encoding engine (Segno) tries to increase the error correction level if it does not affect the version. Error correction level is not increased when it impacts the version of the code.

        The `eci` option indicates if binary data which does not use the default encoding (ISO/IEC 8859-1) should enforce the ECI mode. Since a lot of QR code readers do not support the ECI mode, this feature is disabled by default and the data is encoded in the provided encoding using the usual “byte” mode. Set eci to `True` if an ECI header should be inserted into the QR Code. Note that the implementation may not know the ECI designator for the provided encoding and may raise an exception if the ECI designator cannot be found. The ECI mode is not supported by Micro QR Codes.

        :raises: TypeError in case an unknown argument is given.
           (   N)m1m2m3m4M1M2M3M4T)lmqh )r   png)r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   )_sizeint_border_can_be_cast_to_intlower_version_micro_ecir   _error_correctionAttributeError_boost_error	_encodingr   _image_formatdict_colors)selfr   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   error rW   P/var/www/html/django/DPS/env/lib/python3.9/site-packages/qr_code/qrcode/utils.py__init__   sX    }
zQRCodeOptions.__init__c                 C   s    t | j| j| j| j| j| jdS )zfInternal method which returns a dict of parameters to create a QR code.

        :rtype: dict
        )r   rV   r"   r#   r!   r    )rS   rK   rN   rL   rM   rP   rQ   rU   rW   rW   rX   kw_make   s    zQRCodeOptions.kw_makec                 C   sd   | j }t| j||  d}|dd |   D  |dkr`d|d< t|d d }||d< |S )	zdInternal method which returns a dict of parameters to save a QR code.

        :rtype: dict
        )r   kindscalec                 S   s   i | ]\}}|d d |qS )NirW   .0kvrW   rW   rX   
<dictcomp>       z)QRCodeOptions.kw_save.<locals>.<dictcomp>r   mmunitr]   
   )	rR   rS   r   _size_as_intupdatecolor_mappingitemsdecimalDecimal)rU   r   kwr]   rW   rW   rX   kw_save   s    zQRCodeOptions.kw_savec                 C   s@   dd | j  D }|ddv r(|d= |ddv r<|d= |S )z~Internal method which returns the color mapping.

        Only non-default values are returned.

        :rtype: dict
        c                 S   s   i | ]\}}|d ur||qS )FrW   r^   rW   rW   rX   rb      rc   z/QRCodeOptions.color_mapping.<locals>.<dictcomp>r$   )r   z#000000blackr%   )r   z#FFFz#ffffffz#FFFFFFwhite)rT   rj   get)rU   colorsrW   rW   rX   ri      s    zQRCodeOptions.color_mappingc                 C   sP   | j }t|r(t|}|dk rLtt }n$t|trDt| t}ntt }|S )z@Returns the size as integer value.

        :rtype: int
        r6   )	rF   rI   rG   r   r   
isinstancestrrq   rJ   )rU   r   actual_sizerW   rW   rX   rg      s    

zQRCodeOptions._size_as_intc                 C   s   | j S N)rF   rZ   rW   rW   rX   r     s    zQRCodeOptions.sizec                 C   s   | j S rv   )rH   rZ   rW   rW   rX   r     s    zQRCodeOptions.borderc                 C   s   | j S rv   )rK   rZ   rW   rW   rX   r     s    zQRCodeOptions.versionc                 C   s   | j S rv   )rR   rZ   rW   rW   rX   r     s    zQRCodeOptions.image_formatc                 C   s   | j S rv   )rN   rZ   rW   rW   rX   r     s    zQRCodeOptions.error_correctionc                 C   s   | j S rv   )rP   rZ   rW   rW   rX   r!     s    zQRCodeOptions.boost_errorc                 C   s   | j S rv   )rL   rZ   rW   rW   rX   r"     s    zQRCodeOptions.microc                 C   s   | j S rv   )rQ   rZ   rW   rW   rX   r    #  s    zQRCodeOptions.encodingc                 C   s   | j S rv   )rM   rZ   rW   rW   rX   r#   '  s    zQRCodeOptions.eci)__name__
__module____qualname____doc__r   r   r   r   rG   rt   r   booltuplerY   r[   rn   ri   rg   propertyr   r   r   r   r   r!   r"   r    r#   rW   rW   rW   rX   r      s    2







r   )valuer5   c                 C   s   t | tpt | to|  S rv   )rs   rG   rt   isdigit)r~   rW   rW   rX   rI   ,  s    rI   c                   @   s   e Zd ZdZdZdZdS )
EventClassr6         N)rw   rx   ry   PUBLICPRIVATEZCONFIDENTIALrW   rW   rW   rX   r   0  s   r   c                   @   s   e Zd ZdZdZdZdS )EventStatusr6   r   r   N)rw   rx   ry   Z	TENTATIVEZ	CONFIRMED	CANCELLEDrW   rW   rW   rX   r   6  s   r   c                   @   s   e Zd ZdZdZdS )EventTransparencyr6   r   N)rw   rx   ry   OPAQUEZTRANSPARENTrW   rW   rW   rX   r   <  s   r   c                   @   s   e Zd ZU dZeed< eed< ejed< ejed< dZeej ed< dZ	ee ed< dZ
ee ed	< dZee ed
< dZee ed< dZeeeef  ed< dZee ed< dZeee  ed< dZee ed< dZee ed< edddZdS )VEventa  
    Data for representing VEVENT for iCalendar (.ics) event.

    Only a subset of https://icalendar.org/iCalendar-RFC-5545/3-6-1-event-component.html is supported.

    Fields meaning:
        * uid: Event identifier
        * summary: This property defines a short summary or subject for the calendar event.
        * start: Start of event
        * end: End of event
        * dtstamp: The property indicates the date/time that the instance of the iCalendar object was created. Defaults to current time in UTC.
        * description: This property provides a more complete description of the calendar component, than that provided by the "SUMMARY" property.
        * organizer: E-mail of organizer
        * status: Status of event
        * location: Location of event
        * geo: This property specifies information related to the global position of event. The property value specifies latitude and longitude, in that order. Whole degrees of latitude shall be represented by a two-digit decimal number ranging from -90 through 90. The longitude represents the location east or west of the prime meridian as a positive or negative real number, respectively (a decimal number ranging from -180 through 180).
        * event_class: Either PUBLIC, PRIVATE or CONFIDENTIAL (see `utils.EventClass`).
        * categories: This property defines the categories for calendar event.
        * transparency: Tell whether the event can have its Time Transparency set to "TRANSPARENT" in order to prevent blocking of the event in searches for busy time.
        * url: This property defines a Uniform Resource Locator (URL) associated with the iCalendar object.
    uidsummarystartendNdtstampdescription	organizerstatuslocationgeoevent_class
categoriestransparencyurlr5   c                    s  d!dd}dd }t ddd	 td fd
d}d| jpBtj tjd d| j	 d|| j
 d|| j d|| j 
}| jr|d| jj 7 }| jr|d|ddt|| j  7 }| jr|d| jj 7 }| jr |d|d|| j  7 }| jr|d| j 7 }| jr2|d| jj 7 }| jrV|d|d|| j  7 }| jr~|d| jd  d| jd  7 }| jr|d| j 7 }|d 7 }|S )"z        Creates a string encoding the event information.

        Only a subset of https://icalendar.org/iCalendar-RFC-5545/3-6-1-event-component.html is supported.
        K   
 c              
      s   d}|  dD ]zd W nl ttfy   g }d}D ]:}t|d}||7 }| krn|| |}|| q>|d|7 }Y q0 || fddtdt d D 7 }q|S )	a  Make a string folded as defined in RFC5545
            Lines of text SHOULD NOT be longer than 75 octets, excluding the line
            break.  Long content lines SHOULD be split into a multiple line
            representations using a line "folding" technique.  That is, a long
            line can be split between any two characters by inserting a CRLF
            immediately followed by a single linear white-space character (i.e.,
            SPACE or HTAB).
            rD   
asciir   r   c                 3   s"   | ]}||  d   V  qdS )r6   NrW   )r_   ilimitlinerW   rX   	<genexpr>  rc   zHVEvent.make_qr_code_data.<locals>.fold_icalendar_line.<locals>.<genexpr>r6   )splitencodeUnicodeEncodeErrorUnicodeDecodeErrorlenappendjoinrange)textr   Zfold_sepZnew_textZ	ret_charsZ
byte_countcharZchar_byte_lenrW   r   rX   fold_icalendar_linep  s"    	
0z5VEvent.make_qr_code_data.<locals>.fold_icalendar_linec                 S   s4   |  dd dd dd dd d	d
 dd
S )z8Format value according to iCalendar TEXT escaping rules.z\Nr   \z\\;z\;,z\,z
z\nreplace)r   rW   rW   rX   escape_char  s    z-VEvent.make_qr_code_data.<locals>.escape_charr   c                 S   s   | j d u p| j | d u S rv   )tzinfo	utcoffset)trW   rW   rX   is_naive_datetime  s    z3VEvent.make_qr_code_data.<locals>.is_naive_datetimec                    s,    | r|  dS | tj}| dS d S )Nz%Y%m%dT%H%M%S%Y%m%dT%H%M%SZ)strftime
astimezonepytzutc)r   Zt_utcr   rW   rX   get_datetime_str  s    
z2VEvent.make_qr_code_data.<locals>.get_datetime_strzGBEGIN:VCALENDAR
PRODID:Django QR Code
VERSION:2.0
BEGIN:VEVENT
DTSTAMP:r   z
UID:z	
DTSTART:z
DTEND:z	
SUMMARY:z
CLASS:r   zCATEGORIES:r   z
TRANSP:zDESCRIPTION:z
ORGANIZER:MAILTO:z
STATUS:z	LOCATION:z
GEO:r   r   r6   z
URL:z
END:VEVENT
END:VCALENDAR)r   r   )r{   rt   r   datetimeutcnowr   r   r   r   r   r   r   r   r   namer   r   mapr   r   r   r   r   r   r   )rU   r   r   r   	event_strrW   r   rX   make_qr_code_datah  sF    
	$ zVEvent.make_qr_code_data)rw   rx   ry   rz   rt   __annotations__r   r   r   r   r   r   r   r   r   r   floatr   r   r   r
   r   r   r   r   rW   rW   rW   rX   r   A  s    


r   c                   @   s   e Zd ZU dZeed< eed< eeee	j
f ed< dZee ed< dZee ed< dZee ed< dZee ed	< ed
ddZdS )EpcDataa   
    Data for representing an European Payments Council Quick Response Code (EPC QR Code) version 002.

    You must always use 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).

    Fields meaning:
        * name: Name of the recipient.
        * iban: International Bank Account Number (IBAN)
        * amount: The amount to transfer. The currency is always Euro, no other currencies are supported.
        * text: Remittance Information (unstructured)
        * reference: Remittance Information (structured)
        * bic: Bank Identifier Code (BIC). Optional, only required for non-EEA countries.
        * purpose: SEPA purpose code.
    r   ZibanamountNr   	referencebicpurposer   c                 C   s   t jf i t| ddiS )a  
        Validates the input and creates the data for an European Payments Council Quick Response Code
        (EPC QR Code) version 002.

        This is a wrapper for :py:func:`segno.helpers._make_epc_qr_data` with no choice for encoding.

        :rtype: str
        r    r6   )r   Z_make_epc_qr_datar   rZ   rW   rW   rX   r     s    	zEpcData.make_qr_code_data)rw   rx   ry   rz   rt   r   r   rG   r   rk   rl   r   r   r   r   r   r   rW   rW   rW   rX   r     s   
r   c                   @   s   e Zd ZdZedee ee ee ee ee ee ee ee ee ee ee ee ee dddZedddZ	ed	d
dZ
dS )ContactDetaila  
    Represents the detail of a contact for MeCARD encoding.

    .. note::
        This is a legacy class. Please use :py:class:`MeCard` instead for new projects.

    Fields meaning:
        * first_name
        * last_name
        * first_name_reading: the sound of the first name.
        * last_name_reading: the sound of the last name.
        * tel: the phone number, it can appear multiple times.
        * tel_av: the video-phone number, it can appear multiple times.
        * email: the email address, it can appear multiple times.
        * memo: notes.
        * birthday: the birth date (Python date).
        * address: the fields divided by commas (,) denote PO box, room number, house number, city, prefecture, zip code and country, in order.
        * url: homepage URL.
        * nickname: display name.
        * org: organization or company name (non-standard,but often recognized, ORG field).
    N
first_name	last_namefirst_name_readinglast_name_readingteltel_avemailmemobirthdayaddressr   nicknameorgc                 C   sR   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	|| _
|| _|| _d S rv   r   )rU   r   r   r   r   r   r   r   r   r   r   r   r   r   rW   rW   rX   rY     s    zContactDetail.__init__r   c                 C   s|  d}dt | jt | jffdt | jt | jfffD ]Z}|d d r^|d d r^d|d  }n|d d px|d d pxd}|r4||d | 7 }q4| jr|dt | j 7 }| jr|d	t | j 7 }| jr|d
t | j 7 }| jr|dt | j 7 }| j	r|d| j	
d 7 }| jr"|d| j 7 }| jr<|dt | j 7 }| jrV|dt | j 7 }| jrp|dt | j 7 }|d7 }|S )a  
        Make a text for configuring a contact in a phone book. The MeCARD format is used, with an optional, non-standard (but often recognized) ORG field.

        See this archive of the format specifications: https://web.archive.org/web/20160304025131/https://www.nttdocomo.co.jp/english/service/developer/make/content/barcode/function/application/addressbook/index.html

        :return: the MeCARD contact description.
        zMECARD:zN:%s;z	SOUND:%s;r6   r   z%s,%srD   zTEL:%s;z
TEL-AV:%s;z	EMAIL:%s;zNOTE:%s;zBDAY:%s;z%Y%m%dzADR:%s;zURL:%s;zNICKNAME:%s;zORG:%s;r   )_escape_mecard_special_charsr   r   r   r   r   r   r   r   r   r   r   r   r   r   )rU   contact_textZname_components_pairr   rW   rW   rX   r   *  s:    zContactDetail.make_qr_code_data)
field_namec                 C   s   t t| |S rv   )r   getattr)rU   r   rW   rW   rX   escaped_valueW  s    zContactDetail.escaped_value)NNNNNNNNNNNNN)rw   rx   ry   rz   r   r   rt   r   rY   r   r   rW   rW   rW   rX   r     s@                -r   c                   @   s^  e Zd ZU dZeed< dZee ed< dZe	ee
e df ed< dZe	ee
e df ed< dZe	ee
e df ed< dZee ed< dZee ed	< dZe	eejdf ed
< dZe	ee
e df ed< dZee ed< dZee ed< dZee ed< dZee ed< dZee ed< dZe	eedf ed< dZee ed< dZee ed< edddZdS )MeCarda  Represents the detail of a contact for MeCARD encoding.

    Fields meaning:
        * name: Name. If it contains a comma, the first part is treated as lastname and the second part is treated as forename.
        * reading: Designates a text string to be set as the kana name in the phonebook
        * email: E-mail address. Multiple values are allowed.
        * phone: Phone number. Multiple values are allowed.
        * videophone: Phone number for video calls. Multiple values are allowed.
        * memo: A notice for the contact.
        * nickname: Nickname.
        * birthday: Birthday. If a string is provided, it should encode the date as YYYYMMDD value.
        * url: Homepage. Multiple values are allowed.
        * pobox: P.O. box (address information).
        * roomno: Room number (address information).
        * houseno: House number (address information).
        * city: City (address information).
        * prefecture: Prefecture (address information).
        * zipcode: Zip code (address information).
        * country: Country (address information).
        * org: organization or company name (ORG field, non-standard,but often recognized by readers).
    r   Nreadingr   phone
videophoner   r   r   r   poboxroomnohousenocity
prefecturezipcodecountryr   r   c                 C   s`   t | }| jdur*| jdkr*t| j|d< |d}tjf i |}|r\|dt| d7 }|S )zb        Creates a string encoding the contact information as MeCARD.

        :rtype: str
        NrD   r   r   zORG:r   )r   r   rt   popr   Zmake_mecard_datar   )rU   rm   r   r   rW   rW   rX   r     s    
zMeCard.make_qr_code_data)rw   rx   ry   rz   rt   r   r   r   r   r   r	   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rG   r   r   r   rW   rW   rW   rX   r   [  s&   
r   c                   @   s:  e Zd ZU dZeed< dZee ed< dZe	ee
e df ed< dZe	ee
e df ed< dZe	ee
e df ed< dZe	ee
e df ed< dZee ed	< dZee ed
< dZe	eejdf ed< dZe	ee
e df ed< dZee ed< dZee ed< dZee ed< dZee ed< dZe	eedf ed< dZee ed< dZee ed< dZee ed< dZee ed< dZee ed< dZ e	eejdf ed< dZ!e	ee
e df ed< dZ"e	ee
e df ed< dZ#e	ee
e df ed< dZ$e	ee
e df ed< dZ%e	ee
e df ed< dd Z&edd d!Z'dS )"VCardal  Represents the detail of a contact for vCard encoding.

    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.

    Fields meaning:
    name: The name. If it contains a semicolon, , the first part
            is treated as lastname and the second part is treated as forename.
    displayname: Common name.
    email: E-mail address. Multiple values are allowed.
    phone: Phone number. Multiple values are allowed.
    fax: Fax number. Multiple values are allowed.
    videophone: Phone number for video calls. Multiple values are allowed.
    memo: A notice for the contact.
    nickname: Nickname.
    birthday: Birthday. If a string is provided, it should encode the
                     date as ``YYYY-MM-DD`` value.
    url: Homepage. Multiple values are allowed.
    pobox: P.O. box (address information).
    street: Street address.
    city: City (address information).
    region: Region (address information).
    zipcode: Zip code (address information).
    country: Country (address information).
    org: Company / organization name.
    lat: Latitude.
    lng: Longitude.
    source: URL where to obtain the vCard.
    rev: Revision of the vCard / last modification date.
    title: Job Title. Multiple values are allowed.
    photo_uri: Photo URI. Multiple values are allowed.
    cellphone: Cell phone number. Multiple values are allowed.
    homephone: Home phone number. Multiple values are allowed.
    workphone: Work phone number. Multiple values are allowed.
    r   Ndisplaynamer   r   faxr   r   r   r   r   r   streetr   regionr   r   r   latlngsourcerevtitle	photo_uri	cellphone	homephone	workphonec                 C   s.   | j d u r*| jdddddd| _ d S )Nz ;  z; r   )r   r   r   rZ   rW   rW   rX   __post_init__  s    
zVCard.__post_init__r   c                 C   s&   t | }t| j|d< tjf i |S )z        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.

        :rtype: str
        r   )r   rt   r   r   Zmake_vcard_data)rU   rm   rW   rW   rX   r     s    	zVCard.make_qr_code_data)(rw   rx   ry   rz   rt   r   r   r   r   r   r	   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rG   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rW   rW   rW   rX   r     s:   
'r   c                   @   sp   e Zd ZdZeddedZejdfej	dfej
dffZdejdd	feeeed
dddZedddZd
S )
WifiConfiga      Represents a WIFI configuration.

    Fields meaning:
        * ssid: the name of the SSID
        * authentication: the authentication type for the SSID; can be AUTHENTICATION.wep or AUTHENTICATION.wpa, or AUTHENTICATION.nopass for no password. Or, omit for no password.
        * password: the password, ignored if "authentication" is 'nopass' (in which case it may be omitted).
        * hidden: tells whether the SSID is hidden or not; can be True or False.
    AUTHENTICATIONznopass WEP WPAr   nopassWEPWPArD   FN)ssidauthenticationpasswordhiddenr5   c                 C   s   || _ || _|| _|| _d S rv   )r   r   r  r  )rU   r   r   r  r  rW   rW   rX   rY     s    zWifiConfig.__init__r   c                 C   sz   d}| j r|dt| j  7 }| jr:|dtj| j d  7 }| jrR|dt| j 7 }| jrn|dt| j  7 }|d7 }|S )z
        Make a text for configuring a Wi-Fi connexion. The syntax is inspired by the MeCARD format used for contacts.

        :return: the WIFI configuration text that can be translated to a QR code.
        :rtype: str
        zWIFI:zS:%s;zT:%s;r6   zP:%s;zH:%s;r   )	r   r   r   r   AUTHENTICATION_CHOICESr  r  rt   rJ   )rU   wifi_configrW   rW   rX   r     s    zWifiConfig.make_qr_code_data)rw   rx   ry   rz   r   _maker   r   r   r   r   r  rt   rG   r{   rY   r   rW   rW   rW   rX   r     s
   
"r   c                   @   sl   e Zd ZU dZeed< eed< dZeee	ef  ed< e
dddZd	d
 Ze
dddZe
dddZdS )Coordinatesz    Represents a set of coordinates with an optional altitude.

    Fields meaning:
        * latitude: The latitude.
        * latitude: The longitude.
        * latitude: The optional altitude.
    latitude	longitudeNaltituder   c                 C   s6   | j r"d| j d| j d| j  S d| j d| j S )Nz
latitude: z, longitude: z, altitude: )r	  r  r  rZ   rW   rW   rX   __str__%  s    zCoordinates.__str__c                 C   s   |d dS )Nz.8f0)rstrip)rU   frW   rW   rX   float_to_str*  s    zCoordinates.float_to_strc                 C   s@   d|  | j d|  | j }| jr<| d|  | j S |S )Nzgeo:r   r  r  r  r	  rU   r   rW   rW   rX   make_geolocation_text-  s     z!Coordinates.make_geolocation_textc                 C   s@   d|  | j d|  | j }| jr<| d|  | j S |S )Nz https://maps.google.com/local?q=r   r  r  rW   rW   rX   make_google_maps_text3  s     z!Coordinates.make_google_maps_text)rw   rx   ry   rz   r   r   r	  r   r   rG   rt   r
  r  r  r  rW   rW   rW   rX   r    s   
	r  )phone_numberr5   c                 C   s   d|  S )Nztel:%srW   r  rW   rW   rX   make_tel_text:  s    r  c                 C   s   d|  S )Nzsms:%srW   r  rW   rW   rX   make_sms_text>  s    r  )video_idr5   c                 C   s   dt |  S )Nz!https://www.youtube.com/watch/?v=r   )r  rW   rW   rX   make_youtube_textB  s    r  )
package_idr5   c                 C   s   dt |  S )Nz.https://play.google.com/store/apps/details?id=r   )r  rW   rW   rX   make_google_play_textF  s    r  c                   @   s   e Zd ZU dZeeee f ed< dZeeee df ed< dZ	eeee df ed< dZ
ee ed< dZee ed< edd	d
ZdS )EmailaZ  Represents the data of an e-mail.

    Fields meaning:
        * to: The email address (recipient). Multiple values are allowed.
        * cc: The carbon copy recipient. Multiple values are allowed.
        * bcc: The blind carbon copy recipient. Multiple values are allowed.
        * subject: The subject.
        * body: The message body.
    toNccbccsubjectbodyr   c                 C   s   t jf i t| S )z        Creates either a simple "mailto:" URL or complete e-mail message with
        (blind) carbon copies and a subject and a body.

        :rtype: str
        )r   Zmake_make_email_datar   rZ   rW   rW   rX   r   \  s    zEmail.make_qr_code_data)rw   rx   ry   rz   r   rt   r	   r   r  r  r  r   r   r   rW   rW   rW   rX   r  J  s   

r  )string_to_escaper5   c                 C   s.   | s| S g d}|D ]}|  |d| } q| S )N)r   "r   r   :z\%sr   )r!  Zspecial_charsscrW   rW   rX   r   f  s    r   )4rz   r   rk   collectionsr   dataclassesr   r   enumr   typingr   r   r   r	   r
   r   r   django.utils.htmlr   pydanticr   pydantic.dataclassesr   Zpydantic_dataclassqr_code.qrcode.constantsr   r   r   r   segnor   r   r{   rI   r   r   r   r   r   r   r   r   r   r  rt   r  r  r  r  r  r   rW   rW   rW   rX   <module>   sT       /g:U)#