当前位置: 首页>>代码示例>>Python>>正文


Python Session.invalidate方法代码示例

本文整理汇总了Python中app.gmemsess.Session.invalidate方法的典型用法代码示例。如果您正苦于以下问题:Python Session.invalidate方法的具体用法?Python Session.invalidate怎么用?Python Session.invalidate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app.gmemsess.Session的用法示例。


在下文中一共展示了Session.invalidate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from app.gmemsess import Session [as 别名]
# 或者: from app.gmemsess.Session import invalidate [as 别名]
	def get(self):
		img = Image()
		imgdata = img.create()
		sess=Session(self,timeout=900)
		if not sess.is_new():
			sess.invalidate()
			sess=Session(self,timeout=900)
		sess['code']=img.text
		sess.save()
		self.response.headers['Content-Type'] = "image/png"
		self.response.out.write(imgdata)
开发者ID:daisyfeng,项目名称:codespot,代码行数:13,代码来源:blog.py

示例2: get

# 需要导入模块: from app.gmemsess import Session [as 别名]
# 或者: from app.gmemsess.Session import invalidate [as 别名]
 def get(self):
     import StringIO
     code_img, strs = create_validate_code()  
     buf = StringIO.StringIO()  
     code_img.save(buf,'JPEG',quality=70)          
     imgdata = buf.getvalue()
     
     sess=Session(self,timeout=900)
     if not sess.is_new():
         sess.invalidate()
         sess=Session(self,timeout=900)
     sess['icode']=strs
     sess.save()
     
     self.response.headers['Content-Type'] = "image/jpeg"
     self.response.out.write(imgdata)
开发者ID:SeanStar,项目名称:micolog,代码行数:18,代码来源:blog.py

示例3: post

# 需要导入模块: from app.gmemsess import Session [as 别名]
# 或者: from app.gmemsess.Session import invalidate [as 别名]
    def post(self,slug=None):
        useajax=self.param('useajax')=='1'
        ismobile=self.paramint('ismobile')==1
        #if not self.is_login:
        #    if useajax:
        #            self.write(json.dumps((False,-102,_('You must login before comment.')),ensure_ascii = False))
        #    else:
        #            self.error(-102,_('You must login before comment .'))
        #    return
        if not self.is_login:
            sess=Session(self,timeout=180)
            try:
                check_ret=True
                if self.blog.comment_check_type==1:
                    checkret=self.param('checkret')
                    check_ret=(int(checkret) == sess['code'])
                elif self.blog.comment_check_type==2:
                    checkret=self.param('checkret')
                    check_ret=(str(checkret) == sess['icode'])
                elif  self.blog.comment_check_type ==3:
                    import app.gbtools as gb
                    checknum=self.param('checknum')
                    checkret=self.param('checkret')
                    check_ret=eval(checknum)==int(gb.stringQ2B( checkret))

                if not check_ret:
                    if useajax:
                        self.write(json.dumps((False,-102,_('Your check code is invalid .')),ensure_ascii = False))
                    else:
                        self.error(-102,_('Your check code is invalid .'))
                    return
            except Exception,e:
                if useajax:
                    self.write(json.dumps((False,-102,_('Your check code is invalid .')+unicode(e)),ensure_ascii = False))
                else:
                    self.error(-102,_('Your check code is invalid .'))
                return

            sess.invalidate()
开发者ID:SeanStar,项目名称:micolog,代码行数:41,代码来源:blog.py

示例4: post

