Unnamed: 0 int64 0 389k | code stringlengths 26 79.6k | docstring stringlengths 1 46.9k |
|---|---|---|
17,900 | def calculate_size(name, id):
data_size = 0
data_size += calculate_size_str(name)
data_size += calculate_size_str(id)
return data_size | Calculates the request payload size |
17,901 | def clear_list_value(self, value):
if not value:
return self.empty_value
if self.clean_empty:
value = [v for v in value if v]
return value or self.empty_value | Clean the argument value to eliminate None or Falsy values if needed. |
17,902 | def _evaluate(self,*args,**kwargs):
if len(args) == 5:
R,vR,vT, z, vz= args
elif len(args) == 6:
R,vR,vT, z, vz, phi= args
else:
self._parse_eval_args(*args)
R= self._eval_R
vR= self._eval_vR
vT= self._eval_vT
... | NAME:
__call__ (_evaluate)
PURPOSE:
evaluate the actions (jr,lz,jz)
INPUT:
Either:
a) R,vR,vT,z,vz[,phi]:
1) floats: phase-space value for single object (phi is optional) (each can be a Quantity)
2) numpy.ndarray: [N] phase... |
17,903 | def post(method, hmc, uri, uri_parms, body, logon_required,
wait_for_completion):
assert wait_for_completion is True
partition_oid = uri_parms[0]
partition_uri = + partition_oid
try:
partition = hmc.lookup_by_uri(partition_uri)
except KeyError... | Operation: Mount ISO Image (requires DPM mode). |
17,904 | def kill_zombies(self, zombies, session=None):
from airflow.models.taskinstance import TaskInstance
for zombie in zombies:
if zombie.dag_id in self.dags:
dag = self.dags[zombie.dag_id]
if zombie.task_id in dag.task_ids:
task = d... | Fail given zombie tasks, which are tasks that haven't
had a heartbeat for too long, in the current DagBag.
:param zombies: zombie task instances to kill.
:type zombies: airflow.utils.dag_processing.SimpleTaskInstance
:param session: DB session.
:type session: sqlalchemy.orm.sess... |
17,905 | def iri_to_uri(value, normalize=False):
if not isinstance(value, str_cls):
raise TypeError(unwrap(
,
type_name(value)
))
scheme = None
if sys.version_info < (2, 7) and not value.startswith() and not value.startswith():
real_prefix = None
pr... | Encodes a unicode IRI into an ASCII byte string URI
:param value:
A unicode string of an IRI
:param normalize:
A bool that controls URI normalization
:return:
A byte string of the ASCII-encoded URI |
17,906 | def get_directories_re(
self,
directory_re,
full_path=False,
ignorecase=False):
if ignorecase:
compiled_re = re.compile(directory_re, re.I)
else:
compiled_re = re.compile(directory_re)
found = set()
if sel... | Same as get_files_re, but for directories |
17,907 | def reset(self):
animation_gen = self._frame_function(*self._animation_args,
**self._animation_kwargs)
self._current_generator = itertools.cycle(
util.concatechain(animation_gen, self._back_up_generator)) | Reset the current animation generator. |
17,908 | def main():
parser = optparse.OptionParser()
parser.add_option(
, , help=, metavar=)
parser.add_option(
, , help=, metavar=)
parser.add_option(
, , help=, metavar=)
parser.add_option(
, , help=, metavar=)
options, _ = parser.parse_args()
myrc = pypirc.P... | Main loop. |
17,909 | def monthdayscalendar(cls, year, month):
weeks = []
week = []
for day in NepCal.itermonthdays(year, month):
week.append(day)
if len(week) == 7:
weeks.append(week)
week = []
if len(week) > 0:
weeks.append(week)
... | Return a list of the weeks in the month month of the year as full weeks.
Weeks are lists of seven day numbers. |
17,910 | def abort_io(self, iocb, err):
if _debug: IOChainMixIn._debug("abort_io %r %r", iocb, err)
if iocb is not self.ioChain:
raise RuntimeError("broken chain")
self.abort(err) | Forward the abort downstream. |
17,911 | def list_resource_record_sets(self, max_results=None, page_token=None, client=None):
client = self._require_client(client)
path = "/projects/%s/managedZones/%s/rrsets" % (self.project, self.name)
iterator = page_iterator.HTTPIterator(
client=client,
api_request=c... | List resource record sets for this zone.
See
https://cloud.google.com/dns/api/v1/resourceRecordSets/list
:type max_results: int
:param max_results: Optional. The maximum number of resource record
sets to return. Defaults to a sensible value
... |
17,912 | def _check_ipcidr_minions(self, expr, greedy):
cache_enabled = self.opts.get(, False)
if greedy:
minions = self._pki_minions()
elif cache_enabled:
minions = self.cache.list()
else:
return {: [],
: []}
if cache_ena... | Return the minions found by looking via ipcidr |
17,913 | def get_section_metrics(cls):
return {
"overview": {
"activity_metrics": [Closed, Submitted],
"author_metrics": None,
"bmi_metrics": [BMI],
"time_to_close_metrics": [DaysToMergeMedian],
"projects_metrics": [Pro... | Get the mapping between metrics and sections in Manuscripts report
:return: a dict with the mapping between metrics and sections in Manuscripts report |
17,914 | def get_device(self):
addr = self.address
servers = [server for server in pyrax.cloudservers.list()
if addr in server.networks.get("private", "")]
try:
return servers[0]
except IndexError:
return None | Returns a reference to the device that is represented by this node.
Returns None if no such device can be determined. |
17,915 | def get_impala_queries(self, start_time, end_time, filter_str="", limit=100,
offset=0):
params = {
: start_time.isoformat(),
: end_time.isoformat(),
: filter_str,
: limit,
: offset,
}
return self._get("impalaQueries", ApiImpalaQueryResponse,
params=para... | Returns a list of queries that satisfy the filter
@type start_time: datetime.datetime. Note that the datetime must either be
time zone aware or specified in the server time zone. See
the python datetime documentation for more details about
python's ... |
17,916 | def post(self, request, key):
try:
hook = Hook.objects.get(key=key, enabled=True)
except Hook.DoesNotExist:
msg = _("Key %s not associated to an enabled hook or bot") % key
logger.warning(msg)
return Response(msg, status=status.HTTP_404_NOT_FOUND)... | Process notitication hooks:
1. Obtain Hook
2. Check Auth
3. Delay processing to a task
4. Respond requester |
17,917 | def bind(self, **config):
while self.unbound_types:
typedef = self.unbound_types.pop()
try:
load, dump = typedef.bind(self, **config)
self.bound_types[typedef] = {
"load": load, "dump": dump
}
except... | Bind all unbound types to the engine.
Bind each unbound typedef to the engine, passing in the engine and
:attr:`config`. The resulting ``load`` and ``dump`` functions can
be found under ``self.bound_types[typedef]["load"]`` and
``self.bound_types[typedef]["dump"], respectively.
... |
17,918 | def delete(self, primary_key):
title = % self.__class__.__name__
delete_statement = self.table.delete(self.table.c.id==primary_key)
self.session.execute(delete_statement)
exit_msg = % primary_key
return exit_msg | a method to delete a record in the table
:param primary_key: string with primary key of record
:return: string with status message |
17,919 | def copy_ssh_keys_to_hosts(self, hosts, known_hosts=DEFAULT_KNOWN_HOSTS, dry=False):
exceptions = []
for host in hosts:
logger.info(, host.hostname, self.sshcopyid.pub_key)
if not dry:
try:
self.copy_ssh_keys_to_host(host, known_host... | Copy the SSH keys to the given hosts.
:param hosts: the list of `Host` objects to copy the SSH keys to.
:param known_hosts: the `known_hosts` file to store the SSH public keys.
:param dry: perform a dry run.
:raise msshcopyid.errors.CopySSHKeysError: |
17,920 | def alterar(self, id_user_group, name, read, write, edit, remove):
if not is_valid_int_param(id_user_group):
raise InvalidParameterError(
u)
url = + str(id_user_group) +
ugroup_map = dict()
ugroup_map[] = name
ugroup_map[] = read
u... | Edit user group data from its identifier.
:param id_user_group: User group id.
:param name: User group name.
:param read: If user group has read permission ('S' ou 'N').
:param write: If user group has write permission ('S' ou 'N').
:param edit: If user group has edit permission... |
17,921 | def exit_success(jid, ext_source=None):
ret = dict()
data = list_job(
jid,
ext_source=ext_source
)
minions = data.get(, [])
result = data.get(, {})
for minion in minions:
if minion in result and in result[minion]:
ret[minion] = True if result[minion][... | Check if a job has been executed and exit successfully
jid
The jid to look up.
ext_source
The external job cache to use. Default: `None`.
CLI Example:
.. code-block:: bash
salt-run jobs.exit_success 20160520145827701627 |
17,922 | def list_nodes_full(**kwargs):
nodes = _query()
ret = {}
for node in nodes:
name = nodes[node][]
ret[name] = nodes[node].copy()
ret[name][] = node
ret[name][] = nodes[node][]
ret[name][] = nodes[node][]
ret[name][] = nodes[node][]
ret[name][] = n... | Return all data on nodes |
17,923 | def gen_sponsor_schedule(user, sponsor=None, num_blocks=6, surrounding_blocks=None, given_date=None):
r
no_attendance_today = None
acts = []
if sponsor is None:
sponsor = user.get_eighth_sponsor()
if surrounding_blocks is None:
surrounding_blocks = EighthBlock.objects.get_upcoming... | r"""Return a list of :class:`EighthScheduledActivity`\s in which the
given user is sponsoring.
Returns:
Dictionary with:
activities
no_attendance_today
num_acts |
17,924 | def get_localhost():
t work
properly and takes a lot of time (had this issue on the pyunit server).
Using the IP directly solves the problem.
127.0.0.1127.0.0.1t have getaddrinfo or SOL_TCP... Just consider it 127.0.0.1 in this case.
_cache =
else:
_cache =
return... | Should return 127.0.0.1 in ipv4 and ::1 in ipv6
localhost is not used because on windows vista/windows 7, there can be issues where the resolving doesn't work
properly and takes a lot of time (had this issue on the pyunit server).
Using the IP directly solves the problem. |
17,925 | def _table_sort_by(table, sort_exprs):
result = table.op().sort_by(table, sort_exprs)
return result.to_expr() | Sort table by the indicated column expressions and sort orders
(ascending/descending)
Parameters
----------
sort_exprs : sorting expressions
Must be one of:
- Column name or expression
- Sort key, e.g. desc(col)
- (column name, True (ascending) / False (descending))
E... |
17,926 | def set_language(self):
try:
self.language = self.soup.find().string
except AttributeError:
self.language = None | Parses feed language and set value |
17,927 | def output_results(results, mvdelim = , output = sys.stdout):
fields = set()
for result in results:
for key in result.keys():
if(isinstance(result[key], list)):
result[ + key] = encode_mv(result[key])
result[key] = mvdelim.join(result[key])... | Given a list of dictionaries, each representing
a single result, and an optional list of fields,
output those results to stdout for consumption by the
Splunk pipeline |
17,928 | def dump(
state, host,
remote_filename, database=None,
postgresql_user=None, postgresql_password=None,
postgresql_host=None, postgresql_port=None,
):
yield .format(make_psql_command(
executable=,
database=database,
user=postgresql_user,
password=postgresql_... | Dump a PostgreSQL database into a ``.sql`` file. Requires ``mysqldump``.
+ database: name of the database to dump
+ remote_filename: name of the file to dump the SQL to
+ postgresql_*: global module arguments, see above |
17,929 | def clean(self: , *, atol: float=1e-9) -> :
negligible = [v for v, c in self._terms.items() if abs(c) <= atol]
for v in negligible:
del self._terms[v]
return self | Remove terms with coefficients of absolute value atol or less. |
17,930 | def safe_filename(self, otype, oid):
permitted = set([, , , ])
oid = .join([c for c in oid if c.isalnum() or c in permitted])
while oid.find() != -1:
oid = oid.replace(, )
ext =
ts = datetime.now().strftime("%Y%m%dT%H%M%S")
fname =
is_new = ... | Santize obj name into fname and verify doesn't already exist |
17,931 | def _resetID(self):
self._setID((None,) * len(self._sqlPrimary))
self._new = True | Reset all ID fields. |
17,932 | def load_from_cache(path=user_path):
if not path:
return
try:
with open(path, ) as f:
dversion, mversion, data = pickle.load(f)
if dversion == data_version and mversion == module_version:
return data
except (FileNotFoundError, ValueError, EOFError):
... | Try to load category ranges from userlevel cache file.
:param path: path to userlevel cache file
:type path: str
:returns: category ranges dict or None
:rtype: None or dict of RangeGroup |
17,933 | def evaluate(self, sequence, transformations):
result = sequence
parallel = partial(
parallelize, processes=self.processes, partition_size=self.partition_size)
staged = []
for transform in transformations:
strategies = transform.execution_strategies or {}... | Execute the sequence of transformations in parallel
:param sequence: Sequence to evaluation
:param transformations: Transformations to apply
:return: Resulting sequence or value |
17,934 | def support_jsonp(api_instance, callback_name_source=):
output_json = api_instance.representations[]
@api_instance.representation()
def handle_jsonp(data, code, headers=None):
resp = output_json(data, code, headers)
if code == 200:
callback = request.args.get(callback_name... | Let API instance can respond jsonp request automatically.
`callback_name_source` can be a string or a callback.
If it is a string, the system will find the argument that named by this string in `query string`.
If found, determine this request to be a jsonp request, and use the argument's value as ... |
17,935 | def text(self):
if callable(self._text):
return str(self._text())
return str(self._text) | Return the string to render. |
17,936 | def get_processes(self):
procs = set()
try:
p = sp.Popen([, , , ], stdout=sp.PIPE)
output, error = p.communicate()
if sys.version_info > (3, 0):
output = output.decode()
for comm in output.split():
... | Grab a shuffled list of all currently running process names |
17,937 | def decode(self, encoded):
encoded = super().decode(encoded)
if encoded.numel() > 1:
raise ValueError(
)
return self.itos[encoded.squeeze().item()] | Decodes ``encoded`` label.
Args:
encoded (torch.Tensor): Encoded label.
Returns:
object: Label decoded from ``encoded``. |
17,938 | def _validate(self, all_valid_addresses):
for dependency, dependents in iteritems(self._dependent_address_map):
if dependency not in all_valid_addresses:
raise AddressLookupError(
.format(
dependency.spec,
.join(d.spec for d in dependents)
)
... | Validate that all of the dependencies in the graph exist in the given addresses set. |
17,939 | def plot_gos(fout_png, goids, obo_dag, *args, **kws):
engine = kws[] if in kws else
godagsmall = OboToGoDagSmall(goids=goids, obodag=obo_dag).godag
godagplot = GODagSmallPlot(godagsmall, *args, **kws)
godagplot.plt(fout_png, engine) | Given GO ids and the obo_dag, create a plot of paths from GO ids. |
17,940 | def format_header_cell(val):
return re.sub(, , re.sub(r, , re.sub(r, , str(val) ))) | Formats given header column. This involves changing '_Px_' to '(', '_xP_' to ')' and
all other '_' to spaces. |
17,941 | def get_stops(records, group_dist):
def traverse(start, next):
position_prev = records[next - 1].position.location
position_next = records[next].position.location
dist = 1000 * great_circle_distance(position_prev, position_next)
return dist <= group_dist
groups = _groupwhil... | Group records arounds stop locations and returns a list of
dict(location, records) for each stop.
Parameters
----------
records : list
A list of Record objects ordered by non-decreasing datetime
group_dist : float
Minimum distance (in meters) to switch to a new stop. |
17,942 | def round(self, multiple=1):
if not isinstance(multiple, int):
raise TypeError("The round multiple must be an int not %s."
% multiple.__class__.__name__)
self._round(multiple) | Rounds the kerning values to increments of **multiple**,
which will be an ``int``.
The default behavior is to round to increments of 1. |
17,943 | def popitem(self):
with self.__timer as time:
self.expire(time)
try:
key = next(iter(self.__links))
except StopIteration:
raise KeyError( % self.__class__.__name__)
else:
return (key, self.pop(key)) | Remove and return the `(key, value)` pair least recently used that
has not already expired. |
17,944 | def methods(self, methods):
self._methods = NocaseDict()
if methods:
try:
iterator = methods.items()
except AttributeError:
iterator = methods
for item in iterator:
... | Setter method; for a description see the getter method. |
17,945 | def runner(self):
printtime(, self.starttime)
if not self.pipeline:
objects = Objectprep(self)
objects.objectprep()
self.runmetadata = objects.samples
Mash(self, self.analysistype) | Run the necessary methods in the correct order |
17,946 | def GpsSecondsFromPyUTC( pyUTC, leapSecs=14 ):
t = t=gpsFromUTC(*ymdhmsFromPyUTC( pyUTC ))
return int(t[0] * 60 * 60 * 24 * 7 + t[1]) | converts the python epoch to gps seconds
pyEpoch = the python epoch from time.time() |
17,947 | def _combine(self, other, conn=):
f = F()
self_filters = copy.deepcopy(self.filters)
other_filters = copy.deepcopy(other.filters)
if not self.filters:
f.filters = other_filters
elif not other.filters:
f.filters = self_filters
elif conn i... | OR and AND will create a new F, with the filters from both F
objects combined with the connector `conn`. |
17,948 | def init_app(self, app):
app.config.setdefault(, self.defaults[])
app.config.setdefault(, self.defaults[])
app.config.setdefault(, self.defaults[])
app.config.setdefault(, self.defaults[])
app.before_request(self.redirect_to_ssl)
app.after_request(self.set_hsts_... | Configures the specified Flask app to enforce SSL. |
17,949 | def getlist(self, section, option, *, raw=False, vars=None,
fallback=None):
val = self.get(section, option, raw=raw, vars=vars, fallback=fallback)
values = []
if val:
for line in val.split("\n"):
values += [s.strip() for s in line.split(",")]
... | Return the [section] option values as a list.
The list items must be delimited with commas and/or newlines. |
17,950 | def get_search_engine(index=None):
search_engine_class = _load_class(getattr(settings, "SEARCH_ENGINE", None), None)
return search_engine_class(index=index) if search_engine_class else None | Returns the desired implementor (defined in settings) |
17,951 | def IsDirectory(self):
if self._stat_object is None:
self._stat_object = self._GetStat()
if self._stat_object is not None:
self.entry_type = self._stat_object.type
return self.entry_type == definitions.FILE_ENTRY_TYPE_DIRECTORY | Determines if the file entry is a directory.
Returns:
bool: True if the file entry is a directory. |
17,952 | def _create_download_failed_message(exception, url):
message = .format(url, exception.__class__.__name__, exception)
if _is_temporal_problem(exception):
if isinstance(exception, requests.ConnectionError):
message +=
else:
message += \
e... | Creates message describing why download has failed
:param exception: Exception raised during download
:type exception: Exception
:param url: An URL from where download was attempted
:type url: str
:return: Error message
:rtype: str |
17,953 | def set_args(self, args, unknown_args=None):
if unknown_args is None:
unknown_args = []
self.logger.setLevel(getattr(logging, args.log_level))
parent = hdfs.path.dirname(hdfs.path.abspath(args.output.rstrip("/")))
self.remote_wd = hdfs.path.join(
parent,... | Configure job, based on the arguments provided. |
17,954 | def execute(
mapchete_files,
zoom=None,
bounds=None,
point=None,
wkt_geometry=None,
tile=None,
overwrite=False,
multi=None,
input_file=None,
logfile=None,
verbose=False,
no_pbar=False,
debug=False,
max_chunksize=None,
vrt=False,
idx_out_dir=None
):
... | Execute a Mapchete process. |
17,955 | def write_text_files(args, infilenames, outfilename):
if not outfilename.endswith():
outfilename = outfilename +
outfilename = overwrite_file_check(args, outfilename)
all_text = []
for i, infilename in enumerate(infilenames):
parsed_text = get_parsed_text(args, infilename)
... | Write text file(s) to disk.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- name of output text file (str) |
17,956 | def _write_superbox(self, fptr, box_id):
orig_pos = fptr.tell()
fptr.write(struct.pack(, 0, box_id))
for box in self.box:
box.write(fptr)
end_pos = fptr.tell()
fptr.seek(orig_pos)
fptr.write(struct.pack(, end_pos - orig_pos))
fptr.se... | Write a superbox.
Parameters
----------
fptr : file or file object
Superbox (box of boxes) to be written to this file.
box_id : bytes
4-byte sequence that identifies the superbox. |
17,957 | def _raise_glfw_errors_as_exceptions(error_code, description):
global ERROR_REPORTING
if ERROR_REPORTING:
message = "(%d) %s" % (error_code, description)
raise GLFWError(message) | Default error callback that raises GLFWError exceptions for glfw errors.
Set an alternative error callback or set glfw.ERROR_REPORTING to False to
disable this behavior. |
17,958 | def json_schema_type(schema_file: str, **kwargs) -> typing.Type:
from doctor.resource import ResourceSchema
schema = ResourceSchema.from_file(schema_file)
kwargs[] = schema
definition_key = kwargs.get()
if definition_key:
params = [definition_key]
request_schema = sch... | Create a :class:`~doctor.types.JsonSchema` type.
This function will automatically load the schema and set it as an attribute
of the class along with the description and example.
:param schema_file: The full path to the json schema file to load.
:param kwargs: Can include any attribute defined in
... |
17,959 | def closedopen(lower_value, upper_value):
return Interval(Interval.CLOSED, lower_value, upper_value, Interval.OPEN) | Helper function to construct an interval object with a closed lower and open upper.
For example:
>>> closedopen(100.2, 800.9)
[100.2, 800.9) |
17,960 | def detect_pattern_format(pattern_filename, encoding, on_word_boundaries):
tsv = True
boundaries = on_word_boundaries
with open_file(pattern_filename) as input_file:
for line in input_file:
line = line.decode(encoding)
if line.count() != 1:
tsv = False
... | Automatically detects the pattern file format, and determines
whether the Aho-Corasick string matching should pay attention to
word boundaries or not.
Arguments:
- `pattern_filename`:
- `encoding`:
- `on_word_boundaries`: |
17,961 | def get_couchdb_admins():
user_list = []
req = curl_couchdb()
for user in req.json().keys():
user_list.append(user)
return user_list | Return the actual CouchDB admins |
17,962 | def calc_effective_conductivity(self, inlets=None, outlets=None,
domain_area=None, domain_length=None):
r
return self._calc_eff_prop(inlets=inlets, outlets=outlets,
domain_area=domain_area,
domain_l... | r"""
This calculates the effective electrical conductivity.
Parameters
----------
inlets : array_like
The pores where the inlet voltage boundary conditions were
applied. If not given an attempt is made to infer them from the
algorithm.
outle... |
17,963 | def iris(display=False):
d = sklearn.datasets.load_iris()
df = pd.DataFrame(data=d.data, columns=d.feature_names)
if display:
return df, [d.target_names[v] for v in d.target]
else:
return df, d.target | Return the classic iris data in a nice package. |
17,964 | def check_physical(self, line):
self.physical_line = line
for name, check, argument_names in self._physical_checks:
self.init_checker_state(name, argument_names)
result = self.run_check(check, argument_names)
if result is not None:
(offset, te... | Run all physical checks on a raw input line. |
17,965 | def get_resources_by_search(self, resource_query, resource_search):
and_list = list()
or_list = list()
for term in resource_query._query_terms:
and_list.append({term: resource_query._query_terms[term]})
for term in resource_query._keyword_t... | Gets the search results matching the given search query using the given search.
arg: resource_query (osid.resource.ResourceQuery): the
resource query
arg: resource_search (osid.resource.ResourceSearch): the
resource search
return: (osid.resource.ResourceSea... |
17,966 | def __replace_capitalise(sentence):
if sentence is not None:
while sentence.find() != -1:
cap_index = _sentence.find()
part1 = sentence[:cap_index]
part2 = sentence[cap_index + 12:cap_index + 13]
part3 = sentence[cap_index + 13:]
if part2 i... | here we replace all instances of #CAPITALISE and cap the next word.
############
#NOTE: Buggy as hell, as it doesn't account for words that are already
#capitalized
############
:param _sentence: |
17,967 | def _inject_cookie_message(self, msg):
if isinstance(msg, unicode):
msg = msg.encode(, )
try:
self.request._cookies = Cookie.SimpleCookie(msg)
except:
logging.warn("couldn't parse cookie string: %s",msg, exc_info=True) | Inject the first message, which is the document cookie,
for authentication. |
17,968 | def find_family(self, pattern=r".*", flags=0, node=None):
return [node for node in foundations.walkers.nodes_walker(node or self) if
re.search(pattern, node.family, flags)] | Returns the Nodes from given family.
:param pattern: Matching pattern.
:type pattern: unicode
:param flags: Matching regex flags.
:type flags: int
:param node: Node to start walking from.
:type node: AbstractNode or AbstractCompositeNode or Object
:return: Family... |
17,969 | def rest_put(url, data, timeout, show_error=False):
try:
response = requests.put(url, headers={: , : },\
data=data, timeout=timeout)
return response
except Exception as exception:
if show_error:
print_error(exception)
return None | Call rest put method |
17,970 | def _gen_shuffles(self):
si = 0
self.shuffles = []
for song in self.loop:
for i in range(song[1]):
self.shuffles.append(si)
si += 1 | Used internally to build a list for mapping between a random number and
a song index. |
17,971 | def write_string(self, s, codec):
for i in range(0, len(s), self.bufsize):
chunk = s[i:i + self.bufsize]
buf, consumed = codec.encode(chunk)
assert consumed == len(chunk)
self.write(buf) | Write string encoding it with codec into stream |
17,972 | def bbox(self, out_crs=None):
return reproject_geometry(
box(*self._bounds),
src_crs=self.td_pyramid.crs,
dst_crs=self.pyramid.crs if out_crs is None else out_crs
) | Return data bounding box.
Parameters
----------
out_crs : ``rasterio.crs.CRS``
rasterio CRS object (default: CRS of process pyramid)
Returns
-------
bounding box : geometry
Shapely geometry object |
17,973 | def query(self, sql, timeout=10):
if not sql:
raise QueryError()
result = ResultQuery(*self.perform_request(**{
: ,
: ,
: {
"queryType": "SQL",
"query": sql
},
: {
: timeout
... | Submit a query and return results.
:param sql: string
:param timeout: int
:return: pydrill.client.ResultQuery |
17,974 | def stop(self):
self._response[] = True
self._response[][][] =
self._response[][][] = []
return self | Send signal to stop the current stream playback |
17,975 | def members(self):
all_members = []
for page in range(1, self.max_page() + 1):
all_members.extend(self.single_page_members(page))
return all_members | 获取小组所有成员的信息列表 |
17,976 | def get_cards(self, **query_params):
cards = self.get_cards_json(self.base_uri, query_params=query_params)
cards_list = []
for card_json in cards:
cards_list.append(self.create_card(card_json))
return cards_list | Get all cards this member is attached to. Return a list of Card
objects.
Returns:
list(Card): Return all cards this member is attached to |
17,977 | def Main():
argument_parser = argparse.ArgumentParser(description=(
))
argument_parser.add_argument(
, , dest=, action=,
metavar=, default=None, help=(
))
argument_parser.add_argument(
, nargs=, action=, metavar=,
default=None, help=)
options = argument_parse... | The main program function.
Returns:
bool: True if successful or False if not. |
17,978 | def format_attributes_json(self):
attributes_json = {}
for key, value in self.attributes.items():
key = utils.check_str_length(key)[0]
value = _format_attribute_value(value)
if value is not None:
attributes_json[key] = value
result ... | Convert the Attributes object to json format. |
17,979 | def check(self):
self._validate_settings()
r = self.local_renderer
r.env.alias = r.env.aliases[0]
r.sudo(r.env.check_command_template) | Run inadyn from the commandline to test the configuration.
To be run like:
fab role inadyn.check |
17,980 | def execute(self, input_data):
output = input_data[]
output[] = {}
for data in [input_data[key] for key in ViewMemoryDeep.dependencies]:
for name,table in data[].iteritems():
output[].update({name: table})
return output | Execute the ViewMemoryDeep worker |
17,981 | def load_and_preprocess_imdb_data(n_gram=None):
X_train, y_train, X_test, y_test = tl.files.load_imdb_dataset(nb_words=VOCAB_SIZE)
if n_gram is not None:
X_train = np.array([augment_with_ngrams(x, VOCAB_SIZE, N_BUCKETS, n=n_gram) for x in X_train])
X_test = np.array([augment_with_ngrams(x,... | Load IMDb data and augment with hashed n-gram features. |
17,982 | def available(name):
*
cmd = .format(name)
name = __salt__[](cmd, python_shell=False)
return name in get_all() | Returns ``True`` if the specified service is available, otherwise returns
``False``.
We look up the name with the svcs command to get back the FMRI
This allows users to use simpler service names
CLI Example:
.. code-block:: bash
salt '*' service.available net-snmp |
17,983 | def drag_and_drop_by_offset(self, source, xoffset, yoffset):
self.click_and_hold(source)
self.move_by_offset(xoffset, yoffset)
self.release()
return self | Holds down the left mouse button on the source element,
then moves to the target offset and releases the mouse button.
:Args:
- source: The element to mouse down.
- xoffset: X offset to move to.
- yoffset: Y offset to move to. |
17,984 | def _parse_configs(self, config):
for config_dict in config:
label = config_dict.keys()[0]
cfg = config_dict[label]
dbpath = cfg[]
pattern = self._parse_dbpath(dbpath)
read_preference = cfg.get(, ).upper()
read_prefer... | Builds a dict with information to connect to Clusters.
Parses the list of configuration dictionaries passed by the user and
builds an internal dict (_clusters) that holds information for creating
Clients connecting to Clusters and matching database names.
Args:
config: A li... |
17,985 | def _get_ema(cls, df, column, windows):
window = cls.get_only_one_positive_int(windows)
column_name = .format(column, window)
if len(df[column]) > 0:
df[column_name] = df[column].ewm(
ignore_na=False, span=window,
min_periods=0, adjust=... | get exponential moving average
:param df: data
:param column: column to calculate
:param windows: collection of window of exponential moving average
:return: None |
17,986 | def update_port_statuses_cfg(self, context, port_ids, status):
self._l3plugin.update_router_port_statuses(context, port_ids,
status) | Update the operational statuses of a list of router ports.
This is called by the Cisco cfg agent to update the status of a list
of ports.
:param context: contains user information
:param port_ids: list of ids of all the ports for the given status
:param status: PORT_STATUS_ACTI... |
17,987 | def create():
if not all(map(os.path.isdir, ARGS.directory)):
exit()
with sqlite3.connect(ARGS.database) as connection:
connection.text_factory = str
cursor = connection.cursor()
cursor.execute()
cursor.execute()
for dir in ARGS.directory:
cursor.... | Create a new database with information about the films in the specified
directory or directories. |
17,988 | def convert(word):
if six.PY2:
if isinstance(word, unicode):
return word.encode()
else:
return word.decode().encode()
else:
if isinstance(word, bytes):
return word.decode()
return word | This method converts given `word` to UTF-8 encoding and `bytes` type for the
SWIG wrapper. |
17,989 | def begin(self):
variables_to_restore = tf.contrib.framework.get_variables_to_restore(
include=self._include, exclude=self._exclude)
assignment_map = {variable.name[len(self._new_model_scope):]: variable
for variable in variables_to_restore
if variab... | Load variables from checkpoint.
New model variables have the following name foramt:
new_model_scope/old_model_scope/xxx/xxx:0 To find the map of
name to variable, need to strip the new_model_scope and then
match the old_model_scope and remove the suffix :0. |
17,990 | def has_entities(status):
try:
if sum(len(v) for v in status.entities.values()) > 0:
return True
except AttributeError:
if sum(len(v) for v in status[].values()) > 0:
return True
return False | Returns true if a Status object has entities.
Args:
status: either a tweepy.Status object or a dict returned from Twitter API |
17,991 | def token_is_correct(self, token):
if self.is_rus_word(token):
return True
elif self.ONLY_MARKS.search(token):
return True
elif self.END_TOKENS.search(token):
return True
elif token in "$^":
return True
return False | Подходит ли токен, для генерации текста.
Допускаются русские слова, знаки препинания и символы начала и конца. |
17,992 | def _get_bound_pressure_height(pressure, bound, heights=None, interpolate=True):
sort_inds = np.argsort(pressure)[::-1]
pressure = pressure[sort_inds]
if heights is not None:
heights = heights[sort_inds]
if bound.dimensionality == {: -1.0, : 1.0, : -2.0}:
if boun... | Calculate the bounding pressure and height in a layer.
Given pressure, optional heights, and a bound, return either the closest pressure/height
or interpolated pressure/height. If no heights are provided, a standard atmosphere is
assumed.
Parameters
----------
pressure : `pint.Quantity`
... |
17,993 | def within_radians(self, key, point, max_distance, min_distance=None):
self.near(key, point)
self._add_condition(key, , max_distance)
if min_distance is not None:
self._add_condition(key, , min_distance)
return self | 增加查询条件,限制返回结果指定字段值的位置在某点的一段距离之内。
:param key: 查询条件字段名
:param point: 查询地理位置
:param max_distance: 最大距离限定(弧度)
:param min_distance: 最小距离限定(弧度)
:rtype: Query |
17,994 | def mean_imls(self):
return numpy.array(
[max(0, self.imls[0] - (self.imls[1] - self.imls[0]) / 2.)] +
[numpy.mean(pair) for pair in pairwise(self.imls)] +
[self.imls[-1] + (self.imls[-1] - self.imls[-2]) / 2.]) | Compute the mean IMLs (Intensity Measure Level)
for the given vulnerability function.
:param vulnerability_function: the vulnerability function where
the IMLs (Intensity Measure Level) are taken from.
:type vuln_function:
:py:class:`openquake.risklib.vulnerability_functio... |
17,995 | def compute_checksum(self):
if self._filename.startswith("s3://"):
print("Warning: Did not perform client-side checksumming for file in S3. To be implemented.")
pass
else:
checksumCalculator = self.ChecksumCalculator(self._filename)
self._checksum... | Calculates checksums for a given file. |
17,996 | def mode_run_common_obs(args, extra_args):
loaded_obs = []
sessions = []
if args.session:
for obfile in args.obsresult:
_logger.info("session file from %r", obfile)
with open(obfile) as fd:
sess = yaml.load(fd)
sessions.append(sess[... | Observing mode processing mode of numina. |
17,997 | def _invert(color, **kwargs):
col = ColorValue(color)
args = [
255.0 - col.value[0],
255.0 - col.value[1],
255.0 - col.value[2],
col.value[3],
]
inverted = ColorValue(args)
return inverted | Returns the inverse (negative) of a color.
The red, green, and blue values are inverted, while the opacity is left alone. |
17,998 | def list_types_poi(self, **kwargs):
url_args = {: util.language_code(kwargs.get())}
result = self.make_request(, url_args)
if not util.check_result(result):
return False, result.get(, )
values = util.response_list(result, )
retur... | Obtain a list of families, types and categories of POI.
Args:
lang (str): Language code (*es* or *en*).
Returns:
Status boolean and parsed response (list[ParkingPoiType]), or message
string in case of error. |
17,999 | def force_process_ordered(self):
for instance_id, messages in self.replicas.take_ordereds_out_of_turn():
num_processed = 0
for message in messages:
self.try_processing_ordered(message)
num_processed += 1
logger.info(
... | Take any messages from replica that have been ordered and process
them, this should be done rarely, like before catchup starts
so a more current LedgerStatus can be sent.
can be called either
1. when node is participating, this happens just before catchup starts
so the node can h... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.