Example #1
0
File: value.py Project: f3at/feat
 def __eq__(self, other):
     if not IValueInfo.providedBy(other):
         return NotSupported
     other = IValueInfo(other)
     if self.value_type != other.value_type:
         return False
     if self.use_default != other.use_default:
         return False
     if self.use_default and (self._default != other.default):
         return False
     if IValueOptions.providedBy(self) != IValueOptions.providedBy(other):
         return False
     if IValueOptions.providedBy(self):
         other = IValueOptions(other)
         other_options = set(other.iter_options())
         self_options = set(self.iter_options())
         if other_options != self_options:
             return False
         if self.is_restricted != other.is_restricted:
             return False
     if IValueRange.providedBy(self) != IValueRange.providedBy(other):
         return False
     if IValueRange.providedBy(self):
         other = IValueRange(other)
         if (self.minimum != other.minimum
             or self.maximum != other.maximum
             or self.increment != other.increment):
             return False
     return True
Example #2
0
def render_value_info(value):
    result = AsyncDict()
    result.add("type", value.value_type.name)
    if value.use_default:
        result.add("default", value.default)
    result.add_if_not_none("label", value.label)
    result.add_if_not_none("desc", value.desc)
    result.add_if_true("metadata", render_metadata(value))
    if IEncodingInfo.providedBy(value):
        encinfo = IEncodingInfo(value)
        result.add_if_not_none("mimetype", encinfo.mime_type)
        result.add_if_not_none("encoding", encinfo.encoding)
    if IValueCollection.providedBy(value):
        coll = IValueCollection(value)
        allowed = [render_value_info(v) for v in coll.allowed_types]
        result.add("allowed", defer.join(*allowed))
        result.add("ordered", coll.is_ordered)
        result.add_if_not_none("min_size", coll.min_size)
        result.add_if_not_none("max_size", coll.max_size)
    if IValueRange.providedBy(value):
        vrange = IValueRange(value)
        result.add("minimum", vrange.minimum)
        result.add("maximum", vrange.maximum)
        result.add_if_not_none("increment", vrange.increment)
    if IValueOptions.providedBy(value):
        options = IValueOptions(value)
        result.add("restricted", options.is_restricted)
        result.add("options", [{"label": o.label, "value": o.value}
                               for o in options.iter_options()])
    return result.wait()