当前位置: 首页>>代码示例>>Python>>正文


Python difflib.HtmlDiff方法代码示例

本文整理汇总了Python中difflib.HtmlDiff方法的典型用法代码示例。如果您正苦于以下问题:Python difflib.HtmlDiff方法的具体用法?Python difflib.HtmlDiff怎么用?Python difflib.HtmlDiff使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在difflib的用法示例。


在下文中一共展示了difflib.HtmlDiff方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: html_diff

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import HtmlDiff [as 别名]
def html_diff(self, fromfile, tofile):
        try:
            import difflib
            fromlines = open(fromfile, 'U').readlines()
            tolines = open(tofile, 'U').readlines()
            diff = difflib.HtmlDiff().make_file(fromlines,tolines,fromfile,tofile)
            path = '/tmp/' + os.path.basename(fromfile) + '_' + os.path.basename(tofile) + '_diff.html'
            f = open(path,'w')
            f.write(diff)
            f.close()
            return path
            #import webbrowser
            #webbrowser.open_new_tab(path)
        except Exception as e:
            self.logger.error("failed to diff files %s, %s: %s", fromfile, tofile, str(e))
            return None 
开发者ID:osssanitizer,项目名称:osspolice,代码行数:18,代码来源:view.py

示例2: make_diff

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import HtmlDiff [as 别名]
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 
开发者ID:dissemin,项目名称:oabot,代码行数:12,代码来源:app.py

示例3: test_main

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import HtmlDiff [as 别名]
def test_main():
    difflib.HtmlDiff._default_prefix = 0
    Doctests = doctest.DocTestSuite(difflib)
    run_unittest(
        TestWithAscii, TestAutojunk, TestSFpatches, TestSFbugs,
        TestOutputFormat, TestJunkAPIs) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_difflib.py

示例4: test_main

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import HtmlDiff [as 别名]
def test_main():
    difflib.HtmlDiff._default_prefix = 0
    Doctests = doctest.DocTestSuite(difflib)
    run_unittest(
        TestWithAscii, TestAutojunk, TestSFpatches, TestSFbugs,
        TestOutputFormat, Doctests) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:8,代码来源:test_difflib.py

示例5: main

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import HtmlDiff [as 别名]
def main():

    usage = "usage: %prog [options] fromfile tofile"
    parser = optparse.OptionParser(usage)
    parser.add_option("-c", action="store_true", default=False, help='Produce a context format diff (default)')
    parser.add_option("-u", action="store_true", default=False, help='Produce a unified format diff')
    parser.add_option("-m", action="store_true", default=False, help='Produce HTML side by side diff (can use -c and -l in conjunction)')
    parser.add_option("-n", action="store_true", default=False, help='Produce a ndiff format diff')
    parser.add_option("-l", "--lines", type="int", default=3, help='Set number of context lines (default 3)')
    (options, args) = parser.parse_args()

    if len(args) == 0:
        parser.print_help()
        sys.exit(1)
    if len(args) != 2:
        parser.error("need to specify both a fromfile and tofile")

    n = options.lines
    fromfile, tofile = args

    fromdate = time.ctime(os.stat(fromfile).st_mtime)
    todate = time.ctime(os.stat(tofile).st_mtime)
    fromlines = open(fromfile, 'U').readlines()
    tolines = open(tofile, 'U').readlines()

    if options.u:
        diff = difflib.unified_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n)
    elif options.n:
        diff = difflib.ndiff(fromlines, tolines)
    elif options.m:
        diff = difflib.HtmlDiff().make_file(fromlines,tolines,fromfile,tofile,context=options.c,numlines=n)
    else:
        diff = difflib.context_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n)

    sys.stdout.writelines(diff) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:37,代码来源:diff.py

示例6: main

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import HtmlDiff [as 别名]
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('-c', action='store_true', default=False,
                        help='Produce a context format diff (default)')
    parser.add_argument('-u', action='store_true', default=False,
                        help='Produce a unified format diff')
    parser.add_argument('-m', action='store_true', default=False,
                        help='Produce HTML side by side diff '
                             '(can use -c and -l in conjunction)')
    parser.add_argument('-n', action='store_true', default=False,
                        help='Produce a ndiff format diff')
    parser.add_argument('-l', '--lines', type=int, default=3,
                        help='Set number of context lines (default 3)')
    parser.add_argument('fromfile')
    parser.add_argument('tofile')
    options = parser.parse_args()

    n = options.lines
    fromfile = options.fromfile
    tofile = options.tofile

    fromdate = file_mtime(fromfile)
    todate = file_mtime(tofile)
    with open(fromfile) as ff:
        fromlines = ff.readlines()
    with open(tofile) as tf:
        tolines = tf.readlines()

    if options.u:
        diff = difflib.unified_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n)
    elif options.n:
        diff = difflib.ndiff(fromlines, tolines)
    elif options.m:
        diff = difflib.HtmlDiff().make_file(fromlines,tolines,fromfile,tofile,context=options.c,numlines=n)
    else:
        diff = difflib.context_diff(fromlines, tolines, fromfile, tofile, fromdate, todate, n=n)

    sys.stdout.writelines(diff) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:41,代码来源:diff.py

