| 1 |
from abc import ABCMeta, abstractmethod |
| 2 |
|
| 3 |
|
| 4 |
class Datagram(metaclass=ABCMeta): |
| 5 |
""" Base class of all data grams. """ |
| 6 |
|
| 7 |
def __init__(self): |
| 8 |
pass |
| 9 |
|
| 10 |
@abstractmethod |
| 11 |
def format(self, prefix=""): |
| 12 |
pass |
| 13 |
|
| 14 |
|
| 15 |
class DatagramHandler(metaclass=ABCMeta): |
| 16 |
|
| 17 |
def __init__(self): |
| 18 |
pass |
| 19 |
|
| 20 |
@abstractmethod |
| 21 |
def handleFromHost(self, dgram: Datagram): |
| 22 |
pass |
| 23 |
|
| 24 |
@abstractmethod |
| 25 |
def handleToHost(self, dgram: Datagram): |
| 26 |
pass |
| 27 |
|
| 28 |
|
| 29 |
class RawDatagramDump(DatagramHandler): |
| 30 |
def __init__(self): |
| 31 |
super().__init__() |
| 32 |
|
| 33 |
def handleFromHost(self, dgram:Datagram): |
| 34 |
print(dgram.format("< ")) |
| 35 |
|
| 36 |
def handleToHost(self, dgram:Datagram): |
| 37 |
print(dgram.format("> ")) |