def __init__(self, request=None, response=None, mc=None, ignore_trailing_slash=True): RequestHandler.__init__(self, request, response) self.ignore_trailing_slash = ignore_trailing_slash self.log = logging.getLogger(self.__class__.__name__) if mc == None: raise "No Memcache Client provided" else: self.mc = mc
def dispatch(self): self.session_store = sessions.get_store(factory=sessions.SessionStore, key='webapp2_extras.sessions.SessionStore', request=self.request) self.session_flash = sessions.get_store(factory=sessions.SessionDict, key='webapp2_extras.sessions.SessionDict', request=self.request) try: RequestHandler.dispatch(self) finally: self.session_store.save_sessions(self.response)
def dispatch(self): self.session_store = sessions.get_store(request=self.request) if not self.session.get('user'): self.redirect(self.app_url('/login')) self.user = db.get( db.Key(session['user']) ) try: RequestHandler.dispatch(self) finally: self.session_store.save_sessions(self.response)
def dispatch(self): # Get a session store for this request. self.session_store = sessions.get_store(request=self.request) try: # Dispatch the request. RequestHandler.dispatch(self) finally: # Save all sessions. self.session_store.save_sessions(self.response)
def dispatch(self): self.session_store = sessions.get_store(request=self.request) if not self.session.get("user"): self.redirect(self.app_url("/login")) self.user = db.get(db.Key(session["user"])) try: RequestHandler.dispatch(self) finally: self.session_store.save_sessions(self.response)
def dispatch(self): self.session_store = sessions.get_store(request=self.request) try: RequestHandler.dispatch(self) except Exception as error: postArgs = dict(self.request.POST) if POST_USER_PASSWORD in postArgs: postArgs.pop(POST_USER_PASSWORD) logging.error("Unhandled error "+str(type(error))+" "+str(error)+" "+error.message+" "+str(postArgs)) self.response.write(RESPONSE_UNHANDLED_ERROR) finally: self.session_store.save_sessions(self.response)
def test_request_handler_get_config(self): app = WSGIApplication() handler = RequestHandler(app, None, None) assert handler.get_config('resources.i18n', 'locale') == 'en_US' assert handler.get_config('resources.i18n', 'locale', 'foo') == 'en_US' assert handler.get_config('resources.i18n') == { 'locale': 'en_US', 'timezone': 'America/Chicago', 'required': REQUIRED_VALUE, }
def dispatch(self): # Get a session store for this request. # See this for more info on webapp2 sessions: # http://webapp-improved.appspot.com/api/webapp2_extras/sessions.html self.session_store = sessions.get_store(request=self.request) i18n.get_i18n().set_locale('en') try: # Dispatch the request. RequestHandler.dispatch(self) finally: # Save all sessions. self.session_store.save_sessions(self.response)
def initialize(self, *args, **kwargs): RequestHandler.initialize(self, *args, **kwargs) uid = self.read_secure_cookie('user_id') self.user = uid and User.by_id(int(uid)) self.url = self.request.route_args[0] if len(self.request.route_args) > 0 else '/' v = self.request.get('v') if v and v.isdigit(): self.v = int(v) p = Page.by_id(int(self.v), self.url) if p: self.page = p else: self.error(404) else: self.page = Page.by_url(self.url)
def dispatch(self): self.session_store = sessions.get_store(request=self.request) try: RequestHandler.dispatch(self) except: import traceback logging.error(traceback.format_exc()) d = dict(stacktrace=traceback.format_exc(), req=self.request) self.render_response('error/general.html', d) finally: self.session_store.save_sessions(self.response) if 'User-Agent' in self.request.headers and 'msie' in self.request.headers['User-Agent'].lower(): self.response.headers['X-UA-Compatible'] = 'IE=edge,chrome=1'
def dispatch(self): """ Dispatches the request after grabbing the ``session_store`` and providing access to the current `webapp2.Request`_ 's session. This will first check if there's a handler_method defined in the matched route, and if not it'll use the method correspondent to the request method (``get()``, ``post()`` etc). """ # Get a session store for this request. self.session_store = sessions.get_store(factory=SessionStore, request=self.request) try: # Dispatch the request. RequestHandler.dispatch(self) finally: # Save all sessions. self.session_store.save_sessions(self.response)
def dispatch(self): # memories of bobo traverse name = self.request.path_info_pop() if name: if name.endswith('.png') and self.Form.hasImageField(name[:-4]): return self.getImage(self.wobObj, name[:-4]) else: return self.traverseTo(name) return RequestHandler.dispatch(self)
def dispatch(self): self.session_store = sessions.get_store(request=self.request) try: RequestHandler.dispatch(self) except UnicodeDecodeError: logging.warning("Username with bad characters") self.response.write(RESPONSE_USER_BAD_USERNAME) except Exception as error: try: postArgs = dict(self.request.POST) if POST_USER_PASSWORD in postArgs: postArgs.pop(POST_USER_PASSWORD) logging.error( "Unhandled error \n" + traceback.format_exc() + str(postArgs)) except Exception: logging.error("Unhandled error, unprintable POST args \n" + traceback.format_exc()) self.response.write(RESPONSE_UNHANDLED_ERROR) finally: self.session_store.save_sessions(self.response)
def initialize(self, *a, **kw): RequestHandler.initialize(self, *a, **kw) if self.request.url.endswith('.json'): self.format = 'json' else: self.format = 'html'
def __init__(self, request, response, wobObj=None): RequestHandler.__init__(self, request, response) self.wobObj = wobObj
def __init__(self, request, response): RequestHandler.initialize(self, request, response) self.fd = self.request.POST self.vessel = Vessel(parent=Owner.get_key()) self.valid = True
def dispatch(self): self.session_store = sessions.get_store(request=self.request) try: RequestHandler.dispatch(self) finally: self.session_store.save_sessions(self.response)
def build_uri(handler, key_id): return RequestHandler.uri_for(handler, 'workflow', _full=True) + "?id=" + str(key_id)
def dispatch(self): RequestHandler.dispatch(self) self.response.headers['SessionMock'] = json.dumps(self.session)
def __init__(self, request, response): RequestHandler.initialize(self, request, response) self.fd = self.request.POST self.err = {}
def initialize(self, *a, **kw): #runs on every request and checks if user is logged in RequestHandler.initialize(self, *a, **kw) sid = self.read_secure_cookie('student_id') self.student = sid and Student_by_id(int(sid))
def dispatch(self): self.session_store = get_store(request=self.request) try: RequestHandler.dispatch(self) finally: self.session_store.save_sessions(self.response)
def __init__(self, request=None, response=None): RequestHandler.__init__(self, request, response) # Retrieve user by his cookie self.user = User.get_by_cookie(self.request.cookies.get("uid"))
def initialize(self, *a, **kw): RequestHandler.initialize(self, *a, **kw) uid = self.read_secure_cookie('user_id') self.user = uid and User.by_id(int(uid))