1. My goal is to replace exec with import.
2. Each application a package, imported by gluon (conceptually by the wsgi application) to service a request.
3. Application code imports its own modules with absolute_import (this requires Python 2.5, which ought to be fine for this purpose). That is, a controller imports models, etc. This eliminates the need for local_import().
4. request-scope variables (request, response, session, etc) are held in gluon.globals.rq, thus:
from gluon.globals import rq
...
request = rq.request # or just use rq.request
(we've also called this gluon.globals.current; I'm using rq because it's shorter)
5. Application code imports html helpers, validators, etc, from gluon.html or gluon.validators directly.
6. Running models. A model file would have a single callable function that would be called on each request, if present. Immutable application globals could go in the module namespace. Request-scope "globals" would go in thread-local storage.
So stuff like mail settings could be global to the module, and initialized at import time. Per-request stuff would run in the called function, so maybe like:
from gluon.globals import rq
def run_model():
rq.db = DAL(whatever)
or perhaps
def run_model():
app = rq.app # all the app-specific thread-local info goes in rq.app = Storage()
app.db = DAL(whatever)
7. As a package, each application automatically runs in its own namespace(s), but that namespace is common to all requests.
8. Possible reloading solution: each request takes a reader lock on its application. To force a reload, set a per-app flag. When a request sees that flag, it takes the writer lock instead of the reader lock. Once it has the writer lock, if the flag is still set, it clears the flag, reloads the application package, releases the writer lock, takes the reader lock, and runs the request. (If the flag isn't still set, it skips the reload.)
9. Views. Views would be 'compiled' by parsing their templates and using the result to populate a compiled-views folder (package). A compiled view is the parsed template wrapped in a callable function, with a standard set of imports--a .py file.
Views would access request-scope globals, including stuff defined in model files, in the same way that controllers do, via thread-local storage: rq.request, rq.app.db.
Assuming that this works (a dangerous assumption) ... what are the implications for an application author?
1. No injected globals means explicit imports of validators, html helpers, request-scope objects. This can be viewed as a plus.
2. Syntax for request-scope objects changes from (eg) 'request' to 'rq.request'.
3. Apps would have to distinguish app-wide globals from request-scope globals. The rq.something syntax makes this explicit.
Again, this isn't a proposal per se. At this point I'm just curious about what an import-based version of web2py might look like. Is it possible? What are the advantages and disadvantages?
It's not unlikely that I've overlooked some gaping hole in the logic; if so, somebody break it to me gently.
db.define_table(Field(...,default=request.now))
would have to be
db.define_table(Field(...,default=lambda:global.request.now))
where global is a new thread local object.
There should be a lot of changes inside web2py because the DAL thread
pooling would break. I do not think this can be done without a
complete rewrite of main.py and, give that, I would just use bottle.py
> --
> mail from:GoogleGroups "web2py-developers" mailing list
> make speech: web2py-d...@googlegroups.com
> unsubscribe: web2py-develop...@googlegroups.com
> details : http://groups.google.com/group/web2py-developers
> the project: http://code.google.com/p/web2py/
> official : http://www.web2py.com/
There should be a lot of changes inside web2py because the DAL thread pooling would break. I do not think this can be done without a complete rewrite of main.py and, give that, I would just use bottle.py
There should be a lot of changes inside web2py because the DAL thread pooling would break. I do not think this can be done without a complete rewrite of main.py and, give that, I would just use bottle.pyWhat about some kind of merge? bottle2py ? a different project.
I'd like not to drop python, C-python without threads, IMHO is a good
performer. Avoiding threads if not on PyPy python would be a good
start. PyPy python can be a good choice to have for having restricted
python interpreters on the fly thus making framework more secure.
Anyway that would be
a long term project
The growth of JavaScript as a practical platform and its strength on the client side certainly makes it an interesting candidate for a new framework. And the fact that one can leverage all those client-side CPU cycles doesn't hurt, either.
A DAL seems like a handy part of such an architecture. I wonder if JSON could serve as the abstract representation of a request. (I'm thinking DAL here, not ORM.)
I was thinking that a model would (could) contain a wrapper function (let's call it 'run') that would be called per-request. So if db.py is now:
db = DAL(...)
...Field(...request.now)
it would become:
def run(rq):
rq.db = DAL(...)
...Field(...rq.now)
Would that break DAL thread pooling? I don't really understand it well enough to have an opinion.
A side note: rq (what we were calling 'current') can just as well have stuff like rq.now and rq.env at its root level. In particular, 'request' isn't all that useful as its own object, in the way that session is. OTOH, we wouldn't actually change it, because gluon wants to support both app styles.
And yes, this would be incompatible at the app level, though the conversion would be straightforward.
>> 3. Apps would have to distinguish app-wide globals from request-scope globals. The rq.something syntax makes this explicit.
I am all for a successor of web2py but, given that it will break backward compatibility, I would change a lot of things.Here is what I am thinking....- The controller should be a REST engine.- All views for each app (in html) should automatically be packaged into one single html that talks to the rest services via ajax. The app should not transmit html at every requet, only data in JSON. All required html should be sent at once when the app is loaded.- would preserve the web based editors admin interface.- I am not sure I would use Python any more for serverside. I think node.js or erlang are a better choice today.
Everything is a component You can nest components inside container components.
you add component to outer component till you reach a Page component.
Every component can have Behaviors to handle events or to contribute
to Page headers.
Note that unlike web2py components need to instantiated before being
added. You manipulate class definition not
objects. i.e. a Button is a class in Wicket, BUTTON in web2py is an
object. So if I want to have a custom button i do
Button myButton = new Button() { // extend as anonymous class
...
...
}
container.add(myButton);
or to reuse
public class MyButton extends Button {
..
..
}
Better yet is this http://www.webtoolkit.eu/widgets you can make full
featured ajax apps with integrated http server (boost w forking) in
less than
200kb
2011/2/11 Massimo Di Pierro <massimo....@gmail.com>:
2011/2/12 Michele Comitini <michele....@gmail.com>: