當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。