예제 #1
0
파일: html.py 프로젝트: vfaronov/httpolice
def _render_header_entries(annotated_entries):
    for entry, annotated in annotated_entries:
        with H.pre(**_for_object(entry, 'header-entry')), H.code():
            # Dominate defaults to ``__pretty=False`` for ``pre``.
            _render_known(entry.name)
            text_node(u': ')
            _render_annotated(annotated)
예제 #2
0
파일: html.py 프로젝트: vfaronov/httpolice
def _cite_elem_to_html(elem, ctx):
    _piece_to_html(elem.info, ctx)
    quote = elem.content
    if quote:
        text_node(u': ')
        with H.q():
            _piece_to_html(quote, ctx)
예제 #3
0
파일: html.py 프로젝트: vfaronov/httpolice
def _render_annotated(pieces):
    """Render an annotated string as produced by :mod:`httpolice.parse`."""
    for piece in pieces:
        if isinstance(piece, bytes):
            text_node(printable(piece.decode('iso-8859-1')))
        else:
            _render_known(piece)
예제 #4
0
파일: html.py 프로젝트: weijl6819/httpolice
def _cite_elem_to_html(elem, ctx):
    _piece_to_html(elem.info, ctx)
    quote = elem.content
    if quote:
        text_node(u': ')
        with H.q():
            _piece_to_html(quote, ctx)
예제 #5
0
파일: html.py 프로젝트: weijl6819/httpolice
def _render_annotated(pieces):
    """Render an annotated string as produced by :mod:`httpolice.parse`."""
    for piece in pieces:
        if isinstance(piece, bytes):
            text_node(printable(piece.decode('iso-8859-1')))
        else:
            _render_known(piece)
예제 #6
0
파일: html.py 프로젝트: weijl6819/httpolice
def _render_header_entries(annotated_entries):
    for entry, annotated in annotated_entries:
        with H.pre(**_for_object(entry, 'header-entry')), H.code():
            # Dominate defaults to ``__pretty=False`` for ``pre``.
            _render_known(entry.name)
            text_node(u': ')
            _render_annotated(annotated)
예제 #7
0
파일: html.py 프로젝트: vfaronov/httpolice
def _render_known(obj):
    """Render an instance of one of the :data:`httpolice.known.classes`."""
    text = printable(str(obj))
    cite = known.citation(obj)
    if cite:
        with H.a(text, href=cite.url):
            title = known.title(obj, with_citation=True)
            if title:
                H.attr(title=title)
    else:
        text_node(text)
예제 #8
0
파일: html.py 프로젝트: weijl6819/httpolice
def _render_known(obj):
    """Render an instance of one of the :data:`httpolice.known.classes`."""
    text = printable(str(obj))
    cite = known.citation(obj)
    if cite:
        with H.a(text, href=cite.url):
            title = known.title(obj, with_citation=True)
            if title:
                H.attr(title=title)
    else:
        text_node(text)
예제 #9
0
파일: html.py 프로젝트: tomzhang/httpolice
def _render_response(resp):
    with H.section():
        with H.div(_class=u'message-display'):
            if resp.remark:
                H.p(printable(resp.remark), _class=u'message-remark')
            with H.h2(), H.code():  # Status line
                # See above regarding spaces.
                if resp.version:
                    H.span(printable(resp.version),
                           **_for_object(resp.version))
                with H.span(**_for_object(resp.status)):
                    _render_known(resp.status)
                    text_node(u' ' + printable(find_reason_phrase(resp)))
            _render_message(resp)  # Headers, body and all that
        _render_complaints(resp)
예제 #10
0
파일: html.py 프로젝트: vfaronov/httpolice
def _render_response(resp):
    with H.section():
        with H.div(_class=u'message-display'):
            if resp.remark:
                H.p(printable(resp.remark), _class=u'message-remark')
            with H.h2(), H.code():      # Status line
                # See above regarding spaces.
                if resp.version:
                    H.span(printable(resp.version),
                           **_for_object(resp.version))
                # httpolice-devtool (the Chrome extension) relies
                # on the ``StatusCode`` class. Avoid breaking it, at least
                # as long as it doesn't inconvenience HTTPolice itself.
                with H.span(**_for_object(resp.status, u'StatusCode')):
                    _render_known(resp.status)
                    text_node(u' ' + printable(find_reason_phrase(resp)))
            _render_message(resp)       # Headers, body and all that
        _render_complaints(resp)
