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


Python cherrypy.session方法代码示例

本文整理汇总了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 '/') 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:18,代码来源:cptools.py

示例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) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:27,代码来源:cptools.py

示例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') 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:26,代码来源:sessions.py

示例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 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:19,代码来源:sessions.py

示例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') 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:18,代码来源:sessions.py

示例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" 
开发者ID:alexcoman,项目名称:labs,代码行数:23,代码来源:main.py

示例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 "/") 
开发者ID:naparuba,项目名称:opsbro,代码行数:18,代码来源:cptools.py

示例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 
开发者ID:naparuba,项目名称:opsbro,代码行数:19,代码来源:sessions.py

示例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
        ) 
开发者ID:kakwa,项目名称:ldapcherry,代码行数:22,代码来源:__init__.py

示例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(),
            ) 
开发者ID:kakwa,项目名称:ldapcherry,代码行数:20,代码来源:__init__.py

示例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') 
开发者ID:splunk,项目名称:SA-ctf_scoreboard,代码行数:22,代码来源:scoreboard_controller.py

示例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 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:14,代码来源:tut07_sessions.py

示例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) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:11,代码来源:cptools.py

示例14: id

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import session [as 别名]
def id(self):
        """Return the current session id."""
        return self._id 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:5,代码来源:sessions.py

示例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() 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:9,代码来源:sessions.py


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