• BaseRequestHandler



    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 other arbitrary instance variables.

    """

    def __init__(self, request, client_address, server):
    self.request = request
    self.client_address = client_address
    self.server = server
    self.setup()
    try:
    self.handle()
    finally:
    self.finish()

    def setup(self):
    pass

    def handle(self):
    pass

    def finish(self):
    pass


    # The following two classes make it possible to use the same service
    # class for stream or datagram servers.
    # Each class sets up these instance variables:
    # - rfile: a file object from which receives the request is read
    # - wfile: a file object to which the reply is written
    # When the handle() method returns, wfile is flushed properly

  • 相关阅读:
    网络编程之Tcp,udp
    网络编程简介
    面向对象之高级篇 反射,元类
    面向对象 高级篇
    面向对象,继承
    初识面向对象
    包 hashlib,logging
    模块
    Dango生命周期回顾与forms组件
    Django中auth登录、注册、修改密码、退出、ORM自关联
  • 原文地址:https://www.cnblogs.com/rongye/p/9974619.html
Copyright © 2020-2023  润新知