Your IP : 3.144.28.90


Current Path : /opt/alt/python311/lib64/python3.11/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/__pycache__/socketserver.cpython-311.pyc

�

c��f�k��v�dZdZddlZddlZddlZddlZddlZddlmZddl	m
Z	gd�Zeed��re�
gd���eed	��re�
gd
���eed��rejZnejZGd�d
��ZGd�de��ZGd�de��Zeed��r
Gd�d��ZGd�de��ZGd�d��ZGd�d��Zeed��rGd�dee��ZGd�dee��ZGd�dee��ZGd �d!ee��Zeed	��r:Gd"�d#e��ZGd$�d%e��ZGd&�d'ee��ZGd(�d)ee��Z Gd*�d+��Z!Gd,�d-e!��Z"Gd.�d/e��Z#Gd0�d1e!��Z$dS)2aqGeneric socket server classes.

This module tries to capture the various aspects of defining a server:

For socket-based servers:

- address family:
        - AF_INET{,6}: IP (Internet Protocol) sockets (default)
        - AF_UNIX: Unix domain sockets
        - others, e.g. AF_DECNET are conceivable (see <socket.h>
- socket type:
        - SOCK_STREAM (reliable stream, e.g. TCP)
        - SOCK_DGRAM (datagrams, e.g. UDP)

For request-based servers (including socket-based):

- client address verification before further looking at the request
        (This is actually a hook for any processing that needs to look
         at the request before anything else, e.g. logging)
- how to handle multiple requests:
        - synchronous (one request is handled at a time)
        - forking (each request is handled by a new process)
        - threading (each request is handled by a new thread)

The classes in this module favor the server type that is simplest to
write: a synchronous TCP/IP server.  This is bad class design, but
saves some typing.  (There's also the issue that a deep class hierarchy
slows down method lookups.)

There are five classes in an inheritance diagram, four of which represent
synchronous servers of four types:

        +------------+
        | BaseServer |
        +------------+
              |
              v
        +-----------+        +------------------+
        | TCPServer |------->| UnixStreamServer |
        +-----------+        +------------------+
              |
              v
        +-----------+        +--------------------+
        | UDPServer |------->| UnixDatagramServer |
        +-----------+        +--------------------+

Note that UnixDatagramServer derives from UDPServer, not from
UnixStreamServer -- the only difference between an IP and a Unix
stream server is the address family, which is simply repeated in both
unix server classes.

Forking and threading versions of each type of server can be created
using the ForkingMixIn and ThreadingMixIn mix-in classes.  For
instance, a threading UDP server class is created as follows:

        class ThreadingUDPServer(ThreadingMixIn, UDPServer): pass

The Mix-in class must come first, since it overrides a method defined
in UDPServer! Setting the various member variables also changes
the behavior of the underlying server mechanism.

To implement a service, you must derive a class from
BaseRequestHandler and redefine its handle() method.  You can then run
various versions of the service by combining one of the server classes
with your request handler class.

The request handler class must be different for datagram or stream
services.  This can be hidden by using the request handler
subclasses StreamRequestHandler or DatagramRequestHandler.

Of course, you still have to use your head!

For instance, it makes no sense to use a forking server if the service
contains state in memory that can be modified by requests (since the
modifications in the child process would never reach the initial state
kept in the parent process and passed to each child).  In this case,
you can use a threading server, but you will probably have to use
locks to avoid two requests that come in nearly simultaneous to apply
conflicting changes to the server state.

On the other hand, if you are building e.g. an HTTP server, where all
data is stored externally (e.g. in the file system), a synchronous
class will essentially render the service "deaf" while one request is
being handled -- which may be for a very long time if a client is slow
to read all the data it has requested.  Here a threading or forking
server is appropriate.

In some cases, it may be appropriate to process part of a request
synchronously, but to finish processing in a forked child depending on
the request data.  This can be implemented by using a synchronous
server and doing an explicit fork in the request handler class
handle() method.

Another approach to handling multiple simultaneous requests in an
environment that supports neither threads nor fork (or where these are
too expensive or inappropriate for the service) is to maintain an
explicit table of partially finished requests and to use a selector to
decide which request to work on next (or whether to handle a new
incoming request).  This is particularly important for stream services
where each client can potentially be connected for a long time (if
threads or subprocesses cannot be used).

Future work:
- Standard classes for Sun RPC (which uses either UDP or TCP)
- Standard mix-in classes to implement various authentication
  and encryption schemes

XXX Open problems:
- What to do with out-of-band data?

BaseServer:
- split generic "request" functionality out into BaseServer class.
  Copyright (C) 2000  Luke Kenneth Casson Leighton <lkcl@samba.org>

  example: read entries from a SQL database (requires overriding
  get_request() to return a table entry from the database).
  entry is processed by a RequestHandlerClass.

z0.4�N)�BufferedIOBase)�	monotonic)	�
BaseServer�	TCPServer�	UDPServer�ThreadingUDPServer�ThreadingTCPServer�BaseRequestHandler�StreamRequestHandler�DatagramRequestHandler�ThreadingMixIn�fork)�ForkingUDPServer�ForkingTCPServer�ForkingMixIn�AF_UNIX)�UnixStreamServer�UnixDatagramServer�ThreadingUnixStreamServer�ThreadingUnixDatagramServer�PollSelectorc�~�eZdZdZdZd�Zd�Zdd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZdS)ra�Base class for server classes.

    Methods for the caller:

    - __init__(server_address, RequestHandlerClass)
    - serve_forever(poll_interval=0.5)
    - shutdown()
    - handle_request()  # if you do not use serve_forever()
    - fileno() -> int   # for selector

    Methods that may be overridden:

    - server_bind()
    - server_activate()
    - get_request() -> request, client_address
    - handle_timeout()
    - verify_request(request, client_address)
    - server_close()
    - process_request(request, client_address)
    - shutdown_request(request)
    - close_request(request)
    - service_actions()
    - handle_error()

    Methods for derived classes:

    - finish_request(request, client_address)

    Class variables that may be overridden by derived classes or
    instances:

    - timeout
    - address_family
    - socket_type
    - allow_reuse_address
    - allow_reuse_port

    Instance variables:

    - RequestHandlerClass
    - socket

    Nc�`�||_||_tj��|_d|_dS)�/Constructor.  May be extended, do not override.FN)�server_address�RequestHandlerClass�	threading�Event�_BaseServer__is_shut_down�_BaseServer__shutdown_request)�selfrrs   �3/opt/alt/python311/lib64/python3.11/socketserver.py�__init__zBaseServer.__init__�s0��,���#6�� �'�o�/�/���"'�����c��dS�zSCalled by constructor to activate the server.

        May be overridden.

        N��r!s r"�server_activatezBaseServer.server_activate��	��	
�r$��?c��|j���	t��5}|�|tj��|jsN|�|��}|jrn1|r|���|�	��|j�Nddd��n#1swxYwYd|_|j�
��dS#d|_|j�
��wxYw)z�Handle one request at a time until shutdown.

        Polls for shutdown every poll_interval seconds. Ignores
        self.timeout. If you need to do periodic tasks, do them in
        another thread.
        NF)r�clear�_ServerSelector�register�	selectors�
EVENT_READr �select�_handle_request_noblock�service_actions�set)r!�
poll_interval�selector�readys    r"�
serve_foreverzBaseServer.serve_forever�sE��	
��!�!�#�#�#�	&�
!�"�"�
+�h��!�!�$�	�(<�=�=�=��1�+�$�O�O�M�:�:�E��.����7��4�4�6�6�6��(�(�*�*�*��1�+�
+�
+�
+�
+�
+�
+�
+�
+�
+�
+�
+����
+�
+�
+�
+�',�D�#���#�#�%�%�%�%�%��',�D�#���#�#�%�%�%�%���s/�C�A6B+�C�+B/�/C�2B/�3C�"C:c�F�d|_|j���dS)z�Stops the serve_forever loop.

        Blocks until the loop has finished. This must be called while
        serve_forever() is running in another thread, or it will
        deadlock.
        TN)r r�waitr(s r"�shutdownzBaseServer.shutdown�s'��#'����� � �"�"�"�"�"r$c��dS)z�Called by the serve_forever() loop.

        May be overridden by a subclass / Mixin to implement any code that
        needs to be run during the loop.
        Nr'r(s r"r4zBaseServer.service_actions�r*r$c��|j���}|�|j}n|j�t||j��}|�t	��|z}t��5}|�|tj��	|�	|��}|r |�
��cddd��S|�7|t	��z
}|dkr |���cddd��S�q#1swxYwYdS)zOHandle one request, possibly blocking.

        Respects self.timeout.
        NTr)�socket�
gettimeout�timeout�min�timer.r/r0r1r2r3�handle_timeout)r!rA�deadliner7r8s     r"�handle_requestzBaseServer.handle_requestsb���+�(�(�*�*���?��l�G�G�
�\�
%��'�4�<�0�0�G����v�v��'�H��
�
�	9�(����d�I�$8�9�9�9�
9� ����0�0���9��7�7�9�9�
	9�	9�	9�	9�	9�	9�	9�	9��*�"*�T�V�V�"3��"�Q�;�;�#'�#6�#6�#8�#8�	9�	9�	9�	9�	9�	9�	9�	9�
9�	9�	9�	9�	9����	9�	9�	9�	9�	9�	9s�!AC4�:,C4�3C4�4C8�;C8c��	|���\}}n#t$rYdSwxYw|�||��rk	|�||��dS#t$r/|�||��|�|��YdS|�|���xYw|�|��dS)z�Handle one request, without blocking.

        I assume that selector.select() has returned that the socket is
        readable before this function was called, so there should be no risk of
        blocking in get_request().
        N)�get_request�OSError�verify_request�process_request�	Exception�handle_error�shutdown_request�r!�request�client_addresss   r"r3z"BaseServer._handle_request_noblock0s���	�&*�&6�&6�&8�&8�#�G�^�^���	�	�	��F�F�	�������w��7�7�
	+�
��$�$�W�n�=�=�=�=�=���
/�
/�
/��!�!�'�>�:�:�:��%�%�g�.�.�.�.�.�.�
��%�%�g�.�.�.������!�!�'�*�*�*�*�*s��
(�(�A�5B)�B)c��dS)zcCalled if no new request arrives within self.timeout.

        Overridden by ForkingMixIn.
        Nr'r(s r"rDzBaseServer.handle_timeoutGs	��
	
�r$c��dS)znVerify the request.  May be overridden.

        Return True if we should proceed with this request.

        Tr'rOs   r"rJzBaseServer.verify_requestNs	���tr$c�\�|�||��|�|��dS)zVCall finish_request.

        Overridden by ForkingMixIn and ThreadingMixIn.

        N)�finish_requestrNrOs   r"rKzBaseServer.process_requestVs4��	
���G�^�4�4�4����g�&�&�&�&�&r$c��dS�zDCalled to clean-up the server.

        May be overridden.

        Nr'r(s r"�server_closezBaseServer.server_close_r*r$c�4�|�|||��dS)z8Finish one request by instantiating RequestHandlerClass.N)rrOs   r"rUzBaseServer.finish_requestgs ��� � ��.�$�?�?�?�?�?r$c�0�|�|��dS�z3Called to shutdown and close an individual request.N��
close_request�r!rPs  r"rNzBaseServer.shutdown_requestk������7�#�#�#�#�#r$c��dS�z)Called to clean up an individual request.Nr'r^s  r"r]zBaseServer.close_requesto����r$c���tdtj���td|tj���ddl}|���tdtj���dS)ztHandle an error gracefully.  May be overridden.

        The default is to print a traceback and continue.

        z(----------------------------------------)�filez4Exception occurred during processing of request fromrN)�print�sys�stderr�	traceback�	print_exc)r!rPrQrhs    r"rMzBaseServer.handle_errorsss��	�f�3�:�&�&�&�&�
�D����	-�	-�	-�	-�����������
�f�3�:�&�&�&�&�&�&r$c��|S�Nr'r(s r"�	__enter__zBaseServer.__enter__�s���r$c�.�|���dSrk)rX)r!�argss  r"�__exit__zBaseServer.__exit__�s���������r$)r+)�__name__�
__module__�__qualname__�__doc__rAr#r)r9r<r4rFr3rDrJrKrXrUrNr]rMrlror'r$r"rr�s-������*�*�X�G�(�(�(�
�
�
�&�&�&�&�:#�#�#�
�
�
�&9�9�9�<+�+�+�.
�
�
����'�'�'�
�
�
�@�@�@�$�$�$�
�
�
�'�'�'��������r$rc�l�eZdZdZejZejZdZ	dZ
dZdd�Zd�Z
d�Zd�Zd	�Zd
�Zd�Zd�Zd
S)raJBase class for various socket-based server classes.

    Defaults to synchronous IP stream (i.e., TCP).

    Methods for the caller:

    - __init__(server_address, RequestHandlerClass, bind_and_activate=True)
    - serve_forever(poll_interval=0.5)
    - shutdown()
    - handle_request()  # if you don't use serve_forever()
    - fileno() -> int   # for selector

    Methods that may be overridden:

    - server_bind()
    - server_activate()
    - get_request() -> request, client_address
    - handle_timeout()
    - verify_request(request, client_address)
    - process_request(request, client_address)
    - shutdown_request(request)
    - close_request(request)
    - handle_error()

    Methods for derived classes:

    - finish_request(request, client_address)

    Class variables that may be overridden by derived classes or
    instances:

    - timeout
    - address_family
    - socket_type
    - request_queue_size (only for stream sockets)
    - allow_reuse_address
    - allow_reuse_port

    Instance variables:

    - server_address
    - RequestHandlerClass
    - socket

    �FTc��t�|||��tj|j|j��|_|rE	|���|���dS#|����xYwdS)rN)rr#r?�address_family�socket_type�server_bindr)rX)r!rr�bind_and_activates    r"r#zTCPServer.__init__�s������D�.�2E�F�F�F��m�D�$7�$(�$4�6�6����	�
�� � �"�"�"��$�$�&�&�&�&�&��
��!�!�#�#�#�����
	�	s�(A.�.Bc��|jrEttd��r0|j�tjtjd��|jrEttd��r0|j�tjtjd��|j�|j	��|j�
��|_	dS)zOCalled by constructor to bind the socket.

        May be overridden.

        �SO_REUSEADDR��SO_REUSEPORTN)�allow_reuse_address�hasattrr?�
setsockopt�
SOL_SOCKETr|�allow_reuse_portr~�bindr�getsocknamer(s r"ryzTCPServer.server_bind�s����#�	N����(G�(G�	N��K�"�"�6�#4�f�6I�1�M�M�M�� �	N�W�V�^�%D�%D�	N��K�"�"�6�#4�f�6I�1�M�M�M������,�-�-�-�"�k�5�5�7�7����r$c�D�|j�|j��dSr&)r?�listen�request_queue_sizer(s r"r)zTCPServer.server_activate�s#��	
����4�2�3�3�3�3�3r$c�8�|j���dSrW)r?�closer(s r"rXzTCPServer.server_close�s��	
��������r$c�4�|j���S)zMReturn socket file number.

        Interface required by selector.

        )r?�filenor(s r"r�zTCPServer.fileno�����{�!�!�#�#�#r$c�4�|j���S)zYGet the request and client address from the socket.

        May be overridden.

        )r?�acceptr(s r"rHzTCPServer.get_request�r�r$c��	|�tj��n#t$rYnwxYw|�|��dSr[)r<r?�SHUT_WRrIr]r^s  r"rNzTCPServer.shutdown_request�s\��	�
���V�^�,�,�,�,���	�	�	��D�	�������7�#�#�#�#�#s�"�
/�/c�.�|���dSra)r�r^s  r"r]zTCPServer.close_requests���
�
�����r$N)T)rprqrrrsr?�AF_INETrw�SOCK_STREAMrxr�rr�r#ryr)rXr�rHrNr]r'r$r"rr�s�������,�,�\�^�N��$�K�����������8�8�8�4�4�4����$�$�$�$�$�$�$�$�$�����r$rc�D�eZdZdZdZdZejZdZ	d�Z
d�Zd�Zd�Z
dS)	rzUDP server class.Fi c�\�|j�|j��\}}||jf|fSrk)r?�recvfrom�max_packet_size)r!�data�client_addrs   r"rHzUDPServer.get_requests1�� �K�0�0��1E�F�F���k��d�k�"�K�/�/r$c��dSrkr'r(s r"r)zUDPServer.server_activaterbr$c�0�|�|��dSrkr\r^s  r"rNzUDPServer.shutdown_requestr_r$c��dSrkr'r^s  r"r]zUDPServer.close_request"rbr$N)rprqrrrsrr�r?�
SOCK_DGRAMrxr�rHr)rNr]r'r$r"rr
so�������������#�K��O�0�0�0�
�
�
�$�$�$�
�
�
�
�
r$rc�P��eZdZdZdZdZdZdZdd�d�Zd	�Z	d
�Z
d�Z�fd�Z�xZ
S)
rz5Mix-in class to handle each request in a new process.i,N�(TF��blockingc��|j�dSt|j��|jkr�	tjdd��\}}|j�|��n4#t$r|j���Ynt$rYn!wxYwt|j��|jk��|j�	��D]z}	|rdntj
}tj||��\}}|j�|���F#t$r|j�|��Y�lt$rY�wwxYwdS)z7Internal routine to wait for children that have exited.N���r)�active_children�len�max_children�os�waitpid�discard�ChildProcessErrorr-rI�copy�WNOHANG)r!r��pid�_�flagss     r"�collect_childrenzForkingMixIn.collect_children0s����#�+����d�*�+�+�t�/@�@�@���Z��A�.�.�F�C���(�0�0��5�5�5�5��(�1�1�1��(�.�.�0�0�0�0�0������E������d�*�+�+�t�/@�@�@��+�0�0�2�2�
�
��
�!)�9�A�A�r�z�E��Z��U�3�3�F�C���(�0�0��5�5�5�5��(�6�6�6��(�0�0��5�5�5�5�5������D�����
�
s0�2A�#B�	B�B�AD�$D=�1	D=�<D=c�.�|���dS)zvWait for zombies after self.timeout seconds of inactivity.

            May be extended, do not override.
            N�r�r(s r"rDzForkingMixIn.handle_timeoutS���

�!�!�#�#�#�#�#r$c�.�|���dS)z�Collect the zombie child processes regularly in the ForkingMixIn.

            service_actions is called in the BaseServer's serve_forever loop.
            Nr�r(s r"r4zForkingMixIn.service_actionsZr�r$c�`�tj��}|rK|j�t��|_|j�|��|�|��dSd}	|�||��d}n&#t$r|�||��YnwxYw	|�	|��tj
