def load(cls, path):
        path = pathlib.Path(path)

        if lzma and path.suffix.upper() == ".XZ":
            file = lzma.LZMAFile(path, "r")

        elif bz2 and path.suffix.upper() == ".BZ2":
            file = bz2.BZ2File(path, "r")

        elif gzip and path.suffix.upper() == ".GZ":
            file = gzip.GzipFile(path, "r")

        else:
            file = open(path, "rb")

        head = EBMLHead.fromFile(file)

        if head.docType == "filterchain":
            self = FilterChainElement.fromFile(file)

        elif head.docType == "filter":
            self = cls.fromFile(file)

        else:
            raise ValueError("Not a valid filter or filterchain file.")

        return self.toObj({"path": path, "module": filters})
Example #2
0
    def _init_read(self):
        head = EBMLHead.fromFile(self._file)

        if head.docType != "matroska":
            raise ReadError("Not a matroska file.")

        self.head = head
        self.body = self._bodycls(self._file)
Example #3
0
 def _init_read(self):
     """
     This should be overridden in subclasses if you are looking to handle specific document types.
     """
     self.head = EBMLHead.fromFile(self._file)
     self.body = self._bodycls(self._file)