Пример #1
0
 def test_whitespace_marked_up3(self):
     """Related to #5795"""
     changes = diff.diff_blocks(["a   "], ["b   "])
     block = changes[0][0]
     self.assertEqual(block["type"], "mod")
     self.assertEqual(str(block["base"]["lines"][0]), "<del>a</del>&nbsp; &nbsp;")
     self.assertEqual(str(block["changed"]["lines"][0]), "<ins>b</ins>&nbsp; &nbsp;")
Пример #2
0
 def test_expandtabs_works_right(self):
     """Regression test for #4557"""
     changes = diff.diff_blocks(["aa\tb"], ["aaxb"])
     block = changes[0][0]
     self.assertEqual(block["type"], "mod")
     self.assertEqual(str(block["base"]["lines"][0]), "aa<del>&nbsp; &nbsp; &nbsp; </del>b")
     self.assertEqual(str(block["changed"]["lines"][0]), "aa<ins>x</ins>b")
Пример #3
0
 def test_whitespace_marked_up1(self):
     """Regression test for #5795"""
     changes = diff.diff_blocks(["*a"], [" *a"])
     block = changes[0][0]
     self.assertEqual(block["type"], "mod")
     self.assertEqual(str(block["base"]["lines"][0]), "<del></del>*a")
     self.assertEqual(str(block["changed"]["lines"][0]), "<ins>&nbsp;</ins>*a")
Пример #4
0
    def _prepare_diff(self, req, page, old_text, new_text,
                      old_version, new_version):
        diff_style, diff_options, diff_data = get_diff_options(req)
        diff_context = 3
        for option in diff_options:
            if option.startswith('-U'):
                diff_context = int(option[2:])
                break
        if diff_context < 0:
            diff_context = None
        diffs = diff_blocks(old_text, new_text, context=diff_context,
                            ignore_blank_lines='-B' in diff_options,
                            ignore_case='-i' in diff_options,
                            ignore_space_changes='-b' in diff_options)
        def version_info(v, last=0):
            return {'path': get_resource_name(self.env, page.resource),
                    # TRANSLATOR: wiki page
                    'rev': v or _('currently edited'),
                    'shortrev': v or last + 1,
                    'href': req.href.wiki(page.name, version=v) if v else None}
        changes = [{'diffs': diffs, 'props': [],
                    'new': version_info(new_version, old_version),
                    'old': version_info(old_version)}]

        add_stylesheet(req, 'common/css/diff.css')
        add_script(req, 'common/js/diff.js')
        return diff_data, changes
Пример #5
0
def get_diffs(self, req, title, old_text, new_text):
    diff_style, diff_options, diff_data = get_diff_options(req)
    diff_context = 3
    for option in diff_options:
        if option.startswith('-U'):
            diff_context = int(option[2:])
            break
    if diff_context < 0:
        diff_context = None
    diffs = diff_blocks(old_text.splitlines(), new_text.splitlines(), context=diff_context,
                        tabwidth=2,
                        ignore_blank_lines=True,
                        ignore_case=True,
                        ignore_space_changes=True)
    
    chrome = Chrome(self.env)
    loader = TemplateLoader(chrome.get_all_templates_dirs())
    tmpl = loader.load('diff_div.html')
    
    changes=[{'diffs': diffs, 'props': [],
              'title': title,
              'new': {'path':"", 'rev':'', 'shortrev': '', 'href':''},
              'old': {'path':"", 'rev':'', 'shortrev': '', 'href': ''}}]

    data = chrome.populate_data(req,
                                { 'changes':changes , 'no_id':True, 'diff':diff_data,
                                  'longcol': '', 'shortcol': ''})
    diff_data['style']='sidebyside';
    data.update({ 'changes':changes , 'no_id':True, 'diff':diff_data,
                  'longcol': '', 'shortcol': ''})
    stream = tmpl.generate(**data)
    return stream.render()
Пример #6
0
 def test_expandtabs_works_right(self):
     """Regression test for #4557"""
     changes = diff.diff_blocks(['aa\tb'], ['aaxb'])
     block = changes[0][0]
     self.assertEquals(block['type'], 'mod')
     self.assertEquals(str(block['base']['lines'][0]), 'aa<del>&nbsp; &nbsp; &nbsp; </del>b')
     self.assertEquals(str(block['changed']['lines'][0]), 'aa<ins>x</ins>b')
