• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python resources.get函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中aspen.resources.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: redirect_confirmation

def redirect_confirmation(website, request):
    from aspen import resources
    request.internally_redirected_from = request.fs
    request.fs = website.www_root + '/on/confirm.html.spt'
    request.resource = resources.get(request)

    raise request.resource.respond(request)
开发者ID:BastianBerndsen,项目名称:www.gittip.com,代码行数:7,代码来源:__init__.py


示例2: handler

    def handler(self, request):
        """Given an Aspen request, return an Aspen response.

        The default handler uses Resource subclasses to generate responses from
        simplates on the filesystem. See aspen/resources/__init__.py.

        You can monkey-patch this method to implement single-page web apps or
        other things in configure-aspen.py:

            from aspen import Response

            def greetings_program(website, request):
                return Response(200, "Greetings, program!")

            website.handler = greetings_program

        """
        self.hooks.inbound_early.run(request)
        gauntlet.run(request)  # sets request.fs
        request.socket = sockets.get(request)
        self.hooks.inbound_late.run(request)

        # Look for a Socket.IO socket (http://socket.io/).
        if isinstance(request.socket, Response):    # handshake
            response = request.socket
            request.socket = None
        elif request.socket is None:                # non-socket
            request.resource = resources.get(request)
            response = request.resource.respond(request)
        else:                                       # socket
            response = request.socket.respond(request)
        return response
开发者ID:allisonmobley,项目名称:aspen,代码行数:32,代码来源:website.py


示例3: handle

    def handle(self, request):
        """Given an Aspen request, return an Aspen response.

        Aspen uses Resource subclasses to generate responses. See
        aspen/resources/__init__.py.

        """
        try:
            try:
                self.copy_configuration_to(request)
                request.website = self

                self.hooks.run('inbound_early', request)
                gauntlet.run(request) # sets request.fs
                request.socket = sockets.get(request)
                self.hooks.run('inbound_late', request)

                # Look for a Socket.IO socket (http://socket.io/).
                if isinstance(request.socket, Response):    # handshake
                    response = request.socket
                    request.socket = None
                elif request.socket is None:                # non-socket
                    request.resource = resources.get(request)
                    response = request.resource.respond(request)
                else:                                       # socket
                    response = request.socket.respond(request)
            except:
                response = self.handle_error_nicely(request)
        except Response, response:
            # Grab the response object in the case where it was raised.  In the
            # case where it was returned, response is set in a try block above.
            pass
开发者ID:berryp,项目名称:aspen,代码行数:32,代码来源:website.py


示例4: handle_error_nicely

    def handle_error_nicely(self, tb_1, request):

        response = sys.exc_info()[1]

        if not isinstance(response, Response):

            # We have a true Exception; convert it to a Response object.

            response = Response(500, tb_1)
            response.request = request

        if 200 <= response.code < 300:

            # The app raised a Response(2xx). Act as if nothing
            # happened. This is unusual but allowed.

            pass

        else:

            # Delegate to any error simplate.
            # ===============================

            fs = self.ours_or_theirs(str(response.code) + '.html')
            if fs is None:
                fs = self.ours_or_theirs('error.html')
            if fs is not None:
                request.fs = fs
                request.original_resource = request.resource
                request.resource = resources.get(request)
                response = request.resource.respond(request, response)

        return response
开发者ID:joonas,项目名称:aspen,代码行数:33,代码来源:website.py


示例5: handle

    def handle(self, request):
        """Given an Aspen request, return an Aspen response.

        By default we use Resource subclasses to generate responses from
        simplates on the filesystem. See aspen/resources/__init__.py.

        You can monkey-patch this method to implement single-page web apps or
        other things in configure-aspen.py:

            from aspen import Response

            def greetings_program(website, request):
                return Response(200, "Greetings, program!")

            website.handle = greetings_program

        Unusual but allowed.

        """
        # Look for a Socket.IO socket (http://socket.io/).
        if isinstance(request.socket, Response):    # handshake
            response = request.socket
            request.socket = None
        elif request.socket is None:                # non-socket
            request.resource = resources.get(request)
            response = request.resource.respond(request)
        else:                                       # socket
            response = request.socket.respond(request)
        response.request = request
        return response
开发者ID:joonas,项目名称:aspen,代码行数:30,代码来源:website.py


示例6: delegate_error_to_simplate

