Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def prepareThemeParameters(context, request, parameterExpressions, cache=None):
"""Prepare and return a dict of parameter expression values.
"""
# Find real or virtual path - PATH_INFO has VHM elements in it
url = request.get('ACTUAL_URL', '')
# Find the host name
base = request.get('BASE1', '')
path = url[len(base):]
parts = urlsplit(base.lower())
params = dict(
url=quote_param(url),
base=quote_param(base),
path=quote_param(path),
scheme=quote_param(parts.scheme),
host=quote_param(parts.netloc),
)
# Add expression-based parameters
if not parameterExpressions:
return params
# Compile and cache expressions
expressions = None
if cache is not None:
expressions = cache.expressions
if expressions is None:
expressions = {}
for name, expressionText in parameterExpressions.items():
def prepareThemeParameters(context, request, parameterExpressions, cache=None):
"""Prepare and return a dict of parameter expression values.
"""
# Find real or virtual path - PATH_INFO has VHM elements in it
url = request.get('ACTUAL_URL', '')
# Find the host name
base = request.get('BASE1', '')
path = url[len(base):]
parts = urlsplit(base.lower())
params = dict(
url=quote_param(url),
base=quote_param(base),
path=quote_param(path),
scheme=quote_param(parts.scheme),
host=quote_param(parts.netloc),
)
# Add expression-based parameters
if not parameterExpressions:
return params
# Compile and cache expressions
expressions = None
if cache is not None:
expressions = cache.expressions
if expressions is None:
expressions = {}
"""
# Find real or virtual path - PATH_INFO has VHM elements in it
url = request.get('ACTUAL_URL', '')
# Find the host name
base = request.get('BASE1', '')
path = url[len(base):]
parts = urlsplit(base.lower())
params = dict(
url=quote_param(url),
base=quote_param(base),
path=quote_param(path),
scheme=quote_param(parts.scheme),
host=quote_param(parts.netloc),
)
# Add expression-based parameters
if not parameterExpressions:
return params
# Compile and cache expressions
expressions = None
if cache is not None:
expressions = cache.expressions
if expressions is None:
expressions = {}
for name, expressionText in parameterExpressions.items():
expressions[name] = compileExpression(expressionText)
def prepareThemeParameters(context, request, parameterExpressions, cache=None):
"""Prepare and return a dict of parameter expression values.
"""
# Find real or virtual path - PATH_INFO has VHM elements in it
url = request.get('ACTUAL_URL', '')
# Find the host name
base = request.get('BASE1', '')
path = url[len(base):]
parts = urlsplit(base.lower())
params = dict(
url=quote_param(url),
base=quote_param(base),
path=quote_param(path),
scheme=quote_param(parts.scheme),
host=quote_param(parts.netloc),
)
# Add expression-based parameters
if not parameterExpressions:
return params
# Compile and cache expressions
expressions = None
if cache is not None:
expressions = cache.expressions
if expressions is None:
"""Prepare and return a dict of parameter expression values.
"""
# Find real or virtual path - PATH_INFO has VHM elements in it
url = request.get('ACTUAL_URL', '')
# Find the host name
base = request.get('BASE1', '')
path = url[len(base):]
parts = urlsplit(base.lower())
params = dict(
url=quote_param(url),
base=quote_param(base),
path=quote_param(path),
scheme=quote_param(parts.scheme),
host=quote_param(parts.netloc),
)
# Add expression-based parameters
if not parameterExpressions:
return params
# Compile and cache expressions
expressions = None
if cache is not None:
expressions = cache.expressions
if expressions is None:
expressions = {}
for name, expressionText in parameterExpressions.items():
expressions[name] = compileExpression(expressionText)
def set_parser(stylesheet, parser, compiler_parser=None):
file_obj = pkg_resources.resource_filename('diazo', 'dummy.html')
with open(file_obj) as file_handler:
dummy_doc = etree.parse(
file_handler,
parser=parser,
)
name = 'file:///__diazo__'
resolver = CustomResolver({name: stylesheet})
if compiler_parser is None:
compiler_parser = etree.XMLParser()
compiler_parser.resolvers.add(resolver)
identity = pkg_xsl('identity.xsl', compiler_parser)
output_doc = identity(dummy_doc, docurl="'{name}'".format(name=name))
compiler_parser.resolvers.remove(resolver)
return output_doc
#!/usr/bin/env python
import logging
from diazo.rules import process_rules
from diazo.utils import pkg_xsl
from lxml import etree
from xml.etree import ElementTree
logger = logging.getLogger('diazo')
_runtrace_to_html = pkg_xsl('runtrace_to_html.xsl')
def log_to_xml_string(error_log):
return """
%s
""" % "".join(l.message for l
in error_log
if l.message.startswith('
CONDITIONAL_SRC = re.compile(
r"""(?P<[^>]*?(src|href)=(?P['"]?))"""
r"""(?P[^ \t\n\r\f\v>]+)(?P(?P=quote)[^>]*?>)""",
re.IGNORECASE,
)
SRCSET = re.compile(r'(?P^\s*|\s*,\s*)(?P[^\s]*)')
update_transform = pkg_xsl('update-namespace.xsl')
normalize_rules = pkg_xsl('normalize-rules.xsl')
include = pkg_xsl('include.xsl')
apply_conditions = pkg_xsl('apply-conditions.xsl')
merge_conditions = pkg_xsl('merge-conditions.xsl')
annotate_themes = pkg_xsl('annotate-themes.xsl')
annotate_rules = pkg_xsl('annotate-rules.xsl')
apply_rules = pkg_xsl('apply-rules.xsl')
fixup_themes = pkg_xsl('fixup-themes.xsl')
def anchor_safe_urljoin(base, url):
"""Join the base with the url only when the url doesn't start with '#'"""
if url.startswith('#'):
return url
else:
return urljoin(base, url)
def add_identifiers(rules_doc):
"""Add identifiers to the rules for debugging"""
for index, elem in enumerate(
rules_doc.xpath(
'//diazo:rules | //diazo:rules/diazo:*'
usage = __doc__
IMPORT_STYLESHEET = re.compile(
r"""(?P@import[ \t]+(?Purl\([ \t]?)?(?P['"]?))"""
r"""(?P\S+)(?P(?P=quote)(?(paren)\)))""",
re.IGNORECASE,
)
CONDITIONAL_SRC = re.compile(
r"""(?P<[^>]*?(src|href)=(?P['"]?))"""
r"""(?P[^ \t\n\r\f\v>]+)(?P(?P=quote)[^>]*?>)""",
re.IGNORECASE,
)
SRCSET = re.compile(r'(?P^\s*|\s*,\s*)(?P[^\s]*)')
update_transform = pkg_xsl('update-namespace.xsl')
normalize_rules = pkg_xsl('normalize-rules.xsl')
include = pkg_xsl('include.xsl')
apply_conditions = pkg_xsl('apply-conditions.xsl')
merge_conditions = pkg_xsl('merge-conditions.xsl')
annotate_themes = pkg_xsl('annotate-themes.xsl')
annotate_rules = pkg_xsl('annotate-rules.xsl')
apply_rules = pkg_xsl('apply-rules.xsl')
fixup_themes = pkg_xsl('fixup-themes.xsl')
def anchor_safe_urljoin(base, url):
"""Join the base with the url only when the url doesn't start with '#'"""
if url.startswith('#'):
return url
else:
return urljoin(base, url)
IMPORT_STYLESHEET = re.compile(
r"""(?P@import[ \t]+(?Purl\([ \t]?)?(?P['"]?))"""
r"""(?P\S+)(?P(?P=quote)(?(paren)\)))""",
re.IGNORECASE,
)
CONDITIONAL_SRC = re.compile(
r"""(?P<[^>]*?(src|href)=(?P['"]?))"""
r"""(?P[^ \t\n\r\f\v>]+)(?P(?P=quote)[^>]*?>)""",
re.IGNORECASE,
)
SRCSET = re.compile(r'(?P^\s*|\s*,\s*)(?P[^\s]*)')
update_transform = pkg_xsl('update-namespace.xsl')
normalize_rules = pkg_xsl('normalize-rules.xsl')
include = pkg_xsl('include.xsl')
apply_conditions = pkg_xsl('apply-conditions.xsl')
merge_conditions = pkg_xsl('merge-conditions.xsl')
annotate_themes = pkg_xsl('annotate-themes.xsl')
annotate_rules = pkg_xsl('annotate-rules.xsl')
apply_rules = pkg_xsl('apply-rules.xsl')
fixup_themes = pkg_xsl('fixup-themes.xsl')
def anchor_safe_urljoin(base, url):
"""Join the base with the url only when the url doesn't start with '#'"""
if url.startswith('#'):
return url
else:
return urljoin(base, url)