diff options
| author | CoprDistGit <infra@openeuler.org> | 2023-05-29 10:23:25 +0000 |
|---|---|---|
| committer | CoprDistGit <infra@openeuler.org> | 2023-05-29 10:23:25 +0000 |
| commit | 46007a45eebe60cc6d88e880edd5601eece642e0 (patch) | |
| tree | 3583c92bd605ba39093af4d613aabaa8c74f2aff /python-sanic-dispatcher.spec | |
| parent | f697da13a6860ef773e63bfd65926f3c98ac8a20 (diff) | |
automatic import of python-sanic-dispatcher
Diffstat (limited to 'python-sanic-dispatcher.spec')
| -rw-r--r-- | python-sanic-dispatcher.spec | 640 |
1 files changed, 640 insertions, 0 deletions
diff --git a/python-sanic-dispatcher.spec b/python-sanic-dispatcher.spec new file mode 100644 index 0000000..4c34969 --- /dev/null +++ b/python-sanic-dispatcher.spec @@ -0,0 +1,640 @@ +%global _empty_manifest_terminate_build 0 +Name: python-Sanic-Dispatcher +Version: 0.8.0.0 +Release: 1 +Summary: Multi-application dispatcher based on DispatcherMiddleware from the Werkzeug Project. +License: MIT +URL: https://github.com/ashleysommer/sanic-dispatcher +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/c9/ad/d6178f101f98dd7c5c6bd3d033212e13912e3a3d96b97406e3d3723f0d29/Sanic-Dispatcher-0.8.0.0.tar.gz +BuildArch: noarch + +Requires: python3-sanic + +%description +# Sanic-Dispatcher +### A Dispatcher extension for Sanic that also acts as a Sanic-to-WSGI adapter + +Allows you to do this: *(seriously)* +```python +from sanic import Sanic, response +from sanic_dispatcher import SanicDispatcherMiddlewareController +from flask import Flask, make_response, current_app as flask_app + +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) + +child_sanic_app = Sanic("MyChildSanicApp") + +child_flask_app = Flask("MyChildFlaskApp") + +@app.middleware("response") +async def modify_response(request, response): + response.body = response.body + b"\nModified by Sanic Response middleware!" + response.headers['Content-Length'] = len(response.body) + return response + +@app.route("/") +async def index(request): + return response.text("Hello World from {}".format(request.app.name)) + +@child_sanic_app.route("/") +async def index(request): + return response.text("Hello World from {}".format(request.app.name)) + +@child_flask_app.route("/") +def index(): + app = flask_app + return make_response("Hello World from {}".format(app.import_name)) + +dispatcher.register_sanic_application(child_sanic_app, '/sanicchild', apply_middleware=True) +dispatcher.register_wsgi_application(child_flask_app.wsgi_app, '/flaskchild', apply_middleware=True) + +if __name__ == "__main__": + app.run(port=8001, debug=True) +``` + +## Installation + + pip install Sanic-Dispatcher + +## How To Use + +First make a Sanic application the way you normally do: +```python +from sanic import Sanic + +app = Sanic(__name__) # This creates a sanic app +``` +`app` becomes your 'base' or 'parent' sanic app which will accommodate the Dispatcher extension + +Create a Dispatcher +```python +from sanic_dispatcher import SanicDispatcherMiddlewareController + +dispatcher = SanicDispatcherMiddlewareController(app) +``` +`dispatcher` is your new dispatcher controller. +*Note: This takes a reference to `app` as its first parameter, but it does not consume `app`, nor does it return `app`.* + +**I want to dispatch another Sanic App** +```python +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) + +otherapp = Sanic("MyChildApp") + +dispatcher.register_sanic_application(otherapp, "/childprefix") + +@otherapp.route('/') +async def index(request): + return response.text("Hello World from Child App") +``` +Browsing to url `/childprefix/` will invoke the `otherapp` App, and call the `/` route which displays "Hello World from Child App" + +**What if the other App is a Flask App?** +```python +from flask import Flask, make_response + +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) +flaskapp = Flask("MyFlaskApp") + +# register the wsgi_app method from the flask app into the dispatcher +dispatcher.register_wsgi_application(flaskapp.wsgi_app, "/flaskprefix") + +@flaskapp.route('/') +def index(): + return make_response("Hello World from Flask App") +``` +Browsing to url `/flaskprefix/` will invoke the Flask App, and call the `/` route which displays "Hello World from Flask App" + +**What if the other App is a Django App?** +```python +import my_django_app + +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) +# register the django wsgi application into the dispatcher +dispatcher.register_wsgi_application(my_django_app.wsgi.application, + "/djangoprefix") +``` +Browsing to url `/djangoprefix/` will invoke the Django App. + +**Can I run a default application?** + +The Sanic App `app` you create at the start is also the default app. + +When you navigate to a URL that does not match a registered dispatch prefix, this Sanic app will handle the request itself as per normal. +```python +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) + +otherapp = Sanic("MyChildApp") + +dispatcher.register_sanic_application(otherapp, "/childprefix") + +@app.route('/') +async def index(request): + return response.text("Hello World from Default App") + +@otherapp.route('/') +async def index(request): + return response.text("Hello World from Child App") +``` +Browsing to url `/` will *not* invoke any Dispatcher applications, so `app` will handle the request itself, resolving the `/` route which displays "Hello World from Default App" + +**I want to apply common middleware to the registered applications!** + +Easy! +```python +import my_django_app +from flask import Flask, make_response, current_app + +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) + +child_sanic_app = Sanic("MyChildSanicApp") + +child_flask_app = Flask("MyChildFlaskApp") + +@app.middleware("request") +async def modify_request(request): + request.headers['Content-Type'] = "text/plain" + +@app.middleware("response") +async def modify_response(request, response): + response.body = response.body + b"\nModified by Sanic Response middleware!" + response.headers['Content-Length'] = len(response.body) + return response + +@app.route("/") +async def index(request): + return response.text("Hello World from {}".format(request.app.name)) + +@child_sanic_app.route("/") +async def index(request): + return response.text("Hello World from {}".format(request.app.name)) + +@child_flask_app.route("/") +def index(): + app = current_app + return make_response("Hello World from {}".format(app.import_name)) + +dispatcher.register_sanic_application(child_sanic_app, + '/childprefix', apply_middleware=True) +dispatcher.register_wsgi_application(my_django_app.wsgi.application, + '/djangoprefix', apply_middleware=True) +dispatcher.register_wsgi_application(child_flask_app.wsgi_app, + '/flaskprefix', apply_middleware=True) +``` +The key here is passing `apply_middleware=True` to the relevant register application function. By default `apply_middleware` is set to `False` for all registered dispatcher applications. + +In this example the Sanic Request Middleware `modify_request` will be applied to ALL requests, including those handled by applications registered on the dispatcher. The request middleware will be applied to the `request` *before* it is passed to any registered applications. + +In this example the Sanic Response Middleware `modify_response` will be applied to ALL responses, including those which were generated by applications registered on the dispatcher. The response middleware will be applied to the `response` *after* it is processed by the registered application. + + + + +%package -n python3-Sanic-Dispatcher +Summary: Multi-application dispatcher based on DispatcherMiddleware from the Werkzeug Project. +Provides: python-Sanic-Dispatcher +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-Sanic-Dispatcher +# Sanic-Dispatcher +### A Dispatcher extension for Sanic that also acts as a Sanic-to-WSGI adapter + +Allows you to do this: *(seriously)* +```python +from sanic import Sanic, response +from sanic_dispatcher import SanicDispatcherMiddlewareController +from flask import Flask, make_response, current_app as flask_app + +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) + +child_sanic_app = Sanic("MyChildSanicApp") + +child_flask_app = Flask("MyChildFlaskApp") + +@app.middleware("response") +async def modify_response(request, response): + response.body = response.body + b"\nModified by Sanic Response middleware!" + response.headers['Content-Length'] = len(response.body) + return response + +@app.route("/") +async def index(request): + return response.text("Hello World from {}".format(request.app.name)) + +@child_sanic_app.route("/") +async def index(request): + return response.text("Hello World from {}".format(request.app.name)) + +@child_flask_app.route("/") +def index(): + app = flask_app + return make_response("Hello World from {}".format(app.import_name)) + +dispatcher.register_sanic_application(child_sanic_app, '/sanicchild', apply_middleware=True) +dispatcher.register_wsgi_application(child_flask_app.wsgi_app, '/flaskchild', apply_middleware=True) + +if __name__ == "__main__": + app.run(port=8001, debug=True) +``` + +## Installation + + pip install Sanic-Dispatcher + +## How To Use + +First make a Sanic application the way you normally do: +```python +from sanic import Sanic + +app = Sanic(__name__) # This creates a sanic app +``` +`app` becomes your 'base' or 'parent' sanic app which will accommodate the Dispatcher extension + +Create a Dispatcher +```python +from sanic_dispatcher import SanicDispatcherMiddlewareController + +dispatcher = SanicDispatcherMiddlewareController(app) +``` +`dispatcher` is your new dispatcher controller. +*Note: This takes a reference to `app` as its first parameter, but it does not consume `app`, nor does it return `app`.* + +**I want to dispatch another Sanic App** +```python +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) + +otherapp = Sanic("MyChildApp") + +dispatcher.register_sanic_application(otherapp, "/childprefix") + +@otherapp.route('/') +async def index(request): + return response.text("Hello World from Child App") +``` +Browsing to url `/childprefix/` will invoke the `otherapp` App, and call the `/` route which displays "Hello World from Child App" + +**What if the other App is a Flask App?** +```python +from flask import Flask, make_response + +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) +flaskapp = Flask("MyFlaskApp") + +# register the wsgi_app method from the flask app into the dispatcher +dispatcher.register_wsgi_application(flaskapp.wsgi_app, "/flaskprefix") + +@flaskapp.route('/') +def index(): + return make_response("Hello World from Flask App") +``` +Browsing to url `/flaskprefix/` will invoke the Flask App, and call the `/` route which displays "Hello World from Flask App" + +**What if the other App is a Django App?** +```python +import my_django_app + +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) +# register the django wsgi application into the dispatcher +dispatcher.register_wsgi_application(my_django_app.wsgi.application, + "/djangoprefix") +``` +Browsing to url `/djangoprefix/` will invoke the Django App. + +**Can I run a default application?** + +The Sanic App `app` you create at the start is also the default app. + +When you navigate to a URL that does not match a registered dispatch prefix, this Sanic app will handle the request itself as per normal. +```python +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) + +otherapp = Sanic("MyChildApp") + +dispatcher.register_sanic_application(otherapp, "/childprefix") + +@app.route('/') +async def index(request): + return response.text("Hello World from Default App") + +@otherapp.route('/') +async def index(request): + return response.text("Hello World from Child App") +``` +Browsing to url `/` will *not* invoke any Dispatcher applications, so `app` will handle the request itself, resolving the `/` route which displays "Hello World from Default App" + +**I want to apply common middleware to the registered applications!** + +Easy! +```python +import my_django_app +from flask import Flask, make_response, current_app + +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) + +child_sanic_app = Sanic("MyChildSanicApp") + +child_flask_app = Flask("MyChildFlaskApp") + +@app.middleware("request") +async def modify_request(request): + request.headers['Content-Type'] = "text/plain" + +@app.middleware("response") +async def modify_response(request, response): + response.body = response.body + b"\nModified by Sanic Response middleware!" + response.headers['Content-Length'] = len(response.body) + return response + +@app.route("/") +async def index(request): + return response.text("Hello World from {}".format(request.app.name)) + +@child_sanic_app.route("/") +async def index(request): + return response.text("Hello World from {}".format(request.app.name)) + +@child_flask_app.route("/") +def index(): + app = current_app + return make_response("Hello World from {}".format(app.import_name)) + +dispatcher.register_sanic_application(child_sanic_app, + '/childprefix', apply_middleware=True) +dispatcher.register_wsgi_application(my_django_app.wsgi.application, + '/djangoprefix', apply_middleware=True) +dispatcher.register_wsgi_application(child_flask_app.wsgi_app, + '/flaskprefix', apply_middleware=True) +``` +The key here is passing `apply_middleware=True` to the relevant register application function. By default `apply_middleware` is set to `False` for all registered dispatcher applications. + +In this example the Sanic Request Middleware `modify_request` will be applied to ALL requests, including those handled by applications registered on the dispatcher. The request middleware will be applied to the `request` *before* it is passed to any registered applications. + +In this example the Sanic Response Middleware `modify_response` will be applied to ALL responses, including those which were generated by applications registered on the dispatcher. The response middleware will be applied to the `response` *after* it is processed by the registered application. + + + + +%package help +Summary: Development documents and examples for Sanic-Dispatcher +Provides: python3-Sanic-Dispatcher-doc +%description help +# Sanic-Dispatcher +### A Dispatcher extension for Sanic that also acts as a Sanic-to-WSGI adapter + +Allows you to do this: *(seriously)* +```python +from sanic import Sanic, response +from sanic_dispatcher import SanicDispatcherMiddlewareController +from flask import Flask, make_response, current_app as flask_app + +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) + +child_sanic_app = Sanic("MyChildSanicApp") + +child_flask_app = Flask("MyChildFlaskApp") + +@app.middleware("response") +async def modify_response(request, response): + response.body = response.body + b"\nModified by Sanic Response middleware!" + response.headers['Content-Length'] = len(response.body) + return response + +@app.route("/") +async def index(request): + return response.text("Hello World from {}".format(request.app.name)) + +@child_sanic_app.route("/") +async def index(request): + return response.text("Hello World from {}".format(request.app.name)) + +@child_flask_app.route("/") +def index(): + app = flask_app + return make_response("Hello World from {}".format(app.import_name)) + +dispatcher.register_sanic_application(child_sanic_app, '/sanicchild', apply_middleware=True) +dispatcher.register_wsgi_application(child_flask_app.wsgi_app, '/flaskchild', apply_middleware=True) + +if __name__ == "__main__": + app.run(port=8001, debug=True) +``` + +## Installation + + pip install Sanic-Dispatcher + +## How To Use + +First make a Sanic application the way you normally do: +```python +from sanic import Sanic + +app = Sanic(__name__) # This creates a sanic app +``` +`app` becomes your 'base' or 'parent' sanic app which will accommodate the Dispatcher extension + +Create a Dispatcher +```python +from sanic_dispatcher import SanicDispatcherMiddlewareController + +dispatcher = SanicDispatcherMiddlewareController(app) +``` +`dispatcher` is your new dispatcher controller. +*Note: This takes a reference to `app` as its first parameter, but it does not consume `app`, nor does it return `app`.* + +**I want to dispatch another Sanic App** +```python +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) + +otherapp = Sanic("MyChildApp") + +dispatcher.register_sanic_application(otherapp, "/childprefix") + +@otherapp.route('/') +async def index(request): + return response.text("Hello World from Child App") +``` +Browsing to url `/childprefix/` will invoke the `otherapp` App, and call the `/` route which displays "Hello World from Child App" + +**What if the other App is a Flask App?** +```python +from flask import Flask, make_response + +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) +flaskapp = Flask("MyFlaskApp") + +# register the wsgi_app method from the flask app into the dispatcher +dispatcher.register_wsgi_application(flaskapp.wsgi_app, "/flaskprefix") + +@flaskapp.route('/') +def index(): + return make_response("Hello World from Flask App") +``` +Browsing to url `/flaskprefix/` will invoke the Flask App, and call the `/` route which displays "Hello World from Flask App" + +**What if the other App is a Django App?** +```python +import my_django_app + +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) +# register the django wsgi application into the dispatcher +dispatcher.register_wsgi_application(my_django_app.wsgi.application, + "/djangoprefix") +``` +Browsing to url `/djangoprefix/` will invoke the Django App. + +**Can I run a default application?** + +The Sanic App `app` you create at the start is also the default app. + +When you navigate to a URL that does not match a registered dispatch prefix, this Sanic app will handle the request itself as per normal. +```python +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) + +otherapp = Sanic("MyChildApp") + +dispatcher.register_sanic_application(otherapp, "/childprefix") + +@app.route('/') +async def index(request): + return response.text("Hello World from Default App") + +@otherapp.route('/') +async def index(request): + return response.text("Hello World from Child App") +``` +Browsing to url `/` will *not* invoke any Dispatcher applications, so `app` will handle the request itself, resolving the `/` route which displays "Hello World from Default App" + +**I want to apply common middleware to the registered applications!** + +Easy! +```python +import my_django_app +from flask import Flask, make_response, current_app + +app = Sanic(__name__) + +dispatcher = SanicDispatcherMiddlewareController(app) + +child_sanic_app = Sanic("MyChildSanicApp") + +child_flask_app = Flask("MyChildFlaskApp") + +@app.middleware("request") +async def modify_request(request): + request.headers['Content-Type'] = "text/plain" + +@app.middleware("response") +async def modify_response(request, response): + response.body = response.body + b"\nModified by Sanic Response middleware!" + response.headers['Content-Length'] = len(response.body) + return response + +@app.route("/") +async def index(request): + return response.text("Hello World from {}".format(request.app.name)) + +@child_sanic_app.route("/") +async def index(request): + return response.text("Hello World from {}".format(request.app.name)) + +@child_flask_app.route("/") +def index(): + app = current_app + return make_response("Hello World from {}".format(app.import_name)) + +dispatcher.register_sanic_application(child_sanic_app, + '/childprefix', apply_middleware=True) +dispatcher.register_wsgi_application(my_django_app.wsgi.application, + '/djangoprefix', apply_middleware=True) +dispatcher.register_wsgi_application(child_flask_app.wsgi_app, + '/flaskprefix', apply_middleware=True) +``` +The key here is passing `apply_middleware=True` to the relevant register application function. By default `apply_middleware` is set to `False` for all registered dispatcher applications. + +In this example the Sanic Request Middleware `modify_request` will be applied to ALL requests, including those handled by applications registered on the dispatcher. The request middleware will be applied to the `request` *before* it is passed to any registered applications. + +In this example the Sanic Response Middleware `modify_response` will be applied to ALL responses, including those which were generated by applications registered on the dispatcher. The response middleware will be applied to the `response` *after* it is processed by the registered application. + + + + +%prep +%autosetup -n Sanic-Dispatcher-0.8.0.0 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-Sanic-Dispatcher -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Mon May 29 2023 Python_Bot <Python_Bot@openeuler.org> - 0.8.0.0-1 +- Package Spec generated |
