Skip to content

Commit

Permalink
strip_quotes improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabrizio Sestito committed Dec 14, 2011
1 parent 0b0d335 commit 125d7ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
20 changes: 9 additions & 11 deletions threaded_messages/tests.py
Expand Up @@ -3,7 +3,7 @@
from django.contrib.auth.models import User
from models import Message
from utils import strip_quotes

from django.utils.html import strip_tags

class UtilsTest(TestCase):
def test_strip_quotes(self):
Expand All @@ -12,6 +12,14 @@ def test_strip_quotes(self):
nyan nyan nyan nyan nyan
2011/10/28 Nyan Cat <nyan@nyan.cat>:
> hey guys
> sarete il 31 dicembre con Pascal a Firenze?
Expand All @@ -29,13 +37,3 @@ def test_strip_quotes(self):
"""

self.assertEquals(body_stripped.strip(), strip_quotes(body).strip())
def test_strip_quotes(self):
body = "miao\r\n\r\n2011/12/13 Fabrizio Sestito <fabrizio@gidsy.com>:\r\n> try\r\n>\r\n> 2011/12/13 Fabrizio Sestito <fabrizio@gidsy.com>:\r\n>> repr\r\n>>\r\n>> 2011/12/13 Fabrizio Sestito <fabrizio@gidsy.com>:\r\n>>> meow\r\n>>>\r\n>>> 2011/12/13 Fabrizio Sestito <fabrizio@gidsy.com>:\r\n>>>> mhh?\r\n>>>>\r\n>>>>\r\n>>>> 2011/12/13 Fabrizio Sestito <fabrizio@gidsy.com>:\r\n>>>>> nyancat\r\n>>>>>\r\n>>>>> 2011/12/13 Fabrizio Sestito <fabrizio@gidsy.com>:\r\n>>>>>> hi there\r\n>>>>>>\r\n>>>>>>\r\n>>>>>> 2011/12/13 Fabrizio Sestito <fabrizio@gidsy.com>:\r\n>>>>>>> fgfg\r\n>>>>>>>\r\n>>>>>>> 2011/12/13 Fabrizio Sestito <fabrizio@gidsy.com>:\r\n>>>>>>>> dfdfd\r\n>>>>>>>>\r\n>>>>>>>> On Tue, Dec 13, 2011 at 12:35 PM, Fabrizio Sestito <fabrizio@gidsy.com> wrote:\r\n>>>>>>>>> ciao\n"

body_stripped = """miao
"""

self.assertEquals(body_stripped.strip(), strip_quotes(body).strip())

7 changes: 6 additions & 1 deletion threaded_messages/utils.py
Expand Up @@ -94,7 +94,12 @@ def strip_quotes(body):
if l.lstrip().startswith('>'):
if not custom_line_no:
custom_line_no = i-1
lines.pop(custom_line_no)
popme_no = custom_line_no
#import nose; nose.tools.set_trace()
lines.pop(popme_no)
while lines[popme_no] =='\n' and popme_no <= 0:
lines.pop(popme_no)
popme_no -= 1
break

stripped_lines = [s for s in lines if not s.lstrip().startswith('>')]
Expand Down

0 comments on commit 125d7ae

Please sign in to comment.