- @classmethod
- def child_elements_of_element(cls, parent):
- children = [element for element in cls.elements if parent in element.class_parents]
- children += cls.global_elements()
- if 'self' in parent.class_parents and parent not in children:
- children.append(parent)
- return children
-
-
-class EBML(Schema):
- elements = (
- EBMLElement,
- EBMLVersionElement,
- EBMLReadVersionElement,
- EBMLMaxIDLengthElement,
- EBMLMaxSizeLengthElement,
- DocTypeElement,
- DocTypeVersionElement,
- DocTypeReadVersionElement,
- CRC32Element,
- VoidElement,
- SignatureSlotElement,
- SignatureAlgoElement,
- SignatureHashElement,
- SignaturePublicKeyElement,
- SignatureElement,
- SignatureElementsElement,
- SignatureElementListElement,
- SignedElementElement
- )
\ No newline at end of file
+ @property
+ def value(self):
+ if self._value is None and self._encoding is not None:
+ if self.type in READERS:
+ self._value = READERS[self.type](StringIO(self._encoding[1]), self._encoding[0])
+ elif self.type == CONTAINER:
+ self._value = read_elements(StringIO(self._encoding[1]), self._encoding[0], self.document, self.children)
+ return self._value
+
+ @value.setter
+ def set_value(self, value):
+ if not self.check_value(value):
+ raise ValueError('Unsupported element value.')
+ self._value = value
+ self._encoding = None
+
+ @property
+ def encoding(self):
+ if self._encoding is None:
+ size = 0
+ data = bytearray()
+ if self._value is not None:
+ if self.type in ENCODERS:
+ data = ENCODERS[self.type](self._value)
+ size = len(data)
+ elif self.type == CONTAINER:
+ for element in self._value:
+ size += element.size
+ data.extend(element.encoding[1])
+ self._encoding = (size, data)
+ return self._encoding
+
+ @property
+ def id_size(self):
+ return len(encode_element_id(self.id))
+
+ @property
+ def size_size(self):
+ return len(encode_element_size(self.body_size))
+
+ @property
+ def head_size(self):
+ return self.id_size + self.size_size
+
+ @property
+ def body_size(self):
+ return self.encoding[0]
+
+ @property
+ def size(self):
+ return self.head_size + self.body_size
+
+
+class Document(object):
+ __metaclass__ = abc.ABCMeta
+
+ type = abc.abstractproperty()
+ version = abc.abstractproperty()
+ children = ()
+ globals = ()
+
+ def __init__(self, stream):
+ self.stream = stream
+ self._roots = None
+
+ @property
+ def roots(self):
+ if self._roots is None:
+ self._roots = read_elements(self.stream, None, self, self.children)
+ return self._roots
\ No newline at end of file