# 需要导入模块: from app.gmemsess import Session [as 别名]
# 或者: from app.gmemsess.Session import invalidate [as 别名]
	def post(self,slug=None):
		useajax=self.param('useajax')=='1'

		name=self.param('author')
		email=self.param('email')
		url=self.param('url')

		key=self.param('key')
		content=self.param('comment')
		parent_id=self.paramint('parentid',0)
		reply_notify_mail=self.parambool('reply_notify_mail')

		sess=Session(self,timeout=180)
		if not self.is_login:
			#if not (self.request.cookies.get('comment_user', '')):
			try:
				check_ret=True
				if g_blog.comment_check_type in (1,2)  :
					checkret=self.param('checkret')
					logging.info('______'+checkret)
					check_ret=(int(checkret) == sess['code'])
				elif  g_blog.comment_check_type ==3:
					import app.gbtools as gb
					checknum=self.param('checknum')
					checkret=self.param('checkret')
					check_ret=eval(checknum)==int(gb.stringQ2B( checkret))

				if not check_ret:
					if useajax:
						self.write(simplejson.dumps((False,-102,_('Your check code is invalid .'))))
					else:
						self.error(-102,_('Your check code is invalid .'))
					return
			except:
				if useajax:
					self.write(simplejson.dumps((False,-102,_('Your check code is invalid .'))))
				else:
					self.error(-102,_('Your check code is invalid .'))
				return

		sess.invalidate()
		content=content.replace('\n','<br>')
		content=myfilter.do_filter(content)
		name=cgi.escape(name)[:20]
		url=cgi.escape(url)[:100]

		if not (name and email and content):
			if useajax:
						self.write(simplejson.dumps((False,-101,_('Please input name, email and comment .'))))
			else:
				self.error(-101,_('Please input name, email and comment .'))
		else:
			comment=Comment(author=name,
							content=content,
							email=email,
							reply_notify_mail=reply_notify_mail,
							entry=Entry.get(key))
			if url:
			   try:
					comment.weburl=url
			   except:
				   comment.weburl=None

			#name=name.decode('utf8').encode('gb2312')


			info_str='#@#'.join([urlencode(name),urlencode(email),urlencode(url)])

			 #info_str='#@#'.join([name,email,url.encode('utf8')])
			cookiestr='comment_user=%s;expires=%s;domain=%s;path=/'%( info_str,
					   (datetime.now()+timedelta(days=100)).strftime("%a, %d-%b-%Y %H:%M:%S GMT"),
					   ''
					   )
			comment.ip=self.request.remote_addr
			
			if parent_id:
				comment.parent=Comment.get_by_id(parent_id)
				
			try:
				comment.save()
				memcache.delete("/"+comment.entry.link)

				self.response.headers.add_header( 'Set-Cookie', cookiestr)
				if useajax:
					comment_c=self.get_render('comment',{'comment':comment})
					self.write(simplejson.dumps((True,comment_c.decode('utf8'))))
				else:
					self.redirect(self.referer+"#comment-"+str(comment.key().id()))

				comment.entry.removecache()
				memcache.delete("/feed/comments")
			except:
				if useajax:
					self.write(simplejson.dumps((False,-102,_('Comment not allowed.'))))
				else:
					self.error(-102,_('Comment not allowed .'))
开发者ID:daisyfeng,项目名称:codespot,代码行数:98,代码来源:blog.py

示例5: post

# 需要导入模块: from app.gmemsess import Session [as 别名]
# 或者: from app.gmemsess.Session import invalidate [as 别名]
	def post(self,slug=None):
		useajax=self.param('useajax')=='1'

		name=self.param('author')
		email=self.param('email')
		url=self.param('url')

		key=self.param('key')
		content=self.param('comment')
		parent_id=self.paramint('parentid',0)
		reply_notify_mail=self.parambool('reply_notify_mail')

		sess=Session(self,timeout=180)

		if not self.is_login:
			#if not (self.request.cookies.get('comment_user', '')):
			try:
				check_ret=True
				if g_blog.comment_check_type in (1,2)  :
					checkret=self.param('checkret')
					check_ret=(int(checkret) == sess['code'])
				elif  g_blog.comment_check_type ==3:
					import app.gbtools as gb
					checknum=self.param('checknum')
					checkret=self.param('checkret')
					check_ret=eval(checknum)==int(gb.stringQ2B( checkret))
				elif g_blog.comment_check_type == 4:#reCAPTCHA, probably not working in China mainland
					ip = self.request.remote_addr
					private_key = "6Leox8YSAAAAAGJ734ttj4OYojDiCcsb1tcDBarA"
					resp = self.param('checkret')
					chalg = self.param('challenge')
					import urllib
					import urllib2
					params = urllib.urlencode({
						'privatekey': private_key,
						'remoteip' : ip,
						'challenge' : chalg,
						'response' : resp 
					})
					request = urllib2.Request(
						url = "http://www.google.com/recaptcha/api/verify",
						data = params,
						headers = { "Content-type": "application/x-www-form-urlencoded" }
						)
					httpresp = urllib2.urlopen(request)
					return_values = httpresp.read().splitlines();
					check_ret = (return_values[0] == "true")

				if not check_ret:
					if useajax:
						self.write(simplejson.dumps((False,-102,_('Your check code is invalid .')),ensure_ascii = False))
					else:
						self.error(-102,_('Your check code is invalid .'))
					return
			except Exception:
				logging.exception('Error when checking CAPTCHA')
				#Assume the captcha is right, which is less confusing. TODO: send admin an email to notify this event
				'''
				if useajax:
					self.write(simplejson.dumps((False,-102,_('Your check code is invalid .')),ensure_ascii = False))
				else:
					self.error(-102,_('Your check code is invalid .'))
				return
				'''

		sess.invalidate()
		content=content.replace('\n','<br />')
		content=myfilter.do_filter(content)
		name=cgi.escape(name)[:20]
		url=cgi.escape(url)[:100]

		if not (name and email and content):
			if useajax:
				self.write(simplejson.dumps((False,-101,_('Please input name, email and comment .'))))
			else:
				self.error(-101,_('Please input name, email and comment .'))
		else:
			comment=Comment(author=name,
							content=content,
							email=email,
							reply_notify_mail=reply_notify_mail,
							entry=Entry.get(key))

			if url:
				try:
					if not url.startswith(('http://','https://')):
						url = 'http://' + url
					comment.weburl=url
				except:
					comment.weburl=None

			#name=name.decode('utf8').encode('gb2312')
			info_str='#@#'.join([urlencode(name),urlencode(email),urlencode(url)])

			 #info_str='#@#'.join([name,email,url.encode('utf8')])
			cookiestr='comment_user=%s;expires=%s;domain=%s;path=/'%( info_str,
					   (datetime.now()+timedelta(days=100)).strftime("%a, %d-%b-%Y %H:%M:%S GMT"),
					   ''
					   )
			comment.ip=self.request.remote_addr
