Did I find the right examples for you? yes no

All Samples(24)  |  Call(24)  |  Derive(0)  |  Import(0)
Formats as JSON, writing to the given object.

        def jsonFormat(output, statDict = None, query = None, pretty = False):
  """Formats as JSON, writing to the given object."""
  statDict = statDict or scales.getStats()
  if query:
    statDict = runQuery(statDict, query)
  indent = 2 if pretty else None
  # At first, assume that strings are in UTF-8. If this fails -- if, for example, we have
  # crazy binary data -- then in order to get *something* out, we assume ISO-8859-1,
  # which maps each byte to a unicode code point.
  try:
    serialized = json.dumps(statDict, cls=scales.StatContainerEncoder, indent=indent)
  except UnicodeDecodeError:
    serialized = json.dumps(statDict, cls=scales.StatContainerEncoder, indent=indent, encoding='iso-8859-1')

  output.write(serialized)
  output.write('\n')
        


src/s/c/scales-1.0.6/src/greplin/scales/twistedweb.py   scales(Download)
    if 'format' in request.args and request.args['format'][0] == 'json':
      request.headers['content-type'] = 'text/javascript; charset=UTF-8'
      formats.jsonFormat(request, statDict, query)
    elif 'format' in request.args and request.args['format'][0] == 'prettyjson':
      request.headers['content-type'] = 'text/javascript; charset=UTF-8'
      formats.jsonFormat(request, statDict, query, pretty=True)

src/s/c/scales-1.0.6/src/greplin/scales/tornadohandler.py   scales(Download)
    query = self.get_argument('query', default=None)
    if outputFormat == 'json':
      formats.jsonFormat(self, statDict, query)
    elif outputFormat == 'prettyjson':
      formats.jsonFormat(self, statDict, query, pretty=True)

src/s/c/scales-1.0.6/src/greplin/scales/flaskhandler.py   scales(Download)
  query = request.args.get('query', None)
  if outputFormat == 'json':
    formats.jsonFormat(output, statDict, query)
  elif outputFormat == 'prettyjson':
    formats.jsonFormat(output, statDict, query, pretty=True)

src/s/c/scales-1.0.6/src/greplin/scales/bottlehandler.py   scales(Download)
    if output_format == 'json':
        response.content_type = "application/json"
        formats.jsonFormat(output, stat_dict, query)
    elif output_format == 'prettyjson':
        formats.jsonFormat(output, stat_dict, query, pretty=True)

src/s/c/scales-HEAD/src/greplin/scales/twistedweb.py   scales(Download)
    if 'format' in request.args and request.args['format'][0] == 'json':
      request.headers['content-type'] = 'text/javascript; charset=UTF-8'
      formats.jsonFormat(request, statDict, query)
    elif 'format' in request.args and request.args['format'][0] == 'prettyjson':
      request.headers['content-type'] = 'text/javascript; charset=UTF-8'
      formats.jsonFormat(request, statDict, query, pretty=True)

src/s/c/scales-HEAD/src/greplin/scales/tornadohandler.py   scales(Download)
    query = self.get_argument('query', default=None)
    if outputFormat == 'json':
      formats.jsonFormat(self, statDict, query)
    elif outputFormat == 'prettyjson':
      formats.jsonFormat(self, statDict, query, pretty=True)

src/s/c/scales-HEAD/src/greplin/scales/flaskhandler.py   scales(Download)
  query = request.args.get('query', None)
  if outputFormat == 'json':
    formats.jsonFormat(output, statDict, query)
  elif outputFormat == 'prettyjson':
    formats.jsonFormat(output, statDict, query, pretty=True)

src/s/c/scales-HEAD/src/greplin/scales/bottlehandler.py   scales(Download)
    if output_format == 'json':
        response.content_type = "application/json"
        formats.jsonFormat(output, stat_dict, query)
    elif output_format == 'prettyjson':
        formats.jsonFormat(output, stat_dict, query, pretty=True)

src/p/y/pyramid_scales-1.0/src/pyramid_scales/__init__.py   pyramid_scales(Download)
    if outputFormat == 'json':
        request.response.content_type = 'application/json'
        greplin.scales.formats.jsonFormat(output, stats, query)
    elif outputFormat == 'prettyjson':
        request.response.content_type = 'application/json'
        greplin.scales.formats.jsonFormat(output, stats, query, pretty=True)

src/s/c/scales-1.0.6/src/greplin/scales/formats_test.py   scales(Download)
 
    out = six.StringIO()
    formats.jsonFormat(out)
 
    self.assertEquals('{"here": {"count": 1}}\n', out.getvalue())
  def testJsonFormat(self):
    """Test generating JSON with Unicode values."""
    out = six.StringIO()
    stats = {'name': self.UNICODE_VALUE}
    formats.jsonFormat(out, statDict=stats)
  def testJsonFormatBinaryGarbage(self):
    """Make sure that JSON formatting of binary junk does not crash."""
    out = six.StringIO()
    stats = {'garbage': '\xc2\xc2 ROAR!! \0\0'}
    formats.jsonFormat(out, statDict=stats)

  1 | 2  Next