kr.motd.maven.sphinx.dist.future.backports.socketserver$py.class Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sphinx-maven-plugin Show documentation
Show all versions of sphinx-maven-plugin Show documentation
Maven plugin that creates the site with Sphinx
???? 1? f$0 R(Lorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject; __doc__ ?Generic 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 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
save 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 select() 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
- Standard framework for select-based multiplexing
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
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.
org/python/core/PyString fromInterned .(Ljava/lang/String;)Lorg/python/core/PyString;
org/python/core/PyFrame
setglobal /(Ljava/lang/String;Lorg/python/core/PyObject;)V
setline (I)V
__future__ java/lang/String absolute_import print_function org/python/core/imp
importFrom \(Ljava/lang/String;[Ljava/lang/String;Lorg/python/core/PyFrame;I)[Lorg/python/core/PyObject; ! "
# setlocal %
& 0.4 ( __version__ * socket , importOne H(Ljava/lang/String;Lorg/python/core/PyFrame;I)Lorg/python/core/PyObject; . /
0 select 2 sys 4 os 6 errno 8 threading : org/python/core/Py < setException M(Ljava/lang/Throwable;Lorg/python/core/PyFrame;)Lorg/python/core/PyException; > ?
= @ ImportError B getname .(Ljava/lang/String;)Lorg/python/core/PyObject; D E
F org/python/core/PyException H match (Lorg/python/core/PyObject;)Z J K
I L dummy_threading N importOneAs P /
Q java/lang/Throwable S org/python/core/PyList U org/python/core/PyObject W TCPServer Y UDPServer [ ForkingUDPServer ] ForkingTCPServer _ ThreadingUDPServer a ThreadingTCPServer c BaseRequestHandler e StreamRequestHandler g DatagramRequestHandler i ThreadingMixIn k ForkingMixIn m ([Lorg/python/core/PyObject;)V o p
V q __all__ s hasattr u AF_UNIX w __call__ m(Lorg/python/core/ThreadState;Lorg/python/core/PyObject;Lorg/python/core/PyObject;)Lorg/python/core/PyObject; y z
X { __nonzero__ ()Z } ~
X extend ? __getattr__ ? E
X ? UnixStreamServer ? UnixDatagramServer ? ThreadingUnixStreamServer ? ThreadingUnixDatagramServer ? S(Lorg/python/core/ThreadState;Lorg/python/core/PyObject;)Lorg/python/core/PyObject; y ?
X ? EmptyObjects [Lorg/python/core/PyObject; ? ? = ? org/python/core/PyFunction ? f_globals Lorg/python/core/PyObject; ? ? ? _eintr_retry$1 *restart a system call interrupted by EINTR ? getlocal (I)Lorg/python/core/PyObject; ? ?
?
_callextra ~([Lorg/python/core/PyObject;[Ljava/lang/String;Lorg/python/core/PyObject;Lorg/python/core/PyObject;)Lorg/python/core/PyObject; ? ?
X ? f_lasti I ? ? ? OSError ? getglobal ? E
? value ? ? I ? (ILorg/python/core/PyObject;)V % ?
? EINTR ? _ne 6(Lorg/python/core/PyObject;)Lorg/python/core/PyObject; ? ?
X ?
makeException ()Lorg/python/core/PyException; ? ?
= ? True ? None ? ? = ? future/backports/socketserver$py ? Lorg/python/core/PyCode; ? ? ? ? j(Lorg/python/core/PyObject;[Lorg/python/core/PyObject;Lorg/python/core/PyCode;Lorg/python/core/PyObject;)V o ?
? ? _eintr_retry ? object ?
BaseServer ? BaseServer$2
__module__ ? __name__ ??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 select()
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
Instance variables:
- RequestHandlerClass
- socket
? ? timeout ?
__init__$3 /Constructor. May be extended, do not override. ? server_address ? __setattr__ ?
X ? RequestHandlerClass ? Event ? 9(Lorg/python/core/ThreadState;)Lorg/python/core/PyObject; y ?
X ? _BaseServer__is_shut_down ? False ? _BaseServer__shutdown_request ? ? ? ? ? __init__ ? server_activate$4 SCalled by constructor to activate the server.
May be overridden.
? ? ? ? ? server_activate ??? newFloat (D)Lorg/python/core/PyFloat; ? ?
= serve_forever$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.
clear T(Lorg/python/core/ThreadState;[Lorg/python/core/PyObject;)Lorg/python/core/PyObject; y
X unpackSequence 8(Lorg/python/core/PyObject;I)[Lorg/python/core/PyObject;
= _in ?
X _handle_request_noblock service_actions __not__ ()Lorg/python/core/PyObject;
X set addTraceback 1(Ljava/lang/Throwable;Lorg/python/core/PyFrame;)V
= ? ?
serve_forever!
shutdown$6 ?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.
$ wait&# ? ?( shutdown* service_actions$7 ?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.
-, ? ?/ handle_request$8 OHandle one request, possibly blocking.
Respects self.timeout.
2
gettimeout4 _is6 ?
X7 _isnot9 ?
X: min<
newInteger (I)Lorg/python/core/PyInteger;>?
=@ __getitem__B ?
XC handle_timeoutE1 ? ?G handle_requestI _handle_request_noblock$9 ?Handle one request, without blocking.
I assume that select.select has returned that the socket is
readable before this function was called, so there should be
no risk of blocking in get_request().
L get_requestN errorP verify_requestR process_requestT handle_errorV shutdown_requestXK ? ?Z handle_timeout$10 cCalled if no new request arrives within self.timeout.
Overridden by ForkingMixIn.
]\ ? ?_ verify_request$11 nVerify the request. May be overridden.
Return True if we should proceed with this request.
ba ? ?d process_request$12 VCall finish_request.
Overridden by ForkingMixIn and ThreadingMixIn.
g finish_requestif ? ?k server_close$13 DCalled to clean-up the server.
May be overridden.
nm ? ?p server_closer finish_request$14 8Finish one request by instantiating RequestHandlerClass.u ?(Lorg/python/core/ThreadState;Lorg/python/core/PyObject;Lorg/python/core/PyObject;Lorg/python/core/PyObject;)Lorg/python/core/PyObject; yw
Xxt ? ?z shutdown_request$15 3Called to shutdown and close an individual request.}
close_request| ? ?? close_request$16 )Called to clean up an individual request.?? ? ?? handle_error$17 tHandle an error gracefully. May be overridden.
The default is to print a traceback and continue.
? print? -? _mul? ?
X? 4Exception happened during processing of request from? ? end? g(Lorg/python/core/ThreadState;[Lorg/python/core/PyObject;[Ljava/lang/String;)Lorg/python/core/PyObject; y?
X? traceback? print_exc?? ? ?? getf_locals?
? ? ? ?? makeClass a(Ljava/lang/String;[Lorg/python/core/PyObject;Lorg/python/core/PyCode;)Lorg/python/core/PyObject;??
=? java/util/Arrays? fill (([Ljava/lang/Object;Ljava/lang/Object;)V??
?? TCPServer$183Base 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
? AF_INET? address_family? SOCK_STREAM? socket_type? request_queue_size? allow_reuse_address? __init__$19 server_bind?? ? ?? server_bind$20 OCalled by constructor to bind the socket.
May be overridden.
?
setsockopt?
SOL_SOCKET? SO_REUSEADDR? bind? getsockname?? ? ?? server_activate$21 listen?? ? ?? server_close$22 close?? ? ?? fileno$23 MReturn socket file number.
Interface required by select().
? fileno?? ? ?? get_request$24 YGet the request and client address from the socket.
May be overridden.
? accept?? ? ?? shutdown_request$25 SHUT_WR?? ? ?? close_request$26? ? ??? ? ?? UDPServer$27 UDP server class.?
SOCK_DGRAM? max_packet_size? get_request$28 recvfrom? org/python/core/PyTuple?
q? ? ? server_activate$29 ? ? shutdown_request$30 ? ? close_request$31
? ?? ? ?
ForkingMixIn$32 5Mix-in class to handle each request in a new process. active_children max_children collect_children$33 7Internal routine to wait for children that have exited. waitpid _notin ?
X remove len _ge" ?
X# __iter__%
X& WNOHANG(
ValueError* %s. x=%d and list=%r, message. _mod0 ?
X1 9(Lorg/python/core/PyObject;)Lorg/python/core/PyException; ?3
=4 __iternext__6
X7 ? ?9 collect_children; handle_timeout$34 nWait for zombies after self.timeout seconds of inactivity.
May be extended, do not override.
>= ? ?@ service_actions$35 ?Collect the zombie child processes regularly in the ForkingMixIn.
service_actions is called in the BaseServer's serve_forver loop.
CB ? ?E process_request$36 -Fork a new subprocess to process the request.H forkJ appendL _exitNG ? ?P ? ?R ThreadingMixIn$37 4Mix-in class to handle each request in a new thread.U daemon_threadsW process_request_thread$38 gSame as in BaseServer but as a thread.
In addition, exception handling is done here.
ZY ? ?\ process_request_thread^ process_request$39 *Start a new thread to process the request.a Threadc targete argsg daemoni startk` ? ?mT ? ?o ForkingUDPServer$40q ? ?r ForkingTCPServer$41t ? ?u ThreadingUDPServer$42w ? ?x ThreadingTCPServer$43z ? ?{ UnixStreamServer$44} ? ?~ UnixDatagramServer$45? ? ?? ThreadingUnixStreamServer$46? ? ?? ThreadingUnixDatagramServer$47? ? ?? BaseRequestHandler$48?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.
? __init__$49 request? client_address? server? setup? handle? finish?? ? ?? setup$50? ? ?? handle$51? ? ?? finish$52? ? ??? ? ?? StreamRequestHandler$53 4Define self.rfile and self.wfile for stream sockets.? rbufsize? wbufsize? disable_nagle_algorithm? setup$54
connection?
settimeout? IPPROTO_TCP? TCP_NODELAY? makefile? rb? rfile? wb? wfile?? ? ?? finish$55 closed? flush?? ? ??? ? ?? DatagramRequestHandler$56 6Define self.rfile and self.wfile for datagram sockets.? setup$57 io? BytesIO? packet?? ? ?? finish$58 sendto? getvalue?? ? ??? ? ?? (Ljava/lang/String;)V org/python/core/PyFunctionTable? ()V o?
?? self "Lfuture/backports/socketserver$py;?? ?? ? newCode ?(I[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZLorg/python/core/PyFunctionTable;I[Ljava/lang/String;[Ljava/lang/String;II)Lorg/python/core/PyCode;??
=? ? ?? func? e??
poll_interval? r? w? fd_sets? bind_and_activate data client_addr pid status child t
getMain ()Lorg/python/core/PyCode; main ([Ljava/lang/String;)V ? o?
?
? org/python/core/CodeLoader createSimpleBootstrap 9(Lorg/python/core/PyCode;)Lorg/python/core/CodeBootstrap;
runMain 5(Lorg/python/core/CodeBootstrap;[Ljava/lang/String;)V
= getCodeBootstrap !()Lorg/python/core/CodeBootstrap; #org/python/core/PyRunnableBootstrap$ )getFilenameConstructorReflectionBootstrap 2(Ljava/lang/Class;)Lorg/python/core/CodeBootstrap;&'
%(
call_function S(ILorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;
?, ?
?. ?
?0 ?
?2 ?
?4
?6#
?8,
?:1
?<K
?>\
?@a
?Bf
?Dm
?Ft
?H|
?J?
?L?
?N?
?P?
?R?
?T?
?V?
?X?
?Z?
?\?
?^?
?`?
?b?
?d
?f
?h
?j
?l
?n=
?pB
?rG
?tT
?vY
?x`
?zq
?|t
?~w
??z
??}
???
???
???
???
???
???
???
???
???
???
???
???
???
???
?? org/python/core/PyRunnable? Lorg/python/compiler/APIVersion; % Lorg/python/compiler/MTime; `9 G? Lorg/python/compiler/Filename; g/home/trustin/Workspaces/sphinx-maven-plugin/target/update-sphinx/dist/future/backports/socketserver.py org/python/core/ThreadState? ? Code LineNumberTable StackMap
SourceFile RuntimeVisibleAnnotations ! ?? ? <