You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
840 B
35 lines
840 B
import types
|
|
|
|
class RWBuilder(object):
|
|
def __init__(self, rFunc=None, wFunc=None):
|
|
self.read = rFunc
|
|
self.write = wFunc
|
|
|
|
class Protocol(object):
|
|
|
|
@property
|
|
def reader(self):
|
|
return self._reader
|
|
|
|
@property
|
|
def writer(self):
|
|
return self._writer
|
|
|
|
@reader.setter
|
|
def reader(self, r):
|
|
if hasattr(r, "read") and callable(r.read):
|
|
self._reader = r
|
|
elif callable(r):
|
|
self._reader = RWBuilder(rFunc=r)
|
|
else:
|
|
raise TypeError("unknown type for reader")
|
|
|
|
@writer.setter
|
|
def writer(self, w):
|
|
if hasattr(w, "write") and callable(w.write):
|
|
self._writer = w
|
|
elif callable(w):
|
|
self._writer = RWBuilder(wFunc=w)
|
|
else:
|
|
raise TypeError("unknown type for writer")
|
|
|
|
|