def get_status(self, sock: socket.socket, address: tuple[str, int], request_parser: HTTPParser) -> HTTPEventHandler: try: with open(self.static_filename, "rb") as static_fileobj: status_body = static_fileobj.read() return HTTPEventHandler( self.server, sock, address, request_parser, HTTPResponse(200, b"OK", {b"Content-Type": b"application/octet-stream"}, status_body), ) except IOError as exc: self.server.logger.exception("Error when trying to serve static status file %s:", self.static_filename) return HTTPEventHandler( self.server, sock, address, request_parser, HTTPResponse( 500, b"Internal Server Error", {b"Content-Type": b"text/plain"}, b"Failed to open static status file\n", ), )
def flush(self): HTTPEventHandler.flush(self) if self.output_buffer.ready: # FIXME could we replace ready with buffer.empty ? # De-activate handler to avoid unnecessary notifications self.unwatch_write() # deactivate timer if output_buffer is empty self.io_timeout.stop()
def flush(self): HTTPEventHandler.flush(self) if self.output_buffer.ready: # De-activate handler to avoid unnecessary notifications self.server.loop.register(self, 0) # deactivate timer if output_buffer is empty self.server.remove_inactivity_timeout(self) self.timeout_state = False
def __init__(self, server, source, sock, address, request_parser, content_type, http_response = None): if http_response is None: http_response = HTTPResponse( 200, b'OK', {b'Content-Length': None, b'Content-Type': content_type}, ) HTTPEventHandler.__init__(self, server, sock, address, request_parser, http_response) self.source = source
def __init__(self, server, source, sock, address, request_parser, content_type, http_response = None): if http_response is None: http_response = HTTPResponse( 200, b'OK', {b'Content-Length': None, b'Content-Type': content_type}, ) HTTPEventHandler.__init__(self, server, sock, address, request_parser, http_response) self.source = source self.timeout_state = False self.server.remove_inactivity_timeout(self)
def get_status(self, sock, address, request_parser): try: with open(self.static_filename) as static_fileobj: status_body = static_fileobj.read() return HTTPEventHandler( self.server, sock, address, request_parser, HTTPResponse(200, b'OK', {b'Content-Type': 'application/octet-stream'}, status_body)) except IOError as exc: self.server.logger.exception( 'Error when trying to serve static status file %s:', self.static_filename) return HTTPEventHandler( self.server, sock, address, request_parser, HTTPResponse(500, b'Internal Server Error', {b'Content-Type': 'text/plain'}, 'Failed to open static status file\n'))
def get_status(self, sock: socket.socket, address: tuple[str, int], request_parser: HTTPParser) -> HTTPEventHandler: return HTTPEventHandler( self.server, sock, address, request_parser, HTTPResponse( 200, b"OK", {b"Content-Type": b"text/plain"}, bytes(pprint.pformat(self.server.sources), "ascii") ), )
def __init__(self, server, sock, address, request_parser): sources_dict = {} total_clients_number = 0 for path, sources in server.sources.items(): sources_dict[path] = {} for source, source_dict in sources.items(): source_address = '%s:%s' % source.address sources_dict[path][source_address] = {} for fd, client in source_dict['clients'].items(): sources_dict[path][source_address][fd] = '%s:%s' % client.address total_clients_number += 1 status_dict = { 'total_clients_number': total_clients_number, 'pid': os.getpid(), 'sources': sources_dict, } HTTPEventHandler.__init__(self, server, sock, address, request_parser, 200, b'OK', {b'Content-Type': 'application/json'}, json.dumps(status_dict, indent = 4) + '\n')
def __init__(self, server, source, sock, address, request_parser, content_type, http_response=None): if http_response is None: http_response = HTTPResponse( 200, b'OK', { b'Content-Length': None, b'Content-Type': content_type }, ) HTTPEventHandler.__init__(self, server, sock, address, request_parser, http_response) self.source = source self.timeout_state = False self.server.remove_inactivity_timeout(self)
def get_status(self, sock: socket.socket, address: tuple[str, int], request_parser: HTTPParser) -> HTTPEventHandler: sources_dict: dict[str, dict[str, dict[int, str]]] = {} total_clients_number = 0 queue_sizes = [] for path, sources in self.server.sources.items(): sources_dict[path] = {} for source, source_dict in list(sources.items()): source_address = "%s:%s (%s)" % (source.address[0], source.address[1], id(source)) sources_dict[path][source_address] = {} for fd, client in list(source_dict["clients"].items()): sources_dict[path][source_address][fd] = "%s:%s" % client.address total_clients_number += 1 queue_sizes.append(sum(len(elt) for elt in client.output_buffer.buffer_queue)) queue_sizes.sort() if not queue_sizes: queue_sizes = [-1] status_dict = { "total_clients_number": total_clients_number, "pid": os.getpid(), "max_buffer_queue_size": queue_sizes[-1], "min_buffer_queue_size": queue_sizes[0], "median_buffer_queue_size": queue_sizes[total_clients_number // 2], "average_buffer_queue_size": sum(queue_sizes) / len(queue_sizes), "sources": sources_dict, } return HTTPEventHandler( self.server, sock, address, request_parser, HTTPResponse( 200, b"OK", {b"Content-Type": b"application/json"}, bytes(json.dumps(status_dict, indent=4) + "\n", "utf-8"), ), )
def get_status(self, sock, address, request_parser): sources_dict = {} total_clients_number = 0 queue_sizes = [] for path, sources in self.server.sources.items(): sources_dict[path] = {} for source, source_dict in sources.items(): source_address = '%s:%s (%s)' % (source.address[0], source.address[1], id(source)) sources_dict[path][source_address] = {} for fd, client in source_dict['clients'].items(): sources_dict[path][source_address][ fd] = '%s:%s' % client.address total_clients_number += 1 queue_sizes.append( sum( len(elt) for elt in client.output_buffer.buffer_queue)) queue_sizes.sort() if not queue_sizes: queue_sizes = [-1] status_dict = { 'total_clients_number': total_clients_number, 'pid': os.getpid(), 'max_buffer_queue_size': queue_sizes[-1], 'min_buffer_queue_size': queue_sizes[0], 'median_buffer_queue_size': queue_sizes[total_clients_number / 2], 'average_buffer_queue_size': sum(queue_sizes) / len(queue_sizes), 'sources': sources_dict, } return HTTPEventHandler( self.server, sock, address, request_parser, HTTPResponse(200, b'OK', {b'Content-Type': 'application/json'}, json.dumps(status_dict, indent=4) + '\n'))
def close(self): self.server.remove_client(self) HTTPEventHandler.close(self)
def stop(self): self.server.remove_client(self) HTTPEventHandler.stop(self)
def get_status(self, sock, address, request_parser): return HTTPEventHandler( self.server, sock, address, request_parser, HTTPResponse(200, b'OK', {b'Content-Type': 'text/plain'}, pprint.pformat(self.server.sources)))
def __init__(self, server, source, sock, address, request_parser, content_type): HTTPEventHandler.__init__(self, server, sock, address, request_parser, 200, b'OK', {b'Content-Length': None, b'Content-Type': content_type}) self.source = source
def __init__(self, server, sock, address, request_parser): HTTPEventHandler.__init__(self, server, sock, address, request_parser, 200, b'OK', {b'Content-Type': 'text/plain'}, pprint.pformat(server.sources))