string.py 814 B

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