|��dS#tj
|��wxYw#	|�	|��tj
|��w#tj
|��wxYwxYw)z-Fork a new subprocess to process the request.Nr}r)r�rr�r5�addr]rUrLrMrN�_exit)r!rPrQr��statuss     r"rKzForkingMixIn.process_requestasE���'�)�)�C��
)��'�/�+.�5�5�D�(��$�(�(��-�-�-��"�"�7�+�+�+�����	)��'�'���@�@�@��F�F�� �?�?�?��%�%�g�~�>�>�>�>�>�?����)��-�-�g�6�6�6����(�(�(�(�(�����(�(�(�(�����)��-�-�g�6�6�6����(�(�(�(�����(�(�(�(������sN�$A=�<C(�= B �C(�B � C(�$C�C%�(D-�*D�?D-�D*�*D-c�~��t�����|�|j���dS)Nr�)�superrXr��block_on_close�r!�	__class__s �r"rXzForkingMixIn.server_closezs9����G�G� � �"�"�"��!�!�4�+>�!�?�?�?�?�?r$)rprqrrrsrAr�r�r�r�rDr4rKrX�
__classcell__�r�s@r"rr's��������C�C���������/4�!	�!	�!	�!	�!	�F	$�	$�	$�	$�	$�	$�	)�	)�	)�2	@�	@�	@�	@�	@�	@�	@�	@�	@r$rc�4��eZdZdZ�fd�Zd�Zd�Zd�Z�xZS)�_Threadsz2
    Joinable list of all non-daemon threads.
    c���|���|jrdSt���|��dSrk)�reap�daemonr��append)r!�threadr�s  �r"r�z_Threads.append�s;����	�	�����=�	��F�
