Please help me to understand Nick's blog.
http://blog.notdot.net/2010/02/Webapps-on-App-Engine-part-6-Lazy-loading

If I tried "Import framework" I got "framework not found".  I assume
he wants us to substitute the name of my framework, which is webapp??

I created a file lazytest.py, with the following:

from google.appengine.ext import webapp
class TestHome(webapp.RequestHandler):

  def get(self):
     self.response.out.write('<h1>Hello Lazy World</h1>')

testHomeHandler = TestHome()



If I do this:


application = webapp.WSGIRouter()
application.connect('/',
framework.WSGILazyLoader('LazyTest.testHomeHandler'))

def main():
     run_wsgi_app(application)

then I get this error:
    application = webapp.WSGIRouter()
AttributeError: 'module' object has no attribute 'WSGIRouter'


So I tried more of what I had before, but with the insertion of the
LazyLoader class:
class WSGILazyLoader(object):
  def __init__(self, fullname):
    self.modulename, self.objname = fullname.rpartition('.')
    self.obj = None

  def __call__(self, environ, start_response):
    if not self.obj:
      __import__(self.modulename, globals(), locals())
      module = sys.modules[self.modulename]
      self.obj = module.__dict__[self.objname]
    return self.obj(environ, start_response)

def main():
     # i have temporarily removed 300 of my pages until I get these
simple ones to work
     application = webapp.WSGIApplication([
                    ('/',
WSGILazyLoader('LazyTest.testHomeHandler')),
                    ("/reportTaskLogs",        ReportTaskLogs),
                    ("/getImage",                 GetImage),
                    ("/getText",                    GetText),
                    ],
                           debug=True)

     run_wsgi_app(application)

then I get this error:

  File "c:\GoogleAppEngine\olexe3\main.py", line 449, in main
    application = webapp.WSGIApplication([ ('/',
WSGILazyLoader('LazyTest.testHomeHandler')),
  File "c:\GoogleAppEngine\olexe3\main.py", line 389, in __init__
    self.modulename, self.objname = fullname.rpartition('.')
ValueError: too many values to unpack

I went off to research "rpartition", and seems like maybe Nick had a
bug???  Surely, not Nick.
So I tried this, as the separator itself is returned in the
rpartition...

class WSGILazyLoader(object):
  def __init__(self, fullname):
    self.modulename, sep, self.objname = fullname.rpartition('.')
    self.obj = None



Now I'm getting this:
  File "c:\GoogleAppEngine\olexe3\main.py", line 451, in main
    run_wsgi_app(application)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine
\ext\webapp\util.py", line 97, in run_wsgi_app
    run_bare_wsgi_app(add_wsgi_middleware(application))
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine
\ext\webapp\util.py", line 115, in run_bare_wsgi_app
    result = application(env, _start_response)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine
\ext\webapp\__init__.py", line 500, in __call__
    handler = handler_class()
TypeError: __call__() takes exactly 3 arguments (1 given)

So now I'm totally lost.  Any help appreciated, or if anyone has a
sample app that works in this manner.

Neal




-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" 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/google-appengine?hl=en.

Reply via email to