Python re.DEBUG() Examples

The following are code examples for showing how to use re.DEBUG(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: pefile.pypy   Author: cloudtracer   File: test_re.py    (license) View Source Project 6 votes vote down vote up
def test_debug_flag(self):
        pat = r'(\.)(?:[ch]|py)(?(1)$|: )'
        with captured_stdout() as out:
            re.compile(pat, re.DEBUG)
        dump = '''\
subpattern 1
  literal 46
subpattern None
  branch
    in
      literal 99
      literal 104
  or
    literal 112
    literal 121
subpattern None
  groupref_exists 1
    at at_end
  else
    literal 58
    literal 32
'''
        self.assertEqual(out.getvalue(), dump)
        # Debug output is output again even a second time (bypassing
        # the cache -- issue #20426).
        with captured_stdout() as out:
            re.compile(pat, re.DEBUG)
        self.assertEqual(out.getvalue(), dump) 
Example 2
Project: oil   Author: oilshell   File: test_re.py    (license) View Source Project 5 votes vote down vote up
def test_debug_flag(self):
        pat = r'(\.)(?:[ch]|py)(?(1)$|: )'
        with captured_stdout() as out:
            re.compile(pat, re.DEBUG)
        dump = '''\
subpattern 1
  literal 46
subpattern None
  branch
    in
      literal 99
      literal 104
  or
    literal 112
    literal 121
subpattern None
  groupref_exists 1
    at at_end
  else
    literal 58
    literal 32
'''
        self.assertEqual(out.getvalue(), dump)
        # Debug output is output again even a second time (bypassing
        # the cache -- issue #20426).
        with captured_stdout() as out:
            re.compile(pat, re.DEBUG)
        self.assertEqual(out.getvalue(), dump) 
Example 3
Project: python2-tracer   Author: extremecoders-re   File: test_re.py    (license) View Source Project 5 votes vote down vote up
def test_debug_flag(self):
        pat = r'(\.)(?:[ch]|py)(?(1)$|: )'
        with captured_stdout() as out:
            re.compile(pat, re.DEBUG)
        dump = '''\
subpattern 1
  literal 46
subpattern None
  branch
    in
      literal 99
      literal 104
  or
    literal 112
    literal 121
subpattern None
  groupref_exists 1
    at at_end
  else
    literal 58
    literal 32
'''
        self.assertEqual(out.getvalue(), dump)
        # Debug output is output again even a second time (bypassing
        # the cache -- issue #20426).
        with captured_stdout() as out:
            re.compile(pat, re.DEBUG)
        self.assertEqual(out.getvalue(), dump) 
Example 4
Project: ouroboros   Author: pybee   File: test_re.py    (license) View Source Project 5 votes vote down vote up
def test_debug_flag(self):
        pat = r'(\.)(?:[ch]|py)(?(1)$|: )'
        with captured_stdout() as out:
            re.compile(pat, re.DEBUG)
        dump = '''\
subpattern 1
  literal 46
subpattern None
  branch
    in
      literal 99
      literal 104
  or
    literal 112
    literal 121
subpattern None
  groupref_exists 1
    at at_end
  else
    literal 58
    literal 32
'''
        self.assertEqual(out.getvalue(), dump)
        # Debug output is output again even a second time (bypassing
        # the cache -- issue #20426).
        with captured_stdout() as out:
            re.compile(pat, re.DEBUG)
        self.assertEqual(out.getvalue(), dump) 
Example 5
Project: kbe_server   Author: xiaohaoppy   File: test_re.py    (license) View Source Project 5 votes vote down vote up
def test_debug_flag(self):
        with captured_stdout() as out:
            re.compile('foo', re.DEBUG)
        self.assertEqual(out.getvalue().splitlines(),
                         ['literal 102 ', 'literal 111 ', 'literal 111 '])
        # Debug output is output again even a second time (bypassing
        # the cache -- issue #20426).
        with captured_stdout() as out:
            re.compile('foo', re.DEBUG)
        self.assertEqual(out.getvalue().splitlines(),
                         ['literal 102 ', 'literal 111 ', 'literal 111 '])