def __init__(self):

        self.text_plain_f = To_HTTP_Text_Plain()
        self.text_occi_f = To_HTTP_Text_OCCI()
        self.text_uri_f = To_HTTP_Text_URI_List()
Пример #2
0
    def __init__(self):

        self.text_plain_f = To_HTTP_Text_Plain()
        self.text_occi_f = To_HTTP_Text_OCCI()
        self.text_uri_f = To_HTTP_Text_URI_List()
class ResponseAdapter():
    """
    Converts the response data into the required data format (text/plain, text/occi ,text/uri, application/occi+json).
    """

    def __init__(self):

        self.text_plain_f = To_HTTP_Text_Plain()
        self.text_occi_f = To_HTTP_Text_OCCI()
        self.text_uri_f = To_HTTP_Text_URI_List()

    def convert_response_category_content(self, res, jdata):
        if str(res.content_type) == "application/occi+json":
            res.body = json.dumps(jdata)

        elif str(res.content_type) == "text/occi":
            #reformat the response to text/occi
            res.body = "OK"
            res.headers.extend(self.text_occi_f.format_to_text_occi_categories(jdata))

        else:
            #reformat the response to text/plain (default OCCI response format)
            res.headers.extend({"content_type": "text/plain"})
            res.body = self.text_plain_f.format_to_text_plain_categories(jdata)

        return res


    def convert_response_entity_multi_location_content(self, var, res):
        if str(res.content_type) == "application/occi+json":
            location_dict = {"Location": var}
            res.body = json.dumps(location_dict)

        elif str(res.content_type) == "text/occi":
            #reformat the response to text/occi
            res.body = "OK"
            res.headers = self.text_occi_f.format_to_text_occi_locations(var)

        elif str(res.content_type) == "text/uri-list":
            #reformat the response to text/occi
            res, ok = self.text_uri_f.check_for_uri_locations(var)
            if ok is True:
                res.body = res
            else:
                res.content_type = "text/plain"
                res.body = self.text_plain_f.format_to_text_plain_locations(var)

        else:
            #reformat the response to text/plain (default OCCI response format)
            res.content_type = "text/plain"
            res.body = self.text_plain_f.format_to_text_plain_locations(var)

        return res

    def convert_response_entity_location_content(self, var, res):

        if str(res.content_type) == "application/occi+json":
            res.body = json.dumps({"Location":[var]})

        elif str(res.content_type) == "text/occi":
            #reformat the response to text/occi
            res.body = "OK"
            res.location = var

        else:
            #reformat the response to text/plain (default OCCI response format)
            res.content_type = "text/plain"
            res.body = "Location: "+ var

        return res

    def convert_response_entity_content(self, res, var):

        if str(res.content_type) == "application/occi+json":
            res.body = json.dumps(var)

        elif str(res.content_type) == "text/occi":
            #reformat the response to text/occi
            res.body = "OK"
            res.headers.extend(self.text_occi_f.format_to_text_occi_entities(var))

        else:
            #reformat the response to text/plain (default OCCI response format)
            res.content_type = "text/plain"
            res.body = self.text_plain_f.format_to_text_plain_entities(var)

        return res

    def convert_response_entity_multi_x_occi_location_content(self, var, res):

        if str(res.content_type) == "application/occi+json":
            x_occi_location_dict = {"X-OCCI-Location": var}
            res.body = json.dumps(x_occi_location_dict)

        elif str(res.content_type) == "text/occi":
            #reformat the response to text/occi
            res.body = "OK"
            res.headers = self.text_occi_f.format_to_text_x_occi_locations(var)

        elif str(res.content_type) == "text/uri-list":
            #reformat the response to text/occi
            response, ok = self.text_uri_f.check_for_uri_locations(var)
            if ok is True:
                res.body = response
            else:
                res.content_type = "text/plain"
                res.body = self.text_plain_f.format_to_text_plain_x_locations(var)

        else:
            #reformat the response to text/plain (default OCCI response format)
            res.content_type = "text/plain"
            res.body = self.text_plain_f.format_to_text_plain_x_locations(var)

        return res
