repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
Kortemme-Lab/klab
klab/bio/pdb.py
PDB.get_rosetta_sequence_to_atom_json_map
def get_rosetta_sequence_to_atom_json_map(self): '''Returns the mapping from Rosetta residue IDs to PDB ATOM residue IDs in JSON format.''' import json if not self.rosetta_to_atom_sequence_maps and self.rosetta_sequences: raise Exception('The PDB to Rosetta mapping has not been deter...
python
def get_rosetta_sequence_to_atom_json_map(self): '''Returns the mapping from Rosetta residue IDs to PDB ATOM residue IDs in JSON format.''' import json if not self.rosetta_to_atom_sequence_maps and self.rosetta_sequences: raise Exception('The PDB to Rosetta mapping has not been deter...
[ "def", "get_rosetta_sequence_to_atom_json_map", "(", "self", ")", ":", "import", "json", "if", "not", "self", ".", "rosetta_to_atom_sequence_maps", "and", "self", ".", "rosetta_sequences", ":", "raise", "Exception", "(", "'The PDB to Rosetta mapping has not been determined....
Returns the mapping from Rosetta residue IDs to PDB ATOM residue IDs in JSON format.
[ "Returns", "the", "mapping", "from", "Rosetta", "residue", "IDs", "to", "PDB", "ATOM", "residue", "IDs", "in", "JSON", "format", "." ]
6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b
https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L1755-L1766
train
Kortemme-Lab/klab
klab/bio/pdb.py
PDB.assert_wildtype_matches
def assert_wildtype_matches(self, mutation): '''Check that the wildtype of the Mutation object matches the PDB sequence.''' readwt = self.getAminoAcid(self.getAtomLine(mutation.Chain, mutation.ResidueID)) assert(mutation.WildTypeAA == residue_type_3to1_map[readwt])
python
def assert_wildtype_matches(self, mutation): '''Check that the wildtype of the Mutation object matches the PDB sequence.''' readwt = self.getAminoAcid(self.getAtomLine(mutation.Chain, mutation.ResidueID)) assert(mutation.WildTypeAA == residue_type_3to1_map[readwt])
[ "def", "assert_wildtype_matches", "(", "self", ",", "mutation", ")", ":", "readwt", "=", "self", ".", "getAminoAcid", "(", "self", ".", "getAtomLine", "(", "mutation", ".", "Chain", ",", "mutation", ".", "ResidueID", ")", ")", "assert", "(", "mutation", "....
Check that the wildtype of the Mutation object matches the PDB sequence.
[ "Check", "that", "the", "wildtype", "of", "the", "Mutation", "object", "matches", "the", "PDB", "sequence", "." ]
6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b
https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L1788-L1791
train
Kortemme-Lab/klab
klab/bio/pdb.py
PDB.get_B_factors
def get_B_factors(self, force = False): '''This reads in all ATOM lines and compute the mean and standard deviation of each residue's B-factors. It returns a table of the mean and standard deviation per residue as well as the mean and standard deviation over all residues with each ...
python
def get_B_factors(self, force = False): '''This reads in all ATOM lines and compute the mean and standard deviation of each residue's B-factors. It returns a table of the mean and standard deviation per residue as well as the mean and standard deviation over all residues with each ...
[ "def", "get_B_factors", "(", "self", ",", "force", "=", "False", ")", ":", "if", "(", "not", "self", ".", "bfactors", ")", "or", "(", "force", "==", "True", ")", ":", "bfactors", "=", "{", "}", "old_chain_residue_id", "=", "None", "for", "line", "in"...
This reads in all ATOM lines and compute the mean and standard deviation of each residue's B-factors. It returns a table of the mean and standard deviation per residue as well as the mean and standard deviation over all residues with each residue having equal weighting. Whet...
[ "This", "reads", "in", "all", "ATOM", "lines", "and", "compute", "the", "mean", "and", "standard", "deviation", "of", "each", "residue", "s", "B", "-", "factors", ".", "It", "returns", "a", "table", "of", "the", "mean", "and", "standard", "deviation", "p...
6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b
https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2071-L2104
train
Kortemme-Lab/klab
klab/bio/pdb.py
PDB.validate_mutations
def validate_mutations(self, mutations): '''This function has been refactored to use the SimpleMutation class. The parameter is a list of Mutation objects. The function has no return value but raises a PDBValidationException if the wildtype in the Mutation m does not match the residue type...
python
def validate_mutations(self, mutations): '''This function has been refactored to use the SimpleMutation class. The parameter is a list of Mutation objects. The function has no return value but raises a PDBValidationException if the wildtype in the Mutation m does not match the residue type...
[ "def", "validate_mutations", "(", "self", ",", "mutations", ")", ":", "resID2AA", "=", "self", ".", "get_residue_id_to_type_map", "(", ")", "badmutations", "=", "[", "]", "for", "m", "in", "mutations", ":", "wildtype", "=", "resID2AA", ".", "get", "(", "PD...
This function has been refactored to use the SimpleMutation class. The parameter is a list of Mutation objects. The function has no return value but raises a PDBValidationException if the wildtype in the Mutation m does not match the residue type corresponding to residue m.ResidueID in the PDB fil...
[ "This", "function", "has", "been", "refactored", "to", "use", "the", "SimpleMutation", "class", ".", "The", "parameter", "is", "a", "list", "of", "Mutation", "objects", ".", "The", "function", "has", "no", "return", "value", "but", "raises", "a", "PDBValidat...
6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b
https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2252-L2265
train
Kortemme-Lab/klab
klab/bio/pdb.py
PDB.fix_chain_id
def fix_chain_id(self): """fill in missing chain identifier""" for i in xrange(len(self.lines)): line = self.lines[i] if line.startswith("ATOM") and line[21] == ' ': self.lines[i] = line[:21] + 'A' + line[22:]
python
def fix_chain_id(self): """fill in missing chain identifier""" for i in xrange(len(self.lines)): line = self.lines[i] if line.startswith("ATOM") and line[21] == ' ': self.lines[i] = line[:21] + 'A' + line[22:]
[ "def", "fix_chain_id", "(", "self", ")", ":", "for", "i", "in", "xrange", "(", "len", "(", "self", ".", "lines", ")", ")", ":", "line", "=", "self", ".", "lines", "[", "i", "]", "if", "line", ".", "startswith", "(", "\"ATOM\"", ")", "and", "line"...
fill in missing chain identifier
[ "fill", "in", "missing", "chain", "identifier" ]
6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b
https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2308-L2314
train
Kortemme-Lab/klab
klab/bio/pdb.py
PDB.getAtomLine
def getAtomLine(self, chain, resid): '''This function assumes that all lines are ATOM or HETATM lines. resid should have the proper PDB format i.e. an integer left-padded to length 4 followed by the insertion code which may be a blank space.''' for line in self.lines: f...
python
def getAtomLine(self, chain, resid): '''This function assumes that all lines are ATOM or HETATM lines. resid should have the proper PDB format i.e. an integer left-padded to length 4 followed by the insertion code which may be a blank space.''' for line in self.lines: f...
[ "def", "getAtomLine", "(", "self", ",", "chain", ",", "resid", ")", ":", "for", "line", "in", "self", ".", "lines", ":", "fieldtype", "=", "line", "[", "0", ":", "6", "]", ".", "strip", "(", ")", "assert", "(", "fieldtype", "==", "\"ATOM\"", "or", ...
This function assumes that all lines are ATOM or HETATM lines. resid should have the proper PDB format i.e. an integer left-padded to length 4 followed by the insertion code which may be a blank space.
[ "This", "function", "assumes", "that", "all", "lines", "are", "ATOM", "or", "HETATM", "lines", ".", "resid", "should", "have", "the", "proper", "PDB", "format", "i", ".", "e", ".", "an", "integer", "left", "-", "padded", "to", "length", "4", "followed", ...
6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b
https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2329-L2338
train
Kortemme-Lab/klab
klab/bio/pdb.py
PDB.getAtomLinesForResidueInRosettaStructure
def getAtomLinesForResidueInRosettaStructure(self, resid): '''We assume a Rosetta-generated structure where residues are uniquely identified by number.''' lines = [line for line in self.lines if line[0:4] == "ATOM" and resid == int(line[22:27])] if not lines: #print('Failed searching...
python
def getAtomLinesForResidueInRosettaStructure(self, resid): '''We assume a Rosetta-generated structure where residues are uniquely identified by number.''' lines = [line for line in self.lines if line[0:4] == "ATOM" and resid == int(line[22:27])] if not lines: #print('Failed searching...
[ "def", "getAtomLinesForResidueInRosettaStructure", "(", "self", ",", "resid", ")", ":", "lines", "=", "[", "line", "for", "line", "in", "self", ".", "lines", "if", "line", "[", "0", ":", "4", "]", "==", "\"ATOM\"", "and", "resid", "==", "int", "(", "li...
We assume a Rosetta-generated structure where residues are uniquely identified by number.
[ "We", "assume", "a", "Rosetta", "-", "generated", "structure", "where", "residues", "are", "uniquely", "identified", "by", "number", "." ]
6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b
https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2340-L2347
train
Kortemme-Lab/klab
klab/bio/pdb.py
PDB.stripForDDG
def stripForDDG(self, chains = True, keepHETATM = False, numberOfModels = None, raise_exception = True): '''Strips a PDB to ATOM lines. If keepHETATM is True then also retain HETATM lines. By default all PDB chains are kept. The chains parameter should be True or a list. In the latter case...
python
def stripForDDG(self, chains = True, keepHETATM = False, numberOfModels = None, raise_exception = True): '''Strips a PDB to ATOM lines. If keepHETATM is True then also retain HETATM lines. By default all PDB chains are kept. The chains parameter should be True or a list. In the latter case...
[ "def", "stripForDDG", "(", "self", ",", "chains", "=", "True", ",", "keepHETATM", "=", "False", ",", "numberOfModels", "=", "None", ",", "raise_exception", "=", "True", ")", ":", "if", "raise_exception", ":", "raise", "Exception", "(", "'This code is deprecate...
Strips a PDB to ATOM lines. If keepHETATM is True then also retain HETATM lines. By default all PDB chains are kept. The chains parameter should be True or a list. In the latter case, only those chains in the list are kept. Unoccupied ATOM lines are discarded. This function a...
[ "Strips", "a", "PDB", "to", "ATOM", "lines", ".", "If", "keepHETATM", "is", "True", "then", "also", "retain", "HETATM", "lines", ".", "By", "default", "all", "PDB", "chains", "are", "kept", ".", "The", "chains", "parameter", "should", "be", "True", "or",...
6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b
https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2372-L2432
train
Kortemme-Lab/klab
klab/bio/pdb.py
PDB.CheckForPresenceOf
def CheckForPresenceOf(self, reslist): '''This checks whether residues in reslist exist in the ATOM lines. It returns a list of the residues in reslist which did exist.''' if type(reslist) == type(""): reslist = [reslist] foundRes = {} for line in self.lines: ...
python
def CheckForPresenceOf(self, reslist): '''This checks whether residues in reslist exist in the ATOM lines. It returns a list of the residues in reslist which did exist.''' if type(reslist) == type(""): reslist = [reslist] foundRes = {} for line in self.lines: ...
[ "def", "CheckForPresenceOf", "(", "self", ",", "reslist", ")", ":", "if", "type", "(", "reslist", ")", "==", "type", "(", "\"\"", ")", ":", "reslist", "=", "[", "reslist", "]", "foundRes", "=", "{", "}", "for", "line", "in", "self", ".", "lines", "...
This checks whether residues in reslist exist in the ATOM lines. It returns a list of the residues in reslist which did exist.
[ "This", "checks", "whether", "residues", "in", "reslist", "exist", "in", "the", "ATOM", "lines", ".", "It", "returns", "a", "list", "of", "the", "residues", "in", "reslist", "which", "did", "exist", "." ]
6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b
https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2475-L2488
train
Kortemme-Lab/klab
klab/bio/pdb.py
PDB.fix_residue_numbering
def fix_residue_numbering(self): """this function renumbers the res ids in order to avoid strange behaviour of Rosetta""" resid_list = self.aa_resids() resid_set = set(resid_list) resid_lst1 = list(resid_set) resid_lst1.sort() map_res_id = {} x = 1 old_...
python
def fix_residue_numbering(self): """this function renumbers the res ids in order to avoid strange behaviour of Rosetta""" resid_list = self.aa_resids() resid_set = set(resid_list) resid_lst1 = list(resid_set) resid_lst1.sort() map_res_id = {} x = 1 old_...
[ "def", "fix_residue_numbering", "(", "self", ")", ":", "resid_list", "=", "self", ".", "aa_resids", "(", ")", "resid_set", "=", "set", "(", "resid_list", ")", "resid_lst1", "=", "list", "(", "resid_set", ")", "resid_lst1", ".", "sort", "(", ")", "map_res_i...
this function renumbers the res ids in order to avoid strange behaviour of Rosetta
[ "this", "function", "renumbers", "the", "res", "ids", "in", "order", "to", "avoid", "strange", "behaviour", "of", "Rosetta" ]
6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b
https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2542-L2573
train
Kortemme-Lab/klab
klab/bio/pdb.py
PDB.neighbors2
def neighbors2(self, distance, chain_residue, atom = None, resid_list = None): #atom = " CA " '''this one is more precise since it uses the chain identifier also''' if atom == None: # consider all atoms lines = [line for line in self.atomlines(resid_list) if line[17:20] in allo...
python
def neighbors2(self, distance, chain_residue, atom = None, resid_list = None): #atom = " CA " '''this one is more precise since it uses the chain identifier also''' if atom == None: # consider all atoms lines = [line for line in self.atomlines(resid_list) if line[17:20] in allo...
[ "def", "neighbors2", "(", "self", ",", "distance", ",", "chain_residue", ",", "atom", "=", "None", ",", "resid_list", "=", "None", ")", ":", "if", "atom", "==", "None", ":", "lines", "=", "[", "line", "for", "line", "in", "self", ".", "atomlines", "(...
this one is more precise since it uses the chain identifier also
[ "this", "one", "is", "more", "precise", "since", "it", "uses", "the", "chain", "identifier", "also" ]
6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b
https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2634-L2660
train
Kortemme-Lab/klab
klab/bio/pdb.py
PDB.extract_xyz_matrix_from_chain
def extract_xyz_matrix_from_chain(self, chain_id, atoms_of_interest = []): '''Create a pandas coordinates dataframe from the lines in the specified chain.''' chains = [l[21] for l in self.structure_lines if len(l) > 21] chain_lines = [l for l in self.structure_lines if len(l) > 21 and l[21] == c...
python
def extract_xyz_matrix_from_chain(self, chain_id, atoms_of_interest = []): '''Create a pandas coordinates dataframe from the lines in the specified chain.''' chains = [l[21] for l in self.structure_lines if len(l) > 21] chain_lines = [l for l in self.structure_lines if len(l) > 21 and l[21] == c...
[ "def", "extract_xyz_matrix_from_chain", "(", "self", ",", "chain_id", ",", "atoms_of_interest", "=", "[", "]", ")", ":", "chains", "=", "[", "l", "[", "21", "]", "for", "l", "in", "self", ".", "structure_lines", "if", "len", "(", "l", ")", ">", "21", ...
Create a pandas coordinates dataframe from the lines in the specified chain.
[ "Create", "a", "pandas", "coordinates", "dataframe", "from", "the", "lines", "in", "the", "specified", "chain", "." ]
6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b
https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2998-L3002
train
cozy/python_cozy_management
cozy_management/couchdb.py
create_token_file
def create_token_file(username=id_generator(), password=id_generator()): ''' Store the admins password for further retrieve ''' cozy_ds_uid = helpers.get_uid('cozy-data-system') if not os.path.isfile(LOGIN_FILENAME): with open(LOGIN_FILENAME, 'w+') as token_file: token_file....
python
def create_token_file(username=id_generator(), password=id_generator()): ''' Store the admins password for further retrieve ''' cozy_ds_uid = helpers.get_uid('cozy-data-system') if not os.path.isfile(LOGIN_FILENAME): with open(LOGIN_FILENAME, 'w+') as token_file: token_file....
[ "def", "create_token_file", "(", "username", "=", "id_generator", "(", ")", ",", "password", "=", "id_generator", "(", ")", ")", ":", "cozy_ds_uid", "=", "helpers", ".", "get_uid", "(", "'cozy-data-system'", ")", "if", "not", "os", ".", "path", ".", "isfil...
Store the admins password for further retrieve
[ "Store", "the", "admins", "password", "for", "further", "retrieve" ]
820cea58458ae3e067fa8cc2da38edbda4681dac
https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L37-L47
train
cozy/python_cozy_management
cozy_management/couchdb.py
get_admin
def get_admin(): ''' Return the actual admin from token file ''' if os.path.isfile(LOGIN_FILENAME): with open(LOGIN_FILENAME, 'r') as token_file: old_login, old_password = token_file.read().splitlines()[:2] return old_login, old_password else: return None,...
python
def get_admin(): ''' Return the actual admin from token file ''' if os.path.isfile(LOGIN_FILENAME): with open(LOGIN_FILENAME, 'r') as token_file: old_login, old_password = token_file.read().splitlines()[:2] return old_login, old_password else: return None,...
[ "def", "get_admin", "(", ")", ":", "if", "os", ".", "path", ".", "isfile", "(", "LOGIN_FILENAME", ")", ":", "with", "open", "(", "LOGIN_FILENAME", ",", "'r'", ")", "as", "token_file", ":", "old_login", ",", "old_password", "=", "token_file", ".", "read",...
Return the actual admin from token file
[ "Return", "the", "actual", "admin", "from", "token", "file" ]
820cea58458ae3e067fa8cc2da38edbda4681dac
https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L50-L59
train
cozy/python_cozy_management
cozy_management/couchdb.py
curl_couchdb
def curl_couchdb(url, method='GET', base_url=BASE_URL, data=None): ''' Launch a curl on CouchDB instance ''' (username, password) = get_admin() if username is None: auth = None else: auth = (username, password) if method == 'PUT': req = requests.put('{}{}'.format...
python
def curl_couchdb(url, method='GET', base_url=BASE_URL, data=None): ''' Launch a curl on CouchDB instance ''' (username, password) = get_admin() if username is None: auth = None else: auth = (username, password) if method == 'PUT': req = requests.put('{}{}'.format...
[ "def", "curl_couchdb", "(", "url", ",", "method", "=", "'GET'", ",", "base_url", "=", "BASE_URL", ",", "data", "=", "None", ")", ":", "(", "username", ",", "password", ")", "=", "get_admin", "(", ")", "if", "username", "is", "None", ":", "auth", "=",...
Launch a curl on CouchDB instance
[ "Launch", "a", "curl", "on", "CouchDB", "instance" ]
820cea58458ae3e067fa8cc2da38edbda4681dac
https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L62-L81
train
cozy/python_cozy_management
cozy_management/couchdb.py
get_couchdb_admins
def get_couchdb_admins(): ''' Return the actual CouchDB admins ''' user_list = [] req = curl_couchdb('/_config/admins/') for user in req.json().keys(): user_list.append(user) return user_list
python
def get_couchdb_admins(): ''' Return the actual CouchDB admins ''' user_list = [] req = curl_couchdb('/_config/admins/') for user in req.json().keys(): user_list.append(user) return user_list
[ "def", "get_couchdb_admins", "(", ")", ":", "user_list", "=", "[", "]", "req", "=", "curl_couchdb", "(", "'/_config/admins/'", ")", "for", "user", "in", "req", ".", "json", "(", ")", ".", "keys", "(", ")", ":", "user_list", ".", "append", "(", "user", ...
Return the actual CouchDB admins
[ "Return", "the", "actual", "CouchDB", "admins" ]
820cea58458ae3e067fa8cc2da38edbda4681dac
https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L84-L94
train
cozy/python_cozy_management
cozy_management/couchdb.py
create_couchdb_admin
def create_couchdb_admin(username, password): ''' Create a CouchDB user ''' curl_couchdb('/_config/admins/{}'.format(username), method='PUT', data='"{}"'.format(password))
python
def create_couchdb_admin(username, password): ''' Create a CouchDB user ''' curl_couchdb('/_config/admins/{}'.format(username), method='PUT', data='"{}"'.format(password))
[ "def", "create_couchdb_admin", "(", "username", ",", "password", ")", ":", "curl_couchdb", "(", "'/_config/admins/{}'", ".", "format", "(", "username", ")", ",", "method", "=", "'PUT'", ",", "data", "=", "'\"{}\"'", ".", "format", "(", "password", ")", ")" ]
Create a CouchDB user
[ "Create", "a", "CouchDB", "user" ]
820cea58458ae3e067fa8cc2da38edbda4681dac
https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L97-L103
train
cozy/python_cozy_management
cozy_management/couchdb.py
is_cozy_registered
def is_cozy_registered(): ''' Check if a Cozy is registered ''' req = curl_couchdb('/cozy/_design/user/_view/all') users = req.json()['rows'] if len(users) > 0: return True else: return False
python
def is_cozy_registered(): ''' Check if a Cozy is registered ''' req = curl_couchdb('/cozy/_design/user/_view/all') users = req.json()['rows'] if len(users) > 0: return True else: return False
[ "def", "is_cozy_registered", "(", ")", ":", "req", "=", "curl_couchdb", "(", "'/cozy/_design/user/_view/all'", ")", "users", "=", "req", ".", "json", "(", ")", "[", "'rows'", "]", "if", "len", "(", "users", ")", ">", "0", ":", "return", "True", "else", ...
Check if a Cozy is registered
[ "Check", "if", "a", "Cozy", "is", "registered" ]
820cea58458ae3e067fa8cc2da38edbda4681dac
https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L114-L124
train
cozy/python_cozy_management
cozy_management/couchdb.py
unregister_cozy
def unregister_cozy(): ''' Unregister a cozy ''' req = curl_couchdb('/cozy/_design/user/_view/all') users = req.json()['rows'] if len(users) > 0: user = users[0]['value'] user_id = user['_id'] user_rev = user['_rev'] print 'Delete cozy user: {}'.format(user_...
python
def unregister_cozy(): ''' Unregister a cozy ''' req = curl_couchdb('/cozy/_design/user/_view/all') users = req.json()['rows'] if len(users) > 0: user = users[0]['value'] user_id = user['_id'] user_rev = user['_rev'] print 'Delete cozy user: {}'.format(user_...
[ "def", "unregister_cozy", "(", ")", ":", "req", "=", "curl_couchdb", "(", "'/cozy/_design/user/_view/all'", ")", "users", "=", "req", ".", "json", "(", ")", "[", "'rows'", "]", "if", "len", "(", "users", ")", ">", "0", ":", "user", "=", "users", "[", ...
Unregister a cozy
[ "Unregister", "a", "cozy" ]
820cea58458ae3e067fa8cc2da38edbda4681dac
https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L127-L146
train
cozy/python_cozy_management
cozy_management/couchdb.py
delete_all_couchdb_admins
def delete_all_couchdb_admins(): ''' Delete all CouchDB users ''' # Get current cozy token username = get_admin()[0] # Get CouchDB admin list admins = get_couchdb_admins() # Delete all admin user excluding current for admin in admins: if admin == username: pr...
python
def delete_all_couchdb_admins(): ''' Delete all CouchDB users ''' # Get current cozy token username = get_admin()[0] # Get CouchDB admin list admins = get_couchdb_admins() # Delete all admin user excluding current for admin in admins: if admin == username: pr...
[ "def", "delete_all_couchdb_admins", "(", ")", ":", "username", "=", "get_admin", "(", ")", "[", "0", "]", "admins", "=", "get_couchdb_admins", "(", ")", "for", "admin", "in", "admins", ":", "if", "admin", "==", "username", ":", "print", "\"Delete {} later......
Delete all CouchDB users
[ "Delete", "all", "CouchDB", "users" ]
820cea58458ae3e067fa8cc2da38edbda4681dac
https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L159-L179
train
cozy/python_cozy_management
cozy_management/couchdb.py
delete_token
def delete_token(): ''' Delete current token, file & CouchDB admin user ''' username = get_admin()[0] admins = get_couchdb_admins() # Delete current admin if exist if username in admins: print 'I delete {} CouchDB user'.format(username) delete_couchdb_admin(username) ...
python
def delete_token(): ''' Delete current token, file & CouchDB admin user ''' username = get_admin()[0] admins = get_couchdb_admins() # Delete current admin if exist if username in admins: print 'I delete {} CouchDB user'.format(username) delete_couchdb_admin(username) ...
[ "def", "delete_token", "(", ")", ":", "username", "=", "get_admin", "(", ")", "[", "0", "]", "admins", "=", "get_couchdb_admins", "(", ")", "if", "username", "in", "admins", ":", "print", "'I delete {} CouchDB user'", ".", "format", "(", "username", ")", "...
Delete current token, file & CouchDB admin user
[ "Delete", "current", "token", "file", "&", "CouchDB", "admin", "user" ]
820cea58458ae3e067fa8cc2da38edbda4681dac
https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L182-L197
train
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
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
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
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
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
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
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
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
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", "if", "self", ".", "validate", "(", ")", ":", "data", "=", "{", "}", "data", "[", "'token'", "]", "=", "self", ".", "token", "[", "'ac...
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
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'", "}", "if", "self", ".", "api_key", ":", "headers", "[", "'X-API-KEY'", "]", "=", "self", ".", "api_key", "return", "requests", ",", "headers", "else", ":...
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
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
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
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'", ")", "return", "[", "(", "os", ".", "path", ".", "split", "(", "x", ")", "[", "1", "]", ",", "x", ")", "for", "x", "in", "result", "[",...
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
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
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
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
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", ")", ":", "item_url", "=", "str", "(", "item_url", ")", "metadata", "=", "self", ".", "get_item", "(", "item_url", ")", ".", "met...
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
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
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", ":", "for", "key", "in", "(", "'@type'...
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
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
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
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
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
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", "metadata", "[", "'@type'", "]", "=", "'ausnc:AusN...
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
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
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
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
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
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
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
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
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
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
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\"", ")", "if", "'success'", "in", "resp", ":", "return", "Tr...
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
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
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
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
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
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", ")", "result", "[", "'id'", "]", "=", "os", ".", "path", ".", "split", "(", "result", "[", "'url'", "]", ")", "[", "1", "]", "ret...
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
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", ")", ")", "result", "[", "'id'", ...
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
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", ")", ":", "try", ":", "result", "=", "self", ".", "api_request", "(", "url", ")", "if", "'url'", "in", "result", "and", "'documents'", "in", "result", ":", "self", ".", "api_request", "(", "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
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
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
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
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", "(", "\"Either addr...
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
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
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
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
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
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
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
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", ")", ":", "if", "hasattr", "(", "self", ",", "'manager'", ")", "and", "self", ".", "manager", "is", "not", "None", ":", "artifacts", "=", "await", "self", ".", "manager", ".", "...
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
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
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", ".", "PI...
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
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
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
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", "if", "user", ".", "is_locked", "(", ")", ":", "raise", "x", ".", "AccountLocked", "(", "locked_until", "=", "user", ".", "locked_until", ")", "is_new"...
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
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", "user", "=", "current_user", "events", ".", "logout_event", ".", "send", "...
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
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
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
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
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
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
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
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", "subject", "=", "''", "subjects", "=", "self", ".", "email_subj...
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
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
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
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
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
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
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
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
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
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
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
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", "(", ")", ":", "replacer", "=", "random", ".", "choice", "(", "network", ".", "nodes", "(", "type", "=", "Source", ")", ")", "replacer", ".", "transmit", "...
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
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
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
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