當前位置: 首頁>>代碼示例>>Python>>正文


Python Session.connect方法代碼示例

本文整理匯總了Python中gluon.globals.Session.connect方法的典型用法代碼示例。如果您正苦於以下問題:Python Session.connect方法的具體用法?Python Session.connect怎麽用?Python Session.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gluon.globals.Session的用法示例。


在下文中一共展示了Session.connect方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setUp

# 需要導入模塊: from gluon.globals import Session [as 別名]
# 或者: from gluon.globals.Session import connect [as 別名]
    def setUp(self):
        request = Request(env={})
        request.application = "a"
        request.controller = "c"
        request.function = "f"
        request.folder = "applications/admin"
        response = Response()
        session = Session()
        T = translator("", "en")
        session.connect(request, response)
        from gluon.globals import current

        current.request = request
        current.response = response
        current.session = session
        current.T = T
        self.db = DAL(DEFAULT_URI, check_reserved=["all"])
        self.auth = Auth(self.db)
        self.auth.define_tables(username=True, signature=False)
        self.db.define_table("t0", Field("tt"), self.auth.signature)
        self.auth.enable_record_versioning(self.db)
        # Create a user
        self.db.auth_user.insert(
            first_name="Bart",
            last_name="Simpson",
            username="user1",
            email="[email protected]",
            password="password_123",
            registration_key=None,
            registration_id=None,
        )

        self.db.commit()
開發者ID:topleft,項目名稱:book2-exercises,代碼行數:35,代碼來源:test_sqlhtml.py

示例2: setUp

# 需要導入模塊: from gluon.globals import Session [as 別名]
# 或者: from gluon.globals.Session import connect [as 別名]
    def setUp(self):
        request = Request(env={})
        request.application = 'a'
        request.controller = 'c'
        request.function = 'f'
        request.folder = 'applications/admin'
        response = Response()
        session = Session()
        T = translator('', 'en')
        session.connect(request, response)
        from gluon.globals import current
        current.request = request
        current.response = response
        current.session = session
        current.T = T
        self.db = DAL(DEFAULT_URI, check_reserved=['all'])
        self.auth = Auth(self.db)
        self.auth.define_tables(username=True, signature=False)
        self.db.define_table('t0', Field('tt'), self.auth.signature)
        self.auth.enable_record_versioning(self.db)
        # Create a user
        self.db.auth_user.insert(first_name='Bart',
                                 last_name='Simpson',
                                 username='user1',
                                 email='[email protected]',
                                 password='password_123',
                                 registration_key=None,
                                 registration_id=None)

        self.db.commit()
開發者ID:cccaballero,項目名稱:web2py,代碼行數:32,代碼來源:test_sqlhtml.py

示例3: setup_clean_session

# 需要導入模塊: from gluon.globals import Session [as 別名]
# 或者: from gluon.globals.Session import connect [as 別名]
def setup_clean_session():
        request = Request(env={})
        request.application = 'a'
        request.controller = 'c'
        request.function = 'f'
        request.folder = 'applications/admin'
        response = Response()
        session = Session()
        session.connect(request, response)
        from gluon.globals import current
        current.request = request
        current.response = response
        current.session = session
        return current
開發者ID:Pac23,項目名稱:book2-exercises,代碼行數:16,代碼來源:test_globals.py

示例4: testRun

