def get(self): response = Response() cookie = self.session_store.get_secure_cookie('test') or {} res = cookie.get('test') if not res: res = 'undefined' self.session_store.set_secure_cookie(response, 'test', {'test': 'a secure cookie value'}) response.data = res return response
def get(self): response = Response() cookie = self.session_store.get_secure_cookie('test') or {} res = cookie.get('test') if not res: res = 'undefined' self.session_store.set_secure_cookie( response, 'test', {'test': 'a secure cookie value'}) response.data = res return response
def get(self): id = int(self.request.args.get('id')) if not id: return Response('no id') doc = Document.get_by_id(id) if not doc: return Response('no doc found') r = Response(doc.file) r.headers['Content-Type'] = 'binary/octet-stream' r.headers['Content-Disposition'] = 'attachment; filename=%s;' % doc.file_name return r
def post(self): devtime = DevTime() devtime.date = datetime.now() devtime.topics = ['Python', 'tipfy'] devtime.put() return Response('Done.')
def get(self): res = [msg for msg, level in self.session.get_flashes()] if not res: res = [{'body': 'undefined'}] self.session.flash({'body': 'a flash value'}) return Response(res[0]['body'])
def get(self): res = self.request.cookies.get('test') if not res: res = 'undefined' self.session_store.set_cookie('test', 'a cookie value') self.session_store.unset_cookie('test') return Response(res)
def get(self): session = self.session_store.get_session(backend='datastore') res = session.get('test') if not res: res = 'undefined' session['test'] = 'a datastore session value' return Response(res)
def get(self): res = self.session.get('key') if not res: res = 'undefined' session = SecureCookieSession() session['key'] = 'a session value' self.session_store.set_session( self.session_store.config['cookie_name'], session) return Response(res)
def post(self): logging.error(dir(self.auth)) if not self.auth.user: return Response('Error: authenticate first') place_key_name = self.request.form.get('place_key_name') l = Location.all().filter('osm =', place_key_name).fetch(1) if not l: l = Location(osm = place_key_name) l.put() else: l = l[0] c = Checkin(user=self.auth.user, location=l) osmpoi = OSMPOI.get_by_key_name(place_key_name) place_name = osmpoi.name if place_name: c.place_name = place_name else: c.place_key_name = osmpoi.key().name() c.user_name = self.auth.user.username c.put() return Response('Success %s, %s' % (self.auth.user, place_key_name) )
def get(self): session = self.session_store.get_session(backend='datastore') res = session.get('key') if not res: res = 'undefined' session = DatastoreSession(None, 'a_random_session_id') session['key'] = 'a session value' self.session_store.set_session( self.session_store.config['cookie_name'], session, backend='datastore') return Response(res)
def test_set_cookie_encoded(self): with self._get_app().get_test_context() as request: store = request.session_store store.set_cookie('foo', 'bar', format='json') store.set_cookie('baz', 'ding', format='json') response = Response() store.save(response) headers = {'Cookie': '\n'.join(response.headers.getlist('Set-Cookie'))} with self._get_app().get_test_context('/', headers=headers) as request: store = request.session_store self.assertEqual(json_b64decode(request.cookies.get('foo')), 'bar') self.assertEqual(json_b64decode(request.cookies.get('baz')), 'ding')
def test_get_save_session(self): with self._get_app().get_test_context() as request: store = request.session_store session = store.get_session() self.assertEqual(isinstance(session, SecureCookieSession), True) self.assertEqual(session, {}) session['foo'] = 'bar' response = Response() store.save(response) with self._get_app().get_test_context( '/', headers={ 'Cookie': '\n'.join(response.headers.getlist('Set-Cookie')) }) as request: store = request.session_store session = store.get_session() self.assertEqual(isinstance(session, SecureCookieSession), True) self.assertEqual(session, {'foo': 'bar'})
def test_set_delete_cookie(self): with self._get_app().get_test_context() as request: store = request.session_store store.set_cookie('foo', 'bar') store.set_cookie('baz', 'ding') response = Response() store.save(response) headers = {'Cookie': '\n'.join(response.headers.getlist('Set-Cookie'))} with self._get_app().get_test_context('/', headers=headers) as request: store = request.session_store self.assertEqual(request.cookies.get('foo'), 'bar') self.assertEqual(request.cookies.get('baz'), 'ding') store.delete_cookie('foo') store.save(response) headers = {'Cookie': '\n'.join(response.headers.getlist('Set-Cookie'))} with self._get_app().get_test_context('/', headers=headers) as request: self.assertEqual(request.cookies.get('foo', None), '') self.assertEqual(request.cookies['baz'], 'ding')
def get(self): self.set_message('success', 'a normal message value') self.set_message('success', 'a flash message value', flash=True) return Response('|'.join(msg['body'] for msg in self.messages))
def get(self): response = Response(js.get_js(minify=False)) response.headers['Content-Type'] = 'text/javascript' return response
def get(self): """Simply returns a Response object with an enigmatic salutation.""" return Response('Hello, World!')
def get(self): return Response('OK')
logging.getLogger().setLevel(logging.DEBUG) if '_' in kwargs: # Browser caching buster del kwargs['_'] try: response_obj = func(self, **kwargs) except Error, err: response_obj = { 'rc': err.value, 'msg': err.message } except AssertionError, err: logging.exception(method) response_obj = { 'rc': 2, 'msg': 'Assert failed: %s' % (err.args[0] if err.args else '') } else: if response_obj is None: response_obj = {} if 'rc' not in response_obj: response_obj['rc'] = 0 response = Response( json.json_encode(response_obj) ) response.headers['content-type'] = 'application/json' return response
def get(self): response = Response(js.get_constants()) response.headers['Content-Type'] = 'text/javascript' return response
def get(self, **kwargs): locale = self.i18n.locale return Response(locale)