Ejemplo n.º 1
0
    def to_bytes(self, x, shift=0):
        # Try to avoid re-encoding; this sucks because on Python 2 we can't
        # tell the difference between a string and encoded bytes, so we have
        # to require the user use unicode when they mean string
        if isinstance(x, bytes_type):
            return x

        if x == emptybytes or x is None:
            return self.sortable_to_bytes(0)

        x = self.prepare_number(x)
        x = to_sortable(self.numtype, self.bits, self.signed, x)
        return self.sortable_to_bytes(x, shift)
Ejemplo n.º 2
0
    def to_bytes(self, x, shift=0):
        # Try to avoid re-encoding; this sucks because on Python 2 we can't
        # tell the difference between a string and encoded bytes, so we have
        # to require the user use unicode when they mean string
        if isinstance(x, bytes_type):
            return x

        if x == emptybytes or x is None:
            return self.sortable_to_bytes(0)

        x = self.prepare_number(x)
        x = to_sortable(self.numtype, self.bits, self.signed, x)
        return self.sortable_to_bytes(x, shift)
Ejemplo n.º 3
0
 def to_column_value(self, x):
     if isinstance(x, (list, tuple, array)):
         x = x[0]
     x = self.prepare_number(x)
     return to_sortable(self.numtype, self.bits, self.signed, x)
Ejemplo n.º 4
0
 def to_column_value(self, x):
     if isinstance(x, (list, tuple, array)):
         x = x[0]
     x = self.prepare_number(x)
     return to_sortable(self.numtype, self.bits, self.signed, x)