示例#1
0
    def change(self, id):
        from .models.changes import Change

        change = Change.query.get(id)
        previous = (Change.query.filter(
            Change.created_at < change.created_at).filter(
                Change.cve == change.cve).order_by(
                    Change.created_at.desc()).first())

        if previous:
            previous_json = previous.json
        else:
            previous_json = {}

        differ = HtmlDiff(wrapcolumn=100)
        diff = differ.make_table(
            json.dumps(previous_json, sort_keys=True, indent=2).split("\n"),
            json.dumps(change.json, sort_keys=True, indent=2).split("\n"),
            "Old",
            "New",
        )

        return self.render("/admin/change.html",
                           change=change,
                           previous=previous,
                           diff=diff)
示例#2
0
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    extra = getattr(report, "extra", [])
    if report.when == "call" and report.outcome != "skipped":
        props = {k: v for k, v in report.user_properties}
        if "compare" in props:
            required, obtained = props["compare"]
            html_content = """
                <button class="copy-button" onclick="this.nextElementSibling.select();document.execCommand('copy');this.textContent = 'Copied!';">Copy obtained output to clipboard</button>
                <textarea class="hidden-textarea" readonly>{}</textarea>
            """.format(escape(obtained))
            actual = obtained.split("\n")
            htmldiff = HtmlDiff(2)
            html_content += '<h4>Diffs</h4><div class="diffs">'
            html_content += "<hr>".join(
                htmldiff.make_table(
                    expected.split("\n"),
                    actual,
                    fromdesc="expected",
                    todesc="actual",
                    context=True,
                ) for expected in required)
            html_content += "</div>"
            extra.append(pytest_html.extras.html(html_content))
        report.extra = extra
示例#3
0
文件: pages.py 项目: Turupawn/website
def installer_diff(request):

    form = DiffInstallerForm()
    diff_table = None

    installer_1_id = request.GET.get('installer_1')
    installer_2_id = request.GET.get('installer_2')

    installer_1 = None
    installer_2 = None

    if installer_1_id and installer_2_id:
        installer_1 = get_object_or_404(Installer, id=installer_1_id)
        installer_2 = get_object_or_404(Installer, id=installer_2_id)
        i1_lines = installer_1.content.split('\n')
        i2_lines = installer_2.content.split('\n')
        diff = HtmlDiff(tabsize=2, wrapcolumn=64)
        diff_table = diff.make_table(i1_lines, i2_lines)

    return render(
        request, 'installers/diff.html', {
            'form': form,
            'diff_table': diff_table,
            'installer_1': installer_1,
            'installer_2': installer_2
        })
示例#4
0
 def run(self):
     with open(self.options['left']) as left:
         left_lines = left.readlines()
     with open(self.options['right']) as right:
         right_lines = right.readlines()
     diff = HtmlDiff()
     return [nodes.raw('', diff.make_table(left_lines, right_lines), format='html')]
def create_diff(csv1, csv2, diff_output_file, context, numlines):
    """creates a html source code file with diff details

    context, set to True for contextual differences (defaults to False
    which shows full differences i.e. the whole file. Lines that
    have changes and also those that don't have any changes).

    numlines, number of context lines. When context is set to True,
    controls number of lines(extra lines) displayed before
    and after the lines where the changes have been made.
    When context is False, controls the number of lines to place
    the "next" link anchors before the next change in the diff html
    file (so click of "next" link jumps to just before the change).
    It basically is used to position the "next" anchor tag a particular
    number of lines before the change.
    """
    html_diff = HtmlDiff()
    try:
        with open(csv1, 'r', encoding="ISO-8859-1") as file1, \
                open(csv2, 'r', encoding="ISO-8859-1") as file2, \
                open(diff_output_file, 'w') as file3:
            diff_lines = html_diff.make_file(file1,
                                             file2,
                                             context=context,
                                             numlines=numlines)
            file3.writelines(diff_lines)
            return True
    except IOError as e:
        print(e, ": in create diff")
        return IOError
示例#6
0
def html_diff(old_as_text, new_as_text):  # {{{1
    """ returns a utf8 string containing the code of a html table showing
    differences of the utf8 parameters """
    old_as_text = old_as_text.splitlines()
    new_as_text = new_as_text.splitlines()
    table = HtmlDiff(tabsize=4).make_table(old_as_text, new_as_text)
    return table.replace('&nbsp;', ' ').replace(' nowrap="nowrap"', '')
示例#7
0
def diff(request, group, snipName, changeId=None):
    snip = get_object_or_404(WikiSnip, group=group, name=snipName)
    if not snip.has_view_permission():
        raise PermissionDenied()
    changeEnd = get_object_or_404(
        WikiSnipChange,
        snip=snip,
        pk=changeId,
    )
    args = {
        'snip': snip,
        'snipName': snipName,
    }
    try:
        changeStart = snip.wikisnipchange_set.filter(
            edited__lt=changeEnd.edited, ).order_by('-edited')[0]
        args['prev_change'] = changeStart
    except IndexError:
        changeStart = None
        diffTable = ugettext("This is the first change.")

    try:
        next_change = snip.wikisnipchange_set.filter(
            edited__gt=changeEnd.edited, ).order_by('edited')[0]
        args['next_change'] = next_change
    except IndexError:
        pass

    if changeStart:
        htmlDiff = HtmlDiff(wrapcolumn=50, )
        from sphene.community.templatetags.sph_extras import sph_date, sph_user_displayname
        desc = ugettext('%(date)s by %(editor)s')
        if snip.has_edit_permission():
            desc += ' / <a href="%(editversionlink)s">' + ugettext(
                'Edit this version') + '</a>'
        fromdesc = desc % {
            'date': sph_date(changeStart.edited),
            'editor': sph_user_displayname(changeStart.editor),
            'editversionlink': changeStart.get_absolute_editurl()
        },
        todesc = desc % {
            'date': sph_date(changeEnd.edited),
            'editor': sph_user_displayname(changeEnd.editor),
            'editversionlink': changeEnd.get_absolute_editurl()
        },

        diffTable = htmlDiff.make_table(
            changeStart.body.splitlines(1),
            changeEnd.body.splitlines(1),
            fromdesc=fromdesc,
            todesc=todesc,
            context=True,
        )

    args['diffTable'] = mark_safe(diffTable)
    args['fromchange'] = changeStart
    args['tochange'] = changeEnd
    return render_to_response('sphene/sphwiki/diff.html',
                              args,
                              context_instance=RequestContext(request))
