Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
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.

sexpy.py 944B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. def parse(s):
  4. s = s.strip()
  5. expr = []
  6. while s:
  7. if s[0:1] == b"(":
  8. newSexp = []
  9. if expr:
  10. expr[-1].append(newSexp)
  11. expr.append(newSexp)
  12. s = s[1:]
  13. continue
  14. if s[0:1] == b")":
  15. aList = expr.pop()
  16. s = s[1:]
  17. if not expr:
  18. assert not s
  19. return aList
  20. continue
  21. i = 0
  22. while s[i : i + 1].isdigit():
  23. i += 1
  24. assert i
  25. length = int(s[:i])
  26. data = s[i + 1 : i + 1 + length]
  27. expr[-1].append(data)
  28. s = s[i + 1 + length :]
  29. assert False, "this should not happen"
  30. def pack(sexp):
  31. return b"".join(
  32. b"(%b)" % (pack(o),)
  33. if type(o) in (type(()), type([]))
  34. else b"%d:%b" % (len(o), o)
  35. for o in sexp
  36. )