Sorry, I'm afraid I'm still not getting it. I can see how it would be possible to pass the request object to each function within my custom module, and then decide if it's appropriate to import the GAE-specific routines. This conditional import would need to happen in every function within my custom module, correct?
But it would be nicer to avoid duplicating that import -- if it's possible to do the conditional import at the top of a module. It seems to me that a conditional import statement at the top of a custom module cannot successfully reference the request object -- because it is not contained in a function, so I don't know how to pass the request object to the module - is that possible? Or is there another way to determine if it's running on GAE? Dan On Jul 12, 8:42 am, mdipierro <[email protected]> wrote: > You can one one import statement at the top of the module. > > As far as global objects, it depends. I suggest defining a class, pass > the globals to the contructor, store them, so that all methods have > access to them as needed. > > On Jul 12, 9:42 am, Dan <[email protected]> wrote: > > > ok, that makes sense. And would I need to put import statements > > inside each function in my custom module? Or can I do something to get > > that module-level reference to request/response/session/etc working? > > > On Jul 11, 10:21 pm, mdipierro <[email protected]> wrote: > > > > This is not a bad idea but there some rules to follow. > > > > request, response, session, cache, T are global objects in web2py so > > > if you import a function from a module, you have to pass those 5 > > > objects to the function (not all of them, only those you need). You > > > probably want to pass your database connection too. > > > > All the other web2py keywords can be imported from your modules as > > > needed. > > > > Massimo > > > > On Jul 11, 5:48 pm, Dan <[email protected]> wrote: > > > > > Hello- > > > > I want to re-use some data access routines in a few different > > > > controller files, so I would like to put them in a separate file in > > > > the /modules directory, and then import that file into the controller > > > > files that need them. However, I'm running into this error because I'm > > > > trying to use some web2py stuff in my module, like caching - and this > > > > is a conditional import that depends on accessing the request > > > > variable. > > > > > in /modules/my_module.py: > > > > if request.env.web2py_runtime_gae: # if running on Google App Engine > > > > from gluon.contrib.gae_memcache import MemcacheClient > > > > cache.ram=cache.disk=MemcacheClient(request) > > > > > error: > > > > name 'request' is not defined > > > > > Another way to put it is that I'm building an abstraction layer on top > > > > of web2py's DAL so that I can reuse my code. Is this possible? Or > > > > maybe a bad idea? > > > > > Dan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