示例#8
0
def make_diff(old, new):
    df = HtmlDiff()
    old_lines = old.splitlines(1)
    new_lines = new.splitlines(1)
    html = df.make_table(old_lines, new_lines, context=True)
    html = html.replace(' nowrap="nowrap"','')
    return html
示例#9
0
    def diff(
        left: NDLElement,
        right: NDLElement,
        cls: Optional[Type[JSONEncoder]] = None,
        sorters: LIST_SORTERS = None,
        normalizers: NORMALIZERS = None,
        max_col_width: Optional[int] = 20,
    ) -> DiffResult:
        """
        Show the difference of two objects.  Unix like diff results.
        :param left: Test object
        :param right: Expected object
        :param cls: JSON Encoder if any fields aren't JSON encodable.
        :param sorters: Sorters for list elements.
        :param normalizers: Normalizers for leaf elements.
        :param max_col_width: Maximum column width of diff output.
        :return: True if match.
        """
        if normalizers:
            normalizers = (
                normalizers if isinstance(normalizers, list) else [normalizers]
            )
        sorted_left = Sorter.sorted(left, sorters=sorters, normalizers=normalizers)
        sorted_right = Sorter.sorted(right, sorters=sorters, normalizers=normalizers)
        differ = HtmlDiff()

        result = differ.make_file(
            json.dumps(sorted_left, indent=2, cls=cls).split("\n"),
            json.dumps(sorted_right, indent=2, cls=cls).split("\n"),
        )
        match, support = Formatter(max_col_width=max_col_width).format(result)
        return DiffResult(match, support)
示例#10
0
def email_changes(zone, prev_addrs, curr_addrs, subject, server, fromaddr, toaddr, test=False):
    bindformat = format_records_for_email(curr_addrs)
    prev_addrs = ' '.join(prev_addrs)
    curr_addrs = ' '.join(curr_addrs)
    prev = sorted([s for s in prev_addrs.split() if 'ip' in s])
    curr = sorted([s for s in curr_addrs.split() if 'ip' in s])

    diff = HtmlDiff()
    table = diff.make_table(
        fromlines=prev,
        tolines=curr,
        fromdesc='Old records',
        todesc='New records'
    )

    header = '<h1>Diff</h1>'
    html = _email_style + bindformat + header + table
    html = MIMEText(html, 'html')
    msg_template = MIMEMultipart('alternative')
    msg_template['Subject'] = subject.format(zone=zone)
    email = msg_template
    email.attach(html)

    try:
        mailserver = smtplib.SMTP()
        mailserver.connect(server)
        mailserver.sendmail(fromaddr, toaddr, email.as_string())
    except Exception as err:
        print('Email failed: ' + str(err))
        with open('result.html', 'w+') as mailfile:
            mailfile.write(html.as_string())
    if test:
        return bindformat
示例#11
0
def diff_text(text1, text2="", title1="", title2=""):
    txt1 = text1.splitlines(1)
    txt2 = text2.splitlines(1)

    d = HtmlDiff()
    result = d.make_file(txt1, txt2, title1, title2, context=True)

    return result
示例#12
0
def diff_text(text1, text2="", title1="", title2=""):
    txt1 = text1.splitlines(1)
    txt2 = text2.splitlines(1)

    d = HtmlDiff()
    result = d.make_file(txt1, txt2, title1, title2, context=True)

    return result
示例#13
0
 def __init__ (self, result1=[''], result2=[''], \
               column=4, wrap=50, junk='\n'):
     
     HtmlDiff.__init__ (self, column, wrap, self.line_junk)
     
     self.result1 = result1
     self.result2 = result2
     self.junk = junk
示例#14
0
 async def run(self, ctx):
     diff = HtmlDiff()
     async with aclosing(ctx.detector.changed.stream_events()) as stream:
         async for event in stream:
             difference = diff.make_file(event.old_lines, event.new_lines, context=True)
             await ctx.mailer.create_and_deliver(
                 subject='Change detected in %s' % event.source.url, html_body=difference)
             logger.info('Sent notification email')
    def __init__ (self, result1=[''], result2=[''], \
                  column=4, wrap=50, junk='\n'):

        HtmlDiff.__init__(self, column, wrap, self.line_junk)

        self.result1 = result1
        self.result2 = result2
        self.junk = junk
示例#16
0
def diff_html(html_dict, base_ip, other_ip):
    """
    Uses difflib to construct a table that is the difference between the base and
    all of the other returned html
    """
    diff = HtmlDiff(wrapcolumn=60)
    return diff.make_table(
        fromlines=html_dict[base_ip].splitlines(),
        tolines=html_dict[other_ip].splitlines(),
    )
示例#17
0
文件: app.py 项目: quiddity-wp/oabot
def make_diff(old, new):
    """
    Render in HTML the diff between two texts
    """
    df = HtmlDiff()
    old_lines = old.splitlines(1)
    new_lines = new.splitlines(1)
    html = df.make_table(old_lines, new_lines, context=True)
    html = html.replace(' nowrap="nowrap"','')
    return html
示例#18
0
def diff_table(rawinfo, newinfo):
    '''
    Generate the difference as the table format.
    :param rawinfo:
    :param newinfo:
    :return:
    '''
    return HtmlDiff.make_table(HtmlDiff(), rawinfo.split('\n'), newinfo.split('\n'),
                               context=True,
                               numlines=1)
