Beispiel #1
0
 def __on_exception(website, request):
     response = Response(500)
     if mode.IS_DEBUGGING or mode.IS_DEVELOPMENT:
         response.body = traceback.format_exc()
     if website.__hooks['exception'] is not None:
         for func in website.__hooks['exception']:
             response = func(website, request, response)
             if response is None:
                 raise HookError, "An exception hook returned None."
     return response
Beispiel #2
0
 def __on_exception(website, request):
     response = Response(500)
     if mode.IS_DEBUGGING or mode.IS_DEVELOPMENT:
         response.body = traceback.format_exc()
     for plugin in website.__hooks['exception']:
         try:
             exec plugin.hooks['exception']
         except SystemExit:
             pass
     return response
Beispiel #3
0
    def respond(self, request):
        """Serve a static file off of the filesystem.

        In staging and deployment modes, we honor any 'If-Modified-Since'
        header, an HTTP header used for caching.

        """

        fs_path = self.translate(request.path)
        fs_path = self.validate(request.path, fs_path)
        fs_path = self.find_default(fs_path)

        ims = request.headers.get('If-Modified-Since', '')

        # Get basic info from the filesystem and start building a response.
        # =================================================================

        stats = os.stat(fs_path)
        mtime = stats[stat.ST_MTIME]
        size = stats[stat.ST_SIZE]
        content_type = mimetypes.guess_type(fs_path)[0] or 'text/plain'
        response = Response(200)

        # Support 304s, but only in deployment mode.
        # ==========================================

        if mode.IS_DEPLOYMENT or mode.IS_STAGING:
            if ims:
                mod_since = rfc822.parsedate(ims)
                last_modified = time.gmtime(mtime)
                if last_modified[:6] <= mod_since[:6]:
                    response.code = 304

        # Finish building the response and return it.
        # ===========================================

        response.headers['Last-Modified'] = rfc822.formatdate(mtime)
        response.headers['Content-Type'] = content_type
        response.headers['Content-Length'] = size
        if response.code != 304:
            response.body = open(fs_path).read()
        return response
Beispiel #4
0
 def respond(self, request):
     response = Response(200, "Greetings, program!")
     response.body = Response(200, "Greetings, program!")
     raise response