old_contents: from twisted.python.failure import Failure
  from twisted.web.resource import Resource
  import cStringIO, gzip
  import traceback
  import simplejson
  
  class BaseResource(Resource):
  
      def __init__(self):
          Resource.__init__(self)
  
      def _successResponse(self, data):
          # if isinstance(data, str):
          #      return data
          return simplejson.dumps(data)
  
      def _errorResponse(self, error):
          from ..servers.base import LOGGER
          reason = str(error.value)
          tb = error.getTraceback()
          LOGGER.error("\n%s" % tb)
          #tb = traceback.format_exc(traceback.extract_tb(error.tb))
          return simplejson.dumps({"error":reason, "traceback":tb})
  
      def _immediateResponse(self, data, request):
          encoding = request.getHeader("accept-encoding")
          if encoding and "gzip" in encoding:
              zbuf = cStringIO.StringIO()
              zfile = gzip.GzipFile(None, 'wb', 9, zbuf)
              if isinstance(data, unicode):
                  zfile.write(unicode(data).encode("utf-8"))
              elif isinstance(data, str):
                  zfile.write(unicode(data, 'utf-8').encode("utf-8"))
              else:
                  zfile.write(unicode(data).encode("utf-8"))
              zfile.close()
              request.setHeader("Content-encoding","gzip")
              request.write(zbuf.getvalue())
          else:
              request.write(data)
          request.finish()
  
new_contents: from twisted.python.failure import Failure
  from twisted.web.resource import Resource
  import cStringIO, gzip
  import traceback
  import simplejson
  
  class BaseResource(Resource):
  
      def __init__(self):
          Resource.__init__(self)
  
      def _successResponse(self, data):
          # if isinstance(data, str):
          #      return data
          return simplejson.dumps(data)
  
      def _errorResponse(self, error):
          from ..servers.base import LOGGER
          reason = str(error.value)
          tb = error.getTraceback()
          LOGGER.error("%s\n%s" % (reason, tb))
          #tb = traceback.format_exc(traceback.extract_tb(error.tb))
          return simplejson.dumps({"error":reason, "traceback":tb})
  
      def _immediateResponse(self, data, request):
          encoding = request.getHeader("accept-encoding")
          if encoding and "gzip" in encoding:
              zbuf = cStringIO.StringIO()
              zfile = gzip.GzipFile(None, 'wb', 9, zbuf)
              if isinstance(data, unicode):
                  zfile.write(unicode(data).encode("utf-8"))
              elif isinstance(data, str):
                  zfile.write(unicode(data, 'utf-8').encode("utf-8"))
              else:
                  zfile.write(unicode(data).encode("utf-8"))
              zfile.close()
              request.setHeader("Content-encoding","gzip")
              request.write(zbuf.getvalue())
          else:
              request.write(data)
          request.finish()
  
subject: improve logging on error conditions (slightly)