示例#19
0
def index(request):
    if request.method == "POST":
        print "=" * 100
        print request
        print "=" * 1000
        afile = request.FILES['file1']
        #Check if file is PDF and Convert to text using method defined below
        # if afile[-3:]=='pdf':
        #     afile = convert_pdf_to_txt(afile)
        print afile.name, afile.read()
        instance = Tuple(file1=request.FILES['file1'],
                         file2=request.FILES['file2'])
        instance.save()
        print str(instance.file1)[1:], str(instance.file2)
        file1 = str(instance.file1)[2:]
        file2 = str(instance.file2)[2:]
        dire = str(settings.MEDIA_ROOT)
        #Used to truncate strings
        ccod1 = open(dire + file1).read().split('\n')
        if len(ccod1) >= 100:
            ccod1 = ccod1[:100]
        ccod2 = open(dire + file2).read().split('\n')
        if len(ccod2) >= 100:
            ccod2 = ccod2[:100]
        datastuff = process_it(file1, file2, dire)
        # ddifference = difference(file1, file2, dire)
        # data1 = open(dire+file1).read()
        # data2 = open(dire+file2).read()
        sMatcher = SequenceMatcher(None, ccod1, ccod2)
        fileRatio = sMatcher.ratio() * 100
        matchingBlocks = sMatcher.get_matching_blocks()
        HtmlDiff().__init__()
        differenze = HtmlDiff().make_file(ccod1, ccod2)
        ccod1.insert(0, '')
        ccod2.insert(0, '')
        print datastuff[0][2]
        return render(
            request, 'ComparedResult\\ComparedResult.html', {
                'diff': differenze,
                'mblocks': matchingBlocks,
                'ratio': fileRatio,
                'code1': ccod1,
                'code2': ccod2,
                'ccode1': ["", datastuff[1][1]],
                'ccode2': ["", datastuff[1][2]],
                'assembly1': ["", datastuff[0][1]],
                'assembly2': ["", datastuff[0][2]]
            })
    return render(
        request, 'ComparedResult\\ComparedResult.html', {
            'ccode1': [
                "",
                '''<div><mark>.def __main; .scl 2; .type 32; .endef</mark><br>.LC0:<br>.ascii "Hello world\\0"<br>.text<br>.globl main<br>.def main; .scl 2; .type 32; .endef<br>.seh_proc main<br>main:<br>pushq %rbp<br>.seh_pushreg %rbp<br>movq %rsp, %rbp<br>.seh_setframe %rbp, 0<br>subq $32, %rsp<br>.seh_stackalloc 32<br>.seh_endprologue<br>call __main<br>leaq .LC0(%rip), %rcx<br>call puts<br>movl $0, %eax<br>addq $32, %rsp<br><mark>popq %rbp</mark><br><mark>ret</mark><br><mark>.seh_endproc</mark><br><mark>.def puts; .scl 2; .type 32; .endef</mark><br></div> '''
            ]
        })
示例#20
0
    async def start(self, ctx):
        self.add_component('detector', ChangeDetectorComponent)
        self.add_component('mailer', backend='smtp')
        await super().start(ctx)

        diff = HtmlDiff()
        async for event in ctx.detector.changed.stream_events():
            difference = diff.make_file(event.old_lines, event.new_lines, context=True)
            await ctx.mailer.create_and_deliver(
                subject='Change detected in %s' % event.source.url, html_body=difference)
            logger.info('Sent notification email')
示例#21
0
    def command_autoconvert(self):
        dry = self.is_dry_run()

        from digipal_text.models import TextContentXML, TextAnnotation
        from digipal_text.views import viewer
        before = ur''
        after = ur''
        total = 0
        converted = 0
        for tcx in TextContentXML.objects.filter(
                text_content__type__slug='transcription').order_by('id'):
            total += 1
            content = tcx.content
            if not content: continue
            tcx.convert()
            if content != tcx.content:
                converted += 1
                text_name = u'#%s: %s [length diff = %s]' % (
                    tcx.id, tcx, abs(len(content) - len(tcx.content)))
                print text_name

                before += u'\n\n'
                before += text_name
                before += u'\n\n'
                before += content.replace('\r', '\n')

                after += u'\n\n'
                after += text_name
                after += u'\n\n'
                after += tcx.content.replace('\r', '\n')

                if 0:
                    html = ''
                    from difflib import HtmlDiff
                    diff = HtmlDiff(tabsize=2)
                    d = diff.make_table([content], [tcx.content])

                    html += u'<h2>%s</h2>' % text_name
                    html += d

                if not dry:
                    tcx.save()

                #break

            #tcx.save()

        dputils.write_file('before.txt', before)
        dputils.write_file('after.txt', after)

        print '%s converted out of %s texts' % (converted, total)

        if dry:
            print 'DRY RUN: no data was changed in the database.'
示例#22
0
文件: app.py 项目: AvdN/asphalt
 async def run(self, ctx):
     diff = HtmlDiff()
     async with aclosing(ctx.detector.changed.stream_events()) as stream:
         async for event in stream:
             difference = diff.make_file(event.old_lines,
                                         event.new_lines,
                                         context=True)
             await ctx.mailer.create_and_deliver(
                 subject='Change detected in %s' % event.source.url,
                 html_body=difference)
             logger.info('Sent notification email')
def compare_file(file1, file2):
    lines1 = get_file_content(file1)
    lines2 = get_file_content(file2)

    # 找出差异输出到result(str)
    html_diff = HtmlDiff()
    result = html_diff.make_file(lines1, lines2)
    
    # 将差异写入html文件
    with open("comparison.html", "w", encoding="utf8") as f:
        f.write(result)
示例#24
0
def html_comp(in_lines1, in_lines2, out_file):
    """

    :param in_lines1:
    :param in_lines2:
    :param out_file:
    :return:
    """
    d = HtmlDiff()
    result = d.make_file(in_lines1, in_lines2)
    with open(out_file, 'w') as f:
        f.writelines(result)
示例#25
0
def htmldiff(string1, string2):
    txt1 = str(string1).splitlines()
    txt2 = str(string2).splitlines()

    diff = HtmlDiff(tabsize=4, wrapcolumn=80)
    result = diff.make_table(txt1, txt2, context=True, numlines=2)

    if '<td> No Differences Found </td>' in result:
        return _('<p>Pas de changements.</p>')
    else:
        return format_html('<div class="diff_delta">{}</div>',
                           mark_safe(result))
示例#26
0
def _gen_diff_html(from_title, from_lines, to_title, to_lines):
    """Compare two strings and string of HTML code with the output.

    :param from_title: Title of the left content to compare.
    :param from_lines: List of lines to compare.
    :param to_title: Title of the right content to compare.
    :param to_lines: List of lines to compare.
    :return: String of HTML code with the comparison output.
    """
    html_template = """<!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>Diff {from_title} vs. {to_title}</title>
        <style type="text/css">
            table {{font-family:Courier; border:medium}}
            .diff_header {{background-color:#e0e0e0; padding:0px 10px}}
            td.diff_header {{text-align:right}}
            .diff_next {{background-color:#c0c0c0; padding:0px 10px}}
            .diff_add {{background-color:#aaffaa}}
            .diff_chg {{background-color:#ffff77}}
            .diff_sub {{background-color:#ffaaaa}}
        </style>
    </head>
    <body>
        <table>
            <tr><td><table>
                <tr><th>Colors</th></tr>
                <tr><td class="diff_add">Added</td></tr>
                <tr><td class="diff_chg">Changed</td></tr>
                <tr><td class="diff_sub">Deleted</td></tr>
            </table></td><td><table>
                <tr><th>Links<th></tr>
                <tr><td>(f)irst change</td></tr>
                <tr><td>(n)ext change</td></tr>
                <tr><td>(t)op</td></tr>
            </table></td><td><table>
                <tr><th>Files<th></tr>
                <tr><td>Left: {from_title}</td></tr>
                <tr><td>Right: {to_title}</td></tr>
            </table></td></tr>
        </table>
        {diff_table}
    </body>
    </html>"""
    differ = HtmlDiff()
    filled_template = html_template.format(
        from_title=from_title,
        to_title=to_title,
        diff_table=differ.make_table(from_lines, to_lines),
    )
    return filled_template
