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


Python difflib._mdiff方法代码示例

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


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

示例1: make_file

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import _mdiff [as 别名]
def make_file(self, lhs, rhs):
    rows = []
    for left, right, changed in difflib._mdiff(lhs, rhs):
        lno, ltxt = left
        rno, rtxt = right
        ltxt = self._stop_wasting_space(ltxt)
        rtxt = self._stop_wasting_space(rtxt)
        ltxt = self._trunc(ltxt, changed).replace(" ", " ")
        rtxt = self._trunc(rtxt, changed).replace(" ", " ")
        row = self._row_template % (str(lno), ltxt, str(rno), rtxt)
        rows.append(row)

    all_the_rows = "\n".join(rows)
    all_the_rows = all_the_rows.replace(
          "\x00+", '<span class="diff_add">').replace(
          "\x00-", '<span class="diff_sub">').replace(
          "\x00^", '<span class="diff_chg">').replace(
          "\x01", '</span>').replace(
          "\t", 4 * "&nbsp;")

    res = self._html_template % {"style": self._style, "rows": all_the_rows}
    return res 
开发者ID:joxeankoret,项目名称:maltindex,代码行数:24,代码来源:diaphora_ida.py

示例2: make_file

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import _mdiff [as 别名]
def make_file(self, lhs, rhs):
    rows = []
    for left, right, changed in difflib._mdiff(lhs, rhs, charjunk=difflib.IS_CHARACTER_JUNK):
        lno, ltxt = left
        rno, rtxt = right
        ltxt = self._stop_wasting_space(ltxt)
        rtxt = self._stop_wasting_space(rtxt)
        ltxt = self._trunc(ltxt, changed).replace(" ", "&nbsp;")
        rtxt = self._trunc(rtxt, changed).replace(" ", "&nbsp;")
        row = self._row_template % (str(lno), ltxt, str(rno), rtxt)
        rows.append(row)

    all_the_rows = "\n".join(rows)
    all_the_rows = all_the_rows.replace(
          "\x00+", '<span class="diff_add">').replace(
          "\x00-", '<span class="diff_sub">').replace(
          "\x00^", '<span class="diff_chg">').replace(
          "\x01", '</span>').replace(
          "\t", 4 * "&nbsp;")

    res = self._html_template % {"style": self._style, "rows": all_the_rows}
    return res 
开发者ID:joxeankoret,项目名称:pigaios,代码行数:24,代码来源:sourceimp_ida.py

示例3: getDiffDetails

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import _mdiff [as 别名]
def getDiffDetails(self, fromdesc='', todesc='', context=False, numlines=5, tabSize=8):
        # change tabs to spaces before it gets more difficult after we insert
        # markkup
        def expand_tabs(line):
            # hide real spaces
            line = line.replace(' ', '\0')
            # expand tabs into spaces
            line = line.expandtabs(tabSize)
            # replace spaces from expanded tabs back into tab characters
            # (we'll replace them with markup after we do differencing)
            line = line.replace(' ', '\t')
            return line.replace('\0', ' ').rstrip('\n')

        self.fromlines = [expand_tabs(line) for line in self.fromlines]
        self.tolines = [expand_tabs(line) for line in self.tolines]

        # create diffs iterator which generates side by side from/to data
        if context:
            context_lines = numlines
        else:
            context_lines = None

        diffs = difflib._mdiff(self.fromlines, self.tolines, context_lines,
                               linejunk=None, charjunk=difflib.IS_CHARACTER_JUNK)
        return list(diffs) 
开发者ID:wagoodman,项目名称:diff2HtmlCompare,代码行数:27,代码来源:diff2HtmlCompare.py

示例4: make_table

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import _mdiff [as 别名]
def make_table(self, a, b, adesc=None, bdesc=None, context=5):
        """Make html table that displays side-by-side diff

        Arguments:
         - a -- list of text lines to be compared to b
         - b -- list of text lines to be compared to a
         - adesc -- description of the 'a' lines (e.g. filename)
         - bdesc -- description of the 'b' lines (e.g. filename)
         - context -- number of context lines to display

        Uses difflib._mdiff function to generate diff.
        """
        adesc = six.ensure_text(adesc) or ''
        bdesc = six.ensure_text(bdesc) or ''
        diff = difflib._mdiff(a, b, context=context)
        lines = [self._make_line(d) for d in diff]
        return h.really_unicode(
            self.table_tmpl % (adesc, bdesc, '\n'.join(lines))) 
