
    U thm?                       U d dl mZ d dl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mZ d dlmZmZmZmZmZ d dlZd dlZd dlZddlmZ ddlmZmZm Z m!Z! ddl"m#Z#m$Z$m%Z% dd	l&m'Z' dd
l(m)Z)m*Z*m+Z+m,Z, ddl-m.Z. erddl"m/Z/ ddl0m1Z1  ed          Z2 ed          Z3 ed          Z4 ej5        e6          Z7de8d<    G d dee3                   Z9 G d de:          Z;d!dZ<d"dZ= G d d           Z>dS )#    )annotationsN)
TYPE_CHECKINGAnyUnionGenericTypeVarCallableIteratorAsyncIteratorcastoverload)	Awaitable	ParamSpecoverride
deprecated
get_origin   )NoneType)is_givenextract_type_argis_annotated_typeis_type_alias_type)	BaseModelis_basemodeladd_request_id)RAW_RESPONSE_HEADER)StreamAsyncStreamis_stream_class_typeextract_stream_chunk_type)APIResponseValidationError)FinalRequestOptions)
BaseClientPR_Tzlogging.Loggerlogc                     e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   ded<   	 ddd<dZed=d            Zed>d"            Z	ed?d$            Z	d%d&d@d)Z	edAd+            Z
edBd-            ZedCd.            ZedDd0            ZedEd2            ZedFd4            ZedEd5            ZedEd6            ZedGd7            ZedHd9            Zd%d&d@d:ZedEd;            Zd%S )ILegacyAPIResponsea  This is a legacy class as it will be replaced by `APIResponse`
    and `AsyncAPIResponse` in the `_response.py` file in the next major
    release.

    For the sync client this will mostly be the same with the exception
    of `content` & `text` will be methods instead of properties. In the
    async client, all methods will be async.

    A migration script will be provided & the migration in general should
    be smooth.
    type[R]_cast_toBaseClient[Any, Any]_clientzdict[type[Any], Any]_parsed_by_typebool_stream1type[Stream[Any]] | type[AsyncStream[Any]] | None_stream_clsr"   _optionshttpx.Responsehttp_responseintretries_takenr   )r7   rawcast_toclientstream
stream_clsoptionsreturnNonec               v    || _         || _        i | _        || _        || _        || _        || _        || _        d S N)r+   r-   r.   r0   r2   r3   r5   r7   )selfr8   r9   r:   r;   r<   r=   r7   s           k/var/www/html/mycamper/aliexpress-site/backend/venv/lib/python3.11/site-packages/openai/_legacy_response.py__init__zLegacyAPIResponse.__init__F   sF      !% *    
str | Nonec                @    | j         j                            d          S )Nzx-request-id)r5   headersgetrB   s    rC   
request_idzLegacyAPIResponse.request_idZ   s    !)--n===rE   totype[_T]r&   c                   d S rA    )rB   rL   s     rC   parsezLegacyAPIResponse.parse^   s    ,/CrE   r%   c                    d S rA   rO   rJ   s    rC   rP   zLegacyAPIResponse.parsea   s    #rE   NrL   type[_T] | NoneR | _Tc               x   ||n| j         }| j                            |          }||S |                     |          }t	          | j        j                  r| j                            |          }t          |t                    rt          || j
                   || j        |<   t          t          |          S )a  Returns the rich python representation of this response's data.

        NOTE: For the async client: this will become a coroutine in the next major version.

        For lower-level control, see `.read()`, `.json()`, `.iter_bytes()`.

        You can customise the type that the response is parsed into through
        the `to` argument, e.g.

        ```py
        from openai import BaseModel


        class MyModel(BaseModel):
            foo: str


        obj = response.parse(to=MyModel)
        print(obj.foo)
        ```

        We support parsing:
          - `BaseModel`
          - `dict`
          - `list`
          - `Union`
          - `str`
          - `int`
          - `float`
          - `httpx.Response`
        NrR   )r+   r.   rI   _parser   r3   post_parser
