49 lines
737 B
Python
49 lines
737 B
Python
|
|
#!/usr/bin/env python
|
||
|
|
# -*- encoding: utf-8 -*-
|
||
|
|
"""
|
||
|
|
Topic: 定义接口或抽象类
|
||
|
|
Desc :
|
||
|
|
"""
|
||
|
|
from abc import ABCMeta, abstractmethod
|
||
|
|
|
||
|
|
|
||
|
|
class IStream(metaclass=ABCMeta):
|
||
|
|
@abstractmethod
|
||
|
|
def read(self, maxbytes=-1):
|
||
|
|
pass
|
||
|
|
|
||
|
|
@abstractmethod
|
||
|
|
def write(self, data):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class SocketStream(IStream):
|
||
|
|
def read(self, maxbytes=-1):
|
||
|
|
pass
|
||
|
|
|
||
|
|
def write(self, data):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class A(metaclass=ABCMeta):
|
||
|
|
@property
|
||
|
|
@abstractmethod
|
||
|
|
def name(self):
|
||
|
|
pass
|
||
|
|
|
||
|
|
@name.setter
|
||
|
|
@abstractmethod
|
||
|
|
def name(self, value):
|
||
|
|
pass
|
||
|
|
|
||
|
|
@classmethod
|
||
|
|
@abstractmethod
|
||
|
|
def method1(cls):
|
||
|
|
pass
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
@abstractmethod
|
||
|
|
def method2():
|
||
|
|
pass
|
||
|
|
|