2019-04-19 22:20:27 +00:00
|
|
|
# Copyright 2019 Ram Rachum.
|
|
|
|
# This program is distributed under the MIT license.
|
|
|
|
|
|
|
|
import abc
|
|
|
|
import sys
|
|
|
|
|
2019-04-21 13:53:18 +00:00
|
|
|
from .pycompat import ABC
|
2019-04-19 22:20:27 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2019-04-21 13:53:18 +00:00
|
|
|
class WritableStream(ABC):
|
2019-04-19 22:20:27 +00:00
|
|
|
@abc.abstractmethod
|
|
|
|
def write(self, s):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def __subclasshook__(cls, C):
|
|
|
|
if cls is WritableStream:
|
|
|
|
return _check_methods(C, 'write')
|
|
|
|
return NotImplemented
|
|
|
|
|