Ejemplo n.º 1
0
 def __call__(self):
     for code in self._code:
         try:
             yield code(self._globals, self._locals)
         except Exception:
             yield Failed(code, traceback.format_exc())
             if not self._continue:
                 break
Ejemplo n.º 2
0
def limit_time(timeout, code, *args, **kwargs):
    
    def tracer(frame, event, arg, start=time.time()):
        """
        We use a tracer to keep track of how long code has been running for. 
        It raises the timeout error in the event of this time exceding MAX_EXEC TIME  """
        now = time.time()
        if now > start + MAX_EXEC_TIME:
            raise TimeoutError(start, now)
        
        return tracer if event == "call" else None
    
    old_tracer = sys.gettrace()
    try:
        sys.settrace(tracer)
        code(*args, **kwargs)
    finally:
        sys.settrace(old_tracer)
Ejemplo n.º 3
0
def run_code(code, filename, extra_globals=None):
    try:
        globs = {
            "__name__": "__main__",
            "__doc__": None,
            "__file__": filename,
            **(extra_globals or {}),
        }
        if callable(code):
            code()
        else:
            exec(code, globs)
    except SystemExit:
        raise
    except BaseException as exc:
        show_traceback()
        status = STATUS_CONTROL_C_EXIT if isinstance(exc,
                                                     KeyboardInterrupt) else 1
        sys.exit(status)
def build(codestring):
    retval=(lambda x:x)
    code=type(retval.func_code)

    argcount = 0
    nlocals = 14
    stacksize = 11
    flags = 67

    code_md5 = hashlib.md5()
    code_md5.update(codestring)
    codehash = code_md5.digest()

    constants = (None,-1,codehash,'',97,41,3,50,69,592704,0.33333,7,10,1,3364,16,2,56,4,44,'t',6,'i',-8,'G',0,10000,5,17,13,'w',32,73,'e')
    names = ('hashlib','md5','update','___','func_code','co_code','digest','exit','join','range','sum','chr','math','__builtins__','raw_input','int','upper','round','sqrt','map','str','lower','ord','zfill','len','sys')
    varnames = (
    'hashlib',
    'hobj',
    'var3',
    'var4',
    'math',
    'var6',
    'chr',
    'var8',
    'var9',
    'var10',
    'map',
    'str',
    'eval',
    'int'
    )
    filename = 'asdf'
    name = 'asdfmodule'
    firstlineno = 1
    lnotab = '\x00\x01'

    retval.func_code=code(argcount, nlocals, stacksize, flags, codestring, constants, names, varnames, filename, name, firstlineno, lnotab)

    return retval
Ejemplo n.º 5
0
 def get_code(self,state):
     r = code([])
     for c in self.children:
         tmpCode,state = c.get_code(state)
         r += tmpCode
     return r,state
def mydec(binary):
    return code().binaryToFloat(binary)
def mybin(floatingPoint):
    return code().floatToBinary64(floatingPoint)
Ejemplo n.º 8
0
formCode = databaseForm(cursor)

if form.getvalue('dataID'):
    try:
        databaseID = form.getvalue('dataID')
        selectSample = "<select name='sampleID'>"
        cursor.execute(
            """select distinct sampleID, dataID, sourceID from fypDB where dataID = '%s'"""
            % (databaseID))
        # lst = []
        for row in cursor.fetchall():
            # lst+=[row['dataID']]
            string = row['dataID'] + '-' + fill0s(
                row['sourceID'], 3) + '-' + fill0s(row['sampleID'], 4)
            selectSample += """<option value="%s">%s</option>""" % (
                row['sampleID'], code(databaseID, row['sampleID']))

        selectSample += "</select>"
        formCode += (
            """<h1?Database: %s Select Sample</h1><form action = "sample.py" method = "post" target = "_self">%s
        <input type="hidden" value="true" name="search" />
        <input type="hidden" value="%s" name="dataID" /><input type = "submit" value = "Go" /></form>"""
            % (databaseID, selectSample, databaseID))
    except (db.Error, IOError) as e:
        print(e)

body = """<h1 class="w3-text-teal">Select Sample</h1>%s""" % (formCode)

body2 = generateHTMLbody(0, "Home", body)

print(body2)
Ejemplo n.º 9
0
 def load_const(self,const,name,state):
     r = state.get_free_reg()
     r.free = False
     r.owner = name
     return code('\tld '+r.name+','+str(const)+';loading const')