nwo
stringlengths
5
106
sha
stringlengths
40
40
path
stringlengths
4
174
language
stringclasses
1 value
identifier
stringlengths
1
140
parameters
stringlengths
0
87.7k
argument_list
stringclasses
1 value
return_statement
stringlengths
0
426k
docstring
stringlengths
0
64.3k
docstring_summary
stringlengths
0
26.3k
docstring_tokens
list
function
stringlengths
18
4.83M
function_tokens
list
url
stringlengths
83
304
DxCx/plugin.video.9anime
34358c2f701e5ddf19d3276926374a16f63f7b6a
resources/lib/ui/js2py/base.py
python
PyJs.__unicode__
(self)
return self.to_string().value
[]
def __unicode__(self): return self.to_string().value
[ "def", "__unicode__", "(", "self", ")", ":", "return", "self", ".", "to_string", "(", ")", ".", "value" ]
https://github.com/DxCx/plugin.video.9anime/blob/34358c2f701e5ddf19d3276926374a16f63f7b6a/resources/lib/ui/js2py/base.py#L905-L906
QUANTAXIS/QUANTAXIS
d6eccb97c8385854aa596d6ba8d70ec0655519ff
QUANTAXIS/QASU/save_binance.py
python
QA_SU_save_data_binance_callback
(data, freq)
异步获取数据回调用的 MongoDB 存储函数
异步获取数据回调用的 MongoDB 存储函数
[ "异步获取数据回调用的", "MongoDB", "存储函数" ]
def QA_SU_save_data_binance_callback(data, freq): """ 异步获取数据回调用的 MongoDB 存储函数 """ symbol_template = Binance_SYMBOL QA_util_log_info( 'SYMBOL "{}" Recived "{}" from {} to {} in total {} klines'.format( data.iloc[0].symbol, freq, time.strftime( '%Y-%m-%d %H:%M:%S', time.localtime(data.iloc[0].time_stamp) )[2:16], time.strftime( '%Y-%m-%d %H:%M:%S', time.localtime(data.iloc[-1].time_stamp) )[2:16], len(data) ) ) if (freq not in ['1day', '86400', 'day', '1d']): col = DATABASE.cryptocurrency_min col.create_index( [ ("symbol", pymongo.ASCENDING), ('time_stamp', pymongo.ASCENDING), ('date_stamp', pymongo.ASCENDING) ] ) col.create_index( [ ("symbol", pymongo.ASCENDING), ("type", pymongo.ASCENDING), ('time_stamp', pymongo.ASCENDING) ], unique=True ) # 查询是否新 tick query_id = { "symbol": data.iloc[0].symbol, 'type': data.iloc[0].type, 'time_stamp': { '$in': data['time_stamp'].tolist() } } refcount = col.count_documents(query_id) else: col = DATABASE.cryptocurrency_day col.create_index( [ ("symbol", pymongo.ASCENDING), ("date_stamp", pymongo.ASCENDING) ], unique=True ) # 查询是否新 tick query_id = { "symbol": data.iloc[0].symbol, 'date_stamp': { '$in': data['date_stamp'].tolist() } } refcount = col.count_documents(query_id) # 删除多余列 if ('_id' in data.columns.values): data.drop( [ '_id', ], axis=1, inplace=True ) if refcount > 0: if (len(data) > 1): # 删掉重复数据 col.delete_many(query_id) data = QA_util_to_json_from_pandas(data) col.insert_many(data) else: # 持续接收行情,更新记录 data.drop('created_at', axis=1, inplace=True) data = QA_util_to_json_from_pandas(data) col.replace_one(query_id, data[0]) else: # 新 tick,插入记录 data = QA_util_to_json_from_pandas(data) col.insert_many(data)
[ "def", "QA_SU_save_data_binance_callback", "(", "data", ",", "freq", ")", ":", "symbol_template", "=", "Binance_SYMBOL", "QA_util_log_info", "(", "'SYMBOL \"{}\" Recived \"{}\" from {} to {} in total {} klines'", ".", "format", "(", "data", ".", "iloc", "[", "0", "]", "...
https://github.com/QUANTAXIS/QUANTAXIS/blob/d6eccb97c8385854aa596d6ba8d70ec0655519ff/QUANTAXIS/QASU/save_binance.py#L541-L638
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/Python-2.7.9/Lib/argparse.py
python
_get_action_name
(argument)
[]
def _get_action_name(argument): if argument is None: return None elif argument.option_strings: return '/'.join(argument.option_strings) elif argument.metavar not in (None, SUPPRESS): return argument.metavar elif argument.dest not in (None, SUPPRESS): return argument.dest else: return None
[ "def", "_get_action_name", "(", "argument", ")", ":", "if", "argument", "is", "None", ":", "return", "None", "elif", "argument", ".", "option_strings", ":", "return", "'/'", ".", "join", "(", "argument", ".", "option_strings", ")", "elif", "argument", ".", ...
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/Python-2.7.9/Lib/argparse.py#L672-L682
postgres/pgadmin4
374c5e952fa594d749fadf1f88076c1cba8c5f64
web/pgadmin/tools/datagrid/__init__.py
python
_connect
(conn, **kwargs)
return status, msg, is_ask_password, user, role, password
Connect the database. :param conn: Connection instance. :param kwargs: user, role and password data from user. :return:
Connect the database. :param conn: Connection instance. :param kwargs: user, role and password data from user. :return:
[ "Connect", "the", "database", ".", ":", "param", "conn", ":", "Connection", "instance", ".", ":", "param", "kwargs", ":", "user", "role", "and", "password", "data", "from", "user", ".", ":", "return", ":" ]
def _connect(conn, **kwargs): """ Connect the database. :param conn: Connection instance. :param kwargs: user, role and password data from user. :return: """ user = None role = None password = None is_ask_password = False if 'user' in kwargs and 'role' in kwargs: user = kwargs['user'] role = kwargs['role'] if kwargs['role'] else None password = kwargs['password'] if kwargs['password'] else None is_ask_password = True if user: status, msg = conn.connect(user=user, role=role, password=password) else: status, msg = conn.connect() return status, msg, is_ask_password, user, role, password
[ "def", "_connect", "(", "conn", ",", "*", "*", "kwargs", ")", ":", "user", "=", "None", "role", "=", "None", "password", "=", "None", "is_ask_password", "=", "False", "if", "'user'", "in", "kwargs", "and", "'role'", "in", "kwargs", ":", "user", "=", ...
https://github.com/postgres/pgadmin4/blob/374c5e952fa594d749fadf1f88076c1cba8c5f64/web/pgadmin/tools/datagrid/__init__.py#L344-L366
jgagneastro/coffeegrindsize
22661ebd21831dba4cf32bfc6ba59fe3d49f879c
App/venv/lib/python3.7/site-packages/pip/_vendor/distlib/database.py
python
Distribution.__repr__
(self)
return '<Distribution %s (%s)%s>' % (self.name, self.version, suffix)
Return a textual representation of this instance,
Return a textual representation of this instance,
[ "Return", "a", "textual", "representation", "of", "this", "instance" ]
def __repr__(self): """ Return a textual representation of this instance, """ if self.source_url: suffix = ' [%s]' % self.source_url else: suffix = '' return '<Distribution %s (%s)%s>' % (self.name, self.version, suffix)
[ "def", "__repr__", "(", "self", ")", ":", "if", "self", ".", "source_url", ":", "suffix", "=", "' [%s]'", "%", "self", ".", "source_url", "else", ":", "suffix", "=", "''", "return", "'<Distribution %s (%s)%s>'", "%", "(", "self", ".", "name", ",", "self"...
https://github.com/jgagneastro/coffeegrindsize/blob/22661ebd21831dba4cf32bfc6ba59fe3d49f879c/App/venv/lib/python3.7/site-packages/pip/_vendor/distlib/database.py#L441-L449
khanhnamle1994/natural-language-processing
01d450d5ac002b0156ef4cf93a07cb508c1bcdc5
assignment1/.env/lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.py
python
ihilbert
(x)
return -hilbert(x)
Return inverse Hilbert transform of a periodic sequence x. If ``x_j`` and ``y_j`` are Fourier coefficients of periodic functions x and y, respectively, then:: y_j = -sqrt(-1)*sign(j) * x_j y_0 = 0
Return inverse Hilbert transform of a periodic sequence x.
[ "Return", "inverse", "Hilbert", "transform", "of", "a", "periodic", "sequence", "x", "." ]
def ihilbert(x): """ Return inverse Hilbert transform of a periodic sequence x. If ``x_j`` and ``y_j`` are Fourier coefficients of periodic functions x and y, respectively, then:: y_j = -sqrt(-1)*sign(j) * x_j y_0 = 0 """ return -hilbert(x)
[ "def", "ihilbert", "(", "x", ")", ":", "return", "-", "hilbert", "(", "x", ")" ]
https://github.com/khanhnamle1994/natural-language-processing/blob/01d450d5ac002b0156ef4cf93a07cb508c1bcdc5/assignment1/.env/lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.py#L252-L263
itailang/SampleNet
442459abc54f9e14f0966a169a094a98febd32eb
reconstruction/src/samplenet_pointnet_ae.py
python
SampleNetPointNetAE.reconstruct
(self, X, GT=None, S=None, compute_loss=True)
return self.sess.run( (self.x_reconstr, loss, loss_ae, loss_simplification, loss_projection), feed_dict=feed_dict, )
Use AE to reconstruct given data. GT will be used to measure the loss (e.g., if X is a noisy version of the GT)
Use AE to reconstruct given data. GT will be used to measure the loss (e.g., if X is a noisy version of the GT)
[ "Use", "AE", "to", "reconstruct", "given", "data", ".", "GT", "will", "be", "used", "to", "measure", "the", "loss", "(", "e", ".", "g", ".", "if", "X", "is", "a", "noisy", "version", "of", "the", "GT", ")" ]
def reconstruct(self, X, GT=None, S=None, compute_loss=True): """Use AE to reconstruct given data. GT will be used to measure the loss (e.g., if X is a noisy version of the GT)""" if compute_loss: loss = self.loss loss_ae = self.loss_ae loss_simplification = self.loss_simplification loss_projection = self.loss_projection else: loss = self.no_op loss_ae = self.no_op loss_simplification = self.no_op loss_projection = self.no_op feed_dict = {self.x: X} if GT is not None: feed_dict[self.gt] = GT if S is not None: feed_dict[self.s] = S return self.sess.run( (self.x_reconstr, loss, loss_ae, loss_simplification, loss_projection), feed_dict=feed_dict, )
[ "def", "reconstruct", "(", "self", ",", "X", ",", "GT", "=", "None", ",", "S", "=", "None", ",", "compute_loss", "=", "True", ")", ":", "if", "compute_loss", ":", "loss", "=", "self", ".", "loss", "loss_ae", "=", "self", ".", "loss_ae", "loss_simplif...
https://github.com/itailang/SampleNet/blob/442459abc54f9e14f0966a169a094a98febd32eb/reconstruction/src/samplenet_pointnet_ae.py#L265-L289
trakt/Plex-Trakt-Scrobbler
aeb0bfbe62fad4b06c164f1b95581da7f35dce0b
Trakttv.bundle/Contents/Libraries/Linux/x86_64/ucs4/cryptography/x509/base.py
python
CertificateSigningRequestBuilder.sign
(self, private_key, algorithm, backend)
return backend.create_x509_csr(self, private_key, algorithm)
Signs the request using the requestor's private key.
Signs the request using the requestor's private key.
[ "Signs", "the", "request", "using", "the", "requestor", "s", "private", "key", "." ]
def sign(self, private_key, algorithm, backend): """ Signs the request using the requestor's private key. """ if self._subject_name is None: raise ValueError("A CertificateSigningRequest must have a subject") return backend.create_x509_csr(self, private_key, algorithm)
[ "def", "sign", "(", "self", ",", "private_key", ",", "algorithm", ",", "backend", ")", ":", "if", "self", ".", "_subject_name", "is", "None", ":", "raise", "ValueError", "(", "\"A CertificateSigningRequest must have a subject\"", ")", "return", "backend", ".", "...
https://github.com/trakt/Plex-Trakt-Scrobbler/blob/aeb0bfbe62fad4b06c164f1b95581da7f35dce0b/Trakttv.bundle/Contents/Libraries/Linux/x86_64/ucs4/cryptography/x509/base.py#L368-L374
oilshell/oil
94388e7d44a9ad879b12615f6203b38596b5a2d3
osh/word_.py
python
_RightMostSpanForPart
(part)
[]
def _RightMostSpanForPart(part): # type: (word_part_t) -> int UP_part = part with tagswitch(part) as case: if case(word_part_e.ShArrayLiteral): part = cast(sh_array_literal, UP_part) # TODO: Return ) return LeftMostSpanForWord(part.words[0]) # Hm this is a=(1 2 3) elif case(word_part_e.Literal): # Just use the token tok = cast(Token, UP_part) return tok.span_id elif case(word_part_e.EscapedLiteral): part = cast(word_part__EscapedLiteral, UP_part) return part.token.span_id elif case(word_part_e.SingleQuoted): part = cast(single_quoted, UP_part) return part.spids[1] # right ' elif case(word_part_e.DoubleQuoted): part = cast(double_quoted, UP_part) return part.spids[1] # right " elif case(word_part_e.SimpleVarSub): part = cast(simple_var_sub, UP_part) return part.token.span_id elif case(word_part_e.BracedVarSub): part = cast(braced_var_sub, UP_part) spid = part.spids[1] # right } assert spid != runtime.NO_SPID return spid elif case(word_part_e.CommandSub): part = cast(command_sub, UP_part) return part.spids[1] elif case(word_part_e.TildeSub): return runtime.NO_SPID elif case(word_part_e.ArithSub): part = cast(word_part__ArithSub, UP_part) return part.spids[1] elif case(word_part_e.ExtGlob): part = cast(word_part__ExtGlob, UP_part) return part.spids[1] # TODO: Do Splice and FuncCall need it? else: raise AssertionError(part.tag_())
[ "def", "_RightMostSpanForPart", "(", "part", ")", ":", "# type: (word_part_t) -> int", "UP_part", "=", "part", "with", "tagswitch", "(", "part", ")", "as", "case", ":", "if", "case", "(", "word_part_e", ".", "ShArrayLiteral", ")", ":", "part", "=", "cast", "...
https://github.com/oilshell/oil/blob/94388e7d44a9ad879b12615f6203b38596b5a2d3/osh/word_.py#L214-L267
MDudek-ICS/TRISIS-TRITON-HATMAN
15a00af7fd1040f0430729d024427601f84886a1
decompiled_code/library/pdb.py
python
Pdb.user_call
(self, frame, argument_list)
return
This method is called when there is the remote possibility that we ever need to stop in this function.
This method is called when there is the remote possibility that we ever need to stop in this function.
[ "This", "method", "is", "called", "when", "there", "is", "the", "remote", "possibility", "that", "we", "ever", "need", "to", "stop", "in", "this", "function", "." ]
def user_call(self, frame, argument_list): """This method is called when there is the remote possibility that we ever need to stop in this function.""" if self._wait_for_mainpyfile: return if self.stop_here(frame): print >> self.stdout, '--Call--' self.interaction(frame, None) return
[ "def", "user_call", "(", "self", ",", "frame", ",", "argument_list", ")", ":", "if", "self", ".", "_wait_for_mainpyfile", ":", "return", "if", "self", ".", "stop_here", "(", "frame", ")", ":", "print", ">>", "self", ".", "stdout", ",", "'--Call--'", "sel...
https://github.com/MDudek-ICS/TRISIS-TRITON-HATMAN/blob/15a00af7fd1040f0430729d024427601f84886a1/decompiled_code/library/pdb.py#L122-L130
mdiazcl/fuzzbunch-debian
2b76c2249ade83a389ae3badb12a1bd09901fd2c
windows/Resources/Python/Core/Lib/random.py
python
Random.randrange
(self, start, stop=None, step=1, int=int, default=None, maxwidth=1 << BPF)
return istart + istep * int(self.random() * n)
Choose a random item from range(start, stop[, step]). This fixes the problem with randint() which includes the endpoint; in Python this is usually not what you want. Do not supply the 'int', 'default', and 'maxwidth' arguments.
Choose a random item from range(start, stop[, step]). This fixes the problem with randint() which includes the endpoint; in Python this is usually not what you want. Do not supply the 'int', 'default', and 'maxwidth' arguments.
[ "Choose", "a", "random", "item", "from", "range", "(", "start", "stop", "[", "step", "]", ")", ".", "This", "fixes", "the", "problem", "with", "randint", "()", "which", "includes", "the", "endpoint", ";", "in", "Python", "this", "is", "usually", "not", ...
def randrange(self, start, stop=None, step=1, int=int, default=None, maxwidth=1 << BPF): """Choose a random item from range(start, stop[, step]). This fixes the problem with randint() which includes the endpoint; in Python this is usually not what you want. Do not supply the 'int', 'default', and 'maxwidth' arguments. """ istart = int(start) if istart != start: raise ValueError, 'non-integer arg 1 for randrange()' if stop is default: if istart > 0: if istart >= maxwidth: return self._randbelow(istart) return int(self.random() * istart) raise ValueError, 'empty range for randrange()' istop = int(stop) if istop != stop: raise ValueError, 'non-integer stop for randrange()' width = istop - istart if step == 1 and width > 0: if width >= maxwidth: return int(istart + self._randbelow(width)) return int(istart + int(self.random() * width)) if step == 1: raise ValueError, 'empty range for randrange() (%d,%d, %d)' % (istart, istop, width) istep = int(step) if istep != step: raise ValueError, 'non-integer step for randrange()' if istep > 0: n = (width + istep - 1) // istep elif istep < 0: n = (width + istep + 1) // istep else: raise ValueError, 'zero step for randrange()' if n <= 0: raise ValueError, 'empty range for randrange()' if n >= maxwidth: return istart + istep * self._randbelow(n) return istart + istep * int(self.random() * n)
[ "def", "randrange", "(", "self", ",", "start", ",", "stop", "=", "None", ",", "step", "=", "1", ",", "int", "=", "int", ",", "default", "=", "None", ",", "maxwidth", "=", "1", "<<", "BPF", ")", ":", "istart", "=", "int", "(", "start", ")", "if"...
https://github.com/mdiazcl/fuzzbunch-debian/blob/2b76c2249ade83a389ae3badb12a1bd09901fd2c/windows/Resources/Python/Core/Lib/random.py#L157-L196
rizar/attention-lvcsr
1ae52cafdd8419874846f9544a299eef9c758f3b
libs/Theano/theano/tensor/type.py
python
TensorType.value_zeros
(self, shape)
return numpy.zeros(shape, dtype=self.dtype)
Create an numpy ndarray full of 0 values.
Create an numpy ndarray full of 0 values.
[ "Create", "an", "numpy", "ndarray", "full", "of", "0", "values", "." ]
def value_zeros(self, shape): """ Create an numpy ndarray full of 0 values. """ return numpy.zeros(shape, dtype=self.dtype)
[ "def", "value_zeros", "(", "self", ",", "shape", ")", ":", "return", "numpy", ".", "zeros", "(", "shape", ",", "dtype", "=", "self", ".", "dtype", ")" ]
https://github.com/rizar/attention-lvcsr/blob/1ae52cafdd8419874846f9544a299eef9c758f3b/libs/Theano/theano/tensor/type.py#L629-L634
IntelAI/models
1d7a53ccfad3e6f0e7378c9e3c8840895d63df8c
models/language_translation/tensorflow/transformer_mlperf/training/bfloat16/transformer/utils/dataset.py
python
_parse_example
(serialized_example)
return inputs, targets
Return inputs and targets Tensors from a serialized tf.Example.
Return inputs and targets Tensors from a serialized tf.Example.
[ "Return", "inputs", "and", "targets", "Tensors", "from", "a", "serialized", "tf", ".", "Example", "." ]
def _parse_example(serialized_example): """Return inputs and targets Tensors from a serialized tf.Example.""" data_fields = { "inputs": tf.io.VarLenFeature(tf.int64), "targets": tf.io.VarLenFeature(tf.int64) } parsed = tf.io.parse_single_example(serialized=serialized_example, features=data_fields) inputs = tf.sparse.to_dense(parsed["inputs"]) targets = tf.sparse.to_dense(parsed["targets"]) return inputs, targets
[ "def", "_parse_example", "(", "serialized_example", ")", ":", "data_fields", "=", "{", "\"inputs\"", ":", "tf", ".", "io", ".", "VarLenFeature", "(", "tf", ".", "int64", ")", ",", "\"targets\"", ":", "tf", ".", "io", ".", "VarLenFeature", "(", "tf", ".",...
https://github.com/IntelAI/models/blob/1d7a53ccfad3e6f0e7378c9e3c8840895d63df8c/models/language_translation/tensorflow/transformer_mlperf/training/bfloat16/transformer/utils/dataset.py#L77-L86
dimagi/commcare-hq
d67ff1d3b4c51fa050c19e60c3253a79d3452a39
corehq/apps/hqwebapp/templatetags/hq_shared_tags.py
python
add_days
(date, days=1)
Return a date with some days added
Return a date with some days added
[ "Return", "a", "date", "with", "some", "days", "added" ]
def add_days(date, days=1): '''Return a date with some days added''' span = timedelta(days=days) try: return date + span except: return datetime.strptime(date, '%m/%d/%Y').date() + span
[ "def", "add_days", "(", "date", ",", "days", "=", "1", ")", ":", "span", "=", "timedelta", "(", "days", "=", "days", ")", "try", ":", "return", "date", "+", "span", "except", ":", "return", "datetime", ".", "strptime", "(", "date", ",", "'%m/%d/%Y'",...
https://github.com/dimagi/commcare-hq/blob/d67ff1d3b4c51fa050c19e60c3253a79d3452a39/corehq/apps/hqwebapp/templatetags/hq_shared_tags.py#L74-L80
CvvT/dumpDex
92ab3b7e996194a06bf1dd5538a4954e8a5ee9c1
python/idaapi.py
python
is_weak_name
(*args)
return _idaapi.is_weak_name(*args)
is_weak_name(ea) -> bool
is_weak_name(ea) -> bool
[ "is_weak_name", "(", "ea", ")", "-", ">", "bool" ]
def is_weak_name(*args): """ is_weak_name(ea) -> bool """ return _idaapi.is_weak_name(*args)
[ "def", "is_weak_name", "(", "*", "args", ")", ":", "return", "_idaapi", ".", "is_weak_name", "(", "*", "args", ")" ]
https://github.com/CvvT/dumpDex/blob/92ab3b7e996194a06bf1dd5538a4954e8a5ee9c1/python/idaapi.py#L47353-L47357
timonwong/OmniMarkupPreviewer
21921ac7a99d2b5924a2219b33679a5b53621392
OmniMarkupLib/Renderers/libs/python2/docutils/parsers/rst/directives/__init__.py
python
flag
(argument)
Check for a valid flag option (no argument) and return ``None``. (Directive option conversion function.) Raise ``ValueError`` if an argument is found.
Check for a valid flag option (no argument) and return ``None``. (Directive option conversion function.)
[ "Check", "for", "a", "valid", "flag", "option", "(", "no", "argument", ")", "and", "return", "None", ".", "(", "Directive", "option", "conversion", "function", ".", ")" ]
def flag(argument): """ Check for a valid flag option (no argument) and return ``None``. (Directive option conversion function.) Raise ``ValueError`` if an argument is found. """ if argument and argument.strip(): raise ValueError('no argument is allowed; "%s" supplied' % argument) else: return None
[ "def", "flag", "(", "argument", ")", ":", "if", "argument", "and", "argument", ".", "strip", "(", ")", ":", "raise", "ValueError", "(", "'no argument is allowed; \"%s\" supplied'", "%", "argument", ")", "else", ":", "return", "None" ]
https://github.com/timonwong/OmniMarkupPreviewer/blob/21921ac7a99d2b5924a2219b33679a5b53621392/OmniMarkupLib/Renderers/libs/python2/docutils/parsers/rst/directives/__init__.py#L141-L151
vslavik/bakefile
0757295c3e4ac23cd1e0767c77c14c2256ed16e1
3rdparty/antlr3/python-runtime/antlr3/treewizard.py
python
TreeWizard.parse
(self, t, pattern, labels=None)
return self._parse(t, tpattern, labels)
Given a pattern like (ASSIGN %lhs:ID %rhs:.) with optional labels on the various nodes and '.' (dot) as the node/subtree wildcard, return true if the pattern matches and fill the labels Map with the labels pointing at the appropriate nodes. Return false if the pattern is malformed or the tree does not match. If a node specifies a text arg in pattern, then that must match for that node in t.
Given a pattern like (ASSIGN %lhs:ID %rhs:.) with optional labels on the various nodes and '.' (dot) as the node/subtree wildcard, return true if the pattern matches and fill the labels Map with the labels pointing at the appropriate nodes. Return false if the pattern is malformed or the tree does not match.
[ "Given", "a", "pattern", "like", "(", "ASSIGN", "%lhs", ":", "ID", "%rhs", ":", ".", ")", "with", "optional", "labels", "on", "the", "various", "nodes", "and", ".", "(", "dot", ")", "as", "the", "node", "/", "subtree", "wildcard", "return", "true", "...
def parse(self, t, pattern, labels=None): """ Given a pattern like (ASSIGN %lhs:ID %rhs:.) with optional labels on the various nodes and '.' (dot) as the node/subtree wildcard, return true if the pattern matches and fill the labels Map with the labels pointing at the appropriate nodes. Return false if the pattern is malformed or the tree does not match. If a node specifies a text arg in pattern, then that must match for that node in t. """ tokenizer = TreePatternLexer(pattern) parser = TreePatternParser(tokenizer, self, TreePatternTreeAdaptor()) tpattern = parser.pattern() return self._parse(t, tpattern, labels)
[ "def", "parse", "(", "self", ",", "t", ",", "pattern", ",", "labels", "=", "None", ")", ":", "tokenizer", "=", "TreePatternLexer", "(", "pattern", ")", "parser", "=", "TreePatternParser", "(", "tokenizer", ",", "self", ",", "TreePatternTreeAdaptor", "(", "...
https://github.com/vslavik/bakefile/blob/0757295c3e4ac23cd1e0767c77c14c2256ed16e1/3rdparty/antlr3/python-runtime/antlr3/treewizard.py#L521-L537
zhuifengshen/xmind
be2966776f2a7262b6a9960682380571a2e91ccf
xmind/utils.py
python
get_abs_path
(path)
return join_path(fp, fn)
Return the absolute path of a file If path contains a start point (eg Unix '/') then use the specified start point instead of the current working directory. The starting point of the file path is allowed to begin with a tilde "~", which will be replaced with the user's home directory.
Return the absolute path of a file
[ "Return", "the", "absolute", "path", "of", "a", "file" ]
def get_abs_path(path): """ Return the absolute path of a file If path contains a start point (eg Unix '/') then use the specified start point instead of the current working directory. The starting point of the file path is allowed to begin with a tilde "~", which will be replaced with the user's home directory. """ fp, fn = os.path.split(path) if not fp: fp = os.getcwd() fp = os.path.abspath(os.path.expanduser(fp)) return join_path(fp, fn)
[ "def", "get_abs_path", "(", "path", ")", ":", "fp", ",", "fn", "=", "os", ".", "path", ".", "split", "(", "path", ")", "if", "not", "fp", ":", "fp", "=", "os", ".", "getcwd", "(", ")", "fp", "=", "os", ".", "path", ".", "abspath", "(", "os", ...
https://github.com/zhuifengshen/xmind/blob/be2966776f2a7262b6a9960682380571a2e91ccf/xmind/utils.py#L49-L64
nlloyd/SubliminalCollaborator
5c619e17ddbe8acb9eea8996ec038169ddcd50a1
libs/twisted/application/app.py
python
ServerOptions.opt_spew
(self)
Print an insanely verbose log of everything that happens. Useful when debugging freezes or locks in complex code.
Print an insanely verbose log of everything that happens. Useful when debugging freezes or locks in complex code.
[ "Print", "an", "insanely", "verbose", "log", "of", "everything", "that", "happens", ".", "Useful", "when", "debugging", "freezes", "or", "locks", "in", "complex", "code", "." ]
def opt_spew(self): """ Print an insanely verbose log of everything that happens. Useful when debugging freezes or locks in complex code.""" sys.settrace(util.spewer) try: import threading except ImportError: return threading.settrace(util.spewer)
[ "def", "opt_spew", "(", "self", ")", ":", "sys", ".", "settrace", "(", "util", ".", "spewer", ")", "try", ":", "import", "threading", "except", "ImportError", ":", "return", "threading", ".", "settrace", "(", "util", ".", "spewer", ")" ]
https://github.com/nlloyd/SubliminalCollaborator/blob/5c619e17ddbe8acb9eea8996ec038169ddcd50a1/libs/twisted/application/app.py#L599-L608
eventable/vobject
498555a553155ea9b26aace93332ae79365ecb31
docs/build/lib/vobject/vcard.py
python
VCard3_0.generateImplicitParameters
(cls, obj)
Create PRODID, VERSION, and VTIMEZONEs if needed. VTIMEZONEs will need to exist whenever TZID parameters exist or when datetimes with tzinfo exist.
Create PRODID, VERSION, and VTIMEZONEs if needed.
[ "Create", "PRODID", "VERSION", "and", "VTIMEZONEs", "if", "needed", "." ]
def generateImplicitParameters(cls, obj): """ Create PRODID, VERSION, and VTIMEZONEs if needed. VTIMEZONEs will need to exist whenever TZID parameters exist or when datetimes with tzinfo exist. """ if not hasattr(obj, 'version'): obj.add(ContentLine('VERSION', [], cls.versionString))
[ "def", "generateImplicitParameters", "(", "cls", ",", "obj", ")", ":", "if", "not", "hasattr", "(", "obj", ",", "'version'", ")", ":", "obj", ".", "add", "(", "ContentLine", "(", "'VERSION'", ",", "[", "]", ",", "cls", ".", "versionString", ")", ")" ]
https://github.com/eventable/vobject/blob/498555a553155ea9b26aace93332ae79365ecb31/docs/build/lib/vobject/vcard.py#L185-L193
softlayer/softlayer-python
cdef7d63c66413197a9a97b0414de9f95887a82a
SoftLayer/managers/network.py
python
NetworkManager.set_tags_subnet
(self, subnet_id, tags)
return self.subnet.setTags(tags, id=subnet_id)
Tag a subnet by passing in one or more tags separated by a comma. :param int subnet_id: The ID of the subnet. :param string tags: Comma separated list of tags.
Tag a subnet by passing in one or more tags separated by a comma.
[ "Tag", "a", "subnet", "by", "passing", "in", "one", "or", "more", "tags", "separated", "by", "a", "comma", "." ]
def set_tags_subnet(self, subnet_id, tags): """Tag a subnet by passing in one or more tags separated by a comma. :param int subnet_id: The ID of the subnet. :param string tags: Comma separated list of tags. """ return self.subnet.setTags(tags, id=subnet_id)
[ "def", "set_tags_subnet", "(", "self", ",", "subnet_id", ",", "tags", ")", ":", "return", "self", ".", "subnet", ".", "setTags", "(", "tags", ",", "id", "=", "subnet_id", ")" ]
https://github.com/softlayer/softlayer-python/blob/cdef7d63c66413197a9a97b0414de9f95887a82a/SoftLayer/managers/network.py#L269-L275
stepjam/PyRep
d778d5d4ffa3be366d4e699f6e2941553fd47ecc
pyrep/objects/shape.py
python
Shape.import_shape
(cls, filename: str, scaling_factor=1.0, keep_identical_vertices=False, ignore_color=False, ignore_texture=False, reorient_bounding_box=False, ignore_up_vector=False)
return cls(handle)
Imports a shape with visuals from a file. :param filename: The location of the file to import. :param scaling_factor: The scaling factor to apply to the imported vertices :param keep_identical_vertices: Keep identical vertices. :param ignore_color: Do not preserve colors. :param ignore_texture: Do not preserve texture. :param reorient_bounding_box: Reorient the shape's bounding box with the world. :param ignore_up_vector: Ignore up-vector coded in file. :return: The Shape object.
Imports a shape with visuals from a file.
[ "Imports", "a", "shape", "with", "visuals", "from", "a", "file", "." ]
def import_shape(cls, filename: str, scaling_factor=1.0, keep_identical_vertices=False, ignore_color=False, ignore_texture=False, reorient_bounding_box=False, ignore_up_vector=False) -> 'Shape': """Imports a shape with visuals from a file. :param filename: The location of the file to import. :param scaling_factor: The scaling factor to apply to the imported vertices :param keep_identical_vertices: Keep identical vertices. :param ignore_color: Do not preserve colors. :param ignore_texture: Do not preserve texture. :param reorient_bounding_box: Reorient the shape's bounding box with the world. :param ignore_up_vector: Ignore up-vector coded in file. :return: The Shape object. """ if not os.path.isfile(filename): raise ValueError('Filename does not exist: ' + filename) options = 0 if keep_identical_vertices: options |= 1 if ignore_color: options |= 8 if not ignore_texture: options |= 16 if reorient_bounding_box: options |= 32 if ignore_up_vector: options |= 128 handle = sim.simImportShape(0, filename, options, 0, scaling_factor) return cls(handle)
[ "def", "import_shape", "(", "cls", ",", "filename", ":", "str", ",", "scaling_factor", "=", "1.0", ",", "keep_identical_vertices", "=", "False", ",", "ignore_color", "=", "False", ",", "ignore_texture", "=", "False", ",", "reorient_bounding_box", "=", "False", ...
https://github.com/stepjam/PyRep/blob/d778d5d4ffa3be366d4e699f6e2941553fd47ecc/pyrep/objects/shape.py#L82-L114
mkelly12/google_closure_compiler
74572d592f5364504615853ef2a2dd0d4f5cabe0
bin/calcdeps.py
python
Compile
(compiler_jar_path, source_paths, out, flags=None)
Prepares command-line call to Closure compiler. Args: compiler_jar_path: Path to the Closure compiler .jar file. source_paths: Source paths to build, in order. flags: A list of additional flags to pass on to Closure compiler.
Prepares command-line call to Closure compiler.
[ "Prepares", "command", "-", "line", "call", "to", "Closure", "compiler", "." ]
def Compile(compiler_jar_path, source_paths, out, flags=None): """Prepares command-line call to Closure compiler. Args: compiler_jar_path: Path to the Closure compiler .jar file. source_paths: Source paths to build, in order. flags: A list of additional flags to pass on to Closure compiler. """ args = ['java', '-jar', compiler_jar_path] for path in source_paths: args += ['--js', path] if flags: args += flags logging.info('Compiling with the following command: %s', ' '.join(args)) proc = subprocess.Popen(args, stdout=subprocess.PIPE) (stdoutdata, stderrdata) = proc.communicate() if proc.returncode != 0: logging.error('JavaScript compilation failed.') sys.exit(1) else: out.write(stdoutdata)
[ "def", "Compile", "(", "compiler_jar_path", ",", "source_paths", ",", "out", ",", "flags", "=", "None", ")", ":", "args", "=", "[", "'java'", ",", "'-jar'", ",", "compiler_jar_path", "]", "for", "path", "in", "source_paths", ":", "args", "+=", "[", "'--j...
https://github.com/mkelly12/google_closure_compiler/blob/74572d592f5364504615853ef2a2dd0d4f5cabe0/bin/calcdeps.py#L309-L331
dipy/dipy
be956a529465b28085f8fc435a756947ddee1c89
dipy/denoise/patch2self.py
python
_extract_3d_patches
(arr, patch_radius)
return np.array(all_patches).T
Extract 3D patches from 4D DWI data. Parameters ---------- arr : ndarray The 4D noisy DWI data to be denoised. patch_radius : int or 1D array The radius of the local patch to be taken around each voxel (in voxels). Returns -------- all_patches : ndarray All 3D patches flattened out to be 2D corresponding to the each 3D volume of the 4D DWI data.
Extract 3D patches from 4D DWI data.
[ "Extract", "3D", "patches", "from", "4D", "DWI", "data", "." ]
def _extract_3d_patches(arr, patch_radius): """ Extract 3D patches from 4D DWI data. Parameters ---------- arr : ndarray The 4D noisy DWI data to be denoised. patch_radius : int or 1D array The radius of the local patch to be taken around each voxel (in voxels). Returns -------- all_patches : ndarray All 3D patches flattened out to be 2D corresponding to the each 3D volume of the 4D DWI data. """ if isinstance(patch_radius, int): patch_radius = np.ones(3, dtype=int) * patch_radius if len(patch_radius) != 3: raise ValueError("patch_radius should have length 3") else: patch_radius = np.asarray(patch_radius, dtype=int) patch_size = 2 * patch_radius + 1 dim = arr.shape[-1] all_patches = [] # loop around and find the 3D patch for each direction for i in range(patch_radius[0], arr.shape[0] - patch_radius[0], 1): for j in range(patch_radius[1], arr.shape[1] - patch_radius[1], 1): for k in range(patch_radius[2], arr.shape[2] - patch_radius[2], 1): ix1 = i - patch_radius[0] ix2 = i + patch_radius[0] + 1 jx1 = j - patch_radius[1] jx2 = j + patch_radius[1] + 1 kx1 = k - patch_radius[2] kx2 = k + patch_radius[2] + 1 X = arr[ix1:ix2, jx1:jx2, kx1:kx2].reshape(np.prod(patch_size), dim) all_patches.append(X) return np.array(all_patches).T
[ "def", "_extract_3d_patches", "(", "arr", ",", "patch_radius", ")", ":", "if", "isinstance", "(", "patch_radius", ",", "int", ")", ":", "patch_radius", "=", "np", ".", "ones", "(", "3", ",", "dtype", "=", "int", ")", "*", "patch_radius", "if", "len", "...
https://github.com/dipy/dipy/blob/be956a529465b28085f8fc435a756947ddee1c89/dipy/denoise/patch2self.py#L112-L162
openedx/edx-platform
68dd185a0ab45862a2a61e0f803d7e03d2be71b5
lms/djangoapps/courseware/masquerade.py
python
is_masquerading_as_specific_student
(user, course_key)
return bool(course_masquerade and course_masquerade.user_name)
Returns whether the user is a staff member masquerading as a specific student.
Returns whether the user is a staff member masquerading as a specific student.
[ "Returns", "whether", "the", "user", "is", "a", "staff", "member", "masquerading", "as", "a", "specific", "student", "." ]
def is_masquerading_as_specific_student(user, course_key): """ Returns whether the user is a staff member masquerading as a specific student. """ course_masquerade = get_course_masquerade(user, course_key) return bool(course_masquerade and course_masquerade.user_name)
[ "def", "is_masquerading_as_specific_student", "(", "user", ",", "course_key", ")", ":", "course_masquerade", "=", "get_course_masquerade", "(", "user", ",", "course_key", ")", "return", "bool", "(", "course_masquerade", "and", "course_masquerade", ".", "user_name", ")...
https://github.com/openedx/edx-platform/blob/68dd185a0ab45862a2a61e0f803d7e03d2be71b5/lms/djangoapps/courseware/masquerade.py#L348-L353
python-zk/kazoo
f585d605eea0a37a08aae95a8cc259b80da2ecf0
kazoo/client.py
python
KazooClient.set_acls
(self, path, acls, version=-1)
return self.set_acls_async(path, acls, version).get()
Set the ACL for the node of the given path. Set the ACL for the node of the given path if such a node exists and the given version matches the version of the node. :param path: Path for the node. :param acls: List of :class:`~kazoo.security.ACL` objects to set. :param version: The expected node version that must match. :returns: The stat of the node. :raises: :exc:`~kazoo.exceptions.BadVersionError` if version doesn't match. :exc:`~kazoo.exceptions.NoNodeError` if the node doesn't exist. :exc:`~kazoo.exceptions.InvalidACLError` if the ACL is invalid. :exc:`~kazoo.exceptions.ZookeeperError` if the server returns a non-zero error code. .. versionadded:: 0.5
Set the ACL for the node of the given path.
[ "Set", "the", "ACL", "for", "the", "node", "of", "the", "given", "path", "." ]
def set_acls(self, path, acls, version=-1): """Set the ACL for the node of the given path. Set the ACL for the node of the given path if such a node exists and the given version matches the version of the node. :param path: Path for the node. :param acls: List of :class:`~kazoo.security.ACL` objects to set. :param version: The expected node version that must match. :returns: The stat of the node. :raises: :exc:`~kazoo.exceptions.BadVersionError` if version doesn't match. :exc:`~kazoo.exceptions.NoNodeError` if the node doesn't exist. :exc:`~kazoo.exceptions.InvalidACLError` if the ACL is invalid. :exc:`~kazoo.exceptions.ZookeeperError` if the server returns a non-zero error code. .. versionadded:: 0.5 """ return self.set_acls_async(path, acls, version).get()
[ "def", "set_acls", "(", "self", ",", "path", ",", "acls", ",", "version", "=", "-", "1", ")", ":", "return", "self", ".", "set_acls_async", "(", "path", ",", "acls", ",", "version", ")", ".", "get", "(", ")" ]
https://github.com/python-zk/kazoo/blob/f585d605eea0a37a08aae95a8cc259b80da2ecf0/kazoo/client.py#L1277-L1304
glumpy/glumpy
46a7635c08d3a200478397edbe0371a6c59cd9d7
glumpy/gloo/snippet.py
python
Snippet.next
(self)
return None
Next snippet in the arihmetic chain.
Next snippet in the arihmetic chain.
[ "Next", "snippet", "in", "the", "arihmetic", "chain", "." ]
def next(self): """ Next snippet in the arihmetic chain. """ if self._next: return self._next[1] return None
[ "def", "next", "(", "self", ")", ":", "if", "self", ".", "_next", ":", "return", "self", ".", "_next", "[", "1", "]", "return", "None" ]
https://github.com/glumpy/glumpy/blob/46a7635c08d3a200478397edbe0371a6c59cd9d7/glumpy/gloo/snippet.py#L193-L198
huggingface/transformers
623b4f7c63f60cce917677ee704d6c93ee960b4b
examples/legacy/pytorch-lightning/lightning_base.py
python
BaseTransformer.setup
(self, mode)
[]
def setup(self, mode): if mode == "test": self.dataset_size = len(self.test_dataloader().dataset) else: self.train_loader = self.get_dataloader("train", self.hparams.train_batch_size, shuffle=True) self.dataset_size = len(self.train_dataloader().dataset)
[ "def", "setup", "(", "self", ",", "mode", ")", ":", "if", "mode", "==", "\"test\"", ":", "self", ".", "dataset_size", "=", "len", "(", "self", ".", "test_dataloader", "(", ")", ".", "dataset", ")", "else", ":", "self", ".", "train_loader", "=", "self...
https://github.com/huggingface/transformers/blob/623b4f7c63f60cce917677ee704d6c93ee960b4b/examples/legacy/pytorch-lightning/lightning_base.py#L170-L175
SanPen/GridCal
d3f4566d2d72c11c7e910c9d162538ef0e60df31
src/GridCal/Engine/Simulations/LinearFactors/linear_analysis_ts_driver.py
python
LinearAnalysisTimeSeries.run
(self)
Run the time series simulation @return:
Run the time series simulation
[ "Run", "the", "time", "series", "simulation" ]
def run(self): """ Run the time series simulation @return: """ self.__cancel__ = False a = time.time() if self.end_ is None: self.end_ = len(self.grid.time_profile) time_indices = np.arange(self.start_, self.end_ + 1) ts_numeric_circuit = compile_time_circuit(self.grid) self.results = LinearAnalysisTimeSeriesResults(n=ts_numeric_circuit.nbus, m=ts_numeric_circuit.nbr, time_array=ts_numeric_circuit.time_array[time_indices], bus_names=ts_numeric_circuit.bus_names, bus_types=ts_numeric_circuit.bus_types, branch_names=ts_numeric_circuit.branch_names) self.indices = pd.to_datetime(ts_numeric_circuit.time_array[time_indices]) self.progress_text.emit('Computing PTDF...') linear_analysis = LinearAnalysis(grid=self.grid, distributed_slack=self.options.distribute_slack, correct_values=self.options.correct_values ) linear_analysis.run() self.progress_text.emit('Computing branch flows...') Pbus_0 = ts_numeric_circuit.Sbus.real[:, time_indices] self.results.Sf = linear_analysis.get_flows_time_series(Pbus_0) # compute post process self.results.loading = self.results.Sf / (ts_numeric_circuit.Rates[:, time_indices].T + 1e-9) self.results.S = Pbus_0.T self.elapsed = time.time() - a
[ "def", "run", "(", "self", ")", ":", "self", ".", "__cancel__", "=", "False", "a", "=", "time", ".", "time", "(", ")", "if", "self", ".", "end_", "is", "None", ":", "self", ".", "end_", "=", "len", "(", "self", ".", "grid", ".", "time_profile", ...
https://github.com/SanPen/GridCal/blob/d3f4566d2d72c11c7e910c9d162538ef0e60df31/src/GridCal/Engine/Simulations/LinearFactors/linear_analysis_ts_driver.py#L179-L217
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/combinat/binary_tree.py
python
BinaryTree.tamari_sorting_tuple
(self, reverse=False)
return (u1 + (n2,) + u2, n1 + 1 + n2)
r""" Return the Tamari sorting tuple of ``self`` and the size of ``self``. This is a pair `(w, n)`, where `n` is the number of nodes of ``self``, and `w` is an `n`-tuple whose `i`-th entry is the number of all nodes among the descendants of the right child of the `i`-th node of ``self``. Here, the nodes of ``self`` are numbered from left to right. INPUT: - ``reverse`` -- boolean (default ``False``) if ``True``, return instead the result for the left-right symmetric of the binary tree OUTPUT: a pair `(w, n)`, where `w` is a tuple of integers, and `n` the size Two binary trees of the same size are comparable in the Tamari order if and only if the associated tuples `w` are componentwise comparable. (This is essentially the Theorem in [HT1972]_.) This is used in :meth:`tamari_lequal`. EXAMPLES:: sage: [t.tamari_sorting_tuple() for t in BinaryTrees(3)] [((2, 1, 0), 3), ((2, 0, 0), 3), ((0, 1, 0), 3), ((1, 0, 0), 3), ((0, 0, 0), 3)] sage: t = BinaryTrees(10).random_element() sage: u = t.left_right_symmetry() sage: t.tamari_sorting_tuple(True) == u.tamari_sorting_tuple() True REFERENCES: - [HT1972]_
r""" Return the Tamari sorting tuple of ``self`` and the size of ``self``.
[ "r", "Return", "the", "Tamari", "sorting", "tuple", "of", "self", "and", "the", "size", "of", "self", "." ]
def tamari_sorting_tuple(self, reverse=False): r""" Return the Tamari sorting tuple of ``self`` and the size of ``self``. This is a pair `(w, n)`, where `n` is the number of nodes of ``self``, and `w` is an `n`-tuple whose `i`-th entry is the number of all nodes among the descendants of the right child of the `i`-th node of ``self``. Here, the nodes of ``self`` are numbered from left to right. INPUT: - ``reverse`` -- boolean (default ``False``) if ``True``, return instead the result for the left-right symmetric of the binary tree OUTPUT: a pair `(w, n)`, where `w` is a tuple of integers, and `n` the size Two binary trees of the same size are comparable in the Tamari order if and only if the associated tuples `w` are componentwise comparable. (This is essentially the Theorem in [HT1972]_.) This is used in :meth:`tamari_lequal`. EXAMPLES:: sage: [t.tamari_sorting_tuple() for t in BinaryTrees(3)] [((2, 1, 0), 3), ((2, 0, 0), 3), ((0, 1, 0), 3), ((1, 0, 0), 3), ((0, 0, 0), 3)] sage: t = BinaryTrees(10).random_element() sage: u = t.left_right_symmetry() sage: t.tamari_sorting_tuple(True) == u.tamari_sorting_tuple() True REFERENCES: - [HT1972]_ """ if not self: return tuple(), 0 if not reverse: t1, t2 = self else: t2, t1 = self u1, n1 = t1.tamari_sorting_tuple(reverse=reverse) u2, n2 = t2.tamari_sorting_tuple(reverse=reverse) return (u1 + (n2,) + u2, n1 + 1 + n2)
[ "def", "tamari_sorting_tuple", "(", "self", ",", "reverse", "=", "False", ")", ":", "if", "not", "self", ":", "return", "tuple", "(", ")", ",", "0", "if", "not", "reverse", ":", "t1", ",", "t2", "=", "self", "else", ":", "t2", ",", "t1", "=", "se...
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/combinat/binary_tree.py#L1408-L1463
xdress/xdress
eb7f0a02b3edf617d401939ede7f0d713a88917f
xdress/clang/cindex.py
python
Cursor.get_tokens
(self)
return TokenGroup.get_tokens(self._tu, self.extent)
Obtain Token instances formulating that compose this Cursor. This is a generator for Token instances. It returns all tokens which occupy the extent this cursor occupies.
Obtain Token instances formulating that compose this Cursor.
[ "Obtain", "Token", "instances", "formulating", "that", "compose", "this", "Cursor", "." ]
def get_tokens(self): """Obtain Token instances formulating that compose this Cursor. This is a generator for Token instances. It returns all tokens which occupy the extent this cursor occupies. """ return TokenGroup.get_tokens(self._tu, self.extent)
[ "def", "get_tokens", "(", "self", ")", ":", "return", "TokenGroup", ".", "get_tokens", "(", "self", ".", "_tu", ",", "self", ".", "extent", ")" ]
https://github.com/xdress/xdress/blob/eb7f0a02b3edf617d401939ede7f0d713a88917f/xdress/clang/cindex.py#L1533-L1539
JaniceWuo/MovieRecommend
4c86db64ca45598917d304f535413df3bc9fea65
movierecommend/users/views.py
python
UserBasedCF.generate_dataset
(self, filename2, pivot=1.0)
load rating data and split it to training set and test set
load rating data and split it to training set and test set
[ "load", "rating", "data", "and", "split", "it", "to", "training", "set", "and", "test", "set" ]
def generate_dataset(self, filename2, pivot=1.0): ''' load rating data and split it to training set and test set ''' trainset_len = 0 testset_len = 0 for line in self.loadfile(filename2): # user, movie, rating, _ = line.split('::') user, movie, rating = line.split(',') # split the data by pivot if random.random() < pivot: # pivot=0.7应该表示训练集:测试集=7:3 self.trainset.setdefault(user, {}) self.trainset[user][movie] = (rating) # trainset[user][movie]可以获取用户对电影的评分 都是整数 trainset_len += 1 else: self.testset.setdefault(user, {}) self.testset[user][movie] = (rating) testset_len += 1 print('split training set and test set succ', file=sys.stderr) print('train set = %s' % trainset_len, file=sys.stderr) print('test set = %s' % testset_len, file=sys.stderr)
[ "def", "generate_dataset", "(", "self", ",", "filename2", ",", "pivot", "=", "1.0", ")", ":", "trainset_len", "=", "0", "testset_len", "=", "0", "for", "line", "in", "self", ".", "loadfile", "(", "filename2", ")", ":", "# user, movie, rating, _ = line.split(':...
https://github.com/JaniceWuo/MovieRecommend/blob/4c86db64ca45598917d304f535413df3bc9fea65/movierecommend/users/views.py#L254-L274
AstroPrint/AstroBox
e7e3b8a7d33ea85fcb6b2696869c0d719ceb8b75
src/astroprint/software.py
python
SoftwareManager.restartServer
(self)
return True
[]
def restartServer(self): if platformStr == "linux" or platformStr == "linux2": actions = self._settings.get(["system", "actions"]) for a in actions: if a['action'] == 'reboot': #Call to Popen will start the restart command but return inmediately before it completes threading.Timer(1.0, subprocess.Popen, [a['command'].split(' ')]).start() self._logger.info('Restart command scheduled') from astroprint.printer.manager import printerManager from astroprint.camera import cameraManager from astroprint.network.manager import networkManagerShutdown #let's be nice about shutthing things down printerManager().disconnect() cameraManager().close_camera() networkManagerShutdown() return True return False return True
[ "def", "restartServer", "(", "self", ")", ":", "if", "platformStr", "==", "\"linux\"", "or", "platformStr", "==", "\"linux2\"", ":", "actions", "=", "self", ".", "_settings", ".", "get", "(", "[", "\"system\"", ",", "\"actions\"", "]", ")", "for", "a", "...
https://github.com/AstroPrint/AstroBox/blob/e7e3b8a7d33ea85fcb6b2696869c0d719ceb8b75/src/astroprint/software.py#L601-L623
IronLanguages/ironpython3
7a7bb2a872eeab0d1009fc8a6e24dca43f65b693
Src/StdLib/Lib/mailbox.py
python
_ProxyFile.tell
(self)
return self._pos
Return the position.
Return the position.
[ "Return", "the", "position", "." ]
def tell(self): """Return the position.""" return self._pos
[ "def", "tell", "(", "self", ")", ":", "return", "self", ".", "_pos" ]
https://github.com/IronLanguages/ironpython3/blob/7a7bb2a872eeab0d1009fc8a6e24dca43f65b693/Src/StdLib/Lib/mailbox.py#L1959-L1961
chribsen/simple-machine-learning-examples
dc94e52a4cebdc8bb959ff88b81ff8cfeca25022
venv/lib/python2.7/site-packages/scipy/integrate/quadrature.py
python
romberg
(function, a, b, args=(), tol=1.48e-8, rtol=1.48e-8, show=False, divmax=10, vec_func=False)
return result
Romberg integration of a callable function or method. Returns the integral of `function` (a function of one variable) over the interval (`a`, `b`). If `show` is 1, the triangular array of the intermediate results will be printed. If `vec_func` is True (default is False), then `function` is assumed to support vector arguments. Parameters ---------- function : callable Function to be integrated. a : float Lower limit of integration. b : float Upper limit of integration. Returns ------- results : float Result of the integration. Other Parameters ---------------- args : tuple, optional Extra arguments to pass to function. Each element of `args` will be passed as a single argument to `func`. Default is to pass no extra arguments. tol, rtol : float, optional The desired absolute and relative tolerances. Defaults are 1.48e-8. show : bool, optional Whether to print the results. Default is False. divmax : int, optional Maximum order of extrapolation. Default is 10. vec_func : bool, optional Whether `func` handles arrays as arguments (i.e whether it is a "vector" function). Default is False. See Also -------- fixed_quad : Fixed-order Gaussian quadrature. quad : Adaptive quadrature using QUADPACK. dblquad : Double integrals. tplquad : Triple integrals. romb : Integrators for sampled data. simps : Integrators for sampled data. cumtrapz : Cumulative integration for sampled data. ode : ODE integrator. odeint : ODE integrator. References ---------- .. [1] 'Romberg's method' http://en.wikipedia.org/wiki/Romberg%27s_method Examples -------- Integrate a gaussian from 0 to 1 and compare to the error function. >>> from scipy import integrate >>> from scipy.special import erf >>> gaussian = lambda x: 1/np.sqrt(np.pi) * np.exp(-x**2) >>> result = integrate.romberg(gaussian, 0, 1, show=True) Romberg integration of <function vfunc at ...> from [0, 1] :: Steps StepSize Results 1 1.000000 0.385872 2 0.500000 0.412631 0.421551 4 0.250000 0.419184 0.421368 0.421356 8 0.125000 0.420810 0.421352 0.421350 0.421350 16 0.062500 0.421215 0.421350 0.421350 0.421350 0.421350 32 0.031250 0.421317 0.421350 0.421350 0.421350 0.421350 0.421350 The final result is 0.421350396475 after 33 function evaluations. >>> print("%g %g" % (2*result, erf(1))) 0.842701 0.842701
Romberg integration of a callable function or method.
[ "Romberg", "integration", "of", "a", "callable", "function", "or", "method", "." ]
def romberg(function, a, b, args=(), tol=1.48e-8, rtol=1.48e-8, show=False, divmax=10, vec_func=False): """ Romberg integration of a callable function or method. Returns the integral of `function` (a function of one variable) over the interval (`a`, `b`). If `show` is 1, the triangular array of the intermediate results will be printed. If `vec_func` is True (default is False), then `function` is assumed to support vector arguments. Parameters ---------- function : callable Function to be integrated. a : float Lower limit of integration. b : float Upper limit of integration. Returns ------- results : float Result of the integration. Other Parameters ---------------- args : tuple, optional Extra arguments to pass to function. Each element of `args` will be passed as a single argument to `func`. Default is to pass no extra arguments. tol, rtol : float, optional The desired absolute and relative tolerances. Defaults are 1.48e-8. show : bool, optional Whether to print the results. Default is False. divmax : int, optional Maximum order of extrapolation. Default is 10. vec_func : bool, optional Whether `func` handles arrays as arguments (i.e whether it is a "vector" function). Default is False. See Also -------- fixed_quad : Fixed-order Gaussian quadrature. quad : Adaptive quadrature using QUADPACK. dblquad : Double integrals. tplquad : Triple integrals. romb : Integrators for sampled data. simps : Integrators for sampled data. cumtrapz : Cumulative integration for sampled data. ode : ODE integrator. odeint : ODE integrator. References ---------- .. [1] 'Romberg's method' http://en.wikipedia.org/wiki/Romberg%27s_method Examples -------- Integrate a gaussian from 0 to 1 and compare to the error function. >>> from scipy import integrate >>> from scipy.special import erf >>> gaussian = lambda x: 1/np.sqrt(np.pi) * np.exp(-x**2) >>> result = integrate.romberg(gaussian, 0, 1, show=True) Romberg integration of <function vfunc at ...> from [0, 1] :: Steps StepSize Results 1 1.000000 0.385872 2 0.500000 0.412631 0.421551 4 0.250000 0.419184 0.421368 0.421356 8 0.125000 0.420810 0.421352 0.421350 0.421350 16 0.062500 0.421215 0.421350 0.421350 0.421350 0.421350 32 0.031250 0.421317 0.421350 0.421350 0.421350 0.421350 0.421350 The final result is 0.421350396475 after 33 function evaluations. >>> print("%g %g" % (2*result, erf(1))) 0.842701 0.842701 """ if np.isinf(a) or np.isinf(b): raise ValueError("Romberg integration only available " "for finite limits.") vfunc = vectorize1(function, args, vec_func=vec_func) n = 1 interval = [a, b] intrange = b - a ordsum = _difftrap(vfunc, interval, n) result = intrange * ordsum resmat = [[result]] err = np.inf last_row = resmat[0] for i in xrange(1, divmax+1): n *= 2 ordsum += _difftrap(vfunc, interval, n) row = [intrange * ordsum / n] for k in xrange(i): row.append(_romberg_diff(last_row[k], row[k], k+1)) result = row[i] lastresult = last_row[i-1] if show: resmat.append(row) err = abs(result - lastresult) if err < tol or err < rtol * abs(result): break last_row = row else: warnings.warn( "divmax (%d) exceeded. Latest difference = %e" % (divmax, err), AccuracyWarning) if show: _printresmat(vfunc, interval, resmat) return result
[ "def", "romberg", "(", "function", ",", "a", ",", "b", ",", "args", "=", "(", ")", ",", "tol", "=", "1.48e-8", ",", "rtol", "=", "1.48e-8", ",", "show", "=", "False", ",", "divmax", "=", "10", ",", "vec_func", "=", "False", ")", ":", "if", "np"...
https://github.com/chribsen/simple-machine-learning-examples/blob/dc94e52a4cebdc8bb959ff88b81ff8cfeca25022/venv/lib/python2.7/site-packages/scipy/integrate/quadrature.py#L593-L710
MontrealCorpusTools/Montreal-Forced-Aligner
63473f9a4fabd31eec14e1e5022882f85cfdaf31
montreal_forced_aligner/helper.py
python
TerminalPrinter.indent_string
(self)
return " " * self.indent_size * self.indent_level
Indent string to use in formatting the output messages
Indent string to use in formatting the output messages
[ "Indent", "string", "to", "use", "in", "formatting", "the", "output", "messages" ]
def indent_string(self) -> str: """Indent string to use in formatting the output messages""" return " " * self.indent_size * self.indent_level
[ "def", "indent_string", "(", "self", ")", "->", "str", ":", "return", "\" \"", "*", "self", ".", "indent_size", "*", "self", ".", "indent_level" ]
https://github.com/MontrealCorpusTools/Montreal-Forced-Aligner/blob/63473f9a4fabd31eec14e1e5022882f85cfdaf31/montreal_forced_aligner/helper.py#L183-L185
galaxyproject/galaxy
4c03520f05062e0f4a1b3655dc0b7452fda69943
lib/galaxy/webapps/galaxy/api/pages.py
python
PagesController.share_with_users
(self, trans, id, payload, **kwd)
return self.service.shareable_service.share_with_users(trans, id, payload)
* PUT /api/pages/{id}/share_with_users
* PUT /api/pages/{id}/share_with_users
[ "*", "PUT", "/", "api", "/", "pages", "/", "{", "id", "}", "/", "share_with_users" ]
def share_with_users(self, trans, id, payload, **kwd): """ * PUT /api/pages/{id}/share_with_users """ payload = ShareWithPayload(**payload) return self.service.shareable_service.share_with_users(trans, id, payload)
[ "def", "share_with_users", "(", "self", ",", "trans", ",", "id", ",", "payload", ",", "*", "*", "kwd", ")", ":", "payload", "=", "ShareWithPayload", "(", "*", "*", "payload", ")", "return", "self", ".", "service", ".", "shareable_service", ".", "share_wi...
https://github.com/galaxyproject/galaxy/blob/4c03520f05062e0f4a1b3655dc0b7452fda69943/lib/galaxy/webapps/galaxy/api/pages.py#L349-L354
selfteaching/selfteaching-python-camp
9982ee964b984595e7d664b07c389cddaf158f1e
19100205/Ceasar1978/pip-19.0.3/src/pip/_internal/pep425tags.py
python
get_darwin_arches
(major, minor, machine)
return arches
Return a list of supported arches (including group arches) for the given major, minor and machine architecture of an macOS machine.
Return a list of supported arches (including group arches) for the given major, minor and machine architecture of an macOS machine.
[ "Return", "a", "list", "of", "supported", "arches", "(", "including", "group", "arches", ")", "for", "the", "given", "major", "minor", "and", "machine", "architecture", "of", "an", "macOS", "machine", "." ]
def get_darwin_arches(major, minor, machine): # type: (int, int, str) -> List[str] """Return a list of supported arches (including group arches) for the given major, minor and machine architecture of an macOS machine. """ arches = [] def _supports_arch(major, minor, arch): # type: (int, int, str) -> bool # Looking at the application support for macOS versions in the chart # provided by https://en.wikipedia.org/wiki/OS_X#Versions it appears # our timeline looks roughly like: # # 10.0 - Introduces ppc support. # 10.4 - Introduces ppc64, i386, and x86_64 support, however the ppc64 # and x86_64 support is CLI only, and cannot be used for GUI # applications. # 10.5 - Extends ppc64 and x86_64 support to cover GUI applications. # 10.6 - Drops support for ppc64 # 10.7 - Drops support for ppc # # Given that we do not know if we're installing a CLI or a GUI # application, we must be conservative and assume it might be a GUI # application and behave as if ppc64 and x86_64 support did not occur # until 10.5. # # Note: The above information is taken from the "Application support" # column in the chart not the "Processor support" since I believe # that we care about what instruction sets an application can use # not which processors the OS supports. if arch == 'ppc': return (major, minor) <= (10, 5) if arch == 'ppc64': return (major, minor) == (10, 5) if arch == 'i386': return (major, minor) >= (10, 4) if arch == 'x86_64': return (major, minor) >= (10, 5) if arch in groups: for garch in groups[arch]: if _supports_arch(major, minor, garch): return True return False groups = OrderedDict([ ("fat", ("i386", "ppc")), ("intel", ("x86_64", "i386")), ("fat64", ("x86_64", "ppc64")), ("fat32", ("x86_64", "i386", "ppc")), ]) # type: Dict[str, Tuple[str, ...]] if _supports_arch(major, minor, machine): arches.append(machine) for garch in groups: if machine in groups[garch] and _supports_arch(major, minor, garch): arches.append(garch) arches.append('universal') return arches
[ "def", "get_darwin_arches", "(", "major", ",", "minor", ",", "machine", ")", ":", "# type: (int, int, str) -> List[str]", "arches", "=", "[", "]", "def", "_supports_arch", "(", "major", ",", "minor", ",", "arch", ")", ":", "# type: (int, int, str) -> bool", "# Loo...
https://github.com/selfteaching/selfteaching-python-camp/blob/9982ee964b984595e7d664b07c389cddaf158f1e/19100205/Ceasar1978/pip-19.0.3/src/pip/_internal/pep425tags.py#L199-L259
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/xbox/media_player.py
python
XboxMediaPlayer.media_image_remotely_accessible
(self)
return True
If the image url is remotely accessible.
If the image url is remotely accessible.
[ "If", "the", "image", "url", "is", "remotely", "accessible", "." ]
def media_image_remotely_accessible(self) -> bool: """If the image url is remotely accessible.""" return True
[ "def", "media_image_remotely_accessible", "(", "self", ")", "->", "bool", ":", "return", "True" ]
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/xbox/media_player.py#L159-L161
openshift/openshift-tools
1188778e728a6e4781acf728123e5b356380fe6f
openshift/installer/vendored/openshift-ansible-3.9.14-1/roles/lib_openshift/library/oc_version.py
python
Yedit.delete
(self, path, index=None, value=None)
return (True, self.yaml_dict)
remove path from a dict
remove path from a dict
[ "remove", "path", "from", "a", "dict" ]
def delete(self, path, index=None, value=None): ''' remove path from a dict''' try: entry = Yedit.get_entry(self.yaml_dict, path, self.separator) except KeyError: entry = None if entry is None: return (False, self.yaml_dict) result = Yedit.remove_entry(self.yaml_dict, path, index, value, self.separator) if not result: return (False, self.yaml_dict) return (True, self.yaml_dict)
[ "def", "delete", "(", "self", ",", "path", ",", "index", "=", "None", ",", "value", "=", "None", ")", ":", "try", ":", "entry", "=", "Yedit", ".", "get_entry", "(", "self", ".", "yaml_dict", ",", "path", ",", "self", ".", "separator", ")", "except"...
https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/openshift/installer/vendored/openshift-ansible-3.9.14-1/roles/lib_openshift/library/oc_version.py#L443-L457
JacquesLucke/animation_nodes
b1e3ace8dcb0a771fd882fc3ac4e490b009fa0d1
animation_nodes/sockets/sequence.py
python
SequenceSocket.assignActiveSequence
(self)
[]
def assignActiveSequence(self): sequenceEditor = self.nodeTree.scene.sequence_editor if not sequenceEditor: return sequence = sequenceEditor.active_strip if sequence: self.sequenceName = sequence.name
[ "def", "assignActiveSequence", "(", "self", ")", ":", "sequenceEditor", "=", "self", ".", "nodeTree", ".", "scene", ".", "sequence_editor", "if", "not", "sequenceEditor", ":", "return", "sequence", "=", "sequenceEditor", ".", "active_strip", "if", "sequence", ":...
https://github.com/JacquesLucke/animation_nodes/blob/b1e3ace8dcb0a771fd882fc3ac4e490b009fa0d1/animation_nodes/sockets/sequence.py#L39-L45
Mergifyio/mergify-engine
3a7a0a63927740d67fb58430182cf75a0511ddd3
mergify_engine/duplicate_pull.py
python
duplicate
( ctxt: context.Context, branch_name: github_types.GitHubRefType, *, title_template: str, body_template: str, bot_account: typing.Optional[github_types.GitHubLogin] = None, labels: typing.Optional[List[str]] = None, label_conflicts: typing.Optional[str] = None, ignore_conflicts: bool = False, assignees: typing.Optional[List[str]] = None, branch_prefix: str = "bp", )
return duplicate_pr
Duplicate a pull request. :param pull: The pull request. :type pull: py:class:mergify_engine.context.Context :param title_template: The pull request title template. :param body_template: The pull request body template. :param branch: The branch to copy to. :param labels: The list of labels to add to the created PR. :param label_conflicts: The label to add to the created PR when cherry-pick failed. :param ignore_conflicts: Whether to commit the result if the cherry-pick fails. :param assignees: The list of users to be assigned to the created PR. :param branch_prefix: the prefix of the temporary created branch
Duplicate a pull request.
[ "Duplicate", "a", "pull", "request", "." ]
async def duplicate( ctxt: context.Context, branch_name: github_types.GitHubRefType, *, title_template: str, body_template: str, bot_account: typing.Optional[github_types.GitHubLogin] = None, labels: typing.Optional[List[str]] = None, label_conflicts: typing.Optional[str] = None, ignore_conflicts: bool = False, assignees: typing.Optional[List[str]] = None, branch_prefix: str = "bp", ) -> typing.Optional[github_types.GitHubPullRequest]: """Duplicate a pull request. :param pull: The pull request. :type pull: py:class:mergify_engine.context.Context :param title_template: The pull request title template. :param body_template: The pull request body template. :param branch: The branch to copy to. :param labels: The list of labels to add to the created PR. :param label_conflicts: The label to add to the created PR when cherry-pick failed. :param ignore_conflicts: Whether to commit the result if the cherry-pick fails. :param assignees: The list of users to be assigned to the created PR. :param branch_prefix: the prefix of the temporary created branch """ bp_branch = get_destination_branch_name( ctxt.pull["number"], branch_name, branch_prefix ) cherry_pick_error: str = "" bot_account_user: typing.Optional[UserTokensUser] = None if bot_account is not None: user_tokens = await ctxt.repository.installation.get_user_tokens() bot_account_user = user_tokens.get_token_for(bot_account) if not bot_account_user: raise DuplicateFailed( f"User `{bot_account}` is unknown. " f"Please make sure `{bot_account}` has logged in Mergify dashboard." ) # TODO(sileht): This can be done with the Github API only I think: # An example: # https://github.com/shiqiyang-okta/ghpick/blob/master/ghpick/cherry.py git = gitter.Gitter(ctxt.log) try: await git.init() if bot_account_user is None: token = await ctxt.client.get_access_token() await git.configure() username = "x-access-token" password = token else: await git.configure( bot_account_user["name"] or bot_account_user["login"], bot_account_user["email"], ) username = bot_account_user["oauth_access_token"] password = "" # nosec await git.setup_remote("origin", ctxt.pull["base"]["repo"], username, password) await git("fetch", "--quiet", "origin", f"pull/{ctxt.pull['number']}/head") await git("fetch", "--quiet", "origin", ctxt.pull["base"]["ref"]) await git("fetch", "--quiet", "origin", branch_name) await git("checkout", "--quiet", "-b", bp_branch, f"origin/{branch_name}") merge_commit = github_types.to_cached_github_branch_commit( typing.cast( github_types.GitHubBranchCommit, await ctxt.client.item( f"{ctxt.base_url}/commits/{ctxt.pull['merge_commit_sha']}" ), ) ) for commit in await _get_commits_to_cherrypick(ctxt, merge_commit): # FIXME(sileht): Github does not allow to fetch only one commit # So we have to fetch the branch since the commit date ... # git("fetch", "origin", "%s:refs/remotes/origin/%s-commit" % # (commit["sha"], commit["sha"]) # ) # last_commit_date = commit["commit"]["committer"]["date"] # git("fetch", "origin", ctxt.pull["base"]["ref"], # "--shallow-since='%s'" % last_commit_date) try: await git("cherry-pick", "-x", commit["sha"]) except ( gitter.GitAuthenticationFailure, gitter.GitErrorRetriable, gitter.GitFatalError, ): raise except gitter.GitError as e: # pragma: no cover for message in GIT_MESSAGE_TO_EXCEPTION.keys(): if message in e.output: raise ctxt.log.info("fail to cherry-pick %s: %s", commit["sha"], e.output) output = await git("status") cherry_pick_error += f"Cherry-pick of {commit['sha']} has failed:\n```\n{output}```\n\n\n" if not ignore_conflicts: raise DuplicateFailed(cherry_pick_error) await git("add", "*") await git("commit", "-a", "--no-edit", "--allow-empty") await git("push", "origin", bp_branch) except gitter.GitMergifyNamespaceConflict as e: raise DuplicateUnexpectedError( "`Mergify uses `mergify/...` namespace for creating temporary branches. " "A branch of your repository is conflicting with this namespace\n" f"```\n{e.output}\n```\n" ) except gitter.GitAuthenticationFailure as e: if bot_account_user is None: # Need to get a new token raise DuplicateNeedRetry( f"Git reported the following error:\n```\n{e.output}\n```\n" ) else: raise DuplicateUnexpectedError( f"Git reported the following error:\n```\n{e.output}\n```\n" ) except gitter.GitErrorRetriable as e: raise DuplicateNeedRetry( f"Git reported the following error:\n```\n{e.output}\n```\n" ) except gitter.GitFatalError as e: raise DuplicateUnexpectedError( f"Git reported the following error:\n```\n{e.output}\n```\n" ) except gitter.GitError as e: # pragma: no cover for message, out_exception in GIT_MESSAGE_TO_EXCEPTION.items(): if message in e.output: raise out_exception( f"Git reported the following error:\n```\n{e.output}\n```\n" ) ctxt.log.error( "duplicate pull failed", output=e.output, returncode=e.returncode, exc_info=True, ) raise DuplicateUnexpectedError(e.output) finally: await git.cleanup() if cherry_pick_error: cherry_pick_error += ( "To fix up this pull request, you can check it out locally. " "See documentation: " "https://docs.github.com/en/github/" "collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally" ) try: title = await ctxt.pull_request.render_template( title_template, extra_variables={"destination_branch": branch_name}, ) except context.RenderTemplateFailure as rmf: raise DuplicateFailed(f"Invalid title message: {rmf}") try: body = await ctxt.pull_request.render_template( body_template, extra_variables={ "destination_branch": branch_name, "cherry_pick_error": cherry_pick_error, }, ) except context.RenderTemplateFailure as rmf: raise DuplicateFailed(f"Invalid title message: {rmf}") try: duplicate_pr = typing.cast( github_types.GitHubPullRequest, ( await ctxt.client.post( f"{ctxt.base_url}/pulls", json={ "title": title, "body": body + "\n\n---\n\n" + constants.MERGIFY_PULL_REQUEST_DOC, "base": branch_name, "head": bp_branch, }, oauth_token=bot_account_user["oauth_access_token"] if bot_account_user else None, ) ).json(), ) except http.HTTPClientSideError as e: if e.status_code == 422 and "No commits between" in e.message: if cherry_pick_error: raise DuplicateFailed(cherry_pick_error) else: raise DuplicateNotNeeded(e.message) raise effective_labels = [] if labels is not None: effective_labels.extend(labels) if cherry_pick_error and label_conflicts is not None: effective_labels.append(label_conflicts) if len(effective_labels) > 0: await ctxt.client.post( f"{ctxt.base_url}/issues/{duplicate_pr['number']}/labels", json={"labels": effective_labels}, ) if assignees is not None and len(assignees) > 0: # NOTE(sileht): we don't have to deal with invalid assignees as GitHub # just ignore them and always return 201 await ctxt.client.post( f"{ctxt.base_url}/issues/{duplicate_pr['number']}/assignees", json={"assignees": assignees}, ) return duplicate_pr
[ "async", "def", "duplicate", "(", "ctxt", ":", "context", ".", "Context", ",", "branch_name", ":", "github_types", ".", "GitHubRefType", ",", "*", ",", "title_template", ":", "str", ",", "body_template", ":", "str", ",", "bot_account", ":", "typing", ".", ...
https://github.com/Mergifyio/mergify-engine/blob/3a7a0a63927740d67fb58430182cf75a0511ddd3/mergify_engine/duplicate_pull.py#L216-L440
oracle/graalpython
577e02da9755d916056184ec441c26e00b70145c
graalpython/lib-python/3/idlelib/configdialog.py
python
ConfigDialog.deactivate_current_config
(self)
Remove current key bindings. Iterate over window instances defined in parent and remove the keybindings.
Remove current key bindings. Iterate over window instances defined in parent and remove the keybindings.
[ "Remove", "current", "key", "bindings", ".", "Iterate", "over", "window", "instances", "defined", "in", "parent", "and", "remove", "the", "keybindings", "." ]
def deactivate_current_config(self): """Remove current key bindings. Iterate over window instances defined in parent and remove the keybindings. """ # Before a config is saved, some cleanup of current # config must be done - remove the previous keybindings. win_instances = self.parent.instance_dict.keys() for instance in win_instances: instance.RemoveKeybindings()
[ "def", "deactivate_current_config", "(", "self", ")", ":", "# Before a config is saved, some cleanup of current", "# config must be done - remove the previous keybindings.", "win_instances", "=", "self", ".", "parent", ".", "instance_dict", ".", "keys", "(", ")", "for", "inst...
https://github.com/oracle/graalpython/blob/577e02da9755d916056184ec441c26e00b70145c/graalpython/lib-python/3/idlelib/configdialog.py#L217-L226
SoCo/SoCo
e83fef84d2645d05265dbd574598518655a9c125
soco/core.py
python
SoCo.switch_to_line_in
(self, source=None)
Switch the speaker's input to line-in. Args: source (SoCo): The speaker whose line-in should be played. Default is line-in from the speaker itself.
Switch the speaker's input to line-in.
[ "Switch", "the", "speaker", "s", "input", "to", "line", "-", "in", "." ]
def switch_to_line_in(self, source=None): """Switch the speaker's input to line-in. Args: source (SoCo): The speaker whose line-in should be played. Default is line-in from the speaker itself. """ if source: uid = source.uid else: uid = self.uid self.avTransport.SetAVTransportURI( [ ("InstanceID", 0), ("CurrentURI", "x-rincon-stream:{}".format(uid)), ("CurrentURIMetaData", ""), ] )
[ "def", "switch_to_line_in", "(", "self", ",", "source", "=", "None", ")", ":", "if", "source", ":", "uid", "=", "source", ".", "uid", "else", ":", "uid", "=", "self", ".", "uid", "self", ".", "avTransport", ".", "SetAVTransportURI", "(", "[", "(", "\...
https://github.com/SoCo/SoCo/blob/e83fef84d2645d05265dbd574598518655a9c125/soco/core.py#L1650-L1668
Tuhinshubhra/CMSeeK
d22deab1e22cebd458af9d69e57f6e276ec11e84
deepscans/wp/init.py
python
start
(id, url, ua, ga, source, detection_method)
return
id = ID of the cms url = URL of target ua = User Agent ga = [0/1] is GENERATOR meta tag available source = source code
id = ID of the cms url = URL of target ua = User Agent ga = [0/1] is GENERATOR meta tag available source = source code
[ "id", "=", "ID", "of", "the", "cms", "url", "=", "URL", "of", "target", "ua", "=", "User", "Agent", "ga", "=", "[", "0", "/", "1", "]", "is", "GENERATOR", "meta", "tag", "available", "source", "=", "source", "code" ]
def start(id, url, ua, ga, source, detection_method): ''' id = ID of the cms url = URL of target ua = User Agent ga = [0/1] is GENERATOR meta tag available source = source code ''' ## Do shits later [update from later: i forgot what shit i had to do ;___;] if id == "wp": # referenced before assignment fix vulnss = version = wpvdbres = result = plugins_found = usernames = usernamesgen = '0' cmseek.statement('Starting WordPress DeepScan') # Check if site really is WordPress if detection_method == 'source': # well most of the wordpress false positives are from source detections. cmseek.statement('Checking if the detection is false positive') temp_domain = re.findall('^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n\?\=]+)', url)[0] wp_match_pattern = temp_domain + '\/wp-(content|include|admin)\/' if not re.search(wp_match_pattern, source): cmseek.error('Detection was false positive! CMSeeK is quitting!') cmseek.success('Run CMSeeK with {0}{1}{2} argument next time'.format(cmseek.fgreen, '--ignore-cms wp', cmseek.cln)) #cmseek.handle_quit() return # Version detection version = wordpress_version_detect.start(id, url, ua, ga, source) ## Check for minor stuffs like licesnse readme and some open directory checks cmseek.statement("Initiating open directory and files check") ## Readme.html readmesrc = cmseek.getsource(url + '/readme.html', ua) if readmesrc[0] != '1': ## something went wrong while getting the source codes cmseek.statement("Couldn't get readme file's source code most likely it's not present") readmefile = '0' # Error Getting Readme file elif 'Welcome. WordPress is a very special project to me.' in readmesrc[1]: readmefile = '1' # Readme file present else: readmefile = '2' # Readme file found but most likely it's not of wordpress ## license.txt licsrc = cmseek.getsource(url + '/license.txt', ua) if licsrc[0] != '1': cmseek.statement('license file not found') licfile = '0' elif 'WordPress - Web publishing software' in licsrc[1]: licfile = '1' else: licfile = '2' ## wp-content/uploads/ folder wpupsrc = cmseek.getsource(url + '/wp-content/uploads/', ua) if wpupsrc[0] != '1': wpupdir = '0' elif 'Index of /wp-content/uploads' in wpupsrc[1]: wpupdir = '1' else: wpupdir = '2' ## xmlrpc xmlrpcsrc = cmseek.getsource(url + '/xmlrpc.php', ua) if xmlrpcsrc[0] != '1': cmseek.statement('XML-RPC interface not available') xmlrpc = '0' elif 'XML-RPC server accepts POST requests only.' in xmlrpcsrc[1]: xmlrpc = '1' else: xmlrpc = '2' ## Path disclosure cmseek.statement('Looking for potential path disclosure') path = path_disclosure.start(url, ua) if path != "": cmseek.success('Path disclosure detected, path: ' + cmseek.bold + path + cmseek.cln) ## Check for user registration usereg = check_reg.start(url,ua) reg_found = usereg[0] reg_url = usereg[1] ## Plugins Enumeration plug_enum = wp_plugins_enum.start(source) plugins_found = plug_enum[0] plugins = plug_enum[1] ## Themes Enumeration theme_enum = wp_theme_enum.start(source,url,ua) themes_found = theme_enum[0] themes = theme_enum[1] ## User enumeration uenum = wp_user_enum.start(id, url, ua, ga, source) usernamesgen = uenum[0] usernames = uenum[1] ## Version Vulnerability Detection if version != '0': version_vuln = wp_vuln_scan.start(version, ua) wpvdbres = version_vuln[0] result = version_vuln[1] if wpvdbres != '0' and version != '0': vulnss = len(result['vulnerabilities']) vfc = version_vuln[2] ### Deep Scan Results comes here comptime = round(time.time() - cmseek.cstart, 2) log_file = os.path.join(cmseek.log_dir, 'cms.json') cmseek.clearscreen() cmseek.banner("Deep Scan Results") sresult.target(url) sresult.cms('WordPress', version, 'https://wordpress.org') #cmseek.result("Detected CMS: ", 'WordPress') cmseek.update_log('cms_name','WordPress') # update log #cmseek.result("CMS URL: ", "https://wordpress.org") cmseek.update_log('cms_url', "https://wordpress.org") # update log sresult.menu('[WordPress Deepscan]') item_initiated = False item_ended = False if readmefile == '1': sresult.init_item("Readme file found: " + cmseek.fgreen + url + '/readme.html' + cmseek.cln) cmseek.update_log('wp_readme_file',url + '/readme.html') item_initiated = True if licfile == '1': cmseek.update_log('wp_license', url + '/license.txt') if item_initiated == False: sresult.init_item("License file: " + cmseek.fgreen + url + '/license.txt' + cmseek.cln) else: sresult.item("License file: " + cmseek.fgreen + url + '/license.txt' + cmseek.cln) if wpvdbres == '1': if item_initiated == False: sresult.init_item('Changelog: ' + cmseek.fgreen + str(result['changelog_url']) + cmseek.cln) else: sresult.item('Changelog: ' + cmseek.fgreen + str(result['changelog_url']) + cmseek.cln) cmseek.update_log('wp_changelog_file',str(result['changelog_url'])) if wpupdir == '1': cmseek.update_log('wp_uploads_directory',url + '/wp-content/uploads') if item_initiated == False: sresult.init_item("Uploads directory has listing enabled: " + cmseek.fgreen + url + '/wp-content/uploads' + cmseek.cln) else: sresult.item("Uploads directory has listing enabled: " + cmseek.fgreen + url + '/wp-content/uploads' + cmseek.cln) if xmlrpc == '1': cmseek.update_log('xmlrpc', url + '/xmlrpc.php') if item_initiated == False: sresult.init_item("XML-RPC interface: "+ cmseek.fgreen + url + '/xmlrpc.php' + cmseek.cln) else: sresult.item("XML-RPC interface: " + cmseek.fgreen + url + '/xmlrpc.php' + cmseek.cln) if reg_found == '1': sresult.item('User registration enabled: ' + cmseek.bold + cmseek.fgreen + reg_url + cmseek.cln) cmseek.update_log('user_registration', reg_url) if path != "": sresult.item('Path disclosure: ' + cmseek.bold + cmseek.orange + path + cmseek.cln) cmseek.update_log('path', path) if plugins_found != 0: plugs_count = len(plugins) sresult.init_item("Plugins Enumerated: " + cmseek.bold + cmseek.fgreen + str(plugs_count) + cmseek.cln) wpplugs = "" for i, plugin in enumerate(plugins): plug = plugin.split(':') wpplugs = wpplugs + plug[0] + ' Version ' + plug[1] + ',' if i == 0 and i != plugs_count - 1: sresult.init_sub('Plugin: ' + cmseek.bold + cmseek.fgreen + plug[0] + cmseek.cln) sresult.init_subsub('Version: ' + cmseek.bold + cmseek.fgreen + plug[1] + cmseek.cln) sresult.end_subsub('URL: ' + cmseek.fgreen + url + '/wp-content/plugins/' + plug[0] + cmseek.cln) elif i == plugs_count - 1: sresult.empty_sub() sresult.end_sub('Plugin: ' + cmseek.bold + cmseek.fgreen + plug[0] + cmseek.cln) sresult.init_subsub('Version: ' + cmseek.bold + cmseek.fgreen + plug[1] + cmseek.cln, True, False) sresult.end_subsub('URL: ' + cmseek.fgreen + url + '/wp-content/plugins/' + plug[0] + cmseek.cln, True, False) else: sresult.empty_sub() sresult.sub_item('Plugin: ' + cmseek.bold + cmseek.fgreen + plug[0] + cmseek.cln) sresult.init_subsub('Version: ' + cmseek.bold + cmseek.fgreen + plug[1] + cmseek.cln) sresult.end_subsub('URL: ' + cmseek.fgreen + url + '/wp-content/plugins/' + plug[0] + cmseek.cln) cmseek.update_log('wp_plugins', wpplugs) sresult.empty_item() if themes_found != 0: thms_count = len(themes) sresult.init_item("Themes Enumerated: " + cmseek.bold + cmseek.fgreen + str(thms_count) + cmseek.cln) wpthms = "" for i,theme in enumerate(themes): thm = theme.split(':') thmz = thm[1].split('|') wpthms = wpthms + thm[0] + ' Version ' + thmz[0] + ',' if i == 0 and i != thms_count - 1: sresult.init_sub('Theme: ' + cmseek.bold + cmseek.fgreen + thm[0] + cmseek.cln) sresult.init_subsub('Version: ' + cmseek.bold + cmseek.fgreen + thmz[0] + cmseek.cln) if thmz[1] != '': sresult.subsub('Theme Zip: ' + cmseek.bold + cmseek.fgreen + url + thmz[1] + cmseek.cln) sresult.end_subsub('URL: ' + cmseek.fgreen + url + '/wp-content/themes/' + thm[0] + cmseek.cln) elif i == thms_count - 1: sresult.empty_sub(True) sresult.end_sub('Theme: ' + cmseek.bold + cmseek.fgreen + thm[0] + cmseek.cln) sresult.init_subsub('Version: ' + cmseek.bold + cmseek.fgreen + thmz[0] + cmseek.cln, True, False) if thmz[1] != '': sresult.subsub('Theme Zip: ' + cmseek.bold + cmseek.fgreen + url + thmz[1] + cmseek.cln, True, False) sresult.end_subsub('URL: ' + cmseek.fgreen + url + '/wp-content/themes/' + thm[0] + cmseek.cln, True, False) else: sresult.sub_item('Theme: ' + cmseek.bold + cmseek.fgreen + thm[0] + cmseek.cln) sresult.init_subsub('Version: ' + cmseek.bold + cmseek.fgreen + thmz[0] + cmseek.cln) if thmz[1] != '': sresult.subsub('Theme Zip: ' + cmseek.bold + cmseek.fgreen + url + thmz[1] + cmseek.cln) sresult.end_subsub('URL: ' + cmseek.fgreen + url + '/wp-content/themes/' + thm[0] + cmseek.cln) cmseek.update_log('wp_themes', wpthms) sresult.empty_item() if usernamesgen == '1': user_count = len(usernames) sresult.init_item("Usernames harvested: " + cmseek.bold + cmseek.fgreen + str(user_count) + cmseek.cln) wpunames = "" for i,u in enumerate(usernames): wpunames = wpunames + u + "," if i == 0 and i != user_count - 1: sresult.init_sub(cmseek.bold + cmseek.fgreen + u + cmseek.cln) elif i == user_count - 1: sresult.end_sub(cmseek.bold + cmseek.fgreen + u + cmseek.cln) else: sresult.sub_item(cmseek.bold + cmseek.fgreen + u + cmseek.cln) cmseek.update_log('wp_users', wpunames) sresult.empty_item() if version != '0': # cmseek.result("Version: ", version) cmseek.update_log('wp_version', version) if wpvdbres == '1': sresult.end_item('Version vulnerabilities: ' + cmseek.bold + cmseek.fgreen + str(vulnss) + cmseek.cln) cmseek.update_log('wp_vuln_count', str(vulnss)) cmseek.update_log("wp_vulns", result, False) if vulnss > 0: for i,vuln in enumerate(result['vulnerabilities']): if i == 0 and i != vulnss - 1: sresult.empty_sub(False) sresult.init_sub(cmseek.bold + cmseek.fgreen + str(vuln['name']) + cmseek.cln, False) # sresult.init_subsub("Type: " + cmseek.bold + cmseek.fgreen + str(vuln['vuln_type']) + cmseek.cln, False, True) # sresult.subsub("Link: " + cmseek.bold + cmseek.fgreen + "http://wpvulndb.com/vulnerabilities/" + str(vuln['id']) + cmseek.cln, False, True) strvuln = str(vuln) if vuln['cve'] != "": sresult.subsub("CVE: " + cmseek.fgreen + "http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-" + vuln["cve"] + cmseek.cln, False, True) ''' if 'exploitdb' in strvuln: for ref in vuln['references']['exploitdb']: sresult.subsub("ExploitDB Link: " + cmseek.fgreen + "http://www.exploit-db.com/exploits/" + str(ref) + cmseek.cln, False, True) if 'metasploit' in strvuln: for ref in vuln['references']['metasploit']: sresult.subsub("Metasploit Module: " + cmseek.fgreen + "http://www.metasploit.com/modules/" + str(ref) + cmseek.cln, False, True) if 'osvdb' in strvuln: for ref in vuln['references']['osvdb']: sresult.subsub("OSVDB Link: " + cmseek.fgreen + "http://osvdb.org/" + str(ref) + cmseek.cln, False, True) if 'secunia' in strvuln: for ref in vuln['references']['secunia']: sresult.subsub("Secunia Advisory: " + cmseek.fgreen + "http://secunia.com/advisories/" + str(ref) + cmseek.cln, False, True) if 'url' in strvuln: for ref in vuln['references']['url']: sresult.subsub("Reference: " + cmseek.fgreen + str(ref) + cmseek.cln, False, True) ''' if vuln["references"] != []: for ref in vuln["references"]: sresult.subsub("Reference: " + cmseek.fgreen + str(ref) + cmseek.cln, False, True) sresult.end_subsub("Fixed In Version: " + cmseek.bold + cmseek.fgreen + str(vuln['fixed_in']) + cmseek.cln, False, True) elif i == vulnss - 1: sresult.empty_sub(False) sresult.end_sub(cmseek.bold + cmseek.fgreen + str(vuln['name']) + cmseek.cln, False) # sresult.init_subsub("Type: " + cmseek.bold + cmseek.fgreen + str(vuln['vuln_type']) + cmseek.cln, False, False) # sresult.subsub("Link: " + cmseek.bold + cmseek.fgreen + "http://wpvulndb.com/vulnerabilities/" + str(vuln['id']) + cmseek.cln, False, False) strvuln = str(vuln) if vuln['cve'] != "": sresult.subsub("CVE: " + cmseek.fgreen + "http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-" + vuln["cve"] + cmseek.cln, False, False) if vuln["references"] != []: for ref in vuln["references"]: sresult.subsub("Reference: " + cmseek.fgreen + str(ref) + cmseek.cln, False, False) sresult.end_subsub("Fixed In Version: " + cmseek.bold + cmseek.fgreen + str(vuln['fixed_in']) + cmseek.cln, False, False) else: sresult.empty_sub(False) sresult.sub_item(cmseek.bold + cmseek.fgreen + str(vuln['name']) + cmseek.cln, False) #sresult.init_subsub("Type: " + cmseek.bold + cmseek.fgreen + str(vuln['vuln_type']) + cmseek.cln, False, True) #sresult.subsub("Link: " + cmseek.bold + cmseek.fgreen + "http://wpvulndb.com/vulnerabilities/" + str(vuln['id']) + cmseek.cln, False, True) strvuln = str(vuln) if vuln['cve'] != "": sresult.subsub("CVE: " + cmseek.fgreen + "http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-" + str(ref) + cmseek.cln, False, True) if vuln["references"] != []: for ref in vuln["references"]: sresult.subsub("Reference: " + cmseek.fgreen + str(ref) + cmseek.cln, False, True) sresult.end_subsub("Fixed In Version: " + cmseek.bold + cmseek.fgreen + str(vuln['fixed_in']) + cmseek.cln, False, True) sresult.end(str(cmseek.total_requests), str(comptime), log_file) return return
[ "def", "start", "(", "id", ",", "url", ",", "ua", ",", "ga", ",", "source", ",", "detection_method", ")", ":", "## Do shits later [update from later: i forgot what shit i had to do ;___;]", "if", "id", "==", "\"wp\"", ":", "# referenced before assignment fix", "vulnss",...
https://github.com/Tuhinshubhra/CMSeeK/blob/d22deab1e22cebd458af9d69e57f6e276ec11e84/deepscans/wp/init.py#L21-L340
hypothesis/h
25ef1b8d94889df86ace5a084f1aa0effd9f4e25
h/streamer/websocket.py
python
handle_message
(message, session=None)
Handle an incoming message from a client websocket. Receives a :py:class:`~h.streamer.websocket.Message` instance, which holds references to the :py:class:`~h.streamer.websocket.WebSocket` instance associated with the client connection, as well as the message payload. It updates state on the :py:class:`~h.streamer.websocket.WebSocket` instance in response to the message content. It may also passed a database session which *must* be used for any communication with the database.
Handle an incoming message from a client websocket.
[ "Handle", "an", "incoming", "message", "from", "a", "client", "websocket", "." ]
def handle_message(message, session=None): """ Handle an incoming message from a client websocket. Receives a :py:class:`~h.streamer.websocket.Message` instance, which holds references to the :py:class:`~h.streamer.websocket.WebSocket` instance associated with the client connection, as well as the message payload. It updates state on the :py:class:`~h.streamer.websocket.WebSocket` instance in response to the message content. It may also passed a database session which *must* be used for any communication with the database. """ payload = message.payload type_ = payload.get("type") # FIXME: This code is here to tolerate old and deprecated message formats. if type_ is None: if "messageType" in payload and payload["messageType"] == "client_id": type_ = "client_id" if "filter" in payload: type_ = "filter" # N.B. MESSAGE_HANDLERS[None] handles both incorrect and missing message # types. handler = MESSAGE_HANDLERS.get(type_, MESSAGE_HANDLERS[None]) handler(message, session=session)
[ "def", "handle_message", "(", "message", ",", "session", "=", "None", ")", ":", "payload", "=", "message", ".", "payload", "type_", "=", "payload", ".", "get", "(", "\"type\"", ")", "# FIXME: This code is here to tolerate old and deprecated message formats.", "if", ...
https://github.com/hypothesis/h/blob/25ef1b8d94889df86ace5a084f1aa0effd9f4e25/h/streamer/websocket.py#L92-L119
IronLanguages/main
a949455434b1fda8c783289e897e78a9a0caabb5
External.LCA_RESTRICTED/Languages/IronPython/27/Lib/optparse.py
python
_match_abbrev
(s, wordmap)
_match_abbrev(s : string, wordmap : {string : Option}) -> string Return the string key in 'wordmap' for which 's' is an unambiguous abbreviation. If 's' is found to be ambiguous or doesn't match any of 'words', raise BadOptionError.
_match_abbrev(s : string, wordmap : {string : Option}) -> string
[ "_match_abbrev", "(", "s", ":", "string", "wordmap", ":", "{", "string", ":", "Option", "}", ")", "-", ">", "string" ]
def _match_abbrev(s, wordmap): """_match_abbrev(s : string, wordmap : {string : Option}) -> string Return the string key in 'wordmap' for which 's' is an unambiguous abbreviation. If 's' is found to be ambiguous or doesn't match any of 'words', raise BadOptionError. """ # Is there an exact match? if s in wordmap: return s else: # Isolate all words with s as a prefix. possibilities = [word for word in wordmap.keys() if word.startswith(s)] # No exact match, so there had better be just one possibility. if len(possibilities) == 1: return possibilities[0] elif not possibilities: raise BadOptionError(s) else: # More than one possible completion: ambiguous prefix. possibilities.sort() raise AmbiguousOptionError(s, possibilities)
[ "def", "_match_abbrev", "(", "s", ",", "wordmap", ")", ":", "# Is there an exact match?", "if", "s", "in", "wordmap", ":", "return", "s", "else", ":", "# Isolate all words with s as a prefix.", "possibilities", "=", "[", "word", "for", "word", "in", "wordmap", "...
https://github.com/IronLanguages/main/blob/a949455434b1fda8c783289e897e78a9a0caabb5/External.LCA_RESTRICTED/Languages/IronPython/27/Lib/optparse.py#L1675-L1697
triaquae/triaquae
bbabf736b3ba56a0c6498e7f04e16c13b8b8f2b9
TriAquae/models/Centos_5.9/paramiko/transport.py
python
Transport.add_server_key
(self, key)
Add a host key to the list of keys used for server mode. When behaving as a server, the host key is used to sign certain packets during the SSH2 negotiation, so that the client can trust that we are who we say we are. Because this is used for signing, the key must contain private key info, not just the public half. Only one key of each type (RSA or DSS) is kept. @param key: the host key to add, usually an L{RSAKey <rsakey.RSAKey>} or L{DSSKey <dsskey.DSSKey>}. @type key: L{PKey <pkey.PKey>}
Add a host key to the list of keys used for server mode. When behaving as a server, the host key is used to sign certain packets during the SSH2 negotiation, so that the client can trust that we are who we say we are. Because this is used for signing, the key must contain private key info, not just the public half. Only one key of each type (RSA or DSS) is kept.
[ "Add", "a", "host", "key", "to", "the", "list", "of", "keys", "used", "for", "server", "mode", ".", "When", "behaving", "as", "a", "server", "the", "host", "key", "is", "used", "to", "sign", "certain", "packets", "during", "the", "SSH2", "negotiation", ...
def add_server_key(self, key): """ Add a host key to the list of keys used for server mode. When behaving as a server, the host key is used to sign certain packets during the SSH2 negotiation, so that the client can trust that we are who we say we are. Because this is used for signing, the key must contain private key info, not just the public half. Only one key of each type (RSA or DSS) is kept. @param key: the host key to add, usually an L{RSAKey <rsakey.RSAKey>} or L{DSSKey <dsskey.DSSKey>}. @type key: L{PKey <pkey.PKey>} """ self.server_key_dict[key.get_name()] = key
[ "def", "add_server_key", "(", "self", ",", "key", ")", ":", "self", ".", "server_key_dict", "[", "key", ".", "get_name", "(", ")", "]", "=", "key" ]
https://github.com/triaquae/triaquae/blob/bbabf736b3ba56a0c6498e7f04e16c13b8b8f2b9/TriAquae/models/Centos_5.9/paramiko/transport.py#L535-L548
NordicSemiconductor/pc-nrfutil
d08e742128f2a3dac522601bc6b9f9b2b63952df
nordicsemi/lister/windows/structures.py
python
GUID.__str__
(self)
return str(self._guid)
[]
def __str__(self): return str(self._guid)
[ "def", "__str__", "(", "self", ")", ":", "return", "str", "(", "self", ".", "_guid", ")" ]
https://github.com/NordicSemiconductor/pc-nrfutil/blob/d08e742128f2a3dac522601bc6b9f9b2b63952df/nordicsemi/lister/windows/structures.py#L72-L73
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/lib/python2.7/site-packages/jinja2/loaders.py
python
DictLoader.get_source
(self, environment, template)
[]
def get_source(self, environment, template): if template in self.mapping: source = self.mapping[template] return source, None, lambda: source == self.mapping.get(template) raise TemplateNotFound(template)
[ "def", "get_source", "(", "self", ",", "environment", ",", "template", ")", ":", "if", "template", "in", "self", ".", "mapping", ":", "source", "=", "self", ".", "mapping", "[", "template", "]", "return", "source", ",", "None", ",", "lambda", ":", "sou...
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/lib/python2.7/site-packages/jinja2/loaders.py#L282-L286
jesseweisberg/moveo_ros
b9282bdadbf2505a26d3b94b91e60a98d86efa34
object_detector_app/object_detection/core/target_assigner.py
python
TargetAssigner._create_regression_targets
(self, anchors, groundtruth_boxes, match)
return reg_targets
Returns a regression target for each anchor. Args: anchors: a BoxList representing N anchors groundtruth_boxes: a BoxList representing M groundtruth_boxes match: a matcher.Match object Returns: reg_targets: a float32 tensor with shape [N, box_code_dimension]
Returns a regression target for each anchor.
[ "Returns", "a", "regression", "target", "for", "each", "anchor", "." ]
def _create_regression_targets(self, anchors, groundtruth_boxes, match): """Returns a regression target for each anchor. Args: anchors: a BoxList representing N anchors groundtruth_boxes: a BoxList representing M groundtruth_boxes match: a matcher.Match object Returns: reg_targets: a float32 tensor with shape [N, box_code_dimension] """ matched_anchor_indices = match.matched_column_indices() unmatched_ignored_anchor_indices = (match. unmatched_or_ignored_column_indices()) matched_gt_indices = match.matched_row_indices() matched_anchors = box_list_ops.gather(anchors, matched_anchor_indices) matched_gt_boxes = box_list_ops.gather(groundtruth_boxes, matched_gt_indices) matched_reg_targets = self._box_coder.encode(matched_gt_boxes, matched_anchors) unmatched_ignored_reg_targets = tf.tile( self._default_regression_target(), tf.stack([tf.size(unmatched_ignored_anchor_indices), 1])) reg_targets = tf.dynamic_stitch( [matched_anchor_indices, unmatched_ignored_anchor_indices], [matched_reg_targets, unmatched_ignored_reg_targets]) # TODO: summarize the number of matches on average. return reg_targets
[ "def", "_create_regression_targets", "(", "self", ",", "anchors", ",", "groundtruth_boxes", ",", "match", ")", ":", "matched_anchor_indices", "=", "match", ".", "matched_column_indices", "(", ")", "unmatched_ignored_anchor_indices", "=", "(", "match", ".", "unmatched_...
https://github.com/jesseweisberg/moveo_ros/blob/b9282bdadbf2505a26d3b94b91e60a98d86efa34/object_detector_app/object_detection/core/target_assigner.py#L184-L212
openshift/openshift-tools
1188778e728a6e4781acf728123e5b356380fe6f
openshift/installer/vendored/openshift-ansible-3.10.0-0.29.0/roles/lib_vendored_deps/library/openshift_container_binary_sync.py
python
BinarySyncer.raw_image
(self)
return self._image
Returns the image as it was originally passed in to the instance. .. note:: This image string will only work directly with the atomic command. :returns: The original image passed in. :rtype: str
Returns the image as it was originally passed in to the instance.
[ "Returns", "the", "image", "as", "it", "was", "originally", "passed", "in", "to", "the", "instance", "." ]
def raw_image(self): """ Returns the image as it was originally passed in to the instance. .. note:: This image string will only work directly with the atomic command. :returns: The original image passed in. :rtype: str """ return self._image
[ "def", "raw_image", "(", "self", ")", ":", "return", "self", ".", "_image" ]
https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/openshift/installer/vendored/openshift-ansible-3.10.0-0.29.0/roles/lib_vendored_deps/library/openshift_container_binary_sync.py#L148-L158
lixinsu/RCZoo
37fcb7962fbd4c751c561d4a0c84173881ea8339
reader/multi_fusionnet/vector.py
python
batchify
(batch)
return x1, x1_p, x1_e, x1_c, x1_mask, x2, x2_p, x2_e, x2_c, x2_mask, x1_f ,yy_s, yy_e, ids
Gather a batch of individual examples into one batch.
Gather a batch of individual examples into one batch.
[ "Gather", "a", "batch", "of", "individual", "examples", "into", "one", "batch", "." ]
def batchify(batch): """Gather a batch of individual examples into one batch.""" ids = [ex[-1] for ex in batch] docs = [ex[2] for ex in batch] dc = [ex[3] for ex in batch] dp = [ex[4] for ex in batch] de = [ex[5] for ex in batch] df = [ex[10] for ex in batch] word_len = dc[0].size(1) df = [ex[10] for ex in batch] questions = [ex[6] for ex in batch] qc = [ex[7] for ex in batch] qp = [ex[8] for ex in batch] qe = [ex[9] for ex in batch] # Batch documents and features max_length = max([dd.size(0) for dd in docs]) x1 = torch.LongTensor(len(docs), max_length).zero_() x1_p = torch.LongTensor(len(docs), max_length).zero_() x1_e = torch.LongTensor(len(docs), max_length).zero_() x1_c = torch.LongTensor(len(docs), max_length, word_len).zero_() if df[0] is None: x1_f = None else: x1_f = torch.zeros(len(docs), max_length, df[0].size(1)) x1_mask = torch.ByteTensor(len(docs), max_length).fill_(1) for i, d in enumerate(docs): x1[i, :d.size(0)].copy_(docs[i]) x1_p[i, :d.size(0)].copy_(dp[i]) x1_e[i, :d.size(0)].copy_(de[i]) x1_c[i, :d.size(0)].copy_(dc[i]) x1_f[i, :d.size(0)].copy_(df[i]) x1_mask[i, :d.size(0)].fill_(0) # Batch questions max_length = max([q.size(0) for q in questions]) x2 = torch.LongTensor(len(questions), max_length).zero_() x2_p = torch.LongTensor(len(questions), max_length).zero_() x2_e = torch.LongTensor(len(questions), max_length).zero_() x2_c = torch.LongTensor(len(questions), max_length, word_len).zero_() x2_mask = torch.ByteTensor(len(questions), max_length).fill_(1) for i, q in enumerate(questions): x2[i, :q.size(0)].copy_(questions[i]) x2_p[i, :q.size(0)].copy_(qp[i]) x2_e[i, :q.size(0)].copy_(qe[i]) x2_c[i, :q.size(0)].copy_(qc[i]) x2_mask[i, :q.size(0)].fill_(0) y_s = [ex[11] for ex in batch] y_e = [ex[12] for ex in batch] yy_s = torch.Tensor(len(docs), x1.size(1)).fill_(0) yy_e = torch.Tensor(len(docs), x1.size(1)).fill_(0) for i in range(len(batch)): for j in range(len(y_s[i])): yy_s[i,y_s[i][j]] = 1 yy_e[i,y_e[i][j]] = 1 return x1, x1_p, x1_e, x1_c, x1_mask, x2, x2_p, x2_e, x2_c, x2_mask, x1_f ,yy_s, yy_e, ids
[ "def", "batchify", "(", "batch", ")", ":", "ids", "=", "[", "ex", "[", "-", "1", "]", "for", "ex", "in", "batch", "]", "docs", "=", "[", "ex", "[", "2", "]", "for", "ex", "in", "batch", "]", "dc", "=", "[", "ex", "[", "3", "]", "for", "ex...
https://github.com/lixinsu/RCZoo/blob/37fcb7962fbd4c751c561d4a0c84173881ea8339/reader/multi_fusionnet/vector.py#L92-L156
man-group/mdf
4b2c78084467791ad883c0b4c53832ad70fc96ef
mdf/viewer/frame.py
python
MDFViewerFrame.GetRootContext
(self)
return ctx
returns the root context for use from PyCrust as 'get_ctx()'
returns the root context for use from PyCrust as 'get_ctx()'
[ "returns", "the", "root", "context", "for", "use", "from", "PyCrust", "as", "get_ctx", "()" ]
def GetRootContext(self): """ returns the root context for use from PyCrust as 'get_ctx()' """ tree = self._dag_tree data = tree.GetPyData(tree.GetRootItem()) if not data: return ctx, node = data return ctx
[ "def", "GetRootContext", "(", "self", ")", ":", "tree", "=", "self", ".", "_dag_tree", "data", "=", "tree", ".", "GetPyData", "(", "tree", ".", "GetRootItem", "(", ")", ")", "if", "not", "data", ":", "return", "ctx", ",", "node", "=", "data", "return...
https://github.com/man-group/mdf/blob/4b2c78084467791ad883c0b4c53832ad70fc96ef/mdf/viewer/frame.py#L640-L650
JaniceWuo/MovieRecommend
4c86db64ca45598917d304f535413df3bc9fea65
movierecommend/venv1/Lib/site-packages/pip-9.0.1-py3.6.egg/pip/_vendor/pkg_resources/__init__.py
python
Distribution.has_version
(self)
return True
[]
def has_version(self): try: self.version except ValueError: issue_warning("Unbuilt egg for " + repr(self)) return False return True
[ "def", "has_version", "(", "self", ")", ":", "try", ":", "self", ".", "version", "except", "ValueError", ":", "issue_warning", "(", "\"Unbuilt egg for \"", "+", "repr", "(", "self", ")", ")", "return", "False", "return", "True" ]
https://github.com/JaniceWuo/MovieRecommend/blob/4c86db64ca45598917d304f535413df3bc9fea65/movierecommend/venv1/Lib/site-packages/pip-9.0.1-py3.6.egg/pip/_vendor/pkg_resources/__init__.py#L2739-L2745
SigmaHQ/sigma
6f7d28b52a6468b2430e8d7dfefb79dc01e2f1af
tools/sigma/backends/mdatp.py
python
WindowsDefenderATPBackend.generateANDNode
(self, node)
[]
def generateANDNode(self, node): generated = [ self.generateNode(val) for val in node ] filtered = [] for g in generated: if g and g.startswith("ActionType"): if not any([i for i in filtered if i.startswith("ActionType")]): filtered.append(g) else: continue elif g is not None: filtered.append(g) if filtered: if self.sort_condition_lists: filtered = sorted(filtered) return self.andToken.join(filtered) else: return None
[ "def", "generateANDNode", "(", "self", ",", "node", ")", ":", "generated", "=", "[", "self", ".", "generateNode", "(", "val", ")", "for", "val", "in", "node", "]", "filtered", "=", "[", "]", "for", "g", "in", "generated", ":", "if", "g", "and", "g"...
https://github.com/SigmaHQ/sigma/blob/6f7d28b52a6468b2430e8d7dfefb79dc01e2f1af/tools/sigma/backends/mdatp.py#L173-L189
SpaceNetChallenge/SpaceNet_Off_Nadir_Solutions
014c4ca27a70b5907a183e942228004c989dcbe4
cannab/train50_9ch_fold.py
python
ValData.__init__
(self, image_ids)
[]
def __init__(self, image_ids): super().__init__() self.image_ids = image_ids
[ "def", "__init__", "(", "self", ",", "image_ids", ")", ":", "super", "(", ")", ".", "__init__", "(", ")", "self", ".", "image_ids", "=", "image_ids" ]
https://github.com/SpaceNetChallenge/SpaceNet_Off_Nadir_Solutions/blob/014c4ca27a70b5907a183e942228004c989dcbe4/cannab/train50_9ch_fold.py#L210-L212
JetBrains/python-skeletons
95ad24b666e475998e5d1cc02ed53a2188036167
py/path/__init__.py
python
LocalPath.setmtime
(self, mtime=None)
set modification time for the given path. if 'mtime' is None (the default) then the file's mtime is set to current time. Note that the resolution for 'mtime' is platform dependent.
set modification time for the given path. if 'mtime' is None (the default) then the file's mtime is set to current time.
[ "set", "modification", "time", "for", "the", "given", "path", ".", "if", "mtime", "is", "None", "(", "the", "default", ")", "then", "the", "file", "s", "mtime", "is", "set", "to", "current", "time", "." ]
def setmtime(self, mtime=None): """ set modification time for the given path. if 'mtime' is None (the default) then the file's mtime is set to current time. Note that the resolution for 'mtime' is platform dependent. """
[ "def", "setmtime", "(", "self", ",", "mtime", "=", "None", ")", ":" ]
https://github.com/JetBrains/python-skeletons/blob/95ad24b666e475998e5d1cc02ed53a2188036167/py/path/__init__.py#L280-L285
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/yeelightsunflower/light.py
python
SunflowerBulb.name
(self)
return f"sunflower_{self._light.zid}"
Return the display name of this light.
Return the display name of this light.
[ "Return", "the", "display", "name", "of", "this", "light", "." ]
def name(self): """Return the display name of this light.""" return f"sunflower_{self._light.zid}"
[ "def", "name", "(", "self", ")", ":", "return", "f\"sunflower_{self._light.zid}\"" ]
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/yeelightsunflower/light.py#L61-L63
googlecolab/colabtools
b7b3566363e2f0bad9ad256ae317314ba5bd42f8
google/colab/_tensorflow_magics.py
python
_TFVersionManager._set_version
(self, version)
Perform version change by manipulating PATH/PYTHONPATH.
Perform version change by manipulating PATH/PYTHONPATH.
[ "Perform", "version", "change", "by", "manipulating", "PATH", "/", "PYTHONPATH", "." ]
def _set_version(self, version): """Perform version change by manipulating PATH/PYTHONPATH.""" old_python_path = _get_python_path(self._version) new_python_path = _get_python_path(version) old_os_path = _get_os_path(self._version) new_os_path = _get_os_path(version) # Fix up `sys.path`, for Python imports within this process. _drop_and_prepend(sys.path, old_python_path, new_python_path) # Fix up `$PYTHONPATH`, for Python imports in subprocesses. _drop_and_prepend_env( "PYTHONPATH", old_python_path, new_python_path, empty_includes_cwd=False) # Fix up `$PATH`, for locations of subprocess binaries. _drop_and_prepend_env( "PATH", old_os_path, new_os_path, empty_includes_cwd=True) tf_version = _get_tf_version() self._maybe_switch_tpu_version(tf_version) self._version = version
[ "def", "_set_version", "(", "self", ",", "version", ")", ":", "old_python_path", "=", "_get_python_path", "(", "self", ".", "_version", ")", "new_python_path", "=", "_get_python_path", "(", "version", ")", "old_os_path", "=", "_get_os_path", "(", "self", ".", ...
https://github.com/googlecolab/colabtools/blob/b7b3566363e2f0bad9ad256ae317314ba5bd42f8/google/colab/_tensorflow_magics.py#L153-L177
xonsh/xonsh
b76d6f994f22a4078f602f8b386f4ec280c8461f
xonsh/tools.py
python
is_completion_mode
(x)
return x in CANONIC_COMPLETION_MODES
Enumerated values of $COMPLETION_MODE
Enumerated values of $COMPLETION_MODE
[ "Enumerated", "values", "of", "$COMPLETION_MODE" ]
def is_completion_mode(x): """Enumerated values of $COMPLETION_MODE""" return x in CANONIC_COMPLETION_MODES
[ "def", "is_completion_mode", "(", "x", ")", ":", "return", "x", "in", "CANONIC_COMPLETION_MODES" ]
https://github.com/xonsh/xonsh/blob/b76d6f994f22a4078f602f8b386f4ec280c8461f/xonsh/tools.py#L1655-L1657
lifting-bits/mcsema
b7492e2ffb9f2fa64b5ef269753ba1d134bdf2f2
tools/mcsema_disass/ida7/table.py
python
get_ida_jump_table_reader
(builder, si)
return True
Try to trust IDA's ability to recognize a jump table and its entries, and return an appropriate jump table entry reader.
Try to trust IDA's ability to recognize a jump table and its entries, and return an appropriate jump table entry reader.
[ "Try", "to", "trust", "IDA", "s", "ability", "to", "recognize", "a", "jump", "table", "and", "its", "entries", "and", "return", "an", "appropriate", "jump", "table", "entry", "reader", "." ]
def get_ida_jump_table_reader(builder, si): """Try to trust IDA's ability to recognize a jump table and its entries, and return an appropriate jump table entry reader.""" builder.table_ea = si.jumps DEBUG("IDA inferred jump table base: {:x}".format(builder.table_ea)) builder.entry_size = si.get_jtable_element_size() if (si.flags & idaapi.SWI_JMP_INV) == idaapi.SWI_JMP_INV: builder.entry_mult = -1 DEBUG("IDA inferred jump table entry size: {}".format(builder.entry_size)) if builder.entry_size not in (4, 8): builder.entry_size = get_address_size_in_bits() // 8 DEBUG("Using jump table entry size {} instead".format(builder.entry_size)) # Check if this is an offset based jump table, and if so, create an # appropriate wrapper that uses the displacement from the table base # address to find the actual jump target. if (si.flags & idaapi.SWI_ELBASE) == idaapi.SWI_ELBASE: builder.offset = si.elbase # Figure out if we need to subtract the offset instead of add it. SWI2_SUBTRACT = idaapi.SWI_SUBTRACT >> 16 if (si.flags & SWI2_SUBTRACT) == SWI2_SUBTRACT: builder.offset_mult = -1 DEBUG("IDA inferred jump table offset: {:x}".format(builder.offset)) # NOTE(pag): Converting this base to a real address is likely not correct, # hence commenting it out. The jump table in question had # entries like: # # dd offset msetTab00 - 140000000h; jump table for switch statement # # And then the code would add back in the `0x140000000`. The # way we lift jump tables is to `switch` on the original EAs, # because we can get the address of lifted LLVM basic blocks, # so we need to make sure that the lifted computation and the # original computation produce the same EAs for the jump targets, # and converting the offset to be valid would be incorrect. # # # See Issue #321. The offset ea may end up being nearby the beginning of # # the `.text` segment, e.g. `0x1400000000` is the offset, but the `.text` # # begins at `0x1400001000`. # if is_invalid_ea(builder.offset): # DEBUG("WARNING: Table offset {:x} is not a valid address".format( # builder.offset)) # try_convert_table_offset_to_ea(builder.offset) return True
[ "def", "get_ida_jump_table_reader", "(", "builder", ",", "si", ")", ":", "builder", ".", "table_ea", "=", "si", ".", "jumps", "DEBUG", "(", "\"IDA inferred jump table base: {:x}\"", ".", "format", "(", "builder", ".", "table_ea", ")", ")", "builder", ".", "ent...
https://github.com/lifting-bits/mcsema/blob/b7492e2ffb9f2fa64b5ef269753ba1d134bdf2f2/tools/mcsema_disass/ida7/table.py#L327-L380
omz/PythonistaAppTemplate
f560f93f8876d82a21d108977f90583df08d55af
PythonistaAppTemplate/PythonistaKit.framework/pylib/site-packages/pyparsing.py
python
ParseResults.values
( self )
return [ v[-1][0] for v in self.__tokdict.values() ]
Returns all named result values.
Returns all named result values.
[ "Returns", "all", "named", "result", "values", "." ]
def values( self ): """Returns all named result values.""" return [ v[-1][0] for v in self.__tokdict.values() ]
[ "def", "values", "(", "self", ")", ":", "return", "[", "v", "[", "-", "1", "]", "[", "0", "]", "for", "v", "in", "self", ".", "__tokdict", ".", "values", "(", ")", "]" ]
https://github.com/omz/PythonistaAppTemplate/blob/f560f93f8876d82a21d108977f90583df08d55af/PythonistaAppTemplate/PythonistaKit.framework/pylib/site-packages/pyparsing.py#L400-L402
CoinAlpha/hummingbot
36f6149c1644c07cd36795b915f38b8f49b798e7
hummingbot/script/script_base.py
python
ScriptBase.round_by_step
(a_number: Decimal, step_size: Decimal)
return (a_number // step_size) * step_size
Rounds the number down by the step size, e.g. round_by_step(1.8, 0.25) = 1.75 :param a_number: A number to round :param step_size: The step size. :returns rounded number.
Rounds the number down by the step size, e.g. round_by_step(1.8, 0.25) = 1.75 :param a_number: A number to round :param step_size: The step size. :returns rounded number.
[ "Rounds", "the", "number", "down", "by", "the", "step", "size", "e", ".", "g", ".", "round_by_step", "(", "1", ".", "8", "0", ".", "25", ")", "=", "1", ".", "75", ":", "param", "a_number", ":", "A", "number", "to", "round", ":", "param", "step_si...
def round_by_step(a_number: Decimal, step_size: Decimal): """ Rounds the number down by the step size, e.g. round_by_step(1.8, 0.25) = 1.75 :param a_number: A number to round :param step_size: The step size. :returns rounded number. """ return (a_number // step_size) * step_size
[ "def", "round_by_step", "(", "a_number", ":", "Decimal", ",", "step_size", ":", "Decimal", ")", ":", "return", "(", "a_number", "//", "step_size", ")", "*", "step_size" ]
https://github.com/CoinAlpha/hummingbot/blob/36f6149c1644c07cd36795b915f38b8f49b798e7/hummingbot/script/script_base.py#L172-L179
aiidateam/aiida-core
c743a335480f8bb3a5e4ebd2463a31f9f3b9f9b2
aiida/engine/processes/futures.py
python
ProcessFuture.__init__
( self, pk: int, loop: Optional[asyncio.AbstractEventLoop] = None, poll_interval: Union[None, int, float] = None, communicator: Optional[kiwipy.Communicator] = None )
Construct a future for a process node being finished. If a None poll_interval is supplied polling will not be used. If a communicator is supplied it will be used to listen for broadcast messages. :param pk: process pk :param loop: An event loop :param poll_interval: optional polling interval, if None, polling is not activated. :param communicator: optional communicator, if None, will not subscribe to broadcasts.
Construct a future for a process node being finished.
[ "Construct", "a", "future", "for", "a", "process", "node", "being", "finished", "." ]
def __init__( self, pk: int, loop: Optional[asyncio.AbstractEventLoop] = None, poll_interval: Union[None, int, float] = None, communicator: Optional[kiwipy.Communicator] = None ): """Construct a future for a process node being finished. If a None poll_interval is supplied polling will not be used. If a communicator is supplied it will be used to listen for broadcast messages. :param pk: process pk :param loop: An event loop :param poll_interval: optional polling interval, if None, polling is not activated. :param communicator: optional communicator, if None, will not subscribe to broadcasts. """ from .process import ProcessState # create future in specified event loop loop = loop if loop is not None else asyncio.get_event_loop() super().__init__(loop=loop) assert not (poll_interval is None and communicator is None), 'Must poll or have a communicator to use' node = load_node(pk=pk) if node.is_terminated: self.set_result(node) else: self._communicator = communicator self.add_done_callback(lambda _: self.cleanup()) # Try setting up a filtered broadcast subscriber if self._communicator is not None: def _subscriber(*args, **kwargs): # pylint: disable=unused-argument if not self.done(): self.set_result(node) broadcast_filter = kiwipy.BroadcastFilter(_subscriber, sender=pk) for state in [ProcessState.FINISHED, ProcessState.KILLED, ProcessState.EXCEPTED]: broadcast_filter.add_subject_filter(f'state_changed.*.{state.value}') self._broadcast_identifier = self._communicator.add_broadcast_subscriber(broadcast_filter) # Start polling if poll_interval is not None: loop.create_task(self._poll_process(node, poll_interval))
[ "def", "__init__", "(", "self", ",", "pk", ":", "int", ",", "loop", ":", "Optional", "[", "asyncio", ".", "AbstractEventLoop", "]", "=", "None", ",", "poll_interval", ":", "Union", "[", "None", ",", "int", ",", "float", "]", "=", "None", ",", "commun...
https://github.com/aiidateam/aiida-core/blob/c743a335480f8bb3a5e4ebd2463a31f9f3b9f9b2/aiida/engine/processes/futures.py#L27-L74
TencentCloud/tencentcloud-sdk-python
3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2
tencentcloud/lighthouse/v20200324/models.py
python
InquirePriceCreateBlueprintResponse.__init__
(self)
r""" :param BlueprintPrice: 自定义镜像的价格参数。 :type BlueprintPrice: :class:`tencentcloud.lighthouse.v20200324.models.BlueprintPrice` :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str
r""" :param BlueprintPrice: 自定义镜像的价格参数。 :type BlueprintPrice: :class:`tencentcloud.lighthouse.v20200324.models.BlueprintPrice` :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str
[ "r", ":", "param", "BlueprintPrice", ":", "自定义镜像的价格参数。", ":", "type", "BlueprintPrice", ":", ":", "class", ":", "tencentcloud", ".", "lighthouse", ".", "v20200324", ".", "models", ".", "BlueprintPrice", ":", "param", "RequestId", ":", "唯一请求", "ID,每次请求都会返回。定位问题时需...
def __init__(self): r""" :param BlueprintPrice: 自定义镜像的价格参数。 :type BlueprintPrice: :class:`tencentcloud.lighthouse.v20200324.models.BlueprintPrice` :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str """ self.BlueprintPrice = None self.RequestId = None
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "BlueprintPrice", "=", "None", "self", ".", "RequestId", "=", "None" ]
https://github.com/TencentCloud/tencentcloud-sdk-python/blob/3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2/tencentcloud/lighthouse/v20200324/models.py#L3322-L3330
lisa-lab/pylearn2
af81e5c362f0df4df85c3e54e23b2adeec026055
pylearn2/models/vae/__init__.py
python
VAE.sample
(self, num_samples, return_sample_means=True, **kwargs)
Sample from the model's learned distribution Parameters ---------- num_samples : int Number of samples return_sample_means : bool, optional Whether to return the conditional expectations :math:`\\mathbb{E}[p_\\theta(\\mathbf{x} \\mid \\mathbf{h})]` in addition to the actual samples. Defaults to `False`. Returns ------- rval : tensor_like or tuple of tensor_like Samples, and optionally conditional expectations
Sample from the model's learned distribution
[ "Sample", "from", "the", "model", "s", "learned", "distribution" ]
def sample(self, num_samples, return_sample_means=True, **kwargs): """ Sample from the model's learned distribution Parameters ---------- num_samples : int Number of samples return_sample_means : bool, optional Whether to return the conditional expectations :math:`\\mathbb{E}[p_\\theta(\\mathbf{x} \\mid \\mathbf{h})]` in addition to the actual samples. Defaults to `False`. Returns ------- rval : tensor_like or tuple of tensor_like Samples, and optionally conditional expectations """ # Sample from p(z) z = self.sample_from_p_z(num_samples=num_samples, **kwargs) # Decode theta theta = self.decode_theta(z) # Sample from p(x | z) X = self.sample_from_p_x_given_z(num_samples=num_samples, theta=theta) if return_sample_means: return (X, self.means_from_theta(theta)) else: return X
[ "def", "sample", "(", "self", ",", "num_samples", ",", "return_sample_means", "=", "True", ",", "*", "*", "kwargs", ")", ":", "# Sample from p(z)", "z", "=", "self", ".", "sample_from_p_z", "(", "num_samples", "=", "num_samples", ",", "*", "*", "kwargs", "...
https://github.com/lisa-lab/pylearn2/blob/af81e5c362f0df4df85c3e54e23b2adeec026055/pylearn2/models/vae/__init__.py#L205-L233
bendmorris/static-python
2e0f8c4d7ed5b359dc7d8a75b6fb37e6b6c5c473
Lib/logging/__init__.py
python
Manager.__init__
(self, rootnode)
Initialize the manager with the root node of the logger hierarchy.
Initialize the manager with the root node of the logger hierarchy.
[ "Initialize", "the", "manager", "with", "the", "root", "node", "of", "the", "logger", "hierarchy", "." ]
def __init__(self, rootnode): """ Initialize the manager with the root node of the logger hierarchy. """ self.root = rootnode self.disable = 0 self.emittedNoHandlerWarning = False self.loggerDict = {} self.loggerClass = None self.logRecordFactory = None
[ "def", "__init__", "(", "self", ",", "rootnode", ")", ":", "self", ".", "root", "=", "rootnode", "self", ".", "disable", "=", "0", "self", ".", "emittedNoHandlerWarning", "=", "False", "self", ".", "loggerDict", "=", "{", "}", "self", ".", "loggerClass",...
https://github.com/bendmorris/static-python/blob/2e0f8c4d7ed5b359dc7d8a75b6fb37e6b6c5c473/Lib/logging/__init__.py#L1089-L1098
Thinklab-SJTU/R3Det_Tensorflow
3e092fa65dee2b9f7722b0985b3791811a1de5ae
libs/networks/slim_nets/inception_utils.py
python
inception_arg_scope
(weight_decay=0.00004, use_batch_norm=True, batch_norm_decay=0.9997, batch_norm_epsilon=0.001)
Defines the default arg scope for inception models. Args: weight_decay: The weight decay to use for regularizing the model. use_batch_norm: "If `True`, batch_norm is applied after each convolution. batch_norm_decay: Decay for batch norm moving average. batch_norm_epsilon: Small float added to variance to avoid dividing by zero in batch norm. Returns: An `arg_scope` to use for the inception models.
Defines the default arg scope for inception models.
[ "Defines", "the", "default", "arg", "scope", "for", "inception", "models", "." ]
def inception_arg_scope(weight_decay=0.00004, use_batch_norm=True, batch_norm_decay=0.9997, batch_norm_epsilon=0.001): """Defines the default arg scope for inception models. Args: weight_decay: The weight decay to use for regularizing the model. use_batch_norm: "If `True`, batch_norm is applied after each convolution. batch_norm_decay: Decay for batch norm moving average. batch_norm_epsilon: Small float added to variance to avoid dividing by zero in batch norm. Returns: An `arg_scope` to use for the inception models. """ batch_norm_params = { # Decay for the moving averages. 'decay': batch_norm_decay, # epsilon to prevent 0s in variance. 'epsilon': batch_norm_epsilon, # collection containing update_ops. 'updates_collections': tf.GraphKeys.UPDATE_OPS, } if use_batch_norm: normalizer_fn = slim.batch_norm normalizer_params = batch_norm_params else: normalizer_fn = None normalizer_params = {} # Set weight_decay for weights in Conv and FC layers. with slim.arg_scope([slim.conv2d, slim.fully_connected], weights_regularizer=slim.l2_regularizer(weight_decay)): with slim.arg_scope( [slim.conv2d], weights_initializer=slim.variance_scaling_initializer(), activation_fn=tf.nn.relu, normalizer_fn=normalizer_fn, normalizer_params=normalizer_params) as sc: return sc
[ "def", "inception_arg_scope", "(", "weight_decay", "=", "0.00004", ",", "use_batch_norm", "=", "True", ",", "batch_norm_decay", "=", "0.9997", ",", "batch_norm_epsilon", "=", "0.001", ")", ":", "batch_norm_params", "=", "{", "# Decay for the moving averages.", "'decay...
https://github.com/Thinklab-SJTU/R3Det_Tensorflow/blob/3e092fa65dee2b9f7722b0985b3791811a1de5ae/libs/networks/slim_nets/inception_utils.py#L32-L71
Qirky/Troop
529c5eb14e456f683e6d23fd4adcddc8446aa115
src/interface/interface.py
python
Interface.move_marker_home
(self)
return
Moves the cursor to the beginning of a line
Moves the cursor to the beginning of a line
[ "Moves", "the", "cursor", "to", "the", "beginning", "of", "a", "line" ]
def move_marker_home(self): """ Moves the cursor to the beginning of a line """ tcl_index = self.text.number_index_to_tcl(self.text.marker.get_index_num()) x, y, w, h = self.text.bbox(tcl_index) index = self.text.tcl_index_to_number( self.text.index("@{},{}".format(1, y)) ) self.text.marker.move(index) return
[ "def", "move_marker_home", "(", "self", ")", ":", "tcl_index", "=", "self", ".", "text", ".", "number_index_to_tcl", "(", "self", ".", "text", ".", "marker", ".", "get_index_num", "(", ")", ")", "x", ",", "y", ",", "w", ",", "h", "=", "self", ".", ...
https://github.com/Qirky/Troop/blob/529c5eb14e456f683e6d23fd4adcddc8446aa115/src/interface/interface.py#L956-L962
Source-Python-Dev-Team/Source.Python
d0ffd8ccbd1e9923c9bc44936f20613c1c76b7fb
addons/source-python/Python3/imaplib.py
python
IMAP4.login_cram_md5
(self, user, password)
return self.authenticate('CRAM-MD5', self._CRAM_MD5_AUTH)
Force use of CRAM-MD5 authentication. (typ, [data]) = <instance>.login_cram_md5(user, password)
Force use of CRAM-MD5 authentication.
[ "Force", "use", "of", "CRAM", "-", "MD5", "authentication", "." ]
def login_cram_md5(self, user, password): """ Force use of CRAM-MD5 authentication. (typ, [data]) = <instance>.login_cram_md5(user, password) """ self.user, self.password = user, password return self.authenticate('CRAM-MD5', self._CRAM_MD5_AUTH)
[ "def", "login_cram_md5", "(", "self", ",", "user", ",", "password", ")", ":", "self", ".", "user", ",", "self", ".", "password", "=", "user", ",", "password", "return", "self", ".", "authenticate", "(", "'CRAM-MD5'", ",", "self", ".", "_CRAM_MD5_AUTH", "...
https://github.com/Source-Python-Dev-Team/Source.Python/blob/d0ffd8ccbd1e9923c9bc44936f20613c1c76b7fb/addons/source-python/Python3/imaplib.py#L595-L601
areed1192/td-ameritrade-python-api
3378ca89f464df80a5b651f3e365f2f7d9c758d7
td/utils.py
python
StatePath.json_settings_path
(self)
return self.settings_directory.joinpath(self.credenitals_file_name)
Generates a path to the `.td_python_library/td_state.json` file. Returns: ---- {pathlib.PurePath} -- A PurePath object pointing to the `.td_python_library/td_state.json` file.
Generates a path to the `.td_python_library/td_state.json` file.
[ "Generates", "a", "path", "to", "the", ".", "td_python_library", "/", "td_state", ".", "json", "file", "." ]
def json_settings_path(self): """Generates a path to the `.td_python_library/td_state.json` file. Returns: ---- {pathlib.PurePath} -- A PurePath object pointing to the `.td_python_library/td_state.json` file. """ return self.settings_directory.joinpath(self.credenitals_file_name)
[ "def", "json_settings_path", "(", "self", ")", ":", "return", "self", ".", "settings_directory", ".", "joinpath", "(", "self", ".", "credenitals_file_name", ")" ]
https://github.com/areed1192/td-ameritrade-python-api/blob/3378ca89f464df80a5b651f3e365f2f7d9c758d7/td/utils.py#L105-L113
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/Python-2.7.9/Tools/gdb/libpython.py
python
PyObjectPtr.get_gdb_type
(cls)
return gdb.lookup_type(cls._typename).pointer()
[]
def get_gdb_type(cls): return gdb.lookup_type(cls._typename).pointer()
[ "def", "get_gdb_type", "(", "cls", ")", ":", "return", "gdb", ".", "lookup_type", "(", "cls", ".", "_typename", ")", ".", "pointer", "(", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/Python-2.7.9/Tools/gdb/libpython.py#L362-L363
scipy/scipy
e0a749f01e79046642ccfdc419edbf9e7ca141ad
scipy/stats/_multivariate.py
python
invwishart_gen._mode
(self, dim, df, scale)
return scale / (df + dim + 1)
Mode of the inverse Wishart distribution. Parameters ---------- dim : int Dimension of the scale matrix %(_doc_default_callparams)s Notes ----- As this function does no argument checking, it should not be called directly; use 'mode' instead.
Mode of the inverse Wishart distribution.
[ "Mode", "of", "the", "inverse", "Wishart", "distribution", "." ]
def _mode(self, dim, df, scale): """Mode of the inverse Wishart distribution. Parameters ---------- dim : int Dimension of the scale matrix %(_doc_default_callparams)s Notes ----- As this function does no argument checking, it should not be called directly; use 'mode' instead. """ return scale / (df + dim + 1)
[ "def", "_mode", "(", "self", ",", "dim", ",", "df", ",", "scale", ")", ":", "return", "scale", "/", "(", "df", "+", "dim", "+", "1", ")" ]
https://github.com/scipy/scipy/blob/e0a749f01e79046642ccfdc419edbf9e7ca141ad/scipy/stats/_multivariate.py#L2605-L2620
espnet/espnet
ea411f3f627b8f101c211e107d0ff7053344ac80
espnet2/utils/griffin_lim.py
python
Spectrogram2Waveform.__init__
( self, n_fft: int, n_shift: int, fs: int = None, n_mels: int = None, win_length: int = None, window: Optional[str] = "hann", fmin: int = None, fmax: int = None, griffin_lim_iters: Optional[int] = 8, )
Initialize module. Args: fs: Sampling frequency. n_fft: The number of FFT points. n_shift: Shift size in points. n_mels: The number of mel basis. win_length: Window length in points. window: Window function type. f_min: Minimum frequency to analyze. f_max: Maximum frequency to analyze. griffin_lim_iters: The number of iterations.
Initialize module.
[ "Initialize", "module", "." ]
def __init__( self, n_fft: int, n_shift: int, fs: int = None, n_mels: int = None, win_length: int = None, window: Optional[str] = "hann", fmin: int = None, fmax: int = None, griffin_lim_iters: Optional[int] = 8, ): """Initialize module. Args: fs: Sampling frequency. n_fft: The number of FFT points. n_shift: Shift size in points. n_mels: The number of mel basis. win_length: Window length in points. window: Window function type. f_min: Minimum frequency to analyze. f_max: Maximum frequency to analyze. griffin_lim_iters: The number of iterations. """ assert check_argument_types() self.fs = fs self.logmel2linear = ( partial( logmel2linear, fs=fs, n_fft=n_fft, n_mels=n_mels, fmin=fmin, fmax=fmax ) if n_mels is not None else None ) self.griffin_lim = partial( griffin_lim, n_fft=n_fft, n_shift=n_shift, win_length=win_length, window=window, n_iter=griffin_lim_iters, ) self.params = dict( n_fft=n_fft, n_shift=n_shift, win_length=win_length, window=window, n_iter=griffin_lim_iters, ) if n_mels is not None: self.params.update(fs=fs, n_mels=n_mels, fmin=fmin, fmax=fmax)
[ "def", "__init__", "(", "self", ",", "n_fft", ":", "int", ",", "n_shift", ":", "int", ",", "fs", ":", "int", "=", "None", ",", "n_mels", ":", "int", "=", "None", ",", "win_length", ":", "int", "=", "None", ",", "window", ":", "Optional", "[", "st...
https://github.com/espnet/espnet/blob/ea411f3f627b8f101c211e107d0ff7053344ac80/espnet2/utils/griffin_lim.py#L113-L164
tensorflow/tensorboard
61d11d99ef034c30ba20b6a7840c8eededb9031c
tensorboard/plugins/hparams/list_session_groups.py
python
_MetricStats.__init__
(self)
[]
def __init__(self): self.total = 0 self.count = 0 self.total_step = 0 self.total_wall_time_secs = 0.0
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "total", "=", "0", "self", ".", "count", "=", "0", "self", ".", "total_step", "=", "0", "self", ".", "total_wall_time_secs", "=", "0.0" ]
https://github.com/tensorflow/tensorboard/blob/61d11d99ef034c30ba20b6a7840c8eededb9031c/tensorboard/plugins/hparams/list_session_groups.py#L588-L592
PaddlePaddle/Research
2da0bd6c72d60e9df403aff23a7802779561c4a1
CV/PaddleReid/reid/data/shared_queue/sharedmemory.py
python
SharedMemoryMgr.malloc
(self, size, wait=True)
return SharedBuffer(self._id, size, start, alloc_status=alloc_status)
malloc a new SharedBuffer Args: size (int): buffer size to be malloc wait (bool): whether to wait when no enough memory Returns: SharedBuffer Raises: SharedMemoryError when not found available memory
malloc a new SharedBuffer
[ "malloc", "a", "new", "SharedBuffer" ]
def malloc(self, size, wait=True): """ malloc a new SharedBuffer Args: size (int): buffer size to be malloc wait (bool): whether to wait when no enough memory Returns: SharedBuffer Raises: SharedMemoryError when not found available memory """ page_num = int(math.ceil(size / self._page_size)) size = page_num * self._page_size start = None ct = 0 errmsg = '' while True: self._locker.acquire() try: start = self._allocator.malloc_page(page_num) alloc_status = str(self._allocator) except MemoryFullError as e: start = None errmsg = e.errmsg if not wait: raise e finally: self._locker.release() if start is None: time.sleep(0.1) if ct % 100 == 0: logger.warn('not enough space for reason[%s]' % (errmsg)) ct += 1 else: break return SharedBuffer(self._id, size, start, alloc_status=alloc_status)
[ "def", "malloc", "(", "self", ",", "size", ",", "wait", "=", "True", ")", ":", "page_num", "=", "int", "(", "math", ".", "ceil", "(", "size", "/", "self", ".", "_page_size", ")", ")", "size", "=", "page_num", "*", "self", ".", "_page_size", "start"...
https://github.com/PaddlePaddle/Research/blob/2da0bd6c72d60e9df403aff23a7802779561c4a1/CV/PaddleReid/reid/data/shared_queue/sharedmemory.py#L428-L469
aiidateam/aiida-core
c743a335480f8bb3a5e4ebd2463a31f9f3b9f9b2
aiida/tools/archive/implementations/sqlite/writer.py
python
ArchiveAppenderSqlZip.__enter__
(self)
return self
Start appending to the archive
Start appending to the archive
[ "Start", "appending", "to", "the", "archive" ]
def __enter__(self) -> 'ArchiveAppenderSqlZip': """Start appending to the archive""" # the file should already exist if not self._path.exists(): raise FileNotFoundError(f'Archive {self._path} does not exist') # the file should be an archive with the correct version version = self._format.read_version(self._path) if not version == self._format.latest_version: raise IncompatibleArchiveVersionError( f'Archive is version {version!r} but expected {self._format.latest_version!r}' ) # load the metadata self._metadata = json.loads(read_file_in_zip(self._path, META_FILENAME, 'utf8', search_limit=4)) # overwrite metadata self._metadata['mtime'] = datetime.now().isoformat() self._metadata['compression'] = self._compression # create the work folder self._work_dir = Path(tempfile.mkdtemp()) if self._init_work_dir is None else Path(self._init_work_dir) # create a new zip file in the work folder self._central_dir = {} self._deleted_paths = set() self._zip_path = ZipPath( self._work_dir / 'archive.zip', mode='w', compression=zipfile.ZIP_DEFLATED if self._compression else zipfile.ZIP_STORED, compresslevel=self._compression, info_order=(self.meta_name, self.db_name), name_to_info=self._central_dir, ) # extract the database to the work folder db_file = self._work_dir / self.db_name with db_file.open('wb') as handle: try: extract_file_in_zip(self.path, DB_FILENAME, handle, search_limit=4) except Exception as exc: raise CorruptArchive(f'database could not be read: {exc}') from exc # open a connection to the database engine = create_sqla_engine( self._work_dir / self.db_name, enforce_foreign_keys=self._enforce_foreign_keys, echo=self._debug ) # to-do could check that the database has correct schema: # https://docs.sqlalchemy.org/en/14/core/reflection.html#reflecting-all-tables-at-once self._conn = engine.connect() self._in_context = True return self
[ "def", "__enter__", "(", "self", ")", "->", "'ArchiveAppenderSqlZip'", ":", "# the file should already exist", "if", "not", "self", ".", "_path", ".", "exists", "(", ")", ":", "raise", "FileNotFoundError", "(", "f'Archive {self._path} does not exist'", ")", "# the fil...
https://github.com/aiidateam/aiida-core/blob/c743a335480f8bb3a5e4ebd2463a31f9f3b9f9b2/aiida/tools/archive/implementations/sqlite/writer.py#L223-L267
MaslowCNC/GroundControl
294a05dea5b9753383e24b07ea47d78e76e49422
Simulation/kinematics.py
python
Kinematics.recomputeGeometry
(self)
Some variables are computed on class creation for the geometry of the machine to reduce overhead, calling this function regenerates those values.
Some variables are computed on class creation for the geometry of the machine to reduce overhead, calling this function regenerates those values.
[ "Some", "variables", "are", "computed", "on", "class", "creation", "for", "the", "geometry", "of", "the", "machine", "to", "reduce", "overhead", "calling", "this", "function", "regenerates", "those", "values", "." ]
def recomputeGeometry(self): ''' Some variables are computed on class creation for the geometry of the machine to reduce overhead, calling this function regenerates those values. ''' self.h = math.sqrt((self.l/2)*(self.l/2) + self.s * self.s) self.Theta = math.atan(2*self.s/self.l) self.Psi1 = self.Theta - self.Phi self.Psi2 = self.Theta + self.Phi self._xCordOfMotor = self.D/2 self._yCordOfMotor = self.machineHeight/2 + self.motorOffsetY
[ "def", "recomputeGeometry", "(", "self", ")", ":", "self", ".", "h", "=", "math", ".", "sqrt", "(", "(", "self", ".", "l", "/", "2", ")", "*", "(", "self", ".", "l", "/", "2", ")", "+", "self", ".", "s", "*", "self", ".", "s", ")", "self", ...
https://github.com/MaslowCNC/GroundControl/blob/294a05dea5b9753383e24b07ea47d78e76e49422/Simulation/kinematics.py#L110-L121
biolab/orange3
41685e1c7b1d1babe680113685a2d44bcc9fec0b
Orange/widgets/data/owcsvimport.py
python
guess_data_type
(col: pd.Series)
return col
Guess column types. Logic is same than in guess_data_type from io_utils module. This function only change the dtype of the column such that later correct Orange.data.variable is used. Logic: - if can converted to date-time (ISO) -> TimeVariable - if numeric (only numbers) - only values {0, 1} or {1, 2} -> DiscreteVariable - else -> ContinuousVariable - if not numbers: - num_unique_values < len(data) ** 0.7 and < 100 -> DiscreteVariable - else -> StringVariable Parameters ---------- col Data column Returns ------- Data column with correct dtype
Guess column types. Logic is same than in guess_data_type from io_utils module. This function only change the dtype of the column such that later correct Orange.data.variable is used. Logic: - if can converted to date-time (ISO) -> TimeVariable - if numeric (only numbers) - only values {0, 1} or {1, 2} -> DiscreteVariable - else -> ContinuousVariable - if not numbers: - num_unique_values < len(data) ** 0.7 and < 100 -> DiscreteVariable - else -> StringVariable
[ "Guess", "column", "types", ".", "Logic", "is", "same", "than", "in", "guess_data_type", "from", "io_utils", "module", ".", "This", "function", "only", "change", "the", "dtype", "of", "the", "column", "such", "that", "later", "correct", "Orange", ".", "data"...
def guess_data_type(col: pd.Series) -> pd.Series: """ Guess column types. Logic is same than in guess_data_type from io_utils module. This function only change the dtype of the column such that later correct Orange.data.variable is used. Logic: - if can converted to date-time (ISO) -> TimeVariable - if numeric (only numbers) - only values {0, 1} or {1, 2} -> DiscreteVariable - else -> ContinuousVariable - if not numbers: - num_unique_values < len(data) ** 0.7 and < 100 -> DiscreteVariable - else -> StringVariable Parameters ---------- col Data column Returns ------- Data column with correct dtype """ def parse_dates(s): """ This is an extremely fast approach to datetime parsing. For large data, the same dates are often repeated. Rather than re-parse these, we store all unique dates, parse them, and use a lookup to convert all dates. """ try: dates = {date: pd.to_datetime(date) for date in s.unique()} except ValueError: return None return s.map(dates) if pdtypes.is_numeric_dtype(col): unique_values = col.unique() if len(unique_values) <= 2 and ( len(np.setdiff1d(unique_values, [0, 1])) == 0 or len(np.setdiff1d(unique_values, [1, 2])) == 0): return col.astype("category") else: # object # try parse as date - if None not a date parsed_col = parse_dates(col) if parsed_col is not None: return parsed_col unique_values = col.unique() if len(unique_values) < 100 and len(unique_values) < len(col)**0.7: return col.astype("category") return col
[ "def", "guess_data_type", "(", "col", ":", "pd", ".", "Series", ")", "->", "pd", ".", "Series", ":", "def", "parse_dates", "(", "s", ")", ":", "\"\"\"\n This is an extremely fast approach to datetime parsing.\n For large data, the same dates are often repeated. ...
https://github.com/biolab/orange3/blob/41685e1c7b1d1babe680113685a2d44bcc9fec0b/Orange/widgets/data/owcsvimport.py#L1607-L1657
shiweibsw/Translation-Tools
2fbbf902364e557fa7017f9a74a8797b7440c077
venv/Lib/site-packages/pip-9.0.3-py3.6.egg/pip/_vendor/pkg_resources/__init__.py
python
get_distribution
(dist)
return dist
Return a current distribution object for a Requirement or string
Return a current distribution object for a Requirement or string
[ "Return", "a", "current", "distribution", "object", "for", "a", "Requirement", "or", "string" ]
def get_distribution(dist): """Return a current distribution object for a Requirement or string""" if isinstance(dist, six.string_types): dist = Requirement.parse(dist) if isinstance(dist, Requirement): dist = get_provider(dist) if not isinstance(dist, Distribution): raise TypeError("Expected string, Requirement, or Distribution", dist) return dist
[ "def", "get_distribution", "(", "dist", ")", ":", "if", "isinstance", "(", "dist", ",", "six", ".", "string_types", ")", ":", "dist", "=", "Requirement", ".", "parse", "(", "dist", ")", "if", "isinstance", "(", "dist", ",", "Requirement", ")", ":", "di...
https://github.com/shiweibsw/Translation-Tools/blob/2fbbf902364e557fa7017f9a74a8797b7440c077/venv/Lib/site-packages/pip-9.0.3-py3.6.egg/pip/_vendor/pkg_resources/__init__.py#L553-L561
Clarifai/clarifai-python
7cd160e56799b5a4b04616a1a75961b974d2e6dc
clarifai/rest/client.py
python
Workflow.predict_by_bytes
( self, # type: Workflow raw_bytes, # type: bytes lang=None, # type: typing.Optional[str] is_video=False, # type: typing.Optional[bool] min_value=None, # type: typing.Optional[float] max_concepts=None, # type: typing.Optional[int] select_concepts=None # type: typing.Optional[typing.List[Concept]] )
return res
predict a model with image raw bytes Args: raw_bytes: raw bytes of an image lang: language to predict, if the translation is available is_video: whether this is a video min_value: threshold to cut the predictions, 0-1.0 max_concepts: max concepts to keep in the predictions, 0-200 select_concepts: a list of concepts that are selected to be exposed Returns: the prediction of the model in JSON format
predict a model with image raw bytes
[ "predict", "a", "model", "with", "image", "raw", "bytes" ]
def predict_by_bytes( self, # type: Workflow raw_bytes, # type: bytes lang=None, # type: typing.Optional[str] is_video=False, # type: typing.Optional[bool] min_value=None, # type: typing.Optional[float] max_concepts=None, # type: typing.Optional[int] select_concepts=None # type: typing.Optional[typing.List[Concept]] ): # type: (...) -> dict """ predict a model with image raw bytes Args: raw_bytes: raw bytes of an image lang: language to predict, if the translation is available is_video: whether this is a video min_value: threshold to cut the predictions, 0-1.0 max_concepts: max concepts to keep in the predictions, 0-200 select_concepts: a list of concepts that are selected to be exposed Returns: the prediction of the model in JSON format """ base64_bytes = base64_lib.b64encode(raw_bytes) if is_video is True: input_ = Video(base64=base64_bytes) else: input_ = Image(base64=base64_bytes) output_config = ModelOutputConfig( language=lang, min_value=min_value, max_concepts=max_concepts, select_concepts=select_concepts) res = self.predict([input_], output_config) return res
[ "def", "predict_by_bytes", "(", "self", ",", "# type: Workflow", "raw_bytes", ",", "# type: bytes", "lang", "=", "None", ",", "# type: typing.Optional[str]", "is_video", "=", "False", ",", "# type: typing.Optional[bool]", "min_value", "=", "None", ",", "# type: typing.O...
https://github.com/Clarifai/clarifai-python/blob/7cd160e56799b5a4b04616a1a75961b974d2e6dc/clarifai/rest/client.py#L829-L867
lovelylain/pyctp
fd304de4b50c4ddc31a4190b1caaeb5dec66bc5d
example/pyctp2/trader/trade_command_queue.py
python
TradeCommandQueueStub.__init__
(self, env, account)
[]
def __init__(self, env, account): BaseTradeCommandQueue.__init__(self,env,account) self.lock = threading.Lock()
[ "def", "__init__", "(", "self", ",", "env", ",", "account", ")", ":", "BaseTradeCommandQueue", ".", "__init__", "(", "self", ",", "env", ",", "account", ")", "self", ".", "lock", "=", "threading", ".", "Lock", "(", ")" ]
https://github.com/lovelylain/pyctp/blob/fd304de4b50c4ddc31a4190b1caaeb5dec66bc5d/example/pyctp2/trader/trade_command_queue.py#L300-L302
shiyanlou/louplus-python
4c61697259e286e3d9116c3299f170d019ba3767
taobei/challenge-07/tbmall/handlers/product.py
python
product_info
(id)
return json_response(product=ProductSchema().dump(product))
查询商品
查询商品
[ "查询商品" ]
def product_info(id): """查询商品 """ product = Product.query.get(id) if product is None: return json_response(ResponseCode.NOT_FOUND) return json_response(product=ProductSchema().dump(product))
[ "def", "product_info", "(", "id", ")", ":", "product", "=", "Product", ".", "query", ".", "get", "(", "id", ")", "if", "product", "is", "None", ":", "return", "json_response", "(", "ResponseCode", ".", "NOT_FOUND", ")", "return", "json_response", "(", "p...
https://github.com/shiyanlou/louplus-python/blob/4c61697259e286e3d9116c3299f170d019ba3767/taobei/challenge-07/tbmall/handlers/product.py#L65-L73
openstack/nova
b49b7663e1c3073917d5844b81d38db8e86d05c4
nova/api/openstack/compute/servers.py
python
ServersController._get_server
(self, context, req, instance_uuid, is_detail=False, cell_down_support=False, columns_to_join=None)
return instance
Utility function for looking up an instance by uuid. :param context: request context for auth :param req: HTTP request. :param instance_uuid: UUID of the server instance to get :param is_detail: True if you plan on showing the details of the instance in the response, False otherwise. :param cell_down_support: True if the API (and caller) support returning a minimal instance construct if the relevant cell is down. :param columns_to_join: optional list of extra fields to join on the Instance object
Utility function for looking up an instance by uuid.
[ "Utility", "function", "for", "looking", "up", "an", "instance", "by", "uuid", "." ]
def _get_server(self, context, req, instance_uuid, is_detail=False, cell_down_support=False, columns_to_join=None): """Utility function for looking up an instance by uuid. :param context: request context for auth :param req: HTTP request. :param instance_uuid: UUID of the server instance to get :param is_detail: True if you plan on showing the details of the instance in the response, False otherwise. :param cell_down_support: True if the API (and caller) support returning a minimal instance construct if the relevant cell is down. :param columns_to_join: optional list of extra fields to join on the Instance object """ expected_attrs = ['flavor', 'numa_topology'] if is_detail: if api_version_request.is_supported(req, '2.26'): expected_attrs.append("tags") if api_version_request.is_supported(req, '2.63'): expected_attrs.append("trusted_certs") expected_attrs = self._view_builder.get_show_expected_attrs( expected_attrs) if columns_to_join: expected_attrs.extend(columns_to_join) instance = common.get_instance(self.compute_api, context, instance_uuid, expected_attrs=expected_attrs, cell_down_support=cell_down_support) return instance
[ "def", "_get_server", "(", "self", ",", "context", ",", "req", ",", "instance_uuid", ",", "is_detail", "=", "False", ",", "cell_down_support", "=", "False", ",", "columns_to_join", "=", "None", ")", ":", "expected_attrs", "=", "[", "'flavor'", ",", "'numa_to...
https://github.com/openstack/nova/blob/b49b7663e1c3073917d5844b81d38db8e86d05c4/nova/api/openstack/compute/servers.py#L351-L381
dropbox/dropbox-sdk-python
015437429be224732990041164a21a0501235db1
dropbox/team_log.py
python
FederationStatusChangeAdditionalInfo.is_organization_name
(self)
return self._tag == 'organization_name'
Check if the union tag is ``organization_name``. :rtype: bool
Check if the union tag is ``organization_name``.
[ "Check", "if", "the", "union", "tag", "is", "organization_name", "." ]
def is_organization_name(self): """ Check if the union tag is ``organization_name``. :rtype: bool """ return self._tag == 'organization_name'
[ "def", "is_organization_name", "(", "self", ")", ":", "return", "self", ".", "_tag", "==", "'organization_name'" ]
https://github.com/dropbox/dropbox-sdk-python/blob/015437429be224732990041164a21a0501235db1/dropbox/team_log.py#L44566-L44572
Tautulli/Tautulli
2410eb33805aaac4bd1c5dad0f71e4f15afaf742
lib/dns/resolver.py
python
_Resolution.query_result
(self, response, ex)
[]
def query_result(self, response, ex): # # returns an (answer: Answer, end_loop: bool) tuple. # if ex: # Exception during I/O or from_wire() assert response is None self.errors.append((self.nameserver, self.tcp_attempt, self.port, ex, response)) if isinstance(ex, dns.exception.FormError) or \ isinstance(ex, EOFError) or \ isinstance(ex, OSError) or \ isinstance(ex, NotImplementedError): # This nameserver is no good, take it out of the mix. self.nameservers.remove(self.nameserver) elif isinstance(ex, dns.message.Truncated): if self.tcp_attempt: # Truncation with TCP is no good! self.nameservers.remove(self.nameserver) else: self.retry_with_tcp = True return (None, False) # We got an answer! assert response is not None rcode = response.rcode() if rcode == dns.rcode.NOERROR: answer = Answer(self.qname, self.rdtype, self.rdclass, response, self.nameserver, self.port) if self.resolver.cache: self.resolver.cache.put((self.qname, self.rdtype, self.rdclass), answer) if answer.rrset is None and self.raise_on_no_answer: raise NoAnswer(response=answer.response) return (answer, True) elif rcode == dns.rcode.NXDOMAIN: self.nxdomain_responses[self.qname] = response # Make next_nameserver() return None, so caller breaks its # inner loop and calls next_request(). if self.resolver.cache: answer = Answer(self.qname, dns.rdatatype.ANY, dns.rdataclass.IN, response) self.resolver.cache.put((self.qname, dns.rdatatype.ANY, self.rdclass), answer) return (None, True) elif rcode == dns.rcode.YXDOMAIN: yex = YXDOMAIN() self.errors.append((self.nameserver, self.tcp_attempt, self.port, yex, response)) raise yex else: # # We got a response, but we're not happy with the # rcode in it. # if rcode != dns.rcode.SERVFAIL or not self.resolver.retry_servfail: self.nameservers.remove(self.nameserver) self.errors.append((self.nameserver, self.tcp_attempt, self.port, dns.rcode.to_text(rcode), response)) return (None, False)
[ "def", "query_result", "(", "self", ",", "response", ",", "ex", ")", ":", "#", "# returns an (answer: Answer, end_loop: bool) tuple.", "#", "if", "ex", ":", "# Exception during I/O or from_wire()", "assert", "response", "is", "None", "self", ".", "errors", ".", "app...
https://github.com/Tautulli/Tautulli/blob/2410eb33805aaac4bd1c5dad0f71e4f15afaf742/lib/dns/resolver.py#L609-L669
iosband/ts_tutorial
f28d3bbe88b16a2e61faab9ffe4ae7387880b16a
src/ensemble_nn/agent_nn.py
python
TwoLayerNNDropout.pick_action
(self, observation)
return action
Select the greedy action according to the output of a stochastic forward pass.
Select the greedy action according to the output of a stochastic forward pass.
[ "Select", "the", "greedy", "action", "according", "to", "the", "output", "of", "a", "stochastic", "forward", "pass", "." ]
def pick_action(self, observation): """Select the greedy action according to the output of a stochastic forward pass.""" model_out, _ = self._model_forward(self.actions) action = np.argmax(model_out) return action
[ "def", "pick_action", "(", "self", ",", "observation", ")", ":", "model_out", ",", "_", "=", "self", ".", "_model_forward", "(", "self", ".", "actions", ")", "action", "=", "np", ".", "argmax", "(", "model_out", ")", "return", "action" ]
https://github.com/iosband/ts_tutorial/blob/f28d3bbe88b16a2e61faab9ffe4ae7387880b16a/src/ensemble_nn/agent_nn.py#L257-L262
BlackLight/platypush
a6b552504e2ac327c94f3a28b607061b6b60cf36
platypush/plugins/lcd/__init__.py
python
LcdPlugin.write
(self, value: int)
Write a raw byte to the LCD. :param value: Byte to be sent.
Write a raw byte to the LCD.
[ "Write", "a", "raw", "byte", "to", "the", "LCD", "." ]
def write(self, value: int): """ Write a raw byte to the LCD. :param value: Byte to be sent. """ self._init_lcd() self.lcd.write(value)
[ "def", "write", "(", "self", ",", "value", ":", "int", ")", ":", "self", ".", "_init_lcd", "(", ")", "self", ".", "lcd", ".", "write", "(", "value", ")" ]
https://github.com/BlackLight/platypush/blob/a6b552504e2ac327c94f3a28b607061b6b60cf36/platypush/plugins/lcd/__init__.py#L202-L209
vispy/vispy
26256fdc2574259dd227022fbce0767cae4e244b
vispy/gloo/wrappers.py
python
BaseGlooFunctions.set_polygon_offset
(self, factor=0., units=0.)
Set the scale and units used to calculate depth values Parameters ---------- factor : float Scale factor used to create a variable depth offset for each polygon. units : float Multiplied by an implementation-specific value to create a constant depth offset.
Set the scale and units used to calculate depth values
[ "Set", "the", "scale", "and", "units", "used", "to", "calculate", "depth", "values" ]
def set_polygon_offset(self, factor=0., units=0.): """Set the scale and units used to calculate depth values Parameters ---------- factor : float Scale factor used to create a variable depth offset for each polygon. units : float Multiplied by an implementation-specific value to create a constant depth offset. """ self.glir.command('FUNC', 'glPolygonOffset', float(factor), float(units))
[ "def", "set_polygon_offset", "(", "self", ",", "factor", "=", "0.", ",", "units", "=", "0.", ")", ":", "self", ".", "glir", ".", "command", "(", "'FUNC'", ",", "'glPolygonOffset'", ",", "float", "(", "factor", ")", ",", "float", "(", "units", ")", ")...
https://github.com/vispy/vispy/blob/26256fdc2574259dd227022fbce0767cae4e244b/vispy/gloo/wrappers.py#L162-L175
AppScale/gts
46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9
AppServer/lib/django-1.4/django/db/models/sql/aggregates.py
python
Aggregate.__init__
(self, col, source=None, is_summary=False, **extra)
Instantiate an SQL aggregate * col is a column reference describing the subject field of the aggregate. It can be an alias, or a tuple describing a table and column name. * source is the underlying field or aggregate definition for the column reference. If the aggregate is not an ordinal or computed type, this reference is used to determine the coerced output type of the aggregate. * extra is a dictionary of additional data to provide for the aggregate definition Also utilizes the class variables: * sql_function, the name of the SQL function that implements the aggregate. * sql_template, a template string that is used to render the aggregate into SQL. * is_ordinal, a boolean indicating if the output of this aggregate is an integer (e.g., a count) * is_computed, a boolean indicating if this output of this aggregate is a computed float (e.g., an average), regardless of the input type.
Instantiate an SQL aggregate
[ "Instantiate", "an", "SQL", "aggregate" ]
def __init__(self, col, source=None, is_summary=False, **extra): """Instantiate an SQL aggregate * col is a column reference describing the subject field of the aggregate. It can be an alias, or a tuple describing a table and column name. * source is the underlying field or aggregate definition for the column reference. If the aggregate is not an ordinal or computed type, this reference is used to determine the coerced output type of the aggregate. * extra is a dictionary of additional data to provide for the aggregate definition Also utilizes the class variables: * sql_function, the name of the SQL function that implements the aggregate. * sql_template, a template string that is used to render the aggregate into SQL. * is_ordinal, a boolean indicating if the output of this aggregate is an integer (e.g., a count) * is_computed, a boolean indicating if this output of this aggregate is a computed float (e.g., an average), regardless of the input type. """ self.col = col self.source = source self.is_summary = is_summary self.extra = extra # Follow the chain of aggregate sources back until you find an # actual field, or an aggregate that forces a particular output # type. This type of this field will be used to coerce values # retrieved from the database. tmp = self while tmp and isinstance(tmp, Aggregate): if getattr(tmp, 'is_ordinal', False): tmp = ordinal_aggregate_field elif getattr(tmp, 'is_computed', False): tmp = computed_aggregate_field else: tmp = tmp.source self.field = tmp
[ "def", "__init__", "(", "self", ",", "col", ",", "source", "=", "None", ",", "is_summary", "=", "False", ",", "*", "*", "extra", ")", ":", "self", ".", "col", "=", "col", "self", ".", "source", "=", "source", "self", ".", "is_summary", "=", "is_sum...
https://github.com/AppScale/gts/blob/46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9/AppServer/lib/django-1.4/django/db/models/sql/aggregates.py#L19-L63
ghostop14/sparrow-wifi
4b8289773ea4304872062f65a6ffc9352612b08e
sparrow-wifi.py
python
Divider.mouseMoveEvent
(self, event)
[]
def mouseMoveEvent(self, event): if event.buttons() == Qt.LeftButton: newPos = self.mapToParent(event.pos()) newPos.setX(1) self.move(newPos) self.mainWin.resizeEvent(event)
[ "def", "mouseMoveEvent", "(", "self", ",", "event", ")", ":", "if", "event", ".", "buttons", "(", ")", "==", "Qt", ".", "LeftButton", ":", "newPos", "=", "self", ".", "mapToParent", "(", "event", ".", "pos", "(", ")", ")", "newPos", ".", "setX", "(...
https://github.com/ghostop14/sparrow-wifi/blob/4b8289773ea4304872062f65a6ffc9352612b08e/sparrow-wifi.py#L411-L417
mediacloud/backend
d36b489e4fbe6e44950916a04d9543a1d6cd5df0
apps/topics-base/src/python/topics_base/stories.py
python
copy_story_to_new_medium
(db: DatabaseHandler, topic: dict, old_story: dict, new_medium: dict)
return story
Copy story to new medium. Copy the given story, assigning the new media_id and copying over the download, extracted text, and so on. Return the new story.
Copy story to new medium.
[ "Copy", "story", "to", "new", "medium", "." ]
def copy_story_to_new_medium(db: DatabaseHandler, topic: dict, old_story: dict, new_medium: dict) -> dict: """Copy story to new medium. Copy the given story, assigning the new media_id and copying over the download, extracted text, and so on. Return the new story. """ story = { 'url': old_story['url'], 'media_id': new_medium['media_id'], 'guid': old_story['guid'], 'publish_date': old_story['publish_date'], 'collect_date': sql_now(), 'description': old_story['description'], 'title': old_story['title'] } story = db.create('stories', story) add_to_topic_stories(db=db, story=story, topic=topic, valid_foreign_rss_story=True) db.query( """ insert into stories_tags_map (stories_id, tags_id) select %(a)s, stm.tags_id from stories_tags_map stm where stm.stories_id = %(b)s """, {'a': story['stories_id'], 'b': old_story['stories_id']}) feed = get_spider_feed(db, new_medium) db.create('feeds_stories_map', {'feeds_id': feed['feeds_id'], 'stories_id': story['stories_id']}) old_download = db.query( "select * from downloads where stories_id = %(a)s order by downloads_id limit 1", {'a': old_story['stories_id']}).hash() download = create_download_for_new_story(db, story, feed) if old_download is not None: try: content = fetch_content(db, old_download) download = store_content(db, download, content) except (McDBIDownloadsException, McAmazonS3StoreException): download_update = dict([(f, old_download[f]) for f in ['state', 'error_message', 'download_time']]) db.update_by_id('downloads', download['downloads_id'], download_update) db.query( """ insert into download_texts (downloads_id, download_text, download_text_length) select %(a)s, dt.download_text, dt.download_text_length from download_texts dt where dt.downloads_id = %(a)s """, {'a': download['downloads_id']}) # noinspection SqlInsertValues db.query( f""" insert into story_sentences (stories_id, sentence_number, sentence, media_id, publish_date, language) select {int(story['stories_id'])} as stories_id, sentence_number, sentence, media_id, publish_date, language from story_sentences where stories_id = %(b)s """, {'b': old_story['stories_id']}) return story
[ "def", "copy_story_to_new_medium", "(", "db", ":", "DatabaseHandler", ",", "topic", ":", "dict", ",", "old_story", ":", "dict", ",", "new_medium", ":", "dict", ")", "->", "dict", ":", "story", "=", "{", "'url'", ":", "old_story", "[", "'url'", "]", ",", ...
https://github.com/mediacloud/backend/blob/d36b489e4fbe6e44950916a04d9543a1d6cd5df0/apps/topics-base/src/python/topics_base/stories.py#L577-L639
missionpinball/mpf
8e6b74cff4ba06d2fec9445742559c1068b88582
mpf/platforms/lisy/lisy.py
python
LisyHardwarePlatform._watchdog
(self)
Periodically send watchdog.
Periodically send watchdog.
[ "Periodically", "send", "watchdog", "." ]
async def _watchdog(self): """Periodically send watchdog.""" while True: # send watchdog async with self._bus_lock: self.send_byte(LisyDefines.GeneralWatchdog) response = await self._read_byte() if response != 0: self.warning_log("Watchdog returned %s instead 0", response) # sleep 500ms await asyncio.sleep(.5)
[ "async", "def", "_watchdog", "(", "self", ")", ":", "while", "True", ":", "# send watchdog", "async", "with", "self", ".", "_bus_lock", ":", "self", ".", "send_byte", "(", "LisyDefines", ".", "GeneralWatchdog", ")", "response", "=", "await", "self", ".", "...
https://github.com/missionpinball/mpf/blob/8e6b74cff4ba06d2fec9445742559c1068b88582/mpf/platforms/lisy/lisy.py#L592-L602
bibanon/tubeup
7078d287ac00437fc1209daaf2dd1fe40ec9ca74
tubeup/TubeUp.py
python
TubeUp.archive_urls
(self, urls, custom_meta=None, cookie_file=None, proxy=None, ydl_username=None, ydl_password=None, use_download_archive=False)
Download and upload videos from youtube_dl supported sites to archive.org :param urls: List of url that will be downloaded and uploaded to archive.org :param custom_meta: A custom metadata that will be used when uploading the file with archive.org. :param cookie_file: A cookie file for YoutubeDL. :param proxy_url: A proxy url for YoutubeDL. :param ydl_username: Username that will be used to download the resources with youtube_dl. :param ydl_password: Password of the related username, will be used to download the resources with youtube_dl. :param use_download_archive: Record the video url to the download archive. This will download only videos not listed in the archive file. Record the IDs of all downloaded videos in it. :return: Tuple containing identifier and metadata of the file that has been uploaded to archive.org.
Download and upload videos from youtube_dl supported sites to archive.org
[ "Download", "and", "upload", "videos", "from", "youtube_dl", "supported", "sites", "to", "archive", ".", "org" ]
def archive_urls(self, urls, custom_meta=None, cookie_file=None, proxy=None, ydl_username=None, ydl_password=None, use_download_archive=False): """ Download and upload videos from youtube_dl supported sites to archive.org :param urls: List of url that will be downloaded and uploaded to archive.org :param custom_meta: A custom metadata that will be used when uploading the file with archive.org. :param cookie_file: A cookie file for YoutubeDL. :param proxy_url: A proxy url for YoutubeDL. :param ydl_username: Username that will be used to download the resources with youtube_dl. :param ydl_password: Password of the related username, will be used to download the resources with youtube_dl. :param use_download_archive: Record the video url to the download archive. This will download only videos not listed in the archive file. Record the IDs of all downloaded videos in it. :return: Tuple containing identifier and metadata of the file that has been uploaded to archive.org. """ downloaded_file_basenames = self.get_resource_basenames( urls, cookie_file, proxy, ydl_username, ydl_password, use_download_archive) for basename in downloaded_file_basenames: identifier, meta = self.upload_ia(basename, custom_meta) yield identifier, meta
[ "def", "archive_urls", "(", "self", ",", "urls", ",", "custom_meta", "=", "None", ",", "cookie_file", "=", "None", ",", "proxy", "=", "None", ",", "ydl_username", "=", "None", ",", "ydl_password", "=", "None", ",", "use_download_archive", "=", "False", ")"...
https://github.com/bibanon/tubeup/blob/7078d287ac00437fc1209daaf2dd1fe40ec9ca74/tubeup/TubeUp.py#L357-L387
PyMVPA/PyMVPA
76c476b3de8264b0bb849bf226da5674d659564e
mvpa2/clfs/stats.py
python
MCNullDist.__init__
(self, permutator, dist_class=Nonparametric, measure=None, **kwargs)
Initialize Monte-Carlo Permutation Null-hypothesis testing Parameters ---------- permutator : Node Node instance that generates permuted datasets. dist_class : class This can be any class which provides parameters estimate using `fit()` method to initialize the instance, and provides `cdf(x)` method for estimating value of x in CDF. All distributions from SciPy's 'stats' module can be used. measure : Measure or None Optional measure that is used to compute results on permuted data. If None, a measure needs to be passed to ``fit()``.
Initialize Monte-Carlo Permutation Null-hypothesis testing
[ "Initialize", "Monte", "-", "Carlo", "Permutation", "Null", "-", "hypothesis", "testing" ]
def __init__(self, permutator, dist_class=Nonparametric, measure=None, **kwargs): """Initialize Monte-Carlo Permutation Null-hypothesis testing Parameters ---------- permutator : Node Node instance that generates permuted datasets. dist_class : class This can be any class which provides parameters estimate using `fit()` method to initialize the instance, and provides `cdf(x)` method for estimating value of x in CDF. All distributions from SciPy's 'stats' module can be used. measure : Measure or None Optional measure that is used to compute results on permuted data. If None, a measure needs to be passed to ``fit()``. """ NullDist.__init__(self, **kwargs) self._dist_class = dist_class self._dist = [] # actual distributions self._measure = measure self.__permutator = permutator
[ "def", "__init__", "(", "self", ",", "permutator", ",", "dist_class", "=", "Nonparametric", ",", "measure", "=", "None", ",", "*", "*", "kwargs", ")", ":", "NullDist", ".", "__init__", "(", "self", ",", "*", "*", "kwargs", ")", "self", ".", "_dist_clas...
https://github.com/PyMVPA/PyMVPA/blob/76c476b3de8264b0bb849bf226da5674d659564e/mvpa2/clfs/stats.py#L328-L351
holzschu/Carnets
44effb10ddfc6aa5c8b0687582a724ba82c6b547
Library/lib/python3.7/site-packages/pip/_vendor/chardet/charsetprober.py
python
CharSetProber.filter_with_english_letters
(buf)
return filtered
Returns a copy of ``buf`` that retains only the sequences of English alphabet and high byte characters that are not between <> characters. Also retains English alphabet and high byte characters immediately before occurrences of >. This filter can be applied to all scripts which contain both English characters and extended ASCII characters, but is currently only used by ``Latin1Prober``.
Returns a copy of ``buf`` that retains only the sequences of English alphabet and high byte characters that are not between <> characters. Also retains English alphabet and high byte characters immediately before occurrences of >.
[ "Returns", "a", "copy", "of", "buf", "that", "retains", "only", "the", "sequences", "of", "English", "alphabet", "and", "high", "byte", "characters", "that", "are", "not", "between", "<", ">", "characters", ".", "Also", "retains", "English", "alphabet", "and...
def filter_with_english_letters(buf): """ Returns a copy of ``buf`` that retains only the sequences of English alphabet and high byte characters that are not between <> characters. Also retains English alphabet and high byte characters immediately before occurrences of >. This filter can be applied to all scripts which contain both English characters and extended ASCII characters, but is currently only used by ``Latin1Prober``. """ filtered = bytearray() in_tag = False prev = 0 for curr in range(len(buf)): # Slice here to get bytes instead of an int with Python 3 buf_char = buf[curr:curr + 1] # Check if we're coming out of or entering an HTML tag if buf_char == b'>': in_tag = False elif buf_char == b'<': in_tag = True # If current character is not extended-ASCII and not alphabetic... if buf_char < b'\x80' and not buf_char.isalpha(): # ...and we're not in a tag if curr > prev and not in_tag: # Keep everything after last non-extended-ASCII, # non-alphabetic character filtered.extend(buf[prev:curr]) # Output a space to delimit stretch we kept filtered.extend(b' ') prev = curr + 1 # If we're not in a tag... if not in_tag: # Keep everything after last non-extended-ASCII, non-alphabetic # character filtered.extend(buf[prev:]) return filtered
[ "def", "filter_with_english_letters", "(", "buf", ")", ":", "filtered", "=", "bytearray", "(", ")", "in_tag", "=", "False", "prev", "=", "0", "for", "curr", "in", "range", "(", "len", "(", "buf", ")", ")", ":", "# Slice here to get bytes instead of an int with...
https://github.com/holzschu/Carnets/blob/44effb10ddfc6aa5c8b0687582a724ba82c6b547/Library/lib/python3.7/site-packages/pip/_vendor/chardet/charsetprober.py#L104-L145
polakowo/vectorbt
6638735c131655760474d72b9f045d1dbdbd8fe9
vectorbt/utils/schedule_.py
python
ScheduleManager.async_start
(self, sleep: int = 1)
Async run pending jobs in a loop.
Async run pending jobs in a loop.
[ "Async", "run", "pending", "jobs", "in", "a", "loop", "." ]
async def async_start(self, sleep: int = 1) -> None: """Async run pending jobs in a loop.""" logger.info("Starting schedule manager in the background with jobs %s", str(self.scheduler.jobs)) logger.info("Jobs: %s", str(self.scheduler.jobs)) try: while True: await self.scheduler.async_run_pending() await asyncio.sleep(sleep) except asyncio.CancelledError: logger.info("Stopping schedule manager")
[ "async", "def", "async_start", "(", "self", ",", "sleep", ":", "int", "=", "1", ")", "->", "None", ":", "logger", ".", "info", "(", "\"Starting schedule manager in the background with jobs %s\"", ",", "str", "(", "self", ".", "scheduler", ".", "jobs", ")", "...
https://github.com/polakowo/vectorbt/blob/6638735c131655760474d72b9f045d1dbdbd8fe9/vectorbt/utils/schedule_.py#L250-L259
chipmuenk/pyfda
665310b8548a940a575c0e5ff4bba94608d9ac26
pyfda/libs/pyfda_lib.py
python
fil_save
(fil_dict: dict, arg, format_in: str, sender: str, convert: bool = True)
Save filter design ``arg`` given in the format specified as ``format_in`` in the dictionary ``fil_dict``. The format can be either poles / zeros / gain, filter coefficients (polynomes) or second-order sections. Convert the filter design to the other formats if ``convert`` is True. Parameters ---------- fil_dict : dict The dictionary where the filter design is saved to. arg : various formats The actual filter design format_in : string Specifies how the filter design in 'arg' is passed: :'ba': Coefficient form: Filter coefficients in FIR format (b, one dimensional) are automatically converted to IIR format (b, a). :'zpk': Zero / pole / gain format: When only zeroes are specified, poles and gain are added automatically. :'sos': Second-order sections sender : string The name of the method that calculated the filter. This name is stored in ``fil_dict`` together with ``format_in``. convert : boolean When ``convert = True``, convert arg to the other formats. Returns ------- None
Save filter design ``arg`` given in the format specified as ``format_in`` in the dictionary ``fil_dict``. The format can be either poles / zeros / gain, filter coefficients (polynomes) or second-order sections.
[ "Save", "filter", "design", "arg", "given", "in", "the", "format", "specified", "as", "format_in", "in", "the", "dictionary", "fil_dict", ".", "The", "format", "can", "be", "either", "poles", "/", "zeros", "/", "gain", "filter", "coefficients", "(", "polynom...
def fil_save(fil_dict: dict, arg, format_in: str, sender: str, convert: bool = True) -> None: """ Save filter design ``arg`` given in the format specified as ``format_in`` in the dictionary ``fil_dict``. The format can be either poles / zeros / gain, filter coefficients (polynomes) or second-order sections. Convert the filter design to the other formats if ``convert`` is True. Parameters ---------- fil_dict : dict The dictionary where the filter design is saved to. arg : various formats The actual filter design format_in : string Specifies how the filter design in 'arg' is passed: :'ba': Coefficient form: Filter coefficients in FIR format (b, one dimensional) are automatically converted to IIR format (b, a). :'zpk': Zero / pole / gain format: When only zeroes are specified, poles and gain are added automatically. :'sos': Second-order sections sender : string The name of the method that calculated the filter. This name is stored in ``fil_dict`` together with ``format_in``. convert : boolean When ``convert = True``, convert arg to the other formats. Returns ------- None """ if format_in == 'sos': fil_dict['sos'] = arg fil_dict['ft'] = 'IIR' elif format_in == 'zpk': if any(isinstance(el, list) for el in arg): frmt = "lol" # list or ndarray or tuple of lists elif any(isinstance(el, np.ndarray) for el in arg): frmt = "lon" # list or ndarray or tuple of ndarrays elif isinstance(arg, list): frmt = "lst" elif isinstance(arg, np.ndarray): frmt = "nd" format_error = False if frmt in {'lst', 'nd'}: # list / array with z only -> FIR z = arg p = np.zeros(len(z)) k = 1 fil_dict['zpk'] = [z, p, k] fil_dict['ft'] = 'FIR' elif frmt in {'lol', 'lon'}: # list of lists if len(arg) == 3: fil_dict['zpk'] = [arg[0], arg[1], arg[2]] if np.any(arg[1]): # non-zero poles -> IIR fil_dict['ft'] = 'IIR' else: fil_dict['ft'] = 'FIR' else: format_error = True else: format_error = True # ============================================================================= # if np.ndim(arg) == 1: # if np.ndim(arg[0]) == 0: # list / array with z only -> FIR # z = arg # p = np.zeros(len(z)) # k = 1 # fil_dict['zpk'] = [z, p, k] # fil_dict['ft'] = 'FIR' # elif np.ndim(arg[0]) == 1: # list of lists # if np.shape(arg)[0] == 3: # fil_dict['zpk'] = [arg[0], arg[1], arg[2]] # if np.any(arg[1]): # non-zero poles -> IIR # fil_dict['ft'] = 'IIR' # else: # fil_dict['ft'] = 'FIR' # else: # format_error = True # else: # format_error = True # else: # format_error = True # # ============================================================================= if format_error: raise ValueError("\t'fil_save()': Unknown 'zpk' format {0}".format(arg)) elif format_in == 'ba': if np.ndim(arg) == 1: # arg = [b] -> FIR # convert to type array, trim trailing zeros which correspond to # (superfluous) highest order polynomial with coefficient 0 as they # cause trouble when converting to zpk format b = np.trim_zeros(np.asarray(arg)) a = np.zeros(len(b)) else: # arg = [b,a] b = arg[0] a = arg[1] if len(b) < 2: # no proper coefficients, initialize with a default b = np.asarray([1, 0]) if len(a) < 2: # no proper coefficients, initialize with a default a = np.asarray([1, 0]) a[0] = 1 # first coefficient of recursive filter parts always = 1 # Determine whether it's a FIR or IIR filter and set fil_dict accordingly # Test whether all elements except the first one are zero if not np.any(a[1:]): fil_dict['ft'] = 'FIR' else: fil_dict['ft'] = 'IIR' # equalize if b and a subarrays have different lengths: D = len(b) - len(a) if D > 0: # b is longer than a -> fill up a with zeros a = np.append(a, np.zeros(D)) elif D < 0: # a is longer than b -> fill up b with zeros if fil_dict['ft'] == 'IIR': b = np.append(b, np.zeros(-D)) # make filter causal, fill up b with zeros else: a = a[:D] # discard last D elements of a (only zeros anyway) fil_dict['N'] = len(b) - 1 # correct filter order accordingly fil_dict['ba'] = [np.array(b, dtype=complex), np.array(a, dtype=complex)] else: raise ValueError("\t'fil_save()':Unknown input format {0:s}".format(format_in)) fil_dict['creator'] = (format_in, sender) fil_dict['timestamp'] = time.time() # Remove any antiCausal zero/poles if 'zpkA' in fil_dict: fil_dict.pop('zpkA') if 'baA' in fil_dict: fil_dict.pop('baA') if 'rpk' in fil_dict: fil_dict.pop('rpk') if convert: fil_convert(fil_dict, format_in)
[ "def", "fil_save", "(", "fil_dict", ":", "dict", ",", "arg", ",", "format_in", ":", "str", ",", "sender", ":", "str", ",", "convert", ":", "bool", "=", "True", ")", "->", "None", ":", "if", "format_in", "==", "'sos'", ":", "fil_dict", "[", "'sos'", ...
https://github.com/chipmuenk/pyfda/blob/665310b8548a940a575c0e5ff4bba94608d9ac26/pyfda/libs/pyfda_lib.py#L1302-L1455
PaddlePaddle/PaddleX
2bab73f81ab54e328204e7871e6ae4a82e719f5d
paddlex/paddleseg/models/backbones/xception_deeplab.py
python
Xception_Block.forward
(self, inputs)
return x + skip
[]
def forward(self, inputs): if not self.activation_fn_in_separable_conv: x = F.relu(inputs) x = self._conv1(x) x = F.relu(x) x = self._conv2(x) x = F.relu(x) x = self._conv3(x) else: x = self._conv1(inputs) x = self._conv2(x) x = self._conv3(x) if self.has_skip is False: return x if self.skip_conv: skip = self._short(inputs) else: skip = inputs return x + skip
[ "def", "forward", "(", "self", ",", "inputs", ")", ":", "if", "not", "self", ".", "activation_fn_in_separable_conv", ":", "x", "=", "F", ".", "relu", "(", "inputs", ")", "x", "=", "self", ".", "_conv1", "(", "x", ")", "x", "=", "F", ".", "relu", ...
https://github.com/PaddlePaddle/PaddleX/blob/2bab73f81ab54e328204e7871e6ae4a82e719f5d/paddlex/paddleseg/models/backbones/xception_deeplab.py#L228-L246