开发者ID:apache,项目名称:allura,代码行数:20,代码来源:diff.py

示例5: make_file

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import _mdiff [as 别名]
def make_file(self, lhs, rhs, fmt, lex):
    rows = []
    for left, right, changed in difflib._mdiff(lhs, rhs):
        lno, ltxt = left
        rno, rtxt = right

        if not changed:
          ltxt = highlight(ltxt, lex, fmt)
          rtxt = highlight(rtxt, lex, fmt)
        else:
          ltxt = self._stop_wasting_space(ltxt)
          rtxt = self._stop_wasting_space(rtxt)

          ltxt = ltxt.replace(" ", "&nbsp;")
          rtxt = rtxt.replace(" ", "&nbsp;")
          ltxt = ltxt.replace("<", "&lt;")
          ltxt = ltxt.replace(">", "&gt;")
          rtxt = rtxt.replace("<", "&lt;")
          rtxt = rtxt.replace(">", "&gt;")

        row = self._row_template % (str(lno), ltxt, str(rno), rtxt)
        rows.append(row)

    all_the_rows = "\n".join(rows)
    all_the_rows = all_the_rows.replace(
          "\x00+", '<span class="diff_add">').replace(
          "\x00-", '<span class="diff_sub">').replace(
          "\x00^", '<span class="diff_chg">').replace(
          "\x01", '</span>').replace(
          "\t", 4 * "&nbsp;")

    res = self._html_template % {"style": self._style, "rows": all_the_rows}
    return res 
开发者ID:joxeankoret,项目名称:diaphora,代码行数:35,代码来源:diaphora_ida.py

示例6: test_mdiff_catch_stop_iteration

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import _mdiff [as 别名]
def test_mdiff_catch_stop_iteration(self):
        # Issue #33224
        self.assertEqual(
            list(difflib._mdiff(["2"], ["3"], 1)),
            [((1, '\x00-2\x01'), (1, '\x00+3\x01'), True)],
        ) 
开发者ID:bkerler,项目名称:android_universal,代码行数:8,代码来源:test_difflib.py

示例7: diff

# 需要导入模块: import difflib [as 别名]
# 或者: from difflib import _mdiff [as 别名]
def diff(self, prev_commit, fmt=None, prev_file=None, **kw):
        '''
        :param prev_commit: previous commit to compare against
        :param fmt: "sidebyside", or anything else for "unified"
        :param prev_file: previous filename, if different
        :return:
        '''
        try:
            path, filename = os.path.split(self._blob.path())
            a_ci = c.app.repo.commit(prev_commit)
            a = a_ci.get_path(prev_file or self._blob.path())
            apath = a.path()
        except Exception:
            # prev commit doesn't have the file
            a = M.repository.EmptyBlob()
            apath = ''
        b = self._blob

        if not self._blob.has_html_view:
            diff = "Cannot display: file marked as a binary type."
            return dict(a=a, b=b, diff=diff)

        la = list(a)
        lb = list(b)
        adesc = ('a' + h.really_unicode(apath)).encode('utf-8')
        bdesc = ('b' + h.really_unicode(b.path())).encode('utf-8')

        if not fmt:
            fmt = web_session.get('diformat', '')
        else:
            web_session['diformat'] = fmt
            web_session.save()
        if fmt == 'sidebyside':
            if max(a.size, b.size) > asint(tg.config.get('scm.view.max_syntax_highlight_bytes', 500000)):
                # have to check the original file size, not diff size, because difflib._mdiff inside HtmlSideBySideDiff
                # can take an extremely long time on large files (and its even a generator)
                diff = '<em>File too large for side-by-side view</em>'
            else:
                hd = HtmlSideBySideDiff()
                diff = hd.make_table(la, lb, adesc, bdesc)
        else:
            diff = str('').join(difflib.unified_diff(la, lb, adesc, bdesc))
        return dict(a=a, b=b, diff=diff) 
开发者ID:apache,项目名称:allura,代码行数:45,代码来源:repository.py


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