author Gregory Szorc <>
Tue, 15 Jan 2013 22:21:21 -0800
changeset 119046 ec072cee05025335f0637de7e1dab95623fe8a56
parent 94475 f4157e8c410708d76703f19e4dfb61859bfe32d8
permissions -rw-r--r--
Bug 784841 - Part 2: Implement sandboxing for Python build files; r=ted,glandium This is the beginning of Mozilla's new build system. In this patch, we have a Python sandbox tailored for execution of Python scripts which will define the build system. We also have a build reader that traverses a linked set of scripts. More details are available in the thorough README.rst files as part of this patch. * * * Bug 784841 - Part 2b: Option to not descend into child files; r=ted

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at

"""The test case itsself, and associated stuff"""

import string

class BaseTest:
    def __init__(self):
        self.res = -1
        self.reason = None
    def parse_config(self, config):
        self.files = []

        for line in config.readlines():
            line = string.strip(line)
            self.files.append({'file': line, 'read': 0})

    baseName = 'index'

    def verify_request(self, req):
        """Check that the request is valid.

        Also needs to update any internal 'read' stuff"""
        ## XXXXX
        ## This needs to be done using exceptions, maybe
        ## XXXXX
        for i in self.files:
            if i['file'] == req.fname:
                if i['read'] == 1:
                    self.res = 0
                    self.reason = "File %s was read twice" % (req.fname)
                    return 0
                i['read'] = 1
            elif i['read'] == 0:
                self.res = 0
                self.reason = "File %s requested, expected %s" % (req.fname, i['file'])
                return 0

        ### Simplistic for now...
        res = req.headers.getheader('Host')

        return res

    def result(self):
        if self.res == -1:
            for i in self.files:
                if i['read'] == 0:
                    self.res = 0
                    self.reason = "%s not read" % (i['file'])
                    return self.res, self.reason
            self.res = 1
        return self.res, self.reason

tester = BaseTest