def open(path, mode: [], knownTypes: []): """ Create a new skill file based on argument path and mode. """ actualMode = ActualMode(mode) try: if actualMode.openMode == Mode.Create: strings = StringPool(None) types = [] annotation = Annotation(types) return SkillState({}, strings, annotation, types, FileInputStream.open(path), actualMode.closeMode, knownTypes) elif actualMode.openMode == Mode.Read: p = Parser(FileInputStream.open(path), knownTypes) return p.read(SkillState, actualMode.closeMode, knownTypes) else: raise Exception("should never happen") except SkillException as e: raise e except Exception as e: raise SkillException(e)
def __init__(self, inStream: FileInputStream, knownTypes): """ Parses a binary SKilL file :param inStream: FileInputStream :param knownTypes: classes from the specification """ self.blockCounter = 0 self.seenTypes = set() self.blockIDBarrier = 0 self.poolByName = dict() self.localFields = [] self.fieldDataQueue = [] self.offset = 0 self.types = [] self.inStream = inStream self.strings = StringPool(self.inStream) self.annotation = Annotation(self.types) self.knownTypes = knownTypes while not inStream.eof(): self.stringBlock() self.typeBlock()