repository_name
stringlengths
7
55
func_path_in_repository
stringlengths
4
223
func_name
stringlengths
1
134
whole_func_string
stringlengths
75
104k
language
stringclasses
1 value
func_code_string
stringlengths
75
104k
func_code_tokens
listlengths
19
28.4k
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
listlengths
1
1.97k
split_name
stringclasses
1 value
func_code_url
stringlengths
87
315
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.get_repo_hooks
def get_repo_hooks(self, auth, username, repo_name): """ Returns all hooks of repository with name ``repo_name`` owned by the user with username ``username``. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: name of repository :return: a list of hooks for the specified repository :rtype: List[GogsRepo.Hooks] :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ path = "/repos/{u}/{r}/hooks".format(u=username, r=repo_name) response = self.get(path, auth=auth) return [GogsRepo.Hook.from_json(hook) for hook in response.json()]
python
def get_repo_hooks(self, auth, username, repo_name): """ Returns all hooks of repository with name ``repo_name`` owned by the user with username ``username``. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: name of repository :return: a list of hooks for the specified repository :rtype: List[GogsRepo.Hooks] :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ path = "/repos/{u}/{r}/hooks".format(u=username, r=repo_name) response = self.get(path, auth=auth) return [GogsRepo.Hook.from_json(hook) for hook in response.json()]
[ "def", "get_repo_hooks", "(", "self", ",", "auth", ",", "username", ",", "repo_name", ")", ":", "path", "=", "\"/repos/{u}/{r}/hooks\"", ".", "format", "(", "u", "=", "username", ",", "r", "=", "repo_name", ")", "response", "=", "self", ".", "get", "(", ...
Returns all hooks of repository with name ``repo_name`` owned by the user with username ``username``. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: name of repository :return: a list of hooks for the specified repository :rtype: List[GogsRepo.Hooks] :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Returns", "all", "hooks", "of", "repository", "with", "name", "repo_name", "owned", "by", "the", "user", "with", "username", "username", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L377-L392
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.create_hook
def create_hook(self, auth, repo_name, hook_type, config, events=None, organization=None, active=False): """ Creates a new hook, and returns the created hook. :param auth.Authentication auth: authentication object, must be admin-level :param str repo_name: the name of the repo for which we create the hook :param str hook_type: The type of webhook, either "gogs" or "slack" :param dict config: Settings for this hook (possible keys are ``"url"``, ``"content_type"``, ``"secret"``) :param list events: Determines what events the hook is triggered for. Default: ["push"] :param str organization: Organization of the repo :param bool active: Determines whether the hook is actually triggered on pushes. Default is false :return: a representation of the created hook :rtype: GogsRepo.Hook :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ if events is None: events = ["push"] # default value is mutable, so assign inside body data = { "type": hook_type, "config": config, "events": events, "active": active } url = "/repos/{o}/{r}/hooks".format(o=organization, r=repo_name) if organization is not None \ else "/repos/{r}/hooks".format(r=repo_name) response = self.post(url, auth=auth, data=data) return GogsRepo.Hook.from_json(response.json())
python
def create_hook(self, auth, repo_name, hook_type, config, events=None, organization=None, active=False): """ Creates a new hook, and returns the created hook. :param auth.Authentication auth: authentication object, must be admin-level :param str repo_name: the name of the repo for which we create the hook :param str hook_type: The type of webhook, either "gogs" or "slack" :param dict config: Settings for this hook (possible keys are ``"url"``, ``"content_type"``, ``"secret"``) :param list events: Determines what events the hook is triggered for. Default: ["push"] :param str organization: Organization of the repo :param bool active: Determines whether the hook is actually triggered on pushes. Default is false :return: a representation of the created hook :rtype: GogsRepo.Hook :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ if events is None: events = ["push"] # default value is mutable, so assign inside body data = { "type": hook_type, "config": config, "events": events, "active": active } url = "/repos/{o}/{r}/hooks".format(o=organization, r=repo_name) if organization is not None \ else "/repos/{r}/hooks".format(r=repo_name) response = self.post(url, auth=auth, data=data) return GogsRepo.Hook.from_json(response.json())
[ "def", "create_hook", "(", "self", ",", "auth", ",", "repo_name", ",", "hook_type", ",", "config", ",", "events", "=", "None", ",", "organization", "=", "None", ",", "active", "=", "False", ")", ":", "if", "events", "is", "None", ":", "events", "=", ...
Creates a new hook, and returns the created hook. :param auth.Authentication auth: authentication object, must be admin-level :param str repo_name: the name of the repo for which we create the hook :param str hook_type: The type of webhook, either "gogs" or "slack" :param dict config: Settings for this hook (possible keys are ``"url"``, ``"content_type"``, ``"secret"``) :param list events: Determines what events the hook is triggered for. Default: ["push"] :param str organization: Organization of the repo :param bool active: Determines whether the hook is actually triggered on pushes. Default is false :return: a representation of the created hook :rtype: GogsRepo.Hook :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Creates", "a", "new", "hook", "and", "returns", "the", "created", "hook", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L394-L424
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.update_hook
def update_hook(self, auth, repo_name, hook_id, update, organization=None): """ Updates hook with id ``hook_id`` according to ``update``. :param auth.Authentication auth: authentication object :param str repo_name: repo of the hook to update :param int hook_id: id of the hook to update :param GogsHookUpdate update: a ``GogsHookUpdate`` object describing the requested update :param str organization: name of associated organization, if applicable :return: the updated hook :rtype: GogsRepo.Hook :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ if organization is not None: path = "/repos/{o}/{r}/hooks/{i}".format(o=organization, r=repo_name, i=hook_id) else: path = "/repos/{r}/hooks/{i}".format(r=repo_name, i=hook_id) response = self._patch(path, auth=auth, data=update.as_dict()) return GogsRepo.Hook.from_json(response.json())
python
def update_hook(self, auth, repo_name, hook_id, update, organization=None): """ Updates hook with id ``hook_id`` according to ``update``. :param auth.Authentication auth: authentication object :param str repo_name: repo of the hook to update :param int hook_id: id of the hook to update :param GogsHookUpdate update: a ``GogsHookUpdate`` object describing the requested update :param str organization: name of associated organization, if applicable :return: the updated hook :rtype: GogsRepo.Hook :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ if organization is not None: path = "/repos/{o}/{r}/hooks/{i}".format(o=organization, r=repo_name, i=hook_id) else: path = "/repos/{r}/hooks/{i}".format(r=repo_name, i=hook_id) response = self._patch(path, auth=auth, data=update.as_dict()) return GogsRepo.Hook.from_json(response.json())
[ "def", "update_hook", "(", "self", ",", "auth", ",", "repo_name", ",", "hook_id", ",", "update", ",", "organization", "=", "None", ")", ":", "if", "organization", "is", "not", "None", ":", "path", "=", "\"/repos/{o}/{r}/hooks/{i}\"", ".", "format", "(", "o...
Updates hook with id ``hook_id`` according to ``update``. :param auth.Authentication auth: authentication object :param str repo_name: repo of the hook to update :param int hook_id: id of the hook to update :param GogsHookUpdate update: a ``GogsHookUpdate`` object describing the requested update :param str organization: name of associated organization, if applicable :return: the updated hook :rtype: GogsRepo.Hook :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Updates", "hook", "with", "id", "hook_id", "according", "to", "update", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L426-L445
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.delete_hook
def delete_hook(self, auth, username, repo_name, hook_id): """ Deletes the hook with id ``hook_id`` for repo with name ``repo_name`` owned by the user with username ``username``. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: name of repository of hook to delete :param int hook_id: id of hook to delete :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ path = "/repos/{u}/{r}/hooks/{i}".format(u=username, r=repo_name, i=hook_id) self.delete(path, auth=auth)
python
def delete_hook(self, auth, username, repo_name, hook_id): """ Deletes the hook with id ``hook_id`` for repo with name ``repo_name`` owned by the user with username ``username``. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: name of repository of hook to delete :param int hook_id: id of hook to delete :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ path = "/repos/{u}/{r}/hooks/{i}".format(u=username, r=repo_name, i=hook_id) self.delete(path, auth=auth)
[ "def", "delete_hook", "(", "self", ",", "auth", ",", "username", ",", "repo_name", ",", "hook_id", ")", ":", "path", "=", "\"/repos/{u}/{r}/hooks/{i}\"", ".", "format", "(", "u", "=", "username", ",", "r", "=", "repo_name", ",", "i", "=", "hook_id", ")",...
Deletes the hook with id ``hook_id`` for repo with name ``repo_name`` owned by the user with username ``username``. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: name of repository of hook to delete :param int hook_id: id of hook to delete :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Deletes", "the", "hook", "with", "id", "hook_id", "for", "repo", "with", "name", "repo_name", "owned", "by", "the", "user", "with", "username", "username", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L447-L460
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.create_organization
def create_organization(self, auth, owner_name, org_name, full_name=None, description=None, website=None, location=None): """ Creates a new organization, and returns the created organization. :param auth.Authentication auth: authentication object, must be admin-level :param str owner_name: Username of organization owner :param str org_name: Organization name :param str full_name: Full name of organization :param str description: Description of the organization :param str website: Official website :param str location: Organization location :return: a representation of the created organization :rtype: GogsOrg :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ data = { "username": org_name, "full_name": full_name, "description": description, "website": website, "location": location } url = "/admin/users/{u}/orgs".format(u=owner_name) response = self.post(url, auth=auth, data=data) return GogsOrg.from_json(response.json())
python
def create_organization(self, auth, owner_name, org_name, full_name=None, description=None, website=None, location=None): """ Creates a new organization, and returns the created organization. :param auth.Authentication auth: authentication object, must be admin-level :param str owner_name: Username of organization owner :param str org_name: Organization name :param str full_name: Full name of organization :param str description: Description of the organization :param str website: Official website :param str location: Organization location :return: a representation of the created organization :rtype: GogsOrg :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ data = { "username": org_name, "full_name": full_name, "description": description, "website": website, "location": location } url = "/admin/users/{u}/orgs".format(u=owner_name) response = self.post(url, auth=auth, data=data) return GogsOrg.from_json(response.json())
[ "def", "create_organization", "(", "self", ",", "auth", ",", "owner_name", ",", "org_name", ",", "full_name", "=", "None", ",", "description", "=", "None", ",", "website", "=", "None", ",", "location", "=", "None", ")", ":", "data", "=", "{", "\"username...
Creates a new organization, and returns the created organization. :param auth.Authentication auth: authentication object, must be admin-level :param str owner_name: Username of organization owner :param str org_name: Organization name :param str full_name: Full name of organization :param str description: Description of the organization :param str website: Official website :param str location: Organization location :return: a representation of the created organization :rtype: GogsOrg :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Creates", "a", "new", "organization", "and", "returns", "the", "created", "organization", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L462-L489
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.create_organization_team
def create_organization_team(self, auth, org_name, name, description=None, permission="read"): """ Creates a new team of the organization. :param auth.Authentication auth: authentication object, must be admin-level :param str org_name: Organization user name :param str name: Full name of the team :param str description: Description of the team :param str permission: Team permission, can be read, write or admin, default is read :return: a representation of the created team :rtype: GogsTeam :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ data = { "name": name, "description": description, "permission": permission } url = "/admin/orgs/{o}/teams".format(o=org_name) response = self.post(url, auth=auth, data=data) return GogsTeam.from_json(response.json())
python
def create_organization_team(self, auth, org_name, name, description=None, permission="read"): """ Creates a new team of the organization. :param auth.Authentication auth: authentication object, must be admin-level :param str org_name: Organization user name :param str name: Full name of the team :param str description: Description of the team :param str permission: Team permission, can be read, write or admin, default is read :return: a representation of the created team :rtype: GogsTeam :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ data = { "name": name, "description": description, "permission": permission } url = "/admin/orgs/{o}/teams".format(o=org_name) response = self.post(url, auth=auth, data=data) return GogsTeam.from_json(response.json())
[ "def", "create_organization_team", "(", "self", ",", "auth", ",", "org_name", ",", "name", ",", "description", "=", "None", ",", "permission", "=", "\"read\"", ")", ":", "data", "=", "{", "\"name\"", ":", "name", ",", "\"description\"", ":", "description", ...
Creates a new team of the organization. :param auth.Authentication auth: authentication object, must be admin-level :param str org_name: Organization user name :param str name: Full name of the team :param str description: Description of the team :param str permission: Team permission, can be read, write or admin, default is read :return: a representation of the created team :rtype: GogsTeam :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Creates", "a", "new", "team", "of", "the", "organization", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L491-L513
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.add_team_membership
def add_team_membership(self, auth, team_id, username): """ Add user to team. :param auth.Authentication auth: authentication object, must be admin-level :param str team_id: Team's id :param str username: Username of the user to be added to team :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ url = "/admin/teams/{t}/members/{u}".format(t=team_id, u=username) self.put(url, auth=auth)
python
def add_team_membership(self, auth, team_id, username): """ Add user to team. :param auth.Authentication auth: authentication object, must be admin-level :param str team_id: Team's id :param str username: Username of the user to be added to team :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ url = "/admin/teams/{t}/members/{u}".format(t=team_id, u=username) self.put(url, auth=auth)
[ "def", "add_team_membership", "(", "self", ",", "auth", ",", "team_id", ",", "username", ")", ":", "url", "=", "\"/admin/teams/{t}/members/{u}\"", ".", "format", "(", "t", "=", "team_id", ",", "u", "=", "username", ")", "self", ".", "put", "(", "url", ",...
Add user to team. :param auth.Authentication auth: authentication object, must be admin-level :param str team_id: Team's id :param str username: Username of the user to be added to team :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Add", "user", "to", "team", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L515-L526
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.remove_team_membership
def remove_team_membership(self, auth, team_id, username): """ Remove user from team. :param auth.Authentication auth: authentication object, must be admin-level :param str team_id: Team's id :param str username: Username of the user to be removed from the team :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ url = "/admin/teams/{t}/members/{u}".format(t=team_id, u=username) self.delete(url, auth=auth)
python
def remove_team_membership(self, auth, team_id, username): """ Remove user from team. :param auth.Authentication auth: authentication object, must be admin-level :param str team_id: Team's id :param str username: Username of the user to be removed from the team :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ url = "/admin/teams/{t}/members/{u}".format(t=team_id, u=username) self.delete(url, auth=auth)
[ "def", "remove_team_membership", "(", "self", ",", "auth", ",", "team_id", ",", "username", ")", ":", "url", "=", "\"/admin/teams/{t}/members/{u}\"", ".", "format", "(", "t", "=", "team_id", ",", "u", "=", "username", ")", "self", ".", "delete", "(", "url"...
Remove user from team. :param auth.Authentication auth: authentication object, must be admin-level :param str team_id: Team's id :param str username: Username of the user to be removed from the team :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Remove", "user", "from", "team", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L528-L539
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.add_repo_to_team
def add_repo_to_team(self, auth, team_id, repo_name): """ Add or update repo from team. :param auth.Authentication auth: authentication object, must be admin-level :param str team_id: Team's id :param str repo_name: Name of the repo to be added to the team :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ url = "/admin/teams/{t}/repos/{r}".format(t=team_id, r=repo_name) self.put(url, auth=auth)
python
def add_repo_to_team(self, auth, team_id, repo_name): """ Add or update repo from team. :param auth.Authentication auth: authentication object, must be admin-level :param str team_id: Team's id :param str repo_name: Name of the repo to be added to the team :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ url = "/admin/teams/{t}/repos/{r}".format(t=team_id, r=repo_name) self.put(url, auth=auth)
[ "def", "add_repo_to_team", "(", "self", ",", "auth", ",", "team_id", ",", "repo_name", ")", ":", "url", "=", "\"/admin/teams/{t}/repos/{r}\"", ".", "format", "(", "t", "=", "team_id", ",", "r", "=", "repo_name", ")", "self", ".", "put", "(", "url", ",", ...
Add or update repo from team. :param auth.Authentication auth: authentication object, must be admin-level :param str team_id: Team's id :param str repo_name: Name of the repo to be added to the team :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Add", "or", "update", "repo", "from", "team", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L541-L552
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.remove_repo_from_team
def remove_repo_from_team(self, auth, team_id, repo_name): """ Remove repo from team. :param auth.Authentication auth: authentication object, must be admin-level :param str team_id: Team's id :param str repo_name: Name of the repo to be removed from the team :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ url = "/admin/teams/{t}/repos/{r}".format(t=team_id, r=repo_name) self.delete(url, auth=auth)
python
def remove_repo_from_team(self, auth, team_id, repo_name): """ Remove repo from team. :param auth.Authentication auth: authentication object, must be admin-level :param str team_id: Team's id :param str repo_name: Name of the repo to be removed from the team :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ url = "/admin/teams/{t}/repos/{r}".format(t=team_id, r=repo_name) self.delete(url, auth=auth)
[ "def", "remove_repo_from_team", "(", "self", ",", "auth", ",", "team_id", ",", "repo_name", ")", ":", "url", "=", "\"/admin/teams/{t}/repos/{r}\"", ".", "format", "(", "t", "=", "team_id", ",", "r", "=", "repo_name", ")", "self", ".", "delete", "(", "url",...
Remove repo from team. :param auth.Authentication auth: authentication object, must be admin-level :param str team_id: Team's id :param str repo_name: Name of the repo to be removed from the team :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Remove", "repo", "from", "team", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L554-L565
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.list_deploy_keys
def list_deploy_keys(self, auth, username, repo_name): """ List deploy keys for the specified repo. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: the name of the repo :return: a list of deploy keys for the repo :rtype: List[GogsRepo.DeployKey] :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ response = self.get("/repos/{u}/{r}/keys".format(u=username, r=repo_name), auth=auth) return [GogsRepo.DeployKey.from_json(key_json) for key_json in response.json()]
python
def list_deploy_keys(self, auth, username, repo_name): """ List deploy keys for the specified repo. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: the name of the repo :return: a list of deploy keys for the repo :rtype: List[GogsRepo.DeployKey] :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ response = self.get("/repos/{u}/{r}/keys".format(u=username, r=repo_name), auth=auth) return [GogsRepo.DeployKey.from_json(key_json) for key_json in response.json()]
[ "def", "list_deploy_keys", "(", "self", ",", "auth", ",", "username", ",", "repo_name", ")", ":", "response", "=", "self", ".", "get", "(", "\"/repos/{u}/{r}/keys\"", ".", "format", "(", "u", "=", "username", ",", "r", "=", "repo_name", ")", ",", "auth",...
List deploy keys for the specified repo. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: the name of the repo :return: a list of deploy keys for the repo :rtype: List[GogsRepo.DeployKey] :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "List", "deploy", "keys", "for", "the", "specified", "repo", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L567-L580
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.get_deploy_key
def get_deploy_key(self, auth, username, repo_name, key_id): """ Get a deploy key for the specified repo. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: the name of the repo :param int key_id: the id of the key :return: the deploy key :rtype: GogsRepo.DeployKey :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ response = self.get("/repos/{u}/{r}/keys/{k}".format(u=username, r=repo_name, k=key_id), auth=auth) return GogsRepo.DeployKey.from_json(response.json())
python
def get_deploy_key(self, auth, username, repo_name, key_id): """ Get a deploy key for the specified repo. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: the name of the repo :param int key_id: the id of the key :return: the deploy key :rtype: GogsRepo.DeployKey :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ response = self.get("/repos/{u}/{r}/keys/{k}".format(u=username, r=repo_name, k=key_id), auth=auth) return GogsRepo.DeployKey.from_json(response.json())
[ "def", "get_deploy_key", "(", "self", ",", "auth", ",", "username", ",", "repo_name", ",", "key_id", ")", ":", "response", "=", "self", ".", "get", "(", "\"/repos/{u}/{r}/keys/{k}\"", ".", "format", "(", "u", "=", "username", ",", "r", "=", "repo_name", ...
Get a deploy key for the specified repo. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: the name of the repo :param int key_id: the id of the key :return: the deploy key :rtype: GogsRepo.DeployKey :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Get", "a", "deploy", "key", "for", "the", "specified", "repo", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L582-L596
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.add_deploy_key
def add_deploy_key(self, auth, username, repo_name, title, key_content): """ Add a deploy key to the specified repo. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: the name of the repo :param str title: title of the key to add :param str key_content: content of the key to add :return: a representation of the added deploy key :rtype: GogsRepo.DeployKey :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ data = { "title": title, "key": key_content } response = self.post("/repos/{u}/{r}/keys".format(u=username, r=repo_name), auth=auth, data=data) return GogsRepo.DeployKey.from_json(response.json())
python
def add_deploy_key(self, auth, username, repo_name, title, key_content): """ Add a deploy key to the specified repo. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: the name of the repo :param str title: title of the key to add :param str key_content: content of the key to add :return: a representation of the added deploy key :rtype: GogsRepo.DeployKey :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ data = { "title": title, "key": key_content } response = self.post("/repos/{u}/{r}/keys".format(u=username, r=repo_name), auth=auth, data=data) return GogsRepo.DeployKey.from_json(response.json())
[ "def", "add_deploy_key", "(", "self", ",", "auth", ",", "username", ",", "repo_name", ",", "title", ",", "key_content", ")", ":", "data", "=", "{", "\"title\"", ":", "title", ",", "\"key\"", ":", "key_content", "}", "response", "=", "self", ".", "post", ...
Add a deploy key to the specified repo. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: the name of the repo :param str title: title of the key to add :param str key_content: content of the key to add :return: a representation of the added deploy key :rtype: GogsRepo.DeployKey :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Add", "a", "deploy", "key", "to", "the", "specified", "repo", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L598-L617
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.delete_deploy_key
def delete_deploy_key(self, auth, username, repo_name, key_id): """ Remove deploy key for the specified repo. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: the name of the repo :param int key_id: the id of the key :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ self.delete("/repos/{u}/{r}/keys/{k}".format(u=username, r=repo_name, k=key_id), auth=auth)
python
def delete_deploy_key(self, auth, username, repo_name, key_id): """ Remove deploy key for the specified repo. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: the name of the repo :param int key_id: the id of the key :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ self.delete("/repos/{u}/{r}/keys/{k}".format(u=username, r=repo_name, k=key_id), auth=auth)
[ "def", "delete_deploy_key", "(", "self", ",", "auth", ",", "username", ",", "repo_name", ",", "key_id", ")", ":", "self", ".", "delete", "(", "\"/repos/{u}/{r}/keys/{k}\"", ".", "format", "(", "u", "=", "username", ",", "r", "=", "repo_name", ",", "k", "...
Remove deploy key for the specified repo. :param auth.Authentication auth: authentication object :param str username: username of owner of repository :param str repo_name: the name of the repo :param int key_id: the id of the key :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Remove", "deploy", "key", "for", "the", "specified", "repo", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L619-L630
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.delete
def delete(self, path, auth=None, **kwargs): """ Manually make a DELETE request. :param str path: relative url of the request (e.g. `/users/username`) :param auth.Authentication auth: authentication object :param kwargs dict: Extra arguments for the request, as supported by the `requests <http://docs.python-requests.org/>`_ library. :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ return self._check_ok(self._delete(path, auth=auth, **kwargs))
python
def delete(self, path, auth=None, **kwargs): """ Manually make a DELETE request. :param str path: relative url of the request (e.g. `/users/username`) :param auth.Authentication auth: authentication object :param kwargs dict: Extra arguments for the request, as supported by the `requests <http://docs.python-requests.org/>`_ library. :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ return self._check_ok(self._delete(path, auth=auth, **kwargs))
[ "def", "delete", "(", "self", ",", "path", ",", "auth", "=", "None", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "_check_ok", "(", "self", ".", "_delete", "(", "path", ",", "auth", "=", "auth", ",", "*", "*", "kwargs", ")", ")" ]
Manually make a DELETE request. :param str path: relative url of the request (e.g. `/users/username`) :param auth.Authentication auth: authentication object :param kwargs dict: Extra arguments for the request, as supported by the `requests <http://docs.python-requests.org/>`_ library. :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Manually", "make", "a", "DELETE", "request", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L642-L653
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.get
def get(self, path, auth=None, **kwargs): """ Manually make a GET request. :param str path: relative url of the request (e.g. `/users/username`) :param auth.Authentication auth: authentication object :param kwargs dict: Extra arguments for the request, as supported by the `requests <http://docs.python-requests.org/>`_ library. :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ return self._check_ok(self._get(path, auth=auth, **kwargs))
python
def get(self, path, auth=None, **kwargs): """ Manually make a GET request. :param str path: relative url of the request (e.g. `/users/username`) :param auth.Authentication auth: authentication object :param kwargs dict: Extra arguments for the request, as supported by the `requests <http://docs.python-requests.org/>`_ library. :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ return self._check_ok(self._get(path, auth=auth, **kwargs))
[ "def", "get", "(", "self", ",", "path", ",", "auth", "=", "None", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "_check_ok", "(", "self", ".", "_get", "(", "path", ",", "auth", "=", "auth", ",", "*", "*", "kwargs", ")", ")" ]
Manually make a GET request. :param str path: relative url of the request (e.g. `/users/username`) :param auth.Authentication auth: authentication object :param kwargs dict: Extra arguments for the request, as supported by the `requests <http://docs.python-requests.org/>`_ library. :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Manually", "make", "a", "GET", "request", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L663-L674
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.patch
def patch(self, path, auth=None, **kwargs): """ Manually make a PATCH request. :param str path: relative url of the request (e.g. `/users/username`) :param auth.Authentication auth: authentication object :param kwargs dict: Extra arguments for the request, as supported by the `requests <http://docs.python-requests.org/>`_ library. :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ return self._check_ok(self._patch(path, auth=auth, **kwargs))
python
def patch(self, path, auth=None, **kwargs): """ Manually make a PATCH request. :param str path: relative url of the request (e.g. `/users/username`) :param auth.Authentication auth: authentication object :param kwargs dict: Extra arguments for the request, as supported by the `requests <http://docs.python-requests.org/>`_ library. :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ return self._check_ok(self._patch(path, auth=auth, **kwargs))
[ "def", "patch", "(", "self", ",", "path", ",", "auth", "=", "None", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "_check_ok", "(", "self", ".", "_patch", "(", "path", ",", "auth", "=", "auth", ",", "*", "*", "kwargs", ")", ")" ]
Manually make a PATCH request. :param str path: relative url of the request (e.g. `/users/username`) :param auth.Authentication auth: authentication object :param kwargs dict: Extra arguments for the request, as supported by the `requests <http://docs.python-requests.org/>`_ library. :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Manually", "make", "a", "PATCH", "request", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L684-L695
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.post
def post(self, path, auth=None, **kwargs): """ Manually make a POST request. :param str path: relative url of the request (e.g. `/users/username`) :param auth.Authentication auth: authentication object :param kwargs dict: Extra arguments for the request, as supported by the `requests <http://docs.python-requests.org/>`_ library. :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ return self._check_ok(self._post(path, auth=auth, **kwargs))
python
def post(self, path, auth=None, **kwargs): """ Manually make a POST request. :param str path: relative url of the request (e.g. `/users/username`) :param auth.Authentication auth: authentication object :param kwargs dict: Extra arguments for the request, as supported by the `requests <http://docs.python-requests.org/>`_ library. :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ return self._check_ok(self._post(path, auth=auth, **kwargs))
[ "def", "post", "(", "self", ",", "path", ",", "auth", "=", "None", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "_check_ok", "(", "self", ".", "_post", "(", "path", ",", "auth", "=", "auth", ",", "*", "*", "kwargs", ")", ")" ]
Manually make a POST request. :param str path: relative url of the request (e.g. `/users/username`) :param auth.Authentication auth: authentication object :param kwargs dict: Extra arguments for the request, as supported by the `requests <http://docs.python-requests.org/>`_ library. :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Manually", "make", "a", "POST", "request", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L705-L716
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi.put
def put(self, path, auth=None, **kwargs): """ Manually make a PUT request. :param str path: relative url of the request (e.g. `/users/username`) :param auth.Authentication auth: authentication object :param kwargs dict: Extra arguments for the request, as supported by the `requests <http://docs.python-requests.org/>`_ library. :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ return self._check_ok(self._put(path, auth=auth, **kwargs))
python
def put(self, path, auth=None, **kwargs): """ Manually make a PUT request. :param str path: relative url of the request (e.g. `/users/username`) :param auth.Authentication auth: authentication object :param kwargs dict: Extra arguments for the request, as supported by the `requests <http://docs.python-requests.org/>`_ library. :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced """ return self._check_ok(self._put(path, auth=auth, **kwargs))
[ "def", "put", "(", "self", ",", "path", ",", "auth", "=", "None", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "_check_ok", "(", "self", ".", "_put", "(", "path", ",", "auth", "=", "auth", ",", "*", "*", "kwargs", ")", ")" ]
Manually make a PUT request. :param str path: relative url of the request (e.g. `/users/username`) :param auth.Authentication auth: authentication object :param kwargs dict: Extra arguments for the request, as supported by the `requests <http://docs.python-requests.org/>`_ library. :raises NetworkFailure: if there is an error communicating with the server :raises ApiFailure: if the request cannot be serviced
[ "Manually", "make", "a", "PUT", "request", "." ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L726-L737
unfoldingWord-dev/python-gogs-client
gogs_client/interface.py
GogsApi._fail
def _fail(response): """ Raise an ApiFailure pertaining to the given response """ message = "Status code: {}-{}, url: {}".format(response.status_code, response.reason, response.url) try: message += ", message:{}".format(response.json()["message"]) except (ValueError, KeyError): pass raise ApiFailure(message, response.status_code)
python
def _fail(response): """ Raise an ApiFailure pertaining to the given response """ message = "Status code: {}-{}, url: {}".format(response.status_code, response.reason, response.url) try: message += ", message:{}".format(response.json()["message"]) except (ValueError, KeyError): pass raise ApiFailure(message, response.status_code)
[ "def", "_fail", "(", "response", ")", ":", "message", "=", "\"Status code: {}-{}, url: {}\"", ".", "format", "(", "response", ".", "status_code", ",", "response", ".", "reason", ",", "response", ".", "url", ")", "try", ":", "message", "+=", "\", message:{}\"",...
Raise an ApiFailure pertaining to the given response
[ "Raise", "an", "ApiFailure", "pertaining", "to", "the", "given", "response" ]
train
https://github.com/unfoldingWord-dev/python-gogs-client/blob/b7f27f4995abf914c0db8a424760f5b27331939d/gogs_client/interface.py#L749-L758
LordGaav/python-chaos
chaos/threading/scheduler.py
Scheduler.setStartAction
def setStartAction(self, action, *args, **kwargs): """ Set a function to call when run() is called, before the main action is called. Parameters ---------- action: function pointer The function to call. *args Positional arguments to pass to action. **kwargs: Keyword arguments to pass to action. """ self.init_action = action self.init_args = args self.init_kwargs = kwargs
python
def setStartAction(self, action, *args, **kwargs): """ Set a function to call when run() is called, before the main action is called. Parameters ---------- action: function pointer The function to call. *args Positional arguments to pass to action. **kwargs: Keyword arguments to pass to action. """ self.init_action = action self.init_args = args self.init_kwargs = kwargs
[ "def", "setStartAction", "(", "self", ",", "action", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "init_action", "=", "action", "self", ".", "init_args", "=", "args", "self", ".", "init_kwargs", "=", "kwargs" ]
Set a function to call when run() is called, before the main action is called. Parameters ---------- action: function pointer The function to call. *args Positional arguments to pass to action. **kwargs: Keyword arguments to pass to action.
[ "Set", "a", "function", "to", "call", "when", "run", "()", "is", "called", "before", "the", "main", "action", "is", "called", "." ]
train
https://github.com/LordGaav/python-chaos/blob/52cd29a6fd15693ee1e53786b93bcb23fbf84ddd/chaos/threading/scheduler.py#L72-L88
LordGaav/python-chaos
chaos/threading/scheduler.py
Scheduler.setStopAction
def setStopAction(self, action, *args, **kwargs): """ Set a function to call when run() is stopping, after the main action is called. Parameters ---------- action: function pointer The function to call. *args Positional arguments to pass to action. **kwargs: Keyword arguments to pass to action. """ self.stop_action = action self.stop_args = args self.stop_kwargs = kwargs
python
def setStopAction(self, action, *args, **kwargs): """ Set a function to call when run() is stopping, after the main action is called. Parameters ---------- action: function pointer The function to call. *args Positional arguments to pass to action. **kwargs: Keyword arguments to pass to action. """ self.stop_action = action self.stop_args = args self.stop_kwargs = kwargs
[ "def", "setStopAction", "(", "self", ",", "action", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "stop_action", "=", "action", "self", ".", "stop_args", "=", "args", "self", ".", "stop_kwargs", "=", "kwargs" ]
Set a function to call when run() is stopping, after the main action is called. Parameters ---------- action: function pointer The function to call. *args Positional arguments to pass to action. **kwargs: Keyword arguments to pass to action.
[ "Set", "a", "function", "to", "call", "when", "run", "()", "is", "stopping", "after", "the", "main", "action", "is", "called", "." ]
train
https://github.com/LordGaav/python-chaos/blob/52cd29a6fd15693ee1e53786b93bcb23fbf84ddd/chaos/threading/scheduler.py#L90-L105
LordGaav/python-chaos
chaos/threading/scheduler.py
Scheduler.run
def run(self): """ Calls the defined action every $interval seconds. Optionally calls an action before the main loop, and an action when stopping, if these are defined. Exceptions in the main loop will NOT cause the thread to die. """ self.logger.debug("Thread {0} is entering main loop".format(self.name)) if hasattr(self, "init_action"): self.logger.debug("Thread {0} is calling its init action") self.init_action(*self.init_args, **self.init_kwargs) while not self.stop: self.logger.debug("Delay is {0}".format(self.delay)) if (datetime.datetime.now() - self.lastRun).total_seconds() > self.delay: self.logger.debug("Thread {0} is running".format(self.name)) try: self.main_action(*self.main_args, **self.main_kwargs) except Exception: self.logger.exception("Thread {0} generated an exception!".format(self.name)) self.lastRun = datetime.datetime.now() self.logger.debug("Thread {0} is done".format(self.name)) time.sleep(1) if hasattr(self, "stop_action"): self.logger.debug("Thread {0} is calling its stop action") self.stop_action(*self.stop_args, **self.stop_kwargs) self.logger.debug("Thread {0} is exiting main loop".format(self.name))
python
def run(self): """ Calls the defined action every $interval seconds. Optionally calls an action before the main loop, and an action when stopping, if these are defined. Exceptions in the main loop will NOT cause the thread to die. """ self.logger.debug("Thread {0} is entering main loop".format(self.name)) if hasattr(self, "init_action"): self.logger.debug("Thread {0} is calling its init action") self.init_action(*self.init_args, **self.init_kwargs) while not self.stop: self.logger.debug("Delay is {0}".format(self.delay)) if (datetime.datetime.now() - self.lastRun).total_seconds() > self.delay: self.logger.debug("Thread {0} is running".format(self.name)) try: self.main_action(*self.main_args, **self.main_kwargs) except Exception: self.logger.exception("Thread {0} generated an exception!".format(self.name)) self.lastRun = datetime.datetime.now() self.logger.debug("Thread {0} is done".format(self.name)) time.sleep(1) if hasattr(self, "stop_action"): self.logger.debug("Thread {0} is calling its stop action") self.stop_action(*self.stop_args, **self.stop_kwargs) self.logger.debug("Thread {0} is exiting main loop".format(self.name))
[ "def", "run", "(", "self", ")", ":", "self", ".", "logger", ".", "debug", "(", "\"Thread {0} is entering main loop\"", ".", "format", "(", "self", ".", "name", ")", ")", "if", "hasattr", "(", "self", ",", "\"init_action\"", ")", ":", "self", ".", "logger...
Calls the defined action every $interval seconds. Optionally calls an action before the main loop, and an action when stopping, if these are defined. Exceptions in the main loop will NOT cause the thread to die.
[ "Calls", "the", "defined", "action", "every", "$interval", "seconds", ".", "Optionally", "calls", "an", "action", "before", "the", "main", "loop", "and", "an", "action", "when", "stopping", "if", "these", "are", "defined", "." ]
train
https://github.com/LordGaav/python-chaos/blob/52cd29a6fd15693ee1e53786b93bcb23fbf84ddd/chaos/threading/scheduler.py#L107-L137
peterldowns/lggr
lggr/__init__.py
Printer
def Printer(open_file=sys.stdout, closing=False): """ Prints items with a timestamp. """ try: while True: logstr = (yield) open_file.write(logstr) open_file.write('\n') # new line except GeneratorExit: if closing: try: open_file.close() except: pass
python
def Printer(open_file=sys.stdout, closing=False): """ Prints items with a timestamp. """ try: while True: logstr = (yield) open_file.write(logstr) open_file.write('\n') # new line except GeneratorExit: if closing: try: open_file.close() except: pass
[ "def", "Printer", "(", "open_file", "=", "sys", ".", "stdout", ",", "closing", "=", "False", ")", ":", "try", ":", "while", "True", ":", "logstr", "=", "(", "yield", ")", "open_file", ".", "write", "(", "logstr", ")", "open_file", ".", "write", "(", ...
Prints items with a timestamp.
[ "Prints", "items", "with", "a", "timestamp", "." ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L322-L332
peterldowns/lggr
lggr/__init__.py
FilePrinter
def FilePrinter(filename, mode='a', closing=True): path = os.path.abspath(os.path.expanduser(filename)) """ Opens the given file and returns a printer to it. """ f = open(path, mode) return Printer(f, closing)
python
def FilePrinter(filename, mode='a', closing=True): path = os.path.abspath(os.path.expanduser(filename)) """ Opens the given file and returns a printer to it. """ f = open(path, mode) return Printer(f, closing)
[ "def", "FilePrinter", "(", "filename", ",", "mode", "=", "'a'", ",", "closing", "=", "True", ")", ":", "path", "=", "os", ".", "path", ".", "abspath", "(", "os", ".", "path", ".", "expanduser", "(", "filename", ")", ")", "f", "=", "open", "(", "p...
Opens the given file and returns a printer to it.
[ "Opens", "the", "given", "file", "and", "returns", "a", "printer", "to", "it", "." ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L338-L342
peterldowns/lggr
lggr/__init__.py
SocketWriter
def SocketWriter(host, port, af=None, st=None): """ Writes messages to a socket/host. """ import socket if af is None: af = socket.AF_INET if st is None: st = socket.SOCK_STREAM message = '({0}): {1}' s = socket.socket(af, st) s.connect(host, port) try: while True: logstr = (yield) s.send(logstr) except GeneratorExit: s.close()
python
def SocketWriter(host, port, af=None, st=None): """ Writes messages to a socket/host. """ import socket if af is None: af = socket.AF_INET if st is None: st = socket.SOCK_STREAM message = '({0}): {1}' s = socket.socket(af, st) s.connect(host, port) try: while True: logstr = (yield) s.send(logstr) except GeneratorExit: s.close()
[ "def", "SocketWriter", "(", "host", ",", "port", ",", "af", "=", "None", ",", "st", "=", "None", ")", ":", "import", "socket", "if", "af", "is", "None", ":", "af", "=", "socket", ".", "AF_INET", "if", "st", "is", "None", ":", "st", "=", "socket",...
Writes messages to a socket/host.
[ "Writes", "messages", "to", "a", "socket", "/", "host", "." ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L345-L360
peterldowns/lggr
lggr/__init__.py
Emailer
def Emailer(recipients, sender=None): """ Sends messages as emails to the given list of recipients. """ import smtplib hostname = socket.gethostname() if not sender: sender = 'lggr@{0}'.format(hostname) smtp = smtplib.SMTP('localhost') try: while True: logstr = (yield) try: smtp.sendmail(sender, recipients, logstr) except smtplib.SMTPException: pass except GeneratorExit: smtp.quit()
python
def Emailer(recipients, sender=None): """ Sends messages as emails to the given list of recipients. """ import smtplib hostname = socket.gethostname() if not sender: sender = 'lggr@{0}'.format(hostname) smtp = smtplib.SMTP('localhost') try: while True: logstr = (yield) try: smtp.sendmail(sender, recipients, logstr) except smtplib.SMTPException: pass except GeneratorExit: smtp.quit()
[ "def", "Emailer", "(", "recipients", ",", "sender", "=", "None", ")", ":", "import", "smtplib", "hostname", "=", "socket", ".", "gethostname", "(", ")", "if", "not", "sender", ":", "sender", "=", "'lggr@{0}'", ".", "format", "(", "hostname", ")", "smtp",...
Sends messages as emails to the given list of recipients.
[ "Sends", "messages", "as", "emails", "to", "the", "given", "list", "of", "recipients", "." ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L363-L379
peterldowns/lggr
lggr/__init__.py
GMailer
def GMailer(recipients, username, password, subject='Log message from lggr.py'): """ Sends messages as emails to the given list of recipients, from a GMail account. """ import smtplib srvr = smtplib.SMTP('smtp.gmail.com', 587) srvr.ehlo() srvr.starttls() srvr.ehlo() srvr.login(username, password) if not (isinstance(recipients, list) or isinstance(recipients, tuple)): recipients = [recipients] gmail_sender = '{0}@gmail.com'.format(username) msg = 'To: {0}\nFrom: '+gmail_sender+'\nSubject: '+subject+'\n' msg = msg + '\n{1}\n\n' try: while True: logstr = (yield) for rcp in recipients: message = msg.format(rcp, logstr) srvr.sendmail(gmail_sender, rcp, message) except GeneratorExit: srvr.quit()
python
def GMailer(recipients, username, password, subject='Log message from lggr.py'): """ Sends messages as emails to the given list of recipients, from a GMail account. """ import smtplib srvr = smtplib.SMTP('smtp.gmail.com', 587) srvr.ehlo() srvr.starttls() srvr.ehlo() srvr.login(username, password) if not (isinstance(recipients, list) or isinstance(recipients, tuple)): recipients = [recipients] gmail_sender = '{0}@gmail.com'.format(username) msg = 'To: {0}\nFrom: '+gmail_sender+'\nSubject: '+subject+'\n' msg = msg + '\n{1}\n\n' try: while True: logstr = (yield) for rcp in recipients: message = msg.format(rcp, logstr) srvr.sendmail(gmail_sender, rcp, message) except GeneratorExit: srvr.quit()
[ "def", "GMailer", "(", "recipients", ",", "username", ",", "password", ",", "subject", "=", "'Log message from lggr.py'", ")", ":", "import", "smtplib", "srvr", "=", "smtplib", ".", "SMTP", "(", "'smtp.gmail.com'", ",", "587", ")", "srvr", ".", "ehlo", "(", ...
Sends messages as emails to the given list of recipients, from a GMail account.
[ "Sends", "messages", "as", "emails", "to", "the", "given", "list", "of", "recipients", "from", "a", "GMail", "account", "." ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L382-L407
peterldowns/lggr
lggr/__init__.py
Lggr.add
def add(self, levels, logger): """ Given a list or tuple of logging levels, add a logger instance to each. """ if isinstance(levels, (list, tuple)): for lvl in levels: self.config[lvl].add(logger) else: self.config[levels].add(logger)
python
def add(self, levels, logger): """ Given a list or tuple of logging levels, add a logger instance to each. """ if isinstance(levels, (list, tuple)): for lvl in levels: self.config[lvl].add(logger) else: self.config[levels].add(logger)
[ "def", "add", "(", "self", ",", "levels", ",", "logger", ")", ":", "if", "isinstance", "(", "levels", ",", "(", "list", ",", "tuple", ")", ")", ":", "for", "lvl", "in", "levels", ":", "self", ".", "config", "[", "lvl", "]", ".", "add", "(", "lo...
Given a list or tuple of logging levels, add a logger instance to each.
[ "Given", "a", "list", "or", "tuple", "of", "logging", "levels", "add", "a", "logger", "instance", "to", "each", "." ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L84-L91
peterldowns/lggr
lggr/__init__.py
Lggr.remove
def remove(self, level, logger): """ Given a level, remove a given logger function if it is a member of that level, closing the logger function either way.""" self.config[level].discard(logger) logger.close()
python
def remove(self, level, logger): """ Given a level, remove a given logger function if it is a member of that level, closing the logger function either way.""" self.config[level].discard(logger) logger.close()
[ "def", "remove", "(", "self", ",", "level", ",", "logger", ")", ":", "self", ".", "config", "[", "level", "]", ".", "discard", "(", "logger", ")", "logger", ".", "close", "(", ")" ]
Given a level, remove a given logger function if it is a member of that level, closing the logger function either way.
[ "Given", "a", "level", "remove", "a", "given", "logger", "function", "if", "it", "is", "a", "member", "of", "that", "level", "closing", "the", "logger", "function", "either", "way", "." ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L93-L98
peterldowns/lggr
lggr/__init__.py
Lggr.clear
def clear(self, level): """ Remove all logger functions from a given level. """ for item in self.config[level]: item.close() self.config[level].clear()
python
def clear(self, level): """ Remove all logger functions from a given level. """ for item in self.config[level]: item.close() self.config[level].clear()
[ "def", "clear", "(", "self", ",", "level", ")", ":", "for", "item", "in", "self", ".", "config", "[", "level", "]", ":", "item", ".", "close", "(", ")", "self", ".", "config", "[", "level", "]", ".", "clear", "(", ")" ]
Remove all logger functions from a given level.
[ "Remove", "all", "logger", "functions", "from", "a", "given", "level", "." ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L100-L104
peterldowns/lggr
lggr/__init__.py
Lggr._make_record
def _make_record(self, level, fmt, args, extra, exc_info, inc_stackinfo, inc_multiproc): """ Create a 'record' (a dictionary) with information to be logged. """ fn = fname = '(unknown file)' lno = 0 func = '(unknown function)' code = '(code not available)' cc = [] sinfo = None module = '(unknown module)' if _srcfile and inc_stackinfo: #IronPython doesn't track Python frames, so _find_caller throws an #exception on some versionf of IronPython. We trap it here so that #IronPython can use logging. try: fn, lno, func, code, cc, sinfo = self._find_caller() fname = os.path.basename(fn) module = os.path.splitext(fname)[0] except ValueError: pass if not exc_info or not isinstance(exc_info, tuple): # Allow passed in exc_info, but supply it if it isn't exc_info = sys.exc_info() log_record = { # This is available information for logging functions. #TODO: proc_name, thread_name # see http://hg.python.org/cpython/file/74fa415dc715/Lib/logging/__init__.py#l279 'asctime': time.asctime(), # TODO: actual specifier for format 'code': code, 'codecontext': ''.join(cc), 'excinfo' : exc_info, 'filename' : fname, 'funcname' : func, 'levelname' : level, 'levelno' : ALL.index(level), 'lineno' : lno, 'logmessage' : None, 'messagefmt' : fmt, 'module' : module, 'pathname' : fn, 'process' : os.getpid(), 'processname' : None, 'stackinfo' : sinfo, 'threadid' : None, 'threadname' : None, 'time' : time.time(), # The custom `extra` information can only be used to format the # default format. The `logmessage` can only be passed a dictionary # or a list (as `args`). 'defaultfmt' : self.config['defaultfmt'] } # If the user passed a single dict, use that with format. If we're # passed a tuple or list, dereference its contents as args to format, # too. Otherwise, leave the log message as None. if args: if (isinstance(args, (tuple, list)) and len(args) == 1 and isinstance(args[0], dict)): log_record['logmessage'] = fmt.format(**args[0]) else: log_record['logmessage'] = fmt.format(*args) else: log_record['logmessage'] = fmt if extra: log_record.update(extra) # add custom variables to record if threading: # check to use threading curthread = threading.current_thread() log_record.update({ 'threadid' : curthread.ident, 'threadname' : curthread.name }) if not inc_multiproc: # check to use multiprocessing procname = None else: procname = 'MainProcess' if mp: try: procname = mp.curent_process().name except StandardError: pass log_record['processname'] = procname return log_record
python
def _make_record(self, level, fmt, args, extra, exc_info, inc_stackinfo, inc_multiproc): """ Create a 'record' (a dictionary) with information to be logged. """ fn = fname = '(unknown file)' lno = 0 func = '(unknown function)' code = '(code not available)' cc = [] sinfo = None module = '(unknown module)' if _srcfile and inc_stackinfo: #IronPython doesn't track Python frames, so _find_caller throws an #exception on some versionf of IronPython. We trap it here so that #IronPython can use logging. try: fn, lno, func, code, cc, sinfo = self._find_caller() fname = os.path.basename(fn) module = os.path.splitext(fname)[0] except ValueError: pass if not exc_info or not isinstance(exc_info, tuple): # Allow passed in exc_info, but supply it if it isn't exc_info = sys.exc_info() log_record = { # This is available information for logging functions. #TODO: proc_name, thread_name # see http://hg.python.org/cpython/file/74fa415dc715/Lib/logging/__init__.py#l279 'asctime': time.asctime(), # TODO: actual specifier for format 'code': code, 'codecontext': ''.join(cc), 'excinfo' : exc_info, 'filename' : fname, 'funcname' : func, 'levelname' : level, 'levelno' : ALL.index(level), 'lineno' : lno, 'logmessage' : None, 'messagefmt' : fmt, 'module' : module, 'pathname' : fn, 'process' : os.getpid(), 'processname' : None, 'stackinfo' : sinfo, 'threadid' : None, 'threadname' : None, 'time' : time.time(), # The custom `extra` information can only be used to format the # default format. The `logmessage` can only be passed a dictionary # or a list (as `args`). 'defaultfmt' : self.config['defaultfmt'] } # If the user passed a single dict, use that with format. If we're # passed a tuple or list, dereference its contents as args to format, # too. Otherwise, leave the log message as None. if args: if (isinstance(args, (tuple, list)) and len(args) == 1 and isinstance(args[0], dict)): log_record['logmessage'] = fmt.format(**args[0]) else: log_record['logmessage'] = fmt.format(*args) else: log_record['logmessage'] = fmt if extra: log_record.update(extra) # add custom variables to record if threading: # check to use threading curthread = threading.current_thread() log_record.update({ 'threadid' : curthread.ident, 'threadname' : curthread.name }) if not inc_multiproc: # check to use multiprocessing procname = None else: procname = 'MainProcess' if mp: try: procname = mp.curent_process().name except StandardError: pass log_record['processname'] = procname return log_record
[ "def", "_make_record", "(", "self", ",", "level", ",", "fmt", ",", "args", ",", "extra", ",", "exc_info", ",", "inc_stackinfo", ",", "inc_multiproc", ")", ":", "fn", "=", "fname", "=", "'(unknown file)'", "lno", "=", "0", "func", "=", "'(unknown function)'...
Create a 'record' (a dictionary) with information to be logged.
[ "Create", "a", "record", "(", "a", "dictionary", ")", "with", "information", "to", "be", "logged", "." ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L106-L199
peterldowns/lggr
lggr/__init__.py
Lggr._log
def _log(self, level, fmt, args=None, extra=None, exc_info=None, inc_stackinfo=False, inc_multiproc=False): """ Send a log message to all of the logging functions for a given level as well as adding the message to this logger instance's history. """ if not self.enabled: return # Fail silently so that logging can easily be removed log_record = self._make_record( level, fmt, args, extra, exc_info, inc_stackinfo, inc_multiproc) logstr = log_record['defaultfmt'].format(**log_record) #whoah. if self.keep_history: self.history.append(logstr) log_funcs = self.config[level] to_remove = [] for lf in log_funcs: try: lf.send(logstr) except StopIteration: # in the case that the log function is already closed, add it # to the list of functions to be deleted. to_remove.append(lf) for lf in to_remove: self.remove(level, lf) self.info('Logging function {} removed from level {}', lf, level)
python
def _log(self, level, fmt, args=None, extra=None, exc_info=None, inc_stackinfo=False, inc_multiproc=False): """ Send a log message to all of the logging functions for a given level as well as adding the message to this logger instance's history. """ if not self.enabled: return # Fail silently so that logging can easily be removed log_record = self._make_record( level, fmt, args, extra, exc_info, inc_stackinfo, inc_multiproc) logstr = log_record['defaultfmt'].format(**log_record) #whoah. if self.keep_history: self.history.append(logstr) log_funcs = self.config[level] to_remove = [] for lf in log_funcs: try: lf.send(logstr) except StopIteration: # in the case that the log function is already closed, add it # to the list of functions to be deleted. to_remove.append(lf) for lf in to_remove: self.remove(level, lf) self.info('Logging function {} removed from level {}', lf, level)
[ "def", "_log", "(", "self", ",", "level", ",", "fmt", ",", "args", "=", "None", ",", "extra", "=", "None", ",", "exc_info", "=", "None", ",", "inc_stackinfo", "=", "False", ",", "inc_multiproc", "=", "False", ")", ":", "if", "not", "self", ".", "en...
Send a log message to all of the logging functions for a given level as well as adding the message to this logger instance's history.
[ "Send", "a", "log", "message", "to", "all", "of", "the", "logging", "functions", "for", "a", "given", "level", "as", "well", "as", "adding", "the", "message", "to", "this", "logger", "instance", "s", "history", "." ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L201-L234
peterldowns/lggr
lggr/__init__.py
Lggr.log
def log(self, *args, **kwargs): """ Do logging, but handle error suppression. """ if self.suppress_errors: try: self._log(*args, **kwargs) return True except: return False else: self._log(*args, **kwargs) return True
python
def log(self, *args, **kwargs): """ Do logging, but handle error suppression. """ if self.suppress_errors: try: self._log(*args, **kwargs) return True except: return False else: self._log(*args, **kwargs) return True
[ "def", "log", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "suppress_errors", ":", "try", ":", "self", ".", "_log", "(", "*", "args", ",", "*", "*", "kwargs", ")", "return", "True", "except", ":", "return",...
Do logging, but handle error suppression.
[ "Do", "logging", "but", "handle", "error", "suppression", "." ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L236-L246
peterldowns/lggr
lggr/__init__.py
Lggr.debug
def debug(self, msg, *args, **kwargs): """ Log a message with DEBUG level. Automatically includes stack info unless it is specifically not included. """ kwargs.setdefault('inc_stackinfo', True) self.log(DEBUG, msg, args, **kwargs)
python
def debug(self, msg, *args, **kwargs): """ Log a message with DEBUG level. Automatically includes stack info unless it is specifically not included. """ kwargs.setdefault('inc_stackinfo', True) self.log(DEBUG, msg, args, **kwargs)
[ "def", "debug", "(", "self", ",", "msg", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "kwargs", ".", "setdefault", "(", "'inc_stackinfo'", ",", "True", ")", "self", ".", "log", "(", "DEBUG", ",", "msg", ",", "args", ",", "*", "*", "kwargs...
Log a message with DEBUG level. Automatically includes stack info unless it is specifically not included.
[ "Log", "a", "message", "with", "DEBUG", "level", ".", "Automatically", "includes", "stack", "info", "unless", "it", "is", "specifically", "not", "included", "." ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L257-L261
peterldowns/lggr
lggr/__init__.py
Lggr.error
def error(self, msg, *args, **kwargs): """ Log a message with ERROR level. Automatically includes stack and process info unless they are specifically not included. """ kwargs.setdefault('inc_stackinfo', True) kwargs.setdefault('inc_multiproc', True) self.log(ERROR, msg, args, **kwargs)
python
def error(self, msg, *args, **kwargs): """ Log a message with ERROR level. Automatically includes stack and process info unless they are specifically not included. """ kwargs.setdefault('inc_stackinfo', True) kwargs.setdefault('inc_multiproc', True) self.log(ERROR, msg, args, **kwargs)
[ "def", "error", "(", "self", ",", "msg", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "kwargs", ".", "setdefault", "(", "'inc_stackinfo'", ",", "True", ")", "kwargs", ".", "setdefault", "(", "'inc_multiproc'", ",", "True", ")", "self", ".", "...
Log a message with ERROR level. Automatically includes stack and process info unless they are specifically not included.
[ "Log", "a", "message", "with", "ERROR", "level", ".", "Automatically", "includes", "stack", "and", "process", "info", "unless", "they", "are", "specifically", "not", "included", "." ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L263-L268
peterldowns/lggr
lggr/__init__.py
Lggr.critical
def critical(self, msg, *args, **kwargs): """ Log a message with CRITICAL level. Automatically includes stack and process info unless they are specifically not included. """ kwargs.setdefault('inc_stackinfo', True) kwargs.setdefault('inc_multiproc', True) self.log(CRITICAL, msg, args, **kwargs)
python
def critical(self, msg, *args, **kwargs): """ Log a message with CRITICAL level. Automatically includes stack and process info unless they are specifically not included. """ kwargs.setdefault('inc_stackinfo', True) kwargs.setdefault('inc_multiproc', True) self.log(CRITICAL, msg, args, **kwargs)
[ "def", "critical", "(", "self", ",", "msg", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "kwargs", ".", "setdefault", "(", "'inc_stackinfo'", ",", "True", ")", "kwargs", ".", "setdefault", "(", "'inc_multiproc'", ",", "True", ")", "self", ".", ...
Log a message with CRITICAL level. Automatically includes stack and process info unless they are specifically not included.
[ "Log", "a", "message", "with", "CRITICAL", "level", ".", "Automatically", "includes", "stack", "and", "process", "info", "unless", "they", "are", "specifically", "not", "included", "." ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L270-L275
peterldowns/lggr
lggr/__init__.py
Lggr.multi
def multi(self, lvl_list, msg, *args, **kwargs): """ Log a message at multiple levels""" for level in lvl_list: self.log(level, msg, args, **kwargs)
python
def multi(self, lvl_list, msg, *args, **kwargs): """ Log a message at multiple levels""" for level in lvl_list: self.log(level, msg, args, **kwargs)
[ "def", "multi", "(", "self", ",", "lvl_list", ",", "msg", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "for", "level", "in", "lvl_list", ":", "self", ".", "log", "(", "level", ",", "msg", ",", "args", ",", "*", "*", "kwargs", ")" ]
Log a message at multiple levels
[ "Log", "a", "message", "at", "multiple", "levels" ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L277-L280
peterldowns/lggr
lggr/__init__.py
Lggr.all
def all(self, msg, *args, **kwargs): """ Log a message at every known log level """ self.multi(ALL, msg, args, **kwargs)
python
def all(self, msg, *args, **kwargs): """ Log a message at every known log level """ self.multi(ALL, msg, args, **kwargs)
[ "def", "all", "(", "self", ",", "msg", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "multi", "(", "ALL", ",", "msg", ",", "args", ",", "*", "*", "kwargs", ")" ]
Log a message at every known log level
[ "Log", "a", "message", "at", "every", "known", "log", "level" ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L282-L284
peterldowns/lggr
lggr/__init__.py
Lggr._find_caller
def _find_caller(self): """ Find the stack frame of the caller so that we can note the source file name, line number, and function name. """ rv = ('(unknown file)', 0, '(unknown function)', '(code not available)', [], None) f = inspect.currentframe() while hasattr(f, 'f_code'): co = f.f_code filename = os.path.normcase(co.co_filename) # When lggr is imported as a module, the `_src_file` filename ends # in '.pyc', while the filename grabbed from inspect will end in # '.py'. We use splitext here to compare absolute paths without the # extension, which restores the intended behavior of dropping down # the callstack until we reach the first file not part of this # library. if os.path.splitext(filename)[0] == os.path.splitext(_srcfile)[0]: f = f.f_back # get out of this logging file continue sinfo = traceback.extract_stack(f) fname, lno, fnc, cc, i = inspect.getframeinfo(f, context=10) # Mark the calling line with a > cc = map(lambda info: ('> ' if info[0] == i else '| ') + info[1], enumerate(cc)) code = '>' + cc[i] rv = (fname, lno, fnc, code, cc, sinfo) break return rv
python
def _find_caller(self): """ Find the stack frame of the caller so that we can note the source file name, line number, and function name. """ rv = ('(unknown file)', 0, '(unknown function)', '(code not available)', [], None) f = inspect.currentframe() while hasattr(f, 'f_code'): co = f.f_code filename = os.path.normcase(co.co_filename) # When lggr is imported as a module, the `_src_file` filename ends # in '.pyc', while the filename grabbed from inspect will end in # '.py'. We use splitext here to compare absolute paths without the # extension, which restores the intended behavior of dropping down # the callstack until we reach the first file not part of this # library. if os.path.splitext(filename)[0] == os.path.splitext(_srcfile)[0]: f = f.f_back # get out of this logging file continue sinfo = traceback.extract_stack(f) fname, lno, fnc, cc, i = inspect.getframeinfo(f, context=10) # Mark the calling line with a > cc = map(lambda info: ('> ' if info[0] == i else '| ') + info[1], enumerate(cc)) code = '>' + cc[i] rv = (fname, lno, fnc, code, cc, sinfo) break return rv
[ "def", "_find_caller", "(", "self", ")", ":", "rv", "=", "(", "'(unknown file)'", ",", "0", ",", "'(unknown function)'", ",", "'(code not available)'", ",", "[", "]", ",", "None", ")", "f", "=", "inspect", ".", "currentframe", "(", ")", "while", "hasattr",...
Find the stack frame of the caller so that we can note the source file name, line number, and function name.
[ "Find", "the", "stack", "frame", "of", "the", "caller", "so", "that", "we", "can", "note", "the", "source", "file", "name", "line", "number", "and", "function", "name", "." ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/__init__.py#L286-L319
jakewins/neo4jdb-python
neo4j/cursor.py
Cursor._map_value
def _map_value(self, value): ''' Maps a raw deserialized row to proper types ''' # TODO: Once we've gotten here, we've done the following: # -> Recieve the full response, copy it from network buffer it into a ByteBuffer (copy 1) # -> Copy all the data into a String (copy 2) # -> Deserialize that string (copy 3) # -> Map the deserialized JSON to our response format (copy 4, what we are doing in this method) # This should not bee needed. Technically, this mapping from transport format to python types should require exactly one copy, # from the network buffer into the python VM. if isinstance(value, list): out = [] for c in value: out.append(self._map_value( c )) return out elif isinstance(value, dict) and 'metadata' in value and 'labels' in value['metadata'] and 'self' in value: return neo4j.Node(ustr(value['metadata']['id']), value['metadata']['labels'], value['data']) elif isinstance(value, dict) and 'metadata' in value and 'type' in value and 'self' in value: return neo4j.Relationship(ustr(value['metadata']['id']), value['type'], value['start'].split('/')[-1], value['end'].split('/')[-1], value['data']) elif isinstance(value, dict): out = {} for k,v in value.items(): out[k] = self._map_value( v ) return out elif isinstance(value, str): return ustr(value) else: return value
python
def _map_value(self, value): ''' Maps a raw deserialized row to proper types ''' # TODO: Once we've gotten here, we've done the following: # -> Recieve the full response, copy it from network buffer it into a ByteBuffer (copy 1) # -> Copy all the data into a String (copy 2) # -> Deserialize that string (copy 3) # -> Map the deserialized JSON to our response format (copy 4, what we are doing in this method) # This should not bee needed. Technically, this mapping from transport format to python types should require exactly one copy, # from the network buffer into the python VM. if isinstance(value, list): out = [] for c in value: out.append(self._map_value( c )) return out elif isinstance(value, dict) and 'metadata' in value and 'labels' in value['metadata'] and 'self' in value: return neo4j.Node(ustr(value['metadata']['id']), value['metadata']['labels'], value['data']) elif isinstance(value, dict) and 'metadata' in value and 'type' in value and 'self' in value: return neo4j.Relationship(ustr(value['metadata']['id']), value['type'], value['start'].split('/')[-1], value['end'].split('/')[-1], value['data']) elif isinstance(value, dict): out = {} for k,v in value.items(): out[k] = self._map_value( v ) return out elif isinstance(value, str): return ustr(value) else: return value
[ "def", "_map_value", "(", "self", ",", "value", ")", ":", "# TODO: Once we've gotten here, we've done the following:", "# -> Recieve the full response, copy it from network buffer it into a ByteBuffer (copy 1)", "# -> Copy all the data into a String (copy 2)", "# -> Deserialize that string (co...
Maps a raw deserialized row to proper types
[ "Maps", "a", "raw", "deserialized", "row", "to", "proper", "types" ]
train
https://github.com/jakewins/neo4jdb-python/blob/cd78cb8397885f219500fb1080d301f0c900f7be/neo4j/cursor.py#L123-L149
jeremymcrae/denovonear
denovonear/load_gene.py
get_deprecated_gene_ids
def get_deprecated_gene_ids(filename): """ gets a dict of the gene IDs used during in DDD datasets that have been deprecated in favour of other gene IDs """ deprecated = {} with open(filename) as handle: for line in handle: line = line.strip().split() old = line[0] new = line[1] deprecated[old] = new return deprecated
python
def get_deprecated_gene_ids(filename): """ gets a dict of the gene IDs used during in DDD datasets that have been deprecated in favour of other gene IDs """ deprecated = {} with open(filename) as handle: for line in handle: line = line.strip().split() old = line[0] new = line[1] deprecated[old] = new return deprecated
[ "def", "get_deprecated_gene_ids", "(", "filename", ")", ":", "deprecated", "=", "{", "}", "with", "open", "(", "filename", ")", "as", "handle", ":", "for", "line", "in", "handle", ":", "line", "=", "line", ".", "strip", "(", ")", ".", "split", "(", "...
gets a dict of the gene IDs used during in DDD datasets that have been deprecated in favour of other gene IDs
[ "gets", "a", "dict", "of", "the", "gene", "IDs", "used", "during", "in", "DDD", "datasets", "that", "have", "been", "deprecated", "in", "favour", "of", "other", "gene", "IDs" ]
train
https://github.com/jeremymcrae/denovonear/blob/feaab0fc77e89d70b31e8092899e4f0e68bac9fe/denovonear/load_gene.py#L7-L20
jeremymcrae/denovonear
denovonear/load_gene.py
get_transcript_lengths
def get_transcript_lengths(ensembl, transcript_ids): """ finds the protein length for ensembl transcript IDs for a gene Args: ensembl: EnsemblRequest object to request sequences and data from the ensembl REST API transcript_ids: list of transcript IDs for a single gene Returns: dictionary of lengths (in amino acids), indexed by transcript IDs """ transcripts = {} for transcript_id in transcript_ids: # get the transcript's protein sequence via the ensembl REST API try: seq = ensembl.get_protein_seq_for_transcript(transcript_id) except ValueError: continue transcripts[transcript_id] = len(seq) return transcripts
python
def get_transcript_lengths(ensembl, transcript_ids): """ finds the protein length for ensembl transcript IDs for a gene Args: ensembl: EnsemblRequest object to request sequences and data from the ensembl REST API transcript_ids: list of transcript IDs for a single gene Returns: dictionary of lengths (in amino acids), indexed by transcript IDs """ transcripts = {} for transcript_id in transcript_ids: # get the transcript's protein sequence via the ensembl REST API try: seq = ensembl.get_protein_seq_for_transcript(transcript_id) except ValueError: continue transcripts[transcript_id] = len(seq) return transcripts
[ "def", "get_transcript_lengths", "(", "ensembl", ",", "transcript_ids", ")", ":", "transcripts", "=", "{", "}", "for", "transcript_id", "in", "transcript_ids", ":", "# get the transcript's protein sequence via the ensembl REST API", "try", ":", "seq", "=", "ensembl", "....
finds the protein length for ensembl transcript IDs for a gene Args: ensembl: EnsemblRequest object to request sequences and data from the ensembl REST API transcript_ids: list of transcript IDs for a single gene Returns: dictionary of lengths (in amino acids), indexed by transcript IDs
[ "finds", "the", "protein", "length", "for", "ensembl", "transcript", "IDs", "for", "a", "gene", "Args", ":", "ensembl", ":", "EnsemblRequest", "object", "to", "request", "sequences", "and", "data", "from", "the", "ensembl", "REST", "API", "transcript_ids", ":"...
train
https://github.com/jeremymcrae/denovonear/blob/feaab0fc77e89d70b31e8092899e4f0e68bac9fe/denovonear/load_gene.py#L22-L44
jeremymcrae/denovonear
denovonear/load_gene.py
construct_gene_object
def construct_gene_object(ensembl, transcript_id): """ creates an Transcript object for a gene from ensembl databases Args: ensembl: EnsemblRequest object to request data from ensembl transcript_id: string for an Ensembl transcript ID Returns: a Transcript object, containing transcript coordinates and gene and transcript sequence. Raises: ValueError if CDS from genomic sequence given gene coordinates and CDS retrieved from Ensembl do not match. """ # get the sequence for the identified transcript (chrom, start, end, strand, genomic_sequence) = ensembl.get_genomic_seq_for_transcript(transcript_id, expand=10) cds_sequence = ensembl.get_cds_seq_for_transcript(transcript_id) # get the locations of the exons and cds from ensembl cds_ranges = ensembl.get_cds_ranges_for_transcript(transcript_id) exon_ranges = ensembl.get_exon_ranges_for_transcript(transcript_id) # start a Transcript object with the locations and sequence transcript = Transcript(transcript_id, chrom, start, end, strand) transcript.set_exons(exon_ranges, cds_ranges) transcript.set_cds(cds_ranges) transcript.add_cds_sequence(cds_sequence) transcript.add_genomic_sequence(genomic_sequence, offset=10) return transcript
python
def construct_gene_object(ensembl, transcript_id): """ creates an Transcript object for a gene from ensembl databases Args: ensembl: EnsemblRequest object to request data from ensembl transcript_id: string for an Ensembl transcript ID Returns: a Transcript object, containing transcript coordinates and gene and transcript sequence. Raises: ValueError if CDS from genomic sequence given gene coordinates and CDS retrieved from Ensembl do not match. """ # get the sequence for the identified transcript (chrom, start, end, strand, genomic_sequence) = ensembl.get_genomic_seq_for_transcript(transcript_id, expand=10) cds_sequence = ensembl.get_cds_seq_for_transcript(transcript_id) # get the locations of the exons and cds from ensembl cds_ranges = ensembl.get_cds_ranges_for_transcript(transcript_id) exon_ranges = ensembl.get_exon_ranges_for_transcript(transcript_id) # start a Transcript object with the locations and sequence transcript = Transcript(transcript_id, chrom, start, end, strand) transcript.set_exons(exon_ranges, cds_ranges) transcript.set_cds(cds_ranges) transcript.add_cds_sequence(cds_sequence) transcript.add_genomic_sequence(genomic_sequence, offset=10) return transcript
[ "def", "construct_gene_object", "(", "ensembl", ",", "transcript_id", ")", ":", "# get the sequence for the identified transcript", "(", "chrom", ",", "start", ",", "end", ",", "strand", ",", "genomic_sequence", ")", "=", "ensembl", ".", "get_genomic_seq_for_transcript"...
creates an Transcript object for a gene from ensembl databases Args: ensembl: EnsemblRequest object to request data from ensembl transcript_id: string for an Ensembl transcript ID Returns: a Transcript object, containing transcript coordinates and gene and transcript sequence. Raises: ValueError if CDS from genomic sequence given gene coordinates and CDS retrieved from Ensembl do not match.
[ "creates", "an", "Transcript", "object", "for", "a", "gene", "from", "ensembl", "databases", "Args", ":", "ensembl", ":", "EnsemblRequest", "object", "to", "request", "data", "from", "ensembl", "transcript_id", ":", "string", "for", "an", "Ensembl", "transcript"...
train
https://github.com/jeremymcrae/denovonear/blob/feaab0fc77e89d70b31e8092899e4f0e68bac9fe/denovonear/load_gene.py#L46-L78
jeremymcrae/denovonear
denovonear/load_gene.py
get_de_novos_in_transcript
def get_de_novos_in_transcript(transcript, de_novos): """ get the de novos within the coding sequence of a transcript Args: transcript: Transcript object, which defines the transcript coordinates de_novos: list of chromosome sequence positions for de novo events Returns: list of de novo positions found within the transcript """ in_transcript = [] for de_novo in de_novos: # we check if the de novo is within the transcript by converting the # chromosomal position to a CDS-based position. Variants outside the CDS # will raise an error, which we catch and pass on. It's better to do # this, rather than use the function in_coding_region(), since that # function does not allow for splice site variants. site = transcript.get_coding_distance(de_novo) cds_length = transcript.get_coding_distance(transcript.get_cds_end()) within_cds = site['pos'] >= 0 and site['pos'] < cds_length['pos'] if within_cds and (transcript.in_coding_region(de_novo) or abs(site['offset']) < 9): in_transcript.append(de_novo) return in_transcript
python
def get_de_novos_in_transcript(transcript, de_novos): """ get the de novos within the coding sequence of a transcript Args: transcript: Transcript object, which defines the transcript coordinates de_novos: list of chromosome sequence positions for de novo events Returns: list of de novo positions found within the transcript """ in_transcript = [] for de_novo in de_novos: # we check if the de novo is within the transcript by converting the # chromosomal position to a CDS-based position. Variants outside the CDS # will raise an error, which we catch and pass on. It's better to do # this, rather than use the function in_coding_region(), since that # function does not allow for splice site variants. site = transcript.get_coding_distance(de_novo) cds_length = transcript.get_coding_distance(transcript.get_cds_end()) within_cds = site['pos'] >= 0 and site['pos'] < cds_length['pos'] if within_cds and (transcript.in_coding_region(de_novo) or abs(site['offset']) < 9): in_transcript.append(de_novo) return in_transcript
[ "def", "get_de_novos_in_transcript", "(", "transcript", ",", "de_novos", ")", ":", "in_transcript", "=", "[", "]", "for", "de_novo", "in", "de_novos", ":", "# we check if the de novo is within the transcript by converting the", "# chromosomal position to a CDS-based position. Var...
get the de novos within the coding sequence of a transcript Args: transcript: Transcript object, which defines the transcript coordinates de_novos: list of chromosome sequence positions for de novo events Returns: list of de novo positions found within the transcript
[ "get", "the", "de", "novos", "within", "the", "coding", "sequence", "of", "a", "transcript", "Args", ":", "transcript", ":", "Transcript", "object", "which", "defines", "the", "transcript", "coordinates", "de_novos", ":", "list", "of", "chromosome", "sequence", ...
train
https://github.com/jeremymcrae/denovonear/blob/feaab0fc77e89d70b31e8092899e4f0e68bac9fe/denovonear/load_gene.py#L80-L104
jeremymcrae/denovonear
denovonear/load_gene.py
get_transcript_ids
def get_transcript_ids(ensembl, gene_id): """ gets transcript IDs for a gene. Args: ensembl: EnsemblRequest object to request data from ensembl gene_id: HGNC symbol for gene Returns: dictionary of transcript ID: transcript lengths for all transcripts for a given HGNC symbol. """ ensembl_genes = ensembl.get_genes_for_hgnc_id(gene_id) transcript_ids = ensembl.get_transcript_ids_for_ensembl_gene_ids(ensembl_genes, [gene_id]) # sometimes we get HGNC symbols that do not match the ensembl rest version # that we are currentl using. We can look for earlier HGNC symbols for # the gene using the service at rest.genenames.org alt_symbols = [] if len(transcript_ids) == 0: alt_symbols = ensembl.get_previous_symbol(gene_id) genes = [ensembl.get_genes_for_hgnc_id(symbol) for symbol in alt_symbols] genes = [item for sublist in genes for item in sublist] ensembl_genes += genes symbols = [gene_id] + alt_symbols transcript_ids = ensembl.get_transcript_ids_for_ensembl_gene_ids(ensembl_genes, symbols) return get_transcript_lengths(ensembl, transcript_ids)
python
def get_transcript_ids(ensembl, gene_id): """ gets transcript IDs for a gene. Args: ensembl: EnsemblRequest object to request data from ensembl gene_id: HGNC symbol for gene Returns: dictionary of transcript ID: transcript lengths for all transcripts for a given HGNC symbol. """ ensembl_genes = ensembl.get_genes_for_hgnc_id(gene_id) transcript_ids = ensembl.get_transcript_ids_for_ensembl_gene_ids(ensembl_genes, [gene_id]) # sometimes we get HGNC symbols that do not match the ensembl rest version # that we are currentl using. We can look for earlier HGNC symbols for # the gene using the service at rest.genenames.org alt_symbols = [] if len(transcript_ids) == 0: alt_symbols = ensembl.get_previous_symbol(gene_id) genes = [ensembl.get_genes_for_hgnc_id(symbol) for symbol in alt_symbols] genes = [item for sublist in genes for item in sublist] ensembl_genes += genes symbols = [gene_id] + alt_symbols transcript_ids = ensembl.get_transcript_ids_for_ensembl_gene_ids(ensembl_genes, symbols) return get_transcript_lengths(ensembl, transcript_ids)
[ "def", "get_transcript_ids", "(", "ensembl", ",", "gene_id", ")", ":", "ensembl_genes", "=", "ensembl", ".", "get_genes_for_hgnc_id", "(", "gene_id", ")", "transcript_ids", "=", "ensembl", ".", "get_transcript_ids_for_ensembl_gene_ids", "(", "ensembl_genes", ",", "[",...
gets transcript IDs for a gene. Args: ensembl: EnsemblRequest object to request data from ensembl gene_id: HGNC symbol for gene Returns: dictionary of transcript ID: transcript lengths for all transcripts for a given HGNC symbol.
[ "gets", "transcript", "IDs", "for", "a", "gene", ".", "Args", ":", "ensembl", ":", "EnsemblRequest", "object", "to", "request", "data", "from", "ensembl", "gene_id", ":", "HGNC", "symbol", "for", "gene", "Returns", ":", "dictionary", "of", "transcript", "ID"...
train
https://github.com/jeremymcrae/denovonear/blob/feaab0fc77e89d70b31e8092899e4f0e68bac9fe/denovonear/load_gene.py#L106-L134
jeremymcrae/denovonear
denovonear/load_gene.py
load_gene
def load_gene(ensembl, gene_id, de_novos=[]): """ sort out all the necessary sequences and positions for a gene Args: ensembl: EnsemblRequest object to request data from ensembl gene_id: HGNC symbol for gene de_novos: list of de novo positions, so we can check they all fit in the gene transcript Returns: list of Transcript objects for gene, including genomic ranges and sequences """ transcripts = minimise_transcripts(ensembl, gene_id, de_novos) genes = [] for transcript_id in transcripts: gene = construct_gene_object(ensembl, transcript_id) genes.append(gene) if len(genes) == 0: raise IndexError("{0}: no suitable transcripts".format(gene_id)) return genes
python
def load_gene(ensembl, gene_id, de_novos=[]): """ sort out all the necessary sequences and positions for a gene Args: ensembl: EnsemblRequest object to request data from ensembl gene_id: HGNC symbol for gene de_novos: list of de novo positions, so we can check they all fit in the gene transcript Returns: list of Transcript objects for gene, including genomic ranges and sequences """ transcripts = minimise_transcripts(ensembl, gene_id, de_novos) genes = [] for transcript_id in transcripts: gene = construct_gene_object(ensembl, transcript_id) genes.append(gene) if len(genes) == 0: raise IndexError("{0}: no suitable transcripts".format(gene_id)) return genes
[ "def", "load_gene", "(", "ensembl", ",", "gene_id", ",", "de_novos", "=", "[", "]", ")", ":", "transcripts", "=", "minimise_transcripts", "(", "ensembl", ",", "gene_id", ",", "de_novos", ")", "genes", "=", "[", "]", "for", "transcript_id", "in", "transcrip...
sort out all the necessary sequences and positions for a gene Args: ensembl: EnsemblRequest object to request data from ensembl gene_id: HGNC symbol for gene de_novos: list of de novo positions, so we can check they all fit in the gene transcript Returns: list of Transcript objects for gene, including genomic ranges and sequences
[ "sort", "out", "all", "the", "necessary", "sequences", "and", "positions", "for", "a", "gene", "Args", ":", "ensembl", ":", "EnsemblRequest", "object", "to", "request", "data", "from", "ensembl", "gene_id", ":", "HGNC", "symbol", "for", "gene", "de_novos", "...
train
https://github.com/jeremymcrae/denovonear/blob/feaab0fc77e89d70b31e8092899e4f0e68bac9fe/denovonear/load_gene.py#L136-L159
jeremymcrae/denovonear
denovonear/load_gene.py
count_de_novos_per_transcript
def count_de_novos_per_transcript(ensembl, gene_id, de_novos=[]): """ count de novos in transcripts for a gene. Args: ensembl: EnsemblRequest object to request data from ensembl gene_id: HGNC symbol for gene de_novos: list of de novo positions, so we can check they all fit in the gene transcript Returns: dictionary of lengths and de novo counts, indexed by transcript IDs. """ transcripts = get_transcript_ids(ensembl, gene_id) # TODO: allow for genes without any coding sequence. if len(transcripts) == 0: raise IndexError("{0} lacks coding transcripts".format(gene_id)) # count the de novos observed in all transcripts counts = {} for key in transcripts: try: gene = construct_gene_object(ensembl, key) total = len(get_de_novos_in_transcript(gene, de_novos)) if total > 0: counts[key] = {} counts[key]["n"] = total counts[key]["len"] = transcripts[key] except ValueError: pass return counts
python
def count_de_novos_per_transcript(ensembl, gene_id, de_novos=[]): """ count de novos in transcripts for a gene. Args: ensembl: EnsemblRequest object to request data from ensembl gene_id: HGNC symbol for gene de_novos: list of de novo positions, so we can check they all fit in the gene transcript Returns: dictionary of lengths and de novo counts, indexed by transcript IDs. """ transcripts = get_transcript_ids(ensembl, gene_id) # TODO: allow for genes without any coding sequence. if len(transcripts) == 0: raise IndexError("{0} lacks coding transcripts".format(gene_id)) # count the de novos observed in all transcripts counts = {} for key in transcripts: try: gene = construct_gene_object(ensembl, key) total = len(get_de_novos_in_transcript(gene, de_novos)) if total > 0: counts[key] = {} counts[key]["n"] = total counts[key]["len"] = transcripts[key] except ValueError: pass return counts
[ "def", "count_de_novos_per_transcript", "(", "ensembl", ",", "gene_id", ",", "de_novos", "=", "[", "]", ")", ":", "transcripts", "=", "get_transcript_ids", "(", "ensembl", ",", "gene_id", ")", "# TODO: allow for genes without any coding sequence.", "if", "len", "(", ...
count de novos in transcripts for a gene. Args: ensembl: EnsemblRequest object to request data from ensembl gene_id: HGNC symbol for gene de_novos: list of de novo positions, so we can check they all fit in the gene transcript Returns: dictionary of lengths and de novo counts, indexed by transcript IDs.
[ "count", "de", "novos", "in", "transcripts", "for", "a", "gene", ".", "Args", ":", "ensembl", ":", "EnsemblRequest", "object", "to", "request", "data", "from", "ensembl", "gene_id", ":", "HGNC", "symbol", "for", "gene", "de_novos", ":", "list", "of", "de",...
train
https://github.com/jeremymcrae/denovonear/blob/feaab0fc77e89d70b31e8092899e4f0e68bac9fe/denovonear/load_gene.py#L161-L193
jeremymcrae/denovonear
denovonear/load_gene.py
minimise_transcripts
def minimise_transcripts(ensembl, gene_id, de_novos): """ get a set of minimal transcripts to contain all the de novos. We identify the minimal number of transcripts to contain all de novos. This allows for de novos on mutually exclusive transcripts. The transcripts are selected on the basis of containing the most number of de novos, while also being the longest possible transcript for the gene. Args: ensembl: EnsemblRequest object to request data from ensembl gene_id: HGNC symbol for gene de_novos: set of de novo positions Returns: dictionary of lengths and de novo counts, indexed by transcript ID for the set of minimal transcripts necessary to contain all de novos. """ if len(de_novos) == 0: return {} counts = count_de_novos_per_transcript(ensembl, gene_id, de_novos) if len(counts) == 0: return {} # find the transcripts with the most de novos max_count = max( val["n"] for key, val in counts.items() ) transcripts = [ key for key, val in counts.items() if val["n"] == max_count ] # find the transcripts with the greatest length, and the most de novos max_length = max( counts[key]["len"] for key in transcripts ) tx_ids = [ key for key in transcripts if counts[key]["len"] == max_length ] max_transcripts = {x: counts[x] for x in counts if x in tx_ids} # find which de novos occur in the transcript with the most de novos gene = construct_gene_object(ensembl, next(iter(max_transcripts))) denovos_in_gene = get_de_novos_in_transcript(gene, de_novos) # trim the de novos to the ones not in the current transcript leftovers = [ x for x in de_novos if x not in denovos_in_gene ] # and recursively return the transcripts in the current transcript, along # with transcripts for the reminaing de novos max_transcripts.update(minimise_transcripts(ensembl, gene_id, leftovers)) return max_transcripts
python
def minimise_transcripts(ensembl, gene_id, de_novos): """ get a set of minimal transcripts to contain all the de novos. We identify the minimal number of transcripts to contain all de novos. This allows for de novos on mutually exclusive transcripts. The transcripts are selected on the basis of containing the most number of de novos, while also being the longest possible transcript for the gene. Args: ensembl: EnsemblRequest object to request data from ensembl gene_id: HGNC symbol for gene de_novos: set of de novo positions Returns: dictionary of lengths and de novo counts, indexed by transcript ID for the set of minimal transcripts necessary to contain all de novos. """ if len(de_novos) == 0: return {} counts = count_de_novos_per_transcript(ensembl, gene_id, de_novos) if len(counts) == 0: return {} # find the transcripts with the most de novos max_count = max( val["n"] for key, val in counts.items() ) transcripts = [ key for key, val in counts.items() if val["n"] == max_count ] # find the transcripts with the greatest length, and the most de novos max_length = max( counts[key]["len"] for key in transcripts ) tx_ids = [ key for key in transcripts if counts[key]["len"] == max_length ] max_transcripts = {x: counts[x] for x in counts if x in tx_ids} # find which de novos occur in the transcript with the most de novos gene = construct_gene_object(ensembl, next(iter(max_transcripts))) denovos_in_gene = get_de_novos_in_transcript(gene, de_novos) # trim the de novos to the ones not in the current transcript leftovers = [ x for x in de_novos if x not in denovos_in_gene ] # and recursively return the transcripts in the current transcript, along # with transcripts for the reminaing de novos max_transcripts.update(minimise_transcripts(ensembl, gene_id, leftovers)) return max_transcripts
[ "def", "minimise_transcripts", "(", "ensembl", ",", "gene_id", ",", "de_novos", ")", ":", "if", "len", "(", "de_novos", ")", "==", "0", ":", "return", "{", "}", "counts", "=", "count_de_novos_per_transcript", "(", "ensembl", ",", "gene_id", ",", "de_novos", ...
get a set of minimal transcripts to contain all the de novos. We identify the minimal number of transcripts to contain all de novos. This allows for de novos on mutually exclusive transcripts. The transcripts are selected on the basis of containing the most number of de novos, while also being the longest possible transcript for the gene. Args: ensembl: EnsemblRequest object to request data from ensembl gene_id: HGNC symbol for gene de_novos: set of de novo positions Returns: dictionary of lengths and de novo counts, indexed by transcript ID for the set of minimal transcripts necessary to contain all de novos.
[ "get", "a", "set", "of", "minimal", "transcripts", "to", "contain", "all", "the", "de", "novos", ".", "We", "identify", "the", "minimal", "number", "of", "transcripts", "to", "contain", "all", "de", "novos", ".", "This", "allows", "for", "de", "novos", "...
train
https://github.com/jeremymcrae/denovonear/blob/feaab0fc77e89d70b31e8092899e4f0e68bac9fe/denovonear/load_gene.py#L195-L241
LordGaav/python-chaos
chaos/db.py
dump_simple_db
def dump_simple_db(path): """ Dumps a SimpleDb as string in the following format: <key>: <json-encoded string> """ output = [] simpledb = SimpleDb(path, mode="r", sync=False) with simpledb as db: for key in db: output.append("{0}: {1}".format(key, db.dumpvalue(key))) return "\n".join(output)
python
def dump_simple_db(path): """ Dumps a SimpleDb as string in the following format: <key>: <json-encoded string> """ output = [] simpledb = SimpleDb(path, mode="r", sync=False) with simpledb as db: for key in db: output.append("{0}: {1}".format(key, db.dumpvalue(key))) return "\n".join(output)
[ "def", "dump_simple_db", "(", "path", ")", ":", "output", "=", "[", "]", "simpledb", "=", "SimpleDb", "(", "path", ",", "mode", "=", "\"r\"", ",", "sync", "=", "False", ")", "with", "simpledb", "as", "db", ":", "for", "key", "in", "db", ":", "outpu...
Dumps a SimpleDb as string in the following format: <key>: <json-encoded string>
[ "Dumps", "a", "SimpleDb", "as", "string", "in", "the", "following", "format", ":", "<key", ">", ":", "<json", "-", "encoded", "string", ">" ]
train
https://github.com/LordGaav/python-chaos/blob/52cd29a6fd15693ee1e53786b93bcb23fbf84ddd/chaos/db.py#L21-L31
ReadabilityHoldings/python-readability-api
readability/core.py
required_from_env
def required_from_env(key): """ Retrieve a required variable from the current environment variables. Raises a ValueError if the env variable is not found or has no value. """ val = os.environ.get(key) if not val: raise ValueError( "Required argument '{}' not supplied and not found in environment variables".format(key)) return val
python
def required_from_env(key): """ Retrieve a required variable from the current environment variables. Raises a ValueError if the env variable is not found or has no value. """ val = os.environ.get(key) if not val: raise ValueError( "Required argument '{}' not supplied and not found in environment variables".format(key)) return val
[ "def", "required_from_env", "(", "key", ")", ":", "val", "=", "os", ".", "environ", ".", "get", "(", "key", ")", "if", "not", "val", ":", "raise", "ValueError", "(", "\"Required argument '{}' not supplied and not found in environment variables\"", ".", "format", "...
Retrieve a required variable from the current environment variables. Raises a ValueError if the env variable is not found or has no value.
[ "Retrieve", "a", "required", "variable", "from", "the", "current", "environment", "variables", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/core.py#L4-L15
ReadabilityHoldings/python-readability-api
readability/clients.py
ReaderClient.get
def get(self, url): """ Make a HTTP GET request to the Reader API. :param url: url to which to make a GET request. """ logger.debug('Making GET request to %s', url) return self.oauth_session.get(url)
python
def get(self, url): """ Make a HTTP GET request to the Reader API. :param url: url to which to make a GET request. """ logger.debug('Making GET request to %s', url) return self.oauth_session.get(url)
[ "def", "get", "(", "self", ",", "url", ")", ":", "logger", ".", "debug", "(", "'Making GET request to %s'", ",", "url", ")", "return", "self", ".", "oauth_session", ".", "get", "(", "url", ")" ]
Make a HTTP GET request to the Reader API. :param url: url to which to make a GET request.
[ "Make", "a", "HTTP", "GET", "request", "to", "the", "Reader", "API", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L75-L82
ReadabilityHoldings/python-readability-api
readability/clients.py
ReaderClient.post
def post(self, url, post_params=None): """ Make a HTTP POST request to the Reader API. :param url: url to which to make a POST request. :param post_params: parameters to be sent in the request's body. """ params = urlencode(post_params) logger.debug('Making POST request to %s with body %s', url, params) return self.oauth_session.post(url, data=params)
python
def post(self, url, post_params=None): """ Make a HTTP POST request to the Reader API. :param url: url to which to make a POST request. :param post_params: parameters to be sent in the request's body. """ params = urlencode(post_params) logger.debug('Making POST request to %s with body %s', url, params) return self.oauth_session.post(url, data=params)
[ "def", "post", "(", "self", ",", "url", ",", "post_params", "=", "None", ")", ":", "params", "=", "urlencode", "(", "post_params", ")", "logger", ".", "debug", "(", "'Making POST request to %s with body %s'", ",", "url", ",", "params", ")", "return", "self",...
Make a HTTP POST request to the Reader API. :param url: url to which to make a POST request. :param post_params: parameters to be sent in the request's body.
[ "Make", "a", "HTTP", "POST", "request", "to", "the", "Reader", "API", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L84-L93
ReadabilityHoldings/python-readability-api
readability/clients.py
ReaderClient.delete
def delete(self, url): """ Make a HTTP DELETE request to the Readability API. :param url: The url to which to send a DELETE request. """ logger.debug('Making DELETE request to %s', url) return self.oauth_session.delete(url)
python
def delete(self, url): """ Make a HTTP DELETE request to the Readability API. :param url: The url to which to send a DELETE request. """ logger.debug('Making DELETE request to %s', url) return self.oauth_session.delete(url)
[ "def", "delete", "(", "self", ",", "url", ")", ":", "logger", ".", "debug", "(", "'Making DELETE request to %s'", ",", "url", ")", "return", "self", ".", "oauth_session", ".", "delete", "(", "url", ")" ]
Make a HTTP DELETE request to the Readability API. :param url: The url to which to send a DELETE request.
[ "Make", "a", "HTTP", "DELETE", "request", "to", "the", "Readability", "API", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L95-L102
ReadabilityHoldings/python-readability-api
readability/clients.py
ReaderClient.get_article
def get_article(self, article_id): """ Get a single article represented by `article_id`. :param article_id: ID of the article to retrieve. """ url = self._generate_url('articles/{0}'.format(article_id)) return self.get(url)
python
def get_article(self, article_id): """ Get a single article represented by `article_id`. :param article_id: ID of the article to retrieve. """ url = self._generate_url('articles/{0}'.format(article_id)) return self.get(url)
[ "def", "get_article", "(", "self", ",", "article_id", ")", ":", "url", "=", "self", ".", "_generate_url", "(", "'articles/{0}'", ".", "format", "(", "article_id", ")", ")", "return", "self", ".", "get", "(", "url", ")" ]
Get a single article represented by `article_id`. :param article_id: ID of the article to retrieve.
[ "Get", "a", "single", "article", "represented", "by", "article_id", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L119-L126
ReadabilityHoldings/python-readability-api
readability/clients.py
ReaderClient.get_bookmarks
def get_bookmarks(self, **filters): """ Get Bookmarks for the current user. Filters: :param archive: Filter Bookmarks returned by archived status. :param favorite: Filter Bookmarks returned by favorite status. :param domain: Filter Bookmarks returned by a domain. :param added_since: Filter bookmarks by date added (since this date). :param added_until: Filter bookmarks by date added (until this date). :param opened_since: Filter bookmarks by date opened (since this date). :param opened_until: Filter bookmarks by date opened (until this date). :param archived_since: Filter bookmarks by date archived (since this date.) :param archived_until: Filter bookmarks by date archived (until this date.) :param updated_since: Filter bookmarks by date updated (since this date.) :param updated_until: Filter bookmarks by date updated (until this date.) :param page: What page of results to return. Default is 1. :param per_page: How many results to return per page. Default is 20, max is 50. :param only_deleted: Return only bookmarks that this user has deleted. :param tags: Comma separated string of tags to filter bookmarks. """ filter_dict = filter_args_to_dict(filters, ACCEPTED_BOOKMARK_FILTERS) url = self._generate_url('bookmarks', query_params=filter_dict) return self.get(url)
python
def get_bookmarks(self, **filters): """ Get Bookmarks for the current user. Filters: :param archive: Filter Bookmarks returned by archived status. :param favorite: Filter Bookmarks returned by favorite status. :param domain: Filter Bookmarks returned by a domain. :param added_since: Filter bookmarks by date added (since this date). :param added_until: Filter bookmarks by date added (until this date). :param opened_since: Filter bookmarks by date opened (since this date). :param opened_until: Filter bookmarks by date opened (until this date). :param archived_since: Filter bookmarks by date archived (since this date.) :param archived_until: Filter bookmarks by date archived (until this date.) :param updated_since: Filter bookmarks by date updated (since this date.) :param updated_until: Filter bookmarks by date updated (until this date.) :param page: What page of results to return. Default is 1. :param per_page: How many results to return per page. Default is 20, max is 50. :param only_deleted: Return only bookmarks that this user has deleted. :param tags: Comma separated string of tags to filter bookmarks. """ filter_dict = filter_args_to_dict(filters, ACCEPTED_BOOKMARK_FILTERS) url = self._generate_url('bookmarks', query_params=filter_dict) return self.get(url)
[ "def", "get_bookmarks", "(", "self", ",", "*", "*", "filters", ")", ":", "filter_dict", "=", "filter_args_to_dict", "(", "filters", ",", "ACCEPTED_BOOKMARK_FILTERS", ")", "url", "=", "self", ".", "_generate_url", "(", "'bookmarks'", ",", "query_params", "=", "...
Get Bookmarks for the current user. Filters: :param archive: Filter Bookmarks returned by archived status. :param favorite: Filter Bookmarks returned by favorite status. :param domain: Filter Bookmarks returned by a domain. :param added_since: Filter bookmarks by date added (since this date). :param added_until: Filter bookmarks by date added (until this date). :param opened_since: Filter bookmarks by date opened (since this date). :param opened_until: Filter bookmarks by date opened (until this date). :param archived_since: Filter bookmarks by date archived (since this date.) :param archived_until: Filter bookmarks by date archived (until this date.) :param updated_since: Filter bookmarks by date updated (since this date.) :param updated_until: Filter bookmarks by date updated (until this date.) :param page: What page of results to return. Default is 1. :param per_page: How many results to return per page. Default is 20, max is 50. :param only_deleted: Return only bookmarks that this user has deleted. :param tags: Comma separated string of tags to filter bookmarks.
[ "Get", "Bookmarks", "for", "the", "current", "user", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L128-L152
ReadabilityHoldings/python-readability-api
readability/clients.py
ReaderClient.get_bookmark
def get_bookmark(self, bookmark_id): """ Get a single bookmark represented by `bookmark_id`. The requested bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to retrieve. """ url = self._generate_url('bookmarks/{0}'.format(bookmark_id)) return self.get(url)
python
def get_bookmark(self, bookmark_id): """ Get a single bookmark represented by `bookmark_id`. The requested bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to retrieve. """ url = self._generate_url('bookmarks/{0}'.format(bookmark_id)) return self.get(url)
[ "def", "get_bookmark", "(", "self", ",", "bookmark_id", ")", ":", "url", "=", "self", ".", "_generate_url", "(", "'bookmarks/{0}'", ".", "format", "(", "bookmark_id", ")", ")", "return", "self", ".", "get", "(", "url", ")" ]
Get a single bookmark represented by `bookmark_id`. The requested bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to retrieve.
[ "Get", "a", "single", "bookmark", "represented", "by", "bookmark_id", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L154-L163
ReadabilityHoldings/python-readability-api
readability/clients.py
ReaderClient.add_bookmark
def add_bookmark(self, url, favorite=False, archive=False, allow_duplicates=True): """ Adds given bookmark to the authenticated user. :param url: URL of the article to bookmark :param favorite: whether or not the bookmark should be favorited :param archive: whether or not the bookmark should be archived :param allow_duplicates: whether or not to allow duplicate bookmarks to be created for a given url """ rdb_url = self._generate_url('bookmarks') params = { "url": url, "favorite": int(favorite), "archive": int(archive), "allow_duplicates": int(allow_duplicates) } return self.post(rdb_url, params)
python
def add_bookmark(self, url, favorite=False, archive=False, allow_duplicates=True): """ Adds given bookmark to the authenticated user. :param url: URL of the article to bookmark :param favorite: whether or not the bookmark should be favorited :param archive: whether or not the bookmark should be archived :param allow_duplicates: whether or not to allow duplicate bookmarks to be created for a given url """ rdb_url = self._generate_url('bookmarks') params = { "url": url, "favorite": int(favorite), "archive": int(archive), "allow_duplicates": int(allow_duplicates) } return self.post(rdb_url, params)
[ "def", "add_bookmark", "(", "self", ",", "url", ",", "favorite", "=", "False", ",", "archive", "=", "False", ",", "allow_duplicates", "=", "True", ")", ":", "rdb_url", "=", "self", ".", "_generate_url", "(", "'bookmarks'", ")", "params", "=", "{", "\"url...
Adds given bookmark to the authenticated user. :param url: URL of the article to bookmark :param favorite: whether or not the bookmark should be favorited :param archive: whether or not the bookmark should be archived :param allow_duplicates: whether or not to allow duplicate bookmarks to be created for a given url
[ "Adds", "given", "bookmark", "to", "the", "authenticated", "user", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L165-L182
ReadabilityHoldings/python-readability-api
readability/clients.py
ReaderClient.update_bookmark
def update_bookmark(self, bookmark_id, favorite=None, archive=None, read_percent=None): """ Updates given bookmark. The requested bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to update. :param favorite (optional): Whether this article is favorited or not. :param archive (optional): Whether this article is archived or not. :param read_percent (optional): The read progress made in this article, where 1.0 means the bottom and 0.0 means the very top. """ rdb_url = self._generate_url('bookmarks/{0}'.format(bookmark_id)) params = {} if favorite is not None: params['favorite'] = 1 if favorite == True else 0 if archive is not None: params['archive'] = 1 if archive == True else 0 if read_percent is not None: try: params['read_percent'] = float(read_percent) except ValueError: pass return self.post(rdb_url, params)
python
def update_bookmark(self, bookmark_id, favorite=None, archive=None, read_percent=None): """ Updates given bookmark. The requested bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to update. :param favorite (optional): Whether this article is favorited or not. :param archive (optional): Whether this article is archived or not. :param read_percent (optional): The read progress made in this article, where 1.0 means the bottom and 0.0 means the very top. """ rdb_url = self._generate_url('bookmarks/{0}'.format(bookmark_id)) params = {} if favorite is not None: params['favorite'] = 1 if favorite == True else 0 if archive is not None: params['archive'] = 1 if archive == True else 0 if read_percent is not None: try: params['read_percent'] = float(read_percent) except ValueError: pass return self.post(rdb_url, params)
[ "def", "update_bookmark", "(", "self", ",", "bookmark_id", ",", "favorite", "=", "None", ",", "archive", "=", "None", ",", "read_percent", "=", "None", ")", ":", "rdb_url", "=", "self", ".", "_generate_url", "(", "'bookmarks/{0}'", ".", "format", "(", "boo...
Updates given bookmark. The requested bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to update. :param favorite (optional): Whether this article is favorited or not. :param archive (optional): Whether this article is archived or not. :param read_percent (optional): The read progress made in this article, where 1.0 means the bottom and 0.0 means the very top.
[ "Updates", "given", "bookmark", ".", "The", "requested", "bookmark", "must", "belong", "to", "the", "current", "user", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L184-L206
ReadabilityHoldings/python-readability-api
readability/clients.py
ReaderClient.delete_bookmark
def delete_bookmark(self, bookmark_id): """ Delete a single bookmark represented by `bookmark_id`. The requested bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to delete. """ url = self._generate_url('bookmarks/{0}'.format(bookmark_id)) return self.delete(url)
python
def delete_bookmark(self, bookmark_id): """ Delete a single bookmark represented by `bookmark_id`. The requested bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to delete. """ url = self._generate_url('bookmarks/{0}'.format(bookmark_id)) return self.delete(url)
[ "def", "delete_bookmark", "(", "self", ",", "bookmark_id", ")", ":", "url", "=", "self", ".", "_generate_url", "(", "'bookmarks/{0}'", ".", "format", "(", "bookmark_id", ")", ")", "return", "self", ".", "delete", "(", "url", ")" ]
Delete a single bookmark represented by `bookmark_id`. The requested bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to delete.
[ "Delete", "a", "single", "bookmark", "represented", "by", "bookmark_id", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L237-L246
ReadabilityHoldings/python-readability-api
readability/clients.py
ReaderClient.get_bookmark_tags
def get_bookmark_tags(self, bookmark_id): """ Retrieve tags that have been applied to a bookmark. The requested bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to delete. """ url = self._generate_url('bookmarks/{0}/tags'.format(bookmark_id)) return self.get(url)
python
def get_bookmark_tags(self, bookmark_id): """ Retrieve tags that have been applied to a bookmark. The requested bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to delete. """ url = self._generate_url('bookmarks/{0}/tags'.format(bookmark_id)) return self.get(url)
[ "def", "get_bookmark_tags", "(", "self", ",", "bookmark_id", ")", ":", "url", "=", "self", ".", "_generate_url", "(", "'bookmarks/{0}/tags'", ".", "format", "(", "bookmark_id", ")", ")", "return", "self", ".", "get", "(", "url", ")" ]
Retrieve tags that have been applied to a bookmark. The requested bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to delete.
[ "Retrieve", "tags", "that", "have", "been", "applied", "to", "a", "bookmark", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L248-L257
ReadabilityHoldings/python-readability-api
readability/clients.py
ReaderClient.add_tags_to_bookmark
def add_tags_to_bookmark(self, bookmark_id, tags): """ Add tags to to a bookmark. The identified bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to delete. :param tags: Comma separated tags to be applied. """ url = self._generate_url('bookmarks/{0}/tags'.format(bookmark_id)) params = dict(tags=tags) return self.post(url, params)
python
def add_tags_to_bookmark(self, bookmark_id, tags): """ Add tags to to a bookmark. The identified bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to delete. :param tags: Comma separated tags to be applied. """ url = self._generate_url('bookmarks/{0}/tags'.format(bookmark_id)) params = dict(tags=tags) return self.post(url, params)
[ "def", "add_tags_to_bookmark", "(", "self", ",", "bookmark_id", ",", "tags", ")", ":", "url", "=", "self", ".", "_generate_url", "(", "'bookmarks/{0}/tags'", ".", "format", "(", "bookmark_id", ")", ")", "params", "=", "dict", "(", "tags", "=", "tags", ")",...
Add tags to to a bookmark. The identified bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to delete. :param tags: Comma separated tags to be applied.
[ "Add", "tags", "to", "to", "a", "bookmark", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L259-L270
ReadabilityHoldings/python-readability-api
readability/clients.py
ReaderClient.delete_tag_from_bookmark
def delete_tag_from_bookmark(self, bookmark_id, tag_id): """ Remove a single tag from a bookmark. The identified bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to delete. """ url = self._generate_url('bookmarks/{0}/tags/{1}'.format( bookmark_id, tag_id)) return self.delete(url)
python
def delete_tag_from_bookmark(self, bookmark_id, tag_id): """ Remove a single tag from a bookmark. The identified bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to delete. """ url = self._generate_url('bookmarks/{0}/tags/{1}'.format( bookmark_id, tag_id)) return self.delete(url)
[ "def", "delete_tag_from_bookmark", "(", "self", ",", "bookmark_id", ",", "tag_id", ")", ":", "url", "=", "self", ".", "_generate_url", "(", "'bookmarks/{0}/tags/{1}'", ".", "format", "(", "bookmark_id", ",", "tag_id", ")", ")", "return", "self", ".", "delete",...
Remove a single tag from a bookmark. The identified bookmark must belong to the current user. :param bookmark_id: ID of the bookmark to delete.
[ "Remove", "a", "single", "tag", "from", "a", "bookmark", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L272-L282
ReadabilityHoldings/python-readability-api
readability/clients.py
ReaderClient.get_tag
def get_tag(self, tag_id): """ Get a single tag represented by `tag_id`. The requested tag must belong to the current user. :param tag_id: ID fo the tag to retrieve. """ url = self._generate_url('tags/{0}'.format(tag_id)) return self.get(url)
python
def get_tag(self, tag_id): """ Get a single tag represented by `tag_id`. The requested tag must belong to the current user. :param tag_id: ID fo the tag to retrieve. """ url = self._generate_url('tags/{0}'.format(tag_id)) return self.get(url)
[ "def", "get_tag", "(", "self", ",", "tag_id", ")", ":", "url", "=", "self", ".", "_generate_url", "(", "'tags/{0}'", ".", "format", "(", "tag_id", ")", ")", "return", "self", ".", "get", "(", "url", ")" ]
Get a single tag represented by `tag_id`. The requested tag must belong to the current user. :param tag_id: ID fo the tag to retrieve.
[ "Get", "a", "single", "tag", "represented", "by", "tag_id", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L284-L293
ReadabilityHoldings/python-readability-api
readability/clients.py
ParserClient.post
def post(self, url, post_params=None): """ Make an HTTP POST request to the Parser API. :param url: url to which to make the request :param post_params: POST data to send along. Expected to be a dict. """ post_params['token'] = self.token params = urlencode(post_params) logger.debug('Making POST request to %s with body %s', url, params) return requests.post(url, data=params)
python
def post(self, url, post_params=None): """ Make an HTTP POST request to the Parser API. :param url: url to which to make the request :param post_params: POST data to send along. Expected to be a dict. """ post_params['token'] = self.token params = urlencode(post_params) logger.debug('Making POST request to %s with body %s', url, params) return requests.post(url, data=params)
[ "def", "post", "(", "self", ",", "url", ",", "post_params", "=", "None", ")", ":", "post_params", "[", "'token'", "]", "=", "self", ".", "token", "params", "=", "urlencode", "(", "post_params", ")", "logger", ".", "debug", "(", "'Making POST request to %s ...
Make an HTTP POST request to the Parser API. :param url: url to which to make the request :param post_params: POST data to send along. Expected to be a dict.
[ "Make", "an", "HTTP", "POST", "request", "to", "the", "Parser", "API", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L350-L360
ReadabilityHoldings/python-readability-api
readability/clients.py
ParserClient._generate_url
def _generate_url(self, resource, query_params=None): """ Build the url to resource. :param resource: Name of the resource that is being called. Options are `''` (empty string) for root resource, `'parser'`, `'confidence'`. :param query_params: Data to be passed as query parameters. """ resource = '{resource}?token={token}'.format(resource=resource, token=self.token) if query_params: resource += "&{}".format(urlencode(query_params)) return self.base_url_template.format(resource)
python
def _generate_url(self, resource, query_params=None): """ Build the url to resource. :param resource: Name of the resource that is being called. Options are `''` (empty string) for root resource, `'parser'`, `'confidence'`. :param query_params: Data to be passed as query parameters. """ resource = '{resource}?token={token}'.format(resource=resource, token=self.token) if query_params: resource += "&{}".format(urlencode(query_params)) return self.base_url_template.format(resource)
[ "def", "_generate_url", "(", "self", ",", "resource", ",", "query_params", "=", "None", ")", ":", "resource", "=", "'{resource}?token={token}'", ".", "format", "(", "resource", "=", "resource", ",", "token", "=", "self", ".", "token", ")", "if", "query_param...
Build the url to resource. :param resource: Name of the resource that is being called. Options are `''` (empty string) for root resource, `'parser'`, `'confidence'`. :param query_params: Data to be passed as query parameters.
[ "Build", "the", "url", "to", "resource", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L362-L373
ReadabilityHoldings/python-readability-api
readability/clients.py
ParserClient.get_article
def get_article(self, url=None, article_id=None, max_pages=25): """ Send a GET request to the `parser` endpoint of the parser API to get back the representation of an article. The article can be identified by either a URL or an id that exists in Readability. Note that either the `url` or `article_id` param should be passed. :param url (optional): The url of an article whose content is wanted. :param article_id (optional): The id of an article in the Readability system whose content is wanted. :param max_pages: The maximum number of pages to parse and combine. The default is 25. """ query_params = {} if url is not None: query_params['url'] = url if article_id is not None: query_params['article_id'] = article_id query_params['max_pages'] = max_pages url = self._generate_url('parser', query_params=query_params) return self.get(url)
python
def get_article(self, url=None, article_id=None, max_pages=25): """ Send a GET request to the `parser` endpoint of the parser API to get back the representation of an article. The article can be identified by either a URL or an id that exists in Readability. Note that either the `url` or `article_id` param should be passed. :param url (optional): The url of an article whose content is wanted. :param article_id (optional): The id of an article in the Readability system whose content is wanted. :param max_pages: The maximum number of pages to parse and combine. The default is 25. """ query_params = {} if url is not None: query_params['url'] = url if article_id is not None: query_params['article_id'] = article_id query_params['max_pages'] = max_pages url = self._generate_url('parser', query_params=query_params) return self.get(url)
[ "def", "get_article", "(", "self", ",", "url", "=", "None", ",", "article_id", "=", "None", ",", "max_pages", "=", "25", ")", ":", "query_params", "=", "{", "}", "if", "url", "is", "not", "None", ":", "query_params", "[", "'url'", "]", "=", "url", ...
Send a GET request to the `parser` endpoint of the parser API to get back the representation of an article. The article can be identified by either a URL or an id that exists in Readability. Note that either the `url` or `article_id` param should be passed. :param url (optional): The url of an article whose content is wanted. :param article_id (optional): The id of an article in the Readability system whose content is wanted. :param max_pages: The maximum number of pages to parse and combine. The default is 25.
[ "Send", "a", "GET", "request", "to", "the", "parser", "endpoint", "of", "the", "parser", "API", "to", "get", "back", "the", "representation", "of", "an", "article", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L382-L405
ReadabilityHoldings/python-readability-api
readability/clients.py
ParserClient.post_article_content
def post_article_content(self, content, url, max_pages=25): """ POST content to be parsed to the Parser API. Note: Even when POSTing content, a url must still be provided. :param content: the content to be parsed :param url: the url that represents the content :param max_pages (optional): the maximum number of pages to parse and combine. Default is 25. """ params = { 'doc': content, 'max_pages': max_pages } url = self._generate_url('parser', {"url": url}) return self.post(url, post_params=params)
python
def post_article_content(self, content, url, max_pages=25): """ POST content to be parsed to the Parser API. Note: Even when POSTing content, a url must still be provided. :param content: the content to be parsed :param url: the url that represents the content :param max_pages (optional): the maximum number of pages to parse and combine. Default is 25. """ params = { 'doc': content, 'max_pages': max_pages } url = self._generate_url('parser', {"url": url}) return self.post(url, post_params=params)
[ "def", "post_article_content", "(", "self", ",", "content", ",", "url", ",", "max_pages", "=", "25", ")", ":", "params", "=", "{", "'doc'", ":", "content", ",", "'max_pages'", ":", "max_pages", "}", "url", "=", "self", ".", "_generate_url", "(", "'parser...
POST content to be parsed to the Parser API. Note: Even when POSTing content, a url must still be provided. :param content: the content to be parsed :param url: the url that represents the content :param max_pages (optional): the maximum number of pages to parse and combine. Default is 25.
[ "POST", "content", "to", "be", "parsed", "to", "the", "Parser", "API", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L407-L423
ReadabilityHoldings/python-readability-api
readability/clients.py
ParserClient.get_article_status
def get_article_status(self, url=None, article_id=None): """ Send a HEAD request to the `parser` endpoint to the parser API to get the articles status. Returned is a `requests.Response` object. The id and status for the article can be extracted from the `X-Article-Id` and `X-Article-Status` headers. Note that either the `url` or `article_id` param should be passed. :param url (optional): The url of an article whose content is wanted. :param article_id (optional): The id of an article in the Readability system whose content is wanted. """ query_params = {} if url is not None: query_params['url'] = url if article_id is not None: query_params['article_id'] = article_id url = self._generate_url('parser', query_params=query_params) return self.head(url)
python
def get_article_status(self, url=None, article_id=None): """ Send a HEAD request to the `parser` endpoint to the parser API to get the articles status. Returned is a `requests.Response` object. The id and status for the article can be extracted from the `X-Article-Id` and `X-Article-Status` headers. Note that either the `url` or `article_id` param should be passed. :param url (optional): The url of an article whose content is wanted. :param article_id (optional): The id of an article in the Readability system whose content is wanted. """ query_params = {} if url is not None: query_params['url'] = url if article_id is not None: query_params['article_id'] = article_id url = self._generate_url('parser', query_params=query_params) return self.head(url)
[ "def", "get_article_status", "(", "self", ",", "url", "=", "None", ",", "article_id", "=", "None", ")", ":", "query_params", "=", "{", "}", "if", "url", "is", "not", "None", ":", "query_params", "[", "'url'", "]", "=", "url", "if", "article_id", "is", ...
Send a HEAD request to the `parser` endpoint to the parser API to get the articles status. Returned is a `requests.Response` object. The id and status for the article can be extracted from the `X-Article-Id` and `X-Article-Status` headers. Note that either the `url` or `article_id` param should be passed. :param url (optional): The url of an article whose content is wanted. :param article_id (optional): The id of an article in the Readability system whose content is wanted.
[ "Send", "a", "HEAD", "request", "to", "the", "parser", "endpoint", "to", "the", "parser", "API", "to", "get", "the", "articles", "status", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L425-L446
ReadabilityHoldings/python-readability-api
readability/clients.py
ParserClient.get_confidence
def get_confidence(self, url=None, article_id=None): """ Send a GET request to the `confidence` endpoint of the Parser API. Note that either the `url` or `article_id` param should be passed. :param url (optional): The url of an article whose content is wanted. :param article_id (optional): The id of an article in the Readability system whose content is wanted. """ query_params = {} if url is not None: query_params['url'] = url if article_id is not None: query_params['article_id'] = article_id url = self._generate_url('confidence', query_params=query_params) return self.get(url)
python
def get_confidence(self, url=None, article_id=None): """ Send a GET request to the `confidence` endpoint of the Parser API. Note that either the `url` or `article_id` param should be passed. :param url (optional): The url of an article whose content is wanted. :param article_id (optional): The id of an article in the Readability system whose content is wanted. """ query_params = {} if url is not None: query_params['url'] = url if article_id is not None: query_params['article_id'] = article_id url = self._generate_url('confidence', query_params=query_params) return self.get(url)
[ "def", "get_confidence", "(", "self", ",", "url", "=", "None", ",", "article_id", "=", "None", ")", ":", "query_params", "=", "{", "}", "if", "url", "is", "not", "None", ":", "query_params", "[", "'url'", "]", "=", "url", "if", "article_id", "is", "n...
Send a GET request to the `confidence` endpoint of the Parser API. Note that either the `url` or `article_id` param should be passed. :param url (optional): The url of an article whose content is wanted. :param article_id (optional): The id of an article in the Readability system whose content is wanted.
[ "Send", "a", "GET", "request", "to", "the", "confidence", "endpoint", "of", "the", "Parser", "API", "." ]
train
https://github.com/ReadabilityHoldings/python-readability-api/blob/4b746166877d5a8dc29222aedccb18c2506a5385/readability/clients.py#L448-L464
peterldowns/lggr
lggr/coroutine.py
coroutine
def coroutine(func): """ Decorator for priming co-routines that use (yield) """ def wrapper(*args, **kwargs): c = func(*args, **kwargs) c.next() # prime it for iteration return c return wrapper
python
def coroutine(func): """ Decorator for priming co-routines that use (yield) """ def wrapper(*args, **kwargs): c = func(*args, **kwargs) c.next() # prime it for iteration return c return wrapper
[ "def", "coroutine", "(", "func", ")", ":", "def", "wrapper", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "c", "=", "func", "(", "*", "args", ",", "*", "*", "kwargs", ")", "c", ".", "next", "(", ")", "# prime it for iteration", "return", ...
Decorator for priming co-routines that use (yield)
[ "Decorator", "for", "priming", "co", "-", "routines", "that", "use", "(", "yield", ")" ]
train
https://github.com/peterldowns/lggr/blob/622968f17133e02d9a46a4900dd20fb3b19fe961/lggr/coroutine.py#L8-L14
koreyou/word_embedding_loader
word_embedding_loader/saver/glove.py
save
def save(f, arr, vocab): """ Save word embedding file. Args: f (File): File to write the vectors. File should be open for writing ascii. arr (numpy.array): Numpy array with ``float`` dtype. vocab (iterable): Each element is pair of a word (``bytes``) and ``arr`` index (``int``). Word should be encoded to str apriori. """ itr = iter(vocab) # Avoid empty line at the end word, idx = next(itr) _write_line(f, arr[idx], word) for word, idx in itr: f.write(b'\n') _write_line(f, arr[idx], word)
python
def save(f, arr, vocab): """ Save word embedding file. Args: f (File): File to write the vectors. File should be open for writing ascii. arr (numpy.array): Numpy array with ``float`` dtype. vocab (iterable): Each element is pair of a word (``bytes``) and ``arr`` index (``int``). Word should be encoded to str apriori. """ itr = iter(vocab) # Avoid empty line at the end word, idx = next(itr) _write_line(f, arr[idx], word) for word, idx in itr: f.write(b'\n') _write_line(f, arr[idx], word)
[ "def", "save", "(", "f", ",", "arr", ",", "vocab", ")", ":", "itr", "=", "iter", "(", "vocab", ")", "# Avoid empty line at the end", "word", ",", "idx", "=", "next", "(", "itr", ")", "_write_line", "(", "f", ",", "arr", "[", "idx", "]", ",", "word"...
Save word embedding file. Args: f (File): File to write the vectors. File should be open for writing ascii. arr (numpy.array): Numpy array with ``float`` dtype. vocab (iterable): Each element is pair of a word (``bytes``) and ``arr`` index (``int``). Word should be encoded to str apriori.
[ "Save", "word", "embedding", "file", "." ]
train
https://github.com/koreyou/word_embedding_loader/blob/1bc123f1a8bea12646576dcd768dae3ecea39c06/word_embedding_loader/saver/glove.py#L18-L35
koreyou/word_embedding_loader
word_embedding_loader/cli.py
convert
def convert(outputfile, inputfile, to_format, from_format): """ Convert pretrained word embedding file in one format to another. """ emb = word_embedding.WordEmbedding.load( inputfile, format=_input_choices[from_format][1], binary=_input_choices[from_format][2]) emb.save(outputfile, format=_output_choices[to_format][1], binary=_output_choices[to_format][2])
python
def convert(outputfile, inputfile, to_format, from_format): """ Convert pretrained word embedding file in one format to another. """ emb = word_embedding.WordEmbedding.load( inputfile, format=_input_choices[from_format][1], binary=_input_choices[from_format][2]) emb.save(outputfile, format=_output_choices[to_format][1], binary=_output_choices[to_format][2])
[ "def", "convert", "(", "outputfile", ",", "inputfile", ",", "to_format", ",", "from_format", ")", ":", "emb", "=", "word_embedding", ".", "WordEmbedding", ".", "load", "(", "inputfile", ",", "format", "=", "_input_choices", "[", "from_format", "]", "[", "1",...
Convert pretrained word embedding file in one format to another.
[ "Convert", "pretrained", "word", "embedding", "file", "in", "one", "format", "to", "another", "." ]
train
https://github.com/koreyou/word_embedding_loader/blob/1bc123f1a8bea12646576dcd768dae3ecea39c06/word_embedding_loader/cli.py#L39-L47
koreyou/word_embedding_loader
word_embedding_loader/cli.py
check_format
def check_format(inputfile): """ Check format of inputfile. """ t = word_embedding.classify_format(inputfile) if t == word_embedding._glove: _echo_format_result('glove') elif t == word_embedding._word2vec_bin: _echo_format_result('word2vec-binary') elif t == word_embedding._word2vec_text: _echo_format_result('word2vec-text') else: assert not "Should not get here!"
python
def check_format(inputfile): """ Check format of inputfile. """ t = word_embedding.classify_format(inputfile) if t == word_embedding._glove: _echo_format_result('glove') elif t == word_embedding._word2vec_bin: _echo_format_result('word2vec-binary') elif t == word_embedding._word2vec_text: _echo_format_result('word2vec-text') else: assert not "Should not get here!"
[ "def", "check_format", "(", "inputfile", ")", ":", "t", "=", "word_embedding", ".", "classify_format", "(", "inputfile", ")", "if", "t", "==", "word_embedding", ".", "_glove", ":", "_echo_format_result", "(", "'glove'", ")", "elif", "t", "==", "word_embedding"...
Check format of inputfile.
[ "Check", "format", "of", "inputfile", "." ]
train
https://github.com/koreyou/word_embedding_loader/blob/1bc123f1a8bea12646576dcd768dae3ecea39c06/word_embedding_loader/cli.py#L56-L68
koreyou/word_embedding_loader
word_embedding_loader/cli.py
list
def list(): """ List available format. """ choice_len = max(map(len, _input_choices.keys())) tmpl = " {:<%d}: {}\n" % choice_len text = ''.join(map( lambda k_v: tmpl.format(k_v[0], k_v[1][0]), six.iteritems(_input_choices))) click.echo(text)
python
def list(): """ List available format. """ choice_len = max(map(len, _input_choices.keys())) tmpl = " {:<%d}: {}\n" % choice_len text = ''.join(map( lambda k_v: tmpl.format(k_v[0], k_v[1][0]), six.iteritems(_input_choices))) click.echo(text)
[ "def", "list", "(", ")", ":", "choice_len", "=", "max", "(", "map", "(", "len", ",", "_input_choices", ".", "keys", "(", ")", ")", ")", "tmpl", "=", "\" {:<%d}: {}\\n\"", "%", "choice_len", "text", "=", "''", ".", "join", "(", "map", "(", "lambda", ...
List available format.
[ "List", "available", "format", "." ]
train
https://github.com/koreyou/word_embedding_loader/blob/1bc123f1a8bea12646576dcd768dae3ecea39c06/word_embedding_loader/cli.py#L72-L80
Parsely/birding
src/birding/twitter.py
main
def main(): """Do the default action of `twitter` command.""" from twitter.cmdline import Action, OPTIONS twitter = Twitter.from_oauth_file() Action()(twitter, OPTIONS)
python
def main(): """Do the default action of `twitter` command.""" from twitter.cmdline import Action, OPTIONS twitter = Twitter.from_oauth_file() Action()(twitter, OPTIONS)
[ "def", "main", "(", ")", ":", "from", "twitter", ".", "cmdline", "import", "Action", ",", "OPTIONS", "twitter", "=", "Twitter", ".", "from_oauth_file", "(", ")", "Action", "(", ")", "(", "twitter", ",", "OPTIONS", ")" ]
Do the default action of `twitter` command.
[ "Do", "the", "default", "action", "of", "twitter", "command", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/twitter.py#L106-L110
Parsely/birding
src/birding/twitter.py
Twitter.from_oauth_file
def from_oauth_file(cls, filepath=None): """Get an object bound to the Twitter API using your own credentials. The `twitter` library ships with a `twitter` command that uses PIN OAuth. Generate your own OAuth credentials by running `twitter` from the shell, which will open a browser window to authenticate you. Once successfully run, even just one time, you will have a credential file at ~/.twitter_oauth. This factory function reuses your credential file to get a `Twitter` object. (Really, this code is just lifted from the `twitter.cmdline` module to minimize OAuth dancing.) """ if filepath is None: # Use default OAuth filepath from `twitter` command-line program. home = os.environ.get('HOME', os.environ.get('USERPROFILE', '')) filepath = os.path.join(home, '.twitter_oauth') oauth_token, oauth_token_secret = read_token_file(filepath) twitter = cls( auth=OAuth( oauth_token, oauth_token_secret, CONSUMER_KEY, CONSUMER_SECRET), api_version='1.1', domain='api.twitter.com') return twitter
python
def from_oauth_file(cls, filepath=None): """Get an object bound to the Twitter API using your own credentials. The `twitter` library ships with a `twitter` command that uses PIN OAuth. Generate your own OAuth credentials by running `twitter` from the shell, which will open a browser window to authenticate you. Once successfully run, even just one time, you will have a credential file at ~/.twitter_oauth. This factory function reuses your credential file to get a `Twitter` object. (Really, this code is just lifted from the `twitter.cmdline` module to minimize OAuth dancing.) """ if filepath is None: # Use default OAuth filepath from `twitter` command-line program. home = os.environ.get('HOME', os.environ.get('USERPROFILE', '')) filepath = os.path.join(home, '.twitter_oauth') oauth_token, oauth_token_secret = read_token_file(filepath) twitter = cls( auth=OAuth( oauth_token, oauth_token_secret, CONSUMER_KEY, CONSUMER_SECRET), api_version='1.1', domain='api.twitter.com') return twitter
[ "def", "from_oauth_file", "(", "cls", ",", "filepath", "=", "None", ")", ":", "if", "filepath", "is", "None", ":", "# Use default OAuth filepath from `twitter` command-line program.", "home", "=", "os", ".", "environ", ".", "get", "(", "'HOME'", ",", "os", ".", ...
Get an object bound to the Twitter API using your own credentials. The `twitter` library ships with a `twitter` command that uses PIN OAuth. Generate your own OAuth credentials by running `twitter` from the shell, which will open a browser window to authenticate you. Once successfully run, even just one time, you will have a credential file at ~/.twitter_oauth. This factory function reuses your credential file to get a `Twitter` object. (Really, this code is just lifted from the `twitter.cmdline` module to minimize OAuth dancing.)
[ "Get", "an", "object", "bound", "to", "the", "Twitter", "API", "using", "your", "own", "credentials", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/twitter.py#L17-L43
Parsely/birding
src/birding/twitter.py
TwitterSearchManager.search
def search(self, q=None, **kw): """Search twitter for ``q``, return `results`__ directly from twitter. __ https://dev.twitter.com/rest/reference/get/search/tweets """ if q is None: raise ValueError('No search query provided for `q` keyword.') return self.twitter.search.tweets(q=q, **kw)
python
def search(self, q=None, **kw): """Search twitter for ``q``, return `results`__ directly from twitter. __ https://dev.twitter.com/rest/reference/get/search/tweets """ if q is None: raise ValueError('No search query provided for `q` keyword.') return self.twitter.search.tweets(q=q, **kw)
[ "def", "search", "(", "self", ",", "q", "=", "None", ",", "*", "*", "kw", ")", ":", "if", "q", "is", "None", ":", "raise", "ValueError", "(", "'No search query provided for `q` keyword.'", ")", "return", "self", ".", "twitter", ".", "search", ".", "tweet...
Search twitter for ``q``, return `results`__ directly from twitter. __ https://dev.twitter.com/rest/reference/get/search/tweets
[ "Search", "twitter", "for", "q", "return", "results", "__", "directly", "from", "twitter", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/twitter.py#L52-L59
Parsely/birding
src/birding/twitter.py
TwitterSearchManager.lookup_search_result
def lookup_search_result(self, result, **kw): """Perform :meth:`lookup` on return value of :meth:`search`.""" return self.lookup(s['id_str'] for s in result['statuses'], **kw)
python
def lookup_search_result(self, result, **kw): """Perform :meth:`lookup` on return value of :meth:`search`.""" return self.lookup(s['id_str'] for s in result['statuses'], **kw)
[ "def", "lookup_search_result", "(", "self", ",", "result", ",", "*", "*", "kw", ")", ":", "return", "self", ".", "lookup", "(", "s", "[", "'id_str'", "]", "for", "s", "in", "result", "[", "'statuses'", "]", ",", "", "**", "kw", ")" ]
Perform :meth:`lookup` on return value of :meth:`search`.
[ "Perform", ":", "meth", ":", "lookup", "on", "return", "value", "of", ":", "meth", ":", "search", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/twitter.py#L61-L63
Parsely/birding
src/birding/twitter.py
TwitterSearchManager.lookup
def lookup(self, id_list, **kw): """Lookup list of statuses, return `results`__ directly from twitter. Input can be any sequence of numeric or string values representing twitter status IDs. __ https://dev.twitter.com/rest/reference/get/statuses/lookup """ result_id_pack = ','.join([str(_id) for _id in id_list]) if not result_id_pack: return [] return self.twitter.statuses.lookup(_id=result_id_pack)
python
def lookup(self, id_list, **kw): """Lookup list of statuses, return `results`__ directly from twitter. Input can be any sequence of numeric or string values representing twitter status IDs. __ https://dev.twitter.com/rest/reference/get/statuses/lookup """ result_id_pack = ','.join([str(_id) for _id in id_list]) if not result_id_pack: return [] return self.twitter.statuses.lookup(_id=result_id_pack)
[ "def", "lookup", "(", "self", ",", "id_list", ",", "*", "*", "kw", ")", ":", "result_id_pack", "=", "','", ".", "join", "(", "[", "str", "(", "_id", ")", "for", "_id", "in", "id_list", "]", ")", "if", "not", "result_id_pack", ":", "return", "[", ...
Lookup list of statuses, return `results`__ directly from twitter. Input can be any sequence of numeric or string values representing twitter status IDs. __ https://dev.twitter.com/rest/reference/get/statuses/lookup
[ "Lookup", "list", "of", "statuses", "return", "results", "__", "directly", "from", "twitter", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/twitter.py#L65-L76
alejoe91/MEAutility
MEAutility/plotting.py
plot_probe
def plot_probe(mea, ax=None, xlim=None, ylim=None, color_currents=False, top=None, bottom=None, cmap='viridis', type='shank', alpha_elec=0.7, alpha_prb=0.3): ''' Parameters ---------- mea axis xlim ylim Returns ------- ''' if ax is None: fig = plt.figure() ax = fig.add_subplot(111) n_elec = mea.positions.shape[0] elec_size = mea.size if mea.type == 'mea': mea_pos = np.array([np.dot(mea.positions, mea.main_axes[0]), np.dot(mea.positions, mea.main_axes[1])]).T min_x, max_x = [np.min(np.dot(mea.positions, mea.main_axes[0])), np.max(np.dot(mea.positions, mea.main_axes[0]))] center_x = (min_x + max_x)/2. min_y, max_y = [np.min(np.dot(mea.positions, mea.main_axes[1])), np.max(np.dot(mea.positions, mea.main_axes[1]))] center_y = (min_y + max_y)/2. if type == 'shank': if top is None: probe_height = 200 else: probe_height = top probe_top = max_y + probe_height if bottom is None: probe_bottom = min_y - probe_height else: probe_bottom = min_y - bottom probe_corner = min_y - 0.1*probe_height probe_left = min_x - 0.1*probe_height probe_right = max_x + 0.1*probe_height verts = [ (min_x - 2*elec_size, probe_top), # left, bottom (min_x - 2*elec_size, probe_corner), # left, top (center_x, probe_bottom), # right, top (max_x + 2*elec_size, probe_corner), # right, bottom (max_x + 2*elec_size, probe_top), (min_x - 2 * elec_size, max_y + 2 * elec_size) # ignored ] codes = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY, ] elif type == 'planar': probe_top = max_y + 2 * elec_size probe_bottom = min_y - 2 * elec_size probe_left = min_x - 2 * elec_size probe_right = max_x + 2 * elec_size verts = [ (min_x - 2 * elec_size, max_y + 2 * elec_size), # left, bottom (min_x - 2 * elec_size, min_y - 2 * elec_size), # left, top (max_x + 2 * elec_size, min_y - 2 * elec_size), # right, bottom (max_x + 2 * elec_size, max_y + 2 * elec_size), # ignored (max_x + 2 * elec_size, max_y + 2 * elec_size) # ignored ] codes = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY, ] else: raise AttributeError("'type' can be 'shank' or 'planar'") path = Path(verts, codes) patch = patches.PathPatch(path, facecolor='green', edgecolor='k', lw=0.5, alpha=alpha_prb) ax.add_patch(patch) if color_currents: norm_curr = mea.currents / np.max(np.abs(mea.currents)) colormap = plt.get_cmap(cmap) elec_colors = colormap(norm_curr) else: elec_colors = ['orange'] * mea.number_electrodes if mea.shape == 'square': for e in range(n_elec): elec = patches.Rectangle((mea_pos[e, 0] - elec_size, mea_pos[e, 1] - elec_size), 2*elec_size, 2*elec_size, alpha=alpha_elec, facecolor=elec_colors[e], edgecolor=[0.3, 0.3, 0.3], lw=0.5) ax.add_patch(elec) elif mea.shape == 'circle': for e in range(n_elec): elec = patches.Circle((mea_pos[e, 0], mea_pos[e, 1]), elec_size, alpha=alpha_elec, facecolor=elec_colors[e], edgecolor=[0.3, 0.3, 0.3], lw=0.5) ax.add_patch(elec) else: raise NotImplementedError('Wire type plotting not implemented') ax.axis('equal') if xlim: ax.set_xlim(xlim) else: ax.set_xlim(probe_left - 5 * elec_size, probe_right + 5 * elec_size) if ylim: ax.set_ylim(ylim) else: ax.set_ylim(probe_bottom - 5 * elec_size, probe_top + 5 * elec_size) return ax
python
def plot_probe(mea, ax=None, xlim=None, ylim=None, color_currents=False, top=None, bottom=None, cmap='viridis', type='shank', alpha_elec=0.7, alpha_prb=0.3): ''' Parameters ---------- mea axis xlim ylim Returns ------- ''' if ax is None: fig = plt.figure() ax = fig.add_subplot(111) n_elec = mea.positions.shape[0] elec_size = mea.size if mea.type == 'mea': mea_pos = np.array([np.dot(mea.positions, mea.main_axes[0]), np.dot(mea.positions, mea.main_axes[1])]).T min_x, max_x = [np.min(np.dot(mea.positions, mea.main_axes[0])), np.max(np.dot(mea.positions, mea.main_axes[0]))] center_x = (min_x + max_x)/2. min_y, max_y = [np.min(np.dot(mea.positions, mea.main_axes[1])), np.max(np.dot(mea.positions, mea.main_axes[1]))] center_y = (min_y + max_y)/2. if type == 'shank': if top is None: probe_height = 200 else: probe_height = top probe_top = max_y + probe_height if bottom is None: probe_bottom = min_y - probe_height else: probe_bottom = min_y - bottom probe_corner = min_y - 0.1*probe_height probe_left = min_x - 0.1*probe_height probe_right = max_x + 0.1*probe_height verts = [ (min_x - 2*elec_size, probe_top), # left, bottom (min_x - 2*elec_size, probe_corner), # left, top (center_x, probe_bottom), # right, top (max_x + 2*elec_size, probe_corner), # right, bottom (max_x + 2*elec_size, probe_top), (min_x - 2 * elec_size, max_y + 2 * elec_size) # ignored ] codes = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY, ] elif type == 'planar': probe_top = max_y + 2 * elec_size probe_bottom = min_y - 2 * elec_size probe_left = min_x - 2 * elec_size probe_right = max_x + 2 * elec_size verts = [ (min_x - 2 * elec_size, max_y + 2 * elec_size), # left, bottom (min_x - 2 * elec_size, min_y - 2 * elec_size), # left, top (max_x + 2 * elec_size, min_y - 2 * elec_size), # right, bottom (max_x + 2 * elec_size, max_y + 2 * elec_size), # ignored (max_x + 2 * elec_size, max_y + 2 * elec_size) # ignored ] codes = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY, ] else: raise AttributeError("'type' can be 'shank' or 'planar'") path = Path(verts, codes) patch = patches.PathPatch(path, facecolor='green', edgecolor='k', lw=0.5, alpha=alpha_prb) ax.add_patch(patch) if color_currents: norm_curr = mea.currents / np.max(np.abs(mea.currents)) colormap = plt.get_cmap(cmap) elec_colors = colormap(norm_curr) else: elec_colors = ['orange'] * mea.number_electrodes if mea.shape == 'square': for e in range(n_elec): elec = patches.Rectangle((mea_pos[e, 0] - elec_size, mea_pos[e, 1] - elec_size), 2*elec_size, 2*elec_size, alpha=alpha_elec, facecolor=elec_colors[e], edgecolor=[0.3, 0.3, 0.3], lw=0.5) ax.add_patch(elec) elif mea.shape == 'circle': for e in range(n_elec): elec = patches.Circle((mea_pos[e, 0], mea_pos[e, 1]), elec_size, alpha=alpha_elec, facecolor=elec_colors[e], edgecolor=[0.3, 0.3, 0.3], lw=0.5) ax.add_patch(elec) else: raise NotImplementedError('Wire type plotting not implemented') ax.axis('equal') if xlim: ax.set_xlim(xlim) else: ax.set_xlim(probe_left - 5 * elec_size, probe_right + 5 * elec_size) if ylim: ax.set_ylim(ylim) else: ax.set_ylim(probe_bottom - 5 * elec_size, probe_top + 5 * elec_size) return ax
[ "def", "plot_probe", "(", "mea", ",", "ax", "=", "None", ",", "xlim", "=", "None", ",", "ylim", "=", "None", ",", "color_currents", "=", "False", ",", "top", "=", "None", ",", "bottom", "=", "None", ",", "cmap", "=", "'viridis'", ",", "type", "=", ...
Parameters ---------- mea axis xlim ylim Returns -------
[ "Parameters", "----------", "mea", "axis", "xlim", "ylim" ]
train
https://github.com/alejoe91/MEAutility/blob/7c2b0da52c2752a3baf04e8e248e26b0769cd088/MEAutility/plotting.py#L16-L143
Parsely/birding
setup.py
get_version
def get_version(filepath='src/birding/version.py'): """Get version without import, which avoids dependency issues.""" with open(get_abspath(filepath)) as version_file: return re.search( r"""__version__\s+=\s+(['"])(?P<version>.+?)\1""", version_file.read()).group('version')
python
def get_version(filepath='src/birding/version.py'): """Get version without import, which avoids dependency issues.""" with open(get_abspath(filepath)) as version_file: return re.search( r"""__version__\s+=\s+(['"])(?P<version>.+?)\1""", version_file.read()).group('version')
[ "def", "get_version", "(", "filepath", "=", "'src/birding/version.py'", ")", ":", "with", "open", "(", "get_abspath", "(", "filepath", ")", ")", "as", "version_file", ":", "return", "re", ".", "search", "(", "r\"\"\"__version__\\s+=\\s+(['\"])(?P<version>.+?)\\1\"\"\"...
Get version without import, which avoids dependency issues.
[ "Get", "version", "without", "import", "which", "avoids", "dependency", "issues", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/setup.py#L72-L77
Parsely/birding
src/birding/gnip.py
Gnip.search
def search(self, q, **kw): """Search Gnip for given query, returning deserialized response.""" url = '{base_url}/search/{stream}'.format(**vars(self)) params = { 'q': q, } params.update(self.params) params.update(kw) response = self.session.get(url, params=params) response.raise_for_status() return response.json()
python
def search(self, q, **kw): """Search Gnip for given query, returning deserialized response.""" url = '{base_url}/search/{stream}'.format(**vars(self)) params = { 'q': q, } params.update(self.params) params.update(kw) response = self.session.get(url, params=params) response.raise_for_status() return response.json()
[ "def", "search", "(", "self", ",", "q", ",", "*", "*", "kw", ")", ":", "url", "=", "'{base_url}/search/{stream}'", ".", "format", "(", "*", "*", "vars", "(", "self", ")", ")", "params", "=", "{", "'q'", ":", "q", ",", "}", "params", ".", "update"...
Search Gnip for given query, returning deserialized response.
[ "Search", "Gnip", "for", "given", "query", "returning", "deserialized", "response", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/gnip.py#L38-L50
Parsely/birding
src/birding/gnip.py
GnipSearchManager.dump
def dump(result): """Dump result into a string, useful for debugging.""" if isinstance(result, dict): # Result is a search result. statuses = result['results'] else: # Result is a lookup result. statuses = result status_str_list = [] for status in statuses: status_str_list.append(textwrap.dedent(u""" @{screen_name} -- https://twitter.com/{screen_name} {text} """).strip().format( screen_name=status['actor']['preferredUsername'], text=status['body'])) return u'\n\n'.join(status_str_list)
python
def dump(result): """Dump result into a string, useful for debugging.""" if isinstance(result, dict): # Result is a search result. statuses = result['results'] else: # Result is a lookup result. statuses = result status_str_list = [] for status in statuses: status_str_list.append(textwrap.dedent(u""" @{screen_name} -- https://twitter.com/{screen_name} {text} """).strip().format( screen_name=status['actor']['preferredUsername'], text=status['body'])) return u'\n\n'.join(status_str_list)
[ "def", "dump", "(", "result", ")", ":", "if", "isinstance", "(", "result", ",", "dict", ")", ":", "# Result is a search result.", "statuses", "=", "result", "[", "'results'", "]", "else", ":", "# Result is a lookup result.", "statuses", "=", "result", "status_st...
Dump result into a string, useful for debugging.
[ "Dump", "result", "into", "a", "string", "useful", "for", "debugging", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/gnip.py#L75-L91
Parsely/birding
src/birding/shelf.py
shelf_from_config
def shelf_from_config(config, **default_init): """Get a `Shelf` instance dynamically based on config. `config` is a dictionary containing ``shelf_*`` keys as defined in :mod:`birding.config`. """ shelf_cls = import_name(config['shelf_class'], default_ns='birding.shelf') init = {} init.update(default_init) init.update(config['shelf_init']) shelf = shelf_cls(**init) if hasattr(shelf, 'set_expiration') and 'shelf_expiration' in config: shelf.set_expiration(config['shelf_expiration']) return shelf
python
def shelf_from_config(config, **default_init): """Get a `Shelf` instance dynamically based on config. `config` is a dictionary containing ``shelf_*`` keys as defined in :mod:`birding.config`. """ shelf_cls = import_name(config['shelf_class'], default_ns='birding.shelf') init = {} init.update(default_init) init.update(config['shelf_init']) shelf = shelf_cls(**init) if hasattr(shelf, 'set_expiration') and 'shelf_expiration' in config: shelf.set_expiration(config['shelf_expiration']) return shelf
[ "def", "shelf_from_config", "(", "config", ",", "*", "*", "default_init", ")", ":", "shelf_cls", "=", "import_name", "(", "config", "[", "'shelf_class'", "]", ",", "default_ns", "=", "'birding.shelf'", ")", "init", "=", "{", "}", "init", ".", "update", "("...
Get a `Shelf` instance dynamically based on config. `config` is a dictionary containing ``shelf_*`` keys as defined in :mod:`birding.config`.
[ "Get", "a", "Shelf", "instance", "dynamically", "based", "on", "config", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/shelf.py#L16-L29
Parsely/birding
src/birding/shelf.py
FreshPacker.unpack
def unpack(self, key, value): """Unpack and return value only if it is fresh.""" value, freshness = value if not self.is_fresh(freshness): raise KeyError('{} (stale)'.format(key)) return value
python
def unpack(self, key, value): """Unpack and return value only if it is fresh.""" value, freshness = value if not self.is_fresh(freshness): raise KeyError('{} (stale)'.format(key)) return value
[ "def", "unpack", "(", "self", ",", "key", ",", "value", ")", ":", "value", ",", "freshness", "=", "value", "if", "not", "self", ".", "is_fresh", "(", "freshness", ")", ":", "raise", "KeyError", "(", "'{} (stale)'", ".", "format", "(", "key", ")", ")"...
Unpack and return value only if it is fresh.
[ "Unpack", "and", "return", "value", "only", "if", "it", "is", "fresh", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/shelf.py#L97-L102
Parsely/birding
src/birding/shelf.py
FreshPacker.is_fresh
def is_fresh(self, freshness): """Return False if given freshness value has expired, else True.""" if self.expire_after is None: return True return self.freshness() - freshness <= self.expire_after
python
def is_fresh(self, freshness): """Return False if given freshness value has expired, else True.""" if self.expire_after is None: return True return self.freshness() - freshness <= self.expire_after
[ "def", "is_fresh", "(", "self", ",", "freshness", ")", ":", "if", "self", ".", "expire_after", "is", "None", ":", "return", "True", "return", "self", ".", "freshness", "(", ")", "-", "freshness", "<=", "self", ".", "expire_after" ]
Return False if given freshness value has expired, else True.
[ "Return", "False", "if", "given", "freshness", "value", "has", "expired", "else", "True", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/shelf.py#L116-L120
ministryofjustice/money-to-prisoners-common
mtp_common/templatetags/mtp_common.py
get_form_errors
def get_form_errors(form): """ Django form errors do not obey natural field order, this template tag returns non-field and field-specific errors :param form: the form instance """ return { 'non_field': form.non_field_errors(), 'field_specific': OrderedDict( (field, form.errors[field.name]) for field in form if field.name in form.errors ) }
python
def get_form_errors(form): """ Django form errors do not obey natural field order, this template tag returns non-field and field-specific errors :param form: the form instance """ return { 'non_field': form.non_field_errors(), 'field_specific': OrderedDict( (field, form.errors[field.name]) for field in form if field.name in form.errors ) }
[ "def", "get_form_errors", "(", "form", ")", ":", "return", "{", "'non_field'", ":", "form", ".", "non_field_errors", "(", ")", ",", "'field_specific'", ":", "OrderedDict", "(", "(", "field", ",", "form", ".", "errors", "[", "field", ".", "name", "]", ")"...
Django form errors do not obey natural field order, this template tag returns non-field and field-specific errors :param form: the form instance
[ "Django", "form", "errors", "do", "not", "obey", "natural", "field", "order", "this", "template", "tag", "returns", "non", "-", "field", "and", "field", "-", "specific", "errors", ":", "param", "form", ":", "the", "form", "instance" ]
train
https://github.com/ministryofjustice/money-to-prisoners-common/blob/33c43a2912cb990d9148da7c8718f480f07d90a1/mtp_common/templatetags/mtp_common.py#L115-L128
ministryofjustice/money-to-prisoners-common
mtp_common/templatetags/mtp_common.py
sub_nav
def sub_nav(context): """ Sub-nav displayed below proposition header - creates alternate language links if SHOW_LANGUAGE_SWITCH is set - takes "breadcrumbs" from the context - takes "breadcrumbs_back" from the context to show a back link *instead* of breadcrumbs """ request = context.get('request') return { 'alt_urls': make_alternate_language_urls(request), 'breadcrumbs': context.get('breadcrumbs'), 'breadcrumbs_back': context.get('breadcrumbs_back'), }
python
def sub_nav(context): """ Sub-nav displayed below proposition header - creates alternate language links if SHOW_LANGUAGE_SWITCH is set - takes "breadcrumbs" from the context - takes "breadcrumbs_back" from the context to show a back link *instead* of breadcrumbs """ request = context.get('request') return { 'alt_urls': make_alternate_language_urls(request), 'breadcrumbs': context.get('breadcrumbs'), 'breadcrumbs_back': context.get('breadcrumbs_back'), }
[ "def", "sub_nav", "(", "context", ")", ":", "request", "=", "context", ".", "get", "(", "'request'", ")", "return", "{", "'alt_urls'", ":", "make_alternate_language_urls", "(", "request", ")", ",", "'breadcrumbs'", ":", "context", ".", "get", "(", "'breadcru...
Sub-nav displayed below proposition header - creates alternate language links if SHOW_LANGUAGE_SWITCH is set - takes "breadcrumbs" from the context - takes "breadcrumbs_back" from the context to show a back link *instead* of breadcrumbs
[ "Sub", "-", "nav", "displayed", "below", "proposition", "header", "-", "creates", "alternate", "language", "links", "if", "SHOW_LANGUAGE_SWITCH", "is", "set", "-", "takes", "breadcrumbs", "from", "the", "context", "-", "takes", "breadcrumbs_back", "from", "the", ...
train
https://github.com/ministryofjustice/money-to-prisoners-common/blob/33c43a2912cb990d9148da7c8718f480f07d90a1/mtp_common/templatetags/mtp_common.py#L166-L178
ministryofjustice/money-to-prisoners-common
mtp_common/stack.py
is_first_instance_aws
def is_first_instance_aws(): """ Returns True if the current instance is the first instance in the ASG group, sorted by instance_id. """ try: # get instance id and aws region instance_details = requests.get('http://169.254.169.254/latest/dynamic/instance-identity/document', timeout=5).json() instance_id = instance_details['instanceId'] instance_region = instance_details['region'] except (requests.RequestException, ValueError, KeyError) as e: raise StackInterrogationException(e) try: # get instance's autoscaling group autoscaling_client = boto3.client('autoscaling', region_name=instance_region) response = autoscaling_client.describe_auto_scaling_instances(InstanceIds=[instance_id]) assert len(response['AutoScalingInstances']) == 1 autoscaling_group = response['AutoScalingInstances'][0]['AutoScalingGroupName'] except ClientError as e: raise StackInterrogationException(e) except AssertionError: raise InstanceNotInAsgException() try: # list in-service instances in autoscaling group # instances being launched or terminated should not be considered response = autoscaling_client.describe_auto_scaling_groups(AutoScalingGroupNames=[autoscaling_group]) assert len(response['AutoScalingGroups']) == 1 autoscaling_group_instance_ids = sorted( instance['InstanceId'] for instance in response['AutoScalingGroups'][0]['Instances'] if instance['LifecycleState'] == 'InService' ) except (ClientError, AssertionError) as e: raise StackInterrogationException(e) return bool(autoscaling_group_instance_ids and autoscaling_group_instance_ids[0] == instance_id)
python
def is_first_instance_aws(): """ Returns True if the current instance is the first instance in the ASG group, sorted by instance_id. """ try: # get instance id and aws region instance_details = requests.get('http://169.254.169.254/latest/dynamic/instance-identity/document', timeout=5).json() instance_id = instance_details['instanceId'] instance_region = instance_details['region'] except (requests.RequestException, ValueError, KeyError) as e: raise StackInterrogationException(e) try: # get instance's autoscaling group autoscaling_client = boto3.client('autoscaling', region_name=instance_region) response = autoscaling_client.describe_auto_scaling_instances(InstanceIds=[instance_id]) assert len(response['AutoScalingInstances']) == 1 autoscaling_group = response['AutoScalingInstances'][0]['AutoScalingGroupName'] except ClientError as e: raise StackInterrogationException(e) except AssertionError: raise InstanceNotInAsgException() try: # list in-service instances in autoscaling group # instances being launched or terminated should not be considered response = autoscaling_client.describe_auto_scaling_groups(AutoScalingGroupNames=[autoscaling_group]) assert len(response['AutoScalingGroups']) == 1 autoscaling_group_instance_ids = sorted( instance['InstanceId'] for instance in response['AutoScalingGroups'][0]['Instances'] if instance['LifecycleState'] == 'InService' ) except (ClientError, AssertionError) as e: raise StackInterrogationException(e) return bool(autoscaling_group_instance_ids and autoscaling_group_instance_ids[0] == instance_id)
[ "def", "is_first_instance_aws", "(", ")", ":", "try", ":", "# get instance id and aws region", "instance_details", "=", "requests", ".", "get", "(", "'http://169.254.169.254/latest/dynamic/instance-identity/document'", ",", "timeout", "=", "5", ")", ".", "json", "(", ")...
Returns True if the current instance is the first instance in the ASG group, sorted by instance_id.
[ "Returns", "True", "if", "the", "current", "instance", "is", "the", "first", "instance", "in", "the", "ASG", "group", "sorted", "by", "instance_id", "." ]
train
https://github.com/ministryofjustice/money-to-prisoners-common/blob/33c43a2912cb990d9148da7c8718f480f07d90a1/mtp_common/stack.py#L33-L71
ministryofjustice/money-to-prisoners-common
mtp_common/stack.py
is_first_instance_k8s
def is_first_instance_k8s(current_pod_name=None): """ Returns True if the current pod is the first replica in Kubernetes cluster. """ current_pod_name = current_pod_name or os.environ.get('POD_NAME') if not current_pod_name: raise StackInterrogationException('Pod name not known') namespace = 'money-to-prisoners-%s' % settings.ENVIRONMENT try: load_incluster_config() except ConfigException as e: raise StackInterrogationException(e) try: response = k8s_client.CoreV1Api().list_namespaced_pod( namespace=namespace, label_selector='app=%s' % settings.APP, watch=False, ) except ApiException as e: raise StackInterrogationException(e) pod_names = sorted(pod.metadata.name for pod in filter(lambda pod: pod.status.phase == 'Running', response.items)) return bool(pod_names and pod_names[0] == current_pod_name)
python
def is_first_instance_k8s(current_pod_name=None): """ Returns True if the current pod is the first replica in Kubernetes cluster. """ current_pod_name = current_pod_name or os.environ.get('POD_NAME') if not current_pod_name: raise StackInterrogationException('Pod name not known') namespace = 'money-to-prisoners-%s' % settings.ENVIRONMENT try: load_incluster_config() except ConfigException as e: raise StackInterrogationException(e) try: response = k8s_client.CoreV1Api().list_namespaced_pod( namespace=namespace, label_selector='app=%s' % settings.APP, watch=False, ) except ApiException as e: raise StackInterrogationException(e) pod_names = sorted(pod.metadata.name for pod in filter(lambda pod: pod.status.phase == 'Running', response.items)) return bool(pod_names and pod_names[0] == current_pod_name)
[ "def", "is_first_instance_k8s", "(", "current_pod_name", "=", "None", ")", ":", "current_pod_name", "=", "current_pod_name", "or", "os", ".", "environ", ".", "get", "(", "'POD_NAME'", ")", "if", "not", "current_pod_name", ":", "raise", "StackInterrogationException",...
Returns True if the current pod is the first replica in Kubernetes cluster.
[ "Returns", "True", "if", "the", "current", "pod", "is", "the", "first", "replica", "in", "Kubernetes", "cluster", "." ]
train
https://github.com/ministryofjustice/money-to-prisoners-common/blob/33c43a2912cb990d9148da7c8718f480f07d90a1/mtp_common/stack.py#L74-L96
harvard-nrg/yaxil
scripts/ArcGet.py
splitarg
def splitarg(args): ''' This function will split arguments separated by spaces or commas to be backwards compatible with the original ArcGet command line tool ''' if not args: return args split = list() for arg in args: if ',' in arg: split.extend([x for x in arg.split(',') if x]) elif arg: split.append(arg) return split
python
def splitarg(args): ''' This function will split arguments separated by spaces or commas to be backwards compatible with the original ArcGet command line tool ''' if not args: return args split = list() for arg in args: if ',' in arg: split.extend([x for x in arg.split(',') if x]) elif arg: split.append(arg) return split
[ "def", "splitarg", "(", "args", ")", ":", "if", "not", "args", ":", "return", "args", "split", "=", "list", "(", ")", "for", "arg", "in", "args", ":", "if", "','", "in", "arg", ":", "split", ".", "extend", "(", "[", "x", "for", "x", "in", "arg"...
This function will split arguments separated by spaces or commas to be backwards compatible with the original ArcGet command line tool
[ "This", "function", "will", "split", "arguments", "separated", "by", "spaces", "or", "commas", "to", "be", "backwards", "compatible", "with", "the", "original", "ArcGet", "command", "line", "tool" ]
train
https://github.com/harvard-nrg/yaxil/blob/af594082258e62d1904d6e6841fce0bb5c0bf309/scripts/ArcGet.py#L152-L165
ministryofjustice/money-to-prisoners-common
mtp_common/auth/views.py
login
def login(request, template_name=None, redirect_field_name=REDIRECT_FIELD_NAME, authentication_form=AuthenticationForm, current_app=None, extra_context=None): """ Displays the login form and handles the login action. """ redirect_to = request.POST.get( redirect_field_name, request.GET.get(redirect_field_name, '') ) def get_redirect_to(): # Ensure the user-originating redirection url is safe. if not is_safe_url(url=redirect_to, host=request.get_host()): return resolve_url(settings.LOGIN_REDIRECT_URL) return redirect_to if request.user.is_authenticated: return HttpResponseRedirect(get_redirect_to()) if request.method == "POST": form = authentication_form(request=request, data=request.POST) if form.is_valid(): # Okay, security check complete. Log the user in. auth_login(request, form.get_user()) return HttpResponseRedirect(get_redirect_to()) else: form = authentication_form(request=request) current_site = get_current_site(request) context = { 'form': form, redirect_field_name: redirect_to, 'site': current_site, 'site_name': current_site.name, } if extra_context is not None: context.update(extra_context) if current_app is not None: request.current_app = current_app return TemplateResponse(request, template_name, context)
python
def login(request, template_name=None, redirect_field_name=REDIRECT_FIELD_NAME, authentication_form=AuthenticationForm, current_app=None, extra_context=None): """ Displays the login form and handles the login action. """ redirect_to = request.POST.get( redirect_field_name, request.GET.get(redirect_field_name, '') ) def get_redirect_to(): # Ensure the user-originating redirection url is safe. if not is_safe_url(url=redirect_to, host=request.get_host()): return resolve_url(settings.LOGIN_REDIRECT_URL) return redirect_to if request.user.is_authenticated: return HttpResponseRedirect(get_redirect_to()) if request.method == "POST": form = authentication_form(request=request, data=request.POST) if form.is_valid(): # Okay, security check complete. Log the user in. auth_login(request, form.get_user()) return HttpResponseRedirect(get_redirect_to()) else: form = authentication_form(request=request) current_site = get_current_site(request) context = { 'form': form, redirect_field_name: redirect_to, 'site': current_site, 'site_name': current_site.name, } if extra_context is not None: context.update(extra_context) if current_app is not None: request.current_app = current_app return TemplateResponse(request, template_name, context)
[ "def", "login", "(", "request", ",", "template_name", "=", "None", ",", "redirect_field_name", "=", "REDIRECT_FIELD_NAME", ",", "authentication_form", "=", "AuthenticationForm", ",", "current_app", "=", "None", ",", "extra_context", "=", "None", ")", ":", "redirec...
Displays the login form and handles the login action.
[ "Displays", "the", "login", "form", "and", "handles", "the", "login", "action", "." ]
train
https://github.com/ministryofjustice/money-to-prisoners-common/blob/33c43a2912cb990d9148da7c8718f480f07d90a1/mtp_common/auth/views.py#L33-L79
ministryofjustice/money-to-prisoners-common
mtp_common/auth/views.py
logout
def logout(request, template_name=None, next_page=None, redirect_field_name=REDIRECT_FIELD_NAME, current_app=None, extra_context=None): """ Logs out the user. """ auth_logout(request) if next_page is not None: next_page = resolve_url(next_page) if (redirect_field_name in request.POST or redirect_field_name in request.GET): next_page = request.POST.get(redirect_field_name, request.GET.get(redirect_field_name)) # Security check -- don't allow redirection to a different host. if not is_safe_url(url=next_page, host=request.get_host()): next_page = request.path if next_page: # Redirect to this page until the session has been cleared. return HttpResponseRedirect(next_page) current_site = get_current_site(request) context = { 'site': current_site, 'site_name': current_site.name, 'title': _('Logged out') } if extra_context is not None: context.update(extra_context) if current_app is not None: request.current_app = current_app return TemplateResponse(request, template_name, context)
python
def logout(request, template_name=None, next_page=None, redirect_field_name=REDIRECT_FIELD_NAME, current_app=None, extra_context=None): """ Logs out the user. """ auth_logout(request) if next_page is not None: next_page = resolve_url(next_page) if (redirect_field_name in request.POST or redirect_field_name in request.GET): next_page = request.POST.get(redirect_field_name, request.GET.get(redirect_field_name)) # Security check -- don't allow redirection to a different host. if not is_safe_url(url=next_page, host=request.get_host()): next_page = request.path if next_page: # Redirect to this page until the session has been cleared. return HttpResponseRedirect(next_page) current_site = get_current_site(request) context = { 'site': current_site, 'site_name': current_site.name, 'title': _('Logged out') } if extra_context is not None: context.update(extra_context) if current_app is not None: request.current_app = current_app return TemplateResponse(request, template_name, context)
[ "def", "logout", "(", "request", ",", "template_name", "=", "None", ",", "next_page", "=", "None", ",", "redirect_field_name", "=", "REDIRECT_FIELD_NAME", ",", "current_app", "=", "None", ",", "extra_context", "=", "None", ")", ":", "auth_logout", "(", "reques...
Logs out the user.
[ "Logs", "out", "the", "user", "." ]
train
https://github.com/ministryofjustice/money-to-prisoners-common/blob/33c43a2912cb990d9148da7c8718f480f07d90a1/mtp_common/auth/views.py#L82-L118
Parsely/birding
src/birding/config.py
get_config
def get_config(filepath=None, default_loader=None, on_missing=None): """Get a dict for the current birding configuration. The resulting dictionary is fully populated with defaults, such that all valid keys will resolve to valid values. Invalid and extra values in the configuration result in an exception. See :ref:`config` (module-level docstring) for discussion on how birding configuration works, including filepath loading. Note that a non-default filepath set via env results in a :py:exc:`OSError` when the file is missing, but the default filepath is ignored when missing. This function caches its return values as to only parse configuration once per set of inputs. As such, treat the resulting dictionary as read-only as not to accidentally write values which will be seen by other handles of the dictionary. Args: filepath (str): path to birding configuration YAML file. default_loader (callable): callable which returns file descriptor with YAML data of default configuration values on_missing (callable): callback to call when file is missing. Returns: dict: dict of current birding configuration; treat as read-only. """ # Handle cache lookup explicitly in order to support keyword arguments. cache_key = (filepath, default_loader, on_missing) if CACHE.get(cache_key) is not None: return CACHE.get(cache_key) logger = logging.getLogger('birding') if filepath is None: filepath = BIRDING_CONF if default_loader is None: default_loader = get_defaults_file if on_missing is None: on_missing = logger.info logger.info( 'Looking for configuration file: {}'.format(os.path.abspath(filepath))) if not os.path.exists(filepath): # Log a message if filepath is default; raise error if not default. on_missing('No {} configuration file found.'.format(filepath)) if filepath != BIRDING_CONF_DEFAULT: # Stat the missing file to result in OSError. os.stat(filepath) config = yaml.safe_load(default_loader()) tv.validate(SCHEMA, config) if os.path.exists(filepath): file_config = yaml.safe_load(open(filepath)) if file_config: config = overlay(file_config, config) tv.validate(SCHEMA, config) CACHE.put(cache_key, config) return config
python
def get_config(filepath=None, default_loader=None, on_missing=None): """Get a dict for the current birding configuration. The resulting dictionary is fully populated with defaults, such that all valid keys will resolve to valid values. Invalid and extra values in the configuration result in an exception. See :ref:`config` (module-level docstring) for discussion on how birding configuration works, including filepath loading. Note that a non-default filepath set via env results in a :py:exc:`OSError` when the file is missing, but the default filepath is ignored when missing. This function caches its return values as to only parse configuration once per set of inputs. As such, treat the resulting dictionary as read-only as not to accidentally write values which will be seen by other handles of the dictionary. Args: filepath (str): path to birding configuration YAML file. default_loader (callable): callable which returns file descriptor with YAML data of default configuration values on_missing (callable): callback to call when file is missing. Returns: dict: dict of current birding configuration; treat as read-only. """ # Handle cache lookup explicitly in order to support keyword arguments. cache_key = (filepath, default_loader, on_missing) if CACHE.get(cache_key) is not None: return CACHE.get(cache_key) logger = logging.getLogger('birding') if filepath is None: filepath = BIRDING_CONF if default_loader is None: default_loader = get_defaults_file if on_missing is None: on_missing = logger.info logger.info( 'Looking for configuration file: {}'.format(os.path.abspath(filepath))) if not os.path.exists(filepath): # Log a message if filepath is default; raise error if not default. on_missing('No {} configuration file found.'.format(filepath)) if filepath != BIRDING_CONF_DEFAULT: # Stat the missing file to result in OSError. os.stat(filepath) config = yaml.safe_load(default_loader()) tv.validate(SCHEMA, config) if os.path.exists(filepath): file_config = yaml.safe_load(open(filepath)) if file_config: config = overlay(file_config, config) tv.validate(SCHEMA, config) CACHE.put(cache_key, config) return config
[ "def", "get_config", "(", "filepath", "=", "None", ",", "default_loader", "=", "None", ",", "on_missing", "=", "None", ")", ":", "# Handle cache lookup explicitly in order to support keyword arguments.", "cache_key", "=", "(", "filepath", ",", "default_loader", ",", "...
Get a dict for the current birding configuration. The resulting dictionary is fully populated with defaults, such that all valid keys will resolve to valid values. Invalid and extra values in the configuration result in an exception. See :ref:`config` (module-level docstring) for discussion on how birding configuration works, including filepath loading. Note that a non-default filepath set via env results in a :py:exc:`OSError` when the file is missing, but the default filepath is ignored when missing. This function caches its return values as to only parse configuration once per set of inputs. As such, treat the resulting dictionary as read-only as not to accidentally write values which will be seen by other handles of the dictionary. Args: filepath (str): path to birding configuration YAML file. default_loader (callable): callable which returns file descriptor with YAML data of default configuration values on_missing (callable): callback to call when file is missing. Returns: dict: dict of current birding configuration; treat as read-only.
[ "Get", "a", "dict", "for", "the", "current", "birding", "configuration", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/config.py#L108-L168
Parsely/birding
src/birding/config.py
get_defaults_file
def get_defaults_file(*a, **kw): """Get a file object with YAML data of configuration defaults. Arguments are passed through to :func:`get_defaults_str`. """ fd = StringIO() fd.write(get_defaults_str(*a, **kw)) fd.seek(0) return fd
python
def get_defaults_file(*a, **kw): """Get a file object with YAML data of configuration defaults. Arguments are passed through to :func:`get_defaults_str`. """ fd = StringIO() fd.write(get_defaults_str(*a, **kw)) fd.seek(0) return fd
[ "def", "get_defaults_file", "(", "*", "a", ",", "*", "*", "kw", ")", ":", "fd", "=", "StringIO", "(", ")", "fd", ".", "write", "(", "get_defaults_str", "(", "*", "a", ",", "*", "*", "kw", ")", ")", "fd", ".", "seek", "(", "0", ")", "return", ...
Get a file object with YAML data of configuration defaults. Arguments are passed through to :func:`get_defaults_str`.
[ "Get", "a", "file", "object", "with", "YAML", "data", "of", "configuration", "defaults", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/config.py#L171-L179
Parsely/birding
src/birding/config.py
get_defaults_str
def get_defaults_str(raw=None, after='Defaults::'): """Get the string YAML representation of configuration defaults.""" if raw is None: raw = __doc__ return unicode(textwrap.dedent(raw.split(after)[-1]).strip())
python
def get_defaults_str(raw=None, after='Defaults::'): """Get the string YAML representation of configuration defaults.""" if raw is None: raw = __doc__ return unicode(textwrap.dedent(raw.split(after)[-1]).strip())
[ "def", "get_defaults_str", "(", "raw", "=", "None", ",", "after", "=", "'Defaults::'", ")", ":", "if", "raw", "is", "None", ":", "raw", "=", "__doc__", "return", "unicode", "(", "textwrap", ".", "dedent", "(", "raw", ".", "split", "(", "after", ")", ...
Get the string YAML representation of configuration defaults.
[ "Get", "the", "string", "YAML", "representation", "of", "configuration", "defaults", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/config.py#L182-L186
Parsely/birding
src/birding/config.py
overlay
def overlay(upper, lower): """Return the overlay of `upper` dict onto `lower` dict. This operation is similar to `dict.update`, but recurses when it encounters a dict/mapping, as to allow nested leaf values in the lower collection which are not in the upper collection. Whenever the upper collection has a value, its value is used. >>> overlay({'a': 0}, {}) {'a': 0} >>> abc = {'a': 0, 'b': 1, 'c': 2} >>> abc == overlay({'a': 0, 'c': 2}, {'a': None, 'b': 1}) True >>> result = {' ': None, '_': abc} >>> result == overlay( ... {'_': {'a': 0, 'c': 2}, ' ': None}, ... {'_': {'a': None, 'b': 1}}) ... True >>> """ result = {} for key in upper: if is_mapping(upper[key]): lower_value = lower.get(key, {}) if not is_mapping(lower_value): msg = 'Attempting to overlay a mapping on a non-mapping: {}' raise ValueError(msg.format(key)) result[key] = overlay(upper[key], lower_value) else: result[key] = upper[key] for key in lower: if key in result: continue result[key] = lower[key] return result
python
def overlay(upper, lower): """Return the overlay of `upper` dict onto `lower` dict. This operation is similar to `dict.update`, but recurses when it encounters a dict/mapping, as to allow nested leaf values in the lower collection which are not in the upper collection. Whenever the upper collection has a value, its value is used. >>> overlay({'a': 0}, {}) {'a': 0} >>> abc = {'a': 0, 'b': 1, 'c': 2} >>> abc == overlay({'a': 0, 'c': 2}, {'a': None, 'b': 1}) True >>> result = {' ': None, '_': abc} >>> result == overlay( ... {'_': {'a': 0, 'c': 2}, ' ': None}, ... {'_': {'a': None, 'b': 1}}) ... True >>> """ result = {} for key in upper: if is_mapping(upper[key]): lower_value = lower.get(key, {}) if not is_mapping(lower_value): msg = 'Attempting to overlay a mapping on a non-mapping: {}' raise ValueError(msg.format(key)) result[key] = overlay(upper[key], lower_value) else: result[key] = upper[key] for key in lower: if key in result: continue result[key] = lower[key] return result
[ "def", "overlay", "(", "upper", ",", "lower", ")", ":", "result", "=", "{", "}", "for", "key", "in", "upper", ":", "if", "is_mapping", "(", "upper", "[", "key", "]", ")", ":", "lower_value", "=", "lower", ".", "get", "(", "key", ",", "{", "}", ...
Return the overlay of `upper` dict onto `lower` dict. This operation is similar to `dict.update`, but recurses when it encounters a dict/mapping, as to allow nested leaf values in the lower collection which are not in the upper collection. Whenever the upper collection has a value, its value is used. >>> overlay({'a': 0}, {}) {'a': 0} >>> abc = {'a': 0, 'b': 1, 'c': 2} >>> abc == overlay({'a': 0, 'c': 2}, {'a': None, 'b': 1}) True >>> result = {' ': None, '_': abc} >>> result == overlay( ... {'_': {'a': 0, 'c': 2}, ' ': None}, ... {'_': {'a': None, 'b': 1}}) ... True >>>
[ "Return", "the", "overlay", "of", "upper", "dict", "onto", "lower", "dict", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/config.py#L189-L224
Parsely/birding
src/birding/config.py
import_name
def import_name(name, default_ns=None): """Import an object based on the dotted string. >>> import_name('textwrap') # doctest: +ELLIPSIS <module 'textwrap' from '...'> >>> import_name('birding.config') # doctest: +ELLIPSIS <module 'birding.config' from '...'> >>> import_name('birding.config.get_config') # doctest: +ELLIPSIS <function get_config at ...> >>> If `ns` is provided, use it as the namespace if `name` does not have a dot. >>> ns = 'birding.config' >>> x = import_name('birding.config.get_config') >>> x # doctest: +ELLIPSIS <function get_config at ...> >>> x == import_name('get_config', default_ns=ns) True >>> x == import_name('birding.config.get_config', default_ns=ns) True >>> """ if '.' not in name: if default_ns is None: return importlib.import_module(name) else: name = default_ns + '.' + name module_name, object_name = name.rsplit('.', 1) module = importlib.import_module(module_name) return getattr(module, object_name)
python
def import_name(name, default_ns=None): """Import an object based on the dotted string. >>> import_name('textwrap') # doctest: +ELLIPSIS <module 'textwrap' from '...'> >>> import_name('birding.config') # doctest: +ELLIPSIS <module 'birding.config' from '...'> >>> import_name('birding.config.get_config') # doctest: +ELLIPSIS <function get_config at ...> >>> If `ns` is provided, use it as the namespace if `name` does not have a dot. >>> ns = 'birding.config' >>> x = import_name('birding.config.get_config') >>> x # doctest: +ELLIPSIS <function get_config at ...> >>> x == import_name('get_config', default_ns=ns) True >>> x == import_name('birding.config.get_config', default_ns=ns) True >>> """ if '.' not in name: if default_ns is None: return importlib.import_module(name) else: name = default_ns + '.' + name module_name, object_name = name.rsplit('.', 1) module = importlib.import_module(module_name) return getattr(module, object_name)
[ "def", "import_name", "(", "name", ",", "default_ns", "=", "None", ")", ":", "if", "'.'", "not", "in", "name", ":", "if", "default_ns", "is", "None", ":", "return", "importlib", ".", "import_module", "(", "name", ")", "else", ":", "name", "=", "default...
Import an object based on the dotted string. >>> import_name('textwrap') # doctest: +ELLIPSIS <module 'textwrap' from '...'> >>> import_name('birding.config') # doctest: +ELLIPSIS <module 'birding.config' from '...'> >>> import_name('birding.config.get_config') # doctest: +ELLIPSIS <function get_config at ...> >>> If `ns` is provided, use it as the namespace if `name` does not have a dot. >>> ns = 'birding.config' >>> x = import_name('birding.config.get_config') >>> x # doctest: +ELLIPSIS <function get_config at ...> >>> x == import_name('get_config', default_ns=ns) True >>> x == import_name('birding.config.get_config', default_ns=ns) True >>>
[ "Import", "an", "object", "based", "on", "the", "dotted", "string", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/config.py#L231-L261
Parsely/birding
src/birding/follow.py
follow_topic_from_config
def follow_topic_from_config(): """Read kafka config, then dispatch to `follow_topic`.""" config = get_config()['ResultTopicBolt'] kafka_class = import_name(config['kafka_class']) return follow_topic(kafka_class, config['topic'], **config['kafka_init'])
python
def follow_topic_from_config(): """Read kafka config, then dispatch to `follow_topic`.""" config = get_config()['ResultTopicBolt'] kafka_class = import_name(config['kafka_class']) return follow_topic(kafka_class, config['topic'], **config['kafka_init'])
[ "def", "follow_topic_from_config", "(", ")", ":", "config", "=", "get_config", "(", ")", "[", "'ResultTopicBolt'", "]", "kafka_class", "=", "import_name", "(", "config", "[", "'kafka_class'", "]", ")", "return", "follow_topic", "(", "kafka_class", ",", "config",...
Read kafka config, then dispatch to `follow_topic`.
[ "Read", "kafka", "config", "then", "dispatch", "to", "follow_topic", "." ]
train
https://github.com/Parsely/birding/blob/c7f6eee56424234e361b1a455595de202e744dac/src/birding/follow.py#L23-L27