code: def write(self, chunk):
          
          if self._finished:
              raise RuntimeError("Cannot write() after finish().  May be caused "
                                 "by using async operations without the "
                                 "@asynchronous decorator.")
          if isinstance(chunk, dict):
              options = {'ensure_ascii': False}
              if 'curl' in self.request.headers.get('user-agent'):
                  options['indent'] = 2
                  options['sort_keys'] = True
              chunk = json.dumps(chunk, **options).replace("</", "<\\/") + '\n'
              self.set_header("Content-Type", "application/json; charset=UTF-8")
          self._write_buffer.append(web.utf8(chunk))
docs: Writes the given chunk to the output buffer. Checks for curl in the
          user-agent and if set, provides indented output if returning JSON.
  
          To write the output to the network, use the flush() method below.
  
          If the given chunk is a dictionary, we write it as JSON and set
          the Content-Type of the response to be ``application/json``.
          (if you want to send JSON as a different ``Content-Type``, call
          set_header *after* calling write()).
  
          :param mixed chunk: The string or dict to write to the client