Beispiel #1
0
 def filter(self, *expressions):
     for (field, op, value) in expressions:
         if isinstance(value, (list, set, tuple)):
             items = [(field.serialize(item) if
                       not isinstance(item, string_type) else encode(item))
                      for item in value]
             value = b','.join(items)
         elif isinstance(value, string_type):
             value = encode(value)
         else:
             value = field.serialize(value)
         self._conditions.append((field.name, op, value))
Beispiel #2
0
    def serialize(self, value):
        if isinstance(value, datetime.datetime):
            pass  # Note: date is a subclass of datetime.
        elif isinstance(value, datetime.date):
            value = datetime.datetime(value.year, value.month, value.day)
        elif isinstance(value, int):
            return encode(str(value * 1000000))

        if self._utc:
            timestamp = calendar.timegm(value.utctimetuple())
        else:
            timestamp = time.mktime(value.timetuple())
        timestamp = (timestamp * 1000000) + value.microsecond
        return encode(str(timestamp))
Beispiel #3
0
def serialize_model(model):
    buf = io.BytesIO()
    for name, field in model.__fields__.items():
        if name == 'key': continue
        value = getattr(model, name, None)
        if value is not None:
            buf.write(encode(name))
            buf.write(b'\x00')
            buf.write(field.serialize(value))
            buf.write(b'\x00')
    return model.key, buf.getvalue()
Beispiel #4
0
 def serialize(self, value):
     return encode(str(value))
Beispiel #5
0
 def serialize(self, value):
     return encode(value.strftime(self._format))