repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 3
values | summary stringlengths 4 350 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
cozy/python_cozy_management | cozy_management/couchdb.py | create_token | def create_token():
'''
Create token file & create user
'''
username = id_generator()
password = id_generator()
create_couchdb_admin(username, password)
create_token_file(username, password)
return 'Token {} created'.format(username) | python | def create_token():
'''
Create token file & create user
'''
username = id_generator()
password = id_generator()
create_couchdb_admin(username, password)
create_token_file(username, password)
return 'Token {} created'.format(username) | [
"def",
"create_token",
"(",
")",
":",
"username",
"=",
"id_generator",
"(",
")",
"password",
"=",
"id_generator",
"(",
")",
"create_couchdb_admin",
"(",
"username",
",",
"password",
")",
"create_token_file",
"(",
"username",
",",
"password",
")",
"return",
"'T... | Create token file & create user | [
"Create",
"token",
"file",
"&",
"create",
"user"
] | 820cea58458ae3e067fa8cc2da38edbda4681dac | https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L200-L209 | train | Create token file & create user
|
cozy/python_cozy_management | cozy_management/couchdb.py | ping | def ping():
'''
Ping CozyDB with existing credentials
'''
try:
curl_couchdb('/cozy/')
ping = True
except requests.exceptions.ConnectionError, error:
print error
ping = False
return ping | python | def ping():
'''
Ping CozyDB with existing credentials
'''
try:
curl_couchdb('/cozy/')
ping = True
except requests.exceptions.ConnectionError, error:
print error
ping = False
return ping | [
"def",
"ping",
"(",
")",
":",
"try",
":",
"curl_couchdb",
"(",
"'/cozy/'",
")",
"ping",
"=",
"True",
"except",
"requests",
".",
"exceptions",
".",
"ConnectionError",
",",
"error",
":",
"print",
"error",
"ping",
"=",
"False",
"return",
"ping"
] | Ping CozyDB with existing credentials | [
"Ping",
"CozyDB",
"with",
"existing",
"credentials"
] | 820cea58458ae3e067fa8cc2da38edbda4681dac | https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L220-L230 | train | Ping CozyDB with existing credentials |
cozy/python_cozy_management | cozy_management/couchdb.py | get_cozy_param | def get_cozy_param(param):
'''
Get parameter in Cozy configuration
'''
try:
req = curl_couchdb('/cozy/_design/cozyinstance/_view/all')
rows = req.json()['rows']
if len(rows) == 0:
return None
else:
return rows[0].get('value', {}).get(param, Non... | python | def get_cozy_param(param):
'''
Get parameter in Cozy configuration
'''
try:
req = curl_couchdb('/cozy/_design/cozyinstance/_view/all')
rows = req.json()['rows']
if len(rows) == 0:
return None
else:
return rows[0].get('value', {}).get(param, Non... | [
"def",
"get_cozy_param",
"(",
"param",
")",
":",
"try",
":",
"req",
"=",
"curl_couchdb",
"(",
"'/cozy/_design/cozyinstance/_view/all'",
")",
"rows",
"=",
"req",
".",
"json",
"(",
")",
"[",
"'rows'",
"]",
"if",
"len",
"(",
"rows",
")",
"==",
"0",
":",
"... | Get parameter in Cozy configuration | [
"Get",
"parameter",
"in",
"Cozy",
"configuration"
] | 820cea58458ae3e067fa8cc2da38edbda4681dac | https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L233-L245 | train | Get parameter in Cozy configuration |
adaptive-learning/proso-apps | proso/conversion.py | str2type | def str2type(value):
"""
Take a string and convert it to a value of proper type.
.. testsetup::
from proso.coversion import str2type
.. doctest::
>>> print(str2type("[1, 2, 3]")
[1, 2, 3]
"""
if not isinstance(value, str):
return value
... | python | def str2type(value):
"""
Take a string and convert it to a value of proper type.
.. testsetup::
from proso.coversion import str2type
.. doctest::
>>> print(str2type("[1, 2, 3]")
[1, 2, 3]
"""
if not isinstance(value, str):
return value
... | [
"def",
"str2type",
"(",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"str",
")",
":",
"return",
"value",
"try",
":",
"return",
"json",
".",
"loads",
"(",
"value",
")",
"except",
"JSONDecodeError",
":",
"return",
"value"
] | Take a string and convert it to a value of proper type.
.. testsetup::
from proso.coversion import str2type
.. doctest::
>>> print(str2type("[1, 2, 3]")
[1, 2, 3] | [
"Take",
"a",
"string",
"and",
"convert",
"it",
"to",
"a",
"value",
"of",
"proper",
"type",
"."
] | 8278c72e498d6ef8d392cc47b48473f4ec037142 | https://github.com/adaptive-learning/proso-apps/blob/8278c72e498d6ef8d392cc47b48473f4ec037142/proso/conversion.py#L9-L28 | train | Take a string and convert it to a value of proper type. |
Alveo/pyalveo | pyalveo/pyalveo.py | OAuth2.to_dict | def to_dict(self):
"""
Returns a dict of all of it's necessary components.
Not the same as the __dict__ method
"""
data = dict()
data['api_url'] = self.api_url
data['api_key'] = self.api_key
data['verifySSL'] = self.verifySSL
data['client_i... | python | def to_dict(self):
"""
Returns a dict of all of it's necessary components.
Not the same as the __dict__ method
"""
data = dict()
data['api_url'] = self.api_url
data['api_key'] = self.api_key
data['verifySSL'] = self.verifySSL
data['client_i... | [
"def",
"to_dict",
"(",
"self",
")",
":",
"data",
"=",
"dict",
"(",
")",
"data",
"[",
"'api_url'",
"]",
"=",
"self",
".",
"api_url",
"data",
"[",
"'api_key'",
"]",
"=",
"self",
".",
"api_key",
"data",
"[",
"'verifySSL'",
"]",
"=",
"self",
".",
"veri... | Returns a dict of all of it's necessary components.
Not the same as the __dict__ method | [
"Returns",
"a",
"dict",
"of",
"all",
"of",
"it",
"s",
"necessary",
"components",
".",
"Not",
"the",
"same",
"as",
"the",
"__dict__",
"method"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L157-L172 | train | Returns a dict of all of the necessary components. |
Alveo/pyalveo | pyalveo/pyalveo.py | OAuth2.from_json | def from_json(json_data):
"""
Returns a pyalveo.OAuth2 given a json string built from the oauth.to_json() method.
"""
#If we have a string, then decode it, otherwise assume it's already decoded
if isinstance(json_data, str):
data = json.loads(json_data)
el... | python | def from_json(json_data):
"""
Returns a pyalveo.OAuth2 given a json string built from the oauth.to_json() method.
"""
#If we have a string, then decode it, otherwise assume it's already decoded
if isinstance(json_data, str):
data = json.loads(json_data)
el... | [
"def",
"from_json",
"(",
"json_data",
")",
":",
"#If we have a string, then decode it, otherwise assume it's already decoded",
"if",
"isinstance",
"(",
"json_data",
",",
"str",
")",
":",
"data",
"=",
"json",
".",
"loads",
"(",
"json_data",
")",
"else",
":",
"data",
... | Returns a pyalveo.OAuth2 given a json string built from the oauth.to_json() method. | [
"Returns",
"a",
"pyalveo",
".",
"OAuth2",
"given",
"a",
"json",
"string",
"built",
"from",
"the",
"oauth",
".",
"to_json",
"()",
"method",
"."
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L181-L199 | train | Returns a pyalveo. OAuth2 given a json string built from the oauth. to_json method. |
Alveo/pyalveo | pyalveo/pyalveo.py | OAuth2.get_authorisation_url | def get_authorisation_url(self, reset=False):
""" Initialises the OAuth2 Process by asking the auth server for a login URL.
Once called, the user can login by being redirected to the url returned by
this function.
If there is an error during authorisation, None is returned.""... | python | def get_authorisation_url(self, reset=False):
""" Initialises the OAuth2 Process by asking the auth server for a login URL.
Once called, the user can login by being redirected to the url returned by
this function.
If there is an error during authorisation, None is returned.""... | [
"def",
"get_authorisation_url",
"(",
"self",
",",
"reset",
"=",
"False",
")",
":",
"if",
"reset",
":",
"self",
".",
"auth_url",
"=",
"None",
"if",
"not",
"self",
".",
"auth_url",
":",
"try",
":",
"oauth",
"=",
"OAuth2Session",
"(",
"self",
".",
"client... | Initialises the OAuth2 Process by asking the auth server for a login URL.
Once called, the user can login by being redirected to the url returned by
this function.
If there is an error during authorisation, None is returned. | [
"Initialises",
"the",
"OAuth2",
"Process",
"by",
"asking",
"the",
"auth",
"server",
"for",
"a",
"login",
"URL",
".",
"Once",
"called",
"the",
"user",
"can",
"login",
"by",
"being",
"redirected",
"to",
"the",
"url",
"returned",
"by",
"this",
"function",
"."... | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L201-L218 | train | Initializes the OAuth2 Process by asking the auth server for a login URL. |
Alveo/pyalveo | pyalveo/pyalveo.py | OAuth2.on_callback | def on_callback(self,auth_resp):
""" Must be called once the authorisation server has responded after
redirecting to the url provided by 'get_authorisation_url' and completing
the login there.
Returns True if a token was successfully retrieved, False otherwise."""
try... | python | def on_callback(self,auth_resp):
""" Must be called once the authorisation server has responded after
redirecting to the url provided by 'get_authorisation_url' and completing
the login there.
Returns True if a token was successfully retrieved, False otherwise."""
try... | [
"def",
"on_callback",
"(",
"self",
",",
"auth_resp",
")",
":",
"try",
":",
"oauth",
"=",
"OAuth2Session",
"(",
"self",
".",
"client_id",
",",
"state",
"=",
"self",
".",
"state",
",",
"redirect_uri",
"=",
"self",
".",
"redirect_url",
")",
"self",
".",
"... | Must be called once the authorisation server has responded after
redirecting to the url provided by 'get_authorisation_url' and completing
the login there.
Returns True if a token was successfully retrieved, False otherwise. | [
"Must",
"be",
"called",
"once",
"the",
"authorisation",
"server",
"has",
"responded",
"after",
"redirecting",
"to",
"the",
"url",
"provided",
"by",
"get_authorisation_url",
"and",
"completing",
"the",
"login",
"there",
".",
"Returns",
"True",
"if",
"a",
"token",... | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L220-L239 | train | Called when the user has responded to the authorisation server and the user has requested a token. Returns True if a token was successfully retrieved False otherwise. |
Alveo/pyalveo | pyalveo/pyalveo.py | OAuth2.validate | def validate(self):
""" Confirms the current token is still valid.
Returns True if it is valid, False otherwise. """
try:
resp = self.request().get(self.validate_url, verify=self.verifySSL).json()
except TokenExpiredError:
return False
except AttributeEr... | python | def validate(self):
""" Confirms the current token is still valid.
Returns True if it is valid, False otherwise. """
try:
resp = self.request().get(self.validate_url, verify=self.verifySSL).json()
except TokenExpiredError:
return False
except AttributeEr... | [
"def",
"validate",
"(",
"self",
")",
":",
"try",
":",
"resp",
"=",
"self",
".",
"request",
"(",
")",
".",
"get",
"(",
"self",
".",
"validate_url",
",",
"verify",
"=",
"self",
".",
"verifySSL",
")",
".",
"json",
"(",
")",
"except",
"TokenExpiredError"... | Confirms the current token is still valid.
Returns True if it is valid, False otherwise. | [
"Confirms",
"the",
"current",
"token",
"is",
"still",
"valid",
".",
"Returns",
"True",
"if",
"it",
"is",
"valid",
"False",
"otherwise",
"."
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L241-L254 | train | Checks if the current token is still valid. Returns True if it is valid False otherwise. |
Alveo/pyalveo | pyalveo/pyalveo.py | OAuth2.refresh_token | def refresh_token(self):
""" Refreshes access token using refresh token. Returns true if successful, false otherwise. """
try:
if self.token:
self.token = self.request().refresh_token(self.refresh_url, self.token['refresh_token'])
return True
except ... | python | def refresh_token(self):
""" Refreshes access token using refresh token. Returns true if successful, false otherwise. """
try:
if self.token:
self.token = self.request().refresh_token(self.refresh_url, self.token['refresh_token'])
return True
except ... | [
"def",
"refresh_token",
"(",
"self",
")",
":",
"try",
":",
"if",
"self",
".",
"token",
":",
"self",
".",
"token",
"=",
"self",
".",
"request",
"(",
")",
".",
"refresh_token",
"(",
"self",
".",
"refresh_url",
",",
"self",
".",
"token",
"[",
"'refresh_... | Refreshes access token using refresh token. Returns true if successful, false otherwise. | [
"Refreshes",
"access",
"token",
"using",
"refresh",
"token",
".",
"Returns",
"true",
"if",
"successful",
"false",
"otherwise",
"."
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L256-L268 | train | Refreshes the access token using the refresh token. Returns true if successful False otherwise. |
Alveo/pyalveo | pyalveo/pyalveo.py | OAuth2.revoke_access | def revoke_access(self):
""" Requests that the currently used token becomes invalid. Call this should a user logout. """
if self.token is None:
return True
#Don't try to revoke if token is invalid anyway, will cause an error response anyway.
if self.validate():
d... | python | def revoke_access(self):
""" Requests that the currently used token becomes invalid. Call this should a user logout. """
if self.token is None:
return True
#Don't try to revoke if token is invalid anyway, will cause an error response anyway.
if self.validate():
d... | [
"def",
"revoke_access",
"(",
"self",
")",
":",
"if",
"self",
".",
"token",
"is",
"None",
":",
"return",
"True",
"#Don't try to revoke if token is invalid anyway, will cause an error response anyway.",
"if",
"self",
".",
"validate",
"(",
")",
":",
"data",
"=",
"{",
... | Requests that the currently used token becomes invalid. Call this should a user logout. | [
"Requests",
"that",
"the",
"currently",
"used",
"token",
"becomes",
"invalid",
".",
"Call",
"this",
"should",
"a",
"user",
"logout",
"."
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L270-L279 | train | Revoke access to the current user. |
Alveo/pyalveo | pyalveo/pyalveo.py | OAuth2.request | def request(self):
""" Returns an OAuth2 Session to be used to make requests.
Returns None if a token hasn't yet been received."""
headers = {'Accept': 'application/json'}
# Use API Key if possible
if self.api_key:
headers['X-API-KEY'] = self.api_key
ret... | python | def request(self):
""" Returns an OAuth2 Session to be used to make requests.
Returns None if a token hasn't yet been received."""
headers = {'Accept': 'application/json'}
# Use API Key if possible
if self.api_key:
headers['X-API-KEY'] = self.api_key
ret... | [
"def",
"request",
"(",
"self",
")",
":",
"headers",
"=",
"{",
"'Accept'",
":",
"'application/json'",
"}",
"# Use API Key if possible",
"if",
"self",
".",
"api_key",
":",
"headers",
"[",
"'X-API-KEY'",
"]",
"=",
"self",
".",
"api_key",
"return",
"requests",
"... | Returns an OAuth2 Session to be used to make requests.
Returns None if a token hasn't yet been received. | [
"Returns",
"an",
"OAuth2",
"Session",
"to",
"be",
"used",
"to",
"make",
"requests",
".",
"Returns",
"None",
"if",
"a",
"token",
"hasn",
"t",
"yet",
"been",
"received",
"."
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L317-L332 | train | Returns an OAuth2 Session to be used to make requests. Returns None if no token has been received. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.to_json | def to_json(self):
"""
Returns a json string containing all relevant data to recreate this pyalveo.Client.
"""
data = dict(self.__dict__)
data.pop('context',None)
data['oauth'] = self.oauth.to_dict()
data['cache'] = self.cache.to_dict()
return json.dum... | python | def to_json(self):
"""
Returns a json string containing all relevant data to recreate this pyalveo.Client.
"""
data = dict(self.__dict__)
data.pop('context',None)
data['oauth'] = self.oauth.to_dict()
data['cache'] = self.cache.to_dict()
return json.dum... | [
"def",
"to_json",
"(",
"self",
")",
":",
"data",
"=",
"dict",
"(",
"self",
".",
"__dict__",
")",
"data",
".",
"pop",
"(",
"'context'",
",",
"None",
")",
"data",
"[",
"'oauth'",
"]",
"=",
"self",
".",
"oauth",
".",
"to_dict",
"(",
")",
"data",
"["... | Returns a json string containing all relevant data to recreate this pyalveo.Client. | [
"Returns",
"a",
"json",
"string",
"containing",
"all",
"relevant",
"data",
"to",
"recreate",
"this",
"pyalveo",
".",
"Client",
"."
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L475-L483 | train | Returns a json string containing all relevant data to recreate this pyalveo. Client.
|
Alveo/pyalveo | pyalveo/pyalveo.py | Client.from_json | def from_json(json_data):
"""
Returns a pyalveo.Client given a json string built from the client.to_json() method.
"""
# If we have a string, then decode it, otherwise assume it's already decoded
if isinstance(json_data, str):
data = json.loads(json_data)
... | python | def from_json(json_data):
"""
Returns a pyalveo.Client given a json string built from the client.to_json() method.
"""
# If we have a string, then decode it, otherwise assume it's already decoded
if isinstance(json_data, str):
data = json.loads(json_data)
... | [
"def",
"from_json",
"(",
"json_data",
")",
":",
"# If we have a string, then decode it, otherwise assume it's already decoded",
"if",
"isinstance",
"(",
"json_data",
",",
"str",
")",
":",
"data",
"=",
"json",
".",
"loads",
"(",
"json_data",
")",
"else",
":",
"data",... | Returns a pyalveo.Client given a json string built from the client.to_json() method. | [
"Returns",
"a",
"pyalveo",
".",
"Client",
"given",
"a",
"json",
"string",
"built",
"from",
"the",
"client",
".",
"to_json",
"()",
"method",
"."
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L486-L510 | train | Returns a pyalveo. Client given a json string built from the client. to_json method. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.api_request | def api_request(self, url, data=None, method='GET', raw=False, file=None):
""" Perform an API request to the given URL, optionally
including the specified data
:type url: String
:param url: the URL to which to make the request
:type data: String
:param data: the data to ... | python | def api_request(self, url, data=None, method='GET', raw=False, file=None):
""" Perform an API request to the given URL, optionally
including the specified data
:type url: String
:param url: the URL to which to make the request
:type data: String
:param data: the data to ... | [
"def",
"api_request",
"(",
"self",
",",
"url",
",",
"data",
"=",
"None",
",",
"method",
"=",
"'GET'",
",",
"raw",
"=",
"False",
",",
"file",
"=",
"None",
")",
":",
"if",
"method",
"is",
"'GET'",
":",
"response",
"=",
"self",
".",
"oauth",
".",
"g... | Perform an API request to the given URL, optionally
including the specified data
:type url: String
:param url: the URL to which to make the request
:type data: String
:param data: the data to send with the request, if any
:type method: String
:param method: the H... | [
"Perform",
"an",
"API",
"request",
"to",
"the",
"given",
"URL",
"optionally",
"including",
"the",
"specified",
"data"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L572-L619 | train | Perform an API request to the given URL optionally including the specified data. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.get_collections | def get_collections(self):
"""Retrieve a list of the collection URLs for all collections
hosted on the server.
:rtype: List
:returns: a List of tuples of (name, url) for each collection
"""
result = self.api_request('/catalog')
# get the collection name from the... | python | def get_collections(self):
"""Retrieve a list of the collection URLs for all collections
hosted on the server.
:rtype: List
:returns: a List of tuples of (name, url) for each collection
"""
result = self.api_request('/catalog')
# get the collection name from the... | [
"def",
"get_collections",
"(",
"self",
")",
":",
"result",
"=",
"self",
".",
"api_request",
"(",
"'/catalog'",
")",
"# get the collection name from the url",
"return",
"[",
"(",
"os",
".",
"path",
".",
"split",
"(",
"x",
")",
"[",
"1",
"]",
",",
"x",
")"... | Retrieve a list of the collection URLs for all collections
hosted on the server.
:rtype: List
:returns: a List of tuples of (name, url) for each collection | [
"Retrieve",
"a",
"list",
"of",
"the",
"collection",
"URLs",
"for",
"all",
"collections",
"hosted",
"on",
"the",
"server",
"."
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L660-L670 | train | Retrieve a list of the collection URLs for all collections
hosted on the server. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.get_item | def get_item(self, item_url, force_download=False):
""" Retrieve the item metadata from the server, as an Item object
:type item_url: String or Item
:param item_url: URL of the item, or an Item object
:rtype: Item
:returns: the corresponding metadata, as an Item object
... | python | def get_item(self, item_url, force_download=False):
""" Retrieve the item metadata from the server, as an Item object
:type item_url: String or Item
:param item_url: URL of the item, or an Item object
:rtype: Item
:returns: the corresponding metadata, as an Item object
... | [
"def",
"get_item",
"(",
"self",
",",
"item_url",
",",
"force_download",
"=",
"False",
")",
":",
"item_url",
"=",
"str",
"(",
"item_url",
")",
"if",
"(",
"self",
".",
"use_cache",
"and",
"not",
"force_download",
"and",
"self",
".",
"cache",
".",
"has_item... | Retrieve the item metadata from the server, as an Item object
:type item_url: String or Item
:param item_url: URL of the item, or an Item object
:rtype: Item
:returns: the corresponding metadata, as an Item object
:type force_download: Boolean
:param force_download: Tru... | [
"Retrieve",
"the",
"item",
"metadata",
"from",
"the",
"server",
"as",
"an",
"Item",
"object"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L693-L720 | train | Retrieve the item metadata from the server. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.get_document | def get_document(self, doc_url, force_download=False):
""" Retrieve the data for the given document from the server
:type doc_url: String or Document
:param doc_url: the URL of the document, or a Document object
:type force_download: Boolean
:param force_download: True to downlo... | python | def get_document(self, doc_url, force_download=False):
""" Retrieve the data for the given document from the server
:type doc_url: String or Document
:param doc_url: the URL of the document, or a Document object
:type force_download: Boolean
:param force_download: True to downlo... | [
"def",
"get_document",
"(",
"self",
",",
"doc_url",
",",
"force_download",
"=",
"False",
")",
":",
"doc_url",
"=",
"str",
"(",
"doc_url",
")",
"if",
"(",
"self",
".",
"use_cache",
"and",
"not",
"force_download",
"and",
"self",
".",
"cache",
".",
"has_doc... | Retrieve the data for the given document from the server
:type doc_url: String or Document
:param doc_url: the URL of the document, or a Document object
:type force_download: Boolean
:param force_download: True to download from the server
regardless of the cache's contents
... | [
"Retrieve",
"the",
"data",
"for",
"the",
"given",
"document",
"from",
"the",
"server"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L722-L748 | train | Retrieve the data for the given document from the server. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.get_primary_text | def get_primary_text(self, item_url, force_download=False):
""" Retrieve the primary text for an item from the server
:type item_url: String or Item
:param item_url: URL of the item, or an Item object
:type force_download: Boolean
:param force_download: True to download from the... | python | def get_primary_text(self, item_url, force_download=False):
""" Retrieve the primary text for an item from the server
:type item_url: String or Item
:param item_url: URL of the item, or an Item object
:type force_download: Boolean
:param force_download: True to download from the... | [
"def",
"get_primary_text",
"(",
"self",
",",
"item_url",
",",
"force_download",
"=",
"False",
")",
":",
"item_url",
"=",
"str",
"(",
"item_url",
")",
"metadata",
"=",
"self",
".",
"get_item",
"(",
"item_url",
")",
".",
"metadata",
"(",
")",
"try",
":",
... | Retrieve the primary text for an item from the server
:type item_url: String or Item
:param item_url: URL of the item, or an Item object
:type force_download: Boolean
:param force_download: True to download from the server
regardless of the cache's contents
:rtype: ... | [
"Retrieve",
"the",
"primary",
"text",
"for",
"an",
"item",
"from",
"the",
"server"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L750-L786 | train | Retrieve the primary text for an item from the server |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.get_item_annotations | def get_item_annotations(self, item_url, annotation_type=None, label=None):
""" Retrieve the annotations for an item from the server
:type item_url: String or Item
:param item_url: URL of the item, or an Item object
:type annotation_type: String
:param annotation_type: return on... | python | def get_item_annotations(self, item_url, annotation_type=None, label=None):
""" Retrieve the annotations for an item from the server
:type item_url: String or Item
:param item_url: URL of the item, or an Item object
:type annotation_type: String
:param annotation_type: return on... | [
"def",
"get_item_annotations",
"(",
"self",
",",
"item_url",
",",
"annotation_type",
"=",
"None",
",",
"label",
"=",
"None",
")",
":",
"# get the annotation URL from the item metadata, if not present then there are no annotations",
"item_url",
"=",
"str",
"(",
"item_url",
... | Retrieve the annotations for an item from the server
:type item_url: String or Item
:param item_url: URL of the item, or an Item object
:type annotation_type: String
:param annotation_type: return only results with a matching Type field
:type label: String
:param label: ... | [
"Retrieve",
"the",
"annotations",
"for",
"an",
"item",
"from",
"the",
"server"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L788-L834 | train | Retrieve the annotations for an item from the server |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.get_annotation_types | def get_annotation_types(self, item_url):
""" Retrieve the annotation types for the given item from the server
:type item_url: String or Item
:param item_url: URL of the item, or an Item object
:rtype: List
:returns: a List specifying the annotation types
:raises: APIE... | python | def get_annotation_types(self, item_url):
""" Retrieve the annotation types for the given item from the server
:type item_url: String or Item
:param item_url: URL of the item, or an Item object
:rtype: List
:returns: a List specifying the annotation types
:raises: APIE... | [
"def",
"get_annotation_types",
"(",
"self",
",",
"item_url",
")",
":",
"req_url",
"=",
"item_url",
"+",
"\"/annotations/types\"",
"resp",
"=",
"self",
".",
"api_request",
"(",
"req_url",
")",
"return",
"resp",
"[",
"'annotation_types'",
"]"
] | Retrieve the annotation types for the given item from the server
:type item_url: String or Item
:param item_url: URL of the item, or an Item object
:rtype: List
:returns: a List specifying the annotation types
:raises: APIError if the request was not successful | [
"Retrieve",
"the",
"annotation",
"types",
"for",
"the",
"given",
"item",
"from",
"the",
"server"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L836-L851 | train | Get the annotation types for the given item from the server |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.add_annotations | def add_annotations(self, item_url, annotations):
"""Add annotations to the given item
:type item_url: String or Item
:param item_url: the URL of the item corresponding to the annotation,
or an Item object
:type annotation: list
:param annotations: the annotations as... | python | def add_annotations(self, item_url, annotations):
"""Add annotations to the given item
:type item_url: String or Item
:param item_url: the URL of the item corresponding to the annotation,
or an Item object
:type annotation: list
:param annotations: the annotations as... | [
"def",
"add_annotations",
"(",
"self",
",",
"item_url",
",",
"annotations",
")",
":",
"adict",
"=",
"{",
"'@context'",
":",
"\"https://alveo-staging1.intersect.org.au/schema/json-ld\"",
"}",
"for",
"ann",
"in",
"annotations",
":",
"# verify that we have the required prope... | Add annotations to the given item
:type item_url: String or Item
:param item_url: the URL of the item corresponding to the annotation,
or an Item object
:type annotation: list
:param annotations: the annotations as a list of dictionaries, each with keys '@type', 'label', 'st... | [
"Add",
"annotations",
"to",
"the",
"given",
"item"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L853-L878 | train | Adds the given annotations to the given item |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.create_collection | def create_collection(self, name, metadata):
""" Create a new collection with the given name
and attach the metadata.
:param name: the collection name, suitable for use in a URL (no spaces)
:type name: String
:param metadata: a dictionary of metadata values to associate with the... | python | def create_collection(self, name, metadata):
""" Create a new collection with the given name
and attach the metadata.
:param name: the collection name, suitable for use in a URL (no spaces)
:type name: String
:param metadata: a dictionary of metadata values to associate with the... | [
"def",
"create_collection",
"(",
"self",
",",
"name",
",",
"metadata",
")",
":",
"payload",
"=",
"{",
"'collection_metadata'",
":",
"metadata",
",",
"'name'",
":",
"name",
"}",
"response",
"=",
"self",
".",
"api_request",
"(",
"'/catalog'",
",",
"method",
... | Create a new collection with the given name
and attach the metadata.
:param name: the collection name, suitable for use in a URL (no spaces)
:type name: String
:param metadata: a dictionary of metadata values to associate with the new collection
:type metadata: Dict
:rt... | [
"Create",
"a",
"new",
"collection",
"with",
"the",
"given",
"name",
"and",
"attach",
"the",
"metadata",
"."
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L895-L918 | train | Create a new collection with the given name and attach the metadata. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.modify_collection_metadata | def modify_collection_metadata(self, collection_uri, metadata, replace=None, name=''):
"""Modify the metadata for the given collection.
:param collection_uri: The URI that references the collection
:type collection_uri: String
:param metadata: a dictionary of metadata values to add/mod... | python | def modify_collection_metadata(self, collection_uri, metadata, replace=None, name=''):
"""Modify the metadata for the given collection.
:param collection_uri: The URI that references the collection
:type collection_uri: String
:param metadata: a dictionary of metadata values to add/mod... | [
"def",
"modify_collection_metadata",
"(",
"self",
",",
"collection_uri",
",",
"metadata",
",",
"replace",
"=",
"None",
",",
"name",
"=",
"''",
")",
":",
"payload",
"=",
"{",
"'collection_metadata'",
":",
"metadata",
",",
"'name'",
":",
"name",
"}",
"if",
"... | Modify the metadata for the given collection.
:param collection_uri: The URI that references the collection
:type collection_uri: String
:param metadata: a dictionary of metadata values to add/modify
:type metadata: Dict
:rtype: String
:returns: a message confirming th... | [
"Modify",
"the",
"metadata",
"for",
"the",
"given",
"collection",
"."
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L920-L945 | train | Modify the metadata for the given collection. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.get_items | def get_items(self, collection_uri):
"""Return all items in this collection.
:param collection_uri: The URI that references the collection
:type collection_uri: String
:rtype: List
:returns: a list of the URIs of the items in this collection
"""
cname = os.pat... | python | def get_items(self, collection_uri):
"""Return all items in this collection.
:param collection_uri: The URI that references the collection
:type collection_uri: String
:rtype: List
:returns: a list of the URIs of the items in this collection
"""
cname = os.pat... | [
"def",
"get_items",
"(",
"self",
",",
"collection_uri",
")",
":",
"cname",
"=",
"os",
".",
"path",
".",
"split",
"(",
"collection_uri",
")",
"[",
"1",
"]",
"return",
"self",
".",
"search_metadata",
"(",
"\"collection_name:%s\"",
"%",
"cname",
")"
] | Return all items in this collection.
:param collection_uri: The URI that references the collection
:type collection_uri: String
:rtype: List
:returns: a list of the URIs of the items in this collection | [
"Return",
"all",
"items",
"in",
"this",
"collection",
"."
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L947-L959 | train | Return all items in this collection. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.add_text_item | def add_text_item(self, collection_uri, name, metadata, text, title=None):
"""Add a new item to a collection containing a single
text document.
The full text of the text document is specified as the text
argument and will be stored with the same name as the
item and a .txt exten... | python | def add_text_item(self, collection_uri, name, metadata, text, title=None):
"""Add a new item to a collection containing a single
text document.
The full text of the text document is specified as the text
argument and will be stored with the same name as the
item and a .txt exten... | [
"def",
"add_text_item",
"(",
"self",
",",
"collection_uri",
",",
"name",
",",
"metadata",
",",
"text",
",",
"title",
"=",
"None",
")",
":",
"docname",
"=",
"name",
"+",
"\".txt\"",
"if",
"title",
"is",
"None",
":",
"title",
"=",
"name",
"metadata",
"["... | Add a new item to a collection containing a single
text document.
The full text of the text document is specified as the text
argument and will be stored with the same name as the
item and a .txt extension.
This is a shorthand for the more general add_item method.
:par... | [
"Add",
"a",
"new",
"item",
"to",
"a",
"collection",
"containing",
"a",
"single",
"text",
"document",
"."
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L961-L1023 | train | Adds a new item to a collection containing a single text document. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.add_item | def add_item(self, collection_uri, name, metadata):
"""Add a new item to a collection
:param collection_uri: The URI that references the collection
:type collection_uri: String
:param name: The item name, suitable for use in a URI (no spaces)
:type name: String
:param ... | python | def add_item(self, collection_uri, name, metadata):
"""Add a new item to a collection
:param collection_uri: The URI that references the collection
:type collection_uri: String
:param name: The item name, suitable for use in a URI (no spaces)
:type name: String
:param ... | [
"def",
"add_item",
"(",
"self",
",",
"collection_uri",
",",
"name",
",",
"metadata",
")",
":",
"metadata",
"[",
"'dcterms:identifier'",
"]",
"=",
"name",
"metadata",
"[",
"'dc:identifier'",
"]",
"=",
"name",
"# for backward compatability in Alveo SOLR store until bug ... | Add a new item to a collection
:param collection_uri: The URI that references the collection
:type collection_uri: String
:param name: The item name, suitable for use in a URI (no spaces)
:type name: String
:param metadata: a dictionary of metadata values describing the item
... | [
"Add",
"a",
"new",
"item",
"to",
"a",
"collection"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1025-L1061 | train | Add a new item to a collection |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.modify_item | def modify_item(self, item_uri, metadata):
"""Modify the metadata on an item
"""
md = json.dumps({'metadata': metadata})
response = self.api_request(item_uri, method='PUT', data=md)
return self.__check_success(response) | python | def modify_item(self, item_uri, metadata):
"""Modify the metadata on an item
"""
md = json.dumps({'metadata': metadata})
response = self.api_request(item_uri, method='PUT', data=md)
return self.__check_success(response) | [
"def",
"modify_item",
"(",
"self",
",",
"item_uri",
",",
"metadata",
")",
":",
"md",
"=",
"json",
".",
"dumps",
"(",
"{",
"'metadata'",
":",
"metadata",
"}",
")",
"response",
"=",
"self",
".",
"api_request",
"(",
"item_uri",
",",
"method",
"=",
"'PUT'"... | Modify the metadata on an item | [
"Modify",
"the",
"metadata",
"on",
"an",
"item"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1063-L1071 | train | Modify the metadata on an item |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.delete_item | def delete_item(self, item_uri):
"""Delete an item from a collection
:param item_uri: the URI that references the item
:type item_uri: String
:rtype: String
:returns: a message confirming that the metadata is modified
:raises: APIError if the request was not successful... | python | def delete_item(self, item_uri):
"""Delete an item from a collection
:param item_uri: the URI that references the item
:type item_uri: String
:rtype: String
:returns: a message confirming that the metadata is modified
:raises: APIError if the request was not successful... | [
"def",
"delete_item",
"(",
"self",
",",
"item_uri",
")",
":",
"response",
"=",
"self",
".",
"api_request",
"(",
"item_uri",
",",
"method",
"=",
"'DELETE'",
")",
"return",
"self",
".",
"__check_success",
"(",
"response",
")"
] | Delete an item from a collection
:param item_uri: the URI that references the item
:type item_uri: String
:rtype: String
:returns: a message confirming that the metadata is modified
:raises: APIError if the request was not successful | [
"Delete",
"an",
"item",
"from",
"a",
"collection"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1073-L1086 | train | Delete an item from a collection |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.add_document | def add_document(self, item_uri, name, metadata,
content=None, docurl=None, file=None,
displaydoc=False, preferName=False,
contrib_id=None):
"""Add a document to an existing item
:param item_uri: the URI that references the item
:ty... | python | def add_document(self, item_uri, name, metadata,
content=None, docurl=None, file=None,
displaydoc=False, preferName=False,
contrib_id=None):
"""Add a document to an existing item
:param item_uri: the URI that references the item
:ty... | [
"def",
"add_document",
"(",
"self",
",",
"item_uri",
",",
"name",
",",
"metadata",
",",
"content",
"=",
"None",
",",
"docurl",
"=",
"None",
",",
"file",
"=",
"None",
",",
"displaydoc",
"=",
"False",
",",
"preferName",
"=",
"False",
",",
"contrib_id",
"... | Add a document to an existing item
:param item_uri: the URI that references the item
:type item_uri: String
:param name: The document name
:type name: String
:param metadata: a dictionary of metadata values describing the document
:type metadata: Dict
:param c... | [
"Add",
"a",
"document",
"to",
"an",
"existing",
"item"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1088-L1167 | train | Adds a document to an existing item. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.delete_document | def delete_document(self, doc_uri):
"""Delete a document from an item
:param doc_uri: the URI that references the document
:type doc_uri: String
:rtype: String
:returns: a message confirming that the document was deleted
:raises: APIError if the request was not success... | python | def delete_document(self, doc_uri):
"""Delete a document from an item
:param doc_uri: the URI that references the document
:type doc_uri: String
:rtype: String
:returns: a message confirming that the document was deleted
:raises: APIError if the request was not success... | [
"def",
"delete_document",
"(",
"self",
",",
"doc_uri",
")",
":",
"result",
"=",
"self",
".",
"api_request",
"(",
"doc_uri",
",",
"method",
"=",
"'DELETE'",
")",
"return",
"self",
".",
"__check_success",
"(",
"result",
")"
] | Delete a document from an item
:param doc_uri: the URI that references the document
:type doc_uri: String
:rtype: String
:returns: a message confirming that the document was deleted
:raises: APIError if the request was not successful | [
"Delete",
"a",
"document",
"from",
"an",
"item"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1169-L1182 | train | Delete a document from an item node |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.__check_success | def __check_success(resp):
""" Check a JSON server response to see if it was successful
:type resp: Dictionary (parsed JSON from response)
:param resp: the response string
:rtype: String
:returns: the success message, if it exists
:raises: APIError if the success messa... | python | def __check_success(resp):
""" Check a JSON server response to see if it was successful
:type resp: Dictionary (parsed JSON from response)
:param resp: the response string
:rtype: String
:returns: the success message, if it exists
:raises: APIError if the success messa... | [
"def",
"__check_success",
"(",
"resp",
")",
":",
"if",
"\"success\"",
"not",
"in",
"resp",
".",
"keys",
"(",
")",
":",
"try",
":",
"raise",
"APIError",
"(",
"'200'",
",",
"'Operation Failed'",
",",
"resp",
"[",
"\"error\"",
"]",
")",
"except",
"KeyError"... | Check a JSON server response to see if it was successful
:type resp: Dictionary (parsed JSON from response)
:param resp: the response string
:rtype: String
:returns: the success message, if it exists
:raises: APIError if the success message is not present | [
"Check",
"a",
"JSON",
"server",
"response",
"to",
"see",
"if",
"it",
"was",
"successful"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1185-L1204 | train | Checks a JSON server response to see if it was successful and returns the success message if it exists. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.download_items | def download_items(self, items, file_path, file_format='zip'):
""" Retrieve a file from the server containing the metadata
and documents for the speficied items
:type items: List or ItemGroup
:param items: List of the the URLs of the items to download,
or an ItemGroup object... | python | def download_items(self, items, file_path, file_format='zip'):
""" Retrieve a file from the server containing the metadata
and documents for the speficied items
:type items: List or ItemGroup
:param items: List of the the URLs of the items to download,
or an ItemGroup object... | [
"def",
"download_items",
"(",
"self",
",",
"items",
",",
"file_path",
",",
"file_format",
"=",
"'zip'",
")",
":",
"download_url",
"=",
"'/catalog/download_items'",
"download_url",
"+=",
"'?'",
"+",
"urlencode",
"(",
"(",
"(",
"'format'",
",",
"file_format",
")... | Retrieve a file from the server containing the metadata
and documents for the speficied items
:type items: List or ItemGroup
:param items: List of the the URLs of the items to download,
or an ItemGroup object
:type file_path: String
:param file_path: the path to whic... | [
"Retrieve",
"a",
"file",
"from",
"the",
"server",
"containing",
"the",
"metadata",
"and",
"documents",
"for",
"the",
"speficied",
"items"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1206-L1235 | train | Download the items from the server and save it to the file_path |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.search_metadata | def search_metadata(self, query):
""" Submit a search query to the server and retrieve the results
:type query: String
:param query: the search query
:rtype: ItemGroup
:returns: the search results
:raises: APIError if the API request is not successful
"""
... | python | def search_metadata(self, query):
""" Submit a search query to the server and retrieve the results
:type query: String
:param query: the search query
:rtype: ItemGroup
:returns: the search results
:raises: APIError if the API request is not successful
"""
... | [
"def",
"search_metadata",
"(",
"self",
",",
"query",
")",
":",
"query_url",
"=",
"(",
"'/catalog/search?'",
"+",
"urlencode",
"(",
"(",
"(",
"'metadata'",
",",
"query",
")",
",",
")",
")",
")",
"resp",
"=",
"self",
".",
"api_request",
"(",
"query_url",
... | Submit a search query to the server and retrieve the results
:type query: String
:param query: the search query
:rtype: ItemGroup
:returns: the search results
:raises: APIError if the API request is not successful | [
"Submit",
"a",
"search",
"query",
"to",
"the",
"server",
"and",
"retrieve",
"the",
"results"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1237-L1254 | train | Submit a search query to the server and retrieve the results |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.get_item_list | def get_item_list(self, item_list_url):
""" Retrieve an item list from the server as an ItemList object
:type item_list_url: String or ItemList
:param item_list_url: URL of the item list to retrieve, or an
ItemList object
:rtype: ItemList
:returns: The ItemList
... | python | def get_item_list(self, item_list_url):
""" Retrieve an item list from the server as an ItemList object
:type item_list_url: String or ItemList
:param item_list_url: URL of the item list to retrieve, or an
ItemList object
:rtype: ItemList
:returns: The ItemList
... | [
"def",
"get_item_list",
"(",
"self",
",",
"item_list_url",
")",
":",
"resp",
"=",
"self",
".",
"api_request",
"(",
"str",
"(",
"item_list_url",
")",
")",
"return",
"ItemList",
"(",
"resp",
"[",
"'items'",
"]",
",",
"self",
",",
"str",
"(",
"item_list_url... | Retrieve an item list from the server as an ItemList object
:type item_list_url: String or ItemList
:param item_list_url: URL of the item list to retrieve, or an
ItemList object
:rtype: ItemList
:returns: The ItemList
:raises: APIError if the request was not succes... | [
"Retrieve",
"an",
"item",
"list",
"from",
"the",
"server",
"as",
"an",
"ItemList",
"object"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1256-L1271 | train | Retrieves an item list from the server as an ItemList object |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.get_item_list_by_name | def get_item_list_by_name(self, item_list_name, category='own'):
""" Retrieve an item list from the server as an ItemList object
:type item_list_name: String
:param item_list_name: name of the item list to retrieve
:type category: String
:param category: the category of lists to... | python | def get_item_list_by_name(self, item_list_name, category='own'):
""" Retrieve an item list from the server as an ItemList object
:type item_list_name: String
:param item_list_name: name of the item list to retrieve
:type category: String
:param category: the category of lists to... | [
"def",
"get_item_list_by_name",
"(",
"self",
",",
"item_list_name",
",",
"category",
"=",
"'own'",
")",
":",
"resp",
"=",
"self",
".",
"api_request",
"(",
"'/item_lists'",
")",
"for",
"item_list",
"in",
"resp",
"[",
"category",
"]",
":",
"if",
"item_list",
... | Retrieve an item list from the server as an ItemList object
:type item_list_name: String
:param item_list_name: name of the item list to retrieve
:type category: String
:param category: the category of lists to fetch. At the time of
writing, supported values are "own" and "s... | [
"Retrieve",
"an",
"item",
"list",
"from",
"the",
"server",
"as",
"an",
"ItemList",
"object"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1273-L1293 | train | This method returns an item list object by name. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.add_to_item_list | def add_to_item_list(self, item_urls, item_list_url):
""" Instruct the server to add the given items to the specified
Item List
:type item_urls: List or ItemGroup
:param item_urls: List of URLs for the items to add,
or an ItemGroup object
:type item_list_url: String ... | python | def add_to_item_list(self, item_urls, item_list_url):
""" Instruct the server to add the given items to the specified
Item List
:type item_urls: List or ItemGroup
:param item_urls: List of URLs for the items to add,
or an ItemGroup object
:type item_list_url: String ... | [
"def",
"add_to_item_list",
"(",
"self",
",",
"item_urls",
",",
"item_list_url",
")",
":",
"item_list_url",
"=",
"str",
"(",
"item_list_url",
")",
"name",
"=",
"self",
".",
"get_item_list",
"(",
"item_list_url",
")",
".",
"name",
"(",
")",
"return",
"self",
... | Instruct the server to add the given items to the specified
Item List
:type item_urls: List or ItemGroup
:param item_urls: List of URLs for the items to add,
or an ItemGroup object
:type item_list_url: String or ItemList
:param item_list_url: the URL of the list to w... | [
"Instruct",
"the",
"server",
"to",
"add",
"the",
"given",
"items",
"to",
"the",
"specified",
"Item",
"List"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1295-L1315 | train | Instructs the server to add the given items to the specified Item List |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.add_to_item_list_by_name | def add_to_item_list_by_name(self, item_urls, item_list_name):
""" Instruct the server to add the given items to the specified
Item List (which will be created if it does not already exist)
:type item_urls: List or ItemGroup
:param item_urls: List of URLs for the items to add,
... | python | def add_to_item_list_by_name(self, item_urls, item_list_name):
""" Instruct the server to add the given items to the specified
Item List (which will be created if it does not already exist)
:type item_urls: List or ItemGroup
:param item_urls: List of URLs for the items to add,
... | [
"def",
"add_to_item_list_by_name",
"(",
"self",
",",
"item_urls",
",",
"item_list_name",
")",
":",
"url_name",
"=",
"urlencode",
"(",
"(",
"(",
"'name'",
",",
"item_list_name",
")",
",",
")",
")",
"request_url",
"=",
"'/item_lists?'",
"+",
"url_name",
"data",
... | Instruct the server to add the given items to the specified
Item List (which will be created if it does not already exist)
:type item_urls: List or ItemGroup
:param item_urls: List of URLs for the items to add,
or an ItemGroup object
:type item_list_name: String
:par... | [
"Instruct",
"the",
"server",
"to",
"add",
"the",
"given",
"items",
"to",
"the",
"specified",
"Item",
"List",
"(",
"which",
"will",
"be",
"created",
"if",
"it",
"does",
"not",
"already",
"exist",
")"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1317-L1339 | train | Instructs the server to add the given items to the specified item list. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.rename_item_list | def rename_item_list(self, item_list_url, new_name):
""" Rename an Item List on the server
:type item_list_url: String or ItemList
:param item_list_url: the URL of the list to which to add the items,
or an ItemList object
:type new_name: String
:param new_name: the n... | python | def rename_item_list(self, item_list_url, new_name):
""" Rename an Item List on the server
:type item_list_url: String or ItemList
:param item_list_url: the URL of the list to which to add the items,
or an ItemList object
:type new_name: String
:param new_name: the n... | [
"def",
"rename_item_list",
"(",
"self",
",",
"item_list_url",
",",
"new_name",
")",
":",
"data",
"=",
"json",
".",
"dumps",
"(",
"{",
"'name'",
":",
"new_name",
"}",
")",
"resp",
"=",
"self",
".",
"api_request",
"(",
"str",
"(",
"item_list_url",
")",
"... | Rename an Item List on the server
:type item_list_url: String or ItemList
:param item_list_url: the URL of the list to which to add the items,
or an ItemList object
:type new_name: String
:param new_name: the new name to give the Item List
:rtype: ItemList
:... | [
"Rename",
"an",
"Item",
"List",
"on",
"the",
"server"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1341-L1366 | train | This method allows you to rename an Item List on the server. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.delete_item_list | def delete_item_list(self, item_list_url):
""" Delete an Item List on the server
:type item_list_url: String or ItemList
:param item_list_url: the URL of the list to which to add the items,
or an ItemList object
:rtype: Boolean
:returns: True if the item list was de... | python | def delete_item_list(self, item_list_url):
""" Delete an Item List on the server
:type item_list_url: String or ItemList
:param item_list_url: the URL of the list to which to add the items,
or an ItemList object
:rtype: Boolean
:returns: True if the item list was de... | [
"def",
"delete_item_list",
"(",
"self",
",",
"item_list_url",
")",
":",
"try",
":",
"resp",
"=",
"self",
".",
"api_request",
"(",
"str",
"(",
"item_list_url",
")",
",",
"method",
"=",
"\"DELETE\"",
")",
"# all good if it says success",
"if",
"'success'",
"in",... | Delete an Item List on the server
:type item_list_url: String or ItemList
:param item_list_url: the URL of the list to which to add the items,
or an ItemList object
:rtype: Boolean
:returns: True if the item list was deleted
:raises: APIError if the request was not... | [
"Delete",
"an",
"Item",
"List",
"on",
"the",
"server"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1368-L1393 | train | Delete an Item List on the server |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.get_speakers | def get_speakers(self, collection_name):
"""Get a list of speaker URLs for this collection
:type collection_name: String
:param collection_name: the name of the collection to search
:rtype: List
:returns: a list of URLs for the speakers associated with
the given col... | python | def get_speakers(self, collection_name):
"""Get a list of speaker URLs for this collection
:type collection_name: String
:param collection_name: the name of the collection to search
:rtype: List
:returns: a list of URLs for the speakers associated with
the given col... | [
"def",
"get_speakers",
"(",
"self",
",",
"collection_name",
")",
":",
"speakers_url",
"=",
"\"/speakers/\"",
"+",
"collection_name",
"resp",
"=",
"self",
".",
"api_request",
"(",
"speakers_url",
")",
"if",
"'speakers'",
"in",
"resp",
":",
"return",
"resp",
"["... | Get a list of speaker URLs for this collection
:type collection_name: String
:param collection_name: the name of the collection to search
:rtype: List
:returns: a list of URLs for the speakers associated with
the given collection | [
"Get",
"a",
"list",
"of",
"speaker",
"URLs",
"for",
"this",
"collection"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1395-L1412 | train | Get a list of speaker URLs for the given collection_name |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.add_speaker | def add_speaker(self, collection_name, metadata):
"""Add a new speaker to this collection.
:type collection_name: String
:param collection_name: the name of the collection to search
:type metadata: Dict
:param metadata: dictionary of metadata properties and values
for ... | python | def add_speaker(self, collection_name, metadata):
"""Add a new speaker to this collection.
:type collection_name: String
:param collection_name: the name of the collection to search
:type metadata: Dict
:param metadata: dictionary of metadata properties and values
for ... | [
"def",
"add_speaker",
"(",
"self",
",",
"collection_name",
",",
"metadata",
")",
":",
"if",
"'dcterms:identifier'",
"not",
"in",
"metadata",
":",
"raise",
"APIError",
"(",
"msg",
"=",
"\"No identifier in speaker metadata\"",
")",
"if",
"'@context'",
"not",
"in",
... | Add a new speaker to this collection.
:type collection_name: String
:param collection_name: the name of the collection to search
:type metadata: Dict
:param metadata: dictionary of metadata properties and values
for this speaker. Must include 'dcterms:identifier' a unique
... | [
"Add",
"a",
"new",
"speaker",
"to",
"this",
"collection",
"."
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1428-L1455 | train | Add a new speaker to a collection. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.delete_speaker | def delete_speaker(self, speaker_uri):
"""Delete an speaker from a collection
:param speaker_uri: the URI that references the speaker
:type speaker_uri: String
:rtype: Boolean
:returns: True if the speaker was deleted
:raises: APIError if the request was not successful... | python | def delete_speaker(self, speaker_uri):
"""Delete an speaker from a collection
:param speaker_uri: the URI that references the speaker
:type speaker_uri: String
:rtype: Boolean
:returns: True if the speaker was deleted
:raises: APIError if the request was not successful... | [
"def",
"delete_speaker",
"(",
"self",
",",
"speaker_uri",
")",
":",
"response",
"=",
"self",
".",
"api_request",
"(",
"speaker_uri",
",",
"method",
"=",
"'DELETE'",
")",
"return",
"self",
".",
"__check_success",
"(",
"response",
")"
] | Delete an speaker from a collection
:param speaker_uri: the URI that references the speaker
:type speaker_uri: String
:rtype: Boolean
:returns: True if the speaker was deleted
:raises: APIError if the request was not successful | [
"Delete",
"an",
"speaker",
"from",
"a",
"collection"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1457-L1470 | train | Delete an speaker from a collection
|
Alveo/pyalveo | pyalveo/pyalveo.py | Client.sparql_query | def sparql_query(self, collection_name, query):
""" Submit a sparql query to the server to search metadata
and annotations.
:type collection_name: String
:param collection_name: the name of the collection to search
:type query: String
:param query: the sparql query
... | python | def sparql_query(self, collection_name, query):
""" Submit a sparql query to the server to search metadata
and annotations.
:type collection_name: String
:param collection_name: the name of the collection to search
:type query: String
:param query: the sparql query
... | [
"def",
"sparql_query",
"(",
"self",
",",
"collection_name",
",",
"query",
")",
":",
"request_url",
"=",
"'/sparql/'",
"+",
"collection_name",
"+",
"'?'",
"request_url",
"+=",
"urlencode",
"(",
"(",
"(",
"'query'",
",",
"query",
")",
",",
")",
")",
"return"... | Submit a sparql query to the server to search metadata
and annotations.
:type collection_name: String
:param collection_name: the name of the collection to search
:type query: String
:param query: the sparql query
:rtype: Dict
:returns: the query result from the... | [
"Submit",
"a",
"sparql",
"query",
"to",
"the",
"server",
"to",
"search",
"metadata",
"and",
"annotations",
"."
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1472-L1493 | train | Submit a sparql query to the server to search metadata
and annotations. |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.get_contribution | def get_contribution(self, url):
"""Get the details of a particular contribution given it's
url"""
result = self.api_request(url)
# add the contrib id into the metadata
result['id'] = os.path.split(result['url'])[1]
return result | python | def get_contribution(self, url):
"""Get the details of a particular contribution given it's
url"""
result = self.api_request(url)
# add the contrib id into the metadata
result['id'] = os.path.split(result['url'])[1]
return result | [
"def",
"get_contribution",
"(",
"self",
",",
"url",
")",
":",
"result",
"=",
"self",
".",
"api_request",
"(",
"url",
")",
"# add the contrib id into the metadata",
"result",
"[",
"'id'",
"]",
"=",
"os",
".",
"path",
".",
"split",
"(",
"result",
"[",
"'url'... | Get the details of a particular contribution given it's
url | [
"Get",
"the",
"details",
"of",
"a",
"particular",
"contribution",
"given",
"it",
"s",
"url"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1509-L1518 | train | Get the details of a particular contribution given it s
url |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.create_contribution | def create_contribution(self, metadata):
"""Create a new contribution given a dictionary of metadata
{
"contribution_name": "HelloWorld",
"contribution_collection": "Cooee",
"contribution_text": "This is contribution description",
"con... | python | def create_contribution(self, metadata):
"""Create a new contribution given a dictionary of metadata
{
"contribution_name": "HelloWorld",
"contribution_collection": "Cooee",
"contribution_text": "This is contribution description",
"con... | [
"def",
"create_contribution",
"(",
"self",
",",
"metadata",
")",
":",
"result",
"=",
"self",
".",
"api_request",
"(",
"'/contrib/'",
",",
"method",
"=",
"'POST'",
",",
"data",
"=",
"json",
".",
"dumps",
"(",
"metadata",
")",
")",
"# add the contrib id into t... | Create a new contribution given a dictionary of metadata
{
"contribution_name": "HelloWorld",
"contribution_collection": "Cooee",
"contribution_text": "This is contribution description",
"contribution_abstract": "This is contribution abstract"... | [
"Create",
"a",
"new",
"contribution",
"given",
"a",
"dictionary",
"of",
"metadata"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1520-L1540 | train | Create a new contribution given a dictionary of metadata |
Alveo/pyalveo | pyalveo/pyalveo.py | Client.delete_contribution | def delete_contribution(self, url):
"""Delete the contribution with this identifier
:rtype: bool
:returns: True if the contribution was deleted, False otherwise (eg. if it didn't exist)
"""
# first validate that this is a real contrib
try:
result = self.api_... | python | def delete_contribution(self, url):
"""Delete the contribution with this identifier
:rtype: bool
:returns: True if the contribution was deleted, False otherwise (eg. if it didn't exist)
"""
# first validate that this is a real contrib
try:
result = self.api_... | [
"def",
"delete_contribution",
"(",
"self",
",",
"url",
")",
":",
"# first validate that this is a real contrib",
"try",
":",
"result",
"=",
"self",
".",
"api_request",
"(",
"url",
")",
"if",
"'url'",
"in",
"result",
"and",
"'documents'",
"in",
"result",
":",
"... | Delete the contribution with this identifier
:rtype: bool
:returns: True if the contribution was deleted, False otherwise (eg. if it didn't exist) | [
"Delete",
"the",
"contribution",
"with",
"this",
"identifier"
] | 1e9eec22bc031bc9a08066f9966565a546e6242e | https://github.com/Alveo/pyalveo/blob/1e9eec22bc031bc9a08066f9966565a546e6242e/pyalveo/pyalveo.py#L1542-L1559 | train | Delete the contribution with this identifier |
TUNE-Archive/freight_forwarder | build.py | lint | def lint():
"""
run linter on our code base.
"""
path = os.path.realpath(os.getcwd())
cmd = 'flake8 %s' % path
opt = ''
print(">>> Linting codebase with the following command: %s %s" % (cmd, opt))
try:
return_code = call([cmd, opt], shell=True)
if return_code < 0:
... | python | def lint():
"""
run linter on our code base.
"""
path = os.path.realpath(os.getcwd())
cmd = 'flake8 %s' % path
opt = ''
print(">>> Linting codebase with the following command: %s %s" % (cmd, opt))
try:
return_code = call([cmd, opt], shell=True)
if return_code < 0:
... | [
"def",
"lint",
"(",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"realpath",
"(",
"os",
".",
"getcwd",
"(",
")",
")",
"cmd",
"=",
"'flake8 %s'",
"%",
"path",
"opt",
"=",
"''",
"print",
"(",
"\">>> Linting codebase with the following command: %s %s\"",
"%... | run linter on our code base. | [
"run",
"linter",
"on",
"our",
"code",
"base",
"."
] | 6ea4a49f474ec04abb8bb81b175c774a16b5312f | https://github.com/TUNE-Archive/freight_forwarder/blob/6ea4a49f474ec04abb8bb81b175c774a16b5312f/build.py#L12-L30 | train | run linter on our code base |
TUNE-Archive/freight_forwarder | build.py | main | def main():
"""
need to add http://sphinx-doc.org/
"""
parser = argparse.ArgumentParser()
sub_parser = parser.add_subparsers()
lint_parser = sub_parser.add_parser('lint')
lint_parser.set_defaults(func=lint)
unit_test_parser = sub_parser.add_parser('unit-test')
unit_test_parser.set_... | python | def main():
"""
need to add http://sphinx-doc.org/
"""
parser = argparse.ArgumentParser()
sub_parser = parser.add_subparsers()
lint_parser = sub_parser.add_parser('lint')
lint_parser.set_defaults(func=lint)
unit_test_parser = sub_parser.add_parser('unit-test')
unit_test_parser.set_... | [
"def",
"main",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"sub_parser",
"=",
"parser",
".",
"add_subparsers",
"(",
")",
"lint_parser",
"=",
"sub_parser",
".",
"add_parser",
"(",
"'lint'",
")",
"lint_parser",
".",
"set_defaults... | need to add http://sphinx-doc.org/ | [
"need",
"to",
"add",
"http",
":",
"//",
"sphinx",
"-",
"doc",
".",
"org",
"/"
] | 6ea4a49f474ec04abb8bb81b175c774a16b5312f | https://github.com/TUNE-Archive/freight_forwarder/blob/6ea4a49f474ec04abb8bb81b175c774a16b5312f/build.py#L64-L85 | train | This is the main entry point for the
command line tool. |
Kortemme-Lab/klab | klab/tui/utils.py | prompt_yn | def prompt_yn(stmt):
'''Prints the statement stmt to the terminal and wait for a Y or N answer.
Returns True for 'Y', False for 'N'.'''
print(stmt)
answer = ''
while answer not in ['Y', 'N']:
sys.stdout.write("$ ")
answer = sys.stdin.readline().upper().strip()
return answer ==... | python | def prompt_yn(stmt):
'''Prints the statement stmt to the terminal and wait for a Y or N answer.
Returns True for 'Y', False for 'N'.'''
print(stmt)
answer = ''
while answer not in ['Y', 'N']:
sys.stdout.write("$ ")
answer = sys.stdin.readline().upper().strip()
return answer ==... | [
"def",
"prompt_yn",
"(",
"stmt",
")",
":",
"print",
"(",
"stmt",
")",
"answer",
"=",
"''",
"while",
"answer",
"not",
"in",
"[",
"'Y'",
",",
"'N'",
"]",
":",
"sys",
".",
"stdout",
".",
"write",
"(",
"\"$ \"",
")",
"answer",
"=",
"sys",
".",
"stdin... | Prints the statement stmt to the terminal and wait for a Y or N answer.
Returns True for 'Y', False for 'N'. | [
"Prints",
"the",
"statement",
"stmt",
"to",
"the",
"terminal",
"and",
"wait",
"for",
"a",
"Y",
"or",
"N",
"answer",
".",
"Returns",
"True",
"for",
"Y",
"False",
"for",
"N",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/tui/utils.py#L4-L12 | train | Prints the statement stmt to the terminal and wait for a Y or N answer. Returns True for Y False for N. |
assamite/creamas | creamas/core/environment.py | Environment.get_agents | def get_agents(self, addr=True, agent_cls=None, include_manager=False):
'''Get agents in the environment.
:param bool addr: If ``True``, returns only addresses of the agents.
:param agent_cls:
Optional, if specified returns only agents belonging to that
particular class.... | python | def get_agents(self, addr=True, agent_cls=None, include_manager=False):
'''Get agents in the environment.
:param bool addr: If ``True``, returns only addresses of the agents.
:param agent_cls:
Optional, if specified returns only agents belonging to that
particular class.... | [
"def",
"get_agents",
"(",
"self",
",",
"addr",
"=",
"True",
",",
"agent_cls",
"=",
"None",
",",
"include_manager",
"=",
"False",
")",
":",
"agents",
"=",
"list",
"(",
"self",
".",
"agents",
".",
"dict",
".",
"values",
"(",
")",
")",
"if",
"hasattr",
... | Get agents in the environment.
:param bool addr: If ``True``, returns only addresses of the agents.
:param agent_cls:
Optional, if specified returns only agents belonging to that
particular class.
:param bool include_manager:
If `True``` includes the environ... | [
"Get",
"agents",
"in",
"the",
"environment",
"."
] | 54dc3e31c97a3f938e58272f8ab80b6bcafeff58 | https://github.com/assamite/creamas/blob/54dc3e31c97a3f938e58272f8ab80b6bcafeff58/creamas/core/environment.py#L88-L118 | train | Get agents in the environment. |
assamite/creamas | creamas/core/environment.py | Environment.trigger_act | async def trigger_act(self, *args, addr=None, agent=None, **kwargs):
'''Trigger agent to act.
If *agent* is None, then looks the agent by the address.
:raises ValueError: if both *agent* and *addr* are None.
'''
if agent is None and addr is None:
raise TypeError("Ei... | python | async def trigger_act(self, *args, addr=None, agent=None, **kwargs):
'''Trigger agent to act.
If *agent* is None, then looks the agent by the address.
:raises ValueError: if both *agent* and *addr* are None.
'''
if agent is None and addr is None:
raise TypeError("Ei... | [
"async",
"def",
"trigger_act",
"(",
"self",
",",
"*",
"args",
",",
"addr",
"=",
"None",
",",
"agent",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"agent",
"is",
"None",
"and",
"addr",
"is",
"None",
":",
"raise",
"TypeError",
"(",
"\"Eithe... | Trigger agent to act.
If *agent* is None, then looks the agent by the address.
:raises ValueError: if both *agent* and *addr* are None. | [
"Trigger",
"agent",
"to",
"act",
"."
] | 54dc3e31c97a3f938e58272f8ab80b6bcafeff58 | https://github.com/assamite/creamas/blob/54dc3e31c97a3f938e58272f8ab80b6bcafeff58/creamas/core/environment.py#L120-L135 | train | Trigger an action to act. |
assamite/creamas | creamas/core/environment.py | Environment.trigger_all | async def trigger_all(self, *args, **kwargs):
'''Trigger all agents in the environment to act asynchronously.
:returns: A list of agents' :meth:`act` return values.
Given arguments and keyword arguments are passed down to each agent's
:meth:`creamas.core.agent.CreativeAgent.act`.
... | python | async def trigger_all(self, *args, **kwargs):
'''Trigger all agents in the environment to act asynchronously.
:returns: A list of agents' :meth:`act` return values.
Given arguments and keyword arguments are passed down to each agent's
:meth:`creamas.core.agent.CreativeAgent.act`.
... | [
"async",
"def",
"trigger_all",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"tasks",
"=",
"[",
"]",
"for",
"a",
"in",
"self",
".",
"get_agents",
"(",
"addr",
"=",
"False",
",",
"include_manager",
"=",
"False",
")",
":",
"task",... | Trigger all agents in the environment to act asynchronously.
:returns: A list of agents' :meth:`act` return values.
Given arguments and keyword arguments are passed down to each agent's
:meth:`creamas.core.agent.CreativeAgent.act`.
.. note::
By design, the environment's m... | [
"Trigger",
"all",
"agents",
"in",
"the",
"environment",
"to",
"act",
"asynchronously",
"."
] | 54dc3e31c97a3f938e58272f8ab80b6bcafeff58 | https://github.com/assamite/creamas/blob/54dc3e31c97a3f938e58272f8ab80b6bcafeff58/creamas/core/environment.py#L137-L156 | train | Triggers all agents in the environment to act asynchronously. |
assamite/creamas | creamas/core/environment.py | Environment.create_random_connections | def create_random_connections(self, n=5):
'''Create random connections for all agents in the environment.
:param int n: the number of connections for each agent
Existing agent connections that would be created by chance are not
doubled in the agent's :attr:`connections`, but count towa... | python | def create_random_connections(self, n=5):
'''Create random connections for all agents in the environment.
:param int n: the number of connections for each agent
Existing agent connections that would be created by chance are not
doubled in the agent's :attr:`connections`, but count towa... | [
"def",
"create_random_connections",
"(",
"self",
",",
"n",
"=",
"5",
")",
":",
"if",
"type",
"(",
"n",
")",
"!=",
"int",
":",
"raise",
"TypeError",
"(",
"\"Argument 'n' must be of type int.\"",
")",
"if",
"n",
"<=",
"0",
":",
"raise",
"ValueError",
"(",
... | Create random connections for all agents in the environment.
:param int n: the number of connections for each agent
Existing agent connections that would be created by chance are not
doubled in the agent's :attr:`connections`, but count towards
connections created. | [
"Create",
"random",
"connections",
"for",
"all",
"agents",
"in",
"the",
"environment",
"."
] | 54dc3e31c97a3f938e58272f8ab80b6bcafeff58 | https://github.com/assamite/creamas/blob/54dc3e31c97a3f938e58272f8ab80b6bcafeff58/creamas/core/environment.py#L178-L196 | train | Create random connections for all agents in the environment. |
assamite/creamas | creamas/core/environment.py | Environment.create_connections | def create_connections(self, connection_map):
'''Create agent connections from a given connection map.
:param dict connection_map:
A map of connections to be created. Dictionary where keys are
agent addresses and values are lists of (addr, attitude)-tuples
suitable f... | python | def create_connections(self, connection_map):
'''Create agent connections from a given connection map.
:param dict connection_map:
A map of connections to be created. Dictionary where keys are
agent addresses and values are lists of (addr, attitude)-tuples
suitable f... | [
"def",
"create_connections",
"(",
"self",
",",
"connection_map",
")",
":",
"agents",
"=",
"self",
".",
"get_agents",
"(",
"addr",
"=",
"False",
")",
"rets",
"=",
"[",
"]",
"for",
"a",
"in",
"agents",
":",
"if",
"a",
".",
"addr",
"in",
"connection_map",... | Create agent connections from a given connection map.
:param dict connection_map:
A map of connections to be created. Dictionary where keys are
agent addresses and values are lists of (addr, attitude)-tuples
suitable for
:meth:`~creamas.core.agent.CreativeAgent.a... | [
"Create",
"agent",
"connections",
"from",
"a",
"given",
"connection",
"map",
"."
] | 54dc3e31c97a3f938e58272f8ab80b6bcafeff58 | https://github.com/assamite/creamas/blob/54dc3e31c97a3f938e58272f8ab80b6bcafeff58/creamas/core/environment.py#L198-L215 | train | Create agent connections from a given connection map. |
assamite/creamas | creamas/core/environment.py | Environment.get_connections | def get_connections(self, data=True):
"""Return connections from all the agents in the environment.
:param bool data:
If ``True`` return also the dictionary associated with each
connection
:returns:
A list of ``(addr, connections)``-tuples, where ``connectio... | python | def get_connections(self, data=True):
"""Return connections from all the agents in the environment.
:param bool data:
If ``True`` return also the dictionary associated with each
connection
:returns:
A list of ``(addr, connections)``-tuples, where ``connectio... | [
"def",
"get_connections",
"(",
"self",
",",
"data",
"=",
"True",
")",
":",
"connections",
"=",
"[",
"]",
"for",
"a",
"in",
"self",
".",
"get_agents",
"(",
"addr",
"=",
"False",
")",
":",
"c",
"=",
"(",
"a",
".",
"addr",
",",
"a",
".",
"get_connec... | Return connections from all the agents in the environment.
:param bool data:
If ``True`` return also the dictionary associated with each
connection
:returns:
A list of ``(addr, connections)``-tuples, where ``connections`` is
a list of addresses agent in ... | [
"Return",
"connections",
"from",
"all",
"the",
"agents",
"in",
"the",
"environment",
"."
] | 54dc3e31c97a3f938e58272f8ab80b6bcafeff58 | https://github.com/assamite/creamas/blob/54dc3e31c97a3f938e58272f8ab80b6bcafeff58/creamas/core/environment.py#L217-L242 | train | Return connections from all the agents in the environment. |
assamite/creamas | creamas/core/environment.py | Environment.get_random_agent | def get_random_agent(self, agent):
'''Return random agent that is not the same as agent given as
parameter.
:param agent: Agent that is not wanted to return
:type agent: :py:class:`~creamas.core.agent.CreativeAgent`
:returns: random, non-connected, agent from the environment
... | python | def get_random_agent(self, agent):
'''Return random agent that is not the same as agent given as
parameter.
:param agent: Agent that is not wanted to return
:type agent: :py:class:`~creamas.core.agent.CreativeAgent`
:returns: random, non-connected, agent from the environment
... | [
"def",
"get_random_agent",
"(",
"self",
",",
"agent",
")",
":",
"r_agent",
"=",
"choice",
"(",
"self",
".",
"get_agents",
"(",
"addr",
"=",
"False",
")",
")",
"while",
"r_agent",
".",
"addr",
"==",
"agent",
".",
"addr",
":",
"r_agent",
"=",
"choice",
... | Return random agent that is not the same as agent given as
parameter.
:param agent: Agent that is not wanted to return
:type agent: :py:class:`~creamas.core.agent.CreativeAgent`
:returns: random, non-connected, agent from the environment
:rtype: :py:class:`~creamas.core.agent.Cr... | [
"Return",
"random",
"agent",
"that",
"is",
"not",
"the",
"same",
"as",
"agent",
"given",
"as",
"parameter",
"."
] | 54dc3e31c97a3f938e58272f8ab80b6bcafeff58 | https://github.com/assamite/creamas/blob/54dc3e31c97a3f938e58272f8ab80b6bcafeff58/creamas/core/environment.py#L250-L262 | train | Return random agent that is not the same as agent given as
parameter. |
assamite/creamas | creamas/core/environment.py | Environment.add_artifact | def add_artifact(self, artifact):
'''Add artifact with given framing to the environment.
:param object artifact: Artifact to be added.
'''
artifact.env_time = self.age
self.artifacts.append(artifact)
self._log(logging.DEBUG, "ARTIFACTS appended: '{}', length={}"
... | python | def add_artifact(self, artifact):
'''Add artifact with given framing to the environment.
:param object artifact: Artifact to be added.
'''
artifact.env_time = self.age
self.artifacts.append(artifact)
self._log(logging.DEBUG, "ARTIFACTS appended: '{}', length={}"
... | [
"def",
"add_artifact",
"(",
"self",
",",
"artifact",
")",
":",
"artifact",
".",
"env_time",
"=",
"self",
".",
"age",
"self",
".",
"artifacts",
".",
"append",
"(",
"artifact",
")",
"self",
".",
"_log",
"(",
"logging",
".",
"DEBUG",
",",
"\"ARTIFACTS appen... | Add artifact with given framing to the environment.
:param object artifact: Artifact to be added. | [
"Add",
"artifact",
"with",
"given",
"framing",
"to",
"the",
"environment",
"."
] | 54dc3e31c97a3f938e58272f8ab80b6bcafeff58 | https://github.com/assamite/creamas/blob/54dc3e31c97a3f938e58272f8ab80b6bcafeff58/creamas/core/environment.py#L264-L272 | train | Add an artifact to the environment. |
assamite/creamas | creamas/core/environment.py | Environment.get_artifacts | async def get_artifacts(self, agent=None):
'''Return artifacts published to the environment.
:param agent:
If not ``None``, then returns only artifacts created by the agent.
:returns: All artifacts published (by the agent).
:rtype: list
If environment has a :attr:`... | python | async def get_artifacts(self, agent=None):
'''Return artifacts published to the environment.
:param agent:
If not ``None``, then returns only artifacts created by the agent.
:returns: All artifacts published (by the agent).
:rtype: list
If environment has a :attr:`... | [
"async",
"def",
"get_artifacts",
"(",
"self",
",",
"agent",
"=",
"None",
")",
":",
"# TODO: Figure better way for this",
"if",
"hasattr",
"(",
"self",
",",
"'manager'",
")",
"and",
"self",
".",
"manager",
"is",
"not",
"None",
":",
"artifacts",
"=",
"await",
... | Return artifacts published to the environment.
:param agent:
If not ``None``, then returns only artifacts created by the agent.
:returns: All artifacts published (by the agent).
:rtype: list
If environment has a :attr:`manager` agent, e.g. it is a slave
environment... | [
"Return",
"artifacts",
"published",
"to",
"the",
"environment",
"."
] | 54dc3e31c97a3f938e58272f8ab80b6bcafeff58 | https://github.com/assamite/creamas/blob/54dc3e31c97a3f938e58272f8ab80b6bcafeff58/creamas/core/environment.py#L283-L303 | train | Return all artifacts published to the environment. |
assamite/creamas | creamas/core/environment.py | Environment.destroy | def destroy(self, folder=None, as_coro=False):
'''Destroy the environment.
Does the following:
1. calls :py:meth:`~creamas.core.Environment.save_info`
2. for each agent: calls :py:meth:`close`
3. Shuts down its RPC-service.
'''
async def _destroy(folder):
... | python | def destroy(self, folder=None, as_coro=False):
'''Destroy the environment.
Does the following:
1. calls :py:meth:`~creamas.core.Environment.save_info`
2. for each agent: calls :py:meth:`close`
3. Shuts down its RPC-service.
'''
async def _destroy(folder):
... | [
"def",
"destroy",
"(",
"self",
",",
"folder",
"=",
"None",
",",
"as_coro",
"=",
"False",
")",
":",
"async",
"def",
"_destroy",
"(",
"folder",
")",
":",
"ret",
"=",
"self",
".",
"save_info",
"(",
"folder",
")",
"for",
"a",
"in",
"self",
".",
"get_ag... | Destroy the environment.
Does the following:
1. calls :py:meth:`~creamas.core.Environment.save_info`
2. for each agent: calls :py:meth:`close`
3. Shuts down its RPC-service. | [
"Destroy",
"the",
"environment",
"."
] | 54dc3e31c97a3f938e58272f8ab80b6bcafeff58 | https://github.com/assamite/creamas/blob/54dc3e31c97a3f938e58272f8ab80b6bcafeff58/creamas/core/environment.py#L319-L335 | train | Destroy the environment. |
TelAPI/telapi-python | telapi/rest/__init__.py | ListResource.fetch | def fetch(self, resource_data=None):
"""Populates this class with remote data"""
if not self._populated:
params = {
"Page" : self.page,
"PageSize" : self.page_size,
}
params.update(self._filters)
if not resource_data... | python | def fetch(self, resource_data=None):
"""Populates this class with remote data"""
if not self._populated:
params = {
"Page" : self.page,
"PageSize" : self.page_size,
}
params.update(self._filters)
if not resource_data... | [
"def",
"fetch",
"(",
"self",
",",
"resource_data",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"_populated",
":",
"params",
"=",
"{",
"\"Page\"",
":",
"self",
".",
"page",
",",
"\"PageSize\"",
":",
"self",
".",
"page_size",
",",
"}",
"params",
"... | Populates this class with remote data | [
"Populates",
"this",
"class",
"with",
"remote",
"data"
] | a13dcb12f7ae5ca9f681b96f2802fff6ec2aff32 | https://github.com/TelAPI/telapi-python/blob/a13dcb12f7ae5ca9f681b96f2802fff6ec2aff32/telapi/rest/__init__.py#L178-L197 | train | Populates this class with remote data |
TelAPI/telapi-python | telapi/rest/__init__.py | InstanceResource.fetch | def fetch(self, resource_data=None):
"""Populates this class with remote data"""
try:
if not resource_data:
resource_data = self._client._get(self._url + ".json")
for name in self._allowed_attributes:
setattr(self, name, resource_data.get(name, No... | python | def fetch(self, resource_data=None):
"""Populates this class with remote data"""
try:
if not resource_data:
resource_data = self._client._get(self._url + ".json")
for name in self._allowed_attributes:
setattr(self, name, resource_data.get(name, No... | [
"def",
"fetch",
"(",
"self",
",",
"resource_data",
"=",
"None",
")",
":",
"try",
":",
"if",
"not",
"resource_data",
":",
"resource_data",
"=",
"self",
".",
"_client",
".",
"_get",
"(",
"self",
".",
"_url",
"+",
"\".json\"",
")",
"for",
"name",
"in",
... | Populates this class with remote data | [
"Populates",
"this",
"class",
"with",
"remote",
"data"
] | a13dcb12f7ae5ca9f681b96f2802fff6ec2aff32 | https://github.com/TelAPI/telapi-python/blob/a13dcb12f7ae5ca9f681b96f2802fff6ec2aff32/telapi/rest/__init__.py#L271-L290 | train | Populates this class with remote data |
Kortemme-Lab/klab | klab/process.py | tee | def tee(*popenargs, **kwargs):
"""
Run a command as if it were piped though tee.
Output generated by the command is displayed in real time to the terminal.
It is also captured in strings and returned once the process terminated.
This function is very useful for logging output from cluster runs.... | python | def tee(*popenargs, **kwargs):
"""
Run a command as if it were piped though tee.
Output generated by the command is displayed in real time to the terminal.
It is also captured in strings and returned once the process terminated.
This function is very useful for logging output from cluster runs.... | [
"def",
"tee",
"(",
"*",
"popenargs",
",",
"*",
"*",
"kwargs",
")",
":",
"import",
"subprocess",
",",
"select",
",",
"sys",
"process",
"=",
"subprocess",
".",
"Popen",
"(",
"stdout",
"=",
"subprocess",
".",
"PIPE",
",",
"stderr",
"=",
"subprocess",
".",... | Run a command as if it were piped though tee.
Output generated by the command is displayed in real time to the terminal.
It is also captured in strings and returned once the process terminated.
This function is very useful for logging output from cluster runs. Naive
approaches like check_output()... | [
"Run",
"a",
"command",
"as",
"if",
"it",
"were",
"piped",
"though",
"tee",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/process.py#L26-L66 | train | Runs a command as if it were piped though tee. Returns a string that can be used to display the output of the command. |
Kortemme-Lab/klab | klab/process.py | Daemon.start | def start(self):
"""
Start the daemon
"""
# Check for a pidfile to see if the daemon already runs
pid = None
if os.path.exists(self.pidfile):
try:
pf = file(self.pidfile,'r')
pid = int(pf.read().strip())
pf.close... | python | def start(self):
"""
Start the daemon
"""
# Check for a pidfile to see if the daemon already runs
pid = None
if os.path.exists(self.pidfile):
try:
pf = file(self.pidfile,'r')
pid = int(pf.read().strip())
pf.close... | [
"def",
"start",
"(",
"self",
")",
":",
"# Check for a pidfile to see if the daemon already runs",
"pid",
"=",
"None",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"pidfile",
")",
":",
"try",
":",
"pf",
"=",
"file",
"(",
"self",
".",
"pidfile",... | Start the daemon | [
"Start",
"the",
"daemon"
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/process.py#L177-L198 | train | Start the daemon. |
Kortemme-Lab/klab | klab/process.py | Daemon.stop | def stop(self):
"""
Stop the daemon
"""
# Get the pid from the pidfile
try:
pf = file(self.pidfile,'r')
pid = int(pf.read().strip())
pf.close()
except IOError:
pid = None
if not pid:
message = "pidfile %... | python | def stop(self):
"""
Stop the daemon
"""
# Get the pid from the pidfile
try:
pf = file(self.pidfile,'r')
pid = int(pf.read().strip())
pf.close()
except IOError:
pid = None
if not pid:
message = "pidfile %... | [
"def",
"stop",
"(",
"self",
")",
":",
"# Get the pid from the pidfile",
"try",
":",
"pf",
"=",
"file",
"(",
"self",
".",
"pidfile",
",",
"'r'",
")",
"pid",
"=",
"int",
"(",
"pf",
".",
"read",
"(",
")",
".",
"strip",
"(",
")",
")",
"pf",
".",
"clo... | Stop the daemon | [
"Stop",
"the",
"daemon"
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/process.py#L200-L230 | train | Stop the daemon process |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.init | def init(self, app):
"""
Initialise from flask app
This gets configuration values from a flask application.
:param app: flask.Flask
:return: boiler.user.user_servce.UserService
"""
cfg = app.config
self.welcome_message = cfg.get('USER_SEND_WELCOME_MESSAGE'... | python | def init(self, app):
"""
Initialise from flask app
This gets configuration values from a flask application.
:param app: flask.Flask
:return: boiler.user.user_servce.UserService
"""
cfg = app.config
self.welcome_message = cfg.get('USER_SEND_WELCOME_MESSAGE'... | [
"def",
"init",
"(",
"self",
",",
"app",
")",
":",
"cfg",
"=",
"app",
".",
"config",
"self",
".",
"welcome_message",
"=",
"cfg",
".",
"get",
"(",
"'USER_SEND_WELCOME_MESSAGE'",
")",
"self",
".",
"require_confirmation",
"=",
"cfg",
".",
"get",
"(",
"'USER_... | Initialise from flask app
This gets configuration values from a flask application.
:param app: flask.Flask
:return: boiler.user.user_servce.UserService | [
"Initialise",
"from",
"flask",
"app",
"This",
"gets",
"configuration",
"values",
"from",
"a",
"flask",
"application",
".",
":",
"param",
"app",
":",
"flask",
".",
"Flask",
":",
"return",
":",
"boiler",
".",
"user",
".",
"user_servce",
".",
"UserService"
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L49-L71 | train | Initializes from flask app
|
projectshift/shift-boiler | boiler/user/user_service.py | UserService.save | def save(self, user, commit=True):
""" Persist user and emit event """
self.is_instance(user)
schema = UpdateSchema()
valid = schema.process(user)
if not valid:
return valid
db.session.add(user)
if commit:
db.session.commit()
eve... | python | def save(self, user, commit=True):
""" Persist user and emit event """
self.is_instance(user)
schema = UpdateSchema()
valid = schema.process(user)
if not valid:
return valid
db.session.add(user)
if commit:
db.session.commit()
eve... | [
"def",
"save",
"(",
"self",
",",
"user",
",",
"commit",
"=",
"True",
")",
":",
"self",
".",
"is_instance",
"(",
"user",
")",
"schema",
"=",
"UpdateSchema",
"(",
")",
"valid",
"=",
"schema",
".",
"process",
"(",
"user",
")",
"if",
"not",
"valid",
":... | Persist user and emit event | [
"Persist",
"user",
"and",
"emit",
"event"
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L73-L87 | train | Persist user and emit event |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.delete | def delete(self, user, commit=True):
""" Delete a user """
events.user_delete_event.send(user)
return super().delete(user, commit) | python | def delete(self, user, commit=True):
""" Delete a user """
events.user_delete_event.send(user)
return super().delete(user, commit) | [
"def",
"delete",
"(",
"self",
",",
"user",
",",
"commit",
"=",
"True",
")",
":",
"events",
".",
"user_delete_event",
".",
"send",
"(",
"user",
")",
"return",
"super",
"(",
")",
".",
"delete",
"(",
"user",
",",
"commit",
")"
] | Delete a user | [
"Delete",
"a",
"user"
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L89-L92 | train | Delete a user |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.login | def login(self, email=None, password=None, remember=False):
""" Authenticate user and emit event. """
from flask_login import login_user
user = self.first(email=email)
if user is None:
events.login_failed_nonexistent_event.send()
return False
# check for ... | python | def login(self, email=None, password=None, remember=False):
""" Authenticate user and emit event. """
from flask_login import login_user
user = self.first(email=email)
if user is None:
events.login_failed_nonexistent_event.send()
return False
# check for ... | [
"def",
"login",
"(",
"self",
",",
"email",
"=",
"None",
",",
"password",
"=",
"None",
",",
"remember",
"=",
"False",
")",
":",
"from",
"flask_login",
"import",
"login_user",
"user",
"=",
"self",
".",
"first",
"(",
"email",
"=",
"email",
")",
"if",
"u... | Authenticate user and emit event. | [
"Authenticate",
"user",
"and",
"emit",
"event",
"."
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L98-L133 | train | Authenticate user and emit event. |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.force_login | def force_login(self, user):
""" Force login a user without credentials """
from flask_login import login_user
# check for account being locked
if user.is_locked():
raise x.AccountLocked(locked_until=user.locked_until)
# check for email being confirmed
is_ne... | python | def force_login(self, user):
""" Force login a user without credentials """
from flask_login import login_user
# check for account being locked
if user.is_locked():
raise x.AccountLocked(locked_until=user.locked_until)
# check for email being confirmed
is_ne... | [
"def",
"force_login",
"(",
"self",
",",
"user",
")",
":",
"from",
"flask_login",
"import",
"login_user",
"# check for account being locked",
"if",
"user",
".",
"is_locked",
"(",
")",
":",
"raise",
"x",
".",
"AccountLocked",
"(",
"locked_until",
"=",
"user",
".... | Force login a user without credentials | [
"Force",
"login",
"a",
"user",
"without",
"credentials"
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L135-L158 | train | Force login a user without credentials |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.logout | def logout(self):
""" Logout user and emit event."""
from flask_login import logout_user, current_user
if not current_user.is_authenticated:
return True
# logout otherwise
user = current_user
events.logout_event.send(user)
logout_user()
# not... | python | def logout(self):
""" Logout user and emit event."""
from flask_login import logout_user, current_user
if not current_user.is_authenticated:
return True
# logout otherwise
user = current_user
events.logout_event.send(user)
logout_user()
# not... | [
"def",
"logout",
"(",
"self",
")",
":",
"from",
"flask_login",
"import",
"logout_user",
",",
"current_user",
"if",
"not",
"current_user",
".",
"is_authenticated",
":",
"return",
"True",
"# logout otherwise",
"user",
"=",
"current_user",
"events",
".",
"logout_even... | Logout user and emit event. | [
"Logout",
"user",
"and",
"emit",
"event",
"."
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L160-L175 | train | Logout user and emit event. |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.attempt_social_login | def attempt_social_login(self, provider, id):
""" Attempt social login and return boolean result """
if not provider or not id:
return False
params = dict()
params[provider.lower() + '_id'] = id
user = self.first(**params)
if not user:
return Fals... | python | def attempt_social_login(self, provider, id):
""" Attempt social login and return boolean result """
if not provider or not id:
return False
params = dict()
params[provider.lower() + '_id'] = id
user = self.first(**params)
if not user:
return Fals... | [
"def",
"attempt_social_login",
"(",
"self",
",",
"provider",
",",
"id",
")",
":",
"if",
"not",
"provider",
"or",
"not",
"id",
":",
"return",
"False",
"params",
"=",
"dict",
"(",
")",
"params",
"[",
"provider",
".",
"lower",
"(",
")",
"+",
"'_id'",
"]... | Attempt social login and return boolean result | [
"Attempt",
"social",
"login",
"and",
"return",
"boolean",
"result"
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L177-L189 | train | Attempt social login and return boolean result |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.decode_token | def decode_token(self, token):
"""
Decode token
A shorthand method to decode JWT token. Will return the payload as a
dictionary
:return: str, token
:return: dict
"""
return jwt.decode(
token,
self.jwt_secret,
algorithms=... | python | def decode_token(self, token):
"""
Decode token
A shorthand method to decode JWT token. Will return the payload as a
dictionary
:return: str, token
:return: dict
"""
return jwt.decode(
token,
self.jwt_secret,
algorithms=... | [
"def",
"decode_token",
"(",
"self",
",",
"token",
")",
":",
"return",
"jwt",
".",
"decode",
"(",
"token",
",",
"self",
".",
"jwt_secret",
",",
"algorithms",
"=",
"[",
"self",
".",
"jwt_algo",
"]",
")"
] | Decode token
A shorthand method to decode JWT token. Will return the payload as a
dictionary
:return: str, token
:return: dict | [
"Decode",
"token",
"A",
"shorthand",
"method",
"to",
"decode",
"JWT",
"token",
".",
"Will",
"return",
"the",
"payload",
"as",
"a",
"dictionary",
":",
"return",
":",
"str",
"token",
":",
"return",
":",
"dict"
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L195-L207 | train | Decode a token into a dictionary. |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.revoke_user_token | def revoke_user_token(self, user_id):
"""
Revoke user token
Erases user token on file forcing them to re-login and obtain a new one.
:param user_id: int
:return:
"""
user = self.get(user_id)
user._token = None
self.save(user) | python | def revoke_user_token(self, user_id):
"""
Revoke user token
Erases user token on file forcing them to re-login and obtain a new one.
:param user_id: int
:return:
"""
user = self.get(user_id)
user._token = None
self.save(user) | [
"def",
"revoke_user_token",
"(",
"self",
",",
"user_id",
")",
":",
"user",
"=",
"self",
".",
"get",
"(",
"user_id",
")",
"user",
".",
"_token",
"=",
"None",
"self",
".",
"save",
"(",
"user",
")"
] | Revoke user token
Erases user token on file forcing them to re-login and obtain a new one.
:param user_id: int
:return: | [
"Revoke",
"user",
"token",
"Erases",
"user",
"token",
"on",
"file",
"forcing",
"them",
"to",
"re",
"-",
"login",
"and",
"obtain",
"a",
"new",
"one",
".",
":",
"param",
"user_id",
":",
"int",
":",
"return",
":"
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L209-L218 | train | Revoke user token on file and store it in the cache. |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.get_token | def get_token(self, user_id):
"""
Get user token
Checks if a custom token implementation is registered and uses that.
Otherwise falls back to default token implementation. Returns a string
token on success.
:param user_id: int, user id
:return: str
"""
... | python | def get_token(self, user_id):
"""
Get user token
Checks if a custom token implementation is registered and uses that.
Otherwise falls back to default token implementation. Returns a string
token on success.
:param user_id: int, user id
:return: str
"""
... | [
"def",
"get_token",
"(",
"self",
",",
"user_id",
")",
":",
"if",
"not",
"self",
".",
"jwt_implementation",
":",
"return",
"self",
".",
"default_token_implementation",
"(",
"user_id",
")",
"try",
":",
"implementation",
"=",
"import_string",
"(",
"self",
".",
... | Get user token
Checks if a custom token implementation is registered and uses that.
Otherwise falls back to default token implementation. Returns a string
token on success.
:param user_id: int, user id
:return: str | [
"Get",
"user",
"token",
"Checks",
"if",
"a",
"custom",
"token",
"implementation",
"is",
"registered",
"and",
"uses",
"that",
".",
"Otherwise",
"falls",
"back",
"to",
"default",
"token",
"implementation",
".",
"Returns",
"a",
"string",
"token",
"on",
"success",... | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L220-L241 | train | Get user token from user id. |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.get_user_by_token | def get_user_by_token(self, token):
"""
Get user by token
Using for logging in. Check to see if a custom token user loader was
registered and uses that. Otherwise falls back to default loader
implementation. You should be fine with default implementation as long
as your t... | python | def get_user_by_token(self, token):
"""
Get user by token
Using for logging in. Check to see if a custom token user loader was
registered and uses that. Otherwise falls back to default loader
implementation. You should be fine with default implementation as long
as your t... | [
"def",
"get_user_by_token",
"(",
"self",
",",
"token",
")",
":",
"if",
"not",
"self",
".",
"jwt_loader_implementation",
":",
"return",
"self",
".",
"default_token_user_loader",
"(",
"token",
")",
"try",
":",
"implementation",
"=",
"import_string",
"(",
"self",
... | Get user by token
Using for logging in. Check to see if a custom token user loader was
registered and uses that. Otherwise falls back to default loader
implementation. You should be fine with default implementation as long
as your token has user_id claim in it.
:param token: str... | [
"Get",
"user",
"by",
"token",
"Using",
"for",
"logging",
"in",
".",
"Check",
"to",
"see",
"if",
"a",
"custom",
"token",
"user",
"loader",
"was",
"registered",
"and",
"uses",
"that",
".",
"Otherwise",
"falls",
"back",
"to",
"default",
"loader",
"implementat... | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L243-L267 | train | Get user by token using custom token user loader |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.default_token_implementation | def default_token_implementation(self, user_id):
"""
Default JWT token implementation
This is used by default for generating user tokens if custom
implementation was not configured. The token will contain user_id and
expiration date. If you need more information added to the toke... | python | def default_token_implementation(self, user_id):
"""
Default JWT token implementation
This is used by default for generating user tokens if custom
implementation was not configured. The token will contain user_id and
expiration date. If you need more information added to the toke... | [
"def",
"default_token_implementation",
"(",
"self",
",",
"user_id",
")",
":",
"user",
"=",
"self",
".",
"get",
"(",
"user_id",
")",
"if",
"not",
"user",
":",
"msg",
"=",
"'No user with such id [{}]'",
"raise",
"x",
".",
"JwtNoUser",
"(",
"msg",
".",
"forma... | Default JWT token implementation
This is used by default for generating user tokens if custom
implementation was not configured. The token will contain user_id and
expiration date. If you need more information added to the token,
register your custom implementation.
It will load... | [
"Default",
"JWT",
"token",
"implementation",
"This",
"is",
"used",
"by",
"default",
"for",
"generating",
"user",
"tokens",
"if",
"custom",
"implementation",
"was",
"not",
"configured",
".",
"The",
"token",
"will",
"contain",
"user_id",
"and",
"expiration",
"date... | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L269-L312 | train | Default JWT token implementation for user with given id. |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.default_token_user_loader | def default_token_user_loader(self, token):
"""
Default token user loader
Accepts a token and decodes it checking signature and expiration. Then
loads user by id from the token to see if account is not locked. If
all is good, returns user record, otherwise throws an exception.
... | python | def default_token_user_loader(self, token):
"""
Default token user loader
Accepts a token and decodes it checking signature and expiration. Then
loads user by id from the token to see if account is not locked. If
all is good, returns user record, otherwise throws an exception.
... | [
"def",
"default_token_user_loader",
"(",
"self",
",",
"token",
")",
":",
"try",
":",
"data",
"=",
"self",
".",
"decode_token",
"(",
"token",
")",
"except",
"jwt",
".",
"exceptions",
".",
"DecodeError",
"as",
"e",
":",
"raise",
"x",
".",
"JwtDecodeError",
... | Default token user loader
Accepts a token and decodes it checking signature and expiration. Then
loads user by id from the token to see if account is not locked. If
all is good, returns user record, otherwise throws an exception.
:param token: str, token string
:return: boiler.u... | [
"Default",
"token",
"user",
"loader",
"Accepts",
"a",
"token",
"and",
"decodes",
"it",
"checking",
"signature",
"and",
"expiration",
".",
"Then",
"loads",
"user",
"by",
"id",
"from",
"the",
"token",
"to",
"see",
"if",
"account",
"is",
"not",
"locked",
".",... | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L314-L352 | train | Default token user loader |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.register | def register(self, user_data, base_confirm_url='', send_welcome=True):
"""
Register user
Accepts user data, validates it and performs registration. Will send
a welcome message with a confirmation link on success.
:param user_data: dic, populate user with data
:param send... | python | def register(self, user_data, base_confirm_url='', send_welcome=True):
"""
Register user
Accepts user data, validates it and performs registration. Will send
a welcome message with a confirmation link on success.
:param user_data: dic, populate user with data
:param send... | [
"def",
"register",
"(",
"self",
",",
"user_data",
",",
"base_confirm_url",
"=",
"''",
",",
"send_welcome",
"=",
"True",
")",
":",
"user",
"=",
"self",
".",
"__model__",
"(",
"*",
"*",
"user_data",
")",
"schema",
"=",
"RegisterSchema",
"(",
")",
"valid",
... | Register user
Accepts user data, validates it and performs registration. Will send
a welcome message with a confirmation link on success.
:param user_data: dic, populate user with data
:param send_welcome: bool, whether to send welcome or skip it (testing)
:param base_confirm_ur... | [
"Register",
"user",
"Accepts",
"user",
"data",
"validates",
"it",
"and",
"performs",
"registration",
".",
"Will",
"send",
"a",
"welcome",
"message",
"with",
"a",
"confirmation",
"link",
"on",
"success",
"."
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L358-L385 | train | Register a user with the database. |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.send_welcome_message | def send_welcome_message(self, user, base_url):
""" Send welcome mail with email confirmation link """
if not self.require_confirmation and not self.welcome_message:
return
# get subject
subject = ''
subjects = self.email_subjects
if self.require_confirmation... | python | def send_welcome_message(self, user, base_url):
""" Send welcome mail with email confirmation link """
if not self.require_confirmation and not self.welcome_message:
return
# get subject
subject = ''
subjects = self.email_subjects
if self.require_confirmation... | [
"def",
"send_welcome_message",
"(",
"self",
",",
"user",
",",
"base_url",
")",
":",
"if",
"not",
"self",
".",
"require_confirmation",
"and",
"not",
"self",
".",
"welcome_message",
":",
"return",
"# get subject",
"subject",
"=",
"''",
"subjects",
"=",
"self",
... | Send welcome mail with email confirmation link | [
"Send",
"welcome",
"mail",
"with",
"email",
"confirmation",
"link"
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L387-L428 | train | Send welcome mail with email confirmation link |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.resend_welcome_message | def resend_welcome_message(self, user, base_url):
""" Regenerate email link and resend welcome """
user.require_email_confirmation()
self.save(user)
self.send_welcome_message(user, base_url) | python | def resend_welcome_message(self, user, base_url):
""" Regenerate email link and resend welcome """
user.require_email_confirmation()
self.save(user)
self.send_welcome_message(user, base_url) | [
"def",
"resend_welcome_message",
"(",
"self",
",",
"user",
",",
"base_url",
")",
":",
"user",
".",
"require_email_confirmation",
"(",
")",
"self",
".",
"save",
"(",
"user",
")",
"self",
".",
"send_welcome_message",
"(",
"user",
",",
"base_url",
")"
] | Regenerate email link and resend welcome | [
"Regenerate",
"email",
"link",
"and",
"resend",
"welcome"
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L430-L434 | train | Regenerate email link and resend welcome message |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.confirm_email_with_link | def confirm_email_with_link(self, link):
"""
Confirm email with link
A universal method to confirm email. used for both initial
confirmation and when email is changed.
"""
user = self.first(email_link=link)
if not user:
return False
elif user a... | python | def confirm_email_with_link(self, link):
"""
Confirm email with link
A universal method to confirm email. used for both initial
confirmation and when email is changed.
"""
user = self.first(email_link=link)
if not user:
return False
elif user a... | [
"def",
"confirm_email_with_link",
"(",
"self",
",",
"link",
")",
":",
"user",
"=",
"self",
".",
"first",
"(",
"email_link",
"=",
"link",
")",
"if",
"not",
"user",
":",
"return",
"False",
"elif",
"user",
"and",
"user",
".",
"email_confirmed",
":",
"return... | Confirm email with link
A universal method to confirm email. used for both initial
confirmation and when email is changed. | [
"Confirm",
"email",
"with",
"link",
"A",
"universal",
"method",
"to",
"confirm",
"email",
".",
"used",
"for",
"both",
"initial",
"confirmation",
"and",
"when",
"email",
"is",
"changed",
"."
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L440-L459 | train | Confirm email with link |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.change_email | def change_email(
self, user, new_email, base_confirm_url='', send_message=True):
"""
Change email
Saves new email and sends confirmation before doing the switch.
Can optionally skip sending out message for testing purposes.
The email will be sent to the new email addres... | python | def change_email(
self, user, new_email, base_confirm_url='', send_message=True):
"""
Change email
Saves new email and sends confirmation before doing the switch.
Can optionally skip sending out message for testing purposes.
The email will be sent to the new email addres... | [
"def",
"change_email",
"(",
"self",
",",
"user",
",",
"new_email",
",",
"base_confirm_url",
"=",
"''",
",",
"send_message",
"=",
"True",
")",
":",
"from",
"boiler",
".",
"user",
".",
"models",
"import",
"UpdateSchema",
"schema",
"=",
"UpdateSchema",
"(",
"... | Change email
Saves new email and sends confirmation before doing the switch.
Can optionally skip sending out message for testing purposes.
The email will be sent to the new email address to verify the user has
access to it. Important: please be sure to password-protect this.
:p... | [
"Change",
"email",
"Saves",
"new",
"email",
"and",
"sends",
"confirmation",
"before",
"doing",
"the",
"switch",
".",
"Can",
"optionally",
"skip",
"sending",
"out",
"message",
"for",
"testing",
"purposes",
"."
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L465-L496 | train | Changes the email address of a user s hasnac entry. |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.resend_email_changed_message | def resend_email_changed_message(self, user, base_url):
""" Regenerate email confirmation link and resend message """
user.require_email_confirmation()
self.save(user)
self.send_email_changed_message(user, base_url) | python | def resend_email_changed_message(self, user, base_url):
""" Regenerate email confirmation link and resend message """
user.require_email_confirmation()
self.save(user)
self.send_email_changed_message(user, base_url) | [
"def",
"resend_email_changed_message",
"(",
"self",
",",
"user",
",",
"base_url",
")",
":",
"user",
".",
"require_email_confirmation",
"(",
")",
"self",
".",
"save",
"(",
"user",
")",
"self",
".",
"send_email_changed_message",
"(",
"user",
",",
"base_url",
")"... | Regenerate email confirmation link and resend message | [
"Regenerate",
"email",
"confirmation",
"link",
"and",
"resend",
"message"
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L522-L526 | train | Regenerate email confirmation link and resend email changed message |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.request_password_reset | def request_password_reset(self, user, base_url):
""" Regenerate password link and send message """
user.generate_password_link()
db.session.add(user)
db.session.commit()
events.password_change_requested_event.send(user)
self.send_password_change_message(user, base_url) | python | def request_password_reset(self, user, base_url):
""" Regenerate password link and send message """
user.generate_password_link()
db.session.add(user)
db.session.commit()
events.password_change_requested_event.send(user)
self.send_password_change_message(user, base_url) | [
"def",
"request_password_reset",
"(",
"self",
",",
"user",
",",
"base_url",
")",
":",
"user",
".",
"generate_password_link",
"(",
")",
"db",
".",
"session",
".",
"add",
"(",
"user",
")",
"db",
".",
"session",
".",
"commit",
"(",
")",
"events",
".",
"pa... | Regenerate password link and send message | [
"Regenerate",
"password",
"link",
"and",
"send",
"message"
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L532-L538 | train | Request password reset |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.change_password | def change_password(self, user, new_password):
""" Change user password and logout """
from boiler.user.models import UpdateSchema
from flask_login import logout_user
schema = UpdateSchema()
user.password = new_password
user.password_link=None
user.password_link_... | python | def change_password(self, user, new_password):
""" Change user password and logout """
from boiler.user.models import UpdateSchema
from flask_login import logout_user
schema = UpdateSchema()
user.password = new_password
user.password_link=None
user.password_link_... | [
"def",
"change_password",
"(",
"self",
",",
"user",
",",
"new_password",
")",
":",
"from",
"boiler",
".",
"user",
".",
"models",
"import",
"UpdateSchema",
"from",
"flask_login",
"import",
"logout_user",
"schema",
"=",
"UpdateSchema",
"(",
")",
"user",
".",
"... | Change user password and logout | [
"Change",
"user",
"password",
"and",
"logout"
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L540-L562 | train | Change user password and logout |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.send_password_change_message | def send_password_change_message(self, user, base_url):
""" Send password change message"""
subject = 'Change your password here'
if 'password_change' in self.email_subjects.keys():
subject = self.email_subjects['password_change']
sender = current_app.config['MAIL_DEFAULT_SE... | python | def send_password_change_message(self, user, base_url):
""" Send password change message"""
subject = 'Change your password here'
if 'password_change' in self.email_subjects.keys():
subject = self.email_subjects['password_change']
sender = current_app.config['MAIL_DEFAULT_SE... | [
"def",
"send_password_change_message",
"(",
"self",
",",
"user",
",",
"base_url",
")",
":",
"subject",
"=",
"'Change your password here'",
"if",
"'password_change'",
"in",
"self",
".",
"email_subjects",
".",
"keys",
"(",
")",
":",
"subject",
"=",
"self",
".",
... | Send password change message | [
"Send",
"password",
"change",
"message"
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L564-L586 | train | Send a password change message to the user |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.add_role_to_user | def add_role_to_user(self, user, role):
""" Adds a role to user """
user.add_role(role)
self.save(user)
events.user_got_role_event.send(user, role=role) | python | def add_role_to_user(self, user, role):
""" Adds a role to user """
user.add_role(role)
self.save(user)
events.user_got_role_event.send(user, role=role) | [
"def",
"add_role_to_user",
"(",
"self",
",",
"user",
",",
"role",
")",
":",
"user",
".",
"add_role",
"(",
"role",
")",
"self",
".",
"save",
"(",
"user",
")",
"events",
".",
"user_got_role_event",
".",
"send",
"(",
"user",
",",
"role",
"=",
"role",
")... | Adds a role to user | [
"Adds",
"a",
"role",
"to",
"user"
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L592-L596 | train | Adds a role to a user |
projectshift/shift-boiler | boiler/user/user_service.py | UserService.remove_role_from_user | def remove_role_from_user(self, user, role):
""" Removes role from user """
user.remove_role(role)
self.save(user)
events.user_lost_role_event.send(user, role=role) | python | def remove_role_from_user(self, user, role):
""" Removes role from user """
user.remove_role(role)
self.save(user)
events.user_lost_role_event.send(user, role=role) | [
"def",
"remove_role_from_user",
"(",
"self",
",",
"user",
",",
"role",
")",
":",
"user",
".",
"remove_role",
"(",
"role",
")",
"self",
".",
"save",
"(",
"user",
")",
"events",
".",
"user_lost_role_event",
".",
"send",
"(",
"user",
",",
"role",
"=",
"ro... | Removes role from user | [
"Removes",
"role",
"from",
"user"
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/user/user_service.py#L598-L602 | train | Removes role from user |
berkeley-cocosci/Wallace | wallace/processes.py | random_walk | def random_walk(network):
"""Take a random walk from a source.
Start at a node randomly selected from those that receive input from a
source. At each step, transmit to a randomly-selected downstream node.
"""
latest = network.latest_transmission_recipient()
if (not network.transmissions() or l... | python | def random_walk(network):
"""Take a random walk from a source.
Start at a node randomly selected from those that receive input from a
source. At each step, transmit to a randomly-selected downstream node.
"""
latest = network.latest_transmission_recipient()
if (not network.transmissions() or l... | [
"def",
"random_walk",
"(",
"network",
")",
":",
"latest",
"=",
"network",
".",
"latest_transmission_recipient",
"(",
")",
"if",
"(",
"not",
"network",
".",
"transmissions",
"(",
")",
"or",
"latest",
"is",
"None",
")",
":",
"sender",
"=",
"random",
".",
"... | Take a random walk from a source.
Start at a node randomly selected from those that receive input from a
source. At each step, transmit to a randomly-selected downstream node. | [
"Take",
"a",
"random",
"walk",
"from",
"a",
"source",
"."
] | 3650c0bc3b0804d0adb1d178c5eba9992babb1b0 | https://github.com/berkeley-cocosci/Wallace/blob/3650c0bc3b0804d0adb1d178c5eba9992babb1b0/wallace/processes.py#L7-L22 | train | Take a random walk from a source. |
berkeley-cocosci/Wallace | wallace/processes.py | moran_cultural | def moran_cultural(network):
"""Generalized cultural Moran process.
At eachtime step, an individual is chosen to receive information from
another individual. Nobody dies, but perhaps their ideas do.
"""
if not network.transmissions(): # first step, replacer is a source
replacer = random.ch... | python | def moran_cultural(network):
"""Generalized cultural Moran process.
At eachtime step, an individual is chosen to receive information from
another individual. Nobody dies, but perhaps their ideas do.
"""
if not network.transmissions(): # first step, replacer is a source
replacer = random.ch... | [
"def",
"moran_cultural",
"(",
"network",
")",
":",
"if",
"not",
"network",
".",
"transmissions",
"(",
")",
":",
"# first step, replacer is a source",
"replacer",
"=",
"random",
".",
"choice",
"(",
"network",
".",
"nodes",
"(",
"type",
"=",
"Source",
")",
")"... | Generalized cultural Moran process.
At eachtime step, an individual is chosen to receive information from
another individual. Nobody dies, but perhaps their ideas do. | [
"Generalized",
"cultural",
"Moran",
"process",
"."
] | 3650c0bc3b0804d0adb1d178c5eba9992babb1b0 | https://github.com/berkeley-cocosci/Wallace/blob/3650c0bc3b0804d0adb1d178c5eba9992babb1b0/wallace/processes.py#L25-L43 | train | Generalized cultural Moran process. |
berkeley-cocosci/Wallace | wallace/processes.py | moran_sexual | def moran_sexual(network):
"""The generalized sexual Moran process.
Ateach time step, and individual is chosen for replication and another
individual is chosen to die. The replication replaces the one who dies.
For this process to work you need to add a new agent before calling step.
"""
if not... | python | def moran_sexual(network):
"""The generalized sexual Moran process.
Ateach time step, and individual is chosen for replication and another
individual is chosen to die. The replication replaces the one who dies.
For this process to work you need to add a new agent before calling step.
"""
if not... | [
"def",
"moran_sexual",
"(",
"network",
")",
":",
"if",
"not",
"network",
".",
"transmissions",
"(",
")",
":",
"replacer",
"=",
"random",
".",
"choice",
"(",
"network",
".",
"nodes",
"(",
"type",
"=",
"Source",
")",
")",
"replacer",
".",
"transmit",
"("... | The generalized sexual Moran process.
Ateach time step, and individual is chosen for replication and another
individual is chosen to die. The replication replaces the one who dies.
For this process to work you need to add a new agent before calling step. | [
"The",
"generalized",
"sexual",
"Moran",
"process",
"."
] | 3650c0bc3b0804d0adb1d178c5eba9992babb1b0 | https://github.com/berkeley-cocosci/Wallace/blob/3650c0bc3b0804d0adb1d178c5eba9992babb1b0/wallace/processes.py#L46-L77 | train | Generalized sexual Moran process. |
sprockets/sprockets.mixins.mediatype | sprockets/mixins/mediatype/transcoders.py | JSONTranscoder.dump_object | def dump_object(self, obj):
"""
Called to encode unrecognized object.
:param object obj: the object to encode
:return: the encoded object
:raises TypeError: when `obj` cannot be encoded
This method is passed as the ``default`` keyword parameter
to :func:`json.du... | python | def dump_object(self, obj):
"""
Called to encode unrecognized object.
:param object obj: the object to encode
:return: the encoded object
:raises TypeError: when `obj` cannot be encoded
This method is passed as the ``default`` keyword parameter
to :func:`json.du... | [
"def",
"dump_object",
"(",
"self",
",",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"uuid",
".",
"UUID",
")",
":",
"return",
"str",
"(",
"obj",
")",
"if",
"hasattr",
"(",
"obj",
",",
"'isoformat'",
")",
":",
"return",
"obj",
".",
"isoform... | Called to encode unrecognized object.
:param object obj: the object to encode
:return: the encoded object
:raises TypeError: when `obj` cannot be encoded
This method is passed as the ``default`` keyword parameter
to :func:`json.dumps`. It provides default representations for
... | [
"Called",
"to",
"encode",
"unrecognized",
"object",
"."
] | c034e04f674201487a8d6ce9f8ce36f3f5de07d8 | https://github.com/sprockets/sprockets.mixins.mediatype/blob/c034e04f674201487a8d6ce9f8ce36f3f5de07d8/sprockets/mixins/mediatype/transcoders.py#L81-L115 | train | This method is called to encode unrecognized objects. It returns a string representation of the object. |
sprockets/sprockets.mixins.mediatype | sprockets/mixins/mediatype/transcoders.py | MsgPackTranscoder.normalize_datum | def normalize_datum(self, datum):
"""
Convert `datum` into something that umsgpack likes.
:param datum: something that we want to process with umsgpack
:return: a packable version of `datum`
:raises TypeError: if `datum` cannot be packed
This message is called by :meth:... | python | def normalize_datum(self, datum):
"""
Convert `datum` into something that umsgpack likes.
:param datum: something that we want to process with umsgpack
:return: a packable version of `datum`
:raises TypeError: if `datum` cannot be packed
This message is called by :meth:... | [
"def",
"normalize_datum",
"(",
"self",
",",
"datum",
")",
":",
"if",
"datum",
"is",
"None",
":",
"return",
"datum",
"if",
"isinstance",
"(",
"datum",
",",
"self",
".",
"PACKABLE_TYPES",
")",
":",
"return",
"datum",
"if",
"isinstance",
"(",
"datum",
",",
... | Convert `datum` into something that umsgpack likes.
:param datum: something that we want to process with umsgpack
:return: a packable version of `datum`
:raises TypeError: if `datum` cannot be packed
This message is called by :meth:`.packb` to recursively normalize
an input val... | [
"Convert",
"datum",
"into",
"something",
"that",
"umsgpack",
"likes",
"."
] | c034e04f674201487a8d6ce9f8ce36f3f5de07d8 | https://github.com/sprockets/sprockets.mixins.mediatype/blob/c034e04f674201487a8d6ce9f8ce36f3f5de07d8/sprockets/mixins/mediatype/transcoders.py#L150-L244 | train | Normalizes a datum into something that umsgpack likes. |
Kortemme-Lab/klab | klab/bio/pymolmod/psebuilder.py | create_pymol_selection_from_PDB_residue_ids | def create_pymol_selection_from_PDB_residue_ids(residue_list):
'''Elements of residue_list should be strings extracted from PDB lines from position 21-26 inclusive (zero-indexing)
i.e. the chain letter concatenated by the 5-character (including insertion code) residue ID.'''
residues_by_chain = {}
fo... | python | def create_pymol_selection_from_PDB_residue_ids(residue_list):
'''Elements of residue_list should be strings extracted from PDB lines from position 21-26 inclusive (zero-indexing)
i.e. the chain letter concatenated by the 5-character (including insertion code) residue ID.'''
residues_by_chain = {}
fo... | [
"def",
"create_pymol_selection_from_PDB_residue_ids",
"(",
"residue_list",
")",
":",
"residues_by_chain",
"=",
"{",
"}",
"for",
"residue_id",
"in",
"residue_list",
":",
"chain_id",
"=",
"residue_id",
"[",
"0",
"]",
"pruned_residue_id",
"=",
"residue_id",
"[",
"1",
... | Elements of residue_list should be strings extracted from PDB lines from position 21-26 inclusive (zero-indexing)
i.e. the chain letter concatenated by the 5-character (including insertion code) residue ID. | [
"Elements",
"of",
"residue_list",
"should",
"be",
"strings",
"extracted",
"from",
"PDB",
"lines",
"from",
"position",
"21",
"-",
"26",
"inclusive",
"(",
"zero",
"-",
"indexing",
")",
"i",
".",
"e",
".",
"the",
"chain",
"letter",
"concatenated",
"by",
"the"... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pymolmod/psebuilder.py#L19-L32 | train | Create a pymol selection string from a list of residue IDs. |
TUNE-Archive/freight_forwarder | freight_forwarder/cli/offload.py | OffloadCommand._offload | def _offload(self, args, **extra_args):
"""
Export is the entry point for exporting docker images.
"""
if not isinstance(args, argparse.Namespace):
raise Exception("args should of an instance of argparse.Namespace")
# create new freight forwarder object
freig... | python | def _offload(self, args, **extra_args):
"""
Export is the entry point for exporting docker images.
"""
if not isinstance(args, argparse.Namespace):
raise Exception("args should of an instance of argparse.Namespace")
# create new freight forwarder object
freig... | [
"def",
"_offload",
"(",
"self",
",",
"args",
",",
"*",
"*",
"extra_args",
")",
":",
"if",
"not",
"isinstance",
"(",
"args",
",",
"argparse",
".",
"Namespace",
")",
":",
"raise",
"Exception",
"(",
"\"args should of an instance of argparse.Namespace\"",
")",
"# ... | Export is the entry point for exporting docker images. | [
"Export",
"is",
"the",
"entry",
"point",
"for",
"exporting",
"docker",
"images",
"."
] | 6ea4a49f474ec04abb8bb81b175c774a16b5312f | https://github.com/TUNE-Archive/freight_forwarder/blob/6ea4a49f474ec04abb8bb81b175c774a16b5312f/freight_forwarder/cli/offload.py#L30-L55 | train | This function is the entry point for exporting docker images. |
brunato/lograptor | lograptor/cache.py | LookupCache.map_value | def map_value(self, value, gid):
"""
Return the value for a group id, applying requested mapping.
Map only groups related to a filter, ie when the basename of
the group is identical to the name of a filter.
"""
base_gid = self.base_gid_pattern.search(gid).group(1)
... | python | def map_value(self, value, gid):
"""
Return the value for a group id, applying requested mapping.
Map only groups related to a filter, ie when the basename of
the group is identical to the name of a filter.
"""
base_gid = self.base_gid_pattern.search(gid).group(1)
... | [
"def",
"map_value",
"(",
"self",
",",
"value",
",",
"gid",
")",
":",
"base_gid",
"=",
"self",
".",
"base_gid_pattern",
".",
"search",
"(",
"gid",
")",
".",
"group",
"(",
"1",
")",
"if",
"self",
".",
"anonymyze",
":",
"try",
":",
"if",
"value",
"in"... | Return the value for a group id, applying requested mapping.
Map only groups related to a filter, ie when the basename of
the group is identical to the name of a filter. | [
"Return",
"the",
"value",
"for",
"a",
"group",
"id",
"applying",
"requested",
"mapping",
".",
"Map",
"only",
"groups",
"related",
"to",
"a",
"filter",
"ie",
"when",
"the",
"basename",
"of",
"the",
"group",
"is",
"identical",
"to",
"the",
"name",
"of",
"a... | b1f09fe1b429ed15110610092704ef12d253f3c9 | https://github.com/brunato/lograptor/blob/b1f09fe1b429ed15110610092704ef12d253f3c9/lograptor/cache.py#L69-L101 | train | Map a value for a group id applying requested mapping. |
brunato/lograptor | lograptor/cache.py | LookupCache.match_to_dict | def match_to_dict(self, match, gids):
"""
Map values from match into a dictionary.
"""
values = {}
for gid in gids:
try:
values[gid] = self.map_value(match.group(gid), gid)
except IndexError:
pass
return values | python | def match_to_dict(self, match, gids):
"""
Map values from match into a dictionary.
"""
values = {}
for gid in gids:
try:
values[gid] = self.map_value(match.group(gid), gid)
except IndexError:
pass
return values | [
"def",
"match_to_dict",
"(",
"self",
",",
"match",
",",
"gids",
")",
":",
"values",
"=",
"{",
"}",
"for",
"gid",
"in",
"gids",
":",
"try",
":",
"values",
"[",
"gid",
"]",
"=",
"self",
".",
"map_value",
"(",
"match",
".",
"group",
"(",
"gid",
")",... | Map values from match into a dictionary. | [
"Map",
"values",
"from",
"match",
"into",
"a",
"dictionary",
"."
] | b1f09fe1b429ed15110610092704ef12d253f3c9 | https://github.com/brunato/lograptor/blob/b1f09fe1b429ed15110610092704ef12d253f3c9/lograptor/cache.py#L103-L113 | train | Map values from match into a dictionary. |
brunato/lograptor | lograptor/cache.py | LookupCache.match_to_string | def match_to_string(self, match, gids, values=None):
"""
Return the mapped string from match object. If a dictionary of
values is provided then use it to build the string.
"""
s = match.string
parts = []
k = 0
for gid in sorted(gids, key=lambda x: gids[x])... | python | def match_to_string(self, match, gids, values=None):
"""
Return the mapped string from match object. If a dictionary of
values is provided then use it to build the string.
"""
s = match.string
parts = []
k = 0
for gid in sorted(gids, key=lambda x: gids[x])... | [
"def",
"match_to_string",
"(",
"self",
",",
"match",
",",
"gids",
",",
"values",
"=",
"None",
")",
":",
"s",
"=",
"match",
".",
"string",
"parts",
"=",
"[",
"]",
"k",
"=",
"0",
"for",
"gid",
"in",
"sorted",
"(",
"gids",
",",
"key",
"=",
"lambda",... | Return the mapped string from match object. If a dictionary of
values is provided then use it to build the string. | [
"Return",
"the",
"mapped",
"string",
"from",
"match",
"object",
".",
"If",
"a",
"dictionary",
"of",
"values",
"is",
"provided",
"then",
"use",
"it",
"to",
"build",
"the",
"string",
"."
] | b1f09fe1b429ed15110610092704ef12d253f3c9 | https://github.com/brunato/lograptor/blob/b1f09fe1b429ed15110610092704ef12d253f3c9/lograptor/cache.py#L115-L137 | train | Return the mapped string from a match object. |
brunato/lograptor | lograptor/cache.py | LookupCache.gethost | def gethost(self, ip_addr):
"""
Do reverse lookup on an ip address
"""
# Handle silly fake ipv6 addresses
try:
if ip_addr[:7] == '::ffff:':
ip_addr = ip_addr[7:]
except TypeError:
pass
if ip_addr[0] in string.letters:
... | python | def gethost(self, ip_addr):
"""
Do reverse lookup on an ip address
"""
# Handle silly fake ipv6 addresses
try:
if ip_addr[:7] == '::ffff:':
ip_addr = ip_addr[7:]
except TypeError:
pass
if ip_addr[0] in string.letters:
... | [
"def",
"gethost",
"(",
"self",
",",
"ip_addr",
")",
":",
"# Handle silly fake ipv6 addresses",
"try",
":",
"if",
"ip_addr",
"[",
":",
"7",
"]",
"==",
"'::ffff:'",
":",
"ip_addr",
"=",
"ip_addr",
"[",
"7",
":",
"]",
"except",
"TypeError",
":",
"pass",
"if... | Do reverse lookup on an ip address | [
"Do",
"reverse",
"lookup",
"on",
"an",
"ip",
"address"
] | b1f09fe1b429ed15110610092704ef12d253f3c9 | https://github.com/brunato/lograptor/blob/b1f09fe1b429ed15110610092704ef12d253f3c9/lograptor/cache.py#L139-L164 | train | Do reverse lookup on an ip address and return the host name |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.