Beispiel #1
0
 def process_raw_headers(self, headers: RawHeaderListType) -> None:
     """
     Feed a list of (bytes name, bytes value) header tuples in and process them.
     """
     hp = HeaderProcessor(self)
     self.headers, self.parsed_headers = hp.process(headers)
     if 'content-type' in self.parsed_headers:
         self.character_encoding = self.parsed_headers['content-type'][1].get('charset', 'utf-8')
         # default isn't UTF-8, but oh well
     self.emit("headers_available")
Beispiel #2
0
 def process_raw_headers(self, headers: RawHeaderListType) -> None:
     """
     Feed a list of (bytes name, bytes value) header tuples in and process them.
     """
     hp = HeaderProcessor(self)
     self.headers, self.parsed_headers = hp.process(headers)
     if 'content-type' in self.parsed_headers:
         self.character_encoding = self.parsed_headers['content-type'][1].get('charset', 'utf-8')
         # default isn't UTF-8, but oh well
     self.emit("headers_available")
Beispiel #3
0
 def format_note_description(self, header_name: str) -> Markup:
     description = HeaderProcessor.find_header_handler(header_name).description
     if description:
         return Markup(
             markdown(
                 description % {"field_name": header_name}, output_format="html5"
             )
         )
     return Markup("")
Beispiel #4
0
def checkRegistryCoverage(xml_file):
    """
    Given an XML file from <https://www.iana.org/assignments/message-headers/message-headers.xml>,
    See what headers are missing and check those remaining to see what they don't define.
    """
    for header_name in parseHeaderRegistry(xml_file):
        header_mod = HeaderProcessor.find_header_module(header_name)
        if not header_mod:
            sys.stderr.write("- %s registered but can't find module\n" % header_name)
Beispiel #5
0
def checkRegistryCoverage(xml_file):
    """
    Given an XML file from <https://www.iana.org/assignments/message-headers/message-headers.xml>,
    See what headers are missing and check those remaining to see what they don't define.
    """
    for header_name in parseHeaderRegistry(xml_file):
        header_mod = HeaderProcessor.find_header_module(header_name)
        if not header_mod:
            sys.stderr.write("- %s registered but can't find module\n" %
                             header_name)
Beispiel #6
0
 def format_header_description(self, header_name: str) -> Markup:
     description = HeaderProcessor.find_header_handler(header_name).description
     if description:
         return Markup(
             '<span class="tip">'
             + markdown(
                 description % {"field_name": header_name}, output_format="html5"
             )
             + "</span>"
         )
     return Markup("")
Beispiel #7
0
 def format_header(self, name: str, value: str, offset: int) -> str:
     "Return an individual HTML header as HTML"
     token_name = "header-%s" % name.lower()
     header_desc = HeaderProcessor.find_header_handler(name).description
     if header_desc and token_name not in [i[0] for i in self.hidden_text]:
         html_desc = markdown(header_desc % {'field_name': name},
                              output_format="html5")
         self.hidden_text.append((token_name, html_desc))
     return """\
 <span data-offset='%s' data-name='%s' class='hdr'>%s:%s</span>""" % (
         offset, e_html(name.lower()), e_html(name),
         self.header_presenter.Show(name, value))
Beispiel #8
0
 def format_header(self, name: str, value: str, offset: int) -> str:
     "Return an individual HTML header as HTML"
     token_name = "header-%s" % name.lower()
     header_desc = HeaderProcessor.find_header_handler(name).description
     if header_desc and token_name not in [i[0] for i in self.hidden_text]:
         html_desc = markdown(header_desc % {'field_name': name}, output_format="html5")
         self.hidden_text.append((token_name, html_desc))
     return """\
 <span data-offset='%s' data-name='%s' class='hdr'>%s:%s</span>""" % (
     offset,
     e_html(name.lower()),
     e_html(name),
     self.header_presenter.Show(name, value))
Beispiel #9
0
def checkHeader(header_cls):
    """
    Given a header class, make sure it's complete. Complain on STDERR if not.
    """

    header_name = getattr(header_cls, 'canonical_name') or header_cls.__name__
    attrs = dir(header_cls)
    checks = [
        ('canonical_name', [str], True),
        ('reference', [str], True),
        ('description', [str], True),
        ('valid_in_requests', [bool], True),
        ('valid_in_responses', [bool], True),
        ('syntax', [str, list_rule], True),
        ('list_header', [bool], True),
        ('deprecated', [bool], False),
    ]
    for (attr_name, attr_types, attr_required) in checks:
        attr_value = getattr(header_cls, attr_name)
        if getattr(header_cls, "no_coverage") and attr_name in ['syntax']:
            continue
        if attr_name in ['syntax'] and attr_value == False:
            continue
        if attr_required and attr_value is None:
            sys.stderr.write("* %s lacks %s\n" % (header_name, attr_name))
        elif True not in [isinstance(attr_value, t) for t in attr_types]:
            sys.stderr.write("* %s %s has wrong type\n" %
                             (header_name, attr_name))

    canonical_name = getattr(header_cls, "canonical_name")
    if canonical_name != header_name:
        sys.stderr.write("* %s has mismatching canonical name %s\n" %
                         (header_name, canonical_name))

    loader = unittest.TestLoader()
    header_mod = HeaderProcessor.find_header_module(header_name)
    tests = loader.loadTestsFromModule(header_mod)
    if tests.countTestCases() == 0 and getattr(header_cls,
                                               "no_coverage") == False:
        sys.stderr.write("* %s doesn't have any tests\n" % header_name)
Beispiel #10
0
def checkHeader(header_cls):
    """
    Given a header class, make sure it's complete. Complain on STDERR if not.
    """

    header_name = getattr(header_cls, 'canonical_name') or header_cls.__name__
    attrs = dir(header_cls)
    checks = [
        ('canonical_name', [str], True),
        ('reference', [str], True),
        ('description', [str], True),
        ('valid_in_requests', [bool], True),
        ('valid_in_responses', [bool], True),
        ('syntax', [str, list_rule], True),
        ('list_header', [bool], True),
        ('deprecated', [bool], False),
    ]
    for (attr_name, attr_types, attr_required) in checks:
        attr_value = getattr(header_cls, attr_name)
        if getattr(header_cls, "no_coverage") and attr_name in ['syntax']:
            continue
        if attr_name in ['syntax'] and attr_value == False:
            continue
        if attr_required and attr_value == None:
            sys.stderr.write("* %s lacks %s\n" % (header_name, attr_name))
        elif True not in [isinstance(attr_value, t) for t in attr_types]:
            sys.stderr.write("* %s %s has wrong type\n" % (header_name, attr_name))

    canonical_name = getattr(header_cls, "canonical_name")
    if canonical_name != header_name:
        sys.stderr.write("* %s has mismatching canonical name %s\n" % (header_name, canonical_name))

    loader = unittest.TestLoader()
    header_mod = HeaderProcessor.find_header_module(header_name)
    tests = loader.loadTestsFromModule(header_mod)
    if tests.countTestCases() == 0 and getattr(header_cls, "no_coverage") == False:
        sys.stderr.write("* %s doesn't have any tests\n" % header_name)