示例#1
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
示例#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
示例#3
0
文件: server.py 项目: slashk/keystone
    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
示例#4
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
示例#5
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
示例#6
0
文件: version.py 项目: pvo/keystone
    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
示例#7
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