Example #1
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()
Example #2
0
 def render_binary(self, value, request, response, context, value_info):
     mime_type = None
     encoding = None
     if IEncodingInfo.providedBy(value_info):
         enc_info = IEncodingInfo(value_info)
         mime_type = enc_info.mime_type
         encoding = enc_info.encoding
     mime_type = mime_type or "application/octet-stream"
     response.set_mime_type(mime_type)
     if encoding:
         response.set_encoding(encoding)
     response.set_length(len(value))
     response.write(value)
Example #3
0
        def got_data(data):
            response.set_header("Cache-Control", "no-cache")

            if IEncodingInfo.providedBy(self._action.result_info):
                enc_info = IEncodingInfo(self._action.result_info)
                mime_type = enc_info.mime_type
                encoding = enc_info.encoding

                if mime_type:
                    request.debug("Changing mime_type to %r", mime_type)
                    response.set_mime_type(mime_type)
                if encoding:
                    request.debug("Changing encoding to %r", encoding)
                    response.set_encoding(encoding)

                response.set_length(len(data))
                return response.write(data)

            #FIXME: passing query arguments without validation is not safe
            return response.write_object(data, context=self._context,
                                         **request.arguments)