Exemplo n.º 1
0
 def cast_from_str(self, value):
     try:
         value = QUrl(value)
         self.is_valid(value)
         return value
     except (TypeError, ValueError) as e:
         raise MetadataCastError(e)
Exemplo n.º 2
0
 def cast_from_str(self, value):
     try:
         return float(value)
     except ValueError:
         try:
             return tuple(json.loads(value))
         except ValueError as e:
             raise MetadataCastError(e)
Exemplo n.º 3
0
 def cast_from_str(self, value):
     try:
         return datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f")
     except ValueError:
         try:
             return datetime.strptime(value, "%Y-%m-%dT%H:%M:%S")
         except ValueError:
             try:
                 return datetime.strptime(value, "%Y-%m-%d")
             except ValueError as e:
                 raise MetadataCastError(e)
Exemplo n.º 4
0
 def cast_from_str(self, value):
     try:
         value = json.loads(value)
         # Checking if the v is basestring, try to decode if it's json
         for k, v in value.items():
             if isinstance(v, basestring):
                 try:
                     # Try to get dictionary, if possible.
                     dictionary_value = json.loads(v)
                     if isinstance(dictionary_value, dict):
                         value[k] = dictionary_value
                     else:
                         pass
                 except ValueError:
                     # Try to get time, if possible.
                     try:
                         value[k] = datetime.strptime(
                             v, "%Y-%m-%dT%H:%M:%S.%f")
                     except ValueError:
                         pass
         return value
     except ValueError as e:
         raise MetadataCastError(e)
Exemplo n.º 5
0
 def cast_from_str(self, value):
     try:
         return bool(int(value))
     except ValueError as e:
         raise MetadataCastError(e)