From 9e604c0125c77655aacf925d1c17b91c1f1b38eb Mon Sep 17 00:00:00 2001 From: Dennis Burke Date: Fri, 9 Aug 2024 16:47:30 -0400 Subject: [PATCH] flake8 cleanup --- tests/test_lists.py | 18 ++++++++++-------- textile/core.py | 20 ++++++++++---------- textile/objects/list.py | 1 + 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/tests/test_lists.py b/tests/test_lists.py index 7ea05885..90537894 100644 --- a/tests/test_lists.py +++ b/tests/test_lists.py @@ -1,24 +1,26 @@ from textile import Textile from textile.objects.list import List + def test_lists(): t = Textile() result = t.textileLists("* one\n* two\n* three") expect = '\t' assert result == expect + def test_nested_list(): - l = List('ol', indent_level=1) - l.add_item('li', 'test') + lst = List('ol', indent_level=1) + lst('li', 'test') s = List('ol', indent_level=2) s.add_item('li', 'another one') - l.add_item('li', s) - result = l.process() + lst('li', s) + result = lst() expect = '\t
    \n\t\t
  1. test\n\t\t
      \n\t\t\t
    1. another one
    2. \n\t\t
  2. \n\t
' assert result == expect - l = List('ol', indent_level=1) - l.add_item('li', 'test') + lst = List('ol', indent_level=1) + lst('li', 'test') s1 = List('ol', indent_level=2) s1.add_item('li', 'another one') s2 = List('ul', indent_level=3) @@ -26,7 +28,7 @@ def test_nested_list(): s2.add_item('li', 'point two') s1.add_item('li', s2) s1.add_item('li', 'moar item') - l.add_item('li', s1) - result = l.process() + lst('li', s1) + result = lst() expect = '\t
    \n\t\t
  1. test\n\t\t
      \n\t\t\t
    1. another one\n\t\t\t
        \n\t\t\t\t
      • point one
      • \n\t\t\t\t
      • point two
      • \n\t\t\t
    2. \n\t\t\t
    3. moar item
    4. \n\t\t
  2. \n\t
' assert result == expect diff --git a/textile/core.py b/textile/core.py index 96a86ee1..8737e65a 100644 --- a/textile/core.py +++ b/textile/core.py @@ -293,16 +293,16 @@ def textileLists(self, text): def fTextileList(self, match): text = re.split(r'\n(?=[*#;:]+\s)', match.group(), flags=re.M) pt = '' - result = [] + # result = [] ls = OrderedDict() for i, line in enumerate(text): - try: - nextline = text[i + 1] - except IndexError: - nextline = '' + # try: + # nextline = text[i + 1] + # except IndexError: + # nextline = '' m = re.search(r"^(?P[#*;:]+)(?P_|\d+)?(?P{0})[ .]?" - "(?P.*)?$".format(cls_re_s), line, re.S) + "(?P.*)?$".format(cls_re_s), line, re.S) tl, start, atts, content = m.groups() attributes = parse_attributes(atts) content = content.strip() @@ -373,7 +373,7 @@ def fTextileList(self, match): _list.add_item(litem, content) elif showitem: # itemtag = ("\n{0}\t<{1}>{2}".format(tabs, litem, content) if - # showitem else '') + # showitem else '') _sublist = List('{0}l'.format(ltype), attributes) # line = "<{0}l{1}{2}>{3}".format(ltype, atts, start, itemtag) _sublist.add_item(litem, content, attributes) @@ -381,7 +381,7 @@ def fTextileList(self, match): # line = _sublist.process() else: # line = ("\t<{0}{1}>{2}".format(litem, atts, content) if - # showitem else '') + # showitem else '') _list.add_item(litem, content, attributes) # line = '{0}{1}'.format(tabs, line) @@ -404,8 +404,8 @@ def fTextileList(self, match): # This else exists in the original php version. I'm not sure how # to come up with a case where the line would not match. I think # it may have been necessary due to the way php returns matches. - #else: - #line = "{0}\n".format(line) + # else: + # line = "{0}\n".format(line) # result.append(line) return self.doTagBr(litem, _list.process()) diff --git a/textile/objects/list.py b/textile/objects/list.py index 9a38ee10..7dae531b 100644 --- a/textile/objects/list.py +++ b/textile/objects/list.py @@ -1,5 +1,6 @@ from textile.utils import generate_tag + class List(object): def __init__(self, listtype, attributes={}, indent_level=0): super(List, self).__init__()