import decimal
import datetime

import geojson
from geojson.codec import PyGFPEncoder as GeoJSONEncoder

class Encoder(GeoJSONEncoder):
    # SQLAlchemy's Reflecting Tables mechanism uses decimal.Decimal
    # for numeric columns and datetime.date for dates. simplejson
    # does'nt deal with these types. This class provides a simple
    # encoder to deal with objects of these types.

    def default(self, obj):
        if isinstance(obj, (datetime.date, datetime.datetime)):
            return obj.isoformat()
        return GeoJSONEncoder.default(self, obj)

def _render_json(value, renderer, request):
    if request is not None:
        if not hasattr(request, 'response_content_type'):
            callback = request.params.get('callback')
            if callback is None:
                request.response_content_type = 'application/json'
            else:
                request.response_content_type = 'text/javascript'
                return "%(callback)s(%(json)s);"%{'callback': callback, 'json': renderer(value)}
    return renderer(value)

def geojson_renderer_factory(info):
    def _render(value, system):
        request = system.get('request')
        return _render_json(value, lambda value: geojson.dumps(value, cls=Encoder, use_decimal=True), request)

    return _render

@@ -566,52 +566,186 @@
 def 
-_render_json(value, renderer, 
+geojson_renderer_factory(info):%0A    def _render(value, system):%0A        ret = geojson.dumps(value, cls=Encoder, use_decimal=True)%0A        request = system.get('
 request
-):%0A
+')%0A   
     
+ 
 if r
@@ -760,24 +760,28 @@
 s not None:%0A
+    
         if n
@@ -838,16 +838,20 @@
         
+  
+  
 callback
@@ -896,16 +896,20 @@
         
+    
 if callb
@@ -929,32 +929,36 @@
                 
+ 
+   
 request.response
@@ -992,16 +992,20 @@
 n/json'%0A
+    
         
@@ -1022,32 +1022,36 @@
                 
+    
 request.response
@@ -1104,16 +1104,19 @@
     
+  
+  
 ret
-urn %22
+ = '
 %25(ca
@@ -1138,10 +1138,12 @@
 )s);
-%22%25
+' %25 
 %7B'ca
@@ -1164,281 +1164,95 @@
 ack,
- 'json': renderer(value)%7D%0A    return renderer(value)%0A%0Adef geojson_renderer_factory(info):%0A    def _render(value, system):%0A        request = system.get('request')%0A        return _render_json(value, lambda value: geojson.dumps(value, cls=Encoder, use_decimal=True), request)%0A
+%0A                                                       'json': ret%7D%0A        return ret
 %0A   

refactor the GeoJSON renderer code a bit, removing an uncessary function call