Exemplo n.º 1
0
 def parse_xml(cls, doc, source_location):
     """
     Parses the given XML/etree document into an instance of this
     class.
     """
     assert doc.tag == 'ruleset'
     matchers = []
     clientsides = []
     rules = []
     default_theme = None
     for el in doc.iterchildren():
         if el.tag == 'match':
             matcher = Match.parse_xml(el, source_location)
             matchers.append(matcher)
         elif el.tag == 'clientside':
             matcher = ClientsideMatch.parse_xml(el, source_location)
             clientsides.append(matcher)
         elif el.tag == 'rule':
             rule = Rule.parse_xml(el, source_location)
             rules.append(rule)
         elif el.tag == 'theme':
             ## FIXME: Add parse error
             default_theme = Theme.parse_xml(el, source_location)
         elif el.tag in ('proxy', 'server-settings', Comment):
             # Handled elsewhere, so we just ignore this element
             continue
         else:
             ## FIXME: source location?
             raise DeliveranceSyntaxError(
                 "Invalid tag %s (unknown tag name %r)" %
                 (tostring(el).split('>', 1)[0] + '>', el.tag),
                 element=el)
     rules_by_class = {}
     for rule in rules:
         for class_name in rule.classes:
             rules_by_class.setdefault(class_name, []).append(rule)
     return cls(matchers,
                clientsides,
                rules_by_class,
                default_theme=default_theme,
                source_location=source_location)
Exemplo n.º 2
0
 def parse_xml(cls, doc, source_location):
     """
     Parses the given XML/etree document into an instance of this
     class.
     """
     assert doc.tag == 'ruleset'
     matchers = []
     clientsides = []
     rules = []
     default_theme = None
     for el in doc.iterchildren():
         if el.tag == 'match':
             matcher = Match.parse_xml(el, source_location)
             matchers.append(matcher)
         elif el.tag == 'clientside':
             matcher = ClientsideMatch.parse_xml(el, source_location)
             clientsides.append(matcher)
         elif el.tag == 'rule':
             rule = Rule.parse_xml(el, source_location)
             rules.append(rule)
         elif el.tag == 'theme':
             ## FIXME: Add parse error
             default_theme = Theme.parse_xml(el, source_location)
         elif el.tag in ('proxy', 'server-settings', Comment):
             # Handled elsewhere, so we just ignore this element
             continue
         else:
             ## FIXME: source location?
             raise DeliveranceSyntaxError(
                 "Invalid tag %s (unknown tag name %r)" 
                 % (tostring(el).split('>', 1)[0]+'>', el.tag),
                 element=el)
     rules_by_class = {}
     for rule in rules:
         for class_name in rule.classes:
             rules_by_class.setdefault(class_name, []).append(rule)
     return cls(matchers, clientsides, rules_by_class, default_theme=default_theme,
                source_location=source_location)
Exemplo n.º 3
0
        content_match = _content_re.search(content)
        if not http_equiv_match or not content_match:
            ## FIXME: log partial matches?
            continue
        http_equiv = (http_equiv_match.group(1) or http_equiv_match.group(2) or '')
        http_equiv = http_equiv.strip()
        content = content_match.group(1) or content_match.group(2) or ''
        if not http_equiv or not content:
            ## FIXME: is empty content really meaningless?
            continue
        headers.append((http_equiv, content))
    return headers

# Note: these are included in the documentation; any changes should be
# reflected there as well.
standard_rule = Rule.parse_xml(XML('''\
<rule>
  <!-- FIXME: append-or-replace for title? -->
  <!-- FIXME: maybe something like notheme="append:/html/head" -->
  <replace content="children:/html/head/title" 
           theme="children:/html/head/title" nocontent="ignore" />
  <prepend content="elements:/html/head/link" 
          theme="children:/html/head" nocontent="ignore" />
  <prepend content="elements:/html/head/script" 
          theme="children:/html/head" nocontent="ignore" />
  <prepend content="elements:/html/head/style" 
          theme="children:/html/head" nocontent="ignore" />
  <!-- FIXME: Any handling for overlapping/identical elements? -->
</rule>'''), 'deliverance.ruleset.standard_rule')

Exemplo n.º 4
0
        content_match = _content_re.search(content)
        if not http_equiv_match or not content_match:
            ## FIXME: log partial matches?
            continue
        http_equiv = (http_equiv_match.group(1) or http_equiv_match.group(2) or '')
        http_equiv = http_equiv.strip()
        content = content_match.group(1) or content_match.group(2) or ''
        if not http_equiv or not content:
            ## FIXME: is empty content really meaningless?
            continue
        headers.append((http_equiv, content))
    return headers

# Note: these are included in the documentation; any changes should be
# reflected there as well.
standard_rule = Rule.parse_xml(XML('''\
<rule>
  <!-- FIXME: append-or-replace for title? -->
  <!-- FIXME: maybe something like notheme="append:/html/head" -->
  <replace content="children:/html/head/title" 
           theme="children:/html/head/title" nocontent="ignore" />
  <prepend content="elements:/html/head/link" 
          theme="children:/html/head" nocontent="ignore" />
  <prepend content="elements:/html/head/script" 
          theme="children:/html/head" nocontent="ignore" />
  <prepend content="elements:/html/head/style" 
          theme="children:/html/head" nocontent="ignore" />
  <!-- FIXME: Any handling for overlapping/identical elements? -->
</rule>'''), 'deliverance.ruleset.standard_rule')