def _get(self, *args, **kwargs): categorydocs = yield motor.Op(self.get_categories) self.categories = categories = [Category(**doc) for doc in categorydocs] postdocs = yield motor.Op(self.get_posts, *args, **kwargs) self.posts = posts = [ Post(**doc) if doc else None for doc in postdocs] mod = max( thing.last_modified for things in (posts, categories) for thing in things if thing) if mod: # If-Modified-Since header is only good to the second. Truncate # our own mod-date to match its precision. mod = mod.replace(microsecond=0) self.set_header('Last-Modified', mod) # Adapted from StaticFileHandler ims_value = self.request.headers.get("If-Modified-Since") if ims_value is not None: date_tuple = email.utils.parsedate(ims_value) if_since = models.utc_tz.localize( datetime.datetime.fromtimestamp(time.mktime(date_tuple))) if if_since >= mod: # No change since client's last request. Tornado will take # care of the rest. self.set_status(304) self.finish() return gen.engine(get)(self, *args, **kwargs)
def _get(self, *args, **kwargs): categorydocs = yield motor.Op(self.get_categories) self.categories = categories = [Category(**doc) for doc in categorydocs] postdocs = yield motor.Op(self.get_posts, *args, **kwargs) self.posts = posts = [ Post(**doc) if doc else None for doc in postdocs] if posts or categories: mod = max( thing.last_modified for things in (posts, categories) for thing in things if thing) # If-Modified-Since header is only good to the second. Truncate # our own mod-date to match its precision. mod = mod.replace(microsecond=0) self.set_header('Last-Modified', mod) # Adapted from StaticFileHandler ims_value = self.request.headers.get("If-Modified-Since") if ims_value is not None: date_tuple = email.utils.parsedate(ims_value) if_since = models.utc_tz.localize( datetime.datetime.fromtimestamp(time.mktime(date_tuple))) if if_since >= mod: # No change since client's last request. Tornado will take # care of the rest. self.set_status(304) self.finish() return gen.engine(get)(self, *args, **kwargs)
def wrapper(self, *args, **kwargs): bound_f = partial(gen.engine(f), self, *args, **kwargs) self.io_loop.add_callback(stack_context.wrap(bound_f)) if timeout: self.wait(timeout=timeout) else: self.wait()
def start_test(): gen.engine(func)(self, done)
def _r_e_l_a_x_(*args, **kwargs): return gen.engine(_func_)(*args, **kwargs)
def engine(f): """Like gen.engine, but copy method signature """ return superwraps(f)(gen.engine(f))
def wrapper(*args, **kwargs): engine(fn)(*args, **kwargs) IOLoop.instance().start()