Unnamed: 0 int64 0 389k | code stringlengths 26 79.6k | docstring stringlengths 1 46.9k |
|---|---|---|
375,900 | def non_blocking(func):
from functools import wraps
@wraps(func)
def non_blocking_version(*args, **kwargs):
t = ReturnThread(target=func, args=args, kwargs=kwargs)
t.start()
return t
return non_blocking_version | Decorator to run a function in a different thread.
It can be used to execute a command in a non-blocking way
like this::
@non_blocking
def add_one(n):
print 'starting'
import time
time.sleep(2)
print 'ending'
return n+1
thread... |
375,901 | def verify_rsa_sha1(request, rsa_public_key):
norm_params = normalize_parameters(request.params)
bs_uri = base_string_uri(request.uri)
sig_base_str = signature_base_string(request.http_method, bs_uri,
norm_params).encode()
sig = binascii.a2b_base64(request.s... | Verify a RSASSA-PKCS #1 v1.5 base64 encoded signature.
Per `section 3.4.3`_ of the spec.
Note this method requires the jwt and cryptography libraries.
.. _`section 3.4.3`: https://tools.ietf.org/html/rfc5849#section-3.4.3
To satisfy `RFC2616 section 5.2`_ item 1, the request argument's uri
attri... |
375,902 | def parse_message(message, nodata=False):
header = read_machine_header(message)
h_len = __get_machine_header_length(header)
meta_raw = message[h_len:h_len + header[]]
meta = __parse_meta(meta_raw, header)
data_start = h_len + header[]
data = b
if not nodata:
data = __decompress(... | Parse df message from bytearray.
@message - message data
@nodata - do not load data
@return - [binary header, metadata, binary data] |
375,903 | def _get_missing_trees(self, path, root_tree):
dirpath = posixpath.split(path)[0]
dirs = dirpath.split()
if not dirs or dirs == []:
return []
def get_tree_for_dir(tree, dirname):
for name, mode, id in tree.iteritems():
if name == dirname:... | Creates missing ``Tree`` objects for the given path.
:param path: path given as a string. It may be a path to a file node
(i.e. ``foo/bar/baz.txt``) or directory path - in that case it must
end with slash (i.e. ``foo/bar/``).
:param root_tree: ``dulwich.objects.Tree`` object from wh... |
375,904 | def compile_datetime(rule):
if isinstance(rule.value, datetime.datetime):
return rule
try:
return DatetimeRule(datetime.datetime.fromtimestamp(float(rule.value)))
except (TypeError, ValueError):
pass
res = TIMESTAMP_RE.match(str(rule.value))
if res is not N... | Compiler helper method: attempt to compile constant into object representing
datetime object to enable relations and thus simple comparisons using Python
operators. |
375,905 | def get_stp_mst_detail_output_msti_port_link_type(self, **kwargs):
config = ET.Element("config")
get_stp_mst_detail = ET.Element("get_stp_mst_detail")
config = get_stp_mst_detail
output = ET.SubElement(get_stp_mst_detail, "output")
msti = ET.SubElement(output, "msti")
... | Auto Generated Code |
375,906 | def pixel_array_to_image(self, width, height, channels, undefined_on_failure=True, allow_rounding=False):
if(self.dtype != array.array):
raise TypeError("array_to_img expects SArray of arrays as input SArray")
num_to_test = 10
num_test = min(len(self), num_to_test)
... | Create a new SArray with all the values cast to :py:class:`turicreate.image.Image`
of uniform size.
Parameters
----------
width: int
The width of the new images.
height: int
The height of the new images.
channels: int.
Number of chan... |
375,907 | def pytype_to_ctype(t):
if isinstance(t, List):
return .format(
pytype_to_ctype(t.__args__[0])
)
elif isinstance(t, Set):
return .format(
pytype_to_ctype(t.__args__[0])
)
elif isinstance(t, Dict):
tkey, tvalue = t.__args__
return .... | Python -> pythonic type binding. |
375,908 | def load_XAML(file_obj, *args, **kwargs):
def element_to_color(element):
if element is None:
return visual.DEFAULT_COLOR
hexcolor = int(element.attrib[].replace(, ), 16)
opacity = float(element.attrib[])
rgba = [(hexcolor >> 16) & 0xFF,
(hexc... | Load a 3D XAML file.
Parameters
----------
file_obj : file object
Open, containing XAML file
Returns
----------
result : dict
kwargs for a trimesh constructor, including:
vertices: (n,3) np.float64, points in space
faces: ... |
375,909 | def _do_perform_delete_on_model(self):
if self._force_deleting:
return self.with_trashed().where(self.get_key_name(), self.get_key()).force_delete()
return self._run_soft_delete() | Perform the actual delete query on this model instance. |
375,910 | def get_trace(self, project_id, trace_id):
trace_pb = self._gapic_api.get_trace(project_id, trace_id)
trace_mapping = _parse_trace_pb(trace_pb)
return trace_mapping | Gets a single trace by its ID.
Args:
trace_id (str): ID of the trace to return.
project_id (str): Required. ID of the Cloud project where the trace
data is stored.
Returns:
A Trace dict. |
375,911 | def applyKeyMapping(self, mapping):
for coltype, colname in zip(self.columntypes, self.columnnames):
if coltype in ligolwtypes.IDTypes and (self.next_id is None or colname != self.next_id.column_name):
column = self.getColumnByName(colname)
for i, old in enumerate(column):
try:
column[i] = ma... | Used as the second half of the key reassignment algorithm.
Loops over each row in the table, replacing references to
old row keys with the new values from the mapping. |
375,912 | def thanksgiving(year, country=):
if country == :
if year in [1940, 1941]:
return nth_day_of_month(3, THU, NOV, year)
elif year == 1939:
return nth_day_of_month(4, THU, NOV, year)
else:
return nth_day_of_month(0, THU, NOV, year)
if country == :
... | USA: last Thurs. of November, Canada: 2nd Mon. of October |
375,913 | def download(client, target_dir):
print()
print("download inappproducts")
print()
products = client.list_inappproducts()
for product in products:
path = os.path.join(target_dir, )
del product[]
mkdir_p(path)
with open(os.path.join(path, product[] + ), ) as outfi... | Download inappproducts from play store. |
375,914 | def supported(cls, stream=sys.stdout):
if not stream.isatty():
return False
try:
import curses
except ImportError:
return False
else:
try:
try:
return curses.tigetnum("colors") > 2
... | A class method that returns True if the current platform supports
coloring terminal output using this method. Returns False otherwise. |
375,915 | def get_tournament(self, tag: crtag, **params: keys):
url = self.api.TOURNAMENT + + tag
return self._get_model(url, **params) | Get a tournament information
Parameters
----------
tag: str
A valid tournament tag. Minimum length: 3
Valid characters: 0289PYLQGRJCUV
\*\*keys: Optional[list] = None
Filter which keys should be included in the
response
\*\*exclude... |
375,916 | def loading(self):
if getattr(self, , False):
raise ValueError("Already loading")
self._initialized = False
yield
self._initialized = True | Context manager for when you need to instantiate entities upon unpacking |
375,917 | def ast_to_code(ast, indent=0):
code = []
def append(line):
code.append((" " * indent) + line)
if isinstance(ast, Node):
append("ast.{}(".format(ast.__class__.__name__))
indent += 1
for i, k in enumerate(ast._fields, 1):
v = getattr(ast, k)... | Converts an ast into a python code representation of the AST. |
375,918 | def list_all(self):
url =
code, xml = self.submit(None, , url)
return self.response(code, xml) | Return all equipments in database
:return: Dictionary with the following structure:
::
{'equipaments': {'name' :< name_equipament >}, {... demais equipamentos ...} }
:raise DataBaseError: Networkapi failed to access the database.
:raise XMLError: Networkapi failed to gene... |
375,919 | def calc_time_step(self):
system = self.system
config = self.config
convergence = self.convergence
niter = self.niter
t = self.t
if t == 0:
self._calc_time_step_first()
return
if convergence:
if niter >= 15:
... | Set the time step during time domain simulations
Parameters
----------
convergence: bool
truth value of the convergence of the last step
niter: int
current iteration count
t: float
current simulation time
Returns
-------
... |
375,920 | def get_script_args(dist, executable=sys_executable, wininst=False):
spec = str(dist.as_requirement())
header = get_script_header("", executable, wininst)
for group in , :
for name, ep in dist.get_entry_map(group).items():
script_text = (
"
"__require... | Yield write_script() argument tuples for a distribution's entrypoints |
375,921 | def coupling_matrix_2j(j1, j2):
ur
M1 = [-j1 + i for i in range(2*j1+1)]
M2 = [-j2 + i for i in range(2*j2+1)]
j1j2nums = [(j1, m1, j2, m2) for m1 in M1 for m2 in M2]
Jper = perm_j(j1, j2)
jmjnums = [(J, MJ-J) for J in Jper for MJ in range(2*J+1)]
U = zeros((2*j1+1)*(2*j2+1)... | ur"""For angular momenta $j_1, j_2$ the unitary transformation from the \
uncoupled basis into the $j = j_1 \oplus j_2$ coupled basis.
>>> from sympy import Integer, pprint
>>> L = 0
>>> S = 1/Integer(2)
>>> pprint(coupling_matrix_2j(L, S))
β‘1 0β€
β’ β₯
β£0 1β¦
>>> L = 1
>>> S ... |
375,922 | def upload_file(self, file_or_path, obj_name=None, content_type=None,
etag=None, return_none=False, content_encoding=None, ttl=None,
content_length=None, headers=None):
return self.create(file_or_path=file_or_path, obj_name=obj_name,
content_type=content_type, et... | Uploads the specified file to this container. If no name is supplied,
the file's name will be used. Either a file path or an open file-like
object may be supplied. A StorageObject reference to the uploaded file
will be returned, unless 'return_none' is set to True.
You may optionally se... |
375,923 | def unit(self):
unit = ncVarUnit(self._ncVar)
fieldNames = self._ncVar.dtype.names
if hasattr(unit, ) and len(unit) == len(fieldNames):
idx = fieldNames.index(self.nodeName)
return unit[idx]
else:
return unit | Returns the unit attribute of the underlying ncdf variable.
If the units has a length (e.g is a list) and has precisely one element per field,
the unit for this field is returned. |
375,924 | def detect_protocol(cls, message):
main = cls._message_to_payload(message)
def protocol_for_payload(payload):
if not isinstance(payload, dict):
return JSONRPCLoose
version = payload.get()
if version == :
return... | Attempt to detect the protocol from the message. |
375,925 | def create_archive(archive, filenames, verbosity=0, program=None, interactive=True):
util.check_new_filename(archive)
util.check_archive_filelist(filenames)
if verbosity >= 0:
util.log_info("Creating %s ..." % archive)
res = _create_archive(archive, filenames, verbosity=verbosity,
... | Create given archive with given files. |
375,926 | def is_web_url(string):
assert isinstance(string, basestring)
parsed_url = urllib.parse.urlparse(string)
return (
(
parsed_url.scheme.lower() ==
or parsed_url.scheme.lower() ==
)
and parsed_url.netloc
) | Check to see if string is an validly-formatted web url. |
375,927 | def scan_config_argument(ctx, param, value, config_dir=None):
if callable(config_dir):
config_dir = config_dir()
if not config:
click.echo("Enter at least one CONFIG")
click.echo(ctx.get_help(), color=ctx.color)
ctx.exit()
if isinstance(value, string_types):
va... | Validate / translate config name/path values for click config arg.
Wrapper on top of :func:`cli.scan_config`. |
375,928 | def compare(jaide, commands):
output = color("show | compare:\n", )
return output + color_diffs(jaide.compare_config(commands)) | Perform a show | compare with some set commands.
@param jaide: The jaide connection to the device.
@type jaide: jaide.Jaide object
@param commands: The set commands to send to the device to compare with.
@type commands: str or list
@returns: The output from the device.
@rtype str |
375,929 | def offset(self):
if not self._registry_key and self._registry:
self._GetKeyFromRegistry()
if not self._registry_key:
return None
return self._registry_key.offset | int: offset of the key within the Windows Registry file or None. |
375,930 | def collect_results(self) -> Optional[Tuple[int, Dict[str, float]]]:
self.wait_to_finish()
if self.decoder_metric_queue.empty():
if self._results_pending:
self._any_process_died = True
self._results_pending = False
return None
decoded_... | Returns the decoded checkpoint and the decoder metrics or None if the queue is empty. |
375,931 | def currentDateTime(self):
view = self.uiGanttVIEW
scene = view.scene()
point = view.mapToScene(0, 0)
return scene.datetimeAt(point.x()) | Returns the current date time for this widget.
:return <datetime.datetime> |
375,932 | def _create_ret_object(self, status=SUCCESS, data=None, error=False,
error_message=None, error_cause=None):
ret = {}
if status == self.FAILURE:
ret[] = self.FAILURE
else:
ret[] = self.SUCCESS
ret[] = data
if error:
... | Create generic reponse objects.
:param str status: The SUCCESS or FAILURE of the request
:param obj data: The data to return
:param bool error: Set to True to add Error response
:param str error_message: The generic error message
:param str error_cause: The cause of the error
... |
375,933 | def __configure_interior(self, *args):
(size_x, size_y) = (self.interior.winfo_reqwidth(), self.interior.winfo_reqheight())
self._canvas.config(scrollregion="0 0 {0} {1}".format(size_x, size_y))
if self.interior.winfo_reqwidth() is not self._canvas.winfo_width():
... | Private function to configure the interior Frame.
:param args: Tkinter event |
375,934 | def get_connection(self):
if not self.open:
raise exc.ResourceClosedError()
return Connection(self._engine.connect()) | Get a connection to this Database. Connections are retrieved from a
pool. |
375,935 | def add(self, nb = 1, name = None, xid = None):
for x in xrange(nb):
self.count_lock.acquire()
if self.workers >= self.max_workers:
self.count_lock.release()
continue
self.workers += 1
if xid is None:
xid = ... | Create one or many workers. |
375,936 | def fetch(self, wait=0):
if self.started:
return fetch(self.id, wait=wait, cached=self.cached) | get the task result objects.
:param int wait: how many milliseconds to wait for a result
:return: an unsorted list of task objects |
375,937 | def extend(validator, validators=(), version=None, type_checker=None):
all_validators = dict(validator.VALIDATORS)
all_validators.update(validators)
if type_checker is None:
type_checker = validator.TYPE_CHECKER
elif validator._CREATED_WITH_DEFAULT_TYPES:
raise TypeError(
... | Create a new validator class by extending an existing one.
Arguments:
validator (jsonschema.IValidator):
an existing validator class
validators (collections.Mapping):
a mapping of new validator callables to extend with, whose
structure is as in `create`.
... |
375,938 | def list_same_dimensions(self, unit_object):
equiv = [k for k, v in self.lut.items() if v[1] is unit_object.dimensions]
equiv = list(sorted(set(equiv)))
return equiv | Return a list of base unit names that this registry knows about that
are of equivalent dimensions to *unit_object*. |
375,939 | def MeshLines(*inputobj, **options):
scale = options.pop("scale", 1)
lw = options.pop("lw", 1)
c = options.pop("c", None)
alpha = options.pop("alpha", 1)
mesh, u = _inputsort(inputobj)
startPoints = mesh.coordinates()
u_values = np.array([u(p) for p in mesh.coordinates()])
if not u... | Build the line segments between two lists of points `startPoints` and `endPoints`.
`startPoints` can be also passed in the form ``[[point1, point2], ...]``.
A dolfin ``Mesh`` that was deformed/modified by a function can be
passed together as inputs.
:param float scale: apply a rescaling factor to the ... |
375,940 | def dt(self, start_node=None):
if start_node is None:
return self.root2tree(start_node=start_node)
elem_id = start_node
if elem_id not in self.elem_dict:
return []
elem = self.elem_dict[elem_id]
elem_type = elem[]
assert elem_type in (,... | main method to create an RSTTree from the output of get_rs3_data().
TODO: add proper documentation |
375,941 | def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
allow_nan=True, cls=None, indent=None, **kw):
if cls is None:
cls = JSONEncoder
iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
check_circular=check_circular, allow_nan=allow_nan, indent=indent,
... | Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
``.write()``-supporting file-like object).
If ``skipkeys`` is ``True`` then ``dict`` keys that are not basic types
(``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
will be skipped instead of raising a ``TypeError``.
... |
375,942 | def shared_databases(self):
endpoint = .join((
self.server_url, , , , ))
resp = self.r_session.get(endpoint)
resp.raise_for_status()
data = response_to_json_dict(resp)
return data.get(, []) | Retrieves a list containing the names of databases shared
with this account.
:returns: List of database names |
375,943 | def _file_in_patch(self, filename, patch, ignore):
file = self.quilt_pc + File(os.path.join(patch.get_name(), filename))
if file.exists():
if ignore:
return True
else:
raise QuiltError("File %s is already in patch %s" % (filename,
... | Checks if a backup file of the filename in the current patch
exists |
375,944 | def _get_magnitude_term(self, C, mag):
dmag = mag - 8.0
return C["c0"] + C["c3"] * dmag + C["c4"] * (dmag ** 2.) | Returns the magnitude scaling term provided in Equation (5) |
375,945 | def matches_to_marker_results(df):
assert isinstance(df, pd.DataFrame)
from collections import defaultdict
d = defaultdict(list)
for idx, row in df.iterrows():
marker = row[]
d[marker].append(row)
marker_results = {}
for k,v in d.items():
if len(v) > 1:
... | Perfect BLAST matches to marker results dict
Parse perfect BLAST matches to marker results dict.
Args:
df (pandas.DataFrame): DataFrame of perfect BLAST matches
Returns:
dict: cgMLST330 marker names to matching allele numbers |
375,946 | async def release(
self, *, comment: str = None, erase: bool = None,
secure_erase: bool = None, quick_erase: bool = None,
wait: bool = False, wait_interval: int = 5):
params = remove_None({
"system_id": self.system_id,
"comment": comment,
... | Release the machine.
:param comment: Reason machine was released.
:type comment: `str`
:param erase: Erase the disk when release.
:type erase: `bool`
:param secure_erase: Use the drive's secure erase feature if available.
:type secure_erase: `bool`
:param quick_e... |
375,947 | def balance(self):
self.check()
if not sum(map(lambda x: x.amount, self.src)) == -self.amount:
raise XnBalanceError("Sum of source amounts "
"not equal to transaction amount")
if not sum(map(lambda x: x.amount, self.dst)) == self.amount:
... | Check this transaction for correctness |
375,948 | def wv45(msg):
d = hex2bin(data(msg))
if d[12] == :
return None
ws = bin2int(d[13:15])
return ws | Wake vortex.
Args:
msg (String): 28 bytes hexadecimal message string
Returns:
int: Wake vortex level. 0=NIL, 1=Light, 2=Moderate, 3=Severe |
375,949 | def _full_name(self, record_name):
if not record_name:
return self.domain
return super(Provider, self)._full_name(record_name) | Returns full domain name of a sub-domain name |
375,950 | def _format_finite(negative, digits, dot_pos):
olddigits = digits
digits = digits.lstrip()
dot_pos -= len(olddigits) - len(digits)
use_exponent = dot_pos <= -4 or dot_pos > len(digits)
if use_exponent:
exp = dot_pos - 1 if digits else dot_pos
dot_pos -= exp
... | Given a (possibly empty) string of digits and an integer
dot_pos indicating the position of the decimal point relative to
the start of that string, output a formatted numeric string with
the same value and same implicit exponent. |
375,951 | def get_product(id=None, name=None):
content = get_product_raw(id, name)
if content:
return utils.format_json(content) | Get a specific Product by name or ID |
375,952 | def wirevector_subset(self, cls=None, exclude=tuple()):
if cls is None:
initial_set = self.wirevector_set
else:
initial_set = (x for x in self.wirevector_set if isinstance(x, cls))
if exclude == tuple():
return set(initial_set)
else:
... | Return set of wirevectors, filtered by the type or tuple of types provided as cls.
If no cls is specified, the full set of wirevectors associated with the Block are
returned. If cls is a single type, or a tuple of types, only those wirevectors of
the matching types will be returned. This is h... |
375,953 | def create(url, filename):
files = {: open(filename, )}
response = requests.post(url, files=files)
if response.status_code != 201:
raise ValueError( + filename)
return references_to_dict(response.json()[])[REF_SELF] | Create new fMRI for given experiment by uploading local file.
Expects an tar-archive.
Parameters
----------
url : string
Url to POST fMRI create request
filename : string
Path to tar-archive on local disk
Returns
-------
string
... |
375,954 | def one_hot_encoding(input_tensor, num_labels):
xview = input_tensor.view(-1, 1).to(torch.long)
onehot = torch.zeros(xview.size(0), num_labels, device=input_tensor.device, dtype=torch.float)
onehot.scatter_(1, xview, 1)
return onehot.view(list(input_tensor.shape) + [-1]) | One-hot encode labels from input |
375,955 | def tf_action_exploration(self, action, exploration, action_spec):
action_shape = tf.shape(input=action)
exploration_value = exploration.tf_explore(
episode=self.global_episode,
timestep=self.global_timestep,
shape=action_spec[]
)
exploration_... | Applies optional exploration to the action (post-processor for action outputs).
Args:
action (tf.Tensor): The original output action tensor (to be post-processed).
exploration (Exploration): The Exploration object to use.
action_spec (dict): Dict specifying the action spa... |
375,956 | def _element_keywords(cls, backend, elements=None):
"Returns a dictionary of element names to allowed keywords"
if backend not in Store.loaded_backends():
return {}
mapping = {}
backend_options = Store.options(backend)
elements = elements if elements is not None else... | Returns a dictionary of element names to allowed keywords |
375,957 | def reset(self):
self._allocated_node_names = set()
self._nodes = {}
self._links = {}
self._drawings = {}
self._snapshots = {}
snapshot_dir = os.path.join(self.path, "snapshots")
if os.path.exists(snapshot_dir):
for snap in os.listdi... | Called when open/close a project. Cleanup internal stuff |
375,958 | def eth_getStorageAt(self, address, position=0, block=BLOCK_TAG_LATEST):
block = validate_block(block)
return hex_to_dec((yield from self.rpc_call(,
[address,
hex(position),
... | https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getstorageat
:param address: Storage address
:type address: str
:param position: Position in storage (optional)
:type position: int
:param block: Block tag or number (optional)
:type block: int or BLOCK_TAGS
:... |
375,959 | def read_memory(self, addr, transfer_size=32, now=True):
assert transfer_size in (8, 16, 32)
if transfer_size == 32:
result = conversion.byte_list_to_u32le_list(self._link.read_mem32(addr, 4, self._apsel))[0]
elif transfer_size == 16:
result = conversion.byte_lis... | ! @brief Read a memory location.
By default, a word will be read. |
375,960 | def print_matrix(X, decimals=1):
for row in np.round(X, decimals=decimals):
print(row) | Pretty printing for numpy matrix X |
375,961 | def diam_swamee(FlowRate, HeadLossFric, Length, Nu, PipeRough):
ut.check_range([FlowRate, ">0", "Flow rate"], [Length, ">0", "Length"],
[HeadLossFric, ">0", "Headloss due to friction"],
[Nu, ">0", "Nu"], [PipeRough, "0-1", "Pipe roughness"])
a = ((PipeRough ** 1.2... | Return the inner diameter of a pipe.
The Swamee Jain equation is dimensionally correct and returns the
inner diameter of a pipe given the flow rate and the head loss due
to shear on the pipe walls. The Swamee Jain equation does NOT take
minor losses into account. This equation ONLY applies to turbulent... |
375,962 | def save_config(
self,
cmd="copy running-configuration startup-configuration",
confirm=False,
confirm_response="",
):
return super(DellForce10SSH, self).save_config(
cmd=cmd, confirm=confirm, confirm_response=confirm_response
) | Saves Config |
375,963 | def drop_duplicates(self, subset=None, keep=):
subset = check_and_obtain_subset_columns(subset, self)
df = self.reset_index()
df_names = df._gather_column_names()
subset_indices = [df_names.index(col_name) for col_name in subset]
weld_objects = weld_drop_duplicates(df.... | Return DataFrame with duplicate rows (excluding index) removed,
optionally only considering subset columns.
Note that the row order is NOT maintained due to hashing.
Parameters
----------
subset : list of str, optional
Which columns to consider
keep : {'+', ... |
375,964 | def _pycall_path_simple(
x1: int, y1: int, x2: int, y2: int, handle: Any
) -> float:
return ffi.from_handle(handle)(x1, y1, x2, y2) | Does less and should run faster, just calls the handle function. |
375,965 | def annotate_op(self, op):
if isinstance(op, Label):
return op
else:
return AnnotatedOp(self, op.name, op.arg) | Takes a bytecode operation (:class:`Op`) and annotates it using the
data contained in this code object.
Arguments:
op(Op): An :class:`Op` instance.
Returns:
AnnotatedOp: An annotated bytecode operation. |
375,966 | def _set_config(self, config=None):
if not config:
config = {}
try:
self.config = self.componentmodel(config)
try:
name = self.config.name
self.log("Name set to: ", name, l... | Set this component's initial configuration |
375,967 | def wrap_penalty(p, fit_linear, linear_penalty=0.):
def wrapped_p(n, *args):
if fit_linear:
if n == 1:
return sp.sparse.block_diag([linear_penalty], format=)
return sp.sparse.block_diag([linear_penalty,
p(n-1, *args)], for... | tool to account for unity penalty on the linear term of any feature.
example:
p = wrap_penalty(derivative, fit_linear=True)(n, coef)
Parameters
----------
p : callable.
penalty-matrix-generating function.
fit_linear : boolean.
whether the current feature has a linear term o... |
375,968 | def f2p(phrase, max_word_size=15, cutoff=3):
results = f2p_list(phrase, max_word_size, cutoff)
return .join(i[0][0] for i in results) | Convert a Finglish phrase to the most probable Persian phrase. |
375,969 | def _unpack_zipfile(filename, extract_dir):
try:
import zipfile
except ImportError:
raise ReadError()
if not zipfile.is_zipfile(filename):
raise ReadError("%s is not a zip file" % filename)
zip = zipfile.ZipFile(filename)
try:
for info in zip.infolist():
... | Unpack zip `filename` to `extract_dir` |
375,970 | def Decrypt(self, encrypted_data):
index_split = -(len(encrypted_data) % AES.block_size)
if index_split:
remaining_encrypted_data = encrypted_data[index_split:]
encrypted_data = encrypted_data[:index_split]
else:
remaining_encrypted_data = b
decrypted_data = self._aes_cipher.decr... | Decrypts the encrypted data.
Args:
encrypted_data (bytes): encrypted data.
Returns:
tuple[bytes, bytes]: decrypted data and remaining encrypted data. |
375,971 | def allocate_objects(self, eps = 0.01, noise_size = 1):
if (self.__object_segment_analysers is None):
return [];
segments = [];
for object_segment_analyser in self.__object_segment_analysers:
indexes = object_segment_analyser[];
... | !
@brief Allocates object segments.
@param[in] eps (double): Tolerance level that define maximal difference between phases of oscillators in one segment.
@param[in] noise_size (uint): Threshold that defines noise - segments size (in pixels) that is less then the threshold is conside... |
375,972 | def verify_certificate_issuer(self, certificate_issuer_id, **kwargs):
kwargs[] = True
if kwargs.get():
return self.verify_certificate_issuer_with_http_info(certificate_issuer_id, **kwargs)
else:
(data) = self.verify_certificate_issuer_with_http_info(certifica... | Verify certificate issuer. # noqa: E501
A utility API that can be used to validate the user configuration before activating a certificate issuer. Verifies that the certificate issuer is accessible and can be used to generate certificates by Device Management. <br> **Note:** The API requests the 3rd party CA t... |
375,973 | def evaluate(self):
X = mp_Z_Y
Xf = mp_Zf
Df = mp_Df
Sf = mp_Sf
Ef = sl.inner(Df[np.newaxis, ...], Xf,
axis=self.xstep.cri.axisM+1) - Sf
Ef = np.swapaxes(Ef, 0, self.xstep.cri.axisK+1)[0]
dfd = sl.rfl2norm2(Ef, self.xstep.S.shape,
... | Evaluate functional value of previous iteration. |
375,974 | def elapsed(self):
if self.count == self.total:
elapsed = self.last_update - self.start
else:
elapsed = time.time() - self.start
return elapsed | Get elapsed time is seconds (float) |
375,975 | def set_editor(self, editor):
if self._editor is not None:
try:
self._editor.offset_calculator.pic_infos_available.disconnect(
self._update)
except (AttributeError, RuntimeError, ReferenceError):
pass
s... | Sets the associated editor, when the editor's offset calculator mode
emit the signal pic_infos_available, the table is automatically
refreshed.
You can also refresh manually by calling :meth:`update_pic_infos`. |
375,976 | def parse_model_specifier(specifier):
tests.TestModeltests.models.TestModeltests.TestModel.imagetests.models.TestModelimage
values = specifier.split()
if len(values) == 2:
values.append(None)
elif len(values) != 3:
raise ValueError(
.format(
len(... | Parses a string that specifies either a model or a field.
The string should look like ``app.model.[field]``.
>>> print parse_model_specifier('tests.TestModel')
(<class 'tests.models.TestModel'>, None)
>>> print parse_model_specifier('tests.TestModel.image')
(<class 'tests.models.TestModel'>, 'image... |
375,977 | def addSynapse(self, srcCellCol, srcCellIdx, perm):
self.syns.append([int(srcCellCol), int(srcCellIdx), numpy.float32(perm)]) | Add a new synapse
:param srcCellCol source cell column
:param srcCellIdx source cell index within the column
:param perm initial permanence |
375,978 | def setdefault(self, k, d=None):
return super(HeaderDict, self).setdefault(k.title(), d) | Override dict.setdefault() to title-case keys. |
375,979 | def _define_output_buffers(self):
self.target_buffers = {
None: [(step, self.buffers[step]) for step in self._get_input_steps()]
}
for step in self.steps_sorted:
if step != self:
child_steps = [edge[1] for edge in self.graph.ou... | Prepare a dictionary so we know what buffers have to be update with the the output of every step. |
375,980 | def parse_for(control_line):
error = for $var in expression\ + control_line
regex = re.compile(r)
res = regex.match(control_line)
if not res:
raise exceptions.YamlSyntaxError(error)
groups = res.groups()
control_vars = []
control_vars.append(get_var_name(groups[0]))
if grou... | Returns name of loop control variable(s), iteration type (in/word_in) and
expression to iterate on.
For example:
- given "for $i in $foo", returns (['i'], '$foo')
- given "for ${i} in $(ls $foo)", returns (['i'], '$(ls $foo)')
- given "for $k, $v in $foo", returns (['k', 'v'], '$foo') |
375,981 | def global_var(self, name):
self.newline_label(name, False, True)
self.newline_text("WORD\t1", True) | Inserts a new static (global) variable definition |
375,982 | def crop(self, extent, copy=False):
try:
if extent[0] is None:
extent = (self.start.z, extent[1])
if extent[1] is None:
extent = (extent[0], self.stop.z)
except:
m = "You must provide a 2-tuple for the new extents. Use None for... | Crop to a new depth range.
Args:
extent (tuple): The new start and stop depth. Must be 'inside'
existing striplog.
copy (bool): Whether to operate in place or make a copy.
Returns:
Operates in place by deault; if copy is True, returns a striplog. |
375,983 | def OnInsertCols(self, event):
bbox = self.grid.selection.get_bbox()
if bbox is None or bbox[1][1] is None:
ins_point = self.grid.actions.cursor[1] - 1
no_cols = 1
else:
ins_point = bbox[0][1] - 1
no_cols = self... | Inserts the maximum of 1 and the number of selected columns |
375,984 | def get_issns_for_journal(nlm_id):
params = {: ,
: ,
: nlm_id}
tree = send_request(pubmed_fetch, params)
if tree is None:
return None
issn_list = tree.findall()
issn_linking = tree.findall()
issns = issn_list + issn_linking
if not issns:
... | Get a list of the ISSN numbers for a journal given its NLM ID.
Information on NLM XML DTDs is available at
https://www.nlm.nih.gov/databases/dtd/ |
375,985 | def towgs84(E, N, pkm=False, presentation=None):
_lng0 = lng0pkm if pkm else lng0
E /= 1000.0
N /= 1000.0
epsilon = (N-N0) / (k0*A)
eta = (E-E0) / (k0*A)
epsilonp = epsilon - beta1*sin(2*1*epsilon)*cosh(2*1*eta) - \
beta2*sin(2*2*epsilon)*cosh(2*2*eta) - \
... | Convert coordintes from TWD97 to WGS84
The east and north coordinates should be in meters and in float
pkm true for Penghu, Kinmen and Matsu area
You can specify one of the following presentations of the returned values:
dms - A tuple with degrees (int), minutes (int) and seconds (float)
dm... |
375,986 | def state_get(self):
virtual_names = list(self.virtual_columns.keys()) + list(self.variables.keys())
units = {key: str(value) for key, value in self.units.items()}
ucds = {key: value for key, value in self.ucds.items() if key in virtual_names}
descriptions = {key: value for key... | Return the internal state of the DataFrame in a dictionary
Example:
>>> import vaex
>>> df = vaex.from_scalars(x=1, y=2)
>>> df['r'] = (df.x**2 + df.y**2)**0.5
>>> df.state_get()
{'active_range': [0, 1],
'column_names': ['x', 'y', 'r'],
'description': No... |
375,987 | def new(self, request):
form = (self.form or generate_form(self.model))()
return self._render(
request = request,
template = ,
context = {
: form
},
status = 200
) | Render a form to create a new object. |
375,988 | def connect_cloudfront(self):
"Connect to Cloud Front. This is done automatically for you when needed."
self.conn_cloudfront = connect_cloudfront(self.AWS_ACCESS_KEY_ID, self.AWS_SECRET_ACCESS_KEY, debug=self.S3UTILS_DEBUG_LEVEL) | Connect to Cloud Front. This is done automatically for you when needed. |
375,989 | def filter_paragraphs(paragraphs, contains=None):
if contains is None:
pattern =
else:
if isinstance(contains, str):
contains = [contains]
pattern = .join(r % shortform
for shortform in contains)
paragraphs = [p for p in paragraphs if re.s... | Filter paragraphs to only those containing one of a list of strings
Parameters
----------
paragraphs : list of str
List of plaintext paragraphs from an article
contains : str or list of str
Exclude paragraphs not containing this string as a token, or
at least one of the strings... |
375,990 | def begin_transaction(self, transaction_type, trace_parent=None):
return self.tracer.begin_transaction(transaction_type, trace_parent=trace_parent) | Register the start of a transaction on the client |
375,991 | def resolve_freezer(freezer):
if not freezer:
return _Default()
if isinstance(freezer, six.string_types):
cls = _freezer_lookup(freezer)
return cls()
if freezer.__class__ == type.__class__:
return freezer()
if freezer not in FREEZER.ALL:
... | Locate the appropriate freezer given FREEZER or string input from the programmer.
:param freezer: FREEZER constant or string for the freezer that is requested. (None = FREEZER.DEFAULT)
:return: |
375,992 | def parse_rst(text: str) -> docutils.nodes.document:
parser = docutils.parsers.rst.Parser()
components = (docutils.parsers.rst.Parser,)
settings = docutils.frontend.OptionParser(components=components).get_default_values()
document = docutils.utils.new_document(, settings=settings)
parser.parse(... | Parse text assuming it's an RST markup. |
375,993 | def use(parser, token):
args, kwargs = parser.parse_args(token)
assert isinstance(args[0], ast.Str), \
name = args[0].s
action = ast.YieldFrom(
value=_a.Call(_a.Attribute(_a.Name(), name), [
_a.Name(),
])
)
if kwargs:
kwargs = _wrap_kwargs(kwa... | Counterpart to `macro`, lets you render any block/macro in place. |
375,994 | def read_binary(self, num, item_type=):
if in item_type:
return self.read(num)
if item_type[0] in (, , , , ):
order = item_type[0]
item_type = item_type[1:]
else:
order =
return list(self.read_struct(Struct(order + .format(int(... | Parse the current buffer offset as the specified code. |
375,995 | def setup(app):
app.add_config_value(, True, )
app.add_config_value(, False, )
app.add_config_value(, gallery_conf, )
app.add_stylesheet()
app.connect(, generate_gallery_rst)
app.connect(, embed_code_links) | Setup sphinx-gallery sphinx extension |
375,996 | def search_stack_for_var(varname, verbose=util_arg.NOT_QUIET):
curr_frame = inspect.currentframe()
if verbose:
print( + six.text_type(varname))
frame_no = 0
while curr_frame.f_back is not None:
if varname in curr_frame.f_locals.keys():
if verbose:
print( ... | Finds a varable (local or global) somewhere in the stack and returns the value
Args:
varname (str): variable name
Returns:
None if varname is not found else its value |
375,997 | def init_storage(self):
if not self.storage.exists():
self.storage.update({
: 0,
})
self.storage.update({
: None
}) | Set current term to zero upon initialization & voted_for to None |
375,998 | def to_dot(self, path: str, title: Optional[str] = None):
g = graphviz.Digraph(format=)
g.node(, style=)
for state in self._states:
if state == self._initial_state:
if state in self._accepting_states:
g.node(str(state), root=,
... | Print the automaton to a dot file
:param path: the path where to save the file.
:param title:
:return: |
375,999 | def connected(self, node_id):
conn = self._conns.get(node_id)
if conn is None:
return False
return conn.connected() | Return True iff the node_id is connected. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.