Files
storage_fresco/telegram.py
2019-05-23 13:36:01 +00:00

67 lines
1.5 KiB
Python

#!/usr/bin/python
__author__ = "Michael Rest"
__date__ = "2006/02/15"
__email__ = "michi@rosstein.de"
__version__ = "$Revision: 1.1 $"[11:-2]
# Packet types
TEL_LEBE = 0xa #
TEL_TAUF = 0xb #
TEL_TQUI = 0xc #
TEL_SCLS = 0xd #
TEL_STAT = 0xe #
TEL_QUIT = 0xf #
TEL_IPKT = 0x9 #
class TELEGRAM:
def __init__ (self):
self.len = 0
self.code = 0
self.attrib = {'src': ' ', 'dst': ' ', 'type': 'NONE', 'check' : 0}
def type (self):
"""
Return type hexadecimal type of the TELEGRAM. This function is
common for all TPDUs.
"""
return self.code
def __len__ (self):
"""
Return the calcuclated length of the TELEGRAM. The value is
always WITHOUT the coded type, add 1 to it if in doubt.
"""
return self.len
def __getitem__ (self, key):
"""
Return Attrib
"""
return self.attrib[key]
def has_key (self, key):
"""
Check for Key
"""
return self.attrib.has_key(key)
def __repr__ (self):
"""
Print a representation of the TELEGRAM. Use this method via
`-pair to transfer it over the wire. This will just return
the header data and not the real data!
"""
# Note that the data is not included in the length
return "%c%c" % (2, self.code << 4, self.number)
def __str__ (self):
"""
Return a readable and quite verbose overview of the TPDU instance.
Use this for debugging purposes or if you're just curious.
"""
string = DT_STRING % (self.len, self.number, self.data)
return string