o
    #il                     @  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m
Z
mZ ddlmZ dZd	Zee d
Zee de ZedddZedZedZd(ddZd)ddZd*dd Zd+d"d#Zd,d&d'ZdS )-z
This file contains code from https://github.com/pydantic/pydantic/blob/main/pydantic/v1/datetime_parse.py
without the Pydantic v1 specific errors.
    )annotationsN)DictUnionOptional)datedatetimetimezone	timedelta   )StrBytesIntFloatz3(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})z(?P<hour>\d{1,2}):(?P<minute>\d{1,2})(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?(?P<tzinfo>Z|[+-]\d{2}(?::?\d{2})?)?$$z[T ]i     g    _Bg0)VC0Dvaluer   native_expected_typestrreturnUnion[None, int, float]c                 C  sP   t | ttfr	| S zt| W S  ty   Y d S  ty'   td| dd w )Nzinvalid type; expected z, string, bytes, int or float)
isinstanceintfloat
ValueError	TypeError)r   r    r   ]/var/www/html/flask_server/venv/lib/python3.10/site-packages/openai/_utils/_datetime_parse.py_get_numeric!   s   
r   secondsUnion[int, float]r   c                 C  sZ   | t krtjS | t  k rtjS t| tkr| d } t| tkstt| d }|jt	j
dS )Ni  )r   )tzinfo)
MAX_NUMBERr   maxminabsMS_WATERSHEDEPOCHr	   replacer   utc)r   dtr   r   r   _from_unix_seconds,   s   
r'   Optional[str]Union[None, int, timezone]c                 C  sr   | dkrt jS | d ur7t| dkrt| dd  nd}dt| dd  | }| d dkr0| }t t|dS d S )	NZ   r   <   r   -)minutes)r   r%   lenr   r	   )r   offset_minsoffsetr   r   r   _parse_timezone8   s    r3   !Union[datetime, StrBytesIntFloat]c                 C  s   t | tr| S t| d}|durt|S t | tr|  } t | ttfr&J t	| }|du r3t
d| }|d rE|d dd|d< t|d}dd	 | D }||d< td
i |S )a[  
    Parse a datetime/int/float/string and return a datetime.datetime.

    This function supports time zone offsets. When the input contains one,
    the output uses a timezone with a fixed offset from UTC.

    Raise ValueError if the input is well formatted but not a valid datetime.
    Raise ValueError if the input isn't well formatted.
    r   Nzinvalid datetime formatmicrosecond   0r   c                 S  s"   i | ]\}}|d ur|t |qS )Nr   .0kvr   r   r   
<dictcomp>d   s   " z"parse_datetime.<locals>.<dictcomp>r   )r   r   r   r'   bytesdecoder   r   datetime_rematchr   	groupdictljustr3   popitems)r   numberrA   kwr   kw_r   r   r   parse_datetimeE   s$   




rI   Union[date, StrBytesIntFloat]r   c                 C  s   t | trt | tr|  S | S t| d}|durt| S t | tr(|  } t | ttfr1J t	
| }|du r>tddd |  D }ztdi |W S  ty]   tddw )z
    Parse a date/int/float/string and return a datetime.date.

    Raise ValueError if the input is well formatted but not a valid date.
    Raise ValueError if the input isn't well formatted.
    r   Nzinvalid date formatc                 S  s   i | ]	\}}|t |qS r   r8   r9   r   r   r   r=      s    zparse_date.<locals>.<dictcomp>r   )r   r   r   r   r'   r>   r?   r   r   date_rerA   r   rB   rE   )r   rF   rA   rG   r   r   r   
parse_datej   s&   





rL   )r   r   r   r   r   r   )r   r   r   r   )r   r(   r   r)   )r   r4   r   r   )r   rJ   r   r   )__doc__
__future__r   retypingr   r   r   r   r   r   r	   _typesr   	date_expr	time_exprcompilerK   r@   r#   r   r"   r   r   r'   r3   rI   rL   r   r   r   r   <module>   s&    



%