repository_name
stringlengths
7
55
func_path_in_repository
stringlengths
4
223
func_name
stringlengths
1
134
whole_func_string
stringlengths
75
104k
language
stringclasses
1 value
func_code_string
stringlengths
75
104k
func_code_tokens
listlengths
19
28.4k
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
listlengths
1
1.97k
split_name
stringclasses
1 value
func_code_url
stringlengths
87
315
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/tag_mixin.py
TagManager.get_tags
def get_tags(self): """List all tags as Tag objects.""" res = self.get_request('/tag') return [Tag(cloud_manager=self, **tag) for tag in res['tags']['tag']]
python
def get_tags(self): """List all tags as Tag objects.""" res = self.get_request('/tag') return [Tag(cloud_manager=self, **tag) for tag in res['tags']['tag']]
[ "def", "get_tags", "(", "self", ")", ":", "res", "=", "self", ".", "get_request", "(", "'/tag'", ")", "return", "[", "Tag", "(", "cloud_manager", "=", "self", ",", "*", "*", "tag", ")", "for", "tag", "in", "res", "[", "'tags'", "]", "[", "'tag'", ...
List all tags as Tag objects.
[ "List", "all", "tags", "as", "Tag", "objects", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/tag_mixin.py#L18-L21
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/tag_mixin.py
TagManager.get_tag
def get_tag(self, name): """Return the tag as Tag object.""" res = self.get_request('/tag/' + name) return Tag(cloud_manager=self, **res['tag'])
python
def get_tag(self, name): """Return the tag as Tag object.""" res = self.get_request('/tag/' + name) return Tag(cloud_manager=self, **res['tag'])
[ "def", "get_tag", "(", "self", ",", "name", ")", ":", "res", "=", "self", ".", "get_request", "(", "'/tag/'", "+", "name", ")", "return", "Tag", "(", "cloud_manager", "=", "self", ",", "*", "*", "res", "[", "'tag'", "]", ")" ]
Return the tag as Tag object.
[ "Return", "the", "tag", "as", "Tag", "object", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/tag_mixin.py#L23-L26
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/tag_mixin.py
TagManager.create_tag
def create_tag(self, name, description=None, servers=[]): """ Create a new Tag. Only name is mandatory. Returns the created Tag object. """ servers = [str(server) for server in servers] body = {'tag': Tag(name, description, servers).to_dict()} res = self.request(...
python
def create_tag(self, name, description=None, servers=[]): """ Create a new Tag. Only name is mandatory. Returns the created Tag object. """ servers = [str(server) for server in servers] body = {'tag': Tag(name, description, servers).to_dict()} res = self.request(...
[ "def", "create_tag", "(", "self", ",", "name", ",", "description", "=", "None", ",", "servers", "=", "[", "]", ")", ":", "servers", "=", "[", "str", "(", "server", ")", "for", "server", "in", "servers", "]", "body", "=", "{", "'tag'", ":", "Tag", ...
Create a new Tag. Only name is mandatory. Returns the created Tag object.
[ "Create", "a", "new", "Tag", ".", "Only", "name", "is", "mandatory", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/tag_mixin.py#L28-L38
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/tag_mixin.py
TagManager._modify_tag
def _modify_tag(self, name, description, servers, new_name): """ PUT /tag/name. Returns a dict that can be used to create a Tag object. Private method used by the Tag class and TagManager.modify_tag. """ body = {'tag': Tag(new_name, description, servers).to_dict()} res =...
python
def _modify_tag(self, name, description, servers, new_name): """ PUT /tag/name. Returns a dict that can be used to create a Tag object. Private method used by the Tag class and TagManager.modify_tag. """ body = {'tag': Tag(new_name, description, servers).to_dict()} res =...
[ "def", "_modify_tag", "(", "self", ",", "name", ",", "description", ",", "servers", ",", "new_name", ")", ":", "body", "=", "{", "'tag'", ":", "Tag", "(", "new_name", ",", "description", ",", "servers", ")", ".", "to_dict", "(", ")", "}", "res", "=",...
PUT /tag/name. Returns a dict that can be used to create a Tag object. Private method used by the Tag class and TagManager.modify_tag.
[ "PUT", "/", "tag", "/", "name", ".", "Returns", "a", "dict", "that", "can", "be", "used", "to", "create", "a", "Tag", "object", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/tag_mixin.py#L40-L48
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/tag_mixin.py
TagManager.modify_tag
def modify_tag(self, name, description=None, servers=None, new_name=None): """ PUT /tag/name. Returns a new Tag object based on the API response. """ res = self._modify_tag(name, description, servers, new_name) return Tag(cloud_manager=self, **res['tag'])
python
def modify_tag(self, name, description=None, servers=None, new_name=None): """ PUT /tag/name. Returns a new Tag object based on the API response. """ res = self._modify_tag(name, description, servers, new_name) return Tag(cloud_manager=self, **res['tag'])
[ "def", "modify_tag", "(", "self", ",", "name", ",", "description", "=", "None", ",", "servers", "=", "None", ",", "new_name", "=", "None", ")", ":", "res", "=", "self", ".", "_modify_tag", "(", "name", ",", "description", ",", "servers", ",", "new_name...
PUT /tag/name. Returns a new Tag object based on the API response.
[ "PUT", "/", "tag", "/", "name", ".", "Returns", "a", "new", "Tag", "object", "based", "on", "the", "API", "response", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/tag_mixin.py#L50-L55
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/tag_mixin.py
TagManager.remove_tags
def remove_tags(self, server, tags): """ Remove tags from a server. - server: Server object or UUID string - tags: list of Tag objects or strings """ uuid = str(server) tags = [str(tag) for tag in tags] url = '/server/{0}/untag/{1}'.format(uuid, ','.join...
python
def remove_tags(self, server, tags): """ Remove tags from a server. - server: Server object or UUID string - tags: list of Tag objects or strings """ uuid = str(server) tags = [str(tag) for tag in tags] url = '/server/{0}/untag/{1}'.format(uuid, ','.join...
[ "def", "remove_tags", "(", "self", ",", "server", ",", "tags", ")", ":", "uuid", "=", "str", "(", "server", ")", "tags", "=", "[", "str", "(", "tag", ")", "for", "tag", "in", "tags", "]", "url", "=", "'/server/{0}/untag/{1}'", ".", "format", "(", "...
Remove tags from a server. - server: Server object or UUID string - tags: list of Tag objects or strings
[ "Remove", "tags", "from", "a", "server", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/tag_mixin.py#L70-L81
UpCloudLtd/upcloud-python-api
upcloud_api/utils.py
assignIfExists
def assignIfExists(opts, default=None, **kwargs): """ Helper for assigning object attributes from API responses. """ for opt in opts: if(opt in kwargs): return kwargs[opt] return default
python
def assignIfExists(opts, default=None, **kwargs): """ Helper for assigning object attributes from API responses. """ for opt in opts: if(opt in kwargs): return kwargs[opt] return default
[ "def", "assignIfExists", "(", "opts", ",", "default", "=", "None", ",", "*", "*", "kwargs", ")", ":", "for", "opt", "in", "opts", ":", "if", "(", "opt", "in", "kwargs", ")", ":", "return", "kwargs", "[", "opt", "]", "return", "default" ]
Helper for assigning object attributes from API responses.
[ "Helper", "for", "assigning", "object", "attributes", "from", "API", "responses", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/utils.py#L7-L14
UpCloudLtd/upcloud-python-api
upcloud_api/utils.py
try_it_n_times
def try_it_n_times(operation, expected_error_codes, custom_error='operation failed', n=10): """ Try a given operation (API call) n times. Raises if the API call fails with an error_code that is not expected. Raises if the API call has not succeeded within n attempts. Waits 3 seconds betwee each att...
python
def try_it_n_times(operation, expected_error_codes, custom_error='operation failed', n=10): """ Try a given operation (API call) n times. Raises if the API call fails with an error_code that is not expected. Raises if the API call has not succeeded within n attempts. Waits 3 seconds betwee each att...
[ "def", "try_it_n_times", "(", "operation", ",", "expected_error_codes", ",", "custom_error", "=", "'operation failed'", ",", "n", "=", "10", ")", ":", "for", "i", "in", "itertools", ".", "count", "(", ")", ":", "try", ":", "operation", "(", ")", "break", ...
Try a given operation (API call) n times. Raises if the API call fails with an error_code that is not expected. Raises if the API call has not succeeded within n attempts. Waits 3 seconds betwee each attempt.
[ "Try", "a", "given", "operation", "(", "API", "call", ")", "n", "times", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/utils.py#L17-L34
casebeer/python-hkdf
hkdf.py
hkdf_extract
def hkdf_extract(salt, input_key_material, hash=hashlib.sha512): ''' Extract a pseudorandom key suitable for use with hkdf_expand from the input_key_material and a salt using HMAC with the provided hash (default SHA-512). salt should be a random, application-specific byte string. If salt is None or the empty str...
python
def hkdf_extract(salt, input_key_material, hash=hashlib.sha512): ''' Extract a pseudorandom key suitable for use with hkdf_expand from the input_key_material and a salt using HMAC with the provided hash (default SHA-512). salt should be a random, application-specific byte string. If salt is None or the empty str...
[ "def", "hkdf_extract", "(", "salt", ",", "input_key_material", ",", "hash", "=", "hashlib", ".", "sha512", ")", ":", "hash_len", "=", "hash", "(", ")", ".", "digest_size", "if", "salt", "==", "None", "or", "len", "(", "salt", ")", "==", "0", ":", "sa...
Extract a pseudorandom key suitable for use with hkdf_expand from the input_key_material and a salt using HMAC with the provided hash (default SHA-512). salt should be a random, application-specific byte string. If salt is None or the empty string, an all-zeros string of the same length as the hash's block size w...
[ "Extract", "a", "pseudorandom", "key", "suitable", "for", "use", "with", "hkdf_expand", "from", "the", "input_key_material", "and", "a", "salt", "using", "HMAC", "with", "the", "provided", "hash", "(", "default", "SHA", "-", "512", ")", "." ]
train
https://github.com/casebeer/python-hkdf/blob/cc3c9dbf0a271b27a7ac5cd04cc1485bbc3b4307/hkdf.py#L10-L25
casebeer/python-hkdf
hkdf.py
hkdf_expand
def hkdf_expand(pseudo_random_key, info=b"", length=32, hash=hashlib.sha512): ''' Expand `pseudo_random_key` and `info` into a key of length `bytes` using HKDF's expand function based on HMAC with the provided hash (default SHA-512). See the HKDF draft RFC and paper for usage notes. ''' hash_len = hash().digest_s...
python
def hkdf_expand(pseudo_random_key, info=b"", length=32, hash=hashlib.sha512): ''' Expand `pseudo_random_key` and `info` into a key of length `bytes` using HKDF's expand function based on HMAC with the provided hash (default SHA-512). See the HKDF draft RFC and paper for usage notes. ''' hash_len = hash().digest_s...
[ "def", "hkdf_expand", "(", "pseudo_random_key", ",", "info", "=", "b\"\"", ",", "length", "=", "32", ",", "hash", "=", "hashlib", ".", "sha512", ")", ":", "hash_len", "=", "hash", "(", ")", ".", "digest_size", "length", "=", "int", "(", "length", ")", ...
Expand `pseudo_random_key` and `info` into a key of length `bytes` using HKDF's expand function based on HMAC with the provided hash (default SHA-512). See the HKDF draft RFC and paper for usage notes.
[ "Expand", "pseudo_random_key", "and", "info", "into", "a", "key", "of", "length", "bytes", "using", "HKDF", "s", "expand", "function", "based", "on", "HMAC", "with", "the", "provided", "hash", "(", "default", "SHA", "-", "512", ")", ".", "See", "the", "H...
train
https://github.com/casebeer/python-hkdf/blob/cc3c9dbf0a271b27a7ac5cd04cc1485bbc3b4307/hkdf.py#L27-L45
casebeer/python-hkdf
hkdf.py
Hkdf.expand
def expand(self, info=b"", length=32): ''' Generate output key material based on an `info` value Arguments: - info - context to generate the OKM - length - length in bytes of the key to generate See the HKDF draft RFC for guidance. ''' return hkdf_expand(self._prk, info, length, self._hash)
python
def expand(self, info=b"", length=32): ''' Generate output key material based on an `info` value Arguments: - info - context to generate the OKM - length - length in bytes of the key to generate See the HKDF draft RFC for guidance. ''' return hkdf_expand(self._prk, info, length, self._hash)
[ "def", "expand", "(", "self", ",", "info", "=", "b\"\"", ",", "length", "=", "32", ")", ":", "return", "hkdf_expand", "(", "self", ".", "_prk", ",", "info", ",", "length", ",", "self", ".", "_hash", ")" ]
Generate output key material based on an `info` value Arguments: - info - context to generate the OKM - length - length in bytes of the key to generate See the HKDF draft RFC for guidance.
[ "Generate", "output", "key", "material", "based", "on", "an", "info", "value" ]
train
https://github.com/casebeer/python-hkdf/blob/cc3c9dbf0a271b27a7ac5cd04cc1485bbc3b4307/hkdf.py#L61-L71
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
login_user_block
def login_user_block(username, ssh_keys, create_password=True): """ Helper function for creating Server.login_user blocks. (see: https://www.upcloud.com/api/8-servers/#create-server) """ block = { 'create_password': 'yes' if create_password is True else 'no', 'ssh_keys': { ...
python
def login_user_block(username, ssh_keys, create_password=True): """ Helper function for creating Server.login_user blocks. (see: https://www.upcloud.com/api/8-servers/#create-server) """ block = { 'create_password': 'yes' if create_password is True else 'no', 'ssh_keys': { ...
[ "def", "login_user_block", "(", "username", ",", "ssh_keys", ",", "create_password", "=", "True", ")", ":", "block", "=", "{", "'create_password'", ":", "'yes'", "if", "create_password", "is", "True", "else", "'no'", ",", "'ssh_keys'", ":", "{", "'ssh_key'", ...
Helper function for creating Server.login_user blocks. (see: https://www.upcloud.com/api/8-servers/#create-server)
[ "Helper", "function", "for", "creating", "Server", ".", "login_user", "blocks", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L10-L26
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server._reset
def _reset(self, server, **kwargs): """ Reset the server object with new values given as params. - server: a dict representing the server. e.g the API response. - kwargs: any meta fields such as cloud_manager and populated. Note: storage_devices and ip_addresses may be given in...
python
def _reset(self, server, **kwargs): """ Reset the server object with new values given as params. - server: a dict representing the server. e.g the API response. - kwargs: any meta fields such as cloud_manager and populated. Note: storage_devices and ip_addresses may be given in...
[ "def", "_reset", "(", "self", ",", "server", ",", "*", "*", "kwargs", ")", ":", "if", "server", ":", "# handle storage, ip_address dicts and tags if they exist", "Server", ".", "_handle_server_subobjs", "(", "server", ",", "kwargs", ".", "get", "(", "'cloud_manage...
Reset the server object with new values given as params. - server: a dict representing the server. e.g the API response. - kwargs: any meta fields such as cloud_manager and populated. Note: storage_devices and ip_addresses may be given in server as dicts or in kwargs as lists containin...
[ "Reset", "the", "server", "object", "with", "new", "values", "given", "as", "params", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L74-L92
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.populate
def populate(self): """ Sync changes from the API to the local object. Note: syncs ip_addresses and storage_devices too (/server/uuid endpoint) """ server, IPAddresses, storages = self.cloud_manager.get_server_data(self.uuid) self._reset( server, ...
python
def populate(self): """ Sync changes from the API to the local object. Note: syncs ip_addresses and storage_devices too (/server/uuid endpoint) """ server, IPAddresses, storages = self.cloud_manager.get_server_data(self.uuid) self._reset( server, ...
[ "def", "populate", "(", "self", ")", ":", "server", ",", "IPAddresses", ",", "storages", "=", "self", ".", "cloud_manager", ".", "get_server_data", "(", "self", ".", "uuid", ")", "self", ".", "_reset", "(", "server", ",", "ip_addresses", "=", "IPAddresses"...
Sync changes from the API to the local object. Note: syncs ip_addresses and storage_devices too (/server/uuid endpoint)
[ "Sync", "changes", "from", "the", "API", "to", "the", "local", "object", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L94-L107
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.save
def save(self): """ Sync local changes in server's attributes to the API. Note: DOES NOT sync IPAddresses and storage_devices, use add_ip, add_storage, remove_ip, remove_storage instead. """ # dict comprehension that also works with 2.6 # http://stackoverflow.com...
python
def save(self): """ Sync local changes in server's attributes to the API. Note: DOES NOT sync IPAddresses and storage_devices, use add_ip, add_storage, remove_ip, remove_storage instead. """ # dict comprehension that also works with 2.6 # http://stackoverflow.com...
[ "def", "save", "(", "self", ")", ":", "# dict comprehension that also works with 2.6", "# http://stackoverflow.com/questions/21069668/alternative-to-dict-comprehension-prior-to-python-2-7", "kwargs", "=", "dict", "(", "(", "field", ",", "getattr", "(", "self", ",", "field", "...
Sync local changes in server's attributes to the API. Note: DOES NOT sync IPAddresses and storage_devices, use add_ip, add_storage, remove_ip, remove_storage instead.
[ "Sync", "local", "changes", "in", "server", "s", "attributes", "to", "the", "API", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L116-L132
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.shutdown
def shutdown(self, hard=False, timeout=30): """ Shutdown/stop the server. By default, issue a soft shutdown with a timeout of 30s. After the a timeout a hard shutdown is performed if the server has not stopped. Note: API responds immediately (unlike in start), with state: started. ...
python
def shutdown(self, hard=False, timeout=30): """ Shutdown/stop the server. By default, issue a soft shutdown with a timeout of 30s. After the a timeout a hard shutdown is performed if the server has not stopped. Note: API responds immediately (unlike in start), with state: started. ...
[ "def", "shutdown", "(", "self", ",", "hard", "=", "False", ",", "timeout", "=", "30", ")", ":", "body", "=", "dict", "(", ")", "body", "[", "'stop_server'", "]", "=", "{", "'stop_type'", ":", "'hard'", "if", "hard", "else", "'soft'", ",", "'timeout'"...
Shutdown/stop the server. By default, issue a soft shutdown with a timeout of 30s. After the a timeout a hard shutdown is performed if the server has not stopped. Note: API responds immediately (unlike in start), with state: started. This client will, however, set state as 'maintenance' to sig...
[ "Shutdown", "/", "stop", "the", "server", ".", "By", "default", "issue", "a", "soft", "shutdown", "with", "a", "timeout", "of", "30s", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L137-L155
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.start
def start(self, timeout=120): """ Start the server. Note: slow and blocking request. The API waits for confirmation from UpCloud's IaaS backend before responding. """ path = '/server/{0}/start'.format(self.uuid) self.cloud_manager.post_request(path, timeout=timeout) ...
python
def start(self, timeout=120): """ Start the server. Note: slow and blocking request. The API waits for confirmation from UpCloud's IaaS backend before responding. """ path = '/server/{0}/start'.format(self.uuid) self.cloud_manager.post_request(path, timeout=timeout) ...
[ "def", "start", "(", "self", ",", "timeout", "=", "120", ")", ":", "path", "=", "'/server/{0}/start'", ".", "format", "(", "self", ".", "uuid", ")", "self", ".", "cloud_manager", ".", "post_request", "(", "path", ",", "timeout", "=", "timeout", ")", "o...
Start the server. Note: slow and blocking request. The API waits for confirmation from UpCloud's IaaS backend before responding.
[ "Start", "the", "server", ".", "Note", ":", "slow", "and", "blocking", "request", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L163-L171
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.restart
def restart(self, hard=False, timeout=30, force=True): """ Restart the server. By default, issue a soft restart with a timeout of 30s and a hard restart after the timeout. After the a timeout a hard restart is performed if the server has not stopped. Note: API responds immediat...
python
def restart(self, hard=False, timeout=30, force=True): """ Restart the server. By default, issue a soft restart with a timeout of 30s and a hard restart after the timeout. After the a timeout a hard restart is performed if the server has not stopped. Note: API responds immediat...
[ "def", "restart", "(", "self", ",", "hard", "=", "False", ",", "timeout", "=", "30", ",", "force", "=", "True", ")", ":", "body", "=", "dict", "(", ")", "body", "[", "'restart_server'", "]", "=", "{", "'stop_type'", ":", "'hard'", "if", "hard", "el...
Restart the server. By default, issue a soft restart with a timeout of 30s and a hard restart after the timeout. After the a timeout a hard restart is performed if the server has not stopped. Note: API responds immediately (unlike in start), with state: started. This client will, howev...
[ "Restart", "the", "server", ".", "By", "default", "issue", "a", "soft", "restart", "with", "a", "timeout", "of", "30s", "and", "a", "hard", "restart", "after", "the", "timeout", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L173-L193
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.add_ip
def add_ip(self, family='IPv4'): """ Allocate a new (random) IP-address to the Server. """ IP = self.cloud_manager.attach_ip(self.uuid, family) self.ip_addresses.append(IP) return IP
python
def add_ip(self, family='IPv4'): """ Allocate a new (random) IP-address to the Server. """ IP = self.cloud_manager.attach_ip(self.uuid, family) self.ip_addresses.append(IP) return IP
[ "def", "add_ip", "(", "self", ",", "family", "=", "'IPv4'", ")", ":", "IP", "=", "self", ".", "cloud_manager", ".", "attach_ip", "(", "self", ".", "uuid", ",", "family", ")", "self", ".", "ip_addresses", ".", "append", "(", "IP", ")", "return", "IP" ...
Allocate a new (random) IP-address to the Server.
[ "Allocate", "a", "new", "(", "random", ")", "IP", "-", "address", "to", "the", "Server", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L195-L201
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.remove_ip
def remove_ip(self, IPAddress): """ Release the specified IP-address from the server. """ self.cloud_manager.release_ip(IPAddress.address) self.ip_addresses.remove(IPAddress)
python
def remove_ip(self, IPAddress): """ Release the specified IP-address from the server. """ self.cloud_manager.release_ip(IPAddress.address) self.ip_addresses.remove(IPAddress)
[ "def", "remove_ip", "(", "self", ",", "IPAddress", ")", ":", "self", ".", "cloud_manager", ".", "release_ip", "(", "IPAddress", ".", "address", ")", "self", ".", "ip_addresses", ".", "remove", "(", "IPAddress", ")" ]
Release the specified IP-address from the server.
[ "Release", "the", "specified", "IP", "-", "address", "from", "the", "server", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L203-L208
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.add_storage
def add_storage(self, storage=None, type='disk', address=None): """ Attach the given storage to the Server. Default address is next available. """ self.cloud_manager.attach_storage(server=self.uuid, storage=storage.uuid, ...
python
def add_storage(self, storage=None, type='disk', address=None): """ Attach the given storage to the Server. Default address is next available. """ self.cloud_manager.attach_storage(server=self.uuid, storage=storage.uuid, ...
[ "def", "add_storage", "(", "self", ",", "storage", "=", "None", ",", "type", "=", "'disk'", ",", "address", "=", "None", ")", ":", "self", ".", "cloud_manager", ".", "attach_storage", "(", "server", "=", "self", ".", "uuid", ",", "storage", "=", "stora...
Attach the given storage to the Server. Default address is next available.
[ "Attach", "the", "given", "storage", "to", "the", "Server", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L210-L222
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.remove_storage
def remove_storage(self, storage): """ Remove Storage from a Server. The Storage must be a reference to an object in Server.storage_devices or the method will throw and Exception. A Storage from get_storage(uuid) will not work as it is missing the 'address' property. ""...
python
def remove_storage(self, storage): """ Remove Storage from a Server. The Storage must be a reference to an object in Server.storage_devices or the method will throw and Exception. A Storage from get_storage(uuid) will not work as it is missing the 'address' property. ""...
[ "def", "remove_storage", "(", "self", ",", "storage", ")", ":", "if", "not", "hasattr", "(", "storage", ",", "'address'", ")", ":", "raise", "Exception", "(", "(", "'Storage does not have an address. '", "'Access the Storage via Server.storage_devices '", "'so they incl...
Remove Storage from a Server. The Storage must be a reference to an object in Server.storage_devices or the method will throw and Exception. A Storage from get_storage(uuid) will not work as it is missing the 'address' property.
[ "Remove", "Storage", "from", "a", "Server", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L224-L242
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.add_tags
def add_tags(self, tags): """ Add tags to a server. Accepts tags as strings or Tag objects. """ if self.cloud_manager.assign_tags(self.uuid, tags): tags = self.tags + [str(tag) for tag in tags] object.__setattr__(self, 'tags', tags)
python
def add_tags(self, tags): """ Add tags to a server. Accepts tags as strings or Tag objects. """ if self.cloud_manager.assign_tags(self.uuid, tags): tags = self.tags + [str(tag) for tag in tags] object.__setattr__(self, 'tags', tags)
[ "def", "add_tags", "(", "self", ",", "tags", ")", ":", "if", "self", ".", "cloud_manager", ".", "assign_tags", "(", "self", ".", "uuid", ",", "tags", ")", ":", "tags", "=", "self", ".", "tags", "+", "[", "str", "(", "tag", ")", "for", "tag", "in"...
Add tags to a server. Accepts tags as strings or Tag objects.
[ "Add", "tags", "to", "a", "server", ".", "Accepts", "tags", "as", "strings", "or", "Tag", "objects", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L264-L270
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.remove_tags
def remove_tags(self, tags): """ Add tags to a server. Accepts tags as strings or Tag objects. """ if self.cloud_manager.remove_tags(self, tags): new_tags = [tag for tag in self.tags if tag not in tags] object.__setattr__(self, 'tags', new_tags)
python
def remove_tags(self, tags): """ Add tags to a server. Accepts tags as strings or Tag objects. """ if self.cloud_manager.remove_tags(self, tags): new_tags = [tag for tag in self.tags if tag not in tags] object.__setattr__(self, 'tags', new_tags)
[ "def", "remove_tags", "(", "self", ",", "tags", ")", ":", "if", "self", ".", "cloud_manager", ".", "remove_tags", "(", "self", ",", "tags", ")", ":", "new_tags", "=", "[", "tag", "for", "tag", "in", "self", ".", "tags", "if", "tag", "not", "in", "t...
Add tags to a server. Accepts tags as strings or Tag objects.
[ "Add", "tags", "to", "a", "server", ".", "Accepts", "tags", "as", "strings", "or", "Tag", "objects", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L272-L278
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.configure_firewall
def configure_firewall(self, FirewallRules): """ Helper function for automatically adding several FirewallRules in series. """ firewall_rule_bodies = [ FirewallRule.to_dict() for FirewallRule in FirewallRules ] return self.cloud_manager.configure_f...
python
def configure_firewall(self, FirewallRules): """ Helper function for automatically adding several FirewallRules in series. """ firewall_rule_bodies = [ FirewallRule.to_dict() for FirewallRule in FirewallRules ] return self.cloud_manager.configure_f...
[ "def", "configure_firewall", "(", "self", ",", "FirewallRules", ")", ":", "firewall_rule_bodies", "=", "[", "FirewallRule", ".", "to_dict", "(", ")", "for", "FirewallRule", "in", "FirewallRules", "]", "return", "self", ".", "cloud_manager", ".", "configure_firewal...
Helper function for automatically adding several FirewallRules in series.
[ "Helper", "function", "for", "automatically", "adding", "several", "FirewallRules", "in", "series", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L285-L293
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.prepare_post_body
def prepare_post_body(self): """ Prepare a JSON serializable dict from a Server instance with nested. Storage instances. """ body = dict() # mandatory body['server'] = { 'hostname': self.hostname, 'zone': self.zone, 'title': se...
python
def prepare_post_body(self): """ Prepare a JSON serializable dict from a Server instance with nested. Storage instances. """ body = dict() # mandatory body['server'] = { 'hostname': self.hostname, 'zone': self.zone, 'title': se...
[ "def", "prepare_post_body", "(", "self", ")", ":", "body", "=", "dict", "(", ")", "# mandatory", "body", "[", "'server'", "]", "=", "{", "'hostname'", ":", "self", ".", "hostname", ",", "'zone'", ":", "self", ".", "zone", ",", "'title'", ":", "self", ...
Prepare a JSON serializable dict from a Server instance with nested. Storage instances.
[ "Prepare", "a", "JSON", "serializable", "dict", "from", "a", "Server", "instance", "with", "nested", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L295-L368
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.to_dict
def to_dict(self): """ Prepare a JSON serializable dict for read-only purposes. Includes storages and IP-addresses. Use prepare_post_body for POST and .save() for PUT. """ fields = dict(vars(self).items()) if self.populated: fields['ip_addresses'] = ...
python
def to_dict(self): """ Prepare a JSON serializable dict for read-only purposes. Includes storages and IP-addresses. Use prepare_post_body for POST and .save() for PUT. """ fields = dict(vars(self).items()) if self.populated: fields['ip_addresses'] = ...
[ "def", "to_dict", "(", "self", ")", ":", "fields", "=", "dict", "(", "vars", "(", "self", ")", ".", "items", "(", ")", ")", "if", "self", ".", "populated", ":", "fields", "[", "'ip_addresses'", "]", "=", "[", "]", "fields", "[", "'storage_devices'", ...
Prepare a JSON serializable dict for read-only purposes. Includes storages and IP-addresses. Use prepare_post_body for POST and .save() for PUT.
[ "Prepare", "a", "JSON", "serializable", "dict", "for", "read", "-", "only", "purposes", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L370-L400
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.get_ip
def get_ip(self, access='public', addr_family=None, strict=None): """ Return the server's IP address. Params: - addr_family: IPv4, IPv6 or None. None prefers IPv4 but will return IPv6 if IPv4 addr was not available. - access: 'public' or 'private' ...
python
def get_ip(self, access='public', addr_family=None, strict=None): """ Return the server's IP address. Params: - addr_family: IPv4, IPv6 or None. None prefers IPv4 but will return IPv6 if IPv4 addr was not available. - access: 'public' or 'private' ...
[ "def", "get_ip", "(", "self", ",", "access", "=", "'public'", ",", "addr_family", "=", "None", ",", "strict", "=", "None", ")", ":", "if", "addr_family", "not", "in", "[", "'IPv4'", ",", "'IPv6'", ",", "None", "]", ":", "raise", "Exception", "(", "\"...
Return the server's IP address. Params: - addr_family: IPv4, IPv6 or None. None prefers IPv4 but will return IPv6 if IPv4 addr was not available. - access: 'public' or 'private'
[ "Return", "the", "server", "s", "IP", "address", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L402-L433
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.get_public_ip
def get_public_ip(self, addr_family=None, *args, **kwargs): """Alias for get_ip('public')""" return self.get_ip('public', addr_family, *args, **kwargs)
python
def get_public_ip(self, addr_family=None, *args, **kwargs): """Alias for get_ip('public')""" return self.get_ip('public', addr_family, *args, **kwargs)
[ "def", "get_public_ip", "(", "self", ",", "addr_family", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "get_ip", "(", "'public'", ",", "addr_family", ",", "*", "args", ",", "*", "*", "kwargs", ")" ]
Alias for get_ip('public')
[ "Alias", "for", "get_ip", "(", "public", ")" ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L435-L437
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.get_private_ip
def get_private_ip(self, addr_family=None, *args, **kwargs): """Alias for get_ip('private')""" return self.get_ip('private', addr_family, *args, **kwargs)
python
def get_private_ip(self, addr_family=None, *args, **kwargs): """Alias for get_ip('private')""" return self.get_ip('private', addr_family, *args, **kwargs)
[ "def", "get_private_ip", "(", "self", ",", "addr_family", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "get_ip", "(", "'private'", ",", "addr_family", ",", "*", "args", ",", "*", "*", "kwargs", ")" ]
Alias for get_ip('private')
[ "Alias", "for", "get_ip", "(", "private", ")" ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L439-L441
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server._wait_for_state_change
def _wait_for_state_change(self, target_states, update_interval=10): """ Blocking wait until target_state reached. update_interval is in seconds. Warning: state change must begin before calling this method. """ while self.state not in target_states: if self.state == ...
python
def _wait_for_state_change(self, target_states, update_interval=10): """ Blocking wait until target_state reached. update_interval is in seconds. Warning: state change must begin before calling this method. """ while self.state not in target_states: if self.state == ...
[ "def", "_wait_for_state_change", "(", "self", ",", "target_states", ",", "update_interval", "=", "10", ")", ":", "while", "self", ".", "state", "not", "in", "target_states", ":", "if", "self", ".", "state", "==", "'error'", ":", "raise", "Exception", "(", ...
Blocking wait until target_state reached. update_interval is in seconds. Warning: state change must begin before calling this method.
[ "Blocking", "wait", "until", "target_state", "reached", ".", "update_interval", "is", "in", "seconds", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L443-L455
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.ensure_started
def ensure_started(self): """ Start a server and waits (blocking wait) until it is fully started. """ # server is either starting or stopping (or error) if self.state in ['maintenance', 'error']: self._wait_for_state_change(['stopped', 'started']) if self.sta...
python
def ensure_started(self): """ Start a server and waits (blocking wait) until it is fully started. """ # server is either starting or stopping (or error) if self.state in ['maintenance', 'error']: self._wait_for_state_change(['stopped', 'started']) if self.sta...
[ "def", "ensure_started", "(", "self", ")", ":", "# server is either starting or stopping (or error)", "if", "self", ".", "state", "in", "[", "'maintenance'", ",", "'error'", "]", ":", "self", ".", "_wait_for_state_change", "(", "[", "'stopped'", ",", "'started'", ...
Start a server and waits (blocking wait) until it is fully started.
[ "Start", "a", "server", "and", "waits", "(", "blocking", "wait", ")", "until", "it", "is", "fully", "started", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L457-L473
UpCloudLtd/upcloud-python-api
upcloud_api/server.py
Server.stop_and_destroy
def stop_and_destroy(self, sync=True): """ Destroy a server and its storages. Stops the server before destroying. Syncs the server state from the API, use sync=False to disable. """ def _self_destruct(): """destroy the server and all storages attached to it.""" ...
python
def stop_and_destroy(self, sync=True): """ Destroy a server and its storages. Stops the server before destroying. Syncs the server state from the API, use sync=False to disable. """ def _self_destruct(): """destroy the server and all storages attached to it.""" ...
[ "def", "stop_and_destroy", "(", "self", ",", "sync", "=", "True", ")", ":", "def", "_self_destruct", "(", ")", ":", "\"\"\"destroy the server and all storages attached to it.\"\"\"", "# try_it_n_times util is used as a convenience because", "# Servers and Storages can fluctuate bet...
Destroy a server and its storages. Stops the server before destroying. Syncs the server state from the API, use sync=False to disable.
[ "Destroy", "a", "server", "and", "its", "storages", ".", "Stops", "the", "server", "before", "destroying", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/server.py#L475-L517
okfn/ofs
ofs/local/storedjson.py
PersistentState.revert
def revert(self): """Revert the state to the version stored on disc.""" if self.filepath: if path.isfile(self.filepath): serialised_file = open(self.filepath, "r") try: self.state = json.load(serialised_file) except ValueErr...
python
def revert(self): """Revert the state to the version stored on disc.""" if self.filepath: if path.isfile(self.filepath): serialised_file = open(self.filepath, "r") try: self.state = json.load(serialised_file) except ValueErr...
[ "def", "revert", "(", "self", ")", ":", "if", "self", ".", "filepath", ":", "if", "path", ".", "isfile", "(", "self", ".", "filepath", ")", ":", "serialised_file", "=", "open", "(", "self", ".", "filepath", ",", "\"r\"", ")", "try", ":", "self", "....
Revert the state to the version stored on disc.
[ "Revert", "the", "state", "to", "the", "version", "stored", "on", "disc", "." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/storedjson.py#L33-L49
okfn/ofs
ofs/local/storedjson.py
PersistentState.sync
def sync(self): """Synchronise and update the stored state to the in-memory state.""" if self.filepath: serialised_file = open(self.filepath, "w") json.dump(self.state, serialised_file) serialised_file.close() else: print("Filepath to the persisten...
python
def sync(self): """Synchronise and update the stored state to the in-memory state.""" if self.filepath: serialised_file = open(self.filepath, "w") json.dump(self.state, serialised_file) serialised_file.close() else: print("Filepath to the persisten...
[ "def", "sync", "(", "self", ")", ":", "if", "self", ".", "filepath", ":", "serialised_file", "=", "open", "(", "self", ".", "filepath", ",", "\"w\"", ")", "json", ".", "dump", "(", "self", ".", "state", ",", "serialised_file", ")", "serialised_file", "...
Synchronise and update the stored state to the in-memory state.
[ "Synchronise", "and", "update", "the", "stored", "state", "to", "the", "in", "-", "memory", "state", "." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/storedjson.py#L51-L58
UpCloudLtd/upcloud-python-api
upcloud_api/upcloud_resource.py
UpCloudResource._reset
def _reset(self, **kwargs): """ Reset after repopulating from API (or when initializing). """ # set object attributes from params for key in kwargs: setattr(self, key, kwargs[key]) # set defaults (if need be) where the default is not None for attr in ...
python
def _reset(self, **kwargs): """ Reset after repopulating from API (or when initializing). """ # set object attributes from params for key in kwargs: setattr(self, key, kwargs[key]) # set defaults (if need be) where the default is not None for attr in ...
[ "def", "_reset", "(", "self", ",", "*", "*", "kwargs", ")", ":", "# set object attributes from params", "for", "key", "in", "kwargs", ":", "setattr", "(", "self", ",", "key", ",", "kwargs", "[", "key", "]", ")", "# set defaults (if need be) where the default is ...
Reset after repopulating from API (or when initializing).
[ "Reset", "after", "repopulating", "from", "API", "(", "or", "when", "initializing", ")", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/upcloud_resource.py#L27-L38
UpCloudLtd/upcloud-python-api
upcloud_api/upcloud_resource.py
UpCloudResource.to_dict
def to_dict(self): """ Return a dict that can be serialised to JSON and sent to UpCloud's API. """ return dict( (attr, getattr(self, attr)) for attr in self.ATTRIBUTES if hasattr(self, attr) )
python
def to_dict(self): """ Return a dict that can be serialised to JSON and sent to UpCloud's API. """ return dict( (attr, getattr(self, attr)) for attr in self.ATTRIBUTES if hasattr(self, attr) )
[ "def", "to_dict", "(", "self", ")", ":", "return", "dict", "(", "(", "attr", ",", "getattr", "(", "self", ",", "attr", ")", ")", "for", "attr", "in", "self", ".", "ATTRIBUTES", "if", "hasattr", "(", "self", ",", "attr", ")", ")" ]
Return a dict that can be serialised to JSON and sent to UpCloud's API.
[ "Return", "a", "dict", "that", "can", "be", "serialised", "to", "JSON", "and", "sent", "to", "UpCloud", "s", "API", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/upcloud_resource.py#L47-L55
okfn/ofs
ofs/remote/botostore.py
BotoOFS._require_bucket
def _require_bucket(self, bucket_name): """ Also try to create the bucket. """ if not self.exists(bucket_name) and not self.claim_bucket(bucket_name): raise OFSException("Invalid bucket: %s" % bucket_name) return self._get_bucket(bucket_name)
python
def _require_bucket(self, bucket_name): """ Also try to create the bucket. """ if not self.exists(bucket_name) and not self.claim_bucket(bucket_name): raise OFSException("Invalid bucket: %s" % bucket_name) return self._get_bucket(bucket_name)
[ "def", "_require_bucket", "(", "self", ",", "bucket_name", ")", ":", "if", "not", "self", ".", "exists", "(", "bucket_name", ")", "and", "not", "self", ".", "claim_bucket", "(", "bucket_name", ")", ":", "raise", "OFSException", "(", "\"Invalid bucket: %s\"", ...
Also try to create the bucket.
[ "Also", "try", "to", "create", "the", "bucket", "." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/remote/botostore.py#L42-L46
okfn/ofs
ofs/remote/botostore.py
BotoOFS.del_stream
def del_stream(self, bucket, label): """ Will fail if the bucket or label don't exist """ bucket = self._require_bucket(bucket) key = self._require_key(bucket, label) key.delete()
python
def del_stream(self, bucket, label): """ Will fail if the bucket or label don't exist """ bucket = self._require_bucket(bucket) key = self._require_key(bucket, label) key.delete()
[ "def", "del_stream", "(", "self", ",", "bucket", ",", "label", ")", ":", "bucket", "=", "self", ".", "_require_bucket", "(", "bucket", ")", "key", "=", "self", ".", "_require_key", "(", "bucket", ",", "label", ")", "key", ".", "delete", "(", ")" ]
Will fail if the bucket or label don't exist
[ "Will", "fail", "if", "the", "bucket", "or", "label", "don", "t", "exist" ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/remote/botostore.py#L119-L123
okfn/ofs
ofs/remote/botostore.py
BotoOFS.authenticate_request
def authenticate_request(self, method, bucket='', key='', headers=None): '''Authenticate a HTTP request by filling in Authorization field header. :param method: HTTP method (e.g. GET, PUT, POST) :param bucket: name of the bucket. :param key: name of key within bucket. :param hea...
python
def authenticate_request(self, method, bucket='', key='', headers=None): '''Authenticate a HTTP request by filling in Authorization field header. :param method: HTTP method (e.g. GET, PUT, POST) :param bucket: name of the bucket. :param key: name of key within bucket. :param hea...
[ "def", "authenticate_request", "(", "self", ",", "method", ",", "bucket", "=", "''", ",", "key", "=", "''", ",", "headers", "=", "None", ")", ":", "# following is extracted from S3Connection.make_request and the method", "# it calls: AWSAuthConnection.make_request", "path...
Authenticate a HTTP request by filling in Authorization field header. :param method: HTTP method (e.g. GET, PUT, POST) :param bucket: name of the bucket. :param key: name of key within bucket. :param headers: dictionary of additional HTTP headers. :return: boto.connection.HTTPR...
[ "Authenticate", "a", "HTTP", "request", "by", "filling", "in", "Authorization", "field", "header", "." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/remote/botostore.py#L172-L197
ckan/deadoralive
deadoralive/deadoralive.py
get_resources_to_check
def get_resources_to_check(client_site_url, apikey): """Return a list of resource IDs to check for broken links. Calls the client site's API to get a list of resource IDs. :raises CouldNotGetResourceIDsError: if getting the resource IDs fails for any reason """ url = client_site_url + u"d...
python
def get_resources_to_check(client_site_url, apikey): """Return a list of resource IDs to check for broken links. Calls the client site's API to get a list of resource IDs. :raises CouldNotGetResourceIDsError: if getting the resource IDs fails for any reason """ url = client_site_url + u"d...
[ "def", "get_resources_to_check", "(", "client_site_url", ",", "apikey", ")", ":", "url", "=", "client_site_url", "+", "u\"deadoralive/get_resources_to_check\"", "response", "=", "requests", ".", "get", "(", "url", ",", "headers", "=", "dict", "(", "Authorization", ...
Return a list of resource IDs to check for broken links. Calls the client site's API to get a list of resource IDs. :raises CouldNotGetResourceIDsError: if getting the resource IDs fails for any reason
[ "Return", "a", "list", "of", "resource", "IDs", "to", "check", "for", "broken", "links", "." ]
train
https://github.com/ckan/deadoralive/blob/82eed6c73e17b9884476311a7a8fae9d2b379600/deadoralive/deadoralive.py#L26-L41
ckan/deadoralive
deadoralive/deadoralive.py
get_url_for_id
def get_url_for_id(client_site_url, apikey, resource_id): """Return the URL for the given resource ID. Contacts the client site's API to get the URL for the ID and returns it. :raises CouldNotGetURLError: if getting the URL fails for any reason """ # TODO: Handle invalid responses from the client...
python
def get_url_for_id(client_site_url, apikey, resource_id): """Return the URL for the given resource ID. Contacts the client site's API to get the URL for the ID and returns it. :raises CouldNotGetURLError: if getting the URL fails for any reason """ # TODO: Handle invalid responses from the client...
[ "def", "get_url_for_id", "(", "client_site_url", ",", "apikey", ",", "resource_id", ")", ":", "# TODO: Handle invalid responses from the client site.", "url", "=", "client_site_url", "+", "u\"deadoralive/get_url_for_resource_id\"", "params", "=", "{", "\"resource_id\"", ":", ...
Return the URL for the given resource ID. Contacts the client site's API to get the URL for the ID and returns it. :raises CouldNotGetURLError: if getting the URL fails for any reason
[ "Return", "the", "URL", "for", "the", "given", "resource", "ID", "." ]
train
https://github.com/ckan/deadoralive/blob/82eed6c73e17b9884476311a7a8fae9d2b379600/deadoralive/deadoralive.py#L49-L68
ckan/deadoralive
deadoralive/deadoralive.py
check_url
def check_url(url): """Check whether the given URL is dead or alive. Returns a dict with four keys: "url": The URL that was checked (string) "alive": Whether the URL was working, True or False "status": The HTTP status code of the response from the URL, e.g. 200, 401, 500 (...
python
def check_url(url): """Check whether the given URL is dead or alive. Returns a dict with four keys: "url": The URL that was checked (string) "alive": Whether the URL was working, True or False "status": The HTTP status code of the response from the URL, e.g. 200, 401, 500 (...
[ "def", "check_url", "(", "url", ")", ":", "result", "=", "{", "\"url\"", ":", "url", "}", "try", ":", "response", "=", "requests", ".", "get", "(", "url", ")", "result", "[", "\"status\"", "]", "=", "response", ".", "status_code", "result", "[", "\"r...
Check whether the given URL is dead or alive. Returns a dict with four keys: "url": The URL that was checked (string) "alive": Whether the URL was working, True or False "status": The HTTP status code of the response from the URL, e.g. 200, 401, 500 (int) "reason": The ...
[ "Check", "whether", "the", "given", "URL", "is", "dead", "or", "alive", "." ]
train
https://github.com/ckan/deadoralive/blob/82eed6c73e17b9884476311a7a8fae9d2b379600/deadoralive/deadoralive.py#L71-L121
ckan/deadoralive
deadoralive/deadoralive.py
upsert_result
def upsert_result(client_site_url, apikey, resource_id, result): """Post the given link check result to the client site.""" # TODO: Handle exceptions and unexpected results. url = client_site_url + u"deadoralive/upsert" params = result.copy() params["resource_id"] = resource_id requests.post(ur...
python
def upsert_result(client_site_url, apikey, resource_id, result): """Post the given link check result to the client site.""" # TODO: Handle exceptions and unexpected results. url = client_site_url + u"deadoralive/upsert" params = result.copy() params["resource_id"] = resource_id requests.post(ur...
[ "def", "upsert_result", "(", "client_site_url", ",", "apikey", ",", "resource_id", ",", "result", ")", ":", "# TODO: Handle exceptions and unexpected results.", "url", "=", "client_site_url", "+", "u\"deadoralive/upsert\"", "params", "=", "result", ".", "copy", "(", "...
Post the given link check result to the client site.
[ "Post", "the", "given", "link", "check", "result", "to", "the", "client", "site", "." ]
train
https://github.com/ckan/deadoralive/blob/82eed6c73e17b9884476311a7a8fae9d2b379600/deadoralive/deadoralive.py#L124-L131
ckan/deadoralive
deadoralive/deadoralive.py
get_check_and_report
def get_check_and_report(client_site_url, apikey, get_resource_ids_to_check, get_url_for_id, check_url, upsert_result): """Get links from the client site, check them, and post the results back. Get resource IDs from the client site, get the URL for each resource ID from the client ...
python
def get_check_and_report(client_site_url, apikey, get_resource_ids_to_check, get_url_for_id, check_url, upsert_result): """Get links from the client site, check them, and post the results back. Get resource IDs from the client site, get the URL for each resource ID from the client ...
[ "def", "get_check_and_report", "(", "client_site_url", ",", "apikey", ",", "get_resource_ids_to_check", ",", "get_url_for_id", ",", "check_url", ",", "upsert_result", ")", ":", "logger", "=", "_get_logger", "(", ")", "resource_ids", "=", "get_resource_ids_to_check", "...
Get links from the client site, check them, and post the results back. Get resource IDs from the client site, get the URL for each resource ID from the client site, check each URL, and post the results back to the client site. This function can be called repeatedly to keep on getting more links from ...
[ "Get", "links", "from", "the", "client", "site", "check", "them", "and", "post", "the", "results", "back", "." ]
train
https://github.com/ckan/deadoralive/blob/82eed6c73e17b9884476311a7a8fae9d2b379600/deadoralive/deadoralive.py#L148-L210
okfn/ofs
ofs/local/zipfile.py
ZipExtFile.peek
def peek(self, n=1): """Returns buffered bytes without advancing the position.""" if n > len(self._readbuffer) - self._offset: chunk = self.read(n) self._offset -= len(chunk) # Return up to 512 bytes to reduce allocation overhead for tight loops. return self._rea...
python
def peek(self, n=1): """Returns buffered bytes without advancing the position.""" if n > len(self._readbuffer) - self._offset: chunk = self.read(n) self._offset -= len(chunk) # Return up to 512 bytes to reduce allocation overhead for tight loops. return self._rea...
[ "def", "peek", "(", "self", ",", "n", "=", "1", ")", ":", "if", "n", ">", "len", "(", "self", ".", "_readbuffer", ")", "-", "self", ".", "_offset", ":", "chunk", "=", "self", ".", "read", "(", "n", ")", "self", ".", "_offset", "-=", "len", "(...
Returns buffered bytes without advancing the position.
[ "Returns", "buffered", "bytes", "without", "advancing", "the", "position", "." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipfile.py#L551-L558
okfn/ofs
ofs/local/zipfile.py
ZipExtFile.read
def read(self, n=-1): """Read and return up to n bytes. If the argument is omitted, None, or negative, data is read and returned until EOF is reached.. """ buf = b'' while n < 0 or n is None or n > len(buf): data = self.read1(n) if len(data) == 0: ...
python
def read(self, n=-1): """Read and return up to n bytes. If the argument is omitted, None, or negative, data is read and returned until EOF is reached.. """ buf = b'' while n < 0 or n is None or n > len(buf): data = self.read1(n) if len(data) == 0: ...
[ "def", "read", "(", "self", ",", "n", "=", "-", "1", ")", ":", "buf", "=", "b''", "while", "n", "<", "0", "or", "n", "is", "None", "or", "n", ">", "len", "(", "buf", ")", ":", "data", "=", "self", ".", "read1", "(", "n", ")", "if", "len",...
Read and return up to n bytes. If the argument is omitted, None, or negative, data is read and returned until EOF is reached..
[ "Read", "and", "return", "up", "to", "n", "bytes", ".", "If", "the", "argument", "is", "omitted", "None", "or", "negative", "data", "is", "read", "and", "returned", "until", "EOF", "is", "reached", ".." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipfile.py#L563-L576
okfn/ofs
ofs/local/zipfile.py
ZipFile._RealGetContents
def _RealGetContents(self): """Read in the table of contents for the ZIP file.""" fp = self.fp endrec = _EndRecData(fp) if not endrec: raise BadZipfile("File is not a zip file") if self.debug > 1: print(endrec) size_cd = endrec[_ECD_SIZE] ...
python
def _RealGetContents(self): """Read in the table of contents for the ZIP file.""" fp = self.fp endrec = _EndRecData(fp) if not endrec: raise BadZipfile("File is not a zip file") if self.debug > 1: print(endrec) size_cd = endrec[_ECD_SIZE] ...
[ "def", "_RealGetContents", "(", "self", ")", ":", "fp", "=", "self", ".", "fp", "endrec", "=", "_EndRecData", "(", "fp", ")", "if", "not", "endrec", ":", "raise", "BadZipfile", "(", "\"File is not a zip file\"", ")", "if", "self", ".", "debug", ">", "1",...
Read in the table of contents for the ZIP file.
[ "Read", "in", "the", "table", "of", "contents", "for", "the", "ZIP", "file", "." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipfile.py#L724-L785
okfn/ofs
ofs/local/zipfile.py
ZipFile.open
def open(self, name, mode="r", pwd=None): """Return file-like object for 'name'.""" if mode not in ("r", "U", "rU"): raise RuntimeError('open() requires mode "r", "U", or "rU"') if not self.fp: raise RuntimeError( "Attempt to read ZIP archive that was alre...
python
def open(self, name, mode="r", pwd=None): """Return file-like object for 'name'.""" if mode not in ("r", "U", "rU"): raise RuntimeError('open() requires mode "r", "U", or "rU"') if not self.fp: raise RuntimeError( "Attempt to read ZIP archive that was alre...
[ "def", "open", "(", "self", ",", "name", ",", "mode", "=", "\"r\"", ",", "pwd", "=", "None", ")", ":", "if", "mode", "not", "in", "(", "\"r\"", ",", "\"U\"", ",", "\"rU\"", ")", ":", "raise", "RuntimeError", "(", "'open() requires mode \"r\", \"U\", or \...
Return file-like object for 'name'.
[ "Return", "file", "-", "like", "object", "for", "name", "." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipfile.py#L837-L906
okfn/ofs
ofs/local/zipfile.py
ZipFile.remove
def remove(self, member): """Remove a member from the archive.""" # Make sure we have an info object if isinstance(member, ZipInfo): # 'member' is already an info object zinfo = member else: # Get info object for name zinfo = self.getinfo(m...
python
def remove(self, member): """Remove a member from the archive.""" # Make sure we have an info object if isinstance(member, ZipInfo): # 'member' is already an info object zinfo = member else: # Get info object for name zinfo = self.getinfo(m...
[ "def", "remove", "(", "self", ",", "member", ")", ":", "# Make sure we have an info object", "if", "isinstance", "(", "member", ",", "ZipInfo", ")", ":", "# 'member' is already an info object", "zinfo", "=", "member", "else", ":", "# Get info object for name", "zinfo"...
Remove a member from the archive.
[ "Remove", "a", "member", "from", "the", "archive", "." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipfile.py#L1118-L1146
okfn/ofs
ofs/local/zipfile.py
PyZipFile._get_codename
def _get_codename(self, pathname, basename): """Return (filename, archivename) for the path. Given a module name path, return the correct file path and archive name, compiling if necessary. For example, given /python/lib/string, return (/python/lib/string.pyc, string). """ ...
python
def _get_codename(self, pathname, basename): """Return (filename, archivename) for the path. Given a module name path, return the correct file path and archive name, compiling if necessary. For example, given /python/lib/string, return (/python/lib/string.pyc, string). """ ...
[ "def", "_get_codename", "(", "self", ",", "pathname", ",", "basename", ")", ":", "file_py", "=", "pathname", "+", "\".py\"", "file_pyc", "=", "pathname", "+", "\".pyc\"", "file_pyo", "=", "pathname", "+", "\".pyo\"", "if", "os", ".", "path", ".", "isfile",...
Return (filename, archivename) for the path. Given a module name path, return the correct file path and archive name, compiling if necessary. For example, given /python/lib/string, return (/python/lib/string.pyc, string).
[ "Return", "(", "filename", "archivename", ")", "for", "the", "path", "." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipfile.py#L1334-L1362
tanwanirahul/django-batch-requests
batch_requests/settings.py
import_class
def import_class(class_path): ''' Imports the class for the given class name. ''' module_name, class_name = class_path.rsplit(".", 1) module = import_module(module_name) claz = getattr(module, class_name) return claz
python
def import_class(class_path): ''' Imports the class for the given class name. ''' module_name, class_name = class_path.rsplit(".", 1) module = import_module(module_name) claz = getattr(module, class_name) return claz
[ "def", "import_class", "(", "class_path", ")", ":", "module_name", ",", "class_name", "=", "class_path", ".", "rsplit", "(", "\".\"", ",", "1", ")", "module", "=", "import_module", "(", "module_name", ")", "claz", "=", "getattr", "(", "module", ",", "class...
Imports the class for the given class name.
[ "Imports", "the", "class", "for", "the", "given", "class", "name", "." ]
train
https://github.com/tanwanirahul/django-batch-requests/blob/9c5afc42f7542f466247f4ffed9c44e1c49fa20d/batch_requests/settings.py#L27-L34
tanwanirahul/django-batch-requests
batch_requests/settings.py
BatchRequestSettings._executor
def _executor(self): ''' Creating an ExecutorPool is a costly operation. Executor needs to be instantiated only once. ''' if self.EXECUTE_PARALLEL is False: executor_path = "batch_requests.concurrent.executor.SequentialExecutor" executor_class = import_class(e...
python
def _executor(self): ''' Creating an ExecutorPool is a costly operation. Executor needs to be instantiated only once. ''' if self.EXECUTE_PARALLEL is False: executor_path = "batch_requests.concurrent.executor.SequentialExecutor" executor_class = import_class(e...
[ "def", "_executor", "(", "self", ")", ":", "if", "self", ".", "EXECUTE_PARALLEL", "is", "False", ":", "executor_path", "=", "\"batch_requests.concurrent.executor.SequentialExecutor\"", "executor_class", "=", "import_class", "(", "executor_path", ")", "return", "executor...
Creating an ExecutorPool is a costly operation. Executor needs to be instantiated only once.
[ "Creating", "an", "ExecutorPool", "is", "a", "costly", "operation", ".", "Executor", "needs", "to", "be", "instantiated", "only", "once", "." ]
train
https://github.com/tanwanirahul/django-batch-requests/blob/9c5afc42f7542f466247f4ffed9c44e1c49fa20d/batch_requests/settings.py#L48-L59
okfn/ofs
ofs/command.py
OFS.make_label
def make_label(self, path): """ this borrows too much from the internals of ofs maybe expose different parts of the api? """ from datetime import datetime from StringIO import StringIO path = path.lstrip("/") bucket, label = path.split("/", 1) buc...
python
def make_label(self, path): """ this borrows too much from the internals of ofs maybe expose different parts of the api? """ from datetime import datetime from StringIO import StringIO path = path.lstrip("/") bucket, label = path.split("/", 1) buc...
[ "def", "make_label", "(", "self", ",", "path", ")", ":", "from", "datetime", "import", "datetime", "from", "StringIO", "import", "StringIO", "path", "=", "path", ".", "lstrip", "(", "\"/\"", ")", "bucket", ",", "label", "=", "path", ".", "split", "(", ...
this borrows too much from the internals of ofs maybe expose different parts of the api?
[ "this", "borrows", "too", "much", "from", "the", "internals", "of", "ofs", "maybe", "expose", "different", "parts", "of", "the", "api?" ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/command.py#L57-L73
okfn/ofs
ofs/command.py
OFS.get_proxy_config
def get_proxy_config(self, headers, path): """ stub. this really needs to be a call to the remote restful interface to get the appropriate host and headers to use for this upload """ self.ofs.conn.add_aws_auth_header(headers, 'PUT', path) from pprint import pprint...
python
def get_proxy_config(self, headers, path): """ stub. this really needs to be a call to the remote restful interface to get the appropriate host and headers to use for this upload """ self.ofs.conn.add_aws_auth_header(headers, 'PUT', path) from pprint import pprint...
[ "def", "get_proxy_config", "(", "self", ",", "headers", ",", "path", ")", ":", "self", ".", "ofs", ".", "conn", ".", "add_aws_auth_header", "(", "headers", ",", "'PUT'", ",", "path", ")", "from", "pprint", "import", "pprint", "pprint", "(", "headers", ")...
stub. this really needs to be a call to the remote restful interface to get the appropriate host and headers to use for this upload
[ "stub", ".", "this", "really", "needs", "to", "be", "a", "call", "to", "the", "remote", "restful", "interface", "to", "get", "the", "appropriate", "host", "and", "headers", "to", "use", "for", "this", "upload" ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/command.py#L75-L85
okfn/ofs
ofs/command.py
OFS.proxy_upload
def proxy_upload(self, path, filename, content_type=None, content_encoding=None, cb=None, num_cb=None): """ This is the main function that uploads. We assume the bucket and key (== path) exists. What we do here is simple. Calculate the headers we will need, (e.g. md5...
python
def proxy_upload(self, path, filename, content_type=None, content_encoding=None, cb=None, num_cb=None): """ This is the main function that uploads. We assume the bucket and key (== path) exists. What we do here is simple. Calculate the headers we will need, (e.g. md5...
[ "def", "proxy_upload", "(", "self", ",", "path", ",", "filename", ",", "content_type", "=", "None", ",", "content_encoding", "=", "None", ",", "cb", "=", "None", ",", "num_cb", "=", "None", ")", ":", "from", "boto", ".", "connection", "import", "AWSAuthC...
This is the main function that uploads. We assume the bucket and key (== path) exists. What we do here is simple. Calculate the headers we will need, (e.g. md5, content-type, etc). Then we ask the self.get_proxy_config method to fill in the authentication information and tell us which re...
[ "This", "is", "the", "main", "function", "that", "uploads", ".", "We", "assume", "the", "bucket", "and", "key", "(", "==", "path", ")", "exists", ".", "What", "we", "do", "here", "is", "simple", ".", "Calculate", "the", "headers", "we", "will", "need",...
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/command.py#L87-L187
KKBOX/OpenAPI-Python
kkbox_developer_sdk/mood_station_fetcher.py
KKBOXMoodStationFetcher.fetch_all_mood_stations
def fetch_all_mood_stations(self, terr=KKBOXTerritory.TAIWAN): ''' Fetches all mood stations. :param terr: the current territory. :return: API response. :rtype: dict See `https://docs-en.kkbox.codes/v1.1/reference#moodstations`. ''' url = 'https://api.kk...
python
def fetch_all_mood_stations(self, terr=KKBOXTerritory.TAIWAN): ''' Fetches all mood stations. :param terr: the current territory. :return: API response. :rtype: dict See `https://docs-en.kkbox.codes/v1.1/reference#moodstations`. ''' url = 'https://api.kk...
[ "def", "fetch_all_mood_stations", "(", "self", ",", "terr", "=", "KKBOXTerritory", ".", "TAIWAN", ")", ":", "url", "=", "'https://api.kkbox.com/v1.1/mood-stations'", "url", "+=", "'?'", "+", "url_parse", ".", "urlencode", "(", "{", "'territory'", ":", "terr", "}...
Fetches all mood stations. :param terr: the current territory. :return: API response. :rtype: dict See `https://docs-en.kkbox.codes/v1.1/reference#moodstations`.
[ "Fetches", "all", "mood", "stations", "." ]
train
https://github.com/KKBOX/OpenAPI-Python/blob/77aa22fd300ed987d5507a5b66b149edcd28047d/kkbox_developer_sdk/mood_station_fetcher.py#L13-L25
KKBOX/OpenAPI-Python
kkbox_developer_sdk/mood_station_fetcher.py
KKBOXMoodStationFetcher.fetch_mood_station
def fetch_mood_station(self, station_id, terr=KKBOXTerritory.TAIWAN): ''' Fetches a mood station by given ID. :param station_id: the station ID :param terr: the current territory. :return: API response. :rtype: dict See `https://docs-en.kkbox.codes/v1.1/referenc...
python
def fetch_mood_station(self, station_id, terr=KKBOXTerritory.TAIWAN): ''' Fetches a mood station by given ID. :param station_id: the station ID :param terr: the current territory. :return: API response. :rtype: dict See `https://docs-en.kkbox.codes/v1.1/referenc...
[ "def", "fetch_mood_station", "(", "self", ",", "station_id", ",", "terr", "=", "KKBOXTerritory", ".", "TAIWAN", ")", ":", "url", "=", "'https://api.kkbox.com/v1.1/mood-stations/%s'", "%", "station_id", "url", "+=", "'?'", "+", "url_parse", ".", "urlencode", "(", ...
Fetches a mood station by given ID. :param station_id: the station ID :param terr: the current territory. :return: API response. :rtype: dict See `https://docs-en.kkbox.codes/v1.1/reference#moodstations-station_id`.
[ "Fetches", "a", "mood", "station", "by", "given", "ID", "." ]
train
https://github.com/KKBOX/OpenAPI-Python/blob/77aa22fd300ed987d5507a5b66b149edcd28047d/kkbox_developer_sdk/mood_station_fetcher.py#L28-L41
KKBOX/OpenAPI-Python
kkbox_developer_sdk/fetcher.py
Fetcher.fetch_next_page
def fetch_next_page(self, data): ''' Fetches next page based on previously fetched data. Will get the next page url from data['paging']['next']. :param data: previously fetched API response. :type data: dict :return: API response. :rtype: dict '''...
python
def fetch_next_page(self, data): ''' Fetches next page based on previously fetched data. Will get the next page url from data['paging']['next']. :param data: previously fetched API response. :type data: dict :return: API response. :rtype: dict '''...
[ "def", "fetch_next_page", "(", "self", ",", "data", ")", ":", "next_url", "=", "data", "[", "'paging'", "]", "[", "'next'", "]", "if", "next_url", "!=", "None", ":", "next_data", "=", "self", ".", "http", ".", "_post_data", "(", "next_url", ",", "None"...
Fetches next page based on previously fetched data. Will get the next page url from data['paging']['next']. :param data: previously fetched API response. :type data: dict :return: API response. :rtype: dict
[ "Fetches", "next", "page", "based", "on", "previously", "fetched", "data", ".", "Will", "get", "the", "next", "page", "url", "from", "data", "[", "paging", "]", "[", "next", "]", "." ]
train
https://github.com/KKBOX/OpenAPI-Python/blob/77aa22fd300ed987d5507a5b66b149edcd28047d/kkbox_developer_sdk/fetcher.py#L29-L44
KKBOX/OpenAPI-Python
kkbox_developer_sdk/fetcher.py
Fetcher.fetch_data
def fetch_data(self, url): ''' Fetches data from specific url. :return: The response. :rtype: dict ''' return self.http._post_data(url, None, self.http._headers_with_access_token())
python
def fetch_data(self, url): ''' Fetches data from specific url. :return: The response. :rtype: dict ''' return self.http._post_data(url, None, self.http._headers_with_access_token())
[ "def", "fetch_data", "(", "self", ",", "url", ")", ":", "return", "self", ".", "http", ".", "_post_data", "(", "url", ",", "None", ",", "self", ".", "http", ".", "_headers_with_access_token", "(", ")", ")" ]
Fetches data from specific url. :return: The response. :rtype: dict
[ "Fetches", "data", "from", "specific", "url", "." ]
train
https://github.com/KKBOX/OpenAPI-Python/blob/77aa22fd300ed987d5507a5b66b149edcd28047d/kkbox_developer_sdk/fetcher.py#L46-L53
KKBOX/OpenAPI-Python
kkbox_developer_sdk/shared_playlist_fetcher.py
KKBOXSharedPlaylistFetcher.fetch_shared_playlist
def fetch_shared_playlist(self, playlist_id, terr=KKBOXTerritory.TAIWAN): ''' Fetches a shared playlist by given ID. :param playlist_id: the playlist ID. :type playlist_id: str :param terr: the current territory. :return: API response. :rtype: dictcd See...
python
def fetch_shared_playlist(self, playlist_id, terr=KKBOXTerritory.TAIWAN): ''' Fetches a shared playlist by given ID. :param playlist_id: the playlist ID. :type playlist_id: str :param terr: the current territory. :return: API response. :rtype: dictcd See...
[ "def", "fetch_shared_playlist", "(", "self", ",", "playlist_id", ",", "terr", "=", "KKBOXTerritory", ".", "TAIWAN", ")", ":", "url", "=", "'https://api.kkbox.com/v1.1/shared-playlists/%s'", "%", "playlist_id", "url", "+=", "'?'", "+", "url_parse", ".", "urlencode", ...
Fetches a shared playlist by given ID. :param playlist_id: the playlist ID. :type playlist_id: str :param terr: the current territory. :return: API response. :rtype: dictcd See `https://docs-en.kkbox.codes/v1.1/reference#sharedplaylists-playlist_id`.
[ "Fetches", "a", "shared", "playlist", "by", "given", "ID", "." ]
train
https://github.com/KKBOX/OpenAPI-Python/blob/77aa22fd300ed987d5507a5b66b149edcd28047d/kkbox_developer_sdk/shared_playlist_fetcher.py#L13-L27
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/firewall_mixin.py
FirewallManager.get_firewall_rule
def get_firewall_rule(self, server_uuid, firewall_rule_position, server_instance=None): """ Return a FirewallRule object based on server uuid and rule position. """ url = '/server/{0}/firewall_rule/{1}'.format(server_uuid, firewall_rule_position) res = self.get_request(url) ...
python
def get_firewall_rule(self, server_uuid, firewall_rule_position, server_instance=None): """ Return a FirewallRule object based on server uuid and rule position. """ url = '/server/{0}/firewall_rule/{1}'.format(server_uuid, firewall_rule_position) res = self.get_request(url) ...
[ "def", "get_firewall_rule", "(", "self", ",", "server_uuid", ",", "firewall_rule_position", ",", "server_instance", "=", "None", ")", ":", "url", "=", "'/server/{0}/firewall_rule/{1}'", ".", "format", "(", "server_uuid", ",", "firewall_rule_position", ")", "res", "=...
Return a FirewallRule object based on server uuid and rule position.
[ "Return", "a", "FirewallRule", "object", "based", "on", "server", "uuid", "and", "rule", "position", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/firewall_mixin.py#L20-L26
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/firewall_mixin.py
FirewallManager.get_firewall_rules
def get_firewall_rules(self, server): """ Return all FirewallRule objects based on a server instance or uuid. """ server_uuid, server_instance = uuid_and_instance(server) url = '/server/{0}/firewall_rule'.format(server_uuid) res = self.get_request(url) return [ ...
python
def get_firewall_rules(self, server): """ Return all FirewallRule objects based on a server instance or uuid. """ server_uuid, server_instance = uuid_and_instance(server) url = '/server/{0}/firewall_rule'.format(server_uuid) res = self.get_request(url) return [ ...
[ "def", "get_firewall_rules", "(", "self", ",", "server", ")", ":", "server_uuid", ",", "server_instance", "=", "uuid_and_instance", "(", "server", ")", "url", "=", "'/server/{0}/firewall_rule'", ".", "format", "(", "server_uuid", ")", "res", "=", "self", ".", ...
Return all FirewallRule objects based on a server instance or uuid.
[ "Return", "all", "FirewallRule", "objects", "based", "on", "a", "server", "instance", "or", "uuid", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/firewall_mixin.py#L28-L40
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/firewall_mixin.py
FirewallManager.create_firewall_rule
def create_firewall_rule(self, server, firewall_rule_body): """ Create a new firewall rule for a given server uuid. The rule can begiven as a dict or with FirewallRule.prepare_post_body(). Returns a FirewallRule object. """ server_uuid, server_instance = uuid_and_instanc...
python
def create_firewall_rule(self, server, firewall_rule_body): """ Create a new firewall rule for a given server uuid. The rule can begiven as a dict or with FirewallRule.prepare_post_body(). Returns a FirewallRule object. """ server_uuid, server_instance = uuid_and_instanc...
[ "def", "create_firewall_rule", "(", "self", ",", "server", ",", "firewall_rule_body", ")", ":", "server_uuid", ",", "server_instance", "=", "uuid_and_instance", "(", "server", ")", "url", "=", "'/server/{0}/firewall_rule'", ".", "format", "(", "server_uuid", ")", ...
Create a new firewall rule for a given server uuid. The rule can begiven as a dict or with FirewallRule.prepare_post_body(). Returns a FirewallRule object.
[ "Create", "a", "new", "firewall", "rule", "for", "a", "given", "server", "uuid", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/firewall_mixin.py#L42-L55
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/firewall_mixin.py
FirewallManager.delete_firewall_rule
def delete_firewall_rule(self, server_uuid, firewall_rule_position): """ Delete a firewall rule based on a server uuid and rule position. """ url = '/server/{0}/firewall_rule/{1}'.format(server_uuid, firewall_rule_position) return self.request('DELETE', url)
python
def delete_firewall_rule(self, server_uuid, firewall_rule_position): """ Delete a firewall rule based on a server uuid and rule position. """ url = '/server/{0}/firewall_rule/{1}'.format(server_uuid, firewall_rule_position) return self.request('DELETE', url)
[ "def", "delete_firewall_rule", "(", "self", ",", "server_uuid", ",", "firewall_rule_position", ")", ":", "url", "=", "'/server/{0}/firewall_rule/{1}'", ".", "format", "(", "server_uuid", ",", "firewall_rule_position", ")", "return", "self", ".", "request", "(", "'DE...
Delete a firewall rule based on a server uuid and rule position.
[ "Delete", "a", "firewall", "rule", "based", "on", "a", "server", "uuid", "and", "rule", "position", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/firewall_mixin.py#L57-L62
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/firewall_mixin.py
FirewallManager.configure_firewall
def configure_firewall(self, server, firewall_rule_bodies): """ Helper for calling create_firewall_rule in series for a list of firewall_rule_bodies. """ server_uuid, server_instance = uuid_and_instance(server) return [ self.create_firewall_rule(server_uuid, rule) ...
python
def configure_firewall(self, server, firewall_rule_bodies): """ Helper for calling create_firewall_rule in series for a list of firewall_rule_bodies. """ server_uuid, server_instance = uuid_and_instance(server) return [ self.create_firewall_rule(server_uuid, rule) ...
[ "def", "configure_firewall", "(", "self", ",", "server", ",", "firewall_rule_bodies", ")", ":", "server_uuid", ",", "server_instance", "=", "uuid_and_instance", "(", "server", ")", "return", "[", "self", ".", "create_firewall_rule", "(", "server_uuid", ",", "rule"...
Helper for calling create_firewall_rule in series for a list of firewall_rule_bodies.
[ "Helper", "for", "calling", "create_firewall_rule", "in", "series", "for", "a", "list", "of", "firewall_rule_bodies", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/firewall_mixin.py#L64-L73
csirtgadgets/csirtgsdk-py
csirtgsdk/sinkhole.py
Sinkhole.post
def post(self, data): """ POSTs a raw SMTP message to the Sinkhole API :param data: raw content to be submitted [STRING] :return: { list of predictions } """ uri = '{}/sinkhole'.format(self.client.remote) self.logger.debug(uri) if PYVERSION == 2: ...
python
def post(self, data): """ POSTs a raw SMTP message to the Sinkhole API :param data: raw content to be submitted [STRING] :return: { list of predictions } """ uri = '{}/sinkhole'.format(self.client.remote) self.logger.debug(uri) if PYVERSION == 2: ...
[ "def", "post", "(", "self", ",", "data", ")", ":", "uri", "=", "'{}/sinkhole'", ".", "format", "(", "self", ".", "client", ".", "remote", ")", "self", ".", "logger", ".", "debug", "(", "uri", ")", "if", "PYVERSION", "==", "2", ":", "try", ":", "d...
POSTs a raw SMTP message to the Sinkhole API :param data: raw content to be submitted [STRING] :return: { list of predictions }
[ "POSTs", "a", "raw", "SMTP", "message", "to", "the", "Sinkhole", "API" ]
train
https://github.com/csirtgadgets/csirtgsdk-py/blob/5a7ed9c5e6fa27170366ecbdef710dc80d537dc2/csirtgsdk/sinkhole.py#L20-L41
tanwanirahul/django-batch-requests
batch_requests/utils.py
pre_process_method_headers
def pre_process_method_headers(method, headers): ''' Returns the lowered method. Capitalize headers, prepend HTTP_ and change - to _. ''' method = method.lower() # Standard WSGI supported headers _wsgi_headers = ["content_length", "content_type", "query_string", ...
python
def pre_process_method_headers(method, headers): ''' Returns the lowered method. Capitalize headers, prepend HTTP_ and change - to _. ''' method = method.lower() # Standard WSGI supported headers _wsgi_headers = ["content_length", "content_type", "query_string", ...
[ "def", "pre_process_method_headers", "(", "method", ",", "headers", ")", ":", "method", "=", "method", ".", "lower", "(", ")", "# Standard WSGI supported headers", "_wsgi_headers", "=", "[", "\"content_length\"", ",", "\"content_type\"", ",", "\"query_string\"", ",", ...
Returns the lowered method. Capitalize headers, prepend HTTP_ and change - to _.
[ "Returns", "the", "lowered", "method", ".", "Capitalize", "headers", "prepend", "HTTP_", "and", "change", "-", "to", "_", "." ]
train
https://github.com/tanwanirahul/django-batch-requests/blob/9c5afc42f7542f466247f4ffed9c44e1c49fa20d/batch_requests/utils.py#L47-L70
tanwanirahul/django-batch-requests
batch_requests/utils.py
headers_to_include_from_request
def headers_to_include_from_request(curr_request): ''' Define headers that needs to be included from the current request. ''' return { h: v for h, v in curr_request.META.items() if h in _settings.HEADERS_TO_INCLUDE}
python
def headers_to_include_from_request(curr_request): ''' Define headers that needs to be included from the current request. ''' return { h: v for h, v in curr_request.META.items() if h in _settings.HEADERS_TO_INCLUDE}
[ "def", "headers_to_include_from_request", "(", "curr_request", ")", ":", "return", "{", "h", ":", "v", "for", "h", ",", "v", "in", "curr_request", ".", "META", ".", "items", "(", ")", "if", "h", "in", "_settings", ".", "HEADERS_TO_INCLUDE", "}" ]
Define headers that needs to be included from the current request.
[ "Define", "headers", "that", "needs", "to", "be", "included", "from", "the", "current", "request", "." ]
train
https://github.com/tanwanirahul/django-batch-requests/blob/9c5afc42f7542f466247f4ffed9c44e1c49fa20d/batch_requests/utils.py#L73-L78
tanwanirahul/django-batch-requests
batch_requests/utils.py
get_wsgi_request_object
def get_wsgi_request_object(curr_request, method, url, headers, body): ''' Based on the given request parameters, constructs and returns the WSGI request object. ''' x_headers = headers_to_include_from_request(curr_request) method, t_headers = pre_process_method_headers(method, headers) # A...
python
def get_wsgi_request_object(curr_request, method, url, headers, body): ''' Based on the given request parameters, constructs and returns the WSGI request object. ''' x_headers = headers_to_include_from_request(curr_request) method, t_headers = pre_process_method_headers(method, headers) # A...
[ "def", "get_wsgi_request_object", "(", "curr_request", ",", "method", ",", "url", ",", "headers", ",", "body", ")", ":", "x_headers", "=", "headers_to_include_from_request", "(", "curr_request", ")", "method", ",", "t_headers", "=", "pre_process_method_headers", "("...
Based on the given request parameters, constructs and returns the WSGI request object.
[ "Based", "on", "the", "given", "request", "parameters", "constructs", "and", "returns", "the", "WSGI", "request", "object", "." ]
train
https://github.com/tanwanirahul/django-batch-requests/blob/9c5afc42f7542f466247f4ffed9c44e1c49fa20d/batch_requests/utils.py#L81-L106
tanwanirahul/django-batch-requests
batch_requests/utils.py
BatchRequestFactory._base_environ
def _base_environ(self, **request): ''' Override the default values for the wsgi environment variables. ''' # This is a minimal valid WSGI environ dictionary, plus: # - HTTP_COOKIE: for cookie support, # - REMOTE_ADDR: often useful, see #8551. # See http://www...
python
def _base_environ(self, **request): ''' Override the default values for the wsgi environment variables. ''' # This is a minimal valid WSGI environ dictionary, plus: # - HTTP_COOKIE: for cookie support, # - REMOTE_ADDR: often useful, see #8551. # See http://www...
[ "def", "_base_environ", "(", "self", ",", "*", "*", "request", ")", ":", "# This is a minimal valid WSGI environ dictionary, plus:", "# - HTTP_COOKIE: for cookie support,", "# - REMOTE_ADDR: often useful, see #8551.", "# See http://www.python.org/dev/peps/pep-3333/#environ-variables", "e...
Override the default values for the wsgi environment variables.
[ "Override", "the", "default", "values", "for", "the", "wsgi", "environment", "variables", "." ]
train
https://github.com/tanwanirahul/django-batch-requests/blob/9c5afc42f7542f466247f4ffed9c44e1c49fa20d/batch_requests/utils.py#L16-L44
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/base.py
BaseAPI.request
def request(self, method, endpoint, body=None, timeout=-1): """ Perform a request with a given body to a given endpoint in UpCloud's API. Handles errors with __error_middleware. """ if method not in set(['GET', 'POST', 'PUT', 'DELETE']): raise Exception('Invalid/Forb...
python
def request(self, method, endpoint, body=None, timeout=-1): """ Perform a request with a given body to a given endpoint in UpCloud's API. Handles errors with __error_middleware. """ if method not in set(['GET', 'POST', 'PUT', 'DELETE']): raise Exception('Invalid/Forb...
[ "def", "request", "(", "self", ",", "method", ",", "endpoint", ",", "body", "=", "None", ",", "timeout", "=", "-", "1", ")", ":", "if", "method", "not", "in", "set", "(", "[", "'GET'", ",", "'POST'", ",", "'PUT'", ",", "'DELETE'", "]", ")", ":", ...
Perform a request with a given body to a given endpoint in UpCloud's API. Handles errors with __error_middleware.
[ "Perform", "a", "request", "with", "a", "given", "body", "to", "a", "given", "endpoint", "in", "UpCloud", "s", "API", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/base.py#L21-L54
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/base.py
BaseAPI.post_request
def post_request(self, endpoint, body=None, timeout=-1): """ Perform a POST request to a given endpoint in UpCloud's API. """ return self.request('POST', endpoint, body, timeout)
python
def post_request(self, endpoint, body=None, timeout=-1): """ Perform a POST request to a given endpoint in UpCloud's API. """ return self.request('POST', endpoint, body, timeout)
[ "def", "post_request", "(", "self", ",", "endpoint", ",", "body", "=", "None", ",", "timeout", "=", "-", "1", ")", ":", "return", "self", ".", "request", "(", "'POST'", ",", "endpoint", ",", "body", ",", "timeout", ")" ]
Perform a POST request to a given endpoint in UpCloud's API.
[ "Perform", "a", "POST", "request", "to", "a", "given", "endpoint", "in", "UpCloud", "s", "API", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/base.py#L62-L66
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/base.py
BaseAPI.__error_middleware
def __error_middleware(self, res, res_json): """ Middleware that raises an exception when HTTP statuscode is an error code. """ if(res.status_code in [400, 401, 402, 403, 404, 405, 406, 409]): err_dict = res_json.get('error', {}) raise UpCloudAPIError(error_code=e...
python
def __error_middleware(self, res, res_json): """ Middleware that raises an exception when HTTP statuscode is an error code. """ if(res.status_code in [400, 401, 402, 403, 404, 405, 406, 409]): err_dict = res_json.get('error', {}) raise UpCloudAPIError(error_code=e...
[ "def", "__error_middleware", "(", "self", ",", "res", ",", "res_json", ")", ":", "if", "(", "res", ".", "status_code", "in", "[", "400", ",", "401", ",", "402", ",", "403", ",", "404", ",", "405", ",", "406", ",", "409", "]", ")", ":", "err_dict"...
Middleware that raises an exception when HTTP statuscode is an error code.
[ "Middleware", "that", "raises", "an", "exception", "when", "HTTP", "statuscode", "is", "an", "error", "code", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/base.py#L68-L77
okfn/ofs
ofs/remote/swiftstore.py
SwiftOFS.put_stream
def put_stream(self, bucket, label, stream_object, params={}): ''' Create a new file to swift object storage. ''' self.claim_bucket(bucket) self.connection.put_object(bucket, label, stream_object, headers=self._convert_to_meta(params))
python
def put_stream(self, bucket, label, stream_object, params={}): ''' Create a new file to swift object storage. ''' self.claim_bucket(bucket) self.connection.put_object(bucket, label, stream_object, headers=self._convert_to_meta(params))
[ "def", "put_stream", "(", "self", ",", "bucket", ",", "label", ",", "stream_object", ",", "params", "=", "{", "}", ")", ":", "self", ".", "claim_bucket", "(", "bucket", ")", "self", ".", "connection", ".", "put_object", "(", "bucket", ",", "label", ","...
Create a new file to swift object storage.
[ "Create", "a", "new", "file", "to", "swift", "object", "storage", "." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/remote/swiftstore.py#L116-L120
ralphhaygood/sklearn-gbmi
sklearn_gbmi/sklearn_gbmi.py
h
def h(gbm, array_or_frame, indices_or_columns = 'all'): """ PURPOSE Compute Friedman and Popescu's H statistic, in order to look for an interaction in the passed gradient-boosting model among the variables represented by the elements of the passed array or frame and specified by the passed indices ...
python
def h(gbm, array_or_frame, indices_or_columns = 'all'): """ PURPOSE Compute Friedman and Popescu's H statistic, in order to look for an interaction in the passed gradient-boosting model among the variables represented by the elements of the passed array or frame and specified by the passed indices ...
[ "def", "h", "(", "gbm", ",", "array_or_frame", ",", "indices_or_columns", "=", "'all'", ")", ":", "if", "indices_or_columns", "==", "'all'", ":", "if", "gbm", ".", "max_depth", "<", "array_or_frame", ".", "shape", "[", "1", "]", ":", "raise", "Exception", ...
PURPOSE Compute Friedman and Popescu's H statistic, in order to look for an interaction in the passed gradient-boosting model among the variables represented by the elements of the passed array or frame and specified by the passed indices or columns. See Jerome H. Friedman and Bogdan E. Popescu, 2008,...
[ "PURPOSE" ]
train
https://github.com/ralphhaygood/sklearn-gbmi/blob/23a1e7fd50e53d6261379f22a337d8fa4ee6aabe/sklearn_gbmi/sklearn_gbmi.py#L16-L95
ralphhaygood/sklearn-gbmi
sklearn_gbmi/sklearn_gbmi.py
h_all_pairs
def h_all_pairs(gbm, array_or_frame, indices_or_columns = 'all'): """ PURPOSE Compute Friedman and Popescu's two-variable H statistic, in order to look for an interaction in the passed gradient- boosting model between each pair of variables represented by the elements of the passed array or frame and s...
python
def h_all_pairs(gbm, array_or_frame, indices_or_columns = 'all'): """ PURPOSE Compute Friedman and Popescu's two-variable H statistic, in order to look for an interaction in the passed gradient- boosting model between each pair of variables represented by the elements of the passed array or frame and s...
[ "def", "h_all_pairs", "(", "gbm", ",", "array_or_frame", ",", "indices_or_columns", "=", "'all'", ")", ":", "if", "gbm", ".", "max_depth", "<", "2", ":", "raise", "Exception", "(", "\"gbm.max_depth must be at least 2.\"", ")", "check_args_contd", "(", "array_or_fr...
PURPOSE Compute Friedman and Popescu's two-variable H statistic, in order to look for an interaction in the passed gradient- boosting model between each pair of variables represented by the elements of the passed array or frame and specified by the passed indices or columns. See Jerome H. Friedman and...
[ "PURPOSE" ]
train
https://github.com/ralphhaygood/sklearn-gbmi/blob/23a1e7fd50e53d6261379f22a337d8fa4ee6aabe/sklearn_gbmi/sklearn_gbmi.py#L98-L169
csirtgadgets/csirtgsdk-py
csirtgsdk/predict.py
Predict.get
def get(self, q, limit=None): """ Performs a search against the predict endpoint :param q: query to be searched for [STRING] :return: { score: [0|1] } """ uri = '{}/predict?q={}'.format(self.client.remote, q) self.logger.debug(uri) body = self.client.get...
python
def get(self, q, limit=None): """ Performs a search against the predict endpoint :param q: query to be searched for [STRING] :return: { score: [0|1] } """ uri = '{}/predict?q={}'.format(self.client.remote, q) self.logger.debug(uri) body = self.client.get...
[ "def", "get", "(", "self", ",", "q", ",", "limit", "=", "None", ")", ":", "uri", "=", "'{}/predict?q={}'", ".", "format", "(", "self", ".", "client", ".", "remote", ",", "q", ")", "self", ".", "logger", ".", "debug", "(", "uri", ")", "body", "=",...
Performs a search against the predict endpoint :param q: query to be searched for [STRING] :return: { score: [0|1] }
[ "Performs", "a", "search", "against", "the", "predict", "endpoint" ]
train
https://github.com/csirtgadgets/csirtgsdk-py/blob/5a7ed9c5e6fa27170366ecbdef710dc80d537dc2/csirtgsdk/predict.py#L18-L29
okfn/ofs
ofs/local/zipstore.py
ZOFS.exists
def exists(self, bucket, label): '''Whether a given bucket:label object already exists.''' fn = self._zf(bucket, label) try: self.z.getinfo(fn) return True except KeyError: return False
python
def exists(self, bucket, label): '''Whether a given bucket:label object already exists.''' fn = self._zf(bucket, label) try: self.z.getinfo(fn) return True except KeyError: return False
[ "def", "exists", "(", "self", ",", "bucket", ",", "label", ")", ":", "fn", "=", "self", ".", "_zf", "(", "bucket", ",", "label", ")", "try", ":", "self", ".", "z", ".", "getinfo", "(", "fn", ")", "return", "True", "except", "KeyError", ":", "retu...
Whether a given bucket:label object already exists.
[ "Whether", "a", "given", "bucket", ":", "label", "object", "already", "exists", "." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipstore.py#L112-L119
okfn/ofs
ofs/local/zipstore.py
ZOFS.list_labels
def list_labels(self, bucket): '''List labels for the given bucket. Due to zipfiles inherent arbitrary ordering, this is an expensive operation, as it walks the entire archive searching for individual 'buckets' :param bucket: bucket to list labels for. :return: iterator for the ...
python
def list_labels(self, bucket): '''List labels for the given bucket. Due to zipfiles inherent arbitrary ordering, this is an expensive operation, as it walks the entire archive searching for individual 'buckets' :param bucket: bucket to list labels for. :return: iterator for the ...
[ "def", "list_labels", "(", "self", ",", "bucket", ")", ":", "for", "name", "in", "self", ".", "z", ".", "namelist", "(", ")", ":", "container", ",", "label", "=", "self", ".", "_nf", "(", "name", ".", "encode", "(", "\"utf-8\"", ")", ")", "if", "...
List labels for the given bucket. Due to zipfiles inherent arbitrary ordering, this is an expensive operation, as it walks the entire archive searching for individual 'buckets' :param bucket: bucket to list labels for. :return: iterator for the labels in the specified bucket.
[ "List", "labels", "for", "the", "given", "bucket", ".", "Due", "to", "zipfiles", "inherent", "arbitrary", "ordering", "this", "is", "an", "expensive", "operation", "as", "it", "walks", "the", "entire", "archive", "searching", "for", "individual", "buckets" ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipstore.py#L131-L142
okfn/ofs
ofs/local/zipstore.py
ZOFS.list_buckets
def list_buckets(self): '''List all buckets managed by this OFS instance. Like list_labels, this also walks the entire archive, yielding the bucketnames. A local set is retained so that duplicates aren't returned so this will temporarily pull the entire list into memory even though this ...
python
def list_buckets(self): '''List all buckets managed by this OFS instance. Like list_labels, this also walks the entire archive, yielding the bucketnames. A local set is retained so that duplicates aren't returned so this will temporarily pull the entire list into memory even though this ...
[ "def", "list_buckets", "(", "self", ")", ":", "buckets", "=", "set", "(", ")", "for", "name", "in", "self", ".", "z", ".", "namelist", "(", ")", ":", "bucket", ",", "_", "=", "self", ".", "_nf", "(", "name", ")", "if", "bucket", "not", "in", "b...
List all buckets managed by this OFS instance. Like list_labels, this also walks the entire archive, yielding the bucketnames. A local set is retained so that duplicates aren't returned so this will temporarily pull the entire list into memory even though this is a generator and will slow as mor...
[ "List", "all", "buckets", "managed", "by", "this", "OFS", "instance", ".", "Like", "list_labels", "this", "also", "walks", "the", "entire", "archive", "yielding", "the", "bucketnames", ".", "A", "local", "set", "is", "retained", "so", "that", "duplicates", "...
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipstore.py#L144-L157
okfn/ofs
ofs/local/zipstore.py
ZOFS.get_stream
def get_stream(self, bucket, label, as_stream=True): '''Get a bitstream for the given bucket:label combination. :param bucket: the bucket to use. :return: bitstream as a file-like object ''' if self.mode == "w": raise OFSException("Cannot read from archive in 'w' mod...
python
def get_stream(self, bucket, label, as_stream=True): '''Get a bitstream for the given bucket:label combination. :param bucket: the bucket to use. :return: bitstream as a file-like object ''' if self.mode == "w": raise OFSException("Cannot read from archive in 'w' mod...
[ "def", "get_stream", "(", "self", ",", "bucket", ",", "label", ",", "as_stream", "=", "True", ")", ":", "if", "self", ".", "mode", "==", "\"w\"", ":", "raise", "OFSException", "(", "\"Cannot read from archive in 'w' mode\"", ")", "elif", "self", ".", "exists...
Get a bitstream for the given bucket:label combination. :param bucket: the bucket to use. :return: bitstream as a file-like object
[ "Get", "a", "bitstream", "for", "the", "given", "bucket", ":", "label", "combination", "." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipstore.py#L159-L174
okfn/ofs
ofs/local/zipstore.py
ZOFS.get_url
def get_url(self, bucket, label): '''Get a URL that should point at the bucket:labelled resource. Aimed to aid web apps by allowing them to redirect to an open resource, rather than proxy the bitstream. :param bucket: the bucket to use. :param label: the label of the resource to get :re...
python
def get_url(self, bucket, label): '''Get a URL that should point at the bucket:labelled resource. Aimed to aid web apps by allowing them to redirect to an open resource, rather than proxy the bitstream. :param bucket: the bucket to use. :param label: the label of the resource to get :re...
[ "def", "get_url", "(", "self", ",", "bucket", ",", "label", ")", ":", "if", "self", ".", "exists", "(", "bucket", ",", "label", ")", ":", "root", "=", "\"zip:file//%s\"", "%", "os", ".", "path", ".", "abspath", "(", "self", ".", "zipfile", ")", "fn...
Get a URL that should point at the bucket:labelled resource. Aimed to aid web apps by allowing them to redirect to an open resource, rather than proxy the bitstream. :param bucket: the bucket to use. :param label: the label of the resource to get :return: a string URI - eg 'zip:file:///home/......
[ "Get", "a", "URL", "that", "should", "point", "at", "the", "bucket", ":", "labelled", "resource", ".", "Aimed", "to", "aid", "web", "apps", "by", "allowing", "them", "to", "redirect", "to", "an", "open", "resource", "rather", "than", "proxy", "the", "bit...
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipstore.py#L176-L188
okfn/ofs
ofs/local/zipstore.py
ZOFS.put_stream
def put_stream(self, bucket, label, stream_object, params=None, replace=True, add_md=True): '''Put a bitstream (stream_object) for the specified bucket:label identifier. :param bucket: as standard :param label: as standard :param stream_object: file-like object to read from or bytestrin...
python
def put_stream(self, bucket, label, stream_object, params=None, replace=True, add_md=True): '''Put a bitstream (stream_object) for the specified bucket:label identifier. :param bucket: as standard :param label: as standard :param stream_object: file-like object to read from or bytestrin...
[ "def", "put_stream", "(", "self", ",", "bucket", ",", "label", ",", "stream_object", ",", "params", "=", "None", ",", "replace", "=", "True", ",", "add_md", "=", "True", ")", ":", "if", "self", ".", "mode", "==", "\"r\"", ":", "raise", "OFSException", ...
Put a bitstream (stream_object) for the specified bucket:label identifier. :param bucket: as standard :param label: as standard :param stream_object: file-like object to read from or bytestring. :param params: update metadata with these params (see `update_metadata`)
[ "Put", "a", "bitstream", "(", "stream_object", ")", "for", "the", "specified", "bucket", ":", "label", "identifier", "." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipstore.py#L190-L224
okfn/ofs
ofs/local/zipstore.py
ZOFS.del_stream
def del_stream(self, bucket, label): '''Delete a bitstream. This needs more testing - file deletion in a zipfile is problematic. Alternate method is to create second zipfile without the files in question, which is not a nice method for large zip archives. ''' if self.exists(bucke...
python
def del_stream(self, bucket, label): '''Delete a bitstream. This needs more testing - file deletion in a zipfile is problematic. Alternate method is to create second zipfile without the files in question, which is not a nice method for large zip archives. ''' if self.exists(bucke...
[ "def", "del_stream", "(", "self", ",", "bucket", ",", "label", ")", ":", "if", "self", ".", "exists", "(", "bucket", ",", "label", ")", ":", "name", "=", "self", ".", "_zf", "(", "bucket", ",", "label", ")", "#z = ZipFile(self.zipfile, self.mode, self.comp...
Delete a bitstream. This needs more testing - file deletion in a zipfile is problematic. Alternate method is to create second zipfile without the files in question, which is not a nice method for large zip archives.
[ "Delete", "a", "bitstream", ".", "This", "needs", "more", "testing", "-", "file", "deletion", "in", "a", "zipfile", "is", "problematic", ".", "Alternate", "method", "is", "to", "create", "second", "zipfile", "without", "the", "files", "in", "question", "whic...
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipstore.py#L238-L246
okfn/ofs
ofs/local/zipstore.py
ZOFS.get_metadata
def get_metadata(self, bucket, label): '''Get the metadata for this bucket:label identifier. ''' if self.mode !="w": try: jsn = self._get_bucket_md(bucket) except OFSFileNotFound: # No MD found... return {} excep...
python
def get_metadata(self, bucket, label): '''Get the metadata for this bucket:label identifier. ''' if self.mode !="w": try: jsn = self._get_bucket_md(bucket) except OFSFileNotFound: # No MD found... return {} excep...
[ "def", "get_metadata", "(", "self", ",", "bucket", ",", "label", ")", ":", "if", "self", ".", "mode", "!=", "\"w\"", ":", "try", ":", "jsn", "=", "self", ".", "_get_bucket_md", "(", "bucket", ")", "except", "OFSFileNotFound", ":", "# No MD found...", "re...
Get the metadata for this bucket:label identifier.
[ "Get", "the", "metadata", "for", "this", "bucket", ":", "label", "identifier", "." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipstore.py#L265-L281
okfn/ofs
ofs/local/zipstore.py
ZOFS.update_metadata
def update_metadata(self, bucket, label, params): '''Update the metadata with the provided dictionary of params. :param parmams: dictionary of key values (json serializable). ''' if self.mode !="r": try: payload = self._get_bucket_md(bucket) excep...
python
def update_metadata(self, bucket, label, params): '''Update the metadata with the provided dictionary of params. :param parmams: dictionary of key values (json serializable). ''' if self.mode !="r": try: payload = self._get_bucket_md(bucket) excep...
[ "def", "update_metadata", "(", "self", ",", "bucket", ",", "label", ",", "params", ")", ":", "if", "self", ".", "mode", "!=", "\"r\"", ":", "try", ":", "payload", "=", "self", ".", "_get_bucket_md", "(", "bucket", ")", "except", "OFSFileNotFound", ":", ...
Update the metadata with the provided dictionary of params. :param parmams: dictionary of key values (json serializable).
[ "Update", "the", "metadata", "with", "the", "provided", "dictionary", "of", "params", "." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipstore.py#L283-L307
okfn/ofs
ofs/local/zipstore.py
ZOFS.del_metadata_keys
def del_metadata_keys(self, bucket, label, keys): '''Delete the metadata corresponding to the specified keys. ''' if self.mode !="r": try: payload = self._get_bucket_md(bucket) except OFSFileNotFound: # No MD found... raise ...
python
def del_metadata_keys(self, bucket, label, keys): '''Delete the metadata corresponding to the specified keys. ''' if self.mode !="r": try: payload = self._get_bucket_md(bucket) except OFSFileNotFound: # No MD found... raise ...
[ "def", "del_metadata_keys", "(", "self", ",", "bucket", ",", "label", ",", "keys", ")", ":", "if", "self", ".", "mode", "!=", "\"r\"", ":", "try", ":", "payload", "=", "self", ".", "_get_bucket_md", "(", "bucket", ")", "except", "OFSFileNotFound", ":", ...
Delete the metadata corresponding to the specified keys.
[ "Delete", "the", "metadata", "corresponding", "to", "the", "specified", "keys", "." ]
train
https://github.com/okfn/ofs/blob/c110cbecd7d0ae7e877963914a1a5af030cd6d45/ofs/local/zipstore.py#L309-L325
tanwanirahul/django-batch-requests
batch_requests/views.py
get_response
def get_response(wsgi_request): ''' Given a WSGI request, makes a call to a corresponding view function and returns the response. ''' service_start_time = datetime.now() # Get the view / handler for this request view, args, kwargs = resolve(wsgi_request.path_info) kwargs.update(...
python
def get_response(wsgi_request): ''' Given a WSGI request, makes a call to a corresponding view function and returns the response. ''' service_start_time = datetime.now() # Get the view / handler for this request view, args, kwargs = resolve(wsgi_request.path_info) kwargs.update(...
[ "def", "get_response", "(", "wsgi_request", ")", ":", "service_start_time", "=", "datetime", ".", "now", "(", ")", "# Get the view / handler for this request", "view", ",", "args", ",", "kwargs", "=", "resolve", "(", "wsgi_request", ".", "path_info", ")", "kwargs"...
Given a WSGI request, makes a call to a corresponding view function and returns the response.
[ "Given", "a", "WSGI", "request", "makes", "a", "call", "to", "a", "corresponding", "view", "function", "and", "returns", "the", "response", "." ]
train
https://github.com/tanwanirahul/django-batch-requests/blob/9c5afc42f7542f466247f4ffed9c44e1c49fa20d/batch_requests/views.py#L22-L53
tanwanirahul/django-batch-requests
batch_requests/views.py
get_wsgi_requests
def get_wsgi_requests(request): ''' For the given batch request, extract the individual requests and create WSGIRequest object for each. ''' valid_http_methods = ["get", "post", "put", "patch", "delete", "head", "options", "connect", "trace"] requests = json.loads(request.body) if t...
python
def get_wsgi_requests(request): ''' For the given batch request, extract the individual requests and create WSGIRequest object for each. ''' valid_http_methods = ["get", "post", "put", "patch", "delete", "head", "options", "connect", "trace"] requests = json.loads(request.body) if t...
[ "def", "get_wsgi_requests", "(", "request", ")", ":", "valid_http_methods", "=", "[", "\"get\"", ",", "\"post\"", ",", "\"put\"", ",", "\"patch\"", ",", "\"delete\"", ",", "\"head\"", ",", "\"options\"", ",", "\"connect\"", ",", "\"trace\"", "]", "requests", "...
For the given batch request, extract the individual requests and create WSGIRequest object for each.
[ "For", "the", "given", "batch", "request", "extract", "the", "individual", "requests", "and", "create", "WSGIRequest", "object", "for", "each", "." ]
train
https://github.com/tanwanirahul/django-batch-requests/blob/9c5afc42f7542f466247f4ffed9c44e1c49fa20d/batch_requests/views.py#L56-L94
tanwanirahul/django-batch-requests
batch_requests/views.py
handle_batch_requests
def handle_batch_requests(request, *args, **kwargs): ''' A view function to handle the overall processing of batch requests. ''' batch_start_time = datetime.now() try: # Get the Individual WSGI requests. wsgi_requests = get_wsgi_requests(request) except BadBatchRequest as brx...
python
def handle_batch_requests(request, *args, **kwargs): ''' A view function to handle the overall processing of batch requests. ''' batch_start_time = datetime.now() try: # Get the Individual WSGI requests. wsgi_requests = get_wsgi_requests(request) except BadBatchRequest as brx...
[ "def", "handle_batch_requests", "(", "request", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "batch_start_time", "=", "datetime", ".", "now", "(", ")", "try", ":", "# Get the Individual WSGI requests.", "wsgi_requests", "=", "get_wsgi_requests", "(", "re...
A view function to handle the overall processing of batch requests.
[ "A", "view", "function", "to", "handle", "the", "overall", "processing", "of", "batch", "requests", "." ]
train
https://github.com/tanwanirahul/django-batch-requests/blob/9c5afc42f7542f466247f4ffed9c44e1c49fa20d/batch_requests/views.py#L108-L128
KKBOX/OpenAPI-Python
kkbox_developer_sdk/search_fetcher.py
KKBOXSearchFetcher.search
def search(self, keyword, types=[], terr=KKBOXTerritory.TAIWAN): ''' Searches within KKBOX's database. :param keyword: the keyword. :type keyword: str :param types: the search types. :return: list :param terr: the current territory. :return: API response....
python
def search(self, keyword, types=[], terr=KKBOXTerritory.TAIWAN): ''' Searches within KKBOX's database. :param keyword: the keyword. :type keyword: str :param types: the search types. :return: list :param terr: the current territory. :return: API response....
[ "def", "search", "(", "self", ",", "keyword", ",", "types", "=", "[", "]", ",", "terr", "=", "KKBOXTerritory", ".", "TAIWAN", ")", ":", "url", "=", "'https://api.kkbox.com/v1.1/search'", "url", "+=", "'?'", "+", "url_parse", ".", "urlencode", "(", "{", "...
Searches within KKBOX's database. :param keyword: the keyword. :type keyword: str :param types: the search types. :return: list :param terr: the current territory. :return: API response. :rtype: dict See `https://docs-en.kkbox.codes/v1.1/reference#search...
[ "Searches", "within", "KKBOX", "s", "database", "." ]
train
https://github.com/KKBOX/OpenAPI-Python/blob/77aa22fd300ed987d5507a5b66b149edcd28047d/kkbox_developer_sdk/search_fetcher.py#L24-L42
UpCloudLtd/upcloud-python-api
upcloud_api/ip_address.py
IPAddress.save
def save(self): """ IPAddress can only change its PTR record. Saves the current state, PUT /ip_address/uuid. """ body = {'ip_address': {'ptr_record': self.ptr_record}} data = self.cloud_manager.request('PUT', '/ip_address/' + self.address, body) self._reset(**data['ip_add...
python
def save(self): """ IPAddress can only change its PTR record. Saves the current state, PUT /ip_address/uuid. """ body = {'ip_address': {'ptr_record': self.ptr_record}} data = self.cloud_manager.request('PUT', '/ip_address/' + self.address, body) self._reset(**data['ip_add...
[ "def", "save", "(", "self", ")", ":", "body", "=", "{", "'ip_address'", ":", "{", "'ptr_record'", ":", "self", ".", "ptr_record", "}", "}", "data", "=", "self", ".", "cloud_manager", ".", "request", "(", "'PUT'", ",", "'/ip_address/'", "+", "self", "."...
IPAddress can only change its PTR record. Saves the current state, PUT /ip_address/uuid.
[ "IPAddress", "can", "only", "change", "its", "PTR", "record", ".", "Saves", "the", "current", "state", "PUT", "/", "ip_address", "/", "uuid", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/ip_address.py#L32-L38
UpCloudLtd/upcloud-python-api
upcloud_api/ip_address.py
IPAddress._create_ip_address_objs
def _create_ip_address_objs(ip_addresses, cloud_manager): """ Create IPAddress objects from API response data. Also associates CloudManager with the objects. """ # ip-addresses might be provided as a flat array or as a following dict: # {'ip_addresses': {'ip_address': [.....
python
def _create_ip_address_objs(ip_addresses, cloud_manager): """ Create IPAddress objects from API response data. Also associates CloudManager with the objects. """ # ip-addresses might be provided as a flat array or as a following dict: # {'ip_addresses': {'ip_address': [.....
[ "def", "_create_ip_address_objs", "(", "ip_addresses", ",", "cloud_manager", ")", ":", "# ip-addresses might be provided as a flat array or as a following dict:", "# {'ip_addresses': {'ip_address': [...]}} || {'ip_address': [...]}", "if", "'ip_addresses'", "in", "ip_addresses", ":", "i...
Create IPAddress objects from API response data. Also associates CloudManager with the objects.
[ "Create", "IPAddress", "objects", "from", "API", "response", "data", ".", "Also", "associates", "CloudManager", "with", "the", "objects", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/ip_address.py#L54-L71
UpCloudLtd/upcloud-python-api
upcloud_api/tag.py
Tag._reset
def _reset(self, **kwargs): """ Reset the objects attributes. Accepts servers as either unflattened or flattened UUID strings or Server objects. """ super(Tag, self)._reset(**kwargs) # backup name for changing it (look: Tag.save) self._api_name = self.name ...
python
def _reset(self, **kwargs): """ Reset the objects attributes. Accepts servers as either unflattened or flattened UUID strings or Server objects. """ super(Tag, self)._reset(**kwargs) # backup name for changing it (look: Tag.save) self._api_name = self.name ...
[ "def", "_reset", "(", "self", ",", "*", "*", "kwargs", ")", ":", "super", "(", "Tag", ",", "self", ")", ".", "_reset", "(", "*", "*", "kwargs", ")", "# backup name for changing it (look: Tag.save)", "self", ".", "_api_name", "=", "self", ".", "name", "# ...
Reset the objects attributes. Accepts servers as either unflattened or flattened UUID strings or Server objects.
[ "Reset", "the", "objects", "attributes", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/tag.py#L30-L47
csirtgadgets/csirtgsdk-py
csirtgsdk/client/http.py
HTTP._get
def _get(self, uri, params={}): """ HTTP GET function :param uri: REST endpoint :param params: optional HTTP params to pass to the endpoint :return: list of results (usually a list of dicts) Example: ret = cli.get('/search', params={ 'q': 'example.org' }) ...
python
def _get(self, uri, params={}): """ HTTP GET function :param uri: REST endpoint :param params: optional HTTP params to pass to the endpoint :return: list of results (usually a list of dicts) Example: ret = cli.get('/search', params={ 'q': 'example.org' }) ...
[ "def", "_get", "(", "self", ",", "uri", ",", "params", "=", "{", "}", ")", ":", "if", "not", "uri", ".", "startswith", "(", "self", ".", "remote", ")", ":", "uri", "=", "'{}{}'", ".", "format", "(", "self", ".", "remote", ",", "uri", ")", "retu...
HTTP GET function :param uri: REST endpoint :param params: optional HTTP params to pass to the endpoint :return: list of results (usually a list of dicts) Example: ret = cli.get('/search', params={ 'q': 'example.org' })
[ "HTTP", "GET", "function" ]
train
https://github.com/csirtgadgets/csirtgsdk-py/blob/5a7ed9c5e6fa27170366ecbdef710dc80d537dc2/csirtgsdk/client/http.py#L102-L117
csirtgadgets/csirtgsdk-py
csirtgsdk/client/http.py
HTTP._post
def _post(self, uri, data): """ HTTP POST function :param uri: REST endpoint to POST to :param data: list of dicts to be passed to the endpoint :return: list of dicts, usually will be a list of objects or id's Example: ret = cli.post('/indicators', { 'indica...
python
def _post(self, uri, data): """ HTTP POST function :param uri: REST endpoint to POST to :param data: list of dicts to be passed to the endpoint :return: list of dicts, usually will be a list of objects or id's Example: ret = cli.post('/indicators', { 'indica...
[ "def", "_post", "(", "self", ",", "uri", ",", "data", ")", ":", "if", "not", "uri", ".", "startswith", "(", "self", ".", "remote", ")", ":", "uri", "=", "'{}/{}'", ".", "format", "(", "self", ".", "remote", ",", "uri", ")", "self", ".", "logger",...
HTTP POST function :param uri: REST endpoint to POST to :param data: list of dicts to be passed to the endpoint :return: list of dicts, usually will be a list of objects or id's Example: ret = cli.post('/indicators', { 'indicator': 'example.com' })
[ "HTTP", "POST", "function" ]
train
https://github.com/csirtgadgets/csirtgsdk-py/blob/5a7ed9c5e6fa27170366ecbdef710dc80d537dc2/csirtgsdk/client/http.py#L119-L135
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/server_mixin.py
ServerManager.get_servers
def get_servers(self, populate=False, tags_has_one=None, tags_has_all=None): """ Return a list of (populated or unpopulated) Server instances. - populate = False (default) => 1 API request, returns unpopulated Server instances. - populate = True => Does 1 + n API requests (n = # of serv...
python
def get_servers(self, populate=False, tags_has_one=None, tags_has_all=None): """ Return a list of (populated or unpopulated) Server instances. - populate = False (default) => 1 API request, returns unpopulated Server instances. - populate = True => Does 1 + n API requests (n = # of serv...
[ "def", "get_servers", "(", "self", ",", "populate", "=", "False", ",", "tags_has_one", "=", "None", ",", "tags_has_all", "=", "None", ")", ":", "if", "tags_has_all", "and", "tags_has_one", ":", "raise", "Exception", "(", "'only one of (tags_has_all, tags_has_one) ...
Return a list of (populated or unpopulated) Server instances. - populate = False (default) => 1 API request, returns unpopulated Server instances. - populate = True => Does 1 + n API requests (n = # of servers), returns populated Server instances. New in 0.3.0: the...
[ "Return", "a", "list", "of", "(", "populated", "or", "unpopulated", ")", "Server", "instances", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/server_mixin.py#L15-L54
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/server_mixin.py
ServerManager.get_server
def get_server(self, UUID): """ Return a (populated) Server instance. """ server, IPAddresses, storages = self.get_server_data(UUID) return Server( server, ip_addresses=IPAddresses, storage_devices=storages, populated=True, ...
python
def get_server(self, UUID): """ Return a (populated) Server instance. """ server, IPAddresses, storages = self.get_server_data(UUID) return Server( server, ip_addresses=IPAddresses, storage_devices=storages, populated=True, ...
[ "def", "get_server", "(", "self", ",", "UUID", ")", ":", "server", ",", "IPAddresses", ",", "storages", "=", "self", ".", "get_server_data", "(", "UUID", ")", "return", "Server", "(", "server", ",", "ip_addresses", "=", "IPAddresses", ",", "storage_devices",...
Return a (populated) Server instance.
[ "Return", "a", "(", "populated", ")", "Server", "instance", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/server_mixin.py#L56-L68
UpCloudLtd/upcloud-python-api
upcloud_api/cloud_manager/server_mixin.py
ServerManager.get_server_by_ip
def get_server_by_ip(self, ip_address): """ Return a (populated) Server instance by its IP. Uses GET '/ip_address/x.x.x.x' to retrieve machine UUID using IP-address. """ data = self.get_request('/ip_address/{0}'.format(ip_address)) UUID = data['ip_address']['server'] ...
python
def get_server_by_ip(self, ip_address): """ Return a (populated) Server instance by its IP. Uses GET '/ip_address/x.x.x.x' to retrieve machine UUID using IP-address. """ data = self.get_request('/ip_address/{0}'.format(ip_address)) UUID = data['ip_address']['server'] ...
[ "def", "get_server_by_ip", "(", "self", ",", "ip_address", ")", ":", "data", "=", "self", ".", "get_request", "(", "'/ip_address/{0}'", ".", "format", "(", "ip_address", ")", ")", "UUID", "=", "data", "[", "'ip_address'", "]", "[", "'server'", "]", "return...
Return a (populated) Server instance by its IP. Uses GET '/ip_address/x.x.x.x' to retrieve machine UUID using IP-address.
[ "Return", "a", "(", "populated", ")", "Server", "instance", "by", "its", "IP", "." ]
train
https://github.com/UpCloudLtd/upcloud-python-api/blob/954b0ad7c4b932b2be31a95d88975f6b0eeac8ed/upcloud_api/cloud_manager/server_mixin.py#L70-L78