Unnamed: 0
int64
0
389k
code
stringlengths
26
79.6k
docstring
stringlengths
1
46.9k
383,400
def getprefixes(self): namespaces = [] for l in (self.params, self.types): for t,r in l: ns = r.namespace() if ns[1] is None: continue if ns[1] in namespaces: continue if Namespace.xs(ns) or Namespace.xsd(ns): continue namespaces.append(ns[1]) if t == r: continue ns = t.namespace() if ns[1] is None: continue if ns[1] in namespaces: continue namespaces.append(ns[1]) i = 0 namespaces.sort() for u in namespaces: p = self.nextprefix() ns = (p, u) self.prefixes.append(ns)
Add prefixes for each namespace referenced by parameter types.
383,401
def select(table, key=): database = choice(__db[key + ]) return database.select(table)
Select dialect :param key: a key for your dabtabase you wanna use
383,402
def dispatch(self, *args, **kwargs): return super(AnimalDelete, self).dispatch(*args, **kwargs)
This decorator sets this view to have restricted permissions.
383,403
def evolve(self, new_date): self.state = [p.evolve(new_date) for p in self.producers] return self.state
evolve to the new process state at the next date, i.e. do one step in the simulation :param date new_date: date of the new state :return State:
383,404
def run(self): if not self.services: self.log.warning("no service checks are configured") else: self.log.info("going to lunch %s threads", len(self.services)) if self.config.has_option(, ): splay_startup = self.config.getfloat(, ) else: splay_startup = None for service in self.services: self.log.debug("lunching thread for %s", service) _config = {} for option, getter in SERVICE_OPTIONS_TYPE.items(): try: _config[option] = getattr(self.config, getter)(service, option) except NoOptionError: pass _thread = ServiceCheck(service, _config, self.action, splay_startup) _thread.start() while True: operation = self.action.get(block=True) if isinstance(operation, ServiceCheckDiedError): self.log.critical(operation) self.log.critical("This is a fatal error and the only way to " "recover is to restart, thus exiting with a " "non-zero code and let systemd act by " "triggering a restart") sys.exit(1) self.log.info("returned an item from the queue for %s with IP " "prefix %s and action to %s Bird configuration", operation.name, operation.ip_prefix, operation) bird_updated = self._update_bird_conf_file(operation) self.action.task_done() if bird_updated: ip_version = operation.ip_version if operation.bird_reconfigure_cmd is None: reconfigure_bird( self.bird_configuration[ip_version][]) else: run_custom_bird_reconfigure(operation)
Lunch checks and triggers updates on BIRD configuration.
383,405
def open_using_pefile(input_name, input_bytes): try: pef = pefile.PE(data=input_bytes, fast_load=False) except (AttributeError, pefile.PEFormatError), error: print % input_name error_str = % (str(error)) return None, error_str if pef.PE_TYPE is None or pef.OPTIONAL_HEADER is None or len(pef.OPTIONAL_HEADER.DATA_DIRECTORY) < 7: print % input_name error_str = % input_name return None, error_str return pef, None
Open the PE File using the Python pefile module.
383,406
def get(self): output = for f in self.functions: output += self.underline(f) + if f in self.synopsises and isinstance(self.synopsises[f], str): output += self.format(self.synopsises[f]) + if f in self.descriptions and isinstance( self.descriptions[f], str ): output += self.format(self.descriptions[f], indent=8) + if f in self.examples and isinstance(self.examples[f], str): output += self.format(self.examples[f], indent=8) + output += return output
Retrieve a formated text string
383,407
def _space_delimited_list(value): if isinstance(value, six.string_types): items = value.split() valid = items and all(items) else: valid = hasattr(value, ) and (value != []) if valid: return True, return False, .format(value)
validate that a value contains one or more space-delimited values
383,408
def numpy_weighted_median(data, weights=None): import numpy as np if weights is None: return np.median(np.array(data).flatten()) data, weights = np.array(data).flatten(), np.array(weights).flatten() if any(weights > 0): sorted_data, sorted_weights = map(np.array, zip(*sorted(zip(data, weights)))) midpoint = 0.5 * sum(sorted_weights) if any(weights > midpoint): return (data[weights == np.max(weights)])[0] cumulative_weight = np.cumsum(sorted_weights) below_midpoint_index = np.where(cumulative_weight <= midpoint)[0][-1] if cumulative_weight[below_midpoint_index] - midpoint < sys.float_info.epsilon: return np.mean(sorted_data[below_midpoint_index:below_midpoint_index+2]) return sorted_data[below_midpoint_index+1]
Calculate the weighted median of an array/list using numpy.
383,409
def impersonate(self, user, enterprise): if not user or not enterprise: raise ValueError() self._is_impersonating = True self._impersonation = "%s@%s" % (user, enterprise)
Impersonate a user in a enterprise Args: user: the name of the user to impersonate enterprise: the name of the enterprise where to use impersonation
383,410
def copy_foreign_keys(self, event): event_keys = set(event._meta.fields.keys()) obj_keys = self._meta.fields.keys() matching_keys = event_keys.intersection(obj_keys) for key in matching_keys: if key == : continue setattr(event, possible_key, self)
Copies possible foreign key values from the object into the Event, skipping common keys like modified and created. Args: event (Event): The Event instance to copy the FKs into obj (fleaker.db.Model): The object to pull the values from
383,411
def parse_source_file(file_name): with open(file_name, ) as f: s = f.read() nodes = ast.parse(s) module_imports = get_nodes_by_instance_type(nodes, _ast.Import) specific_imports = get_nodes_by_instance_type(nodes, _ast.ImportFrom) assignment_objs = get_nodes_by_instance_type(nodes, _ast.Assign) call_objects = get_nodes_by_instance_type(nodes, _ast.Call) argparse_assignments = get_nodes_by_containing_attr(assignment_objs, ) group_arg_assignments = get_nodes_by_containing_attr(assignment_objs, ) add_arg_assignments = get_nodes_by_containing_attr(call_objects, ) parse_args_assignment = get_nodes_by_containing_attr(call_objects, ) if not argparse_assignments: aa_references = set([i.func.value.id for i in chain(add_arg_assignments, parse_args_assignment)]) argparse_like_objects = [getattr(i.value.func, , None) for p_ref in aa_references for i in get_nodes_by_containing_attr(assignment_objs, p_ref)] argparse_like_objects = filter(None, argparse_like_objects) argparse_assignments = [get_nodes_by_containing_attr(assignment_objs, i) for i in argparse_like_objects] try: argparse_assignments = argparse_assignments[0] except IndexError: pass argparse_assigned_variables = get_node_args_and_keywords(assignment_objs, argparse_assignments, ) add_arg_assigned_variables = get_node_args_and_keywords(assignment_objs, add_arg_assignments, ) parse_args_assigned_variables = get_node_args_and_keywords(assignment_objs, parse_args_assignment, ) ast_argparse_source = chain( module_imports, specific_imports, argparse_assigned_variables, add_arg_assigned_variables, parse_args_assigned_variables, argparse_assignments, group_arg_assignments, add_arg_assignments, ) return ast_argparse_source
Parses the AST of Python file for lines containing references to the argparse module. returns the collection of ast objects found. Example client code: 1. parser = ArgumentParser(desc="My help Message") 2. parser.add_argument('filename', help="Name of the file to load") 3. parser.add_argument('-f', '--format', help='Format of output \nOptions: ['md', 'html'] 4. args = parser.parse_args() Variables: * nodes Primary syntax tree object * argparse_assignments The assignment of the ArgumentParser (line 1 in example code) * add_arg_assignments Calls to add_argument() (lines 2-3 in example code) * parser_var_name The instance variable of the ArgumentParser (line 1 in example code) * ast_source The curated collection of all parser related nodes in the client code
383,412
def _deactivate(self): self.cache.remove_fetcher(self) if self.active: self._deactivated()
Remove the fetcher from cache and mark it not active.
383,413
def GetAttributeNames(self): attribute_names = [] for attribute_name in iter(self.__dict__.keys()): if attribute_name[0] == : continue attribute_names.append(attribute_name) return attribute_names
Retrieves the names of all attributes. Returns: list[str]: attribute names.
383,414
def yaml_conf_as_dict(file_path, encoding=None): if not pathlib.Path(file_path).is_file(): return False, {}, try: if sys.version > : with open(file_path, , encoding=encoding) as f: d = OrderedDict(yaml.load(f.read())) return True, d, else: with open(file_path, ) as f: d = OrderedDict(yaml.load(f.read())) return True, d, except: return False, {},
读入 yaml 配置文件,返回根据配置文件内容生成的字典类型变量 :param: * file_path: (string) 需要读入的 yaml 配置文件长文件名 * encoding: (string) 文件编码 * msg: (string) 读取配置信息 :return: * flag: (bool) 读取配置文件是否正确,正确返回 True,错误返回 False * d: (dict) 如果读取配置文件正确返回的包含配置文件内容的字典,字典内容顺序与配置文件顺序保持一致 举例如下:: print('--- yaml_conf_as_dict demo---') # 定义配置文件名 conf_filename = 'test_conf.yaml' # 读取配置文件 ds = yaml_conf_as_dict(conf_filename, encoding='utf-8') # 显示是否成功,所有 dict 的内容,dict 的 key 数量 print('flag:', ds[0]) print('dict length:', len(ds[1])) print('msg:', len(ds[1])) print('conf info: ', ds[1].get('tree')) print('---') 执行结果:: --- yaml_conf_as_dict demo--- flag: True dict length: 2 msg: Success conf info: ['README.md', 'requirements.txt', {'hellopackage': ['__init__.py']}, {'test': ['__init__.py']}, {'doc': ['doc.rst']}] ---
383,415
def crawl(plugin): paths_visited = set() paths_to_visit = set(item.get_path() for item in once(plugin)) while paths_to_visit and continue_or_quit(): path = paths_to_visit.pop() paths_visited.add(path) patch_plugin(plugin, path) new_paths = set(item.get_path() for item in once(plugin)) paths_to_visit.update(path for path in new_paths if path not in paths_visited)
Performs a breadth-first crawl of all possible routes from the starting path. Will only visit a URL once, even if it is referenced multiple times in a plugin. Requires user interaction in between each fetch.
383,416
def _get_gos_upper(self, ntpltgo1, max_upper, go2parentids): goids_possible = ntpltgo1.gosubdag.go2obj.keys() return self._get_gosrcs_upper(goids_possible, max_upper, go2parentids)
Plot a GO DAG for the upper portion of a single Group of user GOs.
383,417
def docker_fabric(*args, **kwargs): ci = kwargs.get() or env.get() or CLIENT_API if ci == CLIENT_API: return docker_api(*args, **kwargs) elif ci == CLIENT_CLI: return docker_cli(*args, **kwargs) raise ValueError("Invalid client implementation.", ci)
:param args: Positional arguments to Docker client. :param kwargs: Keyword arguments to Docker client. :return: Docker client. :rtype: dockerfabric.apiclient.DockerFabricClient | dockerfabric.cli.DockerCliClient
383,418
def _hashable_bytes(data): if isinstance(data, bytes): return data elif isinstance(data, str): return data.encode() else: raise TypeError(data)
Coerce strings to hashable bytes.
383,419
def displacements(self): disps = [] if in self._displacement_dataset: for disp in self._displacement_dataset[]: x = disp[] disps.append([disp[], x[0], x[1], x[2]]) elif in self._displacement_dataset: disps = self._displacement_dataset[] return disps
Return displacements Returns ------- There are two types of displacement dataset. See the docstring of set_displacement_dataset about types 1 and 2 for displacement dataset format. Type-1, List of list The internal list has 4 elements such as [32, 0.01, 0.0, 0.0]]. The first element is the supercell atom index starting with 0. The remaining three elements give the displacement in Cartesian coordinates. Type-2, array_like Displacements of all atoms of all supercells in Cartesian coordinates. shape=(supercells, natom, 3) dtype='double'
383,420
def get_sync_binding_cmds(self, switch_bindings, expected_bindings): switch_cmds = list() bindings_to_delete = switch_bindings - expected_bindings bindings_to_add = expected_bindings - switch_bindings for intf, acl, direction in bindings_to_delete: switch_cmds.extend([ % intf, % (acl, direction), ]) for intf, acl, direction in bindings_to_add: switch_cmds.extend([ % intf, % (acl, direction), ]) return switch_cmds
Returns the list of commands required to synchronize ACL bindings 1. Delete any unexpected bindings 2. Add any missing bindings
383,421
def tcl_list_2_py_list(tcl_list, within_tcl_str=False): if not within_tcl_str: tcl_list = tcl_str(tcl_list) return tcl_interp_g.eval( + tcl_list + ).split() if tcl_list else []
Convert Tcl list to Python list using Tcl interpreter. :param tcl_list: string representing the Tcl string. :param within_tcl_str: True - Tcl list is embedded within Tcl str. False - native Tcl string. :return: Python list equivalent to the Tcl ist. :rtye: list
383,422
def select_image_layer(infiles, output_file, log, context): options = context.get_options() page_pdf = next(ii for ii in infiles if ii.endswith()) image = next(ii for ii in infiles if ii.endswith()) if options.lossless_reconstruction: log.debug( f"{page_number(page_pdf):4d}: page eligible for lossless reconstruction" ) re_symlink(page_pdf, output_file, log) return pageinfo = get_pageinfo(image, context)
Selects the image layer for the output page. If possible this is the orientation-corrected input page, or an image of the whole page converted to PDF.
383,423
def getSenderNumberMgtURL(self, CorpNum, UserID): result = self._httpget(, CorpNum, UserID) return result.url
팩스 전송내역 팝업 URL args CorpNum : 회원 사업자번호 UserID : 회원 팝빌아이디 return 30초 보안 토큰을 포함한 url raise PopbillException
383,424
def approximator(molecules, options, sort_order=None, frameworks=[], ensemble=[]): ensemble_size = options.ensemble_size if not sort_order: sort_order = classification.get_sort_order(molecules) print("Performing calculations for ensemble size {s}".format(s=(len(ensemble) + 1))) ensemble = rank_queries(molecules, ensemble, sort_order, options) output.write_ensemble(list(ensemble), options) if len(ensemble) == ensemble_size: return 1 else: return approximator(molecules, options, sort_order, frameworks, ensemble)
recursively rank queries :param molecules: :param options: :param sort_order: :param frameworks: :param ensemble: :return:
383,425
def delete_option_value_by_id(cls, option_value_id, **kwargs): kwargs[] = True if kwargs.get(): return cls._delete_option_value_by_id_with_http_info(option_value_id, **kwargs) else: (data) = cls._delete_option_value_by_id_with_http_info(option_value_id, **kwargs) return data
Delete OptionValue Delete an instance of OptionValue by its ID. This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async=True >>> thread = api.delete_option_value_by_id(option_value_id, async=True) >>> result = thread.get() :param async bool :param str option_value_id: ID of optionValue to delete. (required) :return: None If the method is called asynchronously, returns the request thread.
383,426
def sort_canonical(keyword, stmts): try: (_arg_type, subspec) = stmt_map[keyword] except KeyError: return stmts res = [] keep = [s[0] for s in data_def_stmts] + [] for (kw, _spec) in flatten_spec(subspec): comments = [] for s in stmts: if s.keyword == : comments.append(s) elif s.keyword == kw and kw not in keep: res.extend(comments) comments = [] res.append(s) else: comments = [] res.extend([stmt for stmt in stmts if stmt not in res]) return res
Sort all `stmts` in the canonical order defined by `keyword`. Return the sorted list. The `stmt` list is not modified. If `keyword` does not have a canonical order, the list is returned as is.
383,427
def render_arrow(self, label, start, end, direction, i): level = self.levels.index(end - start) + 1 x_start = self.offset_x + start * self.distance + self.arrow_spacing if self.direction == "rtl": x_start = self.width - x_start y = self.offset_y x_end = ( self.offset_x + (end - start) * self.distance + start * self.distance - self.arrow_spacing * (self.highest_level - level) / 4 ) if self.direction == "rtl": x_end = self.width - x_end y_curve = self.offset_y - level * self.distance / 2 if self.compact: y_curve = self.offset_y - level * self.distance / 6 if y_curve == 0 and len(self.levels) > 5: y_curve = -self.distance arrowhead = self.get_arrowhead(direction, x_start, y, x_end) arc = self.get_arc(x_start, y, y_curve, x_end) label_side = "right" if self.direction == "rtl" else "left" return TPL_DEP_ARCS.format( id=self.id, i=i, stroke=self.arrow_stroke, head=arrowhead, label=label, label_side=label_side, arc=arc, )
Render individual arrow. label (unicode): Dependency label. start (int): Index of start word. end (int): Index of end word. direction (unicode): Arrow direction, 'left' or 'right'. i (int): Unique ID, typically arrow index. RETURNS (unicode): Rendered SVG markup.
383,428
def _get_top_level_secrets(self): top_level_secrets = dict() if self.secrets: for secret, secret_definition in iteritems(self.secrets): if isinstance(secret_definition, dict): for key, value in iteritems(secret_definition): name = .format(secret, key) top_level_secrets[name] = dict(external=True) elif isinstance(secret_definition, string_types): top_level_secrets[secret] = dict(external=True) return top_level_secrets
Convert the top-level 'secrets' directive to the Docker format :return: secrets dict
383,429
def write_file(self, fileobject, skip_unknown=False): self.set_metadata_version() for field in _version2fieldlist(self[]): values = self.get(field) if skip_unknown and values in (, [], []): continue if field in _ELEMENTSFIELD: self._write_field(fileobject, field, .join(values)) continue if field not in _LISTFIELDS: if field == : if self.metadata_version in (, ): values = values.replace(, ) else: values = values.replace(, ) values = [values] if field in _LISTTUPLEFIELDS: values = [.join(value) for value in values] for value in values: self._write_field(fileobject, field, value)
Write the PKG-INFO format data to a file object.
383,430
def _execute_comprehension(self, node: Union[ast.ListComp, ast.SetComp, ast.GeneratorExp, ast.DictComp]) -> Any: args = [ast.arg(arg=name) for name in sorted(self._name_to_value.keys())] func_def_node = ast.FunctionDef( name="generator_expr", args=ast.arguments(args=args, kwonlyargs=[], kw_defaults=[], defaults=[]), decorator_list=[], body=[ast.Return(node)]) module_node = ast.Module(body=[func_def_node]) ast.fix_missing_locations(module_node) code = compile(source=module_node, filename=, mode=) module_locals = {} module_globals = {} exec(code, module_globals, module_locals) generator_expr_func = module_locals["generator_expr"] return generator_expr_func(**self._name_to_value)
Compile the generator or comprehension from the node and execute the compiled code.
383,431
def date(name=None): if name is None: name = field = pp.Regex( ) field.setParseAction(lambda d: datetime.datetime.strptime(d[0], ) .date()) field.setName(name) field.leaveWhitespace() return field
Creates the grammar for a Date (D) field, accepting only numbers in a certain pattern. :param name: name for the field :return: grammar for the date field
383,432
def set_color_temperature(self, temperature, effect=EFFECT_SUDDEN, transition_time=MIN_TRANSITION_TIME): if self.is_off(): raise Exception("set_color_temperature cantemperatureeffecttransition_timetemperatureeffecttransition_time': transition_time}) params = [temperature, effect, transition_time] self.api_call.operate_on_bulb("set_ct_abx", params) self.property[self.PROPERTY_NAME_COLOR_TEMPERATURE] = temperature
Set the white color temperature. The bulb must be switched on. :param temperature: color temperature to set. It can be between 1700 and 6500 K :param effect: if the change is made suddenly or smoothly :param transition_time: in case the change is made smoothly, time in ms that change last :type temperature: int :type effect: str :type transition_time : int
383,433
def output_to_terminal(sources): results = OrderedDict() for source in sources: if source.get_is_available(): source.update() results.update(source.get_summary()) for key, value in results.items(): sys.stdout.write(str(key) + ": " + str(value) + ", ") sys.stdout.write("\n") sys.exit()
Print statistics to the terminal
383,434
def reverse_transform(self, column): self.check_data_type() return pd.DataFrame({self.col_name: np.log(column[self.col_name])})
Applies the natural logarithm function to turn positive values into real ranged values. Args: column (pandas.DataFrame): Data to transform. Returns: pd.DataFrame
383,435
def link(self, mu, dist): return np.log(mu) - np.log(dist.levels - mu)
glm link function this is useful for going from mu to the linear prediction Parameters ---------- mu : array-like of legth n dist : Distribution instance Returns ------- lp : np.array of length n
383,436
def node2geoff(node_name, properties, encoder): if properties: return .format(node_name, encoder.encode(properties)) else: return .format(node_name)
converts a NetworkX node into a Geoff string. Parameters ---------- node_name : str or int the ID of a NetworkX node properties : dict a dictionary of node attributes encoder : json.JSONEncoder an instance of a JSON encoder (e.g. `json.JSONEncoder`) Returns ------- geoff : str a Geoff string
383,437
def data(self): if self.is_obsolete(): data = self.get_data() for datum in data: if in datum: datum[] = \ self.parse_time(datum[]) try: dumped_data = json.dumps(data) except: self.update_cache(data) else: self.update_cache(dumped_data) return data try: return json.loads(self.cache_data) except: return self.cache_data return self.get_data()
load and cache data in json format
383,438
def enabled(self, value): if value is not None: assert type(value) is bool, " attribute: type is not !".format("enabled", value) self.__enabled = value
Setter for **self.__enabled** attribute. :param value: Attribute value. :type value: bool
383,439
def set_target(self, target): self.target = target if target: self.target.set_fuzzer(self) return self
:param target: target object
383,440
def _create_hashes(self,count): for i in range(0,count): blocksize = int(len(self.hexdigest) / count) currentstart = (1 + i) * blocksize - blocksize currentend = (1 +i) * blocksize self.hasharray.append(int(self.hexdigest[currentstart:currentend],16)) self.hasharray = self.hasharray + self.hasharray
Breaks up our hash into slots, so we can pull them out later. Essentially, it splits our SHA/MD5/etc into X parts.
383,441
def render_tag(tag, attrs=None, content=None, close=True): builder = "<{tag}{attrs}>{content}" if content or close: builder += "</{tag}>" return format_html( builder, tag=tag, attrs=mark_safe(flatatt(attrs)) if attrs else "", content=text_value(content), )
Render a HTML tag
383,442
def extract_data(self, page): response_keys = set(page.keys()) uncommon_keys = response_keys - self.common_keys for possible_data_key in uncommon_keys: element = page[possible_data_key] if isinstance(element, dict): return [self.representation(self.client, self.service_name, element)] if isinstance(element, list): return [self.representation(self.client, self.service_name, x) for x in element]
Extract the AppNexus object or list of objects from the response
383,443
def balance(address): txhistory = Address.transactions(address) balance = 0 for i in txhistory: if i.recipientId == address: balance += i.amount if i.senderId == address: balance -= (i.amount + i.fee) delegates = Delegate.delegates() for i in delegates: if address == i.address: forged_blocks = Delegate.blocks(i.pubkey) for block in forged_blocks: balance += (block.reward + block.totalFee) if balance < 0: height = Node.height() logger.fatal(.format(address, height)) raise NegativeBalanceError(.format(address, height)) return balance
Takes a single address and returns the current balance.
383,444
def set(self, section, key, value): if not section in self.config: self.config.add_section(section) self.config.set(section, key, value)
Creates the section value if it does not exists and sets the value. Use write_config to actually set the value.
383,445
def form_valid(self, form): self.object = form.save() meta = getattr(self.object, ) for backend in get_search_backends(): backend.add(object) messages.success( self.request, _(u).format( meta.verbose_name, str(self.object) ), buttons=[messages.button( reverse( .format(self.url_namespace), args=(self.object.id,) ), _(u) )] ) return redirect(self.get_success_url())
Processes a valid form submittal. :param form: the form instance. :rtype: django.http.HttpResponse.
383,446
def profile_form_factory(): if current_app.config[]: return EmailProfileForm( formdata=None, username=current_userprofile.username, full_name=current_userprofile.full_name, email=current_user.email, email_repeat=current_user.email, prefix=, ) else: return ProfileForm( formdata=None, obj=current_userprofile, prefix=, )
Create a profile form.
383,447
def remove_properties_containing_None(properties_dict): new_dict = dict() for key in properties_dict.keys(): value = properties_dict[key] if value is not None: new_dict[key] = value return new_dict
removes keys from a dict those values == None json schema validation might fail if they are set and the type or format of the property does not match
383,448
def replace_in_files(search, replace, depth=0, paths=None, confirm=True): if paths==None: paths = _s.dialogs.MultipleFiles() if paths == []: return for path in paths: lines = read_lines(path) if depth: N=min(len(lines),depth) else: N=len(lines) for n in range(0,N): if lines[n].find(search) >= 0: lines[n] = lines[n].replace(search,replace) print(path.split(_os.path.pathsep)[-1]+ +lines[n]+) if confirm: if input("yes? ")=="yes": replace_in_files(search,replace,depth,paths,False) return
Does a line-by-line search and replace, but only up to the "depth" line.
383,449
def host_create(host, groups, interfaces, **kwargs): s docstring) :param _connection_password: Optional - zabbix password (can also be set in opts or pillar, see modules docstring) :param visible_name: string with visible name of the host, use instead of parameter to not mess with value supplied from Salt sls file. return: ID of the created host. CLI Example: .. code-block:: bash salt zabbix.host_create technicalname 4 interfaces= visible_name= inventory_mode=0 inventory= host.creategroupsinterfacesurlauthresulthostids'] else: raise KeyError except KeyError: return ret
.. versionadded:: 2016.3.0 Create new host .. note:: This function accepts all standard host properties: keyword argument names differ depending on your zabbix version, see here__. .. __: https://www.zabbix.com/documentation/2.4/manual/api/reference/host/object#host :param host: technical name of the host :param groups: groupids of host groups to add the host to :param interfaces: interfaces to be created for the host :param _connection_user: Optional - zabbix user (can also be set in opts or pillar, see module's docstring) :param _connection_password: Optional - zabbix password (can also be set in opts or pillar, see module's docstring) :param _connection_url: Optional - url of zabbix frontend (can also be set in opts, pillar, see module's docstring) :param visible_name: string with visible name of the host, use 'visible_name' instead of 'name' parameter to not mess with value supplied from Salt sls file. return: ID of the created host. CLI Example: .. code-block:: bash salt '*' zabbix.host_create technicalname 4 interfaces='{type: 1, main: 1, useip: 1, ip: "192.168.3.1", dns: "", port: 10050}' visible_name='Host Visible Name' inventory_mode=0 inventory='{"alias": "something"}'
383,450
def create_app(): app = Flask(__name__) app.config.from_object(__name__+) db = MongoEngine(app) class User(db.Document, UserMixin): active = db.BooleanField(default=True) username = db.StringField(default=) password = db.StringField() first_name = db.StringField(default=) last_name = db.StringField(default=) roles = db.ListField(db.StringField(), default=[]) user_manager = UserManager(app, db, User) @app.route() def home_page(): return render_template_string() @app.route() @login_required def member_page(): return render_template_string() return app
Flask application factory
383,451
def _app_exec(self, package, action, params=None): allowed_commands = [] for app in self.get_apps_list(): if app.package == package: allowed_commands = list(app.actions.keys()) break assert(action in allowed_commands) cmd, url = DEVICE_URLS["do_action"] widget_id = self._get_widget_id(package) url = url.format(, package, widget_id) json_data = {"id": action} if params is not None: json_data["params"] = params self.result = self._exec(cmd, url, json_data=json_data)
meta method for all interactions with apps :param package: name of package/app :type package: str :param action: the action to be executed :type action: str :param params: optional parameters for this action :type params: dict :return: None :rtype: None
383,452
def copy(self, tx_ins=None, tx_outs=None, lock_time=None, expiry_height=None, tx_joinsplits=None, joinsplit_pubkey=None, joinsplit_sig=None): return OverwinterTx( tx_ins=tx_ins if tx_ins is not None else self.tx_ins, tx_outs=tx_outs if tx_outs is not None else self.tx_outs, lock_time=(lock_time if lock_time is not None else self.lock_time), expiry_height=(expiry_height if expiry_height is not None else self.expiry_height), tx_joinsplits=(tx_joinsplits if tx_joinsplits is not None else self.tx_joinsplits), joinsplit_pubkey=(joinsplit_pubkey if joinsplit_pubkey is not None else self.joinsplit_pubkey), joinsplit_sig=(joinsplit_sig if joinsplit_sig is not None else self.joinsplit_sig))
OverwinterTx, ... -> OverwinterTx Makes a copy. Allows over-writing specific pieces.
383,453
def _merge_patches(self): for patched_item, patched_namespace in self._patch_data_by_canonical_name.values(): patched_item_base_name = self._get_base_name(patched_item.name, patched_namespace.name) if patched_item_base_name not in self._item_by_canonical_name: raise InvalidSpec(.format( quote(patched_item.name)), patched_item.lineno, patched_item.path) existing_item = self._item_by_canonical_name[patched_item_base_name] self._check_patch_type_mismatch(patched_item, existing_item) if isinstance(patched_item, (AstStructPatch, AstUnionPatch)): self._check_field_names_unique(existing_item, patched_item) existing_item.fields += patched_item.fields self._inject_patched_examples(existing_item, patched_item) else: raise AssertionError(.format( patched_item.__class__.__name__))
Injects object patches into their original object definitions.
383,454
def from_pyfile(cls: Type["Config"], filename: FilePath) -> "Config": file_path = os.fspath(filename) spec = importlib.util.spec_from_file_location("module.name", file_path) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) return cls.from_object(module)
Create a configuration from a Python file. .. code-block:: python Config.from_pyfile('hypercorn_config.py') Arguments: filename: The filename which gives the path to the file.
383,455
def _get_existing_report(self, mask, report): for existing_report in self._reports: if existing_report[] == report[]: if mask == existing_report[]: return existing_report return None
Returns the aggregated report that matches report
383,456
def _marker(self, lat, long, text, xmap, color=None, icon=None, text_mark=False, style=None): kwargs = {} if icon is not None: kwargs["icon"] = icon if color is not None: kwargs["color"] = color if style is None: style = "font-size:18pt;font-weight:bold;" + \ "color:black;border-radius:0.5" try: xicon1 = folium.Icon(**kwargs) if text_mark is True: xicon = DivIcon( icon_size=(150, 36), icon_anchor=(0, 0), html= + style + + text + , ) folium.Marker([lat, long], popup=text, icon=xicon).add_to(xmap) folium.Marker([lat, long], popup=text, icon=xicon1).add_to(xmap) return xmap except Exception as e: self.err(e, self._marker, "Can not get marker")
Adds a marker to the default map
383,457
def tokenize(self, data): super().tokenize(data) token_tuple_zip = self.n_gram.generate_tuple_zip(self.token, self.n) token_list = [] self.token = ["".join(list(token_tuple)) for token_tuple in token_tuple_zip]
Tokenize sentence. Args: [n-gram, n-gram, n-gram, ...]
383,458
def _cleaned(_pipeline_objects): pipeline_objects = copy.deepcopy(_pipeline_objects) for pipeline_object in pipeline_objects: if pipeline_object[] == : for field_object in pipeline_object[]: if field_object[] == : start_date_time_string = field_object[] start_date_time = datetime.datetime.strptime(start_date_time_string, "%Y-%m-%dT%H:%M:%S") field_object[] = start_date_time.strftime("%H:%M:%S") return pipeline_objects
Return standardized pipeline objects to be used for comparing Remove year, month, and day components of the startDateTime so that data pipelines with the same time of day but different days are considered equal.
383,459
def simulate(self, steps, stimulus): self.__create_weights(stimulus) self.__location = stimulus dynamic = cnn_dynamic([], []) dynamic.output.append(self.__output) dynamic.time.append(0) for step in range(1, steps, 1): self.__output = self.__calculate_states() dynamic.output.append(self.__output) dynamic.time.append(step) return dynamic
! @brief Simulates chaotic neural network with extrnal stimulus during specified steps. @details Stimulus are considered as a coordinates of neurons and in line with that weights are initialized. @param[in] steps (uint): Amount of steps for simulation. @param[in] stimulus (list): Stimulus that are used for simulation. @return (cnn_dynamic) Output dynamic of the chaotic neural network.
383,460
def length(min=None, max=None): def validate(value): if min and len(value) < min: return e("{} does not have a length of at least {}", value, min) if max and len(value) > max: return e("{} does not have a length of at most {}", value, max) return validate
Validates that a field value's length is between the bounds given to this validator.
383,461
def reset(self, clear=False): if self._executing: self._executing = False self._request_info[] = {} self._reading = False self._highlighter.highlighting_on = False if clear: self._control.clear() if self._display_banner: if self.kernel_banner: self._append_plain_text(self.kernel_banner) self._append_plain_text(self.banner) self._show_interpreter_prompt()
Overridden to customize the order that the banners are printed
383,462
def handle_request(self, environ, start_response): method = environ[] query = urllib.parse.parse_qs(environ.get(, )) if in query: self.logger.warning() r = self._bad_request() else: sid = query[][0] if in query else None b64 = False if in query: if query[][0] == "1" or query[][0].lower() == "true": b64 = True if method == : if sid is None: transport = query.get(, [])[0] if transport != and transport != : self.logger.warning(, transport) r = self._bad_request() else: r = self._handle_connect(environ, start_response, transport, b64) else: if sid not in self.sockets: self.logger.warning(, sid) r = self._bad_request() else: socket = self._get_socket(sid) try: packets = socket.handle_get_request( environ, start_response) if isinstance(packets, list): r = self._ok(packets, b64=b64) else: r = packets except exceptions.EngineIOError: if sid in self.sockets: self.disconnect(sid) r = self._bad_request() if sid in self.sockets and self.sockets[sid].closed: del self.sockets[sid] elif method == : if sid is None or sid not in self.sockets: self.logger.warning(, sid) r = self._bad_request() else: socket = self._get_socket(sid) try: socket.handle_post_request(environ) r = self._ok() except exceptions.EngineIOError: if sid in self.sockets: self.disconnect(sid) r = self._bad_request() except: self.logger.exception() r = self._ok() elif method == : r = self._ok() else: self.logger.warning(, method) r = self._method_not_found() if not isinstance(r, dict): return r or [] if self.http_compression and \ len(r[]) >= self.compression_threshold: encodings = [e.split()[0].strip() for e in environ.get(, ).split()] for encoding in encodings: if encoding in self.compression_methods: r[] = \ getattr(self, + encoding)(r[]) r[] += [(, encoding)] break cors_headers = self._cors_headers(environ) start_response(r[], r[] + cors_headers) return [r[]]
Handle an HTTP request from the client. This is the entry point of the Engine.IO application, using the same interface as a WSGI application. For the typical usage, this function is invoked by the :class:`Middleware` instance, but it can be invoked directly when the middleware is not used. :param environ: The WSGI environment. :param start_response: The WSGI ``start_response`` function. This function returns the HTTP response body to deliver to the client as a byte sequence.
383,463
def delete_policy(self, scaling_group, policy): uri = "/%s/%s/policies/%s" % (self.uri_base, utils.get_id(scaling_group), utils.get_id(policy)) resp, resp_body = self.api.method_delete(uri)
Deletes the specified policy from the scaling group.
383,464
def songs(self): song_list = [] for chunk in self.songs_iter(page_size=49995): song_list.extend(chunk) return song_list
Get a listing of library songs. Returns: list: Song dicts.
383,465
def models_descriptive(self): f = self._parent return {name: {a: f[name].attrs[a] for a in H5File.stored_attributes} for name in f.keys()}
list all stored models in given file. Returns ------- dict: {model_name: {'repr' : 'string representation, 'created': 'human readable date', ...}
383,466
def set_mode(self, controlmode, drivemode): self.set_register(Addr.Mode, [0x01 | controlmode | drivemode])
Higher level abstraction for setting the mode register. This will set the mode according the the @controlmode and @drivemode you specify. @controlmode and @drivemode should come from the ControlMode and DriveMode class respectively.
383,467
def parameters(self, parameters): self._parameters = NocaseDict() if parameters: try: iterator = parameters.items() except AttributeError: iterator = parameters for item in iterator: if isinstance(item, CIMParameter): key = item.name value = item elif isinstance(item, tuple): key, value = item else: raise TypeError( _format("Input object for parameters has invalid item " "in iterable: {0!A}", item)) self.parameters[key] = value
Setter method; for a description see the getter method.
383,468
def validate_url(url): schemes = [, ] netloc_re = re.compile( r r r r r r, re.IGNORECASE ) try: scheme, netloc, path, query, fragment = urlsplit(url) except ValueError: raise Invalid() if scheme not in schemes: raise Invalid() if not netloc_re.search(netloc): raise Invalid() return url
Validate URL is valid NOTE: only support http & https
383,469
def from_geo(geo, level): pixel = TileSystem.geo_to_pixel(geo, level) tile = TileSystem.pixel_to_tile(pixel) key = TileSystem.tile_to_quadkey(tile, level) return QuadKey(key)
Constucts a quadkey representation from geo and level geo => (lat, lon) If lat or lon are outside of bounds, they will be clipped If level is outside of bounds, an AssertionError is raised
383,470
def _server_error_handler(self, code: int): if code == 501: self._login_fut.set_result(False) else: self.clean() raise abort(code) return True
处理500~599段状态码,抛出对应警告. Parameters: (code): - 响应的状态码 Return: (bool): - 已知的警告类型则返回True,否则返回False Raise: (ServerException): - 当返回为服务异常时则抛出对应异常
383,471
def cli(file1, file2, comments) -> int: sys.exit(compare_files(file1, file2, comments))
Compare file1 to file2 using a filter
383,472
def _generate_packets(file_h, header, layers=0): hdrp = ctypes.pointer(header) while True: pkt = _read_a_packet(file_h, hdrp, layers) if pkt: yield pkt else: break
Read packets one by one from the capture file. Expects the file handle to point to the location immediately after the header (24 bytes).
383,473
def init_blueprint(self, blueprint): if self._route is not None: raise TypeError("route cannot be set when using blueprints!") blueprint.rak = self blueprint.add_url_rule("", view_func=getattr(self, self._view_name), methods=[])
Initialize a Flask Blueprint, similar to init_app, but without the access to the application config. Keyword Arguments: blueprint {Flask Blueprint} -- Flask Blueprint instance to initialize (Default: {None})
383,474
def get_info_content(go_id, termcounts): freq = termcounts.get_term_freq(go_id) return -1.0 * math.log(freq) if freq else 0
Calculates the information content of a GO term.
383,475
def create_capitan_images(self, raw_data_directory: str, destination_directory: str, stroke_thicknesses: List[int]) -> None: symbols = self.load_capitan_symbols(raw_data_directory) self.draw_capitan_stroke_images(symbols, destination_directory, stroke_thicknesses) self.draw_capitan_score_images(symbols, destination_directory)
Creates a visual representation of the Capitan strokes by parsing all text-files and the symbols as specified by the parameters by drawing lines that connect the points from each stroke of each symbol. :param raw_data_directory: The directory, that contains the raw capitan dataset :param destination_directory: The directory, in which the symbols should be generated into. One sub-folder per symbol category will be generated automatically :param stroke_thicknesses: The thickness of the pen, used for drawing the lines in pixels. If multiple are specified, multiple images will be generated that have a different suffix, e.g. 1-16-3.png for the 3-px version and 1-16-2.png for the 2-px version of the image 1-16
383,476
def __make_response(self, data, default_renderer=None): status = headers = None if isinstance(data, tuple): data, status, headers = unpack(data) if data is None: data = self.__app.response_class(status=204) elif not isinstance(data, self.__app.response_class): renderer, mimetype = self.content_negotiation.select_renderer(request, self.default_renderers) if not renderer: if not default_renderer: raise NotAcceptable() renderer = default_renderer mimetype = default_renderer.mimetype data_bytes = renderer.render(data, mimetype) data = self.__app.response_class(data_bytes, mimetype=str(mimetype)) if status is not None: data.status_code = status if headers: data.headers.extend(headers) return data
Creates a Flask response object from the specified data. The appropriated encoder is taken based on the request header Accept. If there is not data to be serialized the response status code is 204. :param data: The Python object to be serialized. :return: A Flask response object.
383,477
def update_variant(self, variant_obj): LOG.debug(, variant_obj.get()) new_variant = self.variant_collection.find_one_and_replace( {: variant_obj[]}, variant_obj, return_document=pymongo.ReturnDocument.AFTER ) return new_variant
Update one variant document in the database. This means that the variant in the database will be replaced by variant_obj. Args: variant_obj(dict) Returns: new_variant(dict)
383,478
def _get_or_create_service_key(self): keys = self.service._get_service_keys(self.name) for key in keys[]: if key[][] == self.service_name: return self.service.get_service_key(self.name, self.service_name) self.service.create_service_key(self.name, self.service_name) return self.service.get_service_key(self.name, self.service_name)
Get a service key or create one if needed.
383,479
def check_var_coverage_content_type(self, ds): results = [] for variable in cfutil.get_geophysical_variables(ds): msgs = [] ctype = getattr(ds.variables[variable], , None) check = ctype is not None if not check: msgs.append("coverage_content_type") results.append(Result(BaseCheck.HIGH, check, self._var_header.format(variable), msgs)) continue valid_ctypes = { , , , , , , , } if ctype not in valid_ctypes: msgs.append("coverage_content_type in \"%s\"" % (variable, sorted(valid_ctypes))) results.append(Result(BaseCheck.HIGH, check, self._var_header.format(variable), msgs)) return results
Check coverage content type against valid ISO-19115-1 codes :param netCDF4.Dataset ds: An open netCDF dataset
383,480
def QA_fetch_stock_full(date, format=, collections=DATABASE.stock_day): Date = str(date)[0:10] if QA_util_date_valid(Date) is True: __data = [] for item in collections.find({ "date_stamp": QA_util_date_stamp(Date)}, batch_size=10000): __data.append([str(item[]), float(item[]), float(item[]), float( item[]), float(item[]), float(item[]), item[]]) if format in [, , ]: __data = numpy.asarray(__data) elif format in [, , ]: __data = __data elif format in [, , , ]: __data = DataFrame(__data, columns=[ , , , , , , ]) __data[] = pd.to_datetime(__data[]) __data = __data.set_index(, drop=False) else: print("QA Error QA_fetch_stock_full format parameter %s is none of \"P, p, pandas, pd , json, dict , n, N, numpy, list, l, L, !\" " % format) return __data else: QA_util_log_info( % date)
获取全市场的某一日的数据
383,481
def export(self, directory): exportInfoFile = os.path.join(directory, "connectordb.json") if os.path.exists(directory): if not os.path.exists(exportInfoFile): raise FileExistsError( "The export directory already exsits, and is not a ConnectorDB export.") with open(exportInfoFile) as f: exportInfo = json.load(f) if exportInfo["Version"] != 1: raise ValueError( "Could not export to directory: incompatible export versions.") else: with open(os.path.join(udir, "user.json"), "w") as f: json.dump(self.data, f) for d in self.devices(): d.export(os.path.join(udir, d.name))
Exports the ConnectorDB user into the given directory. The resulting export can be imported by using the import command(cdb.import(directory)), Note that Python cannot export passwords, since the REST API does not expose password hashes. Therefore, the imported user will have password same as username. The user export function is different than device and stream exports because it outputs a format compatible directly with connectorDB's import functionality: connectordb import < mydatabase > <directory > This also means that you can export multiple users into the same directory without issue
383,482
def pop(self, index=-1): value = self._list.pop(index) self._set.remove(value) return value
Remove and return item at *index* (default last). Raises IndexError if set is empty or index is out of range. Negative indexes are supported, as for slice indices.
383,483
def learnTransitions(self): print "Learning transitions" for (i, j), locationSDR in self.locations.iteritems(): print "i, j", (i, j) for (di, dj), transitionSDR in self.transitions.iteritems(): i2 = i + di j2 = j + dj if (0 <= i2 < self.diameter and 0 <= j2 < self.diameter): for _ in xrange(5): self.locationLayer.reset() self.locationLayer.compute(newLocation=self.locations[(i,j)]) self.locationLayer.compute(deltaLocation=transitionSDR, newLocation=self.locations[(i2, j2)]) self.locationLayer.reset()
Train the location layer to do path integration. For every location, teach it each previous-location + motor command pair.
383,484
def get_default_config(self): config = super(GraphitePickleHandler, self).get_default_config() config.update({ : 2004, }) return config
Return the default config for the handler
383,485
def company_vat(self): vat_digits = [] for _ in range(3): vat_digits.append(self.random_digit_not_null()) for _ in range(6): vat_digits.append(self.random_digit()) check_digit = company_vat_checksum(vat_digits) if check_digit == 10: return self.company_vat() vat_digits.append(check_digit) return .join(str(digit) for digit in vat_digits)
Returns 10 character tax identification number, Polish: Numer identyfikacji podatkowej. https://pl.wikipedia.org/wiki/NIP
383,486
def read(self, len=1024, buffer=None): try: return self._wrap_socket_library_call( lambda: SSL_read(self._ssl.value, len, buffer), ERR_READ_TIMEOUT) except openssl_error() as err: if err.ssl_error == SSL_ERROR_SYSCALL and err.result == -1: raise_ssl_error(ERR_PORT_UNREACHABLE, err) raise
Read data from connection Read up to len bytes and return them. Arguments: len -- maximum number of bytes to read Return value: string containing read bytes
383,487
def list(self, url_components=()): resp = self.get(url_components) return resp.get(self.result_key, [])
Send list request for all members of a collection
383,488
def getFoundIn(self, foundin_name, projectarea_id=None, projectarea_name=None, archived=False): self.log.debug("Try to get <FoundIn %s>", foundin_name) if not isinstance(foundin_name, six.string_types) or not foundin_name: excp_msg = "Please specify a valid PlannedFor name" self.log.error(excp_msg) raise exception.BadValue(excp_msg) foundins = self._getFoundIns(projectarea_id=projectarea_id, projectarea_name=projectarea_name, archived=archived, foundin_name=foundin_name) if foundins is not None: foundin = foundins[0] self.log.info("Find <FoundIn %s>", foundin) return foundin self.log.error("No FoundIn named %s", foundin_name) raise exception.NotFound("No FoundIn named %s" % foundin_name)
Get :class:`rtcclient.models.FoundIn` object by its name :param foundin_name: the foundin name :param projectarea_id: the :class:`rtcclient.project_area.ProjectArea` id :param projectarea_name: the project area name :param archived: (default is False) whether the foundin is archived :return: the :class:`rtcclient.models.FoundIn` object :rtype: rtcclient.models.FoundIn
383,489
def group_audit_ranks(filenames, measurer, similarity_bound=0.05): def _partition_groups(feature_scores): groups = [] for feature, score in feature_scores: added_to_group = False for i, group in enumerate(groups): mean_score, group_feature_scores = group if abs(mean_score - score) < similarity_bound: groups[i][1].append( (feature, score) ) groups[i][0] = sum([s for _, s in group_feature_scores])/len(group_feature_scores) added_to_group = True break if not added_to_group: groups.append( [score, [(feature,score)]] ) return [[feature for feature, score in group] for _, group in groups] score_dict = {} features = [] for filename in filenames: with open(filename) as audit_file: header_line = audit_file.readline()[:-1] feature = header_line[header_line.index(":")+1:] features.append(feature) confusion_matrices = load_audit_confusion_matrices(filename) for rep_level, matrix in confusion_matrices: score = measurer(matrix) if rep_level not in score_dict: score_dict[rep_level] = {} score_dict[rep_level][feature] = score score_keys = sorted(score_dict.keys()) groups = [features] while score_keys: key = score_keys.pop() new_groups = [] for group in groups: group_features = [(f, score_dict[key][f]) for f in group] sub_groups = _partition_groups(group_features) new_groups.extend(sub_groups) groups = new_groups return groups
Given a list of audit files, rank them using the `measurer` and return the features that never deviate more than `similarity_bound` across repairs.
383,490
def key_press(self, key, x, y): "Close the application when the player presses ESCAPE" if ord(key) == 27: if bool(glutLeaveMainLoop): glutLeaveMainLoop() else: raise Exception("Application quit")
Close the application when the player presses ESCAPE
383,491
def parseAnchorName( anchorName, markPrefix=MARK_PREFIX, ligaSeparator=LIGA_SEPARATOR, ligaNumRE=LIGA_NUM_RE, ignoreRE=None, ): number = None if ignoreRE is not None: anchorName = re.sub(ignoreRE, "", anchorName) m = ligaNumRE.match(anchorName) if not m: key = anchorName else: number = m.group(1) key = anchorName.rstrip(number) separator = ligaSeparator if key.endswith(separator): assert separator key = key[: -len(separator)] number = int(number) else: key = anchorName number = None if anchorName.startswith(markPrefix) and key: if number is not None: raise ValueError("mark anchor cannot be numbered: %r" % anchorName) isMark = True key = key[len(markPrefix) :] if not key: raise ValueError("mark anchor key is nil: %r" % anchorName) else: isMark = False return isMark, key, number
Parse anchor name and return a tuple that specifies: 1) whether the anchor is a "mark" anchor (bool); 2) the "key" name of the anchor, i.e. the name after stripping all the prefixes and suffixes, which identifies the class it belongs to (str); 3) An optional number (int), starting from 1, which identifies that index of the ligature component the anchor refers to. The 'ignoreRE' argument is an optional regex pattern (str) identifying sub-strings in the anchor name that should be ignored when parsing the three elements above.
383,492
def arp_ip(opcode, src_mac, src_ip, dst_mac, dst_ip): return arp(ARP_HW_TYPE_ETHERNET, ether.ETH_TYPE_IP, 6, 4, opcode, src_mac, src_ip, dst_mac, dst_ip)
A convenient wrapper for IPv4 ARP for Ethernet. This is an equivalent of the following code. arp(ARP_HW_TYPE_ETHERNET, ether.ETH_TYPE_IP, \ 6, 4, opcode, src_mac, src_ip, dst_mac, dst_ip)
383,493
def get_yes_no(self, question): user_answer = self.get_answer(question).lower() if user_answer in self.yes_input: return True if user_answer in self.no_input: return False is_yes = self.is_yes(user_answer) is_no = self.is_no(user_answer) if is_yes and not is_no: return True if is_no and not is_yes: return False if self.interactive: self.show_help() return self.get_yes_no(self.last_question) return False
Checks if question is yes (True) or no (False) :param question: Question to ask user :return: User answer
383,494
def request(self, name, *args, **kwargs): return self._session.request(name, self, *args, **kwargs)
Wrapper for nvim.request.
383,495
def __retry_session(self, retries=10, backoff_factor=0.3, status_forcelist=(500, 502, 504), session=None): the_session = session or requests.Session() retry = Retry(total=retries, read=retries, connect=retries, backoff_factor=backoff_factor, status_forcelist=status_forcelist) adapter = HTTPAdapter(max_retries=retry) the_session.mount(, adapter) the_session.mount(, adapter) return the_session
Retry the connection using requests if it fails. Use this as a wrapper to request from datapoint
383,496
def open_url_in_browser(url, browsername=None, fallback=False): r import webbrowser print( % (url,)) if browsername is None: browser = webbrowser.open(url) else: browser = get_prefered_browser(pref_list=[browsername], fallback=fallback) return browser.open(url)
r""" Opens a url in the specified or default browser Args: url (str): web url CommandLine: python -m utool.util_grabdata --test-open_url_in_browser Example: >>> # DISABLE_DOCTEST >>> # SCRIPT >>> from utool.util_grabdata import * # NOQA >>> url = 'http://www.jrsoftware.org/isdl.php' >>> open_url_in_browser(url, 'chrome')
383,497
def putcell(self, rownr, value): return self._table.putcell(self._column, rownr, value)
Put a value into one or more table cells. (see :func:`table.putcell`)
383,498
def array(self): url = "{}/{}".format(__endpoint__, self.type.RESOURCE) return RestClient.get(url, self.params)[self.type.RESOURCE]
Get all resources and return the result as an array Returns: array of str: Array of resources
383,499
def search(self, filters=None, fields=None, limit=None, page=1): options = { : False, : filters or {}, : fields or [], : limit or 1000, : page, } return self.call(, [options])
Retrieve order list by options using search api. Using this result can be paginated :param options: Dictionary of options. :param filters: `{<attribute>:{<operator>:<value>}}` :param fields: [<String: magento field names>, ...] :param limit: `page limit` :param page: `current page` :return: `list` of `dict`