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
SanPen/GridCal
d3f4566d2d72c11c7e910c9d162538ef0e60df31
src/GridCal/ThirdParty/pulp/pulp.py
python
permutation
(orgset, k=None)
returns an iterator that lists the permutations of orgset of length k :param orgset: the list to be iterated :param k: the cardinality of the subsets :return: an iterator of the subsets example: >>> c = permutation([1,2,3,4],2) >>> for s in c: ... print(s) (1, 2) (1, 3) (1, 4) (2, 1) (2, 3) (2, 4) (3, 1) (3, 2) (3, 4) (4, 1) (4, 2) (4, 3)
returns an iterator that lists the permutations of orgset of length k
[ "returns", "an", "iterator", "that", "lists", "the", "permutations", "of", "orgset", "of", "length", "k" ]
def permutation(orgset, k=None): """ returns an iterator that lists the permutations of orgset of length k :param orgset: the list to be iterated :param k: the cardinality of the subsets :return: an iterator of the subsets example: >>> c = permutation([1,2,3,4],2) >>> for s in c: ... print(s) (1, 2) (1, 3) (1, 4) (2, 1) (2, 3) (2, 4) (3, 1) (3, 2) (3, 4) (4, 1) (4, 2) (4, 3) """ try: from itertools import permutation as _it_permutation return _it_permutation(orgset, k) except ImportError: return __permutation(orgset, k)
[ "def", "permutation", "(", "orgset", ",", "k", "=", "None", ")", ":", "try", ":", "from", "itertools", "import", "permutation", "as", "_it_permutation", "return", "_it_permutation", "(", "orgset", ",", "k", ")", "except", "ImportError", ":", "return", "__per...
https://github.com/SanPen/GridCal/blob/d3f4566d2d72c11c7e910c9d162538ef0e60df31/src/GridCal/ThirdParty/pulp/pulp.py#L2207-L2239
IronLanguages/ironpython2
51fdedeeda15727717fb8268a805f71b06c0b9f1
Src/StdLib/repackage/setuptools/setuptools/_vendor/pyparsing.py
python
ParserElement.__or__
(self, other )
return MatchFirst( [ self, other ] )
Implementation of | operator - returns C{L{MatchFirst}}
Implementation of | operator - returns C{L{MatchFirst}}
[ "Implementation", "of", "|", "operator", "-", "returns", "C", "{", "L", "{", "MatchFirst", "}}" ]
def __or__(self, other ): """ Implementation of | operator - returns C{L{MatchFirst}} """ if isinstance( other, basestring ): other = ParserElement._literalStringClass( other ) if not isinstance( other, ParserElement ): warnings.warn("Cannot combine element of type %s with ParserElement" % type(other), SyntaxWarning, stacklevel=2) return None return MatchFirst( [ self, other ] )
[ "def", "__or__", "(", "self", ",", "other", ")", ":", "if", "isinstance", "(", "other", ",", "basestring", ")", ":", "other", "=", "ParserElement", ".", "_literalStringClass", "(", "other", ")", "if", "not", "isinstance", "(", "other", ",", "ParserElement"...
https://github.com/IronLanguages/ironpython2/blob/51fdedeeda15727717fb8268a805f71b06c0b9f1/Src/StdLib/repackage/setuptools/setuptools/_vendor/pyparsing.py#L1948-L1958
rigetti/grove
dc6bf6ec63e8c435fe52b1e00f707d5ce4cdb9b3
grove/utils/utility_programs.py
python
ControlledProgramBuilder.with_operation
(self, operation)
return self
Sets the operation that defines the controlled gate. :param numpy.ndarray operation: The unitary gate to be controlled, given as a numpy array. :return: self, with operation set. :rtype: ControlledProgramBuilder
Sets the operation that defines the controlled gate.
[ "Sets", "the", "operation", "that", "defines", "the", "controlled", "gate", "." ]
def with_operation(self, operation): """Sets the operation that defines the controlled gate. :param numpy.ndarray operation: The unitary gate to be controlled, given as a numpy array. :return: self, with operation set. :rtype: ControlledProgramBuilder """ self.operation = operation return self
[ "def", "with_operation", "(", "self", ",", "operation", ")", ":", "self", ".", "operation", "=", "operation", "return", "self" ]
https://github.com/rigetti/grove/blob/dc6bf6ec63e8c435fe52b1e00f707d5ce4cdb9b3/grove/utils/utility_programs.py#L76-L84
F8LEFT/DecLLVM
d38e45e3d0dd35634adae1d0cf7f96f3bd96e74c
python/idaapi.py
python
is_type_uchar
(*args)
return _idaapi.is_type_uchar(*args)
is_type_uchar(t) -> bool
is_type_uchar(t) -> bool
[ "is_type_uchar", "(", "t", ")", "-", ">", "bool" ]
def is_type_uchar(*args): """ is_type_uchar(t) -> bool """ return _idaapi.is_type_uchar(*args)
[ "def", "is_type_uchar", "(", "*", "args", ")", ":", "return", "_idaapi", ".", "is_type_uchar", "(", "*", "args", ")" ]
https://github.com/F8LEFT/DecLLVM/blob/d38e45e3d0dd35634adae1d0cf7f96f3bd96e74c/python/idaapi.py#L28460-L28464
allenai/document-qa
2f9fa6878b60ed8a8a31bcf03f802cde292fe48b
docqa/scripts/train_bidaf.py
python
main
()
A close-as-possible impelemntation of BiDaF, its based on the `dev` tensorflow 1.1 branch of Ming's repo which, in particular, uses Adam not Adadelta. I was not able to replicate the results in paper using Adadelta, but with Adam i was able to get to 78.0 F1 on the dev set with this scripts. I believe this approach is an exact reproduction up the code in the repo, up to initializations. Notes: Exponential Moving Average is very important, as is early stopping. This is also in particualr best run on a GPU due to the large number of parameters and batch size involved.
A close-as-possible impelemntation of BiDaF, its based on the `dev` tensorflow 1.1 branch of Ming's repo which, in particular, uses Adam not Adadelta. I was not able to replicate the results in paper using Adadelta, but with Adam i was able to get to 78.0 F1 on the dev set with this scripts. I believe this approach is an exact reproduction up the code in the repo, up to initializations.
[ "A", "close", "-", "as", "-", "possible", "impelemntation", "of", "BiDaF", "its", "based", "on", "the", "dev", "tensorflow", "1", ".", "1", "branch", "of", "Ming", "s", "repo", "which", "in", "particular", "uses", "Adam", "not", "Adadelta", ".", "I", "...
def main(): """ A close-as-possible impelemntation of BiDaF, its based on the `dev` tensorflow 1.1 branch of Ming's repo which, in particular, uses Adam not Adadelta. I was not able to replicate the results in paper using Adadelta, but with Adam i was able to get to 78.0 F1 on the dev set with this scripts. I believe this approach is an exact reproduction up the code in the repo, up to initializations. Notes: Exponential Moving Average is very important, as is early stopping. This is also in particualr best run on a GPU due to the large number of parameters and batch size involved. """ out = get_output_name_from_cli() train_params = TrainParams(SerializableOptimizer("Adam", dict(learning_rate=0.001)), num_epochs=12, ema=0.999, async_encoding=10, log_period=30, eval_period=1000, save_period=1000, eval_samples=dict(dev=None, train=8000)) # recurrent_layer = BiRecurrentMapper(LstmCellSpec(100, keep_probs=0.8)) # recurrent_layer = FusedLstm() recurrent_layer = SequenceMapperSeq(DropoutLayer(0.8), CudnnLstm(100)) model = Attention( encoder=DocumentAndQuestionEncoder(SingleSpanAnswerEncoder()), word_embed=FixedWordEmbedder(vec_name="glove.6B.100d", word_vec_init_scale=0, learn_unk=False), char_embed=CharWordEmbedder( embedder=LearnedCharEmbedder(16, 49, 8), layer=ReduceLayer("max", Conv1d(100, 5, 0.8), mask=False), shared_parameters=True ), word_embed_layer=None, embed_mapper=SequenceMapperSeq( HighwayLayer(activation="relu"), HighwayLayer(activation="relu"), recurrent_layer), preprocess=None, question_mapper=None, context_mapper=None, memory_builder=NullBiMapper(), attention=BiAttention(TriLinear(bias=True), True), match_encoder=NullMapper(), predictor= BoundsPredictor( ChainConcat( start_layer=SequenceMapperSeq( recurrent_layer, recurrent_layer), end_layer=recurrent_layer ) ), ) with open(__file__, "r") as f: notes = f.read() eval = [LossEvaluator(), SpanEvaluator(bound=[17], text_eval="squad")] corpus = SquadCorpus() train_batching = ClusteredBatcher(60, ContextLenBucketedKey(3), True, False) eval_batching = ClusteredBatcher(60, ContextLenKey(), False, False) data = DocumentQaTrainingData(corpus, None, train_batching, eval_batching) trainer.start_training(data, model, train_params, eval, model_dir.ModelDir(out), notes)
[ "def", "main", "(", ")", ":", "out", "=", "get_output_name_from_cli", "(", ")", "train_params", "=", "TrainParams", "(", "SerializableOptimizer", "(", "\"Adam\"", ",", "dict", "(", "learning_rate", "=", "0.001", ")", ")", ",", "num_epochs", "=", "12", ",", ...
https://github.com/allenai/document-qa/blob/2f9fa6878b60ed8a8a31bcf03f802cde292fe48b/docqa/scripts/train_bidaf.py#L21-L81
SymbiFlow/symbiflow-arch-defs
f38793112ff78a06de9f1e3269bd22543e29729f
xc/common/libraries/parse_pdf_modules.py
python
find_pages
(pgs, start, stop)
Find all the pages between the resolved "start" and "stop" actions
Find all the pages between the resolved "start" and "stop" actions
[ "Find", "all", "the", "pages", "between", "the", "resolved", "start", "and", "stop", "actions" ]
def find_pages(pgs, start, stop): """Find all the pages between the resolved "start" and "stop" actions""" extract = False bottom = PAGE_MARGIN for pg in pgs: if pg.pageid == start[0].objid: extract = True top = start[1] - HEADER_MARGIN else: top = pg.mediabox[3] - PAGE_MARGIN if pg.pageid == stop[0].objid: bottom = stop[1] if extract: yield pg, top, bottom if pg.pageid == stop[0].objid: return
[ "def", "find_pages", "(", "pgs", ",", "start", ",", "stop", ")", ":", "extract", "=", "False", "bottom", "=", "PAGE_MARGIN", "for", "pg", "in", "pgs", ":", "if", "pg", ".", "pageid", "==", "start", "[", "0", "]", ".", "objid", ":", "extract", "=", ...
https://github.com/SymbiFlow/symbiflow-arch-defs/blob/f38793112ff78a06de9f1e3269bd22543e29729f/xc/common/libraries/parse_pdf_modules.py#L190-L205
onaio/onadata
89ad16744e8f247fb748219476f6ac295869a95f
onadata/apps/logger/models/xform.py
python
XFormMixin.get_unique_id_string
(self, id_string, count=0)
return id_string
[]
def get_unique_id_string(self, id_string, count=0): # used to generate a new id_string for new data_dictionary object if # id_string already existed if self._id_string_already_exists_in_account(id_string): if count != 0: if re.match(r'\w+_\d+$', id_string): a = id_string.split('_') id_string = "_".join(a[:-1]) count += 1 id_string = "{}_{}".format(id_string, count) return self.get_unique_id_string(id_string, count) return id_string
[ "def", "get_unique_id_string", "(", "self", ",", "id_string", ",", "count", "=", "0", ")", ":", "# used to generate a new id_string for new data_dictionary object if", "# id_string already existed", "if", "self", ".", "_id_string_already_exists_in_account", "(", "id_string", ...
https://github.com/onaio/onadata/blob/89ad16744e8f247fb748219476f6ac295869a95f/onadata/apps/logger/models/xform.py#L291-L304
vulscanteam/vulscan
787397e267c4e6469522ee0abe55b3e98f968d4a
pocsuite/lib/core/common.py
python
isListLike
(value)
return isinstance(value, (list, tuple, set))
Returns True if the given value is a list-like instance >>> isListLike([1, 2, 3]) True >>> isListLike(u'2') False
Returns True if the given value is a list-like instance
[ "Returns", "True", "if", "the", "given", "value", "is", "a", "list", "-", "like", "instance" ]
def isListLike(value): """ Returns True if the given value is a list-like instance >>> isListLike([1, 2, 3]) True >>> isListLike(u'2') False """ return isinstance(value, (list, tuple, set))
[ "def", "isListLike", "(", "value", ")", ":", "return", "isinstance", "(", "value", ",", "(", "list", ",", "tuple", ",", "set", ")", ")" ]
https://github.com/vulscanteam/vulscan/blob/787397e267c4e6469522ee0abe55b3e98f968d4a/pocsuite/lib/core/common.py#L211-L221
gevent/gevent
ae2cb5aeb2aea8987efcb90a4c50ca4e1ee12c31
src/gevent/resolver/_addresses.py
python
_ipv6_inet_aton
(text, _v4_ending=re.compile(br'(.*):(\d+\.\d+\.\d+\.\d+)$'), _colon_colon_start=re.compile(br'::.*'), _colon_colon_end=re.compile(br'.*::$'))
Convert an IPv6 address in text form to binary form. *text*, a ``text``, the IPv6 address in textual form. Returns a ``binary``.
Convert an IPv6 address in text form to binary form.
[ "Convert", "an", "IPv6", "address", "in", "text", "form", "to", "binary", "form", "." ]
def _ipv6_inet_aton(text, _v4_ending=re.compile(br'(.*):(\d+\.\d+\.\d+\.\d+)$'), _colon_colon_start=re.compile(br'::.*'), _colon_colon_end=re.compile(br'.*::$')): """ Convert an IPv6 address in text form to binary form. *text*, a ``text``, the IPv6 address in textual form. Returns a ``binary``. """ # pylint:disable=too-many-branches # # Our aim here is not something fast; we just want something that works. # if not isinstance(text, bytes): text = text.encode() if text == b'::': text = b'0::' # # Get rid of the icky dot-quad syntax if we have it. # m = _v4_ending.match(text) if not m is None: b = bytearray(_ipv4_inet_aton(m.group(2))) text = (u"{}:{:02x}{:02x}:{:02x}{:02x}".format(m.group(1).decode(), b[0], b[1], b[2], b[3])).encode() # # Try to turn '::<whatever>' into ':<whatever>'; if no match try to # turn '<whatever>::' into '<whatever>:' # m = _colon_colon_start.match(text) if not m is None: text = text[1:] else: m = _colon_colon_end.match(text) if not m is None: text = text[:-1] # # Now canonicalize into 8 chunks of 4 hex digits each # chunks = text.split(b':') l = len(chunks) if l > 8: raise SyntaxError seen_empty = False canonical = [] for c in chunks: if c == b'': if seen_empty: raise AddressSyntaxError(text) seen_empty = True for _ in range(0, 8 - l + 1): canonical.append(b'0000') else: lc = len(c) if lc > 4: raise AddressSyntaxError(text) if lc != 4: c = (b'0' * (4 - lc)) + c canonical.append(c) if l < 8 and not seen_empty: raise AddressSyntaxError(text) text = b''.join(canonical) # # Finally we can go to binary. # try: return binascii.unhexlify(text) except (binascii.Error, TypeError): raise AddressSyntaxError(text)
[ "def", "_ipv6_inet_aton", "(", "text", ",", "_v4_ending", "=", "re", ".", "compile", "(", "br'(.*):(\\d+\\.\\d+\\.\\d+\\.\\d+)$'", ")", ",", "_colon_colon_start", "=", "re", ".", "compile", "(", "br'::.*'", ")", ",", "_colon_colon_end", "=", "re", ".", "compile"...
https://github.com/gevent/gevent/blob/ae2cb5aeb2aea8987efcb90a4c50ca4e1ee12c31/src/gevent/resolver/_addresses.py#L67-L141
berkeleydeeprlcourse/homework_fall2019
e9725d8aba926e2fe1c743f881884111b44e33bb
hw3/cs285/infrastructure/dqn_utils.py
python
MemoryOptimizedReplayBuffer.can_sample
(self, batch_size)
return batch_size + 1 <= self.num_in_buffer
Returns true if `batch_size` different transitions can be sampled from the buffer.
Returns true if `batch_size` different transitions can be sampled from the buffer.
[ "Returns", "true", "if", "batch_size", "different", "transitions", "can", "be", "sampled", "from", "the", "buffer", "." ]
def can_sample(self, batch_size): """Returns true if `batch_size` different transitions can be sampled from the buffer.""" return batch_size + 1 <= self.num_in_buffer
[ "def", "can_sample", "(", "self", ",", "batch_size", ")", ":", "return", "batch_size", "+", "1", "<=", "self", ".", "num_in_buffer" ]
https://github.com/berkeleydeeprlcourse/homework_fall2019/blob/e9725d8aba926e2fe1c743f881884111b44e33bb/hw3/cs285/infrastructure/dqn_utils.py#L347-L349
dimagi/commcare-hq
d67ff1d3b4c51fa050c19e60c3253a79d3452a39
corehq/apps/api/resources/v0_3.py
python
CommCareCaseResource.obj_get_list
(self, bundle, domain, **kwargs)
return ElasticAPIQuerySet( payload=es_query, model=ESCase, es_client=self.case_es(domain) ).order_by('server_modified_on')
[]
def obj_get_list(self, bundle, domain, **kwargs): try: es_query = es_query_from_get_params(bundle.request.GET, domain, doc_type='case') except Http400 as e: raise BadRequest(str(e)) return ElasticAPIQuerySet( payload=es_query, model=ESCase, es_client=self.case_es(domain) ).order_by('server_modified_on')
[ "def", "obj_get_list", "(", "self", ",", "bundle", ",", "domain", ",", "*", "*", "kwargs", ")", ":", "try", ":", "es_query", "=", "es_query_from_get_params", "(", "bundle", ".", "request", ".", "GET", ",", "domain", ",", "doc_type", "=", "'case'", ")", ...
https://github.com/dimagi/commcare-hq/blob/d67ff1d3b4c51fa050c19e60c3253a79d3452a39/corehq/apps/api/resources/v0_3.py#L64-L74
dragonbook/V2V-PoseNet-pytorch
90045b61c45f18dc20b410e2de14bd22be55fe0e
lib/accuracy.py
python
compute_mean_err
(pred, gt)
return np.mean(err_dist, axis=0)
pred: (N, K, 3) gt: (N, K, 3) mean_err: (K,)
pred: (N, K, 3) gt: (N, K, 3)
[ "pred", ":", "(", "N", "K", "3", ")", "gt", ":", "(", "N", "K", "3", ")" ]
def compute_mean_err(pred, gt): ''' pred: (N, K, 3) gt: (N, K, 3) mean_err: (K,) ''' N, K = pred.shape[0], pred.shape[1] err_dist = np.sqrt(np.sum((pred - gt)**2, axis=2)) # (N, K) return np.mean(err_dist, axis=0)
[ "def", "compute_mean_err", "(", "pred", ",", "gt", ")", ":", "N", ",", "K", "=", "pred", ".", "shape", "[", "0", "]", ",", "pred", ".", "shape", "[", "1", "]", "err_dist", "=", "np", ".", "sqrt", "(", "np", ".", "sum", "(", "(", "pred", "-", ...
https://github.com/dragonbook/V2V-PoseNet-pytorch/blob/90045b61c45f18dc20b410e2de14bd22be55fe0e/lib/accuracy.py#L42-L51
plasticityai/magnitude
7ac0baeaf181263b661c3ae00643d21e3fd90216
pymagnitude/third_party/_pysqlite/__init__.py
python
Magnitude._db_full_result_to_vec
(self, result, put_cache=True)
Converts a full database result to a vector.
Converts a full database result to a vector.
[ "Converts", "a", "full", "database", "result", "to", "a", "vector", "." ]
def _db_full_result_to_vec(self, result, put_cache=True): """Converts a full database result to a vector.""" result_key = result[0] if self._query_is_cached(result_key): return (result_key, self.query(result_key)) else: vec = self._db_result_to_vec(result[1:]) if put_cache: self._vector_for_key_cached._cache.put((result_key,), vec) return (result_key, vec)
[ "def", "_db_full_result_to_vec", "(", "self", ",", "result", ",", "put_cache", "=", "True", ")", ":", "result_key", "=", "result", "[", "0", "]", "if", "self", ".", "_query_is_cached", "(", "result_key", ")", ":", "return", "(", "result_key", ",", "self", ...
https://github.com/plasticityai/magnitude/blob/7ac0baeaf181263b661c3ae00643d21e3fd90216/pymagnitude/third_party/_pysqlite/__init__.py#L718-L727
HymanLiuTS/flaskTs
286648286976e85d9b9a5873632331efcafe0b21
flasky/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py
python
RemoteConnection.set_timeout
(cls, timeout)
Override the default timeout :Args: - timeout - timeout value for http requests in seconds
Override the default timeout
[ "Override", "the", "default", "timeout" ]
def set_timeout(cls, timeout): """ Override the default timeout :Args: - timeout - timeout value for http requests in seconds """ cls._timeout = timeout
[ "def", "set_timeout", "(", "cls", ",", "timeout", ")", ":", "cls", ".", "_timeout", "=", "timeout" ]
https://github.com/HymanLiuTS/flaskTs/blob/286648286976e85d9b9a5873632331efcafe0b21/flasky/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py#L149-L156
aws-samples/aws-kube-codesuite
ab4e5ce45416b83bffb947ab8d234df5437f4fca
src/kubernetes/client/models/v1_security_context.py
python
V1SecurityContext.to_dict
(self)
return result
Returns the model properties as a dict
Returns the model properties as a dict
[ "Returns", "the", "model", "properties", "as", "a", "dict" ]
def to_dict(self): """ Returns the model properties as a dict """ result = {} for attr, _ in iteritems(self.swagger_types): value = getattr(self, attr) if isinstance(value, list): result[attr] = list(map( lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value )) elif hasattr(value, "to_dict"): result[attr] = value.to_dict() elif isinstance(value, dict): result[attr] = dict(map( lambda item: (item[0], item[1].to_dict()) if hasattr(item[1], "to_dict") else item, value.items() )) else: result[attr] = value return result
[ "def", "to_dict", "(", "self", ")", ":", "result", "=", "{", "}", "for", "attr", ",", "_", "in", "iteritems", "(", "self", ".", "swagger_types", ")", ":", "value", "=", "getattr", "(", "self", ",", "attr", ")", "if", "isinstance", "(", "value", ","...
https://github.com/aws-samples/aws-kube-codesuite/blob/ab4e5ce45416b83bffb947ab8d234df5437f4fca/src/kubernetes/client/models/v1_security_context.py#L196-L220
bslatkin/effectivepython
4ae6f3141291ea137eb29a245bf889dbc8091713
example_code/item_49.py
python
Point2D.__repr__
(self)
return f'Point2D({self.x}, {self.y})'
[]
def __repr__(self): return f'Point2D({self.x}, {self.y})'
[ "def", "__repr__", "(", "self", ")", ":", "return", "f'Point2D({self.x}, {self.y})'" ]
https://github.com/bslatkin/effectivepython/blob/4ae6f3141291ea137eb29a245bf889dbc8091713/example_code/item_49.py#L67-L68
newfies-dialer/newfies-dialer
8168b3dd43e9f5ce73a2645b3229def1b2815d47
newfies/appointment/utils.py
python
OccurrenceReplacer.get_additional_occurrences
(self, start, end)
return [occ for key, occ in self.lookup.items() if (occ.start < end and occ.end >= start and not occ.cancelled)]
Return persisted occurrences which are now in the period
Return persisted occurrences which are now in the period
[ "Return", "persisted", "occurrences", "which", "are", "now", "in", "the", "period" ]
def get_additional_occurrences(self, start, end): """ Return persisted occurrences which are now in the period """ return [occ for key, occ in self.lookup.items() if (occ.start < end and occ.end >= start and not occ.cancelled)]
[ "def", "get_additional_occurrences", "(", "self", ",", "start", ",", "end", ")", ":", "return", "[", "occ", "for", "key", ",", "occ", "in", "self", ".", "lookup", ".", "items", "(", ")", "if", "(", "occ", ".", "start", "<", "end", "and", "occ", "."...
https://github.com/newfies-dialer/newfies-dialer/blob/8168b3dd43e9f5ce73a2645b3229def1b2815d47/newfies/appointment/utils.py#L33-L37
samuelclay/NewsBlur
2c45209df01a1566ea105e04d499367f32ac9ad2
utils/S3.py
python
AWSAuthConnection.__init__
(self, aws_access_key_id, aws_secret_access_key, is_secure=True, server=DEFAULT_HOST, port=None, calling_format=CallingFormat.SUBDOMAIN)
[]
def __init__(self, aws_access_key_id, aws_secret_access_key, is_secure=True, server=DEFAULT_HOST, port=None, calling_format=CallingFormat.SUBDOMAIN): if not port: port = PORTS_BY_SECURITY[is_secure] self.aws_access_key_id = aws_access_key_id self.aws_secret_access_key = aws_secret_access_key self.is_secure = is_secure self.server = server self.port = port self.calling_format = calling_format
[ "def", "__init__", "(", "self", ",", "aws_access_key_id", ",", "aws_secret_access_key", ",", "is_secure", "=", "True", ",", "server", "=", "DEFAULT_HOST", ",", "port", "=", "None", ",", "calling_format", "=", "CallingFormat", ".", "SUBDOMAIN", ")", ":", "if", ...
https://github.com/samuelclay/NewsBlur/blob/2c45209df01a1566ea105e04d499367f32ac9ad2/utils/S3.py#L145-L156
oracle/oci-python-sdk
3c1604e4e212008fb6718e2f68cdb5ef71fd5793
src/oci/core/virtual_network_client.py
python
VirtualNetworkClient.create_security_list
(self, create_security_list_details, **kwargs)
Creates a new security list for the specified VCN. For more information about security lists, see `Security Lists`__. For information on the number of rules you can have in a security list, see `Service Limits`__. For the purposes of access control, you must provide the `OCID`__ of the compartment where you want the security list to reside. Notice that the security list doesn't have to be in the same compartment as the VCN, subnets, or other Networking Service components. If you're not sure which compartment to use, put the security list in the same compartment as the VCN. For more information about compartments and access control, see `Overview of the IAM Service`__. For information about OCIDs, see `Resource Identifiers`__. You may optionally specify a *display name* for the security list, otherwise a default is provided. It does not have to be unique, and you can change it. Avoid entering confidential information. __ https://docs.cloud.oracle.com/iaas/Content/Network/Concepts/securitylists.htm __ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/servicelimits.htm __ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm __ https://docs.cloud.oracle.com/iaas/Content/Identity/Concepts/overview.htm __ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm :param oci.core.models.CreateSecurityListDetails create_security_list_details: (required) Details regarding the security list to create. :param str opc_retry_token: (optional) A token that uniquely identifies a request so it can be retried in case of a timeout or server error without risk of executing that same action again. Retry tokens expire after 24 hours, but can be invalidated before then due to conflicting operations (for example, if a resource has been deleted and purged from the system, then a retry of the original creation request may be rejected). :param obj retry_strategy: (optional) A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level. This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it. The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__. To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`. :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.core.models.SecurityList` :rtype: :class:`~oci.response.Response` :example: Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/core/create_security_list.py.html>`__ to see an example of how to use create_security_list API.
Creates a new security list for the specified VCN. For more information about security lists, see `Security Lists`__. For information on the number of rules you can have in a security list, see `Service Limits`__.
[ "Creates", "a", "new", "security", "list", "for", "the", "specified", "VCN", ".", "For", "more", "information", "about", "security", "lists", "see", "Security", "Lists", "__", ".", "For", "information", "on", "the", "number", "of", "rules", "you", "can", "...
def create_security_list(self, create_security_list_details, **kwargs): """ Creates a new security list for the specified VCN. For more information about security lists, see `Security Lists`__. For information on the number of rules you can have in a security list, see `Service Limits`__. For the purposes of access control, you must provide the `OCID`__ of the compartment where you want the security list to reside. Notice that the security list doesn't have to be in the same compartment as the VCN, subnets, or other Networking Service components. If you're not sure which compartment to use, put the security list in the same compartment as the VCN. For more information about compartments and access control, see `Overview of the IAM Service`__. For information about OCIDs, see `Resource Identifiers`__. You may optionally specify a *display name* for the security list, otherwise a default is provided. It does not have to be unique, and you can change it. Avoid entering confidential information. __ https://docs.cloud.oracle.com/iaas/Content/Network/Concepts/securitylists.htm __ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/servicelimits.htm __ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm __ https://docs.cloud.oracle.com/iaas/Content/Identity/Concepts/overview.htm __ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm :param oci.core.models.CreateSecurityListDetails create_security_list_details: (required) Details regarding the security list to create. :param str opc_retry_token: (optional) A token that uniquely identifies a request so it can be retried in case of a timeout or server error without risk of executing that same action again. Retry tokens expire after 24 hours, but can be invalidated before then due to conflicting operations (for example, if a resource has been deleted and purged from the system, then a retry of the original creation request may be rejected). :param obj retry_strategy: (optional) A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level. This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it. The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__. To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`. :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.core.models.SecurityList` :rtype: :class:`~oci.response.Response` :example: Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/core/create_security_list.py.html>`__ to see an example of how to use create_security_list API. """ resource_path = "/securityLists" method = "POST" # Don't accept unknown kwargs expected_kwargs = [ "retry_strategy", "opc_retry_token" ] extra_kwargs = [_key for _key in six.iterkeys(kwargs) if _key not in expected_kwargs] if extra_kwargs: raise ValueError( "create_security_list got unknown kwargs: {!r}".format(extra_kwargs)) header_params = { "accept": "application/json", "content-type": "application/json", "opc-retry-token": kwargs.get("opc_retry_token", missing) } header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing and v is not None} retry_strategy = self.base_client.get_preferred_retry_strategy( operation_retry_strategy=kwargs.get('retry_strategy'), client_retry_strategy=self.retry_strategy ) if retry_strategy: if not isinstance(retry_strategy, retry.NoneRetryStrategy): self.base_client.add_opc_retry_token_if_needed(header_params) self.base_client.add_opc_client_retries_header(header_params) retry_strategy.add_circuit_breaker_callback(self.circuit_breaker_callback) return retry_strategy.make_retrying_call( self.base_client.call_api, resource_path=resource_path, method=method, header_params=header_params, body=create_security_list_details, response_type="SecurityList") else: return self.base_client.call_api( resource_path=resource_path, method=method, header_params=header_params, body=create_security_list_details, response_type="SecurityList")
[ "def", "create_security_list", "(", "self", ",", "create_security_list_details", ",", "*", "*", "kwargs", ")", ":", "resource_path", "=", "\"/securityLists\"", "method", "=", "\"POST\"", "# Don't accept unknown kwargs", "expected_kwargs", "=", "[", "\"retry_strategy\"", ...
https://github.com/oracle/oci-python-sdk/blob/3c1604e4e212008fb6718e2f68cdb5ef71fd5793/src/oci/core/virtual_network_client.py#L4959-L5050
paralelo14/google_explorer
0b21b57ef6fb7b9182fb13d00508164d007b2d19
exploits/joomraa.py
python
set_media_options
(options, sess, data)
return True
Allow us to upload a .pht file
Allow us to upload a .pht file
[ "Allow", "us", "to", "upload", "a", ".", "pht", "file" ]
def set_media_options(options, sess, data): """ Allow us to upload a .pht file """ print("[+] Setting media options") newdata = { 'jform[upload_extensions]': 'bmp,csv,doc,gif,ico,jpg,jpeg,odg,odp,ods,odt,pdf,png,ppt,swf,txt,xcf,xls,BMP,CSV,DOC,GIF,ICO,JPG,JPEG,ODG,ODP,ODS,ODT,PDF,PNG,PPT,SWF,TXT,XCF,XLS', 'jform[upload_maxsize]':10, 'jform[file_path]':'images', 'jform[image_path]':'images', 'jform[restrict_uploads]':1, 'jform[check_mime]':0, 'jform[image_extensions]':'bmp,gif,jpg,png', 'jform[ignore_extensions]': '', 'jform[upload_mime]': 'image/jpeg,image/gif,image/png,image/bmp,application/x-shockwave-flash,application/msword,application/excel,application/pdf,application/powerpoint,text/plain,application/x-zip', 'jform[upload_mime_illegal]':'text/html', 'id':13 } newdata.update(data) newdata['component'] = 'com_media' newdata['task'] = 'config.save.component.apply' config_url = options.url + '/administrator/index.php?option=com_config' resp = sess.post(config_url, data=newdata) if 'jform[upload_extensions]' not in resp.text: print('[!] Maybe failed to set media options...') return False return True
[ "def", "set_media_options", "(", "options", ",", "sess", ",", "data", ")", ":", "print", "(", "\"[+] Setting media options\"", ")", "newdata", "=", "{", "'jform[upload_extensions]'", ":", "'bmp,csv,doc,gif,ico,jpg,jpeg,odg,odp,ods,odt,pdf,png,ppt,swf,txt,xcf,xls,BMP,CSV,DOC,GIF...
https://github.com/paralelo14/google_explorer/blob/0b21b57ef6fb7b9182fb13d00508164d007b2d19/exploits/joomraa.py#L75-L101
amirassov/kaggle-imaterialist
f1ae37100801203500d20119b9de7e19b0d89a1c
mmdetection/mmdet/core/post_processing/merge_augs.py
python
merge_aug_masks
(aug_masks, img_metas, rcnn_test_cfg, weights=None)
return merged_masks
Merge augmented mask prediction. Args: aug_masks (list[ndarray]): shape (n, #class, h, w) img_shapes (list[ndarray]): shape (3, ). rcnn_test_cfg (dict): rcnn test config. Returns: tuple: (bboxes, scores)
Merge augmented mask prediction.
[ "Merge", "augmented", "mask", "prediction", "." ]
def merge_aug_masks(aug_masks, img_metas, rcnn_test_cfg, weights=None): """Merge augmented mask prediction. Args: aug_masks (list[ndarray]): shape (n, #class, h, w) img_shapes (list[ndarray]): shape (3, ). rcnn_test_cfg (dict): rcnn test config. Returns: tuple: (bboxes, scores) """ recovered_masks = [ mask if not img_info[0]['flip'] else mask[..., ::-1] for mask, img_info in zip(aug_masks, img_metas) ] if weights is None: merged_masks = np.mean(recovered_masks, axis=0) else: merged_masks = np.average( np.array(recovered_masks), axis=0, weights=np.array(weights)) return merged_masks
[ "def", "merge_aug_masks", "(", "aug_masks", ",", "img_metas", ",", "rcnn_test_cfg", ",", "weights", "=", "None", ")", ":", "recovered_masks", "=", "[", "mask", "if", "not", "img_info", "[", "0", "]", "[", "'flip'", "]", "else", "mask", "[", "...", ",", ...
https://github.com/amirassov/kaggle-imaterialist/blob/f1ae37100801203500d20119b9de7e19b0d89a1c/mmdetection/mmdet/core/post_processing/merge_augs.py#L76-L96
OpenCobolIDE/OpenCobolIDE
c78d0d335378e5fe0a5e74f53c19b68b55e85388
open_cobol_ide/controllers/cobol.py
python
CobolController._on_run_finished
(self)
[]
def _on_run_finished(self): self.enable_compile(True) self.enable_run(True)
[ "def", "_on_run_finished", "(", "self", ")", ":", "self", ".", "enable_compile", "(", "True", ")", "self", ".", "enable_run", "(", "True", ")" ]
https://github.com/OpenCobolIDE/OpenCobolIDE/blob/c78d0d335378e5fe0a5e74f53c19b68b55e85388/open_cobol_ide/controllers/cobol.py#L478-L480
openhatch/oh-mainline
ce29352a034e1223141dcc2f317030bbc3359a51
vendor/packages/gdata/src/gdata/apps/service.py
python
AppsService.GetGeneratorForAllNicknamesOfAUser
( self, user_name, num_retries=gdata.service.DEFAULT_NUM_RETRIES, delay=gdata.service.DEFAULT_DELAY, backoff=gdata.service.DEFAULT_BACKOFF)
return self.GetGeneratorFromLinkFinder( first_page, gdata.apps.NicknameFeedFromString, num_retries=num_retries, delay=delay, backoff=backoff)
Retrieve a generator for all nicknames of a particular user.
Retrieve a generator for all nicknames of a particular user.
[ "Retrieve", "a", "generator", "for", "all", "nicknames", "of", "a", "particular", "user", "." ]
def GetGeneratorForAllNicknamesOfAUser( self, user_name, num_retries=gdata.service.DEFAULT_NUM_RETRIES, delay=gdata.service.DEFAULT_DELAY, backoff=gdata.service.DEFAULT_BACKOFF): """Retrieve a generator for all nicknames of a particular user.""" uri = "%s/nickname/%s?username=%s" % (self._baseURL(), API_VER, user_name) try: first_page = gdata.apps.NicknameFeedFromString(str(self.GetWithRetries( uri, num_retries=num_retries, delay=delay, backoff=backoff))) except gdata.service.RequestError, e: raise AppsForYourDomainException(e.args[0]) return self.GetGeneratorFromLinkFinder( first_page, gdata.apps.NicknameFeedFromString, num_retries=num_retries, delay=delay, backoff=backoff)
[ "def", "GetGeneratorForAllNicknamesOfAUser", "(", "self", ",", "user_name", ",", "num_retries", "=", "gdata", ".", "service", ".", "DEFAULT_NUM_RETRIES", ",", "delay", "=", "gdata", ".", "service", ".", "DEFAULT_DELAY", ",", "backoff", "=", "gdata", ".", "servic...
https://github.com/openhatch/oh-mainline/blob/ce29352a034e1223141dcc2f317030bbc3359a51/vendor/packages/gdata/src/gdata/apps/service.py#L303-L315
aleju/imgaug
0101108d4fed06bc5056c4a03e2bcb0216dac326
imgaug/augmenters/geometric.py
python
_AffineSamplingResult.to_matrix
( self, idx, arr_shape, image_shape, fit_output, shift_add=(0.5, 0.5) )
return matrix, arr_shape
[]
def to_matrix( self, idx, arr_shape, image_shape, fit_output, shift_add=(0.5, 0.5) ): if 0 in image_shape: return np.eye(3, dtype=np.float32), arr_shape params = self.get_affine_parameters( idx, arr_shape=arr_shape, image_shape=image_shape ) matrix_gen = _AffineMatrixGenerator() matrix_gen.centerize(arr_shape) matrix_gen.translate(x_px=shift_add[1], y_px=shift_add[0]) matrix_gen.rotate(params["rotate_rad"]) matrix_gen.scale(x_frac=params["scale_x"], y_frac=params["scale_y"]) matrix_gen.shear(x_rad=params["shear_x_rad"], y_rad=params["shear_y_rad"]) matrix_gen.translate(x_px=params["translate_x_px"], y_px=params["translate_y_px"]) matrix_gen.translate(x_px=-shift_add[1], y_px=-shift_add[0]) matrix_gen.invert_centerize(arr_shape) matrix = matrix_gen.matrix if fit_output: matrix, arr_shape = _compute_affine_warp_output_shape( matrix, arr_shape ) return matrix, arr_shape
[ "def", "to_matrix", "(", "self", ",", "idx", ",", "arr_shape", ",", "image_shape", ",", "fit_output", ",", "shift_add", "=", "(", "0.5", ",", "0.5", ")", ")", ":", "if", "0", "in", "image_shape", ":", "return", "np", ".", "eye", "(", "3", ",", "dty...
https://github.com/aleju/imgaug/blob/0101108d4fed06bc5056c4a03e2bcb0216dac326/imgaug/augmenters/geometric.py#L742-L774
lad1337/XDM
0c1b7009fe00f06f102a6f67c793478f515e7efe
site-packages/logilab/common/tree.py
python
Node.flatten
(self, _list=None)
return _list
return a list with all the nodes descendant from this node
return a list with all the nodes descendant from this node
[ "return", "a", "list", "with", "all", "the", "nodes", "descendant", "from", "this", "node" ]
def flatten(self, _list=None): """ return a list with all the nodes descendant from this node """ if _list is None: _list = [] _list.append(self) for c in self.children: c.flatten(_list) return _list
[ "def", "flatten", "(", "self", ",", "_list", "=", "None", ")", ":", "if", "_list", "is", "None", ":", "_list", "=", "[", "]", "_list", ".", "append", "(", "self", ")", "for", "c", "in", "self", ".", "children", ":", "c", ".", "flatten", "(", "_...
https://github.com/lad1337/XDM/blob/0c1b7009fe00f06f102a6f67c793478f515e7efe/site-packages/logilab/common/tree.py#L208-L217
django-oscar/django-oscar
ffcc530844d40283b6b1552778a140536b904f5f
src/oscar/templatetags/display_tags.py
python
get_parameters
(context, except_field)
return ''
Renders current get parameters except for the specified parameter
Renders current get parameters except for the specified parameter
[ "Renders", "current", "get", "parameters", "except", "for", "the", "specified", "parameter" ]
def get_parameters(context, except_field): """ Renders current get parameters except for the specified parameter """ getvars = context['request'].GET.copy() getvars.pop(except_field, None) if len(getvars.keys()) > 0: return "%s&" % getvars.urlencode() return ''
[ "def", "get_parameters", "(", "context", ",", "except_field", ")", ":", "getvars", "=", "context", "[", "'request'", "]", ".", "GET", ".", "copy", "(", ")", "getvars", ".", "pop", "(", "except_field", ",", "None", ")", "if", "len", "(", "getvars", ".",...
https://github.com/django-oscar/django-oscar/blob/ffcc530844d40283b6b1552778a140536b904f5f/src/oscar/templatetags/display_tags.py#L9-L18
ansible-collections/community.general
3faffe8f47968a2400ba3c896c8901c03001a194
plugins/modules/nagios.py
python
Nagios.disable_svc_notifications
(self, host, services=None)
This command is used to prevent notifications from being sent out for the specified service. Note that this command does not disable notifications from being sent out about the host. Syntax: DISABLE_SVC_NOTIFICATIONS;<host_name>;<service_description>
This command is used to prevent notifications from being sent out for the specified service.
[ "This", "command", "is", "used", "to", "prevent", "notifications", "from", "being", "sent", "out", "for", "the", "specified", "service", "." ]
def disable_svc_notifications(self, host, services=None): """ This command is used to prevent notifications from being sent out for the specified service. Note that this command does not disable notifications from being sent out about the host. Syntax: DISABLE_SVC_NOTIFICATIONS;<host_name>;<service_description> """ cmd = "DISABLE_SVC_NOTIFICATIONS" if services is None: services = [] for service in services: notif_str = self._fmt_notif_str(cmd, host, svc=service) self._write_command(notif_str)
[ "def", "disable_svc_notifications", "(", "self", ",", "host", ",", "services", "=", "None", ")", ":", "cmd", "=", "\"DISABLE_SVC_NOTIFICATIONS\"", "if", "services", "is", "None", ":", "services", "=", "[", "]", "for", "service", "in", "services", ":", "notif...
https://github.com/ansible-collections/community.general/blob/3faffe8f47968a2400ba3c896c8901c03001a194/plugins/modules/nagios.py#L902-L920
abarker/pdfCropMargins
d9378cd6cba55ff137d80ff2d1f098bf6938f759
src/pdfCropMargins/external_program_calls.py
python
call_external_subprocess
(command_list, stdin_filename=None, stdout_filename=None, stderr_filename=None, env=None)
Run the command and arguments in the command_list. Will search the system PATH for commands to execute, but no shell is started. Redirects any selected outputs to the given filename. Waits for command completion.
Run the command and arguments in the command_list. Will search the system PATH for commands to execute, but no shell is started. Redirects any selected outputs to the given filename. Waits for command completion.
[ "Run", "the", "command", "and", "arguments", "in", "the", "command_list", ".", "Will", "search", "the", "system", "PATH", "for", "commands", "to", "execute", "but", "no", "shell", "is", "started", ".", "Redirects", "any", "selected", "outputs", "to", "the", ...
def call_external_subprocess(command_list, stdin_filename=None, stdout_filename=None, stderr_filename=None, env=None): """Run the command and arguments in the command_list. Will search the system PATH for commands to execute, but no shell is started. Redirects any selected outputs to the given filename. Waits for command completion.""" stdin = open(stdin_filename, "r") if stdin_filename else None stdout = open(stdout_filename, "w") if stdout_filename else None stderr = open(stderr_filename, "w") if stderr_filename else None subprocess.check_call(command_list, stdin=stdin, stdout=stdout, stderr=stderr, env=env) if stdin_filename: stdin.close() if stdout_filename: stdout.close() if stderr_filename: stderr.close()
[ "def", "call_external_subprocess", "(", "command_list", ",", "stdin_filename", "=", "None", ",", "stdout_filename", "=", "None", ",", "stderr_filename", "=", "None", ",", "env", "=", "None", ")", ":", "stdin", "=", "open", "(", "stdin_filename", ",", "\"r\"", ...
https://github.com/abarker/pdfCropMargins/blob/d9378cd6cba55ff137d80ff2d1f098bf6938f759/src/pdfCropMargins/external_program_calls.py#L322-L339
Tautulli/Tautulli
2410eb33805aaac4bd1c5dad0f71e4f15afaf742
lib/dns/update.py
python
UpdateMessage.update
(self, v)
[]
def update(self, v): self.sections[2] = v
[ "def", "update", "(", "self", ",", "v", ")", ":", "self", ".", "sections", "[", "2", "]", "=", "v" ]
https://github.com/Tautulli/Tautulli/blob/2410eb33805aaac4bd1c5dad0f71e4f15afaf742/lib/dns/update.py#L103-L104
devopshq/tfs
56644a36dd34457dec6922eb144c21db320f16e7
tfs/connection.py
python
TFSAPI.run_saved_query
(self, id)
return self._find_resource(Wiql, ids=id)
Run saved query by query id :param id: id of the query to run :return: instance of the Wiql object with query results
Run saved query by query id
[ "Run", "saved", "query", "by", "query", "id" ]
def run_saved_query(self, id): """ Run saved query by query id :param id: id of the query to run :return: instance of the Wiql object with query results """ return self._find_resource(Wiql, ids=id)
[ "def", "run_saved_query", "(", "self", ",", "id", ")", ":", "return", "self", ".", "_find_resource", "(", "Wiql", ",", "ids", "=", "id", ")" ]
https://github.com/devopshq/tfs/blob/56644a36dd34457dec6922eb144c21db320f16e7/tfs/connection.py#L237-L243
ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework
cb692f527e4e819b6c228187c5702d990a180043
external/Scripting Engine/Xenotix Python Scripting Engine/Lib/csv.py
python
Sniffer._guess_quote_and_delimiter
(self, data, delimiters)
return (quotechar, doublequote, delim, skipinitialspace)
Looks for text enclosed between two identical quotes (the probable quotechar) which are preceded and followed by the same character (the probable delimiter). For example: ,'some text', The quote with the most wins, same with the delimiter. If there is no quotechar the delimiter can't be determined this way.
Looks for text enclosed between two identical quotes (the probable quotechar) which are preceded and followed by the same character (the probable delimiter). For example: ,'some text', The quote with the most wins, same with the delimiter. If there is no quotechar the delimiter can't be determined this way.
[ "Looks", "for", "text", "enclosed", "between", "two", "identical", "quotes", "(", "the", "probable", "quotechar", ")", "which", "are", "preceded", "and", "followed", "by", "the", "same", "character", "(", "the", "probable", "delimiter", ")", ".", "For", "exa...
def _guess_quote_and_delimiter(self, data, delimiters): """ Looks for text enclosed between two identical quotes (the probable quotechar) which are preceded and followed by the same character (the probable delimiter). For example: ,'some text', The quote with the most wins, same with the delimiter. If there is no quotechar the delimiter can't be determined this way. """ matches = [] for restr in ('(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?", '(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)', # ".*?", '(?P<delim>>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)', # ,".*?" '(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space) regexp = re.compile(restr, re.DOTALL | re.MULTILINE) matches = regexp.findall(data) if matches: break if not matches: # (quotechar, doublequote, delimiter, skipinitialspace) return ('', False, None, 0) quotes = {} delims = {} spaces = 0 for m in matches: n = regexp.groupindex['quote'] - 1 key = m[n] if key: quotes[key] = quotes.get(key, 0) + 1 try: n = regexp.groupindex['delim'] - 1 key = m[n] except KeyError: continue if key and (delimiters is None or key in delimiters): delims[key] = delims.get(key, 0) + 1 try: n = regexp.groupindex['space'] - 1 except KeyError: continue if m[n]: spaces += 1 quotechar = reduce(lambda a, b, quotes = quotes: (quotes[a] > quotes[b]) and a or b, quotes.keys()) if delims: delim = reduce(lambda a, b, delims = delims: (delims[a] > delims[b]) and a or b, delims.keys()) skipinitialspace = delims[delim] == spaces if delim == '\n': # most likely a file with a single column delim = '' else: # there is *no* delimiter, it's a single column of quoted data delim = '' skipinitialspace = 0 # if we see an extra quote between delimiters, we've got a # double quoted format dq_regexp = re.compile(r"((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$)" % \ {'delim':delim, 'quote':quotechar}, re.MULTILINE) if dq_regexp.search(data): doublequote = True else: doublequote = False return (quotechar, doublequote, delim, skipinitialspace)
[ "def", "_guess_quote_and_delimiter", "(", "self", ",", "data", ",", "delimiters", ")", ":", "matches", "=", "[", "]", "for", "restr", "in", "(", "'(?P<delim>[^\\w\\n\"\\'])(?P<space> ?)(?P<quote>[\"\\']).*?(?P=quote)(?P=delim)'", ",", "# ,\".*?\",", "'(?:^|\\n)(?P<quote>[\"...
https://github.com/ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework/blob/cb692f527e4e819b6c228187c5702d990a180043/external/Scripting Engine/Xenotix Python Scripting Engine/Lib/csv.py#L201-L274
vrenkens/nabu
39deb62d182c7036c72f0f7eeb1d5c8eb0fb20fd
nabu/neuralnetworks/decoders/max_decoder.py
python
MaxDecoder.update_evaluation_loss
(self, loss, outputs, references, reference_seq_length)
return update_loss
update the evaluation loss args: loss: the current evaluation loss outputs: the outputs of the decoder as a dictionary references: the references as a dictionary reference_seq_length: the sequence lengths of the references Returns: an op to update the evalution loss
update the evaluation loss
[ "update", "the", "evaluation", "loss" ]
def update_evaluation_loss(self, loss, outputs, references, reference_seq_length): '''update the evaluation loss args: loss: the current evaluation loss outputs: the outputs of the decoder as a dictionary references: the references as a dictionary reference_seq_length: the sequence lengths of the references Returns: an op to update the evalution loss ''' #create a valiable to hold the total number of reference targets num_targets = tf.get_variable( name='num_targets', shape=[], dtype=tf.float32, initializer=tf.zeros_initializer(), trainable=False ) #stack all the logits stacked_outputs = { t:ops.stack_seq(outputs[t][0], outputs[t][1]) for t in outputs} #create the stacked targets stacked_targets = { t:tf.cast(ops.stack_seq(references[t], reference_seq_length[t]), tf.int32) for t in references} #compute the number of errors errors = [ tf.reduce_sum(tf.reduce_sum(tf.cast(tf.not_equal( stacked_outputs[o], stacked_targets[o]), tf.float32))) for o in outputs] errors = tf.reduce_sum(errors) #compute the number of targets in this batch batch_targets = tf.reduce_sum([ tf.reduce_sum(lengths) for lengths in reference_seq_length.values()]) new_num_targets = num_targets + tf.cast(batch_targets, tf.float32) #an operation to update the loss update_loss = loss.assign( (loss*num_targets + errors)/new_num_targets).op #add an operation to update the number of targets with tf.control_dependencies([update_loss]): update_loss = num_targets.assign(new_num_targets).op return update_loss
[ "def", "update_evaluation_loss", "(", "self", ",", "loss", ",", "outputs", ",", "references", ",", "reference_seq_length", ")", ":", "#create a valiable to hold the total number of reference targets", "num_targets", "=", "tf", ".", "get_variable", "(", "name", "=", "'nu...
https://github.com/vrenkens/nabu/blob/39deb62d182c7036c72f0f7eeb1d5c8eb0fb20fd/nabu/neuralnetworks/decoders/max_decoder.py#L75-L133
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/Python-2.7.9/Lib/plat-sunos5/TYPES.py
python
INT64_C
(c)
return __CONCAT__(c,ll)
[]
def INT64_C(c): return __CONCAT__(c,ll)
[ "def", "INT64_C", "(", "c", ")", ":", "return", "__CONCAT__", "(", "c", ",", "ll", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/Python-2.7.9/Lib/plat-sunos5/TYPES.py#L82-L82
andresriancho/w3af
cd22e5252243a87aaa6d0ddea47cf58dacfe00a9
w3af/plugins/attack/xpath.py
python
xpath._get_delimiter
(self, vuln, is_error_resp)
:return: The delimiter to be used to terminate strings, one of single quote or double quote. If an error is found, None is returned.
:return: The delimiter to be used to terminate strings, one of single quote or double quote. If an error is found, None is returned.
[ ":", "return", ":", "The", "delimiter", "to", "be", "used", "to", "terminate", "strings", "one", "of", "single", "quote", "or", "double", "quote", ".", "If", "an", "error", "is", "found", "None", "is", "returned", "." ]
def _get_delimiter(self, vuln, is_error_resp): """ :return: The delimiter to be used to terminate strings, one of single quote or double quote. If an error is found, None is returned. """ mutant = vuln.get_mutant() orig_value = mutant.get_token_original_value() true_sq = "%s' and '%i'='%i" % (orig_value, self.rnum, self.rnum) false_sq = "%s' and '%i'='%i" % (orig_value, self.rnum, self.rnum + 1) true_dq = '%s" and "%i"="%i' % (orig_value, self.rnum, self.rnum) false_dq = '%s" and "%i"="%i' % (orig_value, self.rnum, self.rnum + 1) to_test = [("'", true_sq, false_sq), ('"', true_dq, false_dq)] for str_delim, true_xpath, false_xpath in to_test: mutant_true = mutant.copy() mutant_false = mutant.copy() mutant_true.set_token_value(true_xpath) mutant_false.set_token_value(false_xpath) try: true_resp = self._uri_opener.send_mutant(mutant_true) false_resp = self._uri_opener.send_mutant(mutant_false) except BaseFrameworkException, e: om.out.debug('Error "%s"' % e) else: if (is_error_resp(false_resp.get_body()) and not is_error_resp(true_resp.get_body())): return str_delim else: msg = 'Failed to identify XPATH injection string delimiter.' raise BaseFrameworkException(msg)
[ "def", "_get_delimiter", "(", "self", ",", "vuln", ",", "is_error_resp", ")", ":", "mutant", "=", "vuln", ".", "get_mutant", "(", ")", "orig_value", "=", "mutant", ".", "get_token_original_value", "(", ")", "true_sq", "=", "\"%s' and '%i'='%i\"", "%", "(", "...
https://github.com/andresriancho/w3af/blob/cd22e5252243a87aaa6d0ddea47cf58dacfe00a9/w3af/plugins/attack/xpath.py#L154-L188
oracle/graalpython
577e02da9755d916056184ec441c26e00b70145c
graalpython/lib-python/3/http/cookiejar.py
python
DefaultCookiePolicy.return_ok_expires
(self, cookie, request)
return True
[]
def return_ok_expires(self, cookie, request): if cookie.is_expired(self._now): _debug(" cookie expired") return False return True
[ "def", "return_ok_expires", "(", "self", ",", "cookie", ",", "request", ")", ":", "if", "cookie", ".", "is_expired", "(", "self", ".", "_now", ")", ":", "_debug", "(", "\" cookie expired\"", ")", "return", "False", "return", "True" ]
https://github.com/oracle/graalpython/blob/577e02da9755d916056184ec441c26e00b70145c/graalpython/lib-python/3/http/cookiejar.py#L1133-L1137
smart-mobile-software/gitstack
d9fee8f414f202143eb6e620529e8e5539a2af56
python/Lib/site-packages/django/contrib/localflavor/uy/util.py
python
get_validation_digit
(number)
return (10-sum) % 10
Calculates the validation digit for the given number.
Calculates the validation digit for the given number.
[ "Calculates", "the", "validation", "digit", "for", "the", "given", "number", "." ]
def get_validation_digit(number): """ Calculates the validation digit for the given number. """ sum = 0 dvs = [4, 3, 6, 7, 8, 9, 2] number = str(number) for i in range(0, len(number)): sum = (int(number[-1 - i]) * dvs[i] + sum) % 10 return (10-sum) % 10
[ "def", "get_validation_digit", "(", "number", ")", ":", "sum", "=", "0", "dvs", "=", "[", "4", ",", "3", ",", "6", ",", "7", ",", "8", ",", "9", ",", "2", "]", "number", "=", "str", "(", "number", ")", "for", "i", "in", "range", "(", "0", "...
https://github.com/smart-mobile-software/gitstack/blob/d9fee8f414f202143eb6e620529e8e5539a2af56/python/Lib/site-packages/django/contrib/localflavor/uy/util.py#L3-L12
metamorphose/metamorphose2
d2bdd6a86340b9668e93b35a6a568894c9909d68
src/operations/changeLength.py
python
OpPanel.on_config_load
(self)
Update GUI elements, settings after config load.
Update GUI elements, settings after config load.
[ "Update", "GUI", "elements", "settings", "after", "config", "load", "." ]
def on_config_load(self): """Update GUI elements, settings after config load.""" self.__enable_options(False)
[ "def", "on_config_load", "(", "self", ")", ":", "self", ".", "__enable_options", "(", "False", ")" ]
https://github.com/metamorphose/metamorphose2/blob/d2bdd6a86340b9668e93b35a6a568894c9909d68/src/operations/changeLength.py#L137-L139
oracle/oci-python-sdk
3c1604e4e212008fb6718e2f68cdb5ef71fd5793
examples/list_resources_in_tenancy/list_limits_per_compartments.py
python
print_header
(name, category)
[]
def print_header(name, category): options = {0: 120, 1: 100, 2: 90, 3: 85} chars = int(options[category]) print("") print('#' * chars) print("#" + name.center(chars - 2, " ") + "#") print('#' * chars)
[ "def", "print_header", "(", "name", ",", "category", ")", ":", "options", "=", "{", "0", ":", "120", ",", "1", ":", "100", ",", "2", ":", "90", ",", "3", ":", "85", "}", "chars", "=", "int", "(", "options", "[", "category", "]", ")", "print", ...
https://github.com/oracle/oci-python-sdk/blob/3c1604e4e212008fb6718e2f68cdb5ef71fd5793/examples/list_resources_in_tenancy/list_limits_per_compartments.py#L77-L83
SpriteLink/NIPAP
de09cd7c4c55521f26f00201d694ea9e388b21a9
pynipap/pynipap.py
python
Pynipap.__init__
(self, id=None)
Creates logger and XML-RPC-connection.
Creates logger and XML-RPC-connection.
[ "Creates", "logger", "and", "XML", "-", "RPC", "-", "connection", "." ]
def __init__(self, id=None): """ Creates logger and XML-RPC-connection. """ self._logger = logging.getLogger(self.__class__.__name__) self._auth_opts = AuthOptions() self.id = id
[ "def", "__init__", "(", "self", ",", "id", "=", "None", ")", ":", "self", ".", "_logger", "=", "logging", ".", "getLogger", "(", "self", ".", "__class__", ".", "__name__", ")", "self", ".", "_auth_opts", "=", "AuthOptions", "(", ")", "self", ".", "id...
https://github.com/SpriteLink/NIPAP/blob/de09cd7c4c55521f26f00201d694ea9e388b21a9/pynipap/pynipap.py#L317-L323
oracle/graalpython
577e02da9755d916056184ec441c26e00b70145c
graalpython/lib-python/3/contextlib.py
python
closing.__exit__
(self, *exc_info)
[]
def __exit__(self, *exc_info): self.thing.close()
[ "def", "__exit__", "(", "self", ",", "*", "exc_info", ")", ":", "self", ".", "thing", ".", "close", "(", ")" ]
https://github.com/oracle/graalpython/blob/577e02da9755d916056184ec441c26e00b70145c/graalpython/lib-python/3/contextlib.py#L298-L299
matrix-org/synapse
8e57584a5859a9002759963eb546d523d2498a01
synapse/storage/databases/main/media_repository.py
python
MediaRepositoryStore.mark_local_media_as_safe
(self, media_id: str, safe: bool = True)
Mark a local media as safe or unsafe from quarantining.
Mark a local media as safe or unsafe from quarantining.
[ "Mark", "a", "local", "media", "as", "safe", "or", "unsafe", "from", "quarantining", "." ]
async def mark_local_media_as_safe(self, media_id: str, safe: bool = True) -> None: """Mark a local media as safe or unsafe from quarantining.""" await self.db_pool.simple_update_one( table="local_media_repository", keyvalues={"media_id": media_id}, updatevalues={"safe_from_quarantine": safe}, desc="mark_local_media_as_safe", )
[ "async", "def", "mark_local_media_as_safe", "(", "self", ",", "media_id", ":", "str", ",", "safe", ":", "bool", "=", "True", ")", "->", "None", ":", "await", "self", ".", "db_pool", ".", "simple_update_one", "(", "table", "=", "\"local_media_repository\"", "...
https://github.com/matrix-org/synapse/blob/8e57584a5859a9002759963eb546d523d2498a01/synapse/storage/databases/main/media_repository.py#L333-L340
ctxis/canape
5f0e03424577296bcc60c2008a60a98ec5307e4b
CANAPE.Scripting/Lib/_pyio.py
python
TextIOBase.encoding
(self)
return None
Subclasses should override.
Subclasses should override.
[ "Subclasses", "should", "override", "." ]
def encoding(self): """Subclasses should override.""" return None
[ "def", "encoding", "(", "self", ")", ":", "return", "None" ]
https://github.com/ctxis/canape/blob/5f0e03424577296bcc60c2008a60a98ec5307e4b/CANAPE.Scripting/Lib/_pyio.py#L1331-L1333
cisco/mindmeld
809c36112e9ea8019fe29d54d136ca14eb4fd8db
mindmeld/text_preparation/spacy_model_factory.py
python
SpacyModelFactory.validate_spacy_model_size
(spacy_model_size)
Check if the model size is valid. Args: spacy_model_size (str, optional): Size of the Spacy model to use. ("sm", "md", or "lg")
Check if the model size is valid.
[ "Check", "if", "the", "model", "size", "is", "valid", "." ]
def validate_spacy_model_size(spacy_model_size): """Check if the model size is valid. Args: spacy_model_size (str, optional): Size of the Spacy model to use. ("sm", "md", or "lg") """ if spacy_model_size not in SPACY_MODEL_SIZES: raise ValueError( "{!r} is not a valid model size. Select from: {!r}.".format( spacy_model_size, " ".join(SPACY_MODEL_SIZES) ) )
[ "def", "validate_spacy_model_size", "(", "spacy_model_size", ")", ":", "if", "spacy_model_size", "not", "in", "SPACY_MODEL_SIZES", ":", "raise", "ValueError", "(", "\"{!r} is not a valid model size. Select from: {!r}.\"", ".", "format", "(", "spacy_model_size", ",", "\" \""...
https://github.com/cisco/mindmeld/blob/809c36112e9ea8019fe29d54d136ca14eb4fd8db/mindmeld/text_preparation/spacy_model_factory.py#L61-L72
JiYou/openstack
8607dd488bde0905044b303eb6e52bdea6806923
packages/source/nova/nova/api/openstack/xmlutil.py
python
TemplateElement.get
(self, key)
return self.attrib[key]
Get an attribute. Returns a callable which performs datum selection. :param key: The name of the attribute to get.
Get an attribute.
[ "Get", "an", "attribute", "." ]
def get(self, key): """Get an attribute. Returns a callable which performs datum selection. :param key: The name of the attribute to get. """ return self.attrib[key]
[ "def", "get", "(", "self", ",", "key", ")", ":", "return", "self", ".", "attrib", "[", "key", "]" ]
https://github.com/JiYou/openstack/blob/8607dd488bde0905044b303eb6e52bdea6806923/packages/source/nova/nova/api/openstack/xmlutil.py#L275-L283
snakemake/snakemake
987282dde8a2db5174414988c134a39ae8836a61
snakemake/io.py
python
expand
(*args, **wildcards)
Expand wildcards in given filepatterns. Arguments *args -- first arg: filepatterns as list or one single filepattern, second arg (optional): a function to combine wildcard values (itertools.product per default) **wildcards -- the wildcards as keyword arguments with their values as lists. If allow_missing=True is included wildcards in filepattern without values will stay unformatted.
Expand wildcards in given filepatterns.
[ "Expand", "wildcards", "in", "given", "filepatterns", "." ]
def expand(*args, **wildcards): """ Expand wildcards in given filepatterns. Arguments *args -- first arg: filepatterns as list or one single filepattern, second arg (optional): a function to combine wildcard values (itertools.product per default) **wildcards -- the wildcards as keyword arguments with their values as lists. If allow_missing=True is included wildcards in filepattern without values will stay unformatted. """ filepatterns = args[0] if len(args) == 1: combinator = product elif len(args) == 2: combinator = args[1] if isinstance(filepatterns, str) or isinstance(filepatterns, Path): filepatterns = [filepatterns] def path_to_str(f): if isinstance(f, Path): return str(f) return f filepatterns = list(map(path_to_str, filepatterns)) if any(map(lambda f: getattr(f, "flags", {}), filepatterns)): raise WorkflowError( "Flags in file patterns given to expand() are invalid. " "Flags (e.g. temp(), directory()) have to be applied outside " "of expand (e.g. 'temp(expand(\"plots/{sample}.pdf\", sample=SAMPLES))')." ) # check if remove missing is provided format_dict = dict if "allow_missing" in wildcards and wildcards["allow_missing"] is True: class FormatDict(dict): def __missing__(self, key): return "{" + key + "}" format_dict = FormatDict # check that remove missing is not a wildcard in the filepatterns for filepattern in filepatterns: if "allow_missing" in re.findall(r"{([^}\.[!:]+)", filepattern): format_dict = dict break # remove unused wildcards to avoid duplicate filepatterns wildcards = { filepattern: { k: v for k, v in wildcards.items() if k in re.findall(r"{([^}\.[!:]+)", filepattern) } for filepattern in filepatterns } def flatten(wildcards): for wildcard, values in wildcards.items(): if isinstance(values, str) or not isinstance( values, collections.abc.Iterable ): values = [values] yield [(wildcard, value) for value in values] formatter = string.Formatter() try: return [ formatter.vformat(filepattern, (), comb) for filepattern in filepatterns for comb in map(format_dict, combinator(*flatten(wildcards[filepattern]))) ] except KeyError as e: raise WildcardError("No values given for wildcard {}.".format(e))
[ "def", "expand", "(", "*", "args", ",", "*", "*", "wildcards", ")", ":", "filepatterns", "=", "args", "[", "0", "]", "if", "len", "(", "args", ")", "==", "1", ":", "combinator", "=", "product", "elif", "len", "(", "args", ")", "==", "2", ":", "...
https://github.com/snakemake/snakemake/blob/987282dde8a2db5174414988c134a39ae8836a61/snakemake/io.py#L1107-L1182
errbotio/errbot
66e1de8e1d7daa62be7f9ed1b2ac8832f09fa25d
tools/plugin-gen.py
python
rate_limit
(resp)
Wait enough to be in the budget for this request. :param resp: the http response from github :return:
Wait enough to be in the budget for this request. :param resp: the http response from github :return:
[ "Wait", "enough", "to", "be", "in", "the", "budget", "for", "this", "request", ".", ":", "param", "resp", ":", "the", "http", "response", "from", "github", ":", "return", ":" ]
def rate_limit(resp): """ Wait enough to be in the budget for this request. :param resp: the http response from github :return: """ if "X-RateLimit-Remaining" not in resp.headers: log.info("No rate limit detected. Hum along...") return remain = int(resp.headers["X-RateLimit-Remaining"]) limit = int(resp.headers["X-RateLimit-Limit"]) log.info("Rate limiter: %s allowed out of %d", remain, limit) if remain > 1: # margin by one request return reset = int(resp.headers["X-RateLimit-Reset"]) ts = datetime.fromtimestamp(reset) delay = (ts - datetime.now()).total_seconds() log.info("Hit rate limit. Have to wait for %d seconds", delay) if delay < 0: # time drift delay = 2 time.sleep(delay)
[ "def", "rate_limit", "(", "resp", ")", ":", "if", "\"X-RateLimit-Remaining\"", "not", "in", "resp", ".", "headers", ":", "log", ".", "info", "(", "\"No rate limit detected. Hum along...\"", ")", "return", "remain", "=", "int", "(", "resp", ".", "headers", "[",...
https://github.com/errbotio/errbot/blob/66e1de8e1d7daa62be7f9ed1b2ac8832f09fa25d/tools/plugin-gen.py#L105-L125
deepmind/leo
de9a0c2a77dd7a42c1986b1eef18d184a86e294a
runner.py
python
_construct_training_summaries
(metatrain_loss, metatrain_accuracy, model_grads, model_vars)
[]
def _construct_training_summaries(metatrain_loss, metatrain_accuracy, model_grads, model_vars): tf.summary.scalar("metatrain_loss", metatrain_loss) tf.summary.scalar("metatrain_valid_accuracy", metatrain_accuracy) for g, v in zip(model_grads, model_vars): histogram_name = v.name.split(":")[0] tf.summary.histogram(histogram_name, v) histogram_name = "gradient/{}".format(histogram_name) tf.summary.histogram(histogram_name, g)
[ "def", "_construct_training_summaries", "(", "metatrain_loss", ",", "metatrain_accuracy", ",", "model_grads", ",", "model_vars", ")", ":", "tf", ".", "summary", ".", "scalar", "(", "\"metatrain_loss\"", ",", "metatrain_loss", ")", "tf", ".", "summary", ".", "scala...
https://github.com/deepmind/leo/blob/de9a0c2a77dd7a42c1986b1eef18d184a86e294a/runner.py#L64-L72
natashamjaques/neural_chat
ddb977bb4602a67c460d02231e7bbf7b2cb49a97
ParlAI/parlai/agents/legacy_agents/seq2seq/dict_v1.py
python
find_ngrams
(token_dict, text, n)
return saved_tokens
Break text into ngrams that appear in ``token_dict``. :param token_dict: ``dict`` to check for ngrams :param text: ``str`` to look for ngrams in :param n: ``int`` max size of ngrams
Break text into ngrams that appear in ``token_dict``.
[ "Break", "text", "into", "ngrams", "that", "appear", "in", "token_dict", "." ]
def find_ngrams(token_dict, text, n): """Break text into ngrams that appear in ``token_dict``. :param token_dict: ``dict`` to check for ngrams :param text: ``str`` to look for ngrams in :param n: ``int`` max size of ngrams """ # base case if n <= 1: return text # tokens committed to output saved_tokens = [] # tokens remaining to be searched in sentence search_tokens = text[:] # tokens stored until next ngram found next_search = [] while len(search_tokens) >= n: ngram = ' '.join(search_tokens[:n]) if ngram in token_dict: # first, search previous unmatched words for smaller ngrams sub_n = min(len(next_search), n - 1) saved_tokens.extend(find_ngrams(token_dict, next_search, sub_n)) next_search.clear() # then add this ngram saved_tokens.append(ngram) # then pop this ngram from the remaining words to search search_tokens = search_tokens[n:] else: next_search.append(search_tokens.pop(0)) remainder = next_search + search_tokens sub_n = min(len(remainder), n - 1) saved_tokens.extend(find_ngrams(token_dict, remainder, sub_n)) return saved_tokens
[ "def", "find_ngrams", "(", "token_dict", ",", "text", ",", "n", ")", ":", "# base case", "if", "n", "<=", "1", ":", "return", "text", "# tokens committed to output", "saved_tokens", "=", "[", "]", "# tokens remaining to be searched in sentence", "search_tokens", "="...
https://github.com/natashamjaques/neural_chat/blob/ddb977bb4602a67c460d02231e7bbf7b2cb49a97/ParlAI/parlai/agents/legacy_agents/seq2seq/dict_v1.py#L50-L82
bendmorris/static-python
2e0f8c4d7ed5b359dc7d8a75b6fb37e6b6c5c473
Parser/asdl_c.py
python
PrototypeVisitor.get_args
(self, fields)
return args
Return list of C argument into, one for each field. Argument info is 3-tuple of a C type, variable name, and flag that is true if type can be NULL.
Return list of C argument into, one for each field.
[ "Return", "list", "of", "C", "argument", "into", "one", "for", "each", "field", "." ]
def get_args(self, fields): """Return list of C argument into, one for each field. Argument info is 3-tuple of a C type, variable name, and flag that is true if type can be NULL. """ args = [] unnamed = {} for f in fields: if f.name is None: name = f.type c = unnamed[name] = unnamed.get(name, 0) + 1 if c > 1: name = "name%d" % (c - 1) else: name = f.name # XXX should extend get_c_type() to handle this if f.seq: if f.type.value in ('cmpop',): ctype = "asdl_int_seq *" else: ctype = "asdl_seq *" else: ctype = get_c_type(f.type) args.append((ctype, name, f.opt or f.seq)) return args
[ "def", "get_args", "(", "self", ",", "fields", ")", ":", "args", "=", "[", "]", "unnamed", "=", "{", "}", "for", "f", "in", "fields", ":", "if", "f", ".", "name", "is", "None", ":", "name", "=", "f", ".", "type", "c", "=", "unnamed", "[", "na...
https://github.com/bendmorris/static-python/blob/2e0f8c4d7ed5b359dc7d8a75b6fb37e6b6c5c473/Parser/asdl_c.py#L238-L263
nottombrown/rl-teacher
b2c2201e9d2457b13185424a19da7209364f23df
rl_teacher/teach.py
python
ComparisonRewardPredictor.__init__
(self, env, summary_writer, comparison_collector, agent_logger, label_schedule)
[]
def __init__(self, env, summary_writer, comparison_collector, agent_logger, label_schedule): self.summary_writer = summary_writer self.agent_logger = agent_logger self.comparison_collector = comparison_collector self.label_schedule = label_schedule # Set up some bookkeeping self.recent_segments = deque(maxlen=200) # Keep a queue of recently seen segments to pull new comparisons from self._frames_per_segment = CLIP_LENGTH * env.fps self._steps_since_last_training = 0 self._n_timesteps_per_predictor_training = 1e2 # How often should we train our predictor? self._elapsed_predictor_training_iters = 0 # Build and initialize our predictor model config = tf.ConfigProto( device_count={'GPU': 0} ) self.sess = tf.InteractiveSession(config=config) self.obs_shape = env.observation_space.shape self.discrete_action_space = not hasattr(env.action_space, "shape") self.act_shape = (env.action_space.n,) if self.discrete_action_space else env.action_space.shape self.graph = self._build_model() self.sess.run(tf.global_variables_initializer())
[ "def", "__init__", "(", "self", ",", "env", ",", "summary_writer", ",", "comparison_collector", ",", "agent_logger", ",", "label_schedule", ")", ":", "self", ".", "summary_writer", "=", "summary_writer", "self", ".", "agent_logger", "=", "agent_logger", "self", ...
https://github.com/nottombrown/rl-teacher/blob/b2c2201e9d2457b13185424a19da7209364f23df/rl_teacher/teach.py#L42-L64
TencentCloud/tencentcloud-sdk-python
3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2
tencentcloud/iotvideoindustry/v20201201/iotvideoindustry_client.py
python
IotvideoindustryClient.DescribeIPCChannels
(self, request)
获取IPC设备下属通道 请使用DescribeChannels接口 :param request: Request instance for DescribeIPCChannels. :type request: :class:`tencentcloud.iotvideoindustry.v20201201.models.DescribeIPCChannelsRequest` :rtype: :class:`tencentcloud.iotvideoindustry.v20201201.models.DescribeIPCChannelsResponse`
获取IPC设备下属通道 请使用DescribeChannels接口
[ "获取IPC设备下属通道", "请使用DescribeChannels接口" ]
def DescribeIPCChannels(self, request): """获取IPC设备下属通道 请使用DescribeChannels接口 :param request: Request instance for DescribeIPCChannels. :type request: :class:`tencentcloud.iotvideoindustry.v20201201.models.DescribeIPCChannelsRequest` :rtype: :class:`tencentcloud.iotvideoindustry.v20201201.models.DescribeIPCChannelsResponse` """ try: params = request._serialize() body = self.call("DescribeIPCChannels", params) response = json.loads(body) if "Error" not in response["Response"]: model = models.DescribeIPCChannelsResponse() model._deserialize(response["Response"]) return model else: code = response["Response"]["Error"]["Code"] message = response["Response"]["Error"]["Message"] reqid = response["Response"]["RequestId"] raise TencentCloudSDKException(code, message, reqid) except Exception as e: if isinstance(e, TencentCloudSDKException): raise else: raise TencentCloudSDKException(e.message, e.message)
[ "def", "DescribeIPCChannels", "(", "self", ",", "request", ")", ":", "try", ":", "params", "=", "request", ".", "_serialize", "(", ")", "body", "=", "self", ".", "call", "(", "\"DescribeIPCChannels\"", ",", "params", ")", "response", "=", "json", ".", "l...
https://github.com/TencentCloud/tencentcloud-sdk-python/blob/3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2/tencentcloud/iotvideoindustry/v20201201/iotvideoindustry_client.py#L1412-L1438
toxygen-project/toxygen
0a54012cf5ee72434b923bcde7d8f1a4e575ce2f
toxygen/profile.py
python
Profile.send_friend_request
(self, tox_id, message)
Function tries to send request to contact with specified id :param tox_id: id of new contact or tox dns 4 value :param message: additional message :return: True on success else error string
Function tries to send request to contact with specified id :param tox_id: id of new contact or tox dns 4 value :param message: additional message :return: True on success else error string
[ "Function", "tries", "to", "send", "request", "to", "contact", "with", "specified", "id", ":", "param", "tox_id", ":", "id", "of", "new", "contact", "or", "tox", "dns", "4", "value", ":", "param", "message", ":", "additional", "message", ":", "return", "...
def send_friend_request(self, tox_id, message): """ Function tries to send request to contact with specified id :param tox_id: id of new contact or tox dns 4 value :param message: additional message :return: True on success else error string """ try: message = message or 'Hello! Add me to your contact list please' if '@' in tox_id: # value like groupbot@toxme.io tox_id = tox_dns(tox_id) if tox_id is None: raise Exception('TOX DNS lookup failed') if len(tox_id) == TOX_PUBLIC_KEY_SIZE * 2: # public key self.add_friend(tox_id) msgBox = QtWidgets.QMessageBox() msgBox.setWindowTitle(QtWidgets.QApplication.translate("MainWindow", "Friend added")) text = (QtWidgets.QApplication.translate("MainWindow", 'Friend added without sending friend request')) msgBox.setText(text) msgBox.exec_() else: result = self._tox.friend_add(tox_id, message.encode('utf-8')) tox_id = tox_id[:TOX_PUBLIC_KEY_SIZE * 2] item = self.create_friend_item() if not self._history.friend_exists_in_db(tox_id): self._history.add_friend_to_db(tox_id) message_getter = self._history.messages_getter(tox_id) friend = Friend(message_getter, result, tox_id, '', item, tox_id) self._contacts.append(friend) data = self._tox.get_savedata() ProfileHelper.get_instance().save_profile(data) return True except Exception as ex: # wrong data log('Friend request failed with ' + str(ex)) return str(ex)
[ "def", "send_friend_request", "(", "self", ",", "tox_id", ",", "message", ")", ":", "try", ":", "message", "=", "message", "or", "'Hello! Add me to your contact list please'", "if", "'@'", "in", "tox_id", ":", "# value like groupbot@toxme.io", "tox_id", "=", "tox_dn...
https://github.com/toxygen-project/toxygen/blob/0a54012cf5ee72434b923bcde7d8f1a4e575ce2f/toxygen/profile.py#L813-L847
makerbot/ReplicatorG
d6f2b07785a5a5f1e172fb87cb4303b17c575d5d
skein_engines/skeinforge-47/skeinforge_application/skeinforge_plugins/craft_plugins/smooth.py
python
getNewRepository
()
return SmoothRepository()
Get new repository.
Get new repository.
[ "Get", "new", "repository", "." ]
def getNewRepository(): 'Get new repository.' return SmoothRepository()
[ "def", "getNewRepository", "(", ")", ":", "return", "SmoothRepository", "(", ")" ]
https://github.com/makerbot/ReplicatorG/blob/d6f2b07785a5a5f1e172fb87cb4303b17c575d5d/skein_engines/skeinforge-47/skeinforge_application/skeinforge_plugins/craft_plugins/smooth.py#L75-L77
fastnlp/fitlog
ba9547a56f4855a2d9cf26ae709d01922befa077
fitlog/__init__.py
python
get_log_dir
(absolute=False)
return _logger.get_log_dir(absolute=absolute)
返回的是存放所有log的文件夹。例如logs/,需要调用set_log_dir()先设置log的记录文件夹 :param bool absolute: 是否返回绝对路径 :return:
返回的是存放所有log的文件夹。例如logs/,需要调用set_log_dir()先设置log的记录文件夹
[ "返回的是存放所有log的文件夹。例如logs", "/", ",需要调用set_log_dir", "()", "先设置log的记录文件夹" ]
def get_log_dir(absolute=False): """ 返回的是存放所有log的文件夹。例如logs/,需要调用set_log_dir()先设置log的记录文件夹 :param bool absolute: 是否返回绝对路径 :return: """ return _logger.get_log_dir(absolute=absolute)
[ "def", "get_log_dir", "(", "absolute", "=", "False", ")", ":", "return", "_logger", ".", "get_log_dir", "(", "absolute", "=", "absolute", ")" ]
https://github.com/fastnlp/fitlog/blob/ba9547a56f4855a2d9cf26ae709d01922befa077/fitlog/__init__.py#L50-L57
robotlearn/pyrobolearn
9cd7c060723fda7d2779fa255ac998c2c82b8436
pyrobolearn/simulators/simulator.py
python
Simulator.get_link_state
(self, body_id, link_id, compute_velocity=False, compute_forward_kinematics=False)
Get the state of the associated link. Args: body_id (int): body unique id. link_id (int): link index. compute_velocity (bool): If True, the Cartesian world velocity will be computed and returned. compute_forward_kinematics (bool): if True, the Cartesian world position/orientation will be recomputed using forward kinematics. Returns: np.array[float[3]]: Cartesian world position of CoM np.array[float[4]]: Cartesian world orientation of CoM, in quaternion [x,y,z,w] np.array[float[3]]: local position offset of inertial frame (center of mass) expressed in the URDF link frame np.array[float[4]]: local orientation (quaternion [x,y,z,w]) offset of the inertial frame expressed in URDF link frame np.array[float[3]]: world position of the URDF link frame np.array[float[4]]: world orientation of the URDF link frame np.array[float[3]]: Cartesian world linear velocity. Only returned if `compute_velocity` is True. np.array[float[3]]: Cartesian world angular velocity. Only returned if `compute_velocity` is True.
Get the state of the associated link.
[ "Get", "the", "state", "of", "the", "associated", "link", "." ]
def get_link_state(self, body_id, link_id, compute_velocity=False, compute_forward_kinematics=False): """ Get the state of the associated link. Args: body_id (int): body unique id. link_id (int): link index. compute_velocity (bool): If True, the Cartesian world velocity will be computed and returned. compute_forward_kinematics (bool): if True, the Cartesian world position/orientation will be recomputed using forward kinematics. Returns: np.array[float[3]]: Cartesian world position of CoM np.array[float[4]]: Cartesian world orientation of CoM, in quaternion [x,y,z,w] np.array[float[3]]: local position offset of inertial frame (center of mass) expressed in the URDF link frame np.array[float[4]]: local orientation (quaternion [x,y,z,w]) offset of the inertial frame expressed in URDF link frame np.array[float[3]]: world position of the URDF link frame np.array[float[4]]: world orientation of the URDF link frame np.array[float[3]]: Cartesian world linear velocity. Only returned if `compute_velocity` is True. np.array[float[3]]: Cartesian world angular velocity. Only returned if `compute_velocity` is True. """ pass
[ "def", "get_link_state", "(", "self", ",", "body_id", ",", "link_id", ",", "compute_velocity", "=", "False", ",", "compute_forward_kinematics", "=", "False", ")", ":", "pass" ]
https://github.com/robotlearn/pyrobolearn/blob/9cd7c060723fda7d2779fa255ac998c2c82b8436/pyrobolearn/simulators/simulator.py#L1408-L1431
hhstore/annotated-py-projects
4f4eca9a3913a19983cae496279a72699c083a0b
asyncio/asyncio-3.4.3/asyncio/events.py
python
set_event_loop
(loop)
Equivalent to calling get_event_loop_policy().set_event_loop(loop).
Equivalent to calling get_event_loop_policy().set_event_loop(loop).
[ "Equivalent", "to", "calling", "get_event_loop_policy", "()", ".", "set_event_loop", "(", "loop", ")", "." ]
def set_event_loop(loop): """Equivalent to calling get_event_loop_policy().set_event_loop(loop).""" get_event_loop_policy().set_event_loop(loop)
[ "def", "set_event_loop", "(", "loop", ")", ":", "get_event_loop_policy", "(", ")", ".", "set_event_loop", "(", "loop", ")" ]
https://github.com/hhstore/annotated-py-projects/blob/4f4eca9a3913a19983cae496279a72699c083a0b/asyncio/asyncio-3.4.3/asyncio/events.py#L663-L665
rlgraph/rlgraph
428fc136a9a075f29a397495b4226a491a287be2
rlgraph/components/explorations/epsilon_exploration.py
python
EpsilonExploration.__init__
(self, decay_spec=None, scope="epsilon-exploration", **kwargs)
Args: decay_spec (Optional[dict,DecayComponent]): The spec-dict for the DecayComponent to use or a DecayComponent object directly. Keyword Args: Used as decay_spec (only if `decay_spec` not given) to construct the DecayComponent.
Args: decay_spec (Optional[dict,DecayComponent]): The spec-dict for the DecayComponent to use or a DecayComponent object directly.
[ "Args", ":", "decay_spec", "(", "Optional", "[", "dict", "DecayComponent", "]", ")", ":", "The", "spec", "-", "dict", "for", "the", "DecayComponent", "to", "use", "or", "a", "DecayComponent", "object", "directly", "." ]
def __init__(self, decay_spec=None, scope="epsilon-exploration", **kwargs): """ Args: decay_spec (Optional[dict,DecayComponent]): The spec-dict for the DecayComponent to use or a DecayComponent object directly. Keyword Args: Used as decay_spec (only if `decay_spec` not given) to construct the DecayComponent. """ super(EpsilonExploration, self).__init__(scope=scope, **kwargs) # The space of the samples that we have to produce epsilon decisions for. self.sample_space = None self.flat_sample_space = None # Our (epsilon) Decay-Component. self.decay = TimeDependentParameter.from_spec(decay_spec) # Add the decay component and make time_step our (only) input. self.add_components(self.decay)
[ "def", "__init__", "(", "self", ",", "decay_spec", "=", "None", ",", "scope", "=", "\"epsilon-exploration\"", ",", "*", "*", "kwargs", ")", ":", "super", "(", "EpsilonExploration", ",", "self", ")", ".", "__init__", "(", "scope", "=", "scope", ",", "*", ...
https://github.com/rlgraph/rlgraph/blob/428fc136a9a075f29a397495b4226a491a287be2/rlgraph/components/explorations/epsilon_exploration.py#L47-L66
haiwen/seafile-docker
2d2461d4c8cab3458ec9832611c419d47506c300
cluster/image/pro_seafile_7.1/scripts_7.1/setup-seafile-mysql.py
python
Utils.write_config
(cp, fn)
Return a case sensitive ConfigParser by reading the file "fn"
Return a case sensitive ConfigParser by reading the file "fn"
[ "Return", "a", "case", "sensitive", "ConfigParser", "by", "reading", "the", "file", "fn" ]
def write_config(cp, fn): '''Return a case sensitive ConfigParser by reading the file "fn"''' with open(fn, 'w') as fp: cp.write(fp)
[ "def", "write_config", "(", "cp", ",", "fn", ")", ":", "with", "open", "(", "fn", ",", "'w'", ")", "as", "fp", ":", "cp", ".", "write", "(", "fp", ")" ]
https://github.com/haiwen/seafile-docker/blob/2d2461d4c8cab3458ec9832611c419d47506c300/cluster/image/pro_seafile_7.1/scripts_7.1/setup-seafile-mysql.py#L185-L188
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/interfaces/kenzo.py
python
KenzoSimplicialSet.join
(self, other)
return KenzoSimplicialSet(join_kenzo)
r""" Return the join of ``self`` and ``other``. INPUT: - ``other`` -- the Kenzo simplicial set with which the join is made OUTPUT: - A :class:`KenzoSimplicialSet` EXAMPLES:: sage: from sage.interfaces.kenzo import Sphere # optional - kenzo sage: s2 = Sphere(2) # optional - kenzo sage: s3 = Sphere(3) # optional - kenzo sage: j = s2.join(s3) # optional - kenzo sage: type(j) # optional - kenzo <class 'sage.interfaces.kenzo.KenzoSimplicialSet'> sage: [j.homology(i) for i in range(6)] # optional - kenzo [Z, 0, 0, 0, 0, 0]
r""" Return the join of ``self`` and ``other``.
[ "r", "Return", "the", "join", "of", "self", "and", "other", "." ]
def join(self, other): r""" Return the join of ``self`` and ``other``. INPUT: - ``other`` -- the Kenzo simplicial set with which the join is made OUTPUT: - A :class:`KenzoSimplicialSet` EXAMPLES:: sage: from sage.interfaces.kenzo import Sphere # optional - kenzo sage: s2 = Sphere(2) # optional - kenzo sage: s3 = Sphere(3) # optional - kenzo sage: j = s2.join(s3) # optional - kenzo sage: type(j) # optional - kenzo <class 'sage.interfaces.kenzo.KenzoSimplicialSet'> sage: [j.homology(i) for i in range(6)] # optional - kenzo [Z, 0, 0, 0, 0, 0] """ join_kenzo = __join__(self._kenzo, other._kenzo) return KenzoSimplicialSet(join_kenzo)
[ "def", "join", "(", "self", ",", "other", ")", ":", "join_kenzo", "=", "__join__", "(", "self", ".", "_kenzo", ",", "other", ".", "_kenzo", ")", "return", "KenzoSimplicialSet", "(", "join_kenzo", ")" ]
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/interfaces/kenzo.py#L879-L903
DataDog/integrations-core
934674b29d94b70ccc008f76ea172d0cdae05e1e
pgbouncer/datadog_checks/pgbouncer/config_models/shared.py
python
SharedConfig._run_validations
(cls, v, field)
return getattr(validators, f'shared_{field.name}', identity)(v, field=field)
[]
def _run_validations(cls, v, field): if not v: return v return getattr(validators, f'shared_{field.name}', identity)(v, field=field)
[ "def", "_run_validations", "(", "cls", ",", "v", ",", "field", ")", ":", "if", "not", "v", ":", "return", "v", "return", "getattr", "(", "validators", ",", "f'shared_{field.name}'", ",", "identity", ")", "(", "v", ",", "field", "=", "field", ")" ]
https://github.com/DataDog/integrations-core/blob/934674b29d94b70ccc008f76ea172d0cdae05e1e/pgbouncer/datadog_checks/pgbouncer/config_models/shared.py#L40-L44
ewels/MultiQC
9b953261d3d684c24eef1827a5ce6718c847a5af
multiqc/modules/mirtop/mirtop.py
python
MultiqcModule.mirtop_stats_table
(self)
Take the parsed stats from the mirtop report and add them to the basic stats table at the top of the report
Take the parsed stats from the mirtop report and add them to the basic stats table at the top of the report
[ "Take", "the", "parsed", "stats", "from", "the", "mirtop", "report", "and", "add", "them", "to", "the", "basic", "stats", "table", "at", "the", "top", "of", "the", "report" ]
def mirtop_stats_table(self): """Take the parsed stats from the mirtop report and add them to the basic stats table at the top of the report""" headers = OrderedDict() headers["ref_miRNA_sum"] = { "title": "{} Ref miRNA reads".format(config.read_count_prefix), "description": "Read counts summed over all reference miRNAs ({})".format(config.read_count_desc), "modify": lambda x: x * config.read_count_multiplier, "shared_key": "read_count", "scale": "PuBu", } headers["isomiR_perc"] = { "title": "IsomiR %", "description": "% of total read counts corresponding to isomiRs", "min": 0, "max": 100, "suffix": "%", "scale": "YlOrRd", } headers["isomiR_sum"] = { "title": "{} IsomiR reads".format(config.read_count_prefix), "description": "Read counts summed over all isomiRs ({})".format(config.read_count_desc), "modify": lambda x: x * config.read_count_multiplier, "shared_key": "read_count", "scale": "Oranges", } headers["read_count"] = { "title": "{} Reads".format(config.read_count_prefix), "description": "Total read counts - both isomiRs and reference miRNA ({})".format(config.read_count_desc), "modify": lambda x: x * config.read_count_multiplier, "shared_key": "read_count", "scale": "BuGn", } self.general_stats_addcols(self.mirtop_data, headers)
[ "def", "mirtop_stats_table", "(", "self", ")", ":", "headers", "=", "OrderedDict", "(", ")", "headers", "[", "\"ref_miRNA_sum\"", "]", "=", "{", "\"title\"", ":", "\"{} Ref miRNA reads\"", ".", "format", "(", "config", ".", "read_count_prefix", ")", ",", "\"de...
https://github.com/ewels/MultiQC/blob/9b953261d3d684c24eef1827a5ce6718c847a5af/multiqc/modules/mirtop/mirtop.py#L130-L165
saltstack/salt
fae5bc757ad0f1716483ce7ae180b451545c2058
salt/modules/mount.py
python
swaps
()
return ret
Return a dict containing information on active swap .. versionchanged:: 2016.3.2 CLI Example: .. code-block:: bash salt '*' mount.swaps
Return a dict containing information on active swap
[ "Return", "a", "dict", "containing", "information", "on", "active", "swap" ]
def swaps(): """ Return a dict containing information on active swap .. versionchanged:: 2016.3.2 CLI Example: .. code-block:: bash salt '*' mount.swaps """ ret = {} if __grains__["kernel"] == "SunOS": for line in __salt__["cmd.run_stdout"]("swap -l").splitlines(): if line.startswith("swapfile"): continue comps = line.split() ret[comps[0]] = { "type": "device" if comps[0].startswith(("/dev", "swap")) else "file", "size": int(comps[3]), "used": (int(comps[3]) - int(comps[4])), "priority": "-", } elif "AIX" in __grains__["kernel"]: for line in __salt__["cmd.run_stdout"]("swap -l").splitlines(): if line.startswith("device"): continue comps = line.split() # AIX uses MB for units ret[comps[0]] = { "type": "device", "size": int(comps[3][:-2]) * 1024, "used": (int(comps[3][:-2]) - int(comps[4][:-2])) * 1024, "priority": "-", } elif __grains__["os"] != "OpenBSD": with salt.utils.files.fopen("/proc/swaps") as fp_: for line in fp_: line = salt.utils.stringutils.to_unicode(line) if line.startswith("Filename"): continue comps = line.split() ret[comps[0]] = { "type": comps[1], "size": comps[2], "used": comps[3], "priority": comps[4], } else: for line in __salt__["cmd.run_stdout"]("swapctl -kl").splitlines(): if line.startswith(("Device", "Total")): continue swap_type = "file" comps = line.split() if comps[0].startswith("/dev/"): swap_type = "partition" ret[comps[0]] = { "type": swap_type, "size": comps[1], "used": comps[2], "priority": comps[5], } return ret
[ "def", "swaps", "(", ")", ":", "ret", "=", "{", "}", "if", "__grains__", "[", "\"kernel\"", "]", "==", "\"SunOS\"", ":", "for", "line", "in", "__salt__", "[", "\"cmd.run_stdout\"", "]", "(", "\"swap -l\"", ")", ".", "splitlines", "(", ")", ":", "if", ...
https://github.com/saltstack/salt/blob/fae5bc757ad0f1716483ce7ae180b451545c2058/salt/modules/mount.py#L1422-L1486
demisto/content
5c664a65b992ac8ca90ac3f11b1b2cdf11ee9b07
Packs/FreshDesk/Integrations/FreshDesk/FreshDesk.py
python
get_ticket_conversations_command
()
Lists all replies and notes for a specified ticket. demisto parameter: (number) ticket_id ID of the ticket for which you would like to list all of its conversations returns: Conversation Objects
Lists all replies and notes for a specified ticket.
[ "Lists", "all", "replies", "and", "notes", "for", "a", "specified", "ticket", "." ]
def get_ticket_conversations_command(): """ Lists all replies and notes for a specified ticket. demisto parameter: (number) ticket_id ID of the ticket for which you would like to list all of its conversations returns: Conversation Objects """ # Get id number of ticket as cmd arg for which you want to see all the conversations ticket_id = demisto.args().get('ticket_id') # Make request and get raw response conversations = get_ticket_conversations(ticket_id) # Parse response into context contexts = [] readable_contexts = [] for conversation in conversations: context = {string_to_context_key(key): val for key, val in conversation.iteritems() if val} context = reformat_conversation_context(context) # Parse attachments into context context, context_readable = attachments_into_context(conversation, context) context = reformat_ticket_context(context) context_readable = reformat_ticket_context(context_readable) contexts.append(context) readable_contexts.append(context_readable) complete_context = { 'ID': int(ticket_id), 'Conversation': contexts } title = 'Conversations of Ticket #{}'.format(ticket_id) human_readable = tableToMarkdown(title, readable_contexts, removeNull=True) demisto.results({ 'Type': entryTypes['note'], 'ContentsFormat': formats['json'], 'Contents': conversations, 'ReadableContentsFormat': formats['markdown'], 'HumanReadable': human_readable, 'EntryContext': { 'Freshdesk.Ticket(val.ID && val.ID === obj.ID)': complete_context } })
[ "def", "get_ticket_conversations_command", "(", ")", ":", "# Get id number of ticket as cmd arg for which you want to see all the conversations", "ticket_id", "=", "demisto", ".", "args", "(", ")", ".", "get", "(", "'ticket_id'", ")", "# Make request and get raw response", "con...
https://github.com/demisto/content/blob/5c664a65b992ac8ca90ac3f11b1b2cdf11ee9b07/Packs/FreshDesk/Integrations/FreshDesk/FreshDesk.py#L1461-L1502
dephell/dephell
de96f01fcfd8dd620b049369a8ec30dde566c5de
dephell/cached_property.py
python
cached_property.__get__
(self, obj, cls)
return value
[]
def __get__(self, obj, cls): if obj is None: return self value = obj.__dict__[self.func.__name__] = self.func(obj) return value
[ "def", "__get__", "(", "self", ",", "obj", ",", "cls", ")", ":", "if", "obj", "is", "None", ":", "return", "self", "value", "=", "obj", ".", "__dict__", "[", "self", ".", "func", ".", "__name__", "]", "=", "self", ".", "func", "(", "obj", ")", ...
https://github.com/dephell/dephell/blob/de96f01fcfd8dd620b049369a8ec30dde566c5de/dephell/cached_property.py#L15-L19
celiao/tmdbsimple
2c046367866667102b78247db708c0ac275f805d
tmdbsimple/account.py
python
Account.favorite
(self, **kwargs)
return response
This method allows you to mark a movie or TV show as a favorite item. Args: media_type: 'movie' | 'tv' media_id: The id of the media. favorite: True (to add) | False (to remove). Returns: A dict respresentation of the JSON returned from the API.
This method allows you to mark a movie or TV show as a favorite item.
[ "This", "method", "allows", "you", "to", "mark", "a", "movie", "or", "TV", "show", "as", "a", "favorite", "item", "." ]
def favorite(self, **kwargs): """ This method allows you to mark a movie or TV show as a favorite item. Args: media_type: 'movie' | 'tv' media_id: The id of the media. favorite: True (to add) | False (to remove). Returns: A dict respresentation of the JSON returned from the API. """ path = self._get_id_path('favorite') kwargs.update({'session_id': self.session_id}) payload = { 'media_type': kwargs.pop('media_type', None), 'media_id': kwargs.pop('media_id', None), 'favorite': kwargs.pop('favorite', None), } response = self._POST(path, kwargs, payload) self._set_attrs_to_values(response) return response
[ "def", "favorite", "(", "self", ",", "*", "*", "kwargs", ")", ":", "path", "=", "self", ".", "_get_id_path", "(", "'favorite'", ")", "kwargs", ".", "update", "(", "{", "'session_id'", ":", "self", ".", "session_id", "}", ")", "payload", "=", "{", "'m...
https://github.com/celiao/tmdbsimple/blob/2c046367866667102b78247db708c0ac275f805d/tmdbsimple/account.py#L118-L141
ChineseGLUE/ChineseGLUE
1591b85cf5427c2ff60f718d359ecb71d2b44879
baselines/models_pytorch/classifier_pytorch/transformers/modeling_bert.py
python
BertSelfAttention.transpose_for_scores
(self, x)
return x.permute(0, 2, 1, 3)
[]
def transpose_for_scores(self, x): new_x_shape = x.size()[:-1] + (self.num_attention_heads, self.attention_head_size) x = x.view(*new_x_shape) return x.permute(0, 2, 1, 3)
[ "def", "transpose_for_scores", "(", "self", ",", "x", ")", ":", "new_x_shape", "=", "x", ".", "size", "(", ")", "[", ":", "-", "1", "]", "+", "(", "self", ".", "num_attention_heads", ",", "self", ".", "attention_head_size", ")", "x", "=", "x", ".", ...
https://github.com/ChineseGLUE/ChineseGLUE/blob/1591b85cf5427c2ff60f718d359ecb71d2b44879/baselines/models_pytorch/classifier_pytorch/transformers/modeling_bert.py#L196-L199
TengXiaoDai/DistributedCrawling
f5c2439e6ce68dd9b49bde084d76473ff9ed4963
Lib/site-packages/pip/_vendor/distlib/markers.py
python
Evaluator.__init__
(self, context=None)
Initialise an instance. :param context: If specified, names are looked up in this mapping.
Initialise an instance.
[ "Initialise", "an", "instance", "." ]
def __init__(self, context=None): """ Initialise an instance. :param context: If specified, names are looked up in this mapping. """ self.context = context or {} self.source = None
[ "def", "__init__", "(", "self", ",", "context", "=", "None", ")", ":", "self", ".", "context", "=", "context", "or", "{", "}", "self", ".", "source", "=", "None" ]
https://github.com/TengXiaoDai/DistributedCrawling/blob/f5c2439e6ce68dd9b49bde084d76473ff9ed4963/Lib/site-packages/pip/_vendor/distlib/markers.py#L51-L58
quantumlib/Cirq
89f88b01d69222d3f1ec14d649b7b3a85ed9211f
cirq-core/cirq/sim/simulator.py
python
SimulatesAmplitudes.compute_amplitudes_sweep_iter
( self, program: 'cirq.AbstractCircuit', bitstrings: Sequence[int], params: 'cirq.Sweepable', qubit_order: 'cirq.QubitOrderOrList' = ops.QubitOrder.DEFAULT, )
Computes the desired amplitudes. The initial state is assumed to be the all zeros state. Args: program: The circuit to simulate. bitstrings: The bitstrings whose amplitudes are desired, input as an integer array where each integer is formed from measured qubit values according to `qubit_order` from most to least significant qubit, i.e. in big-endian ordering. params: Parameters to run with the program. qubit_order: Determines the canonical ordering of the qubits. This is often used in specifying the initial state, i.e. the ordering of the computational basis states. Returns: An Iterator over lists of amplitudes. The outer dimension indexes the circuit parameters and the inner dimension indexes bitstrings.
Computes the desired amplitudes.
[ "Computes", "the", "desired", "amplitudes", "." ]
def compute_amplitudes_sweep_iter( self, program: 'cirq.AbstractCircuit', bitstrings: Sequence[int], params: 'cirq.Sweepable', qubit_order: 'cirq.QubitOrderOrList' = ops.QubitOrder.DEFAULT, ) -> Iterator[Sequence[complex]]: """Computes the desired amplitudes. The initial state is assumed to be the all zeros state. Args: program: The circuit to simulate. bitstrings: The bitstrings whose amplitudes are desired, input as an integer array where each integer is formed from measured qubit values according to `qubit_order` from most to least significant qubit, i.e. in big-endian ordering. params: Parameters to run with the program. qubit_order: Determines the canonical ordering of the qubits. This is often used in specifying the initial state, i.e. the ordering of the computational basis states. Returns: An Iterator over lists of amplitudes. The outer dimension indexes the circuit parameters and the inner dimension indexes bitstrings. """ raise NotImplementedError()
[ "def", "compute_amplitudes_sweep_iter", "(", "self", ",", "program", ":", "'cirq.AbstractCircuit'", ",", "bitstrings", ":", "Sequence", "[", "int", "]", ",", "params", ":", "'cirq.Sweepable'", ",", "qubit_order", ":", "'cirq.QubitOrderOrList'", "=", "ops", ".", "Q...
https://github.com/quantumlib/Cirq/blob/89f88b01d69222d3f1ec14d649b7b3a85ed9211f/cirq-core/cirq/sim/simulator.py#L210-L236
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/nexia/sensor.py
python
NexiaThermostatSensor.native_value
(self)
return val
Return the state of the sensor.
Return the state of the sensor.
[ "Return", "the", "state", "of", "the", "sensor", "." ]
def native_value(self): """Return the state of the sensor.""" val = getattr(self._thermostat, self._call)() if self._modifier: val = self._modifier(val) if isinstance(val, float): val = round(val, 1) return val
[ "def", "native_value", "(", "self", ")", ":", "val", "=", "getattr", "(", "self", ".", "_thermostat", ",", "self", ".", "_call", ")", "(", ")", "if", "self", ".", "_modifier", ":", "val", "=", "self", ".", "_modifier", "(", "val", ")", "if", "isins...
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/nexia/sensor.py#L187-L194
microsoft/azure-devops-python-api
451cade4c475482792cbe9e522c1fee32393139e
azure-devops/azure/devops/v6_0/git/git_client_base.py
python
GitClientBase.update_pull_request_reviewers
(self, patch_votes, repository_id, pull_request_id, project=None)
UpdatePullRequestReviewers. [Preview API] Reset the votes of multiple reviewers on a pull request. NOTE: This endpoint only supports updating votes, but does not support updating required reviewers (use policy) or display names. :param [IdentityRefWithVote] patch_votes: IDs of the reviewers whose votes will be reset to zero :param str repository_id: The repository ID of the pull request's target branch. :param int pull_request_id: ID of the pull request :param str project: Project ID or project name
UpdatePullRequestReviewers. [Preview API] Reset the votes of multiple reviewers on a pull request. NOTE: This endpoint only supports updating votes, but does not support updating required reviewers (use policy) or display names. :param [IdentityRefWithVote] patch_votes: IDs of the reviewers whose votes will be reset to zero :param str repository_id: The repository ID of the pull request's target branch. :param int pull_request_id: ID of the pull request :param str project: Project ID or project name
[ "UpdatePullRequestReviewers", ".", "[", "Preview", "API", "]", "Reset", "the", "votes", "of", "multiple", "reviewers", "on", "a", "pull", "request", ".", "NOTE", ":", "This", "endpoint", "only", "supports", "updating", "votes", "but", "does", "not", "support",...
def update_pull_request_reviewers(self, patch_votes, repository_id, pull_request_id, project=None): """UpdatePullRequestReviewers. [Preview API] Reset the votes of multiple reviewers on a pull request. NOTE: This endpoint only supports updating votes, but does not support updating required reviewers (use policy) or display names. :param [IdentityRefWithVote] patch_votes: IDs of the reviewers whose votes will be reset to zero :param str repository_id: The repository ID of the pull request's target branch. :param int pull_request_id: ID of the pull request :param str project: Project ID or project name """ route_values = {} if project is not None: route_values['project'] = self._serialize.url('project', project, 'str') if repository_id is not None: route_values['repositoryId'] = self._serialize.url('repository_id', repository_id, 'str') if pull_request_id is not None: route_values['pullRequestId'] = self._serialize.url('pull_request_id', pull_request_id, 'int') content = self._serialize.body(patch_votes, '[IdentityRefWithVote]') self._send(http_method='PATCH', location_id='4b6702c7-aa35-4b89-9c96-b9abf6d3e540', version='6.0-preview.1', route_values=route_values, content=content)
[ "def", "update_pull_request_reviewers", "(", "self", ",", "patch_votes", ",", "repository_id", ",", "pull_request_id", ",", "project", "=", "None", ")", ":", "route_values", "=", "{", "}", "if", "project", "is", "not", "None", ":", "route_values", "[", "'proje...
https://github.com/microsoft/azure-devops-python-api/blob/451cade4c475482792cbe9e522c1fee32393139e/azure-devops/azure/devops/v6_0/git/git_client_base.py#L2032-L2052
zsdonghao/text-to-image
c1fbfa4349f5aa1c74c9fe17743cc0cff34f1aab
tensorlayer/iterate.py
python
ptb_iterator
(raw_data, batch_size, num_steps)
Generate a generator that iterates on a list of words, see PTB tutorial. Yields (Returns) the source contexts and the target context by the given batch_size and num_steps (sequence_length).\n see ``PTB tutorial``. e.g. x = [0, 1, 2] y = [1, 2, 3] , when batch_size = 1, num_steps = 3, raw_data = [i for i in range(100)] In TensorFlow's tutorial, this generates batch_size pointers into the raw PTB data, and allows minibatch iteration along these pointers. Parameters ---------- raw_data : a list the context in list format; note that context usually be represented by splitting by space, and then convert to unique word IDs. batch_size : int the batch size. num_steps : int the number of unrolls. i.e. sequence_length Yields ------ Pairs of the batched data, each a matrix of shape [batch_size, num_steps]. The second element of the tuple is the same data time-shifted to the right by one. Raises ------ ValueError : if batch_size or num_steps are too high. Examples -------- >>> train_data = [i for i in range(20)] >>> for batch in tl.iterate.ptb_iterator(train_data, batch_size=2, num_steps=3): >>> x, y = batch >>> print(x, y) ... [[ 0 1 2] <---x 1st subset/ iteration ... [10 11 12]] ... [[ 1 2 3] <---y ... [11 12 13]] ... ... [[ 3 4 5] <--- 1st batch input 2nd subset/ iteration ... [13 14 15]] <--- 2nd batch input ... [[ 4 5 6] <--- 1st batch target ... [14 15 16]] <--- 2nd batch target ... ... [[ 6 7 8] 3rd subset/ iteration ... [16 17 18]] ... [[ 7 8 9] ... [17 18 19]] Code References ---------------- - ``tensorflow/models/rnn/ptb/reader.py``
Generate a generator that iterates on a list of words, see PTB tutorial. Yields (Returns) the source contexts and the target context by the given batch_size and num_steps (sequence_length).\n see ``PTB tutorial``.
[ "Generate", "a", "generator", "that", "iterates", "on", "a", "list", "of", "words", "see", "PTB", "tutorial", ".", "Yields", "(", "Returns", ")", "the", "source", "contexts", "and", "the", "target", "context", "by", "the", "given", "batch_size", "and", "nu...
def ptb_iterator(raw_data, batch_size, num_steps): """ Generate a generator that iterates on a list of words, see PTB tutorial. Yields (Returns) the source contexts and the target context by the given batch_size and num_steps (sequence_length).\n see ``PTB tutorial``. e.g. x = [0, 1, 2] y = [1, 2, 3] , when batch_size = 1, num_steps = 3, raw_data = [i for i in range(100)] In TensorFlow's tutorial, this generates batch_size pointers into the raw PTB data, and allows minibatch iteration along these pointers. Parameters ---------- raw_data : a list the context in list format; note that context usually be represented by splitting by space, and then convert to unique word IDs. batch_size : int the batch size. num_steps : int the number of unrolls. i.e. sequence_length Yields ------ Pairs of the batched data, each a matrix of shape [batch_size, num_steps]. The second element of the tuple is the same data time-shifted to the right by one. Raises ------ ValueError : if batch_size or num_steps are too high. Examples -------- >>> train_data = [i for i in range(20)] >>> for batch in tl.iterate.ptb_iterator(train_data, batch_size=2, num_steps=3): >>> x, y = batch >>> print(x, y) ... [[ 0 1 2] <---x 1st subset/ iteration ... [10 11 12]] ... [[ 1 2 3] <---y ... [11 12 13]] ... ... [[ 3 4 5] <--- 1st batch input 2nd subset/ iteration ... [13 14 15]] <--- 2nd batch input ... [[ 4 5 6] <--- 1st batch target ... [14 15 16]] <--- 2nd batch target ... ... [[ 6 7 8] 3rd subset/ iteration ... [16 17 18]] ... [[ 7 8 9] ... [17 18 19]] Code References ---------------- - ``tensorflow/models/rnn/ptb/reader.py`` """ raw_data = np.array(raw_data, dtype=np.int32) data_len = len(raw_data) batch_len = data_len // batch_size data = np.zeros([batch_size, batch_len], dtype=np.int32) for i in range(batch_size): data[i] = raw_data[batch_len * i:batch_len * (i + 1)] epoch_size = (batch_len - 1) // num_steps if epoch_size == 0: raise ValueError("epoch_size == 0, decrease batch_size or num_steps") for i in range(epoch_size): x = data[:, i*num_steps:(i+1)*num_steps] y = data[:, i*num_steps+1:(i+1)*num_steps+1] yield (x, y)
[ "def", "ptb_iterator", "(", "raw_data", ",", "batch_size", ",", "num_steps", ")", ":", "raw_data", "=", "np", ".", "array", "(", "raw_data", ",", "dtype", "=", "np", ".", "int32", ")", "data_len", "=", "len", "(", "raw_data", ")", "batch_len", "=", "da...
https://github.com/zsdonghao/text-to-image/blob/c1fbfa4349f5aa1c74c9fe17743cc0cff34f1aab/tensorlayer/iterate.py#L204-L278
bokeh/bokeh
a00e59da76beb7b9f83613533cfd3aced1df5f06
bokeh/application/handlers/function.py
python
FunctionHandler.safe_to_fork
(self)
return self._safe_to_fork
Whether it is still safe for the Bokeh server to fork new workers. ``False`` if ``modify_doc`` has already been called.
Whether it is still safe for the Bokeh server to fork new workers.
[ "Whether", "it", "is", "still", "safe", "for", "the", "Bokeh", "server", "to", "fork", "new", "workers", "." ]
def safe_to_fork(self) -> bool: ''' Whether it is still safe for the Bokeh server to fork new workers. ``False`` if ``modify_doc`` has already been called. ''' return self._safe_to_fork
[ "def", "safe_to_fork", "(", "self", ")", "->", "bool", ":", "return", "self", ".", "_safe_to_fork" ]
https://github.com/bokeh/bokeh/blob/a00e59da76beb7b9f83613533cfd3aced1df5f06/bokeh/application/handlers/function.py#L125-L131
DamnWidget/anaconda
a9998fb362320f907d5ccbc6fcf5b62baca677c0
anaconda_lib/jedi/_compatibility.py
python
cast_path
(obj)
return u(obj, errors='replace')
Take a bytes or str path and cast it to unicode. Apparently it is perfectly fine to pass both byte and unicode objects into the sys.path. This probably means that byte paths are normal at other places as well. Since this just really complicates everything and Python 2.7 will be EOL soon anyway, just go with always strings.
Take a bytes or str path and cast it to unicode.
[ "Take", "a", "bytes", "or", "str", "path", "and", "cast", "it", "to", "unicode", "." ]
def cast_path(obj): """ Take a bytes or str path and cast it to unicode. Apparently it is perfectly fine to pass both byte and unicode objects into the sys.path. This probably means that byte paths are normal at other places as well. Since this just really complicates everything and Python 2.7 will be EOL soon anyway, just go with always strings. """ return u(obj, errors='replace')
[ "def", "cast_path", "(", "obj", ")", ":", "return", "u", "(", "obj", ",", "errors", "=", "'replace'", ")" ]
https://github.com/DamnWidget/anaconda/blob/a9998fb362320f907d5ccbc6fcf5b62baca677c0/anaconda_lib/jedi/_compatibility.py#L289-L300
sunpy/sunpy
528579df0a4c938c133bd08971ba75c131b189a7
sunpy/io/special/genx.py
python
read_genx
(filename)
return skeleton
solarsoft genx file reader. genx files have been used to store calibration data for multiple instruments and distributed within solarsoft. They are stored in XDR format; The External Data Representation Standard file format (XDR) is described in `RFC 1014 <https://tools.ietf.org/html/rfc1014>`__, written by Sun Microsystems, Inc. June 1987. SolarSoft genx writer creates structures to store the values together with the variable names. It use the ``size`` IDL function to include the data type, dimension and number of elements that each variable contains. Parameters ---------- filename : `str` The genx file to be read Returns ------- output : `~collections.OrderedDict` A dictionary with possibly nested dictionaries with the data in the genx file. Notes ----- The reader aims to maintain the shape and type of the arrays, but take care with the difference in indexing between Python and IDL (row mayor vs column mayor). Regarding the type notice that single numbers are converted to python precision, therefore a single integer is converted from 16 to 32/64 bits, and a float from 32 to 64. **Strings** read from genx files are assumed to be UTF-8.
solarsoft genx file reader.
[ "solarsoft", "genx", "file", "reader", "." ]
def read_genx(filename): """ solarsoft genx file reader. genx files have been used to store calibration data for multiple instruments and distributed within solarsoft. They are stored in XDR format; The External Data Representation Standard file format (XDR) is described in `RFC 1014 <https://tools.ietf.org/html/rfc1014>`__, written by Sun Microsystems, Inc. June 1987. SolarSoft genx writer creates structures to store the values together with the variable names. It use the ``size`` IDL function to include the data type, dimension and number of elements that each variable contains. Parameters ---------- filename : `str` The genx file to be read Returns ------- output : `~collections.OrderedDict` A dictionary with possibly nested dictionaries with the data in the genx file. Notes ----- The reader aims to maintain the shape and type of the arrays, but take care with the difference in indexing between Python and IDL (row mayor vs column mayor). Regarding the type notice that single numbers are converted to python precision, therefore a single integer is converted from 16 to 32/64 bits, and a float from 32 to 64. **Strings** read from genx files are assumed to be UTF-8. """ with open(filename, mode='rb') as xdrfile: xdrdata = SSWUnpacker(xdrfile.read()) # HEADER information version, xdr = xdrdata.unpack_int(), xdrdata.unpack_int() creation = xdrdata.unpack_string() if version == 2: arch = xdrdata.unpack_string() os = xdrdata.unpack_string() release = xdrdata.unpack_string() text = xdrdata.unpack_string() # TODO: I don't think will have dim>1 but need # to check, if it's larger like savegen has run # with a multidimensional structure, then # probably the read_struct_skeleton will have to # run as in multi-dim structure. dim = xdrdata.unpack_int() # [1, 8, 1] = Main structure for the data arr_size = xdrdata.unpack_farray(dim + 2, xdrdata.unpack_int) # the number of upper level strs # This is used somehow mainsize = arr_size[2] # NOQA skeleton = read_struct_skeleton(xdrdata) struct_to_data(xdrdata, skeleton) xdrdata.done() skeleton['HEADER'] = OrderedDict([('VERSION', version), ('XDR', xdr), ('CREATION', creation)]) if version == 2: skeleton['HEADER']['IDL_VERSION'] = OrderedDict([('ARCH', arch), ('OS', os), ('RELEASE', release)]) skeleton['HEADER']['TEXT'] = text # TODO: for python >= 3.2; so we can keep the original order as how it's stored in the file # skeleton.move_to_end('HEADER', last=False) return skeleton
[ "def", "read_genx", "(", "filename", ")", ":", "with", "open", "(", "filename", ",", "mode", "=", "'rb'", ")", "as", "xdrfile", ":", "xdrdata", "=", "SSWUnpacker", "(", "xdrfile", ".", "read", "(", ")", ")", "# HEADER information", "version", ",", "xdr",...
https://github.com/sunpy/sunpy/blob/528579df0a4c938c133bd08971ba75c131b189a7/sunpy/io/special/genx.py#L118-L189
volatilityfoundation/volatility
a438e768194a9e05eb4d9ee9338b881c0fa25937
volatility/plugins/addrspaces/amd64.py
python
AMD64PagedMemory.get_pdpi
(self, vaddr, pml4e)
return self.read_long_long_phys(pdpte_paddr)
This method returns the Page Directory Pointer entry for the virtual address. Bits 32:30 are used to select the appropriate 8 byte entry in the Page Directory Pointer table. "Bits 51:12 are from the PML4E" [Intel] "Bits 11:3 are bits 38:30 of the linear address" [Intel] "Bits 2:0 are all 0" [Intel]
This method returns the Page Directory Pointer entry for the virtual address. Bits 32:30 are used to select the appropriate 8 byte entry in the Page Directory Pointer table.
[ "This", "method", "returns", "the", "Page", "Directory", "Pointer", "entry", "for", "the", "virtual", "address", ".", "Bits", "32", ":", "30", "are", "used", "to", "select", "the", "appropriate", "8", "byte", "entry", "in", "the", "Page", "Directory", "Poi...
def get_pdpi(self, vaddr, pml4e): ''' This method returns the Page Directory Pointer entry for the virtual address. Bits 32:30 are used to select the appropriate 8 byte entry in the Page Directory Pointer table. "Bits 51:12 are from the PML4E" [Intel] "Bits 11:3 are bits 38:30 of the linear address" [Intel] "Bits 2:0 are all 0" [Intel] ''' pdpte_paddr = (pml4e & 0xffffffffff000) | ((vaddr & 0x7FC0000000) >> 27) return self.read_long_long_phys(pdpte_paddr)
[ "def", "get_pdpi", "(", "self", ",", "vaddr", ",", "pml4e", ")", ":", "pdpte_paddr", "=", "(", "pml4e", "&", "0xffffffffff000", ")", "|", "(", "(", "vaddr", "&", "0x7FC0000000", ")", ">>", "27", ")", "return", "self", ".", "read_long_long_phys", "(", "...
https://github.com/volatilityfoundation/volatility/blob/a438e768194a9e05eb4d9ee9338b881c0fa25937/volatility/plugins/addrspaces/amd64.py#L134-L145
WoLpH/python-statsd
a757da04375c48d03d322246405b33382d37f03f
statsd/raw.py
python
Raw.send
(self, subname, value, timestamp=None)
return statsd.Client._send(self, {name: '%s|r|%s' % (value, ts)})
Send the data to statsd via self.connection :keyword subname: The subname to report the data to (appended to the client name) :type subname: str :keyword value: The raw value to send
Send the data to statsd via self.connection
[ "Send", "the", "data", "to", "statsd", "via", "self", ".", "connection" ]
def send(self, subname, value, timestamp=None): '''Send the data to statsd via self.connection :keyword subname: The subname to report the data to (appended to the client name) :type subname: str :keyword value: The raw value to send ''' if timestamp is None: ts = int(dt.datetime.now().strftime("%s")) else: ts = timestamp name = self._get_name(self.name, subname) self.logger.info('%s: %s %s' % (name, value, ts)) return statsd.Client._send(self, {name: '%s|r|%s' % (value, ts)})
[ "def", "send", "(", "self", ",", "subname", ",", "value", ",", "timestamp", "=", "None", ")", ":", "if", "timestamp", "is", "None", ":", "ts", "=", "int", "(", "dt", ".", "datetime", ".", "now", "(", ")", ".", "strftime", "(", "\"%s\"", ")", ")",...
https://github.com/WoLpH/python-statsd/blob/a757da04375c48d03d322246405b33382d37f03f/statsd/raw.py#L24-L38
wxWidgets/Phoenix
b2199e299a6ca6d866aa6f3d0888499136ead9d6
wx/lib/agw/ultimatelistctrl.py
python
UltimateListItemData.GetWidth
(self)
return self._rect.width
Returns the item width, in pixels.
Returns the item width, in pixels.
[ "Returns", "the", "item", "width", "in", "pixels", "." ]
def GetWidth(self): """ Returns the item width, in pixels. """ return self._rect.width
[ "def", "GetWidth", "(", "self", ")", ":", "return", "self", ".", "_rect", ".", "width" ]
https://github.com/wxWidgets/Phoenix/blob/b2199e299a6ca6d866aa6f3d0888499136ead9d6/wx/lib/agw/ultimatelistctrl.py#L3108-L3111
Lab41/ipython-spark-docker
a73dca291447f4861a97a9716593306b148d0b2a
mesos/fabfile.py
python
start_masters
()
[]
def start_masters(): run('echo manual | sudo tee /etc/init/mesos-slave.override') run('sudo stop mesos-slave; sudo restart zookeeper') run('sudo start mesos-master') run('sudo start marathon')
[ "def", "start_masters", "(", ")", ":", "run", "(", "'echo manual | sudo tee /etc/init/mesos-slave.override'", ")", "run", "(", "'sudo stop mesos-slave; sudo restart zookeeper'", ")", "run", "(", "'sudo start mesos-master'", ")", "run", "(", "'sudo start marathon'", ")" ]
https://github.com/Lab41/ipython-spark-docker/blob/a73dca291447f4861a97a9716593306b148d0b2a/mesos/fabfile.py#L73-L77
xonsh/xonsh
b76d6f994f22a4078f602f8b386f4ec280c8461f
xonsh/parsers/base.py
python
xonsh_pathsearch
(pattern, pymode=False, lineno=None, col=None)
return xonsh_call( "__xonsh__.pathsearch", args=[func, pattern, pymode, pathobj], lineno=lineno, col=col, )
Creates the AST node for calling the __xonsh__.pathsearch() function. The pymode argument indicate if it is called from subproc or python mode
Creates the AST node for calling the __xonsh__.pathsearch() function. The pymode argument indicate if it is called from subproc or python mode
[ "Creates", "the", "AST", "node", "for", "calling", "the", "__xonsh__", ".", "pathsearch", "()", "function", ".", "The", "pymode", "argument", "indicate", "if", "it", "is", "called", "from", "subproc", "or", "python", "mode" ]
def xonsh_pathsearch(pattern, pymode=False, lineno=None, col=None): """Creates the AST node for calling the __xonsh__.pathsearch() function. The pymode argument indicate if it is called from subproc or python mode""" pymode = ast.NameConstant(value=pymode, lineno=lineno, col_offset=col) searchfunc, pattern = RE_SEARCHPATH.match(pattern).groups() pattern = ast.Str(s=pattern, lineno=lineno, col_offset=col) pathobj = False if searchfunc.startswith("@"): func = searchfunc[1:] elif "g" in searchfunc: func = "__xonsh__.globsearch" pathobj = "p" in searchfunc else: func = "__xonsh__.regexsearch" pathobj = "p" in searchfunc func = load_attribute_chain(func, lineno=lineno, col=col) pathobj = ast.NameConstant(value=pathobj, lineno=lineno, col_offset=col) return xonsh_call( "__xonsh__.pathsearch", args=[func, pattern, pymode, pathobj], lineno=lineno, col=col, )
[ "def", "xonsh_pathsearch", "(", "pattern", ",", "pymode", "=", "False", ",", "lineno", "=", "None", ",", "col", "=", "None", ")", ":", "pymode", "=", "ast", ".", "NameConstant", "(", "value", "=", "pymode", ",", "lineno", "=", "lineno", ",", "col_offse...
https://github.com/xonsh/xonsh/blob/b76d6f994f22a4078f602f8b386f4ec280c8461f/xonsh/parsers/base.py#L129-L151
marinho/geraldo
868ebdce67176d9b6205cddc92476f642c783fff
site/newsite/site-geraldo/django/__init__.py
python
get_version
()
return v
Returns the version as a human-format string.
Returns the version as a human-format string.
[ "Returns", "the", "version", "as", "a", "human", "-", "format", "string", "." ]
def get_version(): "Returns the version as a human-format string." v = '.'.join([str(i) for i in VERSION[:-1]]) if VERSION[-1]: from django.utils.version import get_svn_revision v = '%s-%s-%s' % (v, VERSION[-1], get_svn_revision()) return v
[ "def", "get_version", "(", ")", ":", "v", "=", "'.'", ".", "join", "(", "[", "str", "(", "i", ")", "for", "i", "in", "VERSION", "[", ":", "-", "1", "]", "]", ")", "if", "VERSION", "[", "-", "1", "]", ":", "from", "django", ".", "utils", "."...
https://github.com/marinho/geraldo/blob/868ebdce67176d9b6205cddc92476f642c783fff/site/newsite/site-geraldo/django/__init__.py#L3-L9
quic/aimet
dae9bae9a77ca719aa7553fefde4768270fc3518
TrainingExtensions/tensorflow/src/python/aimet_tensorflow/common/connectedgraph.py
python
ConnectedGraph.get_op_from_module_name
(self, name: str)
return self._ops.get(op_info.module_name, None)
Given the name of a tf operation, return the op in ops dict corresponding to the tf operation
Given the name of a tf operation, return the op in ops dict corresponding to the tf operation
[ "Given", "the", "name", "of", "a", "tf", "operation", "return", "the", "op", "in", "ops", "dict", "corresponding", "to", "the", "tf", "operation" ]
def get_op_from_module_name(self, name: str): """ Given the name of a tf operation, return the op in ops dict corresponding to the tf operation """ tf_op = self._graph.get_operation_by_name(name) op_info = self._module_identifier.get_op_info(tf_op) return self._ops.get(op_info.module_name, None)
[ "def", "get_op_from_module_name", "(", "self", ",", "name", ":", "str", ")", ":", "tf_op", "=", "self", ".", "_graph", ".", "get_operation_by_name", "(", "name", ")", "op_info", "=", "self", ".", "_module_identifier", ".", "get_op_info", "(", "tf_op", ")", ...
https://github.com/quic/aimet/blob/dae9bae9a77ca719aa7553fefde4768270fc3518/TrainingExtensions/tensorflow/src/python/aimet_tensorflow/common/connectedgraph.py#L87-L92
mathics/Mathics
318e06dea8f1c70758a50cb2f95c9900150e3a68
mathics/builtin/numbers/integer.py
python
BitLength.apply
(self, n, evaluation)
return Integer(n.bit_length())
BitLength[n_Integer]
BitLength[n_Integer]
[ "BitLength", "[", "n_Integer", "]" ]
def apply(self, n, evaluation): "BitLength[n_Integer]" n = n.get_int_value() if n < 0: n = -1 - n return Integer(n.bit_length())
[ "def", "apply", "(", "self", ",", "n", ",", "evaluation", ")", ":", "n", "=", "n", ".", "get_int_value", "(", ")", "if", "n", "<", "0", ":", "n", "=", "-", "1", "-", "n", "return", "Integer", "(", "n", ".", "bit_length", "(", ")", ")" ]
https://github.com/mathics/Mathics/blob/318e06dea8f1c70758a50cb2f95c9900150e3a68/mathics/builtin/numbers/integer.py#L193-L198
stopstalk/stopstalk-deployment
10c3ab44c4ece33ae515f6888c15033db2004bb1
aws_lambda/spoj_aws_lambda_function/lambda_code/setuptools/command/easy_install.py
python
easy_install.create_home_path
(self)
Create directories under ~.
Create directories under ~.
[ "Create", "directories", "under", "~", "." ]
def create_home_path(self): """Create directories under ~.""" if not self.user: return home = convert_path(os.path.expanduser("~")) for name, path in six.iteritems(self.config_vars): if path.startswith(home) and not os.path.isdir(path): self.debug_print("os.makedirs('%s', 0o700)" % path) os.makedirs(path, 0o700)
[ "def", "create_home_path", "(", "self", ")", ":", "if", "not", "self", ".", "user", ":", "return", "home", "=", "convert_path", "(", "os", ".", "path", ".", "expanduser", "(", "\"~\"", ")", ")", "for", "name", ",", "path", "in", "six", ".", "iteritem...
https://github.com/stopstalk/stopstalk-deployment/blob/10c3ab44c4ece33ae515f6888c15033db2004bb1/aws_lambda/spoj_aws_lambda_function/lambda_code/setuptools/command/easy_install.py#L1340-L1348
avrae/avrae
6ebe46a1ec3d4dfaa2f9b18fac948325f39f87de
cogs5e/models/sheet/base.py
python
Saves.update
(self, explicit_saves: dict)
Updates saves with an explicit dictionary of modifiers. All provided are assumed to have prof=1.
Updates saves with an explicit dictionary of modifiers. All provided are assumed to have prof=1.
[ "Updates", "saves", "with", "an", "explicit", "dictionary", "of", "modifiers", ".", "All", "provided", "are", "assumed", "to", "have", "prof", "=", "1", "." ]
def update(self, explicit_saves: dict): """Updates saves with an explicit dictionary of modifiers. All provided are assumed to have prof=1.""" for save, mod in explicit_saves.items(): if save not in self.saves: raise ValueError(f"{save} is not a save.") self.saves[save].value = mod self.saves[save].prof = 1
[ "def", "update", "(", "self", ",", "explicit_saves", ":", "dict", ")", ":", "for", "save", ",", "mod", "in", "explicit_saves", ".", "items", "(", ")", ":", "if", "save", "not", "in", "self", ".", "saves", ":", "raise", "ValueError", "(", "f\"{save} is ...
https://github.com/avrae/avrae/blob/6ebe46a1ec3d4dfaa2f9b18fac948325f39f87de/cogs5e/models/sheet/base.py#L259-L265
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/combinat/set_partition.py
python
SetPartition.check
(self)
Check that we are a valid set partition. EXAMPLES:: sage: S = SetPartitions(4) sage: s = S([[1, 3], [2, 4]]) sage: s.check() TESTS:: sage: s = S([[1, 2, 3]], check=False) sage: s.check() Traceback (most recent call last): ... ValueError: {{1, 2, 3}} is not an element of Set partitions of {1, 2, 3, 4} sage: s = S([1, 2, 3]) Traceback (most recent call last): ... TypeError: 'sage.rings.integer.Integer' object is not iterable
Check that we are a valid set partition.
[ "Check", "that", "we", "are", "a", "valid", "set", "partition", "." ]
def check(self): """ Check that we are a valid set partition. EXAMPLES:: sage: S = SetPartitions(4) sage: s = S([[1, 3], [2, 4]]) sage: s.check() TESTS:: sage: s = S([[1, 2, 3]], check=False) sage: s.check() Traceback (most recent call last): ... ValueError: {{1, 2, 3}} is not an element of Set partitions of {1, 2, 3, 4} sage: s = S([1, 2, 3]) Traceback (most recent call last): ... TypeError: 'sage.rings.integer.Integer' object is not iterable """ if self not in self.parent(): raise ValueError("%s is not an element of %s"%(self, self.parent()))
[ "def", "check", "(", "self", ")", ":", "if", "self", "not", "in", "self", ".", "parent", "(", ")", ":", "raise", "ValueError", "(", "\"%s is not an element of %s\"", "%", "(", "self", ",", "self", ".", "parent", "(", ")", ")", ")" ]
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/combinat/set_partition.py#L626-L650
grayddq/PublicMonitors
814bfe9662d23b64d089ff750aa6a5b3e152d3c2
lib/nmap.py
python
PortScannerHostDict.sctp
(self, port)
return self['sctp'][port]
returns info for sctp port
returns info for sctp port
[ "returns", "info", "for", "sctp", "port" ]
def sctp(self, port): """ returns info for sctp port """ assert type(port) is int, 'Wrong type for [port], should be an int [was {0}]'.format(type(port)) return self['sctp'][port]
[ "def", "sctp", "(", "self", ",", "port", ")", ":", "assert", "type", "(", "port", ")", "is", "int", ",", "'Wrong type for [port], should be an int [was {0}]'", ".", "format", "(", "type", "(", "port", ")", ")", "return", "self", "[", "'sctp'", "]", "[", ...
https://github.com/grayddq/PublicMonitors/blob/814bfe9662d23b64d089ff750aa6a5b3e152d3c2/lib/nmap.py#L772-L778
redis/redis-py
0affa0ed3f3cbcb6dec29b34a580f769f69ae9f7
redis/commands/core.py
python
BasicKeyCommands.getrange
(self, key, start, end)
return self.execute_command("GETRANGE", key, start, end)
Returns the substring of the string value stored at ``key``, determined by the offsets ``start`` and ``end`` (both are inclusive) For more information check https://redis.io/commands/getrange
Returns the substring of the string value stored at ``key``, determined by the offsets ``start`` and ``end`` (both are inclusive)
[ "Returns", "the", "substring", "of", "the", "string", "value", "stored", "at", "key", "determined", "by", "the", "offsets", "start", "and", "end", "(", "both", "are", "inclusive", ")" ]
def getrange(self, key, start, end): """ Returns the substring of the string value stored at ``key``, determined by the offsets ``start`` and ``end`` (both are inclusive) For more information check https://redis.io/commands/getrange """ return self.execute_command("GETRANGE", key, start, end)
[ "def", "getrange", "(", "self", ",", "key", ",", "start", ",", "end", ")", ":", "return", "self", ".", "execute_command", "(", "\"GETRANGE\"", ",", "key", ",", "start", ",", "end", ")" ]
https://github.com/redis/redis-py/blob/0affa0ed3f3cbcb6dec29b34a580f769f69ae9f7/redis/commands/core.py#L1332-L1339
larryhastings/gilectomy
4315ec3f1d6d4f813cc82ce27a24e7f784dbfc1a
Lib/lib2to3/pgen2/conv.py
python
Converter.run
(self, graminit_h, graminit_c)
Load the grammar tables from the text files written by pgen.
Load the grammar tables from the text files written by pgen.
[ "Load", "the", "grammar", "tables", "from", "the", "text", "files", "written", "by", "pgen", "." ]
def run(self, graminit_h, graminit_c): """Load the grammar tables from the text files written by pgen.""" self.parse_graminit_h(graminit_h) self.parse_graminit_c(graminit_c) self.finish_off()
[ "def", "run", "(", "self", ",", "graminit_h", ",", "graminit_c", ")", ":", "self", ".", "parse_graminit_h", "(", "graminit_h", ")", "self", ".", "parse_graminit_c", "(", "graminit_c", ")", "self", ".", "finish_off", "(", ")" ]
https://github.com/larryhastings/gilectomy/blob/4315ec3f1d6d4f813cc82ce27a24e7f784dbfc1a/Lib/lib2to3/pgen2/conv.py#L47-L51
wistbean/learn_python3_spider
73c873f4845f4385f097e5057407d03dd37a117b
stackoverflow/venv/lib/python3.6/site-packages/pycparser/c_ast.py
python
Node.__repr__
(self)
return result
Generates a python representation of the current node
Generates a python representation of the current node
[ "Generates", "a", "python", "representation", "of", "the", "current", "node" ]
def __repr__(self): """ Generates a python representation of the current node """ result = self.__class__.__name__ + '(' indent = '' separator = '' for name in self.__slots__[:-2]: result += separator result += indent result += name + '=' + (_repr(getattr(self, name)).replace('\n', '\n ' + (' ' * (len(name) + len(self.__class__.__name__))))) separator = ',' indent = '\n ' + (' ' * len(self.__class__.__name__)) result += indent + ')' return result
[ "def", "__repr__", "(", "self", ")", ":", "result", "=", "self", ".", "__class__", ".", "__name__", "+", "'('", "indent", "=", "''", "separator", "=", "''", "for", "name", "in", "self", ".", "__slots__", "[", ":", "-", "2", "]", ":", "result", "+="...
https://github.com/wistbean/learn_python3_spider/blob/73c873f4845f4385f097e5057407d03dd37a117b/stackoverflow/venv/lib/python3.6/site-packages/pycparser/c_ast.py#L34-L51
facebookresearch/detectron2
cb92ae1763cd7d3777c243f07749574cdaec6cb8
projects/Panoptic-DeepLab/panoptic_deeplab/target_generator.py
python
PanopticDeepLabTargetGenerator.__call__
(self, panoptic, segments_info)
return dict( sem_seg=torch.as_tensor(semantic.astype("long")), center=torch.as_tensor(center.astype(np.float32)), center_points=center_pts, offset=torch.as_tensor(offset.astype(np.float32)), sem_seg_weights=torch.as_tensor(semantic_weights.astype(np.float32)), center_weights=torch.as_tensor(center_weights.astype(np.float32)), offset_weights=torch.as_tensor(offset_weights.astype(np.float32)), )
Generates the training target. reference: https://github.com/mcordts/cityscapesScripts/blob/master/cityscapesscripts/preparation/createPanopticImgs.py # noqa reference: https://github.com/facebookresearch/detectron2/blob/main/datasets/prepare_panoptic_fpn.py#L18 # noqa Args: panoptic: numpy.array, panoptic label, we assume it is already converted from rgb image by panopticapi.utils.rgb2id. segments_info (list[dict]): see detectron2 documentation of "Use Custom Datasets". Returns: A dictionary with fields: - sem_seg: Tensor, semantic label, shape=(H, W). - center: Tensor, center heatmap, shape=(H, W). - center_points: List, center coordinates, with tuple (y-coord, x-coord). - offset: Tensor, offset, shape=(2, H, W), first dim is (offset_y, offset_x). - sem_seg_weights: Tensor, loss weight for semantic prediction, shape=(H, W). - center_weights: Tensor, ignore region of center prediction, shape=(H, W), used as weights for center regression 0 is ignore, 1 is has instance. Multiply this mask to loss. - offset_weights: Tensor, ignore region of offset prediction, shape=(H, W), used as weights for offset regression 0 is ignore, 1 is has instance. Multiply this mask to loss.
Generates the training target. reference: https://github.com/mcordts/cityscapesScripts/blob/master/cityscapesscripts/preparation/createPanopticImgs.py # noqa reference: https://github.com/facebookresearch/detectron2/blob/main/datasets/prepare_panoptic_fpn.py#L18 # noqa
[ "Generates", "the", "training", "target", ".", "reference", ":", "https", ":", "//", "github", ".", "com", "/", "mcordts", "/", "cityscapesScripts", "/", "blob", "/", "master", "/", "cityscapesscripts", "/", "preparation", "/", "createPanopticImgs", ".", "py",...
def __call__(self, panoptic, segments_info): """Generates the training target. reference: https://github.com/mcordts/cityscapesScripts/blob/master/cityscapesscripts/preparation/createPanopticImgs.py # noqa reference: https://github.com/facebookresearch/detectron2/blob/main/datasets/prepare_panoptic_fpn.py#L18 # noqa Args: panoptic: numpy.array, panoptic label, we assume it is already converted from rgb image by panopticapi.utils.rgb2id. segments_info (list[dict]): see detectron2 documentation of "Use Custom Datasets". Returns: A dictionary with fields: - sem_seg: Tensor, semantic label, shape=(H, W). - center: Tensor, center heatmap, shape=(H, W). - center_points: List, center coordinates, with tuple (y-coord, x-coord). - offset: Tensor, offset, shape=(2, H, W), first dim is (offset_y, offset_x). - sem_seg_weights: Tensor, loss weight for semantic prediction, shape=(H, W). - center_weights: Tensor, ignore region of center prediction, shape=(H, W), used as weights for center regression 0 is ignore, 1 is has instance. Multiply this mask to loss. - offset_weights: Tensor, ignore region of offset prediction, shape=(H, W), used as weights for offset regression 0 is ignore, 1 is has instance. Multiply this mask to loss. """ height, width = panoptic.shape[0], panoptic.shape[1] semantic = np.zeros_like(panoptic, dtype=np.uint8) + self.ignore_label center = np.zeros((height, width), dtype=np.float32) center_pts = [] offset = np.zeros((2, height, width), dtype=np.float32) y_coord, x_coord = np.meshgrid( np.arange(height, dtype=np.float32), np.arange(width, dtype=np.float32), indexing="ij" ) # Generate pixel-wise loss weights semantic_weights = np.ones_like(panoptic, dtype=np.uint8) # 0: ignore, 1: has instance # three conditions for a region to be ignored for instance branches: # (1) It is labeled as `ignore_label` # (2) It is crowd region (iscrowd=1) # (3) (Optional) It is stuff region (for offset branch) center_weights = np.zeros_like(panoptic, dtype=np.uint8) offset_weights = np.zeros_like(panoptic, dtype=np.uint8) for seg in segments_info: cat_id = seg["category_id"] if not (self.ignore_crowd_in_semantic and seg["iscrowd"]): semantic[panoptic == seg["id"]] = cat_id if not seg["iscrowd"]: # Ignored regions are not in `segments_info`. # Handle crowd region. center_weights[panoptic == seg["id"]] = 1 if not self.ignore_stuff_in_offset or cat_id in self.thing_ids: offset_weights[panoptic == seg["id"]] = 1 if cat_id in self.thing_ids: # find instance center mask_index = np.where(panoptic == seg["id"]) if len(mask_index[0]) == 0: # the instance is completely cropped continue # Find instance area ins_area = len(mask_index[0]) if ins_area < self.small_instance_area: semantic_weights[panoptic == seg["id"]] = self.small_instance_weight center_y, center_x = np.mean(mask_index[0]), np.mean(mask_index[1]) center_pts.append([center_y, center_x]) # generate center heatmap y, x = int(round(center_y)), int(round(center_x)) sigma = self.sigma # upper left ul = int(np.round(x - 3 * sigma - 1)), int(np.round(y - 3 * sigma - 1)) # bottom right br = int(np.round(x + 3 * sigma + 2)), int(np.round(y + 3 * sigma + 2)) # start and end indices in default Gaussian image gaussian_x0, gaussian_x1 = max(0, -ul[0]), min(br[0], width) - ul[0] gaussian_y0, gaussian_y1 = max(0, -ul[1]), min(br[1], height) - ul[1] # start and end indices in center heatmap image center_x0, center_x1 = max(0, ul[0]), min(br[0], width) center_y0, center_y1 = max(0, ul[1]), min(br[1], height) center[center_y0:center_y1, center_x0:center_x1] = np.maximum( center[center_y0:center_y1, center_x0:center_x1], self.g[gaussian_y0:gaussian_y1, gaussian_x0:gaussian_x1], ) # generate offset (2, h, w) -> (y-dir, x-dir) offset[0][mask_index] = center_y - y_coord[mask_index] offset[1][mask_index] = center_x - x_coord[mask_index] center_weights = center_weights[None] offset_weights = offset_weights[None] return dict( sem_seg=torch.as_tensor(semantic.astype("long")), center=torch.as_tensor(center.astype(np.float32)), center_points=center_pts, offset=torch.as_tensor(offset.astype(np.float32)), sem_seg_weights=torch.as_tensor(semantic_weights.astype(np.float32)), center_weights=torch.as_tensor(center_weights.astype(np.float32)), offset_weights=torch.as_tensor(offset_weights.astype(np.float32)), )
[ "def", "__call__", "(", "self", ",", "panoptic", ",", "segments_info", ")", ":", "height", ",", "width", "=", "panoptic", ".", "shape", "[", "0", "]", ",", "panoptic", ".", "shape", "[", "1", "]", "semantic", "=", "np", ".", "zeros_like", "(", "panop...
https://github.com/facebookresearch/detectron2/blob/cb92ae1763cd7d3777c243f07749574cdaec6cb8/projects/Panoptic-DeepLab/panoptic_deeplab/target_generator.py#L52-L155
IntelAI/models
1d7a53ccfad3e6f0e7378c9e3c8840895d63df8c
models/common/tensorflow/mlperf_utils/logs/logger.py
python
BenchmarkLogger.log_metric
(self, name, value, unit=None, global_step=None, extras=None)
Log the benchmark metric information to local file. Currently the logging is done in a synchronized way. This should be updated to log asynchronously. Args: name: string, the name of the metric to log. value: number, the value of the metric. The value will not be logged if it is not a number type. unit: string, the unit of the metric, E.g "image per second". global_step: int, the global_step when the metric is logged. extras: map of string:string, the extra information about the metric.
Log the benchmark metric information to local file.
[ "Log", "the", "benchmark", "metric", "information", "to", "local", "file", "." ]
def log_metric(self, name, value, unit=None, global_step=None, extras=None): """Log the benchmark metric information to local file. Currently the logging is done in a synchronized way. This should be updated to log asynchronously. Args: name: string, the name of the metric to log. value: number, the value of the metric. The value will not be logged if it is not a number type. unit: string, the unit of the metric, E.g "image per second". global_step: int, the global_step when the metric is logged. extras: map of string:string, the extra information about the metric. """ if not isinstance(value, numbers.Number): tf.compat.v1.logging.warning( "Metric value to log should be a number. Got %s", type(value)) return if extras: extras = [{"name": k, "value": v} for k, v in sorted(extras.items())] else: extras = [] with tf.io.gfile.GFile( os.path.join(self._logging_dir, METRIC_LOG_FILE_NAME), "a") as f: metric = { "name": name, "value": float(value), "unit": unit, "global_step": global_step, "timestamp": datetime.datetime.now().strftime( _DATE_TIME_FORMAT_PATTERN), "extras": extras} try: json.dump(metric, f) f.write("\n") except (TypeError, ValueError) as e: tf.compat.v1.logging.warning("Failed to dump metric to log file: " "name %s, value %s, error %s", name, value, e)
[ "def", "log_metric", "(", "self", ",", "name", ",", "value", ",", "unit", "=", "None", ",", "global_step", "=", "None", ",", "extras", "=", "None", ")", ":", "if", "not", "isinstance", "(", "value", ",", "numbers", ".", "Number", ")", ":", "tf", "....
https://github.com/IntelAI/models/blob/1d7a53ccfad3e6f0e7378c9e3c8840895d63df8c/models/common/tensorflow/mlperf_utils/logs/logger.py#L66-L103
tendenci/tendenci
0f2c348cc0e7d41bc56f50b00ce05544b083bf1d
tendenci/apps/corporate_memberships/import_processor.py
python
CorpMembershipImportProcessor.process_corp_membership
(self, cmemb_data, **kwargs)
return corp_memb_display
Check if it's insert or update. If dry_run is False, do the import to the corpmembership. :param cmemb_data: a dictionary that includes the info of a corp_membership
Check if it's insert or update. If dry_run is False, do the import to the corpmembership.
[ "Check", "if", "it", "s", "insert", "or", "update", ".", "If", "dry_run", "is", "False", "do", "the", "import", "to", "the", "corpmembership", "." ]
def process_corp_membership(self, cmemb_data, **kwargs): """ Check if it's insert or update. If dry_run is False, do the import to the corpmembership. :param cmemb_data: a dictionary that includes the info of a corp_membership """ self.cmemb_data = cmemb_data if 'id' not in self.cmemb_data: if 'id' in self.corp_membership_fields: del self.corp_membership_fields['id'] self.cmemb_data['name'] = self.cmemb_data['company_name'] del self.cmemb_data['company_name'] self.field_names = cmemb_data # csv field names corp_memb_display = {} corp_memb_display['error'] = '' corp_memb_display['user'] = None status_detail = self.cmemb_data.get('status_detail', 'active') if status_detail == 'archived': status_detail = 'archive' if status_detail not in CorpMembership.VALID_STATUS_DETAIL: status_detail = 'active' self.cmemb_data['status_detail'] = status_detail expiration_dt = self.cmemb_data.get('expiration_dt', None) if expiration_dt: expiration_dt = dparser.parse(expiration_dt) error_msg = self.validate_fields(self.cmemb_data, self.key) # don't process if we have missing value of required fields if error_msg: corp_memb_display['error'] = error_msg corp_memb_display['action'] = 'skip' if not self.dry_run: self.summary_d['invalid'] += 1 else: #if self.key == 'name': [corp_profile] = CorpProfile.objects.filter( name=self.cmemb_data['name'])[:1] or [None] if corp_profile: corp_membs = CorpMembership.objects.filter( corp_profile=corp_profile, status_detail=status_detail) # there might be multiple archives, pick the one that # matches with the expiration_dt if status_detail == 'archive' and expiration_dt: corp_membs = corp_membs.filter( expiration_dt__year=expiration_dt.year, expiration_dt__month=expiration_dt.month, expiration_dt__day=expiration_dt.day ) [corp_memb] = corp_membs.order_by('-id')[:1] or [None] else: corp_memb = None if corp_profile: if corp_memb: corp_memb_display['action'] = 'update' corp_memb_display['corp_profile_action'] = 'update' corp_memb_display['corp_memb_action'] = 'update' else: corp_memb_display['action'] = 'mixed' corp_memb_display['corp_profile_action'] = 'update' corp_memb_display['corp_memb_action'] = 'insert' else: corp_memb_display['action'] = 'insert' corp_memb_display['corp_profile_action'] = 'insert' corp_memb_display['corp_memb_action'] = 'insert' if not self.dry_run: if corp_memb_display['action'] == 'insert': self.summary_d['insert'] += 1 elif corp_memb_display['action'] == 'update': self.summary_d['update'] += 1 else: self.summary_d['update_insert'] += 1 # now do the update or insert corp_profile, corp_memb = self.do_import_corp_membership(corp_profile, corp_memb, corp_memb_display) # handle authorized_domain if 'authorized_domains' in self.field_names: update_authorized_domains(corp_profile, self.cmemb_data['authorized_domains']) # handle dues_rep if 'dues_rep' in self.field_names: self.update_dues_reps(corp_profile, self.cmemb_data['dues_rep']) return corp_memb_display.update({ 'company_name': self.cmemb_data.get('name', ''), 'email': self.cmemb_data.get('email', ''), 'address': self.cmemb_data.get('address', ''), 'address2': self.cmemb_data.get('address2', ''), 'city': self.cmemb_data.get('city', ''), 'state': self.cmemb_data.get('state', ''), 'zip': self.cmemb_data.get('zip', ''), 'status_detail': self.cmemb_data.get('status_detail', ''), }) return corp_memb_display
[ "def", "process_corp_membership", "(", "self", ",", "cmemb_data", ",", "*", "*", "kwargs", ")", ":", "self", ".", "cmemb_data", "=", "cmemb_data", "if", "'id'", "not", "in", "self", ".", "cmemb_data", ":", "if", "'id'", "in", "self", ".", "corp_membership_...
https://github.com/tendenci/tendenci/blob/0f2c348cc0e7d41bc56f50b00ce05544b083bf1d/tendenci/apps/corporate_memberships/import_processor.py#L156-L260
cloudera/impyla
0c736af4cad2bade9b8e313badc08ec50e81c948
impala/_thrift_gen/hive_metastore/ThriftHiveMetastore.py
python
Client.alter_table
(self, dbname, tbl_name, new_tbl)
Parameters: - dbname - tbl_name - new_tbl
Parameters: - dbname - tbl_name - new_tbl
[ "Parameters", ":", "-", "dbname", "-", "tbl_name", "-", "new_tbl" ]
def alter_table(self, dbname, tbl_name, new_tbl): """ Parameters: - dbname - tbl_name - new_tbl """ self.send_alter_table(dbname, tbl_name, new_tbl) self.recv_alter_table()
[ "def", "alter_table", "(", "self", ",", "dbname", ",", "tbl_name", ",", "new_tbl", ")", ":", "self", ".", "send_alter_table", "(", "dbname", ",", "tbl_name", ",", "new_tbl", ")", "self", ".", "recv_alter_table", "(", ")" ]
https://github.com/cloudera/impyla/blob/0c736af4cad2bade9b8e313badc08ec50e81c948/impala/_thrift_gen/hive_metastore/ThriftHiveMetastore.py#L2305-L2313
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/Python-2.7.9/Lib/lib-tk/turtle.py
python
RawTurtle.reset
(self)
Delete the turtle's drawings and restore its default values. No argument. , Delete the turtle's drawings from the screen, re-center the turtle and set variables to the default values. Example (for a Turtle instance named turtle): >>> turtle.position() (0.00,-22.00) >>> turtle.heading() 100.0 >>> turtle.reset() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0
Delete the turtle's drawings and restore its default values.
[ "Delete", "the", "turtle", "s", "drawings", "and", "restore", "its", "default", "values", "." ]
def reset(self): """Delete the turtle's drawings and restore its default values. No argument. , Delete the turtle's drawings from the screen, re-center the turtle and set variables to the default values. Example (for a Turtle instance named turtle): >>> turtle.position() (0.00,-22.00) >>> turtle.heading() 100.0 >>> turtle.reset() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0 """ TNavigator.reset(self) TPen._reset(self) self._clear() self._drawturtle() self._update()
[ "def", "reset", "(", "self", ")", ":", "TNavigator", ".", "reset", "(", "self", ")", "TPen", ".", "_reset", "(", "self", ")", "self", ".", "_clear", "(", ")", "self", ".", "_drawturtle", "(", ")", "self", ".", "_update", "(", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/Python-2.7.9/Lib/lib-tk/turtle.py#L2463-L2486
apache/tvm
6eb4ed813ebcdcd9558f0906a1870db8302ff1e0
python/tvm/contrib/graph_executor.py
python
GraphModule.get_input_info
(self)
return shape_dict, dtype_dict
Return the 'shape' and 'dtype' dictionaries of the graph. .. note:: We can't simply get the input tensors from a TVM graph because weight tensors are treated equivalently. Therefore, to find the input tensors we look at the 'arg_nodes' in the graph (which are either weights or inputs) and check which ones don't appear in the params (where the weights are stored). These nodes are therefore inferred to be input tensors. Returns ------- shape_dict : Map Shape dictionary - {input_name: tuple}. dtype_dict : Map dtype dictionary - {input_name: dtype}.
Return the 'shape' and 'dtype' dictionaries of the graph.
[ "Return", "the", "shape", "and", "dtype", "dictionaries", "of", "the", "graph", "." ]
def get_input_info(self): """Return the 'shape' and 'dtype' dictionaries of the graph. .. note:: We can't simply get the input tensors from a TVM graph because weight tensors are treated equivalently. Therefore, to find the input tensors we look at the 'arg_nodes' in the graph (which are either weights or inputs) and check which ones don't appear in the params (where the weights are stored). These nodes are therefore inferred to be input tensors. Returns ------- shape_dict : Map Shape dictionary - {input_name: tuple}. dtype_dict : Map dtype dictionary - {input_name: dtype}. """ input_info = self._get_input_info() assert "shape" in input_info shape_dict = input_info["shape"] assert "dtype" in input_info dtype_dict = input_info["dtype"] return shape_dict, dtype_dict
[ "def", "get_input_info", "(", "self", ")", ":", "input_info", "=", "self", ".", "_get_input_info", "(", ")", "assert", "\"shape\"", "in", "input_info", "shape_dict", "=", "input_info", "[", "\"shape\"", "]", "assert", "\"dtype\"", "in", "input_info", "dtype_dict...
https://github.com/apache/tvm/blob/6eb4ed813ebcdcd9558f0906a1870db8302ff1e0/python/tvm/contrib/graph_executor.py#L262-L286
mrjoes/flask-admin
402b56ea844dc5b215f6293e7dc63f39a6723692
flask_admin/contrib/sqla/view.py
python
ModelView.__init__
(self, model, session, name=None, category=None, endpoint=None, url=None, static_folder=None, menu_class_name=None, menu_icon_type=None, menu_icon_value=None)
Constructor. :param model: Model class :param session: SQLAlchemy session :param name: View name. If not set, defaults to the model name :param category: Category name :param endpoint: Endpoint name. If not set, defaults to the model name :param url: Base URL. If not set, defaults to '/admin/' + endpoint :param menu_class_name: Optional class name for the menu item. :param menu_icon_type: Optional icon. Possible icon types: - `flask.ext.admin.consts.ICON_TYPE_GLYPH` - Bootstrap glyph icon - `flask.ext.admin.consts.ICON_TYPE_IMAGE` - Image relative to Flask static directory - `flask.ext.admin.consts.ICON_TYPE_IMAGE_URL` - Image with full URL :param menu_icon_value: Icon glyph name or URL, depending on `menu_icon_type` setting
Constructor.
[ "Constructor", "." ]
def __init__(self, model, session, name=None, category=None, endpoint=None, url=None, static_folder=None, menu_class_name=None, menu_icon_type=None, menu_icon_value=None): """ Constructor. :param model: Model class :param session: SQLAlchemy session :param name: View name. If not set, defaults to the model name :param category: Category name :param endpoint: Endpoint name. If not set, defaults to the model name :param url: Base URL. If not set, defaults to '/admin/' + endpoint :param menu_class_name: Optional class name for the menu item. :param menu_icon_type: Optional icon. Possible icon types: - `flask.ext.admin.consts.ICON_TYPE_GLYPH` - Bootstrap glyph icon - `flask.ext.admin.consts.ICON_TYPE_IMAGE` - Image relative to Flask static directory - `flask.ext.admin.consts.ICON_TYPE_IMAGE_URL` - Image with full URL :param menu_icon_value: Icon glyph name or URL, depending on `menu_icon_type` setting """ self.session = session self._search_fields = None self._search_joins = [] self._filter_joins = dict() self._sortable_joins = dict() if self.form_choices is None: self.form_choices = {} super(ModelView, self).__init__(model, name, category, endpoint, url, static_folder, menu_class_name=menu_class_name, menu_icon_type=menu_icon_type, menu_icon_value=menu_icon_value) # Primary key self._primary_key = self.scaffold_pk() if self._primary_key is None: raise Exception('Model %s does not have primary key.' % self.model.__name__) # Configuration if not self.column_select_related_list: self._auto_joins = self.scaffold_auto_joins() else: self._auto_joins = self.column_select_related_list
[ "def", "__init__", "(", "self", ",", "model", ",", "session", ",", "name", "=", "None", ",", "category", "=", "None", ",", "endpoint", "=", "None", ",", "url", "=", "None", ",", "static_folder", "=", "None", ",", "menu_class_name", "=", "None", ",", ...
https://github.com/mrjoes/flask-admin/blob/402b56ea844dc5b215f6293e7dc63f39a6723692/flask_admin/contrib/sqla/view.py#L245-L301
F8LEFT/DecLLVM
d38e45e3d0dd35634adae1d0cf7f96f3bd96e74c
python/idaapi.py
python
AskUsingForm
(*args)
return r
Calls the AskUsingForm() @param: Compiled Arguments obtain through the Form.Compile() function @return: 1 = ok, 0 = cancel
Calls the AskUsingForm()
[ "Calls", "the", "AskUsingForm", "()" ]
def AskUsingForm(*args): """ Calls the AskUsingForm() @param: Compiled Arguments obtain through the Form.Compile() function @return: 1 = ok, 0 = cancel """ old = set_script_timeout(0) r = AskUsingForm__(*args) set_script_timeout(old) return r
[ "def", "AskUsingForm", "(", "*", "args", ")", ":", "old", "=", "set_script_timeout", "(", "0", ")", "r", "=", "AskUsingForm__", "(", "*", "args", ")", "set_script_timeout", "(", "old", ")", "return", "r" ]
https://github.com/F8LEFT/DecLLVM/blob/d38e45e3d0dd35634adae1d0cf7f96f3bd96e74c/python/idaapi.py#L45600-L45609
livid/v2ex-gae
32be3a77d535e7c9df85a333e01ab8834d0e8581
twitter/twitter.py
python
User.SetScreenName
(self, screen_name)
Set the short username of this user. Args: screen_name: the short username of this user
Set the short username of this user.
[ "Set", "the", "short", "username", "of", "this", "user", "." ]
def SetScreenName(self, screen_name): '''Set the short username of this user. Args: screen_name: the short username of this user ''' self._screen_name = screen_name
[ "def", "SetScreenName", "(", "self", ",", "screen_name", ")", ":", "self", ".", "_screen_name", "=", "screen_name" ]
https://github.com/livid/v2ex-gae/blob/32be3a77d535e7c9df85a333e01ab8834d0e8581/twitter/twitter.py#L553-L559
F8LEFT/DecLLVM
d38e45e3d0dd35634adae1d0cf7f96f3bd96e74c
python/idaapi.py
python
wait_for_next_event
(*args)
return _idaapi.wait_for_next_event(*args)
wait_for_next_event(wfne, timeout_in_secs) -> dbg_event_code_t
wait_for_next_event(wfne, timeout_in_secs) -> dbg_event_code_t
[ "wait_for_next_event", "(", "wfne", "timeout_in_secs", ")", "-", ">", "dbg_event_code_t" ]
def wait_for_next_event(*args): """ wait_for_next_event(wfne, timeout_in_secs) -> dbg_event_code_t """ return _idaapi.wait_for_next_event(*args)
[ "def", "wait_for_next_event", "(", "*", "args", ")", ":", "return", "_idaapi", ".", "wait_for_next_event", "(", "*", "args", ")" ]
https://github.com/F8LEFT/DecLLVM/blob/d38e45e3d0dd35634adae1d0cf7f96f3bd96e74c/python/idaapi.py#L24066-L24070
pwnieexpress/pwn_plug_sources
1a23324f5dc2c3de20f9c810269b6a29b2758cad
src/metagoofil/hachoir_parser/network/tcpdump.py
python
Layer.parseNext
(self, parent)
return None
[]
def parseNext(self, parent): return None
[ "def", "parseNext", "(", "self", ",", "parent", ")", ":", "return", "None" ]
https://github.com/pwnieexpress/pwn_plug_sources/blob/1a23324f5dc2c3de20f9c810269b6a29b2758cad/src/metagoofil/hachoir_parser/network/tcpdump.py#L31-L32