Unnamed: 0 int64 0 389k | code stringlengths 26 79.6k | docstring stringlengths 1 46.9k |
|---|---|---|
386,500 | def Run(self, unused_arg):
logging.debug("Disabling service")
msg = "Service disabled."
if hasattr(sys, "frozen"):
grr_binary = os.path.abspath(sys.executable)
elif __file__:
grr_binary = os.path.abspath(__file__)
try:
os.remove(grr_binary)
except OSError:
msg = "C... | This kills us with no cleanups. |
386,501 | def from_taxtable(cls, taxtable_fp):
r = csv.reader(taxtable_fp)
headers = next(r)
rows = (collections.OrderedDict(list(zip(headers, i))) for i in r)
row = next(rows)
root = cls(rank=row[], tax_id=row[
], name=row[])
path_root = headers.index(... | Generate a node from an open handle to a taxtable, as generated by
``taxit taxtable`` |
386,502 | def vi_return_param(self, index):
if index == 0:
return self.mu0
elif index == 1:
return np.log(self.sigma0) | Wrapper function for selecting appropriate latent variable for variational inference
Parameters
----------
index : int
0 or 1 depending on which latent variable
Returns
----------
The appropriate indexed parameter |
386,503 | def decode_call(self, call):
if call is None:
return None
itokens = call.split(self._callables_separator)
odict = {}
for key, value in self._clut.items():
if value in itokens:
odict[itokens[itokens.index(value)]] = key
ret... | Replace callable tokens with callable names.
:param call: Encoded callable name
:type call: string
:rtype: string |
386,504 | def parse_number_factory(alg, sep, pre_sep):
nan_replace = float("+inf") if alg & ns.NANLAST else float("-inf")
def func(val, _nan_replace=nan_replace, _sep=sep):
return _sep, _nan_replace if val != val else val
if alg & ns.PATH and alg & ns.UNGROUPLETTERS and alg & ns.LOCALEALP... | Create a function that will format a number into a tuple.
Parameters
----------
alg : ns enum
Indicate how to format the *bytes*.
sep : str
The string character to be inserted before the number
in the returned tuple.
pre_sep : str
In the event that *alg* contains ``U... |
386,505 | def add_association_to_graph(self):
Assoc.add_association_to_graph(self)
if self.start_stage_id or self.end_stage_id is not None:
stage_process_id = .join((str(self.start_stage_id),
str(self.end_stage_id)))
stage_proces... | Overrides Association by including bnode support
The reified relationship between a genotype (or any genotype part)
and a phenotype is decorated with some provenance information.
This makes the assumption that
both the genotype and phenotype are classes.
currently hardcoded to... |
386,506 | def tau_reduction(ms, rate, n_per_decade):
ms = np.int64(ms)
keep = np.bool8(np.rint(n_per_decade*np.log10(ms[1:])) -
np.rint(n_per_decade*np.log10(ms[:-1])))
ms = ms[:-1]
assert len(ms) == len(keep)
ms = ms[keep]
taus = ms/float(rate)
return ms, taus | Reduce the number of taus to maximum of n per decade (Helper function)
takes in a tau list and reduces the number of taus to a maximum amount per
decade. This is only useful if more than the "decade" and "octave" but
less than the "all" taus are wanted. E.g. to show certain features of
the data one mig... |
386,507 | def p_reset(self, program):
program[0] = node.Reset([program[2]])
self.verify_reg(program[2], ) | reset : RESET primary |
386,508 | def _update_card_file_location(self, card_name, new_directory):
with tmp_chdir(self.gssha_directory):
file_card = self.project_manager.getCard(card_name)
if file_card:
if file_card.value:
original_location = file_card.value.strip("""{0}"'.form... | Moves card to new gssha working directory |
386,509 | def multiple_packaged_versions(package_name):
dist_files = os.listdir()
versions = set()
for filename in dist_files:
version = funcy.re_find(r.format(package_name), filename)
if version:
versions.add(version)
return len(versions) > 1 | Look through built package directory and see if there are multiple versions there |
386,510 | def write_metadata(self, key, values):
values = Series(values)
self.parent.put(self._get_metadata_path(key), values, format=,
encoding=self.encoding, errors=self.errors,
nan_rep=self.nan_rep) | write out a meta data array to the key as a fixed-format Series
Parameters
----------
key : string
values : ndarray |
386,511 | def create_tables(database):
logging.getLogger(__name__).debug("Creating missing database tables")
database.connect()
database.create_tables([User,
Group,
UserToGroup,
GroupToCapability,
Capa... | Create all tables in the given database |
386,512 | def _run_up(self, path, migration_file, batch, pretend=False):
migration = self._resolve(path, migration_file)
if pretend:
return self._pretend_to_run(migration, )
migration.up()
self._repository.log(migration_file, batch)
self._note( % migration_file) | Run "up" a migration instance.
:type migration_file: str
:type batch: int
:type pretend: bool |
386,513 | def solar(filename_solar, solar_factor):
f0=open(filename_solar)
sol=f0.readlines()
f0.close
sol[0].split(" ")
global names_sol
names_sol=[]
global z_sol
z_sol=[]
yps=np.zeros(len(sol))
mass_number=np.zeros(len(sol))
for i in range(len(sol)):
z_sol... | read solar abundances from filename_solar.
Parameters
----------
filename_solar : string
The file name.
solar_factor : float
The correction factor to apply, in case filename_solar is not
solar, but some file used to get initial abundances at
metallicity lower than solar.... |
386,514 | def show_status(self):
txt =
print(txt)
txt += "start_x = " + str(self.start_x) + "\n"
txt += "start_y = " + str(self.start_y) + "\n"
txt += "target_x = " + str(self.target_x) + "\n"
txt += "target_y = " + str(self.target_y) + "\n"
txt += "current_x = ... | dumps the status of the agent |
386,515 | def bar_amplitude(self):
"返回bar振幅"
res = (self.high - self.low) / self.low
res.name =
return res | 返回bar振幅 |
386,516 | def distance(self, there):
return haversine_distance((self.latitude, self.longitude),
(there.latitude, there.longitude)) | Calculate the distance from this location to there.
Parameters
----------
there : Location
Returns
-------
distance_in_m : float |
386,517 | def login(self, username, password, load=True):
self.auth = Auth(username, password)
if load is True:
self.get_ip()
self.get_servers() | Set the authentication data in the object, and if load is True
(default is True) it also retrieve the ip list and the vm list
in order to build the internal objects list.
@param (str) username: username of the cloud
@param (str) password: password of the cloud
@param (bool) load:... |
386,518 | def drawDisplay(self, painter, option, rect, text):
if self.showRichText():
doc = QtGui.QTextDocument()
doc.setTextWidth(float(rect.width()))
doc.setHtml(text)
painter.translate(rect.x(), rect.y())
... | Overloads the drawDisplay method to render HTML if the rich text \
information is set to true.
:param painter | <QtGui.QPainter>
option | <QtGui.QStyleOptionItem>
rect | <QtCore.QRect>
text | <str> |
386,519 | def _http_response(self, url, method, data=None, content_type=None,
schema=None, **kwargs):
if schema is None:
schema = self.schema_2
header = {
: content_type or ,
: schema,
}
auth = self.auth
token_... | url -> full target url
method -> method from requests
data -> request body
kwargs -> url formatting args |
386,520 | def truncate_volume(self, volume, size):
return self.set_volume(volume, size=size, truncate=True) | Truncate a volume to a new, smaller size.
:param volume: Name of the volume to truncate.
:type volume: str
:param size: Size in bytes, or string representing the size of the
volume to be created.
:type size: int or str
:returns: A dictionary mapping "name" ... |
386,521 | def absorb(self, other):
if not isinstance(other, self.__class__):
raise TypeError("`other` has to be a instance of %s!" %
self.__class__)
for attr, value in other.items():
if value is not None:
setattr(self, attr, deepcopy(va... | For attributes of others that value is not None, assign it to self.
**中文文档**
将另一个文档中的数据更新到本条文档。当且仅当数据值不为None时。 |
386,522 | def _populate_input_for_name_id(self, config, record, context, data):
user_id = ""
user_id_from_attrs = config[]
for attr in user_id_from_attrs:
if attr in record["attributes"]:
value = record["attributes"][attr]
if isinstance(value, list):
... | Use a record found in LDAP to populate input for
NameID generation. |
386,523 | def slang_date(self, locale="en"):
dt = pendulum.instance(self.datetime())
try:
return _translate(dt, locale)
except KeyError:
pass
delta = humanize.time.abs_timedelta(
timedelta(seconds=(self.epoch - now().epoch)))
format_string = ... | Returns human slang representation of date.
Keyword Arguments:
locale -- locale to translate to, e.g. 'fr' for french.
(default: 'en' - English) |
386,524 | def dump(self, obj):
self.references = []
self.object_obj = obj
self.object_stream = BytesIO()
self._writeStreamHeader()
self.writeObject(obj)
return self.object_stream.getvalue() | Dumps the given object in the Java serialization format |
386,525 | def get_object(self, object_ids):
for object_id in object_ids:
if not isinstance(object_id, ObjectID):
raise TypeError(
"Attempting to call `get` on the value {}, "
"which is not an ray.ObjectID.".format(object_id))
... | Get the value or values in the object store associated with the IDs.
Return the values from the local object store for object_ids. This will
block until all the values for object_ids have been written to the
local object store.
Args:
object_ids (List[object_id.ObjectID]): A... |
386,526 | def register_listener(self, address, func):
try:
listeners = self.address_listeners[address]
except KeyError:
listeners = []
self.address_listeners[address] = listeners
if not func in listeners:
listeners.append(func)
return True | Adds a listener to messages received on a specific address
If some KNX messages will be received from the KNX bus, this listener
will be called func(address, data).
There can be multiple listeners for a given address |
386,527 | def share_vm_image(self, vm_image_name, permission):
_validate_not_none(, vm_image_name)
_validate_not_none(, permission)
path = self._get_sharing_path_using_vm_image_name(vm_image_name)
query = + permission
path = path + + query.lstrip()
return self._perform... | Share an already replicated OS image. This operation is only for
publishers. You have to be registered as image publisher with Windows
Azure to be able to call this.
vm_image_name:
The name of the virtual machine image to share
permission:
The sharing permission:... |
386,528 | def get_rank_value(cls, name):
if name in cls._RANK_NAMES.values():
return getattr(cls, name, None)
return None | Returns the integer constant value for the given rank name.
:param string rank: the string rank name (E.g., 'HARDCODED').
:returns: the integer constant value of the rank.
:rtype: int |
386,529 | def datum_to_value(self, instance, datum):
datum = self.map_func(instance, datum)
if datum is None:
return None
local_data = None
if self.reverse is not None:
local_data = {}
if self.reverse is undefined:
local_data[instance.__... | Convert a given MAAS-side datum to a Python-side value.
:param instance: The `Object` instance on which this field is
currently operating. This method should treat it as read-only, for
example to perform validation with regards to other fields.
:param datum: The MAAS-side datum ... |
386,530 | def from_zenity_tuple_str(zenity_tuple_str: str):
components = zenity_tuple_str.strip("rgb()").split(",")
return ColourData(*map(int, components)) | Parser for Zenity output, which outputs a named tuple-like string: "rgb(R, G, B)", where R, G, B are base10
integers.
@param zenity_tuple_str: tuple-like string: "rgb(r, g, b), where r, g, b are base10 integers.
@return: ColourData instance
@rtype: ColourData |
386,531 | def get_config(self, name, default=_MISSING):
val = self._config.get(name, default)
if val is _MISSING:
raise ArgumentError("DeviceAdapter config {} did not exist and no default".format(name))
return val | Get a configuration setting from this DeviceAdapter.
See :meth:`AbstractDeviceAdapter.get_config`. |
386,532 | def _fetchBlock(self):
if self._blockRequestInProgress :
return
if self._standbyBlock is not None:
return
self._blockRequestInProgress = True
fetchReq = TFetchResultsReq(operationHandle=self.operationHandle,
... | internal use only.
get a block of rows from the server and put in standby block.
future enhancements:
(1) locks for multithreaded access (protect from multiple calls)
(2) allow for prefetch by use of separate thread |
386,533 | def protect(self, password=None, read_protect=False, protect_from=0):
args = (password, read_protect, protect_from)
return super(NTAG21x, self).protect(*args) | Set password protection or permanent lock bits.
If the *password* argument is None, all memory pages will be
protected by setting the relevant lock bits (note that lock
bits can not be reset). If valid NDEF management data is
found, protect() also sets the NDEF write flag to read-only.
... |
386,534 | def createNetwork(dataSource):
network = Network()
sensor = createRecordSensor(network, name=_RECORD_SENSOR,
dataSource=dataSource)
createSpatialPooler(network, name=_L1_SPATIAL_POOLER,
inputWidth=sensor.encoder.getWidth())
linkType = "UniformLink"
... | Creates and returns a new Network with a sensor region reading data from
'dataSource'. There are two hierarchical levels, each with one SP and one TM.
@param dataSource - A RecordStream containing the input data
@returns a Network ready to run |
386,535 | def init_app(self, app, sessionstore=None, register_blueprint=False):
return super(InvenioAccountsREST, self).init_app(
app, sessionstore=sessionstore,
register_blueprint=register_blueprint,
) | Flask application initialization.
:param app: The Flask application.
:param sessionstore: store for sessions. Passed to
``flask-kvsession``. If ``None`` then Redis is configured.
(Default: ``None``)
:param register_blueprint: If ``True``, the application registers the
... |
386,536 | def _build_youtube_dl_coprocessor(cls, session: AppSession, proxy_port: int):
wpull.processor.coprocessor.youtubedl.get_version(session.args.youtube_dl_exe)
coprocessor = session.factory.new(
,
session.args.youtube_dl_exe,
(session.args.proxy_serve... | Build youtube-dl coprocessor. |
386,537 | def dedents(self, s, stacklevel=3):
s = dedents(s)
return safe_modulo(s, self.params, stacklevel=stacklevel) | Dedent a string and substitute with the :attr:`params` attribute
Parameters
----------
s: str
string to dedent and insert the sections of the :attr:`params`
attribute
stacklevel: int
The stacklevel for the warning raised in :func:`safe_module` when
... |
386,538 | def remove_event(self, name=None, time=None, chan=None):
self.annot.remove_event(name=name, time=time, chan=chan)
self.update_annotations() | Action: remove single event. |
386,539 | def _permute(self, ordering: np.ndarray) -> None:
for key in self.keys():
self[key] = self[key][ordering] | Permute all the attributes in the collection
Remarks:
This permutes the order of the values for each attribute in the file |
386,540 | def set_volume(self, volume=50):
assert(volume in range(101))
log.debug("setting volume...")
cmd, url = DEVICE_URLS["set_volume"]
json_data = {
"volume": volume,
}
return self._exec(cmd, url, json_data=json_data) | allows to change the volume
:param int volume: volume to be set for the current device
[0..100] (default: 50) |
386,541 | def main():
neutron_config.register_agent_state_opts_helper(CONF)
common_config.init(sys.argv[1:])
neutron_config.setup_logging()
hnv_agent = HNVAgent()
LOG.info("Agent initialized successfully, now running... ")
hnv_agent.daemon_loop() | The entry point for the HNV Agent. |
386,542 | def _parse_response(self, resp):
super(RaxIdentity, self)._parse_response(resp)
user = resp["access"]["user"]
defreg = user.get("RAX-AUTH:defaultRegion")
if defreg:
self._default_region = defreg | Gets the authentication information from the returned JSON. |
386,543 | def prepareToSolve(self):
self.setAndUpdateValues(self.solution_next,self.IncomeDstn,self.LivPrb,self.DiscFac)
self.defBoroCnst(self.BoroCnstArt) | Perform preparatory work before calculating the unconstrained consumption
function.
Parameters
----------
none
Returns
-------
none |
386,544 | def make_grid(self):
changes = None
if isinstance(self.magic_dataframe, cb.MagicDataFrame):
col_labels = list(self.magic_dataframe.df.columns)
for ex_col in self.exclude_cols:
col_labels.pop(ex_col)
if self.grid_type == :... | return grid |
386,545 | def __json(self):
if self.exclude_list is None:
self.exclude_list = []
fields = {}
for key, item in vars(self).items():
if hasattr(self, ):
if len(orm.attributes.instance_state(self).unloaded) > 0:
mapp... | Using the exclude lists, convert fields to a string. |
386,546 | def add_mark_at(string, index, mark):
if index == -1:
return string
return string[:index] + add_mark_char(string[index], mark) + string[index+1:] | Add mark to the index-th character of the given string. Return the new string after applying change.
Notice: index > 0 |
386,547 | def forward(self,
layer_input: torch.Tensor,
layer_output: torch.Tensor,
layer_index: int = None,
total_layers: int = None) -> torch.Tensor:
if layer_index is not None and total_layers is not None:
dropout_prob = 1.0 *... | Apply dropout to this layer, for this whole mini-batch.
dropout_prob = layer_index / total_layers * undecayed_dropout_prob if layer_idx and
total_layers is specified, else it will use the undecayed_dropout_prob directly.
Parameters
----------
layer_input ``torch.FloatTensor`` re... |
386,548 | def disable(gandi, resource, backend, port, probe):
result = []
if backend:
backends = backend
for backend in backends:
if not in backend:
if not port:
backend[] = click.prompt(
... | Disable a backend or a probe on a webaccelerator |
386,549 | def pack_nibbles(nibbles):
if nibbles[-1] == NIBBLE_TERMINATOR:
flags = 2
nibbles = nibbles[:-1]
else:
flags = 0
oddlen = len(nibbles) % 2
flags |= oddlen
if oddlen:
nibbles = [flags] + nibbles
else:
nibbles = [flags, 0] + nibbles
o = b
f... | pack nibbles to binary
:param nibbles: a nibbles sequence. may have a terminator |
386,550 | def add_scope(self, scope_type, scope_name, scope_start, is_method=False):
if self._curr is not None:
self._curr[] = scope_start - 1
self._curr = {
: scope_type, : scope_name,
: scope_start, : scope_start
}
if is_method and self._positions:... | we identified a scope and add it to positions. |
386,551 | def search(cls, session, queries, out_type):
cls._check_implements()
domain = cls.get_search_domain(queries)
return cls(
% cls.__endpoint__,
data={: str(domain)},
session=session,
out_type=out_type,
) | Search for a record given a domain.
Args:
session (requests.sessions.Session): Authenticated session.
queries (helpscout.models.Domain or iter): The queries for the
domain. If a ``Domain`` object is provided, it will simply be
returned. Otherwise, a ``Dom... |
386,552 | def update_function(old, new):
for name in func_attrs:
try:
setattr(old, name, getattr(new, name))
except (AttributeError, TypeError):
pass | Upgrade the code object of a function |
386,553 | def options(cls, obj, options=None, **kwargs):
if (options is None) and kwargs == {}: yield
else:
Store._options_context = True
optstate = cls.state(obj)
groups = Store.options().groups.keys()
options = cls.merge_options(groups, options, **kwargs)... | Context-manager for temporarily setting options on an object
(if options is None, no options will be set) . Once the
context manager exits, both the object and the Store will be
left in exactly the same state they were in before the context
manager was used.
See holoviews.core.o... |
386,554 | def ResolveForCreate(self, document):
if document is None:
raise ValueError("document is None.")
partition_key = self.partition_key_extractor(document)
return self.consistent_hash_ring.GetCollectionNode(partition_key) | Resolves the collection for creating the document based on the partition key.
:param dict document:
The document to be created.
:return:
Collection Self link or Name based link which should handle the Create operation.
:rtype:
str |
386,555 | def clear_scroll(self,
scroll_id = None,
body = ,
params = {},
callback = None,
**kwargs
):
url = self.mk_url(*[, , scroll_id])
self.client.fetch(
self.mk_req(url, method=, body=body, **kwargs),
... | Clear the scroll request created by specifying the scroll parameter to
search.
`<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-scroll.html>`_
:arg scroll_id: The scroll ID or a list of scroll IDs
:arg body: A comma-separated list of scroll IDs to cl... |
386,556 | def hasDependencyRecursively(self, name, target=None, test_dependencies=False):
dependencies = self.getDependenciesRecursive(
target = target,
test = test_dependencies
)
return (name in dependencies) | Check if this module, or any of its dependencies, have a
dependencies with the specified name in their dependencies, or in
their targetDependencies corresponding to the specified target.
Note that if recursive dependencies are not installed, this test
may return a false-... |
386,557 | def doc_stream(path):
with open(path, ) as f:
for line in f:
if line.strip():
yield line | Generator to feed tokenized documents (treating each line as a document). |
386,558 | def create_module(name, path):
module = imp.new_module(name)
module.__file__ = path
execfile(path, module.__dict__)
return module | Returns module created *on the fly*. Returned module would have name same
as given ``name`` and would contain code read from file at the given
``path`` (it may also be a zip or package containing *__main__* module). |
386,559 | def single(self):
records = list(self)
size = len(records)
if size == 0:
return None
if size != 1:
warn("Expected a result with a single record, but this result contains %d" % size)
return records[0] | Obtain the next and only remaining record from this result.
A warning is generated if more than one record is available but
the first of these is still returned.
:returns: the next :class:`.Record` or :const:`None` if none remain
:warns: if more than one record is available |
386,560 | def fromFile(cls, filename):
self = cls.__new__(cls)
start = _time()
savedData = _loads(_open(filename, "r").read())
self.string, self.unit, self.voc, self.vocSize, self.SA, features = savedData[:6]
self.length = len(self.SA)
if self.unit ... | Load a suffix array instance from filename, a file created by
toFile.
Accept any filename following the _open conventions. |
386,561 | def format_interface_name(intf_type, port, ch_grp=0):
if ch_grp > 0:
return % str(ch_grp)
return % (intf_type.lower(), port) | Method to format interface name given type, port.
Given interface type, port, and channel-group, this
method formats an interface name. If channel-group is
non-zero, then port-channel is configured.
:param intf_type: Such as 'ethernet' or 'port-channel'
:param port: unique identification -- 1/32 ... |
386,562 | def as_completed(fs, timeout=None):
with _AcquireFutures(fs):
finished = set(f for f in fs if f._state in [CANCELLED_AND_NOTIFIED, FINISHED])
pending = set(fs) - finished
waiter = _create_and_install_waiters(fs, _AS_COMPLETED)
timer = Timeout(timeout)
timer.start()
try:
... | An iterator over the given futures that yields each as it completes.
Args:
fs: The sequence of Futures (possibly created by different Executors) to
iterate over.
timeout: The maximum number of seconds to wait. If None, then there
is no limit on the wait time.
Returns:
... |
386,563 | def build_docs(directory):
os.chdir(directory)
process = subprocess.Popen(["make", "html"], cwd=directory)
process.communicate() | Builds sphinx docs from a given directory. |
386,564 | def past_date(start=):
return lambda n, f: f.past_date(
start_date=start, tzinfo=get_timezone(),
) | Returns a ``date`` object in the past between 1 day ago and the
specified ``start``. ``start`` can be a string, another date, or a
timedelta. If it's a string, it must start with `-`, followed by and integer
and a unit, Eg: ``'-30d'``. Defaults to `'-30d'`
Valid units are:
* ``'years'``, ``'y'``
... |
386,565 | def handle_cannot(reference_answers: List[str]):
num_cannot = 0
num_spans = 0
for ref in reference_answers:
if ref == :
num_cannot += 1
else:
num_spans += 1
if num_cannot >= num_spans:
reference_answers = []
else:
reference_answers = [x fo... | Process a list of reference answers.
If equal or more than half of the reference answers are "CANNOTANSWER", take it as gold.
Otherwise, return answers that are not "CANNOTANSWER". |
386,566 | def read(self, offset, length, min_length=0, unbuffered=False, wait=True,
send=True):
if length > self.connection.max_read_size:
raise SMBException("The requested read length %d is greater than "
"the maximum negotiated read size %d"
... | Reads from an opened file or pipe
Supports out of band send function, call this function with send=False
to return a tuple of (SMB2ReadRequest, receive_func) instead of
sending the the request and waiting for the response. The receive_func
can be used to get the response from the server... |
386,567 | def download_url(url, destination):
from settings import VALID_IMAGE_EXTENSIONS
base_name, ext = os.path.splitext(url)
ext = ext.lstrip()
if ext not in VALID_IMAGE_EXTENSIONS:
raise Exception("Invalid image extension")
base_path, filename = os.path.split(destination)
os.makedirs(b... | Download an external URL to the destination |
386,568 | def qtaax(mt, x, t, q, m=1):
q = float(q)
j = (mt.i - q) / (1 + q)
mtj = Actuarial(nt=mt.nt, i=j)
return taax(mtj, x, t) - ((float(m - 1) / float(m * 2)) * (1 - nEx(mt, x, t))) | geometrica |
386,569 | def property(func):
attr = abc.abstractmethod(func)
attr.__iproperty__ = True
attr = Property(attr)
return attr | Wrap a function as a property.
This differs from attribute by identifying properties explicitly listed
in the class definition rather than named attributes defined on instances
of a class at init time. |
386,570 | def alias_tags(tags_list, alias_map):
def _alias_dict(tags):
tags_ = [alias_map.get(t, t) for t in tags]
return list(set([t for t in tags_ if t is not None]))
tags_list_ = [_alias_dict(tags) for tags in tags_list]
return tags_list_ | update tags to new values
Args:
tags_list (list):
alias_map (list): list of 2-tuples with regex, value
Returns:
list: updated tags
CommandLine:
python -m utool.util_tags alias_tags --show
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_tags import *... |
386,571 | def read_git_branch():
if os.getenv():
return os.getenv()
else:
try:
repo = git.repo.base.Repo(search_parent_directories=True)
return repo.active_branch.name
except Exception:
return | Obtain the current branch name from the Git repository. If on Travis CI,
use the ``TRAVIS_BRANCH`` environment variable. |
386,572 | def load_config():
cfg_path =
cfg_file =
if not os.path.isdir(cfg_path):
print("Can not find default freelan config directory.")
return
cfg_file_path = os.path.join(cfg_path,cfg_file)
if not os.path.isfile( cfg_file_path ):
print("Can not find default freelan config... | try loading config file from a default directory |
386,573 | def start_of_chunk(prev_tag, tag, prev_type, type_):
chunk_start = False
if tag == : chunk_start = True
if tag == : chunk_start = True
if prev_tag == and tag == : chunk_start = True
if prev_tag == and tag == : chunk_start = True
if prev_tag == and tag == : chunk_start = True
if pre... | Checks if a chunk started between the previous and current word.
Args:
prev_tag: previous chunk tag.
tag: current chunk tag.
prev_type: previous type.
type_: current type.
Returns:
chunk_start: boolean. |
386,574 | def get_float(prompt=None):
while True:
s = get_string(prompt)
if s is None:
return None
if len(s) > 0 and re.search(r"^[+-]?\d*(?:\.\d*)?$", s):
try:
return float(s)
except ValueError:
pass
if prompt ... | Read a line of text from standard input and return the equivalent float
as precisely as possible; if text does not represent a double, user is
prompted to retry. If line can't be read, return None. |
386,575 | def reset(self):
self.activeCells = []
self.winnerCells = []
self.activeSegments = []
self.matchingSegments = [] | Indicates the start of a new sequence. Clears any predictions and makes sure
synapses don't grow to the currently active cells in the next time step. |
386,576 | def MessageSetItemSizer(field_number):
static_size = (_TagSize(1) * 2 + _TagSize(2) + _VarintSize(field_number) +
_TagSize(3))
local_VarintSize = _VarintSize
def FieldSize(value):
l = value.ByteSize()
return static_size + local_VarintSize(l) + l
return FieldSize | Returns a sizer for extensions of MessageSet.
The message set message looks like this:
message MessageSet {
repeated group Item = 1 {
required int32 type_id = 2;
required string message = 3;
}
} |
386,577 | def _maybe_cast_to_float64(da):
if da.dtype == np.float32:
logging.warning(
)
return da.astype(np.float64)
else:
return da | Cast DataArrays to np.float64 if they are of type np.float32.
Parameters
----------
da : xr.DataArray
Input DataArray
Returns
-------
DataArray |
386,578 | def save_profile(self, **params):
image = self.get_image()
if (image is None):
return
profile = image.get(, None)
if profile is None:
profile = Settings.SettingGroup()
image.set(profile=profile)
self.logger.debug("saving... | Save the given parameters into profile settings.
Parameters
----------
params : dict
Keywords and values to be saved. |
386,579 | def _count_elements(mapping, iterable):
mapping_get = mapping.get
for elem in iterable:
mapping[elem] = mapping_get(elem, 0) + 1 | Tally elements from the iterable. |
386,580 | def get_acl(self, key_name=, headers=None, version_id=None):
return self.get_acl_helper(key_name, headers, STANDARD_ACL) | returns a bucket's acl. We include a version_id argument
to support a polymorphic interface for callers, however,
version_id is not relevant for Google Cloud Storage buckets
and is therefore ignored here. |
386,581 | def waitget(self,key, maxwaittime = 60 ):
wtimes = [0.2] * 3 + [0.5] * 2 + [1]
tries = 0
waited = 0
while 1:
try:
val = self[key]
return val
except KeyError:
pass
if waited > maxwaittime:
... | Wait (poll) for a key to get a value
Will wait for `maxwaittime` seconds before raising a KeyError.
The call exits normally if the `key` field in db gets a value
within the timeout period.
Use this for synchronizing different processes or for ensuring
that an unfortunately time... |
386,582 | def from_xdr_object(cls, asset_xdr_object):
if asset_xdr_object.type == Xdr.const.ASSET_TYPE_NATIVE:
return Asset.native()
elif asset_xdr_object.type == Xdr.const.ASSET_TYPE_CREDIT_ALPHANUM4:
issuer = encode_check(
, asset_xdr_object.alphaNum4.issuer.ed25... | Create a :class:`Asset` from an XDR Asset object.
:param asset_xdr_object: The XDR Asset object.
:return: A new :class:`Asset` object from the given XDR Asset object. |
386,583 | def _create_namespace(namespace, apiserver_url):
url = "{0}/api/v1/namespaces".format(apiserver_url)
data = {
"kind": "Namespace",
"apiVersion": "v1",
"metadata": {
"name": namespace,
}
}
log.trace("namespace creation requests: %s", data)
... | create namespace on the defined k8s cluster |
386,584 | def pretty_unicode(string):
if isinstance(string, six.text_type):
return string
try:
return string.decode("utf8")
except UnicodeDecodeError:
return string.decode().encode().decode("utf8") | Make sure string is unicode, try to decode with utf8, or unicode escaped string if failed. |
386,585 | def _num_values(self, zVar, varNum):
values = 1
if (zVar == True):
numDims = self.zvarsinfo[varNum][2]
dimSizes = self.zvarsinfo[varNum][3]
dimVary = self.zvarsinfo[varNum][4]
else:
numDims = self.rvarsinfo[varNum][2]
dimSizes ... | Determines the number of values in a record.
Set zVar=True if this is a zvariable. |
386,586 | def eval_basis(self, x, regularize=True):
if regularize:
x = regularize_array(x)
out = zeros((self.n, x.shape[0]), dtype=float, order=)
for i in xrange(self.n):
out[i] = self.basis[i](x, **self.params)
return out | basis_mat = C.eval_basis(x)
Evaluates self's basis functions on x and returns them stacked
in a matrix. basis_mat[i,j] gives basis function i evaluated at
x[j,:]. |
386,587 | def setup_package():
setup(
name=,
version=_get_version(),
description=,
long_description=_get_long_description(),
long_description_content_type=,
url=,
author=,
author_email=,
license=,
classifiers=[
... | Package setup |
386,588 | def sr1(x, promisc=None, filter=None, iface=None, nofilter=0, *args, **kargs):
s = conf.L3socket(promisc=promisc, filter=filter,
nofilter=nofilter, iface=iface)
ans, _ = sndrcv(s, x, *args, **kargs)
s.close()
if len(ans) > 0:
return ans[0][1]
else:
return N... | Send packets at layer 3 and return only the first answer |
386,589 | def apply(self, config, raise_on_unknown_key=True):
_recursive_merge(self._data, config, raise_on_unknown_key) | Apply additional configuration from a dictionary
This will look for dictionary items that exist in the base_config any apply their values on the current
configuration object |
386,590 | def edgepaths(self):
edgepaths = super(TriMesh, self).edgepaths
edgepaths.crs = self.crs
return edgepaths | Returns the fixed EdgePaths or computes direct connections
between supplied nodes. |
386,591 | def make_repr(*args, **kwargs):
def method(self):
cls_name = self.__class__.__name__
if args:
field_names = args
else:
def undercored(name): return name.startswith()
def is_method(name): return callable(getattr(self, name))
def good_na... | Returns __repr__ method which returns ASCII
representaion of the object with given fields.
Without arguments, ``make_repr`` generates a method
which outputs all object's non-protected (non-undercored)
arguments which are not callables.
Accepts ``*args``, which should be a names of object's
att... |
386,592 | def _filter_valid_arguments(self, arguments, binary="mongod",
config=False):
if self.args and self.args[]:
binary = os.path.join(self.args[], binary)
ret = (subprocess.Popen([ % binary, ],
stderr=subprocess.STDOUT, stdout=subpr... | Return a list of accepted arguments.
Check which arguments in list are accepted by the specified binary
(mongod, mongos). If an argument does not start with '-' but its
preceding argument was accepted, then it is accepted as well. Example
['--slowms', '1000'] both arguments would be acc... |
386,593 | def _notify_new_tick_event(self, tick):
if tick.time is :
return
event = Event(type_=EVENT_TINY_TICK)
event.dict_[] = tick
self._event_engine.put(event) | tick推送 |
386,594 | def _flush_data(self):
if self._data and self._data.modified:
hookenv.relation_set(self.relation_id, dict(self.to_publish.data)) | If this relation's local unit data has been modified, publish it on the
relation. This should be automatically called. |
386,595 | def accept(self):
result = dict(self.python_data)
for field in self.fields:
if field.writable:
result.update(field.accept())
else:
field.set_raw_value(self.form.raw_data,
field.from_pyth... | Accepts all children fields, collects resulting values into dict and
passes that dict to converter.
Returns result of converter as separate value in parent `python_data` |
386,596 | def edit_wiki_page(self, subreddit, page, content, reason=):
data = {: content,
: page,
: six.text_type(subreddit),
: reason}
evict = self.config[].format(
subreddit=six.text_type(subreddit), page=page.lower())
self.evict(evict... | Create or edit a wiki page with title `page` for `subreddit`.
:returns: The json response from the server. |
386,597 | def get_span_column_count(span):
columns = 1
first_column = span[0][1]
for i in range(len(span)):
if span[i][1] > first_column:
columns += 1
first_column = span[i][1]
return columns | Find the length of a colspan.
Parameters
----------
span : list of lists of int
The [row, column] pairs that make up the span
Returns
-------
columns : int
The number of columns included in the span
Example
-------
Consider this table::
+------+-----------... |
386,598 | def verify(expr, params=None):
try:
compile(expr, params=params)
return True
except com.TranslationError:
return False | Determine if expression can be successfully translated to execute on
MapD |
386,599 | def flavor_list_paged(request, is_public=True, get_extras=False, marker=None,
paginate=False, sort_key="name", sort_dir="desc",
reversed_order=False):
has_more_data = False
has_prev_data = False
if paginate:
if reversed_order:
sort_dir = ... | Get the list of available instance sizes (flavors). |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.