Hi Neal,
  It is probably confusing because you're looking at sections of a
series of articles on writing your own framework.
      
http://blog.notdot.net/2010/01/Writing-your-own-webapp-framework-for-App-Engine

  You may want to look at using the routing from webapp-improved, or
the router code from it.
     http://code.google.com/p/webapp-improved/
     http://code.google.com/p/url-router/

  Might get you going easier.


Robert






On Sun, Dec 5, 2010 at 13:29, NealWalters <[email protected]> wrote:
> Maybe I'm getting way off track here, but I'd like to get my site back
> working today.
>
> Should framework.py look like this?  (This is based on Nick's prior
> blog: http://blog.notdot.net/2010/01/Webapps-on-App-Engine-part-1-Routing)
>
> I'm all for learning, but I need to get my website fixed ASAP without
> the DeadlineExceeded errors.  Ideally, I wouldn't have to inventor or
> write my own framework to do that???
>
> framework.py??? - attempt#2
> =====================
> import re
>
> class WSGILazyLoader(object):
>  def __init__(self, fullname):
>    self.modulename, sep, 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)
>
> class WSGIRouter(object):
>  def __init__(self):
>    self.routes = []
>
>  def connect(self, template, handler, **kwargs):
>    """Connects URLs matching a template to a handler application.
>
>    Args:
>      template: A template string, consisting of literal text and
> template
>        expressions of the form {label[: regex]}, where label is the
> mandatory
>        name of the expression, and regex is an optional regular
> expression.
>      handler: A WSGI application to execute when the template is
> matched.
>      **kwargs: Additional keyword arguments to pass along with those
> parsed
>        from the template.
>    """
>    route_re = re.compile(template_to_regex(template))
>    self.routes.append((route_re, handler, kwargs))
>
> import re
> var_regex = re.compile(r'''
>     \{          # The exact character "{"
>     (\w+)       # The variable name (restricted to a-z, 0-9, _)
>     (?::([^}]+))? # The optional :regex part
>     \}          # The exact character "}"
>     ''', re.VERBOSE)
> def template_to_regex(template):
>     regex = ''
>     last_pos = 0
>     for match in var_regex.finditer(template):
>         regex += re.escape(template[last_pos:match.start()])
>         var_name = match.group(1)
>         expr = match.group(2) or '[^/]+'
>         expr = '(?P<%s>%s)' % (var_name, expr)
>         regex += expr
>         last_pos = match.end()
>     regex += re.escape(template[last_pos:])
>     regex = '^%s$' % regex
>     return regex
>
>
> Errors:
> Traceback (most recent call last):
>  File "C:\Program Files (x86)\Google\google_appengine\google\appengine
> \tools\dev_appserver.py", line 3206, in _HandleRequest
>    self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
>  File "C:\Program Files (x86)\Google\google_appengine\google\appengine
> \tools\dev_appserver.py", line 3149, in _Dispatch
>    base_env_dict=env_dict)
>  File "C:\Program Files (x86)\Google\google_appengine\google\appengine
> \tools\dev_appserver.py", line 525, in Dispatch
>    base_env_dict=base_env_dict)
>  File "C:\Program Files (x86)\Google\google_appengine\google\appengine
> \tools\dev_appserver.py", line 2402, in Dispatch
>    self._module_dict)
>  File "C:\Program Files (x86)\Google\google_appengine\google\appengine
> \tools\dev_appserver.py", line 2312, in ExecuteCGI
>    reset_modules = exec_script(handler_path, cgi_path, hook)
>  File "C:\Program Files (x86)\Google\google_appengine\google\appengine
> \tools\dev_appserver.py", line 2208, in ExecuteOrImportScript
>    exec module_code in script_module.__dict__
>  File "c:\GoogleAppEngine\olexe3\main.py", line 443, in <module>
>    main()
>  File "c:\GoogleAppEngine\olexe3\main.py", line 440, 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)
> TypeError: 'WSGIRouter' object is not callable
>
> Thanks,
> 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.
>
>

-- 
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