Example #1
0
    def get_static_file(self, req, path, file, mimetype=None, root="content/"):
        resp = Response()

        if mimetype is None:
            if utils.is_xml_response(req):
                mimetype = "application/xml"
            elif utils.is_json_response(req):
                mimetype = "application/json"
            else:
                logger.debug("Unhandled mime type: %s" % req.content_type)

        basename, extension = os.path.splitext(file)
        resp_file = "%s%s%s" % (root, path, file)
        if extension is None or extension == '':
            if mimetype == "application/xml":
                resp_file = "%s.xml" % resp_file
            elif mimetype == "application/json":
                resp_file = "%s.json" % resp_file

        logger.debug("Returning contents from file '%s'" % resp_file)
        return template.static_file(resp,
                                    req,
                                    resp_file,
                                    root=utils.get_app_root(),
                                    mimetype=mimetype)
Example #2
0
    def get_version_info(self, req, file="version"):
        resp = Response()
        resp.charset = 'UTF-8'
        if utils.is_xml_response(req):
            resp_file = os.path.join(POSSIBLE_TOPDIR,
                "keystone/content/%s.xml.tpl" % file)
            resp.content_type = "application/xml"
        elif utils.is_atom_response(req):
            resp_file = os.path.join(POSSIBLE_TOPDIR,
                "keystone/content/%s.atom.tpl" % file)
            resp.content_type = "application/atom+xml"
        else:
            resp_file = os.path.join(POSSIBLE_TOPDIR,
                "keystone/content/%s.json.tpl" % file)
            resp.content_type = "application/json"

        hostname = req.environ.get("SERVER_NAME")
        port = req.environ.get("SERVER_PORT")
        if 'HTTPS' in req.environ:
            protocol = 'https'
        else:
            protocol = 'http'

        resp.unicode_body = template.template(resp_file,
            PROTOCOL=protocol,
            HOST=hostname,
            PORT=port,
            API_VERSION=version.API_VERSION,
            API_VERSION_STATUS=version.API_VERSION_STATUS,
            API_VERSION_DATE=version.API_VERSION_DATE)

        return resp
Example #3
0
    def get_version_info(self, req, file="version"):
        resp = Response()
        resp.charset = 'UTF-8'
        if utils.is_xml_response(req):
            resp_file = os.path.join(POSSIBLE_TOPDIR,
                                     "keystone/content/%s.xml.tpl" % file)
            resp.content_type = "application/xml"
        elif utils.is_atom_response(req):
            resp_file = os.path.join(POSSIBLE_TOPDIR,
                                     "keystone/content/%s.atom.tpl" % file)
            resp.content_type = "application/atom+xml"
        else:
            resp_file = os.path.join(POSSIBLE_TOPDIR,
                                     "keystone/content/%s.json.tpl" % file)
            resp.content_type = "application/json"

        hostname = req.environ.get("SERVER_NAME")
        port = req.environ.get("SERVER_PORT")
        if 'HTTPS' in req.environ:
            protocol = 'https'
        else:
            protocol = 'http'

        resp.unicode_body = template.template(
            resp_file,
            PROTOCOL=protocol,
            HOST=hostname,
            PORT=port,
            API_VERSION=version.API_VERSION,
            API_VERSION_STATUS=version.API_VERSION_STATUS,
            API_VERSION_DATE=version.API_VERSION_DATE)

        return resp
Example #4
0
    def get_static_file(self, req, path, file, mimetype=None, root="content/"):
        resp = Response()

        if mimetype == None:
            if utils.is_xml_response(req):
                mimetype = "application/xml"
            elif utils.is_json_response(req):
                mimetype = "application/json"

        basename, extension = os.path.splitext(file)
        if extension == None or extension == '':
            if mimetype == "application/xml":
                resp_file = "%s%s%s.xml" % (root, path, file)
            elif mimetype == "application/json":
                resp_file = "%s%s%s.json" % (root, path, file)
            else:
                resp_file = root + path + file
        else:
            resp_file = root + path + file

        return template.static_file(resp,
                                    req,
                                    resp_file,
                                    root=utils.get_app_root(),
                                    mimetype=mimetype)
