Q: int treated as `self' in python3 I want to build a simple server that dispatches requests depending on their path. So I wrote the following code:
from http.server import HTTPServer, BaseHTTPRequestHandler
import json
import socket

class Handler:
    """处理对应资源的请求"""
    def __init__(self, dispatcher):
        self.dispatcher = dispatcher

    def handle(self):
        """根据dispatcher解析出来的path,调用对应的方法"""
        command = 'do_' + self.dispatcher.command
        print(command)
        if not hasattr(self, command):
            return;

        method = getattr(self, command)
        method(self)

    def do_GET(self):
        response = {
            'message': 'message'
        }
        dispatcher.protocol_version = 'HTTP/1.1'
        dispatcher.send_response(200, 'OK')
        dispatcher.send_header('Content-type', 'text/plain')
        dispatcher.wfile.write(bytes(json.dumps(response), 'utf-8'))

class dispatcher(BaseHTTPRequestHandler):
    """
    根据url的不同分发请求
    """
    def handle_one_request(self):
        try:
            self.raw_requestline = self.rfile.readline(65537)
            if len(self.raw_requestline) > 65536:
                self.requestline = ''
                self.request_version = ''
                self.command = ''
                self.send_error(HTTPStatus.REQUEST_URI_TOO_LONG)
                return
            if not self.raw_requestline:
                self.close_connection = True
                return
            if not self.parse_request():
                # An error code has been sent, just exit
                return
            print(self.command)
            print(self.path)
            if self.path.startswith('/wrong'):
                Handler(self).handle()
            self.wfile.flush() #actually send the response if not already done.
        except socket.timeout as e:
            #a read or a write timed out.  Discard this connection
            self.log_error("Request timed out: %r", e)
            self.close_connection = True
            return

if __name__ == '__main__':
    server = HTTPServer(('', 8080), dispatcher)
    server.serve_forever()

The dispatcher will parse the incoming request and get the path so that it can decide which handler to call(though there is only one here for now).
In the handler class, it will call corresponding method based on the http method. In the do_GET method, it will call some methods in the dispatcher and that's where things go wrong.
When I ran this program and execute curl http://localhost:8080/wrong, I had the following exception:
GET
/wrong
do_GET
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 50072)
Traceback (most recent call last):
  File "/usr/lib/python3.5/socketserver.py", line 313, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python3.5/socketserver.py", line 341, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.5/socketserver.py", line 354, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.5/socketserver.py", line 681, in __init__
    self.handle()
  File "/usr/lib/python3.5/http/server.py", line 422, in handle
    self.handle_one_request()
  File "hello.py", line 51, in handle_one_request
    Handler(self).handle()
  File "hello.py", line 18, in handle
    method()
  File "hello.py", line 25, in do_GET
    dispatcher.send_response(200, 'OK')
  File "/usr/lib/python3.5/http/server.py", line 487, in send_response
    self.log_request(code)
AttributeError: 'int' object has no attribute 'log_request'
----------------------------------------

log_request is defined as follows in the super class of dispatcher:
def log_request(self, code='-', size='-'):
    # blablabla

and it is called in dispatcher.send_response.
I guess the problem is that the 200 is treated as self by the interpreter.
If my guess is right, why is this happening?
If not, what causes this exception?
I know this question is still in the grammar level, but I'd appreciate it if someone can help me.