isinstancer   r   rK   r   r%   )rB   rL   	cache_keycachedparseds        rC   rP   zLegacyAPIResponse.parsed   s    @ .BBdm	%)))44M##DM-.. 	7]..v66Ffi(( 	464?333*0Y'AvrE   httpx.Headersc                    | j         j        S rA   )r5   rH   rJ   s    rC   rH   zLegacyAPIResponse.headers       !))rE   httpx.Requestc                    | j         j        S rA   )r5   requestrJ   s    rC   http_requestzLegacyAPIResponse.http_request   r^   rE   c                    | j         j        S rA   )r5   status_coderJ   s    rC   rd   zLegacyAPIResponse.status_code   s    !--rE   	httpx.URLc                    | j         j        S rA   )r5   urlrJ   s    rC   rg   zLegacyAPIResponse.url   s    !%%rE   strc                    | j         j        S rA   )rb   methodrJ   s    rC   rj   zLegacyAPIResponse.method   s     ''rE   bytesc                    | j         j        S )zReturn the binary response content.

        NOTE: this will be removed in favour of `.read()` in the
        next major version.
        )r5   contentrJ   s    rC   rm   zLegacyAPIResponse.content   s     !))rE   c                    | j         j        S )zyReturn the decoded response content.

        NOTE: this will be turned into a method in the next major version.
        )r5   textrJ   s    rC   ro   zLegacyAPIResponse.text   s     !&&rE   c                    | j         j        S rA   )r5   http_versionrJ   s    rC   rq   zLegacyAPIResponse.http_version   s    !..rE   c                    | j         j        S rA   )r5   	is_closedrJ   s    rC   rs   zLegacyAPIResponse.is_closed   s    !++rE   datetime.timedeltac                    | j         j        S )zCThe time taken for the complete request/response cycle to complete.)r5   elapsedrJ   s    rC   rv   zLegacyAPIResponse.elapsed   s     !))rE   c               
   ||n| j         }t          |          r|j        }|rt          |          rt	          |d          }t          |          p|}| j        rF|r{t          |          st          dt           dt                     t          t           |t          |d          | j        t          t          | j                                      S | j        rZt          t$          |                     t          | j                  | j        t          t          | j                                      S t          d| j        j                  }|t)                      t          t$           ||| j        t          t          | j                                      S |t*          u rt          t$          d           S | j        }|t,          k    rt          t$          |j                  S |t0          k    r't          t$          t1          |j                            S |t2          k    r't          t$          t3          |j                            S |t4          k    r0t          t$          |j                                        dk              S t9          j        |          r3t=          |t>                    rt          t$           ||                    S |t@          k    rtC          d	          t9          j        |          rNt=          |tD          j#                  r4|tD          j#        k    rtI          d
          t          t$          |          S t9          j        |          r>t=          |tJ                    s)t=          |tL          j%                  rt          d          |tN          ur|tP          urw|tR          urn|tT          uret=          |tJ                    sPtC          d| dtJ           dtR           dtP           dtT           dt*           dt,           dtD          j#         d          |j+        ,                    dd          -                    d          ^}}|.                    d          st_          |          rr	 |0                                }| j        1                    |||          S # td          $ r3}	tf          4                    dtk          |	          |	           Y d }	~	nd }	~	ww xY w| j        j6        rto          |d| d|j                  |j        S |0                                }| j        1                    |||          S )Nr   z/Expected custom parse type to be a subclass of z or zUExpected custom stream type to be passed with a type argument, e.g. Stream[ChunkType])failure_message)r9   responser:   r1   truez+Unexpected state - cast_to is `APIResponse`z:Subclasses of httpx.Response cannot be passed to `cast_to`zVPydantic models must subclass our base model type, e.g. `from openai import BaseModel`zUnsupported type, expected z to be a subclass of z, .zcontent-type*;json)datar9   ry   z5Could not read JSON from response data due to %s - %szMExpected Content-Type response header to be `application/json` but received `z
