Commits

Anonymous committed 26a135c Merge

unfixed the json fix fix.

Comments (0)

Files changed (4)

 *.pyo
 *.swp
 .coverage
+.noseids
 
 syntax: regexp
 ^build

tg/controllers/decoratedcontroller.py

 from tg.render import render as tg_render
 from tg.decorators import expose
 from tg.flash import flash
-from tg.jsonify import JsonEncodeError, is_saobject
+from tg.jsonify import is_saobject
 
 from util import pylons_formencode_gettext
 
 
         self._initialize_validation_context()
 
-        pylons.request.start_response = self.start_response
+        pylons.request.start_response = getattr(self, 'start_response', None)
 
         remainder = remainder or []
         try:
         if content_type is not None: 
             pylons.response.headers['Content-Type'] = content_type
 
-        # skip all the complicated stuff if we're don't have a dict-like object
-        # to work with.
-        try:
-            value = response['test']
-        except TypeError:
-            #json-defined objects must be dict-like
-            if engine_name == 'json' and not hasattr(response, '__json__') and not isinstance(response, basestring) and not is_saobject(response):
-                raise JsonEncodeError('Your Encoded object must be dict-like.')
+        # if it's a string return that string and skip all the stuff
+        if not isinstance(response, dict):
             return response
-        except:
-            pass
 
         """Return a JSON string representation of a Python object."""
 
             error_handler = controller
             output = error_handler(*remainder, **dict(params))
         elif hasattr(error_handler, 'im_self') and error_handler.im_self != controller:
-            output = error_handler(*remainder, **dict(params))
+            output = error_handler(error_handler.im_self, *remainder, **dict(params))
         else:
             output = error_handler(controller.im_self, *remainder, **dict(params))
 

tg/controllers/dispatcher.py

         if pylons.config.get('i18n_enabled', True):
             setup_i18n()
 
-        url_path = pylons.request.path.split('/')[1:]
+        script_name = pylons.request.environ.get('SCRIPT_NAME', '')
+        url_path = pylons.request.path
+        if url_path.startswith(script_name):
+            url_path = url_path[len(script_name):]
+        url_path = url_path.split('/')[1:]
 
         if url_path[-1] == '':
             url_path.pop()

tg/tests/test_tg_controller_dispatch.py

 from wsgiref.simple_server import demo_app
 from wsgiref.validate import validator
 
+from pylons import config
+config['renderers'] = ['genshi', 'mako', 'json']
+
 def setup():
     setup_session_dir()
 def teardown():
     @expose('json')
     def stacked_expose(self):
         return dict(got_json=True)
-    
+
     @expose('json')
     def bad_json(self):
         return [(1, 'a'), 'b']
 
     def test_response_type(self):
         r = self.app.post('/stacked_expose.json')
-        assert 'got_json' in r, r
+        assert 'got_json' in r.body, r
 
     def test_multi_value_kw(self):
         r = self.app.get('/multi_value_kws?foo=1&foo=2')
         assert 'PNG' in resp, resp
         assert resp.headers['Content-Type'] == 'image/png', resp
     
-    @raises(tg.jsonify.JsonEncodeError)
-    def test_bad_json(self):
-        resp = self.app.get('/bad_json')
-        assert 'ab' not in resp.body, resp