Unnamed: 0 int64 0 389k | code stringlengths 26 79.6k | docstring stringlengths 1 46.9k |
|---|---|---|
2,600 | def _rebuild_mod_path(orig_path, package_name, module):
sys_path = [_normalize_cached(p) for p in sys.path]
def safe_sys_path_index(entry):
try:
return sys_path.index(entry)
except ValueError:
return float()
def position_in_sys_path(path):
... | Rebuild module.__path__ ensuring that all entries are ordered
corresponding to their sys.path order |
2,601 | def topological_sort(bpmn_graph, nodes_with_classification):
node_param_name = "node"
classification_param_name = "classification"
tmp_nodes_with_classification = copy.deepcopy(nodes_with_classification)
sorted_nodes_with_classification = []
no_incoming_flow_nodes = []
backward_flows = []
... | :return: |
2,602 | def add_vcenter(self, **kwargs):
config = ET.Element("config")
vcenter = ET.SubElement(config, "vcenter",
xmlns="urn:brocade.com:mgmt:brocade-vswitch")
id = ET.SubElement(vcenter, "id")
id.text = kwargs.pop()
credentials = ET.SubElement(vc... | Add vCenter on the switch
Args:
id(str) : Name of an established vCenter
url (bool) : vCenter URL
username (str): Username of the vCenter
password (str): Password of the vCenter
callback (function): A function executed upon completion of the
... |
2,603 | def configuration_from_uri(cls, persistence_uri):
db_uri, persistence_state_id = cls.parse_persistence_uri(persistence_uri)
engine = create_engine(db_uri)
Base.metadata.create_all(engine)
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session =... | Return a configuration object. |
2,604 | def explode(self):
for realm in [tmp_realm for tmp_realm in self if tmp_realm.higher_realms]:
for parent in realm.higher_realms:
higher_realm = self.find_by_name(parent)
if higher_realm:
higher_realm.realm_mem... | Explode realms with each realm_members and higher_realms to get all the
realms sub realms.
:return: None |
2,605 | def robust_init(stochclass, tries, *args, **kwds):
stochs = [arg for arg in (list(args) + list(kwds.values()))
if isinstance(arg.__class__, StochasticMeta)]
parents = stochs
for s in stochs:
parents.extend(s.extended_parents)
extended_parents = set(parents)
... | Robust initialization of a Stochastic.
If the evaluation of the log-probability returns a ZeroProbability
error, due for example to a parent being outside of the support for
this Stochastic, the values of parents are randomly sampled until
a valid log-probability is obtained.
If the log-probabilit... |
2,606 | def download(url, dest):
u = urllib.FancyURLopener()
logger.info("Downloading %s..." % url)
u.retrieve(url, dest)
logger.info( % dest)
return dest | Platform-agnostic downloader. |
2,607 | def is_valid(self):
if not self:
return True
if self.left and self.data[self.axis] < self.left.data[self.axis]:
return False
if self.right and self.data[self.axis] > self.right.data[self.axis]:
return False
return all(c.is_valid() for c, _... | Checks recursively if the tree is valid
It is valid if each node splits correctly |
2,608 | def s2m(self):
m = % (IDENT)
self.meta.load(m, % (m), mdict=self.settings.get) | Imports settings to meta |
2,609 | def _get_prepped_model_field(model_obj, field):
field = model_obj._meta.get_field(field)
value = field.get_db_prep_save(getattr(model_obj, field.attname), connection)
return value | Gets the value of a field of a model obj that is prepared for the db. |
2,610 | def _repr_latex_(self):
lines.append(r"\begin{align*}")
for lhs, rhs in zip(self.left_hand_side_descriptors, self.right_hand_side):
lines.append(r"\dot{{{0}}} &= {1} \\".format(sympy.latex(lhs.symbol), sympy.latex(rhs)))
lines.append(r"\end{align*}")
return ... | This is used in IPython notebook it allows us to render the ODEProblem object in LaTeX.
How Cool is this? |
2,611 | def show_dependencies(self, stream=sys.stdout):
def child_iter(node):
return [d.node for d in node.deps]
def text_str(node):
return colored(str(node), color=node.status.color_opts["color"])
for task in self.iflat_tasks():
print(draw_tree(task, child... | Writes to the given stream the ASCII representation of the dependency tree. |
2,612 | def create(cls, name, gateway, network, input_speed=None,
output_speed=None, domain_server_address=None,
provider_name=None, probe_address=None,
standby_mode_period=3600, standby_mode_timeout=30,
active_mode_period=5, active_mode_timeout=1, comment=None):
... | Create a new StaticNetlink to be used as a traffic handler.
:param str name: name of netlink Element
:param gateway_ref: gateway to map this netlink to. This can be an element
or str href.
:type gateway_ref: Router,Engine
:param list ref: network/s associated with this netli... |
2,613 | def previous(self):
try:
return self.__class__.objects.for_model(self.content_object,
self.content_type).\
filter(order__gt=self.order).order_by()[0]
except IndexError:
return None | Returns previous image for same content_object and None if image
is the first. |
2,614 | def _read_sections(ifile):
if os.path.exists(ifile):
return read_sections(ifile, exclude_ungrouped=True, prt=None) | Read sections_in.txt file, if it exists. |
2,615 | def get_current_live_chat(self):
now = datetime.now()
chat = self.upcoming_live_chat()
if chat and chat.is_in_progress():
return chat
return None | Check if there is a live chat on the go, so that we should take
over the AskMAMA page with the live chat. |
2,616 | def _get_pos_name(code, name=, english=True, delimiter=,
pos_tags=pos_map.POS_MAP):
pos_name = pos_map.get_pos_name(code, name, english, pos_tags=pos_tags)
return delimiter.join(pos_name) if name == else pos_name | Gets the part of speech name for *code*.
Joins the names together with *delimiter* if *name* is ``'all'``.
See :func:``pynlpir.pos_map.get_pos_name`` for more information. |
2,617 | def parse(s):
r
stuff = []
rest = s
while True:
front, token, rest = peel_off_esc_code(rest)
if front:
stuff.append(front)
if token:
try:
tok = token_type(token)
if tok:
stuff.extend(tok)
exce... | r"""
Returns a list of strings or format dictionaries to describe the strings.
May raise a ValueError if it can't be parsed.
>>> parse(">>> []")
['>>> []']
>>> #parse("\x1b[33m[\x1b[39m\x1b[33m]\x1b[39m\x1b[33m[\x1b[39m\x1b[33m]\x1b[39m\x1b[33m[\x1b[39m\x1b[33m]\x1b[39m\x1b[33m[\x1b[39m") |
2,618 | def set_path(self, file_path):
if not file_path:
self.read_data = self.memory_read
self.write_data = self.memory_write
elif not is_valid(file_path):
self.write_data(file_path, {})
self.path = file_path | Set the path of the database.
Create the file if it does not exist. |
2,619 | def dump_graph(self):
with self.lock:
return {
dot_separated(k): v.dump_graph_entry()
for k, v in self.relations.items()
} | Dump a key-only representation of the schema to a dictionary. Every
known relation is a key with a value of a list of keys it is referenced
by. |
2,620 | def update_slidepos(self):
g = get_root(self).globals
if not g.cpars[]:
self.after(20000, self.update_slidepos)
return
def slide_threaded_update():
try:
(pos_ms, pos_mm, pos_px), msg = g.fpslide.slide.return_position()
... | Periodically update the slide position.
Also farmed out to a thread to avoid hanging GUI main thread |
2,621 | def call_audit(func):
def audited_func(*args, **kwargs):
import traceback
stack = traceback.extract_stack()
r = func(*args, **kwargs)
func_name = func.__name__
print("@depth %d, trace %s -> %s(*%r, **%r) => %r" % (
len(stack),
" -> ".join("%s:%d:... | Print a detailed audit of all calls to this function. |
2,622 | def as_format(item, format_str=):
if isinstance(item, pd.Series):
return item.map(lambda x: format(x, format_str))
elif isinstance(item, pd.DataFrame):
return item.applymap(lambda x: format(x, format_str)) | Map a format string over a pandas object. |
2,623 | def _get_graph(graph, filename):
try:
rendered = graph.rendered_file
except AttributeError:
try:
graph.render(os.path.join(server.tmpdir, filename), format=)
rendered = filename
except OSError:
rendered = None
graph.rendered_file = rendered
... | Retrieve or render a graph. |
2,624 | def mean_subtraction(x, mean, t, base_axis=1, update_running_mean=True):
r
from .function_bases import mean_subtraction as mean_subtraction_base
return mean_subtraction_base(x, mean, t,
base_axis=base_axis,
update_running_mean=update_running_... | r"""
It subtracts the mean of the elements of the input array,
and normalizes it to :math:`0`. Preprocessing arrays with this function has the effect of improving accuracy
in various tasks such as image classification.
At training time, this function is defined as
.. math::
\begin{eqnarray... |
2,625 | def _folder_item_assigned_worksheet(self, analysis_brain, item):
if not IAnalysisRequest.providedBy(self.context):
return
analysis_obj = self.get_object(analysis_brain)
worksheet = analysis_obj.getWorksheet()
if not worksheet:
r... | Adds an icon to the item dict if the analysis is assigned to a
worksheet and if the icon is suitable for the current context
:param analysis_brain: Brain that represents an analysis
:param item: analysis' dictionary counterpart that represents a row |
2,626 | def raw_snapshot_data(self, name):
j, _ = self.datacenter.request(, self.path + +
str(name))
return j | ::
GET /:login/machines/:id/snapshots/:name
:param name: identifier for snapshot
:type name: :py:class:`basestring`
:rtype: :py:class:`dict`
Used internally to get a raw dict of a single machine snapshot. |
2,627 | def for_account_hash(parent, account_hash):
account = AccountProxy(parent)
account.account_hash = account_hash
if account.acquire():
return account
return None | Returns a new AccountProxy that acquires the account with the
given hash, if such an account is known to the account manager.
It is an error if the account manager does not have such an
account. |
2,628 | def launch_ipython_legacy_shell(args):
try:
from IPython.config.loader import Config
except ImportError:
_print("The SolveBio Python shell requires IPython.\n"
"To install, type: ")
return False
try:
globals(), locals())
InteractiveShellE... | Open the SolveBio shell (IPython wrapper) for older IPython versions |
2,629 | def create_secgroup_rule(self, protocol, from_port, to_port,
source, target):
nova = self.nova
def get_id(gname):
sg = nova.security_groups.find(name=gname)
if not sg:
raise BangError("Security group not found, %s" % gname)
return... | Creates a new server security group rule.
:param str protocol: E.g. ``tcp``, ``icmp``, etc...
:param int from_port: E.g. ``1``
:param int to_port: E.g. ``65535``
:param str source:
:param str target: |
2,630 | def update(self, configuration, debug=None):
if self.config != dict(configuration) and debug != self.debug:
self.config = dict(configuration)
self.debug = debug
self.configure()
return True
return False | Update the internal configuration values, removing debug_only
handlers if debug is False. Returns True if the configuration has
changed from previous configuration values.
:param dict configuration: The logging configuration
:param bool debug: Toggles use of debug_only loggers
:... |
2,631 | def touch(args):
from time import ctime
p = OptionParser(touch.__doc__)
opts, args = p.parse_args(args)
if len(args) != 1:
sys.exit(not p.print_help())
info, = args
fp = open(info)
for row in fp:
path, atime, mtime = row.split()
atime = float(atime)
mt... | %prog touch timestamp.info
Recover timestamps for files in the current folder.
CAUTION: you must execute this in the same directory as timestamp(). |
2,632 | def corr_dw_v1(self):
con = self.parameters.control.fastaccess
der = self.parameters.derived.fastaccess
flu = self.sequences.fluxes.fastaccess
old = self.sequences.states.fastaccess_old
new = self.sequences.states.fastaccess_new
idx = der.toy[self.idx_sim]
if (con.maxdw[idx] > 0.) and (... | Adjust the water stage drop to the highest value allowed and correct
the associated fluxes.
Note that method |corr_dw_v1| calls the method `interp_v` of the
respective application model. Hence the requirements of the actual
`interp_v` need to be considered additionally.
Required control parameter... |
2,633 | def delete(name=None, group_id=None, region=None, key=None, keyid=None,
profile=None, vpc_id=None, vpc_name=None):
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
group = _get_group(conn, name=name, vpc_id=vpc_id, vpc_name=vpc_name,
group_id=group_i... | Delete a security group.
CLI example::
salt myminion boto_secgroup.delete mysecgroup |
2,634 | def get_assessment_notification_session_for_bank(self, assessment_receiver, bank_id):
if not self.supports_assessment_notification():
raise errors.Unimplemented()
return sessions.ItemNotificationSession(bank_id, runtime=self._runtime, receiver=ass... | Gets the ``OsidSession`` associated with the assessment notification service for the given bank.
arg: assessment_receiver
(osid.assessment.AssessmentReceiver): the assessment
receiver interface
arg: bank_id (osid.id.Id): the ``Id`` of the bank
return: (osid... |
2,635 | def do_bugin(self, args):
args = args.split()
if _debug: ConsoleCmd._debug("do_bugin %r", args)
if args:
loggerName = args[0]
if loggerName in logging.Logger.manager.loggerDict:
logger = logging.getLogger(loggerName)
else:
... | bugin [ <logger> ] - add a console logging handler to a logger |
2,636 | def SA_tank(D, L, sideA=None, sideB=None, sideA_a=0,
sideB_a=0, sideA_f=None, sideA_k=None, sideB_f=None, sideB_k=None,
full_output=False):
rs type; one of
[None, , , , , ].
sideB : string, optional
The right (or top for vertical) head of the tankconicalellipsoidaltoris... | r'''Calculates the surface are of a cylindrical tank with optional heads.
In the degenerate case of being provided with only `D` and `L`, provides
the surface area of a cylinder.
Parameters
----------
D : float
Diameter of the cylindrical section of the tank, [m]
L : float
Lengt... |
2,637 | def rank_members_in(self, leaderboard_name, members_and_scores):
for member, score in grouper(2, members_and_scores):
self.rank_member_in(leaderboard_name, member, score) | Rank an array of members in the named leaderboard.
@param leaderboard_name [String] Name of the leaderboard.
@param members_and_scores [Array] Variable list of members and scores. |
2,638 | def update_context(self, ctx):
assert isinstance(ctx, dict)
ctx[str(self.context_id)] = self.value | updates the query context with this clauses values |
2,639 | def list_nodes_min(call=None):
if call == :
raise SaltCloudSystemExit(
)
ret = {}
for device in get_devices_by_token():
ret[device.hostname] = {: device.id, : device.state}
return ret | Return a list of the VMs that are on the provider. Only a list of VM names and
their state is returned. This is the minimum amount of information needed to
check for existing VMs.
.. versionadded:: 2015.8.0
CLI Example:
.. code-block:: bash
salt-cloud -f list_nodes_min packet-provider
... |
2,640 | def remove_all_trips_fully_outside_buffer(db_conn, center_lat, center_lon, buffer_km, update_secondary_data=True):
distance_function_str = add_wgs84_distance_function_to_db(db_conn)
stops_within_buffer_query_sql = "SELECT stop_I FROM stops WHERE CAST(" + distance_function_str + \
... | Not used in the regular filter process for the time being.
Parameters
----------
db_conn: sqlite3.Connection
connection to the GTFS object
center_lat: float
center_lon: float
buffer_km: float |
2,641 | def load_checkpoints(self, checkpointDirs):
self.memo_lookup_table = None
if not checkpointDirs:
return {}
if type(checkpointDirs) is not list:
raise BadCheckpoint("checkpointDirs expects a list of checkpoints")
return self._load_checkpoints(checkpoint... | Load checkpoints from the checkpoint files into a dictionary.
The results are used to pre-populate the memoizer's lookup_table
Kwargs:
- checkpointDirs (list) : List of run folder to use as checkpoints
Eg. ['runinfo/001', 'runinfo/002']
Returns:
- dict... |
2,642 | def require(*args, **kwargs):
if not args and not kwargs:
return freeze()
requirements = list(args)
extra = [.format(kw, kwargs[kw]) for kw in kwargs]
requirements.extend(extra)
args = [, ]
args.extend(requirements)
pip.main(args) | Install a set of packages using pip
This is designed to be an interface for IPython notebooks that
replicates the requirements.txt pip format. This lets notebooks
specify which versions of packages they need inside the notebook
itself.
This function is the general-purpose interface that lets
... |
2,643 | def processResponse(self, arg, replytype, **kw):
if self.debug:
log.msg( %arg, debug=1)
for h in self.handlers:
arg.addCallback(h.processResponse, **kw)
arg.addCallback(self.parseResponse, replytype) | Parameters:
arg -- deferred
replytype -- typecode |
2,644 | def lit_count(self):
lit_value = self.value * len(self)
if not isinstance(self[0], PWMLED):
lit_value = int(lit_value)
return lit_value | The number of LEDs on the bar graph actually lit up. Note that just
like :attr:`value`, this can be negative if the LEDs are lit from last
to first. |
2,645 | def rename(name):
from peltak.extra.gitflow import logic
if name is None:
name = click.prompt()
logic.hotfix.rename(name) | Give the currently developed hotfix a new name. |
2,646 | def decode_ay(ay):
if ay is None:
return
elif isinstance(ay, str):
return ay
elif isinstance(ay, bytes):
return ay.decode()
else:
return bytearray(ay).rstrip(bytearray((0,))).decode() | Convert binary blob from DBus queries to strings. |
2,647 | def decode(self, inputs, context, inference=False):
return self.decoder(inputs, context, inference) | Applies the decoder to inputs, given the context from the encoder.
:param inputs: tensor with inputs (batch, seq_len) if 'batch_first'
else (seq_len, batch)
:param context: context from the encoder
:param inference: if True inference mode, if False training mode |
2,648 | def fromstring(cls, s, *args, **kwargs):
s = s.replace("\(", "&lparen;")
s = s.replace("\)", "&rparen;")
s = s.replace("\[", "[")
s = s.replace("\]", "]")
s = s.replace("\{", "&lcurly;")
s = s.replace("\}", "&rcurly;")
p = []
i = 0
... | Returns a new Pattern from the given string.
Constraints are separated by a space.
If a constraint contains a space, it must be wrapped in []. |
2,649 | def subscribe(self, clock_name: str=None, clock_slots: Iterable[str]=None, subscriptions: Dict[str, Any]={}):
for area in subscriptions:
init_full(self, area, subscriptions[area])
subscriptions[area] = {: subscriptions[area]}
if clock_name is not None:
self.clock_name = clock_name
self.clock_slots... | Subscribes this Area to the given Areas and optionally given Slots. Must be called before the Area is run.
Args:
clock_name: The name of the Area that is used as synchronizing Clock.
clock_slots: The slots of the Clock relevant to this Area.
subscriptions: A dictionary containing the relevant Areas names as... |
2,650 | def flush(self, preserve=None):
if not os.path.exists(self.path):
return
if preserve is None:
shutil.rmtree(self.path)
return
for mip in self.vol.available_mips:
preserve_mip = self.vol.slices_from_global_coords(preserve)
preserve_mip = Bbox.from_slices(preserve_mip)
... | Delete the cache for this dataset. Optionally preserve
a region. Helpful when working with overlaping volumes.
Warning: the preserve option is not multi-process safe.
You're liable to end up deleting the entire cache.
Optional:
preserve (Bbox: None): Preserve chunks located partially
or ... |
2,651 | def immediate(self, name, value):
setattr(self, name, value)
self._all.add(name) | Load something immediately |
2,652 | def setconf(self, conf, rscpath, logger=None):
resource = self.pathresource(rscpath=rscpath, logger=logger)
if resource is None:
resource = self.resource()
try:
self._setconf(conf=conf, resource=resource, rscpath=rscpath)
except Exception as ex:
... | Set input conf in input path.
:param Configuration conf: conf to write to path.
:param str rscpath: specific resource path to use.
:param Logger logger: used to log info/errors.
:param bool error: raise catched errors.
:raises: ConfDriver.Error in case of error and input error. |
2,653 | def queue_it(queue=g_queue, **put_args):
def func_wrapper(func):
@wraps(func)
def wrapper(*args, **kwargs):
queue.put(func(*args, **kwargs), **put_args)
return wrapper
return func_wrapper | Wrapper. Instead of returning the result of the function, add it to a queue.
.. code: python
import reusables
import queue
my_queue = queue.Queue()
@reusables.queue_it(my_queue)
def func(a):
return a
func(10)
print(my_queue.get())
# 1... |
2,654 | def in_resource(cls, session_type):
if cls.resources is AllSessionTypes:
return True
return session_type in cls.resources | Returns True if the attribute is part of a given session type.
The session_type is a tuple with the interface type and resource_class
:type session_type: (constants.InterfaceType, str)
:rtype: bool |
2,655 | def switch(self, idx, control):
old = None
new = None
if control == :
if self.PQ[idx] == 1:
old =
new =
elif self.vQ[idx] == 1:
old =
new =
elif control == :
if self.PQ[idx] =... | Switch a single control of <idx> |
2,656 | def RunStateMethod(self, method_name, request=None, responses=None):
if self.rdf_flow.pending_termination:
self.Error(error_message=self.rdf_flow.pending_termination.reason)
return
client_id = self.rdf_flow.client_id
deadline = self.rdf_flow.processing_deadline
if deadline and rdfvalu... | Completes the request by calling the state method.
Args:
method_name: The name of the state method to call.
request: A RequestState protobuf.
responses: A list of FlowMessages responding to the request. |
2,657 | def enterprise_login_required(view):
@wraps(view)
def wrapper(request, *args, **kwargs):
if not in kwargs:
raise Http404
enterprise_uuid = kwargs[]
enterprise_customer = get_enterprise_customer_or_404(enterprise_uuid)
if not... | View decorator for allowing authenticated user with valid enterprise UUID.
This decorator requires enterprise identifier as a parameter
`enterprise_uuid`.
This decorator will throw 404 if no kwarg `enterprise_uuid` is provided to
the decorated view .
If there is no enterprise in database against ... |
2,658 | def load_terminfo(terminal_name=None, fallback=):
terminal_name = os.getenv()
if not terminal_name:
if not fallback:
raise TerminfoError()
else:
terminal_name = fallback
if os.getenv():
terminfo_locations = [os.getenv()]
... | If the environment variable TERM is unset try with `fallback` if not empty.
vt100 is a popular terminal supporting ANSI X3.64. |
2,659 | def get_children(self, node):
try:
index = self.nodes.index(node) + 1
return [self.nodes[index]]
except IndexError:
return [] | Get children. |
2,660 | def create_pipeline(url, auth, json_payload, verify_ssl):
title = json_payload[][]
description = json_payload[][]
params = {:description, :True}
logging.info( + title)
put_result = requests.put(url + + title, params=params, headers=X_REQ_BY, auth=auth, verify=verify_ssl)
put_result.raise_f... | Create a new pipeline.
Args:
url (str): the host url in the form 'http://host:port/'.
auth (tuple): a tuple of username, and password.
json_payload (dict): the exported json paylod as a dictionary.
verify_ssl (bool): whether to verify ssl certificates
Returns... |
2,661 | def preload(python_data: LdapObject, database: Optional[Database] = None) -> LdapObject:
changes = {}
def preload_item(value: Any) -> Any:
if isinstance(value, NotLoaded):
return value.load(database)
else:
return value
for name in python_data.keys():
... | Preload all NotLoaded fields in LdapObject. |
2,662 | def profileUpperLimit(self, delta = 2.71):
a = self.p_2
b = self.p_1
if self.vertex_x < 0:
c = self.p_0 + delta
else:
c = self.p_0 - self.vertex_y + delta
if b**2 - 4. * a * c < 0.:
print()
print(a, b, c)
retur... | Compute one-sided upperlimit via profile method. |
2,663 | def get(no_create=False, server=None, port=None, force_uuid=None):
pid = os.getpid()
thread = threading.current_thread()
wdb = Wdb._instances.get((pid, thread))
if not wdb and not no_create:
wdb = object.__new__(Wdb)
Wdb.__init__(wdb, server, port, force_... | Get the thread local singleton |
2,664 | def display(self, filename=None):
if filename is None:
filename =
self.save(filename)
open_in_browser(filename) | Displays/opens the doc using the OS's default application. |
2,665 | def validate(self, table: pd.DataFrame, failed_only=False) -> pd.DataFrame:
return pd.concat([
self._validate_input(table, failed_only=failed_only),
self._validate_output(table, failed_only=failed_only),
]).fillna(True) | Return a dataframe of validation results for the appropriate series vs the vector of validators.
Args:
table (pd.DataFrame): A dataframe on which to apply validation logic.
failed_only (bool): If ``True``: return only the indexes that failed to validate. |
2,666 | def assert_gt(left, right, message=None, extra=None):
assert left > right, _assert_fail_message(message, left, right, "<=", extra) | Raises an AssertionError if left_hand <= right_hand. |
2,667 | def enqueue_job(self, job):
self.log.debug(.format(job.id, job.origin))
interval = job.meta.get(, None)
repeat = job.meta.get(, None)
cron_string = job.meta.get(, None)
if repeat:
job.meta[] = int(repeat) - 1
queue = self.get_queue_for_job... | Move a scheduled job to a queue. In addition, it also does puts the job
back into the scheduler if needed. |
2,668 | def count(self, model_class, conditions=None):
s table.
- `model_class`: the model to count.
- `conditions`: optional SQL conditions (contents of the WHERE clause).
SELECT count() FROM $table WHERE ' + conditions
query = self._substitute(query, model_class)
r = self._sen... | Counts the number of records in the model's table.
- `model_class`: the model to count.
- `conditions`: optional SQL conditions (contents of the WHERE clause). |
2,669 | def delete(ctx, opts, owner_repo_identifier, yes):
owner, repo, identifier = owner_repo_identifier
delete_args = {
"identifier": click.style(identifier, bold=True),
"repository": click.style(repo, bold=True),
}
prompt = (
"delete the %(identifier)s entitlement from the %(r... | Delete an entitlement from a repository.
- OWNER/REPO/IDENTIFIER: Specify the OWNER namespace (i.e. user or org),
and the REPO name that has an entitlement identified by IDENTIFIER. All
separated by a slash.
Example: 'your-org/your-repo/abcdef123456'
Full CLI example:
$ cloudsmith ... |
2,670 | def array(
item_processor,
alias=None,
nested=None,
omit_empty=False,
hooks=None
):
processor = _Array(item_processor, alias, nested, omit_empty)
return _processor_wrap_if_hooks(processor, hooks) | Create an array processor that can be used to parse and serialize array data.
XML arrays may be nested within an array element, or they may be embedded
within their parent. A nested array would look like:
.. sourcecode:: xml
<root-element>
<some-element>ABC</some-element>
... |
2,671 | def get_or_create_evidence(self, citation: Citation, text: str) -> Evidence:
sha512 = hash_evidence(text=text, type=str(citation.type), reference=str(citation.reference))
if sha512 in self.object_cache_evidence:
evidence = self.object_cache_evidence[sha512]
self.session... | Create an entry and object for given evidence if it does not exist. |
2,672 | def from_str(cls, timestr, shaked=False):
orig = timestr
if not shaked:
timestr = cls.fix_timezone_separator(timestr)
try:
date = parser.parse(timestr)
except ValueError:
if not shaked:
shaked = False
for shaker... | Use `dateutil` module to parse the give string
:param basestring timestr: string representing a date to parse
:param bool shaked: whether the input parameter been already
cleaned or not. |
2,673 | def npz_to_W_pdf(path=None, regx=):
r
file_list = load_file_list(path=path, regx=regx)
for f in file_list:
W = load_npz(path, f)[0]
logging.info("%s --> %s" % (f, f.split()[0] + ))
visualize.draw_weights(W, second=10, saveable=True, name=f.split()[0], fig_idx=2012) | r"""Convert the first weight matrix of `.npz` file to `.pdf` by using `tl.visualize.W()`.
Parameters
----------
path : str
A folder path to `npz` files.
regx : str
Regx for the file name.
Examples
---------
Convert the first weight matrix of w1_pre...npz file to w1_pre...pd... |
2,674 | def set_backlight(self, backlight):
if self._backlight is not None:
if self._pwm_enabled:
self._pwm.set_duty_cycle(self._backlight, self._pwm_duty_cycle(backlight))
else:
self._gpio.output(self._backlight, self._blpol if backlight else not self._b... | Enable or disable the backlight. If PWM is not enabled (default), a
non-zero backlight value will turn on the backlight and a zero value will
turn it off. If PWM is enabled, backlight can be any value from 0.0 to
1.0, with 1.0 being full intensity backlight. |
2,675 | def define_standalone_options(parser, extra_options=None):
c = config.parse_service_config()
parser.add_option(, , action=, dest=,
type=, help=,
default=c.db.host)
parser.add_option(, , action=, dest=,
type=, help=,
... | Adds the options specific to the database connection.
Parses the agency configuration files and uses its configuration as the
default values. |
2,676 | def is_citeable(publication_info):
def _item_has_pub_info(item):
return all(
key in item for key in (
,
)
)
def _item_has_page_or_artid(item):
return any(
key in item for key in (
,
)
)
... | Check some fields in order to define if the article is citeable.
:param publication_info: publication_info field
already populated
:type publication_info: list |
2,677 | def add_permission(FunctionName, StatementId, Action, Principal, SourceArn=None,
SourceAccount=None, Qualifier=None,
region=None, key=None, keyid=None, profile=None):
try:
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
kwargs = {}
... | Add a permission to a lambda function.
Returns {added: true} if the permission was added and returns
{added: False} if the permission was not added.
CLI Example:
.. code-block:: bash
salt myminion boto_lamba.add_permission my_function my_id "lambda:*" \\
s3.amazona... |
2,678 | def move(self, dest, src):
doc = deepcopy(self.document)
parent, fragment = None, doc
for token in Pointer(src):
parent, fragment = fragment, token.extract(fragment,
bypass_ref=True)
if isinstance(par... | Move element from sequence, member from mapping.
:param dest: the destination
:type dest: Pointer
:param src: the source
:type src: Pointer
:return: resolved document
:rtype: Target
.. note::
This operation is functionally identical to a "remove" op... |
2,679 | def order_by(self, key_selector=identity):
if self.closed():
raise ValueError("Attempt to call order_by() on a "
"closed Queryable.")
if not is_callable(key_selector):
raise TypeError("order_by() parameter key_selector={key_selector} "
... | Sorts by a key in ascending order.
Introduces a primary sorting order to the sequence. Additional sort
criteria should be specified by subsequent calls to then_by() and
then_by_descending(). Calling order_by() or order_by_descending() on
the results of a call to order_by() will introdu... |
2,680 | def stop(self):
logger.info("stopping process")
self.watcher.stop()
os.kill(self.child_pid, signal.SIGTERM) | Stop the process. |
2,681 | def _raiseImageMissing(self, pattern):
event = ImageMissingEvent(self, pattern=pattern, event_type="MISSING")
if self._imageMissingHandler is not None:
self._imageMissingHandler(event)
response = (event._response or self._findFailedResponse)
if res... | Builds an ImageMissing event and triggers the default handler (or the custom handler,
if one has been specified). Returns True if throwing method should retry, False if it
should skip, and throws an exception if it should abort. |
2,682 | def get_labels(self, plt, label_fontsize=10):
if len(self.slab_regions) > 1:
label_in_vac = (self.slab_regions[0][1] + self.slab_regions[1][0])/2
if abs(self.slab_regions[0][0]-self.slab_regions[0][1]) > \
abs(self.slab_regions[1][0]-self.slab_regio... | Handles the optional labelling of the plot with relevant quantities
Args:
plt (plt): Plot of the locpot vs c axis
label_fontsize (float): Fontsize of labels
Returns Labelled plt |
2,683 | def _update_settings(self, dialect):
for parameter in self.csv_params[2:]:
pname, ptype, plabel, phelp = parameter
widget = self._widget_from_p(pname, ptype)
if ptype is types.TupleType:
ptype = types.ObjectType
digest = Diges... | Sets the widget settings to those of the chosen dialect |
2,684 | def upload(self, login, package_name, release, basename, fd, distribution_type,
description=, md5=None, size=None, dependencies=None, attrs=None, channels=(,), callback=None):
2.7osx
url = % (self.domain, login, package_name, release, quote(basename))
if attrs is None:
... | Upload a new distribution to a package release.
:param login: the login of the package owner
:param package_name: the name of the package
:param version: the version string of the release
:param basename: the basename of the distribution to download
:param fd: a file like object... |
2,685 | def make_simple(self):
(inner_radius, outer_radius) = self.get_radii()
radius = (inner_radius + outer_radius) / 2
return cadquery.Workplane() \
.circle(radius).extrude(self.length) | Return a cylinder with the thread's average radius & length.
:math:`radius = (inner_radius + outer_radius) / 2` |
2,686 | def safe_either(method, dictionary, key1, key2, default_value=None):
value = method(dictionary, key1)
return value if value is not None else method(dictionary, key2, default_value) | A helper-wrapper for the safe_value_2() family. |
2,687 | def clear_alarms(alarm):
*
if _TRAFFICCTL:
cmd = _traffic_ctl(, , alarm)
else:
cmd = _traffic_line(, alarm)
return _subprocess(cmd) | Clear (acknowledge) an alarm event. The arguments are “all” for all current
alarms, a specific alarm number (e.g. ‘‘1’‘), or an alarm string identifier
(e.g. ‘’MGMT_ALARM_PROXY_CONFIG_ERROR’‘).
.. code-block:: bash
salt '*' trafficserver.clear_alarms [all | #event | name] |
2,688 | def open(self):
options = copy(self.__options)
compression = None
if self.__scheme is None or self.__format is None:
detected_scheme, detected_format = helpers.detect_scheme_and_format(self.__source)
scheme = self.__scheme or detected_scheme
... | Opens the stream for reading. |
2,689 | def FindByIndex(node, index):
s children are in a list it will recursively search - similarly if the index is not found
in the current node
result = None
if isinstance(node.children, dict):
result = node.GetChild(index)
if result is None:
children = list(node.children.keys())... | Method which finds child according to index. Applies only to nodes whose children are sorted into a dict,
so if the current node's children are in a list it will recursively search - similarly if the index is not found
in the current node's dictionary indexes.
:param node: current node to search for
:pa... |
2,690 | def _get_field(self, field):
if not hasattr(self, "id") or self.id is None:
raise APIResponseError("Cannot query an article without an id")
sq = next(SearchQuery(q="id:{}".format(self.id), fl=field))
if field not in sq._raw:
... | Queries the api for a single field for the record by `id`.
This method should only be called indirectly by cached properties.
:param field: name of the record field to load |
2,691 | def get_user_permissions(self, username):
path = Client.urls[] % (username,)
conns = self._call(path, )
return conns | :returns: list of dicts, or an empty list if there are no permissions.
:param string username: User to set permissions for. |
2,692 | def delete_many(self, mongo_collection, filter_doc, mongo_db=None, **kwargs):
collection = self.get_collection(mongo_collection, mongo_db=mongo_db)
return collection.delete_many(filter_doc, **kwargs) | Deletes one or more documents in a mongo collection.
https://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.delete_many
:param mongo_collection: The name of the collection to delete from.
:type mongo_collection: str
:param filter_doc: A query th... |
2,693 | def _get_argspec(func):
if inspect.isclass(func):
func = func.__init__
if not inspect.isfunction(func):
return [], False
parameters = inspect.signature(func).parameters
args = []
uses_starstar = False
for par in parameters.values():
if (par.kind == inspect.P... | Helper function to support both Python versions |
2,694 | def _headline(self, error, i: int) -> str:
msgs = Msg()
if error.errclass == "fatal":
msg = msgs.fatal(i)
elif error.errclass == "warning":
msg = msgs.warning(i)
elif error.errclass == "info":
msg = msgs.info(i)
elif error.err... | Format the error message's headline |
2,695 | def dataset(self, **kwargs):
kwargs_copy = self.base_dict.copy()
kwargs_copy.update(**kwargs)
self._replace_none(kwargs_copy)
try:
return NameFactory.dataset_format.format(**kwargs_copy)
except KeyError:
return None | Return a key that specifies the data selection |
2,696 | def subsample(self):
logging.info()
for _ in range(self.cpus):
threads = Thread(target=self.subsamplethreads, args=())
threads.setDaemon(True)
threads.start()
with progressbar(self.runmetadata.samples) as bar:
for sample in bar:
... | Subsample 1000 reads from the baited files |
2,697 | def _proxy(self):
if self._context is None:
self._context = UsageContext(self._version, sim_sid=self._solution[], )
return self._context | Generate an instance context for the instance, the context is capable of
performing various actions. All instance actions are proxied to the context
:returns: UsageContext for this UsageInstance
:rtype: twilio.rest.preview.wireless.sim.usage.UsageContext |
2,698 | def _handleBulletWidth(bulletText, style, maxWidths):
if bulletText:
if isinstance(bulletText, basestring):
bulletWidth = stringWidth(bulletText, style.bulletFontName, style.bulletFontSize)
else:
bulletWidth = 0
for f in bulletText:
... | work out bullet width and adjust maxWidths[0] if neccessary |
2,699 | def _poor_convergence(z, r, f, bn, mvec):
check_points = (-0.4 + 0.3j, 0.7 + 0.2j, 0.02 - 0.06j)
diffs = []
ftests = []
for check_point in check_points:
rtest = r * check_point
ztest = z + rtest
ftest = f(ztest)
comp = np.sum(bn * np.power(check_point, mvec)... | Test for poor convergence based on three function evaluations.
This test evaluates the function at the three points and returns false if
the relative error is greater than 1e-3. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.