Пример #7
0
    def _prepare_diff(self, req, page, old_text, new_text,
                      old_version, new_version):
        diff_style, diff_options, diff_data = get_diff_options(req)
        diff_context = 3
        for option in diff_options:
            if option.startswith('-U'):
                diff_context = int(option[2:])
                break
        if diff_context < 0:
            diff_context = None
        diffs = diff_blocks(old_text, new_text, context=diff_context,
                            ignore_blank_lines='-B' in diff_options,
                            ignore_case='-i' in diff_options,
                            ignore_space_changes='-b' in diff_options)
        def version_info(v, last=0):
            return {'path': get_resource_name(self.env, page.resource),
                    # TRANSLATOR: wiki page
                    'rev': v or _("currently edited"),
                    'shortrev': v or last + 1,
                    'href': req.href.wiki(page.name, version=v)
                            if v else None}
        changes = [{'diffs': diffs, 'props': [],
                    'new': version_info(new_version, old_version),
                    'old': version_info(old_version)}]

        add_stylesheet(req, 'common/css/diff.css')
        add_script(req, 'common/js/diff.js')
        return diff_data, changes
Пример #8
0
    def get_diffs(self, req, old_text, new_text, id):
        diff_style, diff_options, diff_data = get_diff_options(req)
        diff_context = 3
        for option in diff_options:
            if option.startswith('-U'):
                diff_context = int(option[2:])
                break
        if diff_context < 0:
            diff_context = None
        diffs = diff_blocks(old_text.splitlines(), new_text.splitlines(), context=diff_context,
                            tabwidth=2,
                            ignore_blank_lines=True,
                            ignore_case=True,
                            ignore_space_changes=True)
        
        chrome = Chrome(self.env)
        loader = TemplateLoader(chrome.get_all_templates_dirs())
        tmpl = loader.load('diff_div.html')
        
        title = "Estimate:%s Changed" %id
        changes=[{'diffs': diffs, 'props': [],
                  'title': title, 'href': req.href('Estimate', id=id),
                  'new': {'path':title, 'rev':'', 'shortrev': '', 'href': req.href('Estimate', id=id)},
                  'old': {'path':"", 'rev':'', 'shortrev': '', 'href': ''}}]

        data = chrome.populate_data(req,
                                    { 'changes':changes , 'no_id':True, 'diff':diff_data,
                                      'longcol': '', 'shortcol': ''})
        # diffs = diff_blocks("Russ Tyndall", "Russ Foobar Tyndall", context=None, ignore_blank_lines=True, ignore_case=True, ignore_space_changes=True)
        # data = c._default_context_data.copy ()
        diff_data['style']='sidebyside';
        data.update({ 'changes':changes , 'no_id':True, 'diff':diff_data,
                      'longcol': '', 'shortcol': ''})
        stream = tmpl.generate(**data)
        return stream.render()
Пример #9
0
 def test_whitespace_marked_up3(self):
     """Related to #5795"""
     changes = diff.diff_blocks(['a   '], ['b   '])
     block = changes[0][0]
     self.assertEquals(block['type'], 'mod')
     self.assertEquals(str(block['base']['lines'][0]), '<del>a</del>&nbsp; &nbsp;')
     self.assertEquals(str(block['changed']['lines'][0]), '<ins>b</ins>&nbsp; &nbsp;')
Пример #10
0
 def test_whitespace_marked_up1(self):
     """Regression test for #5795"""
     changes = diff.diff_blocks(['*a'], [' *a'])
     block = changes[0][0]
     self.assertEquals(block['type'], 'mod')
     self.assertEquals(str(block['base']['lines'][0]), '<del></del>*a')
     self.assertEquals(str(block['changed']['lines'][0]), '<ins>&nbsp;</ins>*a')
Пример #11
0
 def test_expandtabs_works_right(self):
     """Regression test for #4557"""
     changes = diff.diff_blocks(['aa\tb'], ['aaxb'])
     block = changes[0][0]
     self.assertEqual(block['type'], 'mod')
     self.assertEqual(str(block['base']['lines'][0]),
                      'aa<del>&nbsp; &nbsp; &nbsp; </del>b')
     self.assertEqual(str(block['changed']['lines'][0]), 'aa<ins>x</ins>b')
Пример #12
0
 def test_whitespace_marked_up1(self):
     """Regression test for #5795"""
     changes = diff.diff_blocks(['*a'], [' *a'])
     block = changes[0][0]
     self.assertEqual(block['type'], 'mod')
     self.assertEqual(str(block['base']['lines'][0]), '<del></del>*a')
     self.assertEqual(str(block['changed']['lines'][0]),
                      '<ins>&nbsp;</ins>*a')
Пример #13
0
 def test_whitespace_marked_up3(self):
     """Related to #5795"""
     changes = diff.diff_blocks(['a   '], ['b   '])
     block = changes[0][0]
     self.assertEqual(block['type'], 'mod')
     self.assertEqual(str(block['base']['lines'][0]),
                      '<del>a</del>&nbsp; &nbsp;')
     self.assertEqual(str(block['changed']['lines'][0]),
                      '<ins>b</ins>&nbsp; &nbsp;')
