| |
- BaseRequestHandler
-
- DatagramRequestHandler
- StreamRequestHandler
- BaseServer
-
- TCPServer
-
- UDPServer
-
- UnixDatagramServer
- UnixStreamServer
- ForkingMixIn
-
- ForkingTCPServer(ForkingMixIn, TCPServer)
- ForkingUDPServer(ForkingMixIn, UDPServer)
- ThreadingMixIn
-
- ThreadingTCPServer(ThreadingMixIn, TCPServer)
- ThreadingUDPServer(ThreadingMixIn, UDPServer)
- ThreadingUnixDatagramServer(ThreadingMixIn, UnixDatagramServer)
- ThreadingUnixStreamServer(ThreadingMixIn, UnixStreamServer)
class BaseRequestHandler |
|
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 arbitrary other instance variariables. |
|
Methods defined here:
- __init__(self, request, client_address, server)
- finish(self)
- handle(self)
- setup(self)
|
class ForkingMixIn |
|
Mix-in class to handle each request in a new process. |
|
Methods defined here:
- collect_children(self)
- Internal routine to wait for children that have exited.
- handle_timeout(self)
- Wait for zombies after self.timeout seconds of inactivity.
May be extended, do not override.
- process_request(self, request, client_address)
- Fork a new subprocess to process the request.
Data and other attributes defined here:
- active_children = None
- max_children = 40
- timeout = 300
|
class ForkingTCPServer(ForkingMixIn, TCPServer) |
| |
- Method resolution order:
- ForkingTCPServer
- ForkingMixIn
- TCPServer
- BaseServer
Methods inherited from ForkingMixIn:
- collect_children(self)
- Internal routine to wait for children that have exited.
- handle_timeout(self)
- Wait for zombies after self.timeout seconds of inactivity.
May be extended, do not override.
- process_request(self, request, client_address)
- Fork a new subprocess to process the request.
Data and other attributes inherited from ForkingMixIn:
- active_children = None
- max_children = 40
- timeout = 300
Methods inherited from TCPServer:
- __init__(self, server_address, RequestHandlerClass, bind_and_activate=True)
- Constructor. May be extended, do not override.
- close_request(self, request)
- Called to clean up an individual request.
- fileno(self)
- Return socket file number.
Interface required by select().
- get_request(self)
- Get the request and client address from the socket.
May be overridden.
- server_activate(self)
- Called by constructor to activate the server.
May be overridden.
- server_bind(self)
- Called by constructor to bind the socket.
May be overridden.
- server_close(self)
- Called to clean-up the server.
May be overridden.
- shutdown_request(self, request)
- Called to shutdown and close an individual request.
Data and other attributes inherited from TCPServer:
- address_family = 2
- allow_reuse_address = False
- request_queue_size = 5
- socket_type = 1
Methods inherited from BaseServer:
- finish_request(self, request, client_address)
- Finish one request by instantiating RequestHandlerClass.
- handle_error(self, request, client_address)
- Handle an error gracefully. May be overridden.
The default is to print a traceback and continue.
- handle_request(self)
- Handle one request, possibly blocking.
Respects self.timeout.
- serve_forever(self, poll_interval=0.5)
- 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.
- shutdown(self)
- 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.
- verify_request(self, request, client_address)
- Verify the request. May be overridden.
Return True if we should proceed with this request.
|
class ForkingUDPServer(ForkingMixIn, UDPServer) |
| |
- Method resolution order:
- ForkingUDPServer
- ForkingMixIn
- UDPServer
- TCPServer
- BaseServer
Methods inherited from ForkingMixIn:
- collect_children(self)
- Internal routine to wait for children that have exited.
- handle_timeout(self)
- Wait for zombies after self.timeout seconds of inactivity.
May be extended, do not override.
- process_request(self, request, client_address)
- Fork a new subprocess to process the request.
Data and other attributes inherited from ForkingMixIn:
- active_children = None
- max_children = 40
- timeout = 300
Methods inherited from UDPServer:
- close_request(self, request)
- get_request(self)
- server_activate(self)
- shutdown_request(self, request)
Data and other attributes inherited from UDPServer:
- allow_reuse_address = False
- max_packet_size = 8192
- socket_type = 2
Methods inherited from TCPServer:
- __init__(self, server_address, RequestHandlerClass, bind_and_activate=True)
- Constructor. May be extended, do not override.
- fileno(self)
- Return socket file number.
Interface required by select().
- server_bind(self)
- Called by constructor to bind the socket.
May be overridden.
- server_close(self)
- Called to clean-up the server.
May be overridden.
Data and other attributes inherited from TCPServer:
- address_family = 2
- request_queue_size = 5
Methods inherited from BaseServer:
- finish_request(self, request, client_address)
- Finish one request by instantiating RequestHandlerClass.
- handle_error(self, request, client_address)
- Handle an error gracefully. May be overridden.
The default is to print a traceback and continue.
- handle_request(self)
- Handle one request, possibly blocking.
Respects self.timeout.
- serve_forever(self, poll_interval=0.5)
- 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.
- shutdown(self)
- 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.
- verify_request(self, request, client_address)
- Verify the request. May be overridden.
Return True if we should proceed with this request.
|
class TCPServer(BaseServer) |
|
Base 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 select()
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
Instance variables:
- server_address
- RequestHandlerClass
- socket |
|
Methods defined here:
- __init__(self, server_address, RequestHandlerClass, bind_and_activate=True)
- Constructor. May be extended, do not override.
- close_request(self, request)
- Called to clean up an individual request.
- fileno(self)
- Return socket file number.
Interface required by select().
- get_request(self)
- Get the request and client address from the socket.
May be overridden.
- server_activate(self)
- Called by constructor to activate the server.
May be overridden.
- server_bind(self)
- Called by constructor to bind the socket.
May be overridden.
- server_close(self)
- Called to clean-up the server.
May be overridden.
- shutdown_request(self, request)
- Called to shutdown and close an individual request.
Data and other attributes defined here:
- address_family = 2
- allow_reuse_address = False
- request_queue_size = 5
- socket_type = 1
Methods inherited from BaseServer:
- finish_request(self, request, client_address)
- Finish one request by instantiating RequestHandlerClass.
- handle_error(self, request, client_address)
- Handle an error gracefully. May be overridden.
The default is to print a traceback and continue.
- handle_request(self)
- Handle one request, possibly blocking.
Respects self.timeout.
- handle_timeout(self)
- Called if no new request arrives within self.timeout.
Overridden by ForkingMixIn.
- process_request(self, request, client_address)
- Call finish_request.
Overridden by ForkingMixIn and ThreadingMixIn.
- serve_forever(self, poll_interval=0.5)
- 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.
- shutdown(self)
- 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.
- verify_request(self, request, client_address)
- Verify the request. May be overridden.
Return True if we should proceed with this request.
Data and other attributes inherited from BaseServer:
- timeout = None
|
class ThreadingMixIn |
|
Mix-in class to handle each request in a new thread. |
|
Methods defined here:
- process_request(self, request, client_address)
- Start a new thread to process the request.
- process_request_thread(self, request, client_address)
- Same as in BaseServer but as a thread.
In addition, exception handling is done here.
Data and other attributes defined here:
- daemon_threads = False
|
class ThreadingTCPServer(ThreadingMixIn, TCPServer) |
| |
- Method resolution order:
- ThreadingTCPServer
- ThreadingMixIn
- TCPServer
- BaseServer
Methods inherited from ThreadingMixIn:
- process_request(self, request, client_address)
- Start a new thread to process the request.
- process_request_thread(self, request, client_address)
- Same as in BaseServer but as a thread.
In addition, exception handling is done here.
Data and other attributes inherited from ThreadingMixIn:
- daemon_threads = False
Methods inherited from TCPServer:
- __init__(self, server_address, RequestHandlerClass, bind_and_activate=True)
- Constructor. May be extended, do not override.
- close_request(self, request)
- Called to clean up an individual request.
- fileno(self)
- Return socket file number.
Interface required by select().
- get_request(self)
- Get the request and client address from the socket.
May be overridden.
- server_activate(self)
- Called by constructor to activate the server.
May be overridden.
- server_bind(self)
- Called by constructor to bind the socket.
May be overridden.
- server_close(self)
- Called to clean-up the server.
May be overridden.
- shutdown_request(self, request)
- Called to shutdown and close an individual request.
Data and other attributes inherited from TCPServer:
- address_family = 2
- allow_reuse_address = False
- request_queue_size = 5
- socket_type = 1
Methods inherited from BaseServer:
- finish_request(self, request, client_address)
- Finish one request by instantiating RequestHandlerClass.
- handle_error(self, request, client_address)
- Handle an error gracefully. May be overridden.
The default is to print a traceback and continue.
- handle_request(self)
- Handle one request, possibly blocking.
Respects self.timeout.
- handle_timeout(self)
- Called if no new request arrives within self.timeout.
Overridden by ForkingMixIn.
- serve_forever(self, poll_interval=0.5)
- 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.
- shutdown(self)
- 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.
- verify_request(self, request, client_address)
- Verify the request. May be overridden.
Return True if we should proceed with this request.
Data and other attributes inherited from BaseServer:
- timeout = None
|
class ThreadingUDPServer(ThreadingMixIn, UDPServer) |
| |
- Method resolution order:
- ThreadingUDPServer
- ThreadingMixIn
- UDPServer
- TCPServer
- BaseServer
Methods inherited from ThreadingMixIn:
- process_request(self, request, client_address)
- Start a new thread to process the request.
- process_request_thread(self, request, client_address)
- Same as in BaseServer but as a thread.
In addition, exception handling is done here.
Data and other attributes inherited from ThreadingMixIn:
- daemon_threads = False
Methods inherited from UDPServer:
- close_request(self, request)
- get_request(self)
- server_activate(self)
- shutdown_request(self, request)
Data and other attributes inherited from UDPServer:
- allow_reuse_address = False
- max_packet_size = 8192
- socket_type = 2
Methods inherited from TCPServer:
- __init__(self, server_address, RequestHandlerClass, bind_and_activate=True)
- Constructor. May be extended, do not override.
- fileno(self)
- Return socket file number.
Interface required by select().
- server_bind(self)
- Called by constructor to bind the socket.
May be overridden.
- server_close(self)
- Called to clean-up the server.
May be overridden.
Data and other attributes inherited from TCPServer:
- address_family = 2
- request_queue_size = 5
Methods inherited from BaseServer:
- finish_request(self, request, client_address)
- Finish one request by instantiating RequestHandlerClass.
- handle_error(self, request, client_address)
- Handle an error gracefully. May be overridden.
The default is to print a traceback and continue.
- handle_request(self)
- Handle one request, possibly blocking.
Respects self.timeout.
- handle_timeout(self)
- Called if no new request arrives within self.timeout.
Overridden by ForkingMixIn.
- serve_forever(self, poll_interval=0.5)
- 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.
- shutdown(self)
- 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.
- verify_request(self, request, client_address)
- Verify the request. May be overridden.
Return True if we should proceed with this request.
Data and other attributes inherited from BaseServer:
- timeout = None
|
class ThreadingUnixDatagramServer(ThreadingMixIn, UnixDatagramServer) |
| |
- Method resolution order:
- ThreadingUnixDatagramServer
- ThreadingMixIn
- UnixDatagramServer
- UDPServer
- TCPServer
- BaseServer
Methods inherited from ThreadingMixIn:
- process_request(self, request, client_address)
- Start a new thread to process the request.
- process_request_thread(self, request, client_address)
- Same as in BaseServer but as a thread.
In addition, exception handling is done here.
Data and other attributes inherited from ThreadingMixIn:
- daemon_threads = False
Data and other attributes inherited from UnixDatagramServer:
- address_family = 1
Methods inherited from UDPServer:
- close_request(self, request)
- get_request(self)
- server_activate(self)
- shutdown_request(self, request)
Data and other attributes inherited from UDPServer:
- allow_reuse_address = False
- max_packet_size = 8192
- socket_type = 2
Methods inherited from TCPServer:
- __init__(self, server_address, RequestHandlerClass, bind_and_activate=True)
- Constructor. May be extended, do not override.
- fileno(self)
- Return socket file number.
Interface required by select().
- server_bind(self)
- Called by constructor to bind the socket.
May be overridden.
- server_close(self)
- Called to clean-up the server.
May be overridden.
Data and other attributes inherited from TCPServer:
- request_queue_size = 5
Methods inherited from BaseServer:
- finish_request(self, request, client_address)
- Finish one request by instantiating RequestHandlerClass.
- handle_error(self, request, client_address)
- Handle an error gracefully. May be overridden.
The default is to print a traceback and continue.
- handle_request(self)
- Handle one request, possibly blocking.
Respects self.timeout.
- handle_timeout(self)
- Called if no new request arrives within self.timeout.
Overridden by ForkingMixIn.
- serve_forever(self, poll_interval=0.5)
- 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.
- shutdown(self)
- 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.
- verify_request(self, request, client_address)
- Verify the request. May be overridden.
Return True if we should proceed with this request.
Data and other attributes inherited from BaseServer:
- timeout = None
|
class ThreadingUnixStreamServer(ThreadingMixIn, UnixStreamServer) |
| |
- Method resolution order:
- ThreadingUnixStreamServer
- ThreadingMixIn
- UnixStreamServer
- TCPServer
- BaseServer
Methods inherited from ThreadingMixIn:
- process_request(self, request, client_address)
- Start a new thread to process the request.
- process_request_thread(self, request, client_address)
- Same as in BaseServer but as a thread.
In addition, exception handling is done here.
Data and other attributes inherited from ThreadingMixIn:
- daemon_threads = False
Data and other attributes inherited from UnixStreamServer:
- address_family = 1
Methods inherited from TCPServer:
- __init__(self, server_address, RequestHandlerClass, bind_and_activate=True)
- Constructor. May be extended, do not override.
- close_request(self, request)
- Called to clean up an individual request.
- fileno(self)
- Return socket file number.
Interface required by select().
- get_request(self)
- Get the request and client address from the socket.
May be overridden.
- server_activate(self)
- Called by constructor to activate the server.
May be overridden.
- server_bind(self)
- Called by constructor to bind the socket.
May be overridden.
- server_close(self)
- Called to clean-up the server.
May be overridden.
- shutdown_request(self, request)
- Called to shutdown and close an individual request.
Data and other attributes inherited from TCPServer:
- allow_reuse_address = False
- request_queue_size = 5
- socket_type = 1
Methods inherited from BaseServer:
- finish_request(self, request, client_address)
- Finish one request by instantiating RequestHandlerClass.
- handle_error(self, request, client_address)
- Handle an error gracefully. May be overridden.
The default is to print a traceback and continue.
- handle_request(self)
- Handle one request, possibly blocking.
Respects self.timeout.
- handle_timeout(self)
- Called if no new request arrives within self.timeout.
Overridden by ForkingMixIn.
- serve_forever(self, poll_interval=0.5)
- 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.
- shutdown(self)
- 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.
- verify_request(self, request, client_address)
- Verify the request. May be overridden.
Return True if we should proceed with this request.
Data and other attributes inherited from BaseServer:
- timeout = None
|
class UDPServer(TCPServer) |
|
UDP server class. |
|
- Method resolution order:
- UDPServer
- TCPServer
- BaseServer
Methods defined here:
- close_request(self, request)
- get_request(self)
- server_activate(self)
- shutdown_request(self, request)
Data and other attributes defined here:
- allow_reuse_address = False
- max_packet_size = 8192
- socket_type = 2
Methods inherited from TCPServer:
- __init__(self, server_address, RequestHandlerClass, bind_and_activate=True)
- Constructor. May be extended, do not override.
- fileno(self)
- Return socket file number.
Interface required by select().
- server_bind(self)
- Called by constructor to bind the socket.
May be overridden.
- server_close(self)
- Called to clean-up the server.
May be overridden.
Data and other attributes inherited from TCPServer:
- address_family = 2
- request_queue_size = 5
Methods inherited from BaseServer:
- finish_request(self, request, client_address)
- Finish one request by instantiating RequestHandlerClass.
- handle_error(self, request, client_address)
- Handle an error gracefully. May be overridden.
The default is to print a traceback and continue.
- handle_request(self)
- Handle one request, possibly blocking.
Respects self.timeout.
- handle_timeout(self)
- Called if no new request arrives within self.timeout.
Overridden by ForkingMixIn.
- process_request(self, request, client_address)
- Call finish_request.
Overridden by ForkingMixIn and ThreadingMixIn.
- serve_forever(self, poll_interval=0.5)
- 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.
- shutdown(self)
- 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.
- verify_request(self, request, client_address)
- Verify the request. May be overridden.
Return True if we should proceed with this request.
Data and other attributes inherited from BaseServer:
- timeout = None
|
class UnixDatagramServer(UDPServer) |
| |
- Method resolution order:
- UnixDatagramServer
- UDPServer
- TCPServer
- BaseServer
Data and other attributes defined here:
- address_family = 1
Methods inherited from UDPServer:
- close_request(self, request)
- get_request(self)
- server_activate(self)
- shutdown_request(self, request)
Data and other attributes inherited from UDPServer:
- allow_reuse_address = False
- max_packet_size = 8192
- socket_type = 2
Methods inherited from TCPServer:
- __init__(self, server_address, RequestHandlerClass, bind_and_activate=True)
- Constructor. May be extended, do not override.
- fileno(self)
- Return socket file number.
Interface required by select().
- server_bind(self)
- Called by constructor to bind the socket.
May be overridden.
- server_close(self)
- Called to clean-up the server.
May be overridden.
Data and other attributes inherited from TCPServer:
- request_queue_size = 5
Methods inherited from BaseServer:
- finish_request(self, request, client_address)
- Finish one request by instantiating RequestHandlerClass.
- handle_error(self, request, client_address)
- Handle an error gracefully. May be overridden.
The default is to print a traceback and continue.
- handle_request(self)
- Handle one request, possibly blocking.
Respects self.timeout.
- handle_timeout(self)
- Called if no new request arrives within self.timeout.
Overridden by ForkingMixIn.
- process_request(self, request, client_address)
- Call finish_request.
Overridden by ForkingMixIn and ThreadingMixIn.
- serve_forever(self, poll_interval=0.5)
- 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.
- shutdown(self)
- 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.
- verify_request(self, request, client_address)
- Verify the request. May be overridden.
Return True if we should proceed with this request.
Data and other attributes inherited from BaseServer:
- timeout = None
|
class UnixStreamServer(TCPServer) |
| |
- Method resolution order:
- UnixStreamServer
- TCPServer
- BaseServer
Data and other attributes defined here:
- address_family = 1
Methods inherited from TCPServer:
- __init__(self, server_address, RequestHandlerClass, bind_and_activate=True)
- Constructor. May be extended, do not override.
- close_request(self, request)
- Called to clean up an individual request.
- fileno(self)
- Return socket file number.
Interface required by select().
- get_request(self)
- Get the request and client address from the socket.
May be overridden.
- server_activate(self)
- Called by constructor to activate the server.
May be overridden.
- server_bind(self)
- Called by constructor to bind the socket.
May be overridden.
- server_close(self)
- Called to clean-up the server.
May be overridden.
- shutdown_request(self, request)
- Called to shutdown and close an individual request.
Data and other attributes inherited from TCPServer:
- allow_reuse_address = False
- request_queue_size = 5
- socket_type = 1
Methods inherited from BaseServer:
- finish_request(self, request, client_address)
- Finish one request by instantiating RequestHandlerClass.
- handle_error(self, request, client_address)
- Handle an error gracefully. May be overridden.
The default is to print a traceback and continue.
- handle_request(self)
- Handle one request, possibly blocking.
Respects self.timeout.
- handle_timeout(self)
- Called if no new request arrives within self.timeout.
Overridden by ForkingMixIn.
- process_request(self, request, client_address)
- Call finish_request.
Overridden by ForkingMixIn and ThreadingMixIn.
- serve_forever(self, poll_interval=0.5)
- 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.
- shutdown(self)
- 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.
- verify_request(self, request, client_address)
- Verify the request. May be overridden.
Return True if we should proceed with this request.
Data and other attributes inherited from BaseServer:
- timeout = None
| |