Commits

imbolc committed 22a1059

change cfg.ROUTING to cfg.ROUTING_QUEUE

Comments (0)

Files changed (4)

     TEMPLATE_AUTO_RELOAD = False
     TEMPLATE_LOADER = 'pysi.template.file_loader'
     FLASH_COOKIE_NAME = u'pysi.flash'
-    ROUTING = 'pysi.auto_routing'  # функция или очередь функций роутинга
+    ROUTING_QUEUE = ['pysi.auto_routing']  # очередь функций роутинга
 
     def set_defaults(self, **kwargs):
         '''
 
 def render_to_string(rq, template, context=None):
     context = context or {}
+    if not isinstance(context, dict):
+        return unicode(context)
     for k, v in rq.context.iteritems():
         if k not in context:
             context[k] = v
                 app_name, path = path.split('/', 1)
                 f = open('%s/templates/%s' % (app_name, path))
             except (IOError, ValueError):
-                assert 0, 'template not found: %s' % fn
+                assert 0, 'template not found: %s' % path
         path = os.path.normpath(os.path.join(os.getcwd(), f.name))
         self.mtimes[path] = os.path.getmtime(path)
         return (f.read().decode('utf-8'), path, 
         '''
         def routing_queue(routing):
             list_obj_from_str(routing)
+            if len(routing) == 1:
+                return routing[0]
             def wrapper(rq):
                 for func in routing:
                     try:
                         return func(rq)
-                    except NotFound:
-                        continue
-                raise NotFound
+                    except HttpError, e:
+                        if e[0] == 404:
+                            continue
+                        raise
+                abort(404)
             return wrapper
         
         try:
         self.response_middlewares = [m().process_response for m in mdls
             if hasattr(m, 'process_response')]
         self.response_middlewares.reverse()
-
-        self.routing = obj_from_str(cfg.ROUTING)
-        if isinstance(self.routing, (tuple, list)):
-            self.routing = routing_queue(self.routing)
+        self.routing = routing_queue(cfg.ROUTING_QUEUE)
 
     def __call__(self, environ, start_response):
         try:
         except HttpError, e:
             if cfg.DEBUG:
                 res = Response(make_traceback(rq.host),
-                    code=404, content_type='text/plain')
+                    code=e[0], content_type='text/plain')
             else:
                 res = get_error_page(rq, e[0])
         except Exception:
 import os
 from setuptools import setup
 
-VERSION = '0.8.5'
+VERSION = '0.8.6'
 PACKAGE = 'pysi'
 
 if __name__ == '__main__':