File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/cheroot/__pycache__/server.cpython-310.pyc
Back
o ;jL9 � @ s| d Z ddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddlZddlZddl Z ddlZddlZddlmZ ddlmZmZmZ ddlmZmZ ddlmZmZ ddlmZ d Z e�!� d kZ" e�#dd��$d �Z% e" oxe% Z& e&r�z ddl'Z'ddl(Z(W n e)y� dZ&d\Z'Z(Y nw ddl*Z*nd\Z'Z(Z*e"r�e+e d�r�e+e d�s�de _,e+e d�s�de _-e+e d�s� er�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� )�__version__�connections�errors)�IS_PPC�bton)�MakeFile�StreamWriter)� threadpool) �ChunkedRFile�DropUnderscoreHeaderReader�Gateway�HTTPConnection�HTTPRequest� HTTPServer�HeaderReader�KnownLengthRFile�SizeCheckWrapper�get_ssl_adapter_class�WindowsZSERVER_SOFTWARE� zGoogle App Engine/F)NN)NNN�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 }d} |� � }|std��|tkr |S |�t�s#td��|dd� tthv r2|�� }n!z |�td�\}}W n tyG td��w |�� }| � |�}|}| � |�sYq|tv rk|�|�}|rkd� ||f�}|||<