Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
wsgi.cpython-313.pyc283 linesDownload Raw Back to __pycache__
1�

2��j�T���SSKJr SSKrSSKrSSKJr SSKJr SSKJ	r	 SSKJ3r4 SSKJr
 SS	KJr \R (aSS5KJr SSKJr SSjrSSS
jjrSSjrS S!SjjrS"SjrS#S$SjjrS%Sjr"SS5rS&S'Sjjr"SS5r"SS5r"SS\R>5r g)(�)�annotationsN)�partial��update_wrapper�)�ClientDisconnected)�RequestEntityTooLarge)�utils)�host_is_trusted)�WSGIApplication)�WSGIEnvironmentc�$^�[U4SjT5$)z�Marks a function as responder.  Decorate a function with it and it6will automatically call the return value as WSGI application.7 8Example::9 10    @responder11    def application(environ, start_response):12        return Response('Hello World!')13c�>�T"U6"USS6$)N������)�a�fs ��SD:\code\apps\devtools\python\user_packages\Python313\site-packages\werkzeug/wsgi.py�<lambda>�responder.<locals>.<lambda>s���Q��U�A�b�c�F�^�r)rs`r�	responderrs����3�Q�7�7rc��US[X5S.nU(d\URSS5US'U(d@URSS5US'U(d$URSS5RS	5US14'[R"S0UD6$)a,Recreate the URL for a request from the parts in a WSGI15environment.16 17The URL is an IRI, not a URI, so it may contain Unicode characters.18Use :func:`~werkzeug.urls.iri_to_uri` to convert it to ASCII.19 20:param environ: The WSGI environment to get the URL parts from.21:param root_only: Only build the root path, don't include the22    remaining path or query string.23:param strip_querystring: Don't include the query string.24:param host_only: Only build the scheme and host.25:param trusted_hosts: A list of trusted host names to validate the26    host against.27�wsgi.url_scheme)�scheme�host�SCRIPT_NAME��	root_path�	PATH_INFO�path�QUERY_STRING�latin1�query_stringr)�get_host�get�encode�
_sansio_utils�get_current_url)�environ�	root_only�strip_querystring�	host_only�
trusted_hosts�partss      rr)r)s���,�+�,���0�
�E�28�$�[�[���;��k���#�K�K��R�8�E�&�M�$�(/���N�B�(G�(N�(N�x�(X��n�%��(�(�1�5�1�1rc��URS5nUcg[URSS55nX4$![[4a SnX4$f=f)N�SERVER_NAME�SERVER_PORT)r&�int�	TypeError�29ValueError)r*�name�ports   r�_get_serverr8Esa���;�;�}�%�D��|����w�{�{�=�$�?�@��30�:���	
�z�"�����:��	�s�5�A�Ac�j�[R"USURS5[U5U5$)aGet and validate a request's ``host:port`` based on the values in the31given WSGI environ.32 33The ``Host`` header sent by the client is preferred. Otherwise, the server's34configured address is used. If the server address is a Unix socket, it is35ignored. The port is omitted if it matches the standard HTTP or HTTPS ports.36 37The value is passed through :func:`host_is_trusted`. The host must be made38up of valid characters, but this does not check validity beyond that. If a39list of trusted domains is given, the domain must match one.40 41:param environ: The WSGI environ.42:param trusted_hosts: A list of trusted domains to match. These should43    already be IDNA encoded, but will be encoded if needed. The port is44    ignored for this check. If a name starts with a dot it will match as a45    suffix, accepting all subdomains. If empty or ``None``, all domains are46    allowed.47 48:return: Host, with port if necessary.49:raise .SecurityError: If the host is not trusted.50 51.. versionchanged:: 3.252    The characters of the host value are validated. The empty string is no53    longer allowed if no header value is available.54 55.. versionchanged:: 3.256    When using the server address, Unix sockets are ignored.57 58.. versionchanged:: 3.1.359    If ``SERVER_NAME`` is IPv6, it is wrapped in ``[]``.60r�	HTTP_HOST)r(r%r&r8)r*r.s  rr%r%Vs8��D�!�!��!�"����K� ��G���	�rc�h�[R"URS5URS5S9$)aPReturn the ``Content-Length`` header value as an int. If the header is not given61or the ``Transfer-Encoding`` header is ``chunked``, ``None`` is returned to indicate62a streaming request. If the value is not an integer, or negative, 0 is returned.63 64:param environ: The WSGI environ to get the content length from.65 66.. versionadded:: 0.967�CONTENT_LENGTH�HTTP_TRANSFER_ENCODING)�http_content_length�http_transfer_encoding)r(�get_content_lengthr&)r*s rr@r@�s1���+�+�#�K�K�(8�9�&�{�{�+C�D��rc	���[R"[R[US5n[	U5nUbUbXB:�a68[5eSU;a9Ub4[R"[R[[
X2SS95$U$UcU(a[R"5$U$[R"[R[[
X455$)aTReturn the WSGI input stream, wrapped so that it may be read safely without going69past the ``Content-Length`` header value or ``max_content_length``.70 71If ``Content-Length`` exceeds ``max_content_length``, a72:exc:`RequestEntityTooLarge`` ``413 Content Too Large`` error is raised.73 74If the WSGI server sets ``environ["wsgi.input_terminated"]``, it indicates that the75server handles terminating the stream, so it is safe to read directly. For example,76a server that knows how to handle chunked requests safely would set this.77 78If ``max_content_length`` is set, it can be enforced on streams if79``wsgi.input_terminated`` is set. Otherwise, an empty stream is returned unless the80user explicitly disables this safe fallback.81 82If the limit is reached before the underlying stream is exhausted (such as a file83that is too large, or an infinite stream), the remaining contents of the stream84cannot be read safely. Depending on how the server handles this, clients may show a85"connection reset" failure instead of seeing the 413 response.86 87:param environ: The WSGI environ containing the stream.88:param safe_fallback: Return an empty stream when ``Content-Length`` is not set.89    Disabling this allows infinite streams, which can be a denial-of-service risk.90:param max_content_length: The maximum length that content-length or streaming91    requests may not exceed.92 93.. versionchanged:: 2.3.294    ``max_content_length`` is only applied to streaming requests if the server sets95    ``wsgi.input_terminated``.96 97.. versionchanged:: 2.398    Check ``max_content_length`` and raise an error if it is exceeded.99 100.. versionadded:: 0.9101z102wsgi.inputzwsgi.input_terminatedT)�is_max)	�t�cast�IO�bytesr@r	�
LimitedStream�io�BytesIO)r*�
safe_fallback�max_content_length�stream�content_lengths     r�get_input_streamrN�s���N�V�V�A�D�D��K���!6�
7�F�'��0�N��!�&8�&D��.�'�)�)��'�)��)��6�6����U��]�6�d�S��
��
�103��,�r�z�z�|�8�&�8��6�6�!�$�$�u�+�}�V�D�E�Erc�b�URSS5RS5nURSS9$)z�Return ``PATH_INFO`` from  the WSGI environment.104 105:param environ: WSGI environment to get the path from.106 107.. versionchanged:: 3.0108    The ``charset`` and ``errors`` parameters were removed.109 110.. versionadded:: 0.9111r rr#�replace)�errors)r&r'�decode)r*r!s  r�
get_path_inforS�s0���+�+�k�2�.�5�5�h�?�D��;�;�i�;�(�(rc�P�\rSrSrSrS	S112SjjrSSjrSSjrS
SjrSr	g)�ClosingIterator��aThe WSGI specification requires that all middlewares and gateways113respect the `close` callback of the iterable returned by the application.114Because it is useful to add another close action to a returned iterable115and adding a custom iterable is a boring task this class can be used for116that::117 118    return ClosingIterator(app(environ, start_response), [cleanup_session,119                                                          cleanup_locals])120 121If there is just one close function it can be passed instead of the list.122 123A closing iterator is not needed if the application uses response objects124and finishes the processing if the response is started::125 126    try:127        return response(environ, start_response)128    finally:129        cleanup_session()130        cleanup_locals()131Nc�>�[U5n[R"[R/[4[[U55UlUc/nO[U5(aU/nO[U5n[USS5nU(aURSU5 X lg)N�closer)
�iterrCrD�CallablerFr�next�_next�callable�list�getattr�insert�132_callbacks)�self�iterable�	callbacks�iterator�iterable_closes     r�__init__�ClosingIterator.__init__�s����>���V�V�A�J�J�r�5�y�1�7�4��3J�K��133����I�
�i�
 �
 �"��I��Y��I� ��7�D�9������Q��/�#�rc��U$�Nr�rbs r�__iter__�ClosingIterator.__iter__134����rc�"�UR5$rj)r\rks r�__next__�ClosingIterator.__next__
s���z�z�|�rc�8�URH135nU"5 M grj)ra)rb�callbacks  rrX�ClosingIterator.closes�����H��J�(r)rar\rj)rc�t.Iterable[bytes]rdz@None | (t.Callable[[], None] | t.Iterable[t.Callable[[], None]])�return�None)rvrU�rvrF�rvrw)136�__name__�137__module__�__qualname__�__firstlineno__�__doc__rgrlrprX�__static_attributes__rrrrUrU�s?���2GK�	$�#�$�D�$�138139�$�&��rrUc�:�URS[5"X5$)agWraps a file.  This uses the WSGI server's file wrapper if available140or otherwise the generic :class:`FileWrapper`.141 142.. versionadded:: 0.5143 144If the file wrapper from the WSGI server is used it's important to not145iterate over it from inside the application but to pass it through146unchanged.  If you want to pass out a file wrapper inside a response147object you have to set :attr:`Response.direct_passthrough` to `True`.148 149More information about file wrappers are available in :pep:`333`.150 151:param file: a :class:`file`-like object with a :meth:`~file.read` method.152:param buffer_size: number of bytes for one iteration.153zwsgi.file_wrapper)r&�FileWrapper)r*�file�buffer_sizes   r�	wrap_filer�s ��$�;�;�*�K�8���rc�b�\rSrSrSrSS
SjjrSSjrSSjrSSjrSSjr	SSjr154SS	jrS155rg)r�i,a0This class can be used to convert a :class:`file`-like object into156an iterable.  It yields `buffer_size` blocks until the file is fully157read.158 159You should not use this class directly but rather use the160:func:`wrap_file` function that uses the WSGI server's file wrapper161support if it's available.162 163.. versionadded:: 0.5164 165If you're using this object together with a :class:`Response` you have166to use the `direct_passthrough` mode.167 168:param file: a :class:`file`-like object with a :meth:`~file.read` method.169:param buffer_size: number of bytes for one iteration.170c��XlX lgrj)r�r�)rbr�r�s   rrg�FileWrapper.__init__>s
���	�&�rc�p�[URS5(aURR5 gg�NrX)�hasattrr�rXrks rrX�FileWrapper.closeBs&���4�9�9�g�&�&��I�I�O�O��'rc��[URS5(aURR5$[URS5(agg)N�seekable�seekTF)r�r�r�rks rr��FileWrapper.seekableFs=���4�9�9�j�)�)��9�9�%�%�'�'��4�9�9�f�%�%��rc�n�[URS5(aURR"U6 gg)Nr�)r�r�r�)rb�argss  rr��FileWrapper.seekMs(���4�9�9�f�%�%��I�I�N�N�D�!�&rc�n�[URS5(aURR5$g)N�tell)r�r�r�rks rr��FileWrapper.tellQs'���4�9�9�f�%�%��9�9�>�>�#�#�rc��U$rjrrks rrl�FileWrapper.__iter__Vrnrc�r�URRUR5nU(aU$[5erj)r��readr��
StopIteration)rb�datas  rrp�FileWrapper.__next__Ys*���y�y�~�~�d�.�.�/����K��o�r)r�r�N�i )r��t.IO[bytes]r�r3rvrwry�rv�bool)r�zt.Anyrvrw)rv�171int | None)rvr�rx)
rzr{r|r}r~rgrXr�r�r�rlrprrrrr�r�,s*���"'���"��172�rr�c�p�\rSrSrSrSS
SjjrSSjrSSjrSSjrSSjr	SS	jr173SS174jrSrg)�
_RangeWrapperi`aKThis class can be used to convert an iterable object into175an iterable that will only yield a piece of the underlying content.176It yields blocks until the underlying stream range is fully read.177The yielded blocks will have a size that can't exceed the original178iterator defined block size, but that can be smaller.179 180If you're using this object together with a :class:`Response` you have181to use the `direct_passthrough` mode.182 183:param iterable: an iterable object with a :meth:`__next__` method.184:param start_byte: byte from which read will start.185:param byte_range: how many bytes to read.186Nc���[U5UlX0lX lSUlUb	X#-UlSUl[
US5=(a UR5UlSUlg)Nrr�F)	rYrc�187byte_range�188start_byte�end_byte�read_lengthr�r��end_reached)rbrcr�r�s    rrg�_RangeWrapper.__init__qs\���X���
�$��$����
��!�&�3�D�M������*�5�M�(�:K�:K�:M��
� ��rc��U$rjrrks rrl�_RangeWrapper.__iter__�rnrc��[UR5nU=R[U5-
slU$![a	 SUlef=f�NT)r[rcr��lenr�r��rb�chunks  r�_next_chunk�_RangeWrapper._next_chunk�sI��	�����'�E�����E�189�*���L���	�#�D���	�s	�47�A190c��SnUR(aSURRUR5 URR	5UlUR191nX4$UR192UR::a,UR
5nUR193UR::aM,UbXRUR194-195SnURnX4$rj)r�rcr�r�r�r�r��rbr��contextual_read_lengths   r�_first_iteration�_RangeWrapper._first_iteration�s������=�=��M�M���t���/�#�}�}�1�1�3�D��%)�%5�%5�"��,�,��"�"�d�o�o�5��(�(�*���"�"�d�o�o�5�� ��o�o��0@�0@�@�B�C��%)�_�_�"��,�,rc�B�UR(a196[5eSnURnURS:XaUR5upUcUR	5nUR197b3URUR198:�aSUlUSUR199U-200$U$)NrT)r�r�r�r�r�r�r�s   rr\�_RangeWrapper._next�s�������/�!���!%�!1�!1�����q� �,0�,A�,A�,C�)�E��=��$�$�&�E��=�=�$��)9�)9�T�]�]�)J�#�D���A�4�=�=�+A�A�B�B��rc�V�UR5nU(aU$SUl[5er�)r\r�r�r�s  rrp�_RangeWrapper.__next__�s%���201�202�����L�����o�rc�p�[URS5(aURR5 ggr�)r�rcrXrks rrX�_RangeWrapper.close�s(���4�=�=�'�*�*��M�M���!�+r)r�r�r�rcr�r�r�)rN)rczt.Iterable[bytes] | t.IO[bytes]r�r3r�r�)rvr�rx)rvztuple[bytes | None, int]ry)
rzr{r|r}r~rgrlr�r�r\rprXrrrrr�r�`sN���"�!%�	!�1�!��!��	!�$��-���"rr�c��\rSrSrSrSSSjjr\SSj5rSSjrSSSjjr	SSjr203SS	jrSS204jrSSjr
SSjrS
rg)rGi�a�Wrap a stream so that it doesn't read more than a given limit. This is used to205limit ``wsgi.input`` to the ``Content-Length`` header value or206:attr:`.Request.max_content_length`.207 208When attempting to read after the limit has been reached, :meth:`on_exhausted` is209called. When the limit is a maximum, this raises :exc:`.RequestEntityTooLarge`.210 211If reading from the stream returns zero bytes or raises an error,212:meth:`on_disconnect` is called, which raises :exc:`.ClientDisconnected`. When the213limit is a maximum and zero bytes were read, no error is raised, since it may be the214end of the stream.215 216If the limit is reached before the underlying stream is exhausted (such as a file217that is too large, or an infinite stream), the remaining contents of the stream218cannot be read safely. Depending on how the server handles this, clients may show a219"connection reset" failure instead of seeing the 413 response.220 221:param stream: The stream to read from. Must be a readable binary IO object.222:param limit: The limit in bytes to not read past. Should be either the223    ``Content-Length`` header value or ``request.max_content_length``.224:param is_max: Whether the given ``limit`` is ``request.max_content_length`` instead225    of the ``Content-Length`` header value. This changes how exhausted and226    disconnect events are handled.227 228.. versionchanged:: 2.3229    Handle ``max_content_length`` differently than ``Content-Length``.230 231.. versionchanged:: 2.3232    Implements ``io.RawIOBase`` rather than ``io.IOBase``.233c�6�XlSUlX lX0lg)Nr)�_stream�_pos�limit�
_limit_is_max)rbrLr�rBs    rrg�LimitedStream.__init__�s������	��234�#�rc�4�URUR:�$)z:Whether the current stream position has reached the limit.)r�r�rks r�is_exhausted�LimitedStream.is_exhausted�s���y�y�D�J�J�&�&rc�:�UR(a235[5eg)aRCalled when attempting to read after the limit has been reached.236 237The default behavior is to do nothing, unless the limit is a maximum, in which238case it raises :exc:`.RequestEntityTooLarge`.239 240.. versionchanged:: 2.3241    Raises ``RequestEntityTooLarge`` if the limit is a maximum.242 243.. versionchanged:: 2.3244    Any return value is ignored.245N)r�r	rks r�on_exhausted�LimitedStream.on_exhausted�s�����'�)�)�rNc�@�UR(aUb246[5eg)a�Called when an attempted read receives zero bytes before the limit was247reached. This indicates that the client disconnected before sending the full248request body.249 250The default behavior is to raise :exc:`.ClientDisconnected`, unless the limit is251a maximum and no error was raised.252 253.. versionchanged:: 2.3254    Added the ``error`` parameter. Do nothing if the limit is a maximum and no255    error was raised.256 257.. versionchanged:: 2.3258    Any return value is ignored.259N)r�r)rb�errors  r�
on_disconnect�LimitedStream.on_disconnect�s ���!�!�U�%6�$�&�&�&7rc�F�UR(dUR5$g)aExhaust the stream by reading until the limit is reached or the client260disconnects, returning the remaining data.261 262.. versionchanged:: 2.3263    Return the remaining data.264 265.. versionchanged:: 2.2.3266    Handle case where wrapped stream returns fewer bytes than requested.267r)r��readallrks r�exhaust�LimitedStream.exhausts��� � ��<�<�>�!�rc�&�[U5nURUR-268nUS::aUR5 g[	UR269S5(aUX#::aUR270R
U5nOg[U5nUR271R
U5nU(aXaSU&O4UR272R[X#55n[U5nXqSU&U(dUR5 gU=RU-
slU$![[4anURUS9 SnAgSnAff=f![[4anURUS9 SnAgSnAff=f![[4anURUS9 SnAgSnAff=f)Nr�readinto)r�)
r�r�r�r�r�r�r��OSErrorr5r��	bytearrayr��min)rb�b�size�	remaining�out_size�e�temp_br�s        rr��LimitedStream.readintosn���1�v���J�J����*�	���>�������4�<�<��,�,�� ��+/�<�<�+@�+@��+C�H�#�9�-���#�|�|�4�4�V�<�H�273�#)�i�x�L��
��|�|�(�(��T�)=�>��274�4�y�H��i�x�L����� ���	�	�X��	����A ��,���&�&�Q�&�/����� ��,���&�&�Q�&�/������Z�(�
��"�"��"�+���
�sH�D�D;�-$E'�D8�D3�3D8�;E$�E�E$�'F�7F�Fc��UR(aUR5 g[5nUR(d=URS5nU(dO$UR	U5 UR(dM=[U5$)Nri)r�r�r�r��extendrF)rb�outr�s   rr��LimitedStream.readallFsh�����������k���#�#��9�9�Y�'�D����J�J�t���#�#�#��S�z�rc��UR$)z;Return the current stream position.275 276.. versionadded:: 0.9277)r�rks rr��LimitedStream.tellYs��278�y�y�rc��gr�rrks r�readable�LimitedStream.readable`s��r)r�r�r�r�)F)rLr�r�r3rBr�rvrwr�ryrj)r�zException | Nonervrwrx)r�r�rvr�)rvr3)rzr{r|r}r~rg�propertyr�r�r�r�r�r�r�r�rrrrrGrG�sD���>$��'��'�
*�'�,
�.�`�&�rrG)rz t.Callable[..., WSGIApplication]rvr)FFFN)r*r
r+r�r,r�r-r�r.�t.Collection[str] | Nonerv�str)r*r
rvztuple[str, int | None] | Nonerj)r*r
r.r�rvr�)r*r
rvr�)TN)r*r
rJr�rKr�rvr�)r*r
rvr�r�)r*r
r�r�r�r3rvru)!�279__future__rrH�typingrC�	functoolsrr�280exceptionsrr	�sansior281r(�sansio.utilsr�
TYPE_CHECKING�_typeshed.wsgirr
rr)r8r%r@rNrSrUr�r�r��	RawIOBaserGrrr�<module>r�s_��"�	���$�*�-�*�)��?�?�.�.�2828��#��.2�#2�
�#2��#2��#2��	#2�283,�#2�	�
#2�L�
��"��$IM�'�
�'�-E�'��'�T�"�%)�AF�
�AF��AF�#�AF��	AF�H)�1�1�jEI��
��$/��>A����.1�1�hT"�T"�nj�B�L�L�jr
codekingpro/portable-devtools · Team Ai