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 workflow_transition(self, issue, status_name): """ Change the status of a JIRA issue to a named status. Will only be updated if this transition is available ...
transitions = self.transitions(issue) for transition in transitions: if transition['to']['name'] == status_name: transition_id = transition['id'] self.transition_issue(issue, transition_id) print "Changed status of issue %s to %s" % (issue.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 get_datetime_issue_in_progress(self, issue): """ If the issue is in progress, gets that most recent time that the issue became 'In Progress' """
histories = issue.changelog.histories for history in reversed(histories): history_items = history.items for item in history_items: if item.field == 'status' and item.toString == "In Progress": return dateutil.parser.parse(history.created)
<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_cycle_time(self, issue_or_start_or_key): """ Provided an issue or a start datetime, will return the cycle time since the start or progress """
if isinstance(issue_or_start_or_key, basestring): issue_or_start_or_key = self.get_issue(issue_or_start_or_key) if isinstance(issue_or_start_or_key, jira.resources.Issue): progress_started = self.get_datetime_issue_in_progress(issue_or_start_or_key) elif isinstance(issu...
<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_week_avg_cycletime(self): """ Gets the average cycletime of the current user for the past week. This includes any ticket that was marked "In Progress" bu...
def moving_average(new_val, old_avg, prev_n): return (new_val + old_avg) / (prev_n + 1) active_tickets_jql = 'assignee=currentUser() and status was "In Progress" DURING (startOfWeek(), endofweek()) and status not in (Backlog, Open) ORDER BY updated DESC' week_active_tickets = 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 b6_evalue_filter(handle, e_value, *args, **kwargs): """Yields lines from handle with E-value less than or equal to e_value Args: handle (file): B6/M8 file h...
for entry in b6_iter(handle, *args, **kwargs): if entry.evalue <= e_value: yield entry
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def value(self): """ Return the current evaluation of a condition statement """
return ''.join(map(str, self.evaluate(self.trigger.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_judged_identifiers(input_file): """ Extracts the paragraph identifiers, and the scores of the judged paragraphs from relevance judgements in the NTCIR-11...
for line in tqdm(list(input_file)): _, __, identifier, score = line.split(' ') yield (identifier, float(score))
<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_identifiers(dataset): """ Extracts paragraph identifiers from a dataset in the NTCIR-11 Math-2, and NTCIR-12 MathIR XHTML5 format. Parameters dataset...
for document in tqdm( dataset.glob("**/*.xhtml.zip"), desc="get_all_identifiers(%s)" % dataset.name): identifier = get_identifier(document) directory = document.parents[0] yield (directory, identifier)
<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_position(directory, identifier): """ Extracts the position of a paragraph from the identifier, and the parent directory of the paragraph. Parameters dire...
paragraph_number = get_paragraph_number(identifier) paragraph_total = max( # Not all paragraphs are stored, e.g. because of processing errors. get_paragraph_number(get_identifier(document)) + 1 for document in directory.iterdir()) assert paragraph_total > paragraph_number and paragraph_tot...
<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_positions(dataset, num_workers=1): """ Extracts paragraph identifiers, and positions from a dataset in the NTCIR-11 Math-2, and NTCIR-12 MathIR XHTML...
positions = [] identifiers = tqdm( list(get_all_identifiers(dataset)), desc="get_all_positions(%s)" % dataset.name) with Pool(num_workers) as pool: for directory, identifier, position in pool.map(_get_position_worker, identifiers): positions.append((directory, identifier, positi...
<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_estimators(positions_all, positions_relevant): """ Extracts density estimators from a judged sample of paragraph positions. Parameters positions_all : di...
samples_all = [ (position,) for _, positions in positions_all.items() for position in positions] samples_relevant = [ (position,) for _, positions in positions_relevant.items() for position in positions] estimators = dict() estimators["P(relevant)"] = len(samples_relevant) / len(samples...
<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_estimates(estimators_tuple, positions, num_workers=1): """ Estimates densities, and probabilities for paragraph positions. Parameters estimators_tuple : ...
estimators = dict() estimators["P(relevant)"], estimators["p(position)"], \ estimators["p(position|relevant)"] = estimators_tuple log_estimates = dict() log_estimates["P(relevant)"] = log(estimators["P(relevant)"]) X = [(position,) for position in positions] with Pool(num_workers) as p...
<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_build_command(self, mkdocs_site_path: Path) -> str: '''Generate ``mkdocs build`` command to build the site. :param mkdocs_site_path: Path to the output directory for the site ''' components = [self._mkdocs_config.get('mkdocs_path', 'mkdocs')] components.append('build')...
<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_ghp_command(self) -> str: '''Generate ``mkdocs gh-deploy`` command to deploy the site to GitHub Pages.''' components = [self._mkdocs_config.get('mkdocs_path', 'mkdocs')] components.append('gh-deploy') command = ' '.join(components) self.logger.debug(f'GHP upload comma...
<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_page_with_optional_heading(self, page_file_path: str) -> str or Dict: '''Get the content of first heading of source Markdown file, if the file contains any headings. Return a data element of ``pages`` section of ``mkdocs.yml`` file. :param page_file_path: path to source Markdow...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def wrap_json(func=None, *, encoder=json.JSONEncoder, preserve_raw_body=False): """ A middleware that parses the body of json requests and encodes the json respo...
if func is None: return functools.partial( wrap_json, encoder=encoder, preserve_raw_body=preserve_raw_body ) wrapped_func = wrap_json_body(func, preserve_raw_body=preserve_raw_body) wrapped_func = wrap_json_response(wrapped_func, encoder=encoder) re...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def wrap_json_params(func): """ A middleware that parses the body of json requests and add it to the request under the `params` key. """
@functools.wraps(func) def wrapper(request, *args, **kwargs): ctype, pdict = parse_header(request.headers.get('Content-Type', '')) if ctype == "application/json": request.params = json.loads(request.body.decode("utf-8")) if request.body else None return func(request, *args,...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def run(itf): """ Run preprocess functions """
if not itf: return 1 # access command-line arguments options = SplitInput(itf) # read input infile = os.path.abspath(options.input) molList = read_csv(infile, options) # split molList into actives and decoys activeList, decoyList = partition(molList, options) # split ac...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def write_csv_header(mol, csv_writer): """ Write the csv header """
# create line list where line elements for writing will be stored line = [] # ID line.append('id') # status line.append('status') # query labels queryList = mol.properties.keys() for queryLabel in queryList: line.append(queryLabel) # write line csv_writer.writer...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def write_csv_line(mol, csv_writer, options): """ Parse mol object and write a line to the csv file """
# set variables status_field = options.status_field # elements for writing will be stored in the line list line = [] # ID id = mol.GetProp('id') if id is not None: line.append(id) else: line.append('n/a') # status line.append(mol.GetProp(status_field)) #...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def csv_writer(molecules, options, prefix): """ Write a csv file. """
# output file outdir = os.getcwd() filename = prefix + '.csv' outfile = os.path.join(outdir, filename) # initiate csv writer object f = open(outfile, 'w') csv_writer = csv.writer(f) # write csv header mol = molecules[0] write_csv_header(mol, csv_writer) # write csv lines...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def split(activeList, decoyList, options): """ Create training and validation sets """
# set input variables training_fraction = options.training_fraction decoy_to_active = options.decoy_to_active # take care of default decoy_to_active ratio if decoy_to_active is None: decoy_to_active = len(decoyList) / len(activeList) # verify that there are enough molecules to satisf...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def partition(molList, options): """ Partition molList into activeList and decoyList """
# set input variables status_field = options.status_field active_label = options.active_label decoy_label = options.decoy_label # initiate lists activeList = [] decoyList = [] # partition moList for mol in molList: if mol.GetProp(status_field) == active_label: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def read_csv(csvfile, options): """ Read csv and return molList, a list of mol objects """
# open file or exit name, ext = os.path.splitext(csvfile) try: if ext == '.gz': f = gzip.open(csvfile, 'rb') else: f = open(csvfile, 'rU') except IOError: print(" \n '{f}' could not be opened\n".format(f=os.path.basename(csvfile))) 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 read(self, input_file): """ Reads an InputHeader from `input_file`. The input header is read as a sequence of *<key>***:***<value>* pairs separated by a newl...
key, value = None, None import sys for line in input_file: if line == '\n': break if line[-1:] == '\n': line = line[:-1] item = line.split(':', 1) if len(item) == 2: # start of a new item ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def write(self, output_file): """ Writes this MessageHeader to an output stream. Messages are written as a sequence of *<message_text-message_level>***=** *<mess...
for message_level, message_text in self: output_file.write('%s=%s\r\n' % (message_level, message_text)) output_file.write('\r\n')
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def callback(self, event): """ Selects cells on click. """
self.init_width() if len(self.initial) > 0: for cell in self.initial: self.color_square(cell[0], cell[1], True) self.initial = [] self.begin_drag = event self.color_square(event.x, event.y)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def init_width(self): """ Get rectangle diameters """
self.col_width = self.c.winfo_width()/self.cols self.row_height = self.c.winfo_height()/self.rows
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def color_square(self, x, y, unit_coords=False): """ Handles actually coloring the squares """
# Calculate column and row number if unit_coords: col = x row = y else: col = x//self.col_width row = y//self.row_height # If the tile is not filled, create a rectangle if not self.tiles[row][col]: self.tiles[row][col]...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def dragend(self, event): """ Handles the end of a drag action. """
x_range = [self.begin_drag.x//self.col_width, event.x//self.col_width] y_range = [self.begin_drag.y//self.row_height, event.y//self.row_height] # Check bounds for i in range(2): for ls in [x_range, y_range]: if ls[i] < 0: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _lower_if_str(item): """ Try to convert item to lowercase, if it is string. Args: item (obj): Str, unicode or any other object. Returns: obj: ``item.lower()...
# python 2 / 3 shill try: string_type = basestring except NameError: string_type = str if isinstance(item, string_type): return item.lower() return item
<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_repo_relpath(repo, relpath): """Returns the absolute path to the 'relpath' taken relative to the base directory of the repository. """
from os import path if relpath[0:2] == "./": return path.join(repo, relpath[2::]) else: from os import chdir, getcwd cd = getcwd() chdir(path.expanduser(repo)) result = path.abspath(relpath) chdir(cd) return result
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def load_with_datetime(pairs): """Deserialize JSON into python datetime objects."""
d = {} for k, v in pairs: if isinstance(v, basestring): try: d[k] = dateutil.parser.parse(v) except ValueError: d[k] = v else: d[k] = v return d
<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_json(jsonpath, default): """Returns the JSON serialized object at the specified path, or the default if it doesn't exist or can't be deserialized. """
from os import path import json result = default if path.isfile(jsonpath): try: with open(jsonpath) as f: result = json.load(f, object_pairs_hook=load_with_datetime) except(IOError): err("Unable to deserialize JSON at {}".format(jsonpath)) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def run_exec(repodir, command, output, index): """Runs the specified command in the repo directory. :arg repodir: the absolute path of the repo directory to run ...
from os import path from subprocess import Popen, PIPE from datetime import datetime child = Popen("cd {}; {} > {}.cidat".format(repodir, command, index), shell=True, executable="/bin/bash") # Need to do this so that we are sure the process is done before moving on child....
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def load_class(location: str) -> type: """ Loads a class from a string and returns it. <class 'arca.backend.base.BaseBackend'> :raise ArcaMisconfigured: If the cl...
module_name, _, class_name = location.rpartition(".") if not module_name: raise ArcaMisconfigured(f"The module is not specified, can't load class from '{location}'") try: imported_module = importlib.import_module(module_name) return getattr(imported_module, class_name) except ...
<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_hash_for_file(repo: Repo, path: Union[str, Path]) -> str: """ Returns the hash for the specified path. Equivalent to ``git rev-parse HEAD:X`` :param repo:...
return repo.git.rev_parse(f"HEAD:{str(path)}")
<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(self, *keys: str, default: Any = NOT_SET) -> Any: """ Returns values from the settings in the order of keys, the first value encountered is used. Example:...
if not len(keys): raise ValueError("At least one key must be provided.") for option in keys: key = f"{self.PREFIX}_{option.upper()}" if key in self._data: return self._data[key] if default is NOT_SET: raise KeyError("None of 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 batch(items, size): """Batches a list into a list of lists, with sub-lists sized by a specified batch size."""
return [items[x:x + size] for x in xrange(0, len(items), size)]
<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_storage(key, username): """Returns the Storage class compatible with the current environment."""
if IS_APPENGINE and appengine: return appengine.StorageByKeyName( appengine.CredentialsModel, username, 'credentials') file_name = os.path.expanduser('~/.config/webreview/{}_{}'.format(key, username)) dir_name = os.path.dirname(file_name) if not os.path.exists(dir_name): os....
<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_record(self, record): """Remove all fields with `None` values"""
for k, v in dict(record).items(): if isinstance(v, dict): v = self._clean_record(v) if v is None: record.pop(k) return record
<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, root, records): """Serialize the payload into JSON"""
logging.info("Serializing record") logging.debug("Root: {}".format(root)) logging.debug("Records: {}".format(records)) if records == {}: return '{}' if isinstance(records, dict): if list(records.keys())[0] == 'errors': logging.warning("Fou...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def rule(ctxt, name): """ Allows evaluation of another rule while evaluating a rule. :param ctxt: The evaluation context for the rule. :param name: The name of t...
# If the result of evaluation is in the rule cache, bypass # evaluation if name in ctxt.rule_cache: ctxt.stack.append(ctxt.rule_cache[name]) return # Obtain the rule we're to evaluate try: rule = ctxt.policy[name] except KeyError: # Rule doesn't exist; log a me...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def resolve(self, symbol): """ Resolve a symbol encountered during a rule evaluation into the actual value for that symbol. :param symbol: The symbol being resol...
# Try the variables first if symbol in self.variables: return self.variables[symbol] return self.policy.resolve(symbol)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def push_rule(self, name): """ Allow one rule to be evaluated in the context of another. This allows keeping track of the rule names during nested rule evaluatio...
# Verify that we haven't been evaluating the rule already; # this is to prohibit recursive rules from locking us up... if name in self._name: raise PolicyException( "Rule recursion detected; invocation chain: %s -> %s" % (' -> '.join(self._name), nam...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def declare(self, name, text='', doc=None, attrs=None, attr_docs=None): """ Declare a rule. This allows a default for a given rule to be set, along with default ...
self._defaults[name] = rules.Rule(name, text, attrs) self._docs[name] = rules.RuleDoc(name, doc, attr_docs) return self._defaults[name]
<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_doc(self, name): """ Retrieve a ``RuleDoc`` object from the ``Policy`` with the given name. The ``RuleDoc`` object contains all documentation for the nam...
# Create one if there isn't one already if name not in self._docs: self._docs[name] = rules.RuleDoc(name) return self._docs[name]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def resolve(self, symbol): """ Resolve a symbol using the entrypoint group. :param symbol: The symbol being resolved. :returns: The value of that symbol. If the ...
# Search for a corresponding symbol if symbol not in self._resolve_cache: result = None # Search through entrypoints only if we have a group if self._group is not None: for ep in pkg_resources.iter_entry_points(self._group, symbol): ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def evaluate(self, name, variables=None): """ Evaluate a named rule. :param name: The name of the rule to evaluate. :param variables: An optional dictionary of v...
# Get the rule and predeclaration rule = self._rules.get(name) default = self._defaults.get(name) # Short-circuit if we don't have either if rule is None and default is None: return authorization.Authorization(False) # Marry the attribute defaults ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def from_string(cls, pid): """Parse a PID from its string representation. PIDs may be represented as name@ip:port, e.g. .. code-block:: python pid = PID.from_str...
try: id_, ip_port = pid.split('@') ip, port = ip_port.split(':') port = int(port) except ValueError: raise ValueError('Invalid PID: %s' % pid) return cls(ip, port, 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 set_as_object(self, index = None, value= None): """ Sets a new value to array element specified by its index. When the index is not defined, it resets the en...
if index == None and value != None: self.set_as_array(value) else: self[index] = value
<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_as_array(self, index): """ Converts array element into an AnyValueArray or returns empty AnyValueArray if conversion is not possible. :param index: an in...
if index == None: array = [] for value in self: array.append(value) return array else: value = self[index] return AnyValueArray.from_value(value)
<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_as_string_with_default(self, index, default_value): """ Converts array element into a string or returns default value if conversion is not possible. :par...
value = self[index] return StringConverter.to_string_with_default(value, default_value)
<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_as_boolean_with_default(self, index, default_value): """ Converts array element into a boolean or returns default value if conversion is not possible. :p...
value = self[index] return BooleanConverter.to_boolean_with_default(value, default_value)
<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_as_integer_with_default(self, index, default_value): """ Converts array element into an integer or returns default value if conversion is not possible. :...
value = self[index] return IntegerConverter.to_integer_with_default(value, default_value)
<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_as_float_with_default(self, index, default_value): """ Converts array element into a float or returns default value if conversion is not possible. :param...
value = self[index] return FloatConverter.to_float_with_default(value, default_value)
<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_as_datetime_with_default(self, index, default_value): """ Converts array element into a Date or returns default value if conversion is not possible. :par...
value = self[index] return DateTimeConverter.to_datetime_with_default(value, default_value)
<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_as_nullable_type(self, index, value_type): """ Converts array element into a value defined by specied typecode. If conversion is not possible it returns ...
value = self[index] return TypeConverter.to_nullable_type(value_type, value)
<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_as_type(self, index, value_type): """ Converts array element into a value defined by specied typecode. If conversion is not possible it returns default v...
value = self[index] return TypeConverter.to_type(value_type, value)
<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_as_type_with_default(self, index, value_type, default_value): """ Converts array element into a value defined by specied typecode. If conversion is not p...
value = self[index] return TypeConverter.to_type_with_default(value_type, value, default_value)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def contains(self, value): """ Checks if this array contains a value. The check uses direct comparison between elements and the specified value. :param value: a ...
str_value = StringConverter.to_nullable_string(value) for element in self: str_element = StringConverter.to_string(element) if str_value == None and str_element == None: return True if str_value == None or str_element == None: contin...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def contains_as_type(self, value_type, value): """ Checks if this array contains a value. The check before comparison converts elements and the value to type spe...
typed_value = TypeConverter.to_nullable_type(value_type, value) for element in self: typed_element = TypeConverter.to_type(value_type, element) if typed_value == None and typed_element == None: return True if typed_value == None or typed_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 from_value(value): """ Converts specified value into AnyValueArray. :param value: value to be converted :return: a newly created AnyValueArray. """
value = ArrayConverter.to_nullable_array(value) if value != None: return AnyValueArray(value) return AnyValueArray()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def from_string(values, separator, remove_duplicates = False): """ Splits specified string into elements using a separator and assigns the elements to a newly cr...
result = AnyValueArray() if values == None or len(values) == 0: return result items = str(values).split(separator) for item in items: if (item != None and len(item) > 0) or remove_duplicates == False: result.append(item) return result
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def paint(self, painter, option, index): """Use the painter and style option to render the item specified by the item index. :param painter: the painter to paint...
if self._widget is None: return super(WidgetDelegate, self).paint(painter, option, index) self.set_widget_index(index) painter.save() painter.translate(option.rect.topLeft()) self._widget.resize(option.rect.size()) self._widget.render(painter, QtCore.QPoint(...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def sizeHint(self, option, index): """Return the appropriate amount for the size of the widget The widget will always be expanded to at least the size of the vie...
if self._widget is None: return super(WidgetDelegate, self).sizeHint(option, index) self.set_widget_index(index) self._widget.resize(option.rect.size()) sh = self._widget.sizeHint() return sh
<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_editors(self, ): """Close all current editors :returns: None :rtype: None :raises: None """
for k in reversed(self._edit_widgets.keys()): self.commit_close_editor(k)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createEditor(self, parent, option, index): """Return the editor to be used for editing the data item with the given index. Note that the index contains infor...
# close all editors self.close_editors() e = self.create_editor_widget(parent, option, index) if e: self._edit_widgets[index] = e e.setAutoFillBackground(True) e.destroyed.connect(partial(self.editor_destroyed, index=index)) return 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 commit_close_editor(self, index, endedithint=QtGui.QAbstractItemDelegate.NoHint): """Commit and close the editor Call this method whenever the user finished ...
editor = self._edit_widgets[index] self.commitData.emit(editor) self.closeEditor.emit(editor, endedithint) del self._edit_widgets[index]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def updateEditorGeometry(self, editor, option, index): """Make sure the editor is the same size as the widget By default it can get smaller because does not expa...
super(WidgetDelegate, self).updateEditorGeometry(editor, option, index) editor.setGeometry(option.rect) if self.keep_editor_size: esh = editor.sizeHint() osh = option.rect.size() w = osh.width() if osh.width() > esh.width() else esh.width() h = os...
<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_pos_in_delegate(self, index, globalpos): """Map the global position to the position relative to the given index :param index: the index to map to :type i...
rect = self.visualRect(index) # rect of the index p = self.viewport().mapToGlobal(rect.topLeft()) return globalpos - p
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def propagate_event_to_delegate(self, event, eventhandler): """Propagate the given Mouse event to the widgetdelegate Enter edit mode, get the editor widget and i...
# if we are recursing because we sent a click event, and it got propagated to the parents # and we recieve it again, terminate if self.__recursing: return # find index at mouse position i = self.index_at_event(event) # if the index is not valid, we don't car...
<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_total_indentation(self, index): """Get the indentation for the given index :param index: the index to query :type index: :class:`QtCore.ModelIndex` :retu...
n = 0 while index.isValid(): n += 1 index = index.parent() return n * self.indentation()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def render(self, f_buf=None): """ Write to the dest buffer :param obj f_buf: A file buffer supporting the write and seek methods """
if f_buf is None: f_buf = StringIO.StringIO() headers = getattr(self, 'headers', ()) keys = [ force_encoding(header['label'], self.encoding) for header in headers ] extra_headers = getattr(self, 'extra_headers', ()) keys.extend([ ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def format_row(self, row): """ Format the row to fit our export switch the key used to store it in the dict since csv writer is expecting dict with keys matching...
res_dict = {} headers = getattr(self, 'headers', []) extra_headers = getattr(self, 'extra_headers', []) for header in tuple(headers) + tuple(extra_headers): name, label = header['name'], header['label'] val = row.get(name) if val is 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 set_headers(self, headers): """ Set the headers of our csv writer :param list headers: list of dict with label and name key (label is mandatory : used for th...
self.headers = [] if 'order' in self.options: for element in self.options['order']: for header in headers: if header['key'] == element: self.headers.append(header) break else: self.header...
<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_style(primary=None, secondary=None): """ Sets primary and secondary component styles. """
global _primary_style, _secondary_style if primary: _primary_style = primary if secondary: _secondary_style = secondary
<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_char(key, value): """ Updates charters used to render components. """
global _chars category = _get_char_category(key) if not category: raise KeyError _chars[category][key] = value
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def ascii_mode(enabled=True): """ Disables color and switches to an ASCII character set if True. """
global _backups, _chars, _primary_style, _secondary_style, _ascii_mode if not (enabled or _backups) or (enabled and _ascii_mode): return if enabled: _backups = _chars.copy(), _primary_style, _secondary_style _chars = { "primary": {"selected": "*", "block": "#"}, ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def sam_verifier(entries, line=None): """Raises error if invalid SAM format detected Args: entries (list): A list of SamEntry instances line (int): Line number...
regex = r'^[!-?A-~]{1,255}\t' \ + r'([0-9]{1,4}|[0-5][0-9]{4}|' \ + r'[0-9]{1,4}|[1-5][0-9]{4}|' \ + r'6[0-4][0-9]{3}|65[0-4][0-9]{2}|' \ + r'655[0-2][0-9]|6553[0-7])\t' \ + r'\*|[!-()+-<>-~][!-~]*\t' \ + r'([0-9]{1,9}|1[0-9]{9}|2(0[0-9]{8}|'...
<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(self, message, *args, **kwargs): """ Send the the `message` to the broker. :param message: The message to send. Its type depends on the serializer used....
routing_keys = kwargs.get('routing_key') or self.routing_key routing_keys = [routing_keys] if isinstance(routing_keys, basestring) else routing_keys correlation_id = kwargs.get('correlation_id', None) reply_to = kwargs.get('reply_to', None) declare=[self.exchange] + kwargs.get('...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def exit_with_error(message): """ Display formatted error message and exit call """
click.secho(message, err=True, bg='red', fg='white') sys.exit(0)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def main(search_engine, search_option, list_engines, query): """Quick search command tool for your terminal"""
engine_data = {} if list_engines: for name in engines: conf = get_config(name) optionals = filter(lambda e: e != 'default', conf.keys()) if optionals: click.echo('{command} -o {options}'.format( command=name.replace('.json', ''), ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _load_db(): """Deserializes the script database from JSON."""
from os import path from pyci.utility import get_json global datapath, db datapath = path.abspath(path.expanduser(settings.datafile)) vms("Deserializing DB from {}".format(datapath)) db = get_json(datapath, {"installed": [], "enabled": True, "cron": False})
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _save_db(): """Serializes the contents of the script db to JSON."""
from pyci.utility import json_serial import json vms("Serializing DB to JSON in {}".format(datapath)) with open(datapath, 'w') as f: json.dump(db, f, default=json_serial)
<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_virtualenv(): """Makes sure that the virtualenv specified in the global settings file actually exists. """
from os import waitpid from subprocess import Popen, PIPE penvs = Popen("source /usr/local/bin/virtualenvwrapper.sh; workon", shell=True, executable="/bin/bash", stdout=PIPE, stderr=PIPE) waitpid(penvs.pid, 0) envs = penvs.stdout.readlines() enverr = penvs.stderr.readlines() ...
<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_global_settings(): """Makes sure that the global settings environment variable and file exist for configuration. """
global settings if settings is not None: #We must have already loaded this and everything was okay! return True from os import getenv result = False if getenv("PYCI_XML") is None: err("The environment variable PYCI_XML for the global configuration " "ha...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _setup_crontab(): """Sets up the crontab if it hasn't already been setup."""
from crontab import CronTab #Since CI works out of a virtualenv anyway, the `ci.py` script will be #installed in the bin already, so we can call it explicitly. command = '/bin/bash -c "source ~/.cron_profile; workon {}; ci.py -cron"'.format(settings.venv) user = _get_real_user() if args["nolive...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _cron_profile(): """Sets up the .cron_profile file if it does not already exist. """
#The main ingredients of the file are the import of the virtualenvwrapper #and the setting of the PYCI_XML variable for global configuration. from os import path cronpath = path.expanduser("~/.cron_profile") if not path.isfile(cronpath): from os import getenv xmlpath = getenv("PYCI_...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _setup_server(): """Checks whether the server needs to be setup if a repo is being installed. If it does, checks whether anything needs to be done. """
if args["setup"] or args["install"]: #If the cron has been configured, it means that the server has been #setup. We also perform some checks of the configuration file and the #existence of the virtualenv. if not _check_global_settings() or not _check_virtualenv(): 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 _server_rollback(): """Removes script database and archive files to rollback the CI server installation. """
#Remove the data and archive files specified in settings. The cron #gets remove by the _setup_server() script if -rollback is specified. from os import path, remove archpath = path.abspath(path.expanduser(settings.archfile)) if path.isfile(archpath) and not args["nolive"]: vms("Removing arc...
<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_repos(): """Lists all the installed repos as well as their last start and finish times from the cron's perspective. """
if not args["list"]: return #Just loop over the list of repos we have in a server instance. See if #they also exist in the db's status; if they do, include the start/end #times we have saved. from pyci.server import Server server = Server(testmode=args["nolive"]) output = ["Rep...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def run(): """Main script entry to handle the arguments given to the script."""
_parser_options() set_verbose(args["verbose"]) if _check_global_settings(): _load_db() else: exit(-1) #Check the server configuration against the script arguments passed in. _setup_server() if args["rollback"]: _server_rollback() okay("The server rollb...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _idle_register_view(self, view): """Internal method that calls register_view"""
assert(self.view is None) self.view = view if self.handlers == "class": for name in dir(self): when, _, what = partition(name, '_') widget, _, signal = partition(what, '__') if when == "on": try: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def __autoconnect_signals(self): """This is called during view registration, to autoconnect signals in glade file with methods within the controller"""
dic = {} for name in dir(self): method = getattr(self, name) if (not isinstance(method, collections.Callable)): continue assert(name not in dic) # not already connected! dic[name] = method # autoconnects glade in the view (if avai...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def parseExtensionArgs(self, args): """Parse the unqualified teams extension request parameters and add them to this object. This method is essentially the inver...
items = args.get('query_membership') if items: for team_name in items.split(','): self.requestTeam(team_name)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def requestTeam(self, team_name): """Request the specified team membership from the OpenID user @param team_name: the unqualified team name @type team_name: str ...
if not team_name in self.requested: self.requested.append(team_name)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def requestTeams(self, team_names): """Add the given list of team names to the request. @param team_names: The team names to request @type team_names: [str] """
if isinstance(team_names, six.string_types): raise TypeError('Teams should be passed as a list of ' 'strings (not %r)' % (type(field_names),)) for team_name in team_names: self.requestTeam(team_name)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def has_property(obj, name): """ Checks recursively if object or its subobjects has a property with specified name. The object can be a user defined object, map ...
if obj == None or name == None: return False names = name.split(".") if names == None or len(names) == 0: return False return RecursiveObjectReader._perform_has_property(obj, names, 0)
<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_property(obj, name): """ Recursively gets value of object or its subobjects property specified by its name. The object can be a user defined object, map ...
if obj == None or name == None: return None names = name.split(".") if names == None or len(names) == 0: return None return RecursiveObjectReader._perform_get_property(obj, names, 0)