�����v�����r$c�*�g|dd�c|dd�<}|Srkr')r!�results  r"�pop_allz_Threads.pop_all�s"���d�1�1�1�g���Q�Q�Q����
r$c�\�|���D]}|����dSrk)r��join�r!r�s  r"r�z
_Threads.join�s2���l�l�n�n�	�	�F��K�K�M�M�M�M�	�	r$c�(�d�|D��|dd�<dS)Nc3�BK�|]}|����|V��dSrk)�is_alive)�.0r�s  r"�	<genexpr>z _Threads.reap.<locals>.<genexpr>�s1����B�B�f����0A�0A�B�6�B�B�B�B�B�Br$r'r(s r"r�z
_Threads.reap�s!��B�B��B�B�B��Q�Q�Q���r$)	rprqrrrsr�r�r�r�r�r�s@r"r�r�sv��������������������C�C�C�C�C�C�Cr$r�c��eZdZdZd�Zd�ZdS)�
_NoThreadsz)
    Degenerate version of _Threads.
    c��dSrkr'r�s  r"r�z_NoThreads.append�����r$c��dSrkr'r(s r"r�z_NoThreads.join�r�r$N)rprqrrrsr�r�r'r$r"r�r��s<��������
�
�
�
�
�
�
�
r$r�c�J��eZdZdZdZdZe��Zd�Zd�Z	�fd�Z
�xZS)r
z4Mix-in class to handle each request in a new thread.FTc���	|�||��n&#t$r|�||��YnwxYw|�|��dS#|�|��wxYw)zgSame as in BaseServer but as a thread.

        In addition, exception handling is done here.

        N)rUrLrMrNrOs   r"�process_request_threadz%ThreadingMixIn.process_request_thread�s���	+������8�8�8�8���	7�	7�	7����g�~�6�6�6�6�6�	7����
