How to use the diazo.utils.quote_param function in diazo

To help you get started, we’ve selected a few diazo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github plone / plone.app.theming / src / plone / app / theming / browser / mapper.py View on Github external
context = findPathContext(path) or portal

            serializer = getHTMLSerializer([result], pretty_print=False)

            try:
                transform = compileThemeTransform(
                    themeInfo.rules, themeInfo.absolutePrefix,
                    settings.readNetwork, themeInfo.parameterExpressions or {})
            except lxml.etree.XMLSyntaxError as e:
                return self.theme_error_template(error=e.msg)

            params = prepareThemeParameters(
                context, self.request, themeInfo.parameterExpressions or {})

            # Fix url and path since the request gave us this view
            params['url'] = quote_param(''.join((portal_url, path,)))
            params['path'] = quote_param(
                ''.join((portal.absolute_url_path(), path,))
            )

            if themeInfo.doctype:
                serializer.doctype = themeInfo.doctype
                if not serializer.doctype.endswith('\n'):
                    serializer.doctype += '\n'

            serializer.tree = transform(serializer.tree, **params)
            result = b''.join(serializer)

        if title or links or forms:
            tree = lxml.html.fromstring(result)

            def encodeUrl(orig):
github plone / diazo / lib / diazo / compiler.py View on Github external
if 'path' not in xsl_params:
        xsl_params['path'] = ''
    known_params = etree.XML(
        '',
    )
    for param_name, param_value in xsl_params.items():
        param_element = etree.SubElement(
            known_params,
            '{http://www.w3.org/1999/XSL/Transform}param',
        )
        param_element.attrib['name'] = param_name
        if isinstance(param_value, string_types):
            param_element.text = param_value
        else:
            param_element.attrib['select'] = str(quote_param(param_value))
        param_element.tail = '\n'

    return known_params
github plone / diazo / lib / diazo / compiler.py View on Github external
# for every value passed in as xsl_params
    known_params = build_xsl_params_document(xsl_params)

    # Create a pseudo resolver for this
    known_params_url = 'file:///__diazo_known_params__'
    emit_stylesheet_resolver = CustomResolver({
        known_params_url: etree.tostring(known_params),
    })
    emit_stylesheet_parser = etree.XMLParser()
    emit_stylesheet_parser.resolvers.add(emit_stylesheet_resolver)

    # Set up parameters
    params = {}
    if indent is not None:
        params['indent'] = indent and "'yes'" or "'no'"
    params['known_params_url'] = quote_param(known_params_url)
    params['runtrace'] = '1' if runtrace else '0'

    # Run the final stage compiler
    emit_stylesheet = pkg_xsl(
        'emit-stylesheet.xsl',
        parser=emit_stylesheet_parser,
    )
    compiled_doc = emit_stylesheet(rules_doc, **params)
    compiled_doc = set_parser(
        etree.tostring(compiled_doc),
        parser,
        compiler_parser,
    )

    return compiled_doc
github plone / diazo / lib / diazo / wsgi.py View on Github external
return response(environ, start_response)
        
        # Set up parameters
        
        params = {}
        for key, value in self.environ_param_map.items():
            if key in environ:
                if value in self.unquoted_params:
                    params[value] = environ[key]
                else:
                    params[value] = quote_param(environ[key])
        for key, value in self.params.items():
            if key in self.unquoted_params:
                params[key] = value
            else:
                params[key] = quote_param(value)
        
        # Apply the transformation
        try:
            serializer = getHTMLSerializer(response.app_iter, encoding=input_encoding)
        finally:
            if hasattr(response.app_iter, 'close'):
                response.app_iter.close()
        
        tree = self.transform(serializer.tree, **params)
        
        # Set content type (normally inferred from stylesheet)
        # Unfortunately lxml does not expose docinfo.mediaType
        if self.content_type is None:
            if tree.getroot().tag == 'html':
                response.content_type = 'text/html'
            else:
github plone / diazo / lib / diazo / wsgi.py View on Github external
if self.content_type is not None:
            response.charset = self.charset

        # Note, the Content-Length header will not be set
        if request.method == 'HEAD':
            return response(environ, start_response)
        
        # Set up parameters
        
        params = {}
        for key, value in self.environ_param_map.items():
            if key in environ:
                if value in self.unquoted_params:
                    params[value] = environ[key]
                else:
                    params[value] = quote_param(environ[key])
        for key, value in self.params.items():
            if key in self.unquoted_params:
                params[key] = value
            else:
                params[key] = quote_param(value)
        
        # Apply the transformation
        try:
            serializer = getHTMLSerializer(response.app_iter, encoding=input_encoding)
        finally:
            if hasattr(response.app_iter, 'close'):
                response.app_iter.close()
        
        tree = self.transform(serializer.tree, **params)
        
        # Set content type (normally inferred from stylesheet)