Esempio n. 1
0
 def test_backslash_escapes(self):
     self.assertListEqual(list(iterparse_character_subset('\\{')),
                          [ord('{')])
     self.assertListEqual(list(iterparse_character_subset('\\(')),
                          [ord('(')])
     self.assertListEqual(list(iterparse_character_subset('\\a')),
                          [ord('\\'), ord('a')])
Esempio n. 2
0
    def test_bad_character_range(self):
        with self.assertRaises(RegexError) as ctx:
            list(iterparse_character_subset('9-2'))
        self.assertIn('bad character range', str(ctx.exception))

        with self.assertRaises(RegexError) as ctx:
            list(iterparse_character_subset('2-\\s'))
        self.assertIn('bad character range', str(ctx.exception))
Esempio n. 3
0
 def test_backslash_character(self):
     self.assertListEqual(list(iterparse_character_subset('\\')), [ord('\\')])
     self.assertListEqual(list(iterparse_character_subset('2-\\')),
                          [(ord('2'), ord('\\') + 1)])
     self.assertListEqual(list(iterparse_character_subset('2-\\\\')),
                          [(ord('2'), ord('\\') + 1), ord('\\')])
     self.assertListEqual(list(iterparse_character_subset('2-\\x')),
                          [(ord('2'), ord('\\') + 1), ord('x')])
     self.assertListEqual(list(iterparse_character_subset('2-\\a-x')),
                          [(ord('2'), ord('\\') + 1), (ord('a'), ord('x') + 1)])
     self.assertListEqual(list(iterparse_character_subset('2-\\{')),
                          [(ord('2'), ord('{') + 1)])
Esempio n. 4
0
    def test_square_brackets(self):
        self.assertListEqual(list(iterparse_character_subset('\\[')), [ord('[')])
        self.assertListEqual(list(iterparse_character_subset('[')), [ord('[')])

        with self.assertRaises(RegexError) as ctx:
            list(iterparse_character_subset('[ '))
        self.assertIn("bad character '['", str(ctx.exception))

        with self.assertRaises(RegexError) as ctx:
            list(iterparse_character_subset('x['))
        self.assertIn("bad character '['", str(ctx.exception))

        self.assertListEqual(list(iterparse_character_subset('\\]')), [ord(']')])
        self.assertListEqual(list(iterparse_character_subset(']')), [ord(']')])

        with self.assertRaises(RegexError) as ctx:
            list(iterparse_character_subset('].'))
        self.assertIn("bad character ']'", str(ctx.exception))

        with self.assertRaises(RegexError) as ctx:
            list(iterparse_character_subset('8['))
        self.assertIn("bad character '['", str(ctx.exception))
Esempio n. 5
0
 def test_expand_ranges(self):
     self.assertListEqual(
         list(iterparse_character_subset('a-e', expand_ranges=True)),
         [ord('a'), ord('b'),
          ord('c'), ord('d'),
          ord('e')])
Esempio n. 6
0
 def test_parse_multiple_ranges(self):
     self.assertListEqual(
         list(iterparse_character_subset('a-c-1-4x-z-7-9')),
         [(ord('a'), ord('c') + 1),
          ord('-'), (ord('1'), ord('4') + 1), (ord('x'), ord('z') + 1),
          ord('-'), (55, 58)])
Esempio n. 7
0
 def test_character_range(self):
     self.assertListEqual(list(iterparse_character_subset('A-z')),
                          [(ord('A'), ord('z') + 1)])
     self.assertListEqual(list(iterparse_character_subset('\\[-z')),
                          [(ord('['), ord('z') + 1)])