Exemple #1
0
 def split_contents(self):
     split = []
     bits = iter(smart_split(self.contents))
     for bit in bits:
         # Handle translation-marked template pieces
         if bit.startswith('_("') or bit.startswith("_('"):
             sentinal = bit[2] + ')'
             trans_bit = [bit]
             while not bit.endswith(sentinal):
                 bit = next(bits)
                 trans_bit.append(bit)
             bit = ' '.join(trans_bit)
         split.append(bit)
     return split
Exemple #2
0
    def test_smart_split(self):

        self.assertEqual(list(smart_split(r'''This is "a person" test.''')),
            ['This', 'is', '"a person"', 'test.'])

        self.assertEqual(list(smart_split(r'''This is "a person's" test.'''))[2],
            '"a person\'s"')

        self.assertEqual(list(smart_split(r'''This is "a person\"s" test.'''))[2],
            '"a person\\"s"')

        self.assertEqual(list(smart_split('''"a 'one''')), ['"a', "'one"])

        self.assertEqual(list(smart_split(r'''all friends' tests'''))[1],
            "friends'")

        self.assertEqual(list(smart_split('url search_page words="something else"')),
            ['url', 'search_page', 'words="something else"'])

        self.assertEqual(list(smart_split("url search_page words='something else'")),
            ['url', 'search_page', "words='something else'"])

        self.assertEqual(list(smart_split('url search_page words "something else"')),
            ['url', 'search_page', 'words', '"something else"'])

        self.assertEqual(list(smart_split('url search_page words-"something else"')),
            ['url', 'search_page', 'words-"something else"'])

        self.assertEqual(list(smart_split('url search_page words=hello')),
            ['url', 'search_page', 'words=hello'])

        self.assertEqual(list(smart_split('url search_page words="something else')),
            ['url', 'search_page', 'words="something', 'else'])

        self.assertEqual(list(smart_split("cut:','|cut:' '")),
            ["cut:','|cut:' '"])