text_prompt
stringlengths
157
13.1k
code_prompt
stringlengths
7
19.8k
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _parse_description(self, description_text): """Turn description to dictionary."""
text = description_text text = text.strip() lines = text.split('\n') data = {} for line in lines: if ":" in line: idx = line.index(":") key = line[:idx] value = line[idx+1:].lstrip().rstrip() data[key] ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _validate_data(data): """Validates the given data and raises an error if any non-allowed keys are provided or any required keys are missing. :param data: Dat...
data_keys = set(data.keys()) extra_keys = data_keys - set(ALLOWED_KEYS) missing_keys = set(REQUIRED_KEYS) - data_keys if extra_keys: raise ValueError( 'Invalid data keys {!r}'.format(', '.join(extra_keys)) ) if missing_keys: raise ValueError( 'Missi...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _send(data): """Send data to the Clowder API. :param data: Dictionary of API data :type data: dict """
url = data.get('url', CLOWDER_API_URL) _validate_data(data) if api_key is not None: data['api_key'] = api_key if 'value' not in data: data['value'] = data.get('status', 1) if 'frequency' in data: data['frequency'] = _clean_frequency(data['frequency']) try: r...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def submit(**kwargs): """Shortcut that takes an alert to evaluate and makes the appropriate API call based on the results. :param kwargs: A list of keyword argum...
if 'alert' not in kwargs: raise ValueError('Alert required') if 'value' not in kwargs: raise ValueError('Value required') alert = kwargs.pop('alert') value = kwargs['value'] if alert(value): fail(kwargs) else: ok(kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _clean_frequency(frequency): """Converts a frequency value to an integer. Raises an error if an invalid type is given. :param frequency: A frequency :type fr...
if isinstance(frequency, int): return frequency elif isinstance(frequency, datetime.timedelta): return int(frequency.total_seconds()) raise ValueError('Invalid frequency {!r}'.format(frequency))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def koschei_group(config, message, group=None): """ Particular Koschei package groups This rule limits message to particular `Koschei <https://apps.fedoraproject...
if not group or 'koschei' not in message['topic']: return False groups = set([item.strip() for item in group.split(',')]) return bool(groups.intersection(message['msg'].get('groups', [])))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def on_response(self, ch, method_frame, props, body): """ setup response is correlation id is the good one """
LOGGER.debug("rabbitmq.Requester.on_response") if self.corr_id == props.correlation_id: self.response = {'props': props, 'body': body} else: LOGGER.warn("rabbitmq.Requester.on_response - discarded response : " + str(props.correlation_id)) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def error(message, *args, **kwargs): """ print an error message """
print('[!] ' + message.format(*args, **kwargs)) sys.exit(1)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def parse_changes(): """ grab version from CHANGES and validate entry """
with open('CHANGES') as changes: for match in re.finditer(RE_CHANGES, changes.read(1024), re.M): if len(match.group(1)) != len(match.group(3)): error('incorrect underline in CHANGES') date = datetime.datetime.strptime(match.group(4), ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def increment_version(version): """ get the next version """
parts = [int(v) for v in version.split('.')] parts[-1] += 1 parts.append('dev0') return '.'.join(map(str, parts))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_version(version): """ set the version in the projects root module """
with open(FILENAME) as pythonfile: content = pythonfile.read() output = re.sub(RE_VERSION, r"\1'{}'".format(version), content) if content == output: error('failed updating {}'.format(FILENAME)) with open(FILENAME, 'w') as pythonfile: pythonfile.write(output)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def upload(): """ build the files and upload to pypi """
def twine(*args): """ run a twine command """ process = run(sys.executable, '-m', 'twine', *args) return process.wait() != 0 if run(sys.executable, 'setup.py', 'sdist', 'bdist_wheel').wait() != 0: error('failed building packages') if twine('register', glob.glob('dist/*')...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def check_tag(version): """ check theres not already a tag for this version """
output = run('git', 'tag', stdout=subprocess.PIPE).communicate()[0] tags = set(output.decode('utf-8').splitlines()) if 'v{}'.format(version) in tags: error('version already exists')
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def as_multi_dict(d): 'Coerce a dictionary to a bottle.MultiDict' if isinstance(d, bottle.MultiDict): return d md = bottle.MultiDict() for k, v in d.iteritems(): if isinstance(v, list): for x in v: md[k] = x else: md[k] = v return md
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def set_query_params(self, query_params): '''Set the query parameters. The query parameters should be a dictionary mapping keys to strings or lists of strings. :param query_params: query parameters :type query_params: ``name |--> (str | [str])`` :rtype: :class:`Queryabl...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def add_query_params(self, query_params): '''Overwrite the given query parameters. This is the same as :meth:`Queryable.set_query_params`, except it overwrites existing parameters individually whereas ``set_query_params`` deletes all existing key in ``query_params``. '''...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def apply_param_schema(self): '''Applies the schema defined to the given parameters. This combines the values in ``config_params`` and ``query_params``, and converts them to typed Python values per ``param_schema``. This is called automatically whenever the query parameters are...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def create_filter_predicate(self): '''Creates a filter predicate. The list of available filters is given by calls to ``add_filter``, and the list of filters to use is given by parameters in ``params``. In this default implementation, multiple filters can be specified wi...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def results(self): '''Returns results as a JSON encodable Python value. This calls :meth:`SearchEngine.recommendations` and converts the results returned into JSON encodable values. Namely, feature collections are slimmed down to only features that are useful to an end-user. ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _get_entry_link(self, entry): """ Returns a unique link for an entry """
entry_link = None for link in entry.link: if '/data/' not in link.href and '/lh/' not in link.href: entry_link = link.href break return entry_link or entry.link[0].href
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def find(value): """ returns a dictionary of rdfclasses based on the a lowercase search args: value: the value to search by """
value = str(value).lower() rtn_dict = RegistryDictionary() for attr in dir(MODULE.rdfclass): if value in attr.lower(): try: item = getattr(MODULE.rdfclass, attr) if issubclass(item, RdfClassBase): rtn_di...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list_hierarchy(class_name, bases): """ Creates a list of the class hierarchy Args: ----- class_name: name of the current class bases: list/tuple of bases for...
class_list = [Uri(class_name)] for base in bases: if base.__name__ not in IGNORE_CLASSES: class_list.append(Uri(base.__name__)) return list([i for i in set(class_list)])
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def es_get_class_defs(cls_def, cls_name): """ Reads through the class defs and gets the related es class defintions Args: ----- class_defs: RdfDataset of class d...
rtn_dict = {key: value for key, value in cls_def.items() \ if key.startswith("kds_es")} for key in rtn_dict: del cls_def[key] return rtn_dict
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_rml_processors(es_defs): """ Returns the es_defs with the instaniated rml_processor Args: ----- es_defs: the rdf_class elacticsearch defnitions cls_name:...
proc_defs = es_defs.get("kds_esRmlProcessor", []) if proc_defs: new_defs = [] for proc in proc_defs: params = proc['kds_rmlProcessorParams'][0] proc_kwargs = {} if params.get("kds_rtn_format"): proc_kwargs["rtn_format"] = params.get("kds_rtn_f...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def remove_parents(bases): """ removes the parent classes if one base is subclass of another"""
if len(bases) < 2: return bases remove_i = [] bases = list(bases) for i, base in enumerate(bases): for j, other in enumerate(bases): # print(i, j, base, other, remove_i) if j != i and (issubclass(other, base) or base == other): remove_i.append(i) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_query_kwargs(es_defs): """ Reads the es_defs and returns a dict of special kwargs to use when query for data of an instance of a class reference: rdffram...
rtn_dict = {} if es_defs: if es_defs.get("kds_esSpecialUnion"): rtn_dict['special_union'] = \ es_defs["kds_esSpecialUnion"][0] if es_defs.get("kds_esQueryFilter"): rtn_dict['filters'] = \ es_defs["kds_esQueryFilter"][0] return ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add_property(self, pred, obj): """ adds a property and its value to the class instance args: pred: the predicate/property to add obj: the value/object to add...
pred = Uri(pred) try: self[pred].append(obj) # except AttributeError: # new_list = [self[pred]] # new_list.append(obj) # self[pred] = new_list except KeyError: try: new_prop = self.properties[pred] e...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def conv_json(self, uri_format="sparql_uri", add_ids=False): """ converts the class to a json compatable python dictionary Args: uri_format('sparql_uri','pyuri')...
def convert_item(ivalue): """ converts an idividual value to a json value Args: ivalue: value of the item to convert Returns: JSON serializable value """ nvalue = ivalue if isinstance(ivalue, BaseRdfDataTy...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def bnode_id(self): """ calculates the bnode id for the class """
if self.subject.type != 'bnode': return self.subject rtn_list = [] for prop in sorted(self): for value in sorted(self[prop]): rtn_list.append("%s%s" % (prop, value)) return sha1("".join(rtn_list).encode()).hexdigest()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def es_json(self, role='rdf_class', remove_empty=True, **kwargs): """ Returns a JSON object of the class for insertion into es args: role: the role states how th...
def test_idx_status(cls_inst, **kwargs): """ Return True if the class has already been indexed in elastisearch Args: ----- cls_inst: the rdfclass instance Kwargs: ------- force[boolean]: True will return f...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_rml(self, rml_def, **kwargs): """ returns the rml mapping output for specified mapping Args: ----- rml_def: The name of the mapping or a dictionary defin...
if isinstance(rml_def, str): rml_procs = self.es_defs.get("kds_esRmlProcessor", []) for item in rml_procs: if item['name'] == rml_def: rml_def = item break proc_kwargs = {rml_def['subj']: self.subject, ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_all_rml(self, **kwargs): """ Returns a dictionary with the output of all the rml procceor results """
rml_procs = self.es_defs.get("kds_esRmlProcessor", []) role = kwargs.get('role') if role: rml_procs = [proc for proc in rml_procs if role == 'rdf_class' or proc['force']] rml_maps = {} for rml in rml_procs: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _set_subject(self, subject): """ sets the subject value for the class instance Args: subject(dict, Uri, str): the subject for the class instance """
# if not subject: # self.subject = def test_uri(value): """ test to see if the value is a uri or bnode Returns: Uri or Bnode """ # .__wrapped__ if not isinstance(value, (Uri, BlankNode)): try: if value.star...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _initilize_props(self): """ Adds an intialized property to the class dictionary """
# if self.subject == "pyuri_aHR0cDovL3R1dHQuZWR1Lw==_": # pdb.set_trace() try: # pdb.set_trace() for prop in self.es_props: self[prop] = self.properties[prop](self, self.dataset) setattr(self, prop, self[prop]) self[__a__]...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_serializer_class(self, action=None): """ Return the serializer class depending on request method. Attribute of proper serializer should be defined. """
if action is not None: return getattr(self, '%s_serializer_class' % action) else: return super(GenericViewSet, self).get_serializer_class()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_serializer(self, *args, **kwargs): """ Returns the serializer instance that should be used to the given action. If any action was given, returns the seri...
action = kwargs.pop('action', None) serializer_class = self.get_serializer_class(action) kwargs['context'] = self.get_serializer_context() return serializer_class(*args, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def open(self, autocommit=False): """Call-through to data_access.open."""
self.data_access.open(autocommit=autocommit) return self
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def close(self, commit=True): """Call-through to data_access.close."""
self.data_access.close(commit=commit) return self
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def reset(self, relation_name=None): """Reset the transfer info for a particular relation, or if none is given, for all relations. """
if relation_name is not None: self.data_access.delete("relations", dict(name=relation_name)) else: self.data_access.delete("relations", "1=1") return self
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def start_transfer(self, relation_name): """Write records to the data source indicating that a transfer has been started for a particular relation. """
self.reset(relation_name) relation = Relation(name=relation_name) self.data_access.insert_model(relation) return relation
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def register_transfer(self, relation, old_id, new_id): """Register the old and new ids for a particular record in a relation."""
transfer = Transfer(relation_id=relation.id, old_id=old_id, new_id=new_id) self.data_access.insert_model(transfer) return transfer
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def complete_transfer(self, relation, cleanup=True): """Write records to the data source indicating that a transfer has been completed for a particular relation....
relation.completed_at = utc_now().isoformat() self.data_access.update_model(relation) if cleanup: self.cleanup() return relation
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def is_transfer_complete(self, relation_name): """Checks to see if a tansfer has been completed."""
phold = self.data_access.sql_writer.to_placeholder() return self.data_access.find_model( Relation, ("name = {0} and completed_at is not null".format(phold), [relation_name])) is not None
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_new_id(self, relation_name, old_id, strict=False): """Given a relation name and its old ID, get the new ID for a relation. If strict is true, an error is...
record = self.data_access.find( "relations as r inner join transfers as t on r.id = t.relation_id", (("r.name", relation_name), ("t.old_id", old_id)), columns="new_id") if record: return record[0] else: if strict: raise KeyError("{0} with id {1} not found".format(relat...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def id_getter(self, relation_name, strict=False): """Returns a function that accepts an old_id and returns the new ID for the enclosed relation name."""
def get_id(old_id): """Get the new ID for the enclosed relation, given an old ID.""" return self.get_new_id(relation_name, old_id, strict) return get_id
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def requires_loaded(func): """ A decorator to ensure the resource data is loaded. """
def _wrapper(self, *args, **kwargs): # If we don't have data, go load it. if self._loaded_data is None: self._loaded_data = self.loader.load(self.service_name) return func(self, *args, **kwargs) return _wrapper
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def full_update_params(self, conn_method_name, params): """ When a API method on the collection is called, this goes through the params & run a series of hooks t...
# We'll check for custom methods to do addition, specific work. custom_method_name = 'update_params_{0}'.format(conn_method_name) custom_method = getattr(self, custom_method_name, None) if custom_method: # Let the specific method further process the data. params...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def full_post_process(self, conn_method_name, result): """ When a response from an API method call is received, this goes through the returned data & run a serie...
result = self.post_process(conn_method_name, result) # We'll check for custom methods to do addition, specific work. custom_method_name = 'post_process_{0}'.format(conn_method_name) custom_method = getattr(self, custom_method_name, None) if custom_method: # Let the...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def construct_for(self, service_name, collection_name, base_class=None): """ Builds a new, specialized ``Collection`` subclass as part of a given service. This w...
details = self.details_class( self.session, service_name, collection_name, loader=self.loader ) attrs = { '_details': details, } # Determine what we should call it. klass_name = self._build_class_name(collecti...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def BFS(G, start): """ Algorithm for breadth-first searching the vertices of a graph. """
if start not in G.vertices: raise GraphInsertError("Vertex %s doesn't exist." % (start,)) color = {} pred = {} dist = {} queue = Queue() queue.put(start) for vertex in G.vertices: color[vertex] = 'white' pred[vertex] = None dist[vertex] = 0 wh...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def BFS_Tree(G, start): """ Return an oriented tree constructed from bfs starting at 'start'. """
if start not in G.vertices: raise GraphInsertError("Vertex %s doesn't exist." % (start,)) pred = BFS(G, start) T = digraph.DiGraph() queue = Queue() queue.put(start) while queue.qsize() > 0: current = queue.get() for element in pred: if pred[element...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def DFS(G): """ Algorithm for depth-first searching the vertices of a graph. """
if not G.vertices: raise GraphInsertError("This graph have no vertices.") color = {} pred = {} reach = {} finish = {} def DFSvisit(G, current, time): color[current] = 'grey' time += 1 reach[current] = time for vertex in G.vertices[current]: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def DFS_Tree(G): """ Return an oriented tree constructed from dfs. """
if not G.vertices: raise GraphInsertError("This graph have no vertices.") pred = {} T = digraph.DiGraph() vertex_data = DFS(G) for vertex in vertex_data: pred[vertex] = vertex_data[vertex][0] queue = Queue() for vertex in pred: if pred[vertex] == None: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def exception_handler_v20(status_code, error_content): """Exception handler for API v2.0 client. This routine generates the appropriate Neutron exception accordi...
error_dict = None request_ids = error_content.request_ids if isinstance(error_content, dict): error_dict = error_content.get('NeutronError') # Find real error type client_exc = None if error_dict: # If Neutron key is found, it will definitely contain # a 'message' and 't...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _append_request_ids(self, resp): """Add request_ids as an attribute to the object :param resp: Response object or list of Response objects """
if isinstance(resp, list): # Add list of request_ids if response is of type list. for resp_obj in resp: self._append_request_id(resp_obj) elif resp is not None: # Add request_ids if response contains single object. self._append_request_id(...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def serialize(self, data): """Serializes a dictionary into JSON. A dictionary with a single key can be passed and it can contain any structure. """
if data is None: return None elif isinstance(data, dict): return serializer.Serializer().serialize(data) else: raise Exception(_("Unable to serialize object of type = '%s'") % type(data))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def deserialize(self, data, status_code): """Deserializes a JSON string into a dictionary."""
if status_code == 204: return data return serializer.Serializer().deserialize( data)['body']
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def retry_request(self, method, action, body=None, headers=None, params=None): """Call do_request with the default retry configuration. Only idempotent requests ...
max_attempts = self.retries + 1 for i in range(max_attempts): try: return self.do_request(method, action, body=body, headers=headers, params=params) except exceptions.ConnectionFailed: # Exception has already...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list_ext(self, collection, path, retrieve_all, **_params): """Client extension hook for list."""
return self.list(collection, path, retrieve_all, **_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def show_ext(self, path, id, **_params): """Client extension hook for show."""
return self.get(path % id, params=_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update_ext(self, path, id, body=None): """Client extension hook for update."""
return self.put(path % id, body=body)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def show_quota(self, project_id, **_params): """Fetch information of a certain project's quotas."""
return self.get(self.quota_path % (project_id), params=_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update_quota(self, project_id, body=None): """Update a project's quotas."""
return self.put(self.quota_path % (project_id), body=body)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def show_extension(self, ext_alias, **_params): """Fetches information of a certain extension."""
return self.get(self.extension_path % ext_alias, params=_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list_ports(self, retrieve_all=True, **_params): """Fetches a list of all ports for a project."""
# Pass filters in "params" argument to do_request return self.list('ports', self.ports_path, retrieve_all, **_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def show_port(self, port, **_params): """Fetches information of a certain port."""
return self.get(self.port_path % (port), params=_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update_port(self, port, body=None): """Updates a port."""
return self.put(self.port_path % (port), body=body)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list_networks(self, retrieve_all=True, **_params): """Fetches a list of all networks for a project."""
# Pass filters in "params" argument to do_request return self.list('networks', self.networks_path, retrieve_all, **_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def show_network(self, network, **_params): """Fetches information of a certain network."""
return self.get(self.network_path % (network), params=_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update_network(self, network, body=None): """Updates a network."""
return self.put(self.network_path % (network), body=body)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list_subnets(self, retrieve_all=True, **_params): """Fetches a list of all subnets for a project."""
return self.list('subnets', self.subnets_path, retrieve_all, **_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def show_subnet(self, subnet, **_params): """Fetches information of a certain subnet."""
return self.get(self.subnet_path % (subnet), params=_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update_subnet(self, subnet, body=None): """Updates a subnet."""
return self.put(self.subnet_path % (subnet), body=body)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list_subnetpools(self, retrieve_all=True, **_params): """Fetches a list of all subnetpools for a project."""
return self.list('subnetpools', self.subnetpools_path, retrieve_all, **_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def show_subnetpool(self, subnetpool, **_params): """Fetches information of a certain subnetpool."""
return self.get(self.subnetpool_path % (subnetpool), params=_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update_subnetpool(self, subnetpool, body=None): """Updates a subnetpool."""
return self.put(self.subnetpool_path % (subnetpool), body=body)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list_routers(self, retrieve_all=True, **_params): """Fetches a list of all routers for a project."""
# Pass filters in "params" argument to do_request return self.list('routers', self.routers_path, retrieve_all, **_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def show_router(self, router, **_params): """Fetches information of a certain router."""
return self.get(self.router_path % (router), params=_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update_router(self, router, body=None): """Updates a router."""
return self.put(self.router_path % (router), body=body)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list_address_scopes(self, retrieve_all=True, **_params): """Fetches a list of all address scopes for a project."""
return self.list('address_scopes', self.address_scopes_path, retrieve_all, **_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def show_address_scope(self, address_scope, **_params): """Fetches information of a certain address scope."""
return self.get(self.address_scope_path % (address_scope), params=_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update_address_scope(self, address_scope, body=None): """Updates a address scope."""
return self.put(self.address_scope_path % (address_scope), body=body)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add_interface_router(self, router, body=None): """Adds an internal network interface to the specified router."""
return self.put((self.router_path % router) + "/add_router_interface", body=body)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def remove_interface_router(self, router, body=None): """Removes an internal network interface from the specified router."""
return self.put((self.router_path % router) + "/remove_router_interface", body=body)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add_gateway_router(self, router, body=None): """Adds an external network gateway to the specified router."""
return self.put((self.router_path % router), body={'router': {'external_gateway_info': body}})
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list_floatingips(self, retrieve_all=True, **_params): """Fetches a list of all floatingips for a project."""
# Pass filters in "params" argument to do_request return self.list('floatingips', self.floatingips_path, retrieve_all, **_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def show_floatingip(self, floatingip, **_params): """Fetches information of a certain floatingip."""
return self.get(self.floatingip_path % (floatingip), params=_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update_floatingip(self, floatingip, body=None): """Updates a floatingip."""
return self.put(self.floatingip_path % (floatingip), body=body)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update_security_group(self, security_group, body=None): """Updates a security group."""
return self.put(self.security_group_path % security_group, body=body)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list_security_groups(self, retrieve_all=True, **_params): """Fetches a list of all security groups for a project."""
return self.list('security_groups', self.security_groups_path, retrieve_all, **_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def show_security_group(self, security_group, **_params): """Fetches information of a certain security group."""
return self.get(self.security_group_path % (security_group), params=_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list_security_group_rules(self, retrieve_all=True, **_params): """Fetches a list of all security group rules for a project."""
return self.list('security_group_rules', self.security_group_rules_path, retrieve_all, **_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def show_security_group_rule(self, security_group_rule, **_params): """Fetches information of a certain security group rule."""
return self.get(self.security_group_rule_path % (security_group_rule), params=_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list_endpoint_groups(self, retrieve_all=True, **_params): """Fetches a list of all VPN endpoint groups for a project."""
return self.list('endpoint_groups', self.endpoint_groups_path, retrieve_all, **_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def show_endpoint_group(self, endpointgroup, **_params): """Fetches information for a specific VPN endpoint group."""
return self.get(self.endpoint_group_path % endpointgroup, params=_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update_endpoint_group(self, endpoint_group, body=None): """Updates a VPN endpoint group."""
return self.put(self.endpoint_group_path % endpoint_group, body=body)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list_vpnservices(self, retrieve_all=True, **_params): """Fetches a list of all configured VPN services for a project."""
return self.list('vpnservices', self.vpnservices_path, retrieve_all, **_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def show_vpnservice(self, vpnservice, **_params): """Fetches information of a specific VPN service."""
return self.get(self.vpnservice_path % (vpnservice), params=_params)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def update_vpnservice(self, vpnservice, body=None): """Updates a VPN service."""
return self.put(self.vpnservice_path % (vpnservice), body=body)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def list_ipsec_site_connections(self, retrieve_all=True, **_params): """Fetches all configured IPsecSiteConnections for a project."""
return self.list('ipsec_site_connections', self.ipsec_site_connections_path, retrieve_all, **_params)