/snap/core22/2437/usr/lib/python3.10/__pycache__
NameSizeModeActions
abc.cpython-310.pyc67510644editdlrm
aifc.cpython-310.pyc246850644editdlrm
antigravity.cpython-310.pyc8220644editdlrm
argparse.cpython-310.pyc635390644editdlrm
ast.cpython-310.pyc557390644editdlrm
asynchat.cpython-310.pyc70250644editdlrm
asyncore.cpython-310.pyc160020644editdlrm
base64.cpython-310.pyc171620644editdlrm
bdb.cpython-310.pyc258320644editdlrm
binhex.cpython-310.pyc128700644editdlrm
bisect.cpython-310.pyc25880644editdlrm
bz2.cpython-310.pyc108700644editdlrm
calendar.cpython-310.pyc263030644editdlrm
cgi.cpython-310.pyc267230644editdlrm
cgitb.cpython-310.pyc99980644editdlrm
chunk.cpython-310.pyc48600644editdlrm
cmd.cpython-310.pyc127070644editdlrm
code.cpython-310.pyc99570644editdlrm
codecs.cpython-310.pyc332190644editdlrm
codeop.cpython-310.pyc55950644editdlrm
colorsys.cpython-310.pyc32650644editdlrm
compileall.cpython-310.pyc127330644editdlrm
configparser.cpython-310.pyc454580644editdlrm
contextlib.cpython-310.pyc208950644editdlrm
contextvars.cpython-310.pyc2460644editdlrm
copy.cpython-310.pyc69960644editdlrm
copyreg.cpython-310.pyc46830644editdlrm
cProfile.cpython-310.pyc51130644editdlrm
crypt.cpython-310.pyc35500644editdlrm
csv.cpython-310.pyc117980644editdlrm
dataclasses.cpython-310.pyc265780644editdlrm
datetime.cpython-310.pyc565330644editdlrm
decimal.cpython-310.pyc3620644editdlrm
difflib.cpython-310.pyc589050644editdlrm
dis.cpython-310.pyc156560644editdlrm
doctest.cpython-310.pyc761750644editdlrm
enum.cpython-310.pyc260630644editdlrm
filecmp.cpython-310.pyc87490644editdlrm
fileinput.cpython-310.pyc140720644editdlrm
fnmatch.cpython-310.pyc42440644editdlrm
fractions.cpython-310.pyc186000644editdlrm
ftplib.cpython-310.pyc289770644editdlrm
functools.cpython-310.pyc283350644editdlrm
genericpath.cpython-310.pyc39070644editdlrm
getopt.cpython-310.pyc63390644editdlrm
getpass.cpython-310.pyc42100644editdlrm
gettext.cpython-310.pyc182210644editdlrm
glob.cpython-310.pyc58520644editdlrm
graphlib.cpython-310.pyc76160644editdlrm
gzip.cpython-310.pyc185460644editdlrm
hashlib.cpython-310.pyc68450644editdlrm
heapq.cpython-310.pyc138650644editdlrm
hmac.cpython-310.pyc69730644editdlrm
imaplib.cpython-310.pyc423120644editdlrm
imghdr.cpython-310.pyc39050644editdlrm
imp.cpython-310.pyc97860644editdlrm
inspect.cpython-310.pyc851530644editdlrm
io.cpython-310.pyc36630644editdlrm
ipaddress.cpython-310.pyc626700644editdlrm
keyword.cpython-310.pyc9270644editdlrm
linecache.cpython-310.pyc41420644editdlrm
locale.cpython-310.pyc461540644editdlrm
lzma.cpython-310.pyc121000644editdlrm
mailbox.cpython-310.pyc600910644editdlrm
mailcap.cpython-310.pyc73200644editdlrm
mimetypes.cpython-310.pyc176190644editdlrm
modulefinder.cpython-310.pyc161660644editdlrm
netrc.cpython-310.pyc39330644editdlrm
nntplib.cpython-310.pyc316230644editdlrm
ntpath.cpython-310.pyc147040644editdlrm
nturl2path.cpython-310.pyc17470644editdlrm
numbers.cpython-310.pyc118660644editdlrm
opcode.cpython-310.pyc54470644editdlrm
operator.cpython-310.pyc135080644editdlrm
optparse.cpython-310.pyc477540644editdlrm
os.cpython-310.pyc315990644editdlrm
pathlib.cpython-310.pyc420520644editdlrm
pdb.cpython-310.pyc474400644editdlrm
pickle.cpython-310.pyc468820644editdlrm
pickletools.cpython-310.pyc677600644editdlrm
pipes.cpython-310.pyc77690644editdlrm
pkgutil.cpython-310.pyc183610644editdlrm
platform.cpython-310.pyc274290644editdlrm
plistlib.cpython-310.pyc237650644editdlrm
poplib.cpython-310.pyc135730644editdlrm
posixpath.cpython-310.pyc105600644editdlrm
pprint.cpython-310.pyc178750644editdlrm
profile.cpython-310.pyc143910644editdlrm
pstats.cpython-310.pyc236210644editdlrm
pty.cpython-310.pyc41430644editdlrm
pyclbr.cpython-310.pyc97750644editdlrm
pydoc.cpython-310.pyc856450644editdlrm
py_compile.cpython-310.pyc73390644editdlrm
queue.cpython-310.pyc107920644editdlrm
quopri.cpython-310.pyc57940644editdlrm
random.cpython-310.pyc227480644editdlrm
re.cpython-310.pyc142270644editdlrm
reprlib.cpython-310.pyc52500644editdlrm
rlcompleter.cpython-310.pyc59540644editdlrm
runpy.cpython-310.pyc94110644editdlrm
sched.cpython-310.pyc61150644editdlrm
secrets.cpython-310.pyc21750644editdlrm
selectors.cpython-310.pyc171050644editdlrm
shelve.cpython-310.pyc94920644editdlrm
shlex.cpython-310.pyc77820644editdlrm
shutil.cpython-310.pyc385360644editdlrm
signal.cpython-310.pyc29350644editdlrm
site.cpython-310.pyc179220644editdlrm
sitecustomize.cpython-310.pyc2250644editdlrm
smtpd.cpython-310.pyc261470644editdlrm
smtplib.cpython-310.pyc357660644editdlrm
sndhdr.cpython-310.pyc69620644editdlrm
socket.cpython-310.pyc289630644editdlrm
socketserver.cpython-310.pyc253470644editdlrm
sre_compile.cpython-310.pyc151940644editdlrm
sre_constants.cpython-310.pyc63570644editdlrm
sre_parse.cpython-310.pyc217550644editdlrm
ssl.cpython-310.pyc452710644editdlrm
stat.cpython-310.pyc42730644editdlrm
statistics.cpython-310.pyc370510644editdlrm
string.cpython-310.pyc71020644editdlrm
stringprep.cpython-310.pyc170750644editdlrm
struct.cpython-310.pyc3070644editdlrm
subprocess.cpython-310.pyc447410644editdlrm
sunau.cpython-310.pyc164820644editdlrm
symtable.cpython-310.pyc128350644editdlrm
sysconfig.cpython-310.pyc181510644editdlrm
tabnanny.cpython-310.pyc69500644editdlrm
tarfile.cpython-310.pyc706740644editdlrm
telnetlib.cpython-310.pyc185060644editdlrm
tempfile.cpython-310.pyc273390644editdlrm
textwrap.cpython-310.pyc138120644editdlrm
this.cpython-310.pyc12640644editdlrm
threading.cpython-310.pyc449690644editdlrm
timeit.cpython-310.pyc117690644editdlrm
token.cpython-310.pyc27380644editdlrm
tokenize.cpython-310.pyc171940644editdlrm
trace.cpython-310.pyc198700644editdlrm
traceback.cpython-310.pyc217120644editdlrm
tracemalloc.cpython-310.pyc175250644editdlrm
tty.cpython-310.pyc10790644editdlrm
turtle.cpython-310.pyc1288570644editdlrm
types.cpython-310.pyc95250644editdlrm
typing.cpython-310.pyc852770644editdlrm
uu.cpython-310.pyc38670644editdlrm
uuid.cpython-310.pyc224980644editdlrm
warnings.cpython-310.pyc136460644editdlrm
wave.cpython-310.pyc175940644editdlrm
weakref.cpython-310.pyc203430644editdlrm
webbrowser.cpython-310.pyc170000644editdlrm
xdrlib.cpython-310.pyc78800644editdlrm
zipapp.cpython-310.pyc60130644editdlrm
zipfile.cpython-310.pyc618450644editdlrm
zipimport.cpython-310.pyc170330644editdlrm
_aix_support.cpython-310.pyc28790644editdlrm
_bootsubprocess.cpython-310.pyc22940644editdlrm
_collections_abc.cpython-310.pyc329250644editdlrm
_compat_pickle.cpython-310.pyc58720644editdlrm
_compression.cpython-310.pyc45120644editdlrm
_distutils_system_mod.cpython-310.pyc54220644editdlrm
_markupbase.cpython-310.pyc75720644editdlrm
_osx_support.cpython-310.pyc115350644editdlrm
_pydecimal.cpython-310.pyc1577360644editdlrm
_pyio.cpython-310.pyc736540644editdlrm
_py_abc.cpython-310.pyc46830644editdlrm
_sitebuiltins.cpython-310.pyc35470644editdlrm
_strptime.cpython-310.pyc159450644editdlrm
_sysconfigdata__linux_x86_64-linux-gnu.cpython-310.pyc353850644editdlrm
_sysconfigdata__x86_64-linux-gnu.cpython-310.pyc353790644editdlrm
_threading_local.cpython-310.pyc65390644editdlrm
_weakrefset.cpython-310.pyc76080644editdlrm
__future__.cpython-310.pyc41310644editdlrm
__phello__.foo.cpython-310.pyc1300644editdlrm
Edit: /snap/core22/2437/usr/lib/python3.10/__pycache__/socketserver.cpython-310.pyc (25347B)
o p̦ij@sdZdZddlZddlZddlZddlZddlZddlmZddl m Z gdZ e edr4e gde ed r@e gd e ed rIejZnejZGd d d ZGdddeZGdddeZe edroGdddZGdddeZGdddZGdddZe edrGdddeeZGdddeeZGdddeeZGd d!d!eeZe ed rGd"d#d#eZGd$d%d%eZGd&d'd'eeZGd(d)d)eeZ Gd*d+d+Z!Gd,d-d-e!Z"Gd.d/d/eZ#Gd0d1d1e!Z$dS)2aqGeneric 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.4N)BufferedIOBase) monotonic) BaseServer TCPServer UDPServerThreadingUDPServerThreadingTCPServerBaseRequestHandlerStreamRequestHandlerDatagramRequestHandlerThreadingMixInfork)ForkingUDPServerForkingTCPServer ForkingMixInAF_UNIX)UnixStreamServerUnixDatagramServerThreadingUnixStreamServerThreadingUnixDatagramServer PollSelectorc@seZdZdZdZddZddZd&dd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%ZdS)'raBase 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_addressRequestHandlerClass threadingEvent_BaseServer__is_shut_down_BaseServer__shutdown_request)selfrrr#/usr/lib/python3.10/socketserver.py__init__s  zBaseServer.__init__cCdSzSCalled by constructor to activate the server. May be overridden. Nrrrrr server_activatezBaseServer.server_activate?cCs|jzIt(}||tj|js*||}|jrn |r#|| |jrWdn1s4wYWd|_|j dSWd|_|j dSd|_|j w)zHandle 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. NF) rclear_ServerSelectorregister selectors EVENT_READrselect_handle_request_noblockservice_actionsset)r poll_intervalselectorreadyrrr serve_forevers*     zBaseServer.serve_forevercCsd|_|jdS)zStops 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)rrwaitr$rrr shutdownszBaseServer.shutdowncCr")zCalled 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$rrr r/r&zBaseServer.service_actionscCs|j}|dur |j}n |jdurt||j}|dur!t|}t4}||tj | |}|r?| WdS|durW|t}|dkrW| WdSq-1s[wYdS)zOHandle one request, possibly blocking. Respects self.timeout. NTr) socket gettimeouttimeoutmintimer)r*r+r,r-r.handle_timeout)rr9deadliner2r3rrr handle_requests*      zBaseServer.handle_requestcCsz|\}}Wn tyYdSw|||r@z |||WdSty7|||||YdS||||dS)zHandle 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_requestOSErrorverify_requestprocess_request Exception handle_errorshutdown_requestrrequestclient_addressrrr r./s     z"BaseServer._handle_request_noblockcCr")zcCalled if no new request arrives within self.timeout. Overridden by ForkingMixIn. Nrr$rrr r<FszBaseServer.handle_timeoutcCr")znVerify the request. May be overridden. Return True if we should proceed with this request. TrrFrrr rAMr&zBaseServer.verify_requestcCs|||||dS)zVCall finish_request. Overridden by ForkingMixIn and ThreadingMixIn. N)finish_requestrErFrrr rBUs zBaseServer.process_requestcCr"zDCalled to clean-up the server. May be overridden. Nrr$rrr server_close^r&zBaseServer.server_closecCs||||dS)z8Finish one request by instantiating RequestHandlerClass.N)rrFrrr rIfszBaseServer.finish_requestcCs||dSz3Called to shutdown and close an individual request.N close_requestrrGrrr rEjzBaseServer.shutdown_requestcCr"z)Called to clean up an individual request.NrrOrrr rNnzBaseServer.close_requestcCs@tdtjdtd|tjdddl}|tdtjddS)ztHandle an error gracefully. May be overridden. The default is to print a traceback and continue. z(----------------------------------------)filez4Exception occurred during processing of request fromrN)printsysstderr traceback print_exc)rrGrHrWrrr rDrszBaseServer.handle_errorcCs|SNrr$rrr __enter__zBaseServer.__enter__cGs |dSrY)rK)rargsrrr __exit__s zBaseServer.__exit__)r')__name__ __module__ __qualname____doc__r9r!r%r4r6r/r>r.r<rArBrKrIrErNrDrZr]rrrr rs(+    rc@sfeZdZdZejZejZdZ dZ dddZ ddZ d d Z d d Zd dZddZddZddZdS)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 FTcCsPt|||t|j|j|_|r&z ||WdS|dS)rN)rr!r7address_family socket_type server_bindr%rK)rrrbind_and_activaterrr r!szTCPServer.__init__cCs8|jr |jtjtjd|j|j|j|_dS)zOCalled by constructor to bind the socket. May be overridden. N)allow_reuse_addressr7 setsockopt SOL_SOCKET SO_REUSEADDRbindr getsocknamer$rrr reszTCPServer.server_bindcCs|j|jdSr#)r7listenrequest_queue_sizer$rrr r%szTCPServer.server_activatecCs|jdSrJ)r7closer$rrr rKszTCPServer.server_closecC |jS)zMReturn socket file number. Interface required by selector. )r7filenor$rrr rr zTCPServer.filenocCrq)zYGet the request and client address from the socket. May be overridden. )r7acceptr$rrr r?rszTCPServer.get_requestcCs2z|tjWn tyYnw||dSrL)r6r7SHUT_WRr@rNrOrrr rEs  zTCPServer.shutdown_requestcCs |dSrQ)rprOrrr rNs zTCPServer.close_requestN)T)r^r_r`rar7AF_INETrc SOCK_STREAMrdrorhr!rer%rKrrr?rErNrrrr rs-    rc@s>eZdZdZdZejZdZddZ ddZ dd Z d d Z d S) rzUDP server class.Fi cCs |j|j\}}||jf|fSrY)r7recvfrommax_packet_size)rdata client_addrrrr r?szUDPServer.get_requestcCdSrYrr$rrr r%rRzUDPServer.server_activatecCs||dSrYrMrOrrr rErPzUDPServer.shutdown_requestcCr|rYrrOrrr rNrRzUDPServer.close_requestN) r^r_r`rarhr7 SOCK_DGRAMrdryr?r%rErNrrrr rs rcsVeZdZdZdZdZdZdZdddd Zd d Z d d Z ddZ fddZ Z S)rz5Mix-in class to handle each request in a new process.i,N(TFblockingc Cs|jdurdSt|j|jkr>ztdd\}}|j|Wnty-|jYn ty5Yn wt|j|jks|j D]0}z|rJdntj }t||\}}|j|WqCtyk|j|YqCtysYqCwdS)z7Internal routine to wait for children that have exited.Nr) active_childrenlen max_childrenoswaitpiddiscardChildProcessErrorr(r@copyWNOHANG)rrpid_flagsrrr collect_children(s.      zForkingMixIn.collect_childrencC |dS)zvWait for zombies after self.timeout seconds of inactivity. May be extended, do not override. Nrr$rrr r<K zForkingMixIn.handle_timeoutcCr)zCollect the zombie child processes regularly in the ForkingMixIn. service_actions is called in the BaseServer's serve_forever loop. Nrr$rrr r/RrzForkingMixIn.service_actionscCst}|r|jdurt|_|j|||dSd}z/z |||d}Wnty8|||YnwWz | |Wt |dSt |wz | |Wt |wt |w)z-Fork a new subprocess to process the request.Nrgr) rr rr0addrNrIrCrDrE_exit)rrGrHrstatusrrr rBYs*       zForkingMixIn.process_requestcst|j|jddS)Nr)superrKrblock_on_closer$ __class__rr rKrs zForkingMixIn.server_close)r^r_r`rar9rrrrr<r/rBrK __classcell__rrrr rs#rcs8eZdZdZfddZddZddZdd ZZS) _Threadsz2 Joinable list of all non-daemon threads. cs"||jr dSt|dSrY)reapdaemonrappendrthreadrrr r{sz_Threads.appendcCsg|dd|dd<}|SrYr)rresultrrr pop_allsz_Threads.pop_allcCs|D]}|qdSrY)rjoinrrrr rs  z _Threads.joincCsdd|D|dd<dS)Ncss|] }|r|VqdSrY)is_alive).0rrrr sz _Threads.reap..rr$rrr rz _Threads.reap) r^r_r`rarrrrrrrrr rws  rc@ eZdZdZddZddZdS) _NoThreadsz) Degenerate version of _Threads. cCr|rYrrrrr rr[z_NoThreads.appendcCr|rYrr$rrr rr[z_NoThreads.joinN)r^r_r`rarrrrrr rs rcs>eZdZdZdZdZeZddZddZ fdd Z Z S) r z4Mix-in class to handle each request in a new thread.FTc Cs^z(z|||Wnty|||Yn wW||dSW||dS||w)zgSame as in BaseServer but as a thread. In addition, exception handling is done here. N)rIrCrDrErFrrr process_request_threads z%ThreadingMixIn.process_request_threadcCsL|jr t|dttj|j||fd}|j|_|j || dS)z*Start a new thread to process the request._threads)targetr\N) rvars setdefaultrrThreadrdaemon_threadsrrrstart)rrGrHtrrr rBs  zThreadingMixIn.process_requestcst|jdSrY)rrKrrr$rrr rKs zThreadingMixIn.server_close) r^r_r`rarrrrrrBrKrrrrr r s  r c@ eZdZdS)rNr^r_r`rrrr r rc@r)rNrrrrr rrrc@r)rNrrrrr rrrc@r)rNrrrrr rrrc@eZdZejZdS)rNr^r_r`r7rrcrrrr r rc@r)rNrrrrr rrrc@r)rNrrrrr rrrc@r)rNrrrrr rrrc@0eZdZdZddZddZddZdd Zd S) r aBase 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. cCs<||_||_||_|z |W|dS|wrY)rGrHserversetuphandlefinish)rrGrHrrrr r!s zBaseRequestHandler.__init__cCr|rYrr$rrr rr[zBaseRequestHandler.setupcCr|rYrr$rrr rr[zBaseRequestHandler.handlecCr|rYrr$rrr rr[zBaseRequestHandler.finishN)r^r_r`rar!rrrrrrr r s   r c@s0eZdZdZdZdZdZdZddZdd Z dS) r z4Define self.rfile and self.wfile for stream sockets.rrNFcCs||j|_|jdur|j|j|jr|jtjtjd|j d|j |_ |j dkr3t |j|_dS|j d|j |_dS)NTrbrwb)rG connectionr9 settimeoutdisable_nagle_algorithmrir7 IPPROTO_TCP TCP_NODELAYmakefilerbufsizerfilewbufsize _SocketWriterwfiler$rrr rs   zStreamRequestHandler.setupcCsD|jjsz|jWn tjyYnw|j|jdSrY)rclosedflushr7errorrprr$rrr r#s zStreamRequestHandler.finish) r^r_r`rarrr9rrrrrrr r s  r c@r) rzSimple writable BufferedIOBase implementation for a socket Does not hold data in a buffer, avoiding any need to call flush().cCs ||_dSrY)_sock)rsockrrr r!3 z_SocketWriter.__init__cCr")NTrr$rrr writable6r[z_SocketWriter.writablecCs>|j|t| }|jWdS1swYdSrY)rsendall memoryviewnbytes)rbviewrrr write9s  $z_SocketWriter.writecCrqrY)rrrr$rrr rr>rz_SocketWriter.filenoN)r^r_r`rar!rrrrrrrr r.s  rc@r)r z6Define self.rfile and self.wfile for datagram sockets.cCs2ddlm}|j\|_|_||j|_||_dS)Nr)BytesIO)iorrGpacketr7rr)rrrrr rEs   zDatagramRequestHandler.setupcCs|j|j|jdSrY)r7sendtorgetvaluerHr$rrr rKrzDatagramRequestHandler.finishN)r^r_r`rarrrrrr r As r )%ra __version__r7r+rrUrrrr;r__all__hasattrextendrr)SelectSelectorrrrrlistrrr rrrrrrrrr r rr rrrr sPz     n~ X ( .-