/snap/core20/2769/usr/lib/python3.8/__pycache__
NameSizeModeActions
abc.cpython-38.pyc53340644editdlrm
aifc.cpython-38.pyc254740644editdlrm
antigravity.cpython-38.pyc7970644editdlrm
argparse.cpython-38.pyc625910644editdlrm
ast.cpython-38.pyc167630644editdlrm
asynchat.cpython-38.pyc68510644editdlrm
asyncore.cpython-38.pyc160280644editdlrm
base64.cpython-38.pyc170710644editdlrm
bdb.cpython-38.pyc249210644editdlrm
binhex.cpython-38.pyc121340644editdlrm
bisect.cpython-38.pyc23540644editdlrm
bz2.cpython-38.pyc114450644editdlrm
calendar.cpython-38.pyc270640644editdlrm
cgi.cpython-38.pyc265440644editdlrm
cgitb.cpython-38.pyc101500644editdlrm
chunk.cpython-38.pyc48390644editdlrm
cmd.cpython-38.pyc126260644editdlrm
code.cpython-38.pyc99130644editdlrm
codecs.cpython-38.pyc339560644editdlrm
codeop.cpython-38.pyc64170644editdlrm
colorsys.cpython-38.pyc32400644editdlrm
compileall.cpython-38.pyc94100644editdlrm
configparser.cpython-38.pyc457180644editdlrm
contextlib.cpython-38.pyc202290644editdlrm
contextvars.cpython-38.pyc2430644editdlrm
copy.cpython-38.pyc69870644editdlrm
copyreg.cpython-38.pyc43180644editdlrm
cProfile.cpython-38.pyc54800644editdlrm
crypt.cpython-38.pyc33870644editdlrm
csv.cpython-38.pyc119100644editdlrm
dataclasses.cpython-38.pyc236530644editdlrm
datetime.cpython-38.pyc571730644editdlrm
decimal.cpython-38.pyc3590644editdlrm
difflib.cpython-38.pyc594380644editdlrm
dis.cpython-38.pyc158080644editdlrm
doctest.cpython-38.pyc759740644editdlrm
dummy_threading.cpython-38.pyc11100644editdlrm
enum.cpython-38.pyc259620644editdlrm
filecmp.cpython-38.pyc84270644editdlrm
fileinput.cpython-38.pyc133730644editdlrm
fnmatch.cpython-38.pyc33550644editdlrm
formatter.cpython-38.pyc175450644editdlrm
fractions.cpython-38.pyc187390644editdlrm
ftplib.cpython-38.pyc280070644editdlrm
functools.cpython-38.pyc279010644editdlrm
genericpath.cpython-38.pyc40010644editdlrm
getopt.cpython-38.pyc62710644editdlrm
getpass.cpython-38.pyc41780644editdlrm
gettext.cpython-38.pyc180000644editdlrm
glob.cpython-38.pyc43430644editdlrm
gzip.cpython-38.pyc181840644editdlrm
hashlib.cpython-38.pyc67270644editdlrm
heapq.cpython-38.pyc140700644editdlrm
hmac.cpython-38.pyc63880644editdlrm
imaplib.cpython-38.pyc414640644editdlrm
imghdr.cpython-38.pyc41180644editdlrm
imp.cpython-38.pyc98090644editdlrm
inspect.cpython-38.pyc805930644editdlrm
io.cpython-38.pyc34540644editdlrm
ipaddress.cpython-38.pyc628290644editdlrm
keyword.cpython-38.pyc9980644editdlrm
linecache.cpython-38.pyc38670644editdlrm
locale.cpython-38.pyc346740644editdlrm
lzma.cpython-38.pyc120180644editdlrm
mailbox.cpython-38.pyc602640644editdlrm
mailcap.cpython-38.pyc72060644editdlrm
mimetypes.cpython-38.pyc160310644editdlrm
modulefinder.cpython-38.pyc161150644editdlrm
netrc.cpython-38.pyc37770644editdlrm
nntplib.cpython-38.pyc339740644editdlrm
ntpath.cpython-38.pyc140910644editdlrm
nturl2path.cpython-38.pyc17440644editdlrm
numbers.cpython-38.pyc122020644editdlrm
opcode.cpython-38.pyc54200644editdlrm
operator.cpython-38.pyc136910644editdlrm
optparse.cpython-38.pyc480570644editdlrm
os.cpython-38.pyc313970644editdlrm
pathlib.cpython-38.pyc442090644editdlrm
pdb.cpython-38.pyc472260644editdlrm
pickle.cpython-38.pyc469080644editdlrm
pickletools.cpython-38.pyc672040644editdlrm
pipes.cpython-38.pyc77950644editdlrm
pkgutil.cpython-38.pyc163090644editdlrm
platform.cpython-38.pyc243260644editdlrm
plistlib.cpython-38.pyc273740644editdlrm
poplib.cpython-38.pyc135560644editdlrm
posixpath.cpython-38.pyc104610644editdlrm
pprint.cpython-38.pyc162810644editdlrm
profile.cpython-38.pyc147580644editdlrm
pstats.cpython-38.pyc220660644editdlrm
pty.cpython-38.pyc39550644editdlrm
pyclbr.cpython-38.pyc104510644editdlrm
pydoc.cpython-38.pyc836460644editdlrm
py_compile.cpython-38.pyc73520644editdlrm
queue.cpython-38.pyc106260644editdlrm
quopri.cpython-38.pyc57480644editdlrm
random.cpython-38.pyc201080644editdlrm
re.cpython-38.pyc144220644editdlrm
reprlib.cpython-38.pyc53030644editdlrm
rlcompleter.cpython-38.pyc57550644editdlrm
runpy.cpython-38.pyc81810644editdlrm
sched.cpython-38.pyc65320644editdlrm
secrets.cpython-38.pyc21900644editdlrm
selectors.cpython-38.pyc169350644editdlrm
shelve.cpython-38.pyc94900644editdlrm
shlex.cpython-38.pyc75360644editdlrm
shutil.cpython-38.pyc372190644editdlrm
signal.cpython-38.pyc28430644editdlrm
site.cpython-38.pyc171680644editdlrm
sitecustomize.cpython-38.pyc2200644editdlrm
smtpd.cpython-38.pyc264630644editdlrm
smtplib.cpython-38.pyc355320644editdlrm
sndhdr.cpython-38.pyc69890644editdlrm
socket.cpython-38.pyc277870644editdlrm
socketserver.cpython-38.pyc253610644editdlrm
sre_compile.cpython-38.pyc151420644editdlrm
sre_constants.cpython-38.pyc63590644editdlrm
sre_parse.cpython-38.pyc216470644editdlrm
ssl.cpython-38.pyc450370644editdlrm
stat.cpython-38.pyc43720644editdlrm
statistics.cpython-38.pyc336530644editdlrm
string.cpython-38.pyc73000644editdlrm
stringprep.cpython-38.pyc110170644editdlrm
struct.cpython-38.pyc3300644editdlrm
subprocess.cpython-38.pyc419670644editdlrm
sunau.cpython-38.pyc170800644editdlrm
symbol.cpython-38.pyc24040644editdlrm
symtable.cpython-38.pyc113220644editdlrm
sysconfig.cpython-38.pyc158370644editdlrm
tabnanny.cpython-38.pyc70300644editdlrm
tarfile.cpython-38.pyc630430644editdlrm
telnetlib.cpython-38.pyc182370644editdlrm
tempfile.cpython-38.pyc266530644editdlrm
textwrap.cpython-38.pyc135190644editdlrm
this.cpython-38.pyc12610644editdlrm
threading.cpython-38.pyc399760644editdlrm
timeit.cpython-38.pyc117770644editdlrm
token.cpython-38.pyc24850644editdlrm
tokenize.cpython-38.pyc171600644editdlrm
trace.cpython-38.pyc200260644editdlrm
traceback.cpython-38.pyc199380644editdlrm
tracemalloc.cpython-38.pyc173630644editdlrm
tty.cpython-38.pyc10760644editdlrm
turtle.cpython-38.pyc1300220644editdlrm
types.cpython-38.pyc91770644editdlrm
typing.cpython-38.pyc624200644editdlrm
uu.cpython-38.pyc36050644editdlrm
uuid.cpython-38.pyc236830644editdlrm
warnings.cpython-38.pyc136520644editdlrm
wave.cpython-38.pyc181490644editdlrm
weakref.cpython-38.pyc195180644editdlrm
webbrowser.cpython-38.pyc171200644editdlrm
xdrlib.cpython-38.pyc82210644editdlrm
zipapp.cpython-38.pyc58540644editdlrm
zipfile.cpython-38.pyc593360644editdlrm
zipimport.cpython-38.pyc172750644editdlrm
_bootlocale.cpython-38.pyc12430644editdlrm
_collections_abc.cpython-38.pyc287410644editdlrm
_compat_pickle.cpython-38.pyc55010644editdlrm
_compression.cpython-38.pyc41460644editdlrm
_dummy_thread.cpython-38.pyc60370644editdlrm
_markupbase.cpython-38.pyc77900644editdlrm
_osx_support.cpython-38.pyc115930644editdlrm
_pydecimal.cpython-38.pyc1607350644editdlrm
_pyio.cpython-38.pyc740790644editdlrm
_py_abc.cpython-38.pyc46700644editdlrm
_sitebuiltins.cpython-38.pyc34810644editdlrm
_strptime.cpython-38.pyc160440644editdlrm
_sysconfigdata__linux_x86_64-linux-gnu.cpython-38.pyc211210644editdlrm
_sysconfigdata__x86_64-linux-gnu.cpython-38.pyc211150644editdlrm
_threading_local.cpython-38.pyc64460644editdlrm
_weakrefset.cpython-38.pyc76000644editdlrm
__future__.cpython-38.pyc41580644editdlrm
__phello__.foo.cpython-38.pyc1270644editdlrm
Edit: /snap/core20/2769/usr/lib/python3.8/__pycache__/socketserver.cpython-38.pyc (25361B)
U yi jã @sdZdZddlZddlZddlZddlZddlZddlmZddl m Z dddd d d d d dg Z e edƒrxe   dddg¡e edƒr”e   ddddg¡e edƒr¦ejZnejZGdd„dƒZGdd„deƒZGdd„deƒZe edƒròGdd„dƒZGdd„deƒZGdd „d ƒZGd!d„dƒZe edƒrNGd"d„deeƒZGd#d„deeƒZGd$d „d eeƒZGd%d „d eeƒZe edƒrÂGd&d„deƒZGd'd„deƒZGd(d„deeƒZGd)d„deeƒZ Gd*d „d ƒZ!Gd+d „d e!ƒZ"Gd,d-„d-eƒZ#Gd.d „d e!ƒZ$dS)/aqGeneric 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 saves 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 a selector 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 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. z0.4éN)ÚBufferedIOBase)Ú monotonicÚ BaseServerÚ TCPServerÚ UDPServerÚThreadingUDPServerÚThreadingTCPServerÚBaseRequestHandlerÚStreamRequestHandlerÚDatagramRequestHandlerÚThreadingMixInÚforkÚForkingUDPServerÚForkingTCPServerÚ ForkingMixInÚAF_UNIXÚUnixStreamServerÚUnixDatagramServerÚThreadingUnixStreamServerÚThreadingUnixDatagramServerÚ PollSelectorc@sžeZdZdZdZdd„Zdd„Zd&dd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„ZdS)'ra¸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 selector 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 NcCs ||_||_t ¡|_d|_dS)ú/Constructor. May be extended, do not override.FN)Úserver_addressÚRequestHandlerClassÚ threadingZEventÚ_BaseServer__is_shut_downÚ_BaseServer__shutdown_request)Úselfrr©rú"/usr/lib/python3.8/socketserver.pyÚ__init__Ès zBaseServer.__init__cCsdS©zSCalled by constructor to activate the server. May be overridden. Nr©rrrrÚserver_activateÏszBaseServer.server_activateçà?c Cst|j ¡zRtƒB}| |tj¡|jsP| |¡}|jr:qP|rF|  ¡|  ¡q"W5QRXW5d|_|j ¡XdS)zÑ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. FN) rÚclearrÚsetÚ_ServerSelectorÚregisterÚ selectorsÚ EVENT_READÚselectÚ_handle_request_noblockÚservice_actions)rZ poll_intervalÚselectorÚreadyrrrÚ serve_forever×s  zBaseServer.serve_forevercCsd|_|j ¡dS)zÀ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. TN)rrÚwaitr"rrrÚshutdownôszBaseServer.shutdowncCsdS)z¡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. Nrr"rrrr-þszBaseServer.service_actionsc Cs¸|j ¡}|dkr|j}n|jdk r0t||jƒ}|dk rBtƒ|}tƒf}| |tj¡|  |¡}|rz|  ¡W5QR£S|dk rX|tƒ}|dkrX|  ¡W5QR£SqXW5QRXdS)zOHandle one request, possibly blocking. Respects self.timeout. Nr) ÚsocketZ gettimeoutÚtimeoutÚminÚtimer'r(r)r*r+r,Úhandle_timeout)rr4Zdeadliner.r/rrrÚhandle_requests       zBaseServer.handle_requestcCs–z| ¡\}}Wntk r&YdSX| ||¡rˆz| ||¡Wq’tk rn| ||¡| |¡Yq’| |¡‚Yq’Xn | |¡dS)zêHandle one request, without blocking. I assume that selector.select() has returned that the socket is readable before this function was called, so there should be no risk of blocking in get_request(). N)Ú get_requestÚOSErrorÚverify_requestÚprocess_requestÚ ExceptionÚ handle_errorÚshutdown_request©rÚrequestÚclient_addressrrrr,/s    z"BaseServer._handle_request_noblockcCsdS)zcCalled if no new request arrives within self.timeout. Overridden by ForkingMixIn. Nrr"rrrr7FszBaseServer.handle_timeoutcCsdS)znVerify the request. May be overridden. Return True if we should proceed with this request. Trr@rrrr;MszBaseServer.verify_requestcCs| ||¡| |¡dS)zVCall finish_request. Overridden by ForkingMixIn and ThreadingMixIn. N)Úfinish_requestr?r@rrrr<Us zBaseServer.process_requestcCsdS©zDCalled to clean-up the server. May be overridden. Nrr"rrrÚ server_close^szBaseServer.server_closecCs| |||¡dS)z8Finish one request by instantiating RequestHandlerClass.N)rr@rrrrCfszBaseServer.finish_requestcCs| |¡dS©z3Called to shutdown and close an individual request.N©Ú close_request©rrArrrr?jszBaseServer.shutdown_requestcCsdS©z)Called to clean up an individual request.NrrIrrrrHnszBaseServer.close_requestcCs@tdtjdtd|tjdddl}| ¡tdtjddS)ztHandle an error gracefully. May be overridden. The default is to print a traceback and continue. z(----------------------------------------)Úfilez4Exception happened during processing of request fromrN)ÚprintÚsysÚstderrÚ tracebackÚ print_exc)rrArBrOrrrr>rsÿzBaseServer.handle_errorcCs|S©Nrr"rrrÚ __enter__szBaseServer.__enter__cGs | ¡dSrQ)rE)rÚargsrrrÚ__exit__‚szBaseServer.__exit__)r$)Ú__name__Ú __module__Ú __qualname__Ú__doc__r4r r#r0r2r-r8r,r7r;r<rErCr?rHr>rRrTrrrrr™s&+    c@sfeZdZdZejZejZdZ dZ ddd„Z dd„Z d d „Z d d „Zd d„Zdd„Zdd„Zdd„ZdS)ra3Base 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 selector 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 éFTcCsTt |||¡t |j|j¡|_|rPz| ¡| ¡Wn| ¡‚YnXdS)rN)rr r3Úaddress_familyÚ socket_typeÚ server_bindr#rE)rrrZbind_and_activaterrrr ½sÿ zTCPServer.__init__cCs8|jr|j tjtjd¡|j |j¡|j ¡|_dS)zOCalled by constructor to bind the socket. May be overridden. éN)Úallow_reuse_addressr3Ú setsockoptZ SOL_SOCKETZ SO_REUSEADDRZbindrZ getsocknamer"rrrr\ÊszTCPServer.server_bindcCs|j |j¡dSr!)r3ZlistenÚrequest_queue_sizer"rrrr#ÕszTCPServer.server_activatecCs|j ¡dSrD)r3Úcloser"rrrrEÝszTCPServer.server_closecCs |j ¡S)zMReturn socket file number. Interface required by selector. )r3Úfilenor"rrrrbåszTCPServer.filenocCs |j ¡S)zYGet the request and client address from the socket. May be overridden. )r3Zacceptr"rrrr9íszTCPServer.get_requestcCs4z| tj¡Wntk r$YnX| |¡dSrF)r2r3ZSHUT_WRr:rHrIrrrr?õs zTCPServer.shutdown_requestcCs | ¡dSrJ)rarIrrrrHÿszTCPServer.close_requestN)T)rUrVrWrXr3ZAF_INETrZZ SOCK_STREAMr[r`r^r r\r#rErbr9r?rHrrrrr†s-   c@s>eZdZdZdZejZdZdd„Z dd„Z dd „Z d d „Z d S) rzUDP server class.Fi cCs |j |j¡\}}||jf|fSrQ)r3ZrecvfromÚmax_packet_size)rÚdataZ client_addrrrrr9szUDPServer.get_requestcCsdSrQrr"rrrr#szUDPServer.server_activatecCs| |¡dSrQrGrIrrrr?szUDPServer.shutdown_requestcCsdSrQrrIrrrrHszUDPServer.close_requestN) rUrVrWrXr^r3Z SOCK_DGRAMr[rcr9r#r?rHrrrrrscsVeZdZdZdZdZdZdZddœdd „Zd d „Z d d „Z dd„Z ‡fdd„Z ‡Z S)rz5Mix-in class to handle each request in a new process.i,Né(TF©Úblockingc Csì|jdkrdSt|jƒ|jkrvz t dd¡\}}|j |¡Wqtk r\|j ¡Yqtk rrYqvYqXq|j  ¡D]f}z.|rŽdntj }t ||¡\}}|j |¡Wq€tk rÒ|j |¡Yq€tk räYq€Xq€dS)z7Internal routine to wait for children that have exited.Néÿÿÿÿr) Úactive_childrenÚlenÚ max_childrenÚosÚwaitpidÚdiscardÚChildProcessErrorr%r:ÚcopyÚWNOHANG)rrgÚpidÚ_ÚflagsrrrÚcollect_children(s&  zForkingMixIn.collect_childrencCs | ¡dS)zvWait for zombies after self.timeout seconds of inactivity. May be extended, do not override. N©rur"rrrr7KszForkingMixIn.handle_timeoutcCs | ¡dS)zCollect the zombie child processes regularly in the ForkingMixIn. service_actions is called in the BaseServer's serve_forever loop. Nrvr"rrrr-RszForkingMixIn.service_actionscCsšt ¡}|r8|jdkrtƒ|_|j |¡| |¡dSd}z:z| ||¡d}Wn t k rr|  ||¡YnXW5z| |¡W5t |¡XXdS)z-Fork a new subprocess to process the request.Nr]r) rlr rir&ÚaddrHÚ_exitr?rCr=r>)rrArBrrZstatusrrrr<Ys     zForkingMixIn.process_requestcstƒ ¡|j|jddS)Nrf)ÚsuperrEruÚblock_on_closer"©Ú __class__rrrErs zForkingMixIn.server_close)rUrVrWrXr4rirkrzrur7r-r<rEÚ __classcell__rrr{rrs#cs8eZdZdZ‡fdd„Zdd„Zdd„Zdd „Z‡ZS) Ú_Threadsz2 Joinable list of all non-daemon threads. cs"| ¡|jrdStƒ |¡dSrQ)ÚreapÚdaemonryÚappend©rÚthreadr{rrr{sz_Threads.appendcCsg|dd…|dd…<}|SrQr)rÚresultrrrÚpop_allsz_Threads.pop_allcCs| ¡D] }| ¡qdSrQ)r…Újoinr‚rrrr†…s z _Threads.joincCsdd„|Dƒ|dd…<dS)Ncss|]}| ¡r|VqdSrQ)Zis_alive)Ú.0rƒrrrÚ Šsz _Threads.reap..rr"rrrr‰sz _Threads.reap) rUrVrWrXrr…r†rr}rrr{rr~ws  r~c@s eZdZdZdd„Zdd„ZdS)Ú _NoThreadsz) Degenerate version of _Threads. cCsdSrQrr‚rrrr‘sz_NoThreads.appendcCsdSrQrr"rrrr†”sz_NoThreads.joinN)rUrVrWrXrr†rrrrr‰sr‰cs>eZdZdZdZdZeƒZdd„Zdd„Z ‡fdd „Z ‡Z S) r z4Mix-in class to handle each request in a new thread.FTc CsHz6z| ||¡Wn tk r2| ||¡YnXW5| |¡XdS)zgSame as in BaseServer but as a thread. In addition, exception handling is done here. N)r?rCr=r>r@rrrÚprocess_request_thread¤s z%ThreadingMixIn.process_request_threadcCsL|jrt|ƒ dtƒ¡tj|j||fd}|j|_|j   |¡|  ¡dS)z*Start a new thread to process the request.Ú_threads)ÚtargetrSN) rzÚvarsÚ setdefaultr~rZThreadrŠÚdaemon_threadsr€r‹rÚstart)rrArBÚtrrrr<±sÿ zThreadingMixIn.process_requestcstƒ ¡|j ¡dSrQ)ryrEr‹r†r"r{rrrE»s zThreadingMixIn.server_close) rUrVrWrXrrzr‰r‹rŠr<rEr}rrr{rr ˜s  c@s eZdZdS)rN©rUrVrWrrrrrÁsc@s eZdZdS)rNr’rrrrrÂsc@s eZdZdS)rNr’rrrrrÄsc@s eZdZdS)rNr’rrrrrÅsc@seZdZejZdS)rN©rUrVrWr3rrZrrrrrÉsc@seZdZejZdS)rNr“rrrrrÌsc@s eZdZdS)rNr’rrrrrÏsc@s eZdZdS)rNr’rrrrrÑsc@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) r a¥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 other arbitrary instance variables. cCs6||_||_||_| ¡z | ¡W5| ¡XdSrQ)rArBÚserverÚsetupÚfinishÚhandle)rrArBr”rrrr ås zBaseRequestHandler.__init__cCsdSrQrr"rrrr•ïszBaseRequestHandler.setupcCsdSrQrr"rrrr—òszBaseRequestHandler.handlecCsdSrQrr"rrrr–õszBaseRequestHandler.finishN)rUrVrWrXr r•r—r–rrrrr Ós  c@s0eZdZdZdZdZdZdZdd„Zdd „Z dS) r z4Define self.rfile and self.wfile for stream sockets.rhrNFcCsz|j|_|jdk r |j |j¡|jr:|j tjtjd¡|j  d|j ¡|_ |j dkrdt |jƒ|_n|j  d|j ¡|_dS)NTÚrbrÚwb)rAZ connectionr4Z settimeoutÚdisable_nagle_algorithmr_r3Z IPPROTO_TCPZ TCP_NODELAYZmakefileÚrbufsizeÚrfileÚwbufsizeÚ _SocketWriterÚwfiler"rrrr•s  ÿ zStreamRequestHandler.setupcCsF|jjs.z|j ¡Wntjk r,YnX|j ¡|j ¡dSrQ)rŸÚclosedÚflushr3Úerrorrarœr"rrrr–#s zStreamRequestHandler.finish) rUrVrWrXr›rr4ršr•r–rrrrr s  c@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) ržz‚Simple writable BufferedIOBase implementation for a socket Does not hold data in a buffer, avoiding any need to call flush().cCs ||_dSrQ)Ú_sock)rZsockrrrr 3sz_SocketWriter.__init__cCsdS)NTrr"rrrÚwritable6sz_SocketWriter.writablec Cs2|j |¡t|ƒ}|jW5QR£SQRXdSrQ)r£ZsendallÚ memoryviewÚnbytes)rÚbZviewrrrÚwrite9s  z_SocketWriter.writecCs |j ¡SrQ)r£rbr"rrrrb>sz_SocketWriter.filenoN)rUrVrWrXr r¤r¨rbrrrrrž.s ržc@s eZdZdZdd„Zdd„ZdS)r z6Define self.rfile and self.wfile for datagram sockets.cCs2ddlm}|j\|_|_||jƒ|_|ƒ|_dS)Nr)ÚBytesIO)Úior©rAZpacketr3rœrŸ)rr©rrrr•Es  zDatagramRequestHandler.setupcCs|j |j ¡|j¡dSrQ)r3ZsendtorŸÚgetvaluerBr"rrrr–KszDatagramRequestHandler.finishN)rUrVrWrXr•r–rrrrr As)%rXÚ __version__r3r)rlrMrrªrr6rÚ__all__ÚhasattrÚextendrr'ZSelectSelectorrrrrÚlistr~r‰r rrrrrrrrr r ržr rrrrÚsbz  ý  þ n~ X (  .-