This file is indexed.

/usr/share/pyshared/bike/testutils.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
from bike.globals import *
import unittest
import os
import os.path
from mock import Mock
from bike.parsing.fastparserast import getRoot, Root, resetRoot
from parsing.utils import fqn_rcar, fqn_rcdr
import re
from bike import log
filesToDelete = None
dirsToDelete = None

class BRMTestCase(unittest.TestCase):
    def setUp(self):
        log.warning = log.SilentLogger()
        try: os.makedirs(tmproot)
        except: pass
        os.chdir(tmproot)
        
        resetRoot(Root([tmproot]))
        getRoot().unittestmode = True
        global filesToDelete
        global dirsToDelete
        filesToDelete = []
        dirsToDelete = []
        from bike.parsing.load import Cache
        Cache.instance.reset()



    def tearDown(self):
        global filesToDelete
        global dirsToDelete

        for path in filesToDelete:
            try: os.remove(path)
            except: pass
        filesToDelete = []
            
        for path in dirsToDelete:
            try: os.removedirs(path)
            except: pass
        dirsToDelete = []

        os.chdir("..")
        try: os.removedirs(tmproot)
        except: pass



tmproot = os.path.abspath("tmproot")
tmpfile = os.path.join(tmproot, "bicyclerepairman_tmp_testfile.py")
tmpmodule = "bicyclerepairman_tmp_testfile"


def writeFile(filename, src):
    f = open(filename, "w+")
    f.write(src)
    f.close()
    filesToDelete.append(filename)

def readFile(filename):
    f = open(filename)
    src = f.read()
    f.close()
    return src

def writeTmpTestFile(src):
    try:
        os.makedirs(tmproot)
    except OSError:
        pass
    writeFile(tmpfile, src)

def readTmpTestFile():
    return readFile(tmpfile)

def deleteTmpTestFile():
    os.remove(tmpfile)
    os.removedirs(tmproot)


pkgstructureRootDir = tmproot
pkgstructureBasedir = os.path.join(pkgstructureRootDir, "a")
pkgstructureChilddir = os.path.join(pkgstructureBasedir, "b")
pkgstructureFile0 = os.path.join(pkgstructureRootDir, "top.py")
pkgstructureFile1 = os.path.join(pkgstructureBasedir, "foo.py")
pkgstructureFile2 = os.path.join(pkgstructureChilddir, "bah.py")


def createPackageStructure(src1, src2, src0="pass"):
    try: os.makedirs(pkgstructureChilddir)
    except: pass
    writeFile(os.path.join(pkgstructureBasedir, "__init__.py"), "#")
    writeFile(os.path.join(pkgstructureChilddir, "__init__.py"), "#")
    writeFile(pkgstructureFile0, src0)
    writeFile(pkgstructureFile1, src1)
    writeFile(pkgstructureFile2, src2)

def removePackageStructure():
    os.remove(os.path.join(pkgstructureBasedir, "__init__.py"))
    os.remove(os.path.join(pkgstructureChilddir, "__init__.py"))
    os.remove(pkgstructureFile0)
    os.remove(pkgstructureFile1)
    os.remove(pkgstructureFile2)
    os.removedirs(pkgstructureChilddir)


pkgstructureBasedir2 = os.path.join(pkgstructureRootDir, "c")
pkgstructureFile3 = os.path.join(pkgstructureBasedir2, "bing.py")

def createSecondPackageStructure(src3):
    try: os.makedirs(pkgstructureBasedir2)
    except: pass
    writeFile(os.path.join(pkgstructureBasedir2, "__init__.py"), "#")
    writeFile(pkgstructureFile3, src3)

def removeSecondPackageStructure():
    os.remove(os.path.join(pkgstructureBasedir2, "__init__.py"))
    os.remove(pkgstructureFile3)
    os.removedirs(pkgstructureBasedir2)



def createAST(src):
    from bike.parsing.load import getSourceNode
    writeFile(tmpfile,src)
    return getSourceNode(tmpfile)


def createSourceNodeAt(src, fqn):
    modname = fqn_rcar(fqn)
    packagefqn = fqn_rcdr(fqn)
    dirpath = os.path.join(*packagefqn.split("."))
    filepath = os.path.join(dirpath,modname+".py")
    try: os.makedirs(dirpath)
    except: pass
    dirsToDelete.append(dirpath)

    # add the __init__.py files
    path = "."
    for pathelem in packagefqn.split("."):
        path = os.path.join(path,pathelem)
        initfile = os.path.join(path,"__init__.py")
        writeFile(initfile,"#")
        filesToDelete.append(initfile)
    writeFile(filepath,src)
    filesToDelete.append(filepath)
    return getRoot()


# takes the leading whitespace out of a multi line comment.
# means you can imbed """
#                     text like
#                     this
#                     """
# in your code, and it will come out
#"""text like
#this"""
def trimLines(src):
    lines = src.splitlines(1)[1:]
    tabwidth = re.match("\s*",lines[0]).end(0)
    newlines = []
    for line in lines:
        if line == "\n" or line == "\r\n":
            newlines.append(line)
        else:
            newlines.append(line[tabwidth:])
    return "".join(newlines)