Unnamed: 0 int64 0 389k | code stringlengths 26 79.6k | docstring stringlengths 1 46.9k |
|---|---|---|
2,300 | def get_live_data_flat_binary(self):
byte_buffer = self.game.UpdateLiveDataPacketFlatbuffer()
if byte_buffer.size >= 4:
proto_string = ctypes.string_at(byte_buffer.ptr, byte_buffer.size)
self.game.Free(byte_buffer.ptr)
self.game_... | Gets the live data packet in flatbuffer binary format. You'll need to do something like
GameTickPacket.GetRootAsGameTickPacket(binary, 0) to get the data out.
This is a temporary method designed to keep the integration test working. It returns the raw bytes
of the flatbuffer so that it can be s... |
2,301 | def getReverseRankMaps(self):
reverseRankMaps = []
for preference in self.preferences:
reverseRankMaps.append(preference.getReverseRankMap())
return reverseRankMaps | Returns a list of dictionaries, one for each preference, that associates each position in
the ranking with a list of integer representations of the candidates ranked at that
position and returns a list of the number of times each preference is given. |
2,302 | def function(self, addr=None, name=None, create=False, syscall=False, plt=None):
if addr is not None:
try:
f = self._function_map.get(addr)
if plt is None or f.is_plt == plt:
return f
except KeyError:
if create:... | Get a function object from the function manager.
Pass either `addr` or `name` with the appropriate values.
:param int addr: Address of the function.
:param str name: Name of the function.
:param bool create: Whether to create the function or not if the function does not exist.
... |
2,303 | def set_stop_chars_left(self, stop_chars):
if not isinstance(stop_chars, set):
raise TypeError("stop_chars should be type set "
"but {} was given".format(type(stop_chars)))
self._stop_chars_left = stop_chars
self._stop_chars = self._stop_chars_le... | Set stop characters for text on left from TLD.
Stop characters are used when determining end of URL.
:param set stop_chars: set of characters
:raises: TypeError |
2,304 | def color_is_forced(**envars):
1
result = env.CLICOLOR_FORCE and env.CLICOLOR_FORCE !=
log.debug(, result, env.CLICOLOR_FORCE or )
for name, value in envars.items():
envar = getattr(env, name)
if envar.value == value:
result = True
log.debug(, name, value, result)
... | Look for clues in environment, e.g.:
- https://bixense.com/clicolors/
Arguments:
envars: Additional environment variables to check for
equality, i.e. ``MYAPP_COLOR_FORCED='1'``
Returns:
Bool: Forced |
2,305 | def set_tag(self, tag):
if self._world:
if self._world.get_entity_by_tag(tag):
raise NonUniqueTagError(tag)
self._tag = tag | Sets the tag.
If the Entity belongs to the world it will check for tag conflicts. |
2,306 | def is_letter(uni_char):
category = Category.get(uni_char)
return (category == Category.UPPERCASE_LETTER or
category == Category.LOWERCASE_LETTER or
category == Category.TITLECASE_LETTER or
category == Category.MODIFIER_LETTER or
category == Category.OTHER_LE... | Determine whether the given Unicode character is a Unicode letter |
2,307 | def parse_note(cls, note):
if isinstance(note, tuple):
if len(note) != 2:
raise ValueError()
return note
try:
match = cls.re_note.match(note)
except TypeError:
return note, None
return match.groups() | Parse string annotation into object reference with optional name. |
2,308 | def update_template(self, template_id, template_dict):
return self._create_put_request(
resource=TEMPLATES,
billomat_id=template_id,
send_data=template_dict
) | Updates a template
:param template_id: the template id
:param template_dict: dict
:return: dict |
2,309 | def _compile_seriesflow(self):
string =
self.seriesflow = compile(eval(string), , ) | Post power flow computation of series device flow |
2,310 | def put_text(self, key, text):
with open(key, "w") as fh:
fh.write(text) | Put the text into the storage associated with the key. |
2,311 | def lookup_casstype(casstype):
if isinstance(casstype, (CassandraType, CassandraTypeType)):
return casstype
try:
return parse_casstype_args(casstype)
except (ValueError, AssertionError, IndexError) as e:
raise ValueError("Don't know how to parse type string %r: %s" % (casstype, ... | Given a Cassandra type as a string (possibly including parameters), hand
back the CassandraType class responsible for it. If a name is not
recognized, a custom _UnrecognizedType subclass will be created for it.
Example:
>>> lookup_casstype('org.apache.cassandra.db.marshal.MapType(org.apache.cassan... |
2,312 | def error_values_summary(error_values, **summary_df_kwargs):
df = pf.summary_df_from_multi(error_values, **summary_df_kwargs)
imp_std, imp_std_unc, imp_frac, imp_frac_unc = \
nestcheck.error_analysis.implementation_std(
df.loc[(, )],
df.loc[(, )],
df.loc[(, ... | Get summary statistics about calculation errors, including estimated
implementation errors.
Parameters
----------
error_values: pandas DataFrame
Of format output by run_list_error_values (look at it for more
details).
summary_df_kwargs: dict, optional
See pandas_functions.su... |
2,313 | def formatPathExpressions(seriesList):
pathExpressions = sorted(set([s.pathExpression for s in seriesList]))
return .join(pathExpressions) | Returns a comma-separated list of unique path expressions. |
2,314 | def add(self, item):
if not item.startswith(self.prefix):
item = os.path.join(self.base, item)
self.files.add(os.path.normpath(item)) | Add a file to the manifest.
:param item: The pathname to add. This can be relative to the base. |
2,315 | def get_socket(host, port, timeout=None):
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
af, socktype, proto, canonname, sa = res
sock = None
try:
sock = socket(af, socktype, proto)
if timeout is not None:
sock.settimeout(timeout)
... | Return a socket.
:param str host: the hostname to connect to
:param int port: the port number to connect to
:param timeout: if specified, set the socket timeout |
2,316 | def get_max_id(self, object_type, role):
if object_type == :
objectclass =
ldap_attr =
elif object_type == :
objectclass =
ldap_attr =
else:
raise ldap_tools.exceptions.InvalidResult()
minID, maxID = Client.__set... | Get the highest used ID. |
2,317 | def _replace_numeric_markers(operation, string_parameters):
def replace_markers(marker, op, parameters):
param_count = len(parameters)
marker_index = 0
start_offset = 0
while True:
found_offset = op.find(marker, start_offset)
if not found_offset > -1:
... | Replaces qname, format, and numeric markers in the given operation, from
the string_parameters list.
Raises ProgrammingError on wrong number of parameters or bindings
when using qmark. There is no error checking on numeric parameters. |
2,318 | def infer_year(date):
if isinstance(date, str):
pattern = r
result = re.match(pattern, date)
if result:
return int(result.groupdict()[])
else:
raise ValueError(.format(date))
elif isinstance(date, np.datetime64):
return date.... | Given a datetime-like object or string infer the year.
Parameters
----------
date : datetime-like object or str
Input date
Returns
-------
int
Examples
--------
>>> infer_year('2000')
2000
>>> infer_year('2000-01')
2000
>>> infer_year('2000-01-31')
2000... |
2,319 | def combine(self, expert_out, multiply_by_gates=True):
stitched = common_layers.convert_gradient_to_tensor(
tf.concat(expert_out, 0))
if multiply_by_gates:
stitched *= tf.expand_dims(self._nonzero_gates, 1)
combined = tf.unsorted_segment_sum(stitched, self._batch_index,
... | Sum together the expert output, weighted by the gates.
The slice corresponding to a particular batch element `b` is computed
as the sum over all experts `i` of the expert output, weighted by the
corresponding gate values. If `multiply_by_gates` is set to False, the
gate values are ignored.
Args:
... |
2,320 | def cancel_broadcast(self, broadcast_guid):
subpath = % broadcast_guid
broadcast = {: }
bcast_dict = self._call(subpath, method=, data=broadcast,
content_type=)
return bcast_dict | Cancel a broadcast specified by guid |
2,321 | def get_image(roi_rec, short, max_size, mean, std):
im = imdecode(roi_rec[])
if roi_rec["flipped"]:
im = im[:, ::-1, :]
im, im_scale = resize(im, short, max_size)
height, width = im.shape[:2]
im_info = np.array([height, width, im_scale], dtype=np.float32)
im_tensor = transform(im, m... | read, resize, transform image, return im_tensor, im_info, gt_boxes
roi_rec should have keys: ["image", "boxes", "gt_classes", "flipped"]
0 --- x (width, second dim of im)
|
y (height, first dim of im) |
2,322 | def get_inters(r, L, R_cut):
if r.shape[1] == 2:
_cell_list.cell_list_2d.make_inters(r.T, L, R_cut)
elif r.shape[1] == 3:
_cell_list.cell_list_3d.make_inters(r.T, L, R_cut)
else:
print(
)
return get_inters_direct(r, L, R_cut)
return _parse_inters() | Return points within a given cut-off of each other,
in a periodic system.
Uses a cell-list.
Parameters
----------
r: array, shape (n, d) where d is one of (2, 3).
A set of n point coordinates.
Coordinates are assumed to lie in [-L / 2, L / 2].
L: float.
Bounds of the sy... |
2,323 | def send_message(self, number, content):
outgoing_message = TextMessageProtocolEntity(content.encode("utf-8") if sys.version_info >= (3, 0)
else content, to=self.normalize_jid(number))
self.toLower(outgoing_message)
return outgoing_me... | Send message
:param str number: phone number with cc (country code)
:param str content: body text of the message |
2,324 | def clearLocatorCache(self, login, tableName):
self.send_clearLocatorCache(login, tableName)
self.recv_clearLocatorCache() | Parameters:
- login
- tableName |
2,325 | def _check_token(self):
need_token = (self._token_info is None or
self.auth_handler.is_token_expired(self._token_info))
if need_token:
new_token = \
self.auth_handler.refresh_access_token(
self._token_info[])
... | Simple Mercedes me API. |
2,326 | def setup_exchange(self, exchange_name):
_logger.debug(, exchange_name)
self._channel.exchange_declare(self.on_exchange_declareok,
exchange_name,
self.EXCHANGE_TYPE,
durable=True... | Setup the exchange on RabbitMQ by invoking the Exchange.Declare RPC
command. When it is complete, the on_exchange_declareok method will
be invoked by pika.
:param str|unicode exchange_name: The name of the exchange to declare |
2,327 | def chart_part(self):
rId = self._element.chart_rId
chart_part = self.part.related_parts[rId]
return chart_part | The |ChartPart| object containing the chart in this graphic frame. |
2,328 | def _make_writeable(filename):
import stat
if sys.platform.startswith():
return
if not os.access(filename, os.W_OK):
st = os.stat(filename)
new_permissions = stat.S_IMODE(st.st_mode) | stat.S_IWUSR
os.chmod(filename, new_permissions) | Make sure that the file is writeable. Useful if our source is
read-only. |
2,329 | def _change_color(self, event):
h = self.bar.get()
self.square.set_hue(h)
(r, g, b), (h, s, v), sel_color = self.square.get()
self.red.set(r)
self.green.set(g)
self.blue.set(b)
self.hue.set(h)
self.saturation.set(s)
self.value.set(v)
... | Respond to motion of the hsv cursor. |
2,330 | def p_expression_logical(self, p):
p[0] = Expression(left=p[1], operator=p[2], right=p[3]) | expression : expression logical expression |
2,331 | def coarsen_line(line, level=2, exponential=False, draw=True):
xdata = line.get_xdata()
ydata = line.get_ydata()
xdata,ydata = _fun.coarsen_data(xdata, ydata, level=level, exponential=exponential)
if len(ydata) == 0: print("There's nothing left in "+str(line)+"!")
else: l... | Coarsens the specified line (see spinmob.coarsen_data() for more information).
Parameters
----------
line
Matplotlib line instance.
level=2
How strongly to coarsen.
exponential=False
If True, use the exponential method (great for log-x plots).
draw=True
Redra... |
2,332 | def get_cipher(self):
return self.cipher_class.new(self.cipher_key, self.cipher_class.MODE_CBC, b * self.cipher_class.block_size) | Return a new Cipher object for each time we want to encrypt/decrypt. This is because
pgcrypto expects a zeroed block for IV (initial value), but the IV on the cipher
object is cumulatively updated each time encrypt/decrypt is called. |
2,333 | def read_relative_file(filename, relative_to=None):
if relative_to is None:
relative_to = os.path.dirname(__file__)
with open(os.path.join(os.path.dirname(relative_to), filename)) as f:
return f.read() | Returns contents of the given file, which path is supposed relative
to this package. |
2,334 | def findNestedClassLike(self, lst):
if self.kind == "class" or self.kind == "struct":
lst.append(self)
for c in self.children:
c.findNestedClassLike(lst) | Recursive helper function for finding nested classes and structs. If this node
is a class or struct, it is appended to ``lst``. Each node also calls each of
its child ``findNestedClassLike`` with the same list.
:Parameters:
``lst`` (list)
The list each class or str... |
2,335 | def list_actions(name, location=):
r\\minion-id
with salt.utils.winapi.Com():
task_service = win32com.client.Dispatch("Schedule.Service")
task_service.Connect()
task_folder = task_service.GetFolder(location)
task_definition = task_folder.GetTask(name).Definition
actions = task... | r'''
List all actions that pertain to a task in the specified location.
:param str name: The name of the task for which list actions.
:param str location: A string value representing the location of the task
from which to list actions. Default is '\\' which is the root for the
task schedul... |
2,336 | def frames(self, flush=True):
self.flush()
ret_val, frame = self._sensor.read()
if not ret_val:
raise Exception("Unable to retrieve frame from OpenCVCameraSensor for id {0}".format(self._device_id))
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
if self._upsi... | Returns the latest color image from the stream
Raises:
Exception if opencv sensor gives ret_val of 0 |
2,337 | def get_dependent_items(self, item) -> typing.List:
with self.__dependency_tree_lock:
return copy.copy(self.__dependency_tree_source_to_target_map.get(weakref.ref(item), list())) | Return the list of data items containing data that directly depends on data in this item. |
2,338 | def pad(num, n=2, sign=False):
s = unicode(abs(num))
if len(s) < n:
s = * (n - len(s)) + s
if not sign:
return s
if num >= 0:
return + s
else:
return + s | returns n digit string representation of the num |
2,339 | def _pct_escape_handler(err):
chunk = err.object[err.start:err.end]
replacements = _pct_encoded_replacements(chunk)
return ("".join(replacements), err.end) | Encoding error handler that does percent-escaping of Unicode, to be used
with codecs.register_error
TODO: replace use of this with urllib.parse.quote as appropriate |
2,340 | def clean(self, timeout=60):
self.refresh()
tds = self[]
ftp = self[]
was_disabled_initially = self.disabled
try:
if (not was_disabled_initially and \
self.service.splunk_version < (5,)):
rais... | Deletes the contents of the index.
This method blocks until the index is empty, because it needs to restore
values at the end of the operation.
:param timeout: The time-out period for the operation, in seconds (the
default is 60).
:type timeout: ``integer``
:return... |
2,341 | def set_href_prefix(self, prefix):
self.href_prefix = prefix
for property_ in self.properties.values():
property_.set_href_prefix(prefix)
for action_name in self.actions.keys():
for action in self.actions[action_name]:
action.set_href_prefix(pre... | Set the prefix of any hrefs associated with this thing.
prefix -- the prefix |
2,342 | def get_status_code_and_schema_rst(self, responses):
for status_code, response_schema in responses.items():
status_code = int(status_code)
schema = response_schema.get(, None)
status = HTTP_STATUS_CODES.get(status_code, None)
if status is None or not (100... | Function for prepare information about responses with example, prepare only
responses with status code from `101` to `299`
:param responses: -- dictionary that contains responses, with status code as key
:type responses: dict
:return: |
2,343 | def plot_groups_unplaced(self, fout_dir=".", **kws_usr):
plotobj = PltGroupedGos(self)
return plotobj.plot_groups_unplaced(fout_dir, **kws_usr) | Plot each GO group. |
2,344 | def sampling_volume_value(self):
svi = self.pdx.SamplingVolume
tli = self.pdx.TransmitLength
return self._sampling_volume_value(svi, tli) | Returns the device samping volume value in m. |
2,345 | def set_color_scheme(self, foreground_color, background_color):
self.ansi_handler.set_color_scheme(foreground_color, background_color)
background_color = QColor(background_color)
foreground_color = QColor(foreground_color)
self.set_palette(background=background_color,
... | Set color scheme of the console (foreground and background). |
2,346 | def get_privacy_options(user):
privacy_options = {}
for ptype in user.permissions:
for field in user.permissions[ptype]:
if ptype == "self":
privacy_options["{}-{}".format(field, ptype)] = user.permissions[ptype][field]
else:
privacy_options... | Get a user's privacy options to pass as an initial value to a PrivacyOptionsForm. |
2,347 | def cumulative_detections(dates=None, template_names=None, detections=None,
plot_grouped=False, group_name=None, rate=False,
plot_legend=True, ax=None, **kwargs):
import matplotlib.pyplot as plt
from eqcorrscan.core.match_filter import Detection
... | Plot cumulative detections or detection rate in time.
Simple plotting function to take a list of either datetime objects or
:class:`eqcorrscan.core.match_filter.Detection` objects and plot
a cumulative detections list. Can take dates as a list of lists and will
plot each list separately, e.g. if you h... |
2,348 | def _set_factory_context(factory_class, bundle_context):
try:
context = getattr(factory_class, constants.IPOPO_FACTORY_CONTEXT)
except AttributeError:
return None
if not context.completed:
return None
context.set_bundle_context(bundle_c... | Transforms the context data dictionary into its FactoryContext object form.
:param factory_class: A manipulated class
:param bundle_context: The class bundle context
:return: The factory context, None on error |
2,349 | def remove_task_db(self, fid, force=False):
self.remove_slice_db(fid)
sql =
self.cursor.execute(sql, [fid, ])
self.check_commit(force=force) | 将任务从数据库中删除 |
2,350 | def parse_datetime(value):
if not value:
return None
elif isinstance(value, datetime.datetime):
return value
return dateutil.parser.parse(value) | Attempts to parse `value` into an instance of ``datetime.datetime``. If
`value` is ``None``, this function will return ``None``.
Args:
value: A timestamp. This can be a string or datetime.datetime value. |
2,351 | def total_border_pixels_from_mask_and_edge_pixels(mask, edge_pixels, masked_grid_index_to_pixel):
border_pixel_total = 0
for i in range(edge_pixels.shape[0]):
if check_if_border_pixel(mask, edge_pixels[i], masked_grid_index_to_pixel):
border_pixel_total += 1
return border_pixel_... | Compute the total number of borders-pixels in a masks. |
2,352 | def get_view(self):
view = self.view
if not view.is_initialized:
view.initialize()
if not view.proxy_is_active:
view.activate_proxy()
return view.proxy.widget | Get the root view to display. Make sure it is
properly initialized. |
2,353 | def reset(self):
self.indent_spaces = 0
self._buffer[:] = []
self.source =
self.code = None
self._is_complete = False
self._full_dedent = False | Reset the input buffer and associated state. |
2,354 | def geometry(AA):
if(AA==):
return GlyGeo()
elif(AA==):
return AlaGeo()
elif(AA==):
return SerGeo()
elif(AA==):
return CysGeo()
elif(AA==):
return ValGeo()
elif(AA==):
return IleGeo()
elif(AA==):
return LeuGeo()
elif(AA==):
... | Generates the geometry of the requested amino acid.
The amino acid needs to be specified by its single-letter
code. If an invalid code is specified, the function
returns the geometry of Glycine. |
2,355 | def post_events(self, events):
url = "{0}/{1}/projects/{2}/events".format(self.base_url, self.api_version,
self.project_id)
headers = utilities.headers(self.write_key)
payload = json.dumps(events)
response = self.fulfill(HTTPM... | Posts a single event to the Keen IO API. The write key must be set first.
:param events: an Event to upload |
2,356 | def parse_file(src):
if config.dest_dir == None:
dest = src.dir
else:
dest = config.dest_dir
output = get_output(src)
output_file = dest + + src.basename +
f = open(output_file,)
f.write(jsmin.jsmin(output))
f.close()
print "Wrote combined and minified file to... | find file in config and output to dest dir |
2,357 | def get_logger(name, verbosity, stream):
logger = logging.getLogger(name)
logger.setLevel(
{0: DEFAULT_LOGGING_LEVEL, 1: logging.INFO, 2: logging.DEBUG}.get(min(2, verbosity), DEFAULT_LOGGING_LEVEL)
)
logger.handlers = []
handler = logging.StreamHandler(stream)
handler.setLevel(logg... | Returns simple console logger. |
2,358 | def select_action(self, pos1, pos2, ctrl, shift):
assert pos1.surf.surf_type == pos2.surf.surf_type
assert pos1.surf.world_to_obs == pos2.surf.world_to_obs
action = sc_pb.Action()
action_spatial = pos1.action_spatial(action)
if pos1.world_pos == pos2.world_pos:
select = action_spatial... | Return a `sc_pb.Action` with the selection filled. |
2,359 | def extract_rzip (archive, compression, cmd, verbosity, interactive, outdir):
cmdlist = [cmd, , ]
if verbosity > 1:
cmdlist.append()
outfile = util.get_single_outfile(outdir, archive)
cmdlist.extend(["-o", outfile, archive])
return cmdlist | Extract an RZIP archive. |
2,360 | def combine_assignments(self, assignments):
group_by_fn = collections.defaultdict(list)
for a in assignments:
if not isinstance(a, Assign):
raise ValueError("ops should be instances of mtf.Assign")
group_by_fn[a.assign_fn].append(a)
assignments_set = set(assignments)
self._opera... | Rewrite the current graph to combine "Assign" operations.
Combine similar Assign operations into grouped Assign operations.
This is useful when using the rewrite_stack_variables() optimization,
since variables can only be stacked if they are present in the same set
of Assign operations.
This funct... |
2,361 | def which(name):
for path in path_val.split(os.pathsep):
filename = os.path.join(path, name)
if os.access(filename, os.X_OK):
return filename
return None | Returns the full path to executable in path matching provided name.
`name`
String value.
Returns string or ``None``. |
2,362 | def collectInterest(self):
if self.collectedInterest:
return False
pg = self.usr.getPage("http://www.neopets.com/bank.phtml")
form = pg.form(action="process_bank.phtml")
form[] = "interest"
pg = form.submit()
if... | Collects user's daily interest, returns result
Returns
bool - True if successful, False otherwise |
2,363 | def y(self, y):
if y is None:
return None
return (self.height * (y - self.box.ymin) / self.box.height) | Project reversed y |
2,364 | def _copy_circuit_metadata(source_dag, coupling_map):
target_dag = DAGCircuit()
target_dag.name = source_dag.name
for creg in source_dag.cregs.values():
target_dag.add_creg(creg)
device_qreg = QuantumRegister(len(coupling_map.physical_qubits), )
target_dag.add_qreg(device_qreg)
... | Return a copy of source_dag with metadata but empty.
Generate only a single qreg in the output DAG, matching the size of the
coupling_map. |
2,365 | def extract_output(self, output_variables_list):
variables_mapping = self.session_context.session_variables_mapping
output = {}
for variable in output_variables_list:
if variable not in variables_mapping:
logger.log_warning(
"variable ca... | extract output variables |
2,366 | def _rdistributive(self, expr, op_example):
if expr.isliteral:
return expr
expr_class = expr.__class__
args = (self._rdistributive(arg, op_example) for arg in expr.args)
args = tuple(arg.simplify() for arg in args)
if len(args) == 1:
return args... | Recursively flatten the `expr` expression for the `op_example`
AND or OR operation instance exmaple. |
2,367 | def _do_validate_sources_present(self, target):
if not self.validate_sources_present:
return True
sources = target.sources_relative_to_buildroot()
if not sources:
message = (.format(target.address.spec))
if not self.get_options().allow_empty:
raise TaskError(message)
els... | Checks whether sources is empty, and either raises a TaskError or just returns False.
The specifics of this behavior are defined by whether the user sets --allow-empty to True/False:
--allow-empty=False will result in a TaskError being raised in the event of an empty source
set. If --allow-empty=True, this... |
2,368 | def atmos_worker(srcs, window, ij, args):
src = srcs[0]
rgb = src.read(window=window)
rgb = to_math_type(rgb)
atmos = simple_atmo(rgb, args["atmo"], args["contrast"], args["bias"])
return scale_dtype(atmos, args["out_dtype"]) | A simple atmospheric correction user function. |
2,369 | def extract_links(self, selector=, *args, **kwargs):
try:
links = self.get_tree_tag(selector=selector)
for link in links:
next_url = urljoin(self.url, link.get())
yield type(self)(next_url)
except XPathError:
raise Exception("Invalid %s selector - %s" % (self.__selector_type__, selector))
exce... | Method for performing the link extraction for the crawler. \
The selector passed as the argument is a selector to point to the anchor tags \
that the crawler should pass through. A list of links is obtained, and the links \
are iterated through. The relative paths are converted into absolute paths and \
a ``Xp... |
2,370 | def adupdates_simple(x, g, L, stepsize, inner_stepsizes, niter,
random=False):
length = len(g)
ranges = [Li.range for Li in L]
duals = [space.zero() for space in ranges]
for _ in range(niter):
for i in range(length):
x -= (1.0 / ... | Non-optimized version of ``adupdates``.
This function is intended for debugging. It makes a lot of copies and
performs no error checking. |
2,371 | def get_signalcheck(self, sar, **params):
params = sar
endpoint =
retValue = self._API__request(endpoint, ,
params=params, convJSON=True)
return retValue | get_signalcheck - perform a signal check.
Parameters
----------
sar : dict
signal-api-request specified as a dictionary of parameters.
All of these parameters are optional. For details
check https://api.postcode.nl/documentation/signal-api-example.
... |
2,372 | def remove_bond(self, particle_pair):
from mbuild.port import Port
if self.root.bond_graph is None or not self.root.bond_graph.has_edge(
*particle_pair):
warn("Bond between {} and {} doesnport[$]port[$]') | Deletes a bond between a pair of Particles
Parameters
----------
particle_pair : indexable object, length=2, dtype=mb.Compound
The pair of Particles to remove the bond between |
2,373 | def new_chain(table=, chain=None, table_type=None, hook=None, priority=None, family=):
******
ret = {: ,
: False}
if not chain:
ret[] =
return ret
res = check_table(table, family=family)
if not res[]:
return res
res = check_chain(table, chain, family=family... | .. versionadded:: 2014.7.0
Create new chain to the specified table.
CLI Example:
.. code-block:: bash
salt '*' nftables.new_chain filter input
salt '*' nftables.new_chain filter input \\
table_type=filter hook=input priority=0
salt '*' nftables.new_chain filter ... |
2,374 | def normalize(self):
median_diff = np.median(np.diff(self.x))
bin_edges = [self.x[0] - median_diff/2.0]
bin_edges.extend(median_diff/2.0 + self.x)
self.y_raw = self.y_raw/(self.y_raw.sum()*np.diff(bin_edges))
self.smooth() | Normalizes the given data such that the area under the histogram/curve
comes to 1. Also re applies smoothing once done. |
2,375 | def import_model(cls, ins_name):
try:
package_space = getattr(cls, )
except AttributeError:
raise ValueError()
else:
return import_object(ins_name, package_space) | Import model class in models package |
2,376 | def parse(self, what):
if not in what:
key, spec = what,
else:
key, spec = what.split()
if spec and not spec.startswith((, )):
raise ValueError( % what)
elif spec == :
aids = []
arefs = []
for aid, rec i... | :param what:
can be 'rlz-1/ref-asset1', 'rlz-2/sid-1', ... |
2,377 | def add_to_inventory(self):
if self.lb_attrs:
self.lb_attrs = self.consul.lb_details(
self.lb_attrs[A.loadbalancer.ID]
)
host = self.lb_attrs[][0][]
self.stack.add_lb_secgroup(self.name, [host], self.backend_port)
s... | Adds lb IPs to stack inventory |
2,378 | def has_builder(self):
try:
b = self.builder
except AttributeError:
b = self.builder = None
return b is not None | Return whether this Node has a builder or not.
In Boolean tests, this turns out to be a *lot* more efficient
than simply examining the builder attribute directly ("if
node.builder: ..."). When the builder attribute is examined
directly, it ends up calling __getattr__ for both the __len_... |
2,379 | def sdot( U, V ):
nu = U.ndim
return np.tensordot( U, V, axes=(nu-1,0) ) | Computes the tensorproduct reducing last dimensoin of U with first dimension of V.
For matrices, it is equal to regular matrix product. |
2,380 | def add_fileobj(self, fileobj, path, compress, flags=None):
f = file_iter(fileobj)
flags = flags or os.stat(path) & 0o777
return self.add_stream(f, path, compress, flags) | Add the contents of a file object to the MAR file.
Args:
fileobj (file-like object): open file object
path (str): name of this file in the MAR file
compress (str): One of 'xz', 'bz2', or None. Defaults to None.
flags (int): permission of this file in the MAR file... |
2,381 | def package_data(pkg, root_list):
data = []
for root in root_list:
for dirname, _, files in os.walk(os.path.join(pkg, root)):
for fname in files:
data.append(os.path.relpath(os.path.join(dirname, fname), pkg))
return {pkg: data} | Generic function to find package_data for `pkg` under `root`. |
2,382 | def init_fakemod_dict(fm,adict=None):
dct = {}
dct.setdefault(,lambda : True)
dct.setdefault(,__file__)
if adict is not None:
dct.update(adict)
fm.__dict__.clear()
fm.__dict__.update(dct) | Initialize a FakeModule instance __dict__.
Kept as a standalone function and not a method so the FakeModule API can
remain basically empty.
This should be considered for private IPython use, used in managing
namespaces for %run.
Parameters
----------
fm : FakeModule instance
adict :... |
2,383 | def ensure_index(self, index, mappings=None, settings=None, clear=False):
mappings = mappings or []
if isinstance(mappings, dict):
mappings = [mappings]
exists = self.indices.exists_index(index)
if exists and not mappings and not clear:
return
if ... | Ensure if an index with mapping exists |
2,384 | def add_metrics(self, metrics: Iterable[float]) -> None:
for metric in metrics:
self.add_metric(metric) | Helper to add multiple metrics at once. |
2,385 | def is_deb_package_installed(pkg):
with settings(hide(, , , ),
warn_only=True, capture=True):
result = sudo( % pkg)
return not bool(result.return_code) | checks if a particular deb package is installed |
2,386 | def ellipsis(text, length, symbol="..."):
if len(text) > length:
pos = text.rfind(" ", 0, length)
if pos < 0:
return text[:length].rstrip(".") + symbol
else:
return text[:pos].rstrip(".") + symbol
else:
return text | Present a block of text of given length.
If the length of available text exceeds the requested length, truncate and
intelligently append an ellipsis. |
2,387 | def _syndic_return(self, load):
if any(key not in load for key in (, , )):
return None
if in load:
fstr = .format(self.opts[])
self.mminion.returners[fstr](load[], load[])
for key, item in six.iteritems(load[]):
... | Receive a syndic minion return and format it to look like returns from
individual minions. |
2,388 | def getSequence(title, db=):
titleId = title.split(, 1)[0]
try:
gi = titleId.split()[1]
except IndexError:
client.close()
return record | Get information about a sequence from Genbank.
@param title: A C{str} sequence title from a BLAST hit. Of the form
'gi|63148399|gb|DQ011818.1| Description...'.
@param db: The C{str} name of the Entrez database to consult.
NOTE: this uses the network! Also, there is a 3 requests/second limit
i... |
2,389 | def uptime(human_readable=False):
**
startup_time = datetime.datetime.fromtimestamp(psutil.boot_time())
uptime = datetime.datetime.now() - startup_time
return six.text_type(uptime) if human_readable else uptime.total_seconds() | .. versionadded:: 2015.8.0
Return the system uptime for the machine
Args:
human_readable (bool):
Return uptime in human readable format if ``True``, otherwise
return seconds. Default is ``False``
.. note::
Human readable format is ``days, hours:min... |
2,390 | def p_try_statement_2(self, p):
p[0] = ast.Try(statements=p[2], fin=p[3]) | try_statement : TRY block finally |
2,391 | def get_queryset(self, *args, **kwargs):
select_sql = {}
encrypted_fields = []
for f in self.model._meta.get_fields_with_model():
field = f[0]
if isinstance(field, PGPMixin):
select_sql[field.name] = self.get_decrypt_sql(field).format(
... | Django queryset.extra() is used here to add decryption sql to query. |
2,392 | def is_country(self, text):
ct_list = self._just_cts.keys()
if text in ct_list:
return True
else:
return False | Check if a piece of text is in the list of countries |
2,393 | def invalidate_cache(user, size=None):
sizes = set(settings.AVATAR_AUTO_GENERATE_SIZES)
if size is not None:
sizes.add(size)
for prefix in cached_funcs:
for size in sizes:
cache.delete(get_cache_key(user, size, prefix)) | Function to be called when saving or changing an user's avatars. |
2,394 | def chimera_layout(G, scale=1., center=None, dim=2):
if not isinstance(G, nx.Graph):
empty_graph = nx.Graph()
empty_graph.add_edges_from(G)
G = empty_graph
if G.graph.get("family") == "chimera":
m = G.graph[]
n = G.graph[]
t = G.graph[]
... | Positions the nodes of graph G in a Chimera cross topology.
NumPy (http://scipy.org) is required for this function.
Parameters
----------
G : NetworkX graph
Should be a Chimera graph or a subgraph of a
Chimera graph. If every node in G has a `chimera_index`
attribute, those are... |
2,395 | def process_macros(self, content, source=None):
macro_options = {: self.relative, : self.linenos}
classes = []
for macro_class in self.macros:
try:
macro = macro_class(logger=self.logger, embed=self.embed,
options=macro_options)
... | Processed all macros. |
2,396 | def share_item(self, token, item_id, dest_folder_id):
parameters = dict()
parameters[] = token
parameters[] = item_id
parameters[] = dest_folder_id
response = self.request(, parameters)
return response | Share an item to the destination folder.
:param token: A valid token for the user in question.
:type token: string
:param item_id: The id of the item to be shared.
:type item_id: int | long
:param dest_folder_id: The id of destination folder where the item is
shared ... |
2,397 | def _compute_slices(self, start_idx, end_idx, assets):
return _compute_row_slices(
self._first_rows,
self._last_rows,
self._calendar_offsets,
start_idx,
end_idx,
assets,
) | Compute the raw row indices to load for each asset on a query for the
given dates after applying a shift.
Parameters
----------
start_idx : int
Index of first date for which we want data.
end_idx : int
Index of last date for which we want data.
as... |
2,398 | def build(self, builder):
builder.start("Question", {})
for translation in self.translations:
translation.build(builder)
builder.end("Question") | Build XML by appending to builder
.. note:: Questions can contain translations |
2,399 | def parse_image_response(self, response):
if in response.headers.get():
xml = xmltodict.parse(response.text)
self.analyze_reply_code(xml_response_dict=xml)
multi_parts = self._get_multiparts(response)
parsed = []
for part in multi_... | Parse multiple objects from the RETS feed. A lot of string methods are used to handle the response before
encoding it back into bytes for the object.
:param response: The response from the feed
:return: list of SingleObjectParser |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.