예제 #11
0
파일: html.py 프로젝트: weijl6819/httpolice
def _render_response(resp):
    with H.section():
        with H.div(_class=u'message-display'):
            if resp.remark:
                H.p(printable(resp.remark), _class=u'message-remark')
            with H.h2(), H.code():  # Status line
                # See above regarding spaces.
                if resp.version:
                    H.span(printable(resp.version),
                           **_for_object(resp.version))
                # httpolice-devtool (the Chrome extension) relies
                # on the ``StatusCode`` class. Avoid breaking it, at least
                # as long as it doesn't inconvenience HTTPolice itself.
                with H.span(**_for_object(resp.status, u'StatusCode')):
                    _render_known(resp.status)
                    text_node(u' ' + printable(find_reason_phrase(resp)))
            _render_message(resp)  # Headers, body and all that
        _render_complaints(resp)
예제 #12
0
파일: html.py 프로젝트: vfaronov/httpolice
def html_report(exchanges, buf):
    """Generate an HTML report with check results.

    :param exchanges:
        An iterable of :class:`~httpolice.Exchange` objects.
        They must be already processed by :func:`~httpolice.check_exchange`.

    :param buf:
        The file (or file-like object) to which the report will be written.
        It must be opened in binary mode (not text).

    """
    # We don't want to hold the entire report in memory before printing it,
    # because that would mean unbounded memory growth with more input.
    # But Dominate obviously doesn't have a streaming mode, so we do this
    # manually. We create our document, but instead of the actual exchanges,
    # we insert a separator string that allows us to split it into a prologue
    # and an epilogue.
    separator = u'---- CUT HERE ----'

    title = u'HTTPolice report'
    document = dominate.document(title=title)
    _common_meta(document)
    with document.head:
        H.script(type=u'text/javascript').add_raw_string(js_code)
    with document.body:
        H.attr(_class=u'report')
    with document:
        H.h1(title)
        H.hr()
        text_node(separator)

    (prologue, epilogue) = document.render().split(separator)

    buf.write(prologue.encode('utf-8'))
    for div in _generate_exchange_divs(exchanges):
        buf.write(div.render().encode('utf-8'))
    buf.write(epilogue.encode('utf-8'))
예제 #13
0
파일: html.py 프로젝트: weijl6819/httpolice
def html_report(exchanges, buf):
    """Generate an HTML report with check results.

    :param exchanges:
        An iterable of :class:`~httpolice.Exchange` objects.
        They must be already processed by :func:`~httpolice.check_exchange`.

    :param buf:
        The file (or file-like object) to which the report will be written.
        It must be opened in binary mode (not text).

    """
    # We don't want to hold the entire report in memory before printing it,
    # because that would mean unbounded memory growth with more input.
    # But Dominate obviously doesn't have a streaming mode, so we do this
    # manually. We create our document, but instead of the actual exchanges,
    # we insert a separator string that allows us to split it into a prologue
    # and an epilogue.
    separator = u'---- CUT HERE ----'

    title = u'HTTPolice report'
    document = dominate.document(title=title)
    _common_meta(document)
    with document.head:
        H.script(type=u'text/javascript').add_raw_string(js_code)
    with document.body:
        H.attr(_class=u'report')
    with document:
        H.h1(title)
        H.hr()
        text_node(separator)

    (prologue, epilogue) = document.render().split(separator)

    buf.write(prologue.encode('utf-8'))
    for div in _generate_exchange_divs(exchanges):
        buf.write(div.render().encode('utf-8'))
    buf.write(epilogue.encode('utf-8'))
예제 #14
0
파일: html.py 프로젝트: vfaronov/httpolice
def _text_to_html(text, _):
    text_node(printable(text))
예제 #15
0
파일: html.py 프로젝트: weijl6819/httpolice
def _text_to_html(text, _):
    text_node(printable(text))