def next(cls, remove=True): u""" The <code>next</code> method answers the next task instance that needs to be executed. The method takes the top of the sorted list of task files from the <code>cls.PATH_SCHEDULERTASKS</code> and creates the <code>Task</code> instance and then deletes the task file (if the optional attribute <attr>remove</attr> has default value <code>True</code>. This method is also called by <code>self.peek()</code>, but then the file is not removed. """ tasknames = cls.getTaskNames() if not tasknames: return None task = None try: for taskname in tasknames: if taskname.startswith('.'): continue path = cls.PATH_SCHEDULERTASKS + '/' + taskname f = open(path, 'rb') code = f.read() f.close() d = cjson.decode(code) task = cls(**d) if remove: os.remove(path) break # Just get the top of the task file list except TypeError: print '### Error in json code:', code except Exception as e: print '### unknown error in task:', e return task
def getCookies(self): u""" The <code>getCookies</code> method answers the cookies dictionary of the current request. The default behavior is to answer <code>self.request.received_cookies</code>. """ import urllib result = {} for k, v in self.request.received_cookies.items(): try: result[k] = cjson.decode(urllib.unquote(v)) except: result[k] = v return result
def _asJson(self): u""" Convert self to an object of standard Python instances, so it can be dumped by JSON. """ return cjson.decode(self._asObject(self))