Example #5
0
    def get_extensions_info(self, req, path):
        resp = Response()

        if utils.is_xml_response(req):
            resp_file = "%s.xml" % path
            mime_type = "application/xml"
        else:
            resp_file = "%s.json" % path
            mime_type = "application/json"

        return template.static_file(resp, req, resp_file,
                root=utils.get_app_root(), mimetype=mime_type)
Example #6
0
    def get_extensions_info(self, req, path):
        resp = Response()

        if utils.is_xml_response(req):
            resp_file = "%s.xml" % path
            mime_type = "application/xml"
        else:
            resp_file = "%s.json" % path
            mime_type = "application/json"

        return template.static_file(resp,
                                    req,
                                    resp_file,
                                    root=utils.get_app_root(),
                                    mimetype=mime_type)
Example #7
0
    def get_version_info(self, req):

        resp = Response()
        resp.charset = "UTF-8"
        if utils.is_xml_response(req):
            resp_file = os.path.join(POSSIBLE_TOPDIR, "keystone/content/version.xml.tpl")
            resp.content_type = "application/xml"
        else:
            resp_file = os.path.join(POSSIBLE_TOPDIR, "keystone/content/version.json.tpl")
            resp.content_type = "application/json"

        hostname = req.environ.get("SERVER_NAME")
        port = req.environ.get("SERVER_PORT")

        resp.unicode_body = template.template(
            resp_file, HOST=hostname, PORT=port, VERSION_STATUS=VERSION_STATUS, VERSION_DATE=VERSION_DATE
        )
        return resp
Example #8
0
    def get_static_file(req, path, file, mimetype=None, root="content/"):
        resp = Response()

        if mimetype is None:
            if utils.is_xml_response(req):
                mimetype = "application/xml"
            elif utils.is_json_response(req):
                mimetype = "application/json"
            else:
                logger.debug("Unhandled mime type: %s" % req.content_type)

        basename, extension = os.path.splitext(file)
        resp_file = "%s%s%s" % (root, path, file)
        if extension is None or extension == "":
            if mimetype == "application/xml":
                resp_file = "%s.xml" % resp_file
            elif mimetype == "application/json":
                resp_file = "%s.json" % resp_file

        logger.debug("Returning contents from file '%s'" % resp_file)
        return template.static_file(resp, req, resp_file, root=utils.get_app_root(), mimetype=mimetype)
Example #9
0
    def get_multiple_choice(self, req, file="multiple_choice", path=None):
        """ Returns a multiple-choices response based on API spec

        Response will include in it only one choice, which is for the
        current API version. The response is a 300 Multiple Choice
        response with either an XML or JSON body.

        """
        if path is None:
            path = ''
        logger.debug("300 Multiple Choices response: %s" % path)
        resp = Response(status="300 Multiple Choices")
        resp.charset = 'UTF-8'
        if utils.is_xml_response(req):
            resp_file = os.path.join(POSSIBLE_TOPDIR,
                "keystone/content/%s.xml.tpl" % file)
            resp.content_type = "application/xml"
        else:
            resp_file = os.path.join(POSSIBLE_TOPDIR,
                "keystone/content/%s.json.tpl" % file)
            resp.content_type = "application/json"

        hostname = req.environ.get("SERVER_NAME")
        port = req.environ.get("SERVER_PORT")
        if 'HTTPS' in req.environ:
            protocol = 'https'
        else:
            protocol = 'http'

        resp.unicode_body = template.template(resp_file,
            PROTOCOL=protocol,
            HOST=hostname,
            PORT=port,
            API_VERSION=version.API_VERSION,
            API_VERSION_STATUS=version.API_VERSION_STATUS,
            API_VERSION_DATE=version.API_VERSION_DATE,
            RESOURCE_PATH=path
            )

        return resp