Пример #4
0
class ResponseAdapter():
    """
    Converts the response data into the required data format (text/plain, text/occi ,text/uri, application/occi+json).
    """
    def __init__(self):

        self.text_plain_f = To_HTTP_Text_Plain()
        self.text_occi_f = To_HTTP_Text_OCCI()
        self.text_uri_f = To_HTTP_Text_URI_List()

    def convert_response_category_content(self, res, jdata):
        if str(res.content_type) == "application/occi+json":
            res.body = json.dumps(jdata)

        elif str(res.content_type) == "text/occi":
            #reformat the response to text/occi
            res.body = "OK"
            res.headers.extend(
                self.text_occi_f.format_to_text_occi_categories(jdata))

        else:
            #reformat the response to text/plain (default OCCI response format)
            res.headers.extend({"content_type": "text/plain"})
            res.body = self.text_plain_f.format_to_text_plain_categories(jdata)

        return res

    def convert_response_entity_multi_location_content(self, var, res):
        if str(res.content_type) == "application/occi+json":
            location_dict = {"Location": var}
            res.body = json.dumps(location_dict)

        elif str(res.content_type) == "text/occi":
            #reformat the response to text/occi
            res.body = "OK"
            res.headers = self.text_occi_f.format_to_text_occi_locations(var)

        elif str(res.content_type) == "text/uri-list":
            #reformat the response to text/occi
            res, ok = self.text_uri_f.check_for_uri_locations(var)
            if ok is True:
                res.body = res
            else:
                res.content_type = "text/plain"
                res.body = self.text_plain_f.format_to_text_plain_locations(
                    var)

        else:
            #reformat the response to text/plain (default OCCI response format)
            res.content_type = "text/plain"
            res.body = self.text_plain_f.format_to_text_plain_locations(var)

        return res

    def convert_response_entity_location_content(self, var, res):

        if str(res.content_type) == "application/occi+json":
            res.body = json.dumps({"Location": [var]})

        elif str(res.content_type) == "text/occi":
            #reformat the response to text/occi
            res.body = "OK"
            res.location = var

        else:
            #reformat the response to text/plain (default OCCI response format)
            res.content_type = "text/plain"
            res.body = "Location: " + var

        return res

    def convert_response_entity_content(self, res, var):

        if str(res.content_type) == "application/occi+json":
            res.body = json.dumps(var)

        elif str(res.content_type) == "text/occi":
            #reformat the response to text/occi
            res.body = "OK"
            res.headers.extend(
                self.text_occi_f.format_to_text_occi_entities(var))

        else:
            #reformat the response to text/plain (default OCCI response format)
            res.content_type = "text/plain"
            res.body = self.text_plain_f.format_to_text_plain_entities(var)

        return res

    def convert_response_entity_multi_x_occi_location_content(self, var, res):

        if str(res.content_type) == "application/occi+json":
            x_occi_location_dict = {"X-OCCI-Location": var}
            res.body = json.dumps(x_occi_location_dict)

        elif str(res.content_type) == "text/occi":
            #reformat the response to text/occi
            res.body = "OK"
            res.headers = self.text_occi_f.format_to_text_x_occi_locations(var)

        elif str(res.content_type) == "text/uri-list":
            #reformat the response to text/occi
            response, ok = self.text_uri_f.check_for_uri_locations(var)
            if ok is True:
                res.body = response
            else:
                res.content_type = "text/plain"
                res.body = self.text_plain_f.format_to_text_plain_x_locations(
                    var)

        else:
            #reformat the response to text/plain (default OCCI response format)
            res.content_type = "text/plain"
            res.body = self.text_plain_f.format_to_text_plain_x_locations(var)

        return res