示例#27
0
def diff(request, group, snipName, changeId = None):
    snip = get_object_or_404( WikiSnip,
                              group = group,
                              name = snipName )
    if not snip.has_view_permission():
        raise PermissionDenied()
    changeEnd = get_object_or_404( WikiSnipChange,
                                   snip = snip,
                                   pk = changeId, )
    args = { 'snip': snip,
             'snipName': snipName,}
    try:
        changeStart = snip.wikisnipchange_set.filter( edited__lt = changeEnd.edited, ).order_by('-edited')[0]
        args['prev_change'] = changeStart
    except IndexError:
        changeStart = None
        diffTable = ugettext("This is the first change.")

    try:
        next_change = snip.wikisnipchange_set.filter( edited__gt = changeEnd.edited, ).order_by('edited')[0]
        args['next_change'] = next_change
    except IndexError:
        pass

    if changeStart:
        htmlDiff = HtmlDiff(wrapcolumn = 50,)
        from sphene.community.templatetags.sph_extras import sph_date, sph_user_displayname
        desc = ugettext('%(date)s by %(editor)s')
        if snip.has_edit_permission():
            desc += ' / <a href="%(editversionlink)s">'+ugettext('Edit this version')+'</a>'
        fromdesc = desc % {
            'date': sph_date( changeStart.edited ),
            'editor': sph_user_displayname( changeStart.editor ),
            'editversionlink': changeStart.get_absolute_editurl() },
        todesc = desc % {
            'date': sph_date( changeEnd.edited ),
            'editor': sph_user_displayname( changeEnd.editor ),
            'editversionlink': changeEnd.get_absolute_editurl() },

        diffTable = htmlDiff.make_table( changeStart.body.splitlines(1),
                                         changeEnd.body.splitlines(1),
                                         fromdesc = fromdesc,
                                         todesc = todesc,
                                         context = True, )

    args['diffTable'] = mark_safe(diffTable)
    args['fromchange'] = changeStart
    args['tochange'] = changeEnd
    return render_to_response( 'sphene/sphwiki/diff.html',
                               args,
                               context_instance = RequestContext(request) )
示例#28
0
def article_diff(request, title):
    article = get_object_or_404(Article, title=title)
    from_id = int(request.GET['from'])
    to_id = int(request.GET['to'])
    from_version = article.versions.get(number=from_id)
    to_version = article.versions.get(number=to_id)
    differ = HtmlDiff()
    from_body = from_version.body.raw.split('\n')
    to_body = to_version.body.raw.split('\n')
    table = differ.make_table(from_body, to_body)
    return render_to_response('markupwiki/article_diff.html',
                              {'article': article, 'table':table,
                               'from': from_id, 'to':to_id},
                              context_instance=RequestContext(request))
示例#29
0
    def get_comparison(self) -> Dict[str, str]:
        """
        Get a comparison object for use in sending emails.

        We have the name (key) -> HTML diff table (value).
        """
        diff = HtmlDiff(tabsize=4, wrapcolumn=80)
        return {
            name: (diff.make_table(v['cached_content'].split('\n'),
                                   v['current_content'].split('\n'),
                                   context=True), v['url'])
            for name, v in self.entries.items()
            if v['cached_content'] is not None and v['current_content']
            is not None and v['cached_content'] != v['current_content']
        }
示例#30
0
    def to_html(self, filename: str) -> None:
        source = self.source.splitlines(keepends=True)
        target = self.target.splitlines(keepends=True)

        diff = HtmlDiff().make_file(source, target)
        with open(filename, mode='w') as fd:
            fd.write(diff)
示例#31
0
文件: service.py 项目: peerau/byceps
def create_html_diff(from_text: str,
                     to_text: str,
                     from_description: str,
                     to_description: str,
                     *,
                     numlines: int = 3) -> Optional[str]:
    """Calculate the difference between the two texts and render it as HTML.

    If the texts to compare are equal, `None` is returned.
    """
    from_text = _fallback_if_none(from_text)
    to_text = _fallback_if_none(to_text)

    if from_text == to_text:
        return None

    from_lines = from_text.split('\n')
    to_lines = to_text.split('\n')

    return HtmlDiff().make_table(from_lines,
                                 to_lines,
                                 from_description,
                                 to_description,
                                 context=True,
                                 numlines=numlines)
示例#32
0
 def default_content_diff(self, obj):
     return mark_safe(HtmlDiff().make_table(
         obj.original_default_content.split('\n')[:-1],
         obj.default_content.split('\n')[:-1],
         fromdesc=_('original default content'),
         todesc=_('current default content'),
     )) if obj.default_content_changed else '-'
示例#33
0
 def changed_content_diff(self, obj):
     return mark_safe(HtmlDiff().make_table(
         obj.default_content.splitlines(),
         obj.changed_content.splitlines(),
         fromdesc=_('default content'),
         todesc=_('changed content'),
     )) if obj.changed_content else '-'
示例#34
0
def compareDocs(newList, oldList):
    #uses html compare to generate a comparison of two eligibility docs
    k = HtmlDiff(wrapcolumn=80)   #gets an instance of html diff with wrapped columns
    with open('diff.html', 'w') as output:  #a file for the output

        for f in newList:           #go through each disease in new
            for g in oldList:       #search through each disease in ref
                if f['Title'] == g['Title']:
                    text1 = g['Text']
                    text2 = f['Text']
                    diffFile = k.make_file(text1.splitlines(keepends = True), text2.splitlines(keepends=True),fromdesc='old Model', todesc='new Model', charset='ISO-8859-1')
                    output.write(diffFile)  #write the Diff to the file
                    break
            else:
                print(f['Title'], " has no match")
    return
