o
    Cji-                     @  s  d dl mZ d dlZd dlZd dlZd dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZ d dlmZ d dlmZmZmZmZmZ ddlmZmZmZmZmZ ddlmZ  dd	lm!Z! dd
lm"Z" e
dZ#e
dee$df dZ%e
de	e&e$f dZ'e
dee$ dZ(e
dedef dZ)dddZ*dddZ+dd'd(Z,dd+d,Z-dd.d/Z.dd2d3Z/dd5d6Z0dd9d:Z1dd<d=Z2dd@dAZ3ddCdDZ4ddFdGZ5ddKdLZ6ddMdNZ7ddOdPZ8ddQdRZ9ddSdTZ:ddUdVZ;ddXdYZ<dZd[d\ddadbZ=ddddeZ>ddhdiZ?e
djZ@e
dkZAeddmdnZBeddqdnZBeddrdnZBddtdnZBddvdwZCddydzZDdd{d|ZEdd~dZFdddZGdddZHdddZIdddZJdddZKdddZLdS )    )annotationsN)	AnyTupleMappingTypeVarCallableIterableSequencecastoverload)Path)Required	Annotated	TypeGuardget_args
get_origin   )HeadersNotGiven	FileTypes
NotGivenOrHeadersLike)is_union)
parse_date)parse_datetime_T_TupleT.)bound	_MappingT
_SequenceT	CallableTtIterable[Iterable[_T]]returnlist[_T]c                 C  s   dd | D S )Nc                 S  s   g | ]	}|D ]}|qqS  r%   ).0sublistitemr%   r%   k/var/www/html/Resume-Parser/resume-parser-inhouse/venv/lib/python3.10/site-packages/openai/_utils/_utils.py
<listcomp>"       zflatten.<locals>.<listcomp>r%   )r!   r%   r%   r)   flatten!   s   r,   queryMapping[str, object]pathsSequence[Sequence[str]]list[tuple[str, FileTypes]]c             	   C  s(   g }|D ]}| t| |ddd q|S )zRecursively extract files from the given dictionary based on specified paths.

    A path may look like this ['foo', 'files', '<array>', 'data'].

    Note: this mutates the given dictionary.
    r   Nindexflattened_key)extend_extract_items)r-   r/   filespathr%   r%   r)   extract_files%   s   r9   objobjectr8   Sequence[str]r3   intr4   
