code
stringlengths
51
2.34k
sequence
stringlengths
186
3.94k
docstring
stringlengths
11
171
def bar_(self, label=None, style=None, opts=None, options={}): try: return self._get_chart("bar", style=style, opts=opts, label=label, options=options) except Exception as e: self.err(e, self.bar_, "Can not draw bar chart")
module function_definition identifier parameters identifier default_parameter identifier none default_parameter identifier none default_parameter identifier none default_parameter identifier dictionary block try_statement block return_statement call attribute identifier identifier argument_list string string_start stri...
Get a bar chart
def getmodule(object): if ismodule(object): return object if isclass(object): return sys.modules.get(object.__module__) try: file = getabsfile(object) except TypeError: return None if modulesbyfile.has_key(file): return sys.modules[modulesbyfile[file]] for...
module function_definition identifier parameters identifier block if_statement call identifier argument_list identifier block return_statement identifier if_statement call identifier argument_list identifier block return_statement call attribute attribute identifier identifier identifier argument_list attribute identif...
Return the module an object was defined in, or None if not found.
def _readhex(self, length, start): if length % 4: raise InterpretError("Cannot convert to hex unambiguously - " "not multiple of 4 bits.") if not length: return '' s = self._slice(start, start + length).tobytes() try: ...
module function_definition identifier parameters identifier identifier identifier block if_statement binary_operator identifier integer block raise_statement call identifier argument_list concatenated_string string string_start string_content string_end string string_start string_content string_end if_statement not_ope...
Read bits and interpret as a hex string.
def getRelativePath(basepath, path): basepath = splitpath(os.path.abspath(basepath)) path = splitpath(os.path.abspath(path)) afterCommon = False for c in basepath: if afterCommon or path[0] != c: path.insert(0, os.path.pardir) afterCommon = True else: ...
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list call attribute attribute identifier identifier identifier argument_list identifier expression_statement assignment identifier call identifier argument_list call attribute...
Get a path that is relative to the given base path.
def cli(ctx, config, quiet): ctx.obj = {} ctx.obj['config'] = load_config(config.read()) ctx.obj['quiet'] = quiet log(ctx, ' * ' + rnd_scotty_quote() + ' * ')
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment attribute identifier identifier dictionary expression_statement assignment subscript attribute identifier identifier string string_start string_content string_end call identifier argument_list call at...
AWS ECS Docker Deployment Tool
def _ReloadArtifacts(self): self._artifacts = {} self._LoadArtifactsFromFiles(self._sources.GetAllFiles()) self.ReloadDatastoreArtifacts()
module function_definition identifier parameters identifier block expression_statement assignment attribute identifier identifier dictionary expression_statement call attribute identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list expression_statement call attribute...
Load artifacts from all sources.
def unregister_transform(self, node_class, transform, predicate=None): self.transforms[node_class].remove((transform, predicate))
module function_definition identifier parameters identifier identifier identifier default_parameter identifier none block expression_statement call attribute subscript attribute identifier identifier identifier identifier argument_list tuple identifier identifier
Unregister the given transform.
def symbol(currency, *, native=True): currency = validate_currency(currency) if native: return _currencies[currency]['symbol_native'] return _currencies[currency]['symbol']
module function_definition identifier parameters identifier keyword_separator default_parameter identifier true block expression_statement assignment identifier call identifier argument_list identifier if_statement identifier block return_statement subscript subscript identifier identifier string string_start string_co...
return symbol of currency
def nice_true_ces(tc): cause_list = [] next_list = [] cause = '<--' effect = '-->' for event in tc: if event.direction == Direction.CAUSE: cause_list.append(["{0:.4f}".format(round(event.alpha, 4)), event.mechanism, cause, event.purview]) el...
module function_definition identifier parameters identifier block expression_statement assignment identifier list expression_statement assignment identifier list expression_statement assignment identifier string string_start string_content string_end expression_statement assignment identifier string string_start string...
Format a true |CauseEffectStructure|.
def create_and_run_collector(document, options): collector = None if not options.report == 'off': collector = Collector() collector.store.configure(document) Event.configure(collector_queue=collector.queue) collector.start() return collector
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier none if_statement not_operator comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment identifier call identifier argume...
Create and run collector process for report data.
def _resolve_time(value): if value is None or isinstance(value,(int,long)): return value if NUMBER_TIME.match(value): return long(value) simple = SIMPLE_TIME.match(value) if SIMPLE_TIME.match(value): multiplier = long( simple.groups()[0] ) constant = SIMPLE_TIMES[ simple.groups()[1] ] return...
module function_definition identifier parameters identifier block if_statement boolean_operator comparison_operator identifier none call identifier argument_list identifier tuple identifier identifier block return_statement identifier if_statement call attribute identifier identifier argument_list identifier block retu...
Resolve the time in seconds of a configuration value.
def fix_positions(self): shift_x = 0 for m in self.__reactants: max_x = self.__fix_positions(m, shift_x, 0) shift_x = max_x + 1 arrow_min = shift_x if self.__reagents: for m in self.__reagents: max_x = self.__fix_positions(m, shift_x, 1...
module function_definition identifier parameters identifier block expression_statement assignment identifier integer for_statement identifier attribute identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier integer expression_state...
fix coordinates of molecules in reaction
def begin(self): self._device.writeList(HT16K33_SYSTEM_SETUP | HT16K33_OSCILLATOR, []) self.set_blink(HT16K33_BLINK_OFF) self.set_brightness(15)
module function_definition identifier parameters identifier block expression_statement call attribute attribute identifier identifier identifier argument_list binary_operator identifier identifier list expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute...
Initialize driver with LEDs enabled and all turned off.
def save(self): self.cells = list(self.renumber()) if not self.cells[-1].endswith('\n'): self.cells[-1] += '\n' with open(self.filename, 'w') as file_open: file_open.write('\n\n'.join(self.cells))
module function_definition identifier parameters identifier block expression_statement assignment attribute identifier identifier call identifier argument_list call attribute identifier identifier argument_list if_statement not_operator call attribute subscript attribute identifier identifier unary_operator integer ide...
Format and save cells.
def dropIndex(cls, fields) : "removes an index created with ensureIndex " con = RabaConnection(cls._raba_namespace) rlf, ff = cls._parseIndex(fields) for name in rlf : con.dropIndex(name, 'anchor_raba_id') con.dropIndex(cls.__name__, ff) con.commit()
module function_definition identifier parameters identifier identifier block expression_statement string string_start string_content string_end expression_statement assignment identifier call identifier argument_list attribute identifier identifier expression_statement assignment pattern_list identifier identifier call...
removes an index created with ensureIndex
def head(self, item): uri = "/%s/%s" % (self.uri_base, utils.get_id(item)) return self._head(uri)
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier binary_operator string string_start string_content string_end tuple attribute identifier identifier call attribute identifier identifier argument_list identifier return_statement call attribute identi...
Makes a HEAD request on a specific item.
def biopython_protein_scale(inseq, scale, custom_scale_dict=None, window=7): if scale == 'kd_hydrophobicity': scale_dict = kd_hydrophobicity_one elif scale == 'bulkiness': scale_dict = bulkiness_one elif scale == 'custom': scale_dict = custom_scale_dict else: raise ValueE...
module function_definition identifier parameters identifier identifier default_parameter identifier none default_parameter identifier integer block if_statement comparison_operator identifier string string_start string_content string_end block expression_statement assignment identifier identifier elif_clause comparison...
Use Biopython to calculate properties using a sliding window over a sequence given a specific scale to use.
def _make_txn(signer, setting_key, payload): serialized_payload = payload.SerializeToString() header = TransactionHeader( signer_public_key=signer.get_public_key().as_hex(), family_name='sawtooth_settings', family_version='1.0', inputs=_config_inputs(setting_key), outputs...
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier call attribute call identifier argument_list keyword_argument identifier call attribute call at...
Creates and signs a sawtooth_settings transaction with with a payload.
def _traverse_command(self, name, *args, **kwargs): if not name in self.available_commands: raise AttributeError("%s is not an available command for %s" % (name, self.__class__.__name__)) attr = getattr(self.connection, "%s" % name) key = self.key ...
module function_definition identifier parameters identifier identifier list_splat_pattern identifier dictionary_splat_pattern identifier block if_statement not_operator comparison_operator identifier attribute identifier identifier block raise_statement call identifier argument_list binary_operator string string_start ...
Add the key to the args and call the Redis command.
def ensure_stacker_compat_config(config_filename): try: with open(config_filename, 'r') as stream: yaml.safe_load(stream) except yaml.constructor.ConstructorError as yaml_error: if yaml_error.problem.startswith( 'could not determine a constructor for the tag \'!'): ...
module function_definition identifier parameters identifier block try_statement block with_statement with_clause with_item as_pattern call identifier argument_list identifier string string_start string_content string_end as_pattern_target identifier block expression_statement call attribute identifier identifier argume...
Ensure config file can be loaded by Stacker.
def checksum_contracts(self) -> None: checksums: Dict[str, str] = {} for contracts_dir in self.contracts_source_dirs.values(): file: Path for file in contracts_dir.glob('*.sol'): checksums[file.name] = hashlib.sha256(file.read_bytes()).hexdigest() self.ove...
module function_definition identifier parameters identifier type none block expression_statement assignment identifier type generic_type identifier type_parameter type identifier type identifier dictionary for_statement identifier call attribute attribute identifier identifier identifier argument_list block expression_...
Remember the checksum of each source, and the overall checksum.
def _create_plain_field(self, attr, options): method = self._get_field_method(attr.py_type) or self._create_other_field klass, options = method(attr, options) if attr.is_unique: options['validators'].append(validators.UniqueEntityValidator(attr.entity)) return klass, options
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier boolean_operator call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier expression_statement assignment pattern_list identifier i...
Creates the form element.
def update(self, **kwargs): for key, value in kwargs.items(): setattr(self, key, value)
module function_definition identifier parameters identifier dictionary_splat_pattern identifier block for_statement pattern_list identifier identifier call attribute identifier identifier argument_list block expression_statement call identifier argument_list identifier identifier identifier
Creates or updates a property for the instance for each parameter.
def install_supervisor(self, update=False): script = supervisor.Recipe( self.buildout, self.name, {'user': self.options.get('user'), 'program': self.options.get('program'), 'command': templ_cmd.render(config=self.conf_filename, prefix=self.prefix), ...
module function_definition identifier parameters identifier default_parameter identifier false block expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier dictionary pair string string_start string_content string_end...
install supervisor config for redis
def _get_results_from_api(identifiers, endpoints, api_key, api_secret): if api_key is not None and api_secret is not None: client = housecanary.ApiClient(api_key, api_secret) else: client = housecanary.ApiClient() wrapper = getattr(client, endpoints[0].split('/')[0]) if len(endpoints) > ...
module function_definition identifier parameters identifier identifier identifier identifier block if_statement boolean_operator comparison_operator identifier none comparison_operator identifier none block expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifi...
Use the HouseCanary API Python Client to access the API
def _dmi_cast(key, val, clean=True): if clean and not _dmi_isclean(key, val): return elif not re.match(r'serial|part|asset|product', key, flags=re.IGNORECASE): if ',' in val: val = [el.strip() for el in val.split(',')] else: try: val = int(val) ...
module function_definition identifier parameters identifier identifier default_parameter identifier true block if_statement boolean_operator identifier not_operator call identifier argument_list identifier identifier block return_statement elif_clause not_operator call attribute identifier identifier argument_list stri...
Simple caster thingy for trying to fish out at least ints & lists from strings
def extract_pls_rsp(rsp_str): try: rsp = json.loads(rsp_str) except ValueError: traceback.print_exc() err = sys.exc_info()[1] err_str = ERROR_STR_PREFIX + str(err) return RET_ERROR, err_str, None error_code = int(rsp['retType']) if error_code != 1: error_s...
module function_definition identifier parameters identifier block try_statement block expression_statement assignment identifier call attribute identifier identifier argument_list identifier except_clause identifier block expression_statement call attribute identifier identifier argument_list expression_statement assig...
Extract the response of PLS
def export_to_dom(self): namespaces = 'xmlns="http://www.neuroml.org/lems/%s" ' + \ 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' + \ 'xsi:schemaLocation="http://www.neuroml.org/lems/%s %s"' namespaces = namespaces%(self.target_lems_version,self.targe...
module function_definition identifier parameters identifier block expression_statement assignment identifier binary_operator binary_operator string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end expression_statement assignment identifie...
Exports this model to a DOM.
def execute(self): self.autocomplete() if len(self.argv): cmd = self.argv[0] cmd_argv = self.get_argv_for_command() self.run_command(cmd, cmd_argv) else: self.show_help()
module function_definition identifier parameters identifier block expression_statement call attribute identifier identifier argument_list if_statement call identifier argument_list attribute identifier identifier block expression_statement assignment identifier subscript attribute identifier identifier integer expressi...
Executes whole process of parsing and running command.
def _handleSmsStatusReport(self, notificationLine): self.log.debug('SMS status report received') cdsiMatch = self.CDSI_REGEX.match(notificationLine) if cdsiMatch: msgMemory = cdsiMatch.group(1) msgIndex = cdsiMatch.group(2) report = self.readStoredSms(msgIndex...
module function_definition identifier parameters identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute attribute identifier identifier identifier arg...
Handler for SMS status reports
def flush(self): self._check_open_file() if self.allow_update and not self.is_stream: contents = self._io.getvalue() if self._append: self._sync_io() old_contents = (self.file_object.byte_contents if is_byte_string(c...
module function_definition identifier parameters identifier block expression_statement call attribute identifier identifier argument_list if_statement boolean_operator attribute identifier identifier not_operator attribute identifier identifier block expression_statement assignment identifier call attribute attribute i...
Flush file contents to 'disk'.
def dictionary_validator(key_type, value_type): def _validate_dictionary(instance, attribute, value): if not isinstance(value, dict): raise TypeError('"{}" must be a dictionary'.format(attribute.name)) for key, data in value.items(): if not isinstance(key, key_type): ...
module function_definition identifier parameters identifier identifier block function_definition identifier parameters identifier identifier identifier block if_statement not_operator call identifier argument_list identifier identifier block raise_statement call identifier argument_list call attribute string string_sta...
Validator for ``attrs`` that performs deep type checking of dictionaries.
def _dispatch_event(self, event: LutronEvent, params: Dict): for handler, context in self._subscribers: handler(self, context, event, params)
module function_definition identifier parameters identifier typed_parameter identifier type identifier typed_parameter identifier type identifier block for_statement pattern_list identifier identifier attribute identifier identifier block expression_statement call identifier argument_list identifier identifier identifi...
Dispatches the specified event to all the subscribers.
def _py_expand_short(subsequence, sequence, max_l_dist): subseq_len = len(subsequence) if subseq_len == 0: return (0, 0) scores = list(range(1, subseq_len + 1)) min_score = subseq_len min_score_idx = -1 for seq_index, char in enumerate(sequence): a = seq_index c = a + 1 ...
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call identifier argument_list identifier if_statement comparison_operator identifier integer block return_statement tuple integer integer expression_statement assignment identifier call ide...
Straightforward implementation of partial match expansion.
def _to_dict(self): physical_prop_names = find_PhysicalProperty(self) physical_prop_vals = [getattr(self, prop) for prop in physical_prop_names] return dict(zip(physical_prop_names, physical_prop_vals))
module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier list_comprehension call identifier argument_list identifier identifier for_in_clause identifier identifier return_statement cal...
Return a dictionary representation of the current object.
def diffuse_template(self, **kwargs): kwargs_copy = self.base_dict.copy() kwargs_copy.update(**kwargs) self._replace_none(kwargs_copy) localpath = NameFactory.diffuse_template_format.format(**kwargs_copy) if kwargs.get('fullpath', False): return self.fullpath(...
module function_definition identifier parameters identifier dictionary_splat_pattern identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list expression_statement call attribute identifier identifier argument_list dictionary_splat identifier exp...
return the file name for other diffuse map templates
def theme_static_with_version(ctx, filename, external=False): if current_app.theme_manager.static_folder: url = assets.cdn_for('_themes.static', filename=current.identifier + '/' + filename, _external=external) else: url = assets.cdn_for(...
module function_definition identifier parameters identifier identifier default_parameter identifier false block if_statement attribute attribute identifier identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_...
Override the default theme static to add cache burst
def strip(notebook): for cell in notebook.cells: if cell.cell_type == 'code': cell.outputs = [] cell.execution_count = None
module function_definition identifier parameters identifier block for_statement identifier attribute identifier identifier block if_statement comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment attribute identifier identifier list expre...
Remove outputs from a notebook.
def _is_mobile(ntype): return (ntype == PhoneNumberType.MOBILE or ntype == PhoneNumberType.FIXED_LINE_OR_MOBILE or ntype == PhoneNumberType.PAGER)
module function_definition identifier parameters identifier block return_statement parenthesized_expression boolean_operator boolean_operator comparison_operator identifier attribute identifier identifier comparison_operator identifier attribute identifier identifier comparison_operator identifier attribute identifier ...
Checks if the supplied number type supports carrier lookup
def install(): tmp_weboob_dir = '/tmp/weboob' while (os.path.exists(tmp_weboob_dir)): tmp_weboob_dir += '1' print 'Fetching sources in temporary dir {}'.format(tmp_weboob_dir) result = cmd_exec('git clone {} {}'.format(WEBOOB_REPO, tmp_weboob_dir)) if (result['error']): print result[...
module function_definition identifier parameters block expression_statement assignment identifier string string_start string_content string_end while_statement parenthesized_expression call attribute attribute identifier identifier identifier argument_list identifier block expression_statement augmented_assignment iden...
Install weboob system-wide
def create(self, id): resp = self.client.accounts.create(id=id) self.display(resp)
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute attribute attribute identifier identifier identifier identifier argument_list keyword_argument identifier identifier expression_statement call attribute identifier identifier argument_l...
Create a new tenant id
def fromTFExample(bytestr): example = tf.train.Example() example.ParseFromString(bytestr) return example
module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list expression_statement call attribute identifier identifier argument_list identifier return_statement identifier
Deserializes a TFExample from a byte string
def schema_map(schema): mapper = {} for name in getFieldNames(schema): mapper[name] = name return mapper
module function_definition identifier parameters identifier block expression_statement assignment identifier dictionary for_statement identifier call identifier argument_list identifier block expression_statement assignment subscript identifier identifier identifier return_statement identifier
Return a valid ICachedItemMapper.map for schema
def _write_to_graph(self): traces = [] for byte_code, trace_data in self.coverage.items(): traces += [list(trace_data.keys()), list(trace_data.values()), "r--"] plt.plot(*traces) plt.axis([0, self.end - self.begin, 0, 100]) plt.xlabel("Duration (seconds)") plt...
module function_definition identifier parameters identifier block expression_statement assignment identifier list for_statement pattern_list identifier identifier call attribute attribute identifier identifier identifier argument_list block expression_statement augmented_assignment identifier list call identifier argum...
Write the coverage results to a graph
def _clean_result(self, text): text = re.sub('\s\s+', ' ', text) text = re.sub('\.\.+', '.', text) text = text.replace("'", "\\'") return text
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end identifier expression_statement assignment identifier cal...
Remove double spaces, punctuation and escapes apostrophes.
def _question_line(self, section): token = self.tok.get(want_leading = True) if not token.is_whitespace(): self.last_name = dns.name.from_text(token.value, None) name = self.last_name token = self.tok.get() if not token.is_identifier(): raise dns.exception...
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list keyword_argument identifier true if_statement not_operator call attribute identifier identifier argument_list block expression_s...
Process one line from the text format question section.
def _decode_temp(byte_1, byte_2): temp = (byte_1 << 8) + byte_2 if (temp > 32767): temp = temp - 65536 temp = temp / 10 return temp
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier binary_operator parenthesized_expression binary_operator identifier integer identifier if_statement parenthesized_expression comparison_operator identifier integer block expression_statement assignmen...
Decode a signed short temperature as two bytes to a single number.
def to_vararray(var_instance, bounds): assert isinstance(var_instance, SymbolVAR) from symbols import BOUNDLIST from symbols import VARARRAY assert isinstance(bounds, BOUNDLIST) var_instance.__class__ = VARARRAY var_instance.class_ = CLASS.array var_instance.bound...
module function_definition identifier parameters identifier identifier block assert_statement call identifier argument_list identifier identifier import_from_statement dotted_name identifier dotted_name identifier import_from_statement dotted_name identifier dotted_name identifier assert_statement call identifier argum...
Converts a var_instance to a var array one
def app_profile_path(cls, project, instance, app_profile): return google.api_core.path_template.expand( "projects/{project}/instances/{instance}/appProfiles/{app_profile}", project=project, instance=instance, app_profile=app_profile, )
module function_definition identifier parameters identifier identifier identifier identifier block return_statement call attribute attribute attribute identifier identifier identifier identifier argument_list string string_start string_content string_end keyword_argument identifier identifier keyword_argument identifie...
Return a fully-qualified app_profile string.
def reloadGraphs(self) : "reloads the graph list" r = self.connection.session.get(self.graphsURL) data = r.json() if r.status_code == 200 : self.graphs = {} for graphData in data["graphs"] : try : self.graphs[graphData["_key"]] ...
module function_definition identifier parameters identifier block expression_statement string string_start string_content string_end expression_statement assignment identifier call attribute attribute attribute identifier identifier identifier identifier argument_list attribute identifier identifier expression_statemen...
reloads the graph list
def find_api_id(self): allapis = self.client.get_rest_apis() api_name = self.trigger_settings['api_name'] api_id = None for api in allapis['items']: if api['name'] == api_name: api_id = api['id'] self.log.info("Found API for: %s", api_name) ...
module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list expression_statement assignment identifier subscript attribute identifier identifier string string_start string_content string_end expressi...
Given API name, find API ID.
def catCSVs(folder, ouputFileName, removeDups = False) : strCmd = r %(folder, ouputFileName) os.system(strCmd) if removeDups : removeDuplicates(ouputFileName, ouputFileName)
module function_definition identifier parameters identifier identifier default_parameter identifier false block expression_statement assignment identifier binary_operator identifier tuple identifier identifier expression_statement call attribute identifier identifier argument_list identifier if_statement identifier blo...
Concatenates all csv in 'folder' and wites the results in 'ouputFileName'. My not work on non Unix systems
def colordict(self): d = {} i=0 n = len(self.constraints) for c in self.constraints: d[c] = cm.jet(1.*i/n) i+=1 return d
module function_definition identifier parameters identifier block expression_statement assignment identifier dictionary expression_statement assignment identifier integer expression_statement assignment identifier call identifier argument_list attribute identifier identifier for_statement identifier attribute identifie...
Dictionary holding colors that correspond to constraints.
def energy(self): e = 0 for i in range(len(self.state)): e += self.distance_matrix[self.state[i-1]][self.state[i]] return e
module function_definition identifier parameters identifier block expression_statement assignment identifier integer for_statement identifier call identifier argument_list call identifier argument_list attribute identifier identifier block expression_statement augmented_assignment identifier subscript subscript attribu...
Calculates the length of the route.
def base_url(klass, space_id, resource_id=None, public=False, environment_id=None, **kwargs): if public: environment_slug = "" if environment_id is not None: environment_slug = "/environments/{0}".format(environment_id) return "spaces/{0}{1}/public/content_typ...
module function_definition identifier parameters identifier identifier default_parameter identifier none default_parameter identifier false default_parameter identifier none dictionary_splat_pattern identifier block if_statement identifier block expression_statement assignment identifier string string_start string_end ...
Returns the URI for the content type.
def _get_app_config(self, app_name): matches = [app_config for app_config in apps.get_app_configs() if app_config.name == app_name] if not matches: return return matches[0]
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier list_comprehension identifier for_in_clause identifier call attribute identifier identifier argument_list if_clause comparison_operator attribute identifier identifier identifier if_statement not_oper...
Returns an app config for the given name, not by label.
def urlencode(params): if not isinstance(params, dict): raise TypeError("Only dicts are supported.") params = flatten(params) url_params = OrderedDict() for param in params: value = param.pop() name = parametrize(param) if isinstance(value, (list, tuple)): nam...
module function_definition identifier parameters identifier block if_statement not_operator call identifier argument_list identifier identifier block raise_statement call identifier argument_list string string_start string_content string_end expression_statement assignment identifier call identifier argument_list ident...
Urlencode a multidimensional dict.
def _get_s3_files(local_dir, file_info, params): assert len(file_info) == 1 files = file_info.values()[0] fnames = [] for k in ["1", "2"]: if files[k] not in fnames: fnames.append(files[k]) out = [] for fname in fnames: bucket, key = fname.replace("s3://", "").split("...
module function_definition identifier parameters identifier identifier identifier block assert_statement comparison_operator call identifier argument_list identifier integer expression_statement assignment identifier subscript call attribute identifier identifier argument_list integer expression_statement assignment id...
Retrieve s3 files to local directory, handling STORMSeq inputs.
def sqlvm_group_create(client, cmd, sql_virtual_machine_group_name, resource_group_name, location, sql_image_offer, sql_image_sku, domain_fqdn, cluster_operator_account, sql_service_account, storage_account_url, storage_account_key, cluster_bootstrap_account=None, ...
module function_definition identifier parameters identifier identifier identifier identifier identifier identifier identifier identifier identifier identifier identifier identifier default_parameter identifier none default_parameter identifier none default_parameter identifier none default_parameter identifier none blo...
Creates a SQL virtual machine group.
def home(request): try: DBSession.query(User).first() except DBAPIError: return Response( conn_err_msg, content_type="text/plain", status_int=500, ) return {"project": "pyramid_tut"}
module function_definition identifier parameters identifier block try_statement block expression_statement call attribute call attribute identifier identifier argument_list identifier identifier argument_list except_clause identifier block return_statement call identifier argument_list identifier keyword_argument ident...
Try to connect to database, and list available examples.
def _read_depth_images(self, num_images): depth_images = self._ros_read_images(self._depth_image_buffer, num_images, self.staleness_limit) for i in range(0, num_images): depth_images[i] = depth_images[i] * MM_TO_METERS if self._flip_images: depth_images[i] = np.fl...
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier identifier attribute identifier identifier for_statement identifier call identifier argument_list integer identifier ...
Reads depth images from the device
def load_yaml(fname): yaml = YAML(typ="safe") yaml.allow_duplicate_keys = True HassSafeConstructor.name = fname yaml.Constructor = HassSafeConstructor with open(fname, encoding="utf-8") as conf_file: return yaml.load(conf_file) or {}
module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list keyword_argument identifier string string_start string_content string_end expression_statement assignment attribute identifier identifier true expression_statement assignment attrib...
Load a YAML file.
def cli(sequencepath, report, refseq_database): main(sequencepath, report, refseq_database, num_threads=multiprocessing.cpu_count())
module function_definition identifier parameters identifier identifier identifier block expression_statement call identifier argument_list identifier identifier identifier keyword_argument identifier call attribute identifier identifier argument_list
Pass command line arguments to, and run the feature extraction functions
def dynare_import(filename,full_output=False, debug=False): import os basename = os.path.basename(filename) fname = re.compile('(.*)\.(.*)').match(basename).group(1) f = open(filename) txt = f.read() model = parse_dynare_text(txt,full_output=full_output, debug=debug) model.name = fname r...
module function_definition identifier parameters identifier default_parameter identifier false default_parameter identifier false block import_statement dotted_name identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier expression_stateme...
Imports model defined in specified file
def start(self, ccallbacks=None): self.__manage_g = gevent.spawn(self.__manage_connections, ccallbacks) self.__ready_ev.wait()
module function_definition identifier parameters identifier default_parameter identifier none block expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list attribute identifier identifier identifier expression_statement call attribute attribute identifier ident...
Establish and maintain connections.
def busy_display(): sys.stdout.write("\033[?25l") sys.stdout.flush() for x in range(1800): symb = ['\\', '|', '/', '-'] sys.stdout.write("\033[D{}".format(symb[x % 4])) sys.stdout.flush() gevent.sleep(0.1)
module function_definition identifier parameters block expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content escape_sequence string_end expression_statement call attribute attribute identifier identifier identifier argument_list for_statement ide...
Display animation to show activity.
def _try_import(module_name): try: mod = importlib.import_module(module_name) return mod except ImportError: err_msg = ("Tried importing %s but failed. See setup.py extras_require. " "The dataset you are trying to use may have additional " "dependencies.") utils.reraise...
module function_definition identifier parameters identifier block try_statement block expression_statement assignment identifier call attribute identifier identifier argument_list identifier return_statement identifier except_clause identifier block expression_statement assignment identifier parenthesized_expression co...
Try importing a module, with an informative error message on failure.
def treeplot(self, qlist, credible_interval): for y, _, label, values, color in self.iterator(): ntiles = np.percentile(values.flatten(), qlist) ntiles[0], ntiles[-1] = hpd(values.flatten(), credible_interval) yield y, label, ntiles, color
module function_definition identifier parameters identifier identifier identifier block for_statement pattern_list identifier identifier identifier identifier identifier call attribute identifier identifier argument_list block expression_statement assignment identifier call attribute identifier identifier argument_list...
Get data for each treeplot for the variable.
def worker_loop_v1(dataset, key_queue, data_queue, batchify_fn): while True: idx, samples = key_queue.get() if idx is None: break batch = batchify_fn([dataset[i] for i in samples]) data_queue.put((idx, batch))
module function_definition identifier parameters identifier identifier identifier identifier block while_statement true block expression_statement assignment pattern_list identifier identifier call attribute identifier identifier argument_list if_statement comparison_operator identifier none block break_statement expre...
Worker loop for multiprocessing DataLoader.
def restore(self): if self.proxy_object is None: if self.getter: setattr(self.getter_class, self.attr_name, self.getter) elif self.is_local: setattr(self.orig_object, self.attr_name, self.orig_value) else: delattr(self.orig_obje...
module function_definition identifier parameters identifier block if_statement comparison_operator attribute identifier identifier none block if_statement attribute identifier identifier block expression_statement call identifier argument_list attribute identifier identifier attribute identifier identifier attribute id...
Restore the saved value for the attribute of the object.
def _array2cstr(arr): out = StringIO() np.save(out, arr) return b64encode(out.getvalue())
module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list expression_statement call attribute identifier identifier argument_list identifier identifier return_statement call identifier argument_list call attribute identifier identifier arg...
Serializes a numpy array to a compressed base64 string
def search_fetch_force(request, id, redirect_to): search = Search.objects.get(id=id) search.fetch(force=True) msg = _("Fetched tweets for %s" % search.criteria) messages.success(request, msg, fail_silently=True) return HttpResponseRedirect(redirect_to)
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list keyword_argument identifier identifier expression_statement call attribute identifier identifier argument_list keywor...
Forcibly fetch tweets for the search
def listDatasetAccessTypes(self, dataset_access_type=""): if isinstance(dataset_access_type, basestring): try: dataset_access_type = str(dataset_access_type) except: dbsExceptionHandler('dbsException-invalid-input', 'dataset_access_type given is not va...
module function_definition identifier parameters identifier default_parameter identifier string string_start string_end block if_statement call identifier argument_list identifier identifier block try_statement block expression_statement assignment identifier call identifier argument_list identifier except_clause block...
List dataset access types
def json_wrap(function, *args, **kwargs): try: response = json.loads(function(*args, **kwargs).content) if 'data' in response: return response['data'] or True else: return response except Exception as exc: raise ClientException(exc)
module function_definition identifier parameters identifier list_splat_pattern identifier dictionary_splat_pattern identifier block try_statement block expression_statement assignment identifier call attribute identifier identifier argument_list attribute call identifier argument_list list_splat identifier dictionary_s...
Return the json content of a function that returns a request
def max(cls): max_recid = db.session.query(func.max(cls.recid)).scalar() return max_recid if max_recid else 0
module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute call attribute attribute identifier identifier identifier argument_list call attribute identifier identifier argument_list attribute identifier identifier identifier argument_list return_statement...
Get max record identifier.
def default_user_agent(name="python-requests"): _implementation = platform.python_implementation() if _implementation == 'CPython': _implementation_version = platform.python_version() elif _implementation == 'PyPy': _implementation_version = '%s.%s.%s' % (sys.pypy_version_info.major, ...
module function_definition identifier parameters default_parameter identifier string string_start string_content string_end block expression_statement assignment identifier call attribute identifier identifier argument_list if_statement comparison_operator identifier string string_start string_content string_end block ...
Return a string representing the default user agent.
def identity(ctx, variant_id): if not variant_id: LOG.warning("Please provide a variant id") ctx.abort() adapter = ctx.obj['adapter'] version = ctx.obj['version'] LOG.info("Search variants {0}".format(adapter)) result = adapter.get_clusters(variant_id) if result.count() == 0: ...
module function_definition identifier parameters identifier identifier block if_statement not_operator identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list expression...
Check how well SVs are working in the database
def weighted_tanimoto(a, b, weights): weighted = lambda s: map(lambda (x,y): float(x)*float(y), zip(s, weights)) return tanimoto_coefficient(weighted(a), weighted(b))
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier lambda lambda_parameters identifier call identifier argument_list lambda lambda_parameters tuple_pattern identifier identifier binary_operator call identifier argument_list identifier call ...
Same as the Tanimoto coefficient, but wit weights for each dimension.
def ssh_config(ssh_user, ssh_private_key_file): try: ssh_file = NamedTemporaryFile(delete=False, mode='w+') ssh_file.write('Host *\n') ssh_file.write(' IdentityFile %s\n' % ssh_private_key_file) ssh_file.write(' User %s' % ssh_user) ssh_file.close() yield ssh_fi...
module function_definition identifier parameters identifier identifier block try_statement block expression_statement assignment identifier call identifier argument_list keyword_argument identifier false keyword_argument identifier string string_start string_content string_end expression_statement call attribute identi...
Create temporary ssh config file.
def c_str(string): if not isinstance(string, str): string = string.decode('ascii') return ctypes.c_char_p(string.encode('utf-8'))
module function_definition identifier parameters identifier block if_statement not_operator call identifier argument_list identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end return_statement call attribut...
Convert a python string to C string.
def create_database_session(engine): try: Session = sessionmaker(bind=engine) return Session() except OperationalError as e: raise DatabaseError(error=e.orig.args[1], code=e.orig.args[0])
module function_definition identifier parameters identifier block try_statement block expression_statement assignment identifier call identifier argument_list keyword_argument identifier identifier return_statement call identifier argument_list except_clause as_pattern identifier as_pattern_target identifier block rais...
Connect to the database
def __load_countries(self, db): try: countries = self.__read_countries_file() except IOError as e: raise LoadError(str(e)) try: with db.connect() as session: for country in countries: session.add(country) except Exce...
module function_definition identifier parameters identifier identifier block try_statement block expression_statement assignment identifier call attribute identifier identifier argument_list except_clause as_pattern identifier as_pattern_target identifier block raise_statement call identifier argument_list call identif...
Load the list of countries
def select_locale_by_request(self, request, locales=()): default_locale = locales and locales[0] or self.cfg.default_locale if len(locales) == 1 or 'ACCEPT-LANGUAGE' not in request.headers: return default_locale ulocales = [ (q, locale_delim_re.split(v)[0]) fo...
module function_definition identifier parameters identifier identifier default_parameter identifier tuple block expression_statement assignment identifier boolean_operator boolean_operator identifier subscript identifier integer attribute attribute identifier identifier identifier if_statement boolean_operator comparis...
Choose an user's locales by request.
def _load_rules(forcefield): rules = dict() for rule_name, smarts in forcefield.atomTypeDefinitions.items(): overrides = forcefield.atomTypeOverrides.get(rule_name) if overrides is not None: overrides = set(overrides) else: overrides = set() rules[rule_nam...
module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list for_statement pattern_list identifier identifier call attribute attribute identifier identifier identifier argument_list block expression_statement assignment identifier call attrib...
Load atomtyping rules from a forcefield into SMARTSGraphs.
def load_data(self): try: df = self.live_quote_arg_func(self.tickers) for index, ticker in enumerate(self.tickers): ticker_info = df.loc[index] self.ticker_dict[ticker].append(ticker_info['price'], ticker_inf...
module function_definition identifier parameters identifier block try_statement block expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier for_statement pattern_list identifier identifier call identifier argument_list attribute identifier identifi...
Overwrite this for new source data structures
def resource(self): if self._resource: return self._resource elif self.binding: return self.binding.resource
module function_definition identifier parameters identifier block if_statement attribute identifier identifier block return_statement attribute identifier identifier elif_clause attribute identifier identifier block return_statement attribute attribute identifier identifier identifier
Resource associated with operation.
def append_rally_point(self, p): if (self.rally_count() > 9): print("Can't have more than 10 rally points, not adding.") return self.rally_points.append(p) self.reindex()
module function_definition identifier parameters identifier identifier block if_statement parenthesized_expression comparison_operator call attribute identifier identifier argument_list integer block expression_statement call identifier argument_list string string_start string_content string_end return_statement expres...
add rallypoint to end of list
def to_dict(self): if not self.url: return None return { 'url': self.url, 'width': self.width, 'height': self.height }
module function_definition identifier parameters identifier block if_statement not_operator attribute identifier identifier block return_statement none return_statement dictionary pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attrib...
Convert Image into raw dictionary data.
def fetch(index, tokens): if len(tokens) == 0: return set() return set.intersection(*[set(index.get(token, [])) for token in tokens])
module function_definition identifier parameters identifier identifier block if_statement comparison_operator call identifier argument_list identifier integer block return_statement call identifier argument_list return_statement call attribute identifier identifier argument_list list_splat list_comprehension call ident...
Fetch the codes from given tokens
def read_header(self): with fopen(self.vpk_path, 'rb') as f: (self.signature, self.version, self.tree_length ) = struct.unpack("3I", f.read(3*4)) if self.signature != 0x55aa1234: raise ValueError("File is not VPK (invalid magic)") ...
module function_definition identifier parameters identifier block with_statement with_clause with_item as_pattern call identifier argument_list attribute identifier identifier string string_start string_content string_end as_pattern_target identifier block expression_statement assignment tuple_pattern attribute identif...
Reads VPK file header from the file
def _read_temp(data): tout = StringIO() tout.write(data) tout.seek(0) output = tout.readlines() tout.close() return output
module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list integer expression_stateme...
Return what would be written to disk
def stop_jobs(self, job_ids=None): self.lock() jobs = self.get_jobs(job_ids) for job in jobs: if job.status in ('executing', 'queued', 'waiting') and job.queue_name == 'local': logger.info("Reset job '%s' (%s) in the database", job.name, self._format_log(job.id)) job.submit() self....
module function_definition identifier parameters identifier default_parameter identifier none block expression_statement call attribute identifier identifier argument_list expression_statement assignment identifier call attribute identifier identifier argument_list identifier for_statement identifier identifier block i...
Resets the status of the job to 'submitted' when they are labeled as 'executing'.
def cl_picard(self, command, options, memscale=None): options = ["%s=%s" % (x, y) for x, y in options] options.append("VALIDATION_STRINGENCY=SILENT") return self._get_picard_cmd(command, memscale=memscale) + options
module function_definition identifier parameters identifier identifier identifier default_parameter identifier none block expression_statement assignment identifier list_comprehension binary_operator string string_start string_content string_end tuple identifier identifier for_in_clause pattern_list identifier identifi...
Prepare a Picard commandline.
def strip( text ): members = [attr for attr in Colors.__dict__.keys() if not attr.startswith( "__" ) and not attr == 'strip'] for c in members: text = text.replace( vars( Colors )[c], '' ) return text
module function_definition identifier parameters identifier block expression_statement assignment identifier list_comprehension identifier for_in_clause identifier call attribute attribute identifier identifier identifier argument_list if_clause boolean_operator not_operator call attribute identifier identifier argumen...
Strips all color codes from a text.
def DiffArrayObjects(self, oldObj, newObj, isElementLinks=False): if oldObj == newObj: return True if not oldObj or not newObj: return False if len(oldObj) != len(newObj): __Log__.debug('DiffArrayObjects: Array lengths do not match %d != %d' % (len(oldObj), len(n...
module function_definition identifier parameters identifier identifier identifier default_parameter identifier false block if_statement comparison_operator identifier identifier block return_statement true if_statement boolean_operator not_operator identifier not_operator identifier block return_statement false if_stat...
Method which deligates the diffing of arrays based on the type
def plot_gaps(plot, columns): from plot_window import window_plot_convolve as plot_window plot_window([[100 - i for i in columns]], len(columns)*.01, plot)
module function_definition identifier parameters identifier identifier block import_from_statement dotted_name identifier aliased_import dotted_name identifier identifier expression_statement call identifier argument_list list list_comprehension binary_operator integer identifier for_in_clause identifier identifier bin...
plot % of gaps at each position
def getMouse(self): self.mouse_x.value = -1 self.mouse_y.value = -1 while self.mouse_x.value == -1 and self.mouse_y.value == -1: time.sleep(.1) return (self.mouse_x.value, self.mouse_y.value)
module function_definition identifier parameters identifier block expression_statement assignment attribute attribute identifier identifier identifier unary_operator integer expression_statement assignment attribute attribute identifier identifier identifier unary_operator integer while_statement boolean_operator compa...
Waits for a mouse click.
def _split_string_to_tokens(text): if not text: return [] ret = [] token_start = 0 is_alnum = [c in _ALPHANUMERIC_CHAR_SET for c in text] for pos in xrange(1, len(text)): if is_alnum[pos] != is_alnum[pos - 1]: token = text[token_start:pos] if token != u" " or token_start == 0: ret....
module function_definition identifier parameters identifier block if_statement not_operator identifier block return_statement list expression_statement assignment identifier list expression_statement assignment identifier integer expression_statement assignment identifier list_comprehension comparison_operator identifi...
Splits text to a list of string tokens.
def handle_pubrel(self): self.logger.info("PUBREL received") ret, mid = self.in_packet.read_uint16() if ret != NC.ERR_SUCCESS: return ret evt = event.EventPubrel(mid) self.push_event(evt) return NC.ERR_SUCCESS
module function_definition identifier parameters identifier block expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end expression_statement assignment pattern_list identifier identifier call attribute attribute identifier identifier i...
Handle incoming PUBREL packet.
def detach(self): if not self._closed: del self._as_parameter_ self._closed = True self._ptr = None
module function_definition identifier parameters identifier block if_statement not_operator attribute identifier identifier block delete_statement attribute identifier identifier expression_statement assignment attribute identifier identifier true expression_statement assignment attribute identifier identifier none
Detach the underlying LLVM resource without disposing of it.