Пример #14
0
 def test_quotes_not_marked_up(self):
     """Make sure that the escape calls leave quotes along, we don't need
     to escape them."""
     changes = diff.diff_blocks(['ab'], ['a"b'])
     self.assertEqual(len(changes), 1)
     blocks = changes[0]
     self.assertEqual(len(blocks), 1)
     block = blocks[0]
     self.assertEqual(block['type'], 'mod')
     self.assertEqual(str(block['base']['lines'][0]), 'a<del></del>b')
     self.assertEqual(str(block['changed']['lines'][0]), 'a<ins>"</ins>b')
Пример #15
0
 def _my_diff(self, old_content, new_content):
     # Determine the difference between two text items.
     if old_content == new_content:
         return None
     try:
         return diff_blocks(old_content.splitlines(),
                            new_content.splitlines(),
                            0, tabwidth=8,
                            ignore_blank_lines=True,
                            ignore_case=True,
                            ignore_space_changes=True)
     except UnicodeDecodeError:
         old_content = unicode(old_content, "iso-8859-1")
         new_content = unicode(new_content, "iso-8859-1")
         return diff_blocks(old_content.splitlines(),
                            new_content.splitlines(),
                            0, tabwidth=8,
                            ignore_blank_lines=True,
                            ignore_case=True,
                            ignore_space_changes=True)
Пример #16
0
 def test_quotes_not_marked_up(self):
     """Make sure that the escape calls leave quotes along, we don't need
     to escape them."""
     changes = diff.diff_blocks(["ab"], ['a"b'])
     self.assertEqual(len(changes), 1)
     blocks = changes[0]
     self.assertEqual(len(blocks), 1)
     block = blocks[0]
     self.assertEqual(block["type"], "mod")
     self.assertEqual(str(block["base"]["lines"][0]), "a<del></del>b")
     self.assertEqual(str(block["changed"]["lines"][0]), 'a<ins>"</ins>b')
Пример #17
0
 def test_quotes_not_marked_up(self):
     """Make sure that the escape calls leave quotes along, we don't need
     to escape them."""
     changes = diff.diff_blocks(['ab'], ['a"b'])
     self.assertEquals(len(changes), 1)
     blocks = changes[0]
     self.assertEquals(len(blocks), 1)
     block = blocks[0]
     self.assertEquals(block['type'], 'mod')
     self.assertEquals(str(block['base']['lines'][0]), 'a<del></del>b')
     self.assertEquals(str(block['changed']['lines'][0]), 'a<ins>"</ins>b')
Пример #18
0
 def _my_diff(self, old_content, new_content):
     # Determine the difference between two text items.
     if old_content == new_content:
         return None
     try:
         return diff_blocks(old_content.splitlines(),
                            new_content.splitlines(),
                            0,
                            tabwidth=8,
                            ignore_blank_lines=True,
                            ignore_case=True,
                            ignore_space_changes=True)
     except UnicodeDecodeError:
         old_content = unicode(old_content, "iso-8859-1")
         new_content = unicode(new_content, "iso-8859-1")
         return diff_blocks(old_content.splitlines(),
                            new_content.splitlines(),
                            0,
                            tabwidth=8,
                            ignore_blank_lines=True,
                            ignore_case=True,
                            ignore_space_changes=True)
Пример #19
0
        def _content_changes(old_node, new_node):
            """Returns the list of differences.

            The list is empty when no differences between comparable files
            are detected, but the return value is None for non-comparable files.
            """
            mview = Mimeview(self.env)
            if mview.is_binary(old_node.content_type, old_node.path):
                return None
            if mview.is_binary(new_node.content_type, new_node.path):
                return None
            old_content = old_node.get_content().read()
            if mview.is_binary(content=old_content):
                return None
            new_content = new_node.get_content().read()
            if mview.is_binary(content=new_content):
                return None

            old_content = mview.to_unicode(old_content, old_node.content_type)
            new_content = mview.to_unicode(new_content, new_node.content_type)

            if old_content != new_content:
                context = options.get('contextlines', 3)
                if context < 0:
                    context = None
                tabwidth = self.config['diff'].getint('tab_width') or \
                           self.config['mimeviewer'].getint('tab_width', 8)
                ignore_blank_lines = options.get('ignoreblanklines')
                ignore_case = options.get('ignorecase')
                ignore_space = options.get('ignorewhitespace')
                return diff_blocks(old_content.splitlines(),
                                   new_content.splitlines(),
                                   context, tabwidth,
                                   ignore_blank_lines=ignore_blank_lines,
                                   ignore_case=ignore_case,
                                   ignore_space_changes=ignore_space)
            else:
                return []