�!�!�'�*�*�*�*�*��D�!�!�'�*�*�*�*���s!��A� <�A�<�A�A-c� �|jr/t|���dt����t	j|j||f���}|j|_|j	�
|��|���dS)z*Start a new thread to process the request.�_threads)�targetrnN)r��vars�
setdefaultr�r�Threadr��daemon_threadsr�r�r��start)r!rPrQ�ts    r"rKzThreadingMixIn.process_request�s�����	:���J�J�!�!�*�h�j�j�9�9�9���d�&A�%,�n�$=�
?�
?�
?���&����
���Q����	���	�	�	�	�	r$c�z��t�����|j���dSrk)r�rXr�r�r�s �r"rXzThreadingMixIn.server_close�s3���
���������
�������r$)rprqrrrsr�r�r�r�r�rKrXr�r�s@r"r
r
�su�������>�>��N��N��z�|�|�H�+�+�+������������r$r
c��eZdZdS)rN�rprqrrr'r$r"rr���������r$rc��eZdZdS)rNr�r'r$r"rr�r�r$rc��eZdZdS)rNr�r'r$r"rr�r�r$rc��eZdZdS)r	Nr�r'r$r"r	r	�r�r$r	c��eZdZejZdS)rN�rprqrrr?rrwr'r$r"rr������������r$rc��eZdZejZdS)rNr�r'r$r"rr�r�r$rc��eZdZdS)rNr�r'r$r"rr�r�r$rc��eZdZdS)rNr�r'r$r"rr�r�r$rc�*�eZdZdZd�Zd�Zd�Zd�ZdS)r
a�Base class for request handler classes.

    This class is instantiated for each request to be handled.  The
    constructor sets the instance variables request, client_address
    and server, and then calls the handle() method.  To implement a
    specific service, all you need to do is to derive a class which
    defines a handle() method.

    The handle() method can find the request as self.request, the
    client address as self.client_address, and the server (in case it
    needs access to per-server information) as self.server.  Since a
    separate instance is created for each request, the handle() method
    can define other arbitrary instance variables.

    c���||_||_||_|���	|���|���dS#|���wxYwrk)rPrQ�server�setup�handle�finish)r!rPrQr�s    r"r#zBaseRequestHandler.__init__�sZ�����,�������
