Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    def update(self, *args, **kw):
        for k, v in AttrDict(kw).attr_items():
            try:
                setattr(self, k, v)
            except:
                pass

        return self
Ejemplo n.º 4
0
    def create(self, *args, **kw):
        for k, v in AttrDict(kw).attr_items():
            try:
                #print("set onCreate", k, v)
                setattr(self, k, v)
            except:
                raise

        return self
Ejemplo n.º 5
0
 def _obj(self, value):
     if not self.created and value != None:
         self._bpy = value
         for k, v in self.cache.attr_items():
             #set_blender_object_property()
             setattr(self._bpy, k, v)
         del self._cache
         self._cache = AttrDict()
     else:
         del self._obj
Ejemplo n.º 6
0
    def __init__(self, init=None, *args, **kw):
        self._cache = AttrDict()
        self._bpy = None
        self._ipokeys = []

        if isinstance(init, Base):
            self._bpy = init._bpy
            self._cache = init._cache
            self._ipokeys = init._ipokeys
        elif isinstance(init, AttrDict):
            self._cache = init.copy()
        elif isinstance(init, bpy.types.ID):
            self._bpy = init
        elif isinstance(init, str):
            self.name = init

        #if self.created:
        for k, v in AttrDict(kw).attr_items():
            if k not in ('ipokeys'):
                #print("BASE SETATTR", self, self.created, k, v)
                setattr(self, k, v)
        if 'ipokeys' in kw:
            self.addAutoKey(kw['ipokeys'])
Ejemplo n.º 7
0
 def _build(self, obj, stream, context):
     if "<unnested>" in context:
         del context["<unnested>"]
     elif self.nested:
         context = AttrDict(_=context)
     for sc in self.subcons:
         if sc.conflags & self.FLAG_EMBED:
             context["<unnested>"] = True
             subobj = obj
         elif sc.name is None:
             subobj = None
         else:
             subobj = getattr(obj, sc.name)
             context[sc.name] = subobj
         sc._build(subobj, stream, context)
Ejemplo n.º 8
0
 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
Ejemplo n.º 9
0
 def _sizeof(self, context):
     if self.nested:
         context = AttrDict(_=context)
     return sum(sc._sizeof(context) for sc in self.subcons)
Ejemplo n.º 10
0
 def sizeof(self, context=None):
     """calculates the size of the construct (if possible) using the 
     given context"""
     if context is None:
         context = AttrDict()
     return self._sizeof(context)
Ejemplo n.º 11
0
 def build_stream(self, obj, stream):
     """builds an object into a stream"""
     self._build(obj, stream, AttrDict())
Ejemplo n.º 12
0
 def parse_stream(self, stream):
     """parses data read directly from a stream"""
     return self._parse(stream, AttrDict())