def EndRedirect(self, redirected_outfile, original_outfile):
      """Handle the end of upload complete notification.

      Makes sure the application upload handler returned an appropriate status
      code.
      """
      response = dev_appserver.RewriteResponse(redirected_outfile)
      logging.info('Upload handler returned %d', response.status_code)

      if (response.status_code in (301, 302, 303) and
          (not response.body or len(response.body.read()) == 0)):
        contentless_outfile = cStringIO.StringIO()


        contentless_outfile.write('Status: %s\n' % response.status_code)
        contentless_outfile.write(''.join(response.headers.headers))
        contentless_outfile.seek(0)
        dev_appserver.URLDispatcher.EndRedirect(self,
                                                contentless_outfile,
                                                original_outfile)
      else:
        logging.error(
            'Invalid upload handler response. Only 301, 302 and 303 '
            'statuses are permitted and it may not have a content body.')
        original_outfile.write('Status: 500\n\n')
Ejemplo n.º 2
0
        def HandleGetApiConfigsResponse(self, dispatched_output, outfile):
            """Parses the result of getApiConfigs, returning True on success.

      Args:
        dispatched_output: Output from the getApiConfigs call handler.
        outfile: CGI output handle, used for error conditions.

      Returns:
        True on success, False on failure
      """
            response = dev_appserver.RewriteResponse(dispatched_output)
            if self.VerifyResponse(response, 200, 'application/json'):
                self.config_manager.ParseApiConfigResponse(
                    response.body.read())
                return True
            else:
                self.FailRequest('BackendService.getApiConfigs Error', outfile)
                return False
        def EndRedirect(self, dispatched_output, original_output):
            """Handle the end of upload complete notification.

      Makes sure the application upload handler returned an appropriate status
      code.
      """
            response = dev_appserver.RewriteResponse(dispatched_output)
            logging.info('Upload handler returned %d', response.status_code)
            outfile = cStringIO.StringIO()
            outfile.write('Status: %s\n' % response.status_code)

            if response.body and len(response.body.read()) > 0:
                response.body.seek(0)
                outfile.write(response.body.read())
            else:
                outfile.write(''.join(response.headers.headers))

            outfile.seek(0)
            dev_appserver.URLDispatcher.EndRedirect(self, outfile,
                                                    original_output)