Exemplo n.º 1
0
 def load_string(self):
     n = self._read_long()
     s = self._read(n)
     if self.python_version[0] >= 3:
         # load_string() loads a bytestring, and in Python 3, str and bytes are
         # different classes.
         s = compat.BytesType(s)
     elif not self._keep_bytes:
         # In Python 2, load_string is used to load both bytestrings and native
         # strings, so we have to specify which we want.
         s = compat.native_str(s)
     return s
Exemplo n.º 2
0
 def load_string(self):
   n = self._read_long()
   s = self._read(n)
   if self.python_version[0] >= 3:
     # load_string() loads a bytestring, and in Python 3, str and bytes are
     # different classes.
     s = compat.BytesType(s)
   elif not self._keep_bytes:
     # In Python 2, load_string is used to load both bytestrings and native
     # strings, so we have to specify which we want. We use the
     # 'backslashreplace' error mode in order to handle non-utf8
     # backslash-escaped string literals correctly.
     s = compat.native_str(s, 'backslashreplace')
   return s
Exemplo n.º 3
0
 def test_load_string(self):
   self.assertStrictEqual(self.load(b's\4\0\0\0test', (2, 7)), 'test')
   self.assertStrictEqual(self.load(b's\4\0\0\0test', (3, 6)),
                          compat.BytesType(b'test'))