コード例 #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.
        """

        output = ioJSON.dumps(float_wrapper.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))
コード例 #2
0
 def _assertWrapsAs(self, to_wrap, expected):
   """Asserts that |to_wrap| becomes |expected| when wrapped."""
   actual = float_wrapper.WrapSpecialFloats(to_wrap)
   for a, e in zip(actual, expected):
     self.assertEqual(e, a)