示例7: test_make_file_default_charset

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import HtmlDiff [as 别名]
def test_make_file_default_charset(self):
        html_diff = difflib.HtmlDiff()
        output = html_diff.make_file(patch914575_from1.splitlines(),
                                     patch914575_to1.splitlines())
        self.assertIn('content="text/html; charset=utf-8"', output) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_difflib.py

示例8: test_make_file_iso88591_charset

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import HtmlDiff [as 别名]
def test_make_file_iso88591_charset(self):
        html_diff = difflib.HtmlDiff()
        output = html_diff.make_file(patch914575_from1.splitlines(),
                                     patch914575_to1.splitlines(),
                                     charset='iso-8859-1')
        self.assertIn('content="text/html; charset=iso-8859-1"', output) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_difflib.py

示例9: test_make_file_usascii_charset_with_nonascii_input

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import HtmlDiff [as 别名]
def test_make_file_usascii_charset_with_nonascii_input(self):
        html_diff = difflib.HtmlDiff()
        output = html_diff.make_file(patch914575_nonascii_from1.splitlines(),
                                     patch914575_nonascii_to1.splitlines(),
                                     charset='us-ascii')
        self.assertIn('content="text/html; charset=us-ascii"', output)
        self.assertIn('ımplıcıt', output) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_difflib.py

示例10: test_main

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import HtmlDiff [as 别名]
def test_main():
    difflib.HtmlDiff._default_prefix = 0
    Doctests = doctest.DocTestSuite(difflib)
    run_unittest(
        TestWithAscii, TestAutojunk, TestSFpatches, TestSFbugs,
        TestOutputFormat, TestBytes, Doctests) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_difflib.py

示例11: test_main

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import HtmlDiff [as 别名]
def test_main():
    difflib.HtmlDiff._default_prefix = 0
    Doctests = doctest.DocTestSuite(difflib)
    run_unittest(
        TestWithAscii, TestAutojunk, TestSFpatches, TestSFbugs,
        TestOutputFormat, TestJunkAPIs, Doctests) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:8,代码来源:test_difflib.py

示例12: showDiff

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import HtmlDiff [as 别名]
def showDiff():
    s1 = request.args.get('s1', '')
    s2 = request.args.get('s2', '')
    p1 = Paste.Paste(s1)
    p2 = Paste.Paste(s2)
    maxLengthLine1 = p1.get_lines_info()[1]
    maxLengthLine2 = p2.get_lines_info()[1]
    if maxLengthLine1 > DiffMaxLineLength or maxLengthLine2 > DiffMaxLineLength:
        return "Can't make the difference as the lines are too long."
    htmlD = difflib.HtmlDiff()
    lines1 = p1.get_p_content().splitlines()
    lines2 = p2.get_p_content().splitlines()
    the_html = htmlD.make_file(lines1, lines2)
    return the_html 
开发者ID:CIRCL,项目名称:AIL-framework,代码行数:16,代码来源:Flask_showpaste.py

示例13: create_diff_report

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import HtmlDiff [as 别名]
def create_diff_report(file1, file2, file_name, from_desc, to_desc, is_64_bit):

    """ Create a report showing the differences between two files

        Arguments :
            file1 : path to a file to disassemble
            file2 : path to a file to disassemble
            report_name : The name to use for the report
            from_desc : A description of the 'from' element
            to_desc : A description of the 'to' element
    """

    # Disassemble each file and split into lines
    disassembled_1 = OPcacheDisassembler(is_64_bit).disassemble(file1).split("\n")
    disassembled_2 = OPcacheDisassembler(is_64_bit).disassemble(file2).split("\n")

    # Differ
    html_differ = difflib.HtmlDiff()

    # Generate the report and write into a file
    file_name = file_name.replace("/", "%2f") + '.html'
    hash_name = hashlib.sha1(file_name).hexdigest()
    with open(hunt_report + "/" + hash_name + ".html", "w") as f:
	content = html_differ.make_file(disassembled_1, disassembled_2, from_desc, to_desc)
        f.write(content)

    # Return the name of the report
    return (file_name, hash_name + ".html") 
开发者ID:GoSecure,项目名称:php7-opcache-override,代码行数:30,代码来源:opcache_malware_hunt.py

示例14: test_main

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import HtmlDiff [as 别名]
def test_main():
    difflib.HtmlDiff._default_prefix = 0
    Doctests = doctest.DocTestSuite(difflib)
    run_unittest(
        TestWithAscii, TestAutojunk, TestSFpatches, TestSFbugs,
        TestOutputFormat, TestBytes, TestJunkAPIs, Doctests) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:8,代码来源:test_difflib.py

示例15: test_main

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import HtmlDiff [as 别名]
def test_main():
    difflib.HtmlDiff._default_prefix = 0
    Doctests = doctest.DocTestSuite(difflib)
    run_unittest(TestSFpatches, TestSFbugs, Doctests) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:6,代码来源:test_difflib.py


注:本文中的difflib.HtmlDiff方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。