# Copyright 2019 Ram Rachum. # This program is distributed under the MIT license. import abc import sys from .pycompat import ABC def _check_methods(C, *methods): mro = C.__mro__ for method in methods: for B in mro: if method in B.__dict__: if B.__dict__[method] is None: return NotImplemented break else: return NotImplemented return True class WritableStream(ABC): @abc.abstractmethod def write(self, s): pass @classmethod def __subclasshook__(cls, C): if cls is WritableStream: return _check_methods(C, 'write') return NotImplemented