Esempio n. 1
0
def sequence_to_sequence(s):
    if not s:
        return empty
    type = type_of(IFieldType(s[0]))
    try:
        for i in s:
            type(i)
    except TypeError:
        raise TypeError('Sequences must be of one type, could not '
                        'convert %r to %r' %  (
            i,
            type
            ))
    return s
Esempio n. 2
0
 def add(self, value, type=IFieldType):
     value = type(value)
     if value is empty:
         return
     name = self.name
     data = self.content.data
     current = data.get(name)
     if name not in data:
         current = data[name] = []
     elif isinstance(current, basestring):
         current = data[name] = [current]
     elif not isinstance(current, list):
         current = data[self.name] = list(current)
     if isinstance(value, (tuple, list)):
         if current and type_of(value) != type_of(current):
             raise TypeError("Can't add %s to %s" % (type_of(value).__name__, type_of(current).__name__))
         self.content.data[self.name].extend(value)
     else:
         if current and type_of(value) != type_of(current[0]):
             raise TypeError("Can't add %s to %s" % (type_of(value).__name__, type_of(current).__name__))
         self.content.data[self.name].append(value)
Esempio n. 3
0
 def type(self):
     return type_of(self.content.data.get(self.name))