` instead.)ry   messagebody)8r+   r   	__value__r   r   r   r0   r   	TypeErrorr   r   r   r&   r    r5   r   r-   r2   r%   _default_stream_clsMissingStreamClassErrorr   rh   ro   r6   floatr/   lowerinspectisclass
issubclassHttpxBinaryResponseContentr)   RuntimeErrorhttpxResponse
ValueErrorr   pydanticobjectlistdictr   rH   rI   splitendswithr   r~   _process_response_data	Exceptionr'   debugtype_strict_response_validationr!   )
rB   rL   r9   originr<   ry   content_type_r   excs
             rC   rV   zLegacyAPIResponse._parse   s   ""DM g&& 	('G  	3(11 	3&w22GG$$/< &	 +B// q#$oV\$o$obm$o$opppB 9 -D! ! ! "&!3#C66  
 
 
  $$ 9$:J K K!%!3#C66 %     QSWS_SsttJ!-///
#!/T\22     h4== %c>>8=)))c>>3x}--...e5//000d??8=..00F:;;;?6"" 	.z&:T'U'U 	.778,,---&&&LMMM?
 
 
	%00
	% %.(( !^___8$$$ O 	v vy11		v
 68#566	v tuuu 6!!dNNdNNeOOvy11 $  Yg  Y  YI  Y  YY]  Y  Yae  Y  Yin  Y  Yrz  Y  Y  B  Y  Y  HM  HV  Y  Y  Y   $+//DDJJ3OOq$$V,, 	!G$$ 
	#==??D  <>>! '!) ?    ! g g gIIUW[\_W`W`beffffffffg |7 0% Elx  E  E  E!    = }}|22 3 
 
 	
s   >R/ /
S,9)S''S,c                B    d| j          d| j        j         d| j         dS )Nz<APIResponse [ z] type=>)rd   r5   reason_phraser+   rJ   s    rC   __repr__zLegacyAPIResponse.__repr__T  s0    l 0ll43E3Sll\`\illllrE   )r8   r4   r9   r*   r:   r,   r;   r/   r<   r1   r=   r"   r7   r6   r>   r?   r>   rF   )rL   rM   r>   r&   )r>   r%   )rL   rS   r>   rT   )r>   r\   )r>   r_   )r>   r6   )r>   re   r>   rh   r>   rk   )r>   r/   )r>   rt   )__name__
__module____qualname____doc____annotations__rD   propertyrK   r   rP   rH   rb   rd   rg   rj   rm   ro   rq   rs   rv   rV   r   r   rO   rE   rC   r)   r)   -   s        
 
 !!!!))))MMMBBBB!!!!!!!!M + + + + + +( > > > X> /// X/ X-1 - - - - - -^ * * * X* * * * X* . . . X. & & & X& ( ( ( X( * * * X* ' ' ' X' / / / X/ , , , X, * * * X* /3 M
 M
 M
 M
 M
 M
^ m m m Xm m mrE   r)   c                        e Zd Zd fdZ xZS )r   r>   r?   c                J    t                                          d           d S )NzzThe `stream` argument was set to `True` but the `stream_cls` argument was not given. See `openai._streaming` for reference)superrD   )rB   	__class__s    rC   rD   z MissingStreamClassError.__init__Z  s/     I	
 	
 	
 	
 	
rE   r>   r?   )r   r   r   rD   __classcell__)r   s   @rC   r   r   Y  s=        
 
 
 
 
 
 
 
 
 
rE   r   funcCallable[P, R]r>   !Callable[P, LegacyAPIResponse[R]]c                H     t          j                   d fd            }|S )	Higher order function that takes one of our bound API methods and wraps it
    to support returning the raw `APIResponse` object directly.
    argsP.argskwargsP.kwargsr>   LegacyAPIResponse[R]c                     i t          t          |                    d                    pi }d|t          <   ||d<   t          t          t
                    | i |          S Nextra_headersrz   r   r   rI   r   r)   r%   r   r   r   r   s      rC   wrappedz(to_raw_response_wrapper.<locals>.wrappede  sc    (ZDfjj6Q6Q,R,R,XVX(Z-3)*"/%a($$*?*?*?@@@rE   r   r   r   r   r>   r   	functoolswrapsr   r   s   ` rC   to_raw_response_wrapperr   `  sE    
 _TA A A A A A NrE   Callable[P, Awaitable[R]],Callable[P, Awaitable[LegacyAPIResponse[R]]]c                H     t          j                   d fd            }|S )	r   r   r   r   r   r>   r   c                    K   i t          t          |                    d                    pi }d|t          <   ||d<   t          t          t
                    | i | d {V           S r   r   r   s      rC   r   z.async_to_raw_response_wrapper.<locals>.wrappedv  sy      (ZDfjj6Q6Q,R,R,XVX(Z-3)*"/%a(d0Ef0E0E*E*E*E*E*E*EFFFrE   r   r   r   s   ` rC   async_to_raw_response_wrapperr   q  sE    
 _TG G G G G G NrE   c                  ^   e Zd ZU ded<   d*dZed+d            Zed,d	            Zed-d            Zed-d            Z	d.dZ
