Python中的super

本文通过实例详细解析了Python中使用super()方法时的调用顺序变化,包括不同初始化方法顺序对类继承结构的影响。

I had played a bit with super(), and had recognized that we can change calling order.

For example, we have next hierarchy structure:

     A
   / \
  B   C
   \ /
    D

In this case MRO of D will be (only for Python 3):

In [26]: D.__mro__

Out[26]: (__main__.D, __main__.B, __main__.C, __main__.A, object)

 Let's create a class where 

In [23]: class A(object): #  or with Python 3 can define class A:
...:     def __init__(self):
...:         print("I'm from A")
...:  
...: class B(A):
...:      def __init__(self):
...:          print("I'm from B")
...:          super().__init__()
...:   
...: class C(A):
...:      def __init__(self):
...:          print("I'm from C")
...:          super().__init__()
...:  
...: class D(B, C):
...:      def __init__(self):
...:          print("I'm from D")
...:          super().__init__()
...: d = D()
...:
I'm from D
I'm from B
I'm from C
I'm from A


    A
   / ⇖
  B ⇒ C
   ⇖ /
    D

So we can see that resolution order is same as in MRO. But when we call super() in the beginning of the method:

 In [21]: class A(object):  # or class A:
...:     def __init__(self):
...:         print("I'm from A")
...:  
...: class B(A):
...:      def __init__(self):
...:          super().__init__()  # or super(B, self).__init_()
...:          print("I'm from B")
...:   
...: class C(A):
...:      def __init__(self):
...:          super().__init__()
...:          print("I'm from C")
...:  
...: class D(B, C):
...:      def __init__(self):
...:          super().__init__()
...:          print("I'm from D")
...: d = D()
...: 
I'm from A
I'm from C
I'm from B
I'm from D

We have a different order it is reversed a order of the MRO tuple.


    A
   / ⇘
  B ⇐ C
   ⇘ /
    D 

内容概要:本文深入剖析了HTTPS中SSL/TLS握手的全流程,系统讲解了HTTPS的诞生背景及其相较于HTTP在安全性上的优势,重点阐述了SSL/TLS握手各阶段的技术细节,包括ClientHello、ServerHello、证书交换、密钥交换及加密通信建立等环节。文章结合加密基础概念(对称加密、非对称加密、哈希算法)和数字证书机制,解释了数据加密、身份验证与完整性保护的实现原理,并通过Wireshark抓包实例帮助读者直观理解握手过程中的数据交互。同时,归纳了常见握手失败问题及其解决方案,最后对SSL/TLS未来发展趋势进行了展望,涵盖抗量子加密算法和高效协议优化方向。; 适合人群:具备基本网络和安全知识的开发人员、运维工程师、网络安全爱好者,以及希望深入理解HTTPS底层机制的技术从业者;尤其适合1-3年经验、正在向中高级岗位发展的技术人员。; 使用场景及目标:①掌握HTTPS工作原理及SSL/TLS握手全过程,理解加密通信建立机制;②能够分析和排查HTTPS连接中的证书、加密套件、版本兼容等问题;③通过抓包实践提升对网络安全协议的实际分析能力;④为后续学习TLS 1.3、零RTT、前向保密等高级主题打下坚实基础; 阅读建议:此资源理论与实践结合紧密,建议在学习过程中同步使用Wireshark等工具进行抓包实验,对照文档中的握手阶段逐一验证各消息内容,加深对加密协商、证书验证和密钥生成过程的理解。同时关注最新TLS版本的发展趋势,拓展安全视野。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值