# 需要導入模塊: from gluon.globals import Session [as 別名]
# 或者: from gluon.globals.Session import connect [as 別名]
    def testRun(self):
        # setup
        request = Request(env={})
        request.application = 'a'
        request.controller = 'c'
        request.function = 'f'
        request.folder = 'applications/admin'
        response = Response()
        session = Session()
        T = translator('', 'en')
        session.connect(request, response)
        from gluon.globals import current
        current.request = request
        current.response = response
        current.session = session
        current.T = T
        db = DAL(DEFAULT_URI, check_reserved=['all'])
        auth = Auth(db)
        auth.define_tables(username=True, signature=False)
        self.assertTrue('auth_user' in db)
        self.assertTrue('auth_group' in db)
        self.assertTrue('auth_membership' in db)
        self.assertTrue('auth_permission' in db)
        self.assertTrue('auth_event' in db)
        db.define_table('t0', Field('tt'), auth.signature)
        auth.enable_record_versioning(db)
        self.assertTrue('t0_archive' in db)
        for f in ['login', 'register', 'retrieve_password',
                  'retrieve_username']:
            html_form = getattr(auth, f)().xml()
            self.assertTrue('name="_formkey"' in html_form)

        for f in ['logout', 'verify_email', 'reset_password',
                  'change_password', 'profile', 'groups']:
            self.assertRaisesRegexp(HTTP, "303*", getattr(auth, f))

        self.assertRaisesRegexp(HTTP, "401*", auth.impersonate)

        try:
            for t in ['t0_archive', 't0', 'auth_cas', 'auth_event',
                      'auth_membership', 'auth_permission', 'auth_group',
                      'auth_user']:
                db[t].drop()
        except SyntaxError as e:
            # GAE doesn't support drop
            pass
        return
開發者ID:bbertka,項目名稱:benbertka-heroku,代碼行數:49,代碼來源:test_tools.py

示例5: setUp

# 需要導入模塊: from gluon.globals import Session [as 別名]
# 或者: from gluon.globals.Session import connect [as 別名]
 def setUp(self):
     from gluon.globals import Request, Response, Session, current
     from gluon.html import A, DIV, FORM, MENU, TABLE, TR, INPUT, URL, XML
     from gluon.html import ASSIGNJS
     from gluon.validators import IS_NOT_EMPTY
     from gluon.compileapp import LOAD
     from gluon.http import HTTP, redirect
     from gluon.tools import Auth
     from gluon.sql import SQLDB
     from gluon.sqlhtml import SQLTABLE, SQLFORM
     self.original_check_credentials = fileutils.check_credentials
     fileutils.check_credentials = fake_check_credentials
     request = Request(env={})
     request.application = 'welcome'
     request.controller = 'appadmin'
     request.function = self._testMethodName.split('_')[1]
     request.folder = 'applications/welcome'
     request.env.http_host = '127.0.0.1:8000'
     request.env.remote_addr = '127.0.0.1'
     response = Response()
     session = Session()
     T = TranslatorFactory('', 'en')
     session.connect(request, response)
     current.request = request
     current.response = response
     current.session = session
     current.T = T
     db = DAL(DEFAULT_URI, check_reserved=['all'])
     auth = Auth(db)
     auth.define_tables(username=True, signature=False)
     db.define_table('t0', Field('tt'), auth.signature)
     # Create a user
     db.auth_user.insert(first_name='Bart',
                         last_name='Simpson',
                         username='user1',
                         email='[email protected]',
                         password='password_123',
                         registration_key=None,
                         registration_id=None)
     self.env = locals()
開發者ID:leonelcamara,項目名稱:web2py,代碼行數:42,代碼來源:test_appadmin.py

示例6: wsgibase

# 需要導入模塊: from gluon.globals import Session [as 別名]
# 或者: from gluon.globals.Session import connect [as 別名]

#.........這裏部分代碼省略.........
                # ##################################################
                # build missing folders
                # ##################################################

                create_missing_app_folders(request)

                # ##################################################
                # get the GET and POST data
                # ##################################################

                #parse_get_post_vars(request, environ)

                # ##################################################
                # expose wsgi hooks for convenience
                # ##################################################

                request.wsgi = LazyWSGI(environ, request, response)

                # ##################################################
                # load cookies
                # ##################################################

                if env.http_cookie:
                    try:
                        request.cookies.load(env.http_cookie)
                    except Cookie.CookieError, e:
                        pass  # invalid cookies

                # ##################################################
                # try load session or create new session file
                # ##################################################

                if not env.web2py_disable_session:
                    session.connect(request, response)

                # ##################################################
                # run controller
                # ##################################################

                if global_settings.debugging and app != "admin":
                    import gluon.debug
                    # activate the debugger
                    gluon.debug.dbg.do_debug(mainpyfile=request.folder)

                serve_controller(request, response, session)

            except HTTP, http_response:

                if static_file:
                    return http_response.to(responder, env=env)

                if request.body:
                    request.body.close()

                if hasattr(current,'request'):

                    # ##################################################
                    # on success, try store session in database
                    # ##################################################
                    session._try_store_in_db(request, response)

                    # ##################################################
                    # on success, commit database
                    # ##################################################

                    if response.do_not_commit is True:
