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


Python Cookie.add_cookie方法代码示例

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


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

示例1: _set_cookie

# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import add_cookie [as 别名]
    def _set_cookie(self, value, **attrs):
        """(session_id : string)

        Ensure that a session cookie with value 'session_id' will be
        returned to the client via the response object.

        Since Mod_Python has its own Cookie management system, we use it.
        """
        config = get_publisher().config
        name = config.session_cookie_name
        domain = config.session_cookie_domain

        if config.session_cookie_path:
            path = config.session_cookie_path
        else:
            path = get_request().get_environ('SCRIPT_NAME')
            if not path.endswith("/"):
                path += "/"

        expires = -1

        options = {'expires': expires,
                   'path': path }

        if domain is not None:
            options.update({'domain':domain})

        if value:
            Cookie.add_cookie(self.modpython_request, name, value, **options)

        return name
开发者ID:philn,项目名称:alinea,代码行数:33,代码来源:ModPySessionManager.py

示例2: index

# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import add_cookie [as 别名]
def index(req):
 # check if cookie is set for respondent who already participated
 client_cookie = Cookie.get_cookie(req, 'rm-group-a')
 if client_cookie is None:
  Cookie.add_cookie(req, 'rm-group-a', 'true', expires=time.time()+31*24*3600) # expires after 1 month
 else:
  return 'You already participated.'
 
 # load current respondent conditions
 with open(PATH, 'r') as f:
  respondents = yaml.load(f)
  if respondents is None:
   respondents = []

  no_avatar_count = count_str_in_seq(NO_AVATAR, respondents)
  avatar_count = count_str_in_seq(AVATAR, respondents)

  if no_avatar_count <= MIN_RESPONDENTS and avatar_count >= MIN_RESPONDENTS:
   condition = NO_AVATAR
  elif no_avatar_count >= MIN_RESPONDENTS and avatar_count <= MIN_RESPONDENTS:
   condition = AVATAR
  else:
   condition = random.choice([NO_AVATAR, AVATAR])
 
 # write new condition entry
 with open(PATH, 'w') as f:
  respondents.append(condition)
  yaml.dump(respondents, f)
 util.redirect(req, 'welcome' + '-' + condition + '.html')
开发者ID:mchlbrnd,项目名称:rm-group-a,代码行数:31,代码来源:randomize.py

示例3: logout

# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import add_cookie [as 别名]
def logout(req):
    cookies = Cookie.get_cookies(req)
    Cookie.add_cookie(req, 'ogtvogh', '', expires=time.time(), path='/')
    req.status=apache.HTTP_MOVED_TEMPORARILY
    req.headers_out["Location"] = SITEURL
    req.send_http_header()
    return "You have successfully logged out"
开发者ID:doublewera,项目名称:smdc,代码行数:9,代码来源:structure.py

示例4: __init__

# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import add_cookie [as 别名]
 def __init__(self, req):
     """get, extract info, and do upkeep on the session cookie. This determines what the sessid and user are 
          for this request."""
     #pass the request in making in so we can edit it later if requested (ACL for example)
     self.ip = req.connection.remote_ip
     c = Cookie.get_cookies(req)
     if not c.has_key('mps'):
         self.sessid = Uid().new_sid(req)
     else:
         c = c['mps']
         self.sessid = c.value
         
     #make new cookie so the cycle continues
     c = Cookie.Cookie('mps', self.sessid)
     c.path = '/'
     Cookie.add_cookie(req, c)
     
     self.session_path = "%s%s"%(path_to_sessions, self.sessid)
     self.full_session_path = "%s%s"%(self.session_path, db_extension)
     
     #use previous authenication until cookie is reevaluated, if they are officially logged in (in Instance)
     if os.path.exists(self.full_session_path):
         session = shelve.open(self.session_path, 'rw')
         self.user  = session['USER_']
         session.close()
     else:
         self.user = self.unauthorized
开发者ID:circlecycle,项目名称:mps,代码行数:29,代码来源:Identity.py

示例5: general_authenhandler

# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import add_cookie [as 别名]
def general_authenhandler(req, req_type, anon_ok=False):
	pw = req.get_basic_auth_pw()
	cookies = Cookie.get_cookies(req)
	if not cookies.has_key('csrftoken'):
		cookie = Cookie.Cookie('csrftoken', hashlib.md5(str(random.randrange(0, 2<<63))).hexdigest())
		cookie.path = '/'
		if config.get('session', 'cookie_host') != '':
			cookie.domain = config.get('session', 'cookie_host')
		Cookie.add_cookie(req, cookie)
	if cookies.has_key('myemsl_session'):
		sql = "select user_name from myemsl.eus_auth where session_id = %(sid)s"
		cnx = myemsldb_connect(myemsl_schema_versions=['1.0'])
		cursor = cnx.cursor()
		cursor.execute(sql, {'sid':cookies['myemsl_session'].value})
		rows = cursor.fetchall()
		found = False
		for row in rows:
			req.user = row[0]
			found = True
		if found:
			logger.debug("Session: %s", str(cookies['myemsl_session'].value))
#FIXME outage_check seems to be in the wrong place for a myemsl database outage.
			return outage_check(req, req_type)
	elif anon_ok:
		req.user = ''
		return outage_check(req, req_type)
	url = urllib.quote(req.unparsed_uri)
	redirect(req, "/myemsl/auth?url=%s" %(url))
	return apache.HTTP_UNAUTHORIZED
