Add comparison method for some framework handling#7
Conversation
|
Hi! Can you give an example of how you are using it with Sanic? Wouldn't it be possible to simply call |
|
Actually yes i can, but since i saw that the type checking is JSX: TypeAlias = JSXElement | strI thought that it could be great to work like str and less misleading, maybe for other case too, and gave it a try. It appears that the send() wait bytes so i added direct encoding in the draft Actually, I just made a dummy test site to explore. I'm use to jinja in many tools but though this can be way more interesting. @bp.route("/")
async def index(request):
"""Route principale avec streaming HTML."""
try:
request.app.ctx.state["visitor_count"] += 1
response = await request.respond() #content_type="text/html; charset=utf-16")
home = HomePage(visitor_count=request.app.ctx.state["visitor_count"])
await response.send(home)
await response.eof()
except Exception as e:
logger.error(f"Erreur lors du streaming HTML : {e}")
return HTTPResponse("Internal Server Error", status=500)
# ---
def HomePage(visitor_count: int = 0) -> JSX:
return (
<BaseLayout title="Accueil">
<Header />
<main style={{"padding": "1rem"}}>
<div id="content">
<p>Contenu initial chargé en streaming.</p>
<div id="dynamic-container">
<Article id="1" />
</div>
</div>
</main>
<Footer visitor_count={visitor_count} />
</BaseLayout>
)By the way, it's just a proposition, if you think of a better way or that shouldn't work this way... |
|
Thanks for the example! What is the error you get? Do you actually need all of the dunder methods? |
|
I tried to reduce to the maximum, was late( or very early ^^) , didn't note/remember why I put '__ add __' __ len __ __ bytes __ for radd and encode. |
|
ok actually didn't reproduce why add and radd, will remove it .. |
Hello
Was trying with Sanic web framework and complaining about some missing str methods.
This is a very naive "fix" might not be the best but streaming html works with this.