#.........这里部分代码省略.........
开发者ID:Alwnikrotikz,项目名称:micolog2,代码行数:103,代码来源:blog.py

示例6: post

# 需要导入模块: from app.gmemsess import Session [as 别名]
# 或者: from app.gmemsess.Session import invalidate [as 别名]
    def post(self, slug=None):
        useajax = self.param("useajax") == "1"

        name = self.param("author")
        email = self.param("email")
        url = self.param("url")

        key = self.param("key")
        content = self.param("comment")
        parent_id = self.paramint("parentid", 0)
        reply_notify_mail = self.parambool("reply_notify_mail")

        sess = Session(self, timeout=180)
        if not self.is_login:
            # if not (self.request.cookies.get('comment_user', '')):
            try:
                check_ret = True
                if g_blog.comment_check_type in (1, 2):
                    checkret = self.param("checkret")
                    check_ret = int(checkret) == sess["code"]
                elif g_blog.comment_check_type == 3:
                    import app.gbtools as gb

                    checknum = self.param("checknum")
                    checkret = self.param("checkret")
                    check_ret = eval(checknum) == int(gb.stringQ2B(checkret))

                if not check_ret:
                    if useajax:
                        self.write(
                            simplejson.dumps((False, -102, _("Your check code is invalid .")), ensure_ascii=False)
                        )
                    else:
                        self.error(-102, _("Your check code is invalid ."))
                    return
            except:
                if useajax:
                    self.write(simplejson.dumps((False, -102, _("Your check code is invalid .")), ensure_ascii=False))
                else:
                    self.error(-102, _("Your check code is invalid ."))
                return

        sess.invalidate()
        content = content.replace("\n", "<br />")
        content = myfilter.do_filter(content)
        name = cgi.escape(name)[:20]
        url = cgi.escape(url)[:100]

        if not (name and email and content):
            if useajax:
                self.write(simplejson.dumps((False, -101, _("Please input name, email and comment ."))))
            else:
                self.error(-101, _("Please input name, email and comment ."))
        else:
            comment = Comment(
                author=name, content=content, email=email, reply_notify_mail=reply_notify_mail, entry=Entry.get(key)
            )
            if url:
                try:
                    if not url.startswith(("http://", "https://")):
                        url = "http://" + url
                    comment.weburl = url
                except:
                    comment.weburl = None

                    # name=name.decode('utf8').encode('gb2312')

            info_str = "#@#".join([urlencode(name), urlencode(email), urlencode(url)])

            # info_str='#@#'.join([name,email,url.encode('utf8')])
            cookiestr = "comment_user=%s;expires=%s;domain=%s;path=/" % (
                info_str,
                (datetime.now() + timedelta(days=100)).strftime("%a, %d-%b-%Y %H:%M:%S GMT"),
                "",
            )
            comment.ip = self.request.remote_addr

            if parent_id:
                comment.parent = Comment.get_by_id(parent_id)

            comment.no = comment.entry.commentcount + 1
            try:
                comment.save()
                memcache.delete("/" + comment.entry.link)

                self.response.headers.add_header("Set-Cookie", cookiestr)
                if useajax:
                    comment_c = self.get_render("comment", {"comment": comment})
                    self.write(simplejson.dumps((True, comment_c.decode("utf8")), ensure_ascii=False))
                else:
                    self.redirect(self.referer + "#comment-" + str(comment.key().id()))

                comment.entry.removecache()
                memcache.delete("/feed/comments")
            except:
                if useajax:
                    self.write(simplejson.dumps((False, -102, _("Comment not allowed."))))
                else:
                    self.error(-102, _("Comment not allowed ."))
开发者ID:itopidea,项目名称:micolog,代码行数:101,代码来源:blog.py


注:本文中的app.gmemsess.Session.invalidate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。