Ejemplo n.º 1
0
 def unwrap_char(self, space):
     w_class = self.getclass(space)
     if not w_class.is_same_object(space.w_Character):
         raise error.UnwrappingError("expected Character")
     w_ord = self.fetch(space, constants.CHARACTER_VALUE_INDEX)
     if not isinstance(w_ord, W_SmallInteger):
         raise error.UnwrappingError("expected SmallInteger from Character")
     return chr(w_ord.value)
Ejemplo n.º 2
0
 def unwrap_uint(self, space):
     if not self.getclass(space).is_same_object(
             space.w_LargePositiveInteger):
         raise error.UnwrappingError(
             "Invalid class for unwrapping byte object as uint")
     if self.size() > constants.BYTES_PER_MACHINE_INT:
         raise error.UnwrappingError("Too large to convert bytes to word")
     word = r_uint(0)
     for i in range(self.size()):
         word += r_uint(ord(self.getchar(i))) << 8 * i
     return word
Ejemplo n.º 3
0
 def unwrap_int64(self, space):
     if self.size() > constants.BYTES_PER_MACHINE_LONGLONG:
         raise error.UnwrappingError("Too large to convert bytes to word")
     elif (self.size() == constants.BYTES_PER_MACHINE_LONGLONG
           and ord(self.getchar(constants.BYTES_PER_MACHINE_LONGLONG - 1))
           >= 0x80):
         # Sign-bit is set, this will overflow
         raise error.UnwrappingError("Too large to convert bytes to word")
     word = r_int64(0)
     for i in range(self.size()):
         try:
             word += r_int64(ord(self.getchar(i))) << 8 * i
         except OverflowError:  # never raised after translation :(
             raise error.UnwrappingError(
                 "Too large to convert bytes to word")
     if self.getclass(space).is_same_object(space.w_LargePositiveInteger):
         return word
     elif self.getclass(space).is_same_object(space.w_LargeNegativeInteger):
         return -word
     else:
         raise error.UnwrappingError
Ejemplo n.º 4
0
 def unwrap_rbigint(self, space):
     raise error.UnwrappingError("Got unexpected class unwrap_rbigint")
Ejemplo n.º 5
0
 def unwrap_int64(self, space):
     raise error.UnwrappingError("Got unexpected class unwrap_int64")
Ejemplo n.º 6
0
 def is_positive(self, space):
     raise error.UnwrappingError("Got unexpected class in is_positive")