def _module_args(self, *args):

        yield __file__  # autopep main is dropping the first argument

        for module in self.modules:
            yield module_path(module)

        for arg in args:
            yield arg
Beispiel #2
0
def _discover(module, folder=None, walk=True):
    folder = folder or module_path(module)
    for is_folder, filename in _scan(folder):
        if not is_folder:
            yield module, filename
        elif walk and not filename == "__pycache__":
            for args in _discover("%s.%s" % (module, filename),
                                  folder=os.path.join(folder, filename),
                                  walk=walk):
                yield args
    async def get_application(self):

        self.session = create_session(poolsize=1)
        routes = web.RouteTableDef()

        @routes.get("/")
        async def hello(request):
            return web.Response(text="Hello from aiohttp")

        @routes.get("/form")
        @routes.post("/form")
        @aiohttp_wl_view(self.session)
        async def form_view(request):
            return wl.FormFunction({"x": "String"}, wl.Identity, "JSON")

        @routes.get("/api")
        @routes.post("/api")
        @aiohttp_wl_view(self.session)
        async def api_view(request):
            return wl.APIFunction({"x": "String"}, wl.Identity, "JSON")

        @routes.get("/request/{name:.*}")
        @routes.post("/request/{name:.*}")
        @aiohttp_wl_view(self.session)
        async def request_view(request):
            return wl.Delayed(
                wl.HTTPRequestData([
                    "Method", "Scheme", "Domain", "PathString", "QueryString",
                    "FormRules"
                ]),
                "JSON",
            )

        path = module_path("wolframwebengine", "examples", "sampleapp")

        for cached in (True, False):

            root = cached and "/cached" or "/app"
            view = create_view(
                session=self.session,
                path=path,
                cached=cached,
                path_extractor=lambda request, l=len(root): request.path[l:],
                index="index.wl",
            )

            routes.get(root + "{name:.*}")(view)
            routes.post(root + "{name:.*}")(view)

        app = web.Application()
        app.add_routes(routes)

        return app
Beispiel #4
0
    def test_sample_explorer(self):

        folder = module_path("wolframwebengine", "examples", "sampleapp")

        for path, resolved in (
            ("/", "index.wl"),
            ("/random.wl", "random.wl"),
            ("/foo/bar/", "foo/bar/index.wl"),
            ("/foo/", "foo/index.wl"),
            ("/foo/bar/index.wl", "foo/bar/index.wl"),
            ("/foo/bar/something.wl", "foo/bar/something.wl"),
        ):

            self.assertEqual(get_wl_handler_path_from_folder(folder, path),
                             os.path.join(folder, resolved))
Beispiel #5
0
def path_to_file_in_data_dir(*args):
    return module_path("wolframclient", "tests", "data", *args)
 def demo_path(self, *args):
     return module_path("wolframwebengine", "examples", "demo", *args)