Esempio n. 1
0
 def probes(self, image):
     if PYTHON_VERSION.major == 3:
         if isinstance(image, str):
             return self.probe(createStringBuffer(bytes(image, "ascii")))
         else:
             return self.probe(createStringBuffer(image))
     else:
         return self.probe(createStringBuffer(image))
Esempio n. 2
0
 def setUp(self):
     if PYTHON_VERSION.major == 3:
         self.buf = io.TextIOWrapper(createStringBuffer())
     else:
         self.buf = createStringBuffer()
     #self.stdout = sys.stdout
     #sys.stdout = self.buf
     self.builder = Builder()
Esempio n. 3
0
 def loads(self, image, **kws):
     if PYTHON_VERSION.major == 3:
         if isinstance(image, str):
             return self.load(createStringBuffer(bytes(image, "ascii")))
         else:
             return self.load(createStringBuffer(image))
     else:
         return self.load(createStringBuffer(image))
Esempio n. 4
0
 def testBasic(self):
     if PYTHON_VERSION.major == 3:
         buf = io.TextIOWrapper(createStringBuffer())
     else:
         buf = createStringBuffer()
     b0 = Builder()
     b0.addSegment("hello world!")
     b0.joinSections()
     b0.hexdump(buf)
     buf.seek(0, os.SEEK_SET)
     self.assertEqual(buf.read(), TEST1)
Esempio n. 5
0
 def probe(self, fp):
     for idx, line in enumerate(fp, 1):
         if not VALID_CHARS.match(line.decode()):
             fp.seek(0, os.SEEK_SET)
             return False
         if idx > 3:
             break
     fp.seek(0, os.SEEK_SET)
     return super(Reader, self).probe(
         createStringBuffer(bytearray(self.decode(fp), "ascii")))
Esempio n. 6
0
 def __init__(self, image, imageReader, byteOrderPrefix):
     super(DwarfReader, self).__init__(createStringBuffer(image),
                                       byteOrderPrefix)
     self.wordSize = None
     self.imageReader = imageReader
Esempio n. 7
0
 def _runTest(self, method, value, expected):
     dr = PlainBinaryReader(createStringBuffer(value),
                            PlainBinaryReader.LITTLE_ENDIAN)
     self.assertEqual(getattr(dr, method)(), expected)
Esempio n. 8
0
 def _createReader():
     return PlainBinaryReader(
         createStringBuffer(bytearray("hello world!", "ascii")),
         PlainBinaryReader.LITTLE_ENDIAN)
Esempio n. 9
0
 def read(self, fp):
     return super(Reader, self).read(
         createStringBuffer(bytearray(self.decode(fp), "ascii")))