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 )UIDGeneratorzUse 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 )zGenerates 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 )zWe 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