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
skylander86/lambda-text-extractor
6da52d077a2fc571e38bfe29c33ae68f6443cd5a
lib-linux_x64/pptx/shapes/shapetree.py
python
NotesSlideShapes.ph_basename
(self, ph_type)
return { PP_PLACEHOLDER.BODY: 'Notes Placeholder', PP_PLACEHOLDER.DATE: 'Date Placeholder', PP_PLACEHOLDER.FOOTER: 'Footer Placeholder', PP_PLACEHOLDER.HEADER: 'Header Placeholder', PP_PLACEHOLDER.SLIDE_IMAGE: 'Slide Image Placeholder', PP_PLACEHOLDER.SLIDE_NUMBER: 'Slide Number Placeholder', }[ph_type]
Return the base name for a placeholder of *ph_type* in this shape collection. A notes slide uses a different name for the body placeholder and has some unique placeholder types, so this method overrides the default in the base class.
Return the base name for a placeholder of *ph_type* in this shape collection. A notes slide uses a different name for the body placeholder and has some unique placeholder types, so this method overrides the default in the base class.
[ "Return", "the", "base", "name", "for", "a", "placeholder", "of", "*", "ph_type", "*", "in", "this", "shape", "collection", ".", "A", "notes", "slide", "uses", "a", "different", "name", "for", "the", "body", "placeholder", "and", "has", "some", "unique", ...
def ph_basename(self, ph_type): """ Return the base name for a placeholder of *ph_type* in this shape collection. A notes slide uses a different name for the body placeholder and has some unique placeholder types, so this method overrides the default in the base class. """ return { PP_PLACEHOLDER.BODY: 'Notes Placeholder', PP_PLACEHOLDER.DATE: 'Date Placeholder', PP_PLACEHOLDER.FOOTER: 'Footer Placeholder', PP_PLACEHOLDER.HEADER: 'Header Placeholder', PP_PLACEHOLDER.SLIDE_IMAGE: 'Slide Image Placeholder', PP_PLACEHOLDER.SLIDE_NUMBER: 'Slide Number Placeholder', }[ph_type]
[ "def", "ph_basename", "(", "self", ",", "ph_type", ")", ":", "return", "{", "PP_PLACEHOLDER", ".", "BODY", ":", "'Notes Placeholder'", ",", "PP_PLACEHOLDER", ".", "DATE", ":", "'Date Placeholder'", ",", "PP_PLACEHOLDER", ".", "FOOTER", ":", "'Footer Placeholder'",...
https://github.com/skylander86/lambda-text-extractor/blob/6da52d077a2fc571e38bfe29c33ae68f6443cd5a/lib-linux_x64/pptx/shapes/shapetree.py#L335-L349
NifTK/NiftyNet
935bf4334cd00fa9f9d50f6a95ddcbfdde4031e0
niftynet/engine/application_initializer.py
python
HeUniform.get_instance
(args)
return VarianceScaling.get_instance(args)
create an instance of the initializer
create an instance of the initializer
[ "create", "an", "instance", "of", "the", "initializer" ]
def get_instance(args): # pylint: disable=unused-argument """ create an instance of the initializer """ if not args: args = {"scale": "2.", "mode": "fan_in", "distribution": "uniform"} return VarianceScaling.get_instance(args)
[ "def", "get_instance", "(", "args", ")", ":", "# pylint: disable=unused-argument", "if", "not", "args", ":", "args", "=", "{", "\"scale\"", ":", "\"2.\"", ",", "\"mode\"", ":", "\"fan_in\"", ",", "\"distribution\"", ":", "\"uniform\"", "}", "return", "VarianceSc...
https://github.com/NifTK/NiftyNet/blob/935bf4334cd00fa9f9d50f6a95ddcbfdde4031e0/niftynet/engine/application_initializer.py#L155-L162
tvaddonsco/script.module.urlresolver
ddeca574c133d51879624bf3059c6e73445d90bc
lib/urlresolver/plugins/streamable.py
python
StreamableResolver.base36encode
(self, number, alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ')
return base36
Converts a positive integer to a base36 string.
Converts a positive integer to a base36 string.
[ "Converts", "a", "positive", "integer", "to", "a", "base36", "string", "." ]
def base36encode(self, number, alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'): """Converts a positive integer to a base36 string.""" base36 = '' if 0 <= number < len(alphabet): return alphabet[number] while number != 0: number, i = divmod(number, len(alphabet)) base36 = alphabet[i] + base36 return base36
[ "def", "base36encode", "(", "self", ",", "number", ",", "alphabet", "=", "'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'", ")", ":", "base36", "=", "''", "if", "0", "<=", "number", "<", "len", "(", "alphabet", ")", ":", "return", "alphabet", "[", "number", "]", "w...
https://github.com/tvaddonsco/script.module.urlresolver/blob/ddeca574c133d51879624bf3059c6e73445d90bc/lib/urlresolver/plugins/streamable.py#L54-L65
XX-net/XX-Net
a9898cfcf0084195fb7e69b6bc834e59aecdf14f
python3.8.2/Lib/difflib.py
python
context_diff
(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n')
r""" Compare two sequences of lines; generate the delta as a context diff. Context diffs are a compact way of showing line changes and a few lines of context. The number of context lines is set by 'n' which defaults to three. By default, the diff control lines (those with *** or ---) are created with a trailing newline. This is helpful so that inputs created from file.readlines() result in diffs that are suitable for file.writelines() since both the inputs and outputs have trailing newlines. For inputs that do not have trailing newlines, set the lineterm argument to "" so that the output will be uniformly newline free. The context diff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. The modification times are normally expressed in the ISO 8601 format. If not specified, the strings default to blanks. Example: >>> print(''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(True), ... 'zero\none\ntree\nfour\n'.splitlines(True), 'Original', 'Current')), ... end="") *** Original --- Current *************** *** 1,4 **** one ! two ! three four --- 1,4 ---- + zero one ! tree four
r""" Compare two sequences of lines; generate the delta as a context diff.
[ "r", "Compare", "two", "sequences", "of", "lines", ";", "generate", "the", "delta", "as", "a", "context", "diff", "." ]
def context_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n'): r""" Compare two sequences of lines; generate the delta as a context diff. Context diffs are a compact way of showing line changes and a few lines of context. The number of context lines is set by 'n' which defaults to three. By default, the diff control lines (those with *** or ---) are created with a trailing newline. This is helpful so that inputs created from file.readlines() result in diffs that are suitable for file.writelines() since both the inputs and outputs have trailing newlines. For inputs that do not have trailing newlines, set the lineterm argument to "" so that the output will be uniformly newline free. The context diff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. The modification times are normally expressed in the ISO 8601 format. If not specified, the strings default to blanks. Example: >>> print(''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(True), ... 'zero\none\ntree\nfour\n'.splitlines(True), 'Original', 'Current')), ... end="") *** Original --- Current *************** *** 1,4 **** one ! two ! three four --- 1,4 ---- + zero one ! tree four """ _check_types(a, b, fromfile, tofile, fromfiledate, tofiledate, lineterm) prefix = dict(insert='+ ', delete='- ', replace='! ', equal=' ') started = False for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n): if not started: started = True fromdate = '\t{}'.format(fromfiledate) if fromfiledate else '' todate = '\t{}'.format(tofiledate) if tofiledate else '' yield '*** {}{}{}'.format(fromfile, fromdate, lineterm) yield '--- {}{}{}'.format(tofile, todate, lineterm) first, last = group[0], group[-1] yield '***************' + lineterm file1_range = _format_range_context(first[1], last[2]) yield '*** {} ****{}'.format(file1_range, lineterm) if any(tag in {'replace', 'delete'} for tag, _, _, _, _ in group): for tag, i1, i2, _, _ in group: if tag != 'insert': for line in a[i1:i2]: yield prefix[tag] + line file2_range = _format_range_context(first[3], last[4]) yield '--- {} ----{}'.format(file2_range, lineterm) if any(tag in {'replace', 'insert'} for tag, _, _, _, _ in group): for tag, _, _, j1, j2 in group: if tag != 'delete': for line in b[j1:j2]: yield prefix[tag] + line
[ "def", "context_diff", "(", "a", ",", "b", ",", "fromfile", "=", "''", ",", "tofile", "=", "''", ",", "fromfiledate", "=", "''", ",", "tofiledate", "=", "''", ",", "n", "=", "3", ",", "lineterm", "=", "'\\n'", ")", ":", "_check_types", "(", "a", ...
https://github.com/XX-net/XX-Net/blob/a9898cfcf0084195fb7e69b6bc834e59aecdf14f/python3.8.2/Lib/difflib.py#L1210-L1284
evilhero/mylar
dbee01d7e48e8c717afa01b2de1946c5d0b956cb
lib/mako/runtime.py
python
capture
(context, callable_, *args, **kwargs)
return buf.getvalue()
Execute the given template def, capturing the output into a buffer. See the example in :ref:`namespaces_python_modules`.
Execute the given template def, capturing the output into a buffer.
[ "Execute", "the", "given", "template", "def", "capturing", "the", "output", "into", "a", "buffer", "." ]
def capture(context, callable_, *args, **kwargs): """Execute the given template def, capturing the output into a buffer. See the example in :ref:`namespaces_python_modules`. """ if not compat.callable(callable_): raise exceptions.RuntimeException( "capture() function expects a callable as " "its argument (i.e. capture(func, *args, **kwargs))" ) context._push_buffer() try: callable_(*args, **kwargs) finally: buf = context._pop_buffer() return buf.getvalue()
[ "def", "capture", "(", "context", ",", "callable_", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "not", "compat", ".", "callable", "(", "callable_", ")", ":", "raise", "exceptions", ".", "RuntimeException", "(", "\"capture() function expects a ...
https://github.com/evilhero/mylar/blob/dbee01d7e48e8c717afa01b2de1946c5d0b956cb/lib/mako/runtime.py#L698-L716
NanYoMy/DHT-woodworm
e28bbff214bc3c41ea462854256dd499fb8a6eb0
btdht/node.py
python
Node.pong
(self, socket=None, trans_id=None, sender_id=None, lock=None)
Construct reply message for ping
Construct reply message for ping
[ "Construct", "reply", "message", "for", "ping" ]
def pong(self, socket=None, trans_id=None, sender_id=None, lock=None): """ Construct reply message for ping """ message = { "y": "r", "r": { "id": sender_id } } logger.debug("pong msg to %s:%d, y:%s, t: %r" % ( self.host, self.port, message["y"], trans_id.encode("hex") )) self._sendmessage(message, socket, trans_id=trans_id, lock=lock)
[ "def", "pong", "(", "self", ",", "socket", "=", "None", ",", "trans_id", "=", "None", ",", "sender_id", "=", "None", ",", "lock", "=", "None", ")", ":", "message", "=", "{", "\"y\"", ":", "\"r\"", ",", "\"r\"", ":", "{", "\"id\"", ":", "sender_id",...
https://github.com/NanYoMy/DHT-woodworm/blob/e28bbff214bc3c41ea462854256dd499fb8a6eb0/btdht/node.py#L111-L125
Chia-Network/chia-blockchain
34d44c1324ae634a0896f7b02eaa2802af9526cd
chia/wallet/wallet_state_manager.py
python
WalletStateManager.remove_from_queue
( self, spendbundle_id: bytes32, name: str, send_status: MempoolInclusionStatus, error: Optional[Err], )
Full node received our transaction, no need to keep it in queue anymore
Full node received our transaction, no need to keep it in queue anymore
[ "Full", "node", "received", "our", "transaction", "no", "need", "to", "keep", "it", "in", "queue", "anymore" ]
async def remove_from_queue( self, spendbundle_id: bytes32, name: str, send_status: MempoolInclusionStatus, error: Optional[Err], ): """ Full node received our transaction, no need to keep it in queue anymore """ updated = await self.tx_store.increment_sent(spendbundle_id, name, send_status, error) if updated: tx: Optional[TransactionRecord] = await self.get_transaction(spendbundle_id) if tx is not None: self.state_changed("tx_update", tx.wallet_id, {"transaction": tx})
[ "async", "def", "remove_from_queue", "(", "self", ",", "spendbundle_id", ":", "bytes32", ",", "name", ":", "str", ",", "send_status", ":", "MempoolInclusionStatus", ",", "error", ":", "Optional", "[", "Err", "]", ",", ")", ":", "updated", "=", "await", "se...
https://github.com/Chia-Network/chia-blockchain/blob/34d44c1324ae634a0896f7b02eaa2802af9526cd/chia/wallet/wallet_state_manager.py#L897-L911
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/water_heater/__init__.py
python
WaterHeaterEntity.min_temp
(self)
return convert_temperature( DEFAULT_MIN_TEMP, TEMP_FAHRENHEIT, self.temperature_unit )
Return the minimum temperature.
Return the minimum temperature.
[ "Return", "the", "minimum", "temperature", "." ]
def min_temp(self): """Return the minimum temperature.""" if hasattr(self, "_attr_min_temp"): return self._attr_min_temp return convert_temperature( DEFAULT_MIN_TEMP, TEMP_FAHRENHEIT, self.temperature_unit )
[ "def", "min_temp", "(", "self", ")", ":", "if", "hasattr", "(", "self", ",", "\"_attr_min_temp\"", ")", ":", "return", "self", ".", "_attr_min_temp", "return", "convert_temperature", "(", "DEFAULT_MIN_TEMP", ",", "TEMP_FAHRENHEIT", ",", "self", ".", "temperature...
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/water_heater/__init__.py#L314-L320
brython-dev/brython
9cba5fb7f43a9b52fff13e89b403e02a1dfaa5f3
www/src/Lib/bdb.py
python
stop_here
(self, frame)
return False
Return True if frame is below the starting frame in the stack.
Return True if frame is below the starting frame in the stack.
[ "Return", "True", "if", "frame", "is", "below", "the", "starting", "frame", "in", "the", "stack", "." ]
def stop_here(self, frame): "Return True if frame is below the starting frame in the stack." # (CT) stopframe may now also be None, see dispatch_call. # (CT) the former test for None is therefore removed from here. if self.skip and \ self.is_skipped_module(frame.f_globals.get('__name__')): return False if frame is self.stopframe: if self.stoplineno == -1: return False return frame.f_lineno >= self.stoplineno if not self.stopframe: return True return False
[ "def", "stop_here", "(", "self", ",", "frame", ")", ":", "# (CT) stopframe may now also be None, see dispatch_call.", "# (CT) the former test for None is therefore removed from here.", "if", "self", ".", "skip", "and", "self", ".", "is_skipped_module", "(", "frame", ".", "f...
https://github.com/brython-dev/brython/blob/9cba5fb7f43a9b52fff13e89b403e02a1dfaa5f3/www/src/Lib/bdb.py#L202-L215
robinhood/deux
5b1e774beba7d63b73b5a3f3c1e16afa54706363
deux/abstract_models.py
python
AbstractMultiFactorAuth.enabled
(self)
return self.challenge_type in CHALLENGE_TYPES
Returns if MFA is enabled.
Returns if MFA is enabled.
[ "Returns", "if", "MFA", "is", "enabled", "." ]
def enabled(self): """Returns if MFA is enabled.""" return self.challenge_type in CHALLENGE_TYPES
[ "def", "enabled", "(", "self", ")", ":", "return", "self", ".", "challenge_type", "in", "CHALLENGE_TYPES" ]
https://github.com/robinhood/deux/blob/5b1e774beba7d63b73b5a3f3c1e16afa54706363/deux/abstract_models.py#L64-L66
matplotlib/matplotlib
8d7a2b9d2a38f01ee0d6802dd4f9e98aec812322
lib/matplotlib/textpath.py
python
TextPath._revalidate_path
(self)
Update the path if necessary. The path for the text is initially create with the font size of `.FONT_SCALE`, and this path is rescaled to other size when necessary.
Update the path if necessary.
[ "Update", "the", "path", "if", "necessary", "." ]
def _revalidate_path(self): """ Update the path if necessary. The path for the text is initially create with the font size of `.FONT_SCALE`, and this path is rescaled to other size when necessary. """ if self._invalid or self._cached_vertices is None: tr = (Affine2D() .scale(self._size / text_to_path.FONT_SCALE) .translate(*self._xy)) self._cached_vertices = tr.transform(self._vertices) self._cached_vertices.flags.writeable = False self._invalid = False
[ "def", "_revalidate_path", "(", "self", ")", ":", "if", "self", ".", "_invalid", "or", "self", ".", "_cached_vertices", "is", "None", ":", "tr", "=", "(", "Affine2D", "(", ")", ".", "scale", "(", "self", ".", "_size", "/", "text_to_path", ".", "FONT_SC...
https://github.com/matplotlib/matplotlib/blob/8d7a2b9d2a38f01ee0d6802dd4f9e98aec812322/lib/matplotlib/textpath.py#L418-L431
lvsh/keywordfinder
2655a3bd6b05e09b8e1a7f463a322aaf25963ae8
example.py
python
main
()
[]
def main(): if len(sys.argv)==1: raise ValueError('Must specify input text file.') else: f = open(sys.argv[1],'r') text = f.read() f.close() # load keyword classifier preload = 1 classifier_type = 'logistic' keyword_classifier = get_keywordclassifier(preload,classifier_type)['model'] # extract top k keywords top_k = 15 keywords = extract_keywords(text,keyword_classifier,top_k,preload) print 'ORIGINAL TEXT:\n%s\nTOP-%d KEYWORDS returned by model: %s\n' % (text,top_k,', '.join(keywords)) # evaluate performance for inspec example if sys.argv[1]=='inspec.txt': true_keywords = [] with open('inspec.key','r') as f: for line in f: true_keywords.extend(line.strip('\n').split()) true_keywords = [remove_punctuation(kw.lower()) for kw in true_keywords] (precision,recall,f1score) = evaluate_keywords(keywords,true_keywords) print 'MANUALLY SPECIFIED KEYWORDS:\n%s' % ', '.join(true_keywords) print '\nModel achieves %.4f precision, %.4f recall, and %.4f f1 score.' % (precision,recall,f1score)
[ "def", "main", "(", ")", ":", "if", "len", "(", "sys", ".", "argv", ")", "==", "1", ":", "raise", "ValueError", "(", "'Must specify input text file.'", ")", "else", ":", "f", "=", "open", "(", "sys", ".", "argv", "[", "1", "]", ",", "'r'", ")", "...
https://github.com/lvsh/keywordfinder/blob/2655a3bd6b05e09b8e1a7f463a322aaf25963ae8/example.py#L13-L41
dipu-bd/lightnovel-crawler
eca7a71f217ce7a6b0a54d2e2afb349571871880
sources/en/s/scribblehub.py
python
ScribbleHubCrawler.download_chapter_list
(self, page)
return soup.select('a.toc_a')
Download list of chapters and volumes.
Download list of chapters and volumes.
[ "Download", "list", "of", "chapters", "and", "volumes", "." ]
def download_chapter_list(self, page): '''Download list of chapters and volumes.''' url = self.novel_url.split('?')[0].strip('/') url += '?toc=%s#content1' % page soup = self.get_soup(url) logger.debug('Crawling chapters url in page %s' % page) return soup.select('a.toc_a')
[ "def", "download_chapter_list", "(", "self", ",", "page", ")", ":", "url", "=", "self", ".", "novel_url", ".", "split", "(", "'?'", ")", "[", "0", "]", ".", "strip", "(", "'/'", ")", "url", "+=", "'?toc=%s#content1'", "%", "page", "soup", "=", "self"...
https://github.com/dipu-bd/lightnovel-crawler/blob/eca7a71f217ce7a6b0a54d2e2afb349571871880/sources/en/s/scribblehub.py#L78-L84
sethmlarson/virtualbox-python
984a6e2cb0e8996f4df40f4444c1528849f1c70d
virtualbox/library.py
python
IVirtualBox.package_type
(self)
return ret
Get str value for 'packageType' A string representing the package type of this product. The format is OS_ARCH_DIST where OS is either WINDOWS, LINUX, SOLARIS, DARWIN. ARCH is either 32BITS or 64BITS. DIST is either GENERIC, UBUNTU_606, UBUNTU_710, or something like this.
Get str value for 'packageType' A string representing the package type of this product. The format is OS_ARCH_DIST where OS is either WINDOWS, LINUX, SOLARIS, DARWIN. ARCH is either 32BITS or 64BITS. DIST is either GENERIC, UBUNTU_606, UBUNTU_710, or something like this.
[ "Get", "str", "value", "for", "packageType", "A", "string", "representing", "the", "package", "type", "of", "this", "product", ".", "The", "format", "is", "OS_ARCH_DIST", "where", "OS", "is", "either", "WINDOWS", "LINUX", "SOLARIS", "DARWIN", ".", "ARCH", "i...
def package_type(self): """Get str value for 'packageType' A string representing the package type of this product. The format is OS_ARCH_DIST where OS is either WINDOWS, LINUX, SOLARIS, DARWIN. ARCH is either 32BITS or 64BITS. DIST is either GENERIC, UBUNTU_606, UBUNTU_710, or something like this. """ ret = self._get_attr("packageType") return ret
[ "def", "package_type", "(", "self", ")", ":", "ret", "=", "self", ".", "_get_attr", "(", "\"packageType\"", ")", "return", "ret" ]
https://github.com/sethmlarson/virtualbox-python/blob/984a6e2cb0e8996f4df40f4444c1528849f1c70d/virtualbox/library.py#L10047-L10056
huawei-noah/Pretrained-Language-Model
d4694a134bdfacbaef8ff1d99735106bd3b3372b
AutoTinyBERT/superbert_run_en_classifier.py
python
QqpProcessor.get_dev_examples
(self, data_dir)
return self._create_examples( self._read_tsv(os.path.join(data_dir, "dev.tsv")), "dev")
See base class.
See base class.
[ "See", "base", "class", "." ]
def get_dev_examples(self, data_dir): """See base class.""" return self._create_examples( self._read_tsv(os.path.join(data_dir, "dev.tsv")), "dev")
[ "def", "get_dev_examples", "(", "self", ",", "data_dir", ")", ":", "return", "self", ".", "_create_examples", "(", "self", ".", "_read_tsv", "(", "os", ".", "path", ".", "join", "(", "data_dir", ",", "\"dev.tsv\"", ")", ")", ",", "\"dev\"", ")" ]
https://github.com/huawei-noah/Pretrained-Language-Model/blob/d4694a134bdfacbaef8ff1d99735106bd3b3372b/AutoTinyBERT/superbert_run_en_classifier.py#L387-L390
Source-Python-Dev-Team/Source.Python
d0ffd8ccbd1e9923c9bc44936f20613c1c76b7fb
addons/source-python/Python3/distutils/cmd.py
python
Command.set_undefined_options
(self, src_cmd, *option_pairs)
Set the values of any "undefined" options from corresponding option values in some other command object. "Undefined" here means "is None", which is the convention used to indicate that an option has not been changed between 'initialize_options()' and 'finalize_options()'. Usually called from 'finalize_options()' for options that depend on some other command rather than another option of the same command. 'src_cmd' is the other command from which option values will be taken (a command object will be created for it if necessary); the remaining arguments are '(src_option,dst_option)' tuples which mean "take the value of 'src_option' in the 'src_cmd' command object, and copy it to 'dst_option' in the current command object".
Set the values of any "undefined" options from corresponding option values in some other command object. "Undefined" here means "is None", which is the convention used to indicate that an option has not been changed between 'initialize_options()' and 'finalize_options()'. Usually called from 'finalize_options()' for options that depend on some other command rather than another option of the same command. 'src_cmd' is the other command from which option values will be taken (a command object will be created for it if necessary); the remaining arguments are '(src_option,dst_option)' tuples which mean "take the value of 'src_option' in the 'src_cmd' command object, and copy it to 'dst_option' in the current command object".
[ "Set", "the", "values", "of", "any", "undefined", "options", "from", "corresponding", "option", "values", "in", "some", "other", "command", "object", ".", "Undefined", "here", "means", "is", "None", "which", "is", "the", "convention", "used", "to", "indicate",...
def set_undefined_options(self, src_cmd, *option_pairs): """Set the values of any "undefined" options from corresponding option values in some other command object. "Undefined" here means "is None", which is the convention used to indicate that an option has not been changed between 'initialize_options()' and 'finalize_options()'. Usually called from 'finalize_options()' for options that depend on some other command rather than another option of the same command. 'src_cmd' is the other command from which option values will be taken (a command object will be created for it if necessary); the remaining arguments are '(src_option,dst_option)' tuples which mean "take the value of 'src_option' in the 'src_cmd' command object, and copy it to 'dst_option' in the current command object". """ # Option_pairs: list of (src_option, dst_option) tuples src_cmd_obj = self.distribution.get_command_obj(src_cmd) src_cmd_obj.ensure_finalized() for (src_option, dst_option) in option_pairs: if getattr(self, dst_option) is None: setattr(self, dst_option, getattr(src_cmd_obj, src_option))
[ "def", "set_undefined_options", "(", "self", ",", "src_cmd", ",", "*", "option_pairs", ")", ":", "# Option_pairs: list of (src_option, dst_option) tuples", "src_cmd_obj", "=", "self", ".", "distribution", ".", "get_command_obj", "(", "src_cmd", ")", "src_cmd_obj", ".", ...
https://github.com/Source-Python-Dev-Team/Source.Python/blob/d0ffd8ccbd1e9923c9bc44936f20613c1c76b7fb/addons/source-python/Python3/distutils/cmd.py#L271-L290
oracle/graalpython
577e02da9755d916056184ec441c26e00b70145c
graalpython/lib-python/3/tkinter/tix.py
python
ScrolledHList.__init__
(self, master, cnf={}, **kw)
[]
def __init__(self, master, cnf={}, **kw): TixWidget.__init__(self, master, 'tixScrolledHList', ['options'], cnf, kw) self.subwidget_list['hlist'] = _dummyHList(self, 'hlist') self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb') self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
[ "def", "__init__", "(", "self", ",", "master", ",", "cnf", "=", "{", "}", ",", "*", "*", "kw", ")", ":", "TixWidget", ".", "__init__", "(", "self", ",", "master", ",", "'tixScrolledHList'", ",", "[", "'options'", "]", ",", "cnf", ",", "kw", ")", ...
https://github.com/oracle/graalpython/blob/577e02da9755d916056184ec441c26e00b70145c/graalpython/lib-python/3/tkinter/tix.py#L1301-L1306
owid/covid-19-data
936aeae6cfbdc0163939ed7bd8ecdbb2582c0a92
scripts/src/cowidev/vax/batch/sweden.py
python
Sweden.pipe_columns
(self, df: pd.DataFrame)
return df.assign(location=self.location, source_url=self.source_url_daily)
[]
def pipe_columns(self, df: pd.DataFrame) -> pd.DataFrame: return df.assign(location=self.location, source_url=self.source_url_daily)
[ "def", "pipe_columns", "(", "self", ",", "df", ":", "pd", ".", "DataFrame", ")", "->", "pd", ".", "DataFrame", ":", "return", "df", ".", "assign", "(", "location", "=", "self", ".", "location", ",", "source_url", "=", "self", ".", "source_url_daily", "...
https://github.com/owid/covid-19-data/blob/936aeae6cfbdc0163939ed7bd8ecdbb2582c0a92/scripts/src/cowidev/vax/batch/sweden.py#L144-L145
IBM/pytorchpipe
9cb17271666061cb19fe24197ecd5e4c8d32c5da
ptp/configuration/config_registry.py
python
ConfigRegistry.__init__
(self)
Constructor: - Call base constructor (:py:class:`Mapping`), - Initializes empty parameters dicts for: - `Default` parameters, - `Config` parameters, - Resulting tree.
Constructor:
[ "Constructor", ":" ]
def __init__(self): """ Constructor: - Call base constructor (:py:class:`Mapping`), - Initializes empty parameters dicts for: - `Default` parameters, - `Config` parameters, - Resulting tree. """ super(ConfigRegistry, self).__init__() # Default parameters set in the code. self._clear_registry()
[ "def", "__init__", "(", "self", ")", ":", "super", "(", "ConfigRegistry", ",", "self", ")", ".", "__init__", "(", ")", "# Default parameters set in the code.", "self", ".", "_clear_registry", "(", ")" ]
https://github.com/IBM/pytorchpipe/blob/9cb17271666061cb19fe24197ecd5e4c8d32c5da/ptp/configuration/config_registry.py#L55-L71
aidiary/PRML
db2dfc10bd39dc5649528d3778aa5fffb283186b
ch9/kmeans.py
python
J
(X, mean, r)
return summation
K-meansの目的関数(最小化を目指す)
K-meansの目的関数(最小化を目指す)
[ "K", "-", "meansの目的関数(最小化を目指す)" ]
def J(X, mean, r): """K-meansの目的関数(最小化を目指す)""" summation = 0.0 for n in range(len(X)): temp = 0.0 for k in range(K): temp += r[n, k] * np.linalg.norm(X[n] - mean[k]) ** 2 summation += temp return summation
[ "def", "J", "(", "X", ",", "mean", ",", "r", ")", ":", "summation", "=", "0.0", "for", "n", "in", "range", "(", "len", "(", "X", ")", ")", ":", "temp", "=", "0.0", "for", "k", "in", "range", "(", "K", ")", ":", "temp", "+=", "r", "[", "n"...
https://github.com/aidiary/PRML/blob/db2dfc10bd39dc5649528d3778aa5fffb283186b/ch9/kmeans.py#L26-L34
mihaip/readerisdead
0e35cf26e88f27e0a07432182757c1ce230f6936
feed_archive/feed_archive.py
python
get_stream_id
(feed_url)
return 'feed/%s' % feed_url
[]
def get_stream_id(feed_url): try: parsed = urlparse.urlparse(feed_url) # If the feed is generated by Reader itself, turn it into the underlying # stream ID. if parsed.hostname.startswith('www.google.') and \ parsed.path.startswith(_READER_SHARED_TAG_FEED_URL_PATH_PREFIX): reader_url_prefix = '%s://%s%s' % ( parsed.scheme, parsed.hostname, _READER_SHARED_TAG_FEED_URL_PATH_PREFIX) return feed_url[len(reader_url_prefix):] except: # Ignore malformed URLs pass return 'feed/%s' % feed_url
[ "def", "get_stream_id", "(", "feed_url", ")", ":", "try", ":", "parsed", "=", "urlparse", ".", "urlparse", "(", "feed_url", ")", "# If the feed is generated by Reader itself, turn it into the underlying", "# stream ID.", "if", "parsed", ".", "hostname", ".", "startswith...
https://github.com/mihaip/readerisdead/blob/0e35cf26e88f27e0a07432182757c1ce230f6936/feed_archive/feed_archive.py#L241-L254
saltstack/salt-contrib
062355938ad1cced273056e9c23dc344c6a2c858
modules/smx.py
python
bundle_start
(bundle)
start the bundle CLI Examples:: salt '*' smx.bundle_start 'some.bundle.name'
start the bundle
[ "start", "the", "bundle" ]
def bundle_start(bundle): ''' start the bundle CLI Examples:: salt '*' smx.bundle_start 'some.bundle.name' ''' if not bundle_exists(bundle): return 'missing' run('osgi:start {0}'.format(bundle)) if bundle_active(bundle): return 'active' else: return 'error'
[ "def", "bundle_start", "(", "bundle", ")", ":", "if", "not", "bundle_exists", "(", "bundle", ")", ":", "return", "'missing'", "run", "(", "'osgi:start {0}'", ".", "format", "(", "bundle", ")", ")", "if", "bundle_active", "(", "bundle", ")", ":", "return", ...
https://github.com/saltstack/salt-contrib/blob/062355938ad1cced273056e9c23dc344c6a2c858/modules/smx.py#L228-L245
PyTorchLightning/lightning-bolts
22e494e546e7fe322d6b4cf36258819c7ba58e02
pl_bolts/datamodules/cifar10_datamodule.py
python
TinyCIFAR10DataModule.__init__
( self, data_dir: Optional[str] = None, val_split: int = 50, num_workers: int = 0, num_samples: int = 100, labels: Optional[Sequence] = (1, 5, 8), *args: Any, **kwargs: Any, )
Args: data_dir: where to save/load the data val_split: how many of the training images to use for the validation split num_workers: how many workers to use for loading data num_samples: number of examples per selected class/label labels: list selected CIFAR10 classes/labels
Args: data_dir: where to save/load the data val_split: how many of the training images to use for the validation split num_workers: how many workers to use for loading data num_samples: number of examples per selected class/label labels: list selected CIFAR10 classes/labels
[ "Args", ":", "data_dir", ":", "where", "to", "save", "/", "load", "the", "data", "val_split", ":", "how", "many", "of", "the", "training", "images", "to", "use", "for", "the", "validation", "split", "num_workers", ":", "how", "many", "workers", "to", "us...
def __init__( self, data_dir: Optional[str] = None, val_split: int = 50, num_workers: int = 0, num_samples: int = 100, labels: Optional[Sequence] = (1, 5, 8), *args: Any, **kwargs: Any, ) -> None: """ Args: data_dir: where to save/load the data val_split: how many of the training images to use for the validation split num_workers: how many workers to use for loading data num_samples: number of examples per selected class/label labels: list selected CIFAR10 classes/labels """ super().__init__(data_dir, val_split, num_workers, *args, **kwargs) self.num_samples = num_samples # type: ignore[misc] self.labels = sorted(labels) if labels is not None else set(range(10)) self.extra_args = dict(num_samples=self.num_samples, labels=self.labels)
[ "def", "__init__", "(", "self", ",", "data_dir", ":", "Optional", "[", "str", "]", "=", "None", ",", "val_split", ":", "int", "=", "50", ",", "num_workers", ":", "int", "=", "0", ",", "num_samples", ":", "int", "=", "100", ",", "labels", ":", "Opti...
https://github.com/PyTorchLightning/lightning-bolts/blob/22e494e546e7fe322d6b4cf36258819c7ba58e02/pl_bolts/datamodules/cifar10_datamodule.py#L147-L169
mathics/Mathics
318e06dea8f1c70758a50cb2f95c9900150e3a68
mathics/builtin/numbers/numbertheory.py
python
PrimePi.apply
(self, n, evaluation)
return from_python(result)
PrimePi[n_?NumericQ]
PrimePi[n_?NumericQ]
[ "PrimePi", "[", "n_?NumericQ", "]" ]
def apply(self, n, evaluation): "PrimePi[n_?NumericQ]" result = sympy.ntheory.primepi(n.to_python(n_evaluation=evaluation)) return from_python(result)
[ "def", "apply", "(", "self", ",", "n", ",", "evaluation", ")", ":", "result", "=", "sympy", ".", "ntheory", ".", "primepi", "(", "n", ".", "to_python", "(", "n_evaluation", "=", "evaluation", ")", ")", "return", "from_python", "(", "result", ")" ]
https://github.com/mathics/Mathics/blob/318e06dea8f1c70758a50cb2f95c9900150e3a68/mathics/builtin/numbers/numbertheory.py#L600-L603
ZhaoJ9014/face.evoLVe
63520924167efb9ef53dcceed0a15cf739cad1c9
paddle/backbone/model_resnet.py
python
ResNet_101
(input_size, **kwargs)
return model
Constructs a ResNet-101 model.
Constructs a ResNet-101 model.
[ "Constructs", "a", "ResNet", "-", "101", "model", "." ]
def ResNet_101(input_size, **kwargs): """Constructs a ResNet-101 model. """ model = ResNet(input_size, Bottleneck, [3, 4, 23, 3], **kwargs) return model
[ "def", "ResNet_101", "(", "input_size", ",", "*", "*", "kwargs", ")", ":", "model", "=", "ResNet", "(", "input_size", ",", "Bottleneck", ",", "[", "3", ",", "4", ",", "23", ",", "3", "]", ",", "*", "*", "kwargs", ")", "return", "model" ]
https://github.com/ZhaoJ9014/face.evoLVe/blob/63520924167efb9ef53dcceed0a15cf739cad1c9/paddle/backbone/model_resnet.py#L176-L181
art-programmer/PlaneNet
ccc4423d278388d01cb3300be992b951b90acc7a
code/polls/models/obj2egg.py
python
floats
(float_list)
return [ float(number) for number in float_list ]
coerce a list of strings that represent floats into a list of floats
coerce a list of strings that represent floats into a list of floats
[ "coerce", "a", "list", "of", "strings", "that", "represent", "floats", "into", "a", "list", "of", "floats" ]
def floats(float_list): """coerce a list of strings that represent floats into a list of floats""" return [ float(number) for number in float_list ]
[ "def", "floats", "(", "float_list", ")", ":", "return", "[", "float", "(", "number", ")", "for", "number", "in", "float_list", "]" ]
https://github.com/art-programmer/PlaneNet/blob/ccc4423d278388d01cb3300be992b951b90acc7a/code/polls/models/obj2egg.py#L27-L29
microsoft/NimbusML
f6be39ce9359786976429bab0ccd837e849b4ba5
src/python/nimbusml/ensemble/sub_model_selector/classifierbestdiverseselector.py
python
ClassifierBestDiverseSelector.get_params
(self, deep=False)
return core.get_params(self)
Get the parameters for this operator.
Get the parameters for this operator.
[ "Get", "the", "parameters", "for", "this", "operator", "." ]
def get_params(self, deep=False): """ Get the parameters for this operator. """ return core.get_params(self)
[ "def", "get_params", "(", "self", ",", "deep", "=", "False", ")", ":", "return", "core", ".", "get_params", "(", "self", ")" ]
https://github.com/microsoft/NimbusML/blob/f6be39ce9359786976429bab0ccd837e849b4ba5/src/python/nimbusml/ensemble/sub_model_selector/classifierbestdiverseselector.py#L52-L56
multani/sonata
48f745662b848308e12a15cbecd2ca44cf618417
sonata/audioscrobbler.py
python
AudioScrobblerError.__init__
(self, message)
Create a new AudioScrobblerError. :Parameters: - `message`: The message that will be displayed to the user
Create a new AudioScrobblerError.
[ "Create", "a", "new", "AudioScrobblerError", "." ]
def __init__(self, message): """ Create a new AudioScrobblerError. :Parameters: - `message`: The message that will be displayed to the user """ self.message = message
[ "def", "__init__", "(", "self", ",", "message", ")", ":", "self", ".", "message", "=", "message" ]
https://github.com/multani/sonata/blob/48f745662b848308e12a15cbecd2ca44cf618417/sonata/audioscrobbler.py#L341-L347
google/transitfeed
d727e97cb66ac2ca2d699a382ea1d449ee26c2a1
gtfsscheduleviewer/marey_graph.py
python
MareyGraph.AddStationDecoration
(self, index, color="#f00")
Flushes existing decorations and highlights the given station-line. Args: # Integer, index of stop to be highlighted. index: 4 # An optional string with a html color code color: "#fff"
Flushes existing decorations and highlights the given station-line.
[ "Flushes", "existing", "decorations", "and", "highlights", "the", "given", "station", "-", "line", "." ]
def AddStationDecoration(self, index, color="#f00"): """Flushes existing decorations and highlights the given station-line. Args: # Integer, index of stop to be highlighted. index: 4 # An optional string with a html color code color: "#fff" """ tmpstr = str() num_stations = len(self._stations) ind = int(index) if self._stations: if 0<ind<num_stations: y = self._stations[ind] tmpstr = '<polyline class="Dec" stroke="%s" points="%s,%s,%s,%s" />' \ % (color, 20, 20+y+.5, self._gwidth+20, 20+y+.5) self._decorators.append(tmpstr)
[ "def", "AddStationDecoration", "(", "self", ",", "index", ",", "color", "=", "\"#f00\"", ")", ":", "tmpstr", "=", "str", "(", ")", "num_stations", "=", "len", "(", "self", ".", "_stations", ")", "ind", "=", "int", "(", "index", ")", "if", "self", "."...
https://github.com/google/transitfeed/blob/d727e97cb66ac2ca2d699a382ea1d449ee26c2a1/gtfsscheduleviewer/marey_graph.py#L400-L417
trezor/trezor-core
18c3a6a5bd45923380312b064be96155f5a7377d
src/apps/monero/signing/step_09_sign_input.py
python
sign_input
( state: State, src_entr: MoneroTransactionSourceEntry, vini_bin: bytes, vini_hmac: bytes, pseudo_out: bytes, pseudo_out_hmac: bytes, pseudo_out_alpha_enc: bytes, spend_enc: bytes, )
return MoneroTransactionSignInputAck( signature=mg_buffer, pseudo_out=crypto.encodepoint(pseudo_out_c) )
:param state: transaction state :param src_entr: Source entry :param vini_bin: tx.vin[i] for the transaction. Contains key image, offsets, amount (usually zero) :param vini_hmac: HMAC for the tx.vin[i] as returned from Trezor :param pseudo_out: Pedersen commitment for the current input, uses pseudo_out_alpha as a mask. Only applicable for RCTTypeSimple. :param pseudo_out_hmac: HMAC for pseudo_out :param pseudo_out_alpha_enc: alpha mask used in pseudo_out, only applicable for RCTTypeSimple. Encrypted. :param spend_enc: one time address spending private key. Encrypted. :return: Generated signature MGs[i]
:param state: transaction state :param src_entr: Source entry :param vini_bin: tx.vin[i] for the transaction. Contains key image, offsets, amount (usually zero) :param vini_hmac: HMAC for the tx.vin[i] as returned from Trezor :param pseudo_out: Pedersen commitment for the current input, uses pseudo_out_alpha as a mask. Only applicable for RCTTypeSimple. :param pseudo_out_hmac: HMAC for pseudo_out :param pseudo_out_alpha_enc: alpha mask used in pseudo_out, only applicable for RCTTypeSimple. Encrypted. :param spend_enc: one time address spending private key. Encrypted. :return: Generated signature MGs[i]
[ ":", "param", "state", ":", "transaction", "state", ":", "param", "src_entr", ":", "Source", "entry", ":", "param", "vini_bin", ":", "tx", ".", "vin", "[", "i", "]", "for", "the", "transaction", ".", "Contains", "key", "image", "offsets", "amount", "(", ...
async def sign_input( state: State, src_entr: MoneroTransactionSourceEntry, vini_bin: bytes, vini_hmac: bytes, pseudo_out: bytes, pseudo_out_hmac: bytes, pseudo_out_alpha_enc: bytes, spend_enc: bytes, ): """ :param state: transaction state :param src_entr: Source entry :param vini_bin: tx.vin[i] for the transaction. Contains key image, offsets, amount (usually zero) :param vini_hmac: HMAC for the tx.vin[i] as returned from Trezor :param pseudo_out: Pedersen commitment for the current input, uses pseudo_out_alpha as a mask. Only applicable for RCTTypeSimple. :param pseudo_out_hmac: HMAC for pseudo_out :param pseudo_out_alpha_enc: alpha mask used in pseudo_out, only applicable for RCTTypeSimple. Encrypted. :param spend_enc: one time address spending private key. Encrypted. :return: Generated signature MGs[i] """ await confirms.transaction_step( state.ctx, state.STEP_SIGN, state.current_input_index + 1, state.input_count ) state.current_input_index += 1 if state.current_input_index >= state.input_count: raise ValueError("Invalid inputs count") if pseudo_out is None: raise ValueError("SimpleRCT requires pseudo_out but none provided") if pseudo_out_alpha_enc is None: raise ValueError("SimpleRCT requires pseudo_out's mask but none provided") input_position = state.source_permutation[state.current_input_index] mods = utils.unimport_begin() # Check input's HMAC from apps.monero.signing import offloading_keys vini_hmac_comp = await offloading_keys.gen_hmac_vini( state.key_hmac, src_entr, vini_bin, input_position ) if not crypto.ct_equals(vini_hmac_comp, vini_hmac): raise ValueError("HMAC is not correct") gc.collect() state.mem_trace(1, True) from apps.monero.xmr.crypto import chacha_poly pseudo_out_alpha = crypto.decodeint( chacha_poly.decrypt_pack( offloading_keys.enc_key_txin_alpha(state.key_enc, input_position), bytes(pseudo_out_alpha_enc), ) ) # Last pseud_out is recomputed so mask sums hold if state.is_det_mask() and input_position + 1 == state.input_count: # Recompute the lash alpha so the sum holds state.mem_trace("Correcting alpha") alpha_diff = crypto.sc_sub(state.sumout, state.sumpouts_alphas) crypto.sc_add_into(pseudo_out_alpha, pseudo_out_alpha, alpha_diff) pseudo_out_c = crypto.gen_commitment(pseudo_out_alpha, state.input_last_amount) else: if input_position + 1 == state.input_count: utils.ensure( crypto.sc_eq(state.sumpouts_alphas, state.sumout), "Sum eq error" ) # both pseudo_out and its mask were offloaded so we need to # validate pseudo_out's HMAC and decrypt the alpha pseudo_out_hmac_comp = crypto.compute_hmac( offloading_keys.hmac_key_txin_comm(state.key_hmac, input_position), pseudo_out, ) if not crypto.ct_equals(pseudo_out_hmac_comp, pseudo_out_hmac): raise ValueError("HMAC is not correct") pseudo_out_c = crypto.decodepoint(pseudo_out) state.mem_trace(2, True) # Spending secret spend_key = crypto.decodeint( chacha_poly.decrypt_pack( offloading_keys.enc_key_spend(state.key_enc, input_position), bytes(spend_enc), ) ) del ( offloading_keys, chacha_poly, pseudo_out, pseudo_out_hmac, pseudo_out_alpha_enc, spend_enc, ) utils.unimport_end(mods) state.mem_trace(3, True) from apps.monero.xmr.serialize_messages.ct_keys import CtKey # Basic setup, sanity check index = src_entr.real_output input_secret_key = CtKey(dest=spend_key, mask=crypto.decodeint(src_entr.mask)) kLRki = None # for multisig: src_entr.multisig_kLRki # Private key correctness test utils.ensure( crypto.point_eq( crypto.decodepoint(src_entr.outputs[src_entr.real_output].key.dest), crypto.scalarmult_base(input_secret_key.dest), ), "Real source entry's destination does not equal spend key's", ) utils.ensure( crypto.point_eq( crypto.decodepoint(src_entr.outputs[src_entr.real_output].key.commitment), crypto.gen_commitment(input_secret_key.mask, src_entr.amount), ), "Real source entry's mask does not equal spend key's", ) state.mem_trace(4, True) from apps.monero.xmr import mlsag mg_buffer = [] ring_pubkeys = [x.key for x in src_entr.outputs] del src_entr mlsag.generate_mlsag_simple( state.full_message, ring_pubkeys, input_secret_key, pseudo_out_alpha, pseudo_out_c, kLRki, index, mg_buffer, ) del (input_secret_key, pseudo_out_alpha, mlsag, ring_pubkeys) state.mem_trace(5, True) from trezor.messages.MoneroTransactionSignInputAck import ( MoneroTransactionSignInputAck, ) return MoneroTransactionSignInputAck( signature=mg_buffer, pseudo_out=crypto.encodepoint(pseudo_out_c) )
[ "async", "def", "sign_input", "(", "state", ":", "State", ",", "src_entr", ":", "MoneroTransactionSourceEntry", ",", "vini_bin", ":", "bytes", ",", "vini_hmac", ":", "bytes", ",", "pseudo_out", ":", "bytes", ",", "pseudo_out_hmac", ":", "bytes", ",", "pseudo_o...
https://github.com/trezor/trezor-core/blob/18c3a6a5bd45923380312b064be96155f5a7377d/src/apps/monero/signing/step_09_sign_input.py#L28-L183
RaRe-Technologies/sqlitedict
7f87568bf0542523fa3c89dd37c9b8f29ffba0be
sqlitedict.py
python
open
(*args, **kwargs)
return SqliteDict(*args, **kwargs)
See documentation of the SqliteDict class.
See documentation of the SqliteDict class.
[ "See", "documentation", "of", "the", "SqliteDict", "class", "." ]
def open(*args, **kwargs): """See documentation of the SqliteDict class.""" return SqliteDict(*args, **kwargs)
[ "def", "open", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "SqliteDict", "(", "*", "args", ",", "*", "*", "kwargs", ")" ]
https://github.com/RaRe-Technologies/sqlitedict/blob/7f87568bf0542523fa3c89dd37c9b8f29ffba0be/sqlitedict.py#L93-L95
dcsync/pycobalt
d3a630bfadaeeb6c99aad28f226abe48f6b4acca
pycobalt/console.py
python
black
(text)
return codes['black'] + text + codes['reset']
Style text black for the Script Console and Beacon Console. :param text: Text to style :return: Styled text
Style text black for the Script Console and Beacon Console.
[ "Style", "text", "black", "for", "the", "Script", "Console", "and", "Beacon", "Console", "." ]
def black(text): """ Style text black for the Script Console and Beacon Console. :param text: Text to style :return: Styled text """ return codes['black'] + text + codes['reset']
[ "def", "black", "(", "text", ")", ":", "return", "codes", "[", "'black'", "]", "+", "text", "+", "codes", "[", "'reset'", "]" ]
https://github.com/dcsync/pycobalt/blob/d3a630bfadaeeb6c99aad28f226abe48f6b4acca/pycobalt/console.py#L440-L448
mrJean1/PyGeodesy
7da5ca71aa3edb7bc49e219e0b8190686e1a7965
pygeodesy/fmath.py
python
Fsum.__iset__
(self, other)
return self
Override this instance with an other. @arg other: L{Fsum} instance or C{scalar}. @return: This instance, overridden (L{Fsum}). @raise TypeError: Invalid B{C{other}} type.
Override this instance with an other.
[ "Override", "this", "instance", "with", "an", "other", "." ]
def __iset__(self, other): # PYCHOK not special '''Override this instance with an other. @arg other: L{Fsum} instance or C{scalar}. @return: This instance, overridden (L{Fsum}). @raise TypeError: Invalid B{C{other}} type. ''' if isscalar(other): self._n = 1 self._ps = [float(other)] self._fsum2_ = float(other) elif isinstance(other, Fsum): if other is not self: self._n = other._n self._ps = list(other._ps) self._fsum2_ = other._fsum2_ else: raise self._Error(_isub_, other) return self
[ "def", "__iset__", "(", "self", ",", "other", ")", ":", "# PYCHOK not special", "if", "isscalar", "(", "other", ")", ":", "self", ".", "_n", "=", "1", "self", ".", "_ps", "=", "[", "float", "(", "other", ")", "]", "self", ".", "_fsum2_", "=", "floa...
https://github.com/mrJean1/PyGeodesy/blob/7da5ca71aa3edb7bc49e219e0b8190686e1a7965/pygeodesy/fmath.py#L276-L296
zvtvz/zvt
054bf8a3e7a049df7087c324fa87e8effbaf5bdc
src/zvt/__init__.py
python
init_plugins
()
[]
def init_plugins(): for finder, name, ispkg in pkgutil.iter_modules(): if name.startswith("zvt_"): try: _plugins[name] = importlib.import_module(name) except Exception as e: logger.warning(f"failed to load plugin {name}", e) logger.info(f"loaded plugins:{_plugins}")
[ "def", "init_plugins", "(", ")", ":", "for", "finder", ",", "name", ",", "ispkg", "in", "pkgutil", ".", "iter_modules", "(", ")", ":", "if", "name", ".", "startswith", "(", "\"zvt_\"", ")", ":", "try", ":", "_plugins", "[", "name", "]", "=", "importl...
https://github.com/zvtvz/zvt/blob/054bf8a3e7a049df7087c324fa87e8effbaf5bdc/src/zvt/__init__.py#L158-L165
huggingface/transformers
623b4f7c63f60cce917677ee704d6c93ee960b4b
src/transformers/models/lxmert/modeling_lxmert.py
python
LxmertOutput.__init__
(self, config)
[]
def __init__(self, config): super().__init__() self.dense = nn.Linear(config.intermediate_size, config.hidden_size) self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=1e-12) self.dropout = nn.Dropout(config.hidden_dropout_prob)
[ "def", "__init__", "(", "self", ",", "config", ")", ":", "super", "(", ")", ".", "__init__", "(", ")", "self", ".", "dense", "=", "nn", ".", "Linear", "(", "config", ".", "intermediate_size", ",", "config", ".", "hidden_size", ")", "self", ".", "Laye...
https://github.com/huggingface/transformers/blob/623b4f7c63f60cce917677ee704d6c93ee960b4b/src/transformers/models/lxmert/modeling_lxmert.py#L437-L441
goace/personal-file-sharing-center
4a5b903b003f2db1306e77c5e51b6660fc5dbc6a
web/wsgiserver/__init__.py
python
KnownLengthRFile.readline
(self, size=None)
return data
[]
def readline(self, size=None): if self.remaining == 0: return '' if size is None: size = self.remaining else: size = min(size, self.remaining) data = self.rfile.readline(size) self.remaining -= len(data) return data
[ "def", "readline", "(", "self", ",", "size", "=", "None", ")", ":", "if", "self", ".", "remaining", "==", "0", ":", "return", "''", "if", "size", "is", "None", ":", "size", "=", "self", ".", "remaining", "else", ":", "size", "=", "min", "(", "siz...
https://github.com/goace/personal-file-sharing-center/blob/4a5b903b003f2db1306e77c5e51b6660fc5dbc6a/web/wsgiserver/__init__.py#L284-L294
openshift/openshift-tools
1188778e728a6e4781acf728123e5b356380fe6f
ansible/roles/lib_oa_openshift/library/oc_pvc.py
python
OCPVC.needs_update
(self)
return not Utils.check_def_equal(self.config.data, self.pvc.yaml_dict, skip_keys=skip, debug=True)
verify an update is needed
verify an update is needed
[ "verify", "an", "update", "is", "needed" ]
def needs_update(self): ''' verify an update is needed ''' if self.pvc.get_volume_name() or self.pvc.is_bound(): return False skip = [] return not Utils.check_def_equal(self.config.data, self.pvc.yaml_dict, skip_keys=skip, debug=True)
[ "def", "needs_update", "(", "self", ")", ":", "if", "self", ".", "pvc", ".", "get_volume_name", "(", ")", "or", "self", ".", "pvc", ".", "is_bound", "(", ")", ":", "return", "False", "skip", "=", "[", "]", "return", "not", "Utils", ".", "check_def_eq...
https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/ansible/roles/lib_oa_openshift/library/oc_pvc.py#L1770-L1776
omz/PythonistaAppTemplate
f560f93f8876d82a21d108977f90583df08d55af
PythonistaAppTemplate/PythonistaKit.framework/pylib_ext/matplotlib/lines.py
python
Line2D.set_marker
(self, marker)
Set the line marker Parameters ----------- marker: marker style See `~matplotlib.markers` for full description of possible argument
Set the line marker
[ "Set", "the", "line", "marker" ]
def set_marker(self, marker): """ Set the line marker Parameters ----------- marker: marker style See `~matplotlib.markers` for full description of possible argument """ self._marker.set_marker(marker)
[ "def", "set_marker", "(", "self", ",", "marker", ")", ":", "self", ".", "_marker", ".", "set_marker", "(", "marker", ")" ]
https://github.com/omz/PythonistaAppTemplate/blob/f560f93f8876d82a21d108977f90583df08d55af/PythonistaAppTemplate/PythonistaKit.framework/pylib_ext/matplotlib/lines.py#L842-L854
nipy/nipy
d16d268938dcd5c15748ca051532c21f57cf8a22
nipy/algorithms/clustering/imm.py
python
IMM.reduce
(self, z)
return z
Reduce the assignments by removing empty clusters and update self.k Parameters ---------- z: array of shape(n), a vector of membership variables changed in place Returns ------- z: the remapped values
Reduce the assignments by removing empty clusters and update self.k
[ "Reduce", "the", "assignments", "by", "removing", "empty", "clusters", "and", "update", "self", ".", "k" ]
def reduce(self, z): """Reduce the assignments by removing empty clusters and update self.k Parameters ---------- z: array of shape(n), a vector of membership variables changed in place Returns ------- z: the remapped values """ uz = np.unique(z[z > - 1]) for i, k in enumerate(uz): z[z == k] = i self.k = z.max() + 1 return z
[ "def", "reduce", "(", "self", ",", "z", ")", ":", "uz", "=", "np", ".", "unique", "(", "z", "[", "z", ">", "-", "1", "]", ")", "for", "i", ",", "k", "in", "enumerate", "(", "uz", ")", ":", "z", "[", "z", "==", "k", "]", "=", "i", "self"...
https://github.com/nipy/nipy/blob/d16d268938dcd5c15748ca051532c21f57cf8a22/nipy/algorithms/clustering/imm.py#L275-L291
Map-A-Droid/MAD
81375b5c9ccc5ca3161eb487aa81469d40ded221
mapadroid/worker/WorkerBase.py
python
WorkerBase._internal_grab_next_location
(self)
return self._mapping_manager.routemanager_get_settings(self._routemanager_name)
[]
def _internal_grab_next_location(self): # TODO: consider adding runWarningThreadEvent.set() self._last_known_state["last_location"] = self.last_location self.logger.debug("Requesting next location from routemanager") # requesting a location is blocking (iv_mitm will wait for a prioQ item), we really need to clean # the workers up... if int(self._geofix_sleeptime) > 0: self.logger.info('Getting a geofix position from MADMin - sleeping for {} seconds', self._geofix_sleeptime) time.sleep(int(self._geofix_sleeptime)) self._geofix_sleeptime = 0 self._check_for_mad_job() self.current_location = self._mapping_manager.routemanager_get_next_location(self._routemanager_name, self._origin) self._wait_again: int = 1 return self._mapping_manager.routemanager_get_settings(self._routemanager_name)
[ "def", "_internal_grab_next_location", "(", "self", ")", ":", "# TODO: consider adding runWarningThreadEvent.set()", "self", ".", "_last_known_state", "[", "\"last_location\"", "]", "=", "self", ".", "last_location", "self", ".", "logger", ".", "debug", "(", "\"Requesti...
https://github.com/Map-A-Droid/MAD/blob/81375b5c9ccc5ca3161eb487aa81469d40ded221/mapadroid/worker/WorkerBase.py#L578-L595
tendenci/tendenci
0f2c348cc0e7d41bc56f50b00ce05544b083bf1d
tendenci/apps/help_files/templatetags/help_file_tags.py
python
help_file_current_app
(context, user, help_file=None)
return context
[]
def help_file_current_app(context, user, help_file=None): context.update({ "app_object": help_file, "user": user }) return context
[ "def", "help_file_current_app", "(", "context", ",", "user", ",", "help_file", "=", "None", ")", ":", "context", ".", "update", "(", "{", "\"app_object\"", ":", "help_file", ",", "\"user\"", ":", "user", "}", ")", "return", "context" ]
https://github.com/tendenci/tendenci/blob/0f2c348cc0e7d41bc56f50b00ce05544b083bf1d/tendenci/apps/help_files/templatetags/help_file_tags.py#L30-L35
PaddlePaddle/PaddleX
2bab73f81ab54e328204e7871e6ae4a82e719f5d
static/paddlex/cv/nets/detection/loss/iou_loss.py
python
IouLoss._create_tensor_from_numpy
(self, numpy_array)
return paddle_array
[]
def _create_tensor_from_numpy(self, numpy_array): paddle_array = fluid.layers.create_parameter( attr=ParamAttr(), shape=numpy_array.shape, dtype=numpy_array.dtype, default_initializer=NumpyArrayInitializer(numpy_array)) paddle_array.stop_gradient = True return paddle_array
[ "def", "_create_tensor_from_numpy", "(", "self", ",", "numpy_array", ")", ":", "paddle_array", "=", "fluid", ".", "layers", ".", "create_parameter", "(", "attr", "=", "ParamAttr", "(", ")", ",", "shape", "=", "numpy_array", ".", "shape", ",", "dtype", "=", ...
https://github.com/PaddlePaddle/PaddleX/blob/2bab73f81ab54e328204e7871e6ae4a82e719f5d/static/paddlex/cv/nets/detection/loss/iou_loss.py#L228-L235
atbaker/spin-docker
33b985fffb82effe18b65587821fd9d7eecc2b61
spindocker/tasks.py
python
remove_container
(self, container_id)
Deletes a container asynchronously.
Deletes a container asynchronously.
[ "Deletes", "a", "container", "asynchronously", "." ]
def remove_container(self, container_id): """Deletes a container asynchronously.""" delete_container_ip(container_id) try: client.stop(container_id) client.remove_container(container_id) except APIError as exception: raise self.retry(exc=exception) r.delete('containers:%s' % container_id)
[ "def", "remove_container", "(", "self", ",", "container_id", ")", ":", "delete_container_ip", "(", "container_id", ")", "try", ":", "client", ".", "stop", "(", "container_id", ")", "client", ".", "remove_container", "(", "container_id", ")", "except", "APIError"...
https://github.com/atbaker/spin-docker/blob/33b985fffb82effe18b65587821fd9d7eecc2b61/spindocker/tasks.py#L103-L113
orakaro/rainbowstream
96141fac10675e0775d703f65a59c4477a48c57e
rainbowstream/util.py
python
format_prefix
(listname='', keyword='')
return formattedPrefix
Format the custom prefix
Format the custom prefix
[ "Format", "the", "custom", "prefix" ]
def format_prefix(listname='', keyword=''): """ Format the custom prefix """ formattedPrefix = c['PREFIX'] owner = '@' + c['original_name'] place = '' # Public stream if keyword: formattedPrefix = ''.join(formattedPrefix.split('#owner')) formattedPrefix = ''.join(formattedPrefix.split('#place')) formattedPrefix = ''.join(formattedPrefix.split('#me')) # List stream elif listname: formattedPrefix = ''.join(formattedPrefix.split('#keyword')) formattedPrefix = ''.join(formattedPrefix.split('#me')) owner, place = listname.split('/') place = '/' + place # Personal stream else: formattedPrefix = ''.join(formattedPrefix.split('#keyword')) formattedPrefix = ''.join(formattedPrefix.split('#owner')) formattedPrefix = ''.join(formattedPrefix.split('#place')) formattedPrefix = formattedPrefix.replace('#owner', owner) formattedPrefix = formattedPrefix.replace('#place', place) formattedPrefix = formattedPrefix.replace('#keyword', keyword) formattedPrefix = formattedPrefix.replace('#me', '@' + c['original_name']) return formattedPrefix
[ "def", "format_prefix", "(", "listname", "=", "''", ",", "keyword", "=", "''", ")", ":", "formattedPrefix", "=", "c", "[", "'PREFIX'", "]", "owner", "=", "'@'", "+", "c", "[", "'original_name'", "]", "place", "=", "''", "# Public stream", "if", "keyword"...
https://github.com/orakaro/rainbowstream/blob/96141fac10675e0775d703f65a59c4477a48c57e/rainbowstream/util.py#L20-L49
BigBrotherBot/big-brother-bot
848823c71413c86e7f1ff9584f43e08d40a7f2c0
b3/plugins/poweradminhf/__init__.py
python
PoweradminhfPlugin.cmd_panextmap
(self, data, client=None, cmd=None)
- force server to the Next Map in rotation
- force server to the Next Map in rotation
[ "-", "force", "server", "to", "the", "Next", "Map", "in", "rotation" ]
def cmd_panextmap(self, data, client=None, cmd=None): """ - force server to the Next Map in rotation """ self.console.write('admin NextMap')
[ "def", "cmd_panextmap", "(", "self", ",", "data", ",", "client", "=", "None", ",", "cmd", "=", "None", ")", ":", "self", ".", "console", ".", "write", "(", "'admin NextMap'", ")" ]
https://github.com/BigBrotherBot/big-brother-bot/blob/848823c71413c86e7f1ff9584f43e08d40a7f2c0/b3/plugins/poweradminhf/__init__.py#L319-L323
noyoshi/smart-sketch
8a3c0c3af4df75bc198168829d59ef367b21ebfb
backend/models/pix2pix_model.py
python
Pix2PixModel.forward
(self, data, mode, verbose=True)
Foward pass, overrides something
Foward pass, overrides something
[ "Foward", "pass", "overrides", "something" ]
def forward(self, data, mode, verbose=True): """Foward pass, overrides something""" input_semantics = self.preprocess_input(data, verbose) with torch.no_grad(): return self.generate_fake(input_semantics)
[ "def", "forward", "(", "self", ",", "data", ",", "mode", ",", "verbose", "=", "True", ")", ":", "input_semantics", "=", "self", ".", "preprocess_input", "(", "data", ",", "verbose", ")", "with", "torch", ".", "no_grad", "(", ")", ":", "return", "self",...
https://github.com/noyoshi/smart-sketch/blob/8a3c0c3af4df75bc198168829d59ef367b21ebfb/backend/models/pix2pix_model.py#L35-L39
ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework
cb692f527e4e819b6c228187c5702d990a180043
bin/x86/Debug/scripting_engine/Lib/lib2to3/pytree.py
python
generate_matches
(patterns, nodes)
Generator yielding matches for a sequence of patterns and nodes. Args: patterns: a sequence of patterns nodes: a sequence of nodes Yields: (count, results) tuples where: count: the entire sequence of patterns matches nodes[:count]; results: dict containing named submatches.
Generator yielding matches for a sequence of patterns and nodes.
[ "Generator", "yielding", "matches", "for", "a", "sequence", "of", "patterns", "and", "nodes", "." ]
def generate_matches(patterns, nodes): """ Generator yielding matches for a sequence of patterns and nodes. Args: patterns: a sequence of patterns nodes: a sequence of nodes Yields: (count, results) tuples where: count: the entire sequence of patterns matches nodes[:count]; results: dict containing named submatches. """ if not patterns: yield 0, {} else: p, rest = patterns[0], patterns[1:] for c0, r0 in p.generate_matches(nodes): if not rest: yield c0, r0 else: for c1, r1 in generate_matches(rest, nodes[c0:]): r = {} r.update(r0) r.update(r1) yield c0 + c1, r
[ "def", "generate_matches", "(", "patterns", ",", "nodes", ")", ":", "if", "not", "patterns", ":", "yield", "0", ",", "{", "}", "else", ":", "p", ",", "rest", "=", "patterns", "[", "0", "]", ",", "patterns", "[", "1", ":", "]", "for", "c0", ",", ...
https://github.com/ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework/blob/cb692f527e4e819b6c228187c5702d990a180043/bin/x86/Debug/scripting_engine/Lib/lib2to3/pytree.py#L862-L887
bugy/script-server
9a57ce15903c81bcb537b872f1330ee55ba31563
src/config/script/list_values.py
python
FilesProvider.__init__
(self, file_dir, file_type=None, file_extensions=None, excluded_files_matcher: FileMatcher = None)
[]
def __init__(self, file_dir, file_type=None, file_extensions=None, excluded_files_matcher: FileMatcher = None) -> None: self._file_dir = file_dir try: self._values = list_files(file_dir, file_type=file_type, file_extensions=file_extensions, excluded_files_matcher=excluded_files_matcher) except InvalidFileException as e: LOGGER.warning('Failed to list files for ' + file_dir + ': ' + str(e)) self._values = []
[ "def", "__init__", "(", "self", ",", "file_dir", ",", "file_type", "=", "None", ",", "file_extensions", "=", "None", ",", "excluded_files_matcher", ":", "FileMatcher", "=", "None", ")", "->", "None", ":", "self", ".", "_file_dir", "=", "file_dir", "try", "...
https://github.com/bugy/script-server/blob/9a57ce15903c81bcb537b872f1330ee55ba31563/src/config/script/list_values.py#L109-L123
IronLanguages/ironpython3
7a7bb2a872eeab0d1009fc8a6e24dca43f65b693
Src/StdLib/Lib/multiprocessing/heap.py
python
Heap.__init__
(self, size=mmap.PAGESIZE)
[]
def __init__(self, size=mmap.PAGESIZE): self._lastpid = os.getpid() self._lock = threading.Lock() self._size = size self._lengths = [] self._len_to_seq = {} self._start_to_block = {} self._stop_to_block = {} self._allocated_blocks = set() self._arenas = [] # list of pending blocks to free - see free() comment below self._pending_free_blocks = []
[ "def", "__init__", "(", "self", ",", "size", "=", "mmap", ".", "PAGESIZE", ")", ":", "self", ".", "_lastpid", "=", "os", ".", "getpid", "(", ")", "self", ".", "_lock", "=", "threading", ".", "Lock", "(", ")", "self", ".", "_size", "=", "size", "s...
https://github.com/IronLanguages/ironpython3/blob/7a7bb2a872eeab0d1009fc8a6e24dca43f65b693/Src/StdLib/Lib/multiprocessing/heap.py#L94-L105
great-expectations/great_expectations
45224cb890aeae725af25905923d0dbbab2d969d
great_expectations/dataset/sparkdf_dataset.py
python
MetaSparkDFDataset.column_map_expectation
(cls, func)
return inner_wrapper
Constructs an expectation using column-map semantics. The MetaSparkDFDataset implementation replaces the "column" parameter supplied by the user with a Spark Dataframe with the actual column data. The current approach for functions implementing expectation logic is to append a column named "__success" to this dataframe and return to this decorator. See :func:`column_map_expectation <great_expectations.Dataset.base.Dataset.column_map_expectation>` \ for full documentation of this function.
Constructs an expectation using column-map semantics.
[ "Constructs", "an", "expectation", "using", "column", "-", "map", "semantics", "." ]
def column_map_expectation(cls, func): """Constructs an expectation using column-map semantics. The MetaSparkDFDataset implementation replaces the "column" parameter supplied by the user with a Spark Dataframe with the actual column data. The current approach for functions implementing expectation logic is to append a column named "__success" to this dataframe and return to this decorator. See :func:`column_map_expectation <great_expectations.Dataset.base.Dataset.column_map_expectation>` \ for full documentation of this function. """ argspec = inspect.getfullargspec(func)[0][1:] @cls.expectation(argspec) @wraps(func) def inner_wrapper( self, column, mostly=None, result_format=None, *args, **kwargs, ): """ This whole decorator is pending a re-write. Currently there is are huge performance issues when the # of unexpected elements gets large (10s of millions). Additionally, there is likely easy optimization opportunities by coupling result_format with how many different transformations are done on the dataset, as is done in sqlalchemy_dataset. """ # Rename column so we only have to handle dot notation here eval_col = "__eval_col_" + column.replace(".", "__").replace("`", "_") self.spark_df = self.spark_df.withColumn(eval_col, col(column)) if result_format is None: result_format = self.default_expectation_args["result_format"] result_format = parse_result_format(result_format) # this is a little dangerous: expectations that specify "COMPLETE" result format and have a very # large number of unexpected results could hang for a long time. we should either call this out in docs # or put a limit on it if result_format["result_format"] == "COMPLETE": unexpected_count_limit = None else: unexpected_count_limit = result_format["partial_unexpected_count"] col_df = self.spark_df.select(col(eval_col)) # pyspark.sql.DataFrame # a couple of tests indicate that caching here helps performance col_df.persist() element_count = self.get_row_count() # FIXME temporary fix for missing/ignored value if func.__name__ not in [ "expect_column_values_to_not_be_null", "expect_column_values_to_be_null", ]: col_df = col_df.filter(col_df[0].isNotNull()) # these nonnull_counts are cached by SparkDFDataset nonnull_count = self.get_column_nonnull_count(eval_col) else: nonnull_count = element_count # success_df will have columns [column, '__success'] # this feels a little hacky, so might want to change success_df = func(self, col_df, *args, **kwargs) success_count = success_df.filter("__success = True").count() unexpected_count = nonnull_count - success_count if unexpected_count == 0: # save some computation time if no unexpected items maybe_limited_unexpected_list = [] else: # here's an example of a place where we could do optimizations if we knew result format: see # comment block below unexpected_df = success_df.filter("__success = False") if unexpected_count_limit: unexpected_df = unexpected_df.limit(unexpected_count_limit) maybe_limited_unexpected_list = [ row[eval_col] for row in unexpected_df.collect() ] if "output_strftime_format" in kwargs: output_strftime_format = kwargs["output_strftime_format"] parsed_maybe_limited_unexpected_list = [] for val in maybe_limited_unexpected_list: if val is None: parsed_maybe_limited_unexpected_list.append(val) else: if isinstance(val, str): val = parse(val) parsed_maybe_limited_unexpected_list.append( datetime.strftime(val, output_strftime_format) ) maybe_limited_unexpected_list = parsed_maybe_limited_unexpected_list success, percent_success = self._calc_map_expectation_success( success_count, nonnull_count, mostly ) # Currently the abstraction of "result_format" that _format_column_map_output provides # limits some possible optimizations within the column-map decorator. It seems that either # this logic should be completely rolled into the processing done in the column_map decorator, or that the decorator # should do a minimal amount of computation agnostic of result_format, and then delegate the rest to this method. # In the first approach, it could make sense to put all of this decorator logic in Dataset, and then implement # properties that require dataset-type-dependent implementations (as is done with SparkDFDataset.row_count currently). # Then a new dataset type could just implement these properties/hooks and Dataset could deal with caching these and # with the optimizations based on result_format. A side benefit would be implementing an interface for the user # to get basic info about a dataset in a standardized way, e.g. my_dataset.row_count, my_dataset.columns (only for # tablular datasets maybe). However, unclear if this is worth it or if it would conflict with optimizations being done # in other dataset implementations. return_obj = self._format_map_output( result_format, success, element_count, nonnull_count, unexpected_count, maybe_limited_unexpected_list, unexpected_index_list=None, ) # FIXME Temp fix for result format if func.__name__ in [ "expect_column_values_to_not_be_null", "expect_column_values_to_be_null", ]: del return_obj["result"]["unexpected_percent_nonmissing"] del return_obj["result"]["missing_count"] del return_obj["result"]["missing_percent"] try: del return_obj["result"]["partial_unexpected_counts"] except KeyError: pass col_df.unpersist() return return_obj inner_wrapper.__name__ = func.__name__ inner_wrapper.__doc__ = func.__doc__ return inner_wrapper
[ "def", "column_map_expectation", "(", "cls", ",", "func", ")", ":", "argspec", "=", "inspect", ".", "getfullargspec", "(", "func", ")", "[", "0", "]", "[", "1", ":", "]", "@", "cls", ".", "expectation", "(", "argspec", ")", "@", "wraps", "(", "func",...
https://github.com/great-expectations/great_expectations/blob/45224cb890aeae725af25905923d0dbbab2d969d/great_expectations/dataset/sparkdf_dataset.py#L68-L211
Komodo/KomodoEdit
61edab75dce2bdb03943b387b0608ea36f548e8e
contrib/mk/mklib/path.py
python
path.listdir
(self, pattern=None)
return [self / child for child in names]
D.listdir() -> List of items in this directory. Use D.files() or D.dirs() instead if you want a listing of just files or just subdirectories. The elements of the list are path objects. With the optional 'pattern' argument, this only lists items whose names match the given pattern.
D.listdir() -> List of items in this directory.
[ "D", ".", "listdir", "()", "-", ">", "List", "of", "items", "in", "this", "directory", "." ]
def listdir(self, pattern=None): """ D.listdir() -> List of items in this directory. Use D.files() or D.dirs() instead if you want a listing of just files or just subdirectories. The elements of the list are path objects. With the optional 'pattern' argument, this only lists items whose names match the given pattern. """ names = os.listdir(self) if pattern is not None: names = fnmatch.filter(names, pattern) return [self / child for child in names]
[ "def", "listdir", "(", "self", ",", "pattern", "=", "None", ")", ":", "names", "=", "os", ".", "listdir", "(", "self", ")", "if", "pattern", "is", "not", "None", ":", "names", "=", "fnmatch", ".", "filter", "(", "names", ",", "pattern", ")", "retur...
https://github.com/Komodo/KomodoEdit/blob/61edab75dce2bdb03943b387b0608ea36f548e8e/contrib/mk/mklib/path.py#L286-L300
chribsen/simple-machine-learning-examples
dc94e52a4cebdc8bb959ff88b81ff8cfeca25022
venv/lib/python2.7/site-packages/scipy/io/arff/arffread.py
python
maxnomlen
(atrv)
return max(len(i) for i in nomtp)
Given a string containing a nominal type definition, returns the string len of the biggest component. A nominal type is defined as seomthing framed between brace ({}). Parameters ---------- atrv : str Nominal type definition Returns ------- slen : int length of longest component Examples -------- maxnomlen("{floup, bouga, fl, ratata}") returns 6 (the size of ratata, the longest nominal value). >>> maxnomlen("{floup, bouga, fl, ratata}") 6
Given a string containing a nominal type definition, returns the string len of the biggest component.
[ "Given", "a", "string", "containing", "a", "nominal", "type", "definition", "returns", "the", "string", "len", "of", "the", "biggest", "component", "." ]
def maxnomlen(atrv): """Given a string containing a nominal type definition, returns the string len of the biggest component. A nominal type is defined as seomthing framed between brace ({}). Parameters ---------- atrv : str Nominal type definition Returns ------- slen : int length of longest component Examples -------- maxnomlen("{floup, bouga, fl, ratata}") returns 6 (the size of ratata, the longest nominal value). >>> maxnomlen("{floup, bouga, fl, ratata}") 6 """ nomtp = get_nom_val(atrv) return max(len(i) for i in nomtp)
[ "def", "maxnomlen", "(", "atrv", ")", ":", "nomtp", "=", "get_nom_val", "(", "atrv", ")", "return", "max", "(", "len", "(", "i", ")", "for", "i", "in", "nomtp", ")" ]
https://github.com/chribsen/simple-machine-learning-examples/blob/dc94e52a4cebdc8bb959ff88b81ff8cfeca25022/venv/lib/python2.7/site-packages/scipy/io/arff/arffread.py#L117-L142
python-rope/rope
bcdfe6b70b1437d976e21c56b6ec1281b22823aa
rope/base/oi/type_hinting/providers/numpydocstrings.py
python
NumPyDocstringParamParser.__call__
(self, docstring, param_name)
return []
Search `docstring` (in numpydoc format) for type(-s) of `param_name`.
Search `docstring` (in numpydoc format) for type(-s) of `param_name`.
[ "Search", "docstring", "(", "in", "numpydoc", "format", ")", "for", "type", "(", "-", "s", ")", "of", "param_name", "." ]
def __call__(self, docstring, param_name): """Search `docstring` (in numpydoc format) for type(-s) of `param_name`.""" if not docstring: return [] params = NumpyDocString(docstring)._parsed_data["Parameters"] for p_name, p_type, p_descr in params: if p_name == param_name: m = re.match("([^,]+(,[^,]+)*?)(,[ ]*optional)?$", p_type) if m: p_type = m.group(1) if p_type.startswith("{"): types = set(type(x).__name__ for x in literal_eval(p_type)) return list(types) else: return [p_type] return []
[ "def", "__call__", "(", "self", ",", "docstring", ",", "param_name", ")", ":", "if", "not", "docstring", ":", "return", "[", "]", "params", "=", "NumpyDocString", "(", "docstring", ")", ".", "_parsed_data", "[", "\"Parameters\"", "]", "for", "p_name", ",",...
https://github.com/python-rope/rope/blob/bcdfe6b70b1437d976e21c56b6ec1281b22823aa/rope/base/oi/type_hinting/providers/numpydocstrings.py#L17-L33
Dash-Industry-Forum/dash-live-source-simulator
23cb15c35656a731d9f6d78a30f2713eff2ec20d
dashlivesim/dashlib/mp4.py
python
stts_box.sample_time_and_duration
(self, sample_number)
return time, duration
[]
def sample_time_and_duration(self, sample_number): # lookup entry, essentially the same as # entry_index = bisect.bisect_right(self.lookup, sample_number) - 1 entry_index = 0 upper_bound = self.entry_count while entry_index < upper_bound: index = (entry_index + upper_bound) // 2 if sample_number < self.lookup[index]: upper_bound = index else: entry_index = index + 1 entry_index -= 1 start_sample = self.lookup[entry_index] entry = self.entries[entry_index] # calculate sample time based on constant sample durations from # looked-up entry sample_diff = sample_number - start_sample time = entry.cumulative_delta + sample_diff * entry.sample_delta duration = entry.sample_delta return time, duration
[ "def", "sample_time_and_duration", "(", "self", ",", "sample_number", ")", ":", "# lookup entry, essentially the same as", "# entry_index = bisect.bisect_right(self.lookup, sample_number) - 1", "entry_index", "=", "0", "upper_bound", "=", "self", ".", "entry_count", "while", "e...
https://github.com/Dash-Industry-Forum/dash-live-source-simulator/blob/23cb15c35656a731d9f6d78a30f2713eff2ec20d/dashlivesim/dashlib/mp4.py#L1575-L1597
mehulj94/BrainDamage
49a29c2606d5f7c0d9705ae5f4201a6bb25cfe73
eclipse.py
python
pollDevice
()
[]
def pollDevice(): while True: if check_external_drive.FLAG == True: print "[*] Drive Found: ", check_external_drive.DRIVE+":\\" copyFiles(check_external_drive.DRIVE+":\\",os.path.realpath(sys.argv[0])) check_external_drive.FLAG = False
[ "def", "pollDevice", "(", ")", ":", "while", "True", ":", "if", "check_external_drive", ".", "FLAG", "==", "True", ":", "print", "\"[*] Drive Found: \"", ",", "check_external_drive", ".", "DRIVE", "+", "\":\\\\\"", "copyFiles", "(", "check_external_drive", ".", ...
https://github.com/mehulj94/BrainDamage/blob/49a29c2606d5f7c0d9705ae5f4201a6bb25cfe73/eclipse.py#L361-L366
Chaffelson/nipyapi
d3b186fd701ce308c2812746d98af9120955e810
nipyapi/registry/models/restriction.py
python
Restriction.__init__
(self, required_permission=None, explanation=None)
Restriction - a model defined in Swagger
Restriction - a model defined in Swagger
[ "Restriction", "-", "a", "model", "defined", "in", "Swagger" ]
def __init__(self, required_permission=None, explanation=None): """ Restriction - a model defined in Swagger """ self._required_permission = None self._explanation = None if required_permission is not None: self.required_permission = required_permission if explanation is not None: self.explanation = explanation
[ "def", "__init__", "(", "self", ",", "required_permission", "=", "None", ",", "explanation", "=", "None", ")", ":", "self", ".", "_required_permission", "=", "None", "self", ".", "_explanation", "=", "None", "if", "required_permission", "is", "not", "None", ...
https://github.com/Chaffelson/nipyapi/blob/d3b186fd701ce308c2812746d98af9120955e810/nipyapi/registry/models/restriction.py#L43-L54
nose-devs/nose
7c26ad1e6b7d308cafa328ad34736d34028c122a
nose/tools/trivial.py
python
ok_
(expr, msg=None)
Shorthand for assert. Saves 3 whole characters!
Shorthand for assert. Saves 3 whole characters!
[ "Shorthand", "for", "assert", ".", "Saves", "3", "whole", "characters!" ]
def ok_(expr, msg=None): """Shorthand for assert. Saves 3 whole characters! """ if not expr: raise AssertionError(msg)
[ "def", "ok_", "(", "expr", ",", "msg", "=", "None", ")", ":", "if", "not", "expr", ":", "raise", "AssertionError", "(", "msg", ")" ]
https://github.com/nose-devs/nose/blob/7c26ad1e6b7d308cafa328ad34736d34028c122a/nose/tools/trivial.py#L18-L22
parallax/svg-animation-tools
3cbad1696760c049ed66b7e0c8631357000dbdb6
example/parallax_svg_tools/bs4/element.py
python
NavigableString.__getattr__
(self, attr)
text.string gives you text. This is for backwards compatibility for Navigable*String, but for CData* it lets you get the string without the CData wrapper.
text.string gives you text. This is for backwards compatibility for Navigable*String, but for CData* it lets you get the string without the CData wrapper.
[ "text", ".", "string", "gives", "you", "text", ".", "This", "is", "for", "backwards", "compatibility", "for", "Navigable", "*", "String", "but", "for", "CData", "*", "it", "lets", "you", "get", "the", "string", "without", "the", "CData", "wrapper", "." ]
def __getattr__(self, attr): """text.string gives you text. This is for backwards compatibility for Navigable*String, but for CData* it lets you get the string without the CData wrapper.""" if attr == 'string': return self else: raise AttributeError( "'%s' object has no attribute '%s'" % ( self.__class__.__name__, attr))
[ "def", "__getattr__", "(", "self", ",", "attr", ")", ":", "if", "attr", "==", "'string'", ":", "return", "self", "else", ":", "raise", "AttributeError", "(", "\"'%s' object has no attribute '%s'\"", "%", "(", "self", ".", "__class__", ".", "__name__", ",", "...
https://github.com/parallax/svg-animation-tools/blob/3cbad1696760c049ed66b7e0c8631357000dbdb6/example/parallax_svg_tools/bs4/element.py#L721-L730
CoinAlpha/hummingbot
36f6149c1644c07cd36795b915f38b8f49b798e7
hummingbot/strategy/spot_perpetual_arbitrage/arb_proposal.py
python
ArbProposal.__init__
(self, spot_side: ArbProposalSide, perp_side: ArbProposalSide, order_amount: Decimal)
Creates ArbProposal :param spot_side: An ArbProposalSide on spot market :param perp_side: An ArbProposalSide on perpetual market :param order_amount: An order amount for both spot and perpetual market
Creates ArbProposal :param spot_side: An ArbProposalSide on spot market :param perp_side: An ArbProposalSide on perpetual market :param order_amount: An order amount for both spot and perpetual market
[ "Creates", "ArbProposal", ":", "param", "spot_side", ":", "An", "ArbProposalSide", "on", "spot", "market", ":", "param", "perp_side", ":", "An", "ArbProposalSide", "on", "perpetual", "market", ":", "param", "order_amount", ":", "An", "order", "amount", "for", ...
def __init__(self, spot_side: ArbProposalSide, perp_side: ArbProposalSide, order_amount: Decimal): """ Creates ArbProposal :param spot_side: An ArbProposalSide on spot market :param perp_side: An ArbProposalSide on perpetual market :param order_amount: An order amount for both spot and perpetual market """ if spot_side.is_buy == perp_side.is_buy: raise Exception("Spot and perpetual arb proposal cannot be on the same side.") self.spot_side: ArbProposalSide = spot_side self.perp_side: ArbProposalSide = perp_side self.order_amount: Decimal = order_amount
[ "def", "__init__", "(", "self", ",", "spot_side", ":", "ArbProposalSide", ",", "perp_side", ":", "ArbProposalSide", ",", "order_amount", ":", "Decimal", ")", ":", "if", "spot_side", ".", "is_buy", "==", "perp_side", ".", "is_buy", ":", "raise", "Exception", ...
https://github.com/CoinAlpha/hummingbot/blob/36f6149c1644c07cd36795b915f38b8f49b798e7/hummingbot/strategy/spot_perpetual_arbitrage/arb_proposal.py#L37-L51
linkchecker/linkchecker
d1078ed8480e5cfc4264d0dbf026b45b45aede4d
linkcheck/checker/mailtourl.py
python
is_quoted
(addr)
return addr.startswith('"') and addr.endswith('"')
Return True iff mail address string is quoted.
Return True iff mail address string is quoted.
[ "Return", "True", "iff", "mail", "address", "string", "is", "quoted", "." ]
def is_quoted(addr): """Return True iff mail address string is quoted.""" return addr.startswith('"') and addr.endswith('"')
[ "def", "is_quoted", "(", "addr", ")", ":", "return", "addr", ".", "startswith", "(", "'\"'", ")", "and", "addr", ".", "endswith", "(", "'\"'", ")" ]
https://github.com/linkchecker/linkchecker/blob/d1078ed8480e5cfc4264d0dbf026b45b45aede4d/linkcheck/checker/mailtourl.py#L44-L46
scrapy/scrapy
b04cfa48328d5d5749dca6f50fa34e0cfc664c89
scrapy/core/downloader/handlers/__init__.py
python
DownloadHandlers._load_handler
(self, scheme, skip_lazy=False)
[]
def _load_handler(self, scheme, skip_lazy=False): path = self._schemes[scheme] try: dhcls = load_object(path) if skip_lazy and getattr(dhcls, 'lazy', True): return None dh = create_instance( objcls=dhcls, settings=self._crawler.settings, crawler=self._crawler, ) except NotConfigured as ex: self._notconfigured[scheme] = str(ex) return None except Exception as ex: logger.error('Loading "%(clspath)s" for scheme "%(scheme)s"', {"clspath": path, "scheme": scheme}, exc_info=True, extra={'crawler': self._crawler}) self._notconfigured[scheme] = str(ex) return None else: self._handlers[scheme] = dh return dh
[ "def", "_load_handler", "(", "self", ",", "scheme", ",", "skip_lazy", "=", "False", ")", ":", "path", "=", "self", ".", "_schemes", "[", "scheme", "]", "try", ":", "dhcls", "=", "load_object", "(", "path", ")", "if", "skip_lazy", "and", "getattr", "(",...
https://github.com/scrapy/scrapy/blob/b04cfa48328d5d5749dca6f50fa34e0cfc664c89/scrapy/core/downloader/handlers/__init__.py#L46-L68
wmayner/pyphi
299fccd4a8152dcfa4bb989d7d739e245343b0a5
pyphi/models/fmt.py
python
make_repr
(self, attrs)
Construct a repr string. If `config.REPR_VERBOSITY` is ``1`` or ``2``, this function calls the object's __str__ method. Although this breaks the convention that __repr__ should return a string which can reconstruct the object, readable reprs are invaluable since the Python interpreter calls `repr` to represent all objects in the shell. Since PyPhi is often used in the interpreter we want to have meaningful and useful representations. Args: self (obj): The object in question attrs (Iterable[str]): Attributes to include in the repr Returns: str: the ``repr``esentation of the object
Construct a repr string.
[ "Construct", "a", "repr", "string", "." ]
def make_repr(self, attrs): """Construct a repr string. If `config.REPR_VERBOSITY` is ``1`` or ``2``, this function calls the object's __str__ method. Although this breaks the convention that __repr__ should return a string which can reconstruct the object, readable reprs are invaluable since the Python interpreter calls `repr` to represent all objects in the shell. Since PyPhi is often used in the interpreter we want to have meaningful and useful representations. Args: self (obj): The object in question attrs (Iterable[str]): Attributes to include in the repr Returns: str: the ``repr``esentation of the object """ # TODO: change this to a closure so we can do # __repr__ = make_repr(attrs) ??? if config.REPR_VERBOSITY in [MEDIUM, HIGH]: return self.__str__() elif config.REPR_VERBOSITY is LOW: return "{}({})".format( self.__class__.__name__, ", ".join(attr + "=" + repr(getattr(self, attr)) for attr in attrs), ) raise ValueError("Invalid value for `config.REPR_VERBOSITY`")
[ "def", "make_repr", "(", "self", ",", "attrs", ")", ":", "# TODO: change this to a closure so we can do", "# __repr__ = make_repr(attrs) ???", "if", "config", ".", "REPR_VERBOSITY", "in", "[", "MEDIUM", ",", "HIGH", "]", ":", "return", "self", ".", "__str__", "(", ...
https://github.com/wmayner/pyphi/blob/299fccd4a8152dcfa4bb989d7d739e245343b0a5/pyphi/models/fmt.py#L47-L76
CedricGuillemet/Imogen
ee417b42747ed5b46cb11b02ef0c3630000085b3
bin/Lib/multiprocessing/context.py
python
BaseContext.Queue
(self, maxsize=0)
return Queue(maxsize, ctx=self.get_context())
Returns a queue object
Returns a queue object
[ "Returns", "a", "queue", "object" ]
def Queue(self, maxsize=0): '''Returns a queue object''' from .queues import Queue return Queue(maxsize, ctx=self.get_context())
[ "def", "Queue", "(", "self", ",", "maxsize", "=", "0", ")", ":", "from", ".", "queues", "import", "Queue", "return", "Queue", "(", "maxsize", ",", "ctx", "=", "self", ".", "get_context", "(", ")", ")" ]
https://github.com/CedricGuillemet/Imogen/blob/ee417b42747ed5b46cb11b02ef0c3630000085b3/bin/Lib/multiprocessing/context.py#L99-L102
snipsco/snips-nlu
74b2893c91fc0bafc919a7e088ecb0b2bd611acf
snips_nlu/intent_classifier/intent_classifier.py
python
IntentClassifier.get_intent
(self, text, intents_filter)
Performs intent classification on the provided *text* Args: text (str): Input intents_filter (str or list of str): When defined, it will find the most likely intent among the list, otherwise it will use the whole list of intents defined in the dataset Returns: dict or None: The most likely intent along with its probability or *None* if no intent was found. See :func:`.intent_classification_result` for the output format.
Performs intent classification on the provided *text*
[ "Performs", "intent", "classification", "on", "the", "provided", "*", "text", "*" ]
def get_intent(self, text, intents_filter): """Performs intent classification on the provided *text* Args: text (str): Input intents_filter (str or list of str): When defined, it will find the most likely intent among the list, otherwise it will use the whole list of intents defined in the dataset Returns: dict or None: The most likely intent along with its probability or *None* if no intent was found. See :func:`.intent_classification_result` for the output format. """ pass
[ "def", "get_intent", "(", "self", ",", "text", ",", "intents_filter", ")", ":", "pass" ]
https://github.com/snipsco/snips-nlu/blob/74b2893c91fc0bafc919a7e088ecb0b2bd611acf/snips_nlu/intent_classifier/intent_classifier.py#L26-L40
cupy/cupy
a47ad3105f0fe817a4957de87d98ddccb8c7491f
cupy/cusparse.py
python
dense2csr
(x)
return csr
Converts a dense matrix in CSR format. Args: x (cupy.ndarray): A matrix to be converted. Returns: cupyx.scipy.sparse.csr_matrix: A converted matrix.
Converts a dense matrix in CSR format.
[ "Converts", "a", "dense", "matrix", "in", "CSR", "format", "." ]
def dense2csr(x): """Converts a dense matrix in CSR format. Args: x (cupy.ndarray): A matrix to be converted. Returns: cupyx.scipy.sparse.csr_matrix: A converted matrix. """ if not check_availability('dense2csr'): raise RuntimeError('dense2csr is not available.') assert x.ndim == 2 x = _cupy.asfortranarray(x) nnz = _numpy.empty((), dtype='i') handle = _device.get_cusparse_handle() m, n = x.shape descr = MatDescriptor.create() nnz_per_row = _cupy.empty(m, 'i') _call_cusparse( 'nnz', x.dtype, handle, _cusparse.CUSPARSE_DIRECTION_ROW, m, n, descr.descriptor, x.data.ptr, m, nnz_per_row.data.ptr, nnz.ctypes.data) nnz = int(nnz) if _runtime.is_hip: if nnz == 0: raise ValueError('hipSPARSE currently cannot handle ' 'sparse matrices with null ptrs') data = _cupy.empty(nnz, x.dtype) indptr = _cupy.empty(m + 1, 'i') indices = _cupy.empty(nnz, 'i') _call_cusparse( 'dense2csr', x.dtype, handle, m, n, descr.descriptor, x.data.ptr, m, nnz_per_row.data.ptr, data.data.ptr, indptr.data.ptr, indices.data.ptr) # Note that a desciptor is recreated csr = cupyx.scipy.sparse.csr_matrix((data, indices, indptr), shape=x.shape) csr._has_canonical_format = True return csr
[ "def", "dense2csr", "(", "x", ")", ":", "if", "not", "check_availability", "(", "'dense2csr'", ")", ":", "raise", "RuntimeError", "(", "'dense2csr is not available.'", ")", "assert", "x", ".", "ndim", "==", "2", "x", "=", "_cupy", ".", "asfortranarray", "(",...
https://github.com/cupy/cupy/blob/a47ad3105f0fe817a4957de87d98ddccb8c7491f/cupy/cusparse.py#L1155-L1198
omz/PythonistaAppTemplate
f560f93f8876d82a21d108977f90583df08d55af
PythonistaAppTemplate/PythonistaKit.framework/pylib_ext/numpy/lib/financial.py
python
npv
(rate, values)
return (values / (1+rate)**np.arange(0, len(values))).sum(axis=0)
Returns the NPV (Net Present Value) of a cash flow series. Parameters ---------- rate : scalar The discount rate. values : array_like, shape(M, ) The values of the time series of cash flows. The (fixed) time interval between cash flow "events" must be the same as that for which `rate` is given (i.e., if `rate` is per year, then precisely a year is understood to elapse between each cash flow event). By convention, investments or "deposits" are negative, income or "withdrawals" are positive; `values` must begin with the initial investment, thus `values[0]` will typically be negative. Returns ------- out : float The NPV of the input cash flow series `values` at the discount `rate`. Notes ----- Returns the result of: [G]_ .. math :: \\sum_{t=0}^{M-1}{\\frac{values_t}{(1+rate)^{t}}} References ---------- .. [G] L. J. Gitman, "Principles of Managerial Finance, Brief," 3rd ed., Addison-Wesley, 2003, pg. 346. Examples -------- >>> np.npv(0.281,[-100, 39, 59, 55, 20]) -0.0084785916384548798 (Compare with the Example given for numpy.lib.financial.irr)
Returns the NPV (Net Present Value) of a cash flow series.
[ "Returns", "the", "NPV", "(", "Net", "Present", "Value", ")", "of", "a", "cash", "flow", "series", "." ]
def npv(rate, values): """ Returns the NPV (Net Present Value) of a cash flow series. Parameters ---------- rate : scalar The discount rate. values : array_like, shape(M, ) The values of the time series of cash flows. The (fixed) time interval between cash flow "events" must be the same as that for which `rate` is given (i.e., if `rate` is per year, then precisely a year is understood to elapse between each cash flow event). By convention, investments or "deposits" are negative, income or "withdrawals" are positive; `values` must begin with the initial investment, thus `values[0]` will typically be negative. Returns ------- out : float The NPV of the input cash flow series `values` at the discount `rate`. Notes ----- Returns the result of: [G]_ .. math :: \\sum_{t=0}^{M-1}{\\frac{values_t}{(1+rate)^{t}}} References ---------- .. [G] L. J. Gitman, "Principles of Managerial Finance, Brief," 3rd ed., Addison-Wesley, 2003, pg. 346. Examples -------- >>> np.npv(0.281,[-100, 39, 59, 55, 20]) -0.0084785916384548798 (Compare with the Example given for numpy.lib.financial.irr) """ values = np.asarray(values) return (values / (1+rate)**np.arange(0, len(values))).sum(axis=0)
[ "def", "npv", "(", "rate", ",", "values", ")", ":", "values", "=", "np", ".", "asarray", "(", "values", ")", "return", "(", "values", "/", "(", "1", "+", "rate", ")", "**", "np", ".", "arange", "(", "0", ",", "len", "(", "values", ")", ")", "...
https://github.com/omz/PythonistaAppTemplate/blob/f560f93f8876d82a21d108977f90583df08d55af/PythonistaAppTemplate/PythonistaKit.framework/pylib_ext/numpy/lib/financial.py#L649-L692
Cog-Creators/Red-DiscordBot
b05933274a11fb097873ab0d1b246d37b06aa306
redbot/core/commands/help.py
python
RedHelpFormatter.send_help
( self, ctx: Context, help_for: HelpTarget = None, *, from_help_command: bool = False )
This delegates to other functions. For most cases, you should use this and only this directly.
This delegates to other functions.
[ "This", "delegates", "to", "other", "functions", "." ]
async def send_help( self, ctx: Context, help_for: HelpTarget = None, *, from_help_command: bool = False ): """ This delegates to other functions. For most cases, you should use this and only this directly. """ help_settings = await HelpSettings.from_context(ctx) if help_for is None or isinstance(help_for, dpy_commands.bot.BotBase): await self.format_bot_help(ctx, help_settings=help_settings) return if isinstance(help_for, str): try: help_for = self.parse_command(ctx, help_for) except NoCommand: await self.command_not_found(ctx, help_for, help_settings=help_settings) return except NoSubCommand as exc: if help_settings.verify_exists: await self.subcommand_not_found( ctx, exc.last, exc.not_found, help_settings=help_settings ) return help_for = exc.last if isinstance(help_for, commands.Cog): await self.format_cog_help(ctx, help_for, help_settings=help_settings) else: await self.format_command_help(ctx, help_for, help_settings=help_settings)
[ "async", "def", "send_help", "(", "self", ",", "ctx", ":", "Context", ",", "help_for", ":", "HelpTarget", "=", "None", ",", "*", ",", "from_help_command", ":", "bool", "=", "False", ")", ":", "help_settings", "=", "await", "HelpSettings", ".", "from_contex...
https://github.com/Cog-Creators/Red-DiscordBot/blob/b05933274a11fb097873ab0d1b246d37b06aa306/redbot/core/commands/help.py#L213-L245
GiulioRossetti/cdlib
b2c6311b99725bb2b029556f531d244a2af14a2a
cdlib/algorithms/internal/CONGA.py
python
CrispOverlap.__str__
(self)
return "{0} vertices in {1} possible covers.".format( len(self._graph.vs), len(self._covers) )
Returns a string representation of the list of covers.
Returns a string representation of the list of covers.
[ "Returns", "a", "string", "representation", "of", "the", "list", "of", "covers", "." ]
def __str__(self): """ Returns a string representation of the list of covers. """ return "{0} vertices in {1} possible covers.".format( len(self._graph.vs), len(self._covers) )
[ "def", "__str__", "(", "self", ")", ":", "return", "\"{0} vertices in {1} possible covers.\"", ".", "format", "(", "len", "(", "self", ".", "_graph", ".", "vs", ")", ",", "len", "(", "self", ".", "_covers", ")", ")" ]
https://github.com/GiulioRossetti/cdlib/blob/b2c6311b99725bb2b029556f531d244a2af14a2a/cdlib/algorithms/internal/CONGA.py#L185-L191
jgagneastro/coffeegrindsize
22661ebd21831dba4cf32bfc6ba59fe3d49f879c
App/dist/coffeegrindsize.app/Contents/Resources/lib/python3.7/scipy/ndimage/interpolation.py
python
shift
(input, shift, output=None, order=3, mode='constant', cval=0.0, prefilter=True)
return output
Shift an array. The array is shifted using spline interpolation of the requested order. Points outside the boundaries of the input are filled according to the given mode. Parameters ---------- %(input)s shift : float or sequence The shift along the axes. If a float, `shift` is the same for each axis. If a sequence, `shift` should contain one value for each axis. %(output)s order : int, optional The order of the spline interpolation, default is 3. The order has to be in the range 0-5. %(mode)s %(cval)s %(prefilter)s Returns ------- shift : ndarray The shifted input.
Shift an array.
[ "Shift", "an", "array", "." ]
def shift(input, shift, output=None, order=3, mode='constant', cval=0.0, prefilter=True): """ Shift an array. The array is shifted using spline interpolation of the requested order. Points outside the boundaries of the input are filled according to the given mode. Parameters ---------- %(input)s shift : float or sequence The shift along the axes. If a float, `shift` is the same for each axis. If a sequence, `shift` should contain one value for each axis. %(output)s order : int, optional The order of the spline interpolation, default is 3. The order has to be in the range 0-5. %(mode)s %(cval)s %(prefilter)s Returns ------- shift : ndarray The shifted input. """ if order < 0 or order > 5: raise RuntimeError('spline order not supported') input = numpy.asarray(input) if numpy.iscomplexobj(input): raise TypeError('Complex type not supported') if input.ndim < 1: raise RuntimeError('input and output rank must be > 0') mode = _ni_support._extend_mode_to_code(mode) if prefilter and order > 1: filtered = spline_filter(input, order, output=numpy.float64) else: filtered = input output = _ni_support._get_output(output, input) shift = _ni_support._normalize_sequence(shift, input.ndim) shift = [-ii for ii in shift] shift = numpy.asarray(shift, dtype=numpy.float64) if not shift.flags.contiguous: shift = shift.copy() _nd_image.zoom_shift(filtered, None, shift, output, order, mode, cval) return output
[ "def", "shift", "(", "input", ",", "shift", ",", "output", "=", "None", ",", "order", "=", "3", ",", "mode", "=", "'constant'", ",", "cval", "=", "0.0", ",", "prefilter", "=", "True", ")", ":", "if", "order", "<", "0", "or", "order", ">", "5", ...
https://github.com/jgagneastro/coffeegrindsize/blob/22661ebd21831dba4cf32bfc6ba59fe3d49f879c/App/dist/coffeegrindsize.app/Contents/Resources/lib/python3.7/scipy/ndimage/interpolation.py#L491-L539
globaleaks/GlobaLeaks
4624ca937728adb8e21c4733a8aecec6a41cb3db
backend/globaleaks/utils/crypto.py
python
_convert_to_bytes
(arg: Union[bytes, str])
return arg
Convert the argument to bytes if of string type :param arg: a string or a byte object :return: the converted byte object
Convert the argument to bytes if of string type :param arg: a string or a byte object :return: the converted byte object
[ "Convert", "the", "argument", "to", "bytes", "if", "of", "string", "type", ":", "param", "arg", ":", "a", "string", "or", "a", "byte", "object", ":", "return", ":", "the", "converted", "byte", "object" ]
def _convert_to_bytes(arg: Union[bytes, str]) -> bytes: """ Convert the argument to bytes if of string type :param arg: a string or a byte object :return: the converted byte object """ if isinstance(arg, str): arg = arg.encode() return arg
[ "def", "_convert_to_bytes", "(", "arg", ":", "Union", "[", "bytes", ",", "str", "]", ")", "->", "bytes", ":", "if", "isinstance", "(", "arg", ",", "str", ")", ":", "arg", "=", "arg", ".", "encode", "(", ")", "return", "arg" ]
https://github.com/globaleaks/GlobaLeaks/blob/4624ca937728adb8e21c4733a8aecec6a41cb3db/backend/globaleaks/utils/crypto.py#L29-L38
oilshell/oil
94388e7d44a9ad879b12615f6203b38596b5a2d3
Python-2.7.13/Lib/lib-tk/Tkinter.py
python
Menu.add_command
(self, cnf={}, **kw)
Add command menu item.
Add command menu item.
[ "Add", "command", "menu", "item", "." ]
def add_command(self, cnf={}, **kw): """Add command menu item.""" self.add('command', cnf or kw)
[ "def", "add_command", "(", "self", ",", "cnf", "=", "{", "}", ",", "*", "*", "kw", ")", ":", "self", ".", "add", "(", "'command'", ",", "cnf", "or", "kw", ")" ]
https://github.com/oilshell/oil/blob/94388e7d44a9ad879b12615f6203b38596b5a2d3/Python-2.7.13/Lib/lib-tk/Tkinter.py#L2742-L2744
smart-mobile-software/gitstack
d9fee8f414f202143eb6e620529e8e5539a2af56
python/Lib/site-packages/django/db/models/query.py
python
QuerySet.reverse
(self)
return clone
Reverses the ordering of the QuerySet.
Reverses the ordering of the QuerySet.
[ "Reverses", "the", "ordering", "of", "the", "QuerySet", "." ]
def reverse(self): """ Reverses the ordering of the QuerySet. """ clone = self._clone() clone.query.standard_ordering = not clone.query.standard_ordering return clone
[ "def", "reverse", "(", "self", ")", ":", "clone", "=", "self", ".", "_clone", "(", ")", "clone", ".", "query", ".", "standard_ordering", "=", "not", "clone", ".", "query", ".", "standard_ordering", "return", "clone" ]
https://github.com/smart-mobile-software/gitstack/blob/d9fee8f414f202143eb6e620529e8e5539a2af56/python/Lib/site-packages/django/db/models/query.py#L780-L786
SkullTech/drymail
56fac5bdfff4410bb52ed98d5f0d483bb5e1e144
drymail.py
python
stringify_addresses
(addresses)
Converts a list of addresses into a string in the `"John Doe" <john@example.com>, "Jane" <jane@example.com>"` format, which can be directly used in the headers of an email. Parameters ---------- addresses : (str or (str, str)) or list of (str or (str, str)) A single address or a list of addresses which is to be converted into a single string. Each element can be either an email address or a tuple of a name and an email address. Returns ------- str The address(es) as a single string which can be directly used in the headers of an email.
Converts a list of addresses into a string in the `"John Doe" <john@example.com>, "Jane" <jane@example.com>"` format, which can be directly used in the headers of an email.
[ "Converts", "a", "list", "of", "addresses", "into", "a", "string", "in", "the", "John", "Doe", "<john@example", ".", "com", ">", "Jane", "<jane@example", ".", "com", ">", "format", "which", "can", "be", "directly", "used", "in", "the", "headers", "of", "...
def stringify_addresses(addresses): """ Converts a list of addresses into a string in the `"John Doe" <john@example.com>, "Jane" <jane@example.com>"` format, which can be directly used in the headers of an email. Parameters ---------- addresses : (str or (str, str)) or list of (str or (str, str)) A single address or a list of addresses which is to be converted into a single string. Each element can be either an email address or a tuple of a name and an email address. Returns ------- str The address(es) as a single string which can be directly used in the headers of an email. """ if isinstance(addresses, list): addresses = [stringify_address(address) for address in addresses] return ', '.join(addresses) else: return stringify_address(addresses)
[ "def", "stringify_addresses", "(", "addresses", ")", ":", "if", "isinstance", "(", "addresses", ",", "list", ")", ":", "addresses", "=", "[", "stringify_address", "(", "address", ")", "for", "address", "in", "addresses", "]", "return", "', '", ".", "join", ...
https://github.com/SkullTech/drymail/blob/56fac5bdfff4410bb52ed98d5f0d483bb5e1e144/drymail.py#L154-L175
exodrifter/unity-python
bef6e4e9ddfbbf1eaf7acbbb973e9aa3dd64a20d
Lib/SimpleXMLRPCServer.py
python
SimpleXMLRPCDispatcher.register_instance
(self, instance, allow_dotted_names=False)
Registers an instance to respond to XML-RPC requests. Only one instance can be installed at a time. If the registered instance has a _dispatch method then that method will be called with the name of the XML-RPC method and its parameters as a tuple e.g. instance._dispatch('add',(2,3)) If the registered instance does not have a _dispatch method then the instance will be searched to find a matching method and, if found, will be called. Methods beginning with an '_' are considered private and will not be called by SimpleXMLRPCServer. If a registered function matches an XML-RPC request, then it will be called instead of the registered instance. If the optional allow_dotted_names argument is true and the instance does not have a _dispatch method, method names containing dots are supported and resolved, as long as none of the name segments start with an '_'. *** SECURITY WARNING: *** Enabling the allow_dotted_names options allows intruders to access your module's global variables and may allow intruders to execute arbitrary code on your machine. Only use this option on a secure, closed network.
Registers an instance to respond to XML-RPC requests.
[ "Registers", "an", "instance", "to", "respond", "to", "XML", "-", "RPC", "requests", "." ]
def register_instance(self, instance, allow_dotted_names=False): """Registers an instance to respond to XML-RPC requests. Only one instance can be installed at a time. If the registered instance has a _dispatch method then that method will be called with the name of the XML-RPC method and its parameters as a tuple e.g. instance._dispatch('add',(2,3)) If the registered instance does not have a _dispatch method then the instance will be searched to find a matching method and, if found, will be called. Methods beginning with an '_' are considered private and will not be called by SimpleXMLRPCServer. If a registered function matches an XML-RPC request, then it will be called instead of the registered instance. If the optional allow_dotted_names argument is true and the instance does not have a _dispatch method, method names containing dots are supported and resolved, as long as none of the name segments start with an '_'. *** SECURITY WARNING: *** Enabling the allow_dotted_names options allows intruders to access your module's global variables and may allow intruders to execute arbitrary code on your machine. Only use this option on a secure, closed network. """ self.instance = instance self.allow_dotted_names = allow_dotted_names
[ "def", "register_instance", "(", "self", ",", "instance", ",", "allow_dotted_names", "=", "False", ")", ":", "self", ".", "instance", "=", "instance", "self", ".", "allow_dotted_names", "=", "allow_dotted_names" ]
https://github.com/exodrifter/unity-python/blob/bef6e4e9ddfbbf1eaf7acbbb973e9aa3dd64a20d/Lib/SimpleXMLRPCServer.py#L175-L209
Source-Python-Dev-Team/Source.Python
d0ffd8ccbd1e9923c9bc44936f20613c1c76b7fb
addons/source-python/Python3/importlib/_bootstrap_external.py
python
_path_is_mode_type
(path, mode)
return (stat_info.st_mode & 0o170000) == mode
Test whether the path is the specified mode type.
Test whether the path is the specified mode type.
[ "Test", "whether", "the", "path", "is", "the", "specified", "mode", "type", "." ]
def _path_is_mode_type(path, mode): """Test whether the path is the specified mode type.""" try: stat_info = _path_stat(path) except OSError: return False return (stat_info.st_mode & 0o170000) == mode
[ "def", "_path_is_mode_type", "(", "path", ",", "mode", ")", ":", "try", ":", "stat_info", "=", "_path_stat", "(", "path", ")", "except", "OSError", ":", "return", "False", "return", "(", "stat_info", ".", "st_mode", "&", "0o170000", ")", "==", "mode" ]
https://github.com/Source-Python-Dev-Team/Source.Python/blob/d0ffd8ccbd1e9923c9bc44936f20613c1c76b7fb/addons/source-python/Python3/importlib/_bootstrap_external.py#L85-L91
hequan2017/chain
169f810551a8355579d3cef670ecf88942478a05
tasks/views.py
python
taillog
(request, hostname, port, username, password, private, tail)
执行 tail log 接口
执行 tail log 接口
[ "执行", "tail", "log", "接口" ]
def taillog(request, hostname, port, username, password, private, tail): """ 执行 tail log 接口 """ channel_layer = get_channel_layer() user = request.user.username os.environ["".format(user)] = "true" ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) if password: ssh.connect(hostname=hostname, port=port, username=username, password=decrypt_p(password)) else: pkey = paramiko.RSAKey.from_private_key_file("{0}".format(private)) ssh.connect(hostname=hostname, port=port, username=username, pkey=pkey) cmd = "tail " + tail stdin, stdout, stderr = ssh.exec_command(cmd, get_pty=True) for line in iter(stdout.readline, ""): if os.environ.get("".format(user)) == 'false': break result = {"status": 0, 'data': line} result_all = json.dumps(result) async_to_sync(channel_layer.group_send)(user, {"type": "user.message", 'text': result_all})
[ "def", "taillog", "(", "request", ",", "hostname", ",", "port", ",", "username", ",", "password", ",", "private", ",", "tail", ")", ":", "channel_layer", "=", "get_channel_layer", "(", ")", "user", "=", "request", ".", "user", ".", "username", "os", ".",...
https://github.com/hequan2017/chain/blob/169f810551a8355579d3cef670ecf88942478a05/tasks/views.py#L163-L184
simons-public/protonfixes
24ecb378bc4e99bfe698090661d255dcbb5b677f
protonfixes/corefonts.py
python
get_corefonts
()
Downloads the ms-corefonts from the pushcx/corefonts mirror
Downloads the ms-corefonts from the pushcx/corefonts mirror
[ "Downloads", "the", "ms", "-", "corefonts", "from", "the", "pushcx", "/", "corefonts", "mirror" ]
def get_corefonts(): """ Downloads the ms-corefonts from the pushcx/corefonts mirror """ if check_corefonts(): return urlbase = 'https://github.com/pushcx/corefonts/raw/master/' urlsuffix = '32.exe' fonts = ['andale', 'arial', 'arialb', 'comic', 'courie', 'georgi', 'impact', 'times', 'trebuc', 'verdan', 'webdin', ] try: os.makedirs(COREFONTS_DIR) except FileExistsError: log.debug('Directory exists: ' + COREFONTS_DIR) urls = [urlbase + x + urlsuffix for x in fonts] files = [] # download files in threads dl_threads = [Thread(target=download_file, args=(u, files)) for u in urls] [thread.start() for thread in dl_threads] [thread.join() for thread in dl_threads] # extract files with threads ex_threads = [Thread(target=extract_cab, args=(f.name, COREFONTS_DIR)) for f in files] [thread.start() for thread in ex_threads] [thread.join() for thread in ex_threads] # rename files to lowercase [shutil.move(os.path.join(d, f), os.path.join(d, f).lower()) for d, _, files in os.walk(COREFONTS_DIR) for f in files] # cleanup temp files [log.debug('Removing ' + f.name) for f in files] [os.remove(f.name) for f in files]
[ "def", "get_corefonts", "(", ")", ":", "if", "check_corefonts", "(", ")", ":", "return", "urlbase", "=", "'https://github.com/pushcx/corefonts/raw/master/'", "urlsuffix", "=", "'32.exe'", "fonts", "=", "[", "'andale'", ",", "'arial'", ",", "'arialb'", ",", "'comic...
https://github.com/simons-public/protonfixes/blob/24ecb378bc4e99bfe698090661d255dcbb5b677f/protonfixes/corefonts.py#L89-L128
tendenci/tendenci
0f2c348cc0e7d41bc56f50b00ce05544b083bf1d
tendenci/apps/helpdesk/views/staff.py
python
calc_basic_ticket_stats
(Tickets)
return basic_ticket_stats
[]
def calc_basic_ticket_stats(Tickets): # all not closed tickets (open, reopened, resolved,) - independent of user all_open_tickets = Tickets.exclude(status = Ticket.CLOSED_STATUS) today = datetime.today() date_30 = date_rel_to_today(today, 30) date_60 = date_rel_to_today(today, 60) date_30_str = date_30.strftime('%Y-%m-%d') date_60_str = date_60.strftime('%Y-%m-%d') # > 0 & <= 30 ota_le_30 = all_open_tickets.filter(created__gte = date_30_str) N_ota_le_30 = len(ota_le_30) # >= 30 & <= 60 ota_le_60_ge_30 = all_open_tickets.filter(created__gte = date_60_str, created__lte = date_30_str) N_ota_le_60_ge_30 = len(ota_le_60_ge_30) # >= 60 ota_ge_60 = all_open_tickets.filter(created__lte = date_60_str) N_ota_ge_60 = len(ota_ge_60) # (O)pen (T)icket (S)tats ots = list() # label, number entries, color, sort_string ots.append(['< 30 days', N_ota_le_30, get_color_for_nbr_days(N_ota_le_30), sort_string(date_30_str, ''), ]) ots.append(['30 - 60 days', N_ota_le_60_ge_30, get_color_for_nbr_days(N_ota_le_60_ge_30), sort_string(date_60_str, date_30_str), ]) ots.append(['> 60 days', N_ota_ge_60, get_color_for_nbr_days(N_ota_ge_60), sort_string('', date_60_str), ]) # all closed tickets - independent of user. all_closed_tickets = Tickets.filter(status = Ticket.CLOSED_STATUS) average_nbr_days_until_ticket_closed = calc_average_nbr_days_until_ticket_resolved(all_closed_tickets) # all closed tickets that were opened in the last 60 days. all_closed_last_60_days = all_closed_tickets.filter(created__gte = date_60_str) average_nbr_days_until_ticket_closed_last_60_days = calc_average_nbr_days_until_ticket_resolved(all_closed_last_60_days) # put together basic stats basic_ticket_stats = { 'average_nbr_days_until_ticket_closed': average_nbr_days_until_ticket_closed, 'average_nbr_days_until_ticket_closed_last_60_days': average_nbr_days_until_ticket_closed_last_60_days, 'open_ticket_stats': ots, } return basic_ticket_stats
[ "def", "calc_basic_ticket_stats", "(", "Tickets", ")", ":", "# all not closed tickets (open, reopened, resolved,) - independent of user", "all_open_tickets", "=", "Tickets", ".", "exclude", "(", "status", "=", "Ticket", ".", "CLOSED_STATUS", ")", "today", "=", "datetime", ...
https://github.com/tendenci/tendenci/blob/0f2c348cc0e7d41bc56f50b00ce05544b083bf1d/tendenci/apps/helpdesk/views/staff.py#L1396-L1437
pyscf/pyscf
0adfb464333f5ceee07b664f291d4084801bae64
pyscf/pbc/scf/kuhf.py
python
make_rdm1
(mo_coeff_kpts, mo_occ_kpts, **kwargs)
return lib.asarray(dm_kpts).reshape(2,nkpts,nao,nao)
Alpha and beta spin one particle density matrices for all k-points. Returns: dm_kpts : (2, nkpts, nao, nao) ndarray
Alpha and beta spin one particle density matrices for all k-points.
[ "Alpha", "and", "beta", "spin", "one", "particle", "density", "matrices", "for", "all", "k", "-", "points", "." ]
def make_rdm1(mo_coeff_kpts, mo_occ_kpts, **kwargs): '''Alpha and beta spin one particle density matrices for all k-points. Returns: dm_kpts : (2, nkpts, nao, nao) ndarray ''' nkpts = len(mo_occ_kpts[0]) nao, nmo = mo_coeff_kpts[0][0].shape def make_dm(mos, occs): return [np.dot(mos[k]*occs[k], mos[k].T.conj()) for k in range(nkpts)] dm_kpts =(make_dm(mo_coeff_kpts[0], mo_occ_kpts[0]) + make_dm(mo_coeff_kpts[1], mo_occ_kpts[1])) return lib.asarray(dm_kpts).reshape(2,nkpts,nao,nao)
[ "def", "make_rdm1", "(", "mo_coeff_kpts", ",", "mo_occ_kpts", ",", "*", "*", "kwargs", ")", ":", "nkpts", "=", "len", "(", "mo_occ_kpts", "[", "0", "]", ")", "nao", ",", "nmo", "=", "mo_coeff_kpts", "[", "0", "]", "[", "0", "]", ".", "shape", "def"...
https://github.com/pyscf/pyscf/blob/0adfb464333f5ceee07b664f291d4084801bae64/pyscf/pbc/scf/kuhf.py#L47-L59
mozillazg/pypy
2ff5cd960c075c991389f842c6d59e71cf0cb7d0
lib-python/2.7/sysconfig.py
python
_parse_makefile
(filename, vars=None)
return vars
Parse a Makefile-style file. A dictionary containing name/value pairs is returned. If an optional dictionary is passed in as the second argument, it is used instead of a new dictionary.
Parse a Makefile-style file.
[ "Parse", "a", "Makefile", "-", "style", "file", "." ]
def _parse_makefile(filename, vars=None): """Parse a Makefile-style file. A dictionary containing name/value pairs is returned. If an optional dictionary is passed in as the second argument, it is used instead of a new dictionary. """ import re # Regexes needed for parsing Makefile (and similar syntaxes, # like old-style Setup files). _variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)") _findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)") _findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}") if vars is None: vars = {} done = {} notdone = {} with open(filename) as f: lines = f.readlines() for line in lines: if line.startswith('#') or line.strip() == '': continue m = _variable_rx.match(line) if m: n, v = m.group(1, 2) v = v.strip() # `$$' is a literal `$' in make tmpv = v.replace('$$', '') if "$" in tmpv: notdone[n] = v else: try: v = int(v) except ValueError: # insert literal `$' done[n] = v.replace('$$', '$') else: done[n] = v # do variable interpolation here while notdone: for name in notdone.keys(): value = notdone[name] m = _findvar1_rx.search(value) or _findvar2_rx.search(value) if m: n = m.group(1) found = True if n in done: item = str(done[n]) elif n in notdone: # get it on a subsequent round found = False elif n in os.environ: # do it like make: fall back to environment item = os.environ[n] else: done[n] = item = "" if found: after = value[m.end():] value = value[:m.start()] + item + after if "$" in after: notdone[name] = value else: try: value = int(value) except ValueError: done[name] = value.strip() else: done[name] = value del notdone[name] else: # bogus variable reference; just drop it since we can't deal del notdone[name] # strip spurious spaces for k, v in done.items(): if isinstance(v, str): done[k] = v.strip() # save the results in the global dictionary vars.update(done) return vars
[ "def", "_parse_makefile", "(", "filename", ",", "vars", "=", "None", ")", ":", "import", "re", "# Regexes needed for parsing Makefile (and similar syntaxes,", "# like old-style Setup files).", "_variable_rx", "=", "re", ".", "compile", "(", "\"([a-zA-Z][a-zA-Z0-9_]+)\\s*=\\s*...
https://github.com/mozillazg/pypy/blob/2ff5cd960c075c991389f842c6d59e71cf0cb7d0/lib-python/2.7/sysconfig.py#L225-L308
microsoft/bistring
e23443e495f762967b09670b27bb1ff46ff4fef1
python/bistring/_builder.py
python
BistrBuilder.is_complete
(self)
return self.remaining == 0
Whether we've completely processed the string. In other words, whether the modified string aligns with the end of the current string.
Whether we've completely processed the string. In other words, whether the modified string aligns with the end of the current string.
[ "Whether", "we", "ve", "completely", "processed", "the", "string", ".", "In", "other", "words", "whether", "the", "modified", "string", "aligns", "with", "the", "end", "of", "the", "current", "string", "." ]
def is_complete(self) -> bool: """ Whether we've completely processed the string. In other words, whether the modified string aligns with the end of the current string. """ return self.remaining == 0
[ "def", "is_complete", "(", "self", ")", "->", "bool", ":", "return", "self", ".", "remaining", "==", "0" ]
https://github.com/microsoft/bistring/blob/e23443e495f762967b09670b27bb1ff46ff4fef1/python/bistring/_builder.py#L119-L124
rhinstaller/anaconda
63edc8680f1b05cbfe11bef28703acba808c5174
pyanaconda/modules/storage/bootloader/grub2.py
python
GRUB2.write_device_map
(self)
Write out a device map containing all supported devices.
Write out a device map containing all supported devices.
[ "Write", "out", "a", "device", "map", "containing", "all", "supported", "devices", "." ]
def write_device_map(self): """Write out a device map containing all supported devices.""" map_path = os.path.normpath(conf.target.system_root + self.device_map_file) if os.access(map_path, os.R_OK): os.rename(map_path, map_path + ".anacbak") devices = self.disks if self.stage1_device not in devices: devices.append(self.stage1_device) for disk in self.stage2_device.disks: if disk not in devices: devices.append(disk) devices = [d for d in devices if d.is_disk] if len(devices) == 0: return dev_map = open(map_path, "w") dev_map.write("# this device map was generated by anaconda\n") for drive in devices: dev_map.write("%s %s\n" % (self.grub_device_name(drive), drive.path)) dev_map.close()
[ "def", "write_device_map", "(", "self", ")", ":", "map_path", "=", "os", ".", "path", ".", "normpath", "(", "conf", ".", "target", ".", "system_root", "+", "self", ".", "device_map_file", ")", "if", "os", ".", "access", "(", "map_path", ",", "os", ".",...
https://github.com/rhinstaller/anaconda/blob/63edc8680f1b05cbfe11bef28703acba808c5174/pyanaconda/modules/storage/bootloader/grub2.py#L227-L251
pantsbuild/pex
473c6ac732ed4bc338b4b20a9ec930d1d722c9b4
pex/vendor/_vendored/setuptools/pkg_resources/__init__.py
python
ResourceManager.resource_isdir
(self, package_or_requirement, resource_name)
return get_provider(package_or_requirement).resource_isdir( resource_name )
Is the named resource an existing directory?
Is the named resource an existing directory?
[ "Is", "the", "named", "resource", "an", "existing", "directory?" ]
def resource_isdir(self, package_or_requirement, resource_name): """Is the named resource an existing directory?""" return get_provider(package_or_requirement).resource_isdir( resource_name )
[ "def", "resource_isdir", "(", "self", ",", "package_or_requirement", ",", "resource_name", ")", ":", "return", "get_provider", "(", "package_or_requirement", ")", ".", "resource_isdir", "(", "resource_name", ")" ]
https://github.com/pantsbuild/pex/blob/473c6ac732ed4bc338b4b20a9ec930d1d722c9b4/pex/vendor/_vendored/setuptools/pkg_resources/__init__.py#L1168-L1172
pdpipe/pdpipe
69502436d2a4ce70c6123d7a9db02cbf10f56cf2
versioneer.py
python
render_pep440_post
(pieces)
return rendered
TAG[.postDISTANCE[.dev0]+gHEX] . The ".dev0" means dirty. Note that .dev0 sorts backwards (a dirty tree will appear "older" than the corresponding clean one), but you shouldn't be releasing software with -dirty anyways. Exceptions: 1: no tags. 0.postDISTANCE[.dev0]
TAG[.postDISTANCE[.dev0]+gHEX] .
[ "TAG", "[", ".", "postDISTANCE", "[", ".", "dev0", "]", "+", "gHEX", "]", "." ]
def render_pep440_post(pieces): """TAG[.postDISTANCE[.dev0]+gHEX] . The ".dev0" means dirty. Note that .dev0 sorts backwards (a dirty tree will appear "older" than the corresponding clean one), but you shouldn't be releasing software with -dirty anyways. Exceptions: 1: no tags. 0.postDISTANCE[.dev0] """ if pieces["closest-tag"]: rendered = pieces["closest-tag"] if pieces["distance"] or pieces["dirty"]: rendered += ".post%d" % pieces["distance"] if pieces["dirty"]: rendered += ".dev0" rendered += plus_or_dot(pieces) rendered += "g%s" % pieces["short"] else: # exception #1 rendered = "0.post%d" % pieces["distance"] if pieces["dirty"]: rendered += ".dev0" rendered += "+g%s" % pieces["short"] return rendered
[ "def", "render_pep440_post", "(", "pieces", ")", ":", "if", "pieces", "[", "\"closest-tag\"", "]", ":", "rendered", "=", "pieces", "[", "\"closest-tag\"", "]", "if", "pieces", "[", "\"distance\"", "]", "or", "pieces", "[", "\"dirty\"", "]", ":", "rendered", ...
https://github.com/pdpipe/pdpipe/blob/69502436d2a4ce70c6123d7a9db02cbf10f56cf2/versioneer.py#L1277-L1301
saltstack/salt-contrib
062355938ad1cced273056e9c23dc344c6a2c858
modules/dockerio.py
python
_valid
(m, id_=NOTSET, comment=VALID_RESPONSE, out=None)
return _set_status(m, status=True, id_=id_, comment=comment, out=out)
Return valid status
Return valid status
[ "Return", "valid", "status" ]
def _valid(m, id_=NOTSET, comment=VALID_RESPONSE, out=None): ''' Return valid status ''' return _set_status(m, status=True, id_=id_, comment=comment, out=out)
[ "def", "_valid", "(", "m", ",", "id_", "=", "NOTSET", ",", "comment", "=", "VALID_RESPONSE", ",", "out", "=", "None", ")", ":", "return", "_set_status", "(", "m", ",", "status", "=", "True", ",", "id_", "=", "id_", ",", "comment", "=", "comment", "...
https://github.com/saltstack/salt-contrib/blob/062355938ad1cced273056e9c23dc344c6a2c858/modules/dockerio.py#L249-L253
LiyuanLucasLiu/LD-Net
f9489b6e7d436b7e3ed6447b797fb6ce9a886483
model_word_ada/utils.py
python
repackage_hidden
(h)
Wraps hidden states in new Variables, to detach them from their history Parameters ---------- h : ``Tuple`` or ``Tensors``, required. Tuple or Tensors, hidden states. Returns ------- hidden: ``Tuple`` or ``Tensors``. detached hidden states
Wraps hidden states in new Variables, to detach them from their history
[ "Wraps", "hidden", "states", "in", "new", "Variables", "to", "detach", "them", "from", "their", "history" ]
def repackage_hidden(h): """ Wraps hidden states in new Variables, to detach them from their history Parameters ---------- h : ``Tuple`` or ``Tensors``, required. Tuple or Tensors, hidden states. Returns ------- hidden: ``Tuple`` or ``Tensors``. detached hidden states """ if type(h) == torch.Tensor: return h.detach() else: return tuple(repackage_hidden(v) for v in h)
[ "def", "repackage_hidden", "(", "h", ")", ":", "if", "type", "(", "h", ")", "==", "torch", ".", "Tensor", ":", "return", "h", ".", "detach", "(", ")", "else", ":", "return", "tuple", "(", "repackage_hidden", "(", "v", ")", "for", "v", "in", "h", ...
https://github.com/LiyuanLucasLiu/LD-Net/blob/f9489b6e7d436b7e3ed6447b797fb6ce9a886483/model_word_ada/utils.py#L17-L34
jina-ai/jina
c77a492fcd5adba0fc3de5347bea83dd4e7d8087
docarray/array/mixins/parallel.py
python
ParallelMixin.map_batch
( self: 'T_DA', func: Callable[['DocumentArray'], 'T'], batch_size: int, backend: str = 'process', num_worker: Optional[int] = None, shuffle: bool = False, )
Return an iterator that applies function to every **minibatch** of iterable in parallel, yielding the results. Each element in the returned iterator is :class:`DocumentArray`. .. seealso:: - To process single element, please use :meth:`.map`; - To return :class:`DocumentArray` or :class:`DocumentArrayMemmap`, please use :meth:`.apply_batch`. :param batch_size: Size of each generated batch (except the last one, which might be smaller, default: 32) :param shuffle: If set, shuffle the Documents before dividing into minibatches. :param func: a function that takes :class:`DocumentArray` as input and outputs anything. You can either modify elements in-place (only with `thread` backend) or work later on return elements. :param backend: if to use multi-`process` or multi-`thread` as the parallelization backend. In general, if your ``func`` is IO-bound then perhaps `thread` is good enough. If your ``func`` is CPU-bound then you may use `process`. In practice, you should try yourselves to figure out the best value. However, if you wish to modify the elements in-place, regardless of IO/CPU-bound, you should always use `thread` backend. .. warning:: When using `process` backend, you should not expect ``func`` modify elements in-place. This is because the multiprocessing backing pass the variable via pickle and work in another process. The passed object and the original object do **not** share the same memory. :param num_worker: the number of parallel workers. If not given, then the number of CPUs in the system will be used. :yield: anything return from ``func``
Return an iterator that applies function to every **minibatch** of iterable in parallel, yielding the results. Each element in the returned iterator is :class:`DocumentArray`.
[ "Return", "an", "iterator", "that", "applies", "function", "to", "every", "**", "minibatch", "**", "of", "iterable", "in", "parallel", "yielding", "the", "results", ".", "Each", "element", "in", "the", "returned", "iterator", "is", ":", "class", ":", "Docume...
def map_batch( self: 'T_DA', func: Callable[['DocumentArray'], 'T'], batch_size: int, backend: str = 'process', num_worker: Optional[int] = None, shuffle: bool = False, ) -> Generator['T', None, None]: """Return an iterator that applies function to every **minibatch** of iterable in parallel, yielding the results. Each element in the returned iterator is :class:`DocumentArray`. .. seealso:: - To process single element, please use :meth:`.map`; - To return :class:`DocumentArray` or :class:`DocumentArrayMemmap`, please use :meth:`.apply_batch`. :param batch_size: Size of each generated batch (except the last one, which might be smaller, default: 32) :param shuffle: If set, shuffle the Documents before dividing into minibatches. :param func: a function that takes :class:`DocumentArray` as input and outputs anything. You can either modify elements in-place (only with `thread` backend) or work later on return elements. :param backend: if to use multi-`process` or multi-`thread` as the parallelization backend. In general, if your ``func`` is IO-bound then perhaps `thread` is good enough. If your ``func`` is CPU-bound then you may use `process`. In practice, you should try yourselves to figure out the best value. However, if you wish to modify the elements in-place, regardless of IO/CPU-bound, you should always use `thread` backend. .. warning:: When using `process` backend, you should not expect ``func`` modify elements in-place. This is because the multiprocessing backing pass the variable via pickle and work in another process. The passed object and the original object do **not** share the same memory. :param num_worker: the number of parallel workers. If not given, then the number of CPUs in the system will be used. :yield: anything return from ``func`` """ if _is_lambda_or_local_function(func) and backend == 'process': func = _globalize_lambda_function(func) with _get_pool(backend, num_worker) as p: for x in p.imap(func, self.batch(batch_size=batch_size, shuffle=shuffle)): yield x
[ "def", "map_batch", "(", "self", ":", "'T_DA'", ",", "func", ":", "Callable", "[", "[", "'DocumentArray'", "]", ",", "'T'", "]", ",", "batch_size", ":", "int", ",", "backend", ":", "str", "=", "'process'", ",", "num_worker", ":", "Optional", "[", "int"...
https://github.com/jina-ai/jina/blob/c77a492fcd5adba0fc3de5347bea83dd4e7d8087/docarray/array/mixins/parallel.py#L128-L165
jjjake/internetarchive
7b0472464b065477101a847a8332d8b4dc1bf74e
internetarchive/cli/ia_upload.py
python
main
(argv, session)
[]
def main(argv, session): if six.PY2: args = docopt(__doc__.encode('utf-8'), argv=argv) else: args = docopt(__doc__, argv=argv) ERRORS = False # Validate args. s = Schema({ str: Use(bool), '<identifier>': Or(None, And(str, validate_s3_identifier, error=('<identifier> should be between 3 and 80 characters in length, and ' 'can only contain alphanumeric characters, periods ".", ' 'underscores "_", or dashes "-". However, <identifier> cannot begin ' 'with periods, underscores, or dashes.'))), '<file>': And( Use(lambda l: l if not six.PY2 else convert_str_list_to_unicode(l)), And(lambda f: all(os.path.exists(x) for x in f if x != '-'), error='<file> should be a readable file or directory.'), And(lambda f: False if f == ['-'] and not args['--remote-name'] else True, error='--remote-name must be provided when uploading from stdin.')), '--remote-name': Or(None, Use(lambda x: x.decode(sys.getfilesystemencoding()) if six.PY2 else x)), '--spreadsheet': Or(None, os.path.isfile, error='--spreadsheet should be a readable file.'), '--file-metadata': Or(None, os.path.isfile, error='--file-metadata should be a readable file.'), '--metadata': Or(None, And(Use(get_args_dict), dict), error='--metadata must be formatted as --metadata="key:value"'), '--header': Or(None, And(Use(get_args_dict), dict), error='--header must be formatted as --header="key:value"'), '--retries': Use(lambda x: int(x[0]) if x else 0), '--sleep': Use(lambda l: int(l[0]), error='--sleep value must be an integer.'), '--size-hint': Or(Use(lambda l: str(l[0]) if l else None), int, None, error='--size-hint value must be an integer.'), '--status-check': bool, }) try: args = s.validate(args) except SchemaError as exc: print('{0}\n{1}'.format(str(exc), printable_usage(__doc__)), file=sys.stderr) sys.exit(1) # Make sure the collection being uploaded to exists. collection_id = args['--metadata'].get('collection') if collection_id and not args['--no-collection-check'] and not args['--status-check']: if isinstance(collection_id, list): collection_id = collection_id[0] collection = session.get_item(collection_id) if not collection.exists: print('You must upload to a collection that exists. ' '"{0}" does not exist.\n{1}'.format(collection_id, printable_usage(__doc__)), file=sys.stderr) sys.exit(1) # Status check. if args['--status-check']: if session.s3_is_overloaded(): print('warning: {0} is over limit, and not accepting requests. ' 'Expect 503 SlowDown errors.'.format(args['<identifier>']), file=sys.stderr) sys.exit(1) else: print('success: {0} is accepting requests.'.format(args['<identifier>'])) sys.exit() elif args['<identifier>']: item = session.get_item(args['<identifier>']) # Upload keyword arguments. if args['--size-hint']: args['--header']['x-archive-size-hint'] = args['--size-hint'] # Upload with backups turned on by default. if not args['--header'].get('x-archive-keep-old-version') and not args['--no-backup']: args['--header']['x-archive-keep-old-version'] = '1' queue_derive = True if args['--no-derive'] is False else False verbose = True if args['--quiet'] is False else False if args['--file-metadata']: try: args['<file>'] = json.load(open(args['--file-metadata'])) except json.decoder.JSONDecodeError: args['<file>'] = list() for line in open(args['--file-metadata']): j = json.loads(line.strip()) args['<file>'].append(j) upload_kwargs = dict( metadata=args['--metadata'], headers=args['--header'], debug=args['--debug'], queue_derive=queue_derive, verbose=verbose, verify=args['--verify'], checksum=args['--checksum'], retries=args['--retries'], retries_sleep=args['--sleep'], delete=args['--delete'], validate_identifier=True ) # Upload files. if not args['--spreadsheet']: if args['-']: local_file = TemporaryFile() local_file.write(sys.stdin.read()) local_file.seek(0) else: local_file = args['<file>'] if isinstance(local_file, (list, tuple, set)) and args['--remote-name']: local_file = local_file[0] if args['--remote-name']: files = {args['--remote-name']: local_file} else: files = local_file for _r in _upload_files(item, files, upload_kwargs): if args['--debug']: break if (not _r.status_code) or (not _r.ok): ERRORS = True else: if args['--open-after-upload']: webbrowser.open_new_tab('{}//{}/details/{}'.format( session.protocol, session.host, item.identifier)) # Bulk upload using spreadsheet. else: # Use the same session for each upload request. with io.open(args['--spreadsheet'], 'rU', newline='', encoding='utf-8') as csvfp: spreadsheet = csv.DictReader(csvfp) prev_identifier = None for row in spreadsheet: for metadata_key in row: if not is_valid_metadata_key(metadata_key): print('error: "%s" is not a valid metadata key.' % metadata_key, file=sys.stderr) sys.exit(1) upload_kwargs_copy = deepcopy(upload_kwargs) if row.get('REMOTE_NAME'): local_file = {row['REMOTE_NAME']: row['file']} del row['REMOTE_NAME'] else: local_file = row['file'] identifier = row.get('item', row.get('identifier')) if not identifier: print('error: no identifier column on spreadsheet.', file=sys.stderr) sys.exit(1) del row['file'] if 'identifier' in row: del row['identifier'] elif 'item' in row: del row['item'] if (not identifier) and (prev_identifier): identifier = prev_identifier item = session.get_item(identifier) # TODO: Clean up how indexed metadata items are coerced # into metadata. md_args = ['{0}:{1}'.format(k.lower(), v) for (k, v) in row.items() if v] metadata = get_args_dict(md_args) upload_kwargs_copy['metadata'].update(metadata) r = _upload_files(item, local_file, upload_kwargs_copy, prev_identifier, session) for _r in r: if args['--debug']: break if (not _r) or (not _r.ok): ERRORS = True else: if args['--open-after-upload']: webbrowser.open_new_tab('{}//{}/details/{}'.format( session.protocol, session.host, identifier)) prev_identifier = identifier if ERRORS: sys.exit(1)
[ "def", "main", "(", "argv", ",", "session", ")", ":", "if", "six", ".", "PY2", ":", "args", "=", "docopt", "(", "__doc__", ".", "encode", "(", "'utf-8'", ")", ",", "argv", "=", "argv", ")", "else", ":", "args", "=", "docopt", "(", "__doc__", ",",...
https://github.com/jjjake/internetarchive/blob/7b0472464b065477101a847a8332d8b4dc1bf74e/internetarchive/cli/ia_upload.py#L132-L310
ialbert/plac
00f9dbb5721ea855132fdc5994961cefb504aa56
plac_core.py
python
ArgumentParser.populate_from
(self, func)
Extract the arguments from the attributes of the passed function and return a populated ArgumentParser instance.
Extract the arguments from the attributes of the passed function and return a populated ArgumentParser instance.
[ "Extract", "the", "arguments", "from", "the", "attributes", "of", "the", "passed", "function", "and", "return", "a", "populated", "ArgumentParser", "instance", "." ]
def populate_from(self, func): """ Extract the arguments from the attributes of the passed function and return a populated ArgumentParser instance. """ self._set_func_argspec(func) f = self.argspec defaults = f.defaults or () n_args = len(f.args) n_defaults = len(defaults) alldefaults = (NONE,) * (n_args - n_defaults) + defaults prefix = self.prefix = getattr(func, 'prefix_chars', '-')[0] for name, default in zip(f.args, alldefaults): ann = f.annotations.get(name, ()) a = Annotation.from_(ann) metavar = a.metavar if default is NONE: dflt = None else: dflt = default if a.help is None: a.help = '[%s]' % str(dflt) # dflt can be a tuple if a.type is None: # try to infer the type from the default argument if isinstance(default, datetime): a.type = to_datetime elif isinstance(default, date): a.type = to_date elif default is not None: a.type = type(default) if not metavar and default == '': metavar = "''" if a.kind in ('option', 'flag'): if name.endswith("_"): # allows reserved words to be specified with underscores suffix = name.rstrip('_') else: # convert undescores to dashes. suffix = name.replace('_', '-') if a.abbrev: shortlong = (prefix + a.abbrev, prefix*2 + suffix) else: shortlong = (prefix + suffix,) elif default is NONE: # required argument self.add_argument(name, help=a.help, type=a.type, choices=a.choices, metavar=metavar) else: # default argument self.add_argument( name, nargs='?', help=a.help, default=dflt, type=a.type, choices=a.choices, metavar=metavar) if a.kind == 'option': if default is not NONE: metavar = metavar or str(default) self.add_argument( help=a.help, default=dflt, type=a.type, choices=a.choices, metavar=metavar, *shortlong) elif a.kind == 'flag': if default is not NONE and default is not False: raise TypeError(_('Flag %r wants default False, got %r') % (name, default)) self.add_argument(action='store_true', help=a.help, *shortlong) if f.varargs: a = Annotation.from_(f.annotations.get(f.varargs, ())) self.add_argument(f.varargs, nargs='*', help=a.help, default=[], type=a.type, metavar=a.metavar) if f.varkw: a = Annotation.from_(f.annotations.get(f.varkw, ())) self.add_argument(f.varkw, nargs='*', help=a.help, default={}, type=a.type, metavar=a.metavar)
[ "def", "populate_from", "(", "self", ",", "func", ")", ":", "self", ".", "_set_func_argspec", "(", "func", ")", "f", "=", "self", ".", "argspec", "defaults", "=", "f", ".", "defaults", "or", "(", ")", "n_args", "=", "len", "(", "f", ".", "args", ")...
https://github.com/ialbert/plac/blob/00f9dbb5721ea855132fdc5994961cefb504aa56/plac_core.py#L331-L402
fonttools/fonttools
892322aaff6a89bea5927379ec06bc0da3dfb7df
Lib/fontTools/cffLib/specializer.py
python
_GeneralizerDecombinerCommandsMap.vvcurveto
(args)
[]
def vvcurveto(args): if len(args) < 4 or len(args) % 4 > 1: raise ValueError(args) if len(args) % 2 == 1: yield ('rrcurveto', [args[0], args[1], args[2], args[3], 0, args[4]]) args = args[5:] for args in _everyN(args, 4): yield ('rrcurveto', [0, args[0], args[1], args[2], 0, args[3]])
[ "def", "vvcurveto", "(", "args", ")", ":", "if", "len", "(", "args", ")", "<", "4", "or", "len", "(", "args", ")", "%", "4", ">", "1", ":", "raise", "ValueError", "(", "args", ")", "if", "len", "(", "args", ")", "%", "2", "==", "1", ":", "y...
https://github.com/fonttools/fonttools/blob/892322aaff6a89bea5927379ec06bc0da3dfb7df/Lib/fontTools/cffLib/specializer.py#L208-L214
JasperSnoek/spearmint
b37a541be1ea035f82c7c82bbd93f5b4320e7d91
spearmint-lite/ExperimentGrid.py
python
ExperimentGrid.__del__
(self)
[]
def __del__(self): self._save_jobs() if self.locker.unlock(self.jobs_pkl): sys.stderr.write("Released lock on job grid.\n") else: raise Exception("Could not release lock on job grid.\n")
[ "def", "__del__", "(", "self", ")", ":", "self", ".", "_save_jobs", "(", ")", "if", "self", ".", "locker", ".", "unlock", "(", "self", ".", "jobs_pkl", ")", ":", "sys", ".", "stderr", ".", "write", "(", "\"Released lock on job grid.\\n\"", ")", "else", ...
https://github.com/JasperSnoek/spearmint/blob/b37a541be1ea035f82c7c82bbd93f5b4320e7d91/spearmint-lite/ExperimentGrid.py#L85-L90
AppScale/gts
46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9
AppServer/lib/setuptools-0.6c11/pkg_resources.py
python
find_on_path
(importer, path_item, only=False)
Yield distributions accessible on a sys.path directory
Yield distributions accessible on a sys.path directory
[ "Yield", "distributions", "accessible", "on", "a", "sys", ".", "path", "directory" ]
def find_on_path(importer, path_item, only=False): """Yield distributions accessible on a sys.path directory""" path_item = _normalize_cached(path_item) if os.path.isdir(path_item) and os.access(path_item, os.R_OK): if path_item.lower().endswith('.egg'): # unpacked egg yield Distribution.from_filename( path_item, metadata=PathMetadata( path_item, os.path.join(path_item,'EGG-INFO') ) ) else: # scan for .egg and .egg-info in directory for entry in os.listdir(path_item): lower = entry.lower() if lower.endswith('.egg-info'): fullpath = os.path.join(path_item, entry) if os.path.isdir(fullpath): # egg-info directory, allow getting metadata metadata = PathMetadata(path_item, fullpath) else: metadata = FileMetadata(fullpath) yield Distribution.from_location( path_item,entry,metadata,precedence=DEVELOP_DIST ) elif not only and lower.endswith('.egg'): for dist in find_distributions(os.path.join(path_item, entry)): yield dist elif not only and lower.endswith('.egg-link'): for line in file(os.path.join(path_item, entry)): if not line.strip(): continue for item in find_distributions(os.path.join(path_item,line.rstrip())): yield item break
[ "def", "find_on_path", "(", "importer", ",", "path_item", ",", "only", "=", "False", ")", ":", "path_item", "=", "_normalize_cached", "(", "path_item", ")", "if", "os", ".", "path", ".", "isdir", "(", "path_item", ")", "and", "os", ".", "access", "(", ...
https://github.com/AppScale/gts/blob/46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9/AppServer/lib/setuptools-0.6c11/pkg_resources.py#L1686-L1720
NeuralEnsemble/python-neo
34d4db8fb0dc950dbbc6defd7fb75e99ea877286
neo/rawio/baserawio.py
python
BaseRawIO.__init__
(self, use_cache=False, cache_path='same_as_resource', **kargs)
:TODO: Why multi-file would have a single filename is confusing here - shouldn't the name of this argument be filenames_list or filenames_base or similar? When rawmode=='one-file' kargs MUST contains 'filename' the filename When rawmode=='multi-file' kargs MUST contains 'filename' one of the filenames. When rawmode=='one-dir' kargs MUST contains 'dirname' the dirname.
:TODO: Why multi-file would have a single filename is confusing here - shouldn't the name of this argument be filenames_list or filenames_base or similar?
[ ":", "TODO", ":", "Why", "multi", "-", "file", "would", "have", "a", "single", "filename", "is", "confusing", "here", "-", "shouldn", "t", "the", "name", "of", "this", "argument", "be", "filenames_list", "or", "filenames_base", "or", "similar?" ]
def __init__(self, use_cache=False, cache_path='same_as_resource', **kargs): """ :TODO: Why multi-file would have a single filename is confusing here - shouldn't the name of this argument be filenames_list or filenames_base or similar? When rawmode=='one-file' kargs MUST contains 'filename' the filename When rawmode=='multi-file' kargs MUST contains 'filename' one of the filenames. When rawmode=='one-dir' kargs MUST contains 'dirname' the dirname. """ # create a logger for the IO class fullname = self.__class__.__module__ + '.' + self.__class__.__name__ self.logger = logging.getLogger(fullname) # Create a logger for 'neo' and add a handler to it if it doesn't have one already. # (it will also not add one if the root logger has a handler) corename = self.__class__.__module__.split('.')[0] corelogger = logging.getLogger(corename) rootlogger = logging.getLogger() if not corelogger.handlers and not rootlogger.handlers: corelogger.addHandler(logging_handler) self.use_cache = use_cache if use_cache: assert HAVE_JOBLIB, 'You need to install joblib for cache' self.setup_cache(cache_path) else: self._cache = None self.header = None
[ "def", "__init__", "(", "self", ",", "use_cache", "=", "False", ",", "cache_path", "=", "'same_as_resource'", ",", "*", "*", "kargs", ")", ":", "# create a logger for the IO class", "fullname", "=", "self", ".", "__class__", ".", "__module__", "+", "'.'", "+",...
https://github.com/NeuralEnsemble/python-neo/blob/34d4db8fb0dc950dbbc6defd7fb75e99ea877286/neo/rawio/baserawio.py#L142-L170
AndroBugs/AndroBugs_Framework
7fd3a2cb1cf65a9af10b7ed2129701d4451493fe
tools/modified/androguard/core/analysis/analysis.py
python
RegisterAnalyzerVM_ImmediateValue.get_register_value_by_param_in_last_ins
(self, param)
Example code: invoke-virtual v2, v3, v6, v4, v5, Landroid/content/Context;->openOrCreateDatabase(Ljava/lang/String; I Landroid/database/sqlite/SQLiteDatabase$CursorFactory; Landroid/database/DatabaseErrorHandler;)Landroid/database/sqlite/SQLiteDatabase; [(0, 2), (0, 3), (0, 6), (0, 4), (0, 5), (256, 147, 'Landroid/content/Context;->openOrCreateDatabase(Ljava/lang/String; I Landroid/database/sqlite/SQLiteDatabase$CursorFactory; Landroid/database/DatabaseErrorHandler;)Landroid/database/sqlite/SQLiteDatabase;')]
Example code: invoke-virtual v2, v3, v6, v4, v5, Landroid/content/Context;->openOrCreateDatabase(Ljava/lang/String; I Landroid/database/sqlite/SQLiteDatabase$CursorFactory; Landroid/database/DatabaseErrorHandler;)Landroid/database/sqlite/SQLiteDatabase; [(0, 2), (0, 3), (0, 6), (0, 4), (0, 5), (256, 147, 'Landroid/content/Context;->openOrCreateDatabase(Ljava/lang/String; I Landroid/database/sqlite/SQLiteDatabase$CursorFactory; Landroid/database/DatabaseErrorHandler;)Landroid/database/sqlite/SQLiteDatabase;')]
[ "Example", "code", ":", "invoke", "-", "virtual", "v2", "v3", "v6", "v4", "v5", "Landroid", "/", "content", "/", "Context", ";", "-", ">", "openOrCreateDatabase", "(", "Ljava", "/", "lang", "/", "String", ";", "I", "Landroid", "/", "database", "/", "sq...
def get_register_value_by_param_in_last_ins(self, param): if (self._register is None) or (self.__ins_stack is None): return None """ Example code: invoke-virtual v2, v3, v6, v4, v5, Landroid/content/Context;->openOrCreateDatabase(Ljava/lang/String; I Landroid/database/sqlite/SQLiteDatabase$CursorFactory; Landroid/database/DatabaseErrorHandler;)Landroid/database/sqlite/SQLiteDatabase; [(0, 2), (0, 3), (0, 6), (0, 4), (0, 5), (256, 147, 'Landroid/content/Context;->openOrCreateDatabase(Ljava/lang/String; I Landroid/database/sqlite/SQLiteDatabase$CursorFactory; Landroid/database/DatabaseErrorHandler;)Landroid/database/sqlite/SQLiteDatabase;')] """ try: last_ins = self.__ins_stack.get() last_ins_register_pair = last_ins[param] if last_ins_register_pair is not None: return self.get_register_value(last_ins_register_pair[1]) return None except IndexError: return None
[ "def", "get_register_value_by_param_in_last_ins", "(", "self", ",", "param", ")", ":", "if", "(", "self", ".", "_register", "is", "None", ")", "or", "(", "self", ".", "__ins_stack", "is", "None", ")", ":", "return", "None", "try", ":", "last_ins", "=", "...
https://github.com/AndroBugs/AndroBugs_Framework/blob/7fd3a2cb1cf65a9af10b7ed2129701d4451493fe/tools/modified/androguard/core/analysis/analysis.py#L343-L361
buke/GreenOdoo
3d8c55d426fb41fdb3f2f5a1533cfe05983ba1df
source/openerp/netsvc.py
python
LocalService
(name)
The openerp.netsvc.LocalService() function is deprecated. It still works in two cases: workflows and reports. For workflows, instead of using LocalService('workflow'), openerp.workflow should be used (better yet, methods on openerp.osv.orm.Model should be used). For reports, openerp.report.render_report() should be used (methods on the Model should be provided too in the future).
The openerp.netsvc.LocalService() function is deprecated. It still works in two cases: workflows and reports. For workflows, instead of using LocalService('workflow'), openerp.workflow should be used (better yet, methods on openerp.osv.orm.Model should be used). For reports, openerp.report.render_report() should be used (methods on the Model should be provided too in the future).
[ "The", "openerp", ".", "netsvc", ".", "LocalService", "()", "function", "is", "deprecated", ".", "It", "still", "works", "in", "two", "cases", ":", "workflows", "and", "reports", ".", "For", "workflows", "instead", "of", "using", "LocalService", "(", "workfl...
def LocalService(name): """ The openerp.netsvc.LocalService() function is deprecated. It still works in two cases: workflows and reports. For workflows, instead of using LocalService('workflow'), openerp.workflow should be used (better yet, methods on openerp.osv.orm.Model should be used). For reports, openerp.report.render_report() should be used (methods on the Model should be provided too in the future). """ assert openerp.conf.deprecation.allow_local_service _logger.warning("LocalService() is deprecated since march 2013 (it was called with '%s')." % name) if name == 'workflow': return openerp.workflow if name.startswith('report.'): report = openerp.report.interface.report_int._reports.get(name) if report: return report else: dbname = getattr(threading.currentThread(), 'dbname', None) if dbname: registry = openerp.modules.registry.RegistryManager.get(dbname) with registry.cursor() as cr: return registry['ir.actions.report.xml']._lookup_report(cr, name[len('report.'):])
[ "def", "LocalService", "(", "name", ")", ":", "assert", "openerp", ".", "conf", ".", "deprecation", ".", "allow_local_service", "_logger", ".", "warning", "(", "\"LocalService() is deprecated since march 2013 (it was called with '%s').\"", "%", "name", ")", "if", "name"...
https://github.com/buke/GreenOdoo/blob/3d8c55d426fb41fdb3f2f5a1533cfe05983ba1df/source/openerp/netsvc.py#L46-L70
volatilityfoundation/volatility
a438e768194a9e05eb4d9ee9338b881c0fa25937
volatility/plugins/overlays/windows/pe_vtypes.py
python
_LDR_DATA_TABLE_ENTRY.import_dir
(self)
return self._directory(1)
Return the IMAGE_DATA_DIRECTORY for imports
Return the IMAGE_DATA_DIRECTORY for imports
[ "Return", "the", "IMAGE_DATA_DIRECTORY", "for", "imports" ]
def import_dir(self): """Return the IMAGE_DATA_DIRECTORY for imports""" return self._directory(1)
[ "def", "import_dir", "(", "self", ")", ":", "return", "self", ".", "_directory", "(", "1", ")" ]
https://github.com/volatilityfoundation/volatility/blob/a438e768194a9e05eb4d9ee9338b881c0fa25937/volatility/plugins/overlays/windows/pe_vtypes.py#L505-L507
securityclippy/elasticintel
aa08d3e9f5ab1c000128e95161139ce97ff0e334
ingest_feed_lambda/pandas/core/indexes/category.py
python
CategoricalIndex._delegate_method
(self, name, *args, **kwargs)
return CategoricalIndex(res, name=self.name)
method delegation to the ._values
method delegation to the ._values
[ "method", "delegation", "to", "the", ".", "_values" ]
def _delegate_method(self, name, *args, **kwargs): """ method delegation to the ._values """ method = getattr(self._values, name) if 'inplace' in kwargs: raise ValueError("cannot use inplace with CategoricalIndex") res = method(*args, **kwargs) if is_scalar(res): return res return CategoricalIndex(res, name=self.name)
[ "def", "_delegate_method", "(", "self", ",", "name", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "method", "=", "getattr", "(", "self", ".", "_values", ",", "name", ")", "if", "'inplace'", "in", "kwargs", ":", "raise", "ValueError", "(", "\"...
https://github.com/securityclippy/elasticintel/blob/aa08d3e9f5ab1c000128e95161139ce97ff0e334/ingest_feed_lambda/pandas/core/indexes/category.py#L738-L746
inducer/pyopencl
71b29745dc023a4d3aa9ddf22ff65c0cb3e6d703
pyopencl/array.py
python
Array.get
(self, queue=None, ary=None, async_=None, **kwargs)
return ary
Transfer the contents of *self* into *ary* or a newly allocated :class:`numpy.ndarray`. If *ary* is given, it must have the same shape and dtype. .. versionchanged:: 2019.1.2 Calling with `async_=True` was deprecated and replaced by :meth:`get_async`. The event returned by :meth:`pyopencl.enqueue_copy` is now stored into :attr:`events` to ensure data is not modified before the copy is complete. .. versionchanged:: 2015.2 *ary* with different shape was deprecated. .. versionchanged:: 2017.2.1 Python 3.7 makes ``async`` a reserved keyword. On older Pythons, we will continue to accept *async* as a parameter, however this should be considered deprecated. *async_* is the new, official spelling.
Transfer the contents of *self* into *ary* or a newly allocated :class:`numpy.ndarray`. If *ary* is given, it must have the same shape and dtype.
[ "Transfer", "the", "contents", "of", "*", "self", "*", "into", "*", "ary", "*", "or", "a", "newly", "allocated", ":", "class", ":", "numpy", ".", "ndarray", ".", "If", "*", "ary", "*", "is", "given", "it", "must", "have", "the", "same", "shape", "a...
def get(self, queue=None, ary=None, async_=None, **kwargs): """Transfer the contents of *self* into *ary* or a newly allocated :class:`numpy.ndarray`. If *ary* is given, it must have the same shape and dtype. .. versionchanged:: 2019.1.2 Calling with `async_=True` was deprecated and replaced by :meth:`get_async`. The event returned by :meth:`pyopencl.enqueue_copy` is now stored into :attr:`events` to ensure data is not modified before the copy is complete. .. versionchanged:: 2015.2 *ary* with different shape was deprecated. .. versionchanged:: 2017.2.1 Python 3.7 makes ``async`` a reserved keyword. On older Pythons, we will continue to accept *async* as a parameter, however this should be considered deprecated. *async_* is the new, official spelling. """ if async_: from warnings import warn warn("calling pyopencl.Array.get with `async_=True` is deprecated. " "Please use pyopencl.Array.get_async for asynchronous " "device-to-host transfers", DeprecationWarning, 2) ary, event1 = self._get(queue=queue, ary=ary, async_=async_, **kwargs) return ary
[ "def", "get", "(", "self", ",", "queue", "=", "None", ",", "ary", "=", "None", ",", "async_", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "async_", ":", "from", "warnings", "import", "warn", "warn", "(", "\"calling pyopencl.Array.get with `asyn...
https://github.com/inducer/pyopencl/blob/71b29745dc023a4d3aa9ddf22ff65c0cb3e6d703/pyopencl/array.py#L780-L814
allenai/allennlp
a3d71254fcc0f3615910e9c3d48874515edf53e0
allennlp/training/learning_rate_schedulers/learning_rate_scheduler.py
python
_PyTorchLearningRateSchedulerWrapper.state_dict
(self)
return self.lr_scheduler.state_dict()
[]
def state_dict(self) -> Dict[str, Any]: return self.lr_scheduler.state_dict()
[ "def", "state_dict", "(", "self", ")", "->", "Dict", "[", "str", ",", "Any", "]", ":", "return", "self", ".", "lr_scheduler", ".", "state_dict", "(", ")" ]
https://github.com/allenai/allennlp/blob/a3d71254fcc0f3615910e9c3d48874515edf53e0/allennlp/training/learning_rate_schedulers/learning_rate_scheduler.py#L36-L37
mlcommons/inference
078e21f2bc0a37c7fd0e435d64f5a49760dca823
translation/gnmt/tensorflow/nmt/model_helper.py
python
_get_embed_device
(vocab_size)
Decide on which device to place an embed matrix given its vocab size.
Decide on which device to place an embed matrix given its vocab size.
[ "Decide", "on", "which", "device", "to", "place", "an", "embed", "matrix", "given", "its", "vocab", "size", "." ]
def _get_embed_device(vocab_size): """Decide on which device to place an embed matrix given its vocab size.""" if vocab_size > VOCAB_SIZE_THRESHOLD_CPU: return "/cpu:0" else: return "/gpu:0"
[ "def", "_get_embed_device", "(", "vocab_size", ")", ":", "if", "vocab_size", ">", "VOCAB_SIZE_THRESHOLD_CPU", ":", "return", "\"/cpu:0\"", "else", ":", "return", "\"/gpu:0\"" ]
https://github.com/mlcommons/inference/blob/078e21f2bc0a37c7fd0e435d64f5a49760dca823/translation/gnmt/tensorflow/nmt/model_helper.py#L237-L242