Comments (9)
@meyt Thoughts?
from nanohttp.
def controller_one():
yield 'hello'
def controller_two():
return 'hello'
def test(controller):
buffer = None
result = controller()
if result:
resp_generator = iter(result)
buffer = next(resp_generator)
else:
resp_generator = None
def _response():
if buffer is not None:
yield buffer
if resp_generator:
# noinspection PyTypeChecker
for chunk in resp_generator:
yield chunk
else:
yield b''
return _response()
print('controller one result:')
for x in test(controller_one):
print(x)
print('controller two result:')
for x in test(controller_two):
print(x)
and this is output
controller one result:
hello
controller two result:
h
e
l
l
o
from nanohttp.
don't care about last commit, it's just a preview of what is in my mind, not a way
from nanohttp.
Seems there is no way to get rid of the type checking. I prefer to check both strings and generators.
from nanohttp.
from nanohttp.
How about refactoring the __call__
method of the Application
?
from nanohttp.
The type checking on each response is not my favorite.
from nanohttp.
for prevent to type checking, i don't know any way else than forcing to just use generators (like #34), have you better?
from nanohttp.
Maybe just checking if the response is a generator or not.
from nanohttp.
Related Issues (20)
- 100% Code Coverage
- Incompatible dependencies HOT 1
- Use exc_info parameter of the start_response
- HTTPFound
- Raise when form field name is unknown.
- Add -o flag as same as the easyq cli
- Migrate to bddrest, Re-write all tests
- Bug in dispatcher HOT 1
- Invalid keyword argument for `start_response` HOT 3
- Unused parts HOT 2
- Empty request body when using prevent_form decorator HOT 6
- Server Halt: prevent_form and RestController
- `begin_response` hook are not called on `handle_exception` HOT 2
- Missed response headers on HTTPNoContent HOT 1
- Dump None type on JSON decorator HOT 1
- Bad request raise when nothing implemented HOT 1
- Application lifecycle conflicts on exception handling
- No query string values in context.form without form parameter HOT 1
- Code execution when loading the configuration HOT 1
- Cannot use python keywords as the HTTP verb
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 nanohttp.