Main interface¶
- enzyme.parsers.ebml.SPEC_TYPES¶
Specification types to Element types mapping
- enzyme.parsers.ebml.READERS¶
Element types to reader functions mapping. See Readers
You can override a reader to use one of your choice here:
>>> def my_binary_reader(stream, size): ... data = stream.read(size) ... return data >>> READERS[BINARY] = my_binary_reader
- class enzyme.parsers.ebml.Element(id=None, type=None, name=None, level=None, position=None, size=None, data=None)¶
Base object of EBML
Parameters: - id (int) – id of the element, best represented as hexadecimal (0x18538067 for Matroska Segment element)
- type (INTEGER, UINTEGER, FLOAT, STRING, UNICODE, DATE, MASTER or BINARY) – type of the element
- name (string) – name of the element
- level (int) – level of the element
- position (int) – position of element’s data
- size (int) – size of element’s data
- data – data as read by the corresponding READERS
- class enzyme.parsers.ebml.MasterElement(id=None, name=None, level=None, position=None, size=None, data=None)¶
Element of type MASTER that has a list of Element as its data
Parameters: - id (int) – id of the element, best represented as hexadecimal (0x18538067 for Matroska Segment element)
- name (string) – name of the element
- level (int) – level of the element
- position (int) – position of element’s data
- size (int) – size of element’s data
- data (list of Element) – child elements
MasterElement implements some magic methods to ease manipulation. Thus, a MasterElement supports the in keyword to test for the presence of a child element by its name and gives access to it with a container getter:
>>> ebml_element = parse(open('test1.mkv', 'rb'), get_matroska_specs())[0] >>> 'EBMLVersion' in ebml_element False >>> 'DocType' in ebml_element True >>> ebml_element['DocType'] Element(DocType, u'matroska')
- load(stream, specs, ignore_element_types=None, ignore_element_names=None, max_level=None)¶
Load children Elements with level lower or equal to the max_level from the stream according to the specs
Parameters: - stream – file-like object from which to read
- specs (dict) – see Specifications
- max_level (int) – maximum level for children elements
- ignore_element_types (list) – list of element types to ignore
- ignore_element_names (list) – list of element names to ignore
- max_level – maximum level of elements
- get(name, default=None)¶
Convenience method for master_element[name].data if name in master_element else default
Parameters: - name (string) – the name of the child to get
- default – default value if name is not in the MasterElement
Returns: the data of the child Element or default
- enzyme.parsers.ebml.parse(stream, specs, size=None, ignore_element_types=None, ignore_element_names=None, max_level=None)¶
Parse a stream for size bytes according to the specs
Parameters: - stream – file-like object from which to read
- size (int or None) – maximum number of bytes to read, None to read all the stream
- specs (dict) – see Specifications
- ignore_element_types (list) – list of element types to ignore
- ignore_element_names (list) – list of element names to ignore
- max_level (int) – maximum level of elements
Returns: parsed data as a tree of Element
Return type: list
Note
If size is reached in a middle of an element, reading will continue until the element is fully parsed.
- enzyme.parsers.ebml.parse_element(stream, specs, load_children=False, ignore_element_types=None, ignore_element_names=None, max_level=None)¶
Extract a single Element from the stream according to the specs
Parameters: - stream – file-like object from which to read
- specs (dict) – see Specifications
- load_children (bool) – load children elements if the parsed element is a MasterElement
- ignore_element_types (list) – list of element types to ignore
- ignore_element_names (list) – list of element names to ignore
- max_level (int) – maximum level for children elements
Returns: the parsed element
Return type:
- enzyme.parsers.ebml.get_matroska_specs(webm_only=False)¶
Get the Matroska specs
Parameters: webm_only (bool) – load only WebM specs Returns: the specs in the appropriate format. See Specifications Return type: dict