Пример #1
0
from sandbox import Sandbox
from sandbox.config import SandboxConfig
config = SandboxConfig('stderr','stdout','interpreter')
config.enable('regex')
config.enable('time')
config.enable('datetime')
config.enable('math')
config.enable('random')
items = ['urllib2','urllib','struct','base64','httplib','socket','_socket']
for item in items: config.allowModule(item)
config.allowModule('httplib')
config.allowModule('array','array')
config.allowModule('StringIO', 'StringIO')
config.allowModule('os','_get_exports_list')
config.allowModule('json','scanner','decoder')

config.recursion_limit = 3000
sandbox = Sandbox(config)

import pickle


f = open('/tmp/data')
code, locals_dict = pickle.load(f)
f.close()

sandbox.execute(code, locals=locals_dict)
Пример #2
0
from celery import task
from ticker.models import *

from sandbox import Sandbox
from sandbox.config import SandboxConfig
config = SandboxConfig('stdout')
config.enable('regex')
config.enable('time')
config.enable('datetime')
config.enable('math')
config.enable('random')

import re
import pickle, os
@task()
def runcode(id, locals_dict={}, debug=False, follow_links=True):
    print locals_dict
    for k,v in locals_dict.items():
        print type(v)
    node = Node.objects.get(id=id)
    if node == None: raise Exception("Node not found")
    
    code = node.code.encode('ascii').replace("\r","")
    
    print "Running node %s"%node.title
    
    
    if os.path.exists(os.path.join('/home/oyvinbak/python/django_ticker/ticker/nodes', code)):
        path = os.path.join('/home/oyvinbak/python/django_ticker/ticker/nodes', code)
        print path
        f = open(path)