本文整理汇总了Python中util.sessions.Session类的典型用法代码示例。如果您正苦于以下问题:Python Session类的具体用法?Python Session怎么用?Python Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VigenereHandler
class VigenereHandler(webapp.RequestHandler):
def post(self):
self.session=Session()
mode = self.session.get("mode")
msg=self.session.get("msg")
txtinput = self.request.get('method')
if (txtinput=='v'):
txtinput="You have chosen Vigenere cipher. Your mode is " + mode +" and your message is " + msg +". Please enter a string of letters to use as a key(ex: vkey-ELFMENG)"
elif (txtinput == 'key'):
key=self.request.get("keystr")
vig = vigenere.VigenereCipherTool(mode,msg)
vig.storekey(key)
translated=vig.getTranslatedMessage()
txtinput="Your translated message is " + translated
array = {'text': txtinput}
# Output the JSON
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps(array))
示例2: SubstitutionHandler
class SubstitutionHandler(webapp.RequestHandler):
def post(self):
self.session=Session()
mode = self.session.get("mode")
msg=self.session.get("msg")
txtinput = self.request.get('method')
if (txtinput=='s'):
txtinput="You have chosen Substitution. Your mode is " + mode +" and your message is " + msg +". Please enter the 26-letter string of characters to use as a key (ex skey-QWERTYUIOPASDFGHJKLZXCVBNM)"
elif (txtinput == 'key'):
key=str(self.request.get("keystr"))
subs = substitution.SubstitutionCipherTool(mode,msg)
if (subs.checkValidKey(key) != True):
txtinput="The key you entered is not valid. Please re-enter the 26-letter string of characters to use as a key (ex skey-QWERTYUIOPASDFGHJKLZXCVBNM)"
else:
subs.storekey(key)
translated=subs.getTranslatedMessage()
txtinput="Your translated message is " + translated
array = {'text': txtinput}
# Output the JSON
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps(array))
示例3: MainHandler
class MainHandler(webapp.RequestHandler):
def get (self):
#filepath = self.request.path
self.session = Session()
loggedUser=""
greeting=""
if (self.session.get('username')):
greeting="Welcome, "
loggedUser = self.session.get('username')
if (self.session.get('role') == 'teacher'):
temp = os.path.join(os.path.dirname(__file__), 'templates/teachermain.html')
#self.response.out.write(temp)
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write(str(template.render(temp,{'loggedUser':loggedUser, "greeting":greeting})))
elif (self.session.get('role') == 'student'):
temp = os.path.join(os.path.dirname(__file__), 'templates/studentmain.html')
#self.response.out.write(temp)
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write(str(template.render(temp,{'loggedUser':loggedUser, "greeting":greeting})))
else:
temp = os.path.join(os.path.dirname(__file__), 'templates/main.html')
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write(str(template.render(temp,{'loggedUser':loggedUser, "greeting":greeting})))
示例4: LoginHandler
class LoginHandler(webapp.RequestHandler):
def get(self):
doRender(self, "loginscreen.htm")
def post(self):
self.session = Session()
acct = self.request.get("account")
pw = self.request.get("password")
logging.info("Checking account=" + acct + " pw=" + pw)
self.session.delete_item("username")
self.session.delete_item("userkey")
if pw == "" or acct == "":
doRender(self, "loginscreen.htm", {"error": "Please specify Account and Password"})
return
que = db.Query(User)
que = que.filter("account =", acct)
que = que.filter("password = ", pw)
results = que.fetch(limit=1)
if len(results) > 0:
user = results[0]
self.session["userkey"] = user.key()
self.session["username"] = acct
doRender(self, "index.htm", {})
else:
doRender(self, "loginscreen.htm", {"error": "Incorrect password"})
示例5: CaesarHandler
class CaesarHandler(webapp.RequestHandler):
def post(self):
self.session=Session()
mode = self.session.get("mode")
msg=self.session.get("msg")
txtinput = self.request.get('method')
if (txtinput=='c'):
txtinput="You have chosen Caesar cipher. Your mode is " + mode +" and your message is " + msg +". Please enter key size(1-26) as key-{key size} (ex ckey-22)"
elif (txtinput == 'key'):
key=self.request.get("keynum")
caes = caesar.CaesarCipherTool(mode,msg)
#get key
if(int(key) >= 1 and int(key) <= 26):
txtinput="Your key is " + key
caes.storekey(key)
txtinput="Your translated message: " + caes.getTranslatedMessage() + ". Please type tb for toolbox, h for help"
else:
txtinput="Your key is not valid it must be in range (1 <= key <= 26). Please try again. key-{key size} (ex ckey-22)" + key
array = {'text': txtinput}
# Output the JSON
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps(array))
示例6: CaesarHandler
class CaesarHandler(webapp.RequestHandler):
def post(self):
self.session=Session()
mode = self.session.get("mode")
msg=self.session.get("msg")
txtinput = self.request.get('method')
if (txtinput=='c'):
txtinput="You have chosen Caesar cipher. Your mode is " + mode +" and your message is " + msg +". Please enter key size(1-26) as key-{key size} (ex ckey-22)"
elif (txtinput == 'key'):
key=self.request.get("keynum")
caes = caesar.CaesarCipherTool(mode,msg)
#get key
if(int(key) >= 1 and int(key) <= 26):
txtinput="Your key is " + key
caes.storekey(key)
txtinput="Your translated message: " + caes.getTranslatedMessage() + ". Please type tb for toolbox, h for help"
else:
txtinput="Your key is not valid it must be in range (1 <= key <= 26). Please try again. key-{key size} (ex ckey-22)" + key
else:
txtinput="Error, invalid command! Please type again. Please select which cipher you would like to use - Caesar cipher(c), Substitution cipher(s), Transposition cipher(t), Vigenere cipher(v), or Affine cipher(a). Please type \"use-cipher method\"(ex - use-s)"
array = {'text': txtinput}
# Output the JSON
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps(array))
示例7: LogoutHandler
class LogoutHandler(webapp.RequestHandler):
def get(self):
self.session = Session()
self.session.delete_item('username')
self.session.delete_item('userkey')
doRender(self, 'index.htm')
示例8: ShowUserHandler
class ShowUserHandler(webapp.RequestHandler):
def get(self):
self.session = Session()
pkey = self.session.get('userkey')
current_user = db.get(pkey)
if current_user.admin == "True":
doRender(self, 'show_user.html', { })
else:
doRender(self, 'main.html', {'msg' : 'Require admin previlege!'})
def post(self):
self.session = Session()
pkey = self.session.get('userkey')
current_user = db.get(pkey)
if current_user.admin == "False":
doRender(self, 'main.html', {'msg' : 'Require admin previlege!'})
return
que = db.Query(User)
if self.request.get('show_admin') == 'True': # if this will show admin
admin = que.filter('admin =', 'True')
admin = admin.fetch(limit = 100)
doRender(self, 'show_user.html', {'user_list' : admin } )
return
else:
user = que.filter('admin =', 'False')
user = user.fetch(limit = 500)
doRender(self, 'show_user.html', {'user_list' : user } )
return
示例9: SubstitutionHandler
class SubstitutionHandler(webapp.RequestHandler):
def post(self):
self.session=Session()
mode = self.session.get("mode")
msg=self.session.get("msg")
txtinput = self.request.get('method')
if (txtinput=='s'):
txtinput="You have chosen Substitution. Your mode is " + mode +" and your message is " + msg +". Please enter the 26-letter string of characters to use as a key (ex skey-QWERTYUIOPASDFGHJKLZXCVBNM)"
elif (txtinput == 'key'):
key=str(self.request.get("keystr"))
subs = substitution.SubstitutionCipherTool(mode,msg)
if (subs.checkValidKey(key) != True):
txtinput="The key you entered is not valid. Please re-enter the 26-letter string of characters to use as a key (ex skey-QWERTYUIOPASDFGHJKLZXCVBNM)"
else:
subs.storekey(key)
translated=subs.getTranslatedMessage()
txtinput="Your translated message is " + translated
else:
txtinput="Error, invalid command! Please type again. Please select which cipher you would like to use - Caesar cipher(c), Substitution cipher(s), Transposition cipher(t), Vigenere cipher(v), or Affine cipher(a). Please type \"use-cipher method\"(ex - use-s)"
array = {'text': txtinput}
# Output the JSON
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps(array))
示例10: VigenereHandler
class VigenereHandler(webapp.RequestHandler):
def post(self):
self.session=Session()
mode = self.session.get("mode")
msg=self.session.get("msg")
txtinput = self.request.get('method')
if (txtinput=='v'):
txtinput="You have chosen Vigenere cipher. Your mode is " + mode +" and your message is " + msg +". Please enter a string of letters to use as a key(ex: vkey-ELFMENG)"
elif (txtinput == 'key'):
key=self.request.get("keystr")
vig = vigenere.VigenereCipherTool(mode,msg)
vig.storekey(key)
translated=vig.getTranslatedMessage()
txtinput="Your translated message is " + translated
else:
txtinput="Error, invalid command! Please type again. Please select which cipher you would like to use - Caesar cipher(c), Substitution cipher(s), Transposition cipher(t), Vigenere cipher(v), or Affine cipher(a). Please type \"use-cipher method\"(ex - use-s)"
array = {'text': txtinput}
# Output the JSON
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps(array))
示例11: LogoutHandler
class LogoutHandler(webapp.RequestHandler):
def get(self):
self.session = Session()
un = self.session.get('username')
self.session.delete_item('username')
self.session.delete_item('userkey')
doRender(self, 'index.html', {'msg' : un + ' logout successful.'} )
示例12: LoginHandler
class LoginHandler(webapp.RequestHandler):
def get(self):
doRender(self, 'loginscreen.htm')
def post(self):
self.session = Session()
acct = self.request.get('account')
pw = self.request.get('password')
logging.info('Checking account='+acct+' pw='+pw)
self.session.delete_item('username')
if pw == '' or acct == '':
doRender(
self,
'loginscreen.htm',
{'error' : 'Please specify Account and Password'} )
return
que = db.Query(User)
que = que.filter('account =',acct)
que = que.filter('password = ',pw)
results = que.fetch(limit=1)
if len(results) > 0 :
self.session['username'] = acct
doRender(self,'index.htm',{ } )
else:
doRender(
self,
'loginscreen.htm',
{'error' : 'Incorrect password'} )
示例13: LogOutHandler
class LogOutHandler(webapp.RequestHandler):
def get(self):
self.session = Session()
self.session.delete_item('user')
self.redirect('main.html')
示例14: TDSettingHandler
class TDSettingHandler(BaseHandler):
def get(self):
if self.guest():
return
self.session = Session()
key = self.session.get('userkey')
user = db.get(key)
form = UserForm()
self.doRender( 'td_setting.html', {'form': form, 'u': user, \
'info': ', please update your profile'})
def post(self):
self.session = Session()
pkey = self.session.get('userkey')
user = db.get(pkey)
form = UserForm(self.request.POST)
if form.validate():
user.cwid = form.cwid.data
user.major = form.major.data
user.email = form.email.data
user.phone = form.phone.data
user.d_hours = form.d_hours.data
user.put()
self.doRender( 'td_setting.html', {'msg' : ', profile updated', 'u': user} )
else: # form validation failed
self.doRender('td_setting.html', {'form': form})
示例15: logout
class logout(webapp.RequestHandler):
def get(self):
self.session = Session()
self.session.delete_item('username')
render(self,"logout.html")
def post(self):
render()