�
����	��K�K�M�M�M��K�K�M�M�M�M�M��D�K�K�M�M�M�M���s�A�A+c��dSrkr'r(s r"r�zBaseRequestHandler.setup�r�r$c��dSrkr'r(s r"r�zBaseRequestHandler.handle�r�r$c��dSrkr'r(s r"r�zBaseRequestHandler.finish�r�r$N)rprqrrrsr#r�r�r�r'r$r"r
r
�sZ�������� ���
�
�
�
�
�
�
�
�
�
�
r$r
c�.�eZdZdZdZdZdZdZd�Zd�Z	dS)rz4Define self.rfile and self.wfile for stream sockets.r�rNFc��|j|_|j�|j�|j��|jr0|j�tjtjd��|j�	d|j
��|_|jdkrt|j��|_dS|j�	d|j��|_dS)NT�rbr�wb)rP�
connectionrA�
settimeout�disable_nagle_algorithmr�r?�IPPROTO_TCP�TCP_NODELAY�makefile�rbufsize�rfile�wbufsize�
_SocketWriter�wfiler(s r"r�zStreamRequestHandler.setups����,����<�#��O�&�&�t�|�4�4�4��'�	A��O�&�&�v�'9�'-�'9�4�
A�
A�
A��_�-�-�d�D�M�B�B��
��=�A���&�t��7�7�D�J�J�J���1�1�$��
�F�F�D�J�J�Jr$c���|jjs0	|j���n#tj$rYnwxYw|j���|j���dSrk)r�closed�flushr?�errorr�rr(s r"r�zStreamRequestHandler.finish+s���z� �	�
��
� � �"�"�"�"���<�
�
�
���
����	
�
�������
�������s�(�:�:)
rprqrrrsrrrArr�r�r'r$r"rr	sV������>�>��H��H��G�$��G�G�G�	�	�	�	�	r$rc�*�eZdZdZd�Zd�Zd�Zd�ZdS)rz�Simple writable BufferedIOBase implementation for a socket

    Does not hold data in a buffer, avoiding any need to call flush().c��||_dSrk)�_sock)r!�socks  r"r#z_SocketWriter.__init__;s
