本文整理汇总了Python中mod_python.Cookie.get_cookies方法的典型用法代码示例。如果您正苦于以下问题:Python Cookie.get_cookies方法的具体用法?Python Cookie.get_cookies怎么用?Python Cookie.get_cookies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mod_python.Cookie
的用法示例。
在下文中一共展示了Cookie.get_cookies方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import get_cookies [as 别名]
def init(self):
# Parse the HTTP headers for variables and files.
for field in self.__field_storage.list:
# This is a normal variable.
if str(type(field.file)) == "<type 'cStringIO.StringI'>" or \
str(type(field.file)) == "<type 'cStringIO.StringO'>":
self.set_var(field.name, field.value)
# This is a file.
else:
# Some browsers give a full path instead of a file name. Some
# browsers give an encoded file name. Plan for those cases.
# FIXME: is the explanation above and the code below correct?
filename = field.filename
filename = urllib.unquote_plus(filename) # unquote filename (it should be encoded like an url)
filename = re.sub(r'\\+', '/', filename) # some OS use "\" for paths... replace '\' in '/'
filename = os.path.basename(filename) # some browsers (IE) send full path.. rip path part and just get file name
self.__files[field.name] = KWebFile(filename, field.file)
# Store the HTTP headers.
for key in self.__req.headers_in:
self.__headers_in[key] = self.__req.headers_in[key]
# Initialize the cookies.
self.__cookies_in = Cookie.get_cookies(self.__req)
示例2: __init__
# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import get_cookies [as 别名]
def __init__(self,req=None, form=None):
self.req = req
if self.req != None:
# mod_python
self.form = util.FieldStorage(self.req)
self._cookies_in = Cookie.get_cookies(self.req)
else:
# if we have a form, don't get a new one
if form:
self.form=form
# if we don't have a form, then get one
else:
self.form = cgi.FieldStorage()
self._cookies_in = SimpleCookie()
try:
self._cookies_in.load(os.environ["HTTP_COOKIE"])
except KeyError:
pass
self._dispatch = {}
self._header_sent = 0
self._header_props = {"Content-Type" : "text/html;charset=UTF-8"}
self._header_props = {}
self._header_type = "header"
self._cookies = []
self._url = ""
self._environ = os.environ
self.template_dir = 'templates'
self.run_mode_param = 'rm'
self.start_mode = ''
self.__globals__ = {}
self.setup()
示例3: get_cookie
# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import get_cookies [as 别名]
def get_cookie(cls, req, name):
"""Retreive cookie by name from request object."""
#cookies = mod_python.Cookie.get_cookies(req)
cookies = Cookie.get_cookies(req)
this_cookie = cookies.get(name)
value = cut(str(this_cookie), "{0}=".format(name))
return value
示例4: __init__
# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import get_cookies [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
示例5: general_authenhandler
# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import get_cookies [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
示例6: accesshandler
# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import get_cookies [as 别名]
def accesshandler(request):
cookies = Cookie.get_cookies(request)
# if login ticket cookie does not exist, then deny
if not cookies.has_key('login_ticket'):
# just refuse access
return apache.HTTP_FORBIDDEN
ticket = cookies['login_ticket'].value
if not ticket:
return apache.HTTP_FORBIDDEN
server = TacticServerStub.get(protocol='local')
expr = "@SOBJECT(sthpw/ticket['ticket','%s'])" % ticket
sobject = server.eval(expr, single=True)
now = SPTDate.now()
expiry = sobject.get("expiry")
if expiry and expiry < str(now):
return apache.HTTP_FORBIDDEN
request.add_common_vars()
path = str(request.subprocess_env['REQUEST_URI'])
if path == None:
return apache.HTTP_FORBIDDEN
# FIXME: find some mechanism which is more acceptable ... like /icons
#if path.find("_icon_") != -1:
# return apache.OK
return apache.OK
示例7: logout
# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import get_cookies [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"
示例8: __init__
# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import get_cookies [as 别名]
def __init__(self,req,appid=None):
self.req = req
if appid == None:
args = split_args(self.req.args);
appid = args['APPID']
self.captureSettings = load_capture_settings(self.req,appid)
self.cookie = Cookie.get_cookies(self.req, Cookie.MarshalCookie, secret=str(self.captureSettings["secretKey"]))
示例9: _add_csrf_cookie_if_needed
# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import get_cookies [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())
示例10: get_cookie
# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import get_cookies [as 别名]
def get_cookie(my, name):
cookies = Cookie.get_cookies(my.request)
cookie = cookies[name]
if cookie == None:
return ""
else:
my.error("cookie: "+cookie.value)
return cookie.value
示例11: isValidSession
# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import get_cookies [as 别名]
def isValidSession(req):
"""
check the Django's session table to decided this is a valid session or not.
"""
# check for PythonOptions
_str_to_bool = lambda s: s.lower() in ('1', 'true', 'on', 'yes')
options = req.get_options()
permission_name = options.get('DjangoPermissionName', None)
staff_only = _str_to_bool(options.get('DjangoRequireStaffStatus', "on"))
superuser_only = _str_to_bool(options.get('DjangoRequireSuperuserStatus', "off"))
settings_module = options.get('DJANGO_SETTINGS_MODULE', None)
if settings_module:
os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
from django.conf import settings
cookieName = settings.SESSION_COOKIE_NAME
cookies = Cookie.get_cookies(req)
if not cookies.has_key(cookieName):
return False
#import pdb; pdb.set_trace()
sessionId = cookies[cookieName].value
# mod_python fakes the environ, and thus doesn't process SetEnv. This fixes
# that so that the following import works
os.environ.update(req.subprocess_env)
from django.contrib.sessions.models import Session
from django import db
db.reset_queries()
try:
try:
session = Session.objects.get(pk=sessionId)
except Session.DoesNotExist:
return False
sessionData = session.get_decoded()
if not sessionData.has_key('_auth_user_id'):
# this is not a valid session!
return False
if session.expire_date > datetime.now():
if isResourcesRequest(req):
# just pass
return True
# this is a valid session, update the expre date!
expiry = settings.SESSION_COOKIE_AGE
session.expire_date = datetime.now() + timedelta(seconds=expiry)
session.save()
return True
else:
return False
finally:
db.connection.close()
示例12: get_session_info
# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import get_cookies [as 别名]
def get_session_info(self):
""" checks to see if the user is logged in, via the session cookie.
"""
cookies = Cookie.get_cookies(self.req)
if not cookies.has_key('sessionkey'):
return None
return cookies['sessionkey'].value
示例13: authorize
# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import get_cookies [as 别名]
def authorize(req):
cookies = Cookie.get_cookies(req)
if cookies.has_key("ogtvogh"):
user = str(cookies["ogtvogh"]).split('=')[1]
f = open('/etc/apache2/passwords')
for line in f:
if user == line.split(':')[1]:
f.close()
return 'auth'
return ''
示例14: index
# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import get_cookies [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>'
示例15: _check_csrf
# 需要导入模块: from mod_python import Cookie [as 别名]
# 或者: from mod_python.Cookie import get_cookies [as 别名]
def _check_csrf(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 not Cookie.SignedCookie or cookie.value != _message_contents():
raise apache.SERVER_RETURN, apache.HTTP_NOT_ACCEPTABLE
else:
return False
return True