コード例 #1
0
 def testNotThereRaisesNotFound(self):
     self.assertRaises(Response, uri_to_fs, self.site_root, self.fs_root,
                       self.uri_root, '/not-there', ())
     try:
         uri_to_fs(self.site_root, self.fs_root, self.uri_root,
                   '/not-there', ('index.html', ))
     except Response, response:
         self.assertEqual(response.code, 404)
コード例 #2
0
 def testNoDefaultRaisesForbidden(self):
     self.assertRaises(Response, uri_to_fs, self.site_root, self.fs_root,
                       self.uri_root, '/about/', ('index.html', ))
     try:
         uri_to_fs(self.site_root, self.fs_root, self.uri_root, '/',
                   ('index.html', ))
     except Response, response:
         self.assertEqual(response.code, 403)
コード例 #3
0
 def testNoTrailingSlashIsRedirected(self):
     self.assertRaises(Response, uri_to_fs, self.site_root, self.fs_root,
                       self.uri_root, '/about', ())
     try:
         uri_to_fs(self.site_root, self.fs_root, self.uri_root, '/about',
                   ())
     except Response, response:
         self.assertEqual(response.code, 301)
         self.assertEqual(response.headers['Location'], '/about/')
コード例 #4
0
    def validate(self):
        """Hook for late validation so we can use Response.
        """

        resource_fs_path = uri_to_fs(self.app.site_root,
                                     self.app.fs_root,
                                     self.app.uri_root,
                                     self.request.path,
                                     raw=True)

        # Is the app still on the filesystem?
        if not os.path.isdir(self.app.fs_root):
            raise Response(404)

        if self.server.config.__:

            # Is the site's magic directory still on the filesystem?
            if self.server.config.__:
                if not os.path.isdir(self.server.config.__):
                    raise Response(
                        500,
                        "The site's magic directory has " + "disappeared.")

            # Protect the magic directory from direct access, but make sure we
            # can serve a default app.py from there.
            if resource_fs_path.startswith(self.server.config.__):
                app_py = os.path.join(self.server.config.__, 'app.py')
                if not resource_fs_path == app_py:
                    raise Response(404)
コード例 #5
0
 def testDefaultDocument(self):
     expected = os.path.realpath(self.convert_path('root/index.html'))
     actual = uri_to_fs( self.config
                       , '/'
                       , ('index.html',)
                        )
     self.assertEqual(expected, actual)
コード例 #6
0
 def testBasic(self):
     expected = os.path.realpath(self.convert_path('root/index.html'))
     actual = uri_to_fs( self.config
                       , '/index.html'
                       , ()
                        )
     self.assertEqual(expected, actual)
コード例 #7
0
ファイル: Task.py プロジェクト: chadwhitacre/public
    def process(self):
        """Execute one transaction.

        The call to Transaction.process is complicated by the fact that in
        development mode we want to drop into the post-mortem debugger when
        there is an exception (other than Response, of course).

        Transaction.process is expected to raise a Response or other exception.

        """

        config = TransactionConfig(self.app, self.server_config)

        # Do some late validation so we can use Response.
        # ===============================================

        resource_fs_path = uri_to_fs(config, self.request.path, raw=True)

        # Is the app still on the filesystem?
        if not os.path.isdir(config.app_fs_root):
            raise Response(404)

        if config.__:

            # Is the app's magic directory still on the filesystem?
            if not os.path.isdir(config.__):
                response = Response(500)
                response.body = ("The application's magic directory has " +
                                 "disappeared.")
                raise response

            # Protect the magic directory from direct access.
            if resource_fs_path.startswith(config.__):
                raise Response(404)

        # Get out of the way.
        # ===================

        transaction = self.app.module.Transaction(config)
        if not self.dev_mode:
            transaction.process(self.request)
        else:
            try:
                transaction.process(self.request)
            except Response:
                raise
            except:
                log(90, traceback.format_exc())
                pdb.post_mortem(sys.exc_info()[2])
                raise

        # You know something? No soup for you!
        # ====================================

        response = Response(500)
        response.body = "%s.process did not raise anything." % str(transaction)
        raise response
コード例 #8
0
ファイル: DefaultApp.py プロジェクト: chadwhitacre/public
    def process(self, request):
        """Given an httpy.Request, raise an httpy.Response.
        """

        self.request = request
        fs_path = uri_to_fs(config=self.config,
                            resource_uri_path=request.path,
                            defaults=('index.html', 'index.htm'))
        self.serve_static(fs_path)
コード例 #9
0
ファイル: Task.py プロジェクト: chadwhitacre/public
    def respond(self):
        """Execute one transaction.

        The call to Application.respond is complicated by the fact that in
        debugging mode we want to drop into the post-mortem debugger when there
        is an exception (other than Response, of course).

        Application.respond is expected to raise a Response or other exception.

        """

        # Do some late validation so we can use Response.
        # ===============================================

        resource_fs_path = uri_to_fs(self.app.site_root,
                                     self.app.fs_root,
                                     self.app.uri_root,
                                     self.request.path,
                                     raw=True)

        # Is the app still on the filesystem?
        if not os.path.isdir(self.app.fs_root):
            raise Response(404)

        if self.app.__:

            # Is the app's magic directory still on the filesystem?
            if not os.path.isdir(self.app.__):
                raise Response(
                    500,
                    "The application's magic directory has " + "disappeared.")

            # Protect the magic directory from direct access.
            if resource_fs_path.startswith(self.app.__):
                raise Response(404)

        # Get out of the way.
        # ===================

        if not self.server.debug_mode:
            self.app.respond(self.request)
        else:
            try:
                self.app.respond(self.request)
            except Response:
                raise
            except:
                log(90, traceback.format_exc())
                pdb.post_mortem(sys.exc_info()[2])
                raise

        # You know something? No soup for you!
        # ====================================

        raise Response(
            500, "%s.respond did not raise " % str(application) + "anything.")
コード例 #10
0
    def testEtcPasswdGoesUncaughtAtThisStage(self):
        # This test will of course fail if you have it buried deep on your fs.
        expected = self.convert_path('/etc/master.passwd')

        if not os.path.isfile(expected):
            # nevermind
            return

        actual = uri_to_fs(self.site_root, self.fs_root, self.uri_root,
                           '../../../../../../../../../../etc/master.passwd',
                           ())
        self.assertEqual(expected, actual)