def _parse(self, stream, context): obj = ListContainer() c = 0 count = self.countfunc(context) try: if self.subcon.conflags & self.FLAG_COPY_CONTEXT: while c < count: obj.append(self.subcon._parse(stream, context.__copy__())) c += 1 else: while c < count: obj.append(self.subcon._parse(stream, context)) c += 1 except ConstructError, ex: raise ArrayError("expected %d, found %d" % (count, c), ex)
def printout(self, stream, context): obj = Container() if self.show_stream: obj.stream_position = stream.tell() follows = stream.read(self.stream_lookahead) if not follows: obj.following_stream_data = "EOF reached" else: stream.seek(-len(follows), 1) obj.following_stream_data = HexString(follows) print if self.show_context: obj.context = context if self.show_stack: obj.stack = ListContainer() frames = [s[0] for s in inspect.stack()][1:-1] frames.reverse() for f in frames: a = AttrDict() a.__update__(f.f_locals) obj.stack.append(a) print "=" * 80 print "Probe", self.printname print obj print "=" * 80
def _parse(self, stream, context): if "<obj>" in context: obj = context["<obj>"] del context["<obj>"] else: obj = ListContainer() if self.nested: context = Container(_ = context) for sc in self.subcons: if sc.conflags & self.FLAG_EMBED: context["<obj>"] = obj sc._parse(stream, context) else: subobj = sc._parse(stream, context) if sc.name is not None: obj.append(subobj) context[sc.name] = subobj return obj
def _parse(self, stream, context): if "<obj>" in context: obj = context["<obj>"] del context["<obj>"] else: obj = ListContainer() if self.nested: context = AttrDict(_=context) for sc in self.subcons: if sc.conflags & self.FLAG_EMBED: context["<obj>"] = obj sc._parse(stream, context) else: subobj = sc._parse(stream, context) if sc.name is not None: obj.append(subobj) context[sc.name] = subobj return obj
def _parse(self, stream, context): obj = ListContainer() c = 0 try: if self.subcon.conflags & self.FLAG_COPY_CONTEXT: while c < self.maxcout: pos = stream.tell() obj.append(self.subcon._parse(stream, context.__copy__())) c += 1 else: while c < self.maxcout: pos = stream.tell() obj.append(self.subcon._parse(stream, context)) c += 1 except ConstructError, ex: if c < self.mincount: raise RangeError("expected %d to %d, found %d" % (self.mincount, self.maxcout, c), ex) stream.seek(pos)
def _parse(self, stream, context): obj = ListContainer() c = 0 try: if self.subcon.conflags & self.FLAG_COPY_CONTEXT: while c < self.maxcout: pos = stream.tell() obj.append(self.subcon._parse(stream, context.__copy__())) c += 1 else: while c < self.maxcout: pos = stream.tell() obj.append(self.subcon._parse(stream, context)) c += 1 except ConstructError: if c < self.mincount: raise RangeError("expected %d to %d, found %d" % (self.mincount, self.maxcout, c)) stream.seek(pos) return obj