示例#1
0
    def HandlePython(self, request, response, filename, files):
        oldctxt = bluepy.PushTimer('HTTP::Handle::Pages')
        try:
            response.header['Expires'] = '0'
            response.header['Cache-Control'] = 'private, no-cache'
            if request.method == 'HEAD':
                log.LogInfo('Got a HEAD request, not executing script...')
            else:
                modified = max([ os.stat(fullpath).st_mtime for fullpath, f in files ])
                if filename not in self.codeCache or modified > self.codeCache[filename][0]:
                    with bluepy.Timer('HTTP::Handle::ExecFile::' + filename):
                        import __builtin__
                        glob = {'__builtins__': __builtin__}
                        for fn, f in files:
                            data = f.read().replace('\r\n', '\n')
                            f.close()
                            code = compile(data, fn, 'exec', 0, True)
                            exec code in glob

                        self.codeCache[filename] = (modified, glob)
                else:
                    glob = self.codeCache[filename][1]
                sess = request.session
                masque = sess.Masquerade()
                if not session.userid and macho.mode != 'client':
                    raise RuntimeError('\n                        **********************************************************************\n                        * SESSION IS BROKED, HAS NO USERID. RESTART YOUR SERVER PAGE BROWSER *\n                        **********************************************************************\n                    ')
                try:
                    ClockThis('HTTP::Handle::Pages::' + request.path, glob['Execute'], request, response, sess)
                finally:
                    masque.UnMask()

        finally:
            bluepy.PopTimer(oldctxt)
示例#2
0
def PushMark(context):
    return bluepy.PushTimer(context)
示例#3
0
def PushMark(context):
    """
    PushMark(context) -> None
    Sets a context string to the current execution. Complement with PopMark plz.
    """
    return bluepy.PushTimer(context)
示例#4
0
 def Wrapper(*args, **kwds):
     t = bluepy.PushTimer(timer)
     try:
         return func(*args, **kwds)
     finally:
         bluepy.PopTimer(t)