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 |
|---|---|---|---|---|---|---|---|---|---|---|
Sheeprider/BitBucket-api | bitbucket/bitbucket.py | Bitbucket.finalize_oauth | def finalize_oauth(self, access_token, access_token_secret):
""" Called internally once auth process is complete. """
self.access_token = access_token
self.access_token_secret = access_token_secret
# Final OAuth object
self.oauth = OAuth1(
self.consumer_key,
... | python | def finalize_oauth(self, access_token, access_token_secret):
""" Called internally once auth process is complete. """
self.access_token = access_token
self.access_token_secret = access_token_secret
# Final OAuth object
self.oauth = OAuth1(
self.consumer_key,
... | [
"def",
"finalize_oauth",
"(",
"self",
",",
"access_token",
",",
"access_token_secret",
")",
":",
"self",
".",
"access_token",
"=",
"access_token",
"self",
".",
"access_token_secret",
"=",
"access_token_secret",
"# Final OAuth object",
"self",
".",
"oauth",
"=",
"OAu... | Called internally once auth process is complete. | [
"Called",
"internally",
"once",
"auth",
"process",
"is",
"complete",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/bitbucket.py#L200-L210 |
Sheeprider/BitBucket-api | bitbucket/bitbucket.py | Bitbucket.dispatch | def dispatch(self, method, url, auth=None, params=None, **kwargs):
""" Send HTTP request, with given method,
credentials and data to the given URL,
and return the success and the result on success.
"""
r = Request(
method=method,
url=url,
... | python | def dispatch(self, method, url, auth=None, params=None, **kwargs):
""" Send HTTP request, with given method,
credentials and data to the given URL,
and return the success and the result on success.
"""
r = Request(
method=method,
url=url,
... | [
"def",
"dispatch",
"(",
"self",
",",
"method",
",",
"url",
",",
"auth",
"=",
"None",
",",
"params",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"r",
"=",
"Request",
"(",
"method",
"=",
"method",
",",
"url",
"=",
"url",
",",
"auth",
"=",
"au... | Send HTTP request, with given method,
credentials and data to the given URL,
and return the success and the result on success. | [
"Send",
"HTTP",
"request",
"with",
"given",
"method",
"credentials",
"and",
"data",
"to",
"the",
"given",
"URL",
"and",
"return",
"the",
"success",
"and",
"the",
"result",
"on",
"success",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/bitbucket.py#L216-L251 |
Sheeprider/BitBucket-api | bitbucket/bitbucket.py | Bitbucket.url | def url(self, action, **kwargs):
""" Construct and return the URL for a specific API service. """
# TODO : should be static method ?
return self.URLS['BASE'] % self.URLS[action] % kwargs | python | def url(self, action, **kwargs):
""" Construct and return the URL for a specific API service. """
# TODO : should be static method ?
return self.URLS['BASE'] % self.URLS[action] % kwargs | [
"def",
"url",
"(",
"self",
",",
"action",
",",
"*",
"*",
"kwargs",
")",
":",
"# TODO : should be static method ?",
"return",
"self",
".",
"URLS",
"[",
"'BASE'",
"]",
"%",
"self",
".",
"URLS",
"[",
"action",
"]",
"%",
"kwargs"
] | Construct and return the URL for a specific API service. | [
"Construct",
"and",
"return",
"the",
"URL",
"for",
"a",
"specific",
"API",
"service",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/bitbucket.py#L253-L256 |
Sheeprider/BitBucket-api | bitbucket/bitbucket.py | Bitbucket.get_user | def get_user(self, username=None):
""" Returns user informations.
If username is not defined, tries to return own informations.
"""
username = username or self.username or ''
url = self.url('GET_USER', username=username)
response = self.dispatch('GET', url)
tr... | python | def get_user(self, username=None):
""" Returns user informations.
If username is not defined, tries to return own informations.
"""
username = username or self.username or ''
url = self.url('GET_USER', username=username)
response = self.dispatch('GET', url)
tr... | [
"def",
"get_user",
"(",
"self",
",",
"username",
"=",
"None",
")",
":",
"username",
"=",
"username",
"or",
"self",
".",
"username",
"or",
"''",
"url",
"=",
"self",
".",
"url",
"(",
"'GET_USER'",
",",
"username",
"=",
"username",
")",
"response",
"=",
... | Returns user informations.
If username is not defined, tries to return own informations. | [
"Returns",
"user",
"informations",
".",
"If",
"username",
"is",
"not",
"defined",
"tries",
"to",
"return",
"own",
"informations",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/bitbucket.py#L262-L273 |
Sheeprider/BitBucket-api | bitbucket/bitbucket.py | Bitbucket.get_tags | def get_tags(self, repo_slug=None):
""" Get a single repository on Bitbucket and return its tags."""
repo_slug = repo_slug or self.repo_slug or ''
url = self.url('GET_TAGS', username=self.username, repo_slug=repo_slug)
return self.dispatch('GET', url, auth=self.auth) | python | def get_tags(self, repo_slug=None):
""" Get a single repository on Bitbucket and return its tags."""
repo_slug = repo_slug or self.repo_slug or ''
url = self.url('GET_TAGS', username=self.username, repo_slug=repo_slug)
return self.dispatch('GET', url, auth=self.auth) | [
"def",
"get_tags",
"(",
"self",
",",
"repo_slug",
"=",
"None",
")",
":",
"repo_slug",
"=",
"repo_slug",
"or",
"self",
".",
"repo_slug",
"or",
"''",
"url",
"=",
"self",
".",
"url",
"(",
"'GET_TAGS'",
",",
"username",
"=",
"self",
".",
"username",
",",
... | Get a single repository on Bitbucket and return its tags. | [
"Get",
"a",
"single",
"repository",
"on",
"Bitbucket",
"and",
"return",
"its",
"tags",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/bitbucket.py#L275-L279 |
Sheeprider/BitBucket-api | bitbucket/bitbucket.py | Bitbucket.get_branches | def get_branches(self, repo_slug=None):
""" Get a single repository on Bitbucket and return its branches."""
repo_slug = repo_slug or self.repo_slug or ''
url = self.url('GET_BRANCHES',
username=self.username,
repo_slug=repo_slug)
return self... | python | def get_branches(self, repo_slug=None):
""" Get a single repository on Bitbucket and return its branches."""
repo_slug = repo_slug or self.repo_slug or ''
url = self.url('GET_BRANCHES',
username=self.username,
repo_slug=repo_slug)
return self... | [
"def",
"get_branches",
"(",
"self",
",",
"repo_slug",
"=",
"None",
")",
":",
"repo_slug",
"=",
"repo_slug",
"or",
"self",
".",
"repo_slug",
"or",
"''",
"url",
"=",
"self",
".",
"url",
"(",
"'GET_BRANCHES'",
",",
"username",
"=",
"self",
".",
"username",
... | Get a single repository on Bitbucket and return its branches. | [
"Get",
"a",
"single",
"repository",
"on",
"Bitbucket",
"and",
"return",
"its",
"branches",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/bitbucket.py#L281-L287 |
Sheeprider/BitBucket-api | bitbucket/bitbucket.py | Bitbucket.get_privileges | def get_privileges(self):
""" Get privledges for this user. """
url = self.url('GET_USER_PRIVILEGES')
return self.dispatch('GET', url, auth=self.auth) | python | def get_privileges(self):
""" Get privledges for this user. """
url = self.url('GET_USER_PRIVILEGES')
return self.dispatch('GET', url, auth=self.auth) | [
"def",
"get_privileges",
"(",
"self",
")",
":",
"url",
"=",
"self",
".",
"url",
"(",
"'GET_USER_PRIVILEGES'",
")",
"return",
"self",
".",
"dispatch",
"(",
"'GET'",
",",
"url",
",",
"auth",
"=",
"self",
".",
"auth",
")"
] | Get privledges for this user. | [
"Get",
"privledges",
"for",
"this",
"user",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/bitbucket.py#L289-L292 |
Sheeprider/BitBucket-api | bitbucket/deploy_key.py | DeployKey.create | def create(self, repo_slug=None, key=None, label=None):
""" Associate an ssh key with your repo and return it.
"""
key = '%s' % key
repo_slug = repo_slug or self.bitbucket.repo_slug or ''
url = self.bitbucket.url('SET_DEPLOY_KEY',
username=self.bi... | python | def create(self, repo_slug=None, key=None, label=None):
""" Associate an ssh key with your repo and return it.
"""
key = '%s' % key
repo_slug = repo_slug or self.bitbucket.repo_slug or ''
url = self.bitbucket.url('SET_DEPLOY_KEY',
username=self.bi... | [
"def",
"create",
"(",
"self",
",",
"repo_slug",
"=",
"None",
",",
"key",
"=",
"None",
",",
"label",
"=",
"None",
")",
":",
"key",
"=",
"'%s'",
"%",
"key",
"repo_slug",
"=",
"repo_slug",
"or",
"self",
".",
"bitbucket",
".",
"repo_slug",
"or",
"''",
... | Associate an ssh key with your repo and return it. | [
"Associate",
"an",
"ssh",
"key",
"with",
"your",
"repo",
"and",
"return",
"it",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/deploy_key.py#L37-L49 |
Sheeprider/BitBucket-api | bitbucket/repository.py | Repository.public | def public(self, username=None):
""" Returns all public repositories from an user.
If username is not defined, tries to return own public repos.
"""
username = username or self.bitbucket.username or ''
url = self.bitbucket.url('GET_USER', username=username)
response =... | python | def public(self, username=None):
""" Returns all public repositories from an user.
If username is not defined, tries to return own public repos.
"""
username = username or self.bitbucket.username or ''
url = self.bitbucket.url('GET_USER', username=username)
response =... | [
"def",
"public",
"(",
"self",
",",
"username",
"=",
"None",
")",
":",
"username",
"=",
"username",
"or",
"self",
".",
"bitbucket",
".",
"username",
"or",
"''",
"url",
"=",
"self",
".",
"bitbucket",
".",
"url",
"(",
"'GET_USER'",
",",
"username",
"=",
... | Returns all public repositories from an user.
If username is not defined, tries to return own public repos. | [
"Returns",
"all",
"public",
"repositories",
"from",
"an",
"user",
".",
"If",
"username",
"is",
"not",
"defined",
"tries",
"to",
"return",
"own",
"public",
"repos",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/repository.py#L50-L61 |
Sheeprider/BitBucket-api | bitbucket/repository.py | Repository.all | def all(self):
""" Return own repositories."""
url = self.bitbucket.url('GET_USER', username=self.bitbucket.username)
response = self.bitbucket.dispatch('GET', url, auth=self.bitbucket.auth)
try:
return (response[0], response[1]['repositories'])
except TypeError:
... | python | def all(self):
""" Return own repositories."""
url = self.bitbucket.url('GET_USER', username=self.bitbucket.username)
response = self.bitbucket.dispatch('GET', url, auth=self.bitbucket.auth)
try:
return (response[0], response[1]['repositories'])
except TypeError:
... | [
"def",
"all",
"(",
"self",
")",
":",
"url",
"=",
"self",
".",
"bitbucket",
".",
"url",
"(",
"'GET_USER'",
",",
"username",
"=",
"self",
".",
"bitbucket",
".",
"username",
")",
"response",
"=",
"self",
".",
"bitbucket",
".",
"dispatch",
"(",
"'GET'",
... | Return own repositories. | [
"Return",
"own",
"repositories",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/repository.py#L63-L71 |
Sheeprider/BitBucket-api | bitbucket/repository.py | Repository.create | def create(self, repo_name, scm='git', private=True, **kwargs):
""" Creates a new repository on own Bitbucket account and return it."""
url = self.bitbucket.url('CREATE_REPO')
return self.bitbucket.dispatch('POST', url, auth=self.bitbucket.auth, name=repo_name, scm=scm, is_private=private, **kwa... | python | def create(self, repo_name, scm='git', private=True, **kwargs):
""" Creates a new repository on own Bitbucket account and return it."""
url = self.bitbucket.url('CREATE_REPO')
return self.bitbucket.dispatch('POST', url, auth=self.bitbucket.auth, name=repo_name, scm=scm, is_private=private, **kwa... | [
"def",
"create",
"(",
"self",
",",
"repo_name",
",",
"scm",
"=",
"'git'",
",",
"private",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"url",
"=",
"self",
".",
"bitbucket",
".",
"url",
"(",
"'CREATE_REPO'",
")",
"return",
"self",
".",
"bitbucket",... | Creates a new repository on own Bitbucket account and return it. | [
"Creates",
"a",
"new",
"repository",
"on",
"own",
"Bitbucket",
"account",
"and",
"return",
"it",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/repository.py#L79-L82 |
Sheeprider/BitBucket-api | bitbucket/repository.py | Repository.archive | def archive(self, repo_slug=None, format='zip', prefix=''):
""" Get one of your repositories and compress it as an archive.
Return the path of the archive.
format parameter is curently not supported.
"""
prefix = '%s'.lstrip('/') % prefix
self._get_files_in_dir(r... | python | def archive(self, repo_slug=None, format='zip', prefix=''):
""" Get one of your repositories and compress it as an archive.
Return the path of the archive.
format parameter is curently not supported.
"""
prefix = '%s'.lstrip('/') % prefix
self._get_files_in_dir(r... | [
"def",
"archive",
"(",
"self",
",",
"repo_slug",
"=",
"None",
",",
"format",
"=",
"'zip'",
",",
"prefix",
"=",
"''",
")",
":",
"prefix",
"=",
"'%s'",
".",
"lstrip",
"(",
"'/'",
")",
"%",
"prefix",
"self",
".",
"_get_files_in_dir",
"(",
"repo_slug",
"... | Get one of your repositories and compress it as an archive.
Return the path of the archive.
format parameter is curently not supported. | [
"Get",
"one",
"of",
"your",
"repositories",
"and",
"compress",
"it",
"as",
"an",
"archive",
".",
"Return",
"the",
"path",
"of",
"the",
"archive",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/repository.py#L98-L114 |
Sheeprider/BitBucket-api | bitbucket/issue_comment.py | IssueComment.create | def create(self, issue_id=None, repo_slug=None, **kwargs):
""" Add an issue comment to one of your repositories.
Each issue comment require only the content data field
the system autopopulate the rest.
"""
issue_id = issue_id or self.issue_id
repo_slug = repo_slug... | python | def create(self, issue_id=None, repo_slug=None, **kwargs):
""" Add an issue comment to one of your repositories.
Each issue comment require only the content data field
the system autopopulate the rest.
"""
issue_id = issue_id or self.issue_id
repo_slug = repo_slug... | [
"def",
"create",
"(",
"self",
",",
"issue_id",
"=",
"None",
",",
"repo_slug",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"issue_id",
"=",
"issue_id",
"or",
"self",
".",
"issue_id",
"repo_slug",
"=",
"repo_slug",
"or",
"self",
".",
"bitbucket",
"."... | Add an issue comment to one of your repositories.
Each issue comment require only the content data field
the system autopopulate the rest. | [
"Add",
"an",
"issue",
"comment",
"to",
"one",
"of",
"your",
"repositories",
".",
"Each",
"issue",
"comment",
"require",
"only",
"the",
"content",
"data",
"field",
"the",
"system",
"autopopulate",
"the",
"rest",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/issue_comment.py#L44-L55 |
Sheeprider/BitBucket-api | bitbucket/issue_comment.py | IssueComment.delete | def delete(self, comment_id, issue_id=None, repo_slug=None):
""" Delete an issue from one of your repositories.
"""
issue_id = issue_id or self.issue_id
repo_slug = repo_slug or self.bitbucket.repo_slug or ''
url = self.bitbucket.url('DELETE_COMMENT',
... | python | def delete(self, comment_id, issue_id=None, repo_slug=None):
""" Delete an issue from one of your repositories.
"""
issue_id = issue_id or self.issue_id
repo_slug = repo_slug or self.bitbucket.repo_slug or ''
url = self.bitbucket.url('DELETE_COMMENT',
... | [
"def",
"delete",
"(",
"self",
",",
"comment_id",
",",
"issue_id",
"=",
"None",
",",
"repo_slug",
"=",
"None",
")",
":",
"issue_id",
"=",
"issue_id",
"or",
"self",
".",
"issue_id",
"repo_slug",
"=",
"repo_slug",
"or",
"self",
".",
"bitbucket",
".",
"repo_... | Delete an issue from one of your repositories. | [
"Delete",
"an",
"issue",
"from",
"one",
"of",
"your",
"repositories",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/issue_comment.py#L71-L81 |
Sheeprider/BitBucket-api | bitbucket/ssh.py | SSH.all | def all(self):
""" Get all ssh keys associated with your account.
"""
url = self.bitbucket.url('GET_SSH_KEYS')
return self.bitbucket.dispatch('GET', url, auth=self.bitbucket.auth) | python | def all(self):
""" Get all ssh keys associated with your account.
"""
url = self.bitbucket.url('GET_SSH_KEYS')
return self.bitbucket.dispatch('GET', url, auth=self.bitbucket.auth) | [
"def",
"all",
"(",
"self",
")",
":",
"url",
"=",
"self",
".",
"bitbucket",
".",
"url",
"(",
"'GET_SSH_KEYS'",
")",
"return",
"self",
".",
"bitbucket",
".",
"dispatch",
"(",
"'GET'",
",",
"url",
",",
"auth",
"=",
"self",
".",
"bitbucket",
".",
"auth",... | Get all ssh keys associated with your account. | [
"Get",
"all",
"ssh",
"keys",
"associated",
"with",
"your",
"account",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/ssh.py#L18-L22 |
Sheeprider/BitBucket-api | bitbucket/ssh.py | SSH.get | def get(self, key_id=None):
""" Get one of the ssh keys associated with your account.
"""
url = self.bitbucket.url('GET_SSH_KEY', key_id=key_id)
return self.bitbucket.dispatch('GET', url, auth=self.bitbucket.auth) | python | def get(self, key_id=None):
""" Get one of the ssh keys associated with your account.
"""
url = self.bitbucket.url('GET_SSH_KEY', key_id=key_id)
return self.bitbucket.dispatch('GET', url, auth=self.bitbucket.auth) | [
"def",
"get",
"(",
"self",
",",
"key_id",
"=",
"None",
")",
":",
"url",
"=",
"self",
".",
"bitbucket",
".",
"url",
"(",
"'GET_SSH_KEY'",
",",
"key_id",
"=",
"key_id",
")",
"return",
"self",
".",
"bitbucket",
".",
"dispatch",
"(",
"'GET'",
",",
"url",... | Get one of the ssh keys associated with your account. | [
"Get",
"one",
"of",
"the",
"ssh",
"keys",
"associated",
"with",
"your",
"account",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/ssh.py#L24-L28 |
Sheeprider/BitBucket-api | bitbucket/ssh.py | SSH.create | def create(self, key=None, label=None):
""" Associate an ssh key with your account and return it.
"""
key = '%s' % key
url = self.bitbucket.url('SET_SSH_KEY')
return self.bitbucket.dispatch('POST', url, auth=self.bitbucket.auth, key=key, label=label) | python | def create(self, key=None, label=None):
""" Associate an ssh key with your account and return it.
"""
key = '%s' % key
url = self.bitbucket.url('SET_SSH_KEY')
return self.bitbucket.dispatch('POST', url, auth=self.bitbucket.auth, key=key, label=label) | [
"def",
"create",
"(",
"self",
",",
"key",
"=",
"None",
",",
"label",
"=",
"None",
")",
":",
"key",
"=",
"'%s'",
"%",
"key",
"url",
"=",
"self",
".",
"bitbucket",
".",
"url",
"(",
"'SET_SSH_KEY'",
")",
"return",
"self",
".",
"bitbucket",
".",
"dispa... | Associate an ssh key with your account and return it. | [
"Associate",
"an",
"ssh",
"key",
"with",
"your",
"account",
"and",
"return",
"it",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/ssh.py#L30-L35 |
Sheeprider/BitBucket-api | bitbucket/ssh.py | SSH.delete | def delete(self, key_id=None):
""" Delete one of the ssh keys associated with your account.
Please use with caution as there is NO confimation and NO undo.
"""
url = self.bitbucket.url('DELETE_SSH_KEY', key_id=key_id)
return self.bitbucket.dispatch('DELETE', url, auth=self.bi... | python | def delete(self, key_id=None):
""" Delete one of the ssh keys associated with your account.
Please use with caution as there is NO confimation and NO undo.
"""
url = self.bitbucket.url('DELETE_SSH_KEY', key_id=key_id)
return self.bitbucket.dispatch('DELETE', url, auth=self.bi... | [
"def",
"delete",
"(",
"self",
",",
"key_id",
"=",
"None",
")",
":",
"url",
"=",
"self",
".",
"bitbucket",
".",
"url",
"(",
"'DELETE_SSH_KEY'",
",",
"key_id",
"=",
"key_id",
")",
"return",
"self",
".",
"bitbucket",
".",
"dispatch",
"(",
"'DELETE'",
",",... | Delete one of the ssh keys associated with your account.
Please use with caution as there is NO confimation and NO undo. | [
"Delete",
"one",
"of",
"the",
"ssh",
"keys",
"associated",
"with",
"your",
"account",
".",
"Please",
"use",
"with",
"caution",
"as",
"there",
"is",
"NO",
"confimation",
"and",
"NO",
"undo",
"."
] | train | https://github.com/Sheeprider/BitBucket-api/blob/be45515d506d87f14807a676f3c2f20d79674b75/bitbucket/ssh.py#L37-L42 |
todddeluca/python-vagrant | vagrant/__init__.py | which | def which(program):
'''
Emulate unix 'which' command. If program is a path to an executable file
(i.e. it contains any directory components, like './myscript'), return
program. Otherwise, if an executable file matching program is found in one
of the directories in the PATH environment variable, re... | python | def which(program):
'''
Emulate unix 'which' command. If program is a path to an executable file
(i.e. it contains any directory components, like './myscript'), return
program. Otherwise, if an executable file matching program is found in one
of the directories in the PATH environment variable, re... | [
"def",
"which",
"(",
"program",
")",
":",
"def",
"is_exe",
"(",
"fpath",
")",
":",
"return",
"os",
".",
"path",
".",
"isfile",
"(",
"fpath",
")",
"and",
"os",
".",
"access",
"(",
"fpath",
",",
"os",
".",
"X_OK",
")",
"# Shortcut: If program contains an... | Emulate unix 'which' command. If program is a path to an executable file
(i.e. it contains any directory components, like './myscript'), return
program. Otherwise, if an executable file matching program is found in one
of the directories in the PATH environment variable, return the first match
found.
... | [
"Emulate",
"unix",
"which",
"command",
".",
"If",
"program",
"is",
"a",
"path",
"to",
"an",
"executable",
"file",
"(",
"i",
".",
"e",
".",
"it",
"contains",
"any",
"directory",
"components",
"like",
".",
"/",
"myscript",
")",
"return",
"program",
".",
... | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L42-L124 |
todddeluca/python-vagrant | vagrant/__init__.py | make_file_cm | def make_file_cm(filename, mode='a'):
'''
Open a file for appending and yield the open filehandle. Close the
filehandle after yielding it. This is useful for creating a context
manager for logging the output of a `Vagrant` instance.
filename: a path to a file
mode: The mode in which to open ... | python | def make_file_cm(filename, mode='a'):
'''
Open a file for appending and yield the open filehandle. Close the
filehandle after yielding it. This is useful for creating a context
manager for logging the output of a `Vagrant` instance.
filename: a path to a file
mode: The mode in which to open ... | [
"def",
"make_file_cm",
"(",
"filename",
",",
"mode",
"=",
"'a'",
")",
":",
"@",
"contextlib",
".",
"contextmanager",
"def",
"cm",
"(",
")",
":",
"with",
"open",
"(",
"filename",
",",
"mode",
"=",
"mode",
")",
"as",
"fh",
":",
"yield",
"fh",
"return",... | Open a file for appending and yield the open filehandle. Close the
filehandle after yielding it. This is useful for creating a context
manager for logging the output of a `Vagrant` instance.
filename: a path to a file
mode: The mode in which to open the file. Defaults to 'a', append
Usage exam... | [
"Open",
"a",
"file",
"for",
"appending",
"and",
"yield",
"the",
"open",
"filehandle",
".",
"Close",
"the",
"filehandle",
"after",
"yielding",
"it",
".",
"This",
"is",
"useful",
"for",
"creating",
"a",
"context",
"manager",
"for",
"logging",
"the",
"output",
... | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L171-L190 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant.version | def version(self):
'''
Return the installed vagrant version, as a string, e.g. '1.5.0'
'''
output = self._run_vagrant_command(['--version'])
m = re.search(r'^Vagrant (?P<version>.+)$', output)
if m is None:
raise Exception('Failed to parse vagrant --version ou... | python | def version(self):
'''
Return the installed vagrant version, as a string, e.g. '1.5.0'
'''
output = self._run_vagrant_command(['--version'])
m = re.search(r'^Vagrant (?P<version>.+)$', output)
if m is None:
raise Exception('Failed to parse vagrant --version ou... | [
"def",
"version",
"(",
"self",
")",
":",
"output",
"=",
"self",
".",
"_run_vagrant_command",
"(",
"[",
"'--version'",
"]",
")",
"m",
"=",
"re",
".",
"search",
"(",
"r'^Vagrant (?P<version>.+)$'",
",",
"output",
")",
"if",
"m",
"is",
"None",
":",
"raise",... | Return the installed vagrant version, as a string, e.g. '1.5.0' | [
"Return",
"the",
"installed",
"vagrant",
"version",
"as",
"a",
"string",
"e",
".",
"g",
".",
"1",
".",
"5",
".",
"0"
] | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L276-L284 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant.up | def up(self, no_provision=False, provider=None, vm_name=None,
provision=None, provision_with=None, stream_output=False):
'''
Invoke `vagrant up` to start a box or boxes, possibly streaming the
command output.
vm_name=None: name of VM.
provision_with: optional list of p... | python | def up(self, no_provision=False, provider=None, vm_name=None,
provision=None, provision_with=None, stream_output=False):
'''
Invoke `vagrant up` to start a box or boxes, possibly streaming the
command output.
vm_name=None: name of VM.
provision_with: optional list of p... | [
"def",
"up",
"(",
"self",
",",
"no_provision",
"=",
"False",
",",
"provider",
"=",
"None",
",",
"vm_name",
"=",
"None",
",",
"provision",
"=",
"None",
",",
"provision_with",
"=",
"None",
",",
"stream_output",
"=",
"False",
")",
":",
"provider_arg",
"=",
... | Invoke `vagrant up` to start a box or boxes, possibly streaming the
command output.
vm_name=None: name of VM.
provision_with: optional list of provisioners to enable.
provider: Back the machine with a specific provider
no_provision: if True, disable provisioning. Same as 'provis... | [
"Invoke",
"vagrant",
"up",
"to",
"start",
"a",
"box",
"or",
"boxes",
"possibly",
"streaming",
"the",
"command",
"output",
".",
"vm_name",
"=",
"None",
":",
"name",
"of",
"VM",
".",
"provision_with",
":",
"optional",
"list",
"of",
"provisioners",
"to",
"ena... | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L302-L340 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant.provision | def provision(self, vm_name=None, provision_with=None):
'''
Runs the provisioners defined in the Vagrantfile.
vm_name: optional VM name string.
provision_with: optional list of provisioners to enable.
e.g. ['shell', 'chef_solo']
'''
prov_with_arg = None if provi... | python | def provision(self, vm_name=None, provision_with=None):
'''
Runs the provisioners defined in the Vagrantfile.
vm_name: optional VM name string.
provision_with: optional list of provisioners to enable.
e.g. ['shell', 'chef_solo']
'''
prov_with_arg = None if provi... | [
"def",
"provision",
"(",
"self",
",",
"vm_name",
"=",
"None",
",",
"provision_with",
"=",
"None",
")",
":",
"prov_with_arg",
"=",
"None",
"if",
"provision_with",
"is",
"None",
"else",
"'--provision-with'",
"providers_arg",
"=",
"None",
"if",
"provision_with",
... | Runs the provisioners defined in the Vagrantfile.
vm_name: optional VM name string.
provision_with: optional list of provisioners to enable.
e.g. ['shell', 'chef_solo'] | [
"Runs",
"the",
"provisioners",
"defined",
"in",
"the",
"Vagrantfile",
".",
"vm_name",
":",
"optional",
"VM",
"name",
"string",
".",
"provision_with",
":",
"optional",
"list",
"of",
"provisioners",
"to",
"enable",
".",
"e",
".",
"g",
".",
"[",
"shell",
"che... | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L342-L352 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant.reload | def reload(self, vm_name=None, provision=None, provision_with=None,
stream_output=False):
'''
Quoting from Vagrant docs:
> The equivalent of running a halt followed by an up.
> This command is usually required for changes made in the Vagrantfile
to take effect. A... | python | def reload(self, vm_name=None, provision=None, provision_with=None,
stream_output=False):
'''
Quoting from Vagrant docs:
> The equivalent of running a halt followed by an up.
> This command is usually required for changes made in the Vagrantfile
to take effect. A... | [
"def",
"reload",
"(",
"self",
",",
"vm_name",
"=",
"None",
",",
"provision",
"=",
"None",
",",
"provision_with",
"=",
"None",
",",
"stream_output",
"=",
"False",
")",
":",
"prov_with_arg",
"=",
"None",
"if",
"provision_with",
"is",
"None",
"else",
"'--prov... | Quoting from Vagrant docs:
> The equivalent of running a halt followed by an up.
> This command is usually required for changes made in the Vagrantfile
to take effect. After making any modifications to the Vagrantfile, a
reload should be called.
> The configured provisioners ... | [
"Quoting",
"from",
"Vagrant",
"docs",
":",
">",
"The",
"equivalent",
"of",
"running",
"a",
"halt",
"followed",
"by",
"an",
"up",
".",
">",
"This",
"command",
"is",
"usually",
"required",
"for",
"changes",
"made",
"in",
"the",
"Vagrantfile",
"to",
"take",
... | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L354-L387 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant.halt | def halt(self, vm_name=None, force=False):
'''
Halt the Vagrant box.
force: If True, force shut down.
'''
force_opt = '--force' if force else None
self._call_vagrant_command(['halt', vm_name, force_opt])
self._cached_conf[vm_name] = None | python | def halt(self, vm_name=None, force=False):
'''
Halt the Vagrant box.
force: If True, force shut down.
'''
force_opt = '--force' if force else None
self._call_vagrant_command(['halt', vm_name, force_opt])
self._cached_conf[vm_name] = None | [
"def",
"halt",
"(",
"self",
",",
"vm_name",
"=",
"None",
",",
"force",
"=",
"False",
")",
":",
"force_opt",
"=",
"'--force'",
"if",
"force",
"else",
"None",
"self",
".",
"_call_vagrant_command",
"(",
"[",
"'halt'",
",",
"vm_name",
",",
"force_opt",
"]",
... | Halt the Vagrant box.
force: If True, force shut down. | [
"Halt",
"the",
"Vagrant",
"box",
"."
] | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L403-L411 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant.status | def status(self, vm_name=None):
'''
Return the results of a `vagrant status` call as a list of one or more
Status objects. A Status contains the following attributes:
- name: The VM name in a multi-vm environment. 'default' otherwise.
- state: The state of the underlying guest... | python | def status(self, vm_name=None):
'''
Return the results of a `vagrant status` call as a list of one or more
Status objects. A Status contains the following attributes:
- name: The VM name in a multi-vm environment. 'default' otherwise.
- state: The state of the underlying guest... | [
"def",
"status",
"(",
"self",
",",
"vm_name",
"=",
"None",
")",
":",
"# machine-readable output are CSV lines",
"output",
"=",
"self",
".",
"_run_vagrant_command",
"(",
"[",
"'status'",
",",
"'--machine-readable'",
",",
"vm_name",
"]",
")",
"return",
"self",
"."... | Return the results of a `vagrant status` call as a list of one or more
Status objects. A Status contains the following attributes:
- name: The VM name in a multi-vm environment. 'default' otherwise.
- state: The state of the underlying guest machine (i.e. VM).
- provider: the name of ... | [
"Return",
"the",
"results",
"of",
"a",
"vagrant",
"status",
"call",
"as",
"a",
"list",
"of",
"one",
"or",
"more",
"Status",
"objects",
".",
"A",
"Status",
"contains",
"the",
"following",
"attributes",
":"
] | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L420-L494 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant._parse_status | def _parse_status(self, output):
'''
Unit testing is so much easier when Vagrant is removed from the
equation.
'''
parsed = self._parse_machine_readable_output(output)
statuses = []
# group tuples by target name
# assuming tuples are sorted by target name,... | python | def _parse_status(self, output):
'''
Unit testing is so much easier when Vagrant is removed from the
equation.
'''
parsed = self._parse_machine_readable_output(output)
statuses = []
# group tuples by target name
# assuming tuples are sorted by target name,... | [
"def",
"_parse_status",
"(",
"self",
",",
"output",
")",
":",
"parsed",
"=",
"self",
".",
"_parse_machine_readable_output",
"(",
"output",
")",
"statuses",
"=",
"[",
"]",
"# group tuples by target name",
"# assuming tuples are sorted by target name, this should group all",
... | Unit testing is so much easier when Vagrant is removed from the
equation. | [
"Unit",
"testing",
"is",
"so",
"much",
"easier",
"when",
"Vagrant",
"is",
"removed",
"from",
"the",
"equation",
"."
] | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L496-L513 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant.conf | def conf(self, ssh_config=None, vm_name=None):
'''
Parse ssh_config into a dict containing the keys defined in ssh_config,
which should include these keys (listed with example values): 'User'
(e.g. 'vagrant'), 'HostName' (e.g. 'localhost'), 'Port' (e.g. '2222'),
'IdentityFile' (... | python | def conf(self, ssh_config=None, vm_name=None):
'''
Parse ssh_config into a dict containing the keys defined in ssh_config,
which should include these keys (listed with example values): 'User'
(e.g. 'vagrant'), 'HostName' (e.g. 'localhost'), 'Port' (e.g. '2222'),
'IdentityFile' (... | [
"def",
"conf",
"(",
"self",
",",
"ssh_config",
"=",
"None",
",",
"vm_name",
"=",
"None",
")",
":",
"if",
"self",
".",
"_cached_conf",
".",
"get",
"(",
"vm_name",
")",
"is",
"None",
"or",
"ssh_config",
"is",
"not",
"None",
":",
"if",
"ssh_config",
"is... | Parse ssh_config into a dict containing the keys defined in ssh_config,
which should include these keys (listed with example values): 'User'
(e.g. 'vagrant'), 'HostName' (e.g. 'localhost'), 'Port' (e.g. '2222'),
'IdentityFile' (e.g. '/home/todd/.ssh/id_dsa'). Cache the parsed
configura... | [
"Parse",
"ssh_config",
"into",
"a",
"dict",
"containing",
"the",
"keys",
"defined",
"in",
"ssh_config",
"which",
"should",
"include",
"these",
"keys",
"(",
"listed",
"with",
"example",
"values",
")",
":",
"User",
"(",
"e",
".",
"g",
".",
"vagrant",
")",
... | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L515-L543 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant.user_hostname | def user_hostname(self, vm_name=None):
'''
Return a string combining user and hostname, e.g. 'vagrant@127.0.0.1'.
This string is suitable for use in an ssh commmand. If user is None
or empty, it will be left out of the string, e.g. 'localhost'. If
hostname is None, have bigger ... | python | def user_hostname(self, vm_name=None):
'''
Return a string combining user and hostname, e.g. 'vagrant@127.0.0.1'.
This string is suitable for use in an ssh commmand. If user is None
or empty, it will be left out of the string, e.g. 'localhost'. If
hostname is None, have bigger ... | [
"def",
"user_hostname",
"(",
"self",
",",
"vm_name",
"=",
"None",
")",
":",
"user",
"=",
"self",
".",
"user",
"(",
"vm_name",
"=",
"vm_name",
")",
"user_prefix",
"=",
"user",
"+",
"'@'",
"if",
"user",
"else",
"''",
"return",
"user_prefix",
"+",
"self",... | Return a string combining user and hostname, e.g. 'vagrant@127.0.0.1'.
This string is suitable for use in an ssh commmand. If user is None
or empty, it will be left out of the string, e.g. 'localhost'. If
hostname is None, have bigger problems.
Raises an Exception if the Vagrant box h... | [
"Return",
"a",
"string",
"combining",
"user",
"and",
"hostname",
"e",
".",
"g",
".",
"vagrant@127",
".",
"0",
".",
"0",
".",
"1",
".",
"This",
"string",
"is",
"suitable",
"for",
"use",
"in",
"an",
"ssh",
"commmand",
".",
"If",
"user",
"is",
"None",
... | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L611-L623 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant.user_hostname_port | def user_hostname_port(self, vm_name=None):
'''
Return a string combining user, hostname and port, e.g.
'vagrant@127.0.0.1:2222'. This string is suitable for use with Fabric,
in env.hosts. If user or port is None or empty, they will be left
out of the string. E.g. 'vagrant@loc... | python | def user_hostname_port(self, vm_name=None):
'''
Return a string combining user, hostname and port, e.g.
'vagrant@127.0.0.1:2222'. This string is suitable for use with Fabric,
in env.hosts. If user or port is None or empty, they will be left
out of the string. E.g. 'vagrant@loc... | [
"def",
"user_hostname_port",
"(",
"self",
",",
"vm_name",
"=",
"None",
")",
":",
"user",
"=",
"self",
".",
"user",
"(",
"vm_name",
"=",
"vm_name",
")",
"port",
"=",
"self",
".",
"port",
"(",
"vm_name",
"=",
"vm_name",
")",
"user_prefix",
"=",
"user",
... | Return a string combining user, hostname and port, e.g.
'vagrant@127.0.0.1:2222'. This string is suitable for use with Fabric,
in env.hosts. If user or port is None or empty, they will be left
out of the string. E.g. 'vagrant@localhost', or 'localhost:2222' or
'localhost'. If hostnam... | [
"Return",
"a",
"string",
"combining",
"user",
"hostname",
"and",
"port",
"e",
".",
"g",
".",
"vagrant@127",
".",
"0",
".",
"0",
".",
"1",
":",
"2222",
".",
"This",
"string",
"is",
"suitable",
"for",
"use",
"with",
"Fabric",
"in",
"env",
".",
"hosts",... | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L625-L641 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant.box_add | def box_add(self, name, url, provider=None, force=False):
'''
Adds a box with given name, from given url.
force: If True, overwrite an existing box if it exists.
'''
force_opt = '--force' if force else None
cmd = ['box', 'add', name, url, force_opt]
if provider i... | python | def box_add(self, name, url, provider=None, force=False):
'''
Adds a box with given name, from given url.
force: If True, overwrite an existing box if it exists.
'''
force_opt = '--force' if force else None
cmd = ['box', 'add', name, url, force_opt]
if provider i... | [
"def",
"box_add",
"(",
"self",
",",
"name",
",",
"url",
",",
"provider",
"=",
"None",
",",
"force",
"=",
"False",
")",
":",
"force_opt",
"=",
"'--force'",
"if",
"force",
"else",
"None",
"cmd",
"=",
"[",
"'box'",
",",
"'add'",
",",
"name",
",",
"url... | Adds a box with given name, from given url.
force: If True, overwrite an existing box if it exists. | [
"Adds",
"a",
"box",
"with",
"given",
"name",
"from",
"given",
"url",
"."
] | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L643-L654 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant.package | def package(self, vm_name=None, base=None, output=None, vagrantfile=None):
'''
Packages a running vagrant environment into a box.
vm_name=None: name of VM.
base=None: name of a VM in virtualbox to package as a base box
output=None: name of the file to output
vagrantfile=... | python | def package(self, vm_name=None, base=None, output=None, vagrantfile=None):
'''
Packages a running vagrant environment into a box.
vm_name=None: name of VM.
base=None: name of a VM in virtualbox to package as a base box
output=None: name of the file to output
vagrantfile=... | [
"def",
"package",
"(",
"self",
",",
"vm_name",
"=",
"None",
",",
"base",
"=",
"None",
",",
"output",
"=",
"None",
",",
"vagrantfile",
"=",
"None",
")",
":",
"cmd",
"=",
"[",
"'package'",
",",
"vm_name",
"]",
"if",
"output",
"is",
"not",
"None",
":"... | Packages a running vagrant environment into a box.
vm_name=None: name of VM.
base=None: name of a VM in virtualbox to package as a base box
output=None: name of the file to output
vagrantfile=None: Vagrantfile to package with this box | [
"Packages",
"a",
"running",
"vagrant",
"environment",
"into",
"a",
"box",
"."
] | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L690-L705 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant.snapshot_pop | def snapshot_pop(self):
'''
This command is the inverse of vagrant snapshot push: it will restore the pushed state.
'''
NO_SNAPSHOTS_PUSHED = 'No pushed snapshot found!'
output = self._run_vagrant_command(['snapshot', 'pop'])
if NO_SNAPSHOTS_PUSHED in output:
... | python | def snapshot_pop(self):
'''
This command is the inverse of vagrant snapshot push: it will restore the pushed state.
'''
NO_SNAPSHOTS_PUSHED = 'No pushed snapshot found!'
output = self._run_vagrant_command(['snapshot', 'pop'])
if NO_SNAPSHOTS_PUSHED in output:
... | [
"def",
"snapshot_pop",
"(",
"self",
")",
":",
"NO_SNAPSHOTS_PUSHED",
"=",
"'No pushed snapshot found!'",
"output",
"=",
"self",
".",
"_run_vagrant_command",
"(",
"[",
"'snapshot'",
",",
"'pop'",
"]",
")",
"if",
"NO_SNAPSHOTS_PUSHED",
"in",
"output",
":",
"raise",
... | This command is the inverse of vagrant snapshot push: it will restore the pushed state. | [
"This",
"command",
"is",
"the",
"inverse",
"of",
"vagrant",
"snapshot",
"push",
":",
"it",
"will",
"restore",
"the",
"pushed",
"state",
"."
] | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L713-L720 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant.snapshot_list | def snapshot_list(self):
'''
This command will list all the snapshots taken.
'''
NO_SNAPSHOTS_TAKEN = 'No snapshots have been taken yet!'
output = self._run_vagrant_command(['snapshot', 'list'])
if NO_SNAPSHOTS_TAKEN in output:
return []
else:
... | python | def snapshot_list(self):
'''
This command will list all the snapshots taken.
'''
NO_SNAPSHOTS_TAKEN = 'No snapshots have been taken yet!'
output = self._run_vagrant_command(['snapshot', 'list'])
if NO_SNAPSHOTS_TAKEN in output:
return []
else:
... | [
"def",
"snapshot_list",
"(",
"self",
")",
":",
"NO_SNAPSHOTS_TAKEN",
"=",
"'No snapshots have been taken yet!'",
"output",
"=",
"self",
".",
"_run_vagrant_command",
"(",
"[",
"'snapshot'",
",",
"'list'",
"]",
")",
"if",
"NO_SNAPSHOTS_TAKEN",
"in",
"output",
":",
"... | This command will list all the snapshots taken. | [
"This",
"command",
"will",
"list",
"all",
"the",
"snapshots",
"taken",
"."
] | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L735-L744 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant.ssh | def ssh(self, vm_name=None, command=None, extra_ssh_args=None):
'''
Execute a command via ssh on the vm specified.
command: The command to execute via ssh.
extra_ssh_args: Corresponds to '--' option in the vagrant ssh command
Returns the output of running the command.
'''... | python | def ssh(self, vm_name=None, command=None, extra_ssh_args=None):
'''
Execute a command via ssh on the vm specified.
command: The command to execute via ssh.
extra_ssh_args: Corresponds to '--' option in the vagrant ssh command
Returns the output of running the command.
'''... | [
"def",
"ssh",
"(",
"self",
",",
"vm_name",
"=",
"None",
",",
"command",
"=",
"None",
",",
"extra_ssh_args",
"=",
"None",
")",
":",
"cmd",
"=",
"[",
"'ssh'",
",",
"vm_name",
",",
"'--command'",
",",
"command",
"]",
"if",
"extra_ssh_args",
"is",
"not",
... | Execute a command via ssh on the vm specified.
command: The command to execute via ssh.
extra_ssh_args: Corresponds to '--' option in the vagrant ssh command
Returns the output of running the command. | [
"Execute",
"a",
"command",
"via",
"ssh",
"on",
"the",
"vm",
"specified",
".",
"command",
":",
"The",
"command",
"to",
"execute",
"via",
"ssh",
".",
"extra_ssh_args",
":",
"Corresponds",
"to",
"--",
"option",
"in",
"the",
"vagrant",
"ssh",
"command",
"Retur... | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L752-L763 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant._parse_box_list | def _parse_box_list(self, output):
'''
Remove Vagrant usage for unit testing
'''
# Parse box list output
boxes = []
# initialize box values
name = provider = version = None
for timestamp, target, kind, data in self._parse_machine_readable_output(output):
... | python | def _parse_box_list(self, output):
'''
Remove Vagrant usage for unit testing
'''
# Parse box list output
boxes = []
# initialize box values
name = provider = version = None
for timestamp, target, kind, data in self._parse_machine_readable_output(output):
... | [
"def",
"_parse_box_list",
"(",
"self",
",",
"output",
")",
":",
"# Parse box list output",
"boxes",
"=",
"[",
"]",
"# initialize box values",
"name",
"=",
"provider",
"=",
"version",
"=",
"None",
"for",
"timestamp",
",",
"target",
",",
"kind",
",",
"data",
"... | Remove Vagrant usage for unit testing | [
"Remove",
"Vagrant",
"usage",
"for",
"unit",
"testing"
] | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L765-L792 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant._parse_plugin_list | def _parse_plugin_list(self, output):
'''
Remove Vagrant from the equation for unit testing.
'''
ENCODED_COMMA = '%!(VAGRANT_COMMA)'
plugins = []
# initialize plugin values
name = None
version = None
system = False
for timestamp, target, k... | python | def _parse_plugin_list(self, output):
'''
Remove Vagrant from the equation for unit testing.
'''
ENCODED_COMMA = '%!(VAGRANT_COMMA)'
plugins = []
# initialize plugin values
name = None
version = None
system = False
for timestamp, target, k... | [
"def",
"_parse_plugin_list",
"(",
"self",
",",
"output",
")",
":",
"ENCODED_COMMA",
"=",
"'%!(VAGRANT_COMMA)'",
"plugins",
"=",
"[",
"]",
"# initialize plugin values",
"name",
"=",
"None",
"version",
"=",
"None",
"system",
"=",
"False",
"for",
"timestamp",
",",
... | Remove Vagrant from the equation for unit testing. | [
"Remove",
"Vagrant",
"from",
"the",
"equation",
"for",
"unit",
"testing",
"."
] | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L844-L877 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant._parse_machine_readable_output | def _parse_machine_readable_output(self, output):
'''
param output: a string containing the output of a vagrant command with the `--machine-readable` option.
returns: a dict mapping each 'target' in the machine readable output to
a dict. The dict of each target, maps each target line t... | python | def _parse_machine_readable_output(self, output):
'''
param output: a string containing the output of a vagrant command with the `--machine-readable` option.
returns: a dict mapping each 'target' in the machine readable output to
a dict. The dict of each target, maps each target line t... | [
"def",
"_parse_machine_readable_output",
"(",
"self",
",",
"output",
")",
":",
"# each line is a tuple of (timestamp, target, type, data)",
"# target is the VM name",
"# type is the type of data, e.g. 'provider-name', 'box-version'",
"# data is a (possibly comma separated) type-specific value,... | param output: a string containing the output of a vagrant command with the `--machine-readable` option.
returns: a dict mapping each 'target' in the machine readable output to
a dict. The dict of each target, maps each target line type/kind to
its data.
Machine-readable output is a co... | [
"param",
"output",
":",
"a",
"string",
"containing",
"the",
"output",
"of",
"a",
"vagrant",
"command",
"with",
"the",
"--",
"machine",
"-",
"readable",
"option",
"."
] | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L879-L904 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant._parse_config | def _parse_config(self, ssh_config):
'''
This lame parser does not parse the full grammar of an ssh config
file. It makes assumptions that are (hopefully) correct for the output
of `vagrant ssh-config [vm-name]`. Specifically it assumes that there
is only one Host section, the ... | python | def _parse_config(self, ssh_config):
'''
This lame parser does not parse the full grammar of an ssh config
file. It makes assumptions that are (hopefully) correct for the output
of `vagrant ssh-config [vm-name]`. Specifically it assumes that there
is only one Host section, the ... | [
"def",
"_parse_config",
"(",
"self",
",",
"ssh_config",
")",
":",
"conf",
"=",
"dict",
"(",
")",
"started_parsing",
"=",
"False",
"for",
"line",
"in",
"ssh_config",
".",
"splitlines",
"(",
")",
":",
"if",
"line",
".",
"strip",
"(",
")",
".",
"startswit... | This lame parser does not parse the full grammar of an ssh config
file. It makes assumptions that are (hopefully) correct for the output
of `vagrant ssh-config [vm-name]`. Specifically it assumes that there
is only one Host section, the default vagrant host. It assumes that
the parame... | [
"This",
"lame",
"parser",
"does",
"not",
"parse",
"the",
"full",
"grammar",
"of",
"an",
"ssh",
"config",
"file",
".",
"It",
"makes",
"assumptions",
"that",
"are",
"(",
"hopefully",
")",
"correct",
"for",
"the",
"output",
"of",
"vagrant",
"ssh",
"-",
"con... | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L906-L939 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant._call_vagrant_command | def _call_vagrant_command(self, args):
'''
Run a vagrant command. Return None.
args: A sequence of arguments to a vagrant command line.
'''
# Make subprocess command
command = self._make_vagrant_command(args)
with self.out_cm() as out_fh, self.err_cm() as err_fh... | python | def _call_vagrant_command(self, args):
'''
Run a vagrant command. Return None.
args: A sequence of arguments to a vagrant command line.
'''
# Make subprocess command
command = self._make_vagrant_command(args)
with self.out_cm() as out_fh, self.err_cm() as err_fh... | [
"def",
"_call_vagrant_command",
"(",
"self",
",",
"args",
")",
":",
"# Make subprocess command",
"command",
"=",
"self",
".",
"_make_vagrant_command",
"(",
"args",
")",
"with",
"self",
".",
"out_cm",
"(",
")",
"as",
"out_fh",
",",
"self",
".",
"err_cm",
"(",... | Run a vagrant command. Return None.
args: A sequence of arguments to a vagrant command line. | [
"Run",
"a",
"vagrant",
"command",
".",
"Return",
"None",
".",
"args",
":",
"A",
"sequence",
"of",
"arguments",
"to",
"a",
"vagrant",
"command",
"line",
"."
] | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L953-L963 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant._run_vagrant_command | def _run_vagrant_command(self, args):
'''
Run a vagrant command and return its stdout.
args: A sequence of arguments to a vagrant command line.
e.g. ['up', 'my_vm_name', '--no-provision'] or
['up', None, '--no-provision'] for a non-Multi-VM environment.
'''
# Make... | python | def _run_vagrant_command(self, args):
'''
Run a vagrant command and return its stdout.
args: A sequence of arguments to a vagrant command line.
e.g. ['up', 'my_vm_name', '--no-provision'] or
['up', None, '--no-provision'] for a non-Multi-VM environment.
'''
# Make... | [
"def",
"_run_vagrant_command",
"(",
"self",
",",
"args",
")",
":",
"# Make subprocess command",
"command",
"=",
"self",
".",
"_make_vagrant_command",
"(",
"args",
")",
"with",
"self",
".",
"err_cm",
"(",
")",
"as",
"err_fh",
":",
"return",
"compat",
".",
"de... | Run a vagrant command and return its stdout.
args: A sequence of arguments to a vagrant command line.
e.g. ['up', 'my_vm_name', '--no-provision'] or
['up', None, '--no-provision'] for a non-Multi-VM environment. | [
"Run",
"a",
"vagrant",
"command",
"and",
"return",
"its",
"stdout",
".",
"args",
":",
"A",
"sequence",
"of",
"arguments",
"to",
"a",
"vagrant",
"command",
"line",
".",
"e",
".",
"g",
".",
"[",
"up",
"my_vm_name",
"--",
"no",
"-",
"provision",
"]",
"o... | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L965-L976 |
todddeluca/python-vagrant | vagrant/__init__.py | Vagrant._stream_vagrant_command | def _stream_vagrant_command(self, args):
"""
Execute a vagrant command, returning a generator of the output lines.
Caller should consume the entire generator to avoid the hanging the
subprocess.
:param args: Arguments for the Vagrant command.
:return: generator that yiel... | python | def _stream_vagrant_command(self, args):
"""
Execute a vagrant command, returning a generator of the output lines.
Caller should consume the entire generator to avoid the hanging the
subprocess.
:param args: Arguments for the Vagrant command.
:return: generator that yiel... | [
"def",
"_stream_vagrant_command",
"(",
"self",
",",
"args",
")",
":",
"py3",
"=",
"sys",
".",
"version_info",
">",
"(",
"3",
",",
"0",
")",
"# Make subprocess command",
"command",
"=",
"self",
".",
"_make_vagrant_command",
"(",
"args",
")",
"with",
"self",
... | Execute a vagrant command, returning a generator of the output lines.
Caller should consume the entire generator to avoid the hanging the
subprocess.
:param args: Arguments for the Vagrant command.
:return: generator that yields each line of the command stdout.
:rtype: generator... | [
"Execute",
"a",
"vagrant",
"command",
"returning",
"a",
"generator",
"of",
"the",
"output",
"lines",
".",
"Caller",
"should",
"consume",
"the",
"entire",
"generator",
"to",
"avoid",
"the",
"hanging",
"the",
"subprocess",
"."
] | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L978-L1005 |
todddeluca/python-vagrant | vagrant/__init__.py | SandboxVagrant.sandbox_status | def sandbox_status(self, vm_name=None):
'''
Returns the status of the sandbox mode.
Possible values are:
- on
- off
- unknown
- not installed
'''
vagrant_sandbox_output = self._run_sandbox_command(['status', vm_name])
return self._parse_va... | python | def sandbox_status(self, vm_name=None):
'''
Returns the status of the sandbox mode.
Possible values are:
- on
- off
- unknown
- not installed
'''
vagrant_sandbox_output = self._run_sandbox_command(['status', vm_name])
return self._parse_va... | [
"def",
"sandbox_status",
"(",
"self",
",",
"vm_name",
"=",
"None",
")",
":",
"vagrant_sandbox_output",
"=",
"self",
".",
"_run_sandbox_command",
"(",
"[",
"'status'",
",",
"vm_name",
"]",
")",
"return",
"self",
".",
"_parse_vagrant_sandbox_status",
"(",
"vagrant... | Returns the status of the sandbox mode.
Possible values are:
- on
- off
- unknown
- not installed | [
"Returns",
"the",
"status",
"of",
"the",
"sandbox",
"mode",
"."
] | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L1043-L1054 |
todddeluca/python-vagrant | vagrant/__init__.py | SandboxVagrant._parse_vagrant_sandbox_status | def _parse_vagrant_sandbox_status(self, vagrant_output):
'''
Returns the status of the sandbox mode given output from
'vagrant sandbox status'.
'''
# typical output
# [default] - snapshot mode is off
# or
# [default] - machine not created
# if the ... | python | def _parse_vagrant_sandbox_status(self, vagrant_output):
'''
Returns the status of the sandbox mode given output from
'vagrant sandbox status'.
'''
# typical output
# [default] - snapshot mode is off
# or
# [default] - machine not created
# if the ... | [
"def",
"_parse_vagrant_sandbox_status",
"(",
"self",
",",
"vagrant_output",
")",
":",
"# typical output",
"# [default] - snapshot mode is off",
"# or",
"# [default] - machine not created",
"# if the box VM is down",
"tokens",
"=",
"[",
"token",
".",
"strip",
"(",
")",
"for"... | Returns the status of the sandbox mode given output from
'vagrant sandbox status'. | [
"Returns",
"the",
"status",
"of",
"the",
"sandbox",
"mode",
"given",
"output",
"from",
"vagrant",
"sandbox",
"status",
"."
] | train | https://github.com/todddeluca/python-vagrant/blob/83b26f9337b1f2cb6314210923bbd189e7c9199e/vagrant/__init__.py#L1056-L1073 |
garnaat/placebo | placebo/serializer.py | deserialize | def deserialize(obj):
"""Convert JSON dicts back into objects."""
# Be careful of shallow copy here
target = dict(obj)
class_name = None
if '__class__' in target:
class_name = target.pop('__class__')
if '__module__' in obj:
obj.pop('__module__')
# Use getattr(module, class_na... | python | def deserialize(obj):
"""Convert JSON dicts back into objects."""
# Be careful of shallow copy here
target = dict(obj)
class_name = None
if '__class__' in target:
class_name = target.pop('__class__')
if '__module__' in obj:
obj.pop('__module__')
# Use getattr(module, class_na... | [
"def",
"deserialize",
"(",
"obj",
")",
":",
"# Be careful of shallow copy here",
"target",
"=",
"dict",
"(",
"obj",
")",
"class_name",
"=",
"None",
"if",
"'__class__'",
"in",
"target",
":",
"class_name",
"=",
"target",
".",
"pop",
"(",
"'__class__'",
")",
"i... | Convert JSON dicts back into objects. | [
"Convert",
"JSON",
"dicts",
"back",
"into",
"objects",
"."
] | train | https://github.com/garnaat/placebo/blob/1e8ab91b92fa7c5bb1fdbce2331f0c55455093d7/placebo/serializer.py#L68-L83 |
garnaat/placebo | placebo/serializer.py | serialize | def serialize(obj):
"""Convert objects into JSON structures."""
# Record class and module information for deserialization
result = {'__class__': obj.__class__.__name__}
try:
result['__module__'] = obj.__module__
except AttributeError:
pass
# Convert objects to dictionary represen... | python | def serialize(obj):
"""Convert objects into JSON structures."""
# Record class and module information for deserialization
result = {'__class__': obj.__class__.__name__}
try:
result['__module__'] = obj.__module__
except AttributeError:
pass
# Convert objects to dictionary represen... | [
"def",
"serialize",
"(",
"obj",
")",
":",
"# Record class and module information for deserialization",
"result",
"=",
"{",
"'__class__'",
":",
"obj",
".",
"__class__",
".",
"__name__",
"}",
"try",
":",
"result",
"[",
"'__module__'",
"]",
"=",
"obj",
".",
"__modu... | Convert objects into JSON structures. | [
"Convert",
"objects",
"into",
"JSON",
"structures",
"."
] | train | https://github.com/garnaat/placebo/blob/1e8ab91b92fa7c5bb1fdbce2331f0c55455093d7/placebo/serializer.py#L86-L110 |
garnaat/placebo | placebo/serializer.py | _serialize_json | def _serialize_json(obj, fp):
""" Serialize ``obj`` as a JSON formatted stream to ``fp`` """
json.dump(obj, fp, indent=4, default=serialize) | python | def _serialize_json(obj, fp):
""" Serialize ``obj`` as a JSON formatted stream to ``fp`` """
json.dump(obj, fp, indent=4, default=serialize) | [
"def",
"_serialize_json",
"(",
"obj",
",",
"fp",
")",
":",
"json",
".",
"dump",
"(",
"obj",
",",
"fp",
",",
"indent",
"=",
"4",
",",
"default",
"=",
"serialize",
")"
] | Serialize ``obj`` as a JSON formatted stream to ``fp`` | [
"Serialize",
"obj",
"as",
"a",
"JSON",
"formatted",
"stream",
"to",
"fp"
] | train | https://github.com/garnaat/placebo/blob/1e8ab91b92fa7c5bb1fdbce2331f0c55455093d7/placebo/serializer.py#L113-L115 |
garnaat/placebo | placebo/serializer.py | get_serializer | def get_serializer(serializer_format):
""" Get the serializer for a specific format """
if serializer_format == Format.JSON:
return _serialize_json
if serializer_format == Format.PICKLE:
return _serialize_pickle | python | def get_serializer(serializer_format):
""" Get the serializer for a specific format """
if serializer_format == Format.JSON:
return _serialize_json
if serializer_format == Format.PICKLE:
return _serialize_pickle | [
"def",
"get_serializer",
"(",
"serializer_format",
")",
":",
"if",
"serializer_format",
"==",
"Format",
".",
"JSON",
":",
"return",
"_serialize_json",
"if",
"serializer_format",
"==",
"Format",
".",
"PICKLE",
":",
"return",
"_serialize_pickle"
] | Get the serializer for a specific format | [
"Get",
"the",
"serializer",
"for",
"a",
"specific",
"format"
] | train | https://github.com/garnaat/placebo/blob/1e8ab91b92fa7c5bb1fdbce2331f0c55455093d7/placebo/serializer.py#L133-L138 |
garnaat/placebo | placebo/serializer.py | get_deserializer | def get_deserializer(serializer_format):
""" Get the deserializer for a specific format """
if serializer_format == Format.JSON:
return _deserialize_json
if serializer_format == Format.PICKLE:
return _deserialize_pickle | python | def get_deserializer(serializer_format):
""" Get the deserializer for a specific format """
if serializer_format == Format.JSON:
return _deserialize_json
if serializer_format == Format.PICKLE:
return _deserialize_pickle | [
"def",
"get_deserializer",
"(",
"serializer_format",
")",
":",
"if",
"serializer_format",
"==",
"Format",
".",
"JSON",
":",
"return",
"_deserialize_json",
"if",
"serializer_format",
"==",
"Format",
".",
"PICKLE",
":",
"return",
"_deserialize_pickle"
] | Get the deserializer for a specific format | [
"Get",
"the",
"deserializer",
"for",
"a",
"specific",
"format"
] | train | https://github.com/garnaat/placebo/blob/1e8ab91b92fa7c5bb1fdbce2331f0c55455093d7/placebo/serializer.py#L141-L146 |
garnaat/placebo | placebo/pill.py | Pill._set_logger | def _set_logger(logger_name, level=logging.INFO):
"""
Convenience function to quickly configure full debug output
to go to the console.
"""
log = logging.getLogger(logger_name)
log.setLevel(level)
ch = logging.StreamHandler(None)
ch.setLevel(level)
... | python | def _set_logger(logger_name, level=logging.INFO):
"""
Convenience function to quickly configure full debug output
to go to the console.
"""
log = logging.getLogger(logger_name)
log.setLevel(level)
ch = logging.StreamHandler(None)
ch.setLevel(level)
... | [
"def",
"_set_logger",
"(",
"logger_name",
",",
"level",
"=",
"logging",
".",
"INFO",
")",
":",
"log",
"=",
"logging",
".",
"getLogger",
"(",
"logger_name",
")",
"log",
".",
"setLevel",
"(",
"level",
")",
"ch",
"=",
"logging",
".",
"StreamHandler",
"(",
... | Convenience function to quickly configure full debug output
to go to the console. | [
"Convenience",
"function",
"to",
"quickly",
"configure",
"full",
"debug",
"output",
"to",
"go",
"to",
"the",
"console",
"."
] | train | https://github.com/garnaat/placebo/blob/1e8ab91b92fa7c5bb1fdbce2331f0c55455093d7/placebo/pill.py#L76-L93 |
garnaat/placebo | placebo/pill.py | Pill.find_file_format | def find_file_format(file_name):
"""
Returns a tuple with the file path and format found, or (None, None)
"""
for file_format in Format.ALLOWED:
file_path = '.'.join((file_name, file_format))
if os.path.exists(file_path):
return file_path, file_for... | python | def find_file_format(file_name):
"""
Returns a tuple with the file path and format found, or (None, None)
"""
for file_format in Format.ALLOWED:
file_path = '.'.join((file_name, file_format))
if os.path.exists(file_path):
return file_path, file_for... | [
"def",
"find_file_format",
"(",
"file_name",
")",
":",
"for",
"file_format",
"in",
"Format",
".",
"ALLOWED",
":",
"file_path",
"=",
"'.'",
".",
"join",
"(",
"(",
"file_name",
",",
"file_format",
")",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"f... | Returns a tuple with the file path and format found, or (None, None) | [
"Returns",
"a",
"tuple",
"with",
"the",
"file",
"path",
"and",
"format",
"found",
"or",
"(",
"None",
"None",
")"
] | train | https://github.com/garnaat/placebo/blob/1e8ab91b92fa7c5bb1fdbce2331f0c55455093d7/placebo/pill.py#L223-L231 |
garnaat/placebo | placebo/pill.py | Pill.get_next_file_path | def get_next_file_path(self, service, operation):
"""
Returns a tuple with the next file to read and the serializer
format used
"""
base_name = '{0}.{1}'.format(service, operation)
if self.prefix:
base_name = '{0}.{1}'.format(self.prefix, base_name)
LO... | python | def get_next_file_path(self, service, operation):
"""
Returns a tuple with the next file to read and the serializer
format used
"""
base_name = '{0}.{1}'.format(service, operation)
if self.prefix:
base_name = '{0}.{1}'.format(self.prefix, base_name)
LO... | [
"def",
"get_next_file_path",
"(",
"self",
",",
"service",
",",
"operation",
")",
":",
"base_name",
"=",
"'{0}.{1}'",
".",
"format",
"(",
"service",
",",
"operation",
")",
"if",
"self",
".",
"prefix",
":",
"base_name",
"=",
"'{0}.{1}'",
".",
"format",
"(",
... | Returns a tuple with the next file to read and the serializer
format used | [
"Returns",
"a",
"tuple",
"with",
"the",
"next",
"file",
"to",
"read",
"and",
"the",
"serializer",
"format",
"used"
] | train | https://github.com/garnaat/placebo/blob/1e8ab91b92fa7c5bb1fdbce2331f0c55455093d7/placebo/pill.py#L233-L259 |
garnaat/placebo | placebo/pill.py | Pill.save_response | def save_response(self, service, operation, response_data,
http_response=200):
"""
Store a response to the data directory. The ``operation``
should be the name of the operation in the service API (e.g.
DescribeInstances), the ``response_data`` should a value you wa... | python | def save_response(self, service, operation, response_data,
http_response=200):
"""
Store a response to the data directory. The ``operation``
should be the name of the operation in the service API (e.g.
DescribeInstances), the ``response_data`` should a value you wa... | [
"def",
"save_response",
"(",
"self",
",",
"service",
",",
"operation",
",",
"response_data",
",",
"http_response",
"=",
"200",
")",
":",
"LOG",
".",
"debug",
"(",
"'save_response: %s.%s'",
",",
"service",
",",
"operation",
")",
"filepath",
"=",
"self",
".",
... | Store a response to the data directory. The ``operation``
should be the name of the operation in the service API (e.g.
DescribeInstances), the ``response_data`` should a value you want
to return from a placebo call and the ``http_response`` should be
the HTTP status code returned from t... | [
"Store",
"a",
"response",
"to",
"the",
"data",
"directory",
".",
"The",
"operation",
"should",
"be",
"the",
"name",
"of",
"the",
"operation",
"in",
"the",
"service",
"API",
"(",
"e",
".",
"g",
".",
"DescribeInstances",
")",
"the",
"response_data",
"should"... | train | https://github.com/garnaat/placebo/blob/1e8ab91b92fa7c5bb1fdbce2331f0c55455093d7/placebo/pill.py#L261-L278 |
garnaat/placebo | placebo/pill.py | Pill._mock_request | def _mock_request(self, **kwargs):
"""
A mocked out make_request call that bypasses all network calls
and simply returns any mocked responses defined.
"""
model = kwargs.get('model')
service = model.service_model.endpoint_prefix
operation = model.name
LOG.... | python | def _mock_request(self, **kwargs):
"""
A mocked out make_request call that bypasses all network calls
and simply returns any mocked responses defined.
"""
model = kwargs.get('model')
service = model.service_model.endpoint_prefix
operation = model.name
LOG.... | [
"def",
"_mock_request",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"model",
"=",
"kwargs",
".",
"get",
"(",
"'model'",
")",
"service",
"=",
"model",
".",
"service_model",
".",
"endpoint_prefix",
"operation",
"=",
"model",
".",
"name",
"LOG",
".",
... | A mocked out make_request call that bypasses all network calls
and simply returns any mocked responses defined. | [
"A",
"mocked",
"out",
"make_request",
"call",
"that",
"bypasses",
"all",
"network",
"calls",
"and",
"simply",
"returns",
"any",
"mocked",
"responses",
"defined",
"."
] | train | https://github.com/garnaat/placebo/blob/1e8ab91b92fa7c5bb1fdbce2331f0c55455093d7/placebo/pill.py#L290-L299 |
garnaat/placebo | placebo/utils.py | placebo_session | def placebo_session(function):
"""
Decorator to help do testing with placebo.
Simply wrap the function you want to test and make sure to add
a "session" argument so the decorator can pass the placebo session.
Accepts the following environment variables to configure placebo:
PLACEBO_MODE: set to ... | python | def placebo_session(function):
"""
Decorator to help do testing with placebo.
Simply wrap the function you want to test and make sure to add
a "session" argument so the decorator can pass the placebo session.
Accepts the following environment variables to configure placebo:
PLACEBO_MODE: set to ... | [
"def",
"placebo_session",
"(",
"function",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"function",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"session_kwargs",
"=",
"{",
"'region_name'",
":",
"os",
".",
"environ",
".... | Decorator to help do testing with placebo.
Simply wrap the function you want to test and make sure to add
a "session" argument so the decorator can pass the placebo session.
Accepts the following environment variables to configure placebo:
PLACEBO_MODE: set to "record" to record AWS calls and save them
... | [
"Decorator",
"to",
"help",
"do",
"testing",
"with",
"placebo",
".",
"Simply",
"wrap",
"the",
"function",
"you",
"want",
"to",
"test",
"and",
"make",
"sure",
"to",
"add",
"a",
"session",
"argument",
"so",
"the",
"decorator",
"can",
"pass",
"the",
"placebo",... | train | https://github.com/garnaat/placebo/blob/1e8ab91b92fa7c5bb1fdbce2331f0c55455093d7/placebo/utils.py#L23-L68 |
IdentityPython/pyop | src/pyop/provider.py | Provider.parse_authentication_request | def parse_authentication_request(self, request_body, http_headers=None):
# type: (str, Optional[Mapping[str, str]]) -> oic.oic.message.AuthorizationRequest
"""
Parses and verifies an authentication request.
:param request_body: urlencoded authentication request
:param http_heade... | python | def parse_authentication_request(self, request_body, http_headers=None):
# type: (str, Optional[Mapping[str, str]]) -> oic.oic.message.AuthorizationRequest
"""
Parses and verifies an authentication request.
:param request_body: urlencoded authentication request
:param http_heade... | [
"def",
"parse_authentication_request",
"(",
"self",
",",
"request_body",
",",
"http_headers",
"=",
"None",
")",
":",
"# type: (str, Optional[Mapping[str, str]]) -> oic.oic.message.AuthorizationRequest",
"auth_req",
"=",
"AuthorizationRequest",
"(",
")",
".",
"deserialize",
"(... | Parses and verifies an authentication request.
:param request_body: urlencoded authentication request
:param http_headers: http headers | [
"Parses",
"and",
"verifies",
"an",
"authentication",
"request",
"."
] | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/provider.py#L116-L131 |
IdentityPython/pyop | src/pyop/provider.py | Provider.authorize | def authorize(self, authentication_request, # type: oic.oic.message.AuthorizationRequest
user_id, # type: str
extra_id_token_claims=None
# type: Optional[Union[Mapping[str, Union[str, List[str]]], Callable[[str, str], Mapping[str, Union[str, List[str]]]]]
... | python | def authorize(self, authentication_request, # type: oic.oic.message.AuthorizationRequest
user_id, # type: str
extra_id_token_claims=None
# type: Optional[Union[Mapping[str, Union[str, List[str]]], Callable[[str, str], Mapping[str, Union[str, List[str]]]]]
... | [
"def",
"authorize",
"(",
"self",
",",
"authentication_request",
",",
"# type: oic.oic.message.AuthorizationRequest",
"user_id",
",",
"# type: str",
"extra_id_token_claims",
"=",
"None",
"# type: Optional[Union[Mapping[str, Union[str, List[str]]], Callable[[str, str], Mapping[str, Union[s... | Creates an Authentication Response for the specified authentication request and local identifier of the
authenticated user. | [
"Creates",
"an",
"Authentication",
"Response",
"for",
"the",
"specified",
"authentication",
"request",
"and",
"local",
"identifier",
"of",
"the",
"authenticated",
"user",
"."
] | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/provider.py#L133-L191 |
IdentityPython/pyop | src/pyop/provider.py | Provider._add_access_token_to_response | def _add_access_token_to_response(self, response, access_token):
# type: (oic.message.AccessTokenResponse, se_leg_op.access_token.AccessToken) -> None
"""
Adds the Access Token and the associated parameters to the Token Response.
"""
response['access_token'] = access_token.value
... | python | def _add_access_token_to_response(self, response, access_token):
# type: (oic.message.AccessTokenResponse, se_leg_op.access_token.AccessToken) -> None
"""
Adds the Access Token and the associated parameters to the Token Response.
"""
response['access_token'] = access_token.value
... | [
"def",
"_add_access_token_to_response",
"(",
"self",
",",
"response",
",",
"access_token",
")",
":",
"# type: (oic.message.AccessTokenResponse, se_leg_op.access_token.AccessToken) -> None",
"response",
"[",
"'access_token'",
"]",
"=",
"access_token",
".",
"value",
"response",
... | Adds the Access Token and the associated parameters to the Token Response. | [
"Adds",
"the",
"Access",
"Token",
"and",
"the",
"associated",
"parameters",
"to",
"the",
"Token",
"Response",
"."
] | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/provider.py#L193-L200 |
IdentityPython/pyop | src/pyop/provider.py | Provider._create_subject_identifier | def _create_subject_identifier(self, user_id, client_id, redirect_uri):
# type (str, str, str) -> str
"""
Creates a subject identifier for the specified client and user
see <a href="http://openid.net/specs/openid-connect-core-1_0.html#Terminology">
"OpenID Connect Core 1.0", Sect... | python | def _create_subject_identifier(self, user_id, client_id, redirect_uri):
# type (str, str, str) -> str
"""
Creates a subject identifier for the specified client and user
see <a href="http://openid.net/specs/openid-connect-core-1_0.html#Terminology">
"OpenID Connect Core 1.0", Sect... | [
"def",
"_create_subject_identifier",
"(",
"self",
",",
"user_id",
",",
"client_id",
",",
"redirect_uri",
")",
":",
"# type (str, str, str) -> str",
"supported_subject_types",
"=",
"self",
".",
"configuration_information",
"[",
"'subject_types_supported'",
"]",
"[",
"0",
... | Creates a subject identifier for the specified client and user
see <a href="http://openid.net/specs/openid-connect-core-1_0.html#Terminology">
"OpenID Connect Core 1.0", Section 1.2</a>.
:param user_id: local user identifier
:param client_id: which client to generate a subject identifier... | [
"Creates",
"a",
"subject",
"identifier",
"for",
"the",
"specified",
"client",
"and",
"user",
"see",
"<a",
"href",
"=",
"http",
":",
"//",
"openid",
".",
"net",
"/",
"specs",
"/",
"openid",
"-",
"connect",
"-",
"core",
"-",
"1_0",
".",
"html#Terminology",... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/provider.py#L202-L216 |
IdentityPython/pyop | src/pyop/provider.py | Provider._get_requested_claims_in | def _get_requested_claims_in(self, authentication_request, response_method):
# type (oic.oic.message.AuthorizationRequest, str) -> Mapping[str, Optional[Mapping[str, Union[str, List[str]]]]
"""
Parses any claims requested using the 'claims' request parameter, see
<a href="http://openid.n... | python | def _get_requested_claims_in(self, authentication_request, response_method):
# type (oic.oic.message.AuthorizationRequest, str) -> Mapping[str, Optional[Mapping[str, Union[str, List[str]]]]
"""
Parses any claims requested using the 'claims' request parameter, see
<a href="http://openid.n... | [
"def",
"_get_requested_claims_in",
"(",
"self",
",",
"authentication_request",
",",
"response_method",
")",
":",
"# type (oic.oic.message.AuthorizationRequest, str) -> Mapping[str, Optional[Mapping[str, Union[str, List[str]]]]",
"if",
"response_method",
"!=",
"'id_token'",
"and",
"re... | Parses any claims requested using the 'claims' request parameter, see
<a href="http://openid.net/specs/openid-connect-core-1_0.html#ClaimsParameter">
"OpenID Connect Core 1.0", Section 5.5</a>.
:param authentication_request: the authentication request
:param response_method: 'id_token' o... | [
"Parses",
"any",
"claims",
"requested",
"using",
"the",
"claims",
"request",
"parameter",
"see",
"<a",
"href",
"=",
"http",
":",
"//",
"openid",
".",
"net",
"/",
"specs",
"/",
"openid",
"-",
"connect",
"-",
"core",
"-",
"1_0",
".",
"html#ClaimsParameter",
... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/provider.py#L218-L234 |
IdentityPython/pyop | src/pyop/provider.py | Provider._create_signed_id_token | def _create_signed_id_token(self,
client_id, # type: str
sub, # type: str
user_claims=None, # type: Optional[Mapping[str, Union[str, List[str]]]]
nonce=None, # type: Optional[str]
... | python | def _create_signed_id_token(self,
client_id, # type: str
sub, # type: str
user_claims=None, # type: Optional[Mapping[str, Union[str, List[str]]]]
nonce=None, # type: Optional[str]
... | [
"def",
"_create_signed_id_token",
"(",
"self",
",",
"client_id",
",",
"# type: str",
"sub",
",",
"# type: str",
"user_claims",
"=",
"None",
",",
"# type: Optional[Mapping[str, Union[str, List[str]]]]",
"nonce",
"=",
"None",
",",
"# type: Optional[str]",
"authorization_code"... | Creates a signed ID Token.
:param client_id: who the ID Token is intended for
:param sub: who the ID Token is regarding
:param user_claims: any claims about the user to be included
:param nonce: nonce from the authentication request
:param authorization_code: the authorization co... | [
"Creates",
"a",
"signed",
"ID",
"Token",
".",
":",
"param",
"client_id",
":",
"who",
"the",
"ID",
"Token",
"is",
"intended",
"for",
":",
"param",
"sub",
":",
"who",
"the",
"ID",
"Token",
"is",
"regarding",
":",
"param",
"user_claims",
":",
"any",
"clai... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/provider.py#L236-L284 |
IdentityPython/pyop | src/pyop/provider.py | Provider._check_subject_identifier_matches_requested | def _check_subject_identifier_matches_requested(self, authentication_request, sub):
# type (oic.message.AuthorizationRequest, str) -> None
"""
Verifies the subject identifier against any requested subject identifier using the claims request parameter.
:param authentication_request: authe... | python | def _check_subject_identifier_matches_requested(self, authentication_request, sub):
# type (oic.message.AuthorizationRequest, str) -> None
"""
Verifies the subject identifier against any requested subject identifier using the claims request parameter.
:param authentication_request: authe... | [
"def",
"_check_subject_identifier_matches_requested",
"(",
"self",
",",
"authentication_request",
",",
"sub",
")",
":",
"# type (oic.message.AuthorizationRequest, str) -> None",
"if",
"'claims'",
"in",
"authentication_request",
":",
"requested_id_token_sub",
"=",
"authentication_... | Verifies the subject identifier against any requested subject identifier using the claims request parameter.
:param authentication_request: authentication request
:param sub: subject identifier
:raise AuthorizationError: if the subject identifier does not match the requested one | [
"Verifies",
"the",
"subject",
"identifier",
"against",
"any",
"requested",
"subject",
"identifier",
"using",
"the",
"claims",
"request",
"parameter",
".",
":",
"param",
"authentication_request",
":",
"authentication",
"request",
":",
"param",
"sub",
":",
"subject",
... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/provider.py#L286-L304 |
IdentityPython/pyop | src/pyop/provider.py | Provider.handle_token_request | def handle_token_request(self, request_body, # type: str
http_headers=None, # type: Optional[Mapping[str, str]]
extra_id_token_claims=None
# type: Optional[Union[Mapping[str, Union[str, List[str]]], Callable[[str, str], Mapping[str... | python | def handle_token_request(self, request_body, # type: str
http_headers=None, # type: Optional[Mapping[str, str]]
extra_id_token_claims=None
# type: Optional[Union[Mapping[str, Union[str, List[str]]], Callable[[str, str], Mapping[str... | [
"def",
"handle_token_request",
"(",
"self",
",",
"request_body",
",",
"# type: str",
"http_headers",
"=",
"None",
",",
"# type: Optional[Mapping[str, str]]",
"extra_id_token_claims",
"=",
"None",
"# type: Optional[Union[Mapping[str, Union[str, List[str]]], Callable[[str, str], Mappin... | Handles a token request, either for exchanging an authorization code or using a refresh token.
:param request_body: urlencoded token request
:param http_headers: http headers
:param extra_id_token_claims: extra claims to include in the signed ID Token | [
"Handles",
"a",
"token",
"request",
"either",
"for",
"exchanging",
"an",
"authorization",
"code",
"or",
"using",
"a",
"refresh",
"token",
".",
":",
"param",
"request_body",
":",
"urlencoded",
"token",
"request",
":",
"param",
"http_headers",
":",
"http",
"head... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/provider.py#L306-L329 |
IdentityPython/pyop | src/pyop/provider.py | Provider._do_code_exchange | def _do_code_exchange(self, request, # type: Dict[str, str]
extra_id_token_claims=None
# type: Optional[Union[Mapping[str, Union[str, List[str]]], Callable[[str, str], Mapping[str, Union[str, List[str]]]]]
):
# type: (...) -> oic.mes... | python | def _do_code_exchange(self, request, # type: Dict[str, str]
extra_id_token_claims=None
# type: Optional[Union[Mapping[str, Union[str, List[str]]], Callable[[str, str], Mapping[str, Union[str, List[str]]]]]
):
# type: (...) -> oic.mes... | [
"def",
"_do_code_exchange",
"(",
"self",
",",
"request",
",",
"# type: Dict[str, str]",
"extra_id_token_claims",
"=",
"None",
"# type: Optional[Union[Mapping[str, Union[str, List[str]]], Callable[[str, str], Mapping[str, Union[str, List[str]]]]]",
")",
":",
"# type: (...) -> oic.message.... | Handles a token request for exchanging an authorization code for an access token
(grant_type=authorization_code).
:param request: parsed http request parameters
:param extra_id_token_claims: any extra parameters to include in the signed ID Token, either as a dict-like
object or as a ... | [
"Handles",
"a",
"token",
"request",
"for",
"exchanging",
"an",
"authorization",
"code",
"for",
"an",
"access",
"token",
"(",
"grant_type",
"=",
"authorization_code",
")",
".",
":",
"param",
"request",
":",
"parsed",
"http",
"request",
"parameters",
":",
"param... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/provider.py#L331-L388 |
IdentityPython/pyop | src/pyop/provider.py | Provider._do_token_refresh | def _do_token_refresh(self, request):
# type: (Mapping[str, str]) -> oic.oic.message.AccessTokenResponse
"""
Handles a token request for refreshing an access token (grant_type=refresh_token).
:param request: parsed http request parameters
:return: a token response containing a ne... | python | def _do_token_refresh(self, request):
# type: (Mapping[str, str]) -> oic.oic.message.AccessTokenResponse
"""
Handles a token request for refreshing an access token (grant_type=refresh_token).
:param request: parsed http request parameters
:return: a token response containing a ne... | [
"def",
"_do_token_refresh",
"(",
"self",
",",
"request",
")",
":",
"# type: (Mapping[str, str]) -> oic.oic.message.AccessTokenResponse",
"token_request",
"=",
"RefreshAccessTokenRequest",
"(",
")",
".",
"from_dict",
"(",
"request",
")",
"try",
":",
"token_request",
".",
... | Handles a token request for refreshing an access token (grant_type=refresh_token).
:param request: parsed http request parameters
:return: a token response containing a new Access Token and possibly a new Refresh Token
:raise InvalidTokenRequest: if the token request is invalid | [
"Handles",
"a",
"token",
"request",
"for",
"refreshing",
"an",
"access",
"token",
"(",
"grant_type",
"=",
"refresh_token",
")",
".",
":",
"param",
"request",
":",
"parsed",
"http",
"request",
"parameters",
":",
"return",
":",
"a",
"token",
"response",
"conta... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/provider.py#L390-L412 |
IdentityPython/pyop | src/pyop/provider.py | Provider._verify_client_authentication | def _verify_client_authentication(self, request_body, http_headers=None):
# type (str, Optional[Mapping[str, str]] -> Mapping[str, str]
"""
Verifies the client authentication.
:param request_body: urlencoded token request
:param http_headers:
:return: The parsed request b... | python | def _verify_client_authentication(self, request_body, http_headers=None):
# type (str, Optional[Mapping[str, str]] -> Mapping[str, str]
"""
Verifies the client authentication.
:param request_body: urlencoded token request
:param http_headers:
:return: The parsed request b... | [
"def",
"_verify_client_authentication",
"(",
"self",
",",
"request_body",
",",
"http_headers",
"=",
"None",
")",
":",
"# type (str, Optional[Mapping[str, str]] -> Mapping[str, str]",
"if",
"http_headers",
"is",
"None",
":",
"http_headers",
"=",
"{",
"}",
"token_request",
... | Verifies the client authentication.
:param request_body: urlencoded token request
:param http_headers:
:return: The parsed request body. | [
"Verifies",
"the",
"client",
"authentication",
".",
":",
"param",
"request_body",
":",
"urlencoded",
"token",
"request",
":",
"param",
"http_headers",
":",
":",
"return",
":",
"The",
"parsed",
"request",
"body",
"."
] | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/provider.py#L414-L426 |
IdentityPython/pyop | src/pyop/provider.py | Provider.handle_userinfo_request | def handle_userinfo_request(self, request=None, http_headers=None):
# type: (Optional[str], Optional[Mapping[str, str]]) -> oic.oic.message.OpenIDSchema
"""
Handles a userinfo request.
:param request: urlencoded request (either query string or POST body)
:param http_headers: http... | python | def handle_userinfo_request(self, request=None, http_headers=None):
# type: (Optional[str], Optional[Mapping[str, str]]) -> oic.oic.message.OpenIDSchema
"""
Handles a userinfo request.
:param request: urlencoded request (either query string or POST body)
:param http_headers: http... | [
"def",
"handle_userinfo_request",
"(",
"self",
",",
"request",
"=",
"None",
",",
"http_headers",
"=",
"None",
")",
":",
"# type: (Optional[str], Optional[Mapping[str, str]]) -> oic.oic.message.OpenIDSchema",
"if",
"http_headers",
"is",
"None",
":",
"http_headers",
"=",
"{... | Handles a userinfo request.
:param request: urlencoded request (either query string or POST body)
:param http_headers: http headers | [
"Handles",
"a",
"userinfo",
"request",
".",
":",
"param",
"request",
":",
"urlencoded",
"request",
"(",
"either",
"query",
"string",
"or",
"POST",
"body",
")",
":",
"param",
"http_headers",
":",
"http",
"headers"
] | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/provider.py#L428-L455 |
IdentityPython/pyop | src/pyop/provider.py | Provider.match_client_preferences_with_provider_capabilities | def match_client_preferences_with_provider_capabilities(self, client_preferences):
# type: (oic.message.RegistrationRequest) -> Mapping[str, Union[str, List[str]]]
"""
Match as many as of the client preferences as possible.
:param client_preferences: requested preferences from client reg... | python | def match_client_preferences_with_provider_capabilities(self, client_preferences):
# type: (oic.message.RegistrationRequest) -> Mapping[str, Union[str, List[str]]]
"""
Match as many as of the client preferences as possible.
:param client_preferences: requested preferences from client reg... | [
"def",
"match_client_preferences_with_provider_capabilities",
"(",
"self",
",",
"client_preferences",
")",
":",
"# type: (oic.message.RegistrationRequest) -> Mapping[str, Union[str, List[str]]]",
"matched_prefs",
"=",
"client_preferences",
".",
"to_dict",
"(",
")",
"for",
"pref",
... | Match as many as of the client preferences as possible.
:param client_preferences: requested preferences from client registration request
:return: the matched preferences selected by the provider | [
"Match",
"as",
"many",
"as",
"of",
"the",
"client",
"preferences",
"as",
"possible",
".",
":",
"param",
"client_preferences",
":",
"requested",
"preferences",
"from",
"client",
"registration",
"request",
":",
"return",
":",
"the",
"matched",
"preferences",
"sele... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/provider.py#L467-L485 |
IdentityPython/pyop | src/pyop/provider.py | Provider.handle_client_registration_request | def handle_client_registration_request(self, request, http_headers=None):
# type: (Optional[str], Optional[Mapping[str, str]]) -> oic.oic.message.RegistrationResponse
"""
Handles a client registration request.
:param request: JSON request from POST body
:param http_headers: http ... | python | def handle_client_registration_request(self, request, http_headers=None):
# type: (Optional[str], Optional[Mapping[str, str]]) -> oic.oic.message.RegistrationResponse
"""
Handles a client registration request.
:param request: JSON request from POST body
:param http_headers: http ... | [
"def",
"handle_client_registration_request",
"(",
"self",
",",
"request",
",",
"http_headers",
"=",
"None",
")",
":",
"# type: (Optional[str], Optional[Mapping[str, str]]) -> oic.oic.message.RegistrationResponse",
"registration_req",
"=",
"RegistrationRequest",
"(",
")",
".",
"... | Handles a client registration request.
:param request: JSON request from POST body
:param http_headers: http headers | [
"Handles",
"a",
"client",
"registration",
"request",
".",
":",
"param",
"request",
":",
"JSON",
"request",
"from",
"POST",
"body",
":",
"param",
"http_headers",
":",
"http",
"headers"
] | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/provider.py#L487-L514 |
IdentityPython/pyop | src/pyop/access_token.py | extract_bearer_token_from_http_request | def extract_bearer_token_from_http_request(parsed_request=None, authz_header=None):
# type (Optional[Mapping[str, str]], Optional[str] -> str
"""
Extracts a Bearer token from an http request
:param parsed_request: parsed request (URL query part of request body)
:param authz_header: HTTP Authorizatio... | python | def extract_bearer_token_from_http_request(parsed_request=None, authz_header=None):
# type (Optional[Mapping[str, str]], Optional[str] -> str
"""
Extracts a Bearer token from an http request
:param parsed_request: parsed request (URL query part of request body)
:param authz_header: HTTP Authorizatio... | [
"def",
"extract_bearer_token_from_http_request",
"(",
"parsed_request",
"=",
"None",
",",
"authz_header",
"=",
"None",
")",
":",
"# type (Optional[Mapping[str, str]], Optional[str] -> str",
"if",
"authz_header",
":",
"# Authorization Request Header Field: https://tools.ietf.org/html/... | Extracts a Bearer token from an http request
:param parsed_request: parsed request (URL query part of request body)
:param authz_header: HTTP Authorization header
:return: Bearer access token, if found
:raise BearerTokenError: if no Bearer token could be extracted from the request | [
"Extracts",
"a",
"Bearer",
"token",
"from",
"an",
"http",
"request",
":",
"param",
"parsed_request",
":",
"parsed",
"request",
"(",
"URL",
"query",
"part",
"of",
"request",
"body",
")",
":",
"param",
"authz_header",
":",
"HTTP",
"Authorization",
"header",
":... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/access_token.py#L21-L46 |
IdentityPython/pyop | src/pyop/storage.py | _format_mongodb_uri | def _format_mongodb_uri(parsed_uri):
"""
Painstakingly reconstruct a MongoDB URI parsed using pymongo.uri_parser.parse_uri.
:param parsed_uri: Result of pymongo.uri_parser.parse_uri
:type parsed_uri: dict
:return: New URI
:rtype: str | unicode
"""
user_pass = ''
if parsed_uri.get('... | python | def _format_mongodb_uri(parsed_uri):
"""
Painstakingly reconstruct a MongoDB URI parsed using pymongo.uri_parser.parse_uri.
:param parsed_uri: Result of pymongo.uri_parser.parse_uri
:type parsed_uri: dict
:return: New URI
:rtype: str | unicode
"""
user_pass = ''
if parsed_uri.get('... | [
"def",
"_format_mongodb_uri",
"(",
"parsed_uri",
")",
":",
"user_pass",
"=",
"''",
"if",
"parsed_uri",
".",
"get",
"(",
"'username'",
")",
"and",
"parsed_uri",
".",
"get",
"(",
"'password'",
")",
":",
"user_pass",
"=",
"'{username!s}:{password!s}@'",
".",
"for... | Painstakingly reconstruct a MongoDB URI parsed using pymongo.uri_parser.parse_uri.
:param parsed_uri: Result of pymongo.uri_parser.parse_uri
:type parsed_uri: dict
:return: New URI
:rtype: str | unicode | [
"Painstakingly",
"reconstruct",
"a",
"MongoDB",
"URI",
"parsed",
"using",
"pymongo",
".",
"uri_parser",
".",
"parse_uri",
"."
] | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/storage.py#L173-L215 |
IdentityPython/pyop | src/pyop/storage.py | MongoDB.sanitized_uri | def sanitized_uri(self):
"""
Return the database URI we're using in a format sensible for logging etc.
:return: db_uri
"""
if self._sanitized_uri is None:
_parsed = copy.copy(self._parsed_uri)
if 'username' in _parsed:
_parsed['password'] ... | python | def sanitized_uri(self):
"""
Return the database URI we're using in a format sensible for logging etc.
:return: db_uri
"""
if self._sanitized_uri is None:
_parsed = copy.copy(self._parsed_uri)
if 'username' in _parsed:
_parsed['password'] ... | [
"def",
"sanitized_uri",
"(",
"self",
")",
":",
"if",
"self",
".",
"_sanitized_uri",
"is",
"None",
":",
"_parsed",
"=",
"copy",
".",
"copy",
"(",
"self",
".",
"_parsed_uri",
")",
"if",
"'username'",
"in",
"_parsed",
":",
"_parsed",
"[",
"'password'",
"]",... | Return the database URI we're using in a format sensible for logging etc.
:return: db_uri | [
"Return",
"the",
"database",
"URI",
"we",
"re",
"using",
"in",
"a",
"format",
"sensible",
"for",
"logging",
"etc",
"."
] | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/storage.py#L102-L114 |
IdentityPython/pyop | src/pyop/storage.py | MongoDB.get_database | def get_database(self, database_name=None, username=None, password=None):
"""
Get a pymongo database handle, after authenticating.
Authenticates using the username/password in the DB URI given to
__init__() unless username/password is supplied as arguments.
:param database_name... | python | def get_database(self, database_name=None, username=None, password=None):
"""
Get a pymongo database handle, after authenticating.
Authenticates using the username/password in the DB URI given to
__init__() unless username/password is supplied as arguments.
:param database_name... | [
"def",
"get_database",
"(",
"self",
",",
"database_name",
"=",
"None",
",",
"username",
"=",
"None",
",",
"password",
"=",
"None",
")",
":",
"if",
"database_name",
"is",
"None",
":",
"database_name",
"=",
"self",
".",
"_database_name",
"if",
"database_name",... | Get a pymongo database handle, after authenticating.
Authenticates using the username/password in the DB URI given to
__init__() unless username/password is supplied as arguments.
:param database_name: (optional) Name of database
:param username: (optional) Username to login with
... | [
"Get",
"a",
"pymongo",
"database",
"handle",
"after",
"authenticating",
"."
] | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/storage.py#L123-L154 |
IdentityPython/pyop | src/pyop/storage.py | MongoDB.get_collection | def get_collection(self, collection, database_name=None, username=None, password=None):
"""
Get a pymongo collection handle.
:param collection: Name of collection
:param database_name: (optional) Name of database
:param username: (optional) Username to login with
:param ... | python | def get_collection(self, collection, database_name=None, username=None, password=None):
"""
Get a pymongo collection handle.
:param collection: Name of collection
:param database_name: (optional) Name of database
:param username: (optional) Username to login with
:param ... | [
"def",
"get_collection",
"(",
"self",
",",
"collection",
",",
"database_name",
"=",
"None",
",",
"username",
"=",
"None",
",",
"password",
"=",
"None",
")",
":",
"_db",
"=",
"self",
".",
"get_database",
"(",
"database_name",
",",
"username",
",",
"password... | Get a pymongo collection handle.
:param collection: Name of collection
:param database_name: (optional) Name of database
:param username: (optional) Username to login with
:param password: (optional) Password to login with
:return: Pymongo collection object | [
"Get",
"a",
"pymongo",
"collection",
"handle",
"."
] | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/storage.py#L156-L167 |
slinderman/pypolyagamma | pypolyagamma/binary_trees.py | balanced_binary_tree | def balanced_binary_tree(n_leaves):
"""
Create a balanced binary tree
"""
def _balanced_subtree(leaves):
if len(leaves) == 1:
return leaves[0]
elif len(leaves) == 2:
return (leaves[0], leaves[1])
else:
split = len(leaves) // 2
retur... | python | def balanced_binary_tree(n_leaves):
"""
Create a balanced binary tree
"""
def _balanced_subtree(leaves):
if len(leaves) == 1:
return leaves[0]
elif len(leaves) == 2:
return (leaves[0], leaves[1])
else:
split = len(leaves) // 2
retur... | [
"def",
"balanced_binary_tree",
"(",
"n_leaves",
")",
":",
"def",
"_balanced_subtree",
"(",
"leaves",
")",
":",
"if",
"len",
"(",
"leaves",
")",
"==",
"1",
":",
"return",
"leaves",
"[",
"0",
"]",
"elif",
"len",
"(",
"leaves",
")",
"==",
"2",
":",
"ret... | Create a balanced binary tree | [
"Create",
"a",
"balanced",
"binary",
"tree"
] | train | https://github.com/slinderman/pypolyagamma/blob/abdc0c53e5114092998f51bf66f1900bc567f0bd/pypolyagamma/binary_trees.py#L32-L46 |
slinderman/pypolyagamma | pypolyagamma/binary_trees.py | decision_list | def decision_list(n_leaves):
"""
Create a decision list
"""
def _list(leaves):
if len(leaves) == 2:
return (leaves[0], leaves[1])
else:
return (leaves[0], _list(leaves[1:]))
return _list(np.arange(n_leaves)) | python | def decision_list(n_leaves):
"""
Create a decision list
"""
def _list(leaves):
if len(leaves) == 2:
return (leaves[0], leaves[1])
else:
return (leaves[0], _list(leaves[1:]))
return _list(np.arange(n_leaves)) | [
"def",
"decision_list",
"(",
"n_leaves",
")",
":",
"def",
"_list",
"(",
"leaves",
")",
":",
"if",
"len",
"(",
"leaves",
")",
"==",
"2",
":",
"return",
"(",
"leaves",
"[",
"0",
"]",
",",
"leaves",
"[",
"1",
"]",
")",
"else",
":",
"return",
"(",
... | Create a decision list | [
"Create",
"a",
"decision",
"list"
] | train | https://github.com/slinderman/pypolyagamma/blob/abdc0c53e5114092998f51bf66f1900bc567f0bd/pypolyagamma/binary_trees.py#L48-L57 |
slinderman/pypolyagamma | pypolyagamma/binary_trees.py | random_tree | def random_tree(n_leaves):
"""
Randomly partition the nodes
"""
def _random_subtree(leaves):
if len(leaves) == 1:
return leaves[0]
elif len(leaves) == 2:
return (leaves[0], leaves[1])
else:
split = npr.randint(1, len(leaves)-1)
retu... | python | def random_tree(n_leaves):
"""
Randomly partition the nodes
"""
def _random_subtree(leaves):
if len(leaves) == 1:
return leaves[0]
elif len(leaves) == 2:
return (leaves[0], leaves[1])
else:
split = npr.randint(1, len(leaves)-1)
retu... | [
"def",
"random_tree",
"(",
"n_leaves",
")",
":",
"def",
"_random_subtree",
"(",
"leaves",
")",
":",
"if",
"len",
"(",
"leaves",
")",
"==",
"1",
":",
"return",
"leaves",
"[",
"0",
"]",
"elif",
"len",
"(",
"leaves",
")",
"==",
"2",
":",
"return",
"("... | Randomly partition the nodes | [
"Randomly",
"partition",
"the",
"nodes"
] | train | https://github.com/slinderman/pypolyagamma/blob/abdc0c53e5114092998f51bf66f1900bc567f0bd/pypolyagamma/binary_trees.py#L60-L74 |
slinderman/pypolyagamma | pypolyagamma/binary_trees.py | leaves | def leaves(tree):
"""
Return the leaves in this subtree.
"""
lvs = []
def _leaves(node):
if np.isscalar(node):
lvs.append(node)
elif isinstance(node, tuple) and len(node) == 2:
_leaves(node[0])
_leaves(node[1])
else:
raise Excep... | python | def leaves(tree):
"""
Return the leaves in this subtree.
"""
lvs = []
def _leaves(node):
if np.isscalar(node):
lvs.append(node)
elif isinstance(node, tuple) and len(node) == 2:
_leaves(node[0])
_leaves(node[1])
else:
raise Excep... | [
"def",
"leaves",
"(",
"tree",
")",
":",
"lvs",
"=",
"[",
"]",
"def",
"_leaves",
"(",
"node",
")",
":",
"if",
"np",
".",
"isscalar",
"(",
"node",
")",
":",
"lvs",
".",
"append",
"(",
"node",
")",
"elif",
"isinstance",
"(",
"node",
",",
"tuple",
... | Return the leaves in this subtree. | [
"Return",
"the",
"leaves",
"in",
"this",
"subtree",
"."
] | train | https://github.com/slinderman/pypolyagamma/blob/abdc0c53e5114092998f51bf66f1900bc567f0bd/pypolyagamma/binary_trees.py#L77-L92 |
slinderman/pypolyagamma | pypolyagamma/binary_trees.py | choices | def choices(tree):
"""
Get the 'address' of each leaf node in terms of internal
node choices
"""
n = len(leaves(tree))
addr = np.nan * np.ones((n, n-1))
def _addresses(node, index, choices):
# index is the index of the current internal node
# choices is a list of (indice, 0/1... | python | def choices(tree):
"""
Get the 'address' of each leaf node in terms of internal
node choices
"""
n = len(leaves(tree))
addr = np.nan * np.ones((n, n-1))
def _addresses(node, index, choices):
# index is the index of the current internal node
# choices is a list of (indice, 0/1... | [
"def",
"choices",
"(",
"tree",
")",
":",
"n",
"=",
"len",
"(",
"leaves",
"(",
"tree",
")",
")",
"addr",
"=",
"np",
".",
"nan",
"*",
"np",
".",
"ones",
"(",
"(",
"n",
",",
"n",
"-",
"1",
")",
")",
"def",
"_addresses",
"(",
"node",
",",
"inde... | Get the 'address' of each leaf node in terms of internal
node choices | [
"Get",
"the",
"address",
"of",
"each",
"leaf",
"node",
"in",
"terms",
"of",
"internal",
"node",
"choices"
] | train | https://github.com/slinderman/pypolyagamma/blob/abdc0c53e5114092998f51bf66f1900bc567f0bd/pypolyagamma/binary_trees.py#L95-L119 |
slinderman/pypolyagamma | pypolyagamma/binary_trees.py | adjacency | def adjacency(tree):
"""
Construct the adjacency matrix of the tree
:param tree:
:return:
"""
dd = ids(tree)
N = len(dd)
A = np.zeros((N, N))
def _adj(node):
if np.isscalar(node):
return
elif isinstance(node, tuple) and len(node) == 2:
A[dd[no... | python | def adjacency(tree):
"""
Construct the adjacency matrix of the tree
:param tree:
:return:
"""
dd = ids(tree)
N = len(dd)
A = np.zeros((N, N))
def _adj(node):
if np.isscalar(node):
return
elif isinstance(node, tuple) and len(node) == 2:
A[dd[no... | [
"def",
"adjacency",
"(",
"tree",
")",
":",
"dd",
"=",
"ids",
"(",
"tree",
")",
"N",
"=",
"len",
"(",
"dd",
")",
"A",
"=",
"np",
".",
"zeros",
"(",
"(",
"N",
",",
"N",
")",
")",
"def",
"_adj",
"(",
"node",
")",
":",
"if",
"np",
".",
"issca... | Construct the adjacency matrix of the tree
:param tree:
:return: | [
"Construct",
"the",
"adjacency",
"matrix",
"of",
"the",
"tree",
":",
"param",
"tree",
":",
":",
"return",
":"
] | train | https://github.com/slinderman/pypolyagamma/blob/abdc0c53e5114092998f51bf66f1900bc567f0bd/pypolyagamma/binary_trees.py#L137-L160 |
slinderman/pypolyagamma | pypolyagamma/distributions.py | BernoulliRegression.max_likelihood | def max_likelihood(self, data, weights=None, stats=None, lmbda=0.1):
"""
As an alternative to MCMC with Polya-gamma augmentation,
we also implement maximum likelihood learning via gradient
descent with autograd. This follows the pybasicbayes
convention.
:param data: list... | python | def max_likelihood(self, data, weights=None, stats=None, lmbda=0.1):
"""
As an alternative to MCMC with Polya-gamma augmentation,
we also implement maximum likelihood learning via gradient
descent with autograd. This follows the pybasicbayes
convention.
:param data: list... | [
"def",
"max_likelihood",
"(",
"self",
",",
"data",
",",
"weights",
"=",
"None",
",",
"stats",
"=",
"None",
",",
"lmbda",
"=",
"0.1",
")",
":",
"import",
"autograd",
".",
"numpy",
"as",
"anp",
"from",
"autograd",
"import",
"value_and_grad",
",",
"hessian_... | As an alternative to MCMC with Polya-gamma augmentation,
we also implement maximum likelihood learning via gradient
descent with autograd. This follows the pybasicbayes
convention.
:param data: list of tuples, (x,y), for each dataset.
:param weights: Not used in this implementat... | [
"As",
"an",
"alternative",
"to",
"MCMC",
"with",
"Polya",
"-",
"gamma",
"augmentation",
"we",
"also",
"implement",
"maximum",
"likelihood",
"learning",
"via",
"gradient",
"descent",
"with",
"autograd",
".",
"This",
"follows",
"the",
"pybasicbayes",
"convention",
... | train | https://github.com/slinderman/pypolyagamma/blob/abdc0c53e5114092998f51bf66f1900bc567f0bd/pypolyagamma/distributions.py#L222-L278 |
slinderman/pypolyagamma | pypolyagamma/distributions.py | TreeStructuredMultinomialRegression.resample | def resample(self, data, mask=None, omega=None):
"""
Multinomial regression is somewhat special. We have to compute the
kappa functions for the entire dataset, not just for one column of
the data at a time.
"""
if not isinstance(data, list):
assert isinstance(... | python | def resample(self, data, mask=None, omega=None):
"""
Multinomial regression is somewhat special. We have to compute the
kappa functions for the entire dataset, not just for one column of
the data at a time.
"""
if not isinstance(data, list):
assert isinstance(... | [
"def",
"resample",
"(",
"self",
",",
"data",
",",
"mask",
"=",
"None",
",",
"omega",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"data",
",",
"list",
")",
":",
"assert",
"isinstance",
"(",
"data",
",",
"tuple",
")",
"and",
"len",
"(",
... | Multinomial regression is somewhat special. We have to compute the
kappa functions for the entire dataset, not just for one column of
the data at a time. | [
"Multinomial",
"regression",
"is",
"somewhat",
"special",
".",
"We",
"have",
"to",
"compute",
"the",
"kappa",
"functions",
"for",
"the",
"entire",
"dataset",
"not",
"just",
"for",
"one",
"column",
"of",
"the",
"data",
"at",
"a",
"time",
"."
] | train | https://github.com/slinderman/pypolyagamma/blob/abdc0c53e5114092998f51bf66f1900bc567f0bd/pypolyagamma/distributions.py#L436-L488 |
IdentityPython/pyop | src/pyop/userinfo.py | Userinfo.get_claims_for | def get_claims_for(self, user_id, requested_claims):
# type: (str, Mapping[str, Optional[Mapping[str, Union[str, List[str]]]]) -> Dict[str, Union[str, List[str]]]
"""
Filter the userinfo based on which claims where requested.
:param user_id: user identifier
:param requested_claim... | python | def get_claims_for(self, user_id, requested_claims):
# type: (str, Mapping[str, Optional[Mapping[str, Union[str, List[str]]]]) -> Dict[str, Union[str, List[str]]]
"""
Filter the userinfo based on which claims where requested.
:param user_id: user identifier
:param requested_claim... | [
"def",
"get_claims_for",
"(",
"self",
",",
"user_id",
",",
"requested_claims",
")",
":",
"# type: (str, Mapping[str, Optional[Mapping[str, Union[str, List[str]]]]) -> Dict[str, Union[str, List[str]]]",
"userinfo",
"=",
"self",
".",
"_db",
"[",
"user_id",
"]",
"claims",
"=",
... | Filter the userinfo based on which claims where requested.
:param user_id: user identifier
:param requested_claims: see <a href="http://openid.net/specs/openid-connect-core-1_0.html#ClaimsParameter">
"OpenID Connect Core 1.0", Section 5.5</a> for structure
:return: All requested clai... | [
"Filter",
"the",
"userinfo",
"based",
"on",
"which",
"claims",
"where",
"requested",
".",
":",
"param",
"user_id",
":",
"user",
"identifier",
":",
"param",
"requested_claims",
":",
"see",
"<a",
"href",
"=",
"http",
":",
"//",
"openid",
".",
"net",
"/",
"... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/userinfo.py#L21-L33 |
IdentityPython/pyop | src/pyop/authz_state.py | AuthorizationState.create_authorization_code | def create_authorization_code(self, authorization_request, subject_identifier, scope=None):
# type: (oic.oic.message.AuthorizationRequest, str, Optional[List[str]]) -> str
"""
Creates an authorization code bound to the authorization request and the authenticated user identified
by the su... | python | def create_authorization_code(self, authorization_request, subject_identifier, scope=None):
# type: (oic.oic.message.AuthorizationRequest, str, Optional[List[str]]) -> str
"""
Creates an authorization code bound to the authorization request and the authenticated user identified
by the su... | [
"def",
"create_authorization_code",
"(",
"self",
",",
"authorization_request",
",",
"subject_identifier",
",",
"scope",
"=",
"None",
")",
":",
"# type: (oic.oic.message.AuthorizationRequest, str, Optional[List[str]]) -> str",
"if",
"not",
"self",
".",
"_is_valid_subject_identif... | Creates an authorization code bound to the authorization request and the authenticated user identified
by the subject identifier. | [
"Creates",
"an",
"authorization",
"code",
"bound",
"to",
"the",
"authorization",
"request",
"and",
"the",
"authenticated",
"user",
"identified",
"by",
"the",
"subject",
"identifier",
"."
] | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/authz_state.py#L82-L106 |
IdentityPython/pyop | src/pyop/authz_state.py | AuthorizationState.create_access_token | def create_access_token(self, authorization_request, subject_identifier, scope=None):
# type: (oic.oic.message.AuthorizationRequest, str, Optional[List[str]]) -> se_leg_op.access_token.AccessToken
"""
Creates an access token bound to the authentication request and the authenticated user identifi... | python | def create_access_token(self, authorization_request, subject_identifier, scope=None):
# type: (oic.oic.message.AuthorizationRequest, str, Optional[List[str]]) -> se_leg_op.access_token.AccessToken
"""
Creates an access token bound to the authentication request and the authenticated user identifi... | [
"def",
"create_access_token",
"(",
"self",
",",
"authorization_request",
",",
"subject_identifier",
",",
"scope",
"=",
"None",
")",
":",
"# type: (oic.oic.message.AuthorizationRequest, str, Optional[List[str]]) -> se_leg_op.access_token.AccessToken",
"if",
"not",
"self",
".",
"... | Creates an access token bound to the authentication request and the authenticated user identified by the
subject identifier. | [
"Creates",
"an",
"access",
"token",
"bound",
"to",
"the",
"authentication",
"request",
"and",
"the",
"authenticated",
"user",
"identified",
"by",
"the",
"subject",
"identifier",
"."
] | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/authz_state.py#L108-L119 |
IdentityPython/pyop | src/pyop/authz_state.py | AuthorizationState._create_access_token | def _create_access_token(self, subject_identifier, auth_req, granted_scope, current_scope=None):
# type: (str, Mapping[str, Union[str, List[str]]], str, Optional[str]) -> se_leg_op.access_token.AccessToken
"""
Creates an access token bound to the subject identifier, client id and requested scope... | python | def _create_access_token(self, subject_identifier, auth_req, granted_scope, current_scope=None):
# type: (str, Mapping[str, Union[str, List[str]]], str, Optional[str]) -> se_leg_op.access_token.AccessToken
"""
Creates an access token bound to the subject identifier, client id and requested scope... | [
"def",
"_create_access_token",
"(",
"self",
",",
"subject_identifier",
",",
"auth_req",
",",
"granted_scope",
",",
"current_scope",
"=",
"None",
")",
":",
"# type: (str, Mapping[str, Union[str, List[str]]], str, Optional[str]) -> se_leg_op.access_token.AccessToken",
"access_token",... | Creates an access token bound to the subject identifier, client id and requested scope. | [
"Creates",
"an",
"access",
"token",
"bound",
"to",
"the",
"subject",
"identifier",
"client",
"id",
"and",
"requested",
"scope",
"."
] | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/authz_state.py#L121-L146 |
IdentityPython/pyop | src/pyop/authz_state.py | AuthorizationState.exchange_code_for_token | def exchange_code_for_token(self, authorization_code):
# type: (str) -> se_leg_op.access_token.AccessToken
"""
Exchanges an authorization code for an access token.
"""
if authorization_code not in self.authorization_codes:
raise InvalidAuthorizationCode('{} unknown'.f... | python | def exchange_code_for_token(self, authorization_code):
# type: (str) -> se_leg_op.access_token.AccessToken
"""
Exchanges an authorization code for an access token.
"""
if authorization_code not in self.authorization_codes:
raise InvalidAuthorizationCode('{} unknown'.f... | [
"def",
"exchange_code_for_token",
"(",
"self",
",",
"authorization_code",
")",
":",
"# type: (str) -> se_leg_op.access_token.AccessToken",
"if",
"authorization_code",
"not",
"in",
"self",
".",
"authorization_codes",
":",
"raise",
"InvalidAuthorizationCode",
"(",
"'{} unknown'... | Exchanges an authorization code for an access token. | [
"Exchanges",
"an",
"authorization",
"code",
"for",
"an",
"access",
"token",
"."
] | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/authz_state.py#L148-L171 |
IdentityPython/pyop | src/pyop/authz_state.py | AuthorizationState.introspect_access_token | def introspect_access_token(self, access_token_value):
# type: (str) -> Dict[str, Union[str, List[str]]]
"""
Returns authorization data associated with the access token.
See <a href="https://tools.ietf.org/html/rfc7662">"Token Introspection", Section 2.2</a>.
"""
if acces... | python | def introspect_access_token(self, access_token_value):
# type: (str) -> Dict[str, Union[str, List[str]]]
"""
Returns authorization data associated with the access token.
See <a href="https://tools.ietf.org/html/rfc7662">"Token Introspection", Section 2.2</a>.
"""
if acces... | [
"def",
"introspect_access_token",
"(",
"self",
",",
"access_token_value",
")",
":",
"# type: (str) -> Dict[str, Union[str, List[str]]]",
"if",
"access_token_value",
"not",
"in",
"self",
".",
"access_tokens",
":",
"raise",
"InvalidAccessToken",
"(",
"'{} unknown'",
".",
"f... | Returns authorization data associated with the access token.
See <a href="https://tools.ietf.org/html/rfc7662">"Token Introspection", Section 2.2</a>. | [
"Returns",
"authorization",
"data",
"associated",
"with",
"the",
"access",
"token",
".",
"See",
"<a",
"href",
"=",
"https",
":",
"//",
"tools",
".",
"ietf",
".",
"org",
"/",
"html",
"/",
"rfc7662",
">",
"Token",
"Introspection",
"Section",
"2",
".",
"2<"... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/authz_state.py#L173-L188 |
IdentityPython/pyop | src/pyop/authz_state.py | AuthorizationState.create_refresh_token | def create_refresh_token(self, access_token_value):
# type: (str) -> str
"""
Creates an refresh token bound to the specified access token.
"""
if access_token_value not in self.access_tokens:
raise InvalidAccessToken('{} unknown'.format(access_token_value))
i... | python | def create_refresh_token(self, access_token_value):
# type: (str) -> str
"""
Creates an refresh token bound to the specified access token.
"""
if access_token_value not in self.access_tokens:
raise InvalidAccessToken('{} unknown'.format(access_token_value))
i... | [
"def",
"create_refresh_token",
"(",
"self",
",",
"access_token_value",
")",
":",
"# type: (str) -> str",
"if",
"access_token_value",
"not",
"in",
"self",
".",
"access_tokens",
":",
"raise",
"InvalidAccessToken",
"(",
"'{} unknown'",
".",
"format",
"(",
"access_token_v... | Creates an refresh token bound to the specified access token. | [
"Creates",
"an",
"refresh",
"token",
"bound",
"to",
"the",
"specified",
"access",
"token",
"."
] | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/authz_state.py#L190-L208 |
IdentityPython/pyop | src/pyop/authz_state.py | AuthorizationState.use_refresh_token | def use_refresh_token(self, refresh_token, scope=None):
# type (str, Optional[List[str]]) -> Tuple[se_leg_op.access_token.AccessToken, Optional[str]]
"""
Creates a new access token, and refresh token, based on the supplied refresh token.
:return: new access token and new refresh token if... | python | def use_refresh_token(self, refresh_token, scope=None):
# type (str, Optional[List[str]]) -> Tuple[se_leg_op.access_token.AccessToken, Optional[str]]
"""
Creates a new access token, and refresh token, based on the supplied refresh token.
:return: new access token and new refresh token if... | [
"def",
"use_refresh_token",
"(",
"self",
",",
"refresh_token",
",",
"scope",
"=",
"None",
")",
":",
"# type (str, Optional[List[str]]) -> Tuple[se_leg_op.access_token.AccessToken, Optional[str]]",
"if",
"refresh_token",
"not",
"in",
"self",
".",
"refresh_tokens",
":",
"rais... | Creates a new access token, and refresh token, based on the supplied refresh token.
:return: new access token and new refresh token if the old one had an expiration time | [
"Creates",
"a",
"new",
"access",
"token",
"and",
"refresh",
"token",
"based",
"on",
"the",
"supplied",
"refresh",
"token",
".",
":",
"return",
":",
"new",
"access",
"token",
"and",
"new",
"refresh",
"token",
"if",
"the",
"old",
"one",
"had",
"an",
"expir... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/authz_state.py#L210-L251 |
IdentityPython/pyop | src/pyop/authz_state.py | AuthorizationState.get_subject_identifier | def get_subject_identifier(self, subject_type, user_id, sector_identifier=None):
# type: (str, str, str) -> str
"""
Returns a subject identifier for the local user identifier.
:param subject_type: 'pairwise' or 'public', see
<a href="http://openid.net/specs/openid-connect-cor... | python | def get_subject_identifier(self, subject_type, user_id, sector_identifier=None):
# type: (str, str, str) -> str
"""
Returns a subject identifier for the local user identifier.
:param subject_type: 'pairwise' or 'public', see
<a href="http://openid.net/specs/openid-connect-cor... | [
"def",
"get_subject_identifier",
"(",
"self",
",",
"subject_type",
",",
"user_id",
",",
"sector_identifier",
"=",
"None",
")",
":",
"# type: (str, str, str) -> str",
"if",
"user_id",
"not",
"in",
"self",
".",
"subject_identifiers",
":",
"self",
".",
"subject_identif... | Returns a subject identifier for the local user identifier.
:param subject_type: 'pairwise' or 'public', see
<a href="http://openid.net/specs/openid-connect-core-1_0.html#SubjectIDTypes">
"OpenID Connect Core 1.0", Section 8</a>.
:param user_id: local user identifier
:par... | [
"Returns",
"a",
"subject",
"identifier",
"for",
"the",
"local",
"user",
"identifier",
".",
":",
"param",
"subject_type",
":",
"pairwise",
"or",
"public",
"see",
"<a",
"href",
"=",
"http",
":",
"//",
"openid",
".",
"net",
"/",
"specs",
"/",
"openid",
"-",... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/authz_state.py#L253-L293 |
IdentityPython/pyop | src/pyop/request_validator.py | authorization_request_verify | def authorization_request_verify(authentication_request):
"""
Verifies that all required parameters and correct values are included in the authentication request.
:param authentication_request: the authentication request to verify
:raise InvalidAuthenticationRequest: if the authentication is incorrect
... | python | def authorization_request_verify(authentication_request):
"""
Verifies that all required parameters and correct values are included in the authentication request.
:param authentication_request: the authentication request to verify
:raise InvalidAuthenticationRequest: if the authentication is incorrect
... | [
"def",
"authorization_request_verify",
"(",
"authentication_request",
")",
":",
"try",
":",
"authentication_request",
".",
"verify",
"(",
")",
"except",
"MessageException",
"as",
"e",
":",
"raise",
"InvalidAuthenticationRequest",
"(",
"str",
"(",
"e",
")",
",",
"a... | Verifies that all required parameters and correct values are included in the authentication request.
:param authentication_request: the authentication request to verify
:raise InvalidAuthenticationRequest: if the authentication is incorrect | [
"Verifies",
"that",
"all",
"required",
"parameters",
"and",
"correct",
"values",
"are",
"included",
"in",
"the",
"authentication",
"request",
".",
":",
"param",
"authentication_request",
":",
"the",
"authentication",
"request",
"to",
"verify",
":",
"raise",
"Inval... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/request_validator.py#L12-L21 |
IdentityPython/pyop | src/pyop/request_validator.py | client_id_is_known | def client_id_is_known(provider, authentication_request):
"""
Verifies the client identifier is known.
:param provider: provider instance
:param authentication_request: the authentication request to verify
:raise InvalidAuthenticationRequest: if the client_id is unknown
"""
if authentication... | python | def client_id_is_known(provider, authentication_request):
"""
Verifies the client identifier is known.
:param provider: provider instance
:param authentication_request: the authentication request to verify
:raise InvalidAuthenticationRequest: if the client_id is unknown
"""
if authentication... | [
"def",
"client_id_is_known",
"(",
"provider",
",",
"authentication_request",
")",
":",
"if",
"authentication_request",
"[",
"'client_id'",
"]",
"not",
"in",
"provider",
".",
"clients",
":",
"logger",
".",
"error",
"(",
"'Unknown client_id \\'{}\\''",
".",
"format",
... | Verifies the client identifier is known.
:param provider: provider instance
:param authentication_request: the authentication request to verify
:raise InvalidAuthenticationRequest: if the client_id is unknown | [
"Verifies",
"the",
"client",
"identifier",
"is",
"known",
".",
":",
"param",
"provider",
":",
"provider",
"instance",
":",
"param",
"authentication_request",
":",
"the",
"authentication",
"request",
"to",
"verify",
":",
"raise",
"InvalidAuthenticationRequest",
":",
... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/request_validator.py#L24-L35 |
IdentityPython/pyop | src/pyop/request_validator.py | redirect_uri_is_in_registered_redirect_uris | def redirect_uri_is_in_registered_redirect_uris(provider, authentication_request):
"""
Verifies the redirect uri is registered for the client making the request.
:param provider: provider instance
:param authentication_request: authentication request to verify
:raise InvalidAuthenticationRequest: if... | python | def redirect_uri_is_in_registered_redirect_uris(provider, authentication_request):
"""
Verifies the redirect uri is registered for the client making the request.
:param provider: provider instance
:param authentication_request: authentication request to verify
:raise InvalidAuthenticationRequest: if... | [
"def",
"redirect_uri_is_in_registered_redirect_uris",
"(",
"provider",
",",
"authentication_request",
")",
":",
"error",
"=",
"InvalidAuthenticationRequest",
"(",
"'Redirect uri is not registered'",
",",
"authentication_request",
",",
"oauth_error",
"=",
"\"invalid_request\"",
... | Verifies the redirect uri is registered for the client making the request.
:param provider: provider instance
:param authentication_request: authentication request to verify
:raise InvalidAuthenticationRequest: if the redirect uri is not registered | [
"Verifies",
"the",
"redirect",
"uri",
"is",
"registered",
"for",
"the",
"client",
"making",
"the",
"request",
".",
":",
"param",
"provider",
":",
"provider",
"instance",
":",
"param",
"authentication_request",
":",
"authentication",
"request",
"to",
"verify",
":... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/request_validator.py#L37-L55 |
IdentityPython/pyop | src/pyop/request_validator.py | response_type_is_in_registered_response_types | def response_type_is_in_registered_response_types(provider, authentication_request):
"""
Verifies that the requested response type is allowed for the client making the request.
:param provider: provider instance
:param authentication_request: authentication request to verify
:raise InvalidAuthentica... | python | def response_type_is_in_registered_response_types(provider, authentication_request):
"""
Verifies that the requested response type is allowed for the client making the request.
:param provider: provider instance
:param authentication_request: authentication request to verify
:raise InvalidAuthentica... | [
"def",
"response_type_is_in_registered_response_types",
"(",
"provider",
",",
"authentication_request",
")",
":",
"error",
"=",
"InvalidAuthenticationRequest",
"(",
"'Response type is not registered'",
",",
"authentication_request",
",",
"oauth_error",
"=",
"'invalid_request'",
... | Verifies that the requested response type is allowed for the client making the request.
:param provider: provider instance
:param authentication_request: authentication request to verify
:raise InvalidAuthenticationRequest: if the response type is not allowed | [
"Verifies",
"that",
"the",
"requested",
"response",
"type",
"is",
"allowed",
"for",
"the",
"client",
"making",
"the",
"request",
".",
":",
"param",
"provider",
":",
"provider",
"instance",
":",
"param",
"authentication_request",
":",
"authentication",
"request",
... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/request_validator.py#L58-L76 |
IdentityPython/pyop | src/pyop/request_validator.py | userinfo_claims_only_specified_when_access_token_is_issued | def userinfo_claims_only_specified_when_access_token_is_issued(authentication_request):
"""
According to <a href="http://openid.net/specs/openid-connect-core-1_0.html#ClaimsParameter">
"OpenID Connect Core 1.0", Section 5.5</a>: "When the userinfo member is used, the request MUST
also use a response_typ... | python | def userinfo_claims_only_specified_when_access_token_is_issued(authentication_request):
"""
According to <a href="http://openid.net/specs/openid-connect-core-1_0.html#ClaimsParameter">
"OpenID Connect Core 1.0", Section 5.5</a>: "When the userinfo member is used, the request MUST
also use a response_typ... | [
"def",
"userinfo_claims_only_specified_when_access_token_is_issued",
"(",
"authentication_request",
")",
":",
"will_issue_access_token",
"=",
"authentication_request",
"[",
"'response_type'",
"]",
"!=",
"[",
"'id_token'",
"]",
"contains_userinfo_claims_request",
"=",
"'claims'",
... | According to <a href="http://openid.net/specs/openid-connect-core-1_0.html#ClaimsParameter">
"OpenID Connect Core 1.0", Section 5.5</a>: "When the userinfo member is used, the request MUST
also use a response_type value that results in an Access Token being issued to the Client for
use at the UserInfo Endpo... | [
"According",
"to",
"<a",
"href",
"=",
"http",
":",
"//",
"openid",
".",
"net",
"/",
"specs",
"/",
"openid",
"-",
"connect",
"-",
"core",
"-",
"1_0",
".",
"html#ClaimsParameter",
">",
"OpenID",
"Connect",
"Core",
"1",
".",
"0",
"Section",
"5",
".",
"5... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/request_validator.py#L79-L94 |
IdentityPython/pyop | src/pyop/request_validator.py | registration_request_verify | def registration_request_verify(registration_request):
"""
Verifies that all required parameters and correct values are included in the client registration request.
:param registration_request: the authentication request to verify
:raise InvalidClientRegistrationRequest: if the registration is incorrect... | python | def registration_request_verify(registration_request):
"""
Verifies that all required parameters and correct values are included in the client registration request.
:param registration_request: the authentication request to verify
:raise InvalidClientRegistrationRequest: if the registration is incorrect... | [
"def",
"registration_request_verify",
"(",
"registration_request",
")",
":",
"try",
":",
"registration_request",
".",
"verify",
"(",
")",
"except",
"MessageException",
"as",
"e",
":",
"raise",
"InvalidClientRegistrationRequest",
"(",
"str",
"(",
"e",
")",
",",
"re... | Verifies that all required parameters and correct values are included in the client registration request.
:param registration_request: the authentication request to verify
:raise InvalidClientRegistrationRequest: if the registration is incorrect | [
"Verifies",
"that",
"all",
"required",
"parameters",
"and",
"correct",
"values",
"are",
"included",
"in",
"the",
"client",
"registration",
"request",
".",
":",
"param",
"registration_request",
":",
"the",
"authentication",
"request",
"to",
"verify",
":",
"raise",
... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/request_validator.py#L106-L115 |
IdentityPython/pyop | src/pyop/request_validator.py | client_preferences_match_provider_capabilities | def client_preferences_match_provider_capabilities(provider, registration_request):
"""
Verifies that all requested preferences in the client metadata can be fulfilled by this provider.
:param registration_request: the authentication request to verify
:raise InvalidClientRegistrationRequest: if the regi... | python | def client_preferences_match_provider_capabilities(provider, registration_request):
"""
Verifies that all requested preferences in the client metadata can be fulfilled by this provider.
:param registration_request: the authentication request to verify
:raise InvalidClientRegistrationRequest: if the regi... | [
"def",
"client_preferences_match_provider_capabilities",
"(",
"provider",
",",
"registration_request",
")",
":",
"def",
"match",
"(",
"client_preference",
",",
"provider_capability",
")",
":",
"if",
"isinstance",
"(",
"client_preference",
",",
"list",
")",
":",
"# dea... | Verifies that all requested preferences in the client metadata can be fulfilled by this provider.
:param registration_request: the authentication request to verify
:raise InvalidClientRegistrationRequest: if the registration is incorrect | [
"Verifies",
"that",
"all",
"requested",
"preferences",
"in",
"the",
"client",
"metadata",
"can",
"be",
"fulfilled",
"by",
"this",
"provider",
".",
":",
"param",
"registration_request",
":",
"the",
"authentication",
"request",
"to",
"verify",
":",
"raise",
"Inval... | train | https://github.com/IdentityPython/pyop/blob/7b1385964f079c39752fce5f2dbcf458b8a92e56/src/pyop/request_validator.py#L118-L145 |
slinderman/pypolyagamma | pypolyagamma/utils.py | _psi_n | def _psi_n(x, n, b):
"""
Compute the n-th term in the infinite sum of
the Jacobi density.
"""
return 2**(b-1) / gamma(b) * (-1)**n * \
np.exp(gammaln(n+b) -
gammaln(n+1) +
np.log(2*n+b) -
0.5 * np.log(2*np.pi*x**3) -
(2*n+b)**2 / (8.*x)) | python | def _psi_n(x, n, b):
"""
Compute the n-th term in the infinite sum of
the Jacobi density.
"""
return 2**(b-1) / gamma(b) * (-1)**n * \
np.exp(gammaln(n+b) -
gammaln(n+1) +
np.log(2*n+b) -
0.5 * np.log(2*np.pi*x**3) -
(2*n+b)**2 / (8.*x)) | [
"def",
"_psi_n",
"(",
"x",
",",
"n",
",",
"b",
")",
":",
"return",
"2",
"**",
"(",
"b",
"-",
"1",
")",
"/",
"gamma",
"(",
"b",
")",
"*",
"(",
"-",
"1",
")",
"**",
"n",
"*",
"np",
".",
"exp",
"(",
"gammaln",
"(",
"n",
"+",
"b",
")",
"-... | Compute the n-th term in the infinite sum of
the Jacobi density. | [
"Compute",
"the",
"n",
"-",
"th",
"term",
"in",
"the",
"infinite",
"sum",
"of",
"the",
"Jacobi",
"density",
"."
] | train | https://github.com/slinderman/pypolyagamma/blob/abdc0c53e5114092998f51bf66f1900bc567f0bd/pypolyagamma/utils.py#L9-L19 |
slinderman/pypolyagamma | pypolyagamma/utils.py | _tilt | def _tilt(omega, b, psi):
"""
Compute the tilt of the PG density for value omega
and tilt psi.
:param omega: point at which to evaluate the density
:param psi: tilt parameter
"""
return np.cosh(psi/2.0)**b * np.exp(-psi**2/2.0 * omega) | python | def _tilt(omega, b, psi):
"""
Compute the tilt of the PG density for value omega
and tilt psi.
:param omega: point at which to evaluate the density
:param psi: tilt parameter
"""
return np.cosh(psi/2.0)**b * np.exp(-psi**2/2.0 * omega) | [
"def",
"_tilt",
"(",
"omega",
",",
"b",
",",
"psi",
")",
":",
"return",
"np",
".",
"cosh",
"(",
"psi",
"/",
"2.0",
")",
"**",
"b",
"*",
"np",
".",
"exp",
"(",
"-",
"psi",
"**",
"2",
"/",
"2.0",
"*",
"omega",
")"
] | Compute the tilt of the PG density for value omega
and tilt psi.
:param omega: point at which to evaluate the density
:param psi: tilt parameter | [
"Compute",
"the",
"tilt",
"of",
"the",
"PG",
"density",
"for",
"value",
"omega",
"and",
"tilt",
"psi",
"."
] | train | https://github.com/slinderman/pypolyagamma/blob/abdc0c53e5114092998f51bf66f1900bc567f0bd/pypolyagamma/utils.py#L21-L29 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.