Exemplo n.º 1
0
 def dtype(self, new_type):
     # check if this is a valid type
     if not dtypes.valid_type(new_type):
         raise AttributeError("'%s' is not a valid type." % new_type)
     # we convert the value if possible
     old_type = self._dtype
     old_value = dtypes.set(self._value, self._dtype)
     try:
         new_value = dtypes.get(old_value, new_type)
     except:
         # cannot convert, try the other way around
         try:
             old_value = dtypes.set(self._value, new_type)
             new_value = dtypes.get(old_value, new_type)
         except:
             #doesn't work either, therefore refuse
             raise ValueError("cannot convert '%s' from '%s' to '%s'" % (self.value, old_type, new_type))
     self._value = new_value
     self._dtype = new_type
Exemplo n.º 2
0
 def dtype(self, new_type):
     # check if this is a valid type
     if not dtypes.valid_type(new_type):
         raise AttributeError("'%s' is not a valid type." % new_type)
     # we convert the value if possible
     old_type = self._dtype
     old_value = dtypes.set(self._value, self._dtype, self._encoder)
     try:
         new_value = dtypes.get(old_value, new_type, self._encoder)
     except:
         # cannot convert, try the other way around
         try:
             old_value = dtypes.set(self._value, new_type, self._encoder)
             new_value = dtypes.get(old_value, new_type, self._encoder)
         except:
             #doesn't work either, therefore refuse
             raise ValueError("cannot convert '%s' from '%s' to '%s'" % (self.value, old_type, new_type))
     self._value = new_value
     self._dtype = new_type
Exemplo n.º 3
0
    def value(self):
        """
        used to access typed data of the value as a string.
        Use data to access the raw type, i.e.:

        >>> v = Value(1, type="float")
        >>> v.data
        1.0
        >>> v.data = 1.5
        >>> v.value
        "1.5"
        >>> v.value = 2
        >>> v.data
        2.0
        """
        return dtypes.set(self._value, self._dtype)
Exemplo n.º 4
0
    def value(self):
        """
        used to access typed data of the value as a string.
        Use data to access the raw type, i.e.:

        >>> v = Value(1, type="float")
        >>> v.data
        1.0
        >>> v.data = 1.5
        >>> v.value
        "1.5"
        >>> v.value = 2
        >>> v.data
        2.0
        """
        return dtypes.set(self._value, self._dtype, self._encoder)
Exemplo n.º 5
0
 def date(self):
     """
     The date the document was created.
     """
     return dtypes.set(self._date, "date")
Exemplo n.º 6
0
 def value_str(self, index=0):
     """
     used to access typed data of the value as a string.
     Use data to access the raw type, i.e.:
     """
     return dtypes.set(self._value[index], self._dtype)
Exemplo n.º 7
0
 def value_str(self, index=0):
     """
     Used to access typed data of the value as a string.
     Use data to access the raw type, i.e.:
     """
     return dtypes.set(self._value[index], self._dtype)