Beispiel #1
0
 def _read(self):
     if not os.path.exists(self.filename):
         return {}
     self._lock.acquire()
     file = None
     try:
         file = open(self.filename, 'r')
         r = RExec()
         r.update_global_names(self._context)
         dict = r.r_eval(file.read())
     finally:
         if file: file.close()
         self._lock.release()
     return dict
Beispiel #2
0
 def _read(self):
     if not os.path.exists(self.filename):
         return {}
     self._lock.acquire()
     file = None
     try:
         file = open(self.filename, 'r')
         r = RExec()
         r.update_global_names(self._context)
         dict = r.r_eval(file.read())
     finally:
         if file: file.close()
         self._lock.release()
     return dict
class TestCase(DefaultTestFixture):
    def _setUp(self):
        warnings.resetwarnings()
        self.rexec = RExec()
        return
    def _tearDown(self):
        if hasattr(self, 'rexec'):
            del self.rexec
        return
    def setUp(self):
        DefaultTestFixture.setUp(self)
        self._setUp()
        return
    def tearDown(self):
        try:
            self._tearDown()
        finally:
            DefaultTestFixture.tearDown(self)
        return
    def test_create(self):
        return
    def test_simple_reval(self):
        result = self.rexec.r_eval('1 + 1')
        if result != 2:
            raise 'Failed simple r_eval.'
        return
    def test_ok_python_imports(self):
        self._tearDown()
        for m in ('audioop', 'array', 'binascii', 'cmath', 'errno', 'imageop',
                  'marshal', 'math', 'md5', 'operator', 'parser', 're',
                  'select', 'strop', 'struct', 'time',
                  'marshal', '__builtin__', '__main__', 'sys', 'posix',
                  ):
            self._setUp()
            warnings.filterwarnings("ignore", '.*', DeprecationWarning)
            self.rexec.r_exec('import %s' % m)
    def test_scary_python_imports(self):
        self._tearDown()
        for m in ('socket', 'msglog', 'signal', 'SocketServer', 'mmap'):
            self._setUp()
            try: self.rexec.r_exec('import %s' % m)
            except ImportError: pass
            else: raise 'Failed to recognize a dangerous module: %s' % m
Beispiel #4
0
def _unpackage_dict(dict):
    r = RExec()
    for key in dict.keys():
        dict[key] = r.r_eval(dict[key])
    return dict
Beispiel #5
0
class TestCase(DefaultTestFixture):
    def _setUp(self):
        warnings.resetwarnings()
        self.rexec = RExec()
        return

    def _tearDown(self):
        if hasattr(self, 'rexec'):
            del self.rexec
        return

    def setUp(self):
        DefaultTestFixture.setUp(self)
        self._setUp()
        return

    def tearDown(self):
        try:
            self._tearDown()
        finally:
            DefaultTestFixture.tearDown(self)
        return

    def test_create(self):
        return

    def test_simple_reval(self):
        result = self.rexec.r_eval('1 + 1')
        if result != 2:
            raise 'Failed simple r_eval.'
        return

    def test_ok_python_imports(self):
        self._tearDown()
        for m in (
                'audioop',
                'array',
                'binascii',
                'cmath',
                'errno',
                'imageop',
                'marshal',
                'math',
                'md5',
                'operator',
                'parser',
                're',
                'select',
                'strop',
                'struct',
                'time',
                'marshal',
                '__builtin__',
                '__main__',
                'sys',
                'posix',
        ):
            self._setUp()
            warnings.filterwarnings("ignore", '.*', DeprecationWarning)
            self.rexec.r_exec('import %s' % m)

    def test_scary_python_imports(self):
        self._tearDown()
        for m in ('socket', 'msglog', 'signal', 'SocketServer', 'mmap'):
            self._setUp()
            try:
                self.rexec.r_exec('import %s' % m)
            except ImportError:
                pass
            else:
                raise 'Failed to recognize a dangerous module: %s' % m
Beispiel #6
0
def _unpackage_dict(dict, context):
    r = RExec()
    r.update_global_names(context)
    for key in dict.keys():
        dict[key] = r.r_eval(dict[key])
    return dict
Beispiel #7
0
def _unpackage_dict(dict, context):
    r = RExec()
    r.update_global_names(context)
    for key in dict.keys():
        dict[key] = r.r_eval(dict[key])
    return dict