����
�
�
r$c��dS)NTr'r(s r"�writablez_SocketWriter.writable>s���tr$c��|j�|��t|��5}|jcddd��S#1swxYwYdSrk)r�sendall�
memoryview�nbytes)r!�b�views   r"�writez_SocketWriter.writeAs����
���1����
��]�]�	�d��;�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s�>�A�Ac�4�|j���Srk)rr�r(s r"r�z_SocketWriter.filenoFs���z� � �"�"�"r$N)rprqrrrsr#rrr�r'r$r"rr6s\������J�J����������
#�#�#�#�#r$rc��eZdZdZd�Zd�ZdS)rz6Define self.rfile and self.wfile for datagram sockets.c��ddlm}|j\|_|_||j��|_|��|_dS)Nr)�BytesIO)�iorrP�packetr?rr)r!rs  r"r�zDatagramRequestHandler.setupMsH��������#'�<� ���T�[��W�T�[�)�)��
��W�Y�Y��
�
�
r$c�t�|j�|j���|j��dSrk)r?�sendtor�getvaluerQr(s r"r�zDatagramRequestHandler.finishSs1������4�:�.�.�0�0�$�2E�F�F�F�F�Fr$N)rprqrrrsr�r�r'r$r"rrIs=������@�@����G�G�G�G�Gr$r)%rs�__version__r?r0r�rfrrrrCr�__all__r��extendrr.�SelectSelectorrrrr�listr�r�r
rrrr	rrrrr
rrrr'r$r"�<module>r(s`��v�v�t���
�
�
�����	�	�	�	�
�
�
�
�����������"�"�"�"�"�"�7�7�7���7�2�v���L��N�N�J�J�J�K�K�K�
�7�6�9���4��N�N�3�3�3�4�4�4��7�9�n�%�%�/��,�O�O��.�O�k�k�k�k�k�k�k�k�\@�@�@�@�@�
�@�@�@�F
�
�
�
�
�	�
�
�
�8�7�2�v���V@�U@�U@�U@�U@�U@�U@�U@�U@�pC�C�C�C�C�t�C�C�C�,
�
�
�
�
�
�
�
�%�%�%�%�%�%�%�%�P�7�2�v���:�9�9�9�9�9�<��9�9�9�9�9�9�9�9�<��9�9�9�9�9�9�9�9���9�9�9�9�9�9�9�9���9�9�9�
�7�6�9���
P�(�(�(�(�(�9�(�(�(�(�(�(�(�(�Y�(�(�(�L�K�K�K�K�N�4D�K�K�K�O�O�O�O�O�n�6H�O�O�O�#
�#
�#
�#
�#
�#
�#
�#
�\+�+�+�+�+�-�+�+�+�Z#�#�#�#�#�N�#�#�#�&G�G�G�G�G�/�G�G�G�G�Gr$

?>