
    Hbb                         d dl Z d dlZd dlZd dlmZ de j         fdZde j         defdZdede j         fdZd	edee j	                 fd
Z
ddededefdZdS )    N)Optionalreturnc                  `    t           j                             t           j        j                  S )z
    Return the current local date and time.
    :return: Returns an aware datetime object of the current date
        and time.
    tz)datetimenowtimezoneutc     ,/usr/lib/python3/dist-packages/ceph/utils.pydatetime_nowr      s$       H$5$9 :::r   dtc                 r    |                      t          j        j                                      d          S )z
    Convert a datetime object into a ISO 8601 string, e.g.
    '2019-04-24T17:06:53.039991Z'.
    :param dt: The datetime object to process.
    :return: Return a string representing the date in
        ISO 8601 (timezone=UTC).
    r   z%Y-%m-%dT%H:%M:%S.%fZ)
astimezoner   r
   r   strftime)r   s    r   datetime_to_strr      s3     ==H-1=22;;! ! !r   stringc                    ddg}t          j        d          }|                    d|           } | r| d         dk    r| dd         dz   } |D ]b}	 t          j                            | |          }|j        %|                    t          j        j        	          }|c S # t          $ r Y _w xY wt          d

                    | t          |                              )a  
    Convert an ISO 8601 string into a datetime object.
    The following formats are supported:

    - 2020-03-03T09:21:43.636153304Z
    - 2020-03-03T15:52:30.136257504-0600
    - 2020-03-03T15:52:30.136257504

    :param string: The string to parse.
    :return: Returns an aware datetime object of the given date
        and time string.
    :raises: :exc:`~exceptions.ValueError` for an unknown
        datetime string.
    z%Y-%m-%dT%H:%M:%S.%fz%Y-%m-%dT%H:%M:%S.%f%zz(\.[\d]{6})[\d]*z\1ZNz-0000)tzinfoz1Time data {} does not match one of the formats {})recompilesubr   strptimer   replacer
   r   
ValueErrorformatstr)r   fmtspfmtr   s        r   str_to_datetimer%      s
     	 D 	
&''AUU5&!!F  '&*##w& 	 		"++FC88B y ZZx'8'<Z==III 	 	 	D	 HOOD		    s   AB
B,+B,deltac                     t          j        d| t           j                  }|sdS |                                }d |                                D             }t          j        di |S )aU  
    Returns a timedelta object represents a duration, the difference
    between two dates or times.

    >>> parse_timedelta('foo')

    >>> parse_timedelta('2d') == datetime.timedelta(days=2)
    True

    >>> parse_timedelta("4w") == datetime.timedelta(days=28)
    True

    >>> parse_timedelta("5s") == datetime.timedelta(seconds=5)
    True

    >>> parse_timedelta("-5s") == datetime.timedelta(days=-1, seconds=86395)
    True

    :param delta: The string to process, e.g. '2h', '10d', '30s'.
    :return: The `datetime.timedelta` object or `None` in case of
        a parsing error.
    z](?P<seconds>-?\d+)s|(?P<minutes>-?\d+)m|(?P<hours>-?\d+)h|(?P<days>-?\d+)d|(?P<weeks>-?\d+)w$Nc                 8    i | ]\  }}||t          |          S r   )int).0nameparams      r   
<dictcomp>z#parse_timedelta.<locals>.<dictcomp>k   s)    GGGuGD#e**GGGr   r   )r   match
IGNORECASE	groupdictitemsr   	timedelta)r&   partsargss      r   parse_timedeltar5   J   st    . H +
 ]$ $E  tOOEGGGGGD%%%%%r   Tsstrictc                 |    	 t          | d           n# t          $ r Y dS w xY w|r| d         t          j        vrdS dS )z2Simple check that a string contains only hex chars   Fr   T)r)   r   r   	hexdigits)r6   r7   s     r   is_hexr;   o   s^    Ar



   uu  Q4v'''54s    
!!)T)r   r   r   typingr   r   r!   r   r%   r2   r5   boolr;   r   r   r   <module>r>      s     				       ;h' ; ; ; ;	!) 	!c 	! 	! 	! 	!*C *H$5 * * * *Z"&3 "&8H,>#? "& "& "& "&J c 4 4      r   