def delegate_error_to_simplate(website, state, response, request=None, resource=None):
    if request is None:
        return  # early parsing must've failed
    if response.code < 400:
        return

    code = str(response.code)
    possibles = [code + ".spt", "error.spt"]
    fspath = _first(website.ours_or_theirs(errpage) for errpage in possibles)

    if fspath is not None:
        request.original_resource = resource
        resource = resources.get(website.request_processor, fspath)
        state['dispatch_result'] = DispatchResult( DispatchStatus.okay
                                                 , fspath
                                                 , {}
                                                 , 'Found.'
                                                 , {}
                                                 , True
                                                  )
        # Try to return an error that matches the type of the response the
        # client would have received if the error didn't occur
        wanted = getattr(state.get('output'), 'media_type', None) or ''
        # If we don't have a media type (e.g. when we're returning a 404), then
        # we fall back to the Accept header
        wanted += ',' + (state.get('accept_header') or '')
        # As a last resort we accept anything, with a preference for text/plain
        wanted += ',text/plain;q=0.2,*/*;q=0.1'
        state['accept_header'] = wanted.lstrip(',')

        render_response(state, resource, response, website.request_processor)
开发者ID:AspenWeb,项目名称:pando.py,代码行数:31,代码来源:state_chain.py


示例7: handle_error_nicely

 def handle_error_nicely(self, request):
     """Try to provide some nice error handling.
     """
     try:                        # nice error messages
         tb_1 = traceback.format_exc()
         response = sys.exc_info()[1]
         if not isinstance(response, Response):
             aspen.log_dammit(tb_1)
             response = Response(500, tb_1)
         elif 200 <= response.code < 300:
             return response
         response.request = request
         self.hooks.outbound_early.run(response)
         fs = self.ours_or_theirs(str(response.code) + '.html')
         if fs is None:
             fs = self.ours_or_theirs('error.html')
         if fs is None:
             raise
         request.fs = fs
         request.original_resource = request.resource
         request.resource = resources.get(request)
         response = request.resource.respond(request, response)
         return response
     except Response, response:  # no nice error simplate available
         raise
开发者ID:allisonmobley,项目名称:aspen,代码行数:25,代码来源:website.py


示例8: load_simplate

 def load_simplate(self, path, request=None, return_request_too=False):
     """Given an URL path, return a simplate (Resource) object.
     """
     if request is None:
         request = Request(uri=path)
     if not hasattr(request, 'website'):
         request.website = self
     self.do_inbound(request)
     resource = resources.get(request)
     if return_request_too:
         return resource, request
     else:
         return resource
开发者ID:joonas,项目名称:aspen,代码行数:13,代码来源:website.py


示例9: load_simplate

def load_simplate(path):
    """Given an URL path, return resource.
    """
    request = StubRequest(path)
    request.website = test_website

    # XXX HACK - aspen.website should be refactored
    from aspen import dispatcher, sockets
    test_website.hooks.run('inbound_early', request)
    dispatcher.dispatch(request)  # sets request.fs
    request.socket = sockets.get(request)
    test_website.hooks.run('inbound_late', request)

    return resources.get(request)
开发者ID:berryp,项目名称:www.gittip.com,代码行数:14,代码来源:__init__.py


示例10: __init__

    def __init__(self, request, channel):
        """Takes the handshake request and the socket's channel.
        """
        self.sid = uuid.uuid4().hex
        self.endpoint = request.line.uri.path.decoded
        self.resource = resources.get(request)

        self.website = request.website
        self.loop = request.website.network_engine.Loop(self)
        self.incoming = request.website.network_engine.Buffer('incoming', self)
        self.outgoing = request.website.network_engine.Buffer('outgoing', self)
        self.channel = channel
        self.channel.add(self)
        self.context = self.resource.exec_second(self, request)
开发者ID:BigBlueHat,项目名称:aspen-python,代码行数:14,代码来源:socket.py


示例11: __init__

    def __init__(self, request, channel):
        """Takes the handshake request and the socket's channel.
        """
        self.sid = uuid.uuid4().hex
        self.endpoint = request.path.raw
        self.resource = resources.get(request)
        request.website.copy_configuration_to(self)
        request.website.copy_configuration_to(channel)

        self.loop = request.engine.Loop(self)
        self.incoming = request.engine.Buffer('incoming', self)
        self.outgoing = request.engine.Buffer('outgoing', self)
        self.channel = channel
        self.channel.add(self)
        self.namespace = self.resource.exec_second(self, request)
开发者ID:berryp,项目名称:aspen,代码行数:15,代码来源:socket.py


示例12: delegate_error_to_simplate

def delegate_error_to_simplate(website, request, response):
    if response.code < 400:
        return

    code = str(response.code)
    possibles = [code + ".html", code + ".html.spt", "error.html", "error.html.spt"]
    fs = _first(website.ours_or_theirs(errpage) for errpage in possibles)

    if fs is not None:
        request.fs = fs
        request.original_resource = request.resource
        resource = resources.get(request)
        response = resource.respond(request, response)

    return {'response': response, 'exception': None}
开发者ID:joeyespo,项目名称:aspen-python,代码行数:15,代码来源:website.py


示例13: compile_assets

