Example #1
0
 def _read_next_raw(self):
   """
   :return: (data_type, args)
   :rtype: (str, object)
   """
   import struct
   size_raw = self.pipe_c2p[0].read(4)
   if len(size_raw) < 4:
     raise EOFError
   size, = struct.unpack("<i", size_raw)
   assert size > 0, "%s: We expect to get some non-empty package. Invalid Python mod in Sprint?" % (self,)
   stream = BytesIO()
   read_size = 0
   while read_size < size:
     data_raw = self.pipe_c2p[0].read(size - read_size)
     if len(data_raw) == 0:
       raise EOFError("%s: expected to read %i bytes but got EOF after %i bytes" % (self, size, read_size))
     read_size += len(data_raw)
     stream.write(data_raw)
   stream.seek(0)
   try:
     if PY3:
       # encoding is for converting Python2 strings to Python3.
       # Cannot use utf8 because Numpy will also encode the data as strings and there we need it as bytes.
       data_type, args = Unpickler(stream, encoding="bytes").load()
     else:
       data_type, args = Unpickler(stream).load()
   except EOFError:
     raise Exception("%s: parse error of %i bytes (%r)" % (self, size, stream.getvalue()))
   return data_type, args
Example #2
0
 def _read_next_raw(self):
   """
   :return: (data_type, args)
   :rtype: (str, object)
   """
   import struct
   size_raw = self.pipe_c2p[0].read(4)
   if len(size_raw) < 4:
     raise EOFError
   size, = struct.unpack("<i", size_raw)
   assert size > 0, "%s: We expect to get some non-empty package. Invalid Python mod in Sprint?" % (self,)
   stream = BytesIO()
   read_size = 0
   while read_size < size:
     data_raw = self.pipe_c2p[0].read(size - read_size)
     if len(data_raw) == 0:
       raise EOFError("%s: expected to read %i bytes but got EOF after %i bytes" % (self, size, read_size))
     read_size += len(data_raw)
     stream.write(data_raw)
   stream.seek(0)
   try:
     if PY3:
       # encoding is for converting Python2 strings to Python3.
       # Cannot use utf8 because Numpy will also encode the data as strings and there we need it as bytes.
       data_type, args = Unpickler(stream, encoding="bytes").load()
     else:
       data_type, args = Unpickler(stream).load()
   except EOFError:
     raise Exception("%s: parse error of %i bytes (%r)" % (self, size, stream.getvalue()))
   return data_type, args
Example #3
0
 def _read_next_raw(self):
     import struct
     size_raw = self.pipe_c2p[0].read(4)
     if len(size_raw) < 4:
         raise EOFError
     size, = struct.unpack("<i", size_raw)
     stream = BytesIO()
     read_size = 0
     while read_size < size:
         data_raw = self.pipe_c2p[0].read(size - read_size)
         if len(data_raw) == 0:
             raise EOFError
         read_size += len(data_raw)
         stream.write(data_raw)
     stream.seek(0)
     if PY3:
         # encoding is for converting Python2 strings to Python3.
         # Cannot use utf8 because Numpy will also encode the data as strings and there we need it as bytes.
         dataType, args = Unpickler(stream, encoding="bytes").load()
     else:
         dataType, args = Unpickler(stream).load()
     return dataType, args