1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | diff -r 576595d1d485 pylons/templates/default_project/+package+/config/environment.py_tmpl --- a/pylons/templates/default_project/+package+/config/environment.py_tmpl Thu Apr 24 12:16:56 2008 -0700 +++ b/pylons/templates/default_project/+package+/config/environment.py_tmpl Thu Apr 24 13:39:40 2008 -0700 @@ -6,6 +6,8 @@ from mako.lookup import TemplateLookup {{elif template_engine == 'genshi'}} from genshi.template import TemplateLoader +{{elif template_engine == 'jinja'}} +from jinja import ChoiceLoader, Environment, FileSystemLoader {{endif}} from pylons import config {{if sqlalchemy}} @@ -50,6 +52,13 @@ # Create the Genshi TemplateLoader config['pylons.app_globals'].genshi_loader = TemplateLoader( paths['templates'], auto_reload=True) + {{elif template_engine == 'jinja'}} + + # Create the Jinja Environment + config['pylons.app_globals'].jinja_env = Environment(loader=ChoiceLoader( + [FileSystemLoader(path) for path in paths['templates']])) + # Jinja's unable to request c's attributes without strict_c + config['pylons.strict_c'] = True {{endif}} {{if sqlalchemy}} # Setup SQLAlchemy database engine diff -r 576595d1d485 pylons/templates/default_project/+package+/lib/base.py_tmpl --- a/pylons/templates/default_project/+package+/lib/base.py_tmpl Thu Apr 24 12:16:56 2008 -0700 +++ b/pylons/templates/default_project/+package+/lib/base.py_tmpl Thu Apr 24 13:39:40 2008 -0700 @@ -3,7 +3,7 @@ Provides the BaseController class for subclassing. """ from pylons.controllers import WSGIController -{{if template_engine in ('genshi', 'mako')}} +{{if template_engine in ('genshi', 'jinja', 'mako')}} from pylons.templating import render_{{template_engine}} as render {{endif}} {{if sqlalchemy}} diff -r 576595d1d485 pylons/templates/minimal_project/+package+/controllers/__init__.py_tmpl --- a/pylons/templates/minimal_project/+package+/controllers/__init__.py_tmpl Thu Apr 24 12:16:56 2008 -0700 +++ b/pylons/templates/minimal_project/+package+/controllers/__init__.py_tmpl Thu Apr 24 13:39:40 2008 -0700 @@ -3,6 +3,9 @@ Provides the BaseController class for subclassing. """ from pylons.controllers import WSGIController +{{if template_engine in ('genshi', 'jinja', 'mako')}} +from pylons.templating import render_{{template_engine}} as render +{{endif}} class BaseController(WSGIController): diff -r 576595d1d485 pylons/templates/minimal_project/+package+/wsgiapp.py_tmpl --- a/pylons/templates/minimal_project/+package+/wsgiapp.py_tmpl Thu Apr 24 12:16:56 2008 -0700 +++ b/pylons/templates/minimal_project/+package+/wsgiapp.py_tmpl Thu Apr 24 13:39:40 2008 -0700 @@ -6,6 +6,8 @@ from mako.lookup import TemplateLookup {{elif template_engine == 'genshi'}} from genshi.template import TemplateLoader +{{elif template_engine == 'jinja'}} +from jinja import ChoiceLoader, Environment, FileSystemLoader {{endif}} from paste.cascade import Cascade from paste.registry import RegistryManager @@ -52,6 +54,13 @@ # Create the Genshi TemplateLoader config['pylons.app_globals'].genshi_loader = TemplateLoader( paths['templates'], auto_reload=True) + {{elif template_engine == 'jinja'}} + + # Create the Jinja Environment + config['pylons.app_globals'].jinja_env = Environment(loader=ChoiceLoader( + [FileSystemLoader(path) for path in paths['templates']])) + # Jinja's unable to request c's attributes without strict_c + config['pylons.strict_c'] = True {{endif}} # CONFIGURATION OPTIONS HERE (note: all config options will override diff -r 576595d1d485 pylons/templating.py --- a/pylons/templating.py Thu Apr 24 12:16:56 2008 -0700 +++ b/pylons/templating.py Thu Apr 24 13:39:40 2008 -0700 @@ -4,10 +4,11 @@ ============================ :mod:`pylons.templating` includes several basic render functions, -:func:`render_mako` and :func:`render_genshi` that render templates -from the file-system with the assumption that variables intended for -the will be attached to :data:`tmpl_context` (hereafter referred to -by its short name of :data:`c` which it is commonly imported as). +:func:`render_mako`, :func:`render_genshi` and :func:`render_jinja` that +render templates from the file-system with the assumption that variables +intended for the will be attached to :data:`tmpl_context` (hereafter +referred to by its short name of :data:`c` which it is commonly imported +as). The default render functions work with the template language loader object that is setup on the :data:`app_globals` object in the project's @@ -57,9 +58,9 @@ ---------------- Templates rendered in Pylons should include the default Pylons globals -as the :func:`render_mako` and :func:`render_genshi` functions. The -full list of Pylons globals that are included in the template's -namespace are: +as the :func:`render_mako`, :func:`render_genshi` and +:func:`render_jinja` functions. The full list of Pylons globals that are +included in the template's namespace are: - :term:`c` -- Template context object - :term:`tmpl_context` -- Template context object @@ -177,7 +178,7 @@ import pylons __all__ = ['Buffet', 'MyghtyTemplatePlugin', 'render', 'render_genshi', - 'render_mako', 'render_response'] + 'render_jinja', 'render_mako', 'render_response'] PYLONS_VARS = ['c', 'config', 'g', 'h', 'render', 'request', 'session', 'translator', 'ungettext', '_', 'N_'] @@ -301,7 +302,7 @@ return template.render(**globs) - return cached_template(template_name, render_template, cache_key=cache_key, + return cached_template(template_name, render_template, cache_key=cache_key, cache_type=cache_type, cache_expire=cache_expire) @@ -324,9 +325,33 @@ return template.generate(**globs).render(method=method) - return cached_template(template_name, render_template, cache_key=cache_key, + return cached_template(template_name, render_template, cache_key=cache_key, cache_type=cache_type, cache_expire=cache_expire, ns_options=('method'), method=method) + + +def render_jinja(template_name, cache_key=None, cache_type=None, + cache_expire=None): + """Render a template with Jinja + + Accepts the cache options ``cache_key``, ``cache_type``, and + ``cache_expire``. + + """ + # Create a render callable for the cache function + def render_template(): + # First, get the globals + globs = pylons_globals() + + # Grab a template reference + template = \ + globs['app_globals'].jinja_env.get_template(template_name) + + return template.render(**globs) + + return cached_template(template_name, render_template, cache_key=cache_key, + cache_type=cache_type, cache_expire=cache_expire) + class BuffetError(Exception): """Buffet Exception""" diff -r 576595d1d485 pylons/util.py --- a/pylons/util.py Thu Apr 24 12:16:56 2008 -0700 +++ b/pylons/util.py Thu Apr 24 13:39:40 2008 -0700 @@ -149,7 +149,7 @@ summary = 'Pylons application template' egg_plugins = ['PasteScript', 'Pylons'] vars = [ - var('template_engine', 'mako/genshi/etc: Template language', + var('template_engine', 'mako/genshi/jinja/etc: Template language', default='mako'), var('sqlalchemy', 'True/False: Include SQLAlchemy 0.4 configuration', default=False), @@ -182,7 +182,7 @@ _template_dir = 'templates/minimal_project' summary = 'Pylons minimal application template' vars = [ - var('template_engine', 'mako/genshi/etc: Template language', + var('template_engine', 'mako/genshi/jinja/etc: Template language', default='mako'), ] |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | diff -uprN pylons.7187766f7d8e/pylons/controllers/core.py pylons/pylons/controllers/core.py --- pylons.7187766f7d8e/pylons/controllers/core.py Tue Apr 22 17:04:34 2008 +++ pylons/pylons/controllers/core.py Tue Apr 22 17:04:34 2008 @@ -71,7 +71,11 @@ class WSGIController(object): args = kargs else: args = {} - argnames = argspec[0][1:] + if isinstance(func, types.FunctionType): + # staticmethod + argnames = argspec[0] + else: + argnames = argspec[0][1:] for name in argnames: if name in kargs: setattr(c, name, kargs[name]) @@ -137,7 +141,7 @@ class WSGIController(object): func = getattr(self, action_method, None) except UnicodeEncodeError: func = None - if isinstance(func, types.MethodType): + if isinstance(func, (types.FunctionType, types.MethodType)): # Store function used to handle request req.environ['pylons.action_method'] = func @@ -160,10 +164,10 @@ class WSGIController(object): self._py_object = environ['pylons.pylons'] # Keep private methods private - if environ['pylons.routes_dict'].get('action', '')[:1] in ('_', '-'): + action = environ['pylons.routes_dict'].get('action', '') + if action[:1] in ('_', '-') or action == 'start_response': if log_debug: - log.debug("Action starts with _, private action not allowed. " - "Returning a 404 response") + log.debug("Restricted action, returning a 404 response") return HTTPNotFound()(environ, start_response) start_response_called = [] diff -uprN pylons.7187766f7d8e/pylons/controllers/xmlrpc.py pylons/pylons/controllers/xmlrpc.py --- pylons.7187766f7d8e/pylons/controllers/xmlrpc.py Tue Apr 22 17:04:34 2008 +++ pylons/pylons/controllers/xmlrpc.py Tue Apr 22 17:04:34 2008 @@ -2,6 +2,7 @@ import inspect import logging import sys +import types import xmlrpclib from paste.response import replace_header @@ -163,7 +164,11 @@ class XMLRPCController(WSGIController): # Change the arg list into a keyword dict based off the arg # names in the functions definition - arglist = inspect.getargspec(func)[0][1:] + if isinstance(func, types.FunctionType): + # staticmethod + arglist = inspect.getargspec(func)[0] + else: + arglist = inspect.getargspec(func)[0][1:] kargs = dict(zip(arglist, rpc_args)) kargs['action'], kargs['environ'] = method, environ kargs['start_response'] = start_response @@ -200,6 +205,12 @@ class XMLRPCController(WSGIController): """Locate a method in the controller by the specified name and return it """ + # Keep private methods private + if name[:1] == '_' or name == 'start_response': + if self._pylons_log_debug: + log.debug("Restricted action, returning a 404 response") + return None + if self._pylons_log_debug: log.debug("Looking for XMLRPC method: %r", name) try: @@ -228,9 +239,8 @@ class XMLRPCController(WSGIController): methods = [] for method in dir(self): meth = getattr(self, method) - - # Only methods have this attribute - if not method.startswith('_') and hasattr(meth, 'im_self'): + if (not (method[:1] == '_' or method == 'start_response') and + isinstance(meth, (types.FunctionType, types.MethodType))): methods.append(self._publish_method_name(method)) return methods system_listMethods.signature = [['array']] |
1 2 3 4 5 6 7 8 9 10 11 | --- pylons.2a7ba5b3b714/pylons/templates/default_project/+package+/websetup.py_tmpl Wed Apr 16 15:12:06 2008 +++ /beans/home/pjenvey/src/python/pylons/pylons/templates/default_project/+package+/websetup.py_tmpl Wed Apr 16 14:51:31 2008 @@ -12,7 +12,7 @@ def setup_config(command, filename, sect """Place any commands to setup {{package}} here""" confuri = "config:" + filename if ":" in section: - confuri += "#" + section.rsplit(":", 1)[-1] + confuri += "#" + section.split(":", 1)[-1] conf = appconfig(confuri) load_environment(conf.global_conf, conf.local_conf) |
1 2 3 4 5 6 7 8 9 10 11 12 | I followed the recipe at : http://docs.pythonweb.org/display/pylonscookbook/Making+a+SOAP+Controller+with+Optio%27s+Soaplib. Routes version 1.7 and 1.8. Pylons 0.9.6.1 Python 2.5 soaplib 0.7.2dev-r27 >>> print client.plop() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.5/site-packages/soaplib-0.7.2dev_r27-py2.5.egg/soaplib/client.py", line 156, in __call__ raise Exception('%s %s %s %s'%(response.status,response.reason,self.host,self.path)) Exception: 301 Moved Permanently |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | class DeveloperController(BaseController): def __before__(self): """prepending Facebook authentication layer on this controller excluded actions: post_remove, welcome, help, privacy, tos """ action = request.environ['pylons.routes_dict']['action'] c.facebook = facebook if facebook.check_session() and facebook.added: c.is_admin = facebook.pages.isAdmin(page_id=g.page_id) elif action == 'post_remove': pass elif facebook.in_canvas and action in ('welcome', 'help', 'privacy', 'tos'): pass else: url = facebook.get_add_url() if facebook.in_canvas: log.debug("Force user to add app: facebook.redirect_to(%r)" % url) return '<fb:redirect url="%s" />' % url #this doesn't stop the controller else: h.redirect_to(url) #this works! |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | def pylons_globals(): """Create and return a dictionary of global Pylons variables Render functions should call this to retrieve a list of global Pylons variables that should be included in the global template namespace if possible. Pylons variables that are returned in the dictionary: c, g, h, _, N_, config, request, response, translator, ungettext """ conf = pylons.config._current_obj() pylons_vars = dict( c=pylons.c._current_obj(), config=conf, g=conf['pylons.g'], h=conf.get('pylons.h') or pylons.h._current_obj(), request=pylons.request._current_obj(), response=pylons.response._current_obj(), translator=pylons.translator._current_obj(), ungettext=pylons.i18n.ungettext, _=pylons.i18n._, N_=pylons.i18n.N_ ) # If the session was overriden to be None, don't populate the session # var if pylons.config['pylons.environ_config'].get('session', True): pylons_vars['session'] = pylons.session._current_obj() log.debug("Created render namespace with pylons vars: %s", pylons_vars) return pylons_vars def cached_template(template_name, render_func, ns_options=(), cache_key=None, cache_type=None, cache_expire=None, **kwargs): """Cache and render a template Cache a template to the namespace ``template_name``, along with a specific key if provided. Basic Options ``template_name`` Name of the template, which is used as the template namespace. ``render_func`` Function used to generate the template should it no longer be valid or doesn't exist in the cache. ``ns_options`` Tuple of strings, that should correspond to keys likely to be in the ``kwargs`` that should be used to construct the namespace used for the cache. For example, if the template language supports the 'fragment' option, the namespace should include it so that the cached copy for a template is not the same as the fragment version of it. Caching options (uses Beaker caching middleware) ``cache_key`` Key to cache this copy of the template under. ``cache_type`` Valid options are ``dbm``, ``file``, ``memory``, ``database``, or ``memcached``. ``cache_expire`` Time in seconds to cache this template with this ``cache_key`` for. Or use 'never' to designate that the cache should never expire. The minimum key required to trigger caching is ``cache_expire='never'`` which will cache the template forever seconds with no key. """ # If one of them is not None then the user did set something if cache_key is not None or cache_expire is not None or cache_type \ is not None: if not cache_type: cache_type = 'dbm' if not cache_key: cache_key = 'default' if cache_expire == 'never': cache_expire = None namespace = template_name for name in ns_options: namespace += str(kwargs.get(name)) cache = pylons.cache.get_cache(namespace) content = cache.get_value(cache_key, createfunc=render_func, type=cache_type, expiretime=cache_expire) return content else: return render_func() def render_mako(template_name, **kwargs): """Render a template with Mako Accepts the cache options ``cache_key``, ``cache_type``, and ``cache_expire`` in addition to other keyword arguments that should be passed into Mako's ``Template.render`` function. """ # First, get the globals globs = pylons_globals() # Try and grab a template reference try: template = globs['g'].mako_lookup.get_template(template_name) except AttributeError: from mako.lookup import TemplateLookup # Make the Mako TemplateLookup instance since it wasn't there globs['g'].mako_lookup = TemplateLookup( directories=globs['config']['pylons.paths']['templates']) template = globs['g'].mako_lookup.get_template(template_name) # Update the template variables with the Pylons globals kwargs.update(globs) def render_template(): return template.render(**kwargs) return cached_template(template_name, render_template, ns_options=('fragment',), **kwargs) def render_genshi(template_name, **kwargs): """Render a template with Genshi Accepts the cache options ``cache_key``, ``cache_type``, and ``cache_expire`` in addition to other keyword arguments that should be passed into Mako's ``Template.render`` function. """ # First, get the globals globs = pylons_globals() # Try and grab a template reference try: template = globs['g'].genshi_loader.load(template_name) except AttributeError: from genshi.template import TemplateLoader # Make the Genshi TemplateLoader instance since it wasn't there globs['g'].genshi_loader = TemplateLoader( globs['config']['pylons.paths']['templates']) template = globs['g'].genshi_loader.load(template_name) # Update the template variables with the Pylons globals kwargs.update(globs) def render_template(): return template.generate(**kwargs).render() return cached_template(template_name, render_template, ns_options=('fragment', 'format'), **kwargs) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | def pylons_globals(): """Create and return a dictionary of global Pylons variables Render functions should call this to retrieve a list of global Pylons variables that should be included in the global template namespace if possible. Pylons variables that are returned in the dictionary: c, g, h, _, N_, config, request, response, translator, ungettext """ conf = pylons.config._current_obj() pylons_vars = dict( c=pylons.c._current_obj(), config=conf, g=conf['pylons.g'], h=conf.get('pylons.h') or pylons.h._current_obj(), request=pylons.request._current_obj(), response=pylons.response._current_obj(), translator=pylons.translator._current_obj(), ungettext=pylons.i18n.ungettext, _=pylons.i18n._, N_=pylons.i18n.N_ ) # If the session was overriden to be None, don't populate the session # var if pylons.config['pylons.environ_config'].get('session', True): pylons_vars['session'] = pylons.session._current_obj() log.debug("Created render namespace with pylons vars: %s", pylons_vars) return pylons_vars def cached_template(template_name, render_func, ns_options=(), cache_key=None, cache_type=None, cache_expire=None, **kwargs): """Cache and render a template Cache a template to the namespace ``template_name``, along with a specific key if provided. Basic Options ``template_name`` Name of the template, which is used as the template namespace. ``render_func`` Function used to generate the template should it no longer be valid or doesn't exist in the cache. ``ns_options`` Tuple of strings, that should correspond to keys likely to be in the ``kwargs`` that should be used to construct the namespace used for the cache. For example, if the template language supports the 'fragment' option, the namespace should include it so that the cached copy for a template is not the same as the fragment version of it. Caching options (uses Beaker caching middleware) ``cache_key`` Key to cache this copy of the template under. ``cache_type`` Valid options are ``dbm``, ``file``, ``memory``, ``database``, or ``memcached``. ``cache_expire`` Time in seconds to cache this template with this ``cache_key`` for. Or use 'never' to designate that the cache should never expire. The minimum key required to trigger caching is ``cache_expire='never'`` which will cache the template forever seconds with no key. """ # If one of them is not None then the user did set something if cache_key is not None or cache_expire is not None or cache_type \ is not None: if not cache_type: cache_type = 'dbm' if not cache_key: cache_key = 'default' if cache_expire == 'never': cache_expire = None namespace = template_name for name in ns_options: namespace += str(kwargs.get(name)) cache = pylons.cache.get_cache(namespace) content = cache.get_value(cache_key, createfunc=render_func, type=cache_type, expiretime=cache_expire) return content else: return render_func() def mako_render(template_name, **kwargs): """Render a template with Mako """ from mako.lookup import TemplateLookup # First, get the globals globs = pylons_globals() # Try and grab a template reference try: template = globs['g'].mako_lookup.get_template(template_name) except AttributeError: # Make the Mako TemplateLookup instance since it wasn't there g.mako_lookup = TemplateLookup( directories=globs['config']['pylons.paths']['templates']) template = globs['g'].mako_lookup.get_template(template_name) # Update the template variables with the Pylons globals kwargs.update(globs) def render_template(): return template.render(**kwargs) return cached_template(template_name, render_template, ns_options=('fragment',), **kwargs) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | def mako_render(template_name, **kwargs): """Render a template with Mako""" from mako.lookup import TemplateLookup # First, get the globals globs = pylons_globals() g = globs['g'] # Try and grab a template reference, or make the lookup try: template = g.mako_lookup.get_template(template_name) except AttributeError: g.mako_lookup = TemplateLookup( directories=globs['config']['pylons.paths']['templates']) template = g.mako_lookup.get_template(template_name) # Update the template variables with the Pylons globals kwargs.update(globs) # Render the template return template.render(**kwargs) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import logging from pylons import request, response, session from pylons import tmpl_context as c from pylons.controllers.util import abort, forward, redirect_to, url_for from pylons.templating import render from forwarder.lib.base import BaseController from paste.fileapp import FileApp log = logging.getLogger(__name__) class HelloController(BaseController): def index(self): return forward(FileApp('/tmp/hi/hello.py')) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | --- pylons-clean.f6873f454528/pylons/controllers/util.py Sat Mar 1 15:18:19 2008 +++ pylons-clean/pylons/controllers/util.py Sat Mar 1 15:18:19 2008 @@ -241,6 +241,20 @@ def etag_cache(key=None): log.debug("ETag didn't match, returning response object") return pylons.response +def forward(wsgi_app): + """Forward the request to a WSGI application + + .. code-block:: Python + + return forward(FileApp('filename')) + + """ + request = pylons.request._current_obj() + controller = request.environ.get('pylons.controller') + assert controller + assert hasattr(controller, 'start_response') + return wsgi_app(request.environ, controller.start_response) + def abort(status_code=None, detail="", headers=None, comment=None): """Aborts the request immediately by returning an HTTP exception diff -uprN pylons-clean.f6873f454528/pylons/wsgiapp.py pylons-clean/pylons/wsgiapp.py --- pylons-clean.f6873f454528/pylons/wsgiapp.py Sat Mar 1 15:18:19 2008 +++ pylons-clean/pylons/wsgiapp.py Sat Mar 1 15:18:19 2008 @@ -249,6 +249,7 @@ class PylonsApp(object): log.debug("Controller appears to be a class, instantiating") controller = controller() controller._pylons_log_debug = log_debug + environ['pylons.controller'] = controller # Controller is assumed to handle a WSGI call if log_debug: |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | webroot@etch:~$ source CBG1/bin/activate (CBG1)webroot@etch:~$ easy_install MySQL-python Searching for MySQL-python Reading http://pypi.python.org/simple/MySQL-python/ Reading http://sourceforge.net/projects/mysql-python Reading http://sourceforge.net/projects/mysql-python/ Best match: MySQL-python 1.2.2 Downloading http://osdn.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.2.tar.gz Processing MySQL-python-1.2.2.tar.gz Running MySQL-python-1.2.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-itldS_/MySQL-python-1.2.2/egg-dist-tmp-biuNKM sh: mysql_config: command not found Traceback (most recent call last): File "/home/webroot/CBG1/bin/easy_install", line 7, in ? sys.exit( File "/home/webroot/CBG1/lib/python2.4/site-packages/setuptools-0.6c7-py2.4.egg/setuptools/command/easy_install.py", line 1670, in main with_ei_usage(lambda: File "/home/webroot/CBG1/lib/python2.4/site-packages/setuptools-0.6c7-py2.4.egg/setuptools/command/easy_install.py", line 1659, in with_ei_usage return f() File "/home/webroot/CBG1/lib/python2.4/site-packages/setuptools-0.6c7-py2.4.egg/setuptools/command/easy_install.py", line 1674, in <lambda> distclass=DistributionWithoutHelpCommands, **kw File "distutils/core.py", line 149, in setup File "distutils/dist.py", line 946, in run_commands File "distutils/dist.py", line 966, in run_command File "/home/webroot/CBG1/lib/python2.4/site-packages/setuptools-0.6c7-py2.4.egg/setuptools/command/easy_install.py", line 211, in run self.easy_install(spec, not self.no_deps) File "/home/webroot/CBG1/lib/python2.4/site-packages/setuptools-0.6c7-py2.4.egg/setuptools/command/easy_install.py", line 446, in easy_install return self.install_item(spec, dist.location, tmpdir, deps) File "/home/webroot/CBG1/lib/python2.4/site-packages/setuptools-0.6c7-py2.4.egg/setuptools/command/easy_install.py", line 471, in install_item dists = self.install_eggs(spec, download, tmpdir) File "/home/webroot/CBG1/lib/python2.4/site-packages/setuptools-0.6c7-py2.4.egg/setuptools/command/easy_install.py", line 655, in install_eggs return self.build_and_install(setup_script, setup_base) File "/home/webroot/CBG1/lib/python2.4/site-packages/setuptools-0.6c7-py2.4.egg/setuptools/command/easy_install.py", line 930, in build_and_install self.run_setup(setup_script, setup_base, args) File "/home/webroot/CBG1/lib/python2.4/site-packages/setuptools-0.6c7-py2.4.egg/setuptools/command/easy_install.py", line 919, in run_setup run_setup(setup_script, args) File "/home/webroot/CBG1/lib/python2.4/site-packages/setuptools-0.6c7-py2.4.egg/setuptools/sandbox.py", line 26, in run_setup DirectorySandbox(setup_dir).run( File "/home/webroot/CBG1/lib/python2.4/site-packages/setuptools-0.6c7-py2.4.egg/setuptools/sandbox.py", line 63, in run return func() File "/home/webroot/CBG1/lib/python2.4/site-packages/setuptools-0.6c7-py2.4.egg/setuptools/sandbox.py", line 29, in <lambda> {'__file__':setup_script, '__name__':'__main__'} File "setup.py", line 16, in ? File "/tmp/easy_install-itldS_/MySQL-python-1.2.2/setup_posix.py", line 43, in get_config File "/tmp/easy_install-itldS_/MySQL-python-1.2.2/setup_posix.py", line 24, in mysql_config EnvironmentError: mysql_config not found |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | class ErrorRedirect(object): """Internally redirects a request based on status code ErrorRedirect watches the response of the app it wraps. If the response is an error code in the errors sequence passed the request will be re-run with the path URL set to the path passed in. This operation is non-recursive and the output of the second request will be used no matter what it is. Should an application wish to bypass the error response (ie, to purposely return a 401), set ``environ['pylons.error_redirect'] = True`` in the application. """ def __init__(self, app, errors=(401,403,404), path='/error/document'): """Initialize the ErrorRedirect ``errors`` A sequence (list, tuple) of error code integers that should be caught. ``path`` The path to set for the next request down to the application. """ self.app = app self.errors = errors self.error_path = path def __call__(self, environ, start_response): req = Request(environ) resp = req.get_response(self.app, catch_exc_info=True) if int(resp.status[:3]) in self.errors and \ 'pylons.error_redirect' not in environ and self.error_path: environ['SCRIPT_NAME'] = '' environ['PATH_INFO'] = self.error_path environ['REQUEST_METHOD'] = 'GET' environ['pylons.original_response'] = resp req = Request(environ) resp = req.get_response(self.app, catch_exc_info=True) return resp(environ, start_response) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # middleware class ErrorRedirect(object): def __init__(self, app, errors, error_path): self.app = app self.errors = errors self.error_path = error_path def __call__(self, environ, start_response): req = Request(environ) resp = req.get_response(self.app) if int(resp.status[:3]) in self.errors and \ 'pylons.bypass_error_doc' not in environ: environ['SCRIPT_NAME'] = '' environ['PATH_INFO'] = self.error_path environ['REQUEST_METHOD'] = 'GET' req = Request(environ) resp = req.get_response(self.app) return resp(environ, start_response) # in proj/middleware.py #app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) app = ErrorRedirect(app, [401,403,404], '/error/document') |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | ### 1) file dbshop/scripts/art_trans_shop.py: import os import sys # put the models dir into the path here_dir = os.path.dirname(os.path.abspath(__file__)) parent_dir = os.path.dirname(here_dir) models_dir = os.path.join(parent_dir, 'models') sys.path.insert(0, models_dir) # article_lan.py is in the dbshop/models dir: from article_lan import ArticleLan ------------------------------------------------------- ### 2) file dbshop/models/article_lan.py import dbshop.lib.my as my # this is the first line and it already raises the error ----------------------------- ### 3) this is how i call it and the error message: >python art_trans_shop.py Traceback (most recent call last): File "art_trans_shop.py", line 16, in ? from article_lan import ArticleLan File "c:\Programme\shopsync-apt9\dbshop\dbshop\models\article_lan.py", line 1, in ? import dbshop.lib.my as my ImportError: No module named dbshop.lib.my |
1 2 3 4 5 6 7 8 9 10 11 12 | # this is only an example and assumes you have the tables ... mapper(Vehicles, Vehicles_table, order_by=[sqla.desc(Vehicles_table.c.date)], properties ={ 'cars': sqla.relation(cars, backref='vehicles'), 'planes': sqla.relation(planes, backref='vehicles'), 'carriages': sqla.relation(carriages, backref='vehicles'), 'trucks': sqla.relation(trucks, backref='vehicles'), 'motorbikes': sqla.relation(motorbikes, backref='vehicles') }, extension=sac.ext) |