string.py 777 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import constants
  2. from packet import Packet
  3. class String(object):
  4. def __init__(self, data=None, label=None, size=None):
  5. if label is None:
  6. label = "1"
  7. if size is None:
  8. size = 32
  9. if len(data) > size:
  10. size = len(data)
  11. if size > 125:
  12. size = 125
  13. if size < 1:
  14. size = 1
  15. self.label = label
  16. self.size = size
  17. self.data = data
  18. def call(self):
  19. """Call a STRING.
  20. This is for inserting a STRING file into a TEXT file.
  21. Returns:
  22. control code and specified string label
  23. """
  24. return "\x10%s" % self.label
  25. def __str__(self):
  26. return str(Packet("%s%s%s" % (constants.WRITE_STRING, self.label,
  27. self.data)))
  28. def __repr__(self):
  29. return repr(self.__str__())