def __init__(self): self.from_text_plain_f = From_Text_Plain_to_JSON() self.from_text_occi_f = From_Text_OCCI_to_JSON()
class RequestAdapter(): """ Converts the data contained inside the request to the occi+json data format. """ def __init__(self): self.from_text_plain_f = From_Text_Plain_to_JSON() self.from_text_occi_f = From_Text_OCCI_to_JSON() def convert_request_category_content(self, req): if req.content_type == "text/plain": # Solution To adopt : Validate HTTP then convert to JSON jdata = self.from_text_plain_f.format_text_plain_categories_to_json(req.body) elif req.content_type == "text/occi": jdata = self.from_text_occi_f.format_text_occi_categories_to_json(req.headers) elif req.content_type == "application/occi+json": #Validate the JSON message jdata = json.loads(req.body) elif req.content_type == "application/json:occi": # Solution To adopt : Validate then convert to application/occi+json pass else: logger.error("========== This is an unknown data format ==========") jdata = None return jdata def convert_request_entity_content(self, req): if req.content_type == "text/plain": # Solution To adopt : Validate HTTP then convert to JSON jdata = self.from_text_plain_f.format_text_plain_entity_to_json(req.body) elif req.content_type == "text/occi": jdata = self.from_text_occi_f.format_text_occi_entity_to_json(req.headers) elif req.content_type == "application/occi+json": #Validate the JSON message jdata = json.loads(req.body) elif req.content_type == "application/json:occi": # Solution To adopt : Validate then convert to application/occi+json pass else: logger.error("========== This is an unknown data format ==========") jdata = None return jdata def convert_request_entity_content_v2(self, req): ''' Used only for partial update. ''' if req.content_type == "text/plain": # Solution To adopt : Validate HTTP then convert to JSON jdata = self.from_text_plain_f.format_text_plain_entity_to_json_v2(req.body) elif req.content_type == "text/occi": jdata = self.from_text_occi_f.format_text_occi_entity_to_json_v2(req.headers) elif req.content_type == "application/occi+json": #Validate the JSON message jdata = json.loads(req.body) elif req.content_type == "application/json:occi": # Solution To adopt : Validate then convert to application/occi+json pass else: logger.error("========== This is an unknown data format ==========") jdata = None return jdata
class RequestAdapter(): """ Converts the data contained inside the request to the application/occi+json data format. """ def __init__(self): self.from_text_plain_f = From_Text_Plain_to_JSON() self.from_text_occi_f = From_Text_OCCI_to_JSON() def convert_request_category_content(self, req): if req.content_type == "text/plain": # Solution To adopt : Validate HTTP then convert to JSON jdata = self.from_text_plain_f.format_text_plain_categories_to_json( req.body) elif req.content_type == "text/occi": jdata = self.from_text_occi_f.format_text_occi_categories_to_json( req.headers) elif req.content_type == "application/occi+json": #Validate the JSON message jdata = json.loads(req.body) elif req.content_type == "application/json:occi": # Solution To adopt : Validate then convert to application/occi+json pass else: logger.error( "========== This is an unknown data format ==========") jdata = None return jdata def convert_request_entity_content(self, req): if req.content_type == "text/plain": # Solution To adopt : Validate HTTP then convert to JSON jdata = self.from_text_plain_f.format_text_plain_entity_to_json( req.body) elif req.content_type == "text/occi": jdata = self.from_text_occi_f.format_text_occi_entity_to_json( req.headers) elif req.content_type == "application/occi+json": #Validate the JSON message jdata = json.loads(req.body) elif req.content_type == "application/json:occi": # Solution To adopt : Validate then convert to application/occi+json pass else: logger.error( "========== This is an unknown data format ==========") jdata = None return jdata def convert_request_entity_content_v2(self, req): """ Used only for partial update. """ if req.content_type == "text/plain": # Solution To adopt : Validate HTTP then convert to JSON jdata = self.from_text_plain_f.format_text_plain_entity_to_json_v2( req.body) elif req.content_type == "text/occi": jdata = self.from_text_occi_f.format_text_occi_entity_to_json_v2( req.headers) elif req.content_type == "application/occi+json": #Validate the JSON message jdata = json.loads(req.body) elif req.content_type == "application/json:occi": # Solution To adopt : Validate then convert to application/occi+json pass else: logger.error( "========== This is an unknown data format ==========") jdata = None return jdata