Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/cheroot/__pycache__/server.cpython-39.pyc
Ðазад
a p�hj0 � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddl Z ddlZddlZddl Z ddlZddlZddlZddlmZ ddlmZmZmZ ddlmZ ddlmZ ddlmZ dd lmZmZ d Z e�!� dkZ"e�#dd ��$d�Z%e" o�e% Z&e&�r:zddl'Z'ddl(Z(W n e)�y0 dZ&d\Z'Z(Y n0 ddl*Z*e"�rpe+ed��rpe+ed��s^de_,e+ed��spde_-e+ed��s�e�r�dnde_.dZ/dZ0dZ1dZ2dZ3dZ4dZ5d Z6d!Z7d"Z8e�9d�:d#e8f��Z;e<� Z=g d$�Z>e+ed%��s�i e_?G d&d'� d'�Z@G d(d)� d)e@�ZAG d*d+� d+�ZBG d,d-� d-�ZCG d.d/� d/�ZDG d0d1� d1�ZEG d2d3� d3�ZFG d4d5� d5�ZGG d6d7� d7�ZHd8d9d:�ZId>d<d=�ZJdS )?a� A high-speed, production ready, thread pooled, generic HTTP server. For those of you wanting to understand internals of this module, here's the basic call flow. The server's listening thread runs a very tight loop, sticking incoming connections onto a Queue:: server = HTTPServer(...) server.start() -> serve() while ready: _connections.run() while not stop_requested: child = socket.accept() # blocks until a request comes in conn = HTTPConnection(child, ...) server.process_conn(conn) # adds conn to threadpool Worker threads are kept in a pool and poll the Queue, popping off and then handling each connection in turn. Each connection can consist of an arbitrary number of requests and their responses, so we run a nested loop:: while True: conn = server.requests.get() conn.communicate() -> while True: req = HTTPRequest(...) req.parse_request() -> # Read the Request-Line, e.g. "GET /page HTTP/1.1" req.rfile.readline() read_headers(req.rfile, req.inheaders) req.respond() -> response = app(...) try: for chunk in response: if chunk: req.write(chunk) finally: if hasattr(response, "close"): response.close() if req.close_connection: return For running a server you can invoke :func:`start() <HTTPServer.start()>` (it will run the server forever) or use invoking :func:`prepare() <HTTPServer.prepare()>` and :func:`serve() <HTTPServer.serve()>` like this:: server = HTTPServer(...) server.prepare() try: threading.Thread(target=server.serve).start() # waiting/detecting some appropriate stop condition here ... finally: server.stop() And now for a trivial doctest to exercise the test suite .. testsetup:: from cheroot.server import HTTPServer >>> 'HTTPServer' in globals() True � N)� lru_cache� )�connections�errors�__version__)�bton)�IS_PPC)� threadpool)�MakeFile�StreamWriter) �HTTPRequest�HTTPConnection� HTTPServer�HeaderReader�DropUnderscoreHeaderReader�SizeCheckWrapper�KnownLengthRFile�ChunkedRFile�Gateway�get_ssl_adapter_class�Windows�SERVER_SOFTWARE� zGoogle App Engine/F)NN�AF_INET6�IPPROTO_IPV6�) �IPV6_V6ONLY� �SO_PEERCRED� � � s � � � :� ;� � *� /s %2Fs (?i))s Accepts Accept-Charsets Accept-Encodings Accept-Languages Accept-Rangess Allows Cache-Control� Connections Content-Encodings Content-Language� Expects If-Matchs If-None-Matchs Pragmas Proxy-Authenticates TEs Trailer� Transfer-Encodings Upgrades Varys Vias Warnings WWW-Authenticate� statisticsc @ s* e Zd ZdZd dd�Zdd� Zdd� ZdS ) r z`Object for reading headers from an HTTP request. Interface and default implementation. Nc C s� |du ri }|� � }|s td��|tkr*q�|�t�s<td��|dd� ttfv rZ|�� }nFz|�td�\}}W n ty� td��Y n0 |�� }| � |�}|}| � |�s�q|tv r�|�|�}|r�d� ||f�}|||<