Esempio n. 1
0
    def test_01_decode_path(self):
        self.assertEqual(
            decoder.decode_path("/test/"),
            ("test",[])
        )

        self.assertEqual(
            decoder.decode_path("/test"),
            ("test",[])
        )

        self.assertEqual(
            decoder.decode_path("test/"),
            ("test",[])
        )

        self.assertEqual(
            decoder.decode_path("test"),
            ("test",[])
        )

        self.assertEqual(
            decoder.decode_path("/request/a/b/c"),
            ("request",["a","b","c"])
        )

        self.assertEqual(
            decoder.decode_path("/debug/a/b/c"),
            ("debug",["a","b","c"])
        )

        self.assertEqual(
            decoder.decode_path("/debugxxx/a/b/c"),
            ("request",["debugxxx","a","b","c"])
        )

        self.assertEqual(
            decoder.decode_path("/odeckmyn/tags/python+zope"),
            ("request",["odeckmyn","tags","python+zope"])
        )

        self.assertEqual(
            decoder.decode_path(""),
            ("request",[])
        )
Esempio n. 2
0
    def _serve(self, send=1):
        f=StringIO()
        (operation, params)=decoder.decode_path(self.path)

        # Run the exec_<operation> method now
        mname = 'exec_' + operation
        if not hasattr(self, mname):
            self.send_error(501, _("Unknown operation (%s)") % `operation`)
            return
        method = getattr(self, mname)
        method(f,params)

        length=f.tell()
        f.seek(0)
        self.send_response(200)
        self.send_header("Content-type", "text/plain")
        self.send_header("Content-Length", str(length))
        self.end_headers()
        if send:
            shutil.copyfileobj(f, self.wfile)
        f.close()