def compile_assets(website):
    cleanup = []
    for spt in find_files(website.www_root+'/assets/', '*.spt'):
        filepath = spt[:-4]  # /path/to/www/assets/foo.css
        if not os.path.exists(filepath):
            cleanup.append(filepath)
        dispatch_result = DispatchResult(DispatchStatus.okay, spt, {}, "Found.", {}, True)
        state = dict(dispatch_result=dispatch_result, response=Response())
        state['state'] = state
        content = resources.get(website, spt).respond(state).body
        if not isinstance(content, bytes):
            content = content.encode('utf8')
        tmpfd, tmpfpath = mkstemp(dir='.')
        os.write(tmpfd, content)
        os.close(tmpfd)
        os.rename(tmpfpath, filepath)
    atexit.register(lambda: rm_f(*cleanup))
开发者ID:CryptArc,项目名称:liberapay.com,代码行数:17,代码来源:http_caching.py


示例14: handle_error_nicely

    def handle_error_nicely(self, tb_1, request):

        response = sys.exc_info()[1]

        if not isinstance(response, Response):

            # We have a true Exception; convert it to a Response object.

            response = Response(500, tb_1)
            response.request = request

        if 500 <= response.code < 600:
            # Log tracebacks for Reponse(5xx).
            aspen.log_dammit(tb_1)

            # TODO Switch to the logging module and use something like this:
            # log_level = [DEBUG,INFO,WARNING,ERROR][(response.code/100)-2]
            # logging.log(log_level, tb_1)

        if 200 <= response.code < 300 or response.code == 304:

            # The app raised a Response(2xx) or Response(304).
            # Act as if nothing happened. This is unusual but allowed.

            pass

        else:

            # Delegate to any error simplate.
            # ===============================

            rc = str(response.code)
            possibles = [ rc + ".html", rc + ".html.spt", "error.html", "error.html.spt" ]
            fs = first( self.ours_or_theirs(errpage) for errpage in possibles )

            if fs is not None:
                request.fs = fs
                request.original_resource = request.resource
                request.resource = resources.get(request)
                response = request.resource.respond(request, response)

        return response
开发者ID:nejstastnejsistene,项目名称:aspen-python,代码行数:42,代码来源:website.py


示例15: delegate_error_to_simplate

def delegate_error_to_simplate(website, request, response, resource=None):
    if response.code < 400:
        return

    code = str(response.code)
    possibles = [code + ".spt", "error.spt"]
    fs = _first(website.ours_or_theirs(errpage) for errpage in possibles)

    if fs is not None:
        request.fs = fs
        request.original_resource = resource
        if resource is not None:
            # Try to return an error that matches the type of the original resource.
            request.headers['Accept'] = resource.media_type + ', text/plain; q=0.1'
        resource = resources.get(request)
        try:
            response = resource.respond(request, response)
        except Response as response:
            if response.code != 406:
                raise

    return {'response': response, 'exception': None}
开发者ID:amitkot,项目名称:aspen-python,代码行数:22,代码来源:website.py


示例16: delegate_error_to_simplate

def delegate_error_to_simplate(website, response, request=None, resource=None):
    if request is None:
        return  # early parsing must've failed
    if response.code < 400:
        return

    code = str(response.code)
    possibles = [code + ".spt", "error.spt"]
    fspath = _first(website.ours_or_theirs(errpage) for errpage in possibles)

    if fspath is not None:
        request.original_resource = resource
        if resource is not None:
            # Try to return an error that matches the type of the original resource.
            request.headers['Accept'] = resource.media_type + ', text/plain; q=0.1'
        resource = resources.get(website, fspath)
        dispatch_result = DispatchResult(DispatchStatus.okay, fspath, {}, 'Found.', {}, True)
        try:
            response = resource.respond(request, dispatch_result, response)
        except Response as response:
            if response.code != 406:
                raise

    return {'response': response, 'exception': None}
开发者ID:Acidburn0zzz,项目名称:aspen-python,代码行数:24,代码来源:website.py


示例17: get_resource_for_request

def get_resource_for_request(request):
    return {"resource": resources.get(request)}
开发者ID:pombredanne,项目名称:aspen,代码行数:2,代码来源:website.py


示例18: get_simplate_context

def get_simplate_context(website, fs):
    resource = resources.get(website, fs)
    return {} if isinstance(resource, StaticResource) else resource.pages[0]
开发者ID:meldfunction,项目名称:inside.gratipay.com,代码行数:3,代码来源:nav.py


示例19: get_resource_for_request

def get_resource_for_request(request, response):
    if response is None:
        return {'resource': resources.get(request)}
开发者ID:joeyespo,项目名称:aspen-python,代码行数:3,代码来源:website.py


示例20: get_resource_for_request

def get_resource_for_request(website, request, dispatch_result):
    return {'resource': resources.get(website, dispatch_result.match)}
开发者ID:Acidburn0zzz,项目名称:aspen-python,代码行数:2,代码来源:website.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python message.Message类代码示例发布时间:2022-05-24
下一篇:
Python json.loads函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap