[web2py] Re: New importer in trunk
It would be nice to have feedback to know if the new feature is working well for you. Tell me if everything is OK or not.
[web2py] Better language support
Hello, It seems that web2py takes care of only the first language listed in the browser request. The other languages are not taken into account. For example, in my browser preferences, I have: fr-ca fr fr-fr en en-us But there is only one value for T.accepted_language and in my case I have fr-ca. I propose a modification for web2py to take in consideration other languages: - T.accepted_language would stay the same. - A new T.accepted_languages, with an 's', would be created to list all the languages accepted by the users. - When searching for a translation, web2py will go through all the files for T.accepted_languages to find the best match What do you think of this idea?
[web2py] Re: New importer in trunk
On 17 mai, 14:36, Martín Mulone mulone.mar...@gmail.com wrote: Pierreth I'm testing this, and it all seem to work very well, nice feature indeed!. :-) I'm looking for memory leak but it's seem stable in my notebook. I already rewrite powerpack, to support this, at first sigth it's double the speed from the old way putting all in models (I have many models). Indeed, models are run at each request. This can be very time consuming. Moving everything in modules that does not need to be run each request is a good idea.
[web2py] Re: Better language support
I would like to further express why this feature would be a great benefit. People doing translation are having a hard time the way web2ppy is working now. I will take the example of translating in French but it seems to be the same for about any languages. One of the problem we have to deal with as translator is that we have few big files that are mostly identical fr.py, fr-cap.y, fr-fr.py. Each time we want to add a new translated term, we must add it to all different language files. On top of that, it becomes hard to see what are the differences in all these files. So what I propose with the mechanism I described in the last message is to have one big file fr.py and only have the differences in fr- fr.py and fr-ca.py. That would already make life a lot easier for translators. The second thing that I propose is that web2py put the term is unable to translate in other files like missing-translations-fr.py. Right now, web2py adds these translation automatically in the file related to T.accepted_language. It does so whiteout even adding a comment so it is difficult for translators to know that the translation is coming from web2py. The missing-translations-xx.py would only exist for main languages like 'fr' but not for 'fr-ca' or 'fr-fr'. Web2py would automatically consider the main language if this one is missing from the request by appending the main language if needed to follow more specific languages (for example, imagine a request accepting fr-ca but not fr, web2py would add fr after fr-ca). Any other ideas?
[web2py] Re: Better language support
On 17 mai, 13:54, pierreth pierre.thibau...@gmail.com wrote: It seems that web2py takes care of only the first language listed in the browser request. The other languages are not taken into account. I made some tests and web2py choose the T.accepted_language as the first language listed in the request for which there is a translation file or match the current language (the language in which the application is written for which no translation is needed). This match must be perfect: web2py won't accept fr as a language if the request only specify fr-ca.
[web2py] Re: Better language support
On 17 mai, 13:54, pierreth pierre.thibau...@gmail.com wrote: - T.accepted_language would stay the same. - A new T.accepted_languages, with an 's', would be created to list all the languages accepted by the users. - When searching for a translation, web2py will go through all the files for T.accepted_languages to find the best match After further reflexion, I realize that it would be unreasonable to go through all the languages files accepted by the user. What would be more reasonable is to try a more generic language if a translation is not found in the language defined by T.accepted_language. So if T.accepted_language == 'fr-ca' and the translation is not present in 'fr-ca.py' then we try to find it in 'fr.py'. Of course we stop the translation as soon as the language we are searching is the current one (the language of the app itself).
[web2py] Re: Better language support
On 17 mai, 23:46, Massimo Di Pierro massimo.dipie...@gmail.com wrote: +1 for this. I would take a patch. ;-) +1 for this one too? : The second thing that I propose is that web2py put the term is unable to translate in other files like missing-translations-fr.py. Right now, web2py adds these translation automatically in the file related to T.accepted_language. It does so whiteout even adding a comment so it is difficult for translators to know that the translation is coming from web2py. The missing-translations-xx.py would only exist for main languages like 'fr' but not for 'fr-ca' or 'fr-fr'. Web2py would automatically consider the main language if this one is missing from the request by appending the main language if needed to follow more specific languages (for example, imagine a request accepting fr-ca but not fr, web2py would add fr after fr-ca). And for Jonathan's idea? It seems to be a very good idea for me. Any way, this time I'll try to be test driven. I was lazy on that with my last patches.
[web2py] New importer in trunk
Hello, There is a new version of the web2py importer in the trunk version. This new version has the capability of reloading any modules when an import is made on a module that has changed. So you can edit your .py files in 'modules' or 'site-packages' or somewhere else and web2py will reload the new version during the next import. To turn this feature on or off, you have to edit the web2py file gluon/ custom_import.py and set DEBUG to True or False. The default value is True so the feature is enabled by default. Feedback on this new feature would be appreciated. I would appreciate feedback on how might be the best to set this feature on and off. Thank you.
[web2py] Re: New importer in trunk
On 16 mai, 11:08, Ross Peoples ross.peop...@gmail.com wrote: I haven't actually tried this yet, but couldn't you do something like this to turn it off/on: import gluon custom_import custom_import.DEBUG = False You can do: from gluon import custom_import custom_import.DEBUG = False But right now it won't change the importer by doing this. Would you like to be able to switch in a similar fashion? We can also add the switch in the web interface I guess.
[web2py] Re: Discussion: Python 2.4 Support
I think 2.4 is getting old. Why now update the module you use to version 2.5 instead? If webp2y is too obsess with backward compatibility, new developers will now be interested in the project. I don't think supporting version 2.4 is a good thing. On 14 mai, 01:14, Ross Peoples ross.peop...@gmail.com wrote: I am developing a web2py app that uses a third party python module that only works on Python 2.4.4. Basically, we are using we2py as a front end for an API. Since recently updating to trunk, I noticed that several things didn't seem to work anymore. I submitted patches to Massimo and he told me that there was discussion before about dropping Python 2.4 support. I am wondering who else is using Python under 2.4? I am hoping that we can continue to support 2.4. The latest patches I provided only make minor changes to support 2.4, so it's really not too bad to support it, even with the latest trunk. Thought? Concerns? Thanks
[web2py] Re: Trunk new importer working?
How can I read a boolean like DEBUG set in models or controllers from a module located in gluon? This is an aspect I don't know how to implement.
[web2py] Re: Trunk new importer working?
On 2 mai, 16:31, Bruno Rocha rochacbr...@gmail.com wrote: On Mon, May 2, 2011 at 5:20 PM, pierreth pierre.thibau...@gmail.com wrote: How can I read a boolean like DEBUG set in models or controllers from a module located in gluon? This is an aspect I don't know how to implement. you need to pass globals() to the module in the same way Auth and Crud does. (take care of reloading the module to update globals on that context) I don't think this is a nice solution. I would like something more transparent.
[web2py] Re: Trunk new importer working?
On 2 mai, 17:20, Bruno Rocha rochacbr...@gmail.com wrote: On Mon, May 2, 2011 at 5:53 PM, pierreth pierre.thibau...@gmail.comwrote: I don't think this is a nice solution. I would like something more transparent. So you dont need to include globals() just pass the vars you want. mymodule,myfunction(request, response, session, db, anyotherobject, DEBUG) I need to be able to read this value when an import is done in the custom importer. I guess the only solution is asking Massimo to offer a special support for the boolean. I don't know otherwise.
[web2py] Re: Code insert-er for Pydev Eclipse users
On 28 avr, 02:20, Anthony abasta...@gmail.com wrote: Is there any other trick to get this working? I added web2py/gluon to the system PYTHONPATH in pydev as described above, but I don't get any web2py autocomplete. Note, I'm on Windows 7. Anthony Hello, I think this is incorrect. You need web2py not gluon (I mean the parent folder). Here I don't use the general preferences of Pydev to add this folder, I prefer to add web2py and web2py/site-packages as an external libraries for each individual project. If you use create_eclipse_project, http://code.google.com/p/neo-web2py2eclipse/, the script adds these folders automatically.
[web2py] Re: web2pyslices registration is not working
On 27 avr, 23:08, Douglass douglassdow...@gmail.com wrote: I've tried multiple times to register. Different password formats, etc. I don't have an OpenId I noticed that comment. Is that required? guess I'm old school but seems unreasonable. I was unable to register too. I was able to login using my Google id.
[web2py] Code insert-er for Pydev Eclipse users
Hello, I made a tool to automatically insert the code necessary to avoid the errors and warnings reported by Eclipse Pydev cause by the automatic imports of web2py. http://code.google.com/p/neo-insert-imports/ Tell me if you like.
[web2py] Re: Code insert-er for Pydev Eclipse users
OK I see, This way, Pydev automatically had the missing imports when we are coding. Personally, I added the library project by project so the feature is working for me too. But this does not solve the problem of the missing imports for existing code if code analysis is activated (Window Pydev Editor Code Analysis Option tab Do Code Analysis checkbox). The script add the missing imports so you don't have to add them manually. I guess you work without the Pydev code analysis. It could also be a good reference for people beginning with web2py. On 27 avr, 14:04, danto web2py.n...@gmail.com wrote: I still don't know what issues are all talking about regarding pydev and web2py. I'm using it on archlinux and imports, autocomplete and functions are all working pretty well. just go to: window preferences pydev interpreter-python libraries and add a [new folder] in system pythonpath pointing to the web2py/gluon folder of your web2py installation. please tell me if this (kind of obvious) thing works for you or I may be missing some more magic from web2py (?). I have autocomplete from DAL and even from HTML helpers atm regards
[web2py] Re: Trunk new importer working?
On 26 avr, 08:28, Massimo Di Pierro massimo.dipie...@gmail.com wrote: import my_module # not right now always assumes reload=False (I think). Yes, assume reload is False. This is the normal behavior for Python. So the code can be: if my_module in dir() and DEBUG: reload(applications.my_app.modules.my_modules) import my_modules reload is working the way it was. Would it be better to adapt it so we can simply write reload('my_module')?
[web2py] Re: Trunk new importer working?
Oups, reload does not take a string but a module object so forget the quotes. It would be difficult to change the behavior of reload. Is reload(my_module) working? I didn't try. On 26 avr, 10:04, pierreth pierre.thibau...@gmail.com wrote: On 26 avr, 08:28, Massimo Di Pierro massimo.dipie...@gmail.com wrote: import my_module # not right now always assumes reload=False (I think). Yes, assume reload is False. This is the normal behavior for Python. So the code can be: if my_module in dir() and DEBUG: reload(applications.my_app.modules.my_modules) import my_modules reload is working the way it was. Would it be better to adapt it so we can simply write reload('my_module')?
[web2py] Re: Trunk new importer working?
On 26 avr, 10:04, pierreth pierre.thibau...@gmail.com wrote: if my_module in dir() and DEBUG: I made a test. The 'in dir()' does not work because the variable is not there yet. You can write: import my_module if DEBUG: my_module = reload(my_module) reload is working well. As Jonathan said, you can continue to local_import instead if you prefer.
[web2py] Re: Trunk new importer working?
On 26 avr, 10:33, Jonathan Lundell jlund...@pobox.com wrote: It'd be worth testing. In fact, how about a unit test module for both flavors of import (local custom)? It would have been a good idea to do so from the start but now that is working it is a bit late. It is now tested by putting it in practice.
[web2py] Re: Trunk new importer working?
On 26 avr, 10:44, Jonathan Lundell jlund...@pobox.com wrote: It's never too late for unit tests. Seriously. Would you like to write them?
[web2py] Re: Trunk new importer working?
Hello Ross, I though it would be cool if web2py automatically reloads any modified module in debug mode. It is already the case for controllers, models and views. It seems to be just the right thing to do regardless of the module. I can implement this for a future version. What do you think (I am asking everyone)? On 26 avr, 08:07, Ross Peoples ross.peop...@gmail.com wrote: I turn everything into modules, so I use local_import() ALOT. If I have a local import that looks like this: DEBUG = True my_module = local_import('my_module', reload=DEBUG) How would I write that with the new importer?
[web2py] Re: Trunk new importer working?
On 26 avr, 15:31, Ross Peoples ross.peop...@gmail.com wrote: Reloading would be awesome, but making it optional would be the best choice, as sometimes you want your modules to persist across requests for performance reasons (so that modules don't get reloaded for every request in a production environment). What I am proposing is the module get reloaded only in DEBUG mode if the file has been modified. Would it be a good behavior? Otherwise, what do you suggest?
[web2py] Re: about bpython
Hi Jose, Here is the problem: File /usr/home/jose/web2py/gluon/shell.py, line 210, in run bpython.embed(locals_=_env) I don't know the problem but it has nothing to do with the new importer. The old importer has the same behavior. On 23 avr, 22:54, Jose jjac...@gmail.com wrote: Hi I edited the shell.py file add raise to see that error occurred when trying to use bpython if bpython: try: import bpython bpython.embed(locals_=_env) return except: raise logger.warning( 'import bpython error; trying ipython...') If I run: python web2py.py -S myapp -M -B fail, showing error: Traceback (most recent call last): File web2py.py, line 19, in module gluon.widget.start(cron=True) File /usr/home/jose/web2py/gluon/widget.py, line 804, in start import_models=options.import_models, startfile=options.run) File /usr/home/jose/web2py/gluon/shell.py, line 210, in run bpython.embed(locals_=_env) File /usr/local/lib/python2.7/site-packages/bpython-0.9.7.1- py2.7.egg/bpython/__init__.py, line 28, in embed from bpython.cli import main File /usr/home/jose/web2py/gluon/custom_import.py, line 80, in _web2py__import__ return _old__import__(name, globals, locals, fromlist, level) File /usr/local/lib/python2.7/site-packages/bpython-0.9.7.1- py2.7.egg/bpython/cli.py, line 47, in module from pygments.lexers import PythonLexer ImportError: cannot import name PythonLexer In the early versions that stand web2py bpython, started well, but now the error mentioned. to rule out any problem in bpython or pygments, I created a python script with the following works well and no error occurs. from pygments.lexers import PythonLexer def test(): a = 10 b = 20 import bpython print locals() bpython.embed(locals_=locals()) test() in these days have developed / edited custom_import. Perhaps the problem happens there. Any idea? Jose
[web2py] Trunk new importer working?
Hello, I am writing this message to know if some users are still experiencing problems with the new importer available in the trunk version. Please tell us if everything is OK or you are having problems. Thank you.
[web2py] Re: Trunk new importer working?
On 25 avr, 20:44, mart msenecal...@gmail.com wrote: how cool! so if all looks good, will we need to make a switch or will both be supported for a while? Thanks, Mart :) The new import function changes how things are loaded when a module is imported from models, controllers or modules (the modules directory). If you do import x it will try transparently to do import applications.your_app.modules.x. If it does not work, it will fall back on the traditional Python way of importing things. This new import enables to have different modules or packages that are dependent on one or another in the modules folder. Before that, the developer was force to modify the modules to use local_import instead or import or from this import that. A second good thing is that if app A uses x in 'modules' and app B uses a different version of x in 'modules', the two versions will work without collision. The down side is that import x for app A does import x under the module name applications.A.modules.x and for the app B it is of course applications.B.modules.x so if the developer is expecting to have a module named x in sys.modules, he will have a bad surprise. But it is very small inconvenient I believe. It is small design tread off. local_import still work like before and it enables modules to be easily reloaded. But we can now use a standard import. This is now available in trunk. Cool?
[web2py] Re: about bpython
Hello, I am unable to reproduce the problem. bpython is importing well here. To make sure, in gluon/custom_import.py, do you have this at line 46: try: result = result or new_mod.__dict__[name] except KeyError: raise ImportError() or something else? If do not have this, you do not have the latest trunk and you need to update. Otherwise, tell me how to reproduce the problem. On 23 avr, 22:54, Jose jjac...@gmail.com wrote: Hi I edited the shell.py file add raise to see that error occurred when trying to use bpython if bpython: try: import bpython bpython.embed(locals_=_env) return except: raise logger.warning( 'import bpython error; trying ipython...') If I run: python web2py.py -S myapp -M -B fail, showing error: Traceback (most recent call last): File web2py.py, line 19, in module gluon.widget.start(cron=True) File /usr/home/jose/web2py/gluon/widget.py, line 804, in start import_models=options.import_models, startfile=options.run) File /usr/home/jose/web2py/gluon/shell.py, line 210, in run bpython.embed(locals_=_env) File /usr/local/lib/python2.7/site-packages/bpython-0.9.7.1- py2.7.egg/bpython/__init__.py, line 28, in embed from bpython.cli import main File /usr/home/jose/web2py/gluon/custom_import.py, line 80, in _web2py__import__ return _old__import__(name, globals, locals, fromlist, level) File /usr/local/lib/python2.7/site-packages/bpython-0.9.7.1- py2.7.egg/bpython/cli.py, line 47, in module from pygments.lexers import PythonLexer ImportError: cannot import name PythonLexer In the early versions that stand web2py bpython, started well, but now the error mentioned. to rule out any problem in bpython or pygments, I created a python script with the following works well and no error occurs. from pygments.lexers import PythonLexer def test(): a = 10 b = 20 import bpython print locals() bpython.embed(locals_=locals()) test() in these days have developed / edited custom_import. Perhaps the problem happens there. Any idea? Jose
[web2py] Re: about bpython
OK, What are the steps to reproduce the problem? On 24 avr, 19:06, Jose jjac...@gmail.com wrote: On 24 abr, 17:14, pierreth pierre.thibau...@gmail.com wrote: Hello, I am unable to reproduce the problem. bpython is importing well here. To make sure, in gluon/custom_import.py, do you have this at line 46: try: result = result or new_mod.__dict__[name] except KeyError: raise ImportError() or something else? If do not have this, you do not have the latest trunk and you need to update. Hi pierret, Supposedly I have the version of the trunk. Updated daily. The last time an hour ago. In gluon/custom_import.py I have what follows: def _web2py__import__(name, globals={}, locals={}, fromlist=[], level=-1): ... ... def _web2py__import__dot(prefix, name, globals, locals, fromlist, level): Here we will import x.y.z as many imports like: from applications.app_name.modules import x from applications.app_name.modules.x import y from applications.app_name.modules.x.y import z. x will be the module returned. result = None for name in name.split(.): new_mod = _old__import__(prefix, globals, locals, [name], level) try: result = result or new_mod.__dict__[name] except KeyError: raise ImportError() prefix += . + name return result Jose
[web2py] Re: new web2py version
Hello, Can you try this patch on the nightly build and tell me if things are now working? http://pastebin.com/3wjuD6vA --- Pierre
[web2py] Re: Modularity
Here are my conclusion on using the modules directory. What is working: - Using local_import avoid collisions of modules or packages that may have the same names in other applications. - Explicit and implicit relative imports are working well for modules located in the modules directory. What is not working: - Absolute imports does not work because modules is not in the Python path. What this mean in practice: - Modules located in modules can import each other if there are not located in a package. This is implicit relative import. - local_import is working well with both modules and packages. - Modules located in modules, regardless of if they are or not located in a package, can only import other modules located both in a package and in modules using explicit relative imports. Absolute imports only work for modules and packages located in the Python path. So if you drop both a module a depending on module b in modules, they will probably work very well. But if you drop both a package a depending on package b (or a module b), it will probably not work. Using relative imports in this case is not the norm. Inter packages dependencies will not work in modules. Is this a bug? See: http://docs.python.org/tutorial/modules.html#packages I suggest to add this message to the web2py book.
[web2py] Re: Modularity
Yes, this is working. applications is in the path. But using applications.yourappname.modules.modulename is specific to web2py. Python developers are expecting to do import modulename otherwise, it will not work outside of web2py. On 6 avr, 10:55, grabau@gmail.com wrote: Importing from modules works with absolute import , you must use import applications.yourappname.modules.modulename The path has been set to the directory that web2py is running in - where the web2py.py file is. Sent from my BlackBerry® smartphone on the MTS High Speed Mobility Network -Original Message- From: pierreth pierre.thibau...@gmail.com Sender: web2py@googlegroups.com Date: Wed, 6 Apr 2011 07:39:47 To: web2py-usersweb2py@googlegroups.com Reply-To: web2py@googlegroups.com Subject: [web2py] Re: Modularity Here are my conclusion on using the modules directory. What is working: - Using local_import avoid collisions of modules or packages that may have the same names in other applications. - Explicit and implicit relative imports are working well for modules located in the modules directory. What is not working: - Absolute imports does not work because modules is not in the Python path. What this mean in practice: - Modules located in modules can import each other if there are not located in a package. This is implicit relative import. - local_import is working well with both modules and packages. - Modules located in modules, regardless of if they are or not located in a package, can only import other modules located both in a package and in modules using explicit relative imports. Absolute imports only work for modules and packages located in the Python path. So if you drop both a module a depending on module b in modules, they will probably work very well. But if you drop both a package a depending on package b (or a module b), it will probably not work. Using relative imports in this case is not the norm. Inter packages dependencies will not work in modules. Is this a bug? See:http://docs.python.org/tutorial/modules.html#packages I suggest to add this message to the web2py book.
[web2py] Re: Modularity
On 6 avr, 12:01, Jonathan Lundell jlund...@pobox.com wrote: It's worth reflecting on why this is the case. Ordinarily, in the Python environment, we'd solve this problem by adding our local module repository to sys.path from inside the application, which would work fine because the edited sys.path is local to the current instance of the interpreter. But in a web2py environment, sys.path (and the interpreter) is shared among all the applications. This is the fact that the Python process is shared. web2py itself is the Python application. The brute-force solution, I think, is to run separate web2py instances, with top-level routing in the external server (Apache, whatever). Yes, but this is not the way web2py is running by default. I can think of a couple of directions to look for alternatives. One is PEP 302 (import hooks and such). Having a custom Python importer that will look in modules first before looking elsewhere would be a great solution. A simpler approach would be for web2py to rebind sys.path to a thread-local variable and add the app-specific modules directory to it. If that worked (offhand I can't think why not, but I'm no doubt missing something), it'd be pretty simple, as long as it didn't get re-bound later, which is a hazard (note that web2py's idiom for adding to sys.path rebinds it). A thread-local variable is not list. sys.path is expected to be a list. Going down that road, rather than rebinding sys.path to a thread-local version, what if we added a thread-local member to sys.path that pointed to the current application's modules directory? That'd be *really* simple, again if I'm not missing something. I thought about it but a thread-local variable is not a string so we cannot add it to sys.path. So it is a problem.
[web2py] Re: Modularity
On 6 avr, 11:42, mgra...@seccuris.com mgra...@seccuris.com wrote: To clarify inter-package dependencies. I'm assuming that you mean a setup like the following: APP/ modules/ modulea/ ...some python files... moduleb/ ...some more python files... If you want to use something from moduleb inside modulea (assuming that both have the __init__.py in their directories), from ..moduleb import * -- or import classA, etc I use it in several parts of an app that I have, it works just fine. Yes, explicit relative imports are working well.
[web2py] Re: Modularity
On 6 avr, 12:26, Mathew Grabau grabau@gmail.com wrote: I totally agree with that. Though, I just read up, if pierreth is trying to borrow code from app1/modules inside app2/controllers, then injecting app1/modules into the python path should work. Of course, this would just avoid having to put the module code inside app2/ modules (and would provide the ability inside the app2 controller to use import moudleA). I want to share code in my applications but I want my applications to be self-contain too. So I use modules and not site-packages. The only problem is that absolute import statements will not import modules in modules. It is not the Python path. If this becomes a real problem. I'll write a custom Python importer. It is not hard to do.
[web2py] Re: Modularity
On 6 avr, 12:59, Mathew Grabau grabau@gmail.com wrote: I think I see it what you're trying to accomplish, but I'm trying to clarify now - you're looking for separate copies of the modules inside each applications modules directory, but the ability to import with an absolute import without having to specify the applications.appname.modules part? Yes, I think this is a good résumé.
[web2py] Re: Modularity
On 6 avr, 12:48, Massimo Di Pierro massimo.dipie...@gmail.com wrote: I would like to see an example of custom importer, it would help me understand the problem that needs to be solved. I think it would be really simple. Just rebind the __import__ to create an around advice that will try a relative import. Just count the number of parent directories from the module doing the import to modules. Use the old __import__ to do the relative import and if it generates an import error, call the old __import__ with the parameters your new __import__ received. See help(__import__) and http://books.google.ca/books?id=JnR9hQA3SncCpg=PA147lpg=PA147dq=python+custom+importersource=blots=Jb1TFp194ssig=PFnaZB4aIubwyjXbmpsoChIKqAMhl=frei=FpucTZmWJ-y10QHn1LzjAgsa=Xoi=book_resultct=resultresnum=6ved=0CEwQ6AEwBQ#v=onepageq=python%20custom%20importerf=false Sounds easy?
[web2py] Re: Modularity
On 6 avr, 13:23, Jonathan Lundell jlund...@pobox.com wrote: How about this, as a means of adding the app-specific modules/ to sys.path: in a thread-local object 'localthing', store the path to the current application's modules/ directory in something.modules. Subclass str thus: class LocalModules(str): def __str__(self): return str(localthing.modules) In the web2py startup logic: sys.path.append(LocalModules(modules)) # the value isn't important, though it could be used to generalize this construct In the web2py request logic: something.modules = path to current application's modules directory This could be generalized somewhat by having LocalModules get the real string (modules in this example) from super, and fetch the attribute of that name from localthing. No, this will not work. sys.path takes string. We can had a marker like __modules__ in sys.path then we add a Python loader in sys.path_hooks for the marker. The new Python loader will read the thread local variable from web2py (could be bended pretty much anywhere). But I think this solution would be more complex then the previous one I just described.
[web2py] Re: Modularity
I made a patch for the import problem. I will submit it to Massimo. It now works the way I wanted.
[web2py] Modularity
I wanted to share code from one web2py application to another. So I created two packages with the same name in two different web2py applications. I load the code of the package modules with local_import from the controllers of both application. The two applications are having almost the same packages in their modules directories. The names of the modules are the same but the code is a little bit different. Here, I am trying to have name collisions on purpose. I was expecting collisions because the packages in the 'modules' directories of my applications are using standard python imports. But no, I have no collision based on my tests even if my packages are referencing other packages also located in the modules directory. Is it really safe to do what I do? It is a bit magical.
[web2py] Re: Modularity
Oups! It does like that it does not work. I was loading old code in my tests. The modules were not reloaded. I have to find another solution... On 5 avr, 22:04, pierreth pierre.thibau...@gmail.com wrote: I wanted to share code from one web2py application to another. So I created two packages with the same name in two different web2py applications. I load the code of the package modules with local_import from the controllers of both application. The two applications are having almost the same packages in their modules directories. The names of the modules are the same but the code is a little bit different. Here, I am trying to have name collisions on purpose. I was expecting collisions because the packages in the 'modules' directories of my applications are using standard python imports. But no, I have no collision based on my tests even if my packages are referencing other packages also located in the modules directory. Is it really safe to do what I do? It is a bit magical.
[web2py] Re: Modularity
On 5 avr, 22:38, pbreit pbreitenb...@gmail.com wrote: Applications are totally discrete so there would be no chance of a collision (if I understand correctly). app1 modules mypackage1 app2 modules mypackage2 Nothing in app1 knows about anything app2 (and vice versa). The 'modules' directory is not in the Python path so we have to use local_import to load them. The applications are not so discrete because they share the same process and the same modules. I found that I cannot import from a package to get a module in another package in the same modules directory if I don't use a relative import. So I do: import sys if sys.argv[0] != web2py.py: import p2 else: from .. import p2 This way my module will use an absolute import, the Python recommendation, if used outside of web2py and a relative import when used in web2py. But the Pydev static analyzer is giving me an error. This looks like a bug because the code is working well. If you don't want to maintain two copies of the same code, you could put it in site-packages in the web2py directory. That folder is accessible by any of your apps. Yes but I would like my applications to be self-contain so I prefer to use the modules directory.
[web2py] My little Python projects
Hello, I updated my blog to talk about some Python projects I started. So take a look and don't be afraid to comment. If you think these projects can be integrated in another bigger project, suggestions are welcome. Note that Python script project to create Eclipse project from web2py applications has now moved. The web2py recipe to integrate web2py, Eclipse and Google Code is also on my blog. See my blogs for all details. http://pierrethibault.posterous.com/my-little-python-projects -- A+ - Pierre My blog (http://pierrethibault.posterous.com) YouTube page (http://www.youtube.com/user/tubetib) Twitter (http://twitter.com/pierreth2) Google profile (http://www.google.com/profiles/pierre.thibault1)
[web2py] html templates using or
Hello, I have small problem when the characters and are used in web2py html template views. Using them for Python breaks the html: {{=OK if x 0 else bad}} Because these characters are not escaped in the code, the html file is no longer well formed. Using the html entities lt; and gr; does not solve the problem because web2py gives an error when theses characters are used as Python code in templates. Is it possible to fix this to have well formed html for web2py templates?
[web2py] Re: html templates using or
I think you mean the response object. The example code you gave still use the character so it does not help. In fact, the problem is that web2py is not processing the xml document but it parse directly the html file. I would really like Massimo to fix this. On Mar 12, 2:15 pm, Jonathan Lundell jlund...@pobox.com wrote: On Mar 12, 2011, at 11:05 AM, pierreth wrote: Hello, I have small problem when the characters and are used in web2py html template views. Using them for Python breaks the html: {{=OK if x 0 else bad}} Because these characters are not escaped in the code, the html file is no longer well formed. Using the html entities lt; and gr; does not solve the problem because web2py gives an error when theses characters are used as Python code in templates. Is it possible to fix this to have well formed html for web2py templates? This is a consequence of the way the '=' (request.write) operator behaves at the beginning of a code block: it treats the entire string as its argument string, something like: request.write('OK if x 0 else bad') You can rewrite it to use request.write explicitly, or to put each = operator on its own line. {{request.write(OK if x 0 else bad)}} or {{if x 0: =OK else: =bad pass }} (I think) When the '=' operator is embedded in a code block, it consumes everything until the end of the physical line or code block, whichever comes first. When it begins a code block, it consumes the entire block.
[web2py] Re: html templates using or
I am sorry Jonathan, I think we have a misunderstanding. All this works with web2py. The problem is that characters and need to be escaped in html. Otherwise, it is not html. The html produced by web2py is well formed but in the template itself the html it is not well formed. Because of this, the templates are not using well formed html all the times and the html code analyzer of my IDE is given me errors. On Mar 12, 3:11 pm, Jonathan Lundell jlund...@pobox.com wrote: On Mar 12, 2011, at 11:54 AM, Jonathan Lundell wrote: On Mar 12, 2011, at 11:39 AM, pierreth wrote: I think you mean the response object. Yes, response. The example code you gave still use the character so it does not help. Did you try it? How about the second version? Hmm. I take back what I said earlier: all versions work for me, including your original one. In what context are you using the expression? In fact, the problem is that web2py is not processing the xml document but it parse directly the html file. I would really like Massimo to fix this. On Mar 12, 2:15 pm, Jonathan Lundell jlund...@pobox.com wrote: On Mar 12, 2011, at 11:05 AM, pierreth wrote: Hello, I have small problem when the characters and are used in web2py html template views. Using them for Python breaks the html: {{=OK if x 0 else bad}} Because these characters are not escaped in the code, the html file is no longer well formed. Using the html entities lt; and gr; does not solve the problem because web2py gives an error when theses characters are used as Python code in templates. Is it possible to fix this to have well formed html for web2py templates? This is a consequence of the way the '=' (request.write) operator behaves at the beginning of a code block: it treats the entire string as its argument string, something like: request.write('OK if x 0 else bad') You can rewrite it to use request.write explicitly, or to put each = operator on its own line. {{request.write(OK if x 0 else bad)}} or {{if x 0: =OK else: =bad pass }} (I think) When the '=' operator is embedded in a code block, it consumes everything until the end of the physical line or code block, whichever comes first. When it begins a code block, it consumes the entire block.
[web2py] Re: html templates using or
OK, So I have to accept that this is not real html. I guess the best thing for me is to enable the validation of my IDE when I am editing html files. This is a good thing because it helps avoid errors. But when I am done I can turn it off so I won't see the warnings and errors that I don't need. It seems to be the best thing to do. May be one day we will have a specific validation engine for web2py templates. On Mar 12, 6:51 pm, Jonathan Lundell jlund...@pobox.com wrote: I see. Yes, the templates are not themselves html, and once they're parsed, they're python, which gets executed to form the eventual html. I'm not sure how you'd work around that. Even if you were able to escape the python code (say by enclosing it in html comment blocks (which would have to be stripped off during parsing)), the template files are not in general complete html, relying as they do on layout or other included files. You run into the same problem with SSI; even though the SSI directives parse as html comments, the .shtml files are seldom valid html. Consider something like this: div id={{=myid}} I can't see an analyzer being happy with that regardless of what you did with it. As it is, it has illegal characters for an id. Wrapping it in html comments wouldn't help (I don't think html comments are legal in that context). Would it suffice to hide the template files from the IDE? Or at least fool it into treating them as plain text? On Mar 12, 3:11 pm, Jonathan Lundell jlund...@pobox.com wrote: On Mar 12, 2011, at 11:54 AM, Jonathan Lundell wrote: On Mar 12, 2011, at 11:39 AM, pierreth wrote: I think you mean the response object. Yes, response. The example code you gave still use the character so it does not help. Did you try it? How about the second version? Hmm. I take back what I said earlier: all versions work for me, including your original one. In what context are you using the expression? In fact, the problem is that web2py is not processing the xml document but it parse directly the html file. I would really like Massimo to fix this. On Mar 12, 2:15 pm, Jonathan Lundell jlund...@pobox.com wrote: On Mar 12, 2011, at 11:05 AM, pierreth wrote: Hello, I have small problem when the characters and are used in web2py html template views. Using them for Python breaks the html: {{=OK if x 0 else bad}} Because these characters are not escaped in the code, the html file is no longer well formed. Using the html entities lt; and gr; does not solve the problem because web2py gives an error when theses characters are used as Python code in templates. Is it possible to fix this to have well formed html for web2py templates? This is a consequence of the way the '=' (request.write) operator behaves at the beginning of a code block: it treats the entire string as its argument string, something like: request.write('OK if x 0 else bad') You can rewrite it to use request.write explicitly, or to put each = operator on its own line. {{request.write(OK if x 0 else bad)}} or {{if x 0: =OK else: =bad pass }} (I think) When the '=' operator is embedded in a code block, it consumes everything until the end of the physical line or code block, whichever comes first. When it begins a code block, it consumes the entire block.
[web2py] Re: Using Jython with web2py
On Nov 26, 6:41 pm, mdipierro mdipie...@cs.depaul.edu wrote: It works (some of us have tested it) but there are some know problems and I would not recommend it in production. One problem is a known problem with Java regular expression parses that Sun marked as won't fix. It is not a web2py specific problem but can cause some web2py templates send enter into a loop. This is the bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050507. Oracle seems to have a valid reason to not fix the bug. They are giving suggestions how to get around. It seems easy to refactor web2py apps having this problem unless regular are created dynamically but I guess this is rare. This seems to be the major problem with Jython and web2py. Do you have other reasons for not recommending web2py with Jython?
[web2py] Re: Using Jython with web2py
On Nov 29, 1:39 am, mdipierro mdipie...@cs.depaul.edu wrote: please let us know if things work or do not work. We have not tested web2py with jython much, Massimo Well, I won't dig that much in Jython with web2py for the moment. In a longer term interest, I would like to be able to use web2py in a Java infrastructure with Hibernate. I think it might be a really nice tool for prototyping in the enterprise world. Also I would like to use web2py with sqlalchemy with Python Spring. I see the mix of the three as a potential solution for the enterprise world too. In fact, I don't understand that you labeled web2py as an Enterprise Web Framework. Without wanting to offend you, I see web2py as a pragmatic, agile and extensible web framework for fast development. I think web2py as a too tight coupling for enterprise development. DAL in not a real ORM and it does not make it easy to apply domain driven design. Add the fact that the web2py book is mixing presentation with the control, I think web2py is favoring pragmatism over abstraction. It is not bad by itself but it conflicts with my vision of the enterprise way. I would appreciate your comments. Pierre
[web2py] Re: Using Jython with web2py
On Nov 29, 1:39 am, mdipierro mdipie...@cs.depaul.edu wrote: please let us know if things work or do not work. We have not tested web2py with jython much, Massimo Well, I won't dig that much in Jython with web2py for the moment. In a longer term interest, I would like to be able to use web2py in a Java infrastructure with Hibernate. I think it might be a really nice tool for prototyping in the enterprise world. Also I would like to use web2py with sqlalchemy with Python Spring. I see the mix of the three as a potential solution for the enterprise world too. In fact, I don't understand that you labeled web2py as an Enterprise Web Framework. Without wanting to offend you, I see web2py as a pragmatic, agile and extensible web framework for fast development. I think web2py as a too tight coupling for enterprise development. DAL in not a real ORM and it does not make it easy to apply domain driven design. Add the fact that the web2py book is mixing presentation with the control, I think web2py is favoring pragmatism over abstraction. It is not bad by itself but it conflicts with my vision of the enterprise way. I would appreciate your comments. Pierre
[web2py] Re: Using Jython with web2py
On Nov 29, 1:39 am, mdipierro mdipie...@cs.depaul.edu wrote: please let us know if things work or do not work. We have not tested web2py with jython much, Massimo Well, I won't dig that much in Jython with web2py for the moment. In a longer term interest, I would like to be able to use web2py in a Java infrastructure with Hibernate. I think it might be a really nice tool for prototyping in the enterprise world. Also I would like to use web2py with sqlalchemy with Python Spring. I see the mix of the three as a potential solution for the enterprise world too. In fact, I don't understand that you labeled web2py as an Enterprise Web Framework. Without wanting to offend you, I see web2py as a pragmatic, agile and extensible web framework for fast development. I think web2py as a too tight coupling for enterprise development. DAL in not a real ORM and it does not make it easy to apply domain driven design. Add the fact that the web2py book is mixing presentation with the control, I think web2py is favoring pragmatism over abstraction. It is not bad by itself but it conflicts with my vision of the enterprise way. I would appreciate your comments. Pierre
[web2py] Re: Using Jython with web2py
On Nov 29, 8:53 am, mdipierro mdipie...@cs.depaul.edu wrote: Why all your messages are always posted 2 or 3 times? We should try fix that. Sorry for this. I click the refresh button after a post for see what are the replies. This post back the same message again (I thought the interface would be smart enough to reject the double post but it is not the case). I will avoid to do it again. It seems the Google interface does not do a redirect after the post to avoid this situation. The real solution is for Google to add a redirect after a post.
[web2py] Re: Using Jython with web2py
On Nov 28, 2:18 am, mdipierro mdipie...@cs.depaul.edu wrote: There are two issues the bug in the line dbpath = os.path.join(self._folder, uri[14:]) instread of dbpath = os.path.join(self._folder, uri[9:]) is cutting sqlite://storage.sqlite short into ge.sqlite instead of storage.sqlite. This can be fixed by replacing 14 with 9. OK, the fix is right. I have 'storage.sqlite' intead of 'ge.sqlite' and the file is there. Maybe I missed that in my last post. Yet, the file ge.sqlite or storage.sqlite is not supposed to be there but created by the line: zxJDBC.connect(java.sql.DriverManager.getConnection('jdbc:sqlite:'+dbpath)) you are getting an error at this line: SQLException: java.sql.SQLException: No suitable driver found for jdbc:sqlite:/media/pierreth-backup/work/web2py/applications/welcome/ databases/ge.sqlite That means that your sqlite driver is not in the java classpath. But if I check at the Jython shell I have: import sys sys.path ['', '/opt/java/lib/sqlitejdbc-v056.jar', '/usr/local/share/java/ sqlite.jar', '/home/pierreth/opt/java/jython-2.5.1/Lib', '__classpath__', '__pyclasspath__/', '/home/pierreth/opt/java/ jython-2.5.1/Lib/site-packages'] import java.lang.System as System System.getProperty(java.library.path) u'/usr/local/lib' My jars are in the class path and my native library is at the right place too. I don't understand. But you are right when you say that the problem is at the Java level. I made a script in Groovy to access the same file and I have this error instead: Unable to load sqlite_jni: java.lang.UnsatisfiedLinkError: no sqlite_jni in java.library.path Caught: java.sql.SQLException: java.lang.UnsatisfiedLinkError: SQLite.Database.internal_init()V at temp.run(temp.groovy:5) I have 'libsqlite_jni.so' in /usr/local/lib and the java.library.path property points to this directory. I don't know... I will on the sqlite mailing list.
[web2py] Re: Using Jython with web2py
On Nov 28, 2:18 am, mdipierro mdipie...@cs.depaul.edu wrote: There are two issues the bug in the line dbpath = os.path.join(self._folder, uri[14:]) instread of dbpath = os.path.join(self._folder, uri[9:]) is cutting sqlite://storage.sqlite short into ge.sqlite instead of storage.sqlite. This can be fixed by replacing 14 with 9. OK, the fix is right. I have 'storage.sqlite' intead of 'ge.sqlite' and the file is there. Maybe I missed that in my last post. Yet, the file ge.sqlite or storage.sqlite is not supposed to be there but created by the line: zxJDBC.connect(java.sql.DriverManager.getConnection('jdbc:sqlite:'+dbpath)) you are getting an error at this line: SQLException: java.sql.SQLException: No suitable driver found for jdbc:sqlite:/media/pierreth-backup/work/web2py/applications/welcome/ databases/ge.sqlite That means that your sqlite driver is not in the java classpath. But if I check at the Jython shell I have: import sys sys.path ['', '/opt/java/lib/sqlitejdbc-v056.jar', '/usr/local/share/java/ sqlite.jar', '/home/pierreth/opt/java/jython-2.5.1/Lib', '__classpath__', '__pyclasspath__/', '/home/pierreth/opt/java/ jython-2.5.1/Lib/site-packages'] import java.lang.System as System System.getProperty(java.library.path) u'/usr/local/lib' My jars are in the class path and my native library is at the right place too. I don't understand. But you are right when you say that the problem is at the Java level. I made a script in Groovy to access the same file and I have this error instead: Unable to load sqlite_jni: java.lang.UnsatisfiedLinkError: no sqlite_jni in java.library.path Caught: java.sql.SQLException: java.lang.UnsatisfiedLinkError: SQLite.Database.internal_init()V at temp.run(temp.groovy:5) I have 'libsqlite_jni.so' in /usr/local/lib and the java.library.path property points to this directory. I don't know... I will on the sqlite mailing list.
[web2py] Re: Using Jython with web2py
I found the problem. I had to set CLASSPATH and not JYTHONPATH, I updated my blog to show the solution: http://pierrethibault.posterous.com/using-sqlite-with-java-on-linux. Everything works fine! :-) On Nov 28, 2:32 am, mdipierro mdipie...@cs.depaul.edu wrote: did you add the driver to the java classpath? as I said the bug is not the cause of the problem. this is not a web2py problem in fact.
[web2py] Re: Using Jython with web2py
I found the problem. I had to set CLASSPATH and not JYTHONPATH, I updated my blog to show the solution: http://pierrethibault.posterous.com/using-sqlite-with-java-on-linux. Everything works fine! :-) On Nov 28, 2:32 am, mdipierro mdipie...@cs.depaul.edu wrote: did you add the driver to the java classpath? as I said the bug is not the cause of the problem. this is not a web2py problem in fact.
[web2py] Re: Using Jython with web2py
I found the problem. I had to set CLASSPATH and not JYTHONPATH, I updated my blog to show the solution: http://pierrethibault.posterous.com/using-sqlite-with-java-on-linux. Everything works fine! :-) On Nov 28, 2:32 am, mdipierro mdipie...@cs.depaul.edu wrote: did you add the driver to the java classpath? as I said the bug is not the cause of the problem. this is not a web2py problem in fact.
[web2py] Re: Using Jython with web2py
On Nov 26, 6:41 pm, mdipierro mdipie...@cs.depaul.edu wrote: The instructions are here:http://web2py.com/book/default/chapter/12#Jython Make sure you have zxJDBC. I don't understand. zxJDBC is included with Jython from long time ago. I can do: from com.ziclix.python.sql import zxJDBC I don't remember having done the installation of this separately. Could you explain?
[web2py] Re: Using Jython with web2py
On Nov 28, 12:46 am, mdipierro mdipie...@cs.depaul.edu wrote: good. Can you try these three statements form shell? from com.ziclix.python.sql import zxJDBC import java.sql from org.sqlite import JDBC Massimo All these statements work without problem.
[web2py] Re: Using Jython with web2py
On Nov 28, 12:48 am, mdipierro mdipie...@cs.depaul.edu wrote: In gluon/sql.py there are these lines: try: from com.ziclix.python.sql import zxJDBC import java.sql from org.sqlite import JDBC drivers.append('zxJDBC') logger.warning('zxJDBC support is experimental') is_jdbc = True except: logger.debug('no zxJDBC driver') is_jdbc = False somehow the exception is raised. I see the message 'zxJDBC support is experimental' printed at the console. I don't know why but now I have a different error: Traceback (most recent call last): File /media/pierreth-backup/work/web2py/gluon/main.py, line 425, in wsgibase serve_controller(request, response, session) File /media/pierreth-backup/work/web2py/gluon/main.py, line 425, in wsgibase serve_controller(request, response, session) File /media/pierreth-backup/work/web2py/gluon/main.py, line 187, in serve_controller run_models_in(environment) File /media/pierreth-backup/work/web2py/gluon/compileapp.py, line 351, in run_models_in restricted(code, environment, layer) File /media/pierreth-backup/work/web2py/gluon/restricted.py, line 188, in restricted exec ccode in environment File /media/pierreth-backup/work/web2py/gluon/restricted.py, line 188, in restricted exec ccode in environment File /media/pierreth-backup/work/web2py/applications/welcome/models/ db.py, line 15, in module db = DAL('sqlite://storage.sqlite') # if not, use SQLite or other DB File /media/pierreth-backup/work/web2py/gluon/sql.py, line 4064, in DAL return SQLDB(uri, pool_size=pool_size, folder=folder, File /media/pierreth-backup/work/web2py/gluon/sql.py, line 4064, in DAL return SQLDB(uri, pool_size=pool_size, folder=folder, File /media/pierreth-backup/work/web2py/gluon/sql.py, line 1211, in __init__ self._pool_connection(lambda dbpath=dbpath: zxJDBC.connect(java.sql.DriverManager.getConnection('jdbc:sqlite:'+dbpath))) File /media/pierreth-backup/work/web2py/gluon/sql.py, line 893, in _pool_connection self._connection = f() File /media/pierreth-backup/work/web2py/gluon/sql.py, line 1211, in lambda self._pool_connection(lambda dbpath=dbpath: zxJDBC.connect(java.sql.DriverManager.getConnection('jdbc:sqlite:'+dbpath))) SQLException: java.sql.SQLException: No suitable driver found for jdbc:sqlite:/media/pierreth-backup/work/web2py/applications/welcome/ databases/ge.sqlite The file '/media/pierreth-backup/work/web2py/applications/welcome/ databases/ge.sqlite' does not exists in the directory.
[web2py] Re: Using Jython with web2py
On Nov 28, 12:48 am, mdipierro mdipie...@cs.depaul.edu wrote: In gluon/sql.py there are these lines: try: from com.ziclix.python.sql import zxJDBC import java.sql from org.sqlite import JDBC drivers.append('zxJDBC') logger.warning('zxJDBC support is experimental') is_jdbc = True except: logger.debug('no zxJDBC driver') is_jdbc = False somehow the exception is raised. I see the message 'zxJDBC support is experimental' printed at the console. I don't know why but now I have a different error: Traceback (most recent call last): File /media/pierreth-backup/work/web2py/gluon/main.py, line 425, in wsgibase serve_controller(request, response, session) File /media/pierreth-backup/work/web2py/gluon/main.py, line 425, in wsgibase serve_controller(request, response, session) File /media/pierreth-backup/work/web2py/gluon/main.py, line 187, in serve_controller run_models_in(environment) File /media/pierreth-backup/work/web2py/gluon/compileapp.py, line 351, in run_models_in restricted(code, environment, layer) File /media/pierreth-backup/work/web2py/gluon/restricted.py, line 188, in restricted exec ccode in environment File /media/pierreth-backup/work/web2py/gluon/restricted.py, line 188, in restricted exec ccode in environment File /media/pierreth-backup/work/web2py/applications/welcome/models/ db.py, line 15, in module db = DAL('sqlite://storage.sqlite') # if not, use SQLite or other DB File /media/pierreth-backup/work/web2py/gluon/sql.py, line 4064, in DAL return SQLDB(uri, pool_size=pool_size, folder=folder, File /media/pierreth-backup/work/web2py/gluon/sql.py, line 4064, in DAL return SQLDB(uri, pool_size=pool_size, folder=folder, File /media/pierreth-backup/work/web2py/gluon/sql.py, line 1211, in __init__ self._pool_connection(lambda dbpath=dbpath: zxJDBC.connect(java.sql.DriverManager.getConnection('jdbc:sqlite:'+dbpath))) File /media/pierreth-backup/work/web2py/gluon/sql.py, line 893, in _pool_connection self._connection = f() File /media/pierreth-backup/work/web2py/gluon/sql.py, line 1211, in lambda self._pool_connection(lambda dbpath=dbpath: zxJDBC.connect(java.sql.DriverManager.getConnection('jdbc:sqlite:'+dbpath))) SQLException: java.sql.SQLException: No suitable driver found for jdbc:sqlite:/media/pierreth-backup/work/web2py/applications/welcome/ databases/ge.sqlite The file '/media/pierreth-backup/work/web2py/applications/welcome/ databases/ge.sqlite' does not exists in the directory.
[web2py] Re: Using Jython with web2py
On Nov 28, 1:49 am, mdipierro mdipie...@cs.depaul.edu wrote: I found a bug. In gluon/sql.py replace elif is_jdbc and self._uri.startswith('sqlite://'): self._dbname='sqlite' if uri[9] != '/': dbpath = os.path.join(self._folder, uri[14:]) else: dbpath = uri[14:] with elif is_jdbc and self._uri.startswith('sqlite://'): self._dbname='sqlite' if uri[9] != '/': dbpath = os.path.join(self._folder, uri[9:]) else: dbpath = uri[9:] Does this fix anything? Sorry, I have the same error with this new code. And the file 'ge.slite' is still not there.
[web2py] Re: Using Jython with web2py
On Nov 28, 1:49 am, mdipierro mdipie...@cs.depaul.edu wrote: I found a bug. In gluon/sql.py replace elif is_jdbc and self._uri.startswith('sqlite://'): self._dbname='sqlite' if uri[9] != '/': dbpath = os.path.join(self._folder, uri[14:]) else: dbpath = uri[14:] with elif is_jdbc and self._uri.startswith('sqlite://'): self._dbname='sqlite' if uri[9] != '/': dbpath = os.path.join(self._folder, uri[9:]) else: dbpath = uri[9:] Does this fix anything? Sorry, I have the same error with this new code. And the file 'ge.slite' is still not there.
[web2py] Using Jython with web2py
Hello, I tried to use Jython with web2py. I am telling the story in my blog: http://pierrethibault.posterous.com/using-sqlite-with-java-on-linux So far, I have this error: Traceback (most recent call last): File /media/pierreth-backup/work/web2py/gluon/restricted.py, line 188, in restricted exec ccode in environment File /media/pierreth-backup/work/web2py/applications/welcome/models/ db.py, line 15, in module db = DAL('sqlite://storage.sqlite') # if not, use SQLite or other DB File /media/pierreth-backup/work/web2py/gluon/sql.py, line 4051, in DAL raise RuntimeError, %s (tried 5 times) % exception RuntimeError: global name 'sqlite3' is not defined (tried 5 times) Error snapshot help Detailed traceback description type 'exceptions.RuntimeError'(global name 'sqlite3' is not defined (tried 5 times)) How far have you been with Jython and web2py? Is it possible to make the two work together?
[web2py] Re: Unable to edit language files
On Nov 17, 1:51 am, JmiXIII sylvn.p...@gmail.com wrote: Salut ! :) What about having a look there :)https://groups.google.com/group/web2py-users-france?hl=fr This is cool. I already did the translation. This is not a big project. Now, we need to verify before integrated it. :-) I am waiting approbation for the group.
[web2py] Recipe about mixing web2py, pydev, GoogleCode and others
Hello, I just published a blog about mixing all this stuff in Eclipse for web2py development: # GC issue tracking with Mylyn; # GC versioning using Mercurial and the MercurialEclipse plug-in; # Pydev with code completion and code checking; # Aptana Studio plug-in for Eclipse for the edition of HTML and CSS files. http://pierreth.blogspot.com/2010/10/web2py-eclipse-pydev-recipe.html I hope you like. Comments are appreciated.
[web2py] Re: Unable to edit language files
I discover that the method T.translate is writing the current dictionary in memory to the file when a word is not found. This is causing me problems because I am changing my language files as I need. Is it possible to deactivate this behavior?
[web2py] Re: Unable to edit language files
On Nov 16, 6:23 pm, mdipierro mdipie...@cs.depaul.edu wrote: I am still trying to understand why this is a problem. web2py loads the langauge in ram, and uses. It finds a T(var) and var is not in dictionary, it assumes it needs to be translated, adds it to the dict and saves it on file. Somehow your code breaks this. How? What is the purpose of your code? Where is it, in a model? OK, I did a re-factoring of my code and everything is now fine and I have no bug. No more worry. My application is in English with translation in French. I wanted to be able to use codes for long texts. This means to always do the translation and look up in the en.py file when I use these codes. Also, I wanted to use specific language files in some cases. Now, my application works in French. Would you like the file? It enables web2py in French.
[web2py] Re: Unable to edit language files
On Nov 16, 6:23 pm, mdipierro mdipie...@cs.depaul.edu wrote: I am still trying to understand why this is a problem. web2py loads the langauge in ram, and uses. It finds a T(var) and var is not in dictionary, it assumes it needs to be translated, adds it to the dict and saves it on file. Somehow your code breaks this. How? What is the purpose of your code? Where is it, in a model? OK, I did a re-factoring of my code and everything is now fine and I have no bug. No more worry. My application is in English with translation in French. I wanted to be able to use codes for long texts. This means to always do the translation and look up in the en.py file when I use these codes. Also, I wanted to use specific language files in some cases. Now, my application works in French. Would you like the file? It enables web2py in French.
[web2py] Re: Unable to edit language files
On Nov 15, 12:19 am, mdipierro mdipie...@cs.depaul.edu wrote: On Nov 14, 7:00 pm, pierreth pierre.thibau...@gmail.com wrote: Hello, I've tried to edit my language files but my changes are all the time overwritten. Do you use windows? If so, do you Mark hammond win32 extesions No. OpenSuse 11.3. When I use the web interface of web2py to edit these files, some fields are in yellow. What is the meaning of this? It means the translation is the same as the original so probably they were not translated. How should I edit these files to have permanent changes? There is a button at the end. When you save them they should be permanent. Can you help isolate what causes them to be overwritten. I cannot reproduce it. May it is my code. Here I have some code manipulating the translator: def translate(word, language, T): Force the translation of word in language. Restore the state of T before returning. @param word: Word or text translate. @param language: The language used by the translator. @param T: The usual T translator. @return: The text translated in the requested language. accepted_language = T.accepted_language language_file = T.language_file lazy = T.lazy try: if language == None: language = en T.force(language) T.lazy = False return T(word) finally: T.accepted_language = accepted_language T.language_file = language_file T.lazy = lazy def translate_fallback(word, T, fallback=None): Try to do a translation like T(word) and fall back on a fall back language if it does not work. Restore the state of T before returning. @param word: Word or text translate. @param T: The usual T translator. @param fallback: The fall back language to used if the translation fail. If None, T.current_languages will be used. @return: The text translated. current_languages = T.current_languages try: T.set_current_languages(None) result = str(T(word)) if result == word: T.force(fallback or current_languages) result = str(T(word)) return result finally: T.set_current_languages(current_languages) Could this be the problem?
[web2py] Re: provide a development flag for applications II
On Nov 13, 11:33 pm, Christopher Steel chris.st...@gmail.com wrote: Works fine for me from the web2py shell: 1) install plugin 2) run the web2py shell:http://web2py.com/book/default/chapter/04?search=shell OR 3) run shell from browser: http://127.0.0.1:8000/admin/shell/index/yourapp 3) set the variable: _debug_on=True This does not seems easier than setting the variable somewhere in the model. What is the plug-in offering?
[web2py] Unable to edit language files
Hello, I've tried to edit my language files but my changes are all the time overwritten. When I use the web interface of web2py to edit these files, some fields are in yellow. What is the meaning of this? How should I edit these files to have permanent changes?
[web2py] provide a development flag for applications II
Massimo wrote: Date: Thu, 29 Jan 2009 09:47:25 -0800 (PST) Subject: Re: provide a development flag for applications OK let's just use WEB2PY_MODE than and it will appear in request.env.web2py_mode Notice we aready have request.env.web2py_path request.env.web2py_version Massimo - Yes, I would need it. It is still not there.
[web2py] Re: provide a development flag for applications II
On Nov 13, 3:42 pm, mdipierro mdipie...@cs.depaul.edu wrote: I lost the context of this. Can you explain more? Here is the old thread: https://groups.google.com/group/web2py/browse_thread/thread/65b6f8197af3eebd/f9c9488f71ba6893?hl=enlnk=gstq=provide+a+development+flag+for+applications#f9c9488f71ba6893
[web2py] Re: provide a development flag for applications II
On Nov 13, 5:07 pm, Jonathan Lundell jlund...@pobox.com wrote: On Nov 13, 2010, at 12:47 PM, pierreth wrote: If this is an application-specific flag (that is, unless the web2py core takes it into consideration), why wouldn't you just set it in your first-parsed model? This is what I did. But I believe it would better to have it at the web2py core. This way, it is the same convention for all applications and plug-ins. It enables plug-ins to know in what mode they are running so they can react accordingly. Otherwise, everyone will use its own convention.
[web2py] Re: provide a development flag for applications II
I think it would be cool to be able to run a web2py app in debug mode by using a flag on the command line.
[web2py] Re: provide a development flag for applications II
I think it would be cool to be able to run a web2py app in debug mode by using a flag on the command line.
[web2py] Re: Some beginner questions on form
On Nov 2, 7:38 pm, Jonathan Lundell jlund...@pobox.com wrote: On Nov 2, 2010, at 4:09 PM, pierreth wrote: A tuple works fine, but zero=None isn't part of the tuple. IS_IN_SET((Dr, Dre, M., Me, Mme, Mlle, Mr, Miss, Mrs, hon), zero=None) You are right. I was wrong.
[web2py] Re: Some beginner questions on form
I have a blank line in the menu when I use IS_IN_SET. How can I remove it?
[web2py] Re: Some beginner questions on form
On 29 oct, 03:22, David Marko dma...@tiscali.cz wrote: Yes, you can use dictionary to define values e.g. Field( 'name',requires=IS_IN_SET({'key1':'label1','key2':'label2','key3':'label3'}) ) David I'm beginning to really like web2py I think!
[web2py] Re: Some beginner questions on form
On 29 oct, 19:48, villas villa...@gmail.com wrote: Tuples. Even better, I didn't realise that advantage regarding sorting. Also in the book, please? :) Now yet in the book. A wonder that should be there!
[web2py] Re: Some beginner questions on form
On 29 oct, 19:48, villas villa...@gmail.com wrote: Tuples. Even better, I didn't realise that advantage regarding sorting. Also in the book, please? :) Now yet in the book. A wonder that should be there!
[web2py] Re: Some beginner questions on form
On 27 oct, 23:10, mdipierro mdipie...@cs.depaul.edu wrote: Field('name',requires=IS_IN_SET(('value1,'value2',value3'))) This is cool. Can I have valuex in the db while presenting something else to the user (I want to value in my db to be always in English but I need to translate these values for the user) without having to do a conversion function that will translate values send my the form to English?
[web2py] Some beginner questions on form
Hello, I am doing my first application with web2py and I don't know how to do some things with forms. Like I would like to show a drop menu to show the possible values for a text field. How can I specify this menu with define_table? Another thing that I would like to do is format postal code and phone numbers with javascript when the user leaves a field. Could you guide me on this?
[web2py] #...@pydevcodeanalysisignore in Web2py code
Hello, Is it possible to add the comment #...@pydevcodeanalysisignore in future versions of web2py to all the controllers and all the models of new applications created by the web2py admin? This comments stop the static code analysis made by Pydev. Because of the automatic import made by web2py, Pydev reports lots of error and lots of warning. I think this a feature that most Pydev will appreciate. Thank you.
[web2py] Re: Web2py and threads
I would appreciate a good reference to understand the concepts you are talking about. It is something new to me and I don't understand. On 25 août, 11:22, John Heenan johnmhee...@gmail.com wrote: No, nothing that abstract. Using WSGI forces a new thread for each request. This is is a simple and inefficient brute force approach that really only suits the simplest Python applications and where only a small number of concurrent connection might be expected. Any application that provides web services is going to OS block on file reading (and writing) and on database access. Using threads is a classic and easy way out that carries a lot of baggage. Windows has had a way out of this for years with its asynch (or event) notification set up through an OVERLAPPED structure. Lightttpd makes use of efficient event notification schemes like kqueue and epoll. Apache only uses such schemes for listening and Keep- Alives. No matter how careful one is with threads and processes there always appears to be unexpected gotchas. Python has a notorious example, the now fixed 'Beazly Effect' that affected the GIL. Also I don't think there is a single experienced Python user that trusts the GIL. John Heenan
[web2py] Re: Web2py and threads
On 24 août, 01:20, mdipierro mdipie...@cs.depaul.edu wrote: In Java a serverlet, as far as I understand, is a class which conforms to some API that allows it to serve one http request. Each instance is executed in its own thread. Yes, but one instance can be executed by multiple threads at the same time. It is one thread per request. EJB, Enterprise Java Beans, are running on their own threads. The Python equivalent of the serverlet API is a WSGI application and web2py is based on WSGI, therefore the parallelization mechanism is equivalent to Java serverlets. Is web2py running as a WSGI application when we do python web2py.py or is it only when used in a specific deployment with WSGI? In web2py (the same in Django, Pylons, any any WSGI app) each http request is executed in its own thread. Threads are recycled to server non-concurrent requests and reuse database connections (pooling) without need to close and reopen them. The web server can be configured for a min number and a max number of threads. So, as a web2py developer, what do I have to do to avoid synchronization problems in my application. Where is the danger of having multiple threads for the web2py developers? What are the instances shared my multiple threads? What are the instances living in their own threads? I think the GIL in this context is a false problem. In fact in production you can use Apache and run as many processes as the number of cores that you have. Each process will create as many threads as it needs to server multiple requests. The GIL is a problems only if one process runs multiple threads on multiple cores. It is possible there are some caveats with many cores but I have not really played with apache configurations and benchmarks. Yes but a web2py server is running with only one process and using more web2py processes for serving the same web2py app will lead to synchronization problems. With processors having more and more cores, having a web server that cannot use them is not very fun. It is an issue to be solved with Python 3.2 I think. Massimo Thank you for this precious information.
[web2py] Re: Web2py and threads
On 24 août, 13:04, mdipierro mdipie...@cs.depaul.edu wrote: when you do python web2py.py you do not start the wsgi app. You start the rocket web server which makes a number of threads. When a new http request arrives it is assigned to a free thread (or a new thread is created) and the wsgi is run in that thread to server that request and only that request. I guess that each time a thread is put in service the model is executed again. So, for the model, a version of the instance exist for each thread. Right? So, as a web2py developer, what do I have to do to avoid synchronization problems in my application. Where is the danger of having multiple threads for the web2py developers? What are the instances shared my multiple threads? What are the instances living in their own threads? You do have to do anything because every concurrency issue is taken care automatically. There are some DO NOTs: - do not ever call os.chdir - do not import third party modules that are not thread safe - do not use thread.start_new_thread and threading.Thread.start() - if you open a file that is not uniquely associate to this http/ request/client/session lock the file. OK
[web2py] Re: Web2py and threads
I don't understand. The link is broken at the moment. Do you mean using only on thread and dispatching using the observer pattern? Doing only one request at a time? It does not makes sense to me. But I guess there is something I don't understand... Can someone guide me? On 24 août, 20:04, mdipierro mdipie...@cs.depaul.edu wrote: I agree with you. web2py does not care. It is the web server that decides. The question that started this thread was about the built-in web server and it does follow the thread model. On Aug 24, 2:00 pm, John Heenan johnmhee...@gmail.com wrote: Can't we at least have an acknowledgement that it is not necessary for web2py to use a thread per request model and that web2py could instead use an event model?
[web2py] Web2py and threads
Hello, I would like to know how Web2py is managing threads. Is it like Java servlets where requests are mapped to servlets while one servlet object can be used by multiple threads at the same time to serve many requests? Are some users here using Jython with Web2py to get around the ugly Pyhton GIL? I would to know about your experience. -- Pierre
[web2py] Re: import of web2py modules very complicated
OK, Thank you for the explanation Massimo. I thought there is package called 'modules' in my web2py application directory so I can put my modules there and import them with 'import'. It is the natural way of doing thing. Now I understand the limitations you are facing.
[web2py] Re: import of web2py modules very complicated
On 14 juin, 08:11, mdipierro mdipie...@cs.depaul.edu wrote: It depends. If you want to import any NORMAL python module, put it in site packages and import it using normal python syntax. If you want to import web2py modules, i.e. modules that belong to a specific application only, then you have to follow the rules and not all modules can be imported this way. I don't understand. Could you explain?
[web2py] import of web2py modules very complicated
I found that importing modules in Web2py seems to be very complex: http://web2py.com/book/default/section/4/18 I have a module in 'modules' and I do 'import modules.my_module' to import the module in my application. This is working fine with Eclipse Pydev because I have setup the Python path for my application in Eclipse. But outside Eclipse, it does not work because the path is not there. Why should it be more complicated than that? I see this as a bug. I will modify my application to add the path but I believe this is the job of Web2py.
[web2py] Re: import of web2py modules very complicated
On 13 juin, 17:54, Jonathan Lundell jlund...@pobox.com wrote: Try local_import instead of import (same manual page). OK :-) I needed that to fix the warning of Pydev. Now I use a template like that at beginning of mvc files: # Fake the imports needed by the static code analyzer. if False: import gluon.languages.translator as T from gluon.cache import Cache from gluon.contrib.gql import GQLDB from gluon.globals import Request from gluon.globals import Response from gluon.globals import Session from gluon.html import * from gluon.http import HTTP from gluon.http import redirect from gluon.sql import DAL from gluon.sql import Field from gluon.sql import SQLDB from gluon.sqlhtml import SQLFORM from gluon.validators import * cache = Cache() request = Request() response = Response() session = Session()
[web2py] Unused key variable
How can I fix the 2 unused 'key' variable warning I have with Pydev in web2py/applications/web2pyfun/controllers/appadmin.py? I mean could someone fix it in the web2py code? It is the only warnings I have from web2py.
[web2py] Re: Support for conversation?
On 11 juin, 01:14, mdipierro mdipie...@cs.depaul.edu wrote: yes but people don't just navigate by submitting forms. they also navigate by clicking links. The only way to keep a conversation would be to store a token in request.args(0) and keep it there in all links. Still the conversation is fragile and ends if the user types in a url without the token. The navigation of a conversation is made with forms using posts and redirects so there are no arguments used because there is no get. If the user click a link or enter a new url he can return to the conversation using the back button (the page must comes from the browser's cache to get the value of the hidden field). If the user returns to the conversation by typing the url of the page of the conversation he has left, then the hidden field is not there to tell which conversation is active. In that case, the user is redirect to the first page of the conversation. There he can start a brand new conversation or he can continue an older conversation if the page lists all the available conversations to join in. If the user close a window during a conversation, a Javascript call may end the conversation. On Jun 11, 12:04 am, Thadeus Burgess thade...@thadeusb.com wrote: That is where the hidden input field with a custom hash comes into play I think? Yes, this is the purpose of the hidden field.
[web2py] Re: Support for conversation?
On 11 juin, 09:42, szimszon szims...@gmail.com wrote: This conversation thing could be handy for my inventory app... I just made use of session but the user starting new conversations to get the info to continue the original... after that we can't trust the info in session. ... :-o Yes, it is exactly the problem it solves.
[web2py] Re: Support for conversation?
On 11 juin, 01:14, mdipierro mdipie...@cs.depaul.edu wrote: The only way to keep a conversation would be to store a token in request.args(0) and keep it there in all links. Still the conversation is fragile and ends if the user types in a url without the token. An url parameter of a get request with the session id could be a way to return to a conversation after the display of a popup window (to give the user some info for example). This a useful feature to support while using a conversation.
[web2py] Support for conversation?
I would like to know if the idea of conversation would be great thing for Web2py. It is an idea coming from Java JBoss Seam http://www.redhat.com/docs/manuals/jboss/jboss-eap-4.2/doc/seam/Seam_Reference_Guide/Conversations_and_workspace_management-Seams_conversation_model.html. The idea is supporting a different state for each browser window. The framework is using a hidden field in the form to track the different windows. This way, the user is able to use multiple windows without interference. I don't see this feature in Web2py and would like to know what you think about. Pierre
[web2py] Re: Y'a-t-il des Québécois sur cette list e?
Encore un! Ça n'arrête plus! Une vraie peste! ;-) We suppose to speak in English... On 10 juin, 15:47, Jean Guy jean...@gmail.com wrote: [?] Je demandais s'il y avait des québécois qui développe avec Web2py et qui son inscrit sur cette liste? Jean Guy 330.gif 1 000AfficherTélécharger