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 add(args): """ cdstarcat add SPEC Add metadata about objects (specified by SPEC) in CDSTAR to the catalog. SPEC: Either a CDSTAR object ID or a query. """
spec = args.args[0] with _catalog(args) as cat: n = len(cat) if OBJID_PATTERN.match(spec): cat.add_objids(spec) else: results = cat.add_query(spec) args.log.info('{0} hits for query {1}'.format(results, spec)) args.log.info('{0} objects added'...
<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(args): """ cdstarcat create PATH Create objects in CDSTAR specified by PATH. When PATH is a file, a single object (possibly with multiple bitstreams) ...
with _catalog(args) as cat: for fname, created, obj in cat.create(args.args[0], {}): args.log.info('{0} -> {1} object {2.id}'.format( fname, 'new' if created else 'existing', obj))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def delete(args): """ cdstarcat delete OID Delete an object specified by OID from CDSTAR. """
with _catalog(args) as cat: n = len(cat) cat.delete(args.args[0]) args.log.info('{0} objects deleted'.format(n - len(cat))) return n - len(cat)
<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_continuously(self, interval=1): """Continuously run, while executing pending jobs at each elapsed time interval. @return cease_continuous_run: threading....
cease_continuous_run = threading.Event() class ScheduleThread(threading.Thread): @classmethod def run(cls): while not cease_continuous_run.is_set(): self.run_pending() time.sleep(interval) continuous_thread = Sche...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def at(self, time_str): """ Schedule the job every day at a specific time. Calling this is only valid for jobs scheduled to run every N day(s). :param time_str: ...
assert self.unit in ('days', 'hours') or self.start_day hour, minute = time_str.split(':') minute = int(minute) if self.unit == 'days' or self.start_day: hour = int(hour) assert 0 <= hour <= 23 elif self.unit == 'hours': hour = 0 asser...
<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_status(self): """ returns True if status has changed """
# this function should be part of the server if (self.status is not None) and self.status > 0: # status is already final return False old_status = self.status job_dir = self.run_dir + os.sep + self.id if os.path.isfile(run_dir + os.sep + 'FAILU...
<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_fasta(filename): """Check if filename is FASTA based on extension Return: Boolean """
if re.search("\.fa*s[ta]*$", filename, flags=re.I): return True elif re.search("\.fa$", filename, flags=re.I): return True else: return 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 plotGene(self): ''' Plot the gene ''' pl.plot(self.x, self.y, '.') pl.grid(True) pl.show()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def plotIndividual(self): ''' Plot the individual ''' pl.plot(self.x_int, self.y_int) pl.grid(True) pl.show()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def plot(self): ''' Plot the individual and the gene ''' pl.plot(self.x, self.y, '.') pl.plot(self.x_int, self.y_int) pl.grid(True) pl.show()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def mutation(self, strength = 0.1): ''' Single gene mutation ''' mutStrengthReal = strength mutMaxSizeReal = self.gLength/2 mutSizeReal = int(numpy.random.random_integers(1,mutMaxSizeReal)) mutationPosReal = int(numpy.random.random_integers(0+mutSizeReal-1,self.y.shape[0]-1-mutSizeReal)) mutationSignRea...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def mutations(self, nbr, strength): ''' Multiple gene mutations ''' for i in range(nbr): self.mutation(strength)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def mutation(self,strength = 0.1): ''' Single gene mutation - Complex version ''' # Mutation du gene - real mutStrengthReal = strength mutMaxSizeReal = self.gLength/2 mutSizeReal = int(numpy.random.random_integers(1,mutMaxSizeReal)) mutationPosReal = int(numpy.random.random_integers(0+mutSizeReal-1,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 rankingEval(self): ''' Sorting the pop. base on the fitnessEval result ''' fitnessAll = numpy.zeros(self.length) fitnessNorm = numpy.zeros(self.length) for i in range(self.length): self.Ind[i].fitnessEval() fitnessAll[i] = self.Ind[i].fitness maxFitness = fitnessAll.max() for i in range(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 sortedbyAge(self): ''' Sorting the pop. base of the age ''' ageAll = numpy.zeros(self.length) for i in range(self.length): ageAll[i] = self.Ind[i].age ageSorted = ageAll.argsort() return ageSorted[::-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 RWSelection(self, mating_pool_size): ''' Make Selection of the mating pool with the roulette wheel algorithm ''' A = numpy.zeros(self.length) mating_pool = numpy.zeros(mating_pool_size) [F,S,P] = self.rankingEval() P_Sorted = numpy.zeros(self.length) for i in range(self.length): P_Sorted[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 SUSSelection(self, mating_pool_size): ''' Make Selection of the mating pool with the stochastic universal sampling algorithm ''' A = numpy.zeros(self.length) mating_pool = numpy.zeros(mating_pool_size) r = numpy.random.random()/float(mating_pool_size) [F,S,P] = self.rankingEval() P_Sorted = num...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def safe_join(base, *paths): """ Joins one or more path components to the base path component intelligently. Returns a normalized, absolute version of the final ...
base = base paths = [p for p in paths] final_path = abspath(os.path.join(base, *paths)) base_path = abspath(base) base_path_len = len(base_path) # Ensure final_path starts with base_path (using normcase to ensure we # don't false-negative on case insensitive operating systems like Windows)...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def filepath_to_uri(path): """ Convert an file system path to a URI portion that is suitable for inclusion in a URL. We are assuming input is either UTF-8 or uni...
if path is None: return path # I know about `os.sep` and `os.altsep` but I want to leave # some flexibility for hardcoding separators. return urllib.quote(path.replace("\\", "/"), safe=b"/~!*()'")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def schema_file(self): """ Gets the full path to the file in which to load configuration schema. """
path = os.getcwd() + '/' + self.lazy_folder return path + self.schema_filename
<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_ignore(self): """ Writes a .gitignore file to ignore the generated data file. """
path = self.lazy_folder + self.ignore_filename # If the file exists, return. if os.path.isfile(os.path.realpath(path)): return None sp, sf = os.path.split(self.data_file) #Write the file. try: handle = open(path,'w') handle....
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def choose_schema(self, out_file): """ Finds all schema templates and prompts to choose one. Copies the file to self.lazy_folder. """
path = os.path.dirname(lazyconf.__file__) + '/schema/' self.prompt.header('Choose a template for your config file: ') i = 0 choices = [] for filename in os.listdir(path): if filename.endswith('.json'): try: template = self._load...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def configure_data(self, data, key_string = ''): """ Goes through all the options in `data`, and prompts new values. This function calls itself recursively if it...
# If there's no keys in this dictionary, we have nothing to do. if len(data.keys()) == 0: return # Split the key string by its dots to find out how deep we are. key_parts = key_string.rsplit('.') prefix = ' ' * (len(key_parts) - 1) # Attempt to get a labe...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def configure(self): """ The main configure function. Uses a schema file and an optional data file, and combines them with user prompts to write a new data file....
# Make the lazy folder if it doesn't already exist. path = os.getcwd() + '/' + self.lazy_folder if not os.path.exists(path): os.makedirs(path) schema_file = self.schema_file data_file = self.data_file # Initialise the schema and data objects. schem...
<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_value(self, inner_dict, label, key, value, default): """ Parses a single value and sets it in an inner dictionary. Arguments: inner_dict -- The diction...
t = type(default) if t is dict: return select = self.data.get_select(key) k = key.split('.')[-1] if select: inner_dict[k] = self.prompt.select(label, select, value, default = default) # If the value type is a boolean, prompt a boolean. ...
<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(self, key, value): """ Sets a single value in a preconfigured data file. Arguments: key -- The full dot-notated key to set the value for. value -- The va...
d = self.data.data keys = key.split('.') latest = keys.pop() for k in keys: d = d.setdefault(k, {}) schema = Schema().load(self.schema_file) self.data.internal = schema.internal self.parse_value(d, '', key, value, schema.get(key)) self.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 _load(self, data_file): """ Internal load function. Creates the object and returns it. Arguments: data_file -- The filename to load. """
# Load the data from a file. try: data = Schema().load(data_file) except (Exception, IOError, ValueError) as e: raise e return 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 load(self, data_file = None): """ Loads a data file and sets it to self.data. Arguments: data_file -- The filename to load. """
if not data_file: data_file = '' elif data_file[-1] != '/': data_file += '/' if data_file[-6:] != self.lazy_folder: data_file += self.lazy_folder data_file += self.data_filename self.data = self._load(data_file) 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 get_for(self, query_type, value): """ Create a query and run it for the given arg if it doesn't exist, and return the tweets for the query. """
from yacms.twitter.models import Query lookup = {"type": query_type, "value": value} query, created = Query.objects.get_or_create(**lookup) if created: query.run() elif not query.interested: query.interested = True query.save() 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 untar(original_tarball, output_directory): """Untar given tarball file into directory. Here we decide if our file is actually a tarball, then we untar it and...
if not tarfile.is_tarfile(original_tarball): raise InvalidTarball tarball = tarfile.open(original_tarball) # set mtimes of members to now epochsecs = int(time()) for member in tarball.getmembers(): member.mtime = epochsecs tarball.extractall(output_directory) file_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 detect_images_and_tex( file_list, allowed_image_types=('eps', 'png', 'ps', 'jpg', 'pdf'), timeout=20): """Detect from a list of files which are TeX or images...
tex_file_extension = 'tex' image_list = [] might_be_tex = [] for extracted_file in file_list: # Ignore directories and hidden (metadata) files if os.path.isdir(extracted_file) \ or os.path.basename(extracted_file).startswith('.'): continue magic_str = m...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def convert_images(image_list, image_format="png", timeout=20): """Convert images from list of images to given format, if needed. Figure out the types of the ima...
png_output_contains = 'PNG image' image_mapping = {} for image_file in image_list: if os.path.isdir(image_file): continue if not os.path.exists(image_file): continue cmd_out = check_output(['file', image_file], timeout=timeout) if cmd_out.find(png_o...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def convert_image(from_file, to_file, image_format): """Convert an image to given format."""
with Image(filename=from_file) as original: with original.convert(image_format) as converted: converted.save(filename=to_file) return to_file
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def rotate_image(filename, line, sdir, image_list): """Rotate a image. Given a filename and a line, figure out what it is that the author wanted to do wrt changi...
file_loc = get_image_location(filename, sdir, image_list) degrees = re.findall('(angle=[-\\d]+|rotate=[-\\d]+)', line) if len(degrees) < 1: return False degrees = degrees[0].split('=')[-1].strip() if file_loc is None or file_loc == 'ERROR' or\ not re.match('-*\\d+', degrees):...
<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_by_owner(cls, owner): """ get all entities owned by specified owner """
return cls.query(cls.owner==cls._get_key(owner))
<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(self): """ Cleans the data and throws ValidationError on failure """
errors = {} cleaned = {} for name, validator in self.validate_schema.items(): val = getattr(self, name, None) try: cleaned[name] = validator.to_python(val) except formencode.api.Invalid, err: errors[name] = err if err...
<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_defaults(self, **defaults): """ Add all keyword arguments to self.args args: **defaults: key and value represents dictionary key and value """
try: defaults_items = defaults.iteritems() except AttributeError: defaults_items = defaults.items() for key, val in defaults_items: if key not in self.args.keys(): self.args[key] = val
<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_args(self, **kwargs): """ Set more arguments to self.args args: **kwargs: key and value represents dictionary key and value """
try: kwargs_items = kwargs.iteritems() except AttributeError: kwargs_items = kwargs.items() for key, val in kwargs_items: self.args[key] = val
<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_important_variables(self): """ Check all the variables needed are defined """
if len(self.important_variables - set(self.args.keys())): raise TypeError("Some important variables are not set")
<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_bestfit_line(self, x_min=None, x_max=None, resolution=None): """ Method to get bestfit line using the defined self.bestfit_func method args: x_min: scala...
x = self.args["x"] if x_min is None: x_min = min(x) if x_max is None: x_max = max(x) if resolution is None: resolution = self.args.get("resolution", 1000) bestfit_x = np.linspace(x_min, x_max, resolution) return [bestfit_x, self.bestfi...
<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_rmse(self, data_x=None, data_y=None): """ Get Root Mean Square Error using self.bestfit_func args: x_min: scalar, default=min(x) minimum x value of the l...
if data_x is None: data_x = np.array(self.args["x"]) if data_y is None: data_y = np.array(self.args["y"]) if len(data_x) != len(data_y): raise ValueError("Lengths of data_x and data_y are different") rmse_y = self.bestfit_func(data_x) return 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 get_mae(self, data_x=None, data_y=None): """ Get Mean Absolute Error using self.bestfit_func args: data_x: array_like, default=x x value used to determine rm...
if data_x is None: data_x = np.array(self.args["x"]) if data_y is None: data_y = np.array(self.args["y"]) if len(data_x) != len(data_y): raise ValueError("Lengths of data_x and data_y are different") mae_y = self.bestfit_func(data_x) return np...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _backup_bytes(target, offset, length): """ Read bytes from one file and write it to a backup file with the .bytes_backup suffix """
click.echo('Backup {l} byes at position {offset} on file {file} to .bytes_backup'.format( l=length, offset=offset, file=target)) with open(target, 'r+b') as f: f.seek(offset) with open(target + '.bytes_backup', 'w+b') as b: for _ in xrange(length): byte = 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 _smudge_bytes(target, offset, magic_bytes): """ Write magic bytes to a file relative from offset """
click.echo('Writing {c} magic byes at position {offset} on file {file}'.format( c=len(magic_bytes), offset=offset, file=target)) with open(target, 'r+b') as f: f.seek(offset) f.write(magic_bytes) f.flush() click.echo('Changes written')
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def smudge(newtype, target): """ Smudge magic bytes with a known type """
db = smudge_db.get() magic_bytes = db[newtype]['magic'] magic_offset = db[newtype]['offset'] _backup_bytes(target, magic_offset, len(magic_bytes)) _smudge_bytes(target, magic_offset, magic_bytes)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def smudgeraw(target, offset, magicbytes): """ Smudge magic bytes with raw bytes """
magicbytes = magicbytes.replace('\\x', '').decode('hex') _backup_bytes(target, offset, len(magicbytes)) _smudge_bytes(target, offset, magicbytes)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def restore(source, offset): """ Restore a smudged file from .bytes_backup """
backup_location = os.path.join( os.path.dirname(os.path.abspath(source)), source + '.bytes_backup') click.echo('Reading backup from: {location}'.format(location=backup_location)) if not os.path.isfile(backup_location): click.echo('No backup found for: {source}'.format(source=source)) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def available(): """ List available types for 'smudge' """
db = smudge_db.get() click.echo('{:<6} {:<6} {:<50}'.format('Type', 'Offset', 'Magic')) for k, v in db.items(): click.echo('{type:<6} {offset:<6} {magic}'.format( type=k, magic=v['magic'].encode('hex'), offset=v['offset']))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def upcoming_releases(self, product): """ Get upcoming releases for this product. Specifically we search for releases with a GA date greater-than or equal to tod...
url = 'api/v6/releases/' url = url + '?product__shortname=' + product url = url + '&ga_date__gte=' + date.today().strftime('%Y-%m-%d') url = url + '&ordering=shortname_sort' releases = yield self._get(url) result = munchify(releases) defer.returnValue(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 newest_release(self, product): """ Get the shortname of the newest upcoming release for a product. :param product: str, eg. "ceph" :returns: deferred that wh...
releases = yield self.upcoming_releases(product) if not releases: raise ProductPagesException('no upcoming releases') defer.returnValue(releases[0].shortname)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def product_url(self, product): """ Return a human-friendly URL for this product. :param product: str, eg. "ceph" :returns: str, URL """
url = 'product/%s' % product return posixpath.join(self.url, url)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def release(self, shortname): """ Get a specific release by its shortname. :param shortname: str, eg. "ceph-3-0" :returns: deferred that when fired returns a Rel...
url = 'api/v6/releases/?shortname=%s' % shortname releases = yield self._get(url) # Note, even if this shortname does not exist, _get() will not errback # for this url. It simply returns an empty list. So check that here: if not releases: raise ReleaseNotFoundExcepti...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def schedule_url(self, release): """ Return a human-friendly URL for this release. :param release: str, release shortname eg. "ceph-3-0" :returns: str, URL """
product, _ = release.split('-', 1) url = 'product/%s/release/%s/schedule/tasks' % (product, release) return posixpath.join(self.url, url)
<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, url, headers={}): """ Get a JSON API endpoint and return the parsed data. :param url: str, *relative* URL (relative to pp-admin/ api endpoint) :pa...
# print('getting %s' % url) headers = headers.copy() headers['Accept'] = 'application/json' url = posixpath.join(self.url, url) try: response = yield treq.get(url, headers=headers, timeout=5) if response.code != 200: err = '%s returned %s'...
<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(secs): """ Return a UTC date from a timestamp. @type secs: C{long} @param secs: Seconds since 1970. @return: UTC timestamp. @rtype: C{datetime.d...
if negative_timestamp_broken and secs < 0: return datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=secs) return datetime.datetime.utcfromtimestamp(secs)
<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_class_sealed(klass): """ Whether or not the supplied class can accept dynamic properties. @rtype: C{bool} @since: 0.5 """
mro = inspect.getmro(klass) new = False if mro[-1] is object: mro = mro[:-1] new = True for kls in mro: if new and '__dict__' in kls.__dict__: return False if not hasattr(kls, '__slots__'): return False return True
<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_underscore(string, prefix='', suffix=''): """ Generate an underscore-separated lower-case identifier, given English text, a prefix, and an optional suf...
return require_valid(append_underscore_if_keyword('_'.join( word.lower() for word in en.words(' '.join([prefix, string, suffix]))) ))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def upper_underscore(string, prefix='', suffix=''): """ Generate an underscore-separated upper-case identifier. Useful for constants. Takes a string, prefix, and...
return require_valid(append_underscore_if_keyword('_'.join( word.upper() for word in en.words(' '.join([prefix, string, suffix]))) ))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def upper_camel(string, prefix='', suffix=''): """ Generate a camel-case identifier with the first word capitalised. Useful for class names. Takes a string, pref...
return require_valid(append_underscore_if_keyword(''.join( upper_case_first_char(word) for word in en.words(' '.join([prefix, string, suffix]))) ))
<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_camel(string, prefix='', suffix=''): """ Generate a camel-case identifier. Useful for unit test methods. Takes a string, prefix, and optional suffix. `...
return require_valid(append_underscore_if_keyword(''.join( word.lower() if index == 0 else upper_case_first_char(word) for index, word in enumerate(en.words(' '.join([prefix, string, suffix])))) ))
<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_valid(identifier): """ If the identifier is valid for Python, return True, otherwise False. """
return ( isinstance(identifier, six.string_types) and bool(NAME_RE.search(identifier)) and not keyword.iskeyword(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 receiver(url, **kwargs): """ Return receiver instance from connection url string url <str> connection url eg. 'tcp://0.0.0.0:8080' """
res = url_to_resources(url) fnc = res["receiver"] return fnc(res.get("url"), **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 sender(url, **kwargs): """ Return sender instance from connection url string url <str> connection url eg. 'tcp://0.0.0.0:8080' """
res = url_to_resources(url) fnc = res["sender"] return fnc(res.get("url"), **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 listen(url, prefix=None, **kwargs): """ bind and return a connection instance from url arguments: - url (str): xbahn connection url """
return listener(url, prefix=get_prefix(prefix), **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 connect(url, prefix=None, **kwargs): """ connect and return a connection instance from url arguments: - url (str): xbahn connection url """
return connection(url, prefix=get_prefix(prefix), **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 make_data(self, message): """ make data string from message according to transport_content_type Returns: str: message data """
if not isinstance(message, Message): return message return message.export(self.transport_content_type)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def make_message(self, data): """ Create a Message instance from data, data will be loaded via munge according to the codec specified in the transport_content_ty...
data = self.codec.loads(data) msg = Message( data.get("data"), *data.get("args",[]), **data.get("kwargs",{}) ) msg.meta.update(data.get("meta")) self.trigger("make_message", data, msg) return msg
<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_permissions(): """ Checks if current user can access docker """
if ( not grp.getgrnam('docker').gr_gid in os.getgroups() and not os.geteuid() == 0 ): exitStr = """ User doesn't have permission to use docker. You can do either of the following, 1. Add user to the 'docker' group (preferred) 2. Run command as superuser u...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def build_base_image_cmd(self, force): """ Build the glusterbase image """
check_permissions() basetag = self.conf.basetag basedir = self.conf.basedir verbose = self.conf.verbose if self.image_exists(tag=basetag): if not force: echo("Image with tag '{0}' already exists".format(basetag)) return self.image_by...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def build_main_image_cmd(self, srcdir, force): """ Build the main image to be used for launching containers """
check_permissions() basetag = self.conf.basetag basedir = self.conf.basedir maintag = self.conf.maintag if not self.image_exists(tag=basetag): if not force: exit("Base image with tag {0} does not exist".format(basetag)) else: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def launch_cmd(self, n, force): """ Launch the specified docker containers using the main image """
check_permissions() prefix = self.conf.prefix maintag = self.conf.maintag commandStr = "supervisord -c /etc/supervisor/conf.d/supervisord.conf" for i in range(1, n+1): cName = "{0}-{1}".format(prefix, i) if self.container_exists(name=cName): ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def stop_cmd(self, name, force): """ Stop the specified or all docker containers launched by us """
check_permissions() if name: echo("Would stop container {0}".format(name)) else: echo("Would stop all containers") echo("For now use 'docker stop' to stop the containers")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def ssh_cmd(self, name, ssh_command): """ SSH into given container and executre command if given """
if not self.container_exists(name=name): exit("Unknown container {0}".format(name)) if not self.container_running(name=name): exit("Container {0} is not running".format(name)) ip = self.get_container_ip(name) if not ip: exit("Failed to get network 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 ip_cmd(self, name): """ Print ip of given container """
if not self.container_exists(name=name): exit('Unknown container {0}'.format(name)) ip = self.get_container_ip(name) if not ip: exit("Failed to get network address for" " container {0}".format(name)) else: echo(ip)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pack(self, message_type, client_id, client_storage, args, kwargs): """ Packs a message """
return pickle.dumps( (message_type, client_id, client_storage, args, kwargs), protocol=2)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def dispatch_message(self, message_type, client_id, client_storage, args, kwargs): """ Calls callback functions """
logger.debug("Backend message ({message_type}) : {args} {kwargs}".format( message_type=dict(MESSAGES_TYPES)[message_type], args=args, kwargs=kwargs)) if message_type in [ON_OPEN, ON_CLOSE, ON_RECEIVE]: # Find if client exists in clients_list client = next( ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _loop(self, *args, **kwargs): """Loops the target function :param args: The args specified on initiation :param kwargs: The kwargs specified on initiation ""...
self.on_start(*self.on_start_args, **self.on_start_kwargs) try: while not self._stop_signal: self.target(*args, **kwargs) finally: self.on_stop(*self.on_stop_args, **self.on_stop_kwargs) self._stop_signal = False self._lock.set()
<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(self, subthread=True): """Starts the loop Tries to start the loop. Raises RuntimeError if the loop is currently running. :param subthread: True/False v...
if self.is_running(): raise RuntimeError('Loop is currently running') else: self._lock.clear() self._stop_signal = False # just in case self._in_subthread = subthread if subthread: self._loop_thread = threading.Thread(target=s...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def stop(self, silent=False): """Sends a stop signal to the loop thread and waits until it stops A stop signal is sent using Loop.send_stop_signal(silent) (see d...
self.send_stop_signal(silent) self._lock.wait()
<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_stop_signal(self, silent=False): """Sends a stop signal to the loop thread :param silent: True/False value that specifies whether or not to raise Runtim...
if self.is_running(): self._stop_signal = True elif not silent: raise RuntimeError('Loop is currently not running')
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def restart(self, subthread=None): """Restarts the loop function Tries to restart the loop thread using the current thread. Raises RuntimeError if a previous cal...
if self._in_subthread is None: raise RuntimeError('A call to start must first be placed before restart') self.stop(silent=True) if subthread is None: subthread = self._in_subthread self.__init__(self.target, self.args, self.kwargs, self.on_stop) self.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 make_property(prop_defs, prop_name, cls_names=[], hierarchy=[]): """ Generates a property class from the defintion dictionary args: prop_defs: the dictionary...
register = False try: cls_names.remove('RdfClassBase') except ValueError: pass if cls_names: new_name = "%s_%s" % (prop_name.pyuri, "_".join(cls_names)) prop_defs['kds_appliesToClass'] = cls_names elif not cls_names: cls_names = [Uri('kdr_AllClasses')] ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def link_property(prop, cls_object): """ Generates a property class linked to the rdfclass args: prop: unlinked property class cls_name: the name of the rdf_clas...
register = False cls_name = cls_object.__name__ if cls_name and cls_name != 'RdfBaseClass': new_name = "%s_%s" % (prop._prop_name, cls_name) else: new_name = prop._prop_name new_prop = types.new_class(new_name, (prop,), ...
<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_properties(cls_def): """ cycles through the class definiton and returns all properties """
# pdb.set_trace() prop_list = {prop: value for prop, value in cls_def.items() \ if 'rdf_Property' in value.get('rdf_type', "") or \ value.get('rdfs_domain')} return prop_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 filter_prop_defs(prop_defs, hierarchy, cls_names): """ Reads through the prop_defs and returns a dictionary filtered by the current class args: prop_defs: th...
def _is_valid(test_list, valid_list): """ reads the list of classes in appliesToClass and returns whether the test_list matches args: test_list: the list of clasees to test against valid_list: list of possible matches """ for test in test_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 get_processors(processor_cat, prop_defs, data_attr=None): """ reads the prop defs and adds applicable processors for the property Args: processor_cat(str): ...
processor_defs = prop_defs.get(processor_cat,[]) processor_list = [] for processor in processor_defs: proc_class = PropertyProcessor[processor['rdf_type'][0]] processor_list.append(proc_class(processor.get('kds_params', [{}]), data_attr)) 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 merge_rdf_list(rdf_list): """ takes an rdf list and merges it into a python list args: rdf_list: the RdfDataset object with the list values returns: list of ...
# pdb.set_trace() if isinstance(rdf_list, list): rdf_list = rdf_list[0] rtn_list = [] # for item in rdf_list: item = rdf_list if item.get('rdf_rest') and item.get('rdf_rest',[1])[0] != 'rdf_nil': rtn_list += merge_rdf_list(item['rdf_rest'][0]) if item.get('rdf_first'): ...
<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, **kwargs): """ Returns a JSON object of the property for insertion into es """
rtn_list = [] rng_defs = get_prop_range_defs(self.class_names, self.kds_rangeDef) # if self.__class__._prop_name == 'bf_partOf': # pdb.set_trace() rng_def = get_prop_range_def(rng_defs) idx_types = rng_def.get('kds_esIndexType', []).copy() if 'es_Ignore' in 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 _parse_in_batches(cmd_array): """Find patterns that match to `in_batches_pat` and replace them into `STDIN` or `TMPFILE`. :param cmd_array: `shlex.split`-ed ...
res_cmd_array = cmd_array[:] res_batch_to_file_s = [] in_batches_cmdidx = BatchCommand._in_batches_cmdidx(cmd_array) for batch_id, cmdidx in enumerate(in_batches_cmdidx): if cmdidx > 0 and cmd_array[cmdidx - 1] == '<': # e.g. `< IN_BATCH0` res_batch_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 _parse_out_batch(cmd_array): """Find patterns that match to `out_batch_pat` and replace them into `STDOUT` or `TMPFILE`. :param cmd_array: `shlex.split`-ed c...
res_cmd_array = cmd_array[:] res_batch_from_file = None out_batch_cmdidx = BatchCommand._out_batch_cmdidx(cmd_array) if out_batch_cmdidx is None: return (res_cmd_array, res_batch_from_file) if out_batch_cmdidx > 0 and cmd_array[out_batch_cmdidx - 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 _in_batches_cmdidx(cmd_array): """Raise `IndexError` if IN_BATCH0 - IN_BATCHx is not used sequentially in `cmd_array` $ cat a.txt IN_BATCH1 IN_BATCH0 b.txt c...
in_batches_cmdidx_dict = {} for cmdidx, tok in enumerate(cmd_array): mat = BatchCommand.in_batches_pat.match(tok) if mat: batch_idx = int(mat.group(1)) if batch_idx in in_batches_cmdidx_dict: raise IndexError( ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _out_batch_cmdidx(cmd_array): """Raise `IndexError` if OUT_BATCH is used multiple time :returns: OUT_BATCH cmdidx (None if OUT_BATCH is not in `cmd_array`) $...
out_batch_cmdidx = None for cmdidx, tok in enumerate(cmd_array): mat = BatchCommand.out_batch_pat.match(tok) if mat: if out_batch_cmdidx: raise IndexError( 'OUT_BATCH is used multiple times in command below:%s$ %s' % ...
<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_builder(self, corpus): ''' creates a builder object for a wordlist ''' builder = WordBuilder(chunk_size=self.chunk_size) builder.ingest(corpus) return builder
<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_common(self, filename): ''' Process lists of common name words ''' word_list = [] words = open(filename) for word in words.readlines(): word_list.append(word.strip()) return word_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 get_scientific_name(self): ''' Get a new flower name ''' genus = self.genus_builder.get_word() species = self.species_builder.get_word() return '%s %s' % (genus, species)
<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_common_name(self): ''' Get a flower's common name ''' name = random.choice(self.common_first) if random.randint(0, 1) == 1: name += ' ' + random.choice(self.common_first).lower() name += ' ' + random.choice(self.common_second).lower() return 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 certify_dict_schema( value, schema=None, key_certifier=None, value_certifier=None, required=None, allow_extra=None, ): """ Certify the dictionary schema. :pa...
if key_certifier is not None or value_certifier is not None: for key, val in value.items(): if key_certifier is not None: key_certifier(key) if value_certifier is not None: value_certifier(val) if schema: if not isinstance(schema, 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 certify_dict( value, schema=None, allow_extra=False, required=True, key_certifier=None, value_certifier=None, include_collections=False, ): """ Certifies a d...
cls = dict # Certify our kwargs: certify_params( (certify_bool, 'allow_extra', allow_extra), (certify_bool, 'include_collections', include_collections), ) if certify_required( value=value, required=required, ): return # Check the type(s): types ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def certify_iterable_schema(value, schema=None, required=True): """ Certify an iterable against a schema. :param iterable value: The iterable to certify against ...
if schema is not None: if len(schema) != len(value): raise CertifierValueError( "encountered {extra} extra items".format( extra=len(value) - len(schema)), value=value, required=required, ) for index, certif...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def certify_iterable( value, types, certifier=None, min_len=None, max_len=None, schema=None, required=True ): """ Validates an iterable sequence, checking it aga...
certify_required( value=value, required=required, ) certify_params( (_certify_int_param, 'max_len', max_len, dict(negative=False, required=False)), (_certify_int_param, 'min_len', min_len, dict(negative=False, required=False)), ) # Check the type(s): if types and...