예제 #1
0
 def _set_date_header(self, key, date):
     # XXX for now we only document that the helpers can accept a
     # datetime object, but you can also pass a string and a int.
     # Let's see in the futur if this is usefull and document all
     # the behavior
     if isinstance(date, datetime):
         date = date
     elif isinstance(date, int):
         date = Date.epoch2time(date)
     elif isinstance(date, str):
         date = Date.str2time(date)
     else:
         raise ValueError("date is of type <{type}> but can only be an "
             "instance of string, int or a datetime object"
             .format(type=type(date)))
     self.set(key, date)
예제 #2
0
    def _get_date_header(self, key):
        value = self.__getitem__(key)
        if value is None:
            return None

        if isinstance(value, str):
            return Date.str2time(value)
        elif isinstance(value, int):
            return Date.epoch2time(value)
        elif isinstance(value, datetime):
            return value
        else:
            print value
            raise ValueError("date is of type <{type}> but can only be an "
                "instance of string, int or a datetime object"
                .format(type=type(value)))