This file is indexed.

/usr/share/pyshared/bike/parsing/test_parserutils.py is in bicyclerepair 0.9-6.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python
import unittest
from parserutils import *
from bike.testutils import *

class TestRemoveEscapedQuotes(BRMTestCase):

    def testMaskEscapedQuotes_MasksEscapedQuotes(self):
        src = '\" \\\\\\\" \' \\\\\\\\\"  \'  \''
        self.assertEqual(maskEscapedQuotes(src),'" **** \' ****"  \'  \'')

class TestMungePythonKeywordsInStrings(BRMTestCase):
    def test_mungesKeywords(self):
        src = '\"\"\"class try while\"\"\" class2 try2 while2 \'\'\' def if for \'\'\' def2 if2 for2'
        self.assertEqual(maskPythonKeywordsInStringsAndComments(src),
                      '"""CLASS TRY WHILE""" class2 try2 while2 \'\'\' DEF IF FOR \'\'\' def2 if2 for2')


class TestSplitLines(BRMTestCase):
    def test_handlesExplicitlyContinuedLineWithComment(self):
        self.assertEqual(splitLogicalLines(explicitlyContinuedLineWithComment),
              ['\n', 'z = a + b + \\  # comment\n  c + d\n', 'pass\n'])

    def test_handlesImplicitlyContinuedLine(self):
        self.assertEqual(splitLogicalLines(implicitlyContinuedLine), 
                         ['\n', 'z = a + b + (\n  c + d)\n', 'pass\n'])

    def test_handlesNestedImplicitlyContinuedLine(self):
        self.assertEqual(splitLogicalLines(implicitlyContinuedLine2), 
                         ['\n', 'z = a + b + ( c + [d\n  + e]\n  + f)   # comment\n', 'pass\n'])


    def test_handlesMultiLineStrings(self):
        self.assertEqual(splitLogicalLines(multilineComment),
                         ['\n', "''' this is an mlc\nso is this\n'''\n", 'pass\n'])
                         

class TestMakeLineParseable(BRMTestCase):
    def test_worksWithIfStatement(self):
        src = "if foo:"
        self.assertEqual(makeLineParseable(src),("if foo: pass"))

    def test_worksWithTryStatement(self):
        src = "try :"
        self.assertEqual(makeLineParseable(src),("try : pass\nexcept: pass"))

    def test_worksOnTryStatementWithCodeInlined(self):
        src = "try : a = 1"
        self.assertEqual(makeLineParseable(src),("try : a = 1\nexcept: pass"))

    def test_worksWithExceptStatement(self):
        src = "except :"
        self.assertEqual(makeLineParseable(src),("try: pass\nexcept : pass"))

    def test_worksWithFinallyStatement(self):
        src = "finally:"
        self.assertEqual(makeLineParseable(src),("try: pass\nfinally: pass"))

    def test_worksWithIfStatement(self):
        src = "if foo:"
        self.assertEqual(makeLineParseable(src),("if foo: pass"))

    def test_worksWithElseStatement(self):
        src = "else :"
        self.assertEqual(makeLineParseable(src),("if 0: pass\nelse : pass"))

    def test_worksWithElifStatement(self):
        src = "elif foo:"
        self.assertEqual(makeLineParseable(src),("if 0: pass\nelif foo: pass"))


def runOverPath(path):
    import compiler
    from parser import ParserError
    from bike.parsing.load import getFilesForName
    files = getFilesForName(path)
    for fname in files:
        print fname
        src = file(fname).read()
        #print src
        src = maskStringsAndRemoveComments(src)

        for logicalline in splitLogicalLines(src):
            #print "logicalline=",logicalline    
            logicalline = logicalline.strip()
            logicalline = makeLineParseable(logicalline)
            try:
                compiler.parse(logicalline)
            except ParserError:
                print "ParserError on logicalline:",logicalline
            except:
                log.exception("caught exception")
                

explicitlyContinuedLineWithComment = """
z = a + b + \  # comment
  c + d
pass
"""

implicitlyContinuedLine = """
z = a + b + (
  c + d)
pass
"""


implicitlyContinuedLine2 = """
z = a + b + ( c + [d
  + e]
  + f)   # comment
pass
"""

multilineComment = """
''' this is an mlc
so is this
'''
pass
"""

if __name__ == "__main__":
    from bike import logging
    logging.init()
    log = logging.getLogger("bike")
    log.setLevel(logging.INFO)
    
    # add soak tests to end of test
    class Z_SoakTest(BRMTestCase):
        def test_linesRunThroughPythonParser(self):
            print ""
            #print splitLogicalLines(file('/usr/local/lib/python2.2/aifc.py').read())
            #runOverPath('/usr/local/lib/python2.2/test/badsyntax_nocaret.py')
            runOverPath('/usr/local/lib/python2.2/')
    unittest.main()