開發者ID:2089764,項目名稱:web2py,代碼行數:70,代碼來源:main.py

示例7: TestAuthAPI

# 需要導入模塊: from gluon.globals import Session [as 別名]
# 或者: from gluon.globals.Session import connect [as 別名]
class TestAuthAPI(unittest.TestCase):

    def setUp(self):
        self.request = Request(env={})
        self.request.application = 'a'
        self.request.controller = 'c'
        self.request.function = 'f'
        self.request.folder = 'applications/admin'
        self.response = Response()
        self.session = Session()
        T = translator('', 'en')
        self.session.connect(self.request, self.response)
        from gluon.globals import current
        self.current = current
        self.current.request = self.request
        self.current.response = self.response
        self.current.session = self.session
        self.current.T = T
        self.db = DAL(DEFAULT_URI, check_reserved=['all'])
        self.auth = AuthAPI(self.db)
        self.auth.define_tables(username=True, signature=False)
        # Create a user
        self.auth.table_user().validate_and_insert(first_name='Bart',
                                                   last_name='Simpson',
                                                   username='bart',
                                                   email='[email protected]',
                                                   password='bart_password',
                                                   registration_key='',
                                                   registration_id=''
                                                   )
        self.db.commit()

    def test_login(self):
        result = self.auth.login(**{'username': 'bart', 'password': 'bart_password'})
        self.assertTrue(self.auth.is_logged_in())
        self.assertTrue(result['user']['email'] == '[email protected]')
        self.auth.logout()
        self.assertFalse(self.auth.is_logged_in())
        self.auth.settings.username_case_sensitive = False
        result = self.auth.login(**{'username': 'BarT', 'password': 'bart_password'})
        self.assertTrue(self.auth.is_logged_in())

    def test_logout(self):
        self.auth.login(**{'username': 'bart', 'password': 'bart_password'})
        self.assertTrue(self.auth.is_logged_in())
        result = self.auth.logout()
        self.assertTrue(not self.auth.is_logged_in())
        self.assertTrue(result['user'] is None)

    def test_register(self):
        self.auth.settings.login_after_registration = True
        result = self.auth.register(**{
            'username': 'lisa',
            'first_name': 'Lisa',
            'last_name': 'Simpson',
            'email': '[email protected]',
            'password': 'lisa_password'
        })
        self.assertTrue(result['user']['email'] == '[email protected]')
        self.assertTrue(self.auth.is_logged_in())
        with self.assertRaises(AssertionError):  # Can't register if you're logged in
            result = self.auth.register(**{
                'username': 'lisa',
                'first_name': 'Lisa',
                'last_name': 'Simpson',
                'email': '[email protected]',
                'password': 'lisa_password'
            })
        self.auth.logout()
        self.auth.settings.login_after_registration = False
        result = self.auth.register(**{
            'username': 'barney',
            'first_name': 'Barney',
            'last_name': 'Gumble',
            'email': '[email protected]',
            'password': 'barney_password'
        })
        self.assertTrue(result['user']['email'] == '[email protected]')
        self.assertFalse(self.auth.is_logged_in())
        self.auth.settings.login_userfield = 'email'
        result = self.auth.register(**{
            'username': 'lisa',
            'first_name': 'Lisa',
            'last_name': 'Simpson',
            'email': '[email protected]',
            'password': 'lisa_password'
        })
        self.assertTrue(result['errors']['email'] == self.auth.messages.email_taken)
        self.assertTrue(result['user'] is None)
        self.auth.settings.registration_requires_verification = True
        result = self.auth.register(**{
            'username': 'homer',
            'first_name': 'Homer',
            'last_name': 'Simpson',
            'email': '[email protected]',
            'password': 'homer_password'
        })
        self.assertTrue('key' in result['user'])

    def test_profile(self):
#.........這裏部分代碼省略.........
開發者ID:huangyuku,項目名稱:web2py,代碼行數:103,代碼來源:test_authapi.py


注:本文中的gluon.globals.Session.connect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。