示例#35
0
def PromptUserToAcceptDiff(old_text, new_text, prompt):
    """Displays a difference in two strings (old and new file contents) to the
  user and asks whether the new version is acceptable.

  Args:
    old_text: A string containing old file contents.
    new_text: A string containing new file contents.
    prompt: Text that should be displayed to the user, asking whether the new
            file contents should be accepted.

  Returns:
    True is user accepted the changes or there were no changes, False otherwise.
  """
    logging.info('Computing diff...')
    if old_text == new_text:
        logging.info('No changes detected')
        return True
    html_diff = HtmlDiff(wrapcolumn=80).make_file(old_text.splitlines(),
                                                  new_text.splitlines(),
                                                  fromdesc='Original',
                                                  todesc='Updated',
                                                  context=True,
                                                  numlines=5)
    temp = NamedTemporaryFile(suffix='.html', delete=False)
    try:
        temp.write(html_diff)
        temp.close()  # Close the file so the browser process can access it.
        webbrowser.open('file://' + temp.name)
        print prompt
        response = raw_input('(Y/n): ').strip().lower()
    finally:
        temp.close()  # May be called on already closed file.
        os.remove(temp.name)
    return response == 'y' or response == ''
示例#36
0
def main(args):
    """Generate diff.html file"""
    if not args.filename:
        """
        print(args.file[0].name)
        file1 = args.file[0].name.split('/')[-1].split('.')[0]
        file2 = args.file[1].name.split('/')[-1].split('.')[0]
        filename = "diff_%s_X_%s.html" % (file1, file2)
        """
        date_now = datetime.now()
        filename = 'Diff from {0:%Y}-{0:%m}-{0:%d} {0:%H}-{0:%M}-{0:%S}.html'
        filename = filename.format(date_now)

    elif not args.filename.endswith(".html"):
        filename = args.filename = args.filename + ".html"
    else:
        filename = args.filename

    with open(filename, 'w+') as output_file:
        first_file, second_file = args.file[0], args.file[1]

        diff = HtmlDiff().make_file(
            fromlines=first_file, tolines=second_file,
            fromdesc=first_file.name.split('/')[-1],
            todesc=second_file.name.split('/')[-1])

        custom = CustomHTML()
        diff = custom.new_html(html=diff, args=args)

        output_file.write(diff)

        for file_open in args.file:
            file_open.close()

        print("Successful diff!\nFile: {}".format(filename))
示例#37
0
def htmldiff(string1, string2):

    try:
        txt1 = string1.decode('utf-8').splitlines()
    # string1 is an empty SafeText from template
    except AttributeError:
        txt1 = string1.splitlines()

    try:
        txt2 = string2.decode('utf-8').splitlines()
    except AttributeError:
        txt2 = string2.splitlines()

    diff = HtmlDiff(tabsize=4, wrapcolumn=80)
    result = diff.make_table(txt1, txt2, context=True, numlines=2)

    if 'No Differences Found' in result:
        return format_html('<p>{}</p>', _('Pas de changements.'))
    else:
        return format_html('<div class="diff_delta">{}</div>', mark_safe(result))
示例#38
0
文件: app.py 项目: arteymix/datapedia
def archives(version, name, ext = None):
    archives = {os.path.basename(f): app.config['FILE_DECODER'][ext if ext else 'json'](open(f, 'r')) for f in glob.iglob(os.path.join(app.config['DATA_FOLDER_PATH'], 'archive', '{}.{}'.format(name, ext if ext else 'json'), '*'))}
    
    if ext:
        return archives

    # compute diff from one to another
    htmldiff = HtmlDiff()
    archives = {}
    last_time = 0
    last_lines = []
    d = os.path.join(app.config['DATA_FOLDER_PATH'], 'archive', '{}.{}'.format(name, 'json'), '*')
    for path in sorted(glob.iglob(d)):
        with open(path, 'r') as f:
            lines = json.dumps(json.load(f), indent = 4, separators = (',', ': '), sort_keys = True).split("\n")
            time = int(os.path.basename(path))
            archives[time] = htmldiff.make_table(last_lines, lines, fromdesc=datetime.fromtimestamp(last_time), todesc=datetime.fromtimestamp(time))
            last_time, last_lines = time, lines

    return render_template('archives.html', name = name, archives = archives)
示例#39
0
文件: views.py 项目: soupytwist/judge
def admin_attempt_diff(request, contest=None, attempt_pk=None, quick=False):
    if not request.user.is_authenticated or not request.user.is_staff:
        return redirect("/admin/")

    attempt = get_object_or_404(models.Attempt, pk=attempt_pk)
    their_lines = []
    my_lines = []

    sizehint = [512] if quick else []

    if attempt.outputfile:
        with open(attempt.outputfile.path) as theirs:
            their_lines = theirs.readlines(*sizehint)

    with open(attempt.get_outputfile_path()) as mine:
        my_lines = mine.readlines(*sizehint)

    differ = HtmlDiff()
    html = differ.make_file(their_lines, my_lines, fromdesc="User's output", todesc="Judge's output")

    return HttpResponse(html, content_type="text/html")
示例#40
0
def diff_working(repo,file,src=source.PATH):
    store=repo.object_store
    index=repo.open_index()
    
    tree=store[store[repo.head()].tree]
    parent_tree=store[store[store[repo.head()].parents[0]].tree]
    
    tree_ver=store[tree.lookup_path(store.peel_sha,file)[1]].data


    local_ver=open(os.path.join(repo.path,file)).read()
    h=HtmlDiff(wrapcolumn=70,tabsize=4)
    if src==source.PATH:
        f=h.make_file(tree_ver.splitlines(),local_ver.splitlines(), file, 'last commit:'+repo.head())
    elif src==source.INDEX:
        index_ver=store[index._byname[file].sha].data
        f=h.make_file(tree_ver.splitlines(),index_ver.splitlines(),file+' staged change', 'last commit'+repo.head())
    else:
        parent_tree_ver=store[parent_tree.lookup_path(store.peel_sha,file)[1]].data
        f=h.make_file(parent_tree_ver.splitlines(),tree_ver.splitlines(), file+' HEAD','HEAD^1')        
    return f
