Comments (2)
🚨 Important!
Because of #31, I would not recommend using callback functions to modify the future's result anymore. So you are left with 2 other options:
- Don't change the behavior on flask-shell2http side, handle the JSON parsing on the client side. Shouldn't be too painful IMO.
- Use a decorator to modify the JSON response and return the modified response. See below example:
from flask import make_response, jsonify
import functools
def json_parser_decorator(f):
@functools.wraps(f)
def decorator(*args, **kwargs):
response = f(*args, **kwargs)
resp_json = response.json.copy()
resp_json["report"] = json.loads(resp_json["report"])
return make_response(jsonify(resp_json), response.status_code)
return decorator
shell2http.register_command(
endpoint="mytool", command_name="mytool", decorators=[json_parser_decorator]
)
from flask-shell2http.
It's possible to "intercept" the output providing a callback function. See this example.
You should probably be able to write a callback function that does something like:
res: dict = future.result() # 1. get current result
res["report"] = json.loads(res["report"]) # 2. manipulate report however u want
future._result = res # 3. set new result
from flask-shell2http.
Related Issues (20)
- [test case] command that raises exception with returncode of -1
- Enable test cases for flask 2.0
- Better typing and mypy in testing
- No report exists for key... HOT 8
- Force Option and Result URL HOT 3
- `wait` query param in `GET`
- `future.done()` and `callback_fn` race condition
- Fails if ran with multiple gunicorn workers HOT 1
- future_key already exists HOT 1
- Enable ci/tests for python 3.10
- Add some kind of basic auth HOT 2
- Permission denied HOT 4
- Possibility to interrupt command HOT 4
- use python format function HOT 2
- Cannot Import 'safe_join' from 'flask.helpers'
- A way to get binary output HOT 2
- Question HOT 1
- Seeing intermittent future_key errors HOT 3
- [New Feature] intercepting arguments before command execution
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-shell2http.