def delete(self): assert self._get_pk_val() is not None, "%s object can't be deleted " \ "because its %s attribute is set to None." \ % (self._meta.object_name, self._meta.pk.attname) # Deletion in cascade should be done server side. resource = Resource(self.get_resource_url_detail(), filters=ROA_FILTERS) logger.debug(u"""Deleting : "%s" through %s""" % \ (unicode(self), unicode(resource.uri))) resource.delete(headers=ROA_HEADERS, **ROA_CUSTOM_ARGS)
class Query(object): def __init__(self, url=GITHUB_URL, params=None, payload=None, headers=None, filters=None, access_token=None): self.url = url self.params = params or dict() self.payload = payload or dict() self.headers = headers or {'Content-Type': 'application/json'} filters = filters or list() self.resource = Resource( url, pool=ConnectionPool(factory=Connection), filters=filters, ) if access_token is not None: self.params["access_token"] = access_token def concat_path(self, *args): for path in args: self.resource.update_uri(path) def do_GET(self, path=None, params=None): params = params or self.params response = self.resource.get(path, self.headers, params) return self.parse_response(response.body_string()) def do_POST(self, path=None, payload=None, params=None): payload = payload or self.payload params = params or self.params response = self.resource.post(path, json.dumps(payload), self.headers, params) return self.parse_response(response.body_string()) def do_DELETE(self, path=None, params=None): params = params or self.params response = self.resource.delete(path, self.headers, params) return self.parse_response(response.body_string()) def do_PATCH(self, path=None, payload=None, params=None): payload = payload or self.payload params = params or self.params response = self.resource.request("PATCH", path, json.dumps(payload), self.headers, params) return self.parse_response(response.body_string()) def parse_response(self, response): try: return json.loads(response) except: return response def __repr__(self): return "uri:<{0}>".format(self.resource.uri) def __str__(self): return self.resource.uri
def _delete_page(self, path): """delete page at a given path""" retval = None res = Resource(self.host) page = res.delete(path) data = page.body_string() if data: retval = json.loads(data) return retval
def _delete_page(host, path): """delete page at a given path""" retval = None if "http://" not in host: host = "http://{0}".format(host) res = Resource(host) page = res.delete(path) data = page.body_string() if data: retval = json.loads(data) return retval
def delete(self): assert self._get_pk_val() is not None, "%s object can't be deleted " \ "because its %s attribute is set to None." \ % (self._meta.object_name, self._meta.pk.attname) # Deletion in cascade should be done server side. resource = Resource(self.get_resource_url_detail(), filters=ROA_FILTERS, **ROA_SSL_ARGS) logger.debug(u"""Deleting : "%s" through %s""" % \ (unicode(self), unicode(resource.uri))) result = resource.delete(headers={'Content-Type': 'application/json'}, **ROA_CUSTOM_ARGS) if result.status_int in [200, 202, 204]: self.pk = None
def removeOwner(namespace, name, owner): ''' Remove an owner for a module or target (owners are the people with permission to publish versions and add/remove the owners). ''' url = '%s/%s/%s/owners/%s' % ( Registry_Base_URL, namespace, name, owner ) auth = _registryAuthFilter() resource = Resource(url, pool=connection_pool.getPool(), filters=[auth]) try: response = resource.delete() except restkit_errors.ResourceNotFound as e: logger.error('no such %s, "%s"' % (namespace, name))
class StoreClient(object): def __init__(self, endpoint, name, **kwargs): if endpoint.endswith('/'): endpoint = endpoint.rstrip('/') if 'pool' not in kwargs: kwargs['pool'] = ConnectionPool(factory=Connection) self.json_default = kwargs.get('json_default', json_util.default) self.json_object_hook = kwargs.get('json_object_hook', json_util.object_hook) self.resource = Resource(endpoint, **kwargs) self.name = name def create_store(self, store): response = self.resource.post("/stores/%s" % store) if response.status_int == 200: return json.loads(response.body_string(), object_hook=self.json_object_hook) def get_stores(self): response = self.resource.get("/stores") if response.status_int == 200: return json.loads(response.body_string(), object_hook=self.json_object_hook) def create_branch(self, store, branch, parent=None): path = _build_path(store, "branch", branch) params = _build_params(parent=parent) response = self.resource.post(path, params_dict=params) if response.status_int == 200: return json.loads(response.body_string(), object_hook=self.json_object_hook) def get_branch(self, store, branch): path = _build_path(store, "branch", branch) response = self.resource.get(path) if response.status_int == 200: return json.loads(response.body_string(), object_hook=self.json_object_hook) def merge(self, store, source, target='master', author=None, committer=None): path = _build_path(store, "merge", source) params = _build_params(target=target, author=author, committer=committer) response = self.resource.post(path, params_dict=params) if response.status_int == 200: return json.loads(response.body_string(), object_hook=self.json_object_hook) def get(self, store, key=None, shallow=False, branch='master', commit_sha=None): path = _entry_path(store, key) params = _build_params(shallow=shallow, branch=branch, commit_sha=commit_sha) response = self.resource.get(path, params_dict=params) if response.status_int == 200: response_body = response.body_string() return json.loads(response_body, object_hook=self.json_object_hook) def put(self, store, key, value, flatten_keys=True, branch='master', author=None, committer=None): path = _entry_path(store, key) payload = json.dumps(value, default=self.json_default) flatten_keys = 1 if flatten_keys else 0 params = _build_params(flatten_keys=flatten_keys, branch=branch, author=author, committer=committer) headers = {'Content-Type': 'application/json'} response = self.resource.put(path, headers=headers, payload=payload, params_dict=params) if response.status_int == 200: return json.loads(response.body_string(), object_hook=self.json_object_hook) def delete(self, store, key, branch='master', author=None, committer=None): path = _entry_path(store, key) params = _build_params(branch=branch, author=author, committer=committer) response = self.resource.delete(path, params_dict=params) if response.status_int == 200: return json.loads(response.body_string(), object_hook=self.json_object_hook) def keys(self, store, key=None, pattern=None, depth=None, filter_by=None, branch='master', commit_sha=None): path = _build_path(store, "keys", key) params = _build_params(pattern=pattern, depth=depth, filter_by=filter_by, branch=branch, commit_sha=commit_sha) response = self.resource.get(path, params_dict=params) if response.status_int == 200: return json.loads(response.body_string(), object_hook=self.json_object_hook) def entries(self, store, key=None, pattern=None, depth=None, branch='master', commit_sha=None): path = _build_path(store, "entries", key) params = _build_params(pattern=pattern, depth=depth, branch=branch, commit_sha=commit_sha) response = self.resource.get(path, params_dict=params) if response.status_int == 200: return json.loads(response.body_string(), object_hook=self.json_object_hook) def trees(self, store, key=None, pattern=None, depth=None, object_depth=None, branch='master', commit_sha=None): path = _build_path(store, "trees", key) params = _build_params(pattern=pattern, depth=depth, object_depth=object_depth, branch=branch, commit_sha=commit_sha) response = self.resource.get(path, params_dict=params) if response.status_int == 200: return json.loads(response.body_string(), object_hook=self.json_object_hook)
class Query(object): def __init__(self, url=GITHUB_URL, params=None, payload=None, headers=None, filters=None, access_token=None): self.url = url self.params = params or dict() self.payload = payload or dict() self.headers = headers or {'Content-Type':'application/json'} filters = filters or list() self.resource = Resource( url, pool=ConnectionPool(factory=Connection), filters=filters, ) if access_token is not None: self.params["access_token"] = access_token def concat_path(self, *args): for path in args: self.resource.update_uri(path) def do_GET(self, path=None, params=None): params = params or self.params response = self.resource.get( path, self.headers, params) return self.parse_response(response.body_string()) def do_POST(self, path=None, payload=None, params=None): payload = payload or self.payload params = params or self.params response = self.resource.post( path, json.dumps(payload), self.headers, params) return self.parse_response(response.body_string()) def do_DELETE(self, path=None, params=None): params = params or self.params response = self.resource.delete( path, self.headers, params) return self.parse_response(response.body_string()) def do_PATCH(self, path=None, payload=None, params=None): payload = payload or self.payload params = params or self.params response = self.resource.request( "PATCH", path, json.dumps(payload), self.headers, params) return self.parse_response(response.body_string()) def parse_response(self, response): try: return json.loads(response) except: return response def __repr__(self): return u"uri:<{0}>".format(self.resource.uri) def __str__(self): return self.resource.uri