def _posta(self, url='', body=None): post_body = None if not url: if self.managed_object is not None: self.url = self.managed_object.url post_body = body or self.managed_object.representation else: raise URLNotSpecifiedError() else: self.url = url post_body = body or self.managed_object.representation post_body = self.remove_None_fields_from_dict(post_body) resp, body = self.client.post(self.url, body=self._get_request_data(post_body)) data = self._get_data(body, method=POSTA, response=resp) if not isinstance(data, list): raise Exception("The parsed posta response data should be a list.") res_list = [] for s_data in data: res_data, res_url = s_data if self.ResponseParser.error_status_key in res_data: res = res_data.get(self.ResponseParser.error_status_key) else: res = self._return_new_resource_by_response_data( resp, res_data.get(self.ResponseParser.resource_data_key), res_url) res_list.append(res) return resp, res_list
def _list(self, url='', obj_class=None, body=None, **kwargs): parent = None if not url: if self.managed_object is not None: self.url = self.managed_object.url parent = self.managed_object.parent else: raise URLNotSpecifiedError() else: self.url = url if body: _, body = self.client.post(self.url, body=body) else: _, body = self.client.get(self.url, **kwargs) if obj_class is None: obj_class = self.resource_class data = self._get_data(body) return [ obj_class(client=self.client, manager=self.__class__(self.client), url=self.url, parent=parent, info=res) for res in data if res ]
def _get(self, resource_id='', url='', obj_class=None, **kwargs): new = False parent = None if not url: if self.managed_object is not None: self.url = self.managed_object.url parent = self.managed_object.parent if resource_id: self.url += '/' + resource_id new = True else: raise URLNotSpecifiedError() else: self.url = url new = True resp, body = self.client.get(self.url, **kwargs) data = self._get_data(body)[0] if not new: return resp, data else: if obj_class is None: obj_class = self.resource_class return obj_class(client=self.client, manager=self.__class__(self.client), url=self.url, info=data, parent=parent, loaded=True)
def _delete(self, url=''): if not url: if self.managed_object is not None: self.url = self.managed_object.url else: raise URLNotSpecifiedError() else: self.url = url resp, body = self.client.delete(self.url) data = self._get_data(body, method='DELETE', response=resp) return resp, data
def _post(self, body, url=None): if not url: if self.managed_object is not None: url = self.managed_object.url else: raise URLNotSpecifiedError() resp, res_body = self.client.post(url, body=self._get_request_data(body)) data = self._get_data(res_body, method=POST, response=resp) return resp, data
def _put(self, url='', body=None): put_body = None if not url: if self.managed_object is not None: self.url = self.managed_object.url put_body = body or self.managed_object.representation else: raise URLNotSpecifiedError() else: self.url = url put_body = body resp, body = self.client.put(self.url, body=self._get_request_data(put_body)) data = self._get_data(body, method='PUT', response=resp) return resp, data
def _post(self, url='', body=None): post_body = None if not body: if self.managed_object is not None: post_body = self.managed_object._get_modified_info_dict() # repre = self.managed_object.representation # post_body = {key: value # for key, value in repre.iteritems() # if key not in self.managed_object.readonly_fileds # } else: raise URLNotSpecifiedError() else: post_body = body return super(BaseManager, self)._post(url=url, body=post_body)
def _patch(self, url='', body=None): patch_body = None if not url: if self.managed_object is not None: self.url = self.managed_object.url patch_body = body if body else \ self.managed_object._get_modified_info_dict() else: raise URLNotSpecifiedError() else: self.url = url patch_body = body resp, body = self.client.patch(self.url, body=self._get_request_data(patch_body)) data = self._get_data(body, method='PATCH', response=resp) return resp, data