示例#1
0
 def _build(self, obj, stream, context):
     size = self._sizeof(context)
     stream2 = StringIO()
     self.subcon._build(obj, stream2, context)
     data = self.encoder(stream2.getvalue())
     assert len(data) == size
     _write_stream(stream, self._sizeof(context), data)
示例#2
0
文件: core.py 项目: crass/construct
 def _build(self, obj, stream, context):
     size = self._sizeof(context)
     stream2 = StringIO()
     self.subcon._build(obj, stream2, context)
     data = self.encoder(stream2.getvalue())
     assert len(data) == size
     _write_stream(stream, self._sizeof(context), data)
示例#3
0
文件: core.py 项目: crass/construct
    def build(self, obj):
        """
        Build an object in memory.
        """

        stream = StringIO()
        self.build_stream(obj, stream)
        return stream.getvalue()
示例#4
0
    def build(self, obj):
        """
        Build an object in memory.
        """

        stream = StringIO()
        self.build_stream(obj, stream)
        return stream.getvalue()
示例#5
0
文件: core.py 项目: crass/construct
 def _build(self, obj, stream, context):
     if self.include_name:
         name, obj = obj
         for sc in self.subcons:
             if sc.name == name:
                 sc._build(obj, stream, context)
                 return
     else:
         for sc in self.subcons:
             stream2 = StringIO()
             context2 = context.__copy__()
             try:
                 sc._build(obj, stream2, context2)
             except Exception:
                 pass
             else:
                 context.__update__(context2)
                 stream.write(stream2.getvalue())
                 return
     raise SelectError("no subconstruct matched", obj)
示例#6
0
 def _build(self, obj, stream, context):
     if self.include_name:
         name, obj = obj
         for sc in self.subcons:
             if sc.name == name:
                 sc._build(obj, stream, context)
                 return
     else:
         for sc in self.subcons:
             stream2 = StringIO()
             context2 = context.__copy__()
             try:
                 sc._build(obj, stream2, context2)
             except Exception:
                 pass
             else:
                 context.__update__(context2)
                 stream.write(stream2.getvalue())
                 return
     raise SelectError("no subconstruct matched", obj)
示例#7
0
 def _encode(self, obj, context):
     stream = StringIO()
     self.inner_subcon._build(obj, stream, context)
     return stream.getvalue()
示例#8
0
 def _encode(self, obj, context):
     stream = StringIO()
     self.inner_subcon._build(obj, stream, context)
     return stream.getvalue()
示例#9
0
 def build(self, obj):
     """builds an object in a string (in memory)"""
     stream = StringIO()
     self.build_stream(obj, stream)
     return stream.getvalue()
示例#10
0
 def build(self, obj):
     """builds an object in a string (in memory)"""
     stream = StringIO()
     self.build_stream(obj, stream)
     return stream.getvalue()