U
    ¤�©jó  ã                   @  sÞ   d Z ddlmZ ddlZddlmZmZmZ ddlmZm	Z	 ddl
mZ ddlmZ dd	lmZ G d
d„ dƒZdddœdd„Zdddœdd„Zdddœdd„Zddœdd„Zddœdd„Zddœdd„ZdddddddgZdS )z Utility functions for icalendar.é    )ÚannotationsN)ÚdateÚdatetimeÚtzinfo)Úascii_lettersÚdigits)Úwarn)Ú
to_unicodeé   )ÚWillBeRemovedInVersion7c                   @  s>   e Zd ZdZeee ƒZedddœdd„ƒZ	edd	d
„ƒZ
dS )ÚUIDGeneratorz¡Use this only if you're too lazy to create real UUIDs.
    
    .. deprecated:: 6.2.1

        Use the Python standard library's :func:`uuid.uuid4` instead.
    é   Ústr)Úreturnc                 C  s&   t dtdd� d dd„ t| ƒD ƒ¡S )z©Generates a string with random characters of length.

         .. deprecated:: 6.2.1

             Use the Python standard library's :func:`uuid.uuid4` instead.
        zCUse https://docs.python.org/3/library/uuid.html#uuid.uuid4 instead.r
   ©Ú
stacklevelÚ c                 S  s   g | ]}t  tj¡‘qS © )ÚrandomÚchoicer   Úchars)Ú.0Ú_r   r   ú3/tmp/pip-unpacked-wheel-g40nyxg1/icalendar/tools.pyÚ
<listcomp>&   s     z+UIDGenerator.rnd_string.<locals>.<listcomp>)r   r   ÚjoinÚrange)Úlengthr   r   r   Ú
rnd_string   s    ýzUIDGenerator.rnd_stringúexample.comr   c                 C  s^   ddl m}m} tdtdd� t| ƒ} |p0t ¡ }t|t 	¡ ƒ 
¡ ƒ}||› d|› d| › �ƒS )a@  Generates a unique ID consisting of ``datetime-uniquevalue@host``.

        For example:
            
            .. code-block:: text

                20050105T225746Z-HKtJMqUgdO0jDUwm@example.com
        
        .. deprecated:: 6.2.1

            Use the Python standard library's :func:`uuid.uuid5` instead.
        r   )Ú	vDatetimeÚvTextzCUse https://docs.python.org/3/library/uuid.html#uuid.uuid5 instead.r
   r   ú-ú@)Zicalendar.propr    r!   r   r   r	   r   r   r   ÚtodayZto_ical)Z	host_nameÚuniquer    r!   r$   r   r   r   Úuid(   s    ýzUIDGenerator.uidN)r   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úlistr   r   r   Ústaticmethodr   r&   r   r   r   r   r      s   r   r   Úbool)Údtr   c                 C  s   t | tƒot | tƒ S ©z*Whether this is a date and not a datetime.)Ú
isinstancer   r   ©r.   r   r   r   Úis_dateC   s    r2   c                 C  s
   t | tƒS r/   )r0   r   r1   r   r   r   Úis_datetimeH   s    r3   r   c                 C  s   t | ƒrt| j| j| jƒS | S )z)Make sure we have a datetime, not a date.)r2   r   ÚyearÚmonthÚdayr1   r   r   r   Úto_datetimeM   s    r7   r   ©Útzc                 C  s
   t | dƒS )z9Whether the timezone requires localize() and normalize().Zlocalize)Úhasattrr8   r   r   r   Úis_pytzT   s    r;   r1   c                 C  s   t | ƒot| jƒS )z5Whether the time requires localize() and normalize().)r3   r;   r   r1   r   r   r   Ú
is_pytz_dtY   s    r<   c                 C  s   t | ƒr| j | ¡S | S )zÀWe have to normalize the time after a calculation if we use pytz.

    pytz requires this function to be used in order to correctly calculate the
    timezone's offset after calculations.
    )r<   r   Ú	normalizer1   r   r   r   Únormalize_pytz^   s    r>   )r*   Ú
__future__r   r   r   r   r   Ústringr   r   Úwarningsr   Zicalendar.parser_toolsr	   Úerrorr   r   r2   r3   r7   r;   r<   r>   Ú__all__r   r   r   r   Ú<module>   s,   4ù