本文整理汇总了Python中cherrypy.session方法的典型用法代码示例。如果您正苦于以下问题:Python cherrypy.session方法的具体用法?Python cherrypy.session怎么用?Python cherrypy.session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cherrypy
的用法示例。
在下文中一共展示了cherrypy.session方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_login
# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import session [as 别名]
def do_login(self, username, password, from_page='..', **kwargs):
"""Login. May raise redirect, or return True if request handled."""
response = cherrypy.serving.response
error_msg = self.check_username_and_password(username, password)
if error_msg:
body = self.login_screen(from_page, username, error_msg)
response.body = body
if 'Content-Length' in response.headers:
# Delete Content-Length header so finalize() recalcs it.
del response.headers['Content-Length']
return True
else:
cherrypy.serving.request.login = username
cherrypy.session[self.session_key] = username
self.on_login(username)
raise cherrypy.HTTPRedirect(from_page or '/')
示例2: do_check
# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import session [as 别名]
def do_check(self):
"""Assert username. Raise redirect, or return True if request handled.
"""
sess = cherrypy.session
request = cherrypy.serving.request
response = cherrypy.serving.response
username = sess.get(self.session_key)
if not username:
sess[self.session_key] = username = self.anonymous()
self._debug_message('No session[username], trying anonymous')
if not username:
url = cherrypy.url(qs=request.query_string)
self._debug_message(
'No username, routing to login_screen with from_page %(url)r',
locals(),
)
response.body = self.login_screen(url)
if 'Content-Length' in response.headers:
# Delete Content-Length header so finalize() recalcs it.
del response.headers['Content-Length']
return True
self._debug_message('Setting request.login to %(username)r', locals())
request.login = username
self.on_check(username)
示例3: save
# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import session [as 别名]
def save(self):
"""Save session data."""
try:
# If session data has never been loaded then it's never been
# accessed: no need to save it
if self.loaded:
t = datetime.timedelta(seconds=self.timeout * 60)
expiration_time = self.now() + t
if self.debug:
cherrypy.log('Saving session %r with expiry %s' %
(self.id, expiration_time),
'TOOLS.SESSIONS')
self._save(expiration_time)
else:
if self.debug:
cherrypy.log(
'Skipping save of session %r (no session loaded).' %
self.id, 'TOOLS.SESSIONS')
finally:
if self.locked:
# Always release the lock if the user didn't release it
self.release_lock()
if self.debug:
cherrypy.log('Lock released after save.', 'TOOLS.SESSIONS')
示例4: _load
# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import session [as 别名]
def _load(self, path=None):
assert self.locked, ('The session load without being locked. '
"Check your tools' priority levels.")
if path is None:
path = self._get_file_path()
try:
f = open(path, 'rb')
try:
return pickle.load(f)
finally:
f.close()
except (IOError, EOFError):
e = sys.exc_info()[1]
if self.debug:
cherrypy.log('Error loading the session pickle: %s' %
e, 'TOOLS.SESSIONS')
return None
示例5: acquire_lock
# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import session [as 别名]
def acquire_lock(self, path=None):
"""Acquire an exclusive lock on the currently-loaded session data."""
if path is None:
path = self._get_file_path()
path += self.LOCK_SUFFIX
checker = locking.LockChecker(self.id, self.lock_timeout)
while not checker.expired():
try:
self.lock = zc.lockfile.LockFile(path)
except zc.lockfile.LockError:
time.sleep(0.1)
else:
break
self.locked = True
if self.debug:
cherrypy.log('Lock acquired.', 'TOOLS.SESSIONS')
示例6: calculeaza
# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import session [as 别名]
def calculeaza(val1, operator, val2):
"""Solve an equation Grade 1."""
for key, value in cherrypy.session.items():
val1 = val1.replace(key, value)
operator = operator.replace(key, value)
val2 = val2.replace(key, value)
try:
if operator == "+":
return str(int(val1) + int(val2))
elif operator == "-":
return str(int(val1) - int(val2))
elif operator == "*":
return str(int(val1) * int(val2))
elif operator == "/":
return str(int(val1) / int(val2))
except ValueError:
return "Respecta constrangerile pentru: {} {} {}".format(
val1, operator, val2)
except ZeroDivisionError:
return "Div by zero"
示例7: do_login
# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import session [as 别名]
def do_login(self, username, password, from_page='..', **kwargs):
"""Login. May raise redirect, or return True if request handled."""
response = cherrypy.serving.response
error_msg = self.check_username_and_password(username, password)
if error_msg:
body = self.login_screen(from_page, username, error_msg)
response.body = body
if "Content-Length" in response.headers:
# Delete Content-Length header so finalize() recalcs it.
del response.headers["Content-Length"]
return True
else:
cherrypy.serving.request.login = username
cherrypy.session[self.session_key] = username
self.on_login(username)
raise cherrypy.HTTPRedirect(from_page or "/")
示例8: _load
# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import session [as 别名]
def _load(self, path=None):
assert self.locked, ("The session load without being locked. "
"Check your tools' priority levels.")
if path is None:
path = self._get_file_path()
try:
f = open(path, "rb")
try:
return pickle.load(f)
finally:
f.close()
except (IOError, EOFError):
e = sys.exc_info()[1]
if self.debug:
cherrypy.log("Error loading the session pickle: %s" %
e, 'TOOLS.SESSIONS')
return None
示例9: _selfmodify
# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import session [as 别名]
def _selfmodify(self, params):
cherrypy.log.error(
msg="modify user form attributes: " + str(params),
severity=logging.DEBUG
)
sess = cherrypy.session
username = sess.get(SESSION_KEY, None)
badd = self._modify_attrs(
params,
self.attributes.get_selfattributes(),
username,
)
cherrypy.log.error(
msg="user '" + username + "' modified his attributes",
severity=logging.INFO
)
cherrypy.log.error(
msg="user '" + username + "' attributes: " + str(badd),
severity=logging.DEBUG
)
示例10: index
# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import session [as 别名]
def index(self):
"""main page rendering
"""
self._check_auth(must_admin=False)
is_admin = self._check_admin()
sess = cherrypy.session
user = sess.get(SESSION_KEY, None)
if self.auth_mode == 'none':
user_attrs = None
else:
user_attrs = self._get_user(user)
attrs_list = self.attributes.get_search_attributes()
return self.temp['index.tmpl'].render(
is_admin=is_admin,
attrs_list=attrs_list,
searchresult=user_attrs,
notifications=self._empty_notification(),
)
示例11: get_kv_lookup
# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import session [as 别名]
def get_kv_lookup(self, lookup_file, namespace='lookup_editor', owner=None):
'''
Get the contents of a KV store lookup.
'''
try:
if owner is None:
owner = 'nobody'
# Get the session key
session_key = cherrypy.session.get('sessionKey')
# Get the contents
_, content = splunk.rest.simpleRequest('/servicesNS/' + owner + '/' + namespace + '/storage/collections/data/' + lookup_file, sessionKey=session_key, getargs={'output_mode': 'json'})
return content
except:
logger_admin.error('KV store lookup could not be loaded')
示例12: index
# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import session [as 别名]
def index(self):
# Increase the silly hit counter
count = cherrypy.session.get('count', 0) + 1
# Store the new value in the session dictionary
cherrypy.session['count'] = count
# And display a silly hit count message!
return '''
During your current session, you've viewed this
page %s times! Your life is a patio of fun!
''' % count
示例13: do_logout
# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import session [as 别名]
def do_logout(self, from_page='..', **kwargs):
"""Logout. May raise redirect, or return True if request handled."""
sess = cherrypy.session
username = sess.get(self.session_key)
sess[self.session_key] = None
if username:
cherrypy.serving.request.login = None
self.on_logout(username)
raise cherrypy.HTTPRedirect(from_page)
示例14: id
# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import session [as 别名]
def id(self):
"""Return the current session id."""
return self._id
示例15: now
# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import session [as 别名]
def now(self):
"""Generate the session specific concept of 'now'.
Other session providers can override this to use alternative,
possibly timezone aware, versions of 'now'.
"""
return datetime.datetime.now()