How to use the cherrypy.response function in CherryPy

To help you get started, we’ve selected a few CherryPy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github antonycourtney / csvview / tableserver.py View on Github external
def default( self, tableName, startRow = 0, rowLimit = 10, sortby = '' ):
        dbTable = PagedDbTable( self.dbName, tableName )     
        # print "startRow = ", startRow, ", rowLimit = ", rowLimit, ", sortby = '", sortby, "'"
        startRow = int( startRow )
        rowLimit = int( rowLimit )
        sortstr = sortby.strip();
        if( len(sortstr) > 0 ):
            [ sortcol, sortdir ] = sortstr.split('+')
        else:
            [ sortcol, sortdir ] = [ None, None ] 
        cherrypy.response.headers['Content-Type'] = 'application/json'
        # rowData = self.dataFile['data'][ startRow : startRow + rowLimit ]
        columnInfo = dbTable.getColumnInfo()
        rowData = dbTable.getDataPage( sortcol, sortdir, startRow, rowLimit )
        request = { 'startRow': startRow, 'rowLimit': rowLimit }
        response = { 'request': request, 'columnInfo': columnInfo, 
                     'totalRowCount': dbTable.totalRowCount, 'results': rowData }                                                          
        return json.dumps( response )
github google / gsa-admin-toolkit / sso.py View on Github external
def redirect(self, path, msg=None):
    cherrypy.response.status = 302
    if path.startswith("http://") or path.startswith("https://"):
     location = path
    elif msg == None:
      location = "%s://%s/%s" % (self.protocol, self.get_host(), path)
    else:
      location = "%s://%s/%s?msg=%s" % (self.protocol, self.get_host(), path, msg)
    cherrypy.response.headers["location"] = location
github Kitware / minerva / girder / api / rest.py View on Github external
def sendAuthTokenCookie(self, user, scope=None):
        """
        Helper method to send the authentication cookie
        """
        days = int(self.model('setting').get(SettingKey.COOKIE_LIFETIME))
        token = self.model('token').createToken(user, days=days, scope=scope)

        cookie = cherrypy.response.cookie
        cookie['girderToken'] = str(token['_id'])
        cookie['girderToken']['path'] = '/'
        cookie['girderToken']['expires'] = days * 3600 * 24

        return token
github kovidgoyal / calibre / src / cherrypy / _cprequest.py View on Github external
raise
            else:
                # Failure in setup, error handler or finalize. Bypass them.
                # Can't use handle_error because we may not have hooks yet.
                cherrypy.log(traceback=True, severity=40)
                if self.show_tracebacks:
                    body = format_exc()
                else:
                    body = ""
                r = bare_error(body)
                response = cherrypy.response
                response.status, response.header_list, response.body = r
        
        if self.method == "HEAD":
            # HEAD requests MUST NOT return a message-body in the response.
            cherrypy.response.body = []
        
        cherrypy.log.access()
        
        if cherrypy.response.timed_out:
            raise cherrypy.TimeoutError()
        
        return cherrypy.response
github xhtml2pdf / xhtml2pdf / demo / cherrypy / demo-cherrypy.py View on Github external
<title>PDF Demo</title>
                  
                  %s
                """ % data
            test = kid.Template(source=data)
            data = test.serialize(output='xhtml')

        result = StringIO.StringIO()
        pdf = pisa.CreatePDF(
            StringIO.StringIO(data),
            result
            )
        if pdf.err:
            return "We had some errors in HTML"
        else:
            cp.response.headers["content-type"] = "application/pdf"
            return result.getvalue()
github bhdouglass / uappexplorer / api / ubuntu_appstore.py View on Github external
def return_json(*args):
		cherrypy.response.headers["Access-Control-Allow-Origin"] = '*'
		cherrypy.response.headers['Content-Type'] = 'application/json'
		return json.dumps(function(*args), default=json_util.default)
github dart-archive / pub-dartlang / app / handlers / package_versions.py View on Github external
Depending on the format, this could be a user-readable webpage (.html),
        a machine-readable YAML document (.yaml), or a download of the actual
        package blob (.tar.gz).
        """

        # The built-in format parsing has trouble with versions since they
        # contain periods, so we have to undo it and apply our own.
        id = '%s.%s' % (id, format)
        if id.endswith('.tar.gz'):
            id = id[0:-len('.tar.gz')]
            version = handlers.request().package_version(id)
            raise cherrypy.HTTPRedirect(version.download_url)
        elif id.endswith('.yaml'):
            id = id[0:-len('.yaml')]
            version = handlers.request().package_version(id)
            cherrypy.response.headers['Content-Type'] = 'text/yaml'
            return version.pubspec.to_yaml()
        else:
            handlers.http_error(404)
github ceph / ceph / src / pybind / mgr / dashboard / controllers / home.py View on Github external
def _language_dir(self, langs):
        for lang in langs:
            if lang in LANGUAGES_PATH_MAP:
                logger.debug("found directory for language '%s'", lang)
                cherrypy.response.headers['Content-Language'] = LANGUAGES_PATH_MAP[lang]['lang']
                return LANGUAGES_PATH_MAP[lang]['path']

        logger.debug("Languages '%s' not available, falling back to %s", langs, DEFAULT_LANGUAGE)
        cherrypy.response.headers['Content-Language'] = DEFAULT_LANGUAGE
        return DEFAULT_LANGUAGE_PATH
github coady / lupyne / lupyne / server / __init__.py View on Github external
def refresh(self):
        if self.indexer.nrt:
            self.indexer.refresh()
            self.updated = time.time()
        else:
            cherrypy.response.status = int(http.client.ACCEPTED)
github dmwm / WMCore / src / python / WMCore / ReqMgr / Web / ReqMgrService.py View on Github external
def set_no_cache_flags():
    "Set cherrypy flags to prevent caching"
    cherrypy.response.headers['Cache-Control'] = 'no-cache'
    cherrypy.response.headers['Pragma'] = 'no-cache'
    cherrypy.response.headers['Expires'] = 'Sat, 01 Dec 2001 00:00:00 GMT'