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


Python BaseAdapter.set_folder方法代码示例

本文整理汇总了Python中pydal.base.BaseAdapter.set_folder方法的典型用法代码示例。如果您正苦于以下问题:Python BaseAdapter.set_folder方法的具体用法?Python BaseAdapter.set_folder怎么用?Python BaseAdapter.set_folder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pydal.base.BaseAdapter的用法示例。


在下文中一共展示了BaseAdapter.set_folder方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_environment

# 需要导入模块: from pydal.base import BaseAdapter [as 别名]
# 或者: from pydal.base.BaseAdapter import set_folder [as 别名]
def build_environment(request, response, session, store_current=True):
    """
    Build the environment dictionary into which web2py files are executed.
    """
    #h,v = html,validators
    environment = dict(_base_environment_)

    if not request.env:
        request.env = Storage()
    # Enable standard conditional models (i.e., /*.py, /[controller]/*.py, and
    # /[controller]/[function]/*.py)
    response.models_to_run = [
        r'^\w+\.py$',
        r'^%s/\w+\.py$' % request.controller,
        r'^%s/%s/\w+\.py$' % (request.controller, request.function)
        ]

    t = environment['T'] = translator(os.path.join(request.folder,'languages'),
                                      request.env.http_accept_language)
    c = environment['cache'] = Cache(request)

    if store_current:
        current.globalenv = environment
        current.request = request
        current.response = response
        current.session = session
        current.T = t
        current.cache = c

    global __builtins__
    if is_jython:  # jython hack
        __builtins__ = mybuiltin()
    elif is_pypy:  # apply the same hack to pypy too
        __builtins__ = mybuiltin()
    else:
        __builtins__['__import__'] = __builtin__.__import__  # WHY?
    environment['request'] = request
    environment['response'] = response
    environment['session'] = session
    environment['local_import'] = \
        lambda name, reload=False, app=request.application:\
        local_import_aux(name, reload, app)
    BaseAdapter.set_folder(pjoin(request.folder, 'databases'))
    response._view_environment = copy.copy(environment)
    custom_import_install()
    return environment
开发者ID:pk359,项目名称:web2py,代码行数:48,代码来源:compileapp.py

示例2: main_wsgi_app

# 需要导入模块: from pydal.base import BaseAdapter [as 别名]
# 或者: from pydal.base.BaseAdapter import set_folder [as 别名]
def main_wsgi_app(environ, start_response):
    import gluon
    common_context = {key:getattr(gluon,key) for key in dir(gluon)}
    have_databases = False
    try:
        try:
            current.request = request = Request(environ)
            response = session = None
            request_folder = request.folder           
            # if client requested a static page
            if request.controller == 'static':
                current.response = None
                current.session = None
                static_folder =  os_path_join(request_folder,'static')
                n = 3 if request.items[2].startswith('_') else 2
                filename = os_path_join(static_folder,*request.items[n:])
                if not filename.startswith(static_folder+'/'): raise HTTP(404)
                if not os_path_exists(filename): raise HTTP(404)
                stream_file_or_304_or_206(filename, environ=environ) # raise HTTP 200
            # if instead client requested a dynamic page
            else:
                # build context and inject variables into context
                runner = CodeRunner(common_context.copy())
                # inject request specific variables into context
                runner.context['request'] = request
                runner.context['response'] = current.response = response = Response()
                runner.context['session'] = current.session = session = Session()
                runner.context['T'] = current.T = translator(
                    os_path_join(request_folder,'languages'),
                    request.environ.get('HTTP_ACCEPT_LANGUAGE'))
                # check if there is a database folder and set the folder
                database_folder =  os_path_join(request_folder,'databases')
                have_databases = os_path_exists(database_folder)
                if have_databases:
                    BaseAdapter.set_folder(os_path_join(request_folder, 'databases'))
                # raise an error if the controller file is missing
                controllers_folder = os_path_join(request_folder,'controllers') 
                controller_filename = os_path_join(controllers_folder,request.controller+'.py')
                if not controller_filename.startswith(controllers_folder+'/'): raise HTTP(404)
                if not os_path_exists(controller_filename): raise HTTP(404)
                # import models, ugly but faster than glob
                models_folder = os_path_join(request_folder,'models')
                if os_path_exists(models_folder):
                    for filename in sorted(filter(lambda x: x[-3:]=='.py',os.listdir(models_folder))): 
                        runner.import_code(models_folder+os.sep+filename)
                # run controller action
                view_context = runner.context.copy()
                content = runner.import_code(controller_filename, request.function)
                # optionally run view
                func_ext = request.function+'.'+request.extension
                if isinstance(content, dict):
                    view_context.update(content)
                    template_folder = os_path_join(request_folder,'views')
                    # maybe a response.view is specified
                    if response.view:
                        template_filename = os_path_join(template_folder,response.view)
                    # or maybe not
                    else:
                        template_filename = os_path_join(template_folder,request.controller,func_ext)
                    # if the view exists use it
                    if os_path_exists(template_filename):
                        content = render(filename=template_filename, path = template_folder, context = view_context)
                    # else but represent the context as a dict (generic views?)
                    else:
                        content = repr(view_context)
                # set the content type
                response.headers["Content-type"] = contenttype(func_ext)                
                raise HTTP(response.status, content, headers=response.headers)
        # if a HTTP is raised, everything is ok, return
        except HTTP, http:       
            if response:
                # commit databases, if any
                have_databases = have_databases and response.auto_commit
                if have_databases:
                    session._try_store_in_db(request, response)
                    BaseAdapter.close_all_instances('commit')
                    have_databases = False
                # save session, if changed
                session._try_store_in_cookie_or_file(request, response)
                # deal with cookies
                if hasattr(response,'_cookies'):
                    http.cookies2headers(response.cookies)
            return http.to(start_response, env=environ)
        # there was an error
        except Exception, err: 
            # maybe log the ticket
            if isinstance(err, RestrictedError):
                ticket = err.log(request)
            # or maybe not
            else:
                print traceback.format_exc()
                #request.logger.error(traceback.format_exc())
                ticket = 'unknown'
            # return HTTP 500
            return  HTTP(500, ticket).to(start_response, env=environ)
开发者ID:Salmista-94,项目名称:web3py,代码行数:97,代码来源:main.py

示例3: build_environment

# 需要导入模块: from pydal.base import BaseAdapter [as 别名]
# 或者: from pydal.base.BaseAdapter import set_folder [as 别名]
def build_environment(request, response, session, store_current=True):
    """
    Build the environment dictionary into which web2py files are executed.
    """
    # h,v = html,validators
    environment = dict(_base_environment_)

    if not request.env:
        request.env = Storage()
    # Enable standard conditional models (i.e., /*.py, /[controller]/*.py, and
    # /[controller]/[function]/*.py)
    response.models_to_run = [
        r'^\w+\.py$',
        r'^%s/\w+\.py$' % request.controller,
        r'^%s/%s/\w+\.py$' % (request.controller, request.function)
        ]

    T = environment['T'] = TranslatorFactory(pjoin(request.folder, 'languages'),
                                             request.env.http_accept_language)
    c = environment['cache'] = Cache(request)

    # configure the validator to use the t translator
    Validator.translator = staticmethod(lambda text: None if text is None else str(T(text)))

    if store_current:
        current.globalenv = environment
        current.request = request
        current.response = response
        current.session = session
        current.T = T
        current.cache = c

    if global_settings.is_jython:
        # jython hack
        class mybuiltin(object):
            """
            NOTE could simple use a dict and populate it,
            NOTE not sure if this changes things though if monkey patching import.....
            """
            # __builtins__
            def __getitem__(self, key):
                try:
                    return getattr(builtin, key)
                except AttributeError:
                    raise KeyError(key)

            def __setitem__(self, key, value):
                setattr(self, key, value)

        global __builtins__
        __builtins__ = mybuiltin()

    environment['request'] = request
    environment['response'] = response
    environment['session'] = session
    environment['local_import'] = \
        lambda name, reload=False, app=request.application:\
        local_import_aux(name, reload, app)
    BaseAdapter.set_folder(pjoin(request.folder, 'databases'))
    custom_import_install()
    return environment
开发者ID:web2py,项目名称:web2py,代码行数:63,代码来源:compileapp.py


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