zoukankan      html  css  js  c++  java
  • Python--socketserve源码分析(一)

     

    class ThreadingTCPServer(ThreadingMixIn, TCPServer): pass

    实现原理:

      s =socketserver.ThreadingTCPServer(参数1,参数2,......)

      根据ThreadingTCPServer的基类顺序,依次匹配各基类的构造函数参数

      若第一个没构造函数则向后匹配

      若有构造函数但参数不匹配则报错

      若有构造函数且参数匹配则调用基类构造函数,并停止匹配过程

    情况1:

    #coding:UTF-8
    
    class Base:def fun(self):
            print ("Base fun")
    
    class B:
        def __init__(self, a, b):
            print (a,b)
    
    class A(Base, B):
        pass        
    
    if __name__ == "__main__":
        a = A(1,2)

    >>>> 1,2

    情况2:

    #coding:UTF-8
    
    class Base:
        def __init__(self):
            self.ip = "192.168.3.8"
            self.port = 1122
            self.fun()
    
        def fun(self):
            print ("Base fun")
    
    class B:
        def __init__(self, a, b):
            print (a,b)
    
    class A(Base, B):
        pass        
    
    if __name__ == "__main__":
        a = A(1,2)

    >>>> Traceback (most recent call last):

    >>>> File "test.py", line 20, in <module>
    >>>> a = A(1,2)
    >>>> TypeError: __init__() takes 1 positional argument but 3 were given
    情况3:

    #coding:UTF-8
    
    class Base:
        def __init__(self, a, b):
            self.ip = "192.168.3.8"
            self.port = 1122
            self.fun()
    
        def fun(self):
            print ("Base fun")
    
    class B:
        def __init__(self, a, b):
            print (a,b)
    
    class A(Base, B):
        pass        
    
    if __name__ == "__main__":
        a = A(1,2)
        

    >>>> Base fun

      

      

  • 相关阅读:
    Win8 iis 环境搭建
    Windows phone 8 触发器使用小结
    Windows Phone 页面之间参数传递方法
    日期SQL 脚本
    net 内存泄露和内存溢出
    Emacs的一些事情(与Vi的争议及使用)
    matlab与示波器连接及电脑连接
    msp430学习笔记-TA
    28个Unix/Linux的命令行神器
    linux在线中文手册
  • 原文地址:https://www.cnblogs.com/xiaobingqianrui/p/8310418.html
Copyright © 2011-2022 走看看