コード例 #1
0
def set_root_path(
    root_path: str,
    app: WSGIApp,
    *endpoints: Type[RepoEndpointBase],
) -> None:
    for endpoint in endpoints:
        app.set_parcel(endpoint, root_path)
コード例 #2
0
ファイル: app.py プロジェクト: jjj999/bamboo
        for no, command, _, func in COMMANDS:
            if request in (no, command):
                func(uris, email)
                break
        else:
            print("一致するコマンドが存在しません.\n")


# --------------------------------------------------------------------------------

if __name__ == "__main__":

    import sys

    uris = Uris(
        "http://localhost:8000/user",
        "http://localhost:8000/tweet",
    )

    user_controller = UserController(UserModel)
    tweet_controller = TweetController(TweetModel)
    app.set_parcel(UserEndpoint, user_controller)
    app.set_parcel(TweetsEndpoint, tweet_controller)

    if len(sys.argv) == 1:
        form = WSGIServerForm("", 8000, app, "app.log")
        executor = WSGITestExecutor(form)
        executor.exec(request_interact, args=(uris, ))
    elif sys.argv[1] == "client":
        request_interact(uris)
コード例 #3
0
            ))


def request_image(uri: str, path_save: str) -> None:
    with http.get(uri, datacls=MockResponse) as res:
        if res.ok:
            data = res.attach()
            print(f"Date time: {data.datetime}")
            print("Saving image in the response...")
            with open(path_save, "wb") as f:
                f.write(decode2binary(data.image))
        else:
            print("Request failed.", end="\n\n")
            print("headers")
            print("-------")
            for key, val in res.headers.items():
                print(f"{key} : {val}")


if __name__ == "__main__":
    me = "hoge"
    URI = f"http://localhost:8000/{me}/image"
    PATH_IMAGE = "elephant.jpg"
    PATH_SAVE = "received.jpg"

    app.set_parcel(MockServeImageEndpoint, PATH_IMAGE)

    form = WSGIServerForm("", 8000, app, "image_traffic.log")
    executer = WSGITestExecutor(form)
    executer.exec(request_image, (URI, PATH_SAVE))