str | Nonec                  s  z }W n, t y2   t| trg  Y S ddlm} ||  d  d us(J  tt| fg Y S w d7 t| rpztkrH| 	|}n| | }W n t
yX   g  Y S w  d u r`| n d| d7  t| dS t| r|dkrzg S t fd	d
| D S g S )Nr   )assert_is_file_content)key   []r2   z<array>c                   s,   g | ]}t | d ur d nddqS )Nz[]r2   )r6   )r&   r(   r4   r3   r8   r%   r)   r*   j   s    z"_extract_items.<locals>.<listcomp>)
IndexError
isinstancer   _filesr?   r
   r   is_dictlenpopKeyErrorr6   is_listr,   )r:   r8   r3   r4   r@   r?   r(   r%   rD   r)   r6   8   sL   
r6   NotGivenOr[_T]TypeGuard[_T]c                 C  s   t | t S NrF   r   r:   r%   r%   r)   is_giveny      rR   TypeGuard[tuple[object, ...]]c                 C  
   t | tS rO   rF   tuplerQ   r%   r%   r)   is_tuple      
rX   _TupleT | objectTypeGuard[_TupleT]c                 C  rU   rO   rV   rQ   r%   r%   r)   
is_tuple_t   rY   r\   TypeGuard[Sequence[object]]c                 C  rU   rO   rF   r	   rQ   r%   r%   r)   is_sequence   rY   r_   _SequenceT | objectTypeGuard[_SequenceT]c                 C  rU   rO   r^   rQ   r%   r%   r)   is_sequence_t   rY   rb   TypeGuard[Mapping[str, object]]c                 C  rU   rO   rF   r   rQ   r%   r%   r)   
is_mapping   rY   re   _MappingT | objectTypeGuard[_MappingT]c                 C  rU   rO   rd   rQ   r%   r%   r)   is_mapping_t   rY   rh   TypeGuard[dict[object, object]]c                 C  rU   rO   )rF   dictrQ   r%   r%   r)   rH      rY   rH   TypeGuard[list[object]]c                 C  rU   rO   )rF   listrQ   r%   r%   r)   rL      rY   rL   typtypeboolc                 C     t | tkS rO   )r   r   rm   r%   r%   r)   is_annotated_type   rS   rr   c                 C  s   t | p| tkS rO   )r   rl   rq   r%   r%   r)   is_list_type   s   rs   c                 C  s   t t| S rO   )	_is_unionr   rq   r%   r%   r)   is_union_type   rS   ru   c                 C  rp   rO   )r   r   rq   r%   r%   r)   is_required_type   rS   rv   c                 C  s*   t | st| rtttt| d S | S )Nr   )rv   rr   strip_annotated_typer
   rn   r   rq   r%   r%   r)   rw      s   rw   c              	   C  s>   t | }ztt|| W S  ty   td|  d| dw )NzExpected type z" to have a type argument at index z but it did not)r   r
   rn   rE   RuntimeError)rm   r3   argsr%   r%   r)   extract_type_arg   s   rz   r(   c                 C  s@   t | rttdd |  D S t| rttdd | D S | S )zMinimal reimplementation of copy.deepcopy() that will only copy certain object types:

    - mappings, e.g. `dict`
    - list

    This is done for performance reasons.
    c                 S  s   i | ]	\}}|t |qS r%   deepcopy_minimal)r&   kvr%   r%   r)   
<dictcomp>   r+   z$deepcopy_minimal.<locals>.<dictcomp>c                 S     g | ]}t |qS r%   r{   )r&   entryr%   r%   r)   r*          z$deepcopy_minimal.<locals>.<listcomp>)re   r
   r   itemsrL   )r(   r%   r%   r)   r|      s
   r|   z, or)delimfinalseqr   strr   c                C  sn   t | }|dkr
dS |dkr| d S |dkr$| d  d| d| d  S || d d d| d| d   S )Nr    rA   r    )rI   join)r   r   r   sizer%   r%   r)   
human_join   s   &r   stringc                 C  s   d|  d S )zOAdd single quotation marks around the given string. Does *not* do any escaping.'r%   )r   r%   r%   r)   quote   s   r   variants Callable[[CallableT], CallableT]c                    s   d fdd}|S )aJ  Decorator to enforce a given set of arguments or variants of arguments are passed to the decorated function.

    Useful for enforcing runtime validation of overloaded functions.

    Example usage:
    ```py
    @overload
    def foo(*, a: str) -> str:
        ...

    @overload
    def foo(*, b: bool) -> str:
        ...

    # This enforces the same constraints that a static type checker would
    # i.e. that either a or b must be passed to the function
    @required_args(['a'], ['b'])
    def foo(*, a: str | None = None, b: bool | None = None) -> str:
        ...
    ```
    funcr    r#   c                   s>   t  j}dd | D t d	 fdd}|S )
Nc                 S  s&   g | ]\}}|j |j|jhv r|qS r%   )kindPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORD)r&   nameparamr%   r%   r)   r*     s    z0required_args.<locals>.inner.<locals>.<listcomp>ry   r;   kwargsr#   c            
        s6  t   t| D ]&\}}z	 |  W q ty-   tj dt dt|  dw | D ]} | q2D ]}t fdd|D }|rM nGq<tdkrgt	dd D }d	| d
}t|t
t d   }	t|	dkrdt	dd |	D  }t|dt|	d  }t|| i |S )Nz	() takes z argument(s) but z were givenc                 3  s    | ]}| v V  qd S rO   r%   )r&   r   given_paramsr%   r)   	<genexpr>  s    z@required_args.<locals>.inner.<locals>.wrapper.<locals>.<genexpr>rA   c                 S  s*   g | ]}d t dd |D dd d qS )(c                 S  r   r%   r   r&   argr%   r%   r)   r*      r   zLrequired_args.<locals>.inner.<locals>.wrapper.<locals>.<listcomp>.<listcomp>and)r   ))r   )r&   variantr%   r%   r)   r*      s   * zArequired_args.<locals>.inner.<locals>.wrapper.<locals>.<listcomp>z,Missing required arguments; Expected either z arguments to be givenr   zMissing required arguments: c                 S  r   r%   r   r   r%   r%   r)   r*   '  r   zMissing required argument: )set	enumerateaddrE   	TypeError__name__rI   keysallr   rl   r   )
ry   r   i_r@   r   matches
variationsmsgmissing)r   
positionalr   r   r)   wrapper  s6   $z-required_args.<locals>.inner.<locals>.wrapper)ry   r;   r   r;   r#   r;   )inspect	signature
parametersr   	functoolswraps)r   paramsr   r   )r   r   r)   inner  s   
zrequired_args.<locals>.innerN)r   r    r#   r    r%   )r   r   r%   r   r)   required_args   s   .r   _K_VNonec                 C     d S rO   r%   rQ   r%   r%   r)   strip_not_given6     r   Mapping[_K, _V | NotGiven]dict[_K, _V]c                 C  r   rO   r%   rQ   r%   r%   r)   r   ;  r   c                 C  r   rO   r%   rQ   r%   r%   r)   r   @  r   object | Nonec                 C  s*   | du rdS t | s| S dd |  D S )zHRemove all top-level keys where their values are instances of `NotGiven`Nc                 S  s    i | ]\}}t |ts||qS r%   rP   )r&   r@   valuer%   r%   r)   r   M  s     z#strip_not_given.<locals>.<dictcomp>)re   r   rQ   r%   r%   r)   r   E  s
   valc                 C  s   t | ddS )N
   )base)r=   r   r%   r%   r)   coerce_integerP  rS   r   floatc                 C  s   t | S rO   )r   r   r%   r%   r)   coerce_floatT  s   r   c                 C  s   | dkp| dkp| dkS )Ntrue1onr%   r   r%   r%   r)   coerce_booleanX  s   r   
int | Nonec                 C     | d u rd S t | S rO   )r   r   r%   r%   r)   maybe_coerce_integer\     r   float | Nonec                 C  r   rO   )r   r   r%   r%   r)   maybe_coerce_floatb  r   r   bool | Nonec                 C  r   rO   )r   r   r%   r%   r)   maybe_coerce_booleanh  r   r   prefixc                 C  s   |  |r| t|d S | S )zXRemove a prefix from a string.

    Backport of `str.removeprefix` for Python < 3.9
    N)
startswithrI   )r   r   r%   r%   r)   removeprefixn  s   
r   suffixc                 C  s    |  |r| dt|  S | S )zXRemove a suffix from a string.

    Backport of `str.removesuffix` for Python < 3.9
    N)endswithrI   )r   r   r%   r%   r)   removesuffixx  s   
r   r   c                 C  s    t |  }tj| }||fS rO   )r   
read_bytesosr8   basename)r8   contents	file_namer%   r%   r)   file_from_path  s   r   headersr   headerc                 C  s   |  }t| tr&tt| } |  D ]\}}|  |kr%t|tr%|  S q	 tddd |	 }|||
 |fD ]}| |}|rG|  S q:td| d)Nz([^\w])(\w)c                 S  s   |  d|  d  S )NrA   r   )groupupper)patr%   r%   r)   <lambda>  s    z%get_required_header.<locals>.<lambda>zCould not find z header)lowerrF   r   r
   r   r   r   resub
capitalizer   get
ValueError)r   r   lower_headerr}   r~   intercaps_headernormalized_headerr   r%   r%   r)   get_required_header  s   


r   )r!   r"   r#   r$   )r-   r.   r/   r0   r#   r1   )
r:   r;   r8   r<   r3   r=   r4   r>   r#   r1   )r:   rM   r#   rN   )r:   r;   r#   rT   )r:   rZ   r#   r[   )r:   r;   r#   r]   )r:   r`   r#   ra   )r:   r;   r#   rc   )r:   rf   r#   rg   )r:   r;   r#   ri   )r:   r;   r#   rk   )rm   rn   r#   ro   )rm   rn   r#   rn   )rm   rn   r3   r=   r#   rn   )r(   r   r#   r   )r   r<   r   r   r   r   r#   r   )r   r   r#   r   )r   r<   r#   r   )r:   r   r#   r   )r:   r   r#   r   )r:   r;   r#   r;   )r:   r   r#   r;   )r   r   r#   r=   )r   r   r#   r   )r   r   r#   ro   )r   r>   r#   r   )r   r>   r#   r   )r   r>   r#   r   )r   r   r   r   r#   r   )r   r   r   r   r#   r   )r8   r   r#   r   )r   r   r   r   r#   r   )M
__future__r   r   r   r   r   typingr   r   r   r   r   r   r	   r
   r   pathlibr   typing_extensionsr   r   r   r   r   _typesr   r   r   r   r   _compatr   rt   r   r   r   r;   r   r   r   r   r    r,   r9   r6   rR   rX   r\   r_   rb   re   rh   rH   rL   rr   rs   ru   rv   rw   rz   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r%   r%   r%   r)   <module>   st    ,



A
















H











