本文整理汇总了Python中util.sessions.Session类的典型用法代码示例。如果您正苦于以下问题:Python Session类的具体用法?Python Session怎么用?Python Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:jancybsec,项目名称:ciphersleuth,代码行数:25,代码来源:main.py
示例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))
开发者ID:jancybsec,项目名称:ciphersleuth,代码行数:27,代码来源:main.py
示例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})))
开发者ID:geekyjulie,项目名称:ciphersleuth,代码行数:35,代码来源:main.py
示例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"})
开发者ID:jacobcr,项目名称:G4Btools,代码行数:30,代码来源:index.py
示例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))
开发者ID:jancybsec,项目名称:ciphersleuth,代码行数:29,代码来源:main.py
示例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))
开发者ID:geekyjulie,项目名称:ciphersleuth,代码行数:32,代码来源:main.py
示例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')
开发者ID:i3enhamin,项目名称:learning_app_engine,代码行数:7,代码来源:index.py
示例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
开发者ID:herohunfer,项目名称:IITVs,代码行数:31,代码来源:index.py
示例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))
开发者ID:geekyjulie,项目名称:ciphersleuth,代码行数:28,代码来源:main.py
示例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))
开发者ID:geekyjulie,项目名称:ciphersleuth,代码行数:27,代码来源:main.py
示例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.'} )
开发者ID:herohunfer,项目名称:IITVs,代码行数:7,代码来源:index.py
示例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'} )
开发者ID:jacobcr,项目名称:G4Btools,代码行数:34,代码来源:index.py
示例13: LogOutHandler
class LogOutHandler(webapp.RequestHandler):
def get(self):
self.session = Session()
self.session.delete_item('user')
self.redirect('main.html')
开发者ID:filipmares,项目名称:SynapSync,代码行数:7,代码来源:logout.py
示例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})
开发者ID:3ancho,项目名称:IITVs,代码行数:28,代码来源:views.py
示例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()
开发者ID:adekola,项目名称:poller-app,代码行数:8,代码来源:pollerdashboard.py
示例16: LogoutHandler
class LogoutHandler(webapp.RequestHandler):
def get(self):
self.session=Session()
self.session.delete_item('username')
self.session.delete_item('ft_client')
path=self.request.path
temp=os.path.join(os.path.dirname(__file__),'templates/index.html')
html=template.render(temp,{'path':path})
self.response.out.write(html)
开发者ID:apurvagoyal,项目名称:Google-App-Engine-Fusion-Table-Sample,代码行数:9,代码来源:index.py
示例17: TmainHandler
class TmainHandler(webapp.RequestHandler):
def get(self):
self.session=Session()
logged_name=self.session.get("username")
logged_id=self.session.get("id")
greeting="Hello"
lookup=(db.GqlQuery("SELECT * FROM TeacherDB WHERE teacher_id = :1", logged_id)).get()
classid_teacher=lookup.teacher_class_id
result=(db.GqlQuery("SELECT * FROM StudentDB WHERE classid = :1", classid_teacher)).fetch(limit=100)
temp = os.path.join(os.path.dirname(__file__), 'templates/tcontrol.html')
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write(str(template.render(temp,{'loggedUser':logged_id, "greeting":greeting,"result":result})))
开发者ID:geekyjulie,项目名称:ciphersleuth,代码行数:14,代码来源:main.py
示例18: ExitHandler
class ExitHandler(webapp.RequestHandler):
def get(self):
self.session=Session()
self.session.delete_item('username')
self.session.delete_item('role')
self.session.delete_item('tid')
self.session.delete_item('level')
self.session.delete_item('game_id')
msg="Thank you for playing. Bye!"
temp = os.path.join(os.path.dirname(__file__), 'templates/logout.html')
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write(str(template.render(temp,{"logoutmsg":msg})))
开发者ID:geekyjulie,项目名称:ciphersleuth,代码行数:15,代码来源:main.py
示例19: CipherInterfaceHandler
class CipherInterfaceHandler(webapp.RequestHandler):
def get(self):
temp=os.path.join(os.path.dirname(__file__), 'templates/sample.html')
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write(str(template.render(temp,{})))
def post(self):
# Our POST Input
self.session=Session()
txtinput = self.request.get('txtValue')
txtinput=txtinput.lower()
mode=self.request.get('mode')
if (txtinput =='show files' or txtinput == 'sf'):
txtinput="Show Files: Ciphers.py Subsitution.py transposition.py vigenere.py Affine.py ciphers.py"
elif (txtinput == "help" or txtinput =='h'):
txtinput="Would you like to go to the tutorial for the Caesar cipher(chelp or ch), Substitution cipher(shelp or sh), Transposition cipher(thelp or th), Vigenere cipher(vhelp or vh), or Affine cipher(ahelp or ah)? You can also type toolbox(toolbox or tb) to use the ciphers."
elif(txtinput == "chelp" or txtinput=="ch"):
txtinput="The Caesar cipher works by substituting letters for different letters a certain number away from the original letter. For example, the letter 'A' with a key of 2 would become 'C' because C is 2 letters away from 'A'. The word 'CAT' would be encoded to say 'ECV'. To figure out the key to decode a message, you can keep trying numbers between 1 and 26 until one decodes the message into something that makes sense."
elif(txtinput == "shelp" or txtinput=="sh"):
txtinput="The substitution cipher has a key of 26 letters, each one in the alphabet, all reordered, and matches the old letters of the alphabet to the new ones. So if the letter 'A' maps to 'V' because it is the first letter of the key, 'B' maps to 'Q' because 'Q' is the second letter in the key. If 'T' maps to 'P', the code word for 'TAB' would be 'PVQ'."
elif(txtinput == "thelp" or txtinput=="th"):
txtinput="The transposition cipher works by mapping different letters to columns in a table, and then putting the rows of the table together to make the ciphertext. For example, to encode the sentence 'The apple is red.' with a key of 3, the cipher will make a table with 3 columns. Because there are 17 characters in this sentence, we take 17/3 which gives 5 with a remainder of 2. This means we need 6 rows and one space will not be used since there are 17 characters and 18 table entries. The cipher will put one letter in each column of the table so that they read [T,h,e; ,a,p;p,l,e; ,i,s; ,r,e;d,.,X] (commas separate columns, semicolumns separate rows) The resulting ciphertext will go down each column one at a time putting together the characters, giving the ciphertext 'T p dhalir.epese'"
elif(txtinput == "vhelp" or txtinput=="vh"):
txtinput="The Vigenere cipher works almost like the Caesar cipher, except for every letter, the number of letters it shifts is different. The alphabet index of each letter in the key tells how many letters to shift each letter of plaintext. To encode the sentence 'The sky is blue' with the key 'cat', the index of each letter in the key 'cat' is the shift number. The first letter of the message 'T' will shift 3 letters since the first letter of the key is 'c', and its index is 3. So, the first letter of the ciphertext will be 'W'. The next letter will shift 1 because the index of a is one, so 'h' will become 'i'. The index of 't' is 20, so 'e' will shift 20 to become 'y'. When the letters in the key run out, it just starts over, so the next letter of the message 's' will shift 3 to 'v' because the next shift will be the letter 'c' again."
elif(txtinput == "ahelp" or txtinput=="ah"):
txtinput="The affine cipher has a few more steps than the other ciphers. First, it maps each letter of the plaintext to its alphabetic index starting at 0. The word 'SLEUTH' would map to the numbers 18, 11, 4, 20, 19, 7. Let's say we want to include special characters in our encoded alphabet, which will now have a length of 96 instead of 26. We then need to select two numbers for the key, and the first number has to be coprime with 96, meaning it does not share any factors with 96. Since 96's prime factors are 2 and 3, the first part of the key can be any number not divisible by 2 or 3. Our numbers a and b will be used in the equation ax+b, where x is the letter index and the result of which needs to be bigger than 96 for reasons we'll explain in a minute. We'll choose a to be 31 and b to be 57. When we use each letter's index as x in the equation, we get 615, 398, 181, 677, 646, 274. To map these numbers to our alphabet of symbols and letters, we need them to be mod 96. This means we want to divide them by 96 and use the remainder as the new number. After doing that, our new numbers are 39, 14, 85, 5, 70, 82. To get our key, we can multiply a by 96 and add b, which gives us 3033. Mapping the new numbers to their indexes in our alphabet gives us the ciphertext '&lTcEQ'."
elif(txtinput == "tb" or txtinput=='toolbox'):
txtinput="You have selected toolbox. Please select a mode(e for Encryption, d for Decryption) and type a message( ex: d-Hello )?"
elif(mode=='e' or mode=='d'):
self.session.delete_item('mode')
self.session['mode']=mode
msg=self.request.get('msg')
self.session.delete_item('msg')
self.session['msg']=msg
if (mode =='e'):
mo="Encryption"
else:
mo="Decryption"
txtinput="You have chosen " + mo +" and your message is " + msg + ". 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)"
else:
txtinput="Error, invalid command! Please type again."
array = {'text': txtinput}
# Output the JSON
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps(array))
开发者ID:geekyjulie,项目名称:ciphersleuth,代码行数:48,代码来源:main.py
示例20: post
def post(self):
self.session = Session()
form = LoginForm(self.request.POST)
if form.validate():
self.session.delete_item('username')
self.session.delete_item('userkey')
self.session.delete_item('admin')
un = form.username.data
pw = form.password.data
m = hashlib.sha224(pw)
que = db.Query(User).filter('username =', un).filter('password =', m.hexdigest())
# que = que.filter('password =', m.hexdigest())
# above two may combine
results = que.fetch(limit = 1)
if len(results) > 0:
user = results[0]
self.session['userkey'] = user.key()
self.session['username'] = un
self.session['admin'] = user.admin
self.redirect('/main')
#self.doRender('main.html', {} ) # if ok, go to main.html (logged in)
else:
self.doRender(
'loginscreen.html',
{'error': 'Username or Password wrong', \
'form': form} )
else: # if form.validate() Fails.
self.doRender('loginscreen.html', {'form': form} )
开发者ID:3ancho,项目名称:IITVs,代码行数:31,代码来源:views.py
注:本文中的util.sessions.Session类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论