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.

86 lines
2.4 KiB

4 years ago
  1. # Abstract classes.
  2. class Event(object):
  3. def __init__(self, start_mark=None, end_mark=None):
  4. self.start_mark = start_mark
  5. self.end_mark = end_mark
  6. def __repr__(self):
  7. attributes = [key for key in ['anchor', 'tag', 'implicit', 'value']
  8. if hasattr(self, key)]
  9. arguments = ', '.join(['%s=%r' % (key, getattr(self, key))
  10. for key in attributes])
  11. return '%s(%s)' % (self.__class__.__name__, arguments)
  12. class NodeEvent(Event):
  13. def __init__(self, anchor, start_mark=None, end_mark=None):
  14. self.anchor = anchor
  15. self.start_mark = start_mark
  16. self.end_mark = end_mark
  17. class CollectionStartEvent(NodeEvent):
  18. def __init__(self, anchor, tag, implicit, start_mark=None, end_mark=None,
  19. flow_style=None):
  20. self.anchor = anchor
  21. self.tag = tag
  22. self.implicit = implicit
  23. self.start_mark = start_mark
  24. self.end_mark = end_mark
  25. self.flow_style = flow_style
  26. class CollectionEndEvent(Event):
  27. pass
  28. # Implementations.
  29. class StreamStartEvent(Event):
  30. def __init__(self, start_mark=None, end_mark=None, encoding=None):
  31. self.start_mark = start_mark
  32. self.end_mark = end_mark
  33. self.encoding = encoding
  34. class StreamEndEvent(Event):
  35. pass
  36. class DocumentStartEvent(Event):
  37. def __init__(self, start_mark=None, end_mark=None,
  38. explicit=None, version=None, tags=None):
  39. self.start_mark = start_mark
  40. self.end_mark = end_mark
  41. self.explicit = explicit
  42. self.version = version
  43. self.tags = tags
  44. class DocumentEndEvent(Event):
  45. def __init__(self, start_mark=None, end_mark=None,
  46. explicit=None):
  47. self.start_mark = start_mark
  48. self.end_mark = end_mark
  49. self.explicit = explicit
  50. class AliasEvent(NodeEvent):
  51. pass
  52. class ScalarEvent(NodeEvent):
  53. def __init__(self, anchor, tag, implicit, value,
  54. start_mark=None, end_mark=None, style=None):
  55. self.anchor = anchor
  56. self.tag = tag
  57. self.implicit = implicit
  58. self.value = value
  59. self.start_mark = start_mark
  60. self.end_mark = end_mark
  61. self.style = style
  62. class SequenceStartEvent(CollectionStartEvent):
  63. pass
  64. class SequenceEndEvent(CollectionEndEvent):
  65. pass
  66. class MappingStartEvent(CollectionStartEvent):
  67. pass
  68. class MappingEndEvent(CollectionEndEvent):
  69. pass