d+dZd/d0dZd/d1dZd2dZd/d0dZd3dZ ed          ddd4d            Zd5d Zd+d!Zd/d6d#Zd/d7d%Zd8d&Zd/d6d'Z ed          ddd4d(            Zd5d)ZdS )9r   r4   ry   r>   r?   c                    || _         d S rA   )ry   )rB   ry   s     rC   rD   z#HttpxBinaryResponseContent.__init__  s     rE   rk   c                    | j         j        S rA   )ry   rm   rJ   s    rC   rm   z"HttpxBinaryResponseContent.content  s    }$$rE   rh   c                    | j         j        S rA   )ry   ro   rJ   s    rC   ro   zHttpxBinaryResponseContent.text  s    }!!rE   rF   c                    | j         j        S rA   )ry   encodingrJ   s    rC   r   z#HttpxBinaryResponseContent.encoding  s    }%%rE   c                    | j         j        S rA   )ry   charset_encodingrJ   s    rC   r   z+HttpxBinaryResponseContent.charset_encoding  s    }--rE   r   r   c                &     | j         j        di |S )NrO   )ry   r~   )rB   r   s     rC   r~   zHttpxBinaryResponseContent.json  s    !t}!++F+++rE   c                4    | j                                         S rA   )ry   readrJ   s    rC   r   zHttpxBinaryResponseContent.read  s    }!!###rE   N
chunk_size
int | NoneIterator[bytes]c                6    | j                             |          S rA   )ry   
iter_bytesrB   r   s     rC   r   z%HttpxBinaryResponseContent.iter_bytes  s    }''
333rE   Iterator[str]c                6    | j                             |          S rA   )ry   	iter_textr   s     rC   r   z$HttpxBinaryResponseContent.iter_text  s    }&&z222rE   c                4    | j                                         S rA   )ry   
iter_linesrJ   s    rC   r   z%HttpxBinaryResponseContent.iter_lines  s    }'')))rE   c                6    | j                             |          S rA   )ry   iter_rawr   s     rC   r   z#HttpxBinaryResponseContent.iter_raw  s    }%%j111rE   filestr | os.PathLike[str]c                    t          |d          5 }| j                                        D ]}|                    |           	 ddd           dS # 1 swxY w Y   dS )av  Write the output to the given file.

        Accepts a filename or any path-like object, e.g. pathlib.Path

        Note: if you want to stream the data to the file instead of writing
        all at once then you should use `.with_streaming_response` when making
        the API request, e.g. `client.with_streaming_response.foo().stream_to_file('my_filename.txt')`
        wbmodeNopenry   r   write)rB   r   fr   s       rC   write_to_filez(HttpxBinaryResponseContent.write_to_file  s     $T""" 	a0022  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   2AAAzDue to a bug, this method doesn't actually stream the response content, `.with_streaming_response.method()` should be used instead)r   c                   t          |d          5 }| j                            |          D ]}|                    |           	 d d d            d S # 1 swxY w Y   d S Nr   r   r   )rB   r   r   r   r   s        rC   stream_to_filez)HttpxBinaryResponseContent.stream_to_file  s     $T""" 	a00<<  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   3AAAc                4    | j                                         S rA   )ry   closerJ   s    rC   r   z HttpxBinaryResponseContent.close  s    }""$$$rE   c                D   K   | j                                          d {V S rA   )ry   areadrJ   s    rC   r   z HttpxBinaryResponseContent.aread  s,      ]((*********rE   AsyncIterator[bytes]c                :   K   | j                             |          S rA   )ry   aiter_bytesr   s     rC   r   z&HttpxBinaryResponseContent.aiter_bytes  s      }((444rE   AsyncIterator[str]c                :   K   | j                             |          S rA   )ry   
aiter_textr   s     rC   r   z%HttpxBinaryResponseContent.aiter_text  s      }''
333rE   c                8   K   | j                                         S rA   )ry   aiter_linesrJ   s    rC   r   z&HttpxBinaryResponseContent.aiter_lines  s      }((***rE   c                :   K   | j                             |          S rA   )ry   	aiter_rawr   s     rC   r  z$HttpxBinaryResponseContent.aiter_raw  s      }&&z222rE   c               >  K   t          j        |          }|                    d           d {V 4 d {V }| j                            |          2 3 d {V }|                    |           d {V  #6 	 d d d           d {V  d S # 1 d {V swxY w Y   d S r   )anyioPathr   ry   r   r   )rB   r   r   pathr   r   s         rC   astream_to_filez*HttpxBinaryResponseContent.astream_to_file  s^      z$-------- 	$ 	$ 	$ 	$ 	$ 	$ 	$"m77
CC $ $ $ $ $ $ $dggdmm######## DC	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   BA7B
BBc                D   K   | j                                          d {V S rA   )ry   acloserJ   s    rC   r  z!HttpxBinaryResponseContent.aclose  s,      ]))+++++++++rE   )ry   r4   r>   r?   r   r   r   )r   r   r>   r   rA   )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   rD   r   rm   ro   r   r   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  rO   rE   rC   r   r     st        ! ! ! ! % % % X% " " " X" & & & X& . . . X., , , ,$ $ $ $4 4 4 4 43 3 3 3 3* * * *2 2 2 2 2     Z 	M  "&	     % % % %+ + + +5 5 5 5 54 4 4 4 4+ + + +3 3 3 3 3 Z 	M  "&		$ 	$ 	$ 	$ 	$ 	$, , , , , ,rE   r   )r   r   r>   r   )r   r   r>   r   )?
__future__r   osr   loggingdatetimer   typingr   r   r   r   r   r	   r
   r   r   r   typing_extensionsr   r   r   r   r   r  r   r   _typesr   _utilsr   r   r   r   _modelsr   r   r   
_constantsr   
_streamingr   r   r   r    _exceptionsr!   r"   _base_clientr#   r$   r%   r&   	getLoggerr   r'   r   r)   r   r   r   r   r   rO   rE   rC   <module>r     s   " " " " " " " 				                               U T T T T T T T T T T T T T          U U U U U U U U U U U U < < < < < < < < < < + + + + + + \ \ \ \ \ \ \ \ \ \ \ \ 3 3 3 3 3 3 ),,,,,,(((((( IcNNGCLLWT]]'g'11 1 1 1 1im im im im im
 im im imX	
 
 
 
 
i 
 
 
   "   "f, f, f, f, f, f, f, f, f, f,rE   