Example #10
0
    def get_multiple_choice(self, req, file="multiple_choice", path=None):
        """ Returns a multiple-choices response based on API spec

        Response will include in it only one choice, which is for the
        current API version. The response is a 300 Multiple Choice
        response with either an XML or JSON body.

        """
        if path is None:
            path = ''
        logger.debug("300 Multiple Choices response: %s" % path)
        resp = Response(status="300 Multiple Choices")
        resp.charset = 'UTF-8'
        if utils.is_xml_response(req):
            resp_file = os.path.join(POSSIBLE_TOPDIR,
                                     "keystone/content/%s.xml.tpl" % file)
            resp.content_type = "application/xml"
        else:
            resp_file = os.path.join(POSSIBLE_TOPDIR,
                                     "keystone/content/%s.json.tpl" % file)
            resp.content_type = "application/json"

        hostname = req.environ.get("SERVER_NAME")
        port = req.environ.get("SERVER_PORT")
        if 'HTTPS' in req.environ:
            protocol = 'https'
        else:
            protocol = 'http'

        resp.unicode_body = template.template(
            resp_file,
            PROTOCOL=protocol,
            HOST=hostname,
            PORT=port,
            API_VERSION=version.API_VERSION,
            API_VERSION_STATUS=version.API_VERSION_STATUS,
            API_VERSION_DATE=version.API_VERSION_DATE,
            RESOURCE_PATH=path)

        return resp
Example #11
0
    def get_static_file(self, req, path, file, mimetype=None, root="content/"):
        resp = Response()

        if mimetype == None:
            if utils.is_xml_response(req):
                mimetype = "application/xml"
            elif utils.is_json_response(req):
                mimetype = "application/json"

        basename, extension = os.path.splitext(file)
        if extension == None or extension == '':
            if mimetype == "application/xml":
                resp_file = "%s%s%s.xml" % (root, path, file)
            elif mimetype == "application/json":
                resp_file = "%s%s%s.json" % (root, path, file)
            else:
                resp_file = root + path + file
        else:
            resp_file = root + path + file

        return template.static_file(resp, req, resp_file,
            root=utils.get_app_root(), mimetype=mimetype)
Example #12
0
    def  get_version_info(self, req, file="version"):
        resp = Response()
        resp.charset = 'UTF-8'
        if utils.is_xml_response(req):
            resp_file = os.path.join(possible_topdir,
                "keystone/content/%s.xml.tpl" % file)
            resp.content_type = "application/xml"
        else:
            resp_file = os.path.join(possible_topdir,
                "keystone/content/%s.json.tpl" % file)
            resp.content_type = "application/json"

        hostname = req.environ.get("SERVER_NAME")
        port = req.environ.get("SERVER_PORT")

        resp.unicode_body = template.template(resp_file,
            HOST=hostname,
            PORT=port,
            VERSION_STATUS=config.VERSION_STATUS,
            VERSION_DATE=config.VERSION_DATE)

        return resp
Example #13
0
    def  get_version_info(self, req, file="version"):
        resp = Response()
        resp.charset = 'UTF-8'
        if utils.is_xml_response(req):
            resp_file = os.path.join(possible_topdir,
                "keystone/content/%s.xml.tpl" % file)
            resp.content_type = "application/xml"
        else:
            resp_file = os.path.join(possible_topdir,
                "keystone/content/%s.json.tpl" % file)
            resp.content_type = "application/json"

        hostname = req.environ.get("SERVER_NAME")
        port = req.environ.get("SERVER_PORT")

        resp.unicode_body = template.template(resp_file,
            HOST=hostname,
            PORT=port,
            VERSION_STATUS=config.VERSION_STATUS,
            VERSION_DATE=config.VERSION_DATE)

        return resp
Example #14
0
 def test_is_xml_response(self):
     self.assertFalse(utils.is_xml_response(self.request))
     self.request.headers["Accept"] = "application/xml"
     self.request.content_type = "application/json"
     self.assertTrue(utils.is_xml_response(self.request))
 def test_is_xml_response(self):
     self.assertFalse(utils.is_xml_response(self.request))
     self.request.headers["Accept"] = "application/xml"
     self.request.content_type = "application/json"
     self.assertTrue(utils.is_xml_response(self.request))