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
emesene/emesene
4548a4098310e21b16437bb36223a7f632a4f7bc
emesene/e3/xmpp/SleekXMPP/sleekxmpp/xmlstream/xmlstream.py
python
XMLStream.del_filter
(self, mode, handler)
Remove an incoming or outgoing filter.
Remove an incoming or outgoing filter.
[ "Remove", "an", "incoming", "or", "outgoing", "filter", "." ]
def del_filter(self, mode, handler): """Remove an incoming or outgoing filter.""" self.__filters[mode].remove(handler)
[ "def", "del_filter", "(", "self", ",", "mode", ",", "handler", ")", ":", "self", ".", "__filters", "[", "mode", "]", ".", "remove", "(", "handler", ")" ]
https://github.com/emesene/emesene/blob/4548a4098310e21b16437bb36223a7f632a4f7bc/emesene/e3/xmpp/SleekXMPP/sleekxmpp/xmlstream/xmlstream.py#L990-L992
pyparallel/pyparallel
11e8c6072d48c8f13641925d17b147bf36ee0ba3
Lib/site-packages/numpy-1.10.0.dev0_046311a-py3.3-win-amd64.egg/numpy/ma/core.py
python
_DomainedBinaryOperation.__call__
(self, a, b, *args, **kwargs)
return result
Execute the call behavior.
Execute the call behavior.
[ "Execute", "the", "call", "behavior", "." ]
def __call__(self, a, b, *args, **kwargs): "Execute the call behavior." # Get the data and the mask (da, db) = (getdata(a, subok=False), getdata(b, subok=False)) (ma, mb) = (getmask(a), getmask(b)) # Get the result with np.errstate(divide='ignore', invalid='ignore'): result = self.f(da, db, *args, **kwargs) # check it worked if result is NotImplemented: return NotImplemented # Get the mask as a combination of ma, mb and invalid m = ~umath.isfinite(result) m |= ma m |= mb # Apply the domain domain = ufunc_domain.get(self.f, None) if domain is not None: m |= filled(domain(da, db), True) # Take care of the scalar case first if (not m.ndim): if m: return masked else: return result # When the mask is True, put back da np.copyto(result, da, casting='unsafe', where=m) result = result.view(get_masked_subclass(a, b)) result._mask = m if isinstance(b, MaskedArray): if isinstance(a, MaskedArray): result._update_from(a) else: result._update_from(b) elif isinstance(a, MaskedArray): result._update_from(a) return result
[ "def", "__call__", "(", "self", ",", "a", ",", "b", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# Get the data and the mask", "(", "da", ",", "db", ")", "=", "(", "getdata", "(", "a", ",", "subok", "=", "False", ")", ",", "getdata", "("...
https://github.com/pyparallel/pyparallel/blob/11e8c6072d48c8f13641925d17b147bf36ee0ba3/Lib/site-packages/numpy-1.10.0.dev0_046311a-py3.3-win-amd64.egg/numpy/ma/core.py#L1075-L1111
GothicAi/Instaboost
b6f80405b8706adad4aca1c1bdbb650b9c1c71e5
mmdetection/mmdet/core/bbox/transforms.py
python
bbox2roi
(bbox_list)
return rois
Convert a list of bboxes to roi format. Args: bbox_list (list[Tensor]): a list of bboxes corresponding to a batch of images. Returns: Tensor: shape (n, 5), [batch_ind, x1, y1, x2, y2]
Convert a list of bboxes to roi format.
[ "Convert", "a", "list", "of", "bboxes", "to", "roi", "format", "." ]
def bbox2roi(bbox_list): """Convert a list of bboxes to roi format. Args: bbox_list (list[Tensor]): a list of bboxes corresponding to a batch of images. Returns: Tensor: shape (n, 5), [batch_ind, x1, y1, x2, y2] """ rois_list = [] for img_id, bboxes in enumerate(bbox_list): if bboxes.size(0) > 0: img_inds = bboxes.new_full((bboxes.size(0), 1), img_id) rois = torch.cat([img_inds, bboxes[:, :4]], dim=-1) else: rois = bboxes.new_zeros((0, 5)) rois_list.append(rois) rois = torch.cat(rois_list, 0) return rois
[ "def", "bbox2roi", "(", "bbox_list", ")", ":", "rois_list", "=", "[", "]", "for", "img_id", ",", "bboxes", "in", "enumerate", "(", "bbox_list", ")", ":", "if", "bboxes", ".", "size", "(", "0", ")", ">", "0", ":", "img_inds", "=", "bboxes", ".", "ne...
https://github.com/GothicAi/Instaboost/blob/b6f80405b8706adad4aca1c1bdbb650b9c1c71e5/mmdetection/mmdet/core/bbox/transforms.py#L106-L125
Chaffelson/nipyapi
d3b186fd701ce308c2812746d98af9120955e810
nipyapi/nifi/models/provenance_event_dto.py
python
ProvenanceEventDTO.event_time
(self)
return self._event_time
Gets the event_time of this ProvenanceEventDTO. The timestamp of the event. :return: The event_time of this ProvenanceEventDTO. :rtype: str
Gets the event_time of this ProvenanceEventDTO. The timestamp of the event.
[ "Gets", "the", "event_time", "of", "this", "ProvenanceEventDTO", ".", "The", "timestamp", "of", "the", "event", "." ]
def event_time(self): """ Gets the event_time of this ProvenanceEventDTO. The timestamp of the event. :return: The event_time of this ProvenanceEventDTO. :rtype: str """ return self._event_time
[ "def", "event_time", "(", "self", ")", ":", "return", "self", ".", "_event_time" ]
https://github.com/Chaffelson/nipyapi/blob/d3b186fd701ce308c2812746d98af9120955e810/nipyapi/nifi/models/provenance_event_dto.py#L298-L306
khanhnamle1994/natural-language-processing
01d450d5ac002b0156ef4cf93a07cb508c1bcdc5
assignment1/.env/lib/python2.7/site-packages/pkg_resources/_vendor/pyparsing.py
python
dictOf
( key, value )
return Dict( ZeroOrMore( Group ( key + value ) ) )
Helper to easily and clearly define a dictionary by specifying the respective patterns for the key and value. Takes care of defining the C{L{Dict}}, C{L{ZeroOrMore}}, and C{L{Group}} tokens in the proper order. The key pattern can include delimiting markers or punctuation, as long as they are suppressed, thereby leaving the significant key text. The value pattern can include named results, so that the C{Dict} results can include named token fields. Example:: text = "shape: SQUARE posn: upper left color: light blue texture: burlap" attr_expr = (label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join)) print(OneOrMore(attr_expr).parseString(text).dump()) attr_label = label attr_value = Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join) # similar to Dict, but simpler call format result = dictOf(attr_label, attr_value).parseString(text) print(result.dump()) print(result['shape']) print(result.shape) # object attribute access works too print(result.asDict()) prints:: [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']] - color: light blue - posn: upper left - shape: SQUARE - texture: burlap SQUARE SQUARE {'color': 'light blue', 'shape': 'SQUARE', 'posn': 'upper left', 'texture': 'burlap'}
Helper to easily and clearly define a dictionary by specifying the respective patterns for the key and value. Takes care of defining the C{L{Dict}}, C{L{ZeroOrMore}}, and C{L{Group}} tokens in the proper order. The key pattern can include delimiting markers or punctuation, as long as they are suppressed, thereby leaving the significant key text. The value pattern can include named results, so that the C{Dict} results can include named token fields.
[ "Helper", "to", "easily", "and", "clearly", "define", "a", "dictionary", "by", "specifying", "the", "respective", "patterns", "for", "the", "key", "and", "value", ".", "Takes", "care", "of", "defining", "the", "C", "{", "L", "{", "Dict", "}}", "C", "{", ...
def dictOf( key, value ): """ Helper to easily and clearly define a dictionary by specifying the respective patterns for the key and value. Takes care of defining the C{L{Dict}}, C{L{ZeroOrMore}}, and C{L{Group}} tokens in the proper order. The key pattern can include delimiting markers or punctuation, as long as they are suppressed, thereby leaving the significant key text. The value pattern can include named results, so that the C{Dict} results can include named token fields. Example:: text = "shape: SQUARE posn: upper left color: light blue texture: burlap" attr_expr = (label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join)) print(OneOrMore(attr_expr).parseString(text).dump()) attr_label = label attr_value = Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join) # similar to Dict, but simpler call format result = dictOf(attr_label, attr_value).parseString(text) print(result.dump()) print(result['shape']) print(result.shape) # object attribute access works too print(result.asDict()) prints:: [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']] - color: light blue - posn: upper left - shape: SQUARE - texture: burlap SQUARE SQUARE {'color': 'light blue', 'shape': 'SQUARE', 'posn': 'upper left', 'texture': 'burlap'} """ return Dict( ZeroOrMore( Group ( key + value ) ) )
[ "def", "dictOf", "(", "key", ",", "value", ")", ":", "return", "Dict", "(", "ZeroOrMore", "(", "Group", "(", "key", "+", "value", ")", ")", ")" ]
https://github.com/khanhnamle1994/natural-language-processing/blob/01d450d5ac002b0156ef4cf93a07cb508c1bcdc5/assignment1/.env/lib/python2.7/site-packages/pkg_resources/_vendor/pyparsing.py#L4605-L4638
gkrizek/bash-lambda-layer
703b0ade8174022d44779d823172ab7ac33a5505
bin/botocore/vendored/requests/api.py
python
options
(url, **kwargs)
return request('options', url, **kwargs)
Sends a OPTIONS request. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response <Response>` object :rtype: requests.Response
Sends a OPTIONS request.
[ "Sends", "a", "OPTIONS", "request", "." ]
def options(url, **kwargs): """Sends a OPTIONS request. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response <Response>` object :rtype: requests.Response """ kwargs.setdefault('allow_redirects', True) return request('options', url, **kwargs)
[ "def", "options", "(", "url", ",", "*", "*", "kwargs", ")", ":", "kwargs", ".", "setdefault", "(", "'allow_redirects'", ",", "True", ")", "return", "request", "(", "'options'", ",", "url", ",", "*", "*", "kwargs", ")" ]
https://github.com/gkrizek/bash-lambda-layer/blob/703b0ade8174022d44779d823172ab7ac33a5505/bin/botocore/vendored/requests/api.py#L93-L103
deepset-ai/haystack
79fdda8a7cf393d774803608a4874f2a6e63cf6f
haystack/modeling/model/prediction_head.py
python
QuestionAnsweringHead.calibrate_conf
(self, logits, label_all)
Learning a temperature parameter to apply temperature scaling to calibrate confidence scores
Learning a temperature parameter to apply temperature scaling to calibrate confidence scores
[ "Learning", "a", "temperature", "parameter", "to", "apply", "temperature", "scaling", "to", "calibrate", "confidence", "scores" ]
def calibrate_conf(self, logits, label_all): """ Learning a temperature parameter to apply temperature scaling to calibrate confidence scores """ logits = torch.cat(logits, dim=0) # To handle no_answer labels correctly (-1,-1), we set their start_position to 0. The logit at index 0 also refers to no_answer # TODO some language models do not have the CLS token at position 0. For these models, we need to map start_position==-1 to the index of CLS token start_position = [label[0][0] if label[0][0] >=0 else 0 for label in label_all] end_position = [label[0][1] if label[0][1] >=0 else 0 for label in label_all] start_logits, end_logits = logits.split(1, dim=-1) start_logits = start_logits.squeeze(-1) end_logits = end_logits.squeeze(-1) start_position = torch.tensor(start_position) if len(start_position.size()) > 1: start_position = start_position.squeeze(-1) end_position = torch.tensor(end_position) if len(end_position.size()) > 1: end_position = end_position.squeeze(-1) ignored_index = start_logits.size(1)-1 start_position.clamp_(0, ignored_index) end_position.clamp_(0, ignored_index) nll_criterion = CrossEntropyLoss() optimizer = optim.LBFGS([self.temperature_for_confidence], lr=0.01, max_iter=50) def eval_start_end_logits(): loss = nll_criterion(self.temperature_scale(start_logits), start_position.to(device=start_logits.device))+\ nll_criterion(self.temperature_scale(end_logits), end_position.to(device=end_logits.device)) loss.backward() return loss optimizer.step(eval_start_end_logits)
[ "def", "calibrate_conf", "(", "self", ",", "logits", ",", "label_all", ")", ":", "logits", "=", "torch", ".", "cat", "(", "logits", ",", "dim", "=", "0", ")", "# To handle no_answer labels correctly (-1,-1), we set their start_position to 0. The logit at index 0 also refe...
https://github.com/deepset-ai/haystack/blob/79fdda8a7cf393d774803608a4874f2a6e63cf6f/haystack/modeling/model/prediction_head.py#L363-L399
danecjensen/subscribely
4d6ac60358b5fe26f0c01be68f1ba063df3b1ea0
src/flask/wrappers.py
python
Request.endpoint
(self)
The endpoint that matched the request. This in combination with :attr:`view_args` can be used to reconstruct the same or a modified URL. If an exception happened when matching, this will be `None`.
The endpoint that matched the request. This in combination with :attr:`view_args` can be used to reconstruct the same or a modified URL. If an exception happened when matching, this will be `None`.
[ "The", "endpoint", "that", "matched", "the", "request", ".", "This", "in", "combination", "with", ":", "attr", ":", "view_args", "can", "be", "used", "to", "reconstruct", "the", "same", "or", "a", "modified", "URL", ".", "If", "an", "exception", "happened"...
def endpoint(self): """The endpoint that matched the request. This in combination with :attr:`view_args` can be used to reconstruct the same or a modified URL. If an exception happened when matching, this will be `None`. """ if self.url_rule is not None: return self.url_rule.endpoint
[ "def", "endpoint", "(", "self", ")", ":", "if", "self", ".", "url_rule", "is", "not", "None", ":", "return", "self", ".", "url_rule", ".", "endpoint" ]
https://github.com/danecjensen/subscribely/blob/4d6ac60358b5fe26f0c01be68f1ba063df3b1ea0/src/flask/wrappers.py#L63-L70
scipy/scipy
e0a749f01e79046642ccfdc419edbf9e7ca141ad
scipy/io/_harwell_boeing/hb.py
python
HBInfo.__init__
(self, title, key, total_nlines, pointer_nlines, indices_nlines, values_nlines, mxtype, nrows, ncols, nnon_zeros, pointer_format_str, indices_format_str, values_format_str, right_hand_sides_nlines=0, nelementals=0)
Do not use this directly, but the class ctrs (from_* functions).
Do not use this directly, but the class ctrs (from_* functions).
[ "Do", "not", "use", "this", "directly", "but", "the", "class", "ctrs", "(", "from_", "*", "functions", ")", "." ]
def __init__(self, title, key, total_nlines, pointer_nlines, indices_nlines, values_nlines, mxtype, nrows, ncols, nnon_zeros, pointer_format_str, indices_format_str, values_format_str, right_hand_sides_nlines=0, nelementals=0): """Do not use this directly, but the class ctrs (from_* functions).""" self.title = title self.key = key if title is None: title = "No Title" if len(title) > 72: raise ValueError("title cannot be > 72 characters") if key is None: key = "|No Key" if len(key) > 8: warnings.warn("key is > 8 characters (key is %s)" % key, LineOverflow) self.total_nlines = total_nlines self.pointer_nlines = pointer_nlines self.indices_nlines = indices_nlines self.values_nlines = values_nlines parser = FortranFormatParser() pointer_format = parser.parse(pointer_format_str) if not isinstance(pointer_format, IntFormat): raise ValueError("Expected int format for pointer format, got %s" % pointer_format) indices_format = parser.parse(indices_format_str) if not isinstance(indices_format, IntFormat): raise ValueError("Expected int format for indices format, got %s" % indices_format) values_format = parser.parse(values_format_str) if isinstance(values_format, ExpFormat): if mxtype.value_type not in ["real", "complex"]: raise ValueError("Inconsistency between matrix type %s and " "value type %s" % (mxtype, values_format)) values_dtype = np.float64 elif isinstance(values_format, IntFormat): if mxtype.value_type not in ["integer"]: raise ValueError("Inconsistency between matrix type %s and " "value type %s" % (mxtype, values_format)) # XXX: fortran int -> dtype association ? values_dtype = int else: raise ValueError("Unsupported format for values %r" % (values_format,)) self.pointer_format = pointer_format self.indices_format = indices_format self.values_format = values_format self.pointer_dtype = np.int32 self.indices_dtype = np.int32 self.values_dtype = values_dtype self.pointer_nlines = pointer_nlines self.pointer_nbytes_full = _nbytes_full(pointer_format, pointer_nlines) self.indices_nlines = indices_nlines self.indices_nbytes_full = _nbytes_full(indices_format, indices_nlines) self.values_nlines = values_nlines self.values_nbytes_full = _nbytes_full(values_format, values_nlines) self.nrows = nrows self.ncols = ncols self.nnon_zeros = nnon_zeros self.nelementals = nelementals self.mxtype = mxtype
[ "def", "__init__", "(", "self", ",", "title", ",", "key", ",", "total_nlines", ",", "pointer_nlines", ",", "indices_nlines", ",", "values_nlines", ",", "mxtype", ",", "nrows", ",", "ncols", ",", "nnon_zeros", ",", "pointer_format_str", ",", "indices_format_str",...
https://github.com/scipy/scipy/blob/e0a749f01e79046642ccfdc419edbf9e7ca141ad/scipy/io/_harwell_boeing/hb.py#L208-L278
Garvit244/Leetcode
a1d31ff0f9f251f3dd0bee5cc8b191b7ebbccc29
1000-1100q/1081.py
python
Solution.smallestSubsequence
(self, text)
return result
:type text: str :rtype: str
:type text: str :rtype: str
[ ":", "type", "text", ":", "str", ":", "rtype", ":", "str" ]
def smallestSubsequence(self, text): """ :type text: str :rtype: str """ if not text: return '' import collections freq_map = collections.Counter(text) used = [False]*26 result = '' for char in text: freq_map[char] -= 1 if used[ord(char)-97]: continue while (result and result[-1] > char and freq_map[result[-1]] > 0): used[ord(result[-1])-97] = False result = result[:-1] used[ord(char)-97] = True result += char return result
[ "def", "smallestSubsequence", "(", "self", ",", "text", ")", ":", "if", "not", "text", ":", "return", "''", "import", "collections", "freq_map", "=", "collections", ".", "Counter", "(", "text", ")", "used", "=", "[", "False", "]", "*", "26", "result", ...
https://github.com/Garvit244/Leetcode/blob/a1d31ff0f9f251f3dd0bee5cc8b191b7ebbccc29/1000-1100q/1081.py#L29-L51
ApostropheEditor/Apostrophe
cc30858c15f3408296d73202497d3cdef5a46064
apostrophe/export_dialog.py
python
ExportDialog.__init__
(self, file, _format, text)
[]
def __init__(self, file, _format, text): self.format = _format self.text = text self._show_texlive_warning = (self.format == "pdf" and not helpers.exist_executable("pdftex")) if (self._show_texlive_warning): self.dialog = Gtk.MessageDialog( None, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE ) self.dialog.get_message_area().add(TexliveWarning()) else: self.dialog = Gtk.FileChooserNative.new( _("Export"), None, Gtk.FileChooserAction.SAVE, _("Export to %s") % self.formats[self.format]["name"], _("Cancel")) dialog_filter = Gtk.FileFilter.new() dialog_filter.set_name(self.formats[self.format]["name"]) dialog_filter.add_mime_type(self.formats[self.format]["mimetype"]) self.dialog.add_filter(dialog_filter) self.dialog.set_do_overwrite_confirmation(True) self.dialog.set_current_name( file.name + '.' + self.formats[self.format]["extension"])
[ "def", "__init__", "(", "self", ",", "file", ",", "_format", ",", "text", ")", ":", "self", ".", "format", "=", "_format", "self", ".", "text", "=", "text", "self", ".", "_show_texlive_warning", "=", "(", "self", ".", "format", "==", "\"pdf\"", "and", ...
https://github.com/ApostropheEditor/Apostrophe/blob/cc30858c15f3408296d73202497d3cdef5a46064/apostrophe/export_dialog.py#L108-L142
mcfletch/pyopengl
02d11dad9ff18e50db10e975c4756e17bf198464
OpenGL/GLU/tess.py
python
GLUtesselator.vertexWrapper
( self, function )
return wrap
Converts a vertex-pointer into an OOR vertex for processing
Converts a vertex-pointer into an OOR vertex for processing
[ "Converts", "a", "vertex", "-", "pointer", "into", "an", "OOR", "vertex", "for", "processing" ]
def vertexWrapper( self, function ): """Converts a vertex-pointer into an OOR vertex for processing""" if (function is not None) and (not hasattr( function,'__call__' )): raise TypeError( """Require a callable callback, got: %s"""%(function,)) def wrap( vertex, data=None ): """Just return the original object for polygon_data""" vertex = self.originalObject(vertex) try: if data is not None: data = self.originalObject(data) return function( vertex, data ) else: return function( vertex ) except Exception as err: err.args += (function,(vertex,data)) raise return wrap
[ "def", "vertexWrapper", "(", "self", ",", "function", ")", ":", "if", "(", "function", "is", "not", "None", ")", "and", "(", "not", "hasattr", "(", "function", ",", "'__call__'", ")", ")", ":", "raise", "TypeError", "(", "\"\"\"Require a callable callback, g...
https://github.com/mcfletch/pyopengl/blob/02d11dad9ff18e50db10e975c4756e17bf198464/OpenGL/GLU/tess.py#L148-L164
LuxCoreRender/BlendLuxCore
bf31ca58501d54c02acd97001b6db7de81da7cbf
ui/world.py
python
register
()
[]
def register(): for panel in compatible_panels(): panel.COMPAT_ENGINES.add("LUXCORE")
[ "def", "register", "(", ")", ":", "for", "panel", "in", "compatible_panels", "(", ")", ":", "panel", ".", "COMPAT_ENGINES", ".", "add", "(", "\"LUXCORE\"", ")" ]
https://github.com/LuxCoreRender/BlendLuxCore/blob/bf31ca58501d54c02acd97001b6db7de81da7cbf/ui/world.py#L283-L285
beeware/ouroboros
a29123c6fab6a807caffbb7587cf548e0c370296
ouroboros/decimal.py
python
Context.remainder
(self, a, b)
Returns the remainder from integer division. The result is the residue of the dividend after the operation of calculating integer division as described for divide-integer, rounded to precision digits if necessary. The sign of the result, if non-zero, is the same as that of the original dividend. This operation will fail under the same conditions as integer division (that is, if integer division on the same two operands would fail, the remainder cannot be calculated). >>> ExtendedContext.remainder(Decimal('2.1'), Decimal('3')) Decimal('2.1') >>> ExtendedContext.remainder(Decimal('10'), Decimal('3')) Decimal('1') >>> ExtendedContext.remainder(Decimal('-10'), Decimal('3')) Decimal('-1') >>> ExtendedContext.remainder(Decimal('10.2'), Decimal('1')) Decimal('0.2') >>> ExtendedContext.remainder(Decimal('10'), Decimal('0.3')) Decimal('0.1') >>> ExtendedContext.remainder(Decimal('3.6'), Decimal('1.3')) Decimal('1.0') >>> ExtendedContext.remainder(22, 6) Decimal('4') >>> ExtendedContext.remainder(Decimal(22), 6) Decimal('4') >>> ExtendedContext.remainder(22, Decimal(6)) Decimal('4')
Returns the remainder from integer division.
[ "Returns", "the", "remainder", "from", "integer", "division", "." ]
def remainder(self, a, b): """Returns the remainder from integer division. The result is the residue of the dividend after the operation of calculating integer division as described for divide-integer, rounded to precision digits if necessary. The sign of the result, if non-zero, is the same as that of the original dividend. This operation will fail under the same conditions as integer division (that is, if integer division on the same two operands would fail, the remainder cannot be calculated). >>> ExtendedContext.remainder(Decimal('2.1'), Decimal('3')) Decimal('2.1') >>> ExtendedContext.remainder(Decimal('10'), Decimal('3')) Decimal('1') >>> ExtendedContext.remainder(Decimal('-10'), Decimal('3')) Decimal('-1') >>> ExtendedContext.remainder(Decimal('10.2'), Decimal('1')) Decimal('0.2') >>> ExtendedContext.remainder(Decimal('10'), Decimal('0.3')) Decimal('0.1') >>> ExtendedContext.remainder(Decimal('3.6'), Decimal('1.3')) Decimal('1.0') >>> ExtendedContext.remainder(22, 6) Decimal('4') >>> ExtendedContext.remainder(Decimal(22), 6) Decimal('4') >>> ExtendedContext.remainder(22, Decimal(6)) Decimal('4') """ a = _convert_other(a, raiseit=True) r = a.__mod__(b, context=self) if r is NotImplemented: raise TypeError("Unable to convert %s to Decimal" % b) else: return r
[ "def", "remainder", "(", "self", ",", "a", ",", "b", ")", ":", "a", "=", "_convert_other", "(", "a", ",", "raiseit", "=", "True", ")", "r", "=", "a", ".", "__mod__", "(", "b", ",", "context", "=", "self", ")", "if", "r", "is", "NotImplemented", ...
https://github.com/beeware/ouroboros/blob/a29123c6fab6a807caffbb7587cf548e0c370296/ouroboros/decimal.py#L5292-L5328
tp4a/teleport
1fafd34f1f775d2cf80ea4af6e44468d8e0b24ad
server/www/packages/packages-linux/x64/cryptography/hazmat/bindings/openssl/_conditional.py
python
cryptography_has_ed448
()
return [ "EVP_PKEY_ED448", "NID_ED448", ]
[]
def cryptography_has_ed448(): return [ "EVP_PKEY_ED448", "NID_ED448", ]
[ "def", "cryptography_has_ed448", "(", ")", ":", "return", "[", "\"EVP_PKEY_ED448\"", ",", "\"NID_ED448\"", ",", "]" ]
https://github.com/tp4a/teleport/blob/1fafd34f1f775d2cf80ea4af6e44468d8e0b24ad/server/www/packages/packages-linux/x64/cryptography/hazmat/bindings/openssl/_conditional.py#L230-L234
wwqgtxx/wwqLyParse
33136508e52821babd9294fdecffbdf02d73a6fc
wwqLyParse/lib/python-3.7.2-embed-amd64/Crypto/Signature/pss.py
python
PSS_SigScheme.__init__
(self, key, mgfunc, saltLen, randfunc)
Initialize this PKCS#1 PSS signature scheme object. :Parameters: key : an RSA key object If a private half is given, both signature and verification are possible. If a public half is given, only verification is possible. mgfunc : callable A mask generation function that accepts two parameters: a string to use as seed, and the lenth of the mask to generate, in bytes. saltLen : integer Length of the salt, in bytes. randfunc : callable A function that returns random bytes.
Initialize this PKCS#1 PSS signature scheme object.
[ "Initialize", "this", "PKCS#1", "PSS", "signature", "scheme", "object", "." ]
def __init__(self, key, mgfunc, saltLen, randfunc): """Initialize this PKCS#1 PSS signature scheme object. :Parameters: key : an RSA key object If a private half is given, both signature and verification are possible. If a public half is given, only verification is possible. mgfunc : callable A mask generation function that accepts two parameters: a string to use as seed, and the lenth of the mask to generate, in bytes. saltLen : integer Length of the salt, in bytes. randfunc : callable A function that returns random bytes. """ self._key = key self._saltLen = saltLen self._mgfunc = mgfunc self._randfunc = randfunc
[ "def", "__init__", "(", "self", ",", "key", ",", "mgfunc", ",", "saltLen", ",", "randfunc", ")", ":", "self", ".", "_key", "=", "key", "self", ".", "_saltLen", "=", "saltLen", "self", ".", "_mgfunc", "=", "mgfunc", "self", ".", "_randfunc", "=", "ran...
https://github.com/wwqgtxx/wwqLyParse/blob/33136508e52821babd9294fdecffbdf02d73a6fc/wwqLyParse/lib/python-3.7.2-embed-amd64/Crypto/Signature/pss.py#L47-L68
Tautulli/Tautulli
2410eb33805aaac4bd1c5dad0f71e4f15afaf742
lib/bs4/builder/__init__.py
python
TreeBuilder.prepare_markup
(self, markup, user_specified_encoding=None, document_declared_encoding=None, exclude_encodings=None)
Run any preliminary steps necessary to make incoming markup acceptable to the parser. :param markup: Some markup -- probably a bytestring. :param user_specified_encoding: The user asked to try this encoding. :param document_declared_encoding: The markup itself claims to be in this encoding. NOTE: This argument is not used by the calling code and can probably be removed. :param exclude_encodings: The user asked _not_ to try any of these encodings. :yield: A series of 4-tuples: (markup, encoding, declared encoding, has undergone character replacement) Each 4-tuple represents a strategy for converting the document to Unicode and parsing it. Each strategy will be tried in turn. By default, the only strategy is to parse the markup as-is. See `LXMLTreeBuilderForXML` and `HTMLParserTreeBuilder` for implementations that take into account the quirks of particular parsers.
Run any preliminary steps necessary to make incoming markup acceptable to the parser.
[ "Run", "any", "preliminary", "steps", "necessary", "to", "make", "incoming", "markup", "acceptable", "to", "the", "parser", "." ]
def prepare_markup(self, markup, user_specified_encoding=None, document_declared_encoding=None, exclude_encodings=None): """Run any preliminary steps necessary to make incoming markup acceptable to the parser. :param markup: Some markup -- probably a bytestring. :param user_specified_encoding: The user asked to try this encoding. :param document_declared_encoding: The markup itself claims to be in this encoding. NOTE: This argument is not used by the calling code and can probably be removed. :param exclude_encodings: The user asked _not_ to try any of these encodings. :yield: A series of 4-tuples: (markup, encoding, declared encoding, has undergone character replacement) Each 4-tuple represents a strategy for converting the document to Unicode and parsing it. Each strategy will be tried in turn. By default, the only strategy is to parse the markup as-is. See `LXMLTreeBuilderForXML` and `HTMLParserTreeBuilder` for implementations that take into account the quirks of particular parsers. """ yield markup, None, None, False
[ "def", "prepare_markup", "(", "self", ",", "markup", ",", "user_specified_encoding", "=", "None", ",", "document_declared_encoding", "=", "None", ",", "exclude_encodings", "=", "None", ")", ":", "yield", "markup", ",", "None", ",", "None", ",", "False" ]
https://github.com/Tautulli/Tautulli/blob/2410eb33805aaac4bd1c5dad0f71e4f15afaf742/lib/bs4/builder/__init__.py#L229-L255
gramps-project/gramps
04d4651a43eb210192f40a9f8c2bad8ee8fa3753
gramps/gen/proxy/proxybase.py
python
ProxyDbBase.get_person_handles
(self, sort_handles=False, locale=glocale)
Return a list of database handles, one handle for each Person in the database. If sort_handles is True, the list is sorted by surnames
Return a list of database handles, one handle for each Person in the database. If sort_handles is True, the list is sorted by surnames
[ "Return", "a", "list", "of", "database", "handles", "one", "handle", "for", "each", "Person", "in", "the", "database", ".", "If", "sort_handles", "is", "True", "the", "list", "is", "sorted", "by", "surnames" ]
def get_person_handles(self, sort_handles=False, locale=glocale): """ Return a list of database handles, one handle for each Person in the database. If sort_handles is True, the list is sorted by surnames """ if (self.db is not None) and self.db.is_open(): proxied = set(self.iter_person_handles()) all = self.basedb.get_person_handles(sort_handles=sort_handles, locale=locale) return [hdl for hdl in all if hdl in proxied] else: return []
[ "def", "get_person_handles", "(", "self", ",", "sort_handles", "=", "False", ",", "locale", "=", "glocale", ")", ":", "if", "(", "self", ".", "db", "is", "not", "None", ")", "and", "self", ".", "db", ".", "is_open", "(", ")", ":", "proxied", "=", "...
https://github.com/gramps-project/gramps/blob/04d4651a43eb210192f40a9f8c2bad8ee8fa3753/gramps/gen/proxy/proxybase.py#L203-L214
jaychsu/algorithm
87dac5456b74a515dd97507ac68e9b8588066a04
leetcode/643_maximum_average_subarray_i.py
python
Solution.findMaxAverage
(self, nums, k)
return max_sum / float(k)
:type nums: List[int] :type k: int :rtype: float
:type nums: List[int] :type k: int :rtype: float
[ ":", "type", "nums", ":", "List", "[", "int", "]", ":", "type", "k", ":", "int", ":", "rtype", ":", "float" ]
def findMaxAverage(self, nums, k): """ :type nums: List[int] :type k: int :rtype: float """ """ Assuming k = 3 i: 0 1 2 3 |--> Start to find max sum |--> Start to remove past child """ max_sum, tmp_sum = float('-inf'), 0 for i in range(len(nums)): tmp_sum += nums[i] if i >= k: tmp_sum -= nums[i-k] if i + 1 >= k: max_sum = max(max_sum, tmp_sum) return max_sum / float(k)
[ "def", "findMaxAverage", "(", "self", ",", "nums", ",", "k", ")", ":", "\"\"\"\n Assuming k = 3\n i: 0 1 2 3\n |--> Start to find max sum\n |--> Start to remove past child\n \"\"\"", "max_sum", ",", "tmp_sum", "=", "float", "(", "'-i...
https://github.com/jaychsu/algorithm/blob/87dac5456b74a515dd97507ac68e9b8588066a04/leetcode/643_maximum_average_subarray_i.py#L27-L46
jackschultz/jbc
dbea920d49f9bcff1fa21be6b425ca88e46490e9
chain.py
python
Chain.self_save
(self)
return True
We want to save this in the file system as we do.
We want to save this in the file system as we do.
[ "We", "want", "to", "save", "this", "in", "the", "file", "system", "as", "we", "do", "." ]
def self_save(self): ''' We want to save this in the file system as we do. ''' for b in self.blocks: b.self_save() return True
[ "def", "self_save", "(", "self", ")", ":", "for", "b", "in", "self", ".", "blocks", ":", "b", ".", "self_save", "(", ")", "return", "True" ]
https://github.com/jackschultz/jbc/blob/dbea920d49f9bcff1fa21be6b425ca88e46490e9/chain.py#L31-L37
Alfanous-team/alfanous
594514729473c24efa3908e3107b45a38255de4b
src/alfanous/Support/whoosh/fields.py
python
FieldType.clean
(self)
Clears any cached information in the field and any child objects.
Clears any cached information in the field and any child objects.
[ "Clears", "any", "cached", "information", "in", "the", "field", "and", "any", "child", "objects", "." ]
def clean(self): """Clears any cached information in the field and any child objects. """ if self.format and hasattr(self.format, "clean"): self.format.clean() if self.vector and hasattr(self.vector, "clean"): self.vector.clean()
[ "def", "clean", "(", "self", ")", ":", "if", "self", ".", "format", "and", "hasattr", "(", "self", ".", "format", ",", "\"clean\"", ")", ":", "self", ".", "format", ".", "clean", "(", ")", "if", "self", ".", "vector", "and", "hasattr", "(", "self",...
https://github.com/Alfanous-team/alfanous/blob/594514729473c24efa3908e3107b45a38255de4b/src/alfanous/Support/whoosh/fields.py#L94-L101
redhat-cop/casl-ansible
51ad6830df8657f4839a04cb7be3a65364c6cb8b
inventory/sample.gcp.example.com.d/inventory/gce.py
python
GceInventory.parse_env_zones
(self)
return [z for z in zones[0]]
returns a list of comma separated zones parsed from the GCE_ZONE environment variable. If provided, this will be used to filter the results of the grouped_instances call
returns a list of comma separated zones parsed from the GCE_ZONE environment variable. If provided, this will be used to filter the results of the grouped_instances call
[ "returns", "a", "list", "of", "comma", "separated", "zones", "parsed", "from", "the", "GCE_ZONE", "environment", "variable", ".", "If", "provided", "this", "will", "be", "used", "to", "filter", "the", "results", "of", "the", "grouped_instances", "call" ]
def parse_env_zones(self): '''returns a list of comma separated zones parsed from the GCE_ZONE environment variable. If provided, this will be used to filter the results of the grouped_instances call''' import csv reader = csv.reader([os.environ.get('GCE_ZONE', "")], skipinitialspace=True) zones = [r for r in reader] return [z for z in zones[0]]
[ "def", "parse_env_zones", "(", "self", ")", ":", "import", "csv", "reader", "=", "csv", ".", "reader", "(", "[", "os", ".", "environ", ".", "get", "(", "'GCE_ZONE'", ",", "\"\"", ")", "]", ",", "skipinitialspace", "=", "True", ")", "zones", "=", "[",...
https://github.com/redhat-cop/casl-ansible/blob/51ad6830df8657f4839a04cb7be3a65364c6cb8b/inventory/sample.gcp.example.com.d/inventory/gce.py#L324-L330
osmr/imgclsmob
f2993d3ce73a2f7ddba05da3891defb08547d504
gluon/gluoncv2/models/sepreresnet.py
python
sepreresnetbc26b
(**kwargs)
return get_sepreresnet(blocks=26, bottleneck=True, conv1_stride=False, model_name="sepreresnetbc26b", **kwargs)
SE-PreResNet-BC-26b model from 'Squeeze-and-Excitation Networks,' https://arxiv.org/abs/1709.01507. Parameters: ---------- pretrained : bool, default False Whether to load the pretrained weights for model. ctx : Context, default CPU The context in which to load the pretrained weights. root : str, default '~/.mxnet/models' Location for keeping the model parameters.
SE-PreResNet-BC-26b model from 'Squeeze-and-Excitation Networks,' https://arxiv.org/abs/1709.01507.
[ "SE", "-", "PreResNet", "-", "BC", "-", "26b", "model", "from", "Squeeze", "-", "and", "-", "Excitation", "Networks", "https", ":", "//", "arxiv", ".", "org", "/", "abs", "/", "1709", ".", "01507", "." ]
def sepreresnetbc26b(**kwargs): """ SE-PreResNet-BC-26b model from 'Squeeze-and-Excitation Networks,' https://arxiv.org/abs/1709.01507. Parameters: ---------- pretrained : bool, default False Whether to load the pretrained weights for model. ctx : Context, default CPU The context in which to load the pretrained weights. root : str, default '~/.mxnet/models' Location for keeping the model parameters. """ return get_sepreresnet(blocks=26, bottleneck=True, conv1_stride=False, model_name="sepreresnetbc26b", **kwargs)
[ "def", "sepreresnetbc26b", "(", "*", "*", "kwargs", ")", ":", "return", "get_sepreresnet", "(", "blocks", "=", "26", ",", "bottleneck", "=", "True", ",", "conv1_stride", "=", "False", ",", "model_name", "=", "\"sepreresnetbc26b\"", ",", "*", "*", "kwargs", ...
https://github.com/osmr/imgclsmob/blob/f2993d3ce73a2f7ddba05da3891defb08547d504/gluon/gluoncv2/models/sepreresnet.py#L351-L364
pyqteval/evlal_win
ce7fc77ac5cdf864cd6aa9b04b5329501f8f4c92
Clicked_Controller/requests/packages/urllib3/packages/ordered_dict.py
python
OrderedDict.items
(self)
return [(key, self[key]) for key in self]
od.items() -> list of (key, value) pairs in od
od.items() -> list of (key, value) pairs in od
[ "od", ".", "items", "()", "-", ">", "list", "of", "(", "key", "value", ")", "pairs", "in", "od" ]
def items(self): 'od.items() -> list of (key, value) pairs in od' return [(key, self[key]) for key in self]
[ "def", "items", "(", "self", ")", ":", "return", "[", "(", "key", ",", "self", "[", "key", "]", ")", "for", "key", "in", "self", "]" ]
https://github.com/pyqteval/evlal_win/blob/ce7fc77ac5cdf864cd6aa9b04b5329501f8f4c92/Clicked_Controller/requests/packages/urllib3/packages/ordered_dict.py#L124-L126
pyGrowler/Growler
5492466d8828115bb04c665917d6aeb4f4323f44
growler/routing.py
python
MiddlewareChain.first
(self)
return self.mw_list[0]
Returns first element in list. Returns: MiddlewareNode: The first middleware in the chain. Raises: IndexError: If the chain is empty
Returns first element in list.
[ "Returns", "first", "element", "in", "list", "." ]
def first(self): """ Returns first element in list. Returns: MiddlewareNode: The first middleware in the chain. Raises: IndexError: If the chain is empty """ return self.mw_list[0]
[ "def", "first", "(", "self", ")", ":", "return", "self", ".", "mw_list", "[", "0", "]" ]
https://github.com/pyGrowler/Growler/blob/5492466d8828115bb04c665917d6aeb4f4323f44/growler/routing.py#L339-L349
davidfoerster/aptsources-cleanup
8ea6b410be2aa7c6fa9382ae25137be71639443d
src/aptsources_cleanup/util/itertools.py
python
_pairs_helper
(iterable, n, *, _mapper=lambda i, it: islice(it, i, None) if i else it )
return map(_mapper, count(), tee(iterable, n))
[]
def _pairs_helper(iterable, n, *, _mapper=lambda i, it: islice(it, i, None) if i else it ): return map(_mapper, count(), tee(iterable, n))
[ "def", "_pairs_helper", "(", "iterable", ",", "n", ",", "*", ",", "_mapper", "=", "lambda", "i", ",", "it", ":", "islice", "(", "it", ",", "i", ",", "None", ")", "if", "i", "else", "it", ")", ":", "return", "map", "(", "_mapper", ",", "count", ...
https://github.com/davidfoerster/aptsources-cleanup/blob/8ea6b410be2aa7c6fa9382ae25137be71639443d/src/aptsources_cleanup/util/itertools.py#L63-L66
securesystemslab/zippy
ff0e84ac99442c2c55fe1d285332cfd4e185e089
zippy/lib-python/3/xmlrpc/server.py
python
SimpleXMLRPCRequestHandler.is_rpc_path_valid
(self)
[]
def is_rpc_path_valid(self): if self.rpc_paths: return self.path in self.rpc_paths else: # If .rpc_paths is empty, just assume all paths are legal return True
[ "def", "is_rpc_path_valid", "(", "self", ")", ":", "if", "self", ".", "rpc_paths", ":", "return", "self", ".", "path", "in", "self", ".", "rpc_paths", "else", ":", "# If .rpc_paths is empty, just assume all paths are legal", "return", "True" ]
https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/lib-python/3/xmlrpc/server.py#L448-L453
Bitmessage/PyBitmessage
97612b049e0453867d6d90aa628f8e7b007b4d85
src/network/announcethread.py
python
AnnounceThread.announceSelf
()
Announce our presence
Announce our presence
[ "Announce", "our", "presence" ]
def announceSelf(): """Announce our presence""" for connection in BMConnectionPool().udpSockets.values(): if not connection.announcing: continue for stream in state.streamsInWhichIAmParticipating: addr = ( stream, Peer( '127.0.0.1', BMConfigParser().safeGetInt( 'bitmessagesettings', 'port')), time.time()) connection.append_write_buf(assemble_addr([addr]))
[ "def", "announceSelf", "(", ")", ":", "for", "connection", "in", "BMConnectionPool", "(", ")", ".", "udpSockets", ".", "values", "(", ")", ":", "if", "not", "connection", ".", "announcing", ":", "continue", "for", "stream", "in", "state", ".", "streamsInWh...
https://github.com/Bitmessage/PyBitmessage/blob/97612b049e0453867d6d90aa628f8e7b007b4d85/src/network/announcethread.py#L30-L43
mozman/ezdxf
59d0fc2ea63f5cf82293428f5931da7e9f9718e9
src/ezdxf/render/arrows.py
python
_Arrows.render_arrow
( self, layout: "GenericLayoutType", name: str, insert: Vertex = NULLVEC, size: float = 1.0, rotation: float = 0, *, dxfattribs = None )
return connection_point( name, insert=insert, scale=size, rotation=rotation )
Render arrow as basic DXF entities into `layout`.
Render arrow as basic DXF entities into `layout`.
[ "Render", "arrow", "as", "basic", "DXF", "entities", "into", "layout", "." ]
def render_arrow( self, layout: "GenericLayoutType", name: str, insert: Vertex = NULLVEC, size: float = 1.0, rotation: float = 0, *, dxfattribs = None ) -> Vec2: """Render arrow as basic DXF entities into `layout`.""" dxfattribs = dict(dxfattribs or {}) arrow = self.arrow_shape(name, insert, size, rotation) arrow.render(layout, dxfattribs) return connection_point( name, insert=insert, scale=size, rotation=rotation )
[ "def", "render_arrow", "(", "self", ",", "layout", ":", "\"GenericLayoutType\"", ",", "name", ":", "str", ",", "insert", ":", "Vertex", "=", "NULLVEC", ",", "size", ":", "float", "=", "1.0", ",", "rotation", ":", "float", "=", "0", ",", "*", ",", "dx...
https://github.com/mozman/ezdxf/blob/59d0fc2ea63f5cf82293428f5931da7e9f9718e9/src/ezdxf/render/arrows.py#L544-L560
makelinux/linux_kernel_map
d65d7f3ded60100b1e5b1d5361f198b50da31e77
srcxray.py
python
call_tree
(node, printed=None, level=0)
prints call tree of a function Ex: start_kernel Obsoleted by doxygen_xml.
prints call tree of a function Ex: start_kernel Obsoleted by doxygen_xml.
[ "prints", "call", "tree", "of", "a", "function", "Ex", ":", "start_kernel", "Obsoleted", "by", "doxygen_xml", "." ]
def call_tree(node, printed=None, level=0): ''' prints call tree of a function Ex: start_kernel Obsoleted by doxygen_xml. ''' if not os.path.isfile('cscope.out'): print("Please run: cscope -Rcbk", file=sys.stderr) return False if printed is None: printed = set() if node in printed: print_limited2(level*'\t' + node + ' ^') return elif level > level_limit - 2: print_limited2(level*'\t' + node + ' ⋮') return '' else: print_limited2(level*'\t' + node) printed.add(node) local_printed = set() for line in popen('cscope -d -L2 "%s"' % (node)): a = line.split()[1] if a in local_printed: continue if a in stop: print_limited2((level + 1)*'\t' + a + (' ^' if a in local_printed else '')) local_printed.add(a) continue if a in ignore: ignored.add(a) if show_ignored: print_limited2((level + 1)*'\t' + '\033[2;30m' + a + (' ^' if a in local_printed else '') + '\033[0m') local_printed.add(a) continue local_printed.add(a) # try: call_tree(a, printed, level + 1)
[ "def", "call_tree", "(", "node", ",", "printed", "=", "None", ",", "level", "=", "0", ")", ":", "if", "not", "os", ".", "path", ".", "isfile", "(", "'cscope.out'", ")", ":", "print", "(", "\"Please run: cscope -Rcbk\"", ",", "file", "=", "sys", ".", ...
https://github.com/makelinux/linux_kernel_map/blob/d65d7f3ded60100b1e5b1d5361f198b50da31e77/srcxray.py#L276-L316
mediacloud/backend
d36b489e4fbe6e44950916a04d9543a1d6cd5df0
apps/common/src/python/mediawords/util/config/common.py
python
RabbitMQConfig.hostname
(self)
return self.__hostname
Hostname.
Hostname.
[ "Hostname", "." ]
def hostname(self) -> str: """Hostname.""" return self.__hostname
[ "def", "hostname", "(", "self", ")", "->", "str", ":", "return", "self", ".", "__hostname" ]
https://github.com/mediacloud/backend/blob/d36b489e4fbe6e44950916a04d9543a1d6cd5df0/apps/common/src/python/mediawords/util/config/common.py#L230-L232
KoreLogicSecurity/mastiff
04d569e4fa59513572e77c74b049cad82f9b0310
mastiff/core.py
python
Mastiff.activate_plugins
(self, single_plugin=None)
Activate all plugins that are in the categories we selected. If single_plugin is given, only activate that plug-in. Note: File Information plug-in is ALWAYS run.
Activate all plugins that are in the categories we selected. If single_plugin is given, only activate that plug-in. Note: File Information plug-in is ALWAYS run.
[ "Activate", "all", "plugins", "that", "are", "in", "the", "categories", "we", "selected", ".", "If", "single_plugin", "is", "given", "only", "activate", "that", "plug", "-", "in", ".", "Note", ":", "File", "Information", "plug", "-", "in", "is", "ALWAYS", ...
def activate_plugins(self, single_plugin=None): """ Activate all plugins that are in the categories we selected. If single_plugin is given, only activate that plug-in. Note: File Information plug-in is ALWAYS run. """ has_prereq = list() for cats in self.cat_list: log = logging.getLogger('Mastiff.Plugins.Activate') log.debug('Activating plugins for category %s.', cats) self.output[self.hashes][cats] = dict() for plugin in self.plugin_manager.getPluginsOfCategory(cats): # check if we are running a single plugin - file information always gets run if single_plugin is not None and single_plugin != plugin.name and plugin.name != 'File Information': continue plugin.plugin_object.set_name(plugin.name) log.debug('Validating plugin "%s"', plugin.name) # if the plugin validates, try to activate it if self.validate(plugin.name, plugin.plugin_object) == True: if plugin.plugin_object.prereq is not None: # this plugin has a pre-req, can't activate yet has_prereq.append([cats, plugin]) else: log.debug('Activating "%s".', plugin.name) self.plugin_manager.activatePluginByName(plugin.name, cats) self.activated_plugins.append(plugin) else: log.debug("Removing plugin %s %s.", plugin.name, cats) self.plugin_manager.deactivatePluginByName(plugin.name, cats) # now try to activate any plug-ins that have pre-reqs flag = True while flag is True: flag = False for plugins in has_prereq: # check to see if the pre-req in in the activated list inact = [p for p in self.activated_plugins if p.name == plugins[1].plugin_object.prereq] if len(inact) > 0: # our pre-req has been activated, we can activate ourself log.debug('Activating "%s". Pre-req fulfilled.', plugins[1].name) self.plugin_manager.activatePluginByName(plugins[1].name, plugins[0]) self.activated_plugins.append(plugins[1]) has_prereq.remove(plugins) flag = True # list out any plugins that were not activated due to missing pre-reqs for plugins in has_prereq: log.debug("Plugin %s not activated due to missing pre-req \"%s.\"" % \ (plugins[1].name, plugins[1].plugin_object.prereq )) # finally activate the output plugins for plugin in self.output_manager.getAllPlugins(): plugin.plugin_object.set_name(plugin.name) log.debug('Activating Output Plug-in "{}"'.format(plugin.name)) self.output_manager.activatePluginByName(plugin.name)
[ "def", "activate_plugins", "(", "self", ",", "single_plugin", "=", "None", ")", ":", "has_prereq", "=", "list", "(", ")", "for", "cats", "in", "self", ".", "cat_list", ":", "log", "=", "logging", ".", "getLogger", "(", "'Mastiff.Plugins.Activate'", ")", "l...
https://github.com/KoreLogicSecurity/mastiff/blob/04d569e4fa59513572e77c74b049cad82f9b0310/mastiff/core.py#L316-L380
httpie/httpie
4c56d894ba9e2bb1c097a3a6067006843ac2944d
httpie/plugins/builtin.py
python
HTTPBearerAuth.__call__
(self, request: requests.PreparedRequest)
return request
[]
def __call__(self, request: requests.PreparedRequest) -> requests.PreparedRequest: request.headers['Authorization'] = f'Bearer {self.token}' return request
[ "def", "__call__", "(", "self", ",", "request", ":", "requests", ".", "PreparedRequest", ")", "->", "requests", ".", "PreparedRequest", ":", "request", ".", "headers", "[", "'Authorization'", "]", "=", "f'Bearer {self.token}'", "return", "request" ]
https://github.com/httpie/httpie/blob/4c56d894ba9e2bb1c097a3a6067006843ac2944d/httpie/plugins/builtin.py#L42-L44
eBay/bayesian-belief-networks
23c3e3ce1c7f99d83efb79f9b7798af2a1537e1c
bayesian/utils.py
python
shrink_matrix
(x)
return x
Remove Nulls
Remove Nulls
[ "Remove", "Nulls" ]
def shrink_matrix(x): '''Remove Nulls''' while True: if len([x for x in m[0] if x is None]) == x.cols: x.pop() x = x.tr() continue return x
[ "def", "shrink_matrix", "(", "x", ")", ":", "while", "True", ":", "if", "len", "(", "[", "x", "for", "x", "in", "m", "[", "0", "]", "if", "x", "is", "None", "]", ")", "==", "x", ".", "cols", ":", "x", ".", "pop", "(", ")", "x", "=", "x", ...
https://github.com/eBay/bayesian-belief-networks/blob/23c3e3ce1c7f99d83efb79f9b7798af2a1537e1c/bayesian/utils.py#L68-L75
onionshare/onionshare
4ab5e0003c83853476ae68b06ba936c8792dc362
desktop/src/onionshare/tab/mode/__init__.py
python
Mode.human_friendly_time
(self, secs)
return result
Returns a human-friendly time delta from given seconds.
Returns a human-friendly time delta from given seconds.
[ "Returns", "a", "human", "-", "friendly", "time", "delta", "from", "given", "seconds", "." ]
def human_friendly_time(self, secs): """ Returns a human-friendly time delta from given seconds. """ days = secs // 86400 hours = (secs - days * 86400) // 3600 minutes = (secs - days * 86400 - hours * 3600) // 60 seconds = secs - days * 86400 - hours * 3600 - minutes * 60 if not seconds: seconds = "0" result = ( (f"{days}{strings._('days_first_letter')}, " if days else "") + (f"{hours}{strings._('hours_first_letter')}, " if hours else "") + (f"{minutes}{strings._('minutes_first_letter')}, " if minutes else "") + f"{seconds}{strings._('seconds_first_letter')}" ) return result
[ "def", "human_friendly_time", "(", "self", ",", "secs", ")", ":", "days", "=", "secs", "//", "86400", "hours", "=", "(", "secs", "-", "days", "*", "86400", ")", "//", "3600", "minutes", "=", "(", "secs", "-", "days", "*", "86400", "-", "hours", "*"...
https://github.com/onionshare/onionshare/blob/4ab5e0003c83853476ae68b06ba936c8792dc362/desktop/src/onionshare/tab/mode/__init__.py#L148-L165
pyqtgraph/pyqtgraph
ac3887abfca4e529aac44f022f8e40556a2587b0
pyqtgraph/functions.py
python
interpolateArray
(data, x, default=0.0, order=1)
return result
N-dimensional interpolation similar to scipy.ndimage.map_coordinates. This function returns linearly-interpolated values sampled from a regular grid of data. It differs from `ndimage.map_coordinates` by allowing broadcasting within the input array. ============== =========================================================================================== **Arguments:** *data* Array of any shape containing the values to be interpolated. *x* Array with (shape[-1] <= data.ndim) containing the locations within *data* to interpolate. (note: the axes for this argument are transposed relative to the same argument for `ndimage.map_coordinates`). *default* Value to return for locations in *x* that are outside the bounds of *data*. *order* Order of interpolation: 0=nearest, 1=linear. ============== =========================================================================================== Returns array of shape (x.shape[:-1] + data.shape[x.shape[-1]:]) For example, assume we have the following 2D image data:: >>> data = np.array([[1, 2, 4 ], [10, 20, 40 ], [100, 200, 400]]) To compute a single interpolated point from this data:: >>> x = np.array([(0.5, 0.5)]) >>> interpolateArray(data, x) array([ 8.25]) To compute a 1D list of interpolated locations:: >>> x = np.array([(0.5, 0.5), (1.0, 1.0), (1.0, 2.0), (1.5, 0.0)]) >>> interpolateArray(data, x) array([ 8.25, 20. , 40. , 55. ]) To compute a 2D array of interpolated locations:: >>> x = np.array([[(0.5, 0.5), (1.0, 2.0)], [(1.0, 1.0), (1.5, 0.0)]]) >>> interpolateArray(data, x) array([[ 8.25, 40. ], [ 20. , 55. ]]) ..and so on. The *x* argument may have any shape as long as ```x.shape[-1] <= data.ndim```. In the case that ```x.shape[-1] < data.ndim```, then the remaining axes are simply broadcasted as usual. For example, we can interpolate one location from an entire row of the data:: >>> x = np.array([[0.5]]) >>> interpolateArray(data, x) array([[ 5.5, 11. , 22. ]]) This is useful for interpolating from arrays of colors, vertexes, etc.
N-dimensional interpolation similar to scipy.ndimage.map_coordinates. This function returns linearly-interpolated values sampled from a regular grid of data. It differs from `ndimage.map_coordinates` by allowing broadcasting within the input array. ============== =========================================================================================== **Arguments:** *data* Array of any shape containing the values to be interpolated. *x* Array with (shape[-1] <= data.ndim) containing the locations within *data* to interpolate. (note: the axes for this argument are transposed relative to the same argument for `ndimage.map_coordinates`). *default* Value to return for locations in *x* that are outside the bounds of *data*. *order* Order of interpolation: 0=nearest, 1=linear. ============== =========================================================================================== Returns array of shape (x.shape[:-1] + data.shape[x.shape[-1]:]) For example, assume we have the following 2D image data:: >>> data = np.array([[1, 2, 4 ], [10, 20, 40 ], [100, 200, 400]]) To compute a single interpolated point from this data:: >>> x = np.array([(0.5, 0.5)]) >>> interpolateArray(data, x) array([ 8.25]) To compute a 1D list of interpolated locations:: >>> x = np.array([(0.5, 0.5), (1.0, 1.0), (1.0, 2.0), (1.5, 0.0)]) >>> interpolateArray(data, x) array([ 8.25, 20. , 40. , 55. ]) To compute a 2D array of interpolated locations:: >>> x = np.array([[(0.5, 0.5), (1.0, 2.0)], [(1.0, 1.0), (1.5, 0.0)]]) >>> interpolateArray(data, x) array([[ 8.25, 40. ], [ 20. , 55. ]]) ..and so on. The *x* argument may have any shape as long as ```x.shape[-1] <= data.ndim```. In the case that ```x.shape[-1] < data.ndim```, then the remaining axes are simply broadcasted as usual. For example, we can interpolate one location from an entire row of the data:: >>> x = np.array([[0.5]]) >>> interpolateArray(data, x) array([[ 5.5, 11. , 22. ]])
[ "N", "-", "dimensional", "interpolation", "similar", "to", "scipy", ".", "ndimage", ".", "map_coordinates", ".", "This", "function", "returns", "linearly", "-", "interpolated", "values", "sampled", "from", "a", "regular", "grid", "of", "data", ".", "It", "diff...
def interpolateArray(data, x, default=0.0, order=1): """ N-dimensional interpolation similar to scipy.ndimage.map_coordinates. This function returns linearly-interpolated values sampled from a regular grid of data. It differs from `ndimage.map_coordinates` by allowing broadcasting within the input array. ============== =========================================================================================== **Arguments:** *data* Array of any shape containing the values to be interpolated. *x* Array with (shape[-1] <= data.ndim) containing the locations within *data* to interpolate. (note: the axes for this argument are transposed relative to the same argument for `ndimage.map_coordinates`). *default* Value to return for locations in *x* that are outside the bounds of *data*. *order* Order of interpolation: 0=nearest, 1=linear. ============== =========================================================================================== Returns array of shape (x.shape[:-1] + data.shape[x.shape[-1]:]) For example, assume we have the following 2D image data:: >>> data = np.array([[1, 2, 4 ], [10, 20, 40 ], [100, 200, 400]]) To compute a single interpolated point from this data:: >>> x = np.array([(0.5, 0.5)]) >>> interpolateArray(data, x) array([ 8.25]) To compute a 1D list of interpolated locations:: >>> x = np.array([(0.5, 0.5), (1.0, 1.0), (1.0, 2.0), (1.5, 0.0)]) >>> interpolateArray(data, x) array([ 8.25, 20. , 40. , 55. ]) To compute a 2D array of interpolated locations:: >>> x = np.array([[(0.5, 0.5), (1.0, 2.0)], [(1.0, 1.0), (1.5, 0.0)]]) >>> interpolateArray(data, x) array([[ 8.25, 40. ], [ 20. , 55. ]]) ..and so on. The *x* argument may have any shape as long as ```x.shape[-1] <= data.ndim```. In the case that ```x.shape[-1] < data.ndim```, then the remaining axes are simply broadcasted as usual. For example, we can interpolate one location from an entire row of the data:: >>> x = np.array([[0.5]]) >>> interpolateArray(data, x) array([[ 5.5, 11. , 22. ]]) This is useful for interpolating from arrays of colors, vertexes, etc. """ if order not in (0, 1): raise ValueError("interpolateArray requires order=0 or 1 (got %s)" % order) prof = debug.Profiler() nd = data.ndim md = x.shape[-1] if md > nd: raise TypeError("x.shape[-1] must be less than or equal to data.ndim") totalMask = np.ones(x.shape[:-1], dtype=bool) # keep track of out-of-bound indexes if order == 0: xinds = np.round(x).astype(int) # NOTE: for 0.5 this rounds to the nearest *even* number for ax in range(md): mask = (xinds[...,ax] >= 0) & (xinds[...,ax] <= data.shape[ax]-1) xinds[...,ax][~mask] = 0 # keep track of points that need to be set to default totalMask &= mask result = data[tuple([xinds[...,i] for i in range(xinds.shape[-1])])] elif order == 1: # First we generate arrays of indexes that are needed to # extract the data surrounding each point fields = np.mgrid[(slice(0,order+1),) * md] xmin = np.floor(x).astype(int) xmax = xmin + 1 indexes = np.concatenate([xmin[np.newaxis, ...], xmax[np.newaxis, ...]]) fieldInds = [] for ax in range(md): mask = (xmin[...,ax] >= 0) & (x[...,ax] <= data.shape[ax]-1) # keep track of points that need to be set to default totalMask &= mask # ..and keep track of indexes that are out of bounds # (note that when x[...,ax] == data.shape[ax], then xmax[...,ax] will be out # of bounds, but the interpolation will work anyway) mask &= (xmax[...,ax] < data.shape[ax]) axisIndex = indexes[...,ax][fields[ax]] axisIndex[axisIndex < 0] = 0 axisIndex[axisIndex >= data.shape[ax]] = 0 fieldInds.append(axisIndex) prof() # Get data values surrounding each requested point fieldData = data[tuple(fieldInds)] prof() ## Interpolate s = np.empty((md,) + fieldData.shape, dtype=float) dx = x - xmin # reshape fields for arithmetic against dx for ax in range(md): f1 = fields[ax].reshape(fields[ax].shape + (1,)*(dx.ndim-1)) sax = f1 * dx[...,ax] + (1-f1) * (1-dx[...,ax]) sax = sax.reshape(sax.shape + (1,) * (s.ndim-1-sax.ndim)) s[ax] = sax s = np.product(s, axis=0) result = fieldData * s for i in range(md): result = result.sum(axis=0) prof() if totalMask.ndim > 0: result[~totalMask] = default else: if totalMask is False: result[:] = default prof() return result
[ "def", "interpolateArray", "(", "data", ",", "x", ",", "default", "=", "0.0", ",", "order", "=", "1", ")", ":", "if", "order", "not", "in", "(", "0", ",", "1", ")", ":", "raise", "ValueError", "(", "\"interpolateArray requires order=0 or 1 (got %s)\"", "%"...
https://github.com/pyqtgraph/pyqtgraph/blob/ac3887abfca4e529aac44f022f8e40556a2587b0/pyqtgraph/functions.py#L884-L1015
arizvisa/ida-minsc
8627a60f047b5e55d3efeecde332039cd1a16eea
base/_interface.py
python
switch_t.handler
(self, ea)
return tuple(case for case in self.range if self.case(case) == ea)
Return all the cases that are handled by the address `ea` as a tuple.
Return all the cases that are handled by the address `ea` as a tuple.
[ "Return", "all", "the", "cases", "that", "are", "handled", "by", "the", "address", "ea", "as", "a", "tuple", "." ]
def handler(self, ea): '''Return all the cases that are handled by the address `ea` as a tuple.''' return tuple(case for case in self.range if self.case(case) == ea)
[ "def", "handler", "(", "self", ",", "ea", ")", ":", "return", "tuple", "(", "case", "for", "case", "in", "self", ".", "range", "if", "self", ".", "case", "(", "case", ")", "==", "ea", ")" ]
https://github.com/arizvisa/ida-minsc/blob/8627a60f047b5e55d3efeecde332039cd1a16eea/base/_interface.py#L1836-L1838
bookwyrm-social/bookwyrm
0c2537e27a2cdbc0136880dfbbf170d5fec72986
bookwyrm/templatetags/bookwyrm_tags.py
python
related_status
(notification)
return load_subclass(notification.related_status)
for notifications
for notifications
[ "for", "notifications" ]
def related_status(notification): """for notifications""" if not notification.related_status: return None return load_subclass(notification.related_status)
[ "def", "related_status", "(", "notification", ")", ":", "if", "not", "notification", ".", "related_status", ":", "return", "None", "return", "load_subclass", "(", "notification", ".", "related_status", ")" ]
https://github.com/bookwyrm-social/bookwyrm/blob/0c2537e27a2cdbc0136880dfbbf170d5fec72986/bookwyrm/templatetags/bookwyrm_tags.py#L124-L128
aws-samples/aws-kube-codesuite
ab4e5ce45416b83bffb947ab8d234df5437f4fca
src/kubernetes/client/models/v1_attached_volume.py
python
V1AttachedVolume.to_str
(self)
return pformat(self.to_dict())
Returns the string representation of the model
Returns the string representation of the model
[ "Returns", "the", "string", "representation", "of", "the", "model" ]
def to_str(self): """ Returns the string representation of the model """ return pformat(self.to_dict())
[ "def", "to_str", "(", "self", ")", ":", "return", "pformat", "(", "self", ".", "to_dict", "(", ")", ")" ]
https://github.com/aws-samples/aws-kube-codesuite/blob/ab4e5ce45416b83bffb947ab8d234df5437f4fca/src/kubernetes/client/models/v1_attached_volume.py#L122-L126
fake-name/ReadableWebProxy
ed5c7abe38706acc2684a1e6cd80242a03c5f010
WebMirror/management/rss_parser_funcs/feed_parse_extractSotranslations.py
python
extractSotranslations
(item)
return False
# Supreme Origin Translations
# Supreme Origin Translations
[ "#", "Supreme", "Origin", "Translations" ]
def extractSotranslations(item): """ # Supreme Origin Translations """ vol, chp, frag, postfix = extractVolChapterFragmentPostfix(item['title']) if not (chp or vol) or 'preview' in item['title'].lower(): return None if 'hachi-nan chapter' in item['title'].lower() and not 'draft' in item['title'].lower(): return buildReleaseMessageWithType(item, 'Hachinan tte, Sore wa nai Deshou!', vol, chp, frag=frag, postfix=postfix) if 'the devil of an angel chapter' in item['title'].lower() and not 'draft' in item['title'].lower(): return buildReleaseMessageWithType(item, 'The Devil of an Angel Chapter', vol, chp, frag=frag, postfix=postfix) return False
[ "def", "extractSotranslations", "(", "item", ")", ":", "vol", ",", "chp", ",", "frag", ",", "postfix", "=", "extractVolChapterFragmentPostfix", "(", "item", "[", "'title'", "]", ")", "if", "not", "(", "chp", "or", "vol", ")", "or", "'preview'", "in", "it...
https://github.com/fake-name/ReadableWebProxy/blob/ed5c7abe38706acc2684a1e6cd80242a03c5f010/WebMirror/management/rss_parser_funcs/feed_parse_extractSotranslations.py#L1-L13
opendatacube/datacube-core
b062184be61c140a168de94510bc3661748f112e
datacube/index/_datasets.py
python
DatasetResource.search_eager
(self, **query)
return list(self.search(**query))
Perform a search, returning results as Dataset objects. :param dict[str,str|float|datacube.model.Range] query: :rtype: list[Dataset]
Perform a search, returning results as Dataset objects.
[ "Perform", "a", "search", "returning", "results", "as", "Dataset", "objects", "." ]
def search_eager(self, **query): """ Perform a search, returning results as Dataset objects. :param dict[str,str|float|datacube.model.Range] query: :rtype: list[Dataset] """ return list(self.search(**query))
[ "def", "search_eager", "(", "self", ",", "*", "*", "query", ")", ":", "return", "list", "(", "self", ".", "search", "(", "*", "*", "query", ")", ")" ]
https://github.com/opendatacube/datacube-core/blob/b062184be61c140a168de94510bc3661748f112e/datacube/index/_datasets.py#L742-L749
vyos/vyos-1x
6e8a8934a7d4e1b21d7c828e372303683b499b56
src/helpers/strip-private.py
python
strip_address
(line: str)
return ipv4_re.sub(lambda match: ip_match(match, ipv4_subst), ipv6_re.sub(lambda match: ip_match(match, ipv6_subst), line))
Strip IPv4 and IPv6 addresses from the given string.
Strip IPv4 and IPv6 addresses from the given string.
[ "Strip", "IPv4", "and", "IPv6", "addresses", "from", "the", "given", "string", "." ]
def strip_address(line: str) -> str: """ Strip IPv4 and IPv6 addresses from the given string. """ return ipv4_re.sub(lambda match: ip_match(match, ipv4_subst), ipv6_re.sub(lambda match: ip_match(match, ipv6_subst), line))
[ "def", "strip_address", "(", "line", ":", "str", ")", "->", "str", ":", "return", "ipv4_re", ".", "sub", "(", "lambda", "match", ":", "ip_match", "(", "match", ",", "ipv4_subst", ")", ",", "ipv6_re", ".", "sub", "(", "lambda", "match", ":", "ip_match",...
https://github.com/vyos/vyos-1x/blob/6e8a8934a7d4e1b21d7c828e372303683b499b56/src/helpers/strip-private.py#L72-L76
tijme/angularjs-csti-scanner
dcf5bf3d36a0a6ee3a9db1340e68de95b33e4615
extended.py
python
require_arguments
()
return parser.parse_args()
Get the arguments from CLI input. Returns: :class:`argparse.Namespace`: A namespace with all the parsed CLI arguments.
Get the arguments from CLI input.
[ "Get", "the", "arguments", "from", "CLI", "input", "." ]
def require_arguments(): """Get the arguments from CLI input. Returns: :class:`argparse.Namespace`: A namespace with all the parsed CLI arguments. """ parser = argparse.ArgumentParser( prog=PackageHelper.get_alias(), formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=180, width=180) ) optional = parser._action_groups.pop() required = parser.add_argument_group("required arguments") required.add_argument("-d", "--domain", help="the domain to scan (e.g. finnwea.com)", required=True) optional.add_argument("-c", "--crawl", help="use the crawler to scan all the entire domain", action="store_true") optional.add_argument("-vp", "--verify-payload", help="use a javascript engine to verify if the payload was executed (otherwise false positives may occur)", action="store_true") optional.add_argument("-av", "--angular-version", help="manually pass the angular version (e.g. 1.4.2) if the automatic check doesn't work", type=str, default=None) optional.add_argument("-vrl", "--vulnerable-requests-log", help="log all vulnerable requests to this file (e.g. /var/logs/acstis.log or urls.log)", type=str, default=None) optional.add_argument("-siv", "--stop-if-vulnerable", help="(crawler option) stop scanning if a vulnerability was found", action="store_true") optional.add_argument("-pmm", "--protocol-must-match", help="(crawler option) only scan pages with the same protocol as the startpoint (e.g. only https)", action="store_true") optional.add_argument("-sos", "--scan-other-subdomains", help="(crawler option) also scan pages that have another subdomain than the startpoint", action="store_true") optional.add_argument("-soh", "--scan-other-hostnames", help="(crawler option) also scan pages that have another hostname than the startpoint", action="store_true") optional.add_argument("-sot", "--scan-other-tlds", help="(crawler option) also scan pages that have another tld than the startpoint", action="store_true") optional.add_argument("-md", "--max-depth", help="(crawler option) the maximum search depth (default is unlimited)", type=int) optional.add_argument("-mt", "--max-threads", help="(crawler option) the maximum amount of simultaneous threads to use (default is 20)", type=int, default=20) optional.add_argument("-iic", "--ignore-invalid-certificates", help="(crawler option) ignore invalid ssl certificates", action="store_true") optional.add_argument("-tc", "--trusted-certificates", help="(crawler option) trust this CA_BUNDLE file (.pem) or directory with certificates", type=str, default=None) parser._action_groups.append(optional) return parser.parse_args()
[ "def", "require_arguments", "(", ")", ":", "parser", "=", "argparse", ".", "ArgumentParser", "(", "prog", "=", "PackageHelper", ".", "get_alias", "(", ")", ",", "formatter_class", "=", "lambda", "prog", ":", "argparse", ".", "HelpFormatter", "(", "prog", ","...
https://github.com/tijme/angularjs-csti-scanner/blob/dcf5bf3d36a0a6ee3a9db1340e68de95b33e4615/extended.py#L64-L97
OpenKMIP/PyKMIP
c0c980395660ea1b1a8009e97f17ab32d1100233
kmip/core/messages/payloads/archive.py
python
ArchiveRequestPayload.__init__
(self, unique_identifier=None)
Construct an Archive request payload struct. Args: unique_identifier (string): The ID of the managed object (e.g., a public key) to archive. Optional, defaults to None.
Construct an Archive request payload struct.
[ "Construct", "an", "Archive", "request", "payload", "struct", "." ]
def __init__(self, unique_identifier=None): """ Construct an Archive request payload struct. Args: unique_identifier (string): The ID of the managed object (e.g., a public key) to archive. Optional, defaults to None. """ super(ArchiveRequestPayload, self).__init__() self._unique_identifier = None self.unique_identifier = unique_identifier
[ "def", "__init__", "(", "self", ",", "unique_identifier", "=", "None", ")", ":", "super", "(", "ArchiveRequestPayload", ",", "self", ")", ".", "__init__", "(", ")", "self", ".", "_unique_identifier", "=", "None", "self", ".", "unique_identifier", "=", "uniqu...
https://github.com/OpenKMIP/PyKMIP/blob/c0c980395660ea1b1a8009e97f17ab32d1100233/kmip/core/messages/payloads/archive.py#L32-L43
TencentCloud/tencentcloud-sdk-python
3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2
tencentcloud/chdfs/v20201112/models.py
python
DeleteFileSystemResponse.__init__
(self)
r""" :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str
r""" :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str
[ "r", ":", "param", "RequestId", ":", "唯一请求", "ID,每次请求都会返回。定位问题时需要提供该次请求的", "RequestId。", ":", "type", "RequestId", ":", "str" ]
def __init__(self): r""" :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str """ self.RequestId = None
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "RequestId", "=", "None" ]
https://github.com/TencentCloud/tencentcloud-sdk-python/blob/3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2/tencentcloud/chdfs/v20201112/models.py#L604-L609
yuxiaokui/Intranet-Penetration
f57678a204840c83cbf3308e3470ae56c5ff514b
proxy/XX-Net/code/default/gae_proxy/server/lib/google/appengine/_internal/antlr3/tree.py
python
TreeAdaptor.deleteChild
(self, t, i)
Remove ith child and shift children down from right.
Remove ith child and shift children down from right.
[ "Remove", "ith", "child", "and", "shift", "children", "down", "from", "right", "." ]
def deleteChild(self, t, i): """Remove ith child and shift children down from right.""" raise NotImplementedError
[ "def", "deleteChild", "(", "self", ",", "t", ",", "i", ")", ":", "raise", "NotImplementedError" ]
https://github.com/yuxiaokui/Intranet-Penetration/blob/f57678a204840c83cbf3308e3470ae56c5ff514b/proxy/XX-Net/code/default/gae_proxy/server/lib/google/appengine/_internal/antlr3/tree.py#L507-L510
huggingface/transformers
623b4f7c63f60cce917677ee704d6c93ee960b4b
src/transformers/integrations.py
python
WandbCallback.on_train_begin
(self, args, state, control, model=None, **kwargs)
[]
def on_train_begin(self, args, state, control, model=None, **kwargs): if self._wandb is None: return hp_search = state.is_hyper_param_search if hp_search: self._wandb.finish() self._initialized = False if not self._initialized: self.setup(args, state, model, **kwargs)
[ "def", "on_train_begin", "(", "self", ",", "args", ",", "state", ",", "control", ",", "model", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "_wandb", "is", "None", ":", "return", "hp_search", "=", "state", ".", "is_hyper_param_sea...
https://github.com/huggingface/transformers/blob/623b4f7c63f60cce917677ee704d6c93ee960b4b/src/transformers/integrations.py#L538-L546
Billwilliams1952/PiCameraApp
61802b367d620aafb6b4e0bb84ea1ebd0dbd42c0
Source/PreferencesDialog.py
python
Interface.ShowTooltipsChecked
( self )
[]
def ShowTooltipsChecked ( self ): ToolTip.ShowToolTips = self.ShowTooltips.get()
[ "def", "ShowTooltipsChecked", "(", "self", ")", ":", "ToolTip", ".", "ShowToolTips", "=", "self", ".", "ShowTooltips", ".", "get", "(", ")" ]
https://github.com/Billwilliams1952/PiCameraApp/blob/61802b367d620aafb6b4e0bb84ea1ebd0dbd42c0/Source/PreferencesDialog.py#L351-L352
holzschu/Carnets
44effb10ddfc6aa5c8b0687582a724ba82c6b547
Library/lib/python3.7/site-packages/pandas-0.24.2-py3.7-macosx-10.9-x86_64.egg/pandas/io/pytables.py
python
Table.read_coordinates
(self, where=None, start=None, stop=None, **kwargs)
return Index(coords)
select coordinates (row numbers) from a table; return the coordinates object
select coordinates (row numbers) from a table; return the coordinates object
[ "select", "coordinates", "(", "row", "numbers", ")", "from", "a", "table", ";", "return", "the", "coordinates", "object" ]
def read_coordinates(self, where=None, start=None, stop=None, **kwargs): """select coordinates (row numbers) from a table; return the coordinates object """ # validate the version self.validate_version(where) # infer the data kind if not self.infer_axes(): return False # create the selection self.selection = Selection( self, where=where, start=start, stop=stop, **kwargs) coords = self.selection.select_coords() if self.selection.filter is not None: for field, op, filt in self.selection.filter.format(): data = self.read_column( field, start=coords.min(), stop=coords.max() + 1) coords = coords[ op(data.iloc[coords - coords.min()], filt).values] return Index(coords)
[ "def", "read_coordinates", "(", "self", ",", "where", "=", "None", ",", "start", "=", "None", ",", "stop", "=", "None", ",", "*", "*", "kwargs", ")", ":", "# validate the version", "self", ".", "validate_version", "(", "where", ")", "# infer the data kind", ...
https://github.com/holzschu/Carnets/blob/44effb10ddfc6aa5c8b0687582a724ba82c6b547/Library/lib/python3.7/site-packages/pandas-0.24.2-py3.7-macosx-10.9-x86_64.egg/pandas/io/pytables.py#L3791-L3814
criteo/biggraphite
1f647ada6b3f2b2f3fb4e59d326f73a2c891fc30
biggraphite/drivers/cassandra.py
python
_CassandraAccessor.create_metric
(self, metric)
See bg_accessor.Accessor.
See bg_accessor.Accessor.
[ "See", "bg_accessor", ".", "Accessor", "." ]
def create_metric(self, metric): """See bg_accessor.Accessor.""" super(_CassandraAccessor, self).create_metric(metric) if self.__bulkimport: return components = self._components_from_name(metric.name) assert metric.id is not None and metric.metadata is not None queries = [] # Check if parent dir exists. This is one round-trip but worthwile since # otherwise creating each parent directory requires a round-trip and the # vast majority of metrics have siblings. parent_dir = metric.name.rpartition(".")[0] if parent_dir and not self.has_directory(parent_dir): queries.extend(self._create_parent_dirs_queries(components)) # Finally, create the metric padding_len = _COMPONENTS_MAX_LEN - len(components) padding = [c_query.UNSET_VALUE] * padding_len metadata_dict = metric.metadata.as_string_dict() queries.append( ( self.__insert_metric_statement.with_param_list( [metric.name, parent_dir + "."] + components + padding ) ) ) queries.append( ( self.__insert_metrics_metadata_statement.with_param_list( [metric.name, metric.id, metadata_dict] ) ) ) self._execute_concurrent_metadata(queries, raise_on_first_error=False)
[ "def", "create_metric", "(", "self", ",", "metric", ")", ":", "super", "(", "_CassandraAccessor", ",", "self", ")", ".", "create_metric", "(", "metric", ")", "if", "self", ".", "__bulkimport", ":", "return", "components", "=", "self", ".", "_components_from_...
https://github.com/criteo/biggraphite/blob/1f647ada6b3f2b2f3fb4e59d326f73a2c891fc30/biggraphite/drivers/cassandra.py#L1706-L1744
MeanEYE/Sunflower
1024bbdde3b8e202ddad3553b321a7b6230bffc9
sunflower/gui/main_window.py
python
MainWindow._toggle_media_preview
(self, widget, data=None)
return True
Enable/disable fast image preview
Enable/disable fast image preview
[ "Enable", "/", "disable", "fast", "image", "preview" ]
def _toggle_media_preview(self, widget, data=None): """Enable/disable fast image preview""" if not isinstance(widget, Gio.SimpleAction): action = self.lookup_action('view.fast_media_preview') else: action = widget state = not action.get_state() action.set_state(GLib.Variant.new_boolean(state)) self.options.set('media_preview', state) # update left notebook for index in range(0, self.left_notebook.get_n_pages()): page = self.left_notebook.get_nth_page(index) if hasattr(page, 'apply_media_preview_settings'): page.apply_media_preview_settings() # update right notebook for index in range(0, self.right_notebook.get_n_pages()): page = self.right_notebook.get_nth_page(index) if hasattr(page, 'apply_media_preview_settings'): page.apply_media_preview_settings() return True
[ "def", "_toggle_media_preview", "(", "self", ",", "widget", ",", "data", "=", "None", ")", ":", "if", "not", "isinstance", "(", "widget", ",", "Gio", ".", "SimpleAction", ")", ":", "action", "=", "self", ".", "lookup_action", "(", "'view.fast_media_preview'"...
https://github.com/MeanEYE/Sunflower/blob/1024bbdde3b8e202ddad3553b321a7b6230bffc9/sunflower/gui/main_window.py#L795-L820
huggingface/transformers
623b4f7c63f60cce917677ee704d6c93ee960b4b
src/transformers/models/deberta/modeling_tf_deberta.py
python
TFDebertaEncoder.call
( self, hidden_states: tf.Tensor, attention_mask: tf.Tensor, query_states: tf.Tensor = None, relative_pos: tf.Tensor = None, output_attentions: bool = False, output_hidden_states: bool = False, return_dict: bool = True, training: bool = False, )
return TFBaseModelOutput( last_hidden_state=hidden_states, hidden_states=all_hidden_states, attentions=all_attentions )
[]
def call( self, hidden_states: tf.Tensor, attention_mask: tf.Tensor, query_states: tf.Tensor = None, relative_pos: tf.Tensor = None, output_attentions: bool = False, output_hidden_states: bool = False, return_dict: bool = True, training: bool = False, ) -> Union[TFBaseModelOutput, Tuple[tf.Tensor]]: all_hidden_states = () if output_hidden_states else None all_attentions = () if output_attentions else None attention_mask = self.get_attention_mask(attention_mask) relative_pos = self.get_rel_pos(hidden_states, query_states, relative_pos) if isinstance(hidden_states, Sequence): next_kv = hidden_states[0] else: next_kv = hidden_states rel_embeddings = self.get_rel_embedding() for i, layer_module in enumerate(self.layer): if output_hidden_states: all_hidden_states = all_hidden_states + (hidden_states,) layer_outputs = layer_module( hidden_states=next_kv, attention_mask=attention_mask, query_states=query_states, relative_pos=relative_pos, rel_embeddings=rel_embeddings, output_attentions=output_attentions, training=training, ) hidden_states = layer_outputs[0] if query_states is not None: query_states = hidden_states if isinstance(hidden_states, Sequence): next_kv = hidden_states[i + 1] if i + 1 < len(self.layer) else None else: next_kv = hidden_states if output_attentions: all_attentions = all_attentions + (layer_outputs[1],) # Add last layer if output_hidden_states: all_hidden_states = all_hidden_states + (hidden_states,) if not return_dict: return tuple(v for v in [hidden_states, all_hidden_states, all_attentions] if v is not None) return TFBaseModelOutput( last_hidden_state=hidden_states, hidden_states=all_hidden_states, attentions=all_attentions )
[ "def", "call", "(", "self", ",", "hidden_states", ":", "tf", ".", "Tensor", ",", "attention_mask", ":", "tf", ".", "Tensor", ",", "query_states", ":", "tf", ".", "Tensor", "=", "None", ",", "relative_pos", ":", "tf", ".", "Tensor", "=", "None", ",", ...
https://github.com/huggingface/transformers/blob/623b4f7c63f60cce917677ee704d6c93ee960b4b/src/transformers/models/deberta/modeling_tf_deberta.py#L331-L390
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/mpd/media_player.py
python
MpdDevice.media_duration
(self)
return self._currentsong.get("time")
Return the duration of current playing media in seconds.
Return the duration of current playing media in seconds.
[ "Return", "the", "duration", "of", "current", "playing", "media", "in", "seconds", "." ]
def media_duration(self): """Return the duration of current playing media in seconds.""" # Time does not exist for streams return self._currentsong.get("time")
[ "def", "media_duration", "(", "self", ")", ":", "# Time does not exist for streams", "return", "self", ".", "_currentsong", ".", "get", "(", "\"time\"", ")" ]
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/mpd/media_player.py#L218-L221
bruderstein/PythonScript
df9f7071ddf3a079e3a301b9b53a6dc78cf1208f
PythonLib/full/encodings/cp1254.py
python
Codec.encode
(self,input,errors='strict')
return codecs.charmap_encode(input,errors,encoding_table)
[]
def encode(self,input,errors='strict'): return codecs.charmap_encode(input,errors,encoding_table)
[ "def", "encode", "(", "self", ",", "input", ",", "errors", "=", "'strict'", ")", ":", "return", "codecs", ".", "charmap_encode", "(", "input", ",", "errors", ",", "encoding_table", ")" ]
https://github.com/bruderstein/PythonScript/blob/df9f7071ddf3a079e3a301b9b53a6dc78cf1208f/PythonLib/full/encodings/cp1254.py#L11-L12
timvieira/arsenal
3a626722f46fd7ef6768abfdffc0eb28cae7dfa2
arsenal/iterview.py
python
time_elapsed
(elapsed)
return '%02d:%02d:%02d' % (hours, minutes, seconds)
Returns a string indicating the time elapsed.
Returns a string indicating the time elapsed.
[ "Returns", "a", "string", "indicating", "the", "time", "elapsed", "." ]
def time_elapsed(elapsed): """ Returns a string indicating the time elapsed. """ seconds = int(elapsed) # if complete, total time elapsed minutes, seconds = divmod(seconds, 60) hours, minutes = divmod(minutes, 60) return '%02d:%02d:%02d' % (hours, minutes, seconds)
[ "def", "time_elapsed", "(", "elapsed", ")", ":", "seconds", "=", "int", "(", "elapsed", ")", "# if complete, total time elapsed", "minutes", ",", "seconds", "=", "divmod", "(", "seconds", ",", "60", ")", "hours", ",", "minutes", "=", "divmod", "(", "minutes"...
https://github.com/timvieira/arsenal/blob/3a626722f46fd7ef6768abfdffc0eb28cae7dfa2/arsenal/iterview.py#L63-L72
hyperledger/aries-cloudagent-python
2f36776e99f6053ae92eed8123b5b1b2e891c02a
aries_cloudagent/transport/inbound/manager.py
python
InboundTransportManager.create_session
( self, transport_type: str, *, accept_undelivered: bool = False, can_respond: bool = False, client_info: dict = None, wire_format: BaseWireFormat = None, )
return session
Create a new inbound session. Args: transport_type: The inbound transport identifier accept_undelivered: Flag for accepting undelivered messages can_respond: Flag indicating that the transport can send responses client_info: An optional dict describing the client wire_format: Override the wire format for this session
Create a new inbound session.
[ "Create", "a", "new", "inbound", "session", "." ]
async def create_session( self, transport_type: str, *, accept_undelivered: bool = False, can_respond: bool = False, client_info: dict = None, wire_format: BaseWireFormat = None, ): """ Create a new inbound session. Args: transport_type: The inbound transport identifier accept_undelivered: Flag for accepting undelivered messages can_respond: Flag indicating that the transport can send responses client_info: An optional dict describing the client wire_format: Override the wire format for this session """ if self.session_limit: await self.session_limit if not wire_format: wire_format = self.profile.context.inject(BaseWireFormat) session = InboundSession( profile=self.profile, accept_undelivered=accept_undelivered, can_respond=can_respond, client_info=client_info, close_handler=self.closed_session, inbound_handler=self.receive_inbound, session_id=str(uuid.uuid4()), transport_type=transport_type, wire_format=wire_format, ) self.sessions[session.session_id] = session return session
[ "async", "def", "create_session", "(", "self", ",", "transport_type", ":", "str", ",", "*", ",", "accept_undelivered", ":", "bool", "=", "False", ",", "can_respond", ":", "bool", "=", "False", ",", "client_info", ":", "dict", "=", "None", ",", "wire_format...
https://github.com/hyperledger/aries-cloudagent-python/blob/2f36776e99f6053ae92eed8123b5b1b2e891c02a/aries_cloudagent/transport/inbound/manager.py#L147-L182
aws-samples/aws-kube-codesuite
ab4e5ce45416b83bffb947ab8d234df5437f4fca
src/kubernetes/client/models/v1_http_get_action.py
python
V1HTTPGetAction.port
(self, port)
Sets the port of this V1HTTPGetAction. Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. :param port: The port of this V1HTTPGetAction. :type: str
Sets the port of this V1HTTPGetAction. Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME.
[ "Sets", "the", "port", "of", "this", "V1HTTPGetAction", ".", "Name", "or", "number", "of", "the", "port", "to", "access", "on", "the", "container", ".", "Number", "must", "be", "in", "the", "range", "1", "to", "65535", ".", "Name", "must", "be", "an", ...
def port(self, port): """ Sets the port of this V1HTTPGetAction. Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. :param port: The port of this V1HTTPGetAction. :type: str """ if port is None: raise ValueError("Invalid value for `port`, must not be `None`") self._port = port
[ "def", "port", "(", "self", ",", "port", ")", ":", "if", "port", "is", "None", ":", "raise", "ValueError", "(", "\"Invalid value for `port`, must not be `None`\"", ")", "self", ".", "_port", "=", "port" ]
https://github.com/aws-samples/aws-kube-codesuite/blob/ab4e5ce45416b83bffb947ab8d234df5437f4fca/src/kubernetes/client/models/v1_http_get_action.py#L136-L147
ralphm/wokkel
76edbf80f0d314e314e2d4d1510c6e5438a538f7
wokkel/iwokkel.py
python
IPubSubService.getConfigurationOptions
()
Retrieve all known node configuration options. The returned dictionary holds the possible node configuration options by option name. The value of each entry represents the specifics for that option in a dictionary: - C{'type'} (C{str}): The option's type (see L{Field<wokkel.data_form.Field>}'s doc string for possible values). - C{'label'} (C{unicode}): A human readable label for this option. - C{'options'} (C{dict}): Optional list of possible values for this option. Example:: { "pubsub#persist_items": {"type": "boolean", "label": "Persist items to storage"}, "pubsub#deliver_payloads": {"type": "boolean", "label": "Deliver payloads with event notifications"}, "pubsub#send_last_published_item": {"type": "list-single", "label": "When to send the last published item", "options": { "never": "Never", "on_sub": "When a new subscription is processed"} } } @rtype: C{dict}.
Retrieve all known node configuration options.
[ "Retrieve", "all", "known", "node", "configuration", "options", "." ]
def getConfigurationOptions(): """ Retrieve all known node configuration options. The returned dictionary holds the possible node configuration options by option name. The value of each entry represents the specifics for that option in a dictionary: - C{'type'} (C{str}): The option's type (see L{Field<wokkel.data_form.Field>}'s doc string for possible values). - C{'label'} (C{unicode}): A human readable label for this option. - C{'options'} (C{dict}): Optional list of possible values for this option. Example:: { "pubsub#persist_items": {"type": "boolean", "label": "Persist items to storage"}, "pubsub#deliver_payloads": {"type": "boolean", "label": "Deliver payloads with event notifications"}, "pubsub#send_last_published_item": {"type": "list-single", "label": "When to send the last published item", "options": { "never": "Never", "on_sub": "When a new subscription is processed"} } } @rtype: C{dict}. """
[ "def", "getConfigurationOptions", "(", ")", ":" ]
https://github.com/ralphm/wokkel/blob/76edbf80f0d314e314e2d4d1510c6e5438a538f7/wokkel/iwokkel.py#L317-L350
glutanimate/cloze-overlapper
9eabb6a9d2a6807595478647fd968e8e4bac86fc
src/cloze_overlapper/libaddon/gui/basic/interface.py
python
CommonWidgetInterface.setMinValue
(self, widget, value)
Set lower boundary of widget Arguments: widget {Qt widget} -- Qt widget to update. Supported: QSpinBox, QDoubleSpinBox, QDateEdit value {int,float} -- Number to set lower boundary to. In case of QDateEdit: - value should be valid unix time in secs since epoch Raises: NotImplementedError -- In case of an unimplemented widget Returns: object -- Setter return value
Set lower boundary of widget Arguments: widget {Qt widget} -- Qt widget to update. Supported: QSpinBox, QDoubleSpinBox, QDateEdit value {int,float} -- Number to set lower boundary to. In case of QDateEdit: - value should be valid unix time in secs since epoch Raises: NotImplementedError -- In case of an unimplemented widget Returns: object -- Setter return value
[ "Set", "lower", "boundary", "of", "widget", "Arguments", ":", "widget", "{", "Qt", "widget", "}", "--", "Qt", "widget", "to", "update", ".", "Supported", ":", "QSpinBox", "QDoubleSpinBox", "QDateEdit", "value", "{", "int", "float", "}", "--", "Number", "to...
def setMinValue(self, widget, value): """ Set lower boundary of widget Arguments: widget {Qt widget} -- Qt widget to update. Supported: QSpinBox, QDoubleSpinBox, QDateEdit value {int,float} -- Number to set lower boundary to. In case of QDateEdit: - value should be valid unix time in secs since epoch Raises: NotImplementedError -- In case of an unimplemented widget Returns: object -- Setter return value """ try: assert isinstance(value, (int, float)), \ "value should be an int or float" except AssertionError as error: error.args += ("Widget: ", widget) raise if isinstance(widget, (QSpinBox, QDoubleSpinBox, QSlider)): return widget.setMinimum(value) elif isinstance(widget, QDateEdit): return self._setDateTimeMin(widget, value) else: raise NotImplementedError( "setMinValue not implemented for widget ", widget)
[ "def", "setMinValue", "(", "self", ",", "widget", ",", "value", ")", ":", "try", ":", "assert", "isinstance", "(", "value", ",", "(", "int", ",", "float", ")", ")", ",", "\"value should be an int or float\"", "except", "AssertionError", "as", "error", ":", ...
https://github.com/glutanimate/cloze-overlapper/blob/9eabb6a9d2a6807595478647fd968e8e4bac86fc/src/cloze_overlapper/libaddon/gui/basic/interface.py#L648-L679
zhaoolee/StarsAndClown
b2d4039cad2f9232b691e5976f787b49a0a2c113
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py
python
VisualStudioVersion.UsesVcxproj
(self)
return self.uses_vcxproj
Returns true if this version uses a vcxproj file.
Returns true if this version uses a vcxproj file.
[ "Returns", "true", "if", "this", "version", "uses", "a", "vcxproj", "file", "." ]
def UsesVcxproj(self): """Returns true if this version uses a vcxproj file.""" return self.uses_vcxproj
[ "def", "UsesVcxproj", "(", "self", ")", ":", "return", "self", ".", "uses_vcxproj" ]
https://github.com/zhaoolee/StarsAndClown/blob/b2d4039cad2f9232b691e5976f787b49a0a2c113/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py#L50-L52
SUSE/DeepSea
9c7fad93915ba1250c40d50c855011e9fe41ed21
srv/salt/_modules/osd.py
python
OSDGrains._grains
(self, storage)
Load and save grains when changed
Load and save grains when changed
[ "Load", "and", "save", "grains", "when", "changed" ]
def _grains(self, storage): """ Load and save grains when changed """ content = {} if os.path.exists(self.filename): with open(self.filename, 'r') as minion_grains: content = yaml.safe_load(minion_grains) if 'ceph' in content and content['ceph'] == storage: log.debug("No update for {}".format(self.filename)) else: content['ceph'] = storage self._update_grains(content)
[ "def", "_grains", "(", "self", ",", "storage", ")", ":", "content", "=", "{", "}", "if", "os", ".", "path", ".", "exists", "(", "self", ".", "filename", ")", ":", "with", "open", "(", "self", ".", "filename", ",", "'r'", ")", "as", "minion_grains",...
https://github.com/SUSE/DeepSea/blob/9c7fad93915ba1250c40d50c855011e9fe41ed21/srv/salt/_modules/osd.py#L773-L785
apachecn/AiLearning
228b62a905a2a9bf6066f65c16d53056b10ec610
src/py3.x/ml/8.Regression/regression.py
python
ridgeTest
(xArr, yArr)
return wMat
Desc: 函数 ridgeTest() 用于在一组 λ 上测试结果 Args: xArr: 样本数据的特征,即 feature yArr: 样本数据的类别标签,即真实数据 Returns: wMat: 将所有的回归系数输出到一个矩阵并返回
Desc: 函数 ridgeTest() 用于在一组 λ 上测试结果 Args: xArr: 样本数据的特征,即 feature yArr: 样本数据的类别标签,即真实数据 Returns: wMat: 将所有的回归系数输出到一个矩阵并返回
[ "Desc", ":", "函数", "ridgeTest", "()", "用于在一组", "λ", "上测试结果", "Args", ":", "xArr", ":", "样本数据的特征,即", "feature", "yArr", ":", "样本数据的类别标签,即真实数据", "Returns", ":", "wMat", ":", "将所有的回归系数输出到一个矩阵并返回" ]
def ridgeTest(xArr, yArr): ''' Desc: 函数 ridgeTest() 用于在一组 λ 上测试结果 Args: xArr: 样本数据的特征,即 feature yArr: 样本数据的类别标签,即真实数据 Returns: wMat: 将所有的回归系数输出到一个矩阵并返回 ''' xMat = mat(xArr) yMat = mat(yArr).T # 计算Y的均值 yMean = mean(yMat, 0) # Y的所有的特征减去均值 yMat = yMat - yMean # 标准化 x,计算 xMat 平均值 xMeans = mean(xMat, 0) # 然后计算 X的方差 xVar = var(xMat, 0) # 所有特征都减去各自的均值并除以方差 xMat = (xMat - xMeans) / xVar # 可以在 30 个不同的 lambda 下调用 ridgeRegres() 函数。 numTestPts = 30 # 创建30 * m 的全部数据为0 的矩阵 wMat = zeros((numTestPts, shape(xMat)[1])) for i in range(numTestPts): # exp() 返回 e^x ws = ridgeRegres(xMat, yMat, exp(i - 10)) wMat[i, :] = ws.T return wMat
[ "def", "ridgeTest", "(", "xArr", ",", "yArr", ")", ":", "xMat", "=", "mat", "(", "xArr", ")", "yMat", "=", "mat", "(", "yArr", ")", ".", "T", "# 计算Y的均值", "yMean", "=", "mean", "(", "yMat", ",", "0", ")", "# Y的所有的特征减去均值", "yMat", "=", "yMat", "-",...
https://github.com/apachecn/AiLearning/blob/228b62a905a2a9bf6066f65c16d53056b10ec610/src/py3.x/ml/8.Regression/regression.py#L202-L233
wistbean/learn_python3_spider
73c873f4845f4385f097e5057407d03dd37a117b
stackoverflow/venv/lib/python3.6/site-packages/twisted/internet/_baseprocess.py
python
BaseProcess.processEnded
(self, status)
This is called when the child terminates.
This is called when the child terminates.
[ "This", "is", "called", "when", "the", "child", "terminates", "." ]
def processEnded(self, status): """ This is called when the child terminates. """ self.status = status self.lostProcess += 1 self.pid = None self._callProcessExited(self._getReason(status)) self.maybeCallProcessEnded()
[ "def", "processEnded", "(", "self", ",", "status", ")", ":", "self", ".", "status", "=", "status", "self", ".", "lostProcess", "+=", "1", "self", ".", "pid", "=", "None", "self", ".", "_callProcessExited", "(", "self", ".", "_getReason", "(", "status", ...
https://github.com/wistbean/learn_python3_spider/blob/73c873f4845f4385f097e5057407d03dd37a117b/stackoverflow/venv/lib/python3.6/site-packages/twisted/internet/_baseprocess.py#L44-L52
bruderstein/PythonScript
df9f7071ddf3a079e3a301b9b53a6dc78cf1208f
PythonLib/full/pprint.py
python
_safe_tuple
(t)
return _safe_key(t[0]), _safe_key(t[1])
Helper function for comparing 2-tuples
Helper function for comparing 2-tuples
[ "Helper", "function", "for", "comparing", "2", "-", "tuples" ]
def _safe_tuple(t): "Helper function for comparing 2-tuples" return _safe_key(t[0]), _safe_key(t[1])
[ "def", "_safe_tuple", "(", "t", ")", ":", "return", "_safe_key", "(", "t", "[", "0", "]", ")", ",", "_safe_key", "(", "t", "[", "1", "]", ")" ]
https://github.com/bruderstein/PythonScript/blob/df9f7071ddf3a079e3a301b9b53a6dc78cf1208f/PythonLib/full/pprint.py#L102-L104
leuchine/S-LSTM
fd9462efbd7f577d7f89c2bc1d64f6c477416746
sequence_tagging/model/ner_model.py
python
NERModel.add_logits_op
(self)
Defines self.logits For each word in each sentence of the batch, it corresponds to a vector of scores, of dimension equal to the number of tags.
Defines self.logits
[ "Defines", "self", ".", "logits" ]
def add_logits_op(self): """Defines self.logits For each word in each sentence of the batch, it corresponds to a vector of scores, of dimension equal to the number of tags. """ print("Using model: "+self.config.model_type) if self.config.model_type=='slstm': self.create_layers_two_gates() elif self.config.model_type=='lstm': self.lstm_layer()
[ "def", "add_logits_op", "(", "self", ")", ":", "print", "(", "\"Using model: \"", "+", "self", ".", "config", ".", "model_type", ")", "if", "self", ".", "config", ".", "model_type", "==", "'slstm'", ":", "self", ".", "create_layers_two_gates", "(", ")", "e...
https://github.com/leuchine/S-LSTM/blob/fd9462efbd7f577d7f89c2bc1d64f6c477416746/sequence_tagging/model/ner_model.py#L442-L452
entropy1337/infernal-twin
10995cd03312e39a48ade0f114ebb0ae3a711bb8
Modules/build/pip/pip/_vendor/cachecontrol/heuristics.py
python
BaseHeuristic.update_headers
(self, response)
return {}
Update the response headers with any new headers. NOTE: This SHOULD always include some Warning header to signify that the response was cached by the client, not by way of the provided headers.
Update the response headers with any new headers.
[ "Update", "the", "response", "headers", "with", "any", "new", "headers", "." ]
def update_headers(self, response): """Update the response headers with any new headers. NOTE: This SHOULD always include some Warning header to signify that the response was cached by the client, not by way of the provided headers. """ return {}
[ "def", "update_headers", "(", "self", ",", "response", ")", ":", "return", "{", "}" ]
https://github.com/entropy1337/infernal-twin/blob/10995cd03312e39a48ade0f114ebb0ae3a711bb8/Modules/build/pip/pip/_vendor/cachecontrol/heuristics.py#L33-L40
IronLanguages/main
a949455434b1fda8c783289e897e78a9a0caabb5
External.LCA_RESTRICTED/Languages/CPython/27/Lib/idlelib/AutoComplete.py
python
AutoComplete.get_entity
(self, name)
return eval(name, namespace)
Lookup name in a namespace spanning sys.modules and __main.dict__
Lookup name in a namespace spanning sys.modules and __main.dict__
[ "Lookup", "name", "in", "a", "namespace", "spanning", "sys", ".", "modules", "and", "__main", ".", "dict__" ]
def get_entity(self, name): """Lookup name in a namespace spanning sys.modules and __main.dict__""" namespace = sys.modules.copy() namespace.update(__main__.__dict__) return eval(name, namespace)
[ "def", "get_entity", "(", "self", ",", "name", ")", ":", "namespace", "=", "sys", ".", "modules", ".", "copy", "(", ")", "namespace", ".", "update", "(", "__main__", ".", "__dict__", ")", "return", "eval", "(", "name", ",", "namespace", ")" ]
https://github.com/IronLanguages/main/blob/a949455434b1fda8c783289e897e78a9a0caabb5/External.LCA_RESTRICTED/Languages/CPython/27/Lib/idlelib/AutoComplete.py#L225-L229
erocarrera/pefile
bdcafa7f5d6564067330731af15a6141c57d1a61
pefile.py
python
PE.parse_resource_entry
(self, rva)
return resource
Parse a directory entry from the resources directory.
Parse a directory entry from the resources directory.
[ "Parse", "a", "directory", "entry", "from", "the", "resources", "directory", "." ]
def parse_resource_entry(self, rva): """Parse a directory entry from the resources directory.""" try: data = self.get_data( rva, Structure(self.__IMAGE_RESOURCE_DIRECTORY_ENTRY_format__).sizeof() ) except PEFormatError: # A warning will be added by the caller if this method returns None return None resource = self.__unpack_data__( self.__IMAGE_RESOURCE_DIRECTORY_ENTRY_format__, data, file_offset=self.get_offset_from_rva(rva), ) if resource is None: return None # resource.NameIsString = (resource.Name & 0x80000000L) >> 31 resource.NameOffset = resource.Name & 0x7FFFFFFF resource.__pad = resource.Name & 0xFFFF0000 resource.Id = resource.Name & 0x0000FFFF resource.DataIsDirectory = (resource.OffsetToData & 0x80000000) >> 31 resource.OffsetToDirectory = resource.OffsetToData & 0x7FFFFFFF return resource
[ "def", "parse_resource_entry", "(", "self", ",", "rva", ")", ":", "try", ":", "data", "=", "self", ".", "get_data", "(", "rva", ",", "Structure", "(", "self", ".", "__IMAGE_RESOURCE_DIRECTORY_ENTRY_format__", ")", ".", "sizeof", "(", ")", ")", "except", "P...
https://github.com/erocarrera/pefile/blob/bdcafa7f5d6564067330731af15a6141c57d1a61/pefile.py#L4437-L4466
khanhnamle1994/natural-language-processing
01d450d5ac002b0156ef4cf93a07cb508c1bcdc5
assignment1/.env/lib/python2.7/site-packages/pip/_vendor/ipaddress.py
python
v6_int_to_packed
(address)
Represent an address as 16 packed bytes in network (big-endian) order. Args: address: An integer representation of an IPv6 IP address. Returns: The integer address packed as 16 bytes in network (big-endian) order.
Represent an address as 16 packed bytes in network (big-endian) order.
[ "Represent", "an", "address", "as", "16", "packed", "bytes", "in", "network", "(", "big", "-", "endian", ")", "order", "." ]
def v6_int_to_packed(address): """Represent an address as 16 packed bytes in network (big-endian) order. Args: address: An integer representation of an IPv6 IP address. Returns: The integer address packed as 16 bytes in network (big-endian) order. """ try: return _compat_to_bytes(address, 16, 'big') except (struct.error, OverflowError): raise ValueError("Address negative or too large for IPv6")
[ "def", "v6_int_to_packed", "(", "address", ")", ":", "try", ":", "return", "_compat_to_bytes", "(", "address", ",", "16", ",", "'big'", ")", "except", "(", "struct", ".", "error", ",", "OverflowError", ")", ":", "raise", "ValueError", "(", "\"Address negativ...
https://github.com/khanhnamle1994/natural-language-processing/blob/01d450d5ac002b0156ef4cf93a07cb508c1bcdc5/assignment1/.env/lib/python2.7/site-packages/pip/_vendor/ipaddress.py#L260-L273
boto/boto
b2a6f08122b2f1b89888d2848e730893595cd001
boto/cloudsearch2/layer1.py
python
CloudSearchConnection.delete_analysis_scheme
(self, domain_name, analysis_scheme_name)
return self._make_request( action='DeleteAnalysisScheme', verb='POST', path='/', params=params)
Deletes an analysis scheme. For more information, see `Configuring Analysis Schemes`_ in the Amazon CloudSearch Developer Guide . :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names are unique across the domains owned by an account within an AWS region. Domain names start with a letter or number and can contain the following characters: a-z (lowercase), 0-9, and - (hyphen). :type analysis_scheme_name: string :param analysis_scheme_name: The name of the analysis scheme you want to delete.
Deletes an analysis scheme. For more information, see `Configuring Analysis Schemes`_ in the Amazon CloudSearch Developer Guide .
[ "Deletes", "an", "analysis", "scheme", ".", "For", "more", "information", "see", "Configuring", "Analysis", "Schemes", "_", "in", "the", "Amazon", "CloudSearch", "Developer", "Guide", "." ]
def delete_analysis_scheme(self, domain_name, analysis_scheme_name): """ Deletes an analysis scheme. For more information, see `Configuring Analysis Schemes`_ in the Amazon CloudSearch Developer Guide . :type domain_name: string :param domain_name: A string that represents the name of a domain. Domain names are unique across the domains owned by an account within an AWS region. Domain names start with a letter or number and can contain the following characters: a-z (lowercase), 0-9, and - (hyphen). :type analysis_scheme_name: string :param analysis_scheme_name: The name of the analysis scheme you want to delete. """ params = { 'DomainName': domain_name, 'AnalysisSchemeName': analysis_scheme_name, } return self._make_request( action='DeleteAnalysisScheme', verb='POST', path='/', params=params)
[ "def", "delete_analysis_scheme", "(", "self", ",", "domain_name", ",", "analysis_scheme_name", ")", ":", "params", "=", "{", "'DomainName'", ":", "domain_name", ",", "'AnalysisSchemeName'", ":", "analysis_scheme_name", ",", "}", "return", "self", ".", "_make_request...
https://github.com/boto/boto/blob/b2a6f08122b2f1b89888d2848e730893595cd001/boto/cloudsearch2/layer1.py#L238-L263
ibis-project/ibis
e1ef8b6870ac53de9d1fe5c52851fa41872109c4
ibis/backends/impala/client.py
python
ImpalaConnection.close
(self)
Close all open Impyla sessions
Close all open Impyla sessions
[ "Close", "all", "open", "Impyla", "sessions" ]
def close(self): """ Close all open Impyla sessions """ for impyla_connection in self._connections: impyla_connection.close() self._connections.clear() self.connection_pool.clear()
[ "def", "close", "(", "self", ")", ":", "for", "impyla_connection", "in", "self", ".", "_connections", ":", "impyla_connection", ".", "close", "(", ")", "self", ".", "_connections", ".", "clear", "(", ")", "self", ".", "connection_pool", ".", "clear", "(", ...
https://github.com/ibis-project/ibis/blob/e1ef8b6870ac53de9d1fe5c52851fa41872109c4/ibis/backends/impala/client.py#L65-L73
huawei-noah/vega
d9f13deede7f2b584e4b1d32ffdb833856129989
vega/algorithms/nas/auto_lane/utils/resnext_all_variant_codec.py
python
ResNeXt_all_Variant.__str__
(self)
return self.arch_code
Repr.
Repr.
[ "Repr", "." ]
def __str__(self): """Repr.""" return self.arch_code
[ "def", "__str__", "(", "self", ")", ":", "return", "self", ".", "arch_code" ]
https://github.com/huawei-noah/vega/blob/d9f13deede7f2b584e4b1d32ffdb833856129989/vega/algorithms/nas/auto_lane/utils/resnext_all_variant_codec.py#L64-L66
alberanid/imdbpy
88cf37772186e275eff212857f512669086b382c
bin/imdbpy2sql.py
python
readMovieList
()
Read the movies.list.gz file.
Read the movies.list.gz file.
[ "Read", "the", "movies", ".", "list", ".", "gz", "file", "." ]
def readMovieList(): """Read the movies.list.gz file.""" try: mdbf = SourceFile(MOVIES, start=MOVIES_START, stop=MOVIES_STOP) except IOError: return count = 0 for line in mdbf: line_d = unpack(line, ('title', 'year')) title = line_d['title'] yearData = None # Collect 'year' column for tv "series years" and episodes' year. if title[0] == '"': yearData = [('movieYear', line_d['year'])] mid = CACHE_MID.addUnique(title, yearData) if mid is None: continue if count % 10000 == 0: print('SCANNING movies:', _(title), end=' ') print('(movieID: %s)' % mid) count += 1 CACHE_MID.flush() CACHE_MID.movieYear.clear() mdbf.close()
[ "def", "readMovieList", "(", ")", ":", "try", ":", "mdbf", "=", "SourceFile", "(", "MOVIES", ",", "start", "=", "MOVIES_START", ",", "stop", "=", "MOVIES_STOP", ")", "except", "IOError", ":", "return", "count", "=", "0", "for", "line", "in", "mdbf", ":...
https://github.com/alberanid/imdbpy/blob/88cf37772186e275eff212857f512669086b382c/bin/imdbpy2sql.py#L1546-L1569
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/lib/python2.7/site-packages/pip/_vendor/packaging/version.py
python
LegacyVersion.public
(self)
return self._version
[]
def public(self): return self._version
[ "def", "public", "(", "self", ")", ":", "return", "self", ".", "_version" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/lib/python2.7/site-packages/pip/_vendor/packaging/version.py#L85-L86
stopstalk/stopstalk-deployment
10c3ab44c4ece33ae515f6888c15033db2004bb1
aws_lambda/spoj_aws_lambda_function/lambda_code/setuptools/_vendor/pyparsing.py
python
ParserElement.searchString
( self, instring, maxMatches=_MAX_INT )
Another extension to C{L{scanString}}, simplifying the access to the tokens found to match the given parse expression. May be called with optional C{maxMatches} argument, to clip searching after 'n' matches are found. Example:: # a capitalized word starts with an uppercase letter, followed by zero or more lowercase letters cap_word = Word(alphas.upper(), alphas.lower()) print(cap_word.searchString("More than Iron, more than Lead, more than Gold I need Electricity")) # the sum() builtin can be used to merge results into a single ParseResults object print(sum(cap_word.searchString("More than Iron, more than Lead, more than Gold I need Electricity"))) prints:: [['More'], ['Iron'], ['Lead'], ['Gold'], ['I'], ['Electricity']] ['More', 'Iron', 'Lead', 'Gold', 'I', 'Electricity']
Another extension to C{L{scanString}}, simplifying the access to the tokens found to match the given parse expression. May be called with optional C{maxMatches} argument, to clip searching after 'n' matches are found. Example:: # a capitalized word starts with an uppercase letter, followed by zero or more lowercase letters cap_word = Word(alphas.upper(), alphas.lower()) print(cap_word.searchString("More than Iron, more than Lead, more than Gold I need Electricity"))
[ "Another", "extension", "to", "C", "{", "L", "{", "scanString", "}}", "simplifying", "the", "access", "to", "the", "tokens", "found", "to", "match", "the", "given", "parse", "expression", ".", "May", "be", "called", "with", "optional", "C", "{", "maxMatche...
def searchString( self, instring, maxMatches=_MAX_INT ): """ Another extension to C{L{scanString}}, simplifying the access to the tokens found to match the given parse expression. May be called with optional C{maxMatches} argument, to clip searching after 'n' matches are found. Example:: # a capitalized word starts with an uppercase letter, followed by zero or more lowercase letters cap_word = Word(alphas.upper(), alphas.lower()) print(cap_word.searchString("More than Iron, more than Lead, more than Gold I need Electricity")) # the sum() builtin can be used to merge results into a single ParseResults object print(sum(cap_word.searchString("More than Iron, more than Lead, more than Gold I need Electricity"))) prints:: [['More'], ['Iron'], ['Lead'], ['Gold'], ['I'], ['Electricity']] ['More', 'Iron', 'Lead', 'Gold', 'I', 'Electricity'] """ try: return ParseResults([ t for t,s,e in self.scanString( instring, maxMatches ) ]) except ParseBaseException as exc: if ParserElement.verbose_stacktrace: raise else: # catch and re-raise exception from here, clears out pyparsing internal stack trace raise exc
[ "def", "searchString", "(", "self", ",", "instring", ",", "maxMatches", "=", "_MAX_INT", ")", ":", "try", ":", "return", "ParseResults", "(", "[", "t", "for", "t", ",", "s", ",", "e", "in", "self", ".", "scanString", "(", "instring", ",", "maxMatches",...
https://github.com/stopstalk/stopstalk-deployment/blob/10c3ab44c4ece33ae515f6888c15033db2004bb1/aws_lambda/spoj_aws_lambda_function/lambda_code/setuptools/_vendor/pyparsing.py#L1772-L1797
PyOCL/OpenCLGA
8192a337d5317795b5d4f1d5c9b76299bf4c4df4
examples/taiwan_travel/taiwan_travel_server.py
python
get_taiwan_travel_info
()
return dict_info
NOTE : Config TaiwanTravel GA parameters in dictionary 'dict_info'.
NOTE : Config TaiwanTravel GA parameters in dictionary 'dict_info'.
[ "NOTE", ":", "Config", "TaiwanTravel", "GA", "parameters", "in", "dictionary", "dict_info", "." ]
def get_taiwan_travel_info(): ''' NOTE : Config TaiwanTravel GA parameters in dictionary 'dict_info'. ''' cities, city_info, city_infoX, city_infoY = read_all_cities('TW319_368Addresses-no-far-islands.json') city_ids = list(range(len(cities))) random.seed() tsp_path = os.path.dirname(os.path.abspath(__file__)) tsp_kernels = os.path.join(tsp_path, 'kernel') sample = ShufflerChromosome([SimpleGene(v, cities) for v in city_ids]) f = open(os.path.join(tsp_kernels, 'taiwan_fitness.cl'), 'r') fstr = ''.join(f.readlines()) f.close() # It seems we don't need to use this helper if we enlarge the population size. Please # re-evaluate and remove or uncomment the following line: # sample.use_improving_only_mutation('improving_only_mutation_helper') dict_info = { 'sample_chromosome' : sample, 'termination' : { 'type' : 'count', 'count' : 100 }, 'population' : 10240, 'fitness_kernel_str' : fstr, 'fitness_func' : 'taiwan_fitness', 'fitness_args' : [{ 't' : 'float', 'v' : city_infoX, 'n' : 'x' }, { 't' : 'float', 'v' : city_infoY, 'n' : 'y' }], 'opt_for_max' : 'min', 'saved_filename' : 'test%d%d.pickle', 'prob_mutation' : 0.1, 'prob_crossover' : 0.8, 'extinction' : { 'type' : 'best_avg', 'diff' : 1, 'ratio' : 0.9 }, 'elitism_mode' : { 'every' : 2, 'interval' : 10, 'compress' : False }, 'serializer': serializer} return dict_info
[ "def", "get_taiwan_travel_info", "(", ")", ":", "cities", ",", "city_info", ",", "city_infoX", ",", "city_infoY", "=", "read_all_cities", "(", "'TW319_368Addresses-no-far-islands.json'", ")", "city_ids", "=", "list", "(", "range", "(", "len", "(", "cities", ")", ...
https://github.com/PyOCL/OpenCLGA/blob/8192a337d5317795b5d4f1d5c9b76299bf4c4df4/examples/taiwan_travel/taiwan_travel_server.py#L43-L79
pythonarcade/arcade
1ee3eb1900683213e8e8df93943327c2ea784564
doc/tutorials/pymunk_platformer/pymunk_demo_platformer_11.py
python
GameWindow.setup
(self)
Set up everything with the game
Set up everything with the game
[ "Set", "up", "everything", "with", "the", "game" ]
def setup(self): """ Set up everything with the game """ # Create the sprite lists self.player_list = arcade.SpriteList() self.bullet_list = arcade.SpriteList() # Map name map_name = "pymunk_test_map.json" # Load in TileMap tile_map = arcade.load_tilemap(map_name, SPRITE_SCALING_TILES) # Pull the sprite layers out of the tile map self.wall_list = tile_map.sprite_lists["Platforms"] self.item_list = tile_map.sprite_lists["Dynamic Items"] # Create player sprite self.player_sprite = PlayerSprite() # Set player location grid_x = 1 grid_y = 1 self.player_sprite.center_x = SPRITE_SIZE * grid_x + SPRITE_SIZE / 2 self.player_sprite.center_y = SPRITE_SIZE * grid_y + SPRITE_SIZE / 2 # Add to player sprite list self.player_list.append(self.player_sprite) # Moving Sprite self.moving_sprites_list = arcade.tilemap.process_layer(my_map, 'Moving Platforms', SPRITE_SCALING_TILES) # --- Pymunk Physics Engine Setup --- # The default damping for every object controls the percent of velocity # the object will keep each second. A value of 1.0 is no speed loss, # 0.9 is 10% per second, 0.1 is 90% per second. # For top-down games, this is basically the friction for moving objects. # For platformers with gravity, this should probably be set to 1.0. # Default value is 1.0 if not specified. damping = DEFAULT_DAMPING # Set the gravity. (0, 0) is good for outer space and top-down. gravity = (0, -GRAVITY) # Create the physics engine self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, gravity=gravity) def wall_hit_handler(bullet_sprite, _wall_sprite, _arbiter, _space, _data): """ Called for bullet/wall collision """ bullet_sprite.remove_from_sprite_lists() self.physics_engine.add_collision_handler("bullet", "wall", post_handler=wall_hit_handler) def item_hit_handler(bullet_sprite, item_sprite, _arbiter, _space, _data): """ Called for bullet/wall collision """ bullet_sprite.remove_from_sprite_lists() item_sprite.remove_from_sprite_lists() self.physics_engine.add_collision_handler("bullet", "item", post_handler=item_hit_handler) # Add the player. # For the player, we set the damping to a lower value, which increases # the damping rate. This prevents the character from traveling too far # after the player lets off the movement keys. # Setting the moment to PymunkPhysicsEngine.MOMENT_INF prevents it from # rotating. # Friction normally goes between 0 (no friction) and 1.0 (high friction) # Friction is between two objects in contact. It is important to remember # in top-down games that friction moving along the 'floor' is controlled # by damping. self.physics_engine.add_sprite(self.player_sprite, friction=PLAYER_FRICTION, mass=PLAYER_MASS, moment=arcade.PymunkPhysicsEngine.MOMENT_INF, collision_type="player", max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED) # Create the walls. # By setting the body type to PymunkPhysicsEngine.STATIC the walls can't # move. # Movable objects that respond to forces are PymunkPhysicsEngine.DYNAMIC # PymunkPhysicsEngine.KINEMATIC objects will move, but are assumed to be # repositioned by code and don't respond to physics forces. # Dynamic is default. self.physics_engine.add_sprite_list(self.wall_list, friction=WALL_FRICTION, collision_type="wall", body_type=arcade.PymunkPhysicsEngine.STATIC) # Create the items self.physics_engine.add_sprite_list(self.item_list, friction=DYNAMIC_ITEM_FRICTION, collision_type="item") # Add kinematic sprites self.physics_engine.add_sprite_list(self.moving_sprites_list, body_type=arcade.PymunkPhysicsEngine.KINEMATIC)
[ "def", "setup", "(", "self", ")", ":", "# Create the sprite lists", "self", ".", "player_list", "=", "arcade", ".", "SpriteList", "(", ")", "self", ".", "bullet_list", "=", "arcade", ".", "SpriteList", "(", ")", "# Map name", "map_name", "=", "\"pymunk_test_ma...
https://github.com/pythonarcade/arcade/blob/1ee3eb1900683213e8e8df93943327c2ea784564/doc/tutorials/pymunk_platformer/pymunk_demo_platformer_11.py#L201-L301
christabor/flask_jsondash
c8984790722327e86694e15409ff4dea0621aab0
example_app/endpoints.py
python
dtable
()
return jsonify({})
Fake endpoint.
Fake endpoint.
[ "Fake", "endpoint", "." ]
def dtable(): """Fake endpoint.""" if 'stress' in request.args: return jsonify([ dict( foo=rr(1, 1000), bar=rr(1, 1000), baz=rr(1, 1000), quux=rr(1, 1000)) for _ in range(STRESS_MAX_POINTS) ]) fname = 'dtable-override' if 'override' in request.args else 'dtable' with open('{}/examples/{}.json'.format(os.getcwd(), fname), 'r') as djson: return djson.read() return jsonify({})
[ "def", "dtable", "(", ")", ":", "if", "'stress'", "in", "request", ".", "args", ":", "return", "jsonify", "(", "[", "dict", "(", "foo", "=", "rr", "(", "1", ",", "1000", ")", ",", "bar", "=", "rr", "(", "1", ",", "1000", ")", ",", "baz", "=",...
https://github.com/christabor/flask_jsondash/blob/c8984790722327e86694e15409ff4dea0621aab0/example_app/endpoints.py#L384-L397
YaoZeyuan/ZhihuHelp_archived
a0e4a7acd4512452022ce088fff2adc6f8d30195
src/lib/requests/packages/urllib3/packages/ssl_match_hostname/_implementation.py
python
match_hostname
(cert, hostname)
Verify that *cert* (in decoded format as returned by SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 and RFC 6125 rules are followed, but IP addresses are not accepted for *hostname*. CertificateError is raised on failure. On success, the function returns nothing.
Verify that *cert* (in decoded format as returned by SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 and RFC 6125 rules are followed, but IP addresses are not accepted for *hostname*.
[ "Verify", "that", "*", "cert", "*", "(", "in", "decoded", "format", "as", "returned", "by", "SSLSocket", ".", "getpeercert", "()", ")", "matches", "the", "*", "hostname", "*", ".", "RFC", "2818", "and", "RFC", "6125", "rules", "are", "followed", "but", ...
def match_hostname(cert, hostname): """Verify that *cert* (in decoded format as returned by SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 and RFC 6125 rules are followed, but IP addresses are not accepted for *hostname*. CertificateError is raised on failure. On success, the function returns nothing. """ if not cert: raise ValueError("empty or no certificate") dnsnames = [] san = cert.get('subjectAltName', ()) for key, value in san: if key == 'DNS': if _dnsname_match(value, hostname): return dnsnames.append(value) if not dnsnames: # The subject is only checked when there is no dNSName entry # in subjectAltName for sub in cert.get('subject', ()): for key, value in sub: # XXX according to RFC 2818, the most specific Common Name # must be used. if key == 'commonName': if _dnsname_match(value, hostname): return dnsnames.append(value) if len(dnsnames) > 1: raise CertificateError("hostname %r " "doesn't match either of %s" % (hostname, ', '.join(map(repr, dnsnames)))) elif len(dnsnames) == 1: raise CertificateError("hostname %r " "doesn't match %r" % (hostname, dnsnames[0])) else: raise CertificateError("no appropriate commonName or " "subjectAltName fields were found")
[ "def", "match_hostname", "(", "cert", ",", "hostname", ")", ":", "if", "not", "cert", ":", "raise", "ValueError", "(", "\"empty or no certificate\"", ")", "dnsnames", "=", "[", "]", "san", "=", "cert", ".", "get", "(", "'subjectAltName'", ",", "(", ")", ...
https://github.com/YaoZeyuan/ZhihuHelp_archived/blob/a0e4a7acd4512452022ce088fff2adc6f8d30195/src/lib/requests/packages/urllib3/packages/ssl_match_hostname/_implementation.py#L67-L105
emesene/emesene
4548a4098310e21b16437bb36223a7f632a4f7bc
emesene/e3/xmpp/SleekXMPP/sleekxmpp/roster/item.py
python
RosterItem.handle_unsubscribe
(self, presence)
+------------------------------------------------------------------+ | EXISTING STATE | DELIVER? | NEW STATE | +------------------------------------------------------------------+ | "None" | no | no state change | | "None + Pending Out" | no | no state change | | "None + Pending In" | yes * | "None" | | "None + Pending Out/In" | yes * | "None + Pending Out" | | "To" | no | no state change | | "To + Pending In" | yes * | "To" | | "From" | yes * | "None" | | "From + Pending Out" | yes * | "None + Pending Out | | "Both" | yes * | "To" | +------------------------------------------------------------------+
+------------------------------------------------------------------+ | EXISTING STATE | DELIVER? | NEW STATE | +------------------------------------------------------------------+ | "None" | no | no state change | | "None + Pending Out" | no | no state change | | "None + Pending In" | yes * | "None" | | "None + Pending Out/In" | yes * | "None + Pending Out" | | "To" | no | no state change | | "To + Pending In" | yes * | "To" | | "From" | yes * | "None" | | "From + Pending Out" | yes * | "None + Pending Out | | "Both" | yes * | "To" | +------------------------------------------------------------------+
[ "+", "------------------------------------------------------------------", "+", "|", "EXISTING", "STATE", "|", "DELIVER?", "|", "NEW", "STATE", "|", "+", "------------------------------------------------------------------", "+", "|", "None", "|", "no", "|", "no", "state", ...
def handle_unsubscribe(self, presence): """ +------------------------------------------------------------------+ | EXISTING STATE | DELIVER? | NEW STATE | +------------------------------------------------------------------+ | "None" | no | no state change | | "None + Pending Out" | no | no state change | | "None + Pending In" | yes * | "None" | | "None + Pending Out/In" | yes * | "None + Pending Out" | | "To" | no | no state change | | "To + Pending In" | yes * | "To" | | "From" | yes * | "None" | | "From + Pending Out" | yes * | "None + Pending Out | | "Both" | yes * | "To" | +------------------------------------------------------------------+ """ if self.xmpp.is_component: if not self['from'] and self['pending_in']: self['pending_in'] = False self._unsubscribed() elif self['from']: self['from'] = False self._unsubscribed() self.xmpp.event('roster_subscription_remove', presence) self.save() else: self.xmpp.event('roster_subscription_remove', presence)
[ "def", "handle_unsubscribe", "(", "self", ",", "presence", ")", ":", "if", "self", ".", "xmpp", ".", "is_component", ":", "if", "not", "self", "[", "'from'", "]", "and", "self", "[", "'pending_in'", "]", ":", "self", "[", "'pending_in'", "]", "=", "Fal...
https://github.com/emesene/emesene/blob/4548a4098310e21b16437bb36223a7f632a4f7bc/emesene/e3/xmpp/SleekXMPP/sleekxmpp/roster/item.py#L427-L453
Calysto/calysto_scheme
15bf81987870bcae1264e5a0a06feb9a8ee12b8b
calysto_scheme/scheme.py
python
b_cont2_103_d
(src, tokens_left, env2, handler, k)
[]
def b_cont2_103_d(src, tokens_left, env2, handler, k): GLOBALS['k_reg'] = make_cont2(b_cont2_102_d, src, tokens_left, env2, handler, k) GLOBALS['fail_reg'] = value2_reg GLOBALS['handler_reg'] = handler GLOBALS['env_reg'] = env2 GLOBALS['exp_reg'] = value1_reg GLOBALS['pc'] = m
[ "def", "b_cont2_103_d", "(", "src", ",", "tokens_left", ",", "env2", ",", "handler", ",", "k", ")", ":", "GLOBALS", "[", "'k_reg'", "]", "=", "make_cont2", "(", "b_cont2_102_d", ",", "src", ",", "tokens_left", ",", "env2", ",", "handler", ",", "k", ")"...
https://github.com/Calysto/calysto_scheme/blob/15bf81987870bcae1264e5a0a06feb9a8ee12b8b/calysto_scheme/scheme.py#L3125-L3131
huggingface/transformers
623b4f7c63f60cce917677ee704d6c93ee960b4b
src/transformers/trainer_callback.py
python
ProgressCallback.on_train_begin
(self, args, state, control, **kwargs)
[]
def on_train_begin(self, args, state, control, **kwargs): if state.is_local_process_zero: self.training_bar = tqdm(total=state.max_steps) self.current_step = 0
[ "def", "on_train_begin", "(", "self", ",", "args", ",", "state", ",", "control", ",", "*", "*", "kwargs", ")", ":", "if", "state", ".", "is_local_process_zero", ":", "self", ".", "training_bar", "=", "tqdm", "(", "total", "=", "state", ".", "max_steps", ...
https://github.com/huggingface/transformers/blob/623b4f7c63f60cce917677ee704d6c93ee960b4b/src/transformers/trainer_callback.py#L462-L465
khanhnamle1994/natural-language-processing
01d450d5ac002b0156ef4cf93a07cb508c1bcdc5
assignment1/.env/lib/python2.7/site-packages/IPython/utils/sysinfo.py
python
get_sys_info
()
return pkg_info(path)
Return useful information about IPython and the system, as a dict.
Return useful information about IPython and the system, as a dict.
[ "Return", "useful", "information", "about", "IPython", "and", "the", "system", "as", "a", "dict", "." ]
def get_sys_info(): """Return useful information about IPython and the system, as a dict.""" p = os.path path = p.dirname(p.abspath(p.join(__file__, '..'))) return pkg_info(path)
[ "def", "get_sys_info", "(", ")", ":", "p", "=", "os", ".", "path", "path", "=", "p", ".", "dirname", "(", "p", ".", "abspath", "(", "p", ".", "join", "(", "__file__", ",", "'..'", ")", ")", ")", "return", "pkg_info", "(", "path", ")" ]
https://github.com/khanhnamle1994/natural-language-processing/blob/01d450d5ac002b0156ef4cf93a07cb508c1bcdc5/assignment1/.env/lib/python2.7/site-packages/IPython/utils/sysinfo.py#L95-L99
minio/minio-py
b3ba3bf99fe6b9ff2b28855550d6ab5345c134e3
minio/deleteobjects.py
python
DeleteRequest.toxml
(self, element)
return element
Convert to XML.
Convert to XML.
[ "Convert", "to", "XML", "." ]
def toxml(self, element): """Convert to XML.""" element = Element("Delete") if self._quiet: SubElement(element, "Quiet", str(self._quiet)) for obj in self._object_list: obj.toxml(element) return element
[ "def", "toxml", "(", "self", ",", "element", ")", ":", "element", "=", "Element", "(", "\"Delete\"", ")", "if", "self", ".", "_quiet", ":", "SubElement", "(", "element", ",", "\"Quiet\"", ",", "str", "(", "self", ".", "_quiet", ")", ")", "for", "obj"...
https://github.com/minio/minio-py/blob/b3ba3bf99fe6b9ff2b28855550d6ab5345c134e3/minio/deleteobjects.py#L47-L54
mautrix/telegram
9f48eca5a6654bc38012cb761ecaaaf416aabdd0
mautrix_telegram/db/upgrade/v02_sponsored_events.py
python
upgrade_v2
(conn: Connection)
[]
async def upgrade_v2(conn: Connection) -> None: await conn.execute("ALTER TABLE portal ADD COLUMN sponsored_event_id TEXT") await conn.execute("ALTER TABLE portal ADD COLUMN sponsored_event_ts BIGINT") await conn.execute("ALTER TABLE portal ADD COLUMN sponsored_msg_random_id bytea")
[ "async", "def", "upgrade_v2", "(", "conn", ":", "Connection", ")", "->", "None", ":", "await", "conn", ".", "execute", "(", "\"ALTER TABLE portal ADD COLUMN sponsored_event_id TEXT\"", ")", "await", "conn", ".", "execute", "(", "\"ALTER TABLE portal ADD COLUMN sponsored...
https://github.com/mautrix/telegram/blob/9f48eca5a6654bc38012cb761ecaaaf416aabdd0/mautrix_telegram/db/upgrade/v02_sponsored_events.py#L22-L25
entropy1337/infernal-twin
10995cd03312e39a48ade0f114ebb0ae3a711bb8
Modules/build/reportlab/build/lib.linux-i686-2.7/reportlab/graphics/shapes.py
python
_renderPath
(path, drawFuncs)
return hadMoveTo == hadClosePath
Helper function for renderers.
Helper function for renderers.
[ "Helper", "function", "for", "renderers", "." ]
def _renderPath(path, drawFuncs): """Helper function for renderers.""" # this could be a method of Path... points = path.points i = 0 hadClosePath = 0 hadMoveTo = 0 for op in path.operators: nArgs = _PATH_OP_ARG_COUNT[op] func = drawFuncs[op] j = i + nArgs func(*points[i:j]) i = j if op == _CLOSEPATH: hadClosePath = hadClosePath + 1 if op == _MOVETO: hadMoveTo += 1 return hadMoveTo == hadClosePath
[ "def", "_renderPath", "(", "path", ",", "drawFuncs", ")", ":", "# this could be a method of Path...", "points", "=", "path", ".", "points", "i", "=", "0", "hadClosePath", "=", "0", "hadMoveTo", "=", "0", "for", "op", "in", "path", ".", "operators", ":", "n...
https://github.com/entropy1337/infernal-twin/blob/10995cd03312e39a48ade0f114ebb0ae3a711bb8/Modules/build/reportlab/build/lib.linux-i686-2.7/reportlab/graphics/shapes.py#L963-L980
saltstack/salt
fae5bc757ad0f1716483ce7ae180b451545c2058
salt/utils/win_runas.py
python
runas
(cmdLine, username, password=None, cwd=None)
return ret
Run a command as another user. If the process is running as an admin or system account this method does not require a password. Other non privileged accounts need to provide a password for the user to runas. Commands are run in with the highest level privileges possible for the account provided.
Run a command as another user. If the process is running as an admin or system account this method does not require a password. Other non privileged accounts need to provide a password for the user to runas. Commands are run in with the highest level privileges possible for the account provided.
[ "Run", "a", "command", "as", "another", "user", ".", "If", "the", "process", "is", "running", "as", "an", "admin", "or", "system", "account", "this", "method", "does", "not", "require", "a", "password", ".", "Other", "non", "privileged", "accounts", "need"...
def runas(cmdLine, username, password=None, cwd=None): """ Run a command as another user. If the process is running as an admin or system account this method does not require a password. Other non privileged accounts need to provide a password for the user to runas. Commands are run in with the highest level privileges possible for the account provided. """ # Validate the domain and sid exist for the username username, domain = split_username(username) try: _, domain, _ = win32security.LookupAccountName(domain, username) except pywintypes.error as exc: message = win32api.FormatMessage(exc.winerror).rstrip("\n") raise CommandExecutionError(message) # Elevate the token from the current process access = win32security.TOKEN_QUERY | win32security.TOKEN_ADJUST_PRIVILEGES th = win32security.OpenProcessToken(win32api.GetCurrentProcess(), access) salt.platform.win.elevate_token(th) # Try to impersonate the SYSTEM user. This process needs to be running as a # user who as been granted the SeImpersonatePrivilege, Administrator # accounts have this permission by default. try: impersonation_token = salt.platform.win.impersonate_sid( salt.platform.win.SYSTEM_SID, session_id=0, privs=["SeTcbPrivilege"], ) except OSError: log.debug("Unable to impersonate SYSTEM user") impersonation_token = None win32api.CloseHandle(th) # Impersonation of the SYSTEM user failed. Fallback to an un-privileged # runas. if not impersonation_token: log.debug("No impersonation token, using unprivileged runas") return runas_unpriv(cmdLine, username, password, cwd) if domain == "NT AUTHORITY": # Logon as a system level account, SYSTEM, LOCAL SERVICE, or NETWORK # SERVICE. user_token = win32security.LogonUser( username, domain, "", win32con.LOGON32_LOGON_SERVICE, win32con.LOGON32_PROVIDER_DEFAULT, ) elif password: # Login with a password. user_token = win32security.LogonUser( username, domain, password, win32con.LOGON32_LOGON_INTERACTIVE, win32con.LOGON32_PROVIDER_DEFAULT, ) else: # Login without a password. This always returns an elevated token. user_token = salt.platform.win.logon_msv1_s4u(username).Token # Get a linked user token to elevate if needed elevation_type = win32security.GetTokenInformation( user_token, win32security.TokenElevationType ) if elevation_type > 1: user_token = win32security.GetTokenInformation( user_token, win32security.TokenLinkedToken ) # Elevate the user token salt.platform.win.elevate_token(user_token) # Make sure the user's token has access to a windows station and desktop salt.platform.win.grant_winsta_and_desktop(user_token) # Create pipes for standard in, out and error streams security_attributes = win32security.SECURITY_ATTRIBUTES() security_attributes.bInheritHandle = 1 stdin_read, stdin_write = win32pipe.CreatePipe(security_attributes, 0) stdin_read = salt.platform.win.make_inheritable(stdin_read) stdout_read, stdout_write = win32pipe.CreatePipe(security_attributes, 0) stdout_write = salt.platform.win.make_inheritable(stdout_write) stderr_read, stderr_write = win32pipe.CreatePipe(security_attributes, 0) stderr_write = salt.platform.win.make_inheritable(stderr_write) # Run the process without showing a window. creationflags = ( win32process.CREATE_NO_WINDOW | win32process.CREATE_NEW_CONSOLE | win32process.CREATE_SUSPENDED ) startup_info = salt.platform.win.STARTUPINFO( dwFlags=win32con.STARTF_USESTDHANDLES, hStdInput=stdin_read.handle, hStdOutput=stdout_write.handle, hStdError=stderr_write.handle, ) # Create the environment for the user env = create_env(user_token, False) hProcess = None try: # Start the process in a suspended state. process_info = salt.platform.win.CreateProcessWithTokenW( int(user_token), logonflags=1, applicationname=None, commandline=cmdLine, currentdirectory=cwd, creationflags=creationflags, startupinfo=startup_info, environment=env, ) hProcess = process_info.hProcess hThread = process_info.hThread dwProcessId = process_info.dwProcessId dwThreadId = process_info.dwThreadId # We don't use these so let's close the handle salt.platform.win.kernel32.CloseHandle(stdin_write.handle) salt.platform.win.kernel32.CloseHandle(stdout_write.handle) salt.platform.win.kernel32.CloseHandle(stderr_write.handle) ret = {"pid": dwProcessId} # Resume the process psutil.Process(dwProcessId).resume() # Wait for the process to exit and get its return code. if ( win32event.WaitForSingleObject(hProcess, win32event.INFINITE) == win32con.WAIT_OBJECT_0 ): exitcode = win32process.GetExitCodeProcess(hProcess) ret["retcode"] = exitcode # Read standard out fd_out = msvcrt.open_osfhandle(stdout_read.handle, os.O_RDONLY | os.O_TEXT) with os.fdopen(fd_out, "r") as f_out: stdout = f_out.read() ret["stdout"] = stdout # Read standard error fd_err = msvcrt.open_osfhandle(stderr_read.handle, os.O_RDONLY | os.O_TEXT) with os.fdopen(fd_err, "r") as f_err: stderr = f_err.read() ret["stderr"] = stderr finally: if hProcess is not None: salt.platform.win.kernel32.CloseHandle(hProcess) win32api.CloseHandle(th) win32api.CloseHandle(user_token) if impersonation_token: win32security.RevertToSelf() win32api.CloseHandle(impersonation_token) return ret
[ "def", "runas", "(", "cmdLine", ",", "username", ",", "password", "=", "None", ",", "cwd", "=", "None", ")", ":", "# Validate the domain and sid exist for the username", "username", ",", "domain", "=", "split_username", "(", "username", ")", "try", ":", "_", "...
https://github.com/saltstack/salt/blob/fae5bc757ad0f1716483ce7ae180b451545c2058/salt/utils/win_runas.py#L85-L250
weewx/weewx
cb594fce224560bd8696050fc5c7843c7839320e
bin/weewx/manager.py
python
DaySummaryManager._read_metadata
(self, key, cursor=None)
return _row[0] if _row else None
Obtain a value from the daily summary metadata table. Returns: Value of the metadata field. Returns None if no value was found.
Obtain a value from the daily summary metadata table.
[ "Obtain", "a", "value", "from", "the", "daily", "summary", "metadata", "table", "." ]
def _read_metadata(self, key, cursor=None): """Obtain a value from the daily summary metadata table. Returns: Value of the metadata field. Returns None if no value was found. """ _row = self.getSql(DaySummaryManager.meta_select_str % self.table_name, (key,), cursor) return _row[0] if _row else None
[ "def", "_read_metadata", "(", "self", ",", "key", ",", "cursor", "=", "None", ")", ":", "_row", "=", "self", ".", "getSql", "(", "DaySummaryManager", ".", "meta_select_str", "%", "self", ".", "table_name", ",", "(", "key", ",", ")", ",", "cursor", ")",...
https://github.com/weewx/weewx/blob/cb594fce224560bd8696050fc5c7843c7839320e/bin/weewx/manager.py#L1476-L1483
JaniceWuo/MovieRecommend
4c86db64ca45598917d304f535413df3bc9fea65
movierecommend/venv1/Lib/site-packages/django/utils/translation/__init__.py
python
npgettext
(context, singular, plural, number)
return _trans.npgettext(context, singular, plural, number)
[]
def npgettext(context, singular, plural, number): return _trans.npgettext(context, singular, plural, number)
[ "def", "npgettext", "(", "context", ",", "singular", ",", "plural", ",", "number", ")", ":", "return", "_trans", ".", "npgettext", "(", "context", ",", "singular", ",", "plural", ",", "number", ")" ]
https://github.com/JaniceWuo/MovieRecommend/blob/4c86db64ca45598917d304f535413df3bc9fea65/movierecommend/venv1/Lib/site-packages/django/utils/translation/__init__.py#L100-L101
oracle/graalpython
577e02da9755d916056184ec441c26e00b70145c
graalpython/com.oracle.graal.python.benchmarks/python/meso/chaos-sized2.py
python
GVector.__repr__
(self)
return "GVector(%f, %f, %f)" % (self.x, self.y, self.z)
[]
def __repr__(self): return "GVector(%f, %f, %f)" % (self.x, self.y, self.z)
[ "def", "__repr__", "(", "self", ")", ":", "return", "\"GVector(%f, %f, %f)\"", "%", "(", "self", ".", "x", ",", "self", ".", "y", ",", "self", ".", "z", ")" ]
https://github.com/oracle/graalpython/blob/577e02da9755d916056184ec441c26e00b70145c/graalpython/com.oracle.graal.python.benchmarks/python/meso/chaos-sized2.py#L78-L79
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/Python-2.7.9/Lib/xml/dom/minidom.py
python
ProcessingInstruction.__setattr__
(self, name, value)
[]
def __setattr__(self, name, value): if name == "data" or name == "nodeValue": self.__dict__['data'] = self.__dict__['nodeValue'] = value elif name == "target" or name == "nodeName": self.__dict__['target'] = self.__dict__['nodeName'] = value else: self.__dict__[name] = value
[ "def", "__setattr__", "(", "self", ",", "name", ",", "value", ")", ":", "if", "name", "==", "\"data\"", "or", "name", "==", "\"nodeValue\"", ":", "self", ".", "__dict__", "[", "'data'", "]", "=", "self", ".", "__dict__", "[", "'nodeValue'", "]", "=", ...
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/Python-2.7.9/Lib/xml/dom/minidom.py#L926-L932
OpenCobolIDE/OpenCobolIDE
c78d0d335378e5fe0a5e74f53c19b68b55e85388
open_cobol_ide/extlibs/pygments/lexer.py
python
DelegatingLexer.get_tokens_unprocessed
(self, text)
return do_insertions(insertions, self.root_lexer.get_tokens_unprocessed(buffered))
[]
def get_tokens_unprocessed(self, text): buffered = '' insertions = [] lng_buffer = [] for i, t, v in self.language_lexer.get_tokens_unprocessed(text): if t is self.needle: if lng_buffer: insertions.append((len(buffered), lng_buffer)) lng_buffer = [] buffered += v else: lng_buffer.append((i, t, v)) if lng_buffer: insertions.append((len(buffered), lng_buffer)) return do_insertions(insertions, self.root_lexer.get_tokens_unprocessed(buffered))
[ "def", "get_tokens_unprocessed", "(", "self", ",", "text", ")", ":", "buffered", "=", "''", "insertions", "=", "[", "]", "lng_buffer", "=", "[", "]", "for", "i", ",", "t", ",", "v", "in", "self", ".", "language_lexer", ".", "get_tokens_unprocessed", "(",...
https://github.com/OpenCobolIDE/OpenCobolIDE/blob/c78d0d335378e5fe0a5e74f53c19b68b55e85388/open_cobol_ide/extlibs/pygments/lexer.py#L225-L240
saltstack/salt
fae5bc757ad0f1716483ce7ae180b451545c2058
salt/modules/win_service.py
python
start
(name, timeout=90)
return srv_status["Status"] == "Running"
Start the specified service. .. warning:: You cannot start a disabled service in Windows. If the service is disabled, it will be changed to ``Manual`` start. Args: name (str): The name of the service to start timeout (int): The time in seconds to wait for the service to start before returning. Default is 90 seconds .. versionadded:: 2017.7.9,2018.3.4 Returns: bool: ``True`` if successful, otherwise ``False``. Also returns ``True`` if the service is already started CLI Example: .. code-block:: bash salt '*' service.start <service name>
Start the specified service.
[ "Start", "the", "specified", "service", "." ]
def start(name, timeout=90): """ Start the specified service. .. warning:: You cannot start a disabled service in Windows. If the service is disabled, it will be changed to ``Manual`` start. Args: name (str): The name of the service to start timeout (int): The time in seconds to wait for the service to start before returning. Default is 90 seconds .. versionadded:: 2017.7.9,2018.3.4 Returns: bool: ``True`` if successful, otherwise ``False``. Also returns ``True`` if the service is already started CLI Example: .. code-block:: bash salt '*' service.start <service name> """ # Set the service to manual if disabled if disabled(name): modify(name, start_type="Manual") try: win32serviceutil.StartService(name) except pywintypes.error as exc: if exc.winerror != 1056: raise CommandExecutionError( "Failed To Start {}: {}".format(name, exc.strerror) ) log.debug('Service "%s" is running', name) srv_status = _status_wait( service_name=name, end_time=time.time() + int(timeout), service_states=["Start Pending", "Stopped"], ) return srv_status["Status"] == "Running"
[ "def", "start", "(", "name", ",", "timeout", "=", "90", ")", ":", "# Set the service to manual if disabled", "if", "disabled", "(", "name", ")", ":", "modify", "(", "name", ",", "start_type", "=", "\"Manual\"", ")", "try", ":", "win32serviceutil", ".", "Star...
https://github.com/saltstack/salt/blob/fae5bc757ad0f1716483ce7ae180b451545c2058/salt/modules/win_service.py#L307-L353
home-assistant/supervisor
69c2517d5211b483fdfe968b0a2b36b672ee7ab2
supervisor/backups/backup.py
python
Backup.addon_list
(self)
return [addon_data[ATTR_SLUG] for addon_data in self.addons]
Return a list of add-ons slugs.
Return a list of add-ons slugs.
[ "Return", "a", "list", "of", "add", "-", "ons", "slugs", "." ]
def addon_list(self): """Return a list of add-ons slugs.""" return [addon_data[ATTR_SLUG] for addon_data in self.addons]
[ "def", "addon_list", "(", "self", ")", ":", "return", "[", "addon_data", "[", "ATTR_SLUG", "]", "for", "addon_data", "in", "self", ".", "addons", "]" ]
https://github.com/home-assistant/supervisor/blob/69c2517d5211b483fdfe968b0a2b36b672ee7ab2/supervisor/backups/backup.py#L99-L101
nltk/nltk
3f74ac55681667d7ef78b664557487145f51eb02
nltk/translate/meteor_score.py
python
stem_match
( hypothesis: Iterable[str], reference: Iterable[str], stemmer: StemmerI = PorterStemmer(), )
return _enum_stem_match(enum_hypothesis_list, enum_reference_list, stemmer=stemmer)
Stems each word and matches them in hypothesis and reference and returns a word mapping between hypothesis and reference :param hypothesis: pre-tokenized hypothesis :param reference: pre-tokenized reference :param stemmer: nltk.stem.api.StemmerI object (default PorterStemmer()) :return: enumerated matched tuples, enumerated unmatched hypothesis tuples, enumerated unmatched reference tuples
Stems each word and matches them in hypothesis and reference and returns a word mapping between hypothesis and reference
[ "Stems", "each", "word", "and", "matches", "them", "in", "hypothesis", "and", "reference", "and", "returns", "a", "word", "mapping", "between", "hypothesis", "and", "reference" ]
def stem_match( hypothesis: Iterable[str], reference: Iterable[str], stemmer: StemmerI = PorterStemmer(), ) -> Tuple[List[Tuple[int, int]], List[Tuple[int, str]], List[Tuple[int, str]]]: """ Stems each word and matches them in hypothesis and reference and returns a word mapping between hypothesis and reference :param hypothesis: pre-tokenized hypothesis :param reference: pre-tokenized reference :param stemmer: nltk.stem.api.StemmerI object (default PorterStemmer()) :return: enumerated matched tuples, enumerated unmatched hypothesis tuples, enumerated unmatched reference tuples """ enum_hypothesis_list, enum_reference_list = _generate_enums(hypothesis, reference) return _enum_stem_match(enum_hypothesis_list, enum_reference_list, stemmer=stemmer)
[ "def", "stem_match", "(", "hypothesis", ":", "Iterable", "[", "str", "]", ",", "reference", ":", "Iterable", "[", "str", "]", ",", "stemmer", ":", "StemmerI", "=", "PorterStemmer", "(", ")", ",", ")", "->", "Tuple", "[", "List", "[", "Tuple", "[", "i...
https://github.com/nltk/nltk/blob/3f74ac55681667d7ef78b664557487145f51eb02/nltk/translate/meteor_score.py#L119-L135
huawei-noah/Pretrained-Language-Model
d4694a134bdfacbaef8ff1d99735106bd3b3372b
DynaBERT/transformers/data/processors/glue.py
python
Sst2Processor.get_labels
(self)
return ["0", "1"]
See base class.
See base class.
[ "See", "base", "class", "." ]
def get_labels(self): """See base class.""" return ["0", "1"]
[ "def", "get_labels", "(", "self", ")", ":", "return", "[", "\"0\"", ",", "\"1\"", "]" ]
https://github.com/huawei-noah/Pretrained-Language-Model/blob/d4694a134bdfacbaef8ff1d99735106bd3b3372b/DynaBERT/transformers/data/processors/glue.py#L447-L449
openshift/openshift-tools
1188778e728a6e4781acf728123e5b356380fe6f
openshift/installer/vendored/openshift-ansible-3.10.0-0.29.0/roles/lib_openshift/library/oc_service.py
python
OpenShiftCLI._run
(self, cmds, input_data)
return proc.returncode, stdout.decode('utf-8'), stderr.decode('utf-8')
Actually executes the command. This makes mocking easier.
Actually executes the command. This makes mocking easier.
[ "Actually", "executes", "the", "command", ".", "This", "makes", "mocking", "easier", "." ]
def _run(self, cmds, input_data): ''' Actually executes the command. This makes mocking easier. ''' curr_env = os.environ.copy() curr_env.update({'KUBECONFIG': self.kubeconfig}) proc = subprocess.Popen(cmds, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=curr_env) stdout, stderr = proc.communicate(input_data) return proc.returncode, stdout.decode('utf-8'), stderr.decode('utf-8')
[ "def", "_run", "(", "self", ",", "cmds", ",", "input_data", ")", ":", "curr_env", "=", "os", ".", "environ", ".", "copy", "(", ")", "curr_env", ".", "update", "(", "{", "'KUBECONFIG'", ":", "self", ".", "kubeconfig", "}", ")", "proc", "=", "subproces...
https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/openshift/installer/vendored/openshift-ansible-3.10.0-0.29.0/roles/lib_openshift/library/oc_service.py#L1160-L1172
ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework
cb692f527e4e819b6c228187c5702d990a180043
external/Scripting Engine/Xenotix Python Scripting Engine/Lib/mailbox.py
python
_ProxyFile.readlines
(self, sizehint=None)
return result
Read multiple lines.
Read multiple lines.
[ "Read", "multiple", "lines", "." ]
def readlines(self, sizehint=None): """Read multiple lines.""" result = [] for line in self: result.append(line) if sizehint is not None: sizehint -= len(line) if sizehint <= 0: break return result
[ "def", "readlines", "(", "self", ",", "sizehint", "=", "None", ")", ":", "result", "=", "[", "]", "for", "line", "in", "self", ":", "result", ".", "append", "(", "line", ")", "if", "sizehint", "is", "not", "None", ":", "sizehint", "-=", "len", "(",...
https://github.com/ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework/blob/cb692f527e4e819b6c228187c5702d990a180043/external/Scripting Engine/Xenotix Python Scripting Engine/Lib/mailbox.py#L1829-L1838
LexPredict/lexpredict-contraxsuite
1d5a2540d31f8f3f1adc442cfa13a7c007319899
contraxsuite_services/apps/analyze/ml/features.py
python
DocumentFeatures.get_feature_df
(self)
return df, unqualified_item_ids
Transform incoming data into pandas dataframe :return: tuple(features pandas.DataFrame, unqualified item id list)
Transform incoming data into pandas dataframe :return: tuple(features pandas.DataFrame, unqualified item id list)
[ "Transform", "incoming", "data", "into", "pandas", "dataframe", ":", "return", ":", "tuple", "(", "features", "pandas", ".", "DataFrame", "unqualified", "item", "id", "list", ")" ]
def get_feature_df(self) -> Tuple[pd.DataFrame, List[Any]]: """ Transform incoming data into pandas dataframe :return: tuple(features pandas.DataFrame, unqualified item id list) """ # prepare features dataframe target_qs = self.get_queryset() all_sample_ids = list(target_qs.values_list('id', flat=True)) # TODO: all documents ref. by all_sample_ids should be in feature_table feature_table: Optional[pd.DataFrame] = None counter = 'counter' for feature_source_item in self.feature_source: msg = f'Get "{feature_source_item}" feature data:' self.log_message(msg) self.log_message('_' * len(msg)) # get aggregation queryset parameters for .annotate function source_model = self.source_models[feature_source_item] source_field = self.source_fields[feature_source_item] target_id_field = self.target_id_field aggregation = {counter: self.aggregation_function} # try to decrease memory usage iterating over chunks and using sparse dataframes # Note: pivot_table takes extra memory so use lower memory limits source_qs = source_model.objects.filter(**{target_id_field + '__in': all_sample_ids}) if hasattr(source_model, 'text_unit'): source_qs = source_qs.filter(**{self.unit_type_filter: self.unit_type}) ids = sorted(source_qs.order_by(target_id_field).values_list(target_id_field, flat=True).distinct()) terms = sorted(source_qs.order_by(source_field).values_list(source_field, flat=True).distinct()) id_count = len(ids) term_count = len(terms) self.log_message(f'{self.source_item}s containing "{feature_source_item}": {id_count}') self.log_message(f'unique "{feature_source_item}" items: {term_count}') if not term_count: self.log_message(f'WARN: there are no "{feature_source_item}" entities found') continue from_mem_chunk_size = self.get_chunk_size(term_count * 2) # np.uint16 - 2 bytes chunk_size = min([self.max_chunk_size, from_mem_chunk_size]) self.log_message(f'chunk_size from_mem/min/final: {from_mem_chunk_size}/{self.max_chunk_size}/{chunk_size}') # TODO: we stopped using pd.SparseDataFrame as there's no such class anymore single_feature_table = SparseSingleFeatureTable(feature_source_item) for step in range(0, id_count, chunk_size): self.log_message(f'...process "{feature_source_item}" feature: "{self.source_item}s" range: {step}-{step + chunk_size}') sample_ids = ids[step:step + chunk_size] chunk_qs = source_qs \ .filter(**{target_id_field + '__in': sample_ids}) \ .order_by(target_id_field, source_field) \ .values(target_id_field, source_field) \ .annotate(**aggregation) df_src = list(chunk_qs) chunk_df = pd.DataFrame.from_records(df_src) del chunk_qs gc.collect() # try to free up memory doc_cat = CategoricalDtype(sample_ids, ordered=True) # TODO: fix for date features: pandas can't compare dates, but datetimes only if terms and isinstance(terms[0], datetime.date): terms = [datetime.datetime.combine(d, datetime.datetime.min.time()) for d in terms] if not chunk_df[source_field].empty and isinstance(chunk_df[source_field][0], datetime.date): chunk_df[source_field] = \ [datetime.datetime.combine(d, datetime.datetime.min.time()) for d in chunk_df[source_field]] term_cat = CategoricalDtype(terms, ordered=True) row = [] if chunk_df.empty else chunk_df[self.target_id_field].astype(doc_cat).cat.codes col = [] if chunk_df.empty else chunk_df[source_field].astype(term_cat).cat.codes val = [] if chunk_df.empty else chunk_df[counter] sparse_matrix = scp.csr_matrix( (val, (row, col)), shape=(len(sample_ids), term_cat.categories.size), dtype=np.uint16) single_feature_table.join(sparse_matrix) del chunk_df gc.collect() # try to free up memory mem = psutil.virtual_memory() self.log_message(f'......available memory: {get_mb(mem.available)}M ({mem.percent}%)') # join feature_source_item-specific dataframe into results dataframe gc.collect() # try to free up memory single_feature_df_src = SparseAllFeaturesTable(ids) single_feature_df_src.add_feature_table(single_feature_table, terms) if feature_table is None: feature_table = single_feature_df_src.to_dataframe() else: feature_table = feature_table.join(single_feature_df_src.to_dataframe(), how='outer') del single_feature_table del single_feature_df_src gc.collect() # try to free up memory # end of "for feature_source_item in self.feature_source" df = feature_table if df is not None and self.drop_empty_columns: df.dropna(axis=1, how='all', inplace=True) if df is None or df.empty: no_features_msg = f'No features of chosen "feature_source" options {self.feature_source} detected.' raise EmptyDataSetError(no_features_msg, feature_source=self.feature_source) self.log_message(f'df: {get_df_info(df)}') mem = psutil.virtual_memory() self.log_message(f'available memory: {get_mb(mem.available)}M ({mem.percent}%)') # item ids not included in feature df which don't have features at all initial_id_set = set(target_qs.values_list('id', flat=True)) feature_id_set = set(df.index.tolist()) unqualified_item_ids = sorted(list(initial_id_set.difference(feature_id_set))) self.log_message('count unqualified_item_ids: {}'.format(len(unqualified_item_ids))) if not self.drop_empty_rows and unqualified_item_ids: unqualified_items_df = pd.DataFrame(index=unqualified_item_ids, columns=df.columns).fillna(0) self.log_message('unqualified_items_df shape: {} size: {}'.format( unqualified_items_df.shape, unqualified_items_df.memory_usage().sum())) df = pd.concat([df, unqualified_items_df]).fillna(0).astype(np.uint16) self.log_message(f'df: {get_df_info(df)}') return df, unqualified_item_ids
[ "def", "get_feature_df", "(", "self", ")", "->", "Tuple", "[", "pd", ".", "DataFrame", ",", "List", "[", "Any", "]", "]", ":", "# prepare features dataframe", "target_qs", "=", "self", ".", "get_queryset", "(", ")", "all_sample_ids", "=", "list", "(", "tar...
https://github.com/LexPredict/lexpredict-contraxsuite/blob/1d5a2540d31f8f3f1adc442cfa13a7c007319899/contraxsuite_services/apps/analyze/ml/features.py#L227-L364
naftaliharris/tauthon
5587ceec329b75f7caf6d65a036db61ac1bae214
Lib/idlelib/tabbedpages.py
python
TabSet._arrange_tabs
(self)
Arrange the tabs in rows, in the order in which they were added. If n_rows >= 1, this will be the number of rows used. Otherwise the number of rows will be calculated according to the number of tabs and max_tabs_per_row. In this case, the number of rows may change when adding/removing tabs.
Arrange the tabs in rows, in the order in which they were added.
[ "Arrange", "the", "tabs", "in", "rows", "in", "the", "order", "in", "which", "they", "were", "added", "." ]
def _arrange_tabs(self): """ Arrange the tabs in rows, in the order in which they were added. If n_rows >= 1, this will be the number of rows used. Otherwise the number of rows will be calculated according to the number of tabs and max_tabs_per_row. In this case, the number of rows may change when adding/removing tabs. """ # remove all tabs and rows for tab_name in self._tabs.keys(): self._tabs.pop(tab_name).destroy() self._reset_tab_rows() if not self._tab_names: return if self.n_rows is not None and self.n_rows > 0: n_rows = self.n_rows else: # calculate the required number of rows n_rows = (len(self._tab_names) - 1) // self.max_tabs_per_row + 1 # not expanding the tabs with more than one row is very ugly expand_tabs = self.expand_tabs or n_rows > 1 i = 0 # index in self._tab_names for row_index in xrange(n_rows): # calculate required number of tabs in this row n_tabs = (len(self._tab_names) - i - 1) // (n_rows - row_index) + 1 tab_names = self._tab_names[i:i + n_tabs] i += n_tabs self._add_tab_row(tab_names, expand_tabs) # re-select selected tab so it is properly displayed selected = self._selected_tab self.set_selected_tab(None) if selected in self._tab_names: self.set_selected_tab(selected)
[ "def", "_arrange_tabs", "(", "self", ")", ":", "# remove all tabs and rows", "for", "tab_name", "in", "self", ".", "_tabs", ".", "keys", "(", ")", ":", "self", ".", "_tabs", ".", "pop", "(", "tab_name", ")", ".", "destroy", "(", ")", "self", ".", "_res...
https://github.com/naftaliharris/tauthon/blob/5587ceec329b75f7caf6d65a036db61ac1bae214/Lib/idlelib/tabbedpages.py#L135-L173