text_prompt
stringlengths
157
13.1k
code_prompt
stringlengths
7
19.8k
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def edituser(self, user_id, **kwargs): """ Edits an user data. :param user_id: id of the user to change :param kwargs: Any param the the Gitlab API supports :ret...
data = {} if kwargs: data.update(kwargs) request = requests.put( '{0}/{1}'.format(self.users_url, user_id), headers=self.headers, data=data, timeout=self.timeout, verify=self.verify_ssl, auth=self.auth) if request.status_code == 200: re...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def getsshkeys(self): """ Gets all the ssh keys for the current user :return: a dictionary with the lists """
request = requests.get( self.keys_url, headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 200: return request.json() else: return False
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def addsshkey(self, title, key): """ Add a new ssh key for the current user :param title: title of the new key :param key: the key itself :return: true if added,...
data = {'title': title, 'key': key} request = requests.post( self.keys_url, headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 201: return True else: return False
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def addsshkeyuser(self, user_id, title, key): """ Add a new ssh key for the user identified by id :param user_id: id of the user to add the key to :param title: ...
data = {'title': title, 'key': key} request = requests.post( '{0}/{1}/keys'.format(self.users_url, user_id), headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 201: return True el...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def deletesshkey(self, key_id): """ Deletes an sshkey for the current user identified by id :param key_id: the id of the key :return: False if it didn't delete i...
request = requests.delete( '{0}/{1}'.format(self.keys_url, key_id), headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.content == b'null': return False else: return True
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get(self, uri, default_response=None, **kwargs): """ Call GET on the Gitlab server :param uri: String with the URI for the endpoint to GET from :param defaul...
url = self.api_url + uri response = requests.get(url, params=kwargs, headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) return self.success_or_raise(response, default_response=default_response)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def post(self, uri, default_response=None, **kwargs): """ Call POST on the Gitlab server :param uri: String with the URI for the endpoint to POST to :param defau...
url = self.api_url + uri response = requests.post( url, headers=self.headers, data=kwargs, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) return self.success_or_raise(response, default_response=default_response)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def delete(self, uri, default_response=None): """ Call DELETE on the Gitlab server :param uri: String with the URI you wish to delete :param default_response: Re...
url = self.api_url + uri response = requests.delete( url, headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) return self.success_or_raise(response, default_response=default_response)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def success_or_raise(self, response, default_response=None): """ Check if request was successful or raises an HttpError :param response: Response Object to check...
if self.suppress_http_error and not response.ok: return False response_json = default_response if response_json is None: response_json = {} response.raise_for_status() try: response_json = response.json() except ValueError: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def getall(fn, page=None, *args, **kwargs): """ Auto-iterate over the paginated results of various methods of the API. Pass the GitLabAPI method as the first arg...
if not page: page = 1 while True: results = fn(*args, page=page, **kwargs) if not results: break for x in results: yield x page += 1
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setsudo(self, user=None): """ Set the subsequent API calls to the user provided :param user: User id or username to change to, None to return to the logged u...
if user is None: try: self.headers.pop('SUDO') except KeyError: pass else: self.headers['SUDO'] = user
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createproject(self, name, **kwargs): """ Creates a new project owned by the authenticated user. :param name: new project name :param path: custom repository ...
data = {'name': name} if kwargs: data.update(kwargs) request = requests.post( self.projects_url, headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 201: return reques...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def editproject(self, project_id, **kwargs): """ Edit an existing project. :param name: new project name :param path: custom repository name for new project. By ...
data = {"id": project_id} if kwargs: data.update(kwargs) request = requests.put( '{0}/{1}'.format(self.projects_url, project_id), headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def shareproject(self, project_id, group_id, group_access): """ Allow to share project with group. :param project_id: The ID of a project :param group_id: The ID...
data = {'id': project_id, 'group_id': group_id, 'group_access': group_access} request = requests.post( '{0}/{1}/share'.format(self.projects_url, project_id), headers=self.headers, data=data, verify=self.verify_ssl) return request.status_code == 201
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def delete_project(self, id): """ Delete a project from the Gitlab server Gitlab currently returns a Boolean True if the deleted and as such we return an empty D...
url = '/projects/{id}'.format(id=id) response = self.delete(url) if response is True: return {} else: return response
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createprojectuser(self, user_id, name, **kwargs): """ Creates a new project owned by the specified user. Available only for admins. :param user_id: user_id o...
data = {'name': name} if kwargs: data.update(kwargs) request = requests.post( '{0}/user/{1}'.format(self.projects_url, user_id), headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code =...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def deleteprojectmember(self, project_id, user_id): """Delete a project member :param project_id: project id :param user_id: user id :return: always true """
request = requests.delete( '{0}/{1}/members/{2}'.format(self.projects_url, project_id, user_id), headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 200: return True
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def addprojecthook(self, project_id, url, push=False, issues=False, merge_requests=False, tag_push=False): """ add a hook to a project :param project_id: project...
data = { 'id': project_id, 'url': url, 'push_events': int(bool(push)), 'issues_events': int(bool(issues)), 'merge_requests_events': int(bool(merge_requests)), 'tag_push_events': int(bool(tag_push)), } request = requests.po...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def editprojecthook(self, project_id, hook_id, url, push=False, issues=False, merge_requests=False, tag_push=False): """ edit an existing hook from a project :pa...
data = { "id": project_id, "hook_id": hook_id, "url": url, 'push_events': int(bool(push)), 'issues_events': int(bool(issues)), 'merge_requests_events': int(bool(merge_requests)), 'tag_push_events': int(bool(tag_push)), ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def getsystemhooks(self, page=1, per_page=20): """ Get all system hooks :param page: Page number :param per_page: Records per page :return: list of hooks """
data = {'page': page, 'per_page': per_page} request = requests.get( self.hook_url, params=data, headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 200: return request.json() else: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def addsystemhook(self, url): """ Add a system hook :param url: url of the hook :return: True if success """
data = {"url": url} request = requests.post( self.hook_url, headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 201: return True else: return False
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def deletesystemhook(self, hook_id): """ Delete a project hook :param hook_id: hook id :return: True if success """
data = {"id": hook_id} request = requests.delete( '{0}/{1}'.format(self.hook_url, hook_id), data=data, headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 200: return True else: r...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createbranch(self, project_id, branch, ref): """ Create branch from commit SHA or existing branch :param project_id: The ID of a project :param branch: The n...
data = {"id": project_id, "branch_name": branch, "ref": ref} request = requests.post( '{0}/{1}/repository/branches'.format(self.projects_url, project_id), headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_c...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def protectbranch(self, project_id, branch): """ Protect a branch from changes :param project_id: project id :param branch: branch id :return: True if success ""...
request = requests.put( '{0}/{1}/repository/branches/{2}/protect'.format(self.projects_url, project_id, branch), headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 200: return True else: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createforkrelation(self, project_id, from_project_id): """ Create a fork relation. This DO NOT create a fork but only adds a link as fork the relation betwee...
data = {'id': project_id, 'forked_from_id': from_project_id} request = requests.post( '{0}/{1}/fork/{2}'.format(self.projects_url, project_id, from_project_id), headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) i...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def removeforkrelation(self, project_id): """ Remove an existing fork relation. this DO NOT remove the fork,only the relation between them :param project_id: pro...
request = requests.delete( '{0}/{1}/fork'.format(self.projects_url, project_id), headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 200: return True else: return False
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createfork(self, project_id): """ Forks a project into the user namespace of the authenticated user. :param project_id: Project ID to fork :return: True if s...
request = requests.post( '{0}/fork/{1}'.format(self.projects_url, project_id), timeout=self.timeout, verify=self.verify_ssl) if request.status_code == 200: return True else: return False
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createissue(self, project_id, title, **kwargs): """ Create a new issue :param project_id: project id :param title: title of the issue :return: dict with the ...
data = {'id': id, 'title': title} if kwargs: data.update(kwargs) request = requests.post( '{0}/{1}/issues'.format(self.projects_url, project_id), headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if reques...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def editissue(self, project_id, issue_id, **kwargs): """ Edit an existing issue data :param project_id: project id :param issue_id: issue id :return: true if suc...
data = {'id': project_id, 'issue_id': issue_id} if kwargs: data.update(kwargs) request = requests.put( '{0}/{1}/issues/{2}'.format(self.projects_url, project_id, issue_id), headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeout=self....
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def enable_deploy_key(self, project, key_id): """ Enables a deploy key for a project. :param project: The ID or URL-encoded path of the project owned by the auth...
url = '/projects/{project}/deploy_keys/{key_id}/enable'.format( project=project, key_id=key_id) return self.post(url, default_response={})
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def adddeploykey(self, project_id, title, key): """ Creates a new deploy key for a project. :param project_id: project id :param title: title of the key :param k...
data = {'id': project_id, 'title': title, 'key': key} request = requests.post( '{0}/{1}/keys'.format(self.projects_url, project_id), headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 201: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def moveproject(self, group_id, project_id): """ Move a given project into a given group :param group_id: ID of the destination group :param project_id: ID of th...
request = requests.post( '{0}/{1}/projects/{2}'.format(self.groups_url, group_id, project_id), headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 201: return request.json() else: return F...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def getmergerequests(self, project_id, page=1, per_page=20, state=None): """ Get all the merge requests for a project. :param project_id: ID of the project to re...
data = {'page': page, 'per_page': per_page, 'state': state} request = requests.get( '{0}/{1}/merge_requests'.format(self.projects_url, project_id), params=data, headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code =...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def getmergerequest(self, project_id, mergerequest_id): """ Get information about a specific merge request. :param project_id: ID of the project :param mergerequ...
request = requests.get( '{0}/{1}/merge_request/{2}'.format(self.projects_url, project_id, mergerequest_id), headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 200: return request.json() else: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createmergerequest(self, project_id, sourcebranch, targetbranch, title, target_project_id=None, assignee_id=None): """ Create a new merge request. :param pro...
data = { 'source_branch': sourcebranch, 'target_branch': targetbranch, 'title': title, 'assignee_id': assignee_id, 'target_project_id': target_project_id } request = requests.post( '{0}/{1}/merge_requests'.format(self.proj...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def acceptmergerequest(self, project_id, mergerequest_id, merge_commit_message=None): """ Update an existing merge request. :param project_id: ID of the project ...
data = {'merge_commit_message': merge_commit_message} request = requests.put( '{0}/{1}/merge_request/{2}/merge'.format(self.projects_url, project_id, mergerequest_id), data=data, headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if re...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def addcommenttomergerequest(self, project_id, mergerequest_id, note): """ Add a comment to a merge request. :param project_id: ID of the project originating the...
request = requests.post( '{0}/{1}/merge_request/{2}/comments'.format(self.projects_url, project_id, mergerequest_id), data={'note': note}, headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) return request.status_code == 201
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createsnippet(self, project_id, title, file_name, code, visibility_level=0): """ Creates an snippet :param project_id: project id to create the snippet under...
data = {'id': project_id, 'title': title, 'file_name': file_name, 'code': code} if visibility_level in [0, 10, 20]: data['visibility_level'] = visibility_level request = requests.post( '{0}/{1}/snippets'.format(self.projects_url, project_id), data=data, ver...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def deletesnippet(self, project_id, snippet_id): """Deletes a given snippet :param project_id: project_id :param snippet_id: snippet id :return: True if success ...
request = requests.delete( '{0}/{1}/snippets/{2}'.format(self.projects_url, project_id, snippet_id), headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) return request.status_code == 200
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def unprotectrepositorybranch(self, project_id, branch): """ Unprotects a single project repository branch. This is an idempotent function, unprotecting an alrea...
request = requests.put( '{0}/{1}/repository/branches/{2}/unprotect'.format(self.projects_url, project_id, branch), headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 200: return request.json() else: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createrepositorytag(self, project_id, tag_name, ref, message=None): """ Creates new tag in the repository that points to the supplied ref :param project_id: ...
data = {'id': project_id, 'tag_name': tag_name, 'ref': ref, 'message': message} request = requests.post( '{0}/{1}/repository/tags'.format(self.projects_url, project_id), data=data, verify=self.verify_ssl, auth=self.auth, headers=self.headers, timeout=self.timeout) if r...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def delete_repository_tag(self, project_id, tag_name): """ Deletes a tag of a repository with given name. :param project_id: The ID of a project :param tag_name:...
return self.delete('/projects/{project_id}/repository/tags/{tag_name}'.format( project_id=project_id, tag_name=tag_name))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def addcommenttocommit(self, project_id, author, sha, path, line, note): """ Adds an inline comment to a specific commit :param project_id: project id :param aut...
data = { 'author': author, 'note': note, 'path': path, 'line': line, 'line_type': 'new' } request = requests.post( '{0}/{1}/repository/commits/{2}/comments'.format(self.projects_url, project_id, sha), headers=...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def getrepositorytree(self, project_id, **kwargs): """ Get a list of repository files and directories in a project. :param project_id: The ID of a project :param...
data = {} if kwargs: data.update(kwargs) request = requests.get( '{0}/{1}/repository/tree'.format(self.projects_url, project_id), params=data, verify=self.verify_ssl, auth=self.auth, headers=self.headers, timeout=self.timeout) if request.status_cod...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def getrawfile(self, project_id, sha1, filepath): """ Get the raw file contents for a file by commit SHA and path. :param project_id: The ID of a project :param ...
data = {'filepath': filepath} request = requests.get( '{0}/{1}/repository/blobs/{2}'.format(self.projects_url, project_id, sha1), params=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout, headers=self.headers) if request.status_code == 200:...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def getrawblob(self, project_id, sha1): """ Get the raw file contents for a blob by blob SHA. :param project_id: The ID of a project :param sha1: the commit sha ...
request = requests.get( '{0}/{1}/repository/raw_blobs/{2}'.format(self.projects_url, project_id, sha1), verify=self.verify_ssl, auth=self.auth, headers=self.headers, timeout=self.timeout) if request.status_code == 200: return request.content else: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def compare_branches_tags_commits(self, project_id, from_id, to_id): """ Compare branches, tags or commits :param project_id: The ID of a project :param from_id:...
data = {'from': from_id, 'to': to_id} request = requests.get( '{0}/{1}/repository/compare'.format(self.projects_url, project_id), params=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout, headers=self.headers) if request.status_code == 200:...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def searchproject(self, search, page=1, per_page=20): """ Search for projects by name which are accessible to the authenticated user :param search: Query to sear...
data = {'page': page, 'per_page': per_page} request = requests.get("{0}/{1}".format(self.search_url, search), params=data, verify=self.verify_ssl, auth=self.auth, headers=self.headers, timeout=self.timeout) if request.status_code == 200: return reques...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def getfilearchive(self, project_id, filepath=None): """ Get an archive of the repository :param project_id: project id :param filepath: path to save the file to...
if not filepath: filepath = '' request = requests.get( '{0}/{1}/repository/archive'.format(self.projects_url, project_id), verify=self.verify_ssl, auth=self.auth, headers=self.headers, timeout=self.timeout) if request.status_code == 200: if file...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def deletegroup(self, group_id): """ Deletes an group by ID :param group_id: id of the group to delete :return: True if it deleted, False if it couldn't. False c...
request = requests.delete( '{0}/{1}'.format(self.groups_url, group_id), headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) return request.status_code == 200
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def getgroupmembers(self, group_id, page=1, per_page=20): """ Lists the members of a given group id :param group_id: the group id :param page: which page to retu...
data = {'page': page, 'per_page': per_page} request = requests.get( '{0}/{1}/members'.format(self.groups_url, group_id), params=data, headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 200: return r...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def deletegroupmember(self, group_id, user_id): """ Delete a group member :param group_id: group id to remove the member from :param user_id: user id :return: al...
request = requests.delete( '{0}/{1}/members/{2}'.format(self.groups_url, group_id, user_id), headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 200: return True
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def addldapgrouplink(self, group_id, cn, group_access, provider): """ Add LDAP group link :param id: The ID of a group :param cn: The CN of a LDAP group :param g...
data = {'id': group_id, 'cn': cn, 'group_access': group_access, 'provider': provider} request = requests.post( '{0}/{1}/ldap_group_links'.format(self.groups_url, group_id), headers=self.headers, data=data, verify=self.verify_ssl) return request.status_code == 201
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createissuewallnote(self, project_id, issue_id, content): """Create a new note :param project_id: Project ID :param issue_id: Issue ID :param content: Conten...
data = {'body': content} request = requests.post( '{0}/{1}/issues/{2}/notes'.format(self.projects_url, project_id, issue_id), verify=self.verify_ssl, auth=self.auth, headers=self.headers, data=data, timeout=self.timeout) if request.status_code == 201: return...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createfile(self, project_id, file_path, branch_name, encoding, content, commit_message): """ Creates a new file in the repository :param project_id: project ...
data = { 'file_path': file_path, 'branch_name': branch_name, 'encoding': encoding, 'content': content, 'commit_message': commit_message } request = requests.post( '{0}/{1}/repository/files'.format(self.projects_url, projec...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def updatefile(self, project_id, file_path, branch_name, content, commit_message): """ Updates an existing file in the repository :param project_id: project id :...
data = { 'file_path': file_path, 'branch_name': branch_name, 'content': content, 'commit_message': commit_message } request = requests.put( '{0}/{1}/repository/files'.format(self.projects_url, project_id), headers=self.hea...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def getfile(self, project_id, file_path, ref): """ Allows you to receive information about file in repository like name, size, content. Note that file content is...
data = {'file_path': file_path, 'ref': ref} request = requests.get( '{0}/{1}/repository/files'.format(self.projects_url, project_id), headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) if request.status_code == 200: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def deletefile(self, project_id, file_path, branch_name, commit_message): """ Deletes existing file in the repository :param project_id: project id :param file_p...
data = { 'file_path': file_path, 'branch_name': branch_name, 'commit_message': commit_message } request = requests.delete( '{0}/{1}/repository/files'.format(self.projects_url, project_id), headers=self.headers, data=data, verify=self....
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setgitlabciservice(self, project_id, token, project_url): """ Set GitLab CI service for project :param project_id: project id :param token: CI project token ...
data = {'token': token, 'project_url': project_url} request = requests.put( '{0}/{1}/services/gitlab-ci'.format(self.projects_url, project_id), verify=self.verify_ssl, auth=self.auth, headers=self.headers, data=data, timeout=self.timeout) return request.status_code == ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def deletegitlabciservice(self, project_id, token, project_url): """ Delete GitLab CI service settings :param project_id: Project ID :param token: Token :param p...
request = requests.delete( '{0}/{1}/services/gitlab-ci'.format(self.projects_url, project_id), headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) return request.status_code == 200
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createlabel(self, project_id, name, color): """ Creates a new label for given repository with given name and color. :param project_id: The ID of a project :p...
data = {'name': name, 'color': color} request = requests.post( '{0}/{1}/labels'.format(self.projects_url, project_id), data=data, verify=self.verify_ssl, auth=self.auth, headers=self.headers, timeout=self.timeout) if request.status_code == 201: return reque...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def deletelabel(self, project_id, name): """ Deletes a label given by its name. :param project_id: The ID of a project :param name: The name of the label :return...
data = {'name': name} request = requests.delete( '{0}/{1}/labels'.format(self.projects_url, project_id), data=data, verify=self.verify_ssl, auth=self.auth, headers=self.headers, timeout=self.timeout) return request.status_code == 200
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def editlabel(self, project_id, name, new_name=None, color=None): """ Updates an existing label with new name or now color. At least one parameter is required, t...
data = {'name': name, 'new_name': new_name, 'color': color} request = requests.put( '{0}/{1}/labels'.format(self.projects_url, project_id), data=data, verify=self.verify_ssl, auth=self.auth, headers=self.headers, timeout=self.timeout) if request.status_code == 200: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def getnamespaces(self, search=None, page=1, per_page=20): """ Return a namespace list :param search: Optional search query :param page: Which page to return (de...
data = {'page': page, 'per_page': per_page} if search: data['search'] = search request = requests.get( self.namespaces_url, params=data, headers=self.headers, verify=self.verify_ssl) if request.status_code == 200: return request.json() else...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_field_mro(cls, field_name): """Goes up the mro and looks for the specified field."""
res = set() if hasattr(cls, '__mro__'): for _class in inspect.getmro(cls): values_ = getattr(_class, field_name, None) if values_ is not None: res = res.union(set(make_list(values_))) return res
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def connect(self): """ Create internal connection to AMQP service. """
logging.info("Connecting to {} with user {}.".format(self.host, self.username)) credentials = pika.PlainCredentials(self.username, self.password) connection_params = pika.ConnectionParameters(host=self.host, credentials=credentials, ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def close(self): """ Close internal connection to AMQP if connected. """
if self.connection: logging.info("Closing connection to {}.".format(self.host)) self.connection.close() self.connection = None
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def process_messages_loop(self): """ Processes incoming WorkRequest messages one at a time via functions specified by add_command. """
self.receiving_messages = True try: self.process_messages_loop_internal() except pika.exceptions.ConnectionClosed as ex: logging.error("Connection closed {}.".format(ex)) raise
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def process_messages_loop_internal(self): """ Busy loop that processes incoming WorkRequest messages via functions specified by add_command. Terminates if a comm...
logging.info("Starting work queue loop.") self.connection.receive_loop_with_callback(self.queue_name, self.process_message)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def process_messages_loop_internal(self): """ Busy loop that processes incoming WorkRequest messages via functions specified by add_command. Disconnects while se...
while self.receiving_messages: # connect to AMQP server and listen for 1 message then disconnect self.work_request = None self.connection.receive_loop_with_callback(self.queue_name, self.save_work_request_and_close) if self.work_request: self.proc...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def save_work_request_and_close(self, ch, method, properties, body): """ Save message body and close connection """
self.work_request = pickle.loads(body) ch.basic_ack(delivery_tag=method.delivery_tag) ch.stop_consuming() self.connection.close()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_related_galleries(gallery, count=5): """ Gets latest related galleries from same section as originating gallery. Count defaults to five but can be overri...
# just get the first cat. If they assigned to more than one, tough try: cat = gallery.sections.all()[0] related = cat.gallery_categories.filter(published=True).exclude(id=gallery.id).order_by('-id')[:count] except: related = None return {'related': related, 'MEDIA_URL': settings...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def load_healthchecks(self): """ Loads healthchecks. """
self.load_default_healthchecks() if getattr(settings, 'AUTODISCOVER_HEALTHCHECKS', True): self.autodiscover_healthchecks() self._registry_loaded = True
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def load_default_healthchecks(self): """ Loads healthchecks specified in settings.HEALTHCHECKS as dotted import paths to the classes. Defaults are listed in `DEF...
default_healthchecks = getattr(settings, 'HEALTHCHECKS', DEFAULT_HEALTHCHECKS) for healthcheck in default_healthchecks: healthcheck = import_string(healthcheck) self.register_healthcheck(healthcheck)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def run_healthchecks(self): """ Runs all registered healthchecks and returns a list of HealthcheckResponse. """
if not self._registry_loaded: self.load_healthchecks() def get_healthcheck_name(hc): if hasattr(hc, 'name'): return hc.name return hc.__name__ responses = [] for healthcheck in self._registry: try: if insp...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def advance_by(self, amount): """Advance the time reference by the given amount. :param `float` amount: number of seconds to advance. :raise `ValueError`: if *am...
if amount < 0: raise ValueError("cannot retreat time reference: amount {} < 0" .format(amount)) self.__delta += amount
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def advance_to(self, timestamp): """Advance the time reference so that now is the given timestamp. :param `float` timestamp: the new current timestamp. :raise `V...
now = self.__original_time() if timestamp < now: raise ValueError("cannot retreat time reference: " "target {} < now {}" .format(timestamp, now)) self.__delta = timestamp - now
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def reset_frequencies(self, frequency=0): """Resets all stored frequencies for the cache :keyword int frequency: Frequency to reset to, must be >= 0"""
frequency = max(frequency, 0) for key in self._store.keys(): self._store[key] = (self._store[key][0], frequency) return frequency
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def oldest(self): """ Gets key, value pair for oldest item in cache :returns: tuple """
if len(self._store) == 0: return kv = min(self._store.items(), key=lambda x: x[1][1]) return kv[0], kv[1][0]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def parser_helper(key, val): ''' Helper for parser function @param key: @param val: ''' start_bracket = key.find("[") end_bracket = key.find("]") pdict = {} if has_variable_name(key): # var['key'][3] pdict[key[:key.find("[")]] = parser_helper(key[start_bracket:], v...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def parse(query_string, unquote=True, normalized=False, encoding=DEFAULT_ENCODING): ''' Main parse function @param query_string: @param unquote: unquote html query string ? @param encoding: An optional encoding used to decode the keys and values. Defaults to utf-8, which the W3C declares as a d...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def validate_swagger_schema(schema_dir, resource_listing): """Validate the structure of Swagger schemas against the spec. **Valid only for Swagger v1.2 spec** No...
schema_filepath = os.path.join(schema_dir, API_DOCS_FILENAME) swagger_spec_validator.validator12.validate_spec( resource_listing, urlparse.urljoin('file:', pathname2url(os.path.abspath(schema_filepath))), )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def build_param_schema(schema, param_type): """Turn a swagger endpoint schema into an equivalent one to validate our request. As an example, this would take this...
properties = filter_params_by_type(schema, param_type) if not properties: return # Generate a jsonschema that describes the set of all query parameters. We # can then validate this against dict(request.params). return { 'type': 'object', 'properties': dict((p['name'], p) fo...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def required_validator(validator, req, instance, schema): """Swagger 1.2 expects `required` to be a bool in the Parameter object, but a list of properties in a M...
if schema.get('paramType'): if req is True and not instance: return [ValidationError("%s is required" % schema['name'])] return [] return _validators.required_draft4(validator, req, instance, schema)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def load_schema(schema_path): """Prepare the api specification for request and response validation. :returns: a mapping from :class:`RequestMatcher` to :class:`V...
with open(schema_path, 'r') as schema_file: schema = simplejson.load(schema_file) resolver = RefResolver('', '', schema.get('models', {})) return build_request_to_validator_map(schema, resolver)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_swagger_objects(settings, route_info, registry): """Returns appropriate swagger handler and swagger spec schema. Swagger Handler contains callables that ...
enabled_swagger_versions = get_swagger_versions(registry.settings) schema12 = registry.settings['pyramid_swagger.schema12'] schema20 = registry.settings['pyramid_swagger.schema20'] fallback_to_swagger12_route = ( SWAGGER_20 in enabled_swagger_versions and SWAGGER_12 in enabled_swagger_...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def validation_tween_factory(handler, registry): """Pyramid tween for performing validation. Note this is very simple -- it validates requests, responses, and pa...
settings = load_settings(registry) route_mapper = registry.queryUtility(IRoutesMapper) validation_context = _get_validation_context(registry) def validator_tween(request): # We don't have access to this yet but let's go ahead and build the # matchdict so we can validate it and use it ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def handle_request(request, validator_map, **kwargs): """Validate the request against the swagger spec and return a dict with all parameter values available in t...
request_data = {} validation_pairs = [] for validator, values in [ (validator_map.query, request.query), (validator_map.path, request.path), (validator_map.form, request.form), (validator_map.headers, request.headers), ]: values = cast_params(validator.schema, v...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def build_swagger12_handler(schema): """Builds a swagger12 handler or returns None if no schema is present. :type schema: :class:`pyramid_swagger.model.SwaggerSc...
if schema: return SwaggerHandler( op_for_request=schema.validators_for_request, handle_request=handle_request, handle_response=validate_response, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def validate_response(response, validator_map): """Validates response against our schemas. :param response: the response object to validate :type response: :clas...
validator = validator_map.response # Short circuit if we are supposed to not validate anything. returns_nothing = validator.schema.get('type') == 'void' body_empty = response.body in (None, b'', b'{}', b'null') if returns_nothing and body_empty: return # Don't attempt to validate non-...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def swaggerize_response(response, op): """ Delegate handling the Swagger concerns of the response to bravado-core. :type response: :class:`pyramid.response.Respo...
response_spec = get_response_spec(response.status_int, op) bravado_core.response.validate_response( response_spec, op, PyramidSwaggerResponse(response))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_op_for_request(request, route_info, spec): """ Find out which operation in the Swagger schema corresponds to the given pyramid request. :type request: :c...
# pyramid.urldispath.Route route = route_info['route'] if hasattr(route, 'path'): route_path = route.path if route_path[0] != '/': route_path = '/' + route_path op = spec.get_op_for_request(request.method, route_path) if op is not None: return op ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_swagger_versions(settings): """ Validates and returns the versions of the Swagger Spec that this pyramid application supports. :type settings: dict :retu...
swagger_versions = set(aslist(settings.get( 'pyramid_swagger.swagger_versions', DEFAULT_SWAGGER_VERSIONS))) if len(swagger_versions) == 0: raise ValueError('pyramid_swagger.swagger_versions is empty') for swagger_version in swagger_versions: if swagger_version not in SUPPORTED_SWA...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def register_api_doc_endpoints(config, endpoints, base_path='/api-docs'): """Create and register pyramid endpoints to service swagger api docs. Routes and views ...
for endpoint in endpoints: path = base_path.rstrip('/') + endpoint.path config.add_route(endpoint.route_name, path) config.add_view( endpoint.view, route_name=endpoint.route_name, renderer=endpoint.renderer)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def build_swagger_12_api_declaration_view(api_declaration_json): """Thanks to the magic of closures, this means we gracefully return JSON without file IO at requ...
def view_for_api_declaration(request): # Note that we rewrite basePath to always point at this server's root. return dict( api_declaration_json, basePath=str(request.application_url), ) return view_for_api_declaration
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def partial_path_match(path1, path2, kwarg_re=r'\{.*\}'): """Validates if path1 and path2 matches, ignoring any kwargs in the string. We need this to ensure we c...
split_p1 = path1.split('/') split_p2 = path2.split('/') pat = re.compile(kwarg_re) if len(split_p1) != len(split_p2): return False for partial_p1, partial_p2 in zip(split_p1, split_p2): if pat.match(partial_p1) or pat.match(partial_p2): continue if not partial_p1...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def validators_for_request(self, request, **kwargs): """Takes a request and returns a validator mapping for the request. :param request: A Pyramid request to fet...
for resource_validator in self.resource_validators: for matcher, validator_map in resource_validator.items(): if matcher.matches(request): return validator_map raise PathNotMatchedError( 'Could not find the relevant path ({0}) in the Swagger ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def build_schema_mapping(schema_dir, resource_listing): """Discovers schema file locations and relations. :param schema_dir: the directory schema files live insi...
def resource_name_to_filepath(name): return os.path.join(schema_dir, '{0}.json'.format(name)) return dict( (resource, resource_name_to_filepath(resource)) for resource in find_resource_names(resource_listing) )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _load_resource_listing(resource_listing): """Load the resource listing from file, handling errors. :param resource_listing: path to the api-docs resource lis...
try: with open(resource_listing) as resource_listing_file: return simplejson.load(resource_listing_file) # If not found, raise a more user-friendly error. except IOError: raise ResourceListingNotFoundError( 'No resource listing found at {0}. Note that your json file ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_resource_listing(schema_dir, should_generate_resource_listing): """Return the resource listing document. :param schema_dir: the directory which contains ...
listing_filename = os.path.join(schema_dir, API_DOCS_FILENAME) resource_listing = _load_resource_listing(listing_filename) if not should_generate_resource_listing: return resource_listing return generate_resource_listing(schema_dir, resource_listing)