开发者ID:EMSL-MSC,项目名称:pacifica-2.0,代码行数:31,代码来源:__init__.py

示例6: set_browser_info

# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import add_cookie [as 别名]
    def set_browser_info(self, info):
        """    sets the "state" info for the browser
        """

        #info = base64.encodestring(repr(info))
        info = repr(info)
        Cookie.add_cookie(self.req, Cookie.Cookie('browseinfo', info))
开发者ID:pombredanne,项目名称:pyjamas-desktop,代码行数:9,代码来源:zct.py

示例7: _add_csrf_cookie_if_needed

# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import add_cookie [as 别名]
def _add_csrf_cookie_if_needed(req):
    signed_cookies = Cookie.get_cookies(req, Cookie.SignedCookie, secret=_get_secret())
    cookie = signed_cookies.get(settings.csrf_cookie_name, None)
    if cookie:
        # make sure we aren't altered
        if type(cookie) is Cookie.SignedCookie and cookie.value == _message_contents():
            return
    Cookie.add_cookie(req, _generate_csrf_cookie())
开发者ID:JonnyFunFun,项目名称:pycoin-gateway,代码行数:10,代码来源:csrf.py

示例8: set

# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import add_cookie [as 别名]
 def set(self,username):
     value = {
         "username": username
     }
     cookie = Cookie.MarshalCookie(self.cookie_key, value, secret=str(self.captureSettings["secretKey"]))
     cookie.path = "/"
     cookie.expires = time.time() + int(self.captureSettings["sessionCookiesTimeout"])
     Cookie.add_cookie(self.req, cookie)
开发者ID:untangle,项目名称:ngfw_src,代码行数:10,代码来源:handler.py

示例9: send_cookies

# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import add_cookie [as 别名]
 def send_cookies(self):
     """ sends the http headers for any cookies that need to be set
     """
     if self.req != None:
         for c in self._cookies:
             Cookie.add_cookie(self.req,c)
     else:
         for c in self._cookies:
             print c
开发者ID:thecapn2k5,项目名称:cloneme,代码行数:11,代码来源:cgi_app.py

示例10: index

# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import add_cookie [as 别名]
def index(req):
    secret = 'my_secret'
    marshal_cookies = Cookie.get_cookies(req, Cookie.MarshalCookie, secret=secret)
    returned_marshal = marshal_cookies.get('marshal', None)
    if(returned_marshal):
        returned_marshal.expires= time.time()
        Cookie.add_cookie(req, returned_marshal)
        return '<html><body>return to main place <a href="./">here</a></body></html>'
    else:
        return '<html><title></title><body>there is nothing <a href="./">back</a></body></html>'
开发者ID:COMU,项目名称:pyldapadmin,代码行数:12,代码来源:server_info.py

示例11: set

# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import add_cookie [as 别名]
    def set(self, var, val):

        ck = scs.encode(self.s, val, len(val))
        if ck is None:
            raise Exception, 'failed scs.encode()'
       
        c = Cookie.Cookie(var, ck)
        Cookie.add_cookie(self.req, c)
        
        return ck
开发者ID:babongo,项目名称:libscs,代码行数:12,代码来源:modpyscs.py

示例12: Cookie_Cookie

# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import add_cookie [as 别名]
def Cookie_Cookie(req):

    from mod_python import Cookie

    cookies = Cookie.get_cookies(req)

    for k in cookies:
        Cookie.add_cookie(req, cookies[k])

    req.write("test ok")
    
    return apache.OK
开发者ID:tianyanhui,项目名称:mod_python,代码行数:14,代码来源:tests.py

示例13: Cookie_MarshalCookie

# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import add_cookie [as 别名]
def Cookie_MarshalCookie(req):

    from mod_python import Cookie

    cookies = Cookie.get_cookies(req, Cookie.MarshalCookie,
                                secret="secret")

    for k in cookies:
        Cookie.add_cookie(req, cookies[k])

    req.write("test ok")
    
    return apache.OK
开发者ID:tianyanhui,项目名称:mod_python,代码行数:15,代码来源:tests.py

示例14: logout

# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import add_cookie [as 别名]
    def logout(self, REQUEST):
        """    logs out and redirects to main page
        """

        Cookie.add_cookie(self.req, Cookie.Cookie("sessionkey", "", expires=0))
        Cookie.add_cookie(self.req, Cookie.Cookie("browseinfo", "", expires=0))
        self.info = {}

        links = {"banner": "menu", "leftcontent": "advertising"}

        page = self.tmpl("logout")
        page.staticlink(links)

        return page
开发者ID:pombredanne,项目名称:pyjamas-desktop,代码行数:16,代码来源:zctlogin.py

示例15: setCookie

# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import add_cookie [as 别名]
	def setCookie(self,key,value,secret=None,expires=None,path=None):
		cookieType = Cookie.Cookie
		options = {}

		if expires != None: options['expires'] = expires
		if path != None: options['path'] = path
		if secret != None:
			cookieType = Cookie.MarshalCookie
			options['secret'] = secret

		Cookie.add_cookie(self.req, cookieType(key, value, **options))
		if expires==0 and not secret:
			self.cookieCache[key] = None
		elif not secret:
			self.cookieCache[key] = value
开发者ID:palli,项目名称:statmon,代码行数:17,代码来源:standardControllers.py


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