<commit_before># Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import absolute_import, division, print_function, unicode_literals
from ....extern import six
from ....extern.six.moves import xrange

# STDLIB
import contextlib
import io
from math import ceil
import os
import re

# ASTROPY
from ....utils.xml.writer import XMLWriter, xml_escape
from .... import online_docs_root

# VO
from .. import exceptions

html_header = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
        "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
"""

default_style = """
body {
font-family: sans-serif
}
a {
text-decoration: none
}
.highlight {
color: red;
font-weight: bold;
text-decoration: underline;
}
.green { background-color: #ddffdd }
.red   { background-color: #ffdddd }
.yellow { background-color: #ffffdd }
tr:hover { background-color: #dddddd }
table {
        border-width: 1px;
        border-spacing: 0px;
        border-style: solid;
        border-color: gray;
        border-collapse: collapse;
        background-color: white;
        padding: 5px;
}
table th {
        border-width: 1px;
        padding: 5px;
        border-style: solid;
        border-color: gray;
}
table td {
        border-width: 1px;
        padding: 5px;
        border-style: solid;
        border-color: gray;
}
"""


@contextlib.contextmanager
def make_html_header(w):
    w.write(html_header)
    with w.tag('html', xmlns="http://www.w3.org/1999/xhtml", lang="en-US"):
        with w.tag('head'):
            w.element('title', 'VO Validation results')
            w.element('style', default_style)

            with w.tag('body'):
                yield


def write_source_line(w, line, nchar=0):
    part1 = xml_escape(line[:nchar].decode('utf-8'))
    char = xml_escape(line[nchar:nchar+1].decode('utf-8'))
    part2 = xml_escape(line[nchar+1:].decode('utf-8'))

    w.write('  ')
    w.write(part1)
    w.write('<span class="highlight">%s</span>' % char)
    w.write(part2)
    w.write('\n\n')


def write_warning(w, line, xml_lines):
    warning = exceptions.parse_vowarning(line)
    if not warning['is_something']:
        w.data(line)
    else:
        w.write('Line %d: ' % warning['nline'])
        if warning['warning']:
            w.write('<a href="%s/%s">%s</a>: ' % (
                online_docs_root, warning['doc_url'], warning['warning']))
        msg = warning['message']
        if not isinstance(warning['message'], six.text_type):
            msg = msg.decode('utf-8')
        w.write(xml_escape(msg))
        w.write('\n')
        write_source_line(w, xml_lines[warning['nline'] - 1], warning['nchar'])


def write_votlint_warning(w, line, xml_lines):
    match = re.search("(WARNING|ERROR|INFO) \(l.(?P<line>[0-9]+), c.(?P<column>[0-9]+)\): (?P<rest>.*)", line)
    if match:
        w.write('Line %d: %s\n' %<commit_msg>Fix for io.votable.validator<commit_after># Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import absolute_import, division, print_function, unicode_literals
from ....extern import six
from ....extern.six.moves import xrange

# STDLIB
import contextlib
import io
from math import ceil
import os
import re

# ASTROPY
from ....utils.xml.writer import XMLWriter, xml_escape
from .... import online_docs_root

# VO
from .. import exceptions

html_header = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
        "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
"""

default_style = """
body {
font-family: sans-serif
}
a {
text-decoration: none
}
.highlight {
color: red;
font-weight: bold;
text-decoration: underline;
}
.green { background-color: #ddffdd }
.red   { background-color: #ffdddd }
.yellow { background-color: #ffffdd }
tr:hover { background-color: #dddddd }
table {
        border-width: 1px;
        border-spacing: 0px;
        border-style: solid;
        border-color: gray;
        border-collapse: collapse;
        background-color: white;
        padding: 5px;
}
table th {
        border-width: 1px;
        padding: 5px;
        border-style: solid;
        border-color: gray;
}
table td {
        border-width: 1px;
        padding: 5px;
        border-style: solid;
        border-color: gray;
}
"""


@contextlib.contextmanager
def make_html_header(w):
    w.write(html_header)
    with w.tag('html', xmlns="http://www.w3.org/1999/xhtml", lang="en-US"):
        with w.tag('head'):
            w.element('title', 'VO Validation results')
            w.element('style', default_style)

            with w.tag('body'):
                yield


def write_source_line(w, line, nchar=0):
    part1 = xml_escape(line[:nchar].decode('utf-8'))
    char = xml_escape(line[nchar:nchar+1].decode('utf-8'))
    part2 = xml_escape(line[nchar+1:].decode('utf-8'))

    w.write('  ')
    w.write(part1)
    w.write('<span class="highlight">%s</span>' % char)
    w.write(part2)
    w.write('\n\n')


def write_warning(w, line, xml_lines):
    warning = exceptions.parse_vowarning(line)
    if not warning['is_something']:
        w.data(line)
    else:
        w.write('Line %d: ' % warning['nline'])
        if warning['warning']:
            w.write('<a href="%s/%s">%s</a>: ' % (
                online_docs_root, warning['doc_url'], warning['warning']))
        msg = warning['message']
        if not isinstance(warning['message'], six.text_type):
            msg = msg.decode('utf-8')
        w.write(xml_escape(msg))
        w.write('\n')
        if warning['nline'] >= 1 and warning['nline'] < len(xml_lines):
            write_source_line(w, xml_lines[warning['nline'] - 1], warning['nchar'])


def write_votlint_warning(w, line, xml_lines):
    match = re.search("(WARNING|ERROR|INFO) \(l.(?P<line>[0-9]+), c.(?P<column>[0-9]+)\): (?P<rest>.*)", line)
    if match:
        w.write('Line %d: %s\n' %
{'fraction_non_alphanumeric': 0.16624515258809644, 'fraction_numerical': 0.012982633619962906, 'mean_word_length': 2.824629271437782, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 2, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 23}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3851466', 'n_tokens_mistral': 2105, 'n_tokens_neox': 2004, 'n_words': 428}