예제 #1
0
    def _send_json_response(self, obj, code=200):
        """Writes out the given object as JSON using the given HTTP status code.

    This also replaces special float values with stringified versions.

    Args:
      obj: The object to respond with.
      code: The numeric HTTP status code to use.
    """
        content = json.dumps(json_util.WrapSpecialFloats(obj))
        self._respond(content, 'application/json', code)
예제 #2
0
  def _send_json_response(self, obj, code=200):
    """Writes out the given object as JSON using the given HTTP status code.

    This also replaces special float values with stringified versions.

    Args:
      obj: The object to respond with.
      code: The numeric HTTP status code to use.
    """

    output = json.dumps(json_util.WrapSpecialFloats(obj))

    self.send_response(code)
    self.send_header('Content-Type', 'application/json')
    self.send_header('Content-Length', len(output))
    self.end_headers()
    self.wfile.write(compat.as_bytes(output))
 def _assertWrapsAs(self, to_wrap, expected):
     """Asserts that |to_wrap| becomes |expected| when wrapped."""
     actual = json_util.WrapSpecialFloats(to_wrap)
     for a, e in zip(actual, expected):
         self.assertEqual(e, a)