示例#41
0
def write_diff_file(updated_file, baseline_file):
    diff = HtmlDiff()

    updated_file = os.path.join(opt.data_root, 'characteristics', updated_file)
    baseline_file = os.path.join(opt.data_root, 'characteristics', baseline_file)

    with open(updated_file, 'r') as fh:
        updated_lines = fh.readlines()
    with open(baseline_file, 'r') as fh:
        baseline_lines = fh.readlines()

    diff_str = diff.make_file(baseline_lines, updated_lines,
                              fromdesc=os.path.basename(baseline_file),
                              todesc=os.path.basename(updated_file),
                              context=True,
                              numlines=5)

    diff_file = updated_file + '_diff.html'
    logger.info('Writing diff to {}'.format(diff_file))
    with open(diff_file, 'w') as fh:
        fh.write(diff_str)
示例#42
0
文件: views.py 项目: philwo/spiky
def compare(request, rev1, rev2):
    page1 = get_object_or_404(Page, rev=rev1)
    page2 = get_object_or_404(Page, rev=rev2)

    # We only compare two pages if they have the same UID!
    if page1.uid != page2.uid:
        raise Http404

    diffengine = HtmlDiff(tabsize=4, wrapcolumn=65)
    htmldiff = diffengine.make_table(
        fromlines=page1.content.split("\n"),
        tolines=page2.content.split("\n"),
        fromdesc=page1.name,
        todesc=page2.name,
        context=False,
    )

    return render_to_response(
        settings.TEMPLATE_DIR + "compare.html",
        {"page1": page1, "page2": page2, "htmldiff": htmldiff, "base_site": settings.BASE_SITE},
        context_instance=RequestContext(request),
    )
示例#43
0
文件: app.py 项目: arteymix/datapedia
def approving(version, name, ext, timestamp):
    form = forms.ApprovingForm()

    approving_path, approving_ext, _ = find_approving(name, ext if ext else form.ext.data, timestamp)

    if not os.path.exists(approving_path):
        if ext:
            return 'There is no data at this endpoint.', NOT_FOUND

        return render_template('error.html', code = NOT_FOUND, message = message), NOT_FOUND

    with open(approving_path, 'r') as a:
        approving = app.config['FILE_DECODER'][approving_ext](a)

    current_path, current_ext = find_current(name, approving_ext)

    with open(current_path, 'r') as c:
        current = app.config['FILE_DECODER'][current_ext](c)

    if request.method == 'POST':
        if request.remote_addr in approving['approvers']:
            return 'You have already approved this data', BAD_REQUEST

        approving['approvers'].append(request.remote_addr)

        # not regressive validation
        form.data = JSONTextAreaField()
        form.data.validators.append(NotRegressive(current))

        if form.validate_on_submit():
            # update approving
            with open(approving_path, 'w') as a:
                app.config['FILE_ENCODER'][approving_ext](approving, a)
                    
            archive_path, archive_ext, archive_timestamp = find_archive(name, ext, timestamp)

            # check if the approving version has more approvers than the current version
            if len(approving['approvers']) > len(current['approvers']):
                with open(current_path, 'w') as c, open(archive_path, 'w')as a:
                    # write to archive and replace current
                    app.config['FILE_ENCODER'][archive_ext](approving, a)
                    app.config['FILE_ENCODER'][current_ext](approving, c)

                # remove approving
                os.remove(approving_path)

                return redirect(url_for('current', name = name, ext = ext))

        elif ext:
            return {field.name: field.errors for field in form}, BAD_REQUEST

    if ext:
        return approving

    # compute the delta between approved and current
    htmldiff = HtmlDiff()
    approving_lines = json.dumps(approving, indent = 4).splitlines()
    current_lines = json.dumps(current, indent = 4).splitlines()
    diff = htmldiff.make_table(fromlines = current_lines, tolines = approving_lines)

    return render_template('approving.html', name = name, approving = approving, timestamp = timestamp, diff = diff, current = current, form = form)
示例#44
0
def compare_orgs_task(job):

	job.status = 'Comparing'
	job.save()

	try:

		org_left = job.sorted_orgs()[0]
		org_right = job.sorted_orgs()[1]

		# Map of name to component
		component_type_map = {}
		component_map = {}

		# Create a list of the left component type names
		left_components = []
		for component_type in org_left.sorted_component_types():

			left_components.append(component_type.name)
			component_type_map['left' + component_type.name] = component_type

			# Append components
			for component in component_type.sorted_components():
				left_components.append(component_type.name + '***' + component.name)
				component_map['left' + component_type.name + '***' + component.name] = component

		# Create a list of the right component type names
		right_components = []
		for component_type in org_right.sorted_component_types():

			right_components.append(component_type.name)
			component_type_map['right' + component_type.name] = component_type
			
			for component in component_type.sorted_components():
				right_components.append(component_type.name + '***' + component.name)
				component_map['right' + component_type.name + '***' + component.name] = component

		# Start the unique list
		all_components_unique = list(left_components)

		# Add all right components that aren't in the list
		for component_type in right_components:

			if component_type not in all_components_unique:

				all_components_unique.append(component_type)

		# Sort alphabetically
		all_components_unique.sort()

		order_counter = 0

		# Start to build the HTML for the table
		for row_value in all_components_unique:

			order_counter = order_counter + 1

			component_result = ComponentListUnique()
			component_result.job = job
			component_result.order = order_counter
			component_result.save() # save now as we need ID

			# Generating HTML here to speed up page load performance on the front end
			row_html = ''

			if row_value in left_components and row_value not in right_components:

				if '***' not in row_value:

					row_html += '<tr class="type type_' + component_type_map['left' + row_value].name + '">'
					row_html += '<td>' + component_type_map['left' + row_value].name + '</td>'
					row_html += '<td></td>'
					row_html += '</tr>'

				else:

					row_html += '<tr class="component danger component_' + component_map['left' + row_value].component_type.name + '">'
					row_html += '<td id="' + str(component_map['left' + row_value].id) + '">' + component_map['left' + row_value].name + '</td>'
					row_html += '<td id="' + str(component_map['left' + row_value].id) + '"></td>'
					row_html += '</tr>'
					
			elif row_value not in left_components and row_value in right_components:
				
				if '***' not in row_value:

					row_html += '<tr class="type type_' + component_type_map['right' + row_value].name + '">'
					row_html += '<td></td>'
					row_html += '<td>' + component_type_map['right' + row_value].name + '</td>'
					row_html += '</tr>'

				else:

					row_html += '<tr class="component danger component_' + component_map['right' + row_value].component_type.name + '">'
					row_html += '<td id="' + str(component_map['right' + row_value].id) + '"></td>'
					row_html += '<td id="' + str(component_map['right' + row_value].id) + '">' + component_map['right' + row_value].name + '</td>'
					row_html += '</tr>'

			elif row_value in left_components and row_value in right_components:

				if '***' not in row_value:

					row_html += '<tr class="type type_' + component_type_map['left' + row_value].name + '">'
					row_html += '<td>' + component_type_map['left' + row_value].name + '</td>'
					row_html += '<td>' + component_type_map['right' + row_value].name + '</td>'
					row_html += '</tr>'

				else:

					# If diff exists
					if component_map['left' + row_value].content != component_map['right' + row_value].content:

						diff_tool = HtmlDiff()
						component_result.diff_html = diff_tool.make_table(component_map['left' + row_value].content.split('\n'), component_map['right' + row_value].content.split('\n'))
				
						row_html += '<tr class="component warning component_' + component_map['left' + row_value].component_type.name + '">'
						row_html += '<td id="' + str(component_result.id) + '" class="diff">' + component_map['left' + row_value].name + '</td>'
						row_html += '<td id="' + str(component_result.id) + '" class="diff">' + component_map['right' + row_value].name + '</td>'
						row_html += '</tr>'

					else:

						row_html += '<tr class="component success component_' + component_map['left' + row_value].component_type.name + '">'
						row_html += '<td id="' + str(component_map['left' + row_value].id) + '" class="both_same">' + component_map['left' + row_value].name + '</td>'
						row_html += '<td id="' + str(component_map['right' + row_value].id) + '" class="both_same">' + component_map['right' + row_value].name + '</td>'
						row_html += '</tr>'

			component_result.row_html = row_html		
			component_result.save()

			job.status = 'Finished'

			email_body = 'Your Org compare job is complete:\n'
			email_body += 'https://sforgcompare.herokuapp.com/compare_result/' + str(job.random_id)
			email_body += '\n\nYour result will be deleted after one day in order to avoid storing any metadata.'

			email_subject = 'Your Salesforce Org Compare results are ready.'

	except Exception as error:

		job.status = 'Error'
		job.error = error

		send_error_email(job, error)


	job.finished_date = datetime.datetime.now()
	job.save()

	if job.email_result and job.status == 'Finished':
		#send_mail('Your Org Compare Results', email_body, '*****@*****.**', [job.email], fail_silently=False)
		message = PMMail(api_key = os.environ.get('POSTMARK_API_KEY'),
				subject = email_subject,
                sender = "*****@*****.**",
                to = job.email,
                text_body = email_body,
                tag = "orgcompareemail")
		message.send()
示例#45
0
    parser.add_argument('--encoding', default='utf-8')
    parser.add_argument('--nosoup', default=False, action='store_true')
    parser.add_argument('--soupthreshold', default=0.9, type=float)
    args = parser.parse_args()

    response = get_response(args.url, {})
    original_body = response.body

    allow_soup = not args.nosoup
    tree = parse_response(body=original_body,
                          encoding=args.encoding,
                          allow_soup=allow_soup,
                          soupthreshold=args.soupthreshold)
    parsed_body = etree.tostring(tree, method='html', encoding=args.encoding)

    original_body_lines = original_body.decode('utf-8').splitlines()
    parsed_body_lines = parsed_body.decode('utf-8').splitlines()

    output_file = '{fn}.diff.html'.format(fn=slug_from_url(args.url))
    with(open(output_file, 'w')) as diff_file:

        htmldiff = HtmlDiff(
            wrapcolumn=59, charjunk=lambda c: c in [" ", "\t", "/"])
        diff_html = htmldiff.make_file(
            original_body_lines, parsed_body_lines, context=True)

        diff_file.writelines(diff_html)

    print('opening diff in browser')
    subprocess.call(['open', output_file])
示例#46
0
def htmlDiff(left, right):
	h = HtmlDiff(wrapcolumn=80)
	return h.make_file(htmlBeautify(left), htmlBeautify(right), context=True)
示例#47
0
文件: diff.py 项目: PandaWei/avocado
    def run(self, args):
        job1_dir, job1_id = self._setup_job(args.jobids[0])
        job2_dir, job2_id = self._setup_job(args.jobids[1])

        job1_data = self._get_job_data(job1_dir)
        job2_data = self._get_job_data(job2_dir)

        report_header = 'Avocado Job Report\n'
        job1_results = [report_header]
        job2_results = [report_header]

        if 'cmdline' in args.diff_filter:
            cmdline1 = self._get_command_line(job1_dir)
            cmdline2 = self._get_command_line(job2_dir)

            if str(cmdline1) != str(cmdline2):
                command_line_header = ['\n',
                                       '# COMMAND LINE\n']
                job1_results.extend(command_line_header)
                job1_results.append(cmdline1)
                job2_results.extend(command_line_header)
                job2_results.append(cmdline2)

        if 'time' in args.diff_filter:
            time1 = '%.2f s\n' % job1_data['time']
            time2 = '%.2f s\n' % job2_data['time']

            if str(time1) != str(time2):
                total_time_header = ['\n',
                                     '# TOTAL TIME\n']
                job1_results.extend(total_time_header)
                job1_results.append(time1)
                job2_results.extend(total_time_header)
                job2_results.append(time2)

        if 'variants' in args.diff_filter:
            variants1 = self._get_variants(job1_dir)
            variants2 = self._get_variants(job2_dir)

            if str(variants1) != str(variants2):
                variants_header = ['\n',
                                   '# VARIANTS\n']
                job1_results.extend(variants_header)
                job1_results.extend(variants1)
                job2_results.extend(variants_header)
                job2_results.extend(variants2)

        if 'results' in args.diff_filter:
            results1 = []
            for test in job1_data['tests']:
                test_result = '%s: %s\n' % (str(test['url']),
                                            str(test['status']))
                results1.append(test_result)
            results2 = []
            for test in job2_data['tests']:
                test_result = '%s: %s\n' % (str(test['url']),
                                            str(test['status']))
                results2.append(test_result)

            if str(results1) != str(results2):
                test_results_header = ['\n',
                                       '# TEST RESULTS\n']
                job1_results.extend(test_results_header)
                job1_results.extend(results1)
                job2_results.extend(test_results_header)
                job2_results.extend(results2)

        if 'config' in args.diff_filter:
            config1 = self._get_config(job1_dir)
            config2 = self._get_config(job2_dir)

            if str(config1) != str(config2):
                config_header = ['\n',
                                 '# SETTINGS\n']
                job1_results.extend(config_header)
                job1_results.extend(config1)
                job2_results.extend(config_header)
                job2_results.extend(config2)

        if 'sysinfo' in args.diff_filter:
            sysinfo_pre1 = self._get_sysinfo(job1_dir, 'pre')
            sysinfo_pre2 = self._get_sysinfo(job2_dir, 'pre')

            if str(sysinfo_pre1) != str(sysinfo_pre2):
                sysinfo_header_pre = ['\n',
                                      '# SYSINFO PRE\n']
                job1_results.extend(sysinfo_header_pre)
                job1_results.extend(sysinfo_pre1)
                job2_results.extend(sysinfo_header_pre)
                job2_results.extend(sysinfo_pre2)

            sysinfo_post1 = self._get_sysinfo(job1_dir, 'post')
            sysinfo_post2 = self._get_sysinfo(job2_dir, 'post')

            if str(sysinfo_post1) != str(sysinfo_post2):
                sysinfo_header_post = ['\n',
                                       '# SYSINFO POST\n']
                job1_results.extend(sysinfo_header_post)
                job1_results.extend(sysinfo_post1)
                job2_results.extend(sysinfo_header_post)
                job2_results.extend(sysinfo_post2)

        if getattr(args, 'create_reports', False):
            self.std_diff_output = False
            prefix = 'avocado_diff_%s_' % job1_id[:7]
            tmp_file1 = tempfile.NamedTemporaryFile(prefix=prefix,
                                                    suffix='.txt',
                                                    delete=False)
            tmp_file1.writelines(job1_results)
            tmp_file1.close()

            prefix = 'avocado_diff_%s_' % job2_id[:7]
            tmp_file2 = tempfile.NamedTemporaryFile(prefix=prefix,
                                                    suffix='.txt',
                                                    delete=False)
            tmp_file2.writelines(job2_results)
            tmp_file2.close()

            LOG.info('%s %s', tmp_file1.name, tmp_file2.name)

        if (getattr(args, 'open_browser', False) and
                getattr(args, 'html', None) is None):

            prefix = 'avocado_diff_%s_%s_' % (job1_id[:7], job2_id[:7])
            tmp_file = tempfile.NamedTemporaryFile(prefix=prefix,
                                                   suffix='.html',
                                                   delete=False)

            setattr(args, 'html', tmp_file.name)

        if getattr(args, 'html', None) is not None:
            self.std_diff_output = False
            try:
                html_diff = HtmlDiff()
                html_diff._legend = """
                    <table class="diff" summary="Legends">
                    <tr> <td> <table border="" summary="Colors">
                    <tr><th> Colors </th> </tr>
                    <tr><td class="diff_add">&nbsp;Added&nbsp;</td></tr>
                    <tr><td class="diff_chg">Changed</td> </tr>
                    <tr><td class="diff_sub">Deleted</td> </tr>
                    </table></td>
                    <td> <table border="" summary="Links">
                    <tr><th colspan="2"> Links </th> </tr>
                    <tr><td>(f)irst change</td> </tr>
                    <tr><td>(n)ext change</td> </tr>
                    <tr><td>(t)op</td> </tr>
                    </table></td> </tr>
                    </table>"""

                job_diff_html = html_diff.make_file((_.decode("utf-8")
                                                     for _ in job1_results),
                                                    (_.decode("utf-8")
                                                     for _ in job2_results),
                                                    fromdesc=job1_id,
                                                    todesc=job2_id)

                with open(args.html, 'w') as html_file:
                    html_file.writelines(job_diff_html.encode("utf-8"))

                LOG.info(args.html)

            except IOError as exception:
                LOG.error(exception)
                sys.exit(exit_codes.AVOCADO_FAIL)

        if getattr(args, 'open_browser', False):
            setsid = getattr(os, 'setsid', None)
            if not setsid:
                setsid = getattr(os, 'setpgrp', None)
            with open(os.devnull, "r+") as inout:
                cmd = ['xdg-open', args.html]
                subprocess.Popen(cmd, close_fds=True, stdin=inout,
                                 stdout=inout, stderr=inout,
                                 preexec_fn=setsid)

        if self.std_diff_output:
            if self.term.enabled:
                for line in self._cdiff(unified_diff(job1_results,
                                                     job2_results,
                                                     fromfile=job1_id,
                                                     tofile=job2_id)):
                    LOG.debug(line.strip())
            else:
                for line in unified_diff(job1_results,
                                         job2_results,
                                         fromfile=job1_id,
                                         tofile=job2_id):
                    LOG.debug(line.strip())
示例#48
0
def diff_table(content_from, content_to):
    """Creates an HTML diff of the passed in content_from and content_to."""
    html_diff = HtmlDiff(wrapcolumn=DIFF_WRAP_COLUMN)
    diff = html_diff.make_table(content_from.splitlines(),
                                content_to.splitlines(), context=True)
    return jinja2.Markup(diff)
示例#49
-1
文件: pages.py 项目: Freso/website
def installer_diff(request):

    form = DiffInstallerForm()
    diff_table = None

    installer_1_id = request.GET.get('installer_1')
    installer_2_id = request.GET.get('installer_2')

    installer_1 = None
    installer_2 = None

    if installer_1_id and installer_2_id:
        installer_1 = get_object_or_404(Installer, id=installer_1_id)
        installer_2 = get_object_or_404(Installer, id=installer_2_id)
        i1_lines = installer_1.content.split('\n')
        i2_lines = installer_2.content.split('\n')
        diff = HtmlDiff(tabsize=2, wrapcolumn=64)
        diff_table = diff.make_table(i1_lines, i2_lines)

    return render(request, 'games/installer-diff.html', {
        'form': form,
        'diff_table': diff_table,
        'installer_1': installer_1,
        'installer_2': installer_2
    })
示例#50
-1
文件: app.py 项目: dissemin/oabot
def make_diff(old, new):
    """
    Render in HTML the diff between two texts
    """
    df = HtmlDiff()
    old_lines = old.splitlines(1)
    new_lines = new.splitlines(1)
    html = df.make_table(old_lines, new_lines, context=True)
    html = html.replace(' nowrap="nowrap"','')
    return html