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
colour-science/colour
38782ac059e8ddd91939f3432bf06811c16667f0
colour/io/image.py
python
read_image
(path, bit_depth='float32', method='OpenImageIO', **kwargs)
return function(path, bit_depth, **kwargs)
Reads the image at given path using given method. Parameters ---------- path : str Image path. bit_depth : str, optional **{'float32', 'uint8', 'uint16', 'float16'}**, Returned image bit depth, for the *Imageio* method, the image data is converted with :func:`colour.io.convert_bit_depth` definition after reading the image, for the *OpenImageIO* method, the bit depth conversion behaviour is driven directly by the library, this definition only converts to the relevant data type after reading. method : str, optional **{'OpenImageIO', 'Imageio'}**, Read method, i.e. the image library used for reading images. Other Parameters ---------------- attributes : bool, optional {:func:`colour.io.read_image_OpenImageIO`}, Whether to return the image attributes. Returns ------- ndarray Image as a ndarray. Notes ----- - If the given method is *OpenImageIO* but the library is not available writing will be performed by *Imageio*. - If the given method is *Imageio*, ``kwargs`` is passed directly to the wrapped definition. - For convenience, single channel images are squeezed to 2d arrays. Examples -------- >>> import os >>> import colour >>> path = os.path.join(colour.__path__[0], 'io', 'tests', 'resources', ... 'CMS_Test_Pattern.exr') >>> image = read_image(path) >>> image.shape # doctest: +SKIP (1267, 1274, 3) >>> image.dtype dtype('float32')
Reads the image at given path using given method.
[ "Reads", "the", "image", "at", "given", "path", "using", "given", "method", "." ]
def read_image(path, bit_depth='float32', method='OpenImageIO', **kwargs): """ Reads the image at given path using given method. Parameters ---------- path : str Image path. bit_depth : str, optional **{'float32', 'uint8', 'uint16', 'float16'}**, Returned image bit depth, for the *Imageio* method, the image data is converted with :func:`colour.io.convert_bit_depth` definition after reading the image, for the *OpenImageIO* method, the bit depth conversion behaviour is driven directly by the library, this definition only converts to the relevant data type after reading. method : str, optional **{'OpenImageIO', 'Imageio'}**, Read method, i.e. the image library used for reading images. Other Parameters ---------------- attributes : bool, optional {:func:`colour.io.read_image_OpenImageIO`}, Whether to return the image attributes. Returns ------- ndarray Image as a ndarray. Notes ----- - If the given method is *OpenImageIO* but the library is not available writing will be performed by *Imageio*. - If the given method is *Imageio*, ``kwargs`` is passed directly to the wrapped definition. - For convenience, single channel images are squeezed to 2d arrays. Examples -------- >>> import os >>> import colour >>> path = os.path.join(colour.__path__[0], 'io', 'tests', 'resources', ... 'CMS_Test_Pattern.exr') >>> image = read_image(path) >>> image.shape # doctest: +SKIP (1267, 1274, 3) >>> image.dtype dtype('float32') """ method = validate_method(method, READ_IMAGE_METHODS) if method == 'openimageio': # pragma: no cover if not is_openimageio_installed(): usage_warning( '"OpenImageIO" related API features are not available, ' 'switching to "Imageio"!') method = 'Imageio' function = READ_IMAGE_METHODS[method] if method == 'openimageio': # pragma: no cover kwargs = filter_kwargs(function, **kwargs) return function(path, bit_depth, **kwargs)
[ "def", "read_image", "(", "path", ",", "bit_depth", "=", "'float32'", ",", "method", "=", "'OpenImageIO'", ",", "*", "*", "kwargs", ")", ":", "method", "=", "validate_method", "(", "method", ",", "READ_IMAGE_METHODS", ")", "if", "method", "==", "'openimageio...
https://github.com/colour-science/colour/blob/38782ac059e8ddd91939f3432bf06811c16667f0/colour/io/image.py#L309-L374
pallets/werkzeug
9efe8c00dcb2b6fc086961ba304729db01912652
src/werkzeug/security.py
python
check_password_hash
(pwhash: str, password: str)
return hmac.compare_digest(_hash_internal(method, salt, password)[0], hashval)
Check a password against a given salted and hashed password value. In order to support unsalted legacy passwords this method supports plain text passwords, md5 and sha1 hashes (both salted and unsalted). Returns `True` if the password matched, `False` otherwise. :param pwhash: a hashed string like returned by :func:`generate_password_hash`. :param password: the plaintext password to compare against the hash.
Check a password against a given salted and hashed password value. In order to support unsalted legacy passwords this method supports plain text passwords, md5 and sha1 hashes (both salted and unsalted).
[ "Check", "a", "password", "against", "a", "given", "salted", "and", "hashed", "password", "value", ".", "In", "order", "to", "support", "unsalted", "legacy", "passwords", "this", "method", "supports", "plain", "text", "passwords", "md5", "and", "sha1", "hashes...
def check_password_hash(pwhash: str, password: str) -> bool: """Check a password against a given salted and hashed password value. In order to support unsalted legacy passwords this method supports plain text passwords, md5 and sha1 hashes (both salted and unsalted). Returns `True` if the password matched, `False` otherwise. :param pwhash: a hashed string like returned by :func:`generate_password_hash`. :param password: the plaintext password to compare against the hash. """ if pwhash.count("$") < 2: return False method, salt, hashval = pwhash.split("$", 2) return hmac.compare_digest(_hash_internal(method, salt, password)[0], hashval)
[ "def", "check_password_hash", "(", "pwhash", ":", "str", ",", "password", ":", "str", ")", "->", "bool", ":", "if", "pwhash", ".", "count", "(", "\"$\"", ")", "<", "2", ":", "return", "False", "method", ",", "salt", ",", "hashval", "=", "pwhash", "."...
https://github.com/pallets/werkzeug/blob/9efe8c00dcb2b6fc086961ba304729db01912652/src/werkzeug/security.py#L92-L107
plotly/plotly.py
cfad7862594b35965c0e000813bd7805e8494a5b
packages/python/plotly/plotly/graph_objs/heatmap/_colorbar.py
python
ColorBar.tickvals
(self)
return self["tickvals"]
Sets the values at which ticks on this axis appear. Only has an effect if `tickmode` is set to "array". Used with `ticktext`. The 'tickvals' property is an array that may be specified as a tuple, list, numpy array, or pandas Series Returns ------- numpy.ndarray
Sets the values at which ticks on this axis appear. Only has an effect if `tickmode` is set to "array". Used with `ticktext`. The 'tickvals' property is an array that may be specified as a tuple, list, numpy array, or pandas Series
[ "Sets", "the", "values", "at", "which", "ticks", "on", "this", "axis", "appear", ".", "Only", "has", "an", "effect", "if", "tickmode", "is", "set", "to", "array", ".", "Used", "with", "ticktext", ".", "The", "tickvals", "property", "is", "an", "array", ...
def tickvals(self): """ Sets the values at which ticks on this axis appear. Only has an effect if `tickmode` is set to "array". Used with `ticktext`. The 'tickvals' property is an array that may be specified as a tuple, list, numpy array, or pandas Series Returns ------- numpy.ndarray """ return self["tickvals"]
[ "def", "tickvals", "(", "self", ")", ":", "return", "self", "[", "\"tickvals\"", "]" ]
https://github.com/plotly/plotly.py/blob/cfad7862594b35965c0e000813bd7805e8494a5b/packages/python/plotly/plotly/graph_objs/heatmap/_colorbar.py#L1082-L1094
plaid/plaid-python
8c60fca608e426f3ff30da8857775946d29e122c
plaid/model/transfer_cancel_request.py
python
TransferCancelRequest.__init__
(self, transfer_id, *args, **kwargs)
TransferCancelRequest - a model defined in OpenAPI Args: transfer_id (str): Plaid’s unique identifier for a transfer. Keyword Args: _check_type (bool): if True, values for parameters in openapi_types will be type checked and a TypeError will be raised if the wrong type is input. Defaults to True _path_to_item (tuple/list): This is a list of keys or values to drill down to the model in received_data when deserializing a response _spec_property_naming (bool): True if the variable names in the input data are serialized names, as specified in the OpenAPI document. False if the variable names in the input data are pythonic names, e.g. snake case (default) _configuration (Configuration): the instance to use when deserializing a file_type parameter. If passed, type conversion is attempted If omitted no type conversion is done. _visited_composed_classes (tuple): This stores a tuple of classes that we have traveled through so that if we see that class again we will not use its discriminator again. When traveling through a discriminator, the composed schema that is is traveled through is added to this set. For example if Animal has a discriminator petType and we pass in "Dog", and the class Dog allOf includes Animal, we move through Animal once using the discriminator, and pick Dog. Then in Dog, we will make an instance of the Animal class but this time we won't travel through its discriminator because we passed in _visited_composed_classes = (Animal,) client_id (str): Your Plaid API `client_id`. The `client_id` is required and may be provided either in the `PLAID-CLIENT-ID` header or as part of a request body.. [optional] # noqa: E501 secret (str): Your Plaid API `secret`. The `secret` is required and may be provided either in the `PLAID-SECRET` header or as part of a request body.. [optional] # noqa: E501
TransferCancelRequest - a model defined in OpenAPI
[ "TransferCancelRequest", "-", "a", "model", "defined", "in", "OpenAPI" ]
def __init__(self, transfer_id, *args, **kwargs): # noqa: E501 """TransferCancelRequest - a model defined in OpenAPI Args: transfer_id (str): Plaid’s unique identifier for a transfer. Keyword Args: _check_type (bool): if True, values for parameters in openapi_types will be type checked and a TypeError will be raised if the wrong type is input. Defaults to True _path_to_item (tuple/list): This is a list of keys or values to drill down to the model in received_data when deserializing a response _spec_property_naming (bool): True if the variable names in the input data are serialized names, as specified in the OpenAPI document. False if the variable names in the input data are pythonic names, e.g. snake case (default) _configuration (Configuration): the instance to use when deserializing a file_type parameter. If passed, type conversion is attempted If omitted no type conversion is done. _visited_composed_classes (tuple): This stores a tuple of classes that we have traveled through so that if we see that class again we will not use its discriminator again. When traveling through a discriminator, the composed schema that is is traveled through is added to this set. For example if Animal has a discriminator petType and we pass in "Dog", and the class Dog allOf includes Animal, we move through Animal once using the discriminator, and pick Dog. Then in Dog, we will make an instance of the Animal class but this time we won't travel through its discriminator because we passed in _visited_composed_classes = (Animal,) client_id (str): Your Plaid API `client_id`. The `client_id` is required and may be provided either in the `PLAID-CLIENT-ID` header or as part of a request body.. [optional] # noqa: E501 secret (str): Your Plaid API `secret`. The `secret` is required and may be provided either in the `PLAID-SECRET` header or as part of a request body.. [optional] # noqa: E501 """ _check_type = kwargs.pop('_check_type', True) _spec_property_naming = kwargs.pop('_spec_property_naming', False) _path_to_item = kwargs.pop('_path_to_item', ()) _configuration = kwargs.pop('_configuration', None) _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) if args: raise ApiTypeError( "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( args, self.__class__.__name__, ), path_to_item=_path_to_item, valid_classes=(self.__class__,), ) self._data_store = {} self._check_type = _check_type self._spec_property_naming = _spec_property_naming self._path_to_item = _path_to_item self._configuration = _configuration self._visited_composed_classes = _visited_composed_classes + (self.__class__,) self.transfer_id = transfer_id for var_name, var_value in kwargs.items(): if var_name not in self.attribute_map and \ self._configuration is not None and \ self._configuration.discard_unknown_keys and \ self.additional_properties_type is None: # discard variable. continue setattr(self, var_name, var_value)
[ "def", "__init__", "(", "self", ",", "transfer_id", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# noqa: E501", "_check_type", "=", "kwargs", ".", "pop", "(", "'_check_type'", ",", "True", ")", "_spec_property_naming", "=", "kwargs", ".", "pop", ...
https://github.com/plaid/plaid-python/blob/8c60fca608e426f3ff30da8857775946d29e122c/plaid/model/transfer_cancel_request.py#L101-L173
coleifer/walrus
2583ac8ba81d3f6aa43fccbe28c0c13b99a1fa9d
walrus/containers.py
python
Hash.values
(self)
return self.database.hvals(self.key)
Return the values stored in the hash.
Return the values stored in the hash.
[ "Return", "the", "values", "stored", "in", "the", "hash", "." ]
def values(self): """Return the values stored in the hash.""" return self.database.hvals(self.key)
[ "def", "values", "(", "self", ")", ":", "return", "self", ".", "database", ".", "hvals", "(", "self", ".", "key", ")" ]
https://github.com/coleifer/walrus/blob/2583ac8ba81d3f6aa43fccbe28c0c13b99a1fa9d/walrus/containers.py#L170-L172
larryhastings/gilectomy
4315ec3f1d6d4f813cc82ce27a24e7f784dbfc1a
Lib/queue.py
python
Queue.join
(self)
Blocks until all items in the Queue have been gotten and processed. The count of unfinished tasks goes up whenever an item is added to the queue. The count goes down whenever a consumer thread calls task_done() to indicate the item was retrieved and all work on it is complete. When the count of unfinished tasks drops to zero, join() unblocks.
Blocks until all items in the Queue have been gotten and processed.
[ "Blocks", "until", "all", "items", "in", "the", "Queue", "have", "been", "gotten", "and", "processed", "." ]
def join(self): '''Blocks until all items in the Queue have been gotten and processed. The count of unfinished tasks goes up whenever an item is added to the queue. The count goes down whenever a consumer thread calls task_done() to indicate the item was retrieved and all work on it is complete. When the count of unfinished tasks drops to zero, join() unblocks. ''' with self.all_tasks_done: while self.unfinished_tasks: self.all_tasks_done.wait()
[ "def", "join", "(", "self", ")", ":", "with", "self", ".", "all_tasks_done", ":", "while", "self", ".", "unfinished_tasks", ":", "self", ".", "all_tasks_done", ".", "wait", "(", ")" ]
https://github.com/larryhastings/gilectomy/blob/4315ec3f1d6d4f813cc82ce27a24e7f784dbfc1a/Lib/queue.py#L72-L83
zhoubear/open-paperless
b42d4e3bc88343ca5803c613321327406eabca1a
mayan/apps/converter/classes.py
python
ConverterBase.soffice
(self)
Executes LibreOffice as a subprocess
Executes LibreOffice as a subprocess
[ "Executes", "LibreOffice", "as", "a", "subprocess" ]
def soffice(self): """ Executes LibreOffice as a subprocess """ if not LIBREOFFICE: raise OfficeConversionError( _('LibreOffice not installed or not found.') ) new_file_object, input_filepath = mkstemp() self.file_object.seek(0) os.write(new_file_object, self.file_object.read()) self.file_object.seek(0) os.lseek(new_file_object, 0, os.SEEK_SET) os.close(new_file_object) libreoffice_filter = None if self.mime_type == 'text/plain': libreoffice_filter = 'Text (encoded):UTF8,LF,,,' libreoffice_home_directory = mkdtemp() args = ( input_filepath, '--outdir', setting_temporary_directory.value, '-env:UserInstallation=file://{}'.format( os.path.join( libreoffice_home_directory, 'LibreOffice_Conversion' ) ), ) kwargs = {'_env': {'HOME': libreoffice_home_directory}} if libreoffice_filter: kwargs.update({'infilter': libreoffice_filter}) try: LIBREOFFICE(*args, **kwargs) except sh.ErrorReturnCode as exception: raise OfficeConversionError(exception) except Exception as exception: logger.error('Exception launching Libre Office; %s', exception) raise finally: fs_cleanup(input_filepath) fs_cleanup(libreoffice_home_directory) filename, extension = os.path.splitext( os.path.basename(input_filepath) ) logger.debug('filename: %s', filename) logger.debug('extension: %s', extension) converted_output = os.path.join( setting_temporary_directory.value, os.path.extsep.join( (filename, 'pdf') ) ) logger.debug('converted_output: %s', converted_output) with open(converted_output) as converted_file_object: while True: data = converted_file_object.read(CHUNK_SIZE) if not data: break yield data fs_cleanup(input_filepath) fs_cleanup(converted_output)
[ "def", "soffice", "(", "self", ")", ":", "if", "not", "LIBREOFFICE", ":", "raise", "OfficeConversionError", "(", "_", "(", "'LibreOffice not installed or not found.'", ")", ")", "new_file_object", ",", "input_filepath", "=", "mkstemp", "(", ")", "self", ".", "fi...
https://github.com/zhoubear/open-paperless/blob/b42d4e3bc88343ca5803c613321327406eabca1a/mayan/apps/converter/classes.py#L114-L181
holzschu/Carnets
44effb10ddfc6aa5c8b0687582a724ba82c6b547
Library/lib/python3.7/turtle.py
python
RawTurtle.undobufferentries
(self)
return self.undobuffer.nr_of_items()
Return count of entries in the undobuffer. No argument. Example (for a Turtle instance named turtle): >>> while undobufferentries(): ... undo()
Return count of entries in the undobuffer.
[ "Return", "count", "of", "entries", "in", "the", "undobuffer", "." ]
def undobufferentries(self): """Return count of entries in the undobuffer. No argument. Example (for a Turtle instance named turtle): >>> while undobufferentries(): ... undo() """ if self.undobuffer is None: return 0 return self.undobuffer.nr_of_items()
[ "def", "undobufferentries", "(", "self", ")", ":", "if", "self", ".", "undobuffer", "is", "None", ":", "return", "0", "return", "self", ".", "undobuffer", ".", "nr_of_items", "(", ")" ]
https://github.com/holzschu/Carnets/blob/44effb10ddfc6aa5c8b0687582a724ba82c6b547/Library/lib/python3.7/turtle.py#L2603-L2614
loli/medpy
39131b94f0ab5328ab14a874229320efc2f74d98
medpy/graphcut/generate.py
python
__boundary_term_label
(graph, label_image, boundary_term_args)
return {}
Fake regional_term function with the appropriate signature.
Fake regional_term function with the appropriate signature.
[ "Fake", "regional_term", "function", "with", "the", "appropriate", "signature", "." ]
def __boundary_term_label(graph, label_image, boundary_term_args): """Fake regional_term function with the appropriate signature.""" # supplying no boundary term contradicts the whole graph cut idea. return {}
[ "def", "__boundary_term_label", "(", "graph", ",", "label_image", ",", "boundary_term_args", ")", ":", "# supplying no boundary term contradicts the whole graph cut idea.", "return", "{", "}" ]
https://github.com/loli/medpy/blob/39131b94f0ab5328ab14a874229320efc2f74d98/medpy/graphcut/generate.py#L311-L314
ni/nidaqmx-python
62fc6b48cbbb330fe1bcc9aedadc86610a1269b6
nidaqmx/_task_modules/export_signals.py
python
ExportSignals.adv_cmplt_event_delay
(self, val)
[]
def adv_cmplt_event_delay(self, val): cfunc = lib_importer.windll.DAQmxSetExportedAdvCmpltEventDelayVal if cfunc.argtypes is None: with cfunc.arglock: if cfunc.argtypes is None: cfunc.argtypes = [ lib_importer.task_handle, ctypes.c_double] error_code = cfunc( self._handle, val) check_for_error(error_code)
[ "def", "adv_cmplt_event_delay", "(", "self", ",", "val", ")", ":", "cfunc", "=", "lib_importer", ".", "windll", ".", "DAQmxSetExportedAdvCmpltEventDelayVal", "if", "cfunc", ".", "argtypes", "is", "None", ":", "with", "cfunc", ".", "arglock", ":", "if", "cfunc"...
https://github.com/ni/nidaqmx-python/blob/62fc6b48cbbb330fe1bcc9aedadc86610a1269b6/nidaqmx/_task_modules/export_signals.py#L47-L57
Antergos/Cnchi
13ac2209da9432d453e0097cf48a107640b563a9
src/widgets/zfs_treeview.py
python
ZFSTreeview.get_num_drives
(self)
return num_drives
Returns number of active drives that will conform the zfs pool
Returns number of active drives that will conform the zfs pool
[ "Returns", "number", "of", "active", "drives", "that", "will", "conform", "the", "zfs", "pool" ]
def get_num_drives(self): """ Returns number of active drives that will conform the zfs pool """ num_drives = 0 for row in self.device_list_store: if row[ZFSTreeview.COL_USE_ACTIVE]: num_drives += 1 return num_drives
[ "def", "get_num_drives", "(", "self", ")", ":", "num_drives", "=", "0", "for", "row", "in", "self", ".", "device_list_store", ":", "if", "row", "[", "ZFSTreeview", ".", "COL_USE_ACTIVE", "]", ":", "num_drives", "+=", "1", "return", "num_drives" ]
https://github.com/Antergos/Cnchi/blob/13ac2209da9432d453e0097cf48a107640b563a9/src/widgets/zfs_treeview.py#L175-L181
IJDykeman/wangTiles
7c1ee2095ebdf7f72bce07d94c6484915d5cae8b
experimental_code/tiles_3d/venv/lib/python2.7/site-packages/setuptools/py26compat.py
python
strip_fragment
(url)
return url
In `Python 8280 <http://bugs.python.org/issue8280>`_, Python 2.7 and later was patched to disregard the fragment when making URL requests. Do the same for Python 2.6 and earlier.
In `Python 8280 <http://bugs.python.org/issue8280>`_, Python 2.7 and later was patched to disregard the fragment when making URL requests. Do the same for Python 2.6 and earlier.
[ "In", "Python", "8280", "<http", ":", "//", "bugs", ".", "python", ".", "org", "/", "issue8280", ">", "_", "Python", "2", ".", "7", "and", "later", "was", "patched", "to", "disregard", "the", "fragment", "when", "making", "URL", "requests", ".", "Do", ...
def strip_fragment(url): """ In `Python 8280 <http://bugs.python.org/issue8280>`_, Python 2.7 and later was patched to disregard the fragment when making URL requests. Do the same for Python 2.6 and earlier. """ url, fragment = splittag(url) return url
[ "def", "strip_fragment", "(", "url", ")", ":", "url", ",", "fragment", "=", "splittag", "(", "url", ")", "return", "url" ]
https://github.com/IJDykeman/wangTiles/blob/7c1ee2095ebdf7f72bce07d94c6484915d5cae8b/experimental_code/tiles_3d/venv/lib/python2.7/site-packages/setuptools/py26compat.py#L9-L16
openedx/edx-platform
68dd185a0ab45862a2a61e0f803d7e03d2be71b5
lms/djangoapps/teams/api.py
python
is_instructor_managed_team
(team)
return is_instructor_managed_topic(team.course_id, team.topic_id)
Return true if the team is managed by instructors.
Return true if the team is managed by instructors.
[ "Return", "true", "if", "the", "team", "is", "managed", "by", "instructors", "." ]
def is_instructor_managed_team(team): """ Return true if the team is managed by instructors. """ if not team: return False return is_instructor_managed_topic(team.course_id, team.topic_id)
[ "def", "is_instructor_managed_team", "(", "team", ")", ":", "if", "not", "team", ":", "return", "False", "return", "is_instructor_managed_topic", "(", "team", ".", "course_id", ",", "team", ".", "topic_id", ")" ]
https://github.com/openedx/edx-platform/blob/68dd185a0ab45862a2a61e0f803d7e03d2be71b5/lms/djangoapps/teams/api.py#L96-L102
caktux/pytrader
b45b216dab3db78d6028d85e9a6f80419c22cea0
api.py
python
Api._on_order_not_found
(self, msg)
this means we have sent order/cancel with non-existing oid
this means we have sent order/cancel with non-existing oid
[ "this", "means", "we", "have", "sent", "order", "/", "cancel", "with", "non", "-", "existing", "oid" ]
def _on_order_not_found(self, msg): """this means we have sent order/cancel with non-existing oid""" parts = msg["id"].split(":") oid = parts[1] self.debug("### got 'Order not found' for", oid) # we are now going to fake a user_order message (the one we # obviously missed earlier) that will have the effect of # removing the order cleanly. fakemsg = {"user_order": {"oid": oid, "reason": "requested"}} self._on_op_private_user_order(fakemsg)
[ "def", "_on_order_not_found", "(", "self", ",", "msg", ")", ":", "parts", "=", "msg", "[", "\"id\"", "]", ".", "split", "(", "\":\"", ")", "oid", "=", "parts", "[", "1", "]", "self", ".", "debug", "(", "\"### got 'Order not found' for\"", ",", "oid", "...
https://github.com/caktux/pytrader/blob/b45b216dab3db78d6028d85e9a6f80419c22cea0/api.py#L1155-L1164
microsoft/unilm
65f15af2a307ebb64cfb25adf54375b002e6fe8d
xtune/src/transformers/tokenization_gpt2.py
python
GPT2Tokenizer.convert_tokens_to_string
(self, tokens)
return text
Converts a sequence of tokens (string) in a single string.
Converts a sequence of tokens (string) in a single string.
[ "Converts", "a", "sequence", "of", "tokens", "(", "string", ")", "in", "a", "single", "string", "." ]
def convert_tokens_to_string(self, tokens): """ Converts a sequence of tokens (string) in a single string. """ text = "".join(tokens) text = bytearray([self.byte_decoder[c] for c in text]).decode("utf-8", errors=self.errors) return text
[ "def", "convert_tokens_to_string", "(", "self", ",", "tokens", ")", ":", "text", "=", "\"\"", ".", "join", "(", "tokens", ")", "text", "=", "bytearray", "(", "[", "self", ".", "byte_decoder", "[", "c", "]", "for", "c", "in", "text", "]", ")", ".", ...
https://github.com/microsoft/unilm/blob/65f15af2a307ebb64cfb25adf54375b002e6fe8d/xtune/src/transformers/tokenization_gpt2.py#L239-L243
oracle/graalpython
577e02da9755d916056184ec441c26e00b70145c
graalpython/lib-python/3/encodings/cp875.py
python
Codec.decode
(self,input,errors='strict')
return codecs.charmap_decode(input,errors,decoding_table)
[]
def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table)
[ "def", "decode", "(", "self", ",", "input", ",", "errors", "=", "'strict'", ")", ":", "return", "codecs", ".", "charmap_decode", "(", "input", ",", "errors", ",", "decoding_table", ")" ]
https://github.com/oracle/graalpython/blob/577e02da9755d916056184ec441c26e00b70145c/graalpython/lib-python/3/encodings/cp875.py#L14-L15
barseghyanartur/django-fobi
a998feae007d7fe3637429a80e42952ec7cda79f
src/fobi/base.py
python
get_registered_form_callbacks
(stage=None)
return form_callback_registry.get_callbacks(stage=stage)
Get registered form callbacks for the stage given.
Get registered form callbacks for the stage given.
[ "Get", "registered", "form", "callbacks", "for", "the", "stage", "given", "." ]
def get_registered_form_callbacks(stage=None): """Get registered form callbacks for the stage given.""" return form_callback_registry.get_callbacks(stage=stage)
[ "def", "get_registered_form_callbacks", "(", "stage", "=", "None", ")", ":", "return", "form_callback_registry", ".", "get_callbacks", "(", "stage", "=", "stage", ")" ]
https://github.com/barseghyanartur/django-fobi/blob/a998feae007d7fe3637429a80e42952ec7cda79f/src/fobi/base.py#L3527-L3529
DonnchaC/shadowbrokers-exploits
42d8265db860b634717da4faa668b2670457cf7e
windows/fuzzbunch/pyreadline/modes/notemacs.py
python
NotEmacsMode.beginning_of_line
(self, e)
Move to the start of the current line.
Move to the start of the current line.
[ "Move", "to", "the", "start", "of", "the", "current", "line", "." ]
def beginning_of_line(self, e): # (C-a) '''Move to the start of the current line. ''' self.l_buffer.beginning_of_line()
[ "def", "beginning_of_line", "(", "self", ",", "e", ")", ":", "# (C-a)", "self", ".", "l_buffer", ".", "beginning_of_line", "(", ")" ]
https://github.com/DonnchaC/shadowbrokers-exploits/blob/42d8265db860b634717da4faa668b2670457cf7e/windows/fuzzbunch/pyreadline/modes/notemacs.py#L93-L95
openid/python-openid
afa6adacbe1a41d8f614c8bce2264dfbe9e76489
openid/extensions/draft/pape2.py
python
Request.parseExtensionArgs
(self, args)
Set the state of this request to be that expressed in these PAPE arguments @param args: The PAPE arguments without a namespace @rtype: None @raises ValueError: When the max_auth_age is not parseable as an integer
Set the state of this request to be that expressed in these PAPE arguments
[ "Set", "the", "state", "of", "this", "request", "to", "be", "that", "expressed", "in", "these", "PAPE", "arguments" ]
def parseExtensionArgs(self, args): """Set the state of this request to be that expressed in these PAPE arguments @param args: The PAPE arguments without a namespace @rtype: None @raises ValueError: When the max_auth_age is not parseable as an integer """ # preferred_auth_policies is a space-separated list of policy URIs self.preferred_auth_policies = [] policies_str = args.get('preferred_auth_policies') if policies_str: for uri in policies_str.split(' '): if uri not in self.preferred_auth_policies: self.preferred_auth_policies.append(uri) # max_auth_age is base-10 integer number of seconds max_auth_age_str = args.get('max_auth_age') self.max_auth_age = None if max_auth_age_str: try: self.max_auth_age = int(max_auth_age_str) except ValueError: pass
[ "def", "parseExtensionArgs", "(", "self", ",", "args", ")", ":", "# preferred_auth_policies is a space-separated list of policy URIs", "self", ".", "preferred_auth_policies", "=", "[", "]", "policies_str", "=", "args", ".", "get", "(", "'preferred_auth_policies'", ")", ...
https://github.com/openid/python-openid/blob/afa6adacbe1a41d8f614c8bce2264dfbe9e76489/openid/extensions/draft/pape2.py#L110-L139
openhatch/oh-mainline
ce29352a034e1223141dcc2f317030bbc3359a51
vendor/packages/Django/django/db/backends/mysql/base.py
python
DatabaseWrapper.check_constraints
(self, table_names=None)
Checks each table name in `table_names` for rows with invalid foreign key references. This method is intended to be used in conjunction with `disable_constraint_checking()` and `enable_constraint_checking()`, to determine if rows with invalid references were entered while constraint checks were off. Raises an IntegrityError on the first invalid foreign key reference encountered (if any) and provides detailed information about the invalid reference in the error message. Backends can override this method if they can more directly apply constraint checking (e.g. via "SET CONSTRAINTS ALL IMMEDIATE")
Checks each table name in `table_names` for rows with invalid foreign key references. This method is intended to be used in conjunction with `disable_constraint_checking()` and `enable_constraint_checking()`, to determine if rows with invalid references were entered while constraint checks were off.
[ "Checks", "each", "table", "name", "in", "table_names", "for", "rows", "with", "invalid", "foreign", "key", "references", ".", "This", "method", "is", "intended", "to", "be", "used", "in", "conjunction", "with", "disable_constraint_checking", "()", "and", "enabl...
def check_constraints(self, table_names=None): """ Checks each table name in `table_names` for rows with invalid foreign key references. This method is intended to be used in conjunction with `disable_constraint_checking()` and `enable_constraint_checking()`, to determine if rows with invalid references were entered while constraint checks were off. Raises an IntegrityError on the first invalid foreign key reference encountered (if any) and provides detailed information about the invalid reference in the error message. Backends can override this method if they can more directly apply constraint checking (e.g. via "SET CONSTRAINTS ALL IMMEDIATE") """ cursor = self.cursor() if table_names is None: table_names = self.introspection.table_names(cursor) for table_name in table_names: primary_key_column_name = self.introspection.get_primary_key_column(cursor, table_name) if not primary_key_column_name: continue key_columns = self.introspection.get_key_columns(cursor, table_name) for column_name, referenced_table_name, referenced_column_name in key_columns: cursor.execute(""" SELECT REFERRING.`%s`, REFERRING.`%s` FROM `%s` as REFERRING LEFT JOIN `%s` as REFERRED ON (REFERRING.`%s` = REFERRED.`%s`) WHERE REFERRING.`%s` IS NOT NULL AND REFERRED.`%s` IS NULL""" % (primary_key_column_name, column_name, table_name, referenced_table_name, column_name, referenced_column_name, column_name, referenced_column_name)) for bad_row in cursor.fetchall(): raise utils.IntegrityError("The row in table '%s' with primary key '%s' has an invalid " "foreign key: %s.%s contains a value '%s' that does not have a corresponding value in %s.%s." % (table_name, bad_row[0], table_name, column_name, bad_row[1], referenced_table_name, referenced_column_name))
[ "def", "check_constraints", "(", "self", ",", "table_names", "=", "None", ")", ":", "cursor", "=", "self", ".", "cursor", "(", ")", "if", "table_names", "is", "None", ":", "table_names", "=", "self", ".", "introspection", ".", "table_names", "(", "cursor",...
https://github.com/openhatch/oh-mainline/blob/ce29352a034e1223141dcc2f317030bbc3359a51/vendor/packages/Django/django/db/backends/mysql/base.py#L459-L492
titu1994/progressive-neural-architecture-search
b180b63fe0c79a65400c3f64888257845889ee8f
manager.py
python
NetworkManager.get_rewards
(self, model_fn, actions, display_model_summary=True)
return reward
Creates a subnetwork given the actions predicted by the controller RNN, trains it on the provided dataset, and then returns a reward. # Args: model_fn: a function which accepts one argument, a list of parsed actions, obtained via an inverse mapping from the StateSpace. actions: a list of parsed actions obtained via an inverse mapping from the StateSpace. It is in a specific order as given below: Consider 4 states were added to the StateSpace via the `add_state` method. Then the `actions` array will be of length 4, with the values of those states in the order that they were added. If number of layers is greater than one, then the `actions` array will be of length `4 * number of layers` (in the above scenario). The index from [0:4] will be for layer 0, from [4:8] for layer 1, etc for the number of layers. These action values are for direct use in the construction of models. display_model_summary: Display the child model summary at the end of training. # Returns: a reward for training a model with the given actions
Creates a subnetwork given the actions predicted by the controller RNN, trains it on the provided dataset, and then returns a reward.
[ "Creates", "a", "subnetwork", "given", "the", "actions", "predicted", "by", "the", "controller", "RNN", "trains", "it", "on", "the", "provided", "dataset", "and", "then", "returns", "a", "reward", "." ]
def get_rewards(self, model_fn, actions, display_model_summary=True): ''' Creates a subnetwork given the actions predicted by the controller RNN, trains it on the provided dataset, and then returns a reward. # Args: model_fn: a function which accepts one argument, a list of parsed actions, obtained via an inverse mapping from the StateSpace. actions: a list of parsed actions obtained via an inverse mapping from the StateSpace. It is in a specific order as given below: Consider 4 states were added to the StateSpace via the `add_state` method. Then the `actions` array will be of length 4, with the values of those states in the order that they were added. If number of layers is greater than one, then the `actions` array will be of length `4 * number of layers` (in the above scenario). The index from [0:4] will be for layer 0, from [4:8] for layer 1, etc for the number of layers. These action values are for direct use in the construction of models. display_model_summary: Display the child model summary at the end of training. # Returns: a reward for training a model with the given actions ''' if tf.test.is_gpu_available(): device = '/gpu:0' else: device = '/cpu:0' tf.keras.backend.reset_uids() # generate a submodel given predicted actions with tf.device(device): model = model_fn(actions) # type: Model # build model shapes X_train, y_train, X_val, y_val = self.dataset # generate the dataset for training train_dataset = tf.data.Dataset.from_tensor_slices((X_train, y_train)) train_dataset = train_dataset.apply(tf.data.experimental.shuffle_and_repeat(10000, seed=0)) train_dataset = train_dataset.batch(self.batchsize) train_dataset = train_dataset.apply(tf.data.experimental.prefetch_to_device(device)) # generate the dataset for evaluation val_dataset = tf.data.Dataset.from_tensor_slices((X_val, y_val)) val_dataset = val_dataset.batch(self.batchsize) val_dataset = val_dataset.apply(tf.data.experimental.prefetch_to_device(device)) num_train_batches = X_train.shape[0] // self.batchsize + 1 global_step = tf.train.get_or_create_global_step() lr = tf.train.cosine_decay(self.lr, global_step, decay_steps=num_train_batches * self.epochs, alpha=0.1) # construct the optimizer and saver of the child model optimizer = tf.train.AdamOptimizer(lr) saver = tf.train.Checkpoint(model=model, optimizer=optimizer, global_step=global_step) best_val_acc = 0.0 for epoch in range(self.epochs): # train child model with tqdm.tqdm(train_dataset, desc='Train Epoch (%d / %d): ' % (epoch + 1, self.epochs), total=num_train_batches) as iterator: for i, (x, y) in enumerate(iterator): # get gradients with tf.GradientTape() as tape: preds = model(x, training=True) loss = tf.keras.losses.categorical_crossentropy(y, preds) grad = tape.gradient(loss, model.variables) grad_vars = zip(grad, model.variables) # update weights of the child model optimizer.apply_gradients(grad_vars, global_step) if (i + 1) >= num_train_batches: break print() # evaluate child model acc = tfe.metrics.CategoricalAccuracy() for j, (x, y) in enumerate(val_dataset): preds = model(x, training=False) acc(y, preds) acc = acc.result().numpy() print("Epoch %d: Val accuracy = %0.6f" % (epoch + 1, acc)) # if acc improved, save the weights if acc > best_val_acc: print("Val accuracy improved from %0.6f to %0.6f. Saving weights !" % ( best_val_acc, acc)) best_val_acc = acc saver.save('temp_weights/temp_network') print() # load best weights of the child model path = tf.train.latest_checkpoint('temp_weights/') saver.restore(path) # display the structure of the child model if display_model_summary: model.summary() # evaluate the best weights of the child model acc = tfe.metrics.CategoricalAccuracy() for j, (x, y) in enumerate(val_dataset): preds = model(x, training=False) acc(y, preds) acc = acc.result().numpy() # compute the reward (validation accuracy) reward = acc print() print("Manager: Accuracy = ", reward) # clean up resources and GPU memory del model del optimizer del global_step return reward
[ "def", "get_rewards", "(", "self", ",", "model_fn", ",", "actions", ",", "display_model_summary", "=", "True", ")", ":", "if", "tf", ".", "test", ".", "is_gpu_available", "(", ")", ":", "device", "=", "'/gpu:0'", "else", ":", "device", "=", "'/cpu:0'", "...
https://github.com/titu1994/progressive-neural-architecture-search/blob/b180b63fe0c79a65400c3f64888257845889ee8f/manager.py#L39-L174
ctxis/CAPE
dae9fa6a254ecdbabeb7eb0d2389fa63722c1e82
lib/cuckoo/common/abstracts.py
python
Machinery.set_status
(self, label, status)
Set status for a virtual machine. @param label: virtual machine label @param status: new virtual machine status
Set status for a virtual machine.
[ "Set", "status", "for", "a", "virtual", "machine", "." ]
def set_status(self, label, status): """Set status for a virtual machine. @param label: virtual machine label @param status: new virtual machine status """ self.db.set_machine_status(label, status)
[ "def", "set_status", "(", "self", ",", "label", ",", "status", ")", ":", "self", ".", "db", ".", "set_machine_status", "(", "label", ",", "status", ")" ]
https://github.com/ctxis/CAPE/blob/dae9fa6a254ecdbabeb7eb0d2389fa63722c1e82/lib/cuckoo/common/abstracts.py#L288-L293
biocore/qiime
76d633c0389671e93febbe1338b5ded658eba31f
qiime/workflow/downstream.py
python
run_alpha_rarefaction
(otu_table_fp, mapping_fp, output_dir, command_handler, params, qiime_config, tree_fp=None, num_steps=10, parallel=False, logger=None, min_rare_depth=10, max_rare_depth=None, suppress_md5=False, status_update_callback=print_to_stdout, plot_stderr_and_stddev=False, retain_intermediate_files=True)
Run the data preparation steps of Qiime The steps performed by this function are: 1) Generate rarefied OTU tables; 2) Compute alpha diversity metrics for each rarefied OTU table; 3) Collate alpha diversity results; 4) Generate alpha rarefaction plots.
Run the data preparation steps of Qiime
[ "Run", "the", "data", "preparation", "steps", "of", "Qiime" ]
def run_alpha_rarefaction(otu_table_fp, mapping_fp, output_dir, command_handler, params, qiime_config, tree_fp=None, num_steps=10, parallel=False, logger=None, min_rare_depth=10, max_rare_depth=None, suppress_md5=False, status_update_callback=print_to_stdout, plot_stderr_and_stddev=False, retain_intermediate_files=True): """ Run the data preparation steps of Qiime The steps performed by this function are: 1) Generate rarefied OTU tables; 2) Compute alpha diversity metrics for each rarefied OTU table; 3) Collate alpha diversity results; 4) Generate alpha rarefaction plots. """ # Prepare some variables for the later steps otu_table_dir, otu_table_filename = split(otu_table_fp) otu_table_basename, otu_table_ext = splitext(otu_table_filename) create_dir(output_dir) commands = [] if logger is None: logger = WorkflowLogger(generate_log_fp(output_dir), params=params, qiime_config=qiime_config) close_logger_on_success = True else: close_logger_on_success = False if not suppress_md5: log_input_md5s(logger, [otu_table_fp, mapping_fp, tree_fp]) if max_rare_depth is None: min_count, max_count, median_count, mean_count, counts_per_sample =\ compute_counts_per_sample_stats( load_table(otu_table_fp)) max_rare_depth = median_count step = int((max_rare_depth - min_rare_depth) / num_steps) or 1 max_rare_depth = int(max_rare_depth) rarefaction_dir = '%s/rarefaction/' % output_dir create_dir(rarefaction_dir) try: params_str = get_params_str(params['multiple_rarefactions']) except KeyError: params_str = '' if parallel: params_str += ' %s' % get_params_str(params['parallel']) # Build the rarefaction command rarefaction_cmd = \ 'parallel_multiple_rarefactions.py -T -i %s -m %s -x %s -s %s -o %s %s' %\ (otu_table_fp, min_rare_depth, max_rare_depth, step, rarefaction_dir, params_str) else: # Build the rarefaction command rarefaction_cmd = \ 'multiple_rarefactions.py -i %s -m %s -x %s -s %s -o %s %s' %\ (otu_table_fp, min_rare_depth, max_rare_depth, step, rarefaction_dir, params_str) commands.append([('Alpha rarefaction', rarefaction_cmd)]) # Prep the alpha diversity command alpha_diversity_dir = '%s/alpha_div/' % output_dir create_dir(alpha_diversity_dir) try: params_str = get_params_str(params['alpha_diversity']) except KeyError: params_str = '' if tree_fp: params_str += ' -t %s' % tree_fp if parallel: params_str += ' %s' % get_params_str(params['parallel']) # Build the alpha diversity command alpha_diversity_cmd = \ "parallel_alpha_diversity.py -T -i %s -o %s %s" %\ (rarefaction_dir, alpha_diversity_dir, params_str) else: # Build the alpha diversity command alpha_diversity_cmd = \ "alpha_diversity.py -i %s -o %s %s" %\ (rarefaction_dir, alpha_diversity_dir, params_str) commands.append( [('Alpha diversity on rarefied OTU tables', alpha_diversity_cmd)]) # Prep the alpha diversity collation command alpha_collated_dir = '%s/alpha_div_collated/' % output_dir create_dir(alpha_collated_dir) try: params_str = get_params_str(params['collate_alpha']) except KeyError: params_str = '' # Build the alpha diversity collation command alpha_collated_cmd = 'collate_alpha.py -i %s -o %s %s' %\ (alpha_diversity_dir, alpha_collated_dir, params_str) commands.append([('Collate alpha', alpha_collated_cmd)]) if not retain_intermediate_files: commands.append([('Removing intermediate files', 'rm -r %s %s' % (rarefaction_dir, alpha_diversity_dir))]) else: commands.append([('Skipping removal of intermediate files.', '')]) # Prep the make rarefaction plot command(s) try: params_str = get_params_str(params['make_rarefaction_plots']) except KeyError: params_str = '' if 'std_type' in params['make_rarefaction_plots'] or not plot_stderr_and_stddev: rarefaction_plot_dir = '%s/alpha_rarefaction_plots/' % output_dir create_dir(rarefaction_plot_dir) # Build the make rarefaction plot command(s) # for metric in alpha_diversity_metrics: make_rarefaction_plot_cmd =\ 'make_rarefaction_plots.py -i %s -m %s -o %s %s' %\ (alpha_collated_dir, mapping_fp, rarefaction_plot_dir, params_str) commands.append( [('Rarefaction plot: %s' % 'All metrics', make_rarefaction_plot_cmd)]) else: rarefaction_plot_dir_stddev = '%s/alpha_rarefaction_plots_stddev/' % output_dir rarefaction_plot_dir_stderr = '%s/alpha_rarefaction_plots_stderr/' % output_dir create_dir(rarefaction_plot_dir_stddev) create_dir(rarefaction_plot_dir_stderr) # Build the make rarefaction plot command(s) # for metric in alpha_diversity_metrics: make_rarefaction_plot_cmd =\ 'make_rarefaction_plots.py -i %s -m %s -o %s %s --std_type stddev' %\ (alpha_collated_dir, mapping_fp, rarefaction_plot_dir_stddev, params_str) commands.append( [('Rarefaction plot: %s' % 'All metrics', make_rarefaction_plot_cmd)]) make_rarefaction_plot_cmd =\ 'make_rarefaction_plots.py -i %s -m %s -o %s %s --std_type stderr' %\ (alpha_collated_dir, mapping_fp, rarefaction_plot_dir_stderr, params_str) commands.append( [('Rarefaction plot: %s' % 'All metrics', make_rarefaction_plot_cmd)]) # Call the command handler on the list of commands command_handler(commands, status_update_callback, logger=logger, close_logger_on_success=close_logger_on_success)
[ "def", "run_alpha_rarefaction", "(", "otu_table_fp", ",", "mapping_fp", ",", "output_dir", ",", "command_handler", ",", "params", ",", "qiime_config", ",", "tree_fp", "=", "None", ",", "num_steps", "=", "10", ",", "parallel", "=", "False", ",", "logger", "=", ...
https://github.com/biocore/qiime/blob/76d633c0389671e93febbe1338b5ded658eba31f/qiime/workflow/downstream.py#L188-L342
cloudera/hue
23f02102d4547c17c32bd5ea0eb24e9eadd657a4
desktop/core/ext-py/docutils-0.14/docutils/utils/error_reporting.py
python
ErrorOutput.write
(self, data)
Write `data` to self.stream. Ignore, if self.stream is False. `data` can be a `string`, `unicode`, or `Exception` instance.
Write `data` to self.stream. Ignore, if self.stream is False.
[ "Write", "data", "to", "self", ".", "stream", ".", "Ignore", "if", "self", ".", "stream", "is", "False", "." ]
def write(self, data): """ Write `data` to self.stream. Ignore, if self.stream is False. `data` can be a `string`, `unicode`, or `Exception` instance. """ if self.stream is False: return if isinstance(data, Exception): data = unicode(SafeString(data, self.encoding, self.encoding_errors, self.decoding_errors)) try: self.stream.write(data) except UnicodeEncodeError: self.stream.write(data.encode(self.encoding, self.encoding_errors)) except TypeError: if isinstance(data, unicode): # passed stream may expect bytes self.stream.write(data.encode(self.encoding, self.encoding_errors)) return if self.stream in (sys.stderr, sys.stdout): self.stream.buffer.write(data) # write bytes to raw stream else: self.stream.write(unicode(data, self.encoding, self.decoding_errors))
[ "def", "write", "(", "self", ",", "data", ")", ":", "if", "self", ".", "stream", "is", "False", ":", "return", "if", "isinstance", "(", "data", ",", "Exception", ")", ":", "data", "=", "unicode", "(", "SafeString", "(", "data", ",", "self", ".", "e...
https://github.com/cloudera/hue/blob/23f02102d4547c17c32bd5ea0eb24e9eadd657a4/desktop/core/ext-py/docutils-0.14/docutils/utils/error_reporting.py#L187-L211
JiYou/openstack
8607dd488bde0905044b303eb6e52bdea6806923
packages/source/glance/glance/openstack/common/notifier/api.py
python
notify
(context, publisher_id, event_type, priority, payload)
Sends a notification using the specified driver :param publisher_id: the source worker_type.host of the message :param event_type: the literal type of event (ex. Instance Creation) :param priority: patterned after the enumeration of Python logging levels in the set (DEBUG, WARN, INFO, ERROR, CRITICAL) :param payload: A python dictionary of attributes Outgoing message format includes the above parameters, and appends the following: message_id a UUID representing the id for this notification timestamp the GMT timestamp the notification was sent at The composite message will be constructed as a dictionary of the above attributes, which will then be sent via the transport mechanism defined by the driver. Message example:: {'message_id': str(uuid.uuid4()), 'publisher_id': 'compute.host1', 'timestamp': timeutils.utcnow(), 'priority': 'WARN', 'event_type': 'compute.create_instance', 'payload': {'instance_id': 12, ... }}
Sends a notification using the specified driver
[ "Sends", "a", "notification", "using", "the", "specified", "driver" ]
def notify(context, publisher_id, event_type, priority, payload): """Sends a notification using the specified driver :param publisher_id: the source worker_type.host of the message :param event_type: the literal type of event (ex. Instance Creation) :param priority: patterned after the enumeration of Python logging levels in the set (DEBUG, WARN, INFO, ERROR, CRITICAL) :param payload: A python dictionary of attributes Outgoing message format includes the above parameters, and appends the following: message_id a UUID representing the id for this notification timestamp the GMT timestamp the notification was sent at The composite message will be constructed as a dictionary of the above attributes, which will then be sent via the transport mechanism defined by the driver. Message example:: {'message_id': str(uuid.uuid4()), 'publisher_id': 'compute.host1', 'timestamp': timeutils.utcnow(), 'priority': 'WARN', 'event_type': 'compute.create_instance', 'payload': {'instance_id': 12, ... }} """ if priority not in log_levels: raise BadPriorityException( _('%s not in valid priorities') % priority) # Ensure everything is JSON serializable. payload = jsonutils.to_primitive(payload, convert_instances=True) msg = dict(message_id=str(uuid.uuid4()), publisher_id=publisher_id, event_type=event_type, priority=priority, payload=payload, timestamp=str(timeutils.utcnow())) for driver in _get_drivers(): try: driver.notify(context, msg) except Exception as e: LOG.exception(_("Problem '%(e)s' attempting to " "send to notification system. " "Payload=%(payload)s") % dict(e=e, payload=payload))
[ "def", "notify", "(", "context", ",", "publisher_id", ",", "event_type", ",", "priority", ",", "payload", ")", ":", "if", "priority", "not", "in", "log_levels", ":", "raise", "BadPriorityException", "(", "_", "(", "'%s not in valid priorities'", ")", "%", "pri...
https://github.com/JiYou/openstack/blob/8607dd488bde0905044b303eb6e52bdea6806923/packages/source/glance/glance/openstack/common/notifier/api.py#L92-L145
baidu/knowledge-driven-dialogue
ba85518a1ac2a57988188fc5f2b8fe42e1facf64
generative_pt/source/utils/metrics.py
python
EmbeddingMetrics.__init__
(self, field)
[]
def __init__(self, field): self.field = field assert field.embeddings is not None self.embeddings = np.array(field.embeddings)
[ "def", "__init__", "(", "self", ",", "field", ")", ":", "self", ".", "field", "=", "field", "assert", "field", ".", "embeddings", "is", "not", "None", "self", ".", "embeddings", "=", "np", ".", "array", "(", "field", ".", "embeddings", ")" ]
https://github.com/baidu/knowledge-driven-dialogue/blob/ba85518a1ac2a57988188fc5f2b8fe42e1facf64/generative_pt/source/utils/metrics.py#L132-L135
DataIntegrationAlliance/data_integration_celery
6775292030213dd1fa33a1ec0f542d5d2d2e612a
tasks/wind/index.py
python
import_index_info
(wind_codes, chain_param=None)
导入指数信息 :param wind_codes: :return:
导入指数信息 :param wind_codes: :return:
[ "导入指数信息", ":", "param", "wind_codes", ":", ":", "return", ":" ]
def import_index_info(wind_codes, chain_param=None): """ 导入指数信息 :param wind_codes: :return: """ table_name = 'wind_index_info' has_table = engine_md.has_table(table_name) col_name_param_list = [ ('LAUNCHDATE', Date), ('BASEDATE', Date), ('BASEVALUE', DOUBLE), ('COUNTRY', String(20)), ('CRM_ISSUER', String(20)), ('SEC_NAME', String(20)), ] col_name_param = ",".join([key.lower() for key, _ in col_name_param_list]) col_name_param_dic = {col_name.upper(): col_name.lower() for col_name, _ in col_name_param_list} # 设置dtype类型 dtype = {key.lower(): val for key, val in col_name_param_list} dtype['wind_code'] = String(20) info_df = invoker.wss(wind_codes, col_name_param) if info_df is None or info_df.shape[0] == 0: logger.warning("没有数据可导入") return info_df.rename(columns=col_name_param_dic, inplace=True) info_df.index.rename("wind_code", inplace=True) info_df.reset_index(inplace=True) bunch_insert_on_duplicate_update(info_df, table_name, engine_md, dtype=dtype) # info_df.to_sql(table_name, engine_md, if_exists='append', index=True, # dtype={ # 'wind_code': String(20), # 'null': Date, # 'basedate': Date, # 'basevalue': DOUBLE, # 'country': String(20), # 'crm_issuer': String(20), # 'sec_name': String(20), # }) logger.info('%d 条指数信息导入成功\n%s', info_df.shape[0], info_df) if not has_table and engine_md.has_table(table_name): alter_table_2_myisam(engine_md, [table_name]) build_primary_key([table_name]) # 更新 code_mapping 表 update_from_info_table(table_name)
[ "def", "import_index_info", "(", "wind_codes", ",", "chain_param", "=", "None", ")", ":", "table_name", "=", "'wind_index_info'", "has_table", "=", "engine_md", ".", "has_table", "(", "table_name", ")", "col_name_param_list", "=", "[", "(", "'LAUNCHDATE'", ",", ...
https://github.com/DataIntegrationAlliance/data_integration_celery/blob/6775292030213dd1fa33a1ec0f542d5d2d2e612a/tasks/wind/index.py#L145-L191
pyg-team/pytorch_geometric
b920e9a3a64e22c8356be55301c88444ff051cae
torch_geometric/datasets/ogb_mag.py
python
OGB_MAG.download
(self)
[]
def download(self): if not all([osp.exists(f) for f in self.raw_paths[:5]]): path = download_url(self.url, self.raw_dir) extract_zip(path, self.raw_dir) for file_name in ['node-feat', 'node-label', 'relations']: path = osp.join(self.raw_dir, 'mag', 'raw', file_name) shutil.move(path, self.raw_dir) path = osp.join(self.raw_dir, 'mag', 'split') shutil.move(path, self.raw_dir) path = osp.join(self.raw_dir, 'mag', 'raw', 'num-node-dict.csv.gz') shutil.move(path, self.raw_dir) shutil.rmtree(osp.join(self.raw_dir, 'mag')) os.remove(osp.join(self.raw_dir, 'mag.zip')) if self.preprocess is not None: path = download_url(self.urls[self.preprocess], self.raw_dir) extract_zip(path, self.raw_dir) os.remove(path)
[ "def", "download", "(", "self", ")", ":", "if", "not", "all", "(", "[", "osp", ".", "exists", "(", "f", ")", "for", "f", "in", "self", ".", "raw_paths", "[", ":", "5", "]", "]", ")", ":", "path", "=", "download_url", "(", "self", ".", "url", ...
https://github.com/pyg-team/pytorch_geometric/blob/b920e9a3a64e22c8356be55301c88444ff051cae/torch_geometric/datasets/ogb_mag.py#L92-L108
fortharris/Pcode
147962d160a834c219e12cb456abc130826468e4
rope/refactor/patchedast.py
python
_PatchingASTWalker._Assert
(self, node)
[]
def _Assert(self, node): children = ['assert', node.test] if node.msg: children.append(',') children.append(node.msg) self._handle(node, children)
[ "def", "_Assert", "(", "self", ",", "node", ")", ":", "children", "=", "[", "'assert'", ",", "node", ".", "test", "]", "if", "node", ".", "msg", ":", "children", ".", "append", "(", "','", ")", "children", ".", "append", "(", "node", ".", "msg", ...
https://github.com/fortharris/Pcode/blob/147962d160a834c219e12cb456abc130826468e4/rope/refactor/patchedast.py#L229-L234
JetBrains/python-skeletons
95ad24b666e475998e5d1cc02ed53a2188036167
os/__init__.py
python
execle
(path, *args)
Execute a new program, replacing the current process. :type path: bytes | unicode :rtype: None
Execute a new program, replacing the current process.
[ "Execute", "a", "new", "program", "replacing", "the", "current", "process", "." ]
def execle(path, *args): """Execute a new program, replacing the current process. :type path: bytes | unicode :rtype: None """ pass
[ "def", "execle", "(", "path", ",", "*", "args", ")", ":", "pass" ]
https://github.com/JetBrains/python-skeletons/blob/95ad24b666e475998e5d1cc02ed53a2188036167/os/__init__.py#L1005-L1011
joerick/pyinstrument
d3c45164a385021f366c1081baec18a1a226a573
metrics/multi_overhead.py
python
time_base
(function, repeats)
return timer.repeat(number=repeats)
[]
def time_base(function, repeats): timer = Timer(stmt=function) return timer.repeat(number=repeats)
[ "def", "time_base", "(", "function", ",", "repeats", ")", ":", "timer", "=", "Timer", "(", "stmt", "=", "function", ")", "return", "timer", ".", "repeat", "(", "number", "=", "repeats", ")" ]
https://github.com/joerick/pyinstrument/blob/d3c45164a385021f366c1081baec18a1a226a573/metrics/multi_overhead.py#L40-L42
tdamdouni/Pythonista
3e082d53b6b9b501a3c8cf3251a8ad4c8be9c2ad
installer/pexif.py
python
IfdData.isifd
(self, other)
return issubclass(other.__class__, IfdData)
Return true if other is an IFD
Return true if other is an IFD
[ "Return", "true", "if", "other", "is", "an", "IFD" ]
def isifd(self, other): """Return true if other is an IFD""" return issubclass(other.__class__, IfdData)
[ "def", "isifd", "(", "self", ",", "other", ")", ":", "return", "issubclass", "(", "other", ".", "__class__", ",", "IfdData", ")" ]
https://github.com/tdamdouni/Pythonista/blob/3e082d53b6b9b501a3c8cf3251a8ad4c8be9c2ad/installer/pexif.py#L471-L473
h2oai/h2o4gpu
aaf7795d3c3be430129eacfd99d598da0cc838e7
src/interface_py/h2o4gpu/solvers/truncated_svd.py
python
TruncatedSVDH2O.transform
(self, X)
return X_new
Perform dimensionality reduction on X. :param X : {array-like, sparse matrix}, shape (n_samples, n_features) Training data. :returns X_new : array, shape (n_samples, n_components) Reduced version of X. This will always be a dense array.
Perform dimensionality reduction on X.
[ "Perform", "dimensionality", "reduction", "on", "X", "." ]
def transform(self, X): """Perform dimensionality reduction on X. :param X : {array-like, sparse matrix}, shape (n_samples, n_features) Training data. :returns X_new : array, shape (n_samples, n_components) Reduced version of X. This will always be a dense array. """ fit = self.fit(X) X_new = fit.U * fit.singular_values_ return X_new
[ "def", "transform", "(", "self", ",", "X", ")", ":", "fit", "=", "self", ".", "fit", "(", "X", ")", "X_new", "=", "fit", ".", "U", "*", "fit", ".", "singular_values_", "return", "X_new" ]
https://github.com/h2oai/h2o4gpu/blob/aaf7795d3c3be430129eacfd99d598da0cc838e7/src/interface_py/h2o4gpu/solvers/truncated_svd.py#L158-L171
biopython/biopython
2dd97e71762af7b046d7f7f8a4f1e38db6b06c86
Bio/HMM/MarkovModel.py
python
HiddenMarkovModel.get_blank_transitions
(self)
return self._transition_pseudo
Get the default transitions for the model. Returns a dictionary of all of the default transitions between any two letters in the sequence alphabet. The dictionary is structured with keys as (letter1, letter2) and values as the starting number of transitions.
Get the default transitions for the model.
[ "Get", "the", "default", "transitions", "for", "the", "model", "." ]
def get_blank_transitions(self): """Get the default transitions for the model. Returns a dictionary of all of the default transitions between any two letters in the sequence alphabet. The dictionary is structured with keys as (letter1, letter2) and values as the starting number of transitions. """ return self._transition_pseudo
[ "def", "get_blank_transitions", "(", "self", ")", ":", "return", "self", ".", "_transition_pseudo" ]
https://github.com/biopython/biopython/blob/2dd97e71762af7b046d7f7f8a4f1e38db6b06c86/Bio/HMM/MarkovModel.py#L509-L517
project-alice-assistant/ProjectAlice
9e0ba019643bdae0a5535c9fa4180739231dc361
core/base/SkillManager.py
python
SkillManager.getSkillRepository
(self, skillName: str, directory: str = None)
Returns a Git object for the given skill :param skillName: :param directory: where to look for that skill, if not standard directory :return:
Returns a Git object for the given skill :param skillName: :param directory: where to look for that skill, if not standard directory :return:
[ "Returns", "a", "Git", "object", "for", "the", "given", "skill", ":", "param", "skillName", ":", ":", "param", "directory", ":", "where", "to", "look", "for", "that", "skill", "if", "not", "standard", "directory", ":", "return", ":" ]
def getSkillRepository(self, skillName: str, directory: str = None) -> Optional[Repository]: """ Returns a Git object for the given skill :param skillName: :param directory: where to look for that skill, if not standard directory :return: """ if not directory: directory = self.getSkillDirectory(skillName=skillName) try: return Repository(directory=directory) except: raise
[ "def", "getSkillRepository", "(", "self", ",", "skillName", ":", "str", ",", "directory", ":", "str", "=", "None", ")", "->", "Optional", "[", "Repository", "]", ":", "if", "not", "directory", ":", "directory", "=", "self", ".", "getSkillDirectory", "(", ...
https://github.com/project-alice-assistant/ProjectAlice/blob/9e0ba019643bdae0a5535c9fa4180739231dc361/core/base/SkillManager.py#L393-L407
tdamdouni/Pythonista
3e082d53b6b9b501a3c8cf3251a8ad4c8be9c2ad
weather/WeatherAnywhereScene-coomlata.py
python
SceneViewer.alerts
(self, sender)
Kill scene to cut memory overhead, textview then loads much faster into ui view. Note too that whene textview is loaded via .present() without killing the scene, the scene will lock up after closing the textview window.
Kill scene to cut memory overhead, textview then loads much faster into ui view. Note too that whene textview is loaded via .present() without killing the scene, the scene will lock up after closing the textview window.
[ "Kill", "scene", "to", "cut", "memory", "overhead", "textview", "then", "loads", "much", "faster", "into", "ui", "view", ".", "Note", "too", "that", "whene", "textview", "is", "loaded", "via", ".", "present", "()", "without", "killing", "the", "scene", "th...
def alerts(self, sender): # Retrieve alerts alerts = wa.get_alerts(json_w, json_f) ''' Kill scene to cut memory overhead, textview then loads much faster into ui view. Note too that whene textview is loaded via .present() without killing the scene, the scene will lock up after closing the textview window. ''' self.remove_subview(self.scene_view) tv = ui.TextView() #w, h = ui.get_screen_size() #tv.frame = (0, 20, w, h / 1.2) tv.frame = self.bounds tv.border_color='grey' tv.border_width = 3 tv.background_color = ('white') tv.text = alerts tv.editable = False tv.selectable = False if py_ver == '2' and is_P6: tv.font = ('<system>', 12) else: tv.font = ('<system>', 9) self.closebutton(tv) self.add_subview(tv)
[ "def", "alerts", "(", "self", ",", "sender", ")", ":", "# Retrieve alerts", "alerts", "=", "wa", ".", "get_alerts", "(", "json_w", ",", "json_f", ")", "self", ".", "remove_subview", "(", "self", ".", "scene_view", ")", "tv", "=", "ui", ".", "TextView", ...
https://github.com/tdamdouni/Pythonista/blob/3e082d53b6b9b501a3c8cf3251a8ad4c8be9c2ad/weather/WeatherAnywhereScene-coomlata.py#L431-L455
jacoxu/encoder_decoder
6829c3bc42105aedfd1b8a81c81be19df4326c0a
keras/old_models.py
python
Model.to_json
(self, **kwargs)
return json.dumps(config, default=get_json_type, **kwargs)
Return a JSON string containing the model configuration. To load a model from a JSON save file, use `keras.models.from_json(json_string, custom_objects={})`.
Return a JSON string containing the model configuration.
[ "Return", "a", "JSON", "string", "containing", "the", "model", "configuration", "." ]
def to_json(self, **kwargs): '''Return a JSON string containing the model configuration. To load a model from a JSON save file, use `keras.models.from_json(json_string, custom_objects={})`. ''' import json def get_json_type(obj): # if obj is any numpy type if type(obj).__module__ == np.__name__: return obj.item() # if obj is a python 'type' if type(obj).__name__ == type.__name__: return obj.__name__ raise TypeError('Not JSON Serializable') config = self.get_config() return json.dumps(config, default=get_json_type, **kwargs)
[ "def", "to_json", "(", "self", ",", "*", "*", "kwargs", ")", ":", "import", "json", "def", "get_json_type", "(", "obj", ")", ":", "# if obj is any numpy type", "if", "type", "(", "obj", ")", ".", "__module__", "==", "np", ".", "__name__", ":", "return", ...
https://github.com/jacoxu/encoder_decoder/blob/6829c3bc42105aedfd1b8a81c81be19df4326c0a/keras/old_models.py#L440-L460
ragulpr/wtte-rnn
162f5c17f21db79a316d563b60835d178142fd69
python/wtte/wtte.py
python
loglik_continuous_conditional_correction
(y, u, a, b, epsilon=K.epsilon())
return loglikelihoods
Integrated conditional excess loss. Explanation TODO
Integrated conditional excess loss. Explanation TODO
[ "Integrated", "conditional", "excess", "loss", ".", "Explanation", "TODO" ]
def loglik_continuous_conditional_correction(y, u, a, b, epsilon=K.epsilon()): """Integrated conditional excess loss. Explanation TODO """ ya = (y + epsilon) / a loglikelihoods = y * \ (u * (K.log(b) + b * K.log(ya)) - (b / (b + 1.)) * K.pow(ya, b)) return loglikelihoods
[ "def", "loglik_continuous_conditional_correction", "(", "y", ",", "u", ",", "a", ",", "b", ",", "epsilon", "=", "K", ".", "epsilon", "(", ")", ")", ":", "ya", "=", "(", "y", "+", "epsilon", ")", "/", "a", "loglikelihoods", "=", "y", "*", "(", "u", ...
https://github.com/ragulpr/wtte-rnn/blob/162f5c17f21db79a316d563b60835d178142fd69/python/wtte/wtte.py#L179-L186
securesystemslab/zippy
ff0e84ac99442c2c55fe1d285332cfd4e185e089
zippy/lib-python/3/http/client.py
python
HTTPResponse.close
(self)
[]
def close(self): if self.fp: self.fp.close() self.fp = None
[ "def", "close", "(", "self", ")", ":", "if", "self", ".", "fp", ":", "self", ".", "fp", ".", "close", "(", ")", "self", ".", "fp", "=", "None" ]
https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/lib-python/3/http/client.py#L449-L452
appium/python-client
72f942d2152ee1b0d7539f3bf2705b50d01133f7
appium/webdriver/extensions/remote_fs.py
python
RemoteFS.push_file
( self: T, destination_path: str, base64data: Optional[str] = None, source_path: Optional[str] = None )
return self
Puts the data from the file at `source_path`, encoded as Base64, in the file specified as `path`. Specify either `base64data` or `source_path`, if both specified default to `source_path` Args: destination_path: the location on the device/simulator where the local file contents should be saved base64data: file contents, encoded as Base64, to be written to the file on the device/simulator source_path: local file path for the file to be loaded on device Returns: Union['WebDriver', 'RemoteFS']: Self instance
Puts the data from the file at `source_path`, encoded as Base64, in the file specified as `path`.
[ "Puts", "the", "data", "from", "the", "file", "at", "source_path", "encoded", "as", "Base64", "in", "the", "file", "specified", "as", "path", "." ]
def push_file( self: T, destination_path: str, base64data: Optional[str] = None, source_path: Optional[str] = None ) -> T: """Puts the data from the file at `source_path`, encoded as Base64, in the file specified as `path`. Specify either `base64data` or `source_path`, if both specified default to `source_path` Args: destination_path: the location on the device/simulator where the local file contents should be saved base64data: file contents, encoded as Base64, to be written to the file on the device/simulator source_path: local file path for the file to be loaded on device Returns: Union['WebDriver', 'RemoteFS']: Self instance """ if source_path is None and base64data is None: raise InvalidArgumentException('Must either pass base64 data or a local file path') if source_path is not None: try: with open(source_path, 'rb') as f: file_data = f.read() except IOError as e: message = f'source_path "{source_path}" could not be found. Are you sure the file exists?' raise InvalidArgumentException(message) from e base64data = base64.b64encode(file_data).decode('utf-8') data = { 'path': destination_path, 'data': base64data, } self.execute(Command.PUSH_FILE, data) return self
[ "def", "push_file", "(", "self", ":", "T", ",", "destination_path", ":", "str", ",", "base64data", ":", "Optional", "[", "str", "]", "=", "None", ",", "source_path", ":", "Optional", "[", "str", "]", "=", "None", ")", "->", "T", ":", "if", "source_pa...
https://github.com/appium/python-client/blob/72f942d2152ee1b0d7539f3bf2705b50d01133f7/appium/webdriver/extensions/remote_fs.py#L59-L92
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/satel_integra/__init__.py
python
async_setup
(hass: HomeAssistant, config: ConfigType)
return True
Set up the Satel Integra component.
Set up the Satel Integra component.
[ "Set", "up", "the", "Satel", "Integra", "component", "." ]
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the Satel Integra component.""" conf = config[DOMAIN] zones = conf.get(CONF_ZONES) outputs = conf.get(CONF_OUTPUTS) switchable_outputs = conf.get(CONF_SWITCHABLE_OUTPUTS) host = conf.get(CONF_HOST) port = conf.get(CONF_PORT) partitions = conf.get(CONF_DEVICE_PARTITIONS) monitored_outputs = collections.OrderedDict( list(outputs.items()) + list(switchable_outputs.items()) ) controller = AsyncSatel(host, port, hass.loop, zones, monitored_outputs, partitions) hass.data[DATA_SATEL] = controller result = await controller.connect() if not result: return False @callback def _close(*_): controller.close() hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _close) _LOGGER.debug("Arm home config: %s, mode: %s ", conf, conf.get(CONF_ARM_HOME_MODE)) hass.async_create_task( async_load_platform(hass, Platform.ALARM_CONTROL_PANEL, DOMAIN, conf, config) ) hass.async_create_task( async_load_platform( hass, Platform.BINARY_SENSOR, DOMAIN, {CONF_ZONES: zones, CONF_OUTPUTS: outputs}, config, ) ) hass.async_create_task( async_load_platform( hass, Platform.SWITCH, DOMAIN, { CONF_SWITCHABLE_OUTPUTS: switchable_outputs, CONF_DEVICE_CODE: conf.get(CONF_DEVICE_CODE), }, config, ) ) @callback def alarm_status_update_callback(): """Send status update received from alarm to Home Assistant.""" _LOGGER.debug("Sending request to update panel state") async_dispatcher_send(hass, SIGNAL_PANEL_MESSAGE) @callback def zones_update_callback(status): """Update zone objects as per notification from the alarm.""" _LOGGER.debug("Zones callback, status: %s", status) async_dispatcher_send(hass, SIGNAL_ZONES_UPDATED, status[ZONES]) @callback def outputs_update_callback(status): """Update zone objects as per notification from the alarm.""" _LOGGER.debug("Outputs updated callback , status: %s", status) async_dispatcher_send(hass, SIGNAL_OUTPUTS_UPDATED, status["outputs"]) # Create a task instead of adding a tracking job, since this task will # run until the connection to satel_integra is closed. hass.loop.create_task(controller.keep_alive()) hass.loop.create_task( controller.monitor_status( alarm_status_update_callback, zones_update_callback, outputs_update_callback ) ) return True
[ "async", "def", "async_setup", "(", "hass", ":", "HomeAssistant", ",", "config", ":", "ConfigType", ")", "->", "bool", ":", "conf", "=", "config", "[", "DOMAIN", "]", "zones", "=", "conf", ".", "get", "(", "CONF_ZONES", ")", "outputs", "=", "conf", "."...
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/satel_integra/__init__.py#L94-L180
CouchPotato/CouchPotatoV1
135b3331d1b88ef645e29b76f2d4cc4a732c9232
library/sqlalchemy/engine/base.py
python
ResultProxy.lastrowid
(self)
return self._saved_cursor.lastrowid
return the 'lastrowid' accessor on the DBAPI cursor. This is a DBAPI specific method and is only functional for those backends which support it, for statements where it is appropriate. It's behavior is not consistent across backends. Usage of this method is normally unnecessary; the :attr:`~ResultProxy.inserted_primary_key` attribute provides a tuple of primary key values for a newly inserted row, regardless of database backend.
return the 'lastrowid' accessor on the DBAPI cursor. This is a DBAPI specific method and is only functional for those backends which support it, for statements where it is appropriate. It's behavior is not consistent across backends. Usage of this method is normally unnecessary; the :attr:`~ResultProxy.inserted_primary_key` attribute provides a tuple of primary key values for a newly inserted row, regardless of database backend.
[ "return", "the", "lastrowid", "accessor", "on", "the", "DBAPI", "cursor", ".", "This", "is", "a", "DBAPI", "specific", "method", "and", "is", "only", "functional", "for", "those", "backends", "which", "support", "it", "for", "statements", "where", "it", "is"...
def lastrowid(self): """return the 'lastrowid' accessor on the DBAPI cursor. This is a DBAPI specific method and is only functional for those backends which support it, for statements where it is appropriate. It's behavior is not consistent across backends. Usage of this method is normally unnecessary; the :attr:`~ResultProxy.inserted_primary_key` attribute provides a tuple of primary key values for a newly inserted row, regardless of database backend. """ return self._saved_cursor.lastrowid
[ "def", "lastrowid", "(", "self", ")", ":", "return", "self", ".", "_saved_cursor", ".", "lastrowid" ]
https://github.com/CouchPotato/CouchPotatoV1/blob/135b3331d1b88ef645e29b76f2d4cc4a732c9232/library/sqlalchemy/engine/base.py#L2293-L2307
OCA/stock-logistics-warehouse
185c1b0cb9e31e3746a89ec269b4bc09c69b2411
stock_packaging_calculator/models/product.py
python
Product._product_qty_by_packaging
(self, pkg_by_qty, qty, with_contained=False)
return res
Produce a list of dictionaries of packaging info.
Produce a list of dictionaries of packaging info.
[ "Produce", "a", "list", "of", "dictionaries", "of", "packaging", "info", "." ]
def _product_qty_by_packaging(self, pkg_by_qty, qty, with_contained=False): """Produce a list of dictionaries of packaging info.""" # TODO: refactor to handle fractional quantities (eg: 0.5 Kg) res = [] prepare_values = self.env.context.get( "_packaging_values_handler", self._prepare_qty_by_packaging_values ) for pkg in pkg_by_qty: qty_per_pkg, qty = self._qty_by_pkg(pkg.qty, qty) if qty_per_pkg: value = prepare_values(pkg, qty_per_pkg) if with_contained: contained = None if not pkg.is_unit: mapping = self.packaging_contained_mapping # integer keys are serialized as strings :/ contained = mapping.get(str(pkg.id)) value["contained"] = contained res.append(value) if not qty: break return res
[ "def", "_product_qty_by_packaging", "(", "self", ",", "pkg_by_qty", ",", "qty", ",", "with_contained", "=", "False", ")", ":", "# TODO: refactor to handle fractional quantities (eg: 0.5 Kg)", "res", "=", "[", "]", "prepare_values", "=", "self", ".", "env", ".", "con...
https://github.com/OCA/stock-logistics-warehouse/blob/185c1b0cb9e31e3746a89ec269b4bc09c69b2411/stock_packaging_calculator/models/product.py#L113-L134
VITA-Group/FasterSeg
478b0265eb9ab626cfbe503ad16d2452878b38cc
latency/operations.py
python
ConvNorm.forward_latency
(self, size)
return latency, (c_out, h_out, w_out)
[]
def forward_latency(self, size): c_in, h_in, w_in = size if self.slimmable: assert c_in == int(self.C_in * self.ratio[0]), "c_in %d, self.C_in * self.ratio[0] %d"%(c_in, self.C_in * self.ratio[0]) c_out = int(self.C_out * self.ratio[1]) else: assert c_in == self.C_in, "c_in %d, self.C_in %d"%(c_in, self.C_in) c_out = self.C_out if self.stride == 1: h_out = h_in; w_out = w_in else: h_out = h_in // 2; w_out = w_in // 2 name = "ConvNorm_H%d_W%d_Cin%d_Cout%d_kernel%d_stride%d"%(h_in, w_in, c_in, c_out, self.kernel_size, self.stride) if name in latency_lookup_table: latency = latency_lookup_table[name] else: print("not found in latency_lookup_table:", name) latency = ConvNorm._latency(h_in, w_in, c_in, c_out, self.kernel_size, self.stride, self.padding, self.dilation, self.groups, self.bias) latency_lookup_table[name] = latency np.save(table_file_name, latency_lookup_table) return latency, (c_out, h_out, w_out)
[ "def", "forward_latency", "(", "self", ",", "size", ")", ":", "c_in", ",", "h_in", ",", "w_in", "=", "size", "if", "self", ".", "slimmable", ":", "assert", "c_in", "==", "int", "(", "self", ".", "C_in", "*", "self", ".", "ratio", "[", "0", "]", "...
https://github.com/VITA-Group/FasterSeg/blob/478b0265eb9ab626cfbe503ad16d2452878b38cc/latency/operations.py#L99-L119
HKUST-Aerial-Robotics/Stereo-RCNN
63c6ab98b7a5e36c7bcfdec4529804fc940ee900
lib/model/utils/blob.py
python
im_list_to_blob
(imgs_left, imgs_right)
return blob_left, blob_right
Convert a list of images into a network input. Assumes images are already prepared (means subtracted, BGR order, ...).
Convert a list of images into a network input.
[ "Convert", "a", "list", "of", "images", "into", "a", "network", "input", "." ]
def im_list_to_blob(imgs_left, imgs_right): """Convert a list of images into a network input. Assumes images are already prepared (means subtracted, BGR order, ...). """ max_shape = np.array([im.shape for im in imgs_left]).max(axis=0) num_images = len(imgs_left) blob_left = np.zeros((num_images, max_shape[0], max_shape[1], 3), dtype=np.float32) blob_right = np.zeros((num_images, max_shape[0], max_shape[1], 3), dtype=np.float32) for i in xrange(num_images): im_l = imgs_left[i] im_r = imgs_right[i] blob_left[i, 0:im_l.shape[0], 0:im_l.shape[1], :] = im_l blob_right[i, 0:im_r.shape[0], 0:im_r.shape[1], :] = im_r return blob_left, blob_right
[ "def", "im_list_to_blob", "(", "imgs_left", ",", "imgs_right", ")", ":", "max_shape", "=", "np", ".", "array", "(", "[", "im", ".", "shape", "for", "im", "in", "imgs_left", "]", ")", ".", "max", "(", "axis", "=", "0", ")", "num_images", "=", "len", ...
https://github.com/HKUST-Aerial-Robotics/Stereo-RCNN/blob/63c6ab98b7a5e36c7bcfdec4529804fc940ee900/lib/model/utils/blob.py#L20-L37
quantopian/zipline
014f1fc339dc8b7671d29be2d85ce57d3daec343
zipline/pipeline/loaders/events.py
python
required_event_fields
(next_value_columns, previous_value_columns)
return { TS_FIELD_NAME, SID_FIELD_NAME, EVENT_DATE_FIELD_NAME, }.union( # We also expect any of the field names that our loadable columns # are mapped to. viewvalues(next_value_columns), viewvalues(previous_value_columns), )
Compute the set of resource columns required to serve ``next_value_columns`` and ``previous_value_columns``.
Compute the set of resource columns required to serve ``next_value_columns`` and ``previous_value_columns``.
[ "Compute", "the", "set", "of", "resource", "columns", "required", "to", "serve", "next_value_columns", "and", "previous_value_columns", "." ]
def required_event_fields(next_value_columns, previous_value_columns): """ Compute the set of resource columns required to serve ``next_value_columns`` and ``previous_value_columns``. """ # These metadata columns are used to align event indexers. return { TS_FIELD_NAME, SID_FIELD_NAME, EVENT_DATE_FIELD_NAME, }.union( # We also expect any of the field names that our loadable columns # are mapped to. viewvalues(next_value_columns), viewvalues(previous_value_columns), )
[ "def", "required_event_fields", "(", "next_value_columns", ",", "previous_value_columns", ")", ":", "# These metadata columns are used to align event indexers.", "return", "{", "TS_FIELD_NAME", ",", "SID_FIELD_NAME", ",", "EVENT_DATE_FIELD_NAME", ",", "}", ".", "union", "(", ...
https://github.com/quantopian/zipline/blob/014f1fc339dc8b7671d29be2d85ce57d3daec343/zipline/pipeline/loaders/events.py#L21-L36
openstack/heat
ea6633c35b04bb49c4a2858edc9df0a82d039478
heat/engine/resources/openstack/heat/software_component.py
python
SoftwareComponent.validate
(self)
Validate SoftwareComponent properties consistency.
Validate SoftwareComponent properties consistency.
[ "Validate", "SoftwareComponent", "properties", "consistency", "." ]
def validate(self): """Validate SoftwareComponent properties consistency.""" super(SoftwareComponent, self).validate() # One lifecycle action (e.g. CREATE) can only be associated with one # config; otherwise a way to define ordering would be required. configs = self.properties[self.CONFIGS] config_actions = set() for config in configs: actions = config.get(self.CONFIG_ACTIONS) if any(action in config_actions for action in actions): msg = _('Defining more than one configuration for the same ' 'action in SoftwareComponent "%s" is not allowed.' ) % self.name raise exception.StackValidationFailed(message=msg) config_actions.update(actions)
[ "def", "validate", "(", "self", ")", ":", "super", "(", "SoftwareComponent", ",", "self", ")", ".", "validate", "(", ")", "# One lifecycle action (e.g. CREATE) can only be associated with one", "# config; otherwise a way to define ordering would be required.", "configs", "=", ...
https://github.com/openstack/heat/blob/ea6633c35b04bb49c4a2858edc9df0a82d039478/heat/engine/resources/openstack/heat/software_component.py#L140-L155
ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework
cb692f527e4e819b6c228187c5702d990a180043
external/Scripting Engine/Xenotix Python Scripting Engine/bin/x86/Debug/Lib/site-packages/Crypto/Hash/HMAC.py
python
HMAC.copy
(self)
return other
Return a copy ("clone") of the MAC object. The copy will have the same internal state as the original MAC object. This can be used to efficiently compute the MAC of strings that share a common initial substring. :Returns: An `HMAC` object
Return a copy ("clone") of the MAC object.
[ "Return", "a", "copy", "(", "clone", ")", "of", "the", "MAC", "object", "." ]
def copy(self): """Return a copy ("clone") of the MAC object. The copy will have the same internal state as the original MAC object. This can be used to efficiently compute the MAC of strings that share a common initial substring. :Returns: An `HMAC` object """ other = HMAC(b("")) other.digestmod = self.digestmod other.inner = self.inner.copy() other.outer = self.outer.copy() return other
[ "def", "copy", "(", "self", ")", ":", "other", "=", "HMAC", "(", "b", "(", "\"\"", ")", ")", "other", ".", "digestmod", "=", "self", ".", "digestmod", "other", ".", "inner", "=", "self", ".", "inner", ".", "copy", "(", ")", "other", ".", "outer",...
https://github.com/ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework/blob/cb692f527e4e819b6c228187c5702d990a180043/external/Scripting Engine/Xenotix Python Scripting Engine/bin/x86/Debug/Lib/site-packages/Crypto/Hash/HMAC.py#L150-L164
KalleHallden/AutoTimer
2d954216700c4930baa154e28dbddc34609af7ce
env/lib/python2.7/site-packages/setuptools/_vendor/pyparsing.py
python
ParseExpression.__str__
( self )
return self.strRepr
[]
def __str__( self ): try: return super(ParseExpression,self).__str__() except Exception: pass if self.strRepr is None: self.strRepr = "%s:(%s)" % ( self.__class__.__name__, _ustr(self.exprs) ) return self.strRepr
[ "def", "__str__", "(", "self", ")", ":", "try", ":", "return", "super", "(", "ParseExpression", ",", "self", ")", ".", "__str__", "(", ")", "except", "Exception", ":", "pass", "if", "self", ".", "strRepr", "is", "None", ":", "self", ".", "strRepr", "...
https://github.com/KalleHallden/AutoTimer/blob/2d954216700c4930baa154e28dbddc34609af7ce/env/lib/python2.7/site-packages/setuptools/_vendor/pyparsing.py#L3309-L3317
mardix/flask-cloudy
cf9f6f074e92af1d98f99fdf6ca458e29099e4b1
flask_cloudy.py
python
get_file_extension_type
(filename)
return "OTHER"
Return the group associated to the file :param filename: :return: str
Return the group associated to the file :param filename: :return: str
[ "Return", "the", "group", "associated", "to", "the", "file", ":", "param", "filename", ":", ":", "return", ":", "str" ]
def get_file_extension_type(filename): """ Return the group associated to the file :param filename: :return: str """ ext = get_file_extension(filename) if ext: for name, group in EXTENSIONS.items(): if ext in group: return name return "OTHER"
[ "def", "get_file_extension_type", "(", "filename", ")", ":", "ext", "=", "get_file_extension", "(", "filename", ")", "if", "ext", ":", "for", "name", ",", "group", "in", "EXTENSIONS", ".", "items", "(", ")", ":", "if", "ext", "in", "group", ":", "return"...
https://github.com/mardix/flask-cloudy/blob/cf9f6f074e92af1d98f99fdf6ca458e29099e4b1/flask_cloudy.py#L70-L81
pgmpy/pgmpy
24279929a28082ea994c52f3d165ca63fc56b02b
pgmpy/models/SEM.py
python
SEMAlg.generate_samples
(self, n_samples=100)
return pd.DataFrame(samples, columns=observed)
Generates random samples from the model. Parameters ---------- n_samples: int The number of samples to generate. Returns ------- pd.DataFrame: The genrated samples.
Generates random samples from the model.
[ "Generates", "random", "samples", "from", "the", "model", "." ]
def generate_samples(self, n_samples=100): """ Generates random samples from the model. Parameters ---------- n_samples: int The number of samples to generate. Returns ------- pd.DataFrame: The genrated samples. """ if (self.B_fixed_mask is None) or (self.zeta_fixed_mask is None): raise ValueError("Parameters for the model has not been specified.") B_inv = np.linalg.inv(np.eye(self.B_fixed_mask.shape[0]) - self.B_fixed_mask) implied_cov = ( self.wedge_y @ B_inv @ self.zeta_fixed_mask @ B_inv.T @ self.wedge_y.T ) # Check if implied covariance matrix is positive definite. if not np.all(np.linalg.eigvals(implied_cov) > 0): raise ValueError( "The implied covariance matrix is not positive definite." + "Please check model parameters." ) # Get the order of observed variables x_index, y_index = np.nonzero(self.wedge_y) observed = [self.eta[i] for i in y_index] # Generate samples and return a dataframe. samples = np.random.multivariate_normal( mean=[0 for i in range(implied_cov.shape[0])], cov=implied_cov, size=n_samples, ) return pd.DataFrame(samples, columns=observed)
[ "def", "generate_samples", "(", "self", ",", "n_samples", "=", "100", ")", ":", "if", "(", "self", ".", "B_fixed_mask", "is", "None", ")", "or", "(", "self", ".", "zeta_fixed_mask", "is", "None", ")", ":", "raise", "ValueError", "(", "\"Parameters for the ...
https://github.com/pgmpy/pgmpy/blob/24279929a28082ea994c52f3d165ca63fc56b02b/pgmpy/models/SEM.py#L952-L990
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/lib/python2.7/site-packages/mako/ext/babelplugin.py
python
BabelMakoExtractor.process_python
(self, code, code_lineno, translator_strings)
[]
def process_python(self, code, code_lineno, translator_strings): comment_tags = self.config['comment-tags'] for lineno, funcname, messages, python_translator_comments \ in extract_python(code, self.keywords, comment_tags, self.options): yield (code_lineno + (lineno - 1), funcname, messages, translator_strings + python_translator_comments)
[ "def", "process_python", "(", "self", ",", "code", ",", "code_lineno", ",", "translator_strings", ")", ":", "comment_tags", "=", "self", ".", "config", "[", "'comment-tags'", "]", "for", "lineno", ",", "funcname", ",", "messages", ",", "python_translator_comment...
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/lib/python2.7/site-packages/mako/ext/babelplugin.py#L27-L33
replit-archive/empythoned
977ec10ced29a3541a4973dc2b59910805695752
cpython/Lib/compiler/pycodegen.py
python
CodeGenerator._implicitNameOp
(self, prefix, name)
Emit name ops for names generated implicitly by for loops The interpreter generates names that start with a period or dollar sign. The symbol table ignores these names because they aren't present in the program text.
Emit name ops for names generated implicitly by for loops
[ "Emit", "name", "ops", "for", "names", "generated", "implicitly", "by", "for", "loops" ]
def _implicitNameOp(self, prefix, name): """Emit name ops for names generated implicitly by for loops The interpreter generates names that start with a period or dollar sign. The symbol table ignores these names because they aren't present in the program text. """ if self.optimized: self.emit(prefix + '_FAST', name) else: self.emit(prefix + '_NAME', name)
[ "def", "_implicitNameOp", "(", "self", ",", "prefix", ",", "name", ")", ":", "if", "self", ".", "optimized", ":", "self", ".", "emit", "(", "prefix", "+", "'_FAST'", ",", "name", ")", "else", ":", "self", ".", "emit", "(", "prefix", "+", "'_NAME'", ...
https://github.com/replit-archive/empythoned/blob/977ec10ced29a3541a4973dc2b59910805695752/cpython/Lib/compiler/pycodegen.py#L299-L309
Xyntax/DirBrute
84a54013f57a4588add9c2032c7c6c0902e6f504
libs/requests/models.py
python
Response.json
(self, **kwargs)
return json.loads(self.text, **kwargs)
Returns the json-encoded content of a response, if any. :param \*\*kwargs: Optional arguments that ``json.loads`` takes.
Returns the json-encoded content of a response, if any.
[ "Returns", "the", "json", "-", "encoded", "content", "of", "a", "response", "if", "any", "." ]
def json(self, **kwargs): """Returns the json-encoded content of a response, if any. :param \*\*kwargs: Optional arguments that ``json.loads`` takes. """ if not self.encoding and len(self.content) > 3: # No encoding set. JSON RFC 4627 section 3 states we should expect # UTF-8, -16 or -32. Detect which one to use; If the detection or # decoding fails, fall back to `self.text` (using chardet to make # a best guess). encoding = guess_json_utf(self.content) if encoding is not None: try: return json.loads(self.content.decode(encoding), **kwargs) except UnicodeDecodeError: # Wrong UTF codec detected; usually because it's not UTF-8 # but some other 8-bit codec. This is an RFC violation, # and the server didn't bother to tell us what codec *was* # used. pass return json.loads(self.text, **kwargs)
[ "def", "json", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "not", "self", ".", "encoding", "and", "len", "(", "self", ".", "content", ")", ">", "3", ":", "# No encoding set. JSON RFC 4627 section 3 states we should expect", "# UTF-8, -16 or -32. Detect w...
https://github.com/Xyntax/DirBrute/blob/84a54013f57a4588add9c2032c7c6c0902e6f504/libs/requests/models.py#L778-L799
hyde/hyde
7f415402cc3e007a746eb2b5bc102281fdb415bd
hyde/ext/plugins/structure.py
python
FlattenerPlugin.begin_site
(self)
Finds all the folders that need flattening and changes the relative deploy path of all resources in those folders.
Finds all the folders that need flattening and changes the relative deploy path of all resources in those folders.
[ "Finds", "all", "the", "folders", "that", "need", "flattening", "and", "changes", "the", "relative", "deploy", "path", "of", "all", "resources", "in", "those", "folders", "." ]
def begin_site(self): """ Finds all the folders that need flattening and changes the relative deploy path of all resources in those folders. """ items = [] try: items = self.site.config.flattener.items except AttributeError: pass for item in items: node = None target = '' try: node = self.site.content.node_from_relative_path(item.source) target = Folder(item.target) except AttributeError: continue if node: for resource in node.walk_resources(): target_path = target.child(resource.name) self.logger.debug( 'Flattening resource path [%s] to [%s]' % (resource, target_path)) resource.relative_deploy_path = target_path for child in node.walk(): child.relative_deploy_path = target.path
[ "def", "begin_site", "(", "self", ")", ":", "items", "=", "[", "]", "try", ":", "items", "=", "self", ".", "site", ".", "config", ".", "flattener", ".", "items", "except", "AttributeError", ":", "pass", "for", "item", "in", "items", ":", "node", "=",...
https://github.com/hyde/hyde/blob/7f415402cc3e007a746eb2b5bc102281fdb415bd/hyde/ext/plugins/structure.py#L32-L59
prakhar1989/Algorithms
82e64ce9d451b33c1bce64a63276d6341a1f13b0
sorting and basics/karatsuba.py
python
karatsuba
(x, y, b=10)
return (bm**2)*z1 + bm*z2 + z3
returns product of x, y. Uses base b in karatsuba algorithm Gives running time of O(n^1.585) as opposed to O(n^2) of naive multiplication >>> karatsuba(1234223123412323, 1234534213423333123) 1523690672850721578619752112274729L
returns product of x, y. Uses base b in karatsuba algorithm Gives running time of O(n^1.585) as opposed to O(n^2) of naive multiplication >>> karatsuba(1234223123412323, 1234534213423333123) 1523690672850721578619752112274729L
[ "returns", "product", "of", "x", "y", ".", "Uses", "base", "b", "in", "karatsuba", "algorithm", "Gives", "running", "time", "of", "O", "(", "n^1", ".", "585", ")", "as", "opposed", "to", "O", "(", "n^2", ")", "of", "naive", "multiplication", ">>>", "...
def karatsuba(x, y, b=10): """ returns product of x, y. Uses base b in karatsuba algorithm Gives running time of O(n^1.585) as opposed to O(n^2) of naive multiplication >>> karatsuba(1234223123412323, 1234534213423333123) 1523690672850721578619752112274729L """ if x < 1000 or y < 1000: return x * y m = min(len(str(x)) / 2, len(str(y)) / 2) bm = b**m x1, x0 = x / bm, x % bm y1, y0 = y / bm, y % bm z1 = karatsuba(x1, y1, b) z3 = karatsuba(x0, y0, b) z2 = karatsuba(x1 + x0, y1 + y0, b) - z1 - z3 return (bm**2)*z1 + bm*z2 + z3
[ "def", "karatsuba", "(", "x", ",", "y", ",", "b", "=", "10", ")", ":", "if", "x", "<", "1000", "or", "y", "<", "1000", ":", "return", "x", "*", "y", "m", "=", "min", "(", "len", "(", "str", "(", "x", ")", ")", "/", "2", ",", "len", "(",...
https://github.com/prakhar1989/Algorithms/blob/82e64ce9d451b33c1bce64a63276d6341a1f13b0/sorting and basics/karatsuba.py#L1-L19
holzschu/Carnets
44effb10ddfc6aa5c8b0687582a724ba82c6b547
Library/lib/python3.7/site-packages/jupyter_contrib_core-0.3.3-py3.7.egg/jupyter_contrib_core/notebook_compat/_compat/nbextensions.py
python
_nbextension_dirs
()
return [ os.path.join(jupyter_data_dir(), u'nbextensions'), os.path.join(ENV_JUPYTER_PATH[0], u'nbextensions'), os.path.join(SYSTEM_JUPYTER_PATH[0], 'nbextensions') ]
The possible locations of nbextensions.
The possible locations of nbextensions.
[ "The", "possible", "locations", "of", "nbextensions", "." ]
def _nbextension_dirs(): """The possible locations of nbextensions.""" return [ os.path.join(jupyter_data_dir(), u'nbextensions'), os.path.join(ENV_JUPYTER_PATH[0], u'nbextensions'), os.path.join(SYSTEM_JUPYTER_PATH[0], 'nbextensions') ]
[ "def", "_nbextension_dirs", "(", ")", ":", "return", "[", "os", ".", "path", ".", "join", "(", "jupyter_data_dir", "(", ")", ",", "u'nbextensions'", ")", ",", "os", ".", "path", ".", "join", "(", "ENV_JUPYTER_PATH", "[", "0", "]", ",", "u'nbextensions'",...
https://github.com/holzschu/Carnets/blob/44effb10ddfc6aa5c8b0687582a724ba82c6b547/Library/lib/python3.7/site-packages/jupyter_contrib_core-0.3.3-py3.7.egg/jupyter_contrib_core/notebook_compat/_compat/nbextensions.py#L459-L465
ansible/ansible-modules-core
00911a75ad6635834b6d28eef41f197b2f73c381
cloud/openstack/os_port.py
python
_needs_update
(module, port, cloud)
return False
Check for differences in the updatable values. NOTE: We don't currently allow name updates.
Check for differences in the updatable values.
[ "Check", "for", "differences", "in", "the", "updatable", "values", "." ]
def _needs_update(module, port, cloud): """Check for differences in the updatable values. NOTE: We don't currently allow name updates. """ compare_simple = ['admin_state_up', 'mac_address', 'device_owner', 'device_id'] compare_dict = ['allowed_address_pairs', 'extra_dhcp_opts'] compare_list = ['security_groups'] for key in compare_simple: if module.params[key] is not None and module.params[key] != port[key]: return True for key in compare_dict: if module.params[key] is not None and cmp(module.params[key], port[key]) != 0: return True for key in compare_list: if module.params[key] is not None and (set(module.params[key]) != set(port[key])): return True # NOTE: if port was created or updated with 'no_security_groups=True', # subsequent updates without 'no_security_groups' flag or # 'no_security_groups=False' and no specified 'security_groups', will not # result in an update to the port where the default security group is # applied. if module.params['no_security_groups'] and port['security_groups'] != []: return True if module.params['fixed_ips'] is not None: for item in module.params['fixed_ips']: if 'ip_address' in item: # if ip_address in request does not match any in existing port, # update is required. if not any(match['ip_address'] == item['ip_address'] for match in port['fixed_ips']): return True if 'subnet_id' in item: return True for item in port['fixed_ips']: # if ip_address in existing port does not match any in request, # update is required. if not any(match.get('ip_address') == item['ip_address'] for match in module.params['fixed_ips']): return True return False
[ "def", "_needs_update", "(", "module", ",", "port", ",", "cloud", ")", ":", "compare_simple", "=", "[", "'admin_state_up'", ",", "'mac_address'", ",", "'device_owner'", ",", "'device_id'", "]", "compare_dict", "=", "[", "'allowed_address_pairs'", ",", "'extra_dhcp...
https://github.com/ansible/ansible-modules-core/blob/00911a75ad6635834b6d28eef41f197b2f73c381/cloud/openstack/os_port.py#L215-L265
tacnetsol/ghidra_scripts
5c4d24bc7166f672015003572daeeb04d2e1f30e
MipsRopSystemChain.py
python
find_epilogue
(rop_finder, controlled_registers)
return function_epilogue
Find epilogues that grant control of each register. Ideal will return nine gadgets one that gives control of s0, one that gives control of s0 and s1, one that gives control of s0/s1/s2, etc. :param rop_finder: Mips rop finder class. :type rop_finder: mipsrop.MipsRop :returns: Gadgets found. :rtype: list(mipsrop.RopGadgets)
Find epilogues that grant control of each register. Ideal will return nine gadgets one that gives control of s0, one that gives control of s0 and s1, one that gives control of s0/s1/s2, etc.
[ "Find", "epilogues", "that", "grant", "control", "of", "each", "register", ".", "Ideal", "will", "return", "nine", "gadgets", "one", "that", "gives", "control", "of", "s0", "one", "that", "gives", "control", "of", "s0", "and", "s1", "one", "that", "gives",...
def find_epilogue(rop_finder, controlled_registers): """ Find epilogues that grant control of each register. Ideal will return nine gadgets one that gives control of s0, one that gives control of s0 and s1, one that gives control of s0/s1/s2, etc. :param rop_finder: Mips rop finder class. :type rop_finder: mipsrop.MipsRop :returns: Gadgets found. :rtype: list(mipsrop.RopGadgets) """ epilogue = mipsrop.MipsInstruction('.*lw', 'ra') function_epilogue = [] for i in range(0, len(mipsropchain.REGISTERS)): control_registers = mipsropchain.REGISTERS[:i + 1] if all(reg in controlled_registers for reg in control_registers): continue epilogue_gadget = rop_finder.find_instructions( [epilogue], controllable_calls=False, overwrite_register=control_registers, preserve_register=mipsropchain.REGISTERS[i + 1:]) if epilogue_gadget.gadgets: function_epilogue.append(epilogue_gadget.gadgets[0]) return function_epilogue
[ "def", "find_epilogue", "(", "rop_finder", ",", "controlled_registers", ")", ":", "epilogue", "=", "mipsrop", ".", "MipsInstruction", "(", "'.*lw'", ",", "'ra'", ")", "function_epilogue", "=", "[", "]", "for", "i", "in", "range", "(", "0", ",", "len", "(",...
https://github.com/tacnetsol/ghidra_scripts/blob/5c4d24bc7166f672015003572daeeb04d2e1f30e/MipsRopSystemChain.py#L96-L121
cronyo/cronyo
cd5abab0871b68bf31b18aac934303928130a441
cronyo/vendor/urllib3/response.py
python
HTTPResponse.flush
(self)
[]
def flush(self): if ( self._fp is not None and hasattr(self._fp, "flush") and not getattr(self._fp, "closed", False) ): return self._fp.flush()
[ "def", "flush", "(", "self", ")", ":", "if", "(", "self", ".", "_fp", "is", "not", "None", "and", "hasattr", "(", "self", ".", "_fp", ",", "\"flush\"", ")", "and", "not", "getattr", "(", "self", ".", "_fp", ",", "\"closed\"", ",", "False", ")", "...
https://github.com/cronyo/cronyo/blob/cd5abab0871b68bf31b18aac934303928130a441/cronyo/vendor/urllib3/response.py#L647-L653
ZhenYangIACAS/NMT_GAN
e27f9468112b117509f065f0f8f298f5b80b5602
model.py
python
shift_right
(input, pad=2)
return tf.concat((tf.ones_like(input[:, :1]) * pad, input[:, :-1]), 1)
Shift input tensor right to create decoder input. '2' denotes <S>
Shift input tensor right to create decoder input. '2' denotes <S>
[ "Shift", "input", "tensor", "right", "to", "create", "decoder", "input", ".", "2", "denotes", "<S", ">" ]
def shift_right(input, pad=2): """Shift input tensor right to create decoder input. '2' denotes <S>""" return tf.concat((tf.ones_like(input[:, :1]) * pad, input[:, :-1]), 1)
[ "def", "shift_right", "(", "input", ",", "pad", "=", "2", ")", ":", "return", "tf", ".", "concat", "(", "(", "tf", ".", "ones_like", "(", "input", "[", ":", ",", ":", "1", "]", ")", "*", "pad", ",", "input", "[", ":", ",", ":", "-", "1", "]...
https://github.com/ZhenYangIACAS/NMT_GAN/blob/e27f9468112b117509f065f0f8f298f5b80b5602/model.py#L764-L766
google/grr
8ad8a4d2c5a93c92729206b7771af19d92d4f915
grr/server/grr_response_server/gui/api_call_router.py
python
ApiCallRouterStub.GetFileDetails
(self, args, context=None)
Get details of a VFS file on a given client.
Get details of a VFS file on a given client.
[ "Get", "details", "of", "a", "VFS", "file", "on", "a", "given", "client", "." ]
def GetFileDetails(self, args, context=None): """Get details of a VFS file on a given client.""" raise NotImplementedError()
[ "def", "GetFileDetails", "(", "self", ",", "args", ",", "context", "=", "None", ")", ":", "raise", "NotImplementedError", "(", ")" ]
https://github.com/google/grr/blob/8ad8a4d2c5a93c92729206b7771af19d92d4f915/grr/server/grr_response_server/gui/api_call_router.py#L452-L455
mitre/caldera
46429594584f3852d1f9353402407fdb7c1a8302
app/api/v2/responses.py
python
json_request_validation_middleware
(request, handler)
Middleware that converts json decoding and marshmallow validation errors into 400 responses w/ json bodies.
Middleware that converts json decoding and marshmallow validation errors into 400 responses w/ json bodies.
[ "Middleware", "that", "converts", "json", "decoding", "and", "marshmallow", "validation", "errors", "into", "400", "responses", "w", "/", "json", "bodies", "." ]
async def json_request_validation_middleware(request, handler): """Middleware that converts json decoding and marshmallow validation errors into 400 responses w/ json bodies. """ try: return await handler(request) except errors.DataValidationError as ex: raise JsonHttpBadRequest( error=str(ex), details={ex.name: ex.value} ) except errors.RequestValidationError as ex: raise JsonHttpBadRequest('Received invalid json', details=ex.errors) except errors.RequestUnparsableJsonError: raise JsonHttpBadRequest('Unexpected error occurred while parsing json')
[ "async", "def", "json_request_validation_middleware", "(", "request", ",", "handler", ")", ":", "try", ":", "return", "await", "handler", "(", "request", ")", "except", "errors", ".", "DataValidationError", "as", "ex", ":", "raise", "JsonHttpBadRequest", "(", "e...
https://github.com/mitre/caldera/blob/46429594584f3852d1f9353402407fdb7c1a8302/app/api/v2/responses.py#L66-L80
getsentry/rb
6f96a68dca2d77e9ac1d8bdd7a21e2575af65a20
rb/clients.py
python
CommandBuffer.fileno
(self)
return self.connection._sock.fileno()
Returns the file number of the underlying connection's socket to be able to select over it.
Returns the file number of the underlying connection's socket to be able to select over it.
[ "Returns", "the", "file", "number", "of", "the", "underlying", "connection", "s", "socket", "to", "be", "able", "to", "select", "over", "it", "." ]
def fileno(self): """Returns the file number of the underlying connection's socket to be able to select over it. """ assert_open(self) return self.connection._sock.fileno()
[ "def", "fileno", "(", "self", ")", ":", "assert_open", "(", "self", ")", "return", "self", ".", "connection", ".", "_sock", ".", "fileno", "(", ")" ]
https://github.com/getsentry/rb/blob/6f96a68dca2d77e9ac1d8bdd7a21e2575af65a20/rb/clients.py#L124-L129
WeblateOrg/weblate
8126f3dda9d24f2846b755955132a8b8410866c8
weblate/trans/models/unit.py
python
Unit.update_source_units
(self, previous_source, user, author)
Update source for units withing same component. This is needed when editing template translation for monolingual formats.
Update source for units withing same component.
[ "Update", "source", "for", "units", "withing", "same", "component", "." ]
def update_source_units(self, previous_source, user, author): """Update source for units withing same component. This is needed when editing template translation for monolingual formats. """ # Find relevant units for unit in self.unit_set.exclude(id=self.id).prefetch().prefetch_bulk(): # Update source and number of words unit.source = self.target unit.num_words = self.num_words # Find reverted units if unit.state == STATE_FUZZY and unit.previous_source == self.target: # Unset fuzzy on reverted unit.original_state = unit.state = STATE_TRANSLATED unit.previous_source = "" elif ( unit.original_state == STATE_FUZZY and unit.previous_source == self.target ): # Unset fuzzy on reverted unit.original_state = STATE_TRANSLATED unit.previous_source = "" elif unit.state >= STATE_TRANSLATED: # Set fuzzy on changed unit.original_state = STATE_FUZZY if unit.state < STATE_READONLY: unit.state = STATE_FUZZY unit.previous_source = previous_source # Save unit and change unit.save() Change.objects.create( unit=unit, action=Change.ACTION_SOURCE_CHANGE, user=user, author=author, old=previous_source, target=self.target, ) # Invalidate stats unit.translation.invalidate_cache()
[ "def", "update_source_units", "(", "self", ",", "previous_source", ",", "user", ",", "author", ")", ":", "# Find relevant units", "for", "unit", "in", "self", ".", "unit_set", ".", "exclude", "(", "id", "=", "self", ".", "id", ")", ".", "prefetch", "(", ...
https://github.com/WeblateOrg/weblate/blob/8126f3dda9d24f2846b755955132a8b8410866c8/weblate/trans/models/unit.py#L995-L1035
pyRiemann/pyRiemann
30c2cd7204d19f1a60d3b7945dfd8ee3c46a8df8
pyriemann/utils/utils.py
python
check_version
(library, min_version)
return ok
Check minimum library version required Parameters ---------- library : str The library name to import. Must have a ``__version__`` property. min_version : str The minimum version string. Anything that matches ``'(\\d+ | [a-z]+ | \\.)'`` Returns ------- ok : bool True if the library exists with at least the specified version. Adapted from MNE-Python: http://github.com/mne-tools/mne-python
Check minimum library version required
[ "Check", "minimum", "library", "version", "required" ]
def check_version(library, min_version): """Check minimum library version required Parameters ---------- library : str The library name to import. Must have a ``__version__`` property. min_version : str The minimum version string. Anything that matches ``'(\\d+ | [a-z]+ | \\.)'`` Returns ------- ok : bool True if the library exists with at least the specified version. Adapted from MNE-Python: http://github.com/mne-tools/mne-python """ from distutils.version import LooseVersion ok = True try: library = __import__(library) except ImportError: ok = False else: this_version = LooseVersion(library.__version__) if this_version < min_version: ok = False return ok
[ "def", "check_version", "(", "library", ",", "min_version", ")", ":", "from", "distutils", ".", "version", "import", "LooseVersion", "ok", "=", "True", "try", ":", "library", "=", "__import__", "(", "library", ")", "except", "ImportError", ":", "ok", "=", ...
https://github.com/pyRiemann/pyRiemann/blob/30c2cd7204d19f1a60d3b7945dfd8ee3c46a8df8/pyriemann/utils/utils.py#L1-L29
pypa/pipenv
b21baade71a86ab3ee1429f71fbc14d4f95fb75d
pipenv/patched/notpip/_vendor/pkg_resources/__init__.py
python
_call_aside
(f, *args, **kwargs)
return f
[]
def _call_aside(f, *args, **kwargs): f(*args, **kwargs) return f
[ "def", "_call_aside", "(", "f", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "f", "(", "*", "args", ",", "*", "*", "kwargs", ")", "return", "f" ]
https://github.com/pypa/pipenv/blob/b21baade71a86ab3ee1429f71fbc14d4f95fb75d/pipenv/patched/notpip/_vendor/pkg_resources/__init__.py#L3234-L3236
oracle/graalpython
577e02da9755d916056184ec441c26e00b70145c
graalpython/lib-python/3/inspect.py
python
Signature.from_function
(cls, func)
return _signature_from_function(cls, func)
Constructs Signature for the given python function. Deprecated since Python 3.5, use `Signature.from_callable()`.
Constructs Signature for the given python function.
[ "Constructs", "Signature", "for", "the", "given", "python", "function", "." ]
def from_function(cls, func): """Constructs Signature for the given python function. Deprecated since Python 3.5, use `Signature.from_callable()`. """ warnings.warn("inspect.Signature.from_function() is deprecated since " "Python 3.5, use Signature.from_callable()", DeprecationWarning, stacklevel=2) return _signature_from_function(cls, func)
[ "def", "from_function", "(", "cls", ",", "func", ")", ":", "warnings", ".", "warn", "(", "\"inspect.Signature.from_function() is deprecated since \"", "\"Python 3.5, use Signature.from_callable()\"", ",", "DeprecationWarning", ",", "stacklevel", "=", "2", ")", "return", "...
https://github.com/oracle/graalpython/blob/577e02da9755d916056184ec441c26e00b70145c/graalpython/lib-python/3/inspect.py#L2816-L2825
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/Python-2.7.9/Lib/lib-tk/Tkinter.py
python
Misc.send
(self, interp, cmd, *args)
return self.tk.call(('send', interp, cmd) + args)
Send Tcl command CMD to different interpreter INTERP to be executed.
Send Tcl command CMD to different interpreter INTERP to be executed.
[ "Send", "Tcl", "command", "CMD", "to", "different", "interpreter", "INTERP", "to", "be", "executed", "." ]
def send(self, interp, cmd, *args): """Send Tcl command CMD to different interpreter INTERP to be executed.""" return self.tk.call(('send', interp, cmd) + args)
[ "def", "send", "(", "self", ",", "interp", ",", "cmd", ",", "*", "args", ")", ":", "return", "self", ".", "tk", ".", "call", "(", "(", "'send'", ",", "interp", ",", "cmd", ")", "+", "args", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/Python-2.7.9/Lib/lib-tk/Tkinter.py#L764-L766
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/rings/asymptotic/misc.py
python
parent_to_repr_short
(P)
return s
r""" Helper method which generates a short(er) representation string out of a parent. INPUT: - ``P`` -- a parent. OUTPUT: A string. EXAMPLES:: sage: from sage.rings.asymptotic.misc import parent_to_repr_short sage: parent_to_repr_short(ZZ) 'ZZ' sage: parent_to_repr_short(QQ) 'QQ' sage: parent_to_repr_short(SR) 'SR' sage: parent_to_repr_short(RR) 'RR' sage: parent_to_repr_short(CC) 'CC' sage: parent_to_repr_short(ZZ['x']) 'ZZ[x]' sage: parent_to_repr_short(QQ['d, k']) 'QQ[d, k]' sage: parent_to_repr_short(QQ['e']) 'QQ[e]' sage: parent_to_repr_short(SR[['a, r']]) 'SR[[a, r]]' sage: parent_to_repr_short(Zmod(3)) 'Ring of integers modulo 3' sage: parent_to_repr_short(Zmod(3)['g']) 'Univariate Polynomial Ring in g over Ring of integers modulo 3'
r""" Helper method which generates a short(er) representation string out of a parent.
[ "r", "Helper", "method", "which", "generates", "a", "short", "(", "er", ")", "representation", "string", "out", "of", "a", "parent", "." ]
def parent_to_repr_short(P): r""" Helper method which generates a short(er) representation string out of a parent. INPUT: - ``P`` -- a parent. OUTPUT: A string. EXAMPLES:: sage: from sage.rings.asymptotic.misc import parent_to_repr_short sage: parent_to_repr_short(ZZ) 'ZZ' sage: parent_to_repr_short(QQ) 'QQ' sage: parent_to_repr_short(SR) 'SR' sage: parent_to_repr_short(RR) 'RR' sage: parent_to_repr_short(CC) 'CC' sage: parent_to_repr_short(ZZ['x']) 'ZZ[x]' sage: parent_to_repr_short(QQ['d, k']) 'QQ[d, k]' sage: parent_to_repr_short(QQ['e']) 'QQ[e]' sage: parent_to_repr_short(SR[['a, r']]) 'SR[[a, r]]' sage: parent_to_repr_short(Zmod(3)) 'Ring of integers modulo 3' sage: parent_to_repr_short(Zmod(3)['g']) 'Univariate Polynomial Ring in g over Ring of integers modulo 3' """ from sage.rings.all import RR, CC, RIF, CIF, RBF, CBF from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ from sage.symbolic.ring import SR from sage.rings.polynomial.polynomial_ring import is_PolynomialRing from sage.rings.polynomial.multi_polynomial_ring_base import is_MPolynomialRing from sage.rings.power_series_ring import is_PowerSeriesRing def abbreviate(P): try: return P._repr_short_() except AttributeError: pass abbreviations = {ZZ: 'ZZ', QQ: 'QQ', SR: 'SR', RR: 'RR', CC: 'CC', RIF: 'RIF', CIF: 'CIF', RBF: 'RBF', CBF: 'CBF'} try: return abbreviations[P] except KeyError: pass raise ValueError('Cannot abbreviate %s.' % (P,)) poly = is_PolynomialRing(P) or is_MPolynomialRing(P) from sage.rings import multi_power_series_ring power = is_PowerSeriesRing(P) or \ multi_power_series_ring.is_MPowerSeriesRing(P) if poly or power: if poly: op, cl = ('[', ']') else: op, cl = ('[[', ']]') try: s = abbreviate(P.base_ring()) + op + ', '.join(P.variable_names()) + cl except ValueError: s = str(P) else: try: s = abbreviate(P) except ValueError: s = str(P) return s
[ "def", "parent_to_repr_short", "(", "P", ")", ":", "from", "sage", ".", "rings", ".", "all", "import", "RR", ",", "CC", ",", "RIF", ",", "CIF", ",", "RBF", ",", "CBF", "from", "sage", ".", "rings", ".", "integer_ring", "import", "ZZ", "from", "sage",...
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/rings/asymptotic/misc.py#L105-L186
avidLearnerInProgress/python-automation-scripts
859cbbf72571673500cfc0fbcf493beaed48b7c5
hackernews-scraper/json_to_csv.py
python
reduce_item
(key, value)
[]
def reduce_item(key, value): global reduced_item #Reduction Condition 1 if type(value) is list: i=0 for sub_item in value: reduce_item(key+'_'+to_string(i), sub_item) i=i+1 #Reduction Condition 2 elif type(value) is dict: sub_keys = value.keys() for sub_key in sub_keys: reduce_item(key+'_'+to_string(sub_key), value[sub_key]) #Base Condition else: reduced_item[to_string(key)] = to_string(value)
[ "def", "reduce_item", "(", "key", ",", "value", ")", ":", "global", "reduced_item", "#Reduction Condition 1", "if", "type", "(", "value", ")", "is", "list", ":", "i", "=", "0", "for", "sub_item", "in", "value", ":", "reduce_item", "(", "key", "+", "'_'",...
https://github.com/avidLearnerInProgress/python-automation-scripts/blob/859cbbf72571673500cfc0fbcf493beaed48b7c5/hackernews-scraper/json_to_csv.py#L40-L58
CityOfZion/neo-python
99783bc8310982a5380081ec41a6ee07ba843f3f
neo/Core/TX/Transaction.py
python
Transaction.GetTransactionResults
(self)
return realresults
Get the execution results of the transaction. Returns: None: if the transaction has no references. list: of TransactionResult objects.
Get the execution results of the transaction.
[ "Get", "the", "execution", "results", "of", "the", "transaction", "." ]
def GetTransactionResults(self): """ Get the execution results of the transaction. Returns: None: if the transaction has no references. list: of TransactionResult objects. """ if self.References is None: return None results = [] realresults = [] for ref_output in self.References.values(): results.append(TransactionResult(ref_output.AssetId, ref_output.Value)) for output in self.outputs: results.append(TransactionResult(output.AssetId, output.Value * Fixed8(-1))) for key, group in groupby(results, lambda x: x.AssetId): sum = Fixed8(0) for item in group: sum = sum + item.Amount if sum != Fixed8.Zero(): realresults.append(TransactionResult(key, sum)) return realresults
[ "def", "GetTransactionResults", "(", "self", ")", ":", "if", "self", ".", "References", "is", "None", ":", "return", "None", "results", "=", "[", "]", "realresults", "=", "[", "]", "for", "ref_output", "in", "self", ".", "References", ".", "values", "(",...
https://github.com/CityOfZion/neo-python/blob/99783bc8310982a5380081ec41a6ee07ba843f3f/neo/Core/TX/Transaction.py#L738-L765
dmlc/dgl
8d14a739bc9e446d6c92ef83eafe5782398118de
tutorials/models/3_generative_model/5_dgmg.py
python
DGMGSkeleton.__init__
(self, v_max)
Parameters ---------- v_max: int Max number of nodes considered
Parameters ---------- v_max: int Max number of nodes considered
[ "Parameters", "----------", "v_max", ":", "int", "Max", "number", "of", "nodes", "considered" ]
def __init__(self, v_max): """ Parameters ---------- v_max: int Max number of nodes considered """ super(DGMGSkeleton, self).__init__() # Graph configuration self.v_max = v_max
[ "def", "__init__", "(", "self", ",", "v_max", ")", ":", "super", "(", "DGMGSkeleton", ",", "self", ")", ".", "__init__", "(", ")", "# Graph configuration", "self", ".", "v_max", "=", "v_max" ]
https://github.com/dmlc/dgl/blob/8d14a739bc9e446d6c92ef83eafe5782398118de/tutorials/models/3_generative_model/5_dgmg.py#L246-L256
saltstack/salt
fae5bc757ad0f1716483ce7ae180b451545c2058
salt/modules/vmctl.py
python
create_disk
(name, size)
return ret
Create a VMM disk with the specified `name` and `size`. size: Size in megabytes, or use a specifier such as M, G, T. CLI Example: .. code-block:: bash salt '*' vmctl.create_disk /path/to/disk.img size=10G
Create a VMM disk with the specified `name` and `size`.
[ "Create", "a", "VMM", "disk", "with", "the", "specified", "name", "and", "size", "." ]
def create_disk(name, size): """ Create a VMM disk with the specified `name` and `size`. size: Size in megabytes, or use a specifier such as M, G, T. CLI Example: .. code-block:: bash salt '*' vmctl.create_disk /path/to/disk.img size=10G """ ret = False cmd = "vmctl create {} -s {}".format(name, size) result = __salt__["cmd.run_all"](cmd, output_loglevel="trace", python_shell=False) if result["retcode"] == 0: ret = True else: raise CommandExecutionError( "Problem encountered creating disk image", info={"errors": [result["stderr"]], "changes": ret}, ) return ret
[ "def", "create_disk", "(", "name", ",", "size", ")", ":", "ret", "=", "False", "cmd", "=", "\"vmctl create {} -s {}\"", ".", "format", "(", "name", ",", "size", ")", "result", "=", "__salt__", "[", "\"cmd.run_all\"", "]", "(", "cmd", ",", "output_loglevel"...
https://github.com/saltstack/salt/blob/fae5bc757ad0f1716483ce7ae180b451545c2058/salt/modules/vmctl.py#L49-L75
holzschu/Carnets
44effb10ddfc6aa5c8b0687582a724ba82c6b547
Library/lib/python3.7/site-packages/sympy/integrals/prde.py
python
prde_spde
(a, b, Q, n, DE)
return (A, B, Qq, R, n1)
Special Polynomial Differential Equation algorithm: Parametric Version. Given a derivation D on k[t], an integer n, and a, b, q1, ..., qm in k[t] with deg(a) > 0 and gcd(a, b) == 1, return (A, B, Q, R, n1), with Qq = [q1, ..., qm] and R = [r1, ..., rm], such that for any solution c1, ..., cm in Const(k) and q in k[t] of degree at most n of a*Dq + b*q == Sum(ci*gi, (i, 1, m)), p = (q - Sum(ci*ri, (i, 1, m)))/a has degree at most n1 and satisfies A*Dp + B*p == Sum(ci*qi, (i, 1, m))
Special Polynomial Differential Equation algorithm: Parametric Version.
[ "Special", "Polynomial", "Differential", "Equation", "algorithm", ":", "Parametric", "Version", "." ]
def prde_spde(a, b, Q, n, DE): """ Special Polynomial Differential Equation algorithm: Parametric Version. Given a derivation D on k[t], an integer n, and a, b, q1, ..., qm in k[t] with deg(a) > 0 and gcd(a, b) == 1, return (A, B, Q, R, n1), with Qq = [q1, ..., qm] and R = [r1, ..., rm], such that for any solution c1, ..., cm in Const(k) and q in k[t] of degree at most n of a*Dq + b*q == Sum(ci*gi, (i, 1, m)), p = (q - Sum(ci*ri, (i, 1, m)))/a has degree at most n1 and satisfies A*Dp + B*p == Sum(ci*qi, (i, 1, m)) """ R, Z = list(zip(*[gcdex_diophantine(b, a, qi) for qi in Q])) A = a B = b + derivation(a, DE) Qq = [zi - derivation(ri, DE) for ri, zi in zip(R, Z)] R = list(R) n1 = n - a.degree(DE.t) return (A, B, Qq, R, n1)
[ "def", "prde_spde", "(", "a", ",", "b", ",", "Q", ",", "n", ",", "DE", ")", ":", "R", ",", "Z", "=", "list", "(", "zip", "(", "*", "[", "gcdex_diophantine", "(", "b", ",", "a", ",", "qi", ")", "for", "qi", "in", "Q", "]", ")", ")", "A", ...
https://github.com/holzschu/Carnets/blob/44effb10ddfc6aa5c8b0687582a724ba82c6b547/Library/lib/python3.7/site-packages/sympy/integrals/prde.py#L284-L303
netaddr/netaddr
e84688f7034b7a88ac00a676359be57eb7a78184
netaddr/ip/__init__.py
python
BaseIP.__lt__
(self, other)
:param other: an `IPAddress` or `IPNetwork` object. :return: ``True`` if this `IPAddress` or `IPNetwork` object is less than ``other``, ``False`` otherwise.
:param other: an `IPAddress` or `IPNetwork` object.
[ ":", "param", "other", ":", "an", "IPAddress", "or", "IPNetwork", "object", "." ]
def __lt__(self, other): """ :param other: an `IPAddress` or `IPNetwork` object. :return: ``True`` if this `IPAddress` or `IPNetwork` object is less than ``other``, ``False`` otherwise. """ try: return self.sort_key() < other.sort_key() except (AttributeError, TypeError): return NotImplemented
[ "def", "__lt__", "(", "self", ",", "other", ")", ":", "try", ":", "return", "self", ".", "sort_key", "(", ")", "<", "other", ".", "sort_key", "(", ")", "except", "(", "AttributeError", ",", "TypeError", ")", ":", "return", "NotImplemented" ]
https://github.com/netaddr/netaddr/blob/e84688f7034b7a88ac00a676359be57eb7a78184/netaddr/ip/__init__.py#L86-L96
deepgram/sidomo
b70825d9017eb0c2c6b6389345cccbcbd52cf669
sidomo/sidomo.py
python
dodo
(do, image, sharedir, display)
dodo (like sudo but for docker) runs argument in a docker image. do is the command to run in the image. image taken from (1) command-line, (2) "DODOIMAGE" environment variable, or (3) first built image. sharedir (e.g., to pass data to command) is mounted (default: current directory). empty string does no mounting. display is environment variable to set in docker image that allows X11 forwarding.
dodo (like sudo but for docker) runs argument in a docker image.
[ "dodo", "(", "like", "sudo", "but", "for", "docker", ")", "runs", "argument", "in", "a", "docker", "image", "." ]
def dodo(do, image, sharedir, display): """ dodo (like sudo but for docker) runs argument in a docker image. do is the command to run in the image. image taken from (1) command-line, (2) "DODOIMAGE" environment variable, or (3) first built image. sharedir (e.g., to pass data to command) is mounted (default: current directory). empty string does no mounting. display is environment variable to set in docker image that allows X11 forwarding. """ # try to set image three ways if not image: if 'DODOIMAGE' in os.environ: image = os.environ['DODOIMAGE'] else: ims = client.images() if len(ims) >= 1: image = [im['RepoTags'][0] for im in client.images()][0] assert image, 'No image given or found locally.' # get image if not available locally imnames = [im['RepoTags'][0] for im in client.images()] if (not any([image in imname for imname in imnames])) and client.search(image): print('Image {} not found locally. Pulling from docker hub.'.format(image)) client.pull(image) # mount directory in docker if sharedir: volumes = ['{}:/home'.format(sharedir)] else: volumes = [] # set docker environment to display X11 locally if display: environment = ['DISPLAY={}'.format(display)] elif 'DODODISPLAY' in os.environ: environment = ['DISPLAY={}'.format(os.environ['DODODISPLAY'])] else: environment = [] with Container(image, volumes=volumes, cleanup=True, environment=environment) as c: for output_line in c.run(do): print('{}:\t {}'.format(image, output_line.decode('utf-8')))
[ "def", "dodo", "(", "do", ",", "image", ",", "sharedir", ",", "display", ")", ":", "# try to set image three ways", "if", "not", "image", ":", "if", "'DODOIMAGE'", "in", "os", ".", "environ", ":", "image", "=", "os", ".", "environ", "[", "'DODOIMAGE'", "...
https://github.com/deepgram/sidomo/blob/b70825d9017eb0c2c6b6389345cccbcbd52cf669/sidomo/sidomo.py#L79-L121
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/rtsp_to_webrtc/__init__.py
python
async_setup_entry
(hass: HomeAssistant, entry: ConfigEntry)
return True
Set up RTSPtoWebRTC from a config entry.
Set up RTSPtoWebRTC from a config entry.
[ "Set", "up", "RTSPtoWebRTC", "from", "a", "config", "entry", "." ]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up RTSPtoWebRTC from a config entry.""" hass.data.setdefault(DOMAIN, {}) client: WebRTCClientInterface try: async with async_timeout.timeout(TIMEOUT): client = await get_adaptive_client( async_get_clientsession(hass), entry.data[DATA_SERVER_URL] ) except ResponseError as err: raise ConfigEntryNotReady from err except (TimeoutError, ClientError) as err: raise ConfigEntryNotReady from err async def async_offer_for_stream_source( stream_source: str, offer_sdp: str, stream_id: str, ) -> str: """Handle the signal path for a WebRTC stream. This signal path is used to route the offer created by the client to the proxy server that translates a stream to WebRTC. The communication for the stream itself happens directly between the client and proxy. """ try: async with async_timeout.timeout(TIMEOUT): return await client.offer_stream_id(offer_sdp, stream_source, stream_id) except TimeoutError as err: raise HomeAssistantError("Timeout talking to RTSPtoWebRTC server") from err except ClientError as err: raise HomeAssistantError(str(err)) from err entry.async_on_unload( camera.async_register_rtsp_to_web_rtc_provider( hass, DOMAIN, async_offer_for_stream_source ) ) return True
[ "async", "def", "async_setup_entry", "(", "hass", ":", "HomeAssistant", ",", "entry", ":", "ConfigEntry", ")", "->", "bool", ":", "hass", ".", "data", ".", "setdefault", "(", "DOMAIN", ",", "{", "}", ")", "client", ":", "WebRTCClientInterface", "try", ":",...
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/rtsp_to_webrtc/__init__.py#L42-L82
mukulhase/WebWhatsapp-Wrapper
d2ea6e821cf754ba4e16a6d5ebc141c3f65da339
sample/flask/webapi.py
python
init_client
(client_id)
return drivers[client_id]
Initialse a driver for client and store for future reference @param client_id: ID of client user @return whebwhatsapi object
Initialse a driver for client and store for future reference
[ "Initialse", "a", "driver", "for", "client", "and", "store", "for", "future", "reference" ]
def init_client(client_id): """Initialse a driver for client and store for future reference @param client_id: ID of client user @return whebwhatsapi object """ if client_id not in drivers: drivers[client_id] = init_driver(client_id) return drivers[client_id]
[ "def", "init_client", "(", "client_id", ")", ":", "if", "client_id", "not", "in", "drivers", ":", "drivers", "[", "client_id", "]", "=", "init_driver", "(", "client_id", ")", "return", "drivers", "[", "client_id", "]" ]
https://github.com/mukulhase/WebWhatsapp-Wrapper/blob/d2ea6e821cf754ba4e16a6d5ebc141c3f65da339/sample/flask/webapi.py#L217-L225
behave/behave
e6364fe3d62c2befe34bc56471cfb317a218cd01
behave4cmd0/log/steps.py
python
step_command_output_should_not_contain_log_records_from_categories
(context)
Verifies that the command output contains not log records from the provided log categories (in any order). .. code-block: gherkin Given I define the log record schema: | category | level | message | | root | ERROR | __LOG_MESSAGE__ | Then the command output should not contain log records from categories: | category | | bar |
Verifies that the command output contains not log records from the provided log categories (in any order).
[ "Verifies", "that", "the", "command", "output", "contains", "not", "log", "records", "from", "the", "provided", "log", "categories", "(", "in", "any", "order", ")", "." ]
def step_command_output_should_not_contain_log_records_from_categories(context): """ Verifies that the command output contains not log records from the provided log categories (in any order). .. code-block: gherkin Given I define the log record schema: | category | level | message | | root | ERROR | __LOG_MESSAGE__ | Then the command output should not contain log records from categories: | category | | bar | """ assert context.table, "REQUIRE: context.table" context.table.require_column("category") record_schema = context.log_record_row_schema LogRecordTable.annotate_with_row_schema(context.table, record_schema) step_command_output_should_not_contain_log_records(context) context.table.remove_columns(["level", "message"])
[ "def", "step_command_output_should_not_contain_log_records_from_categories", "(", "context", ")", ":", "assert", "context", ".", "table", ",", "\"REQUIRE: context.table\"", "context", ".", "table", ".", "require_column", "(", "\"category\"", ")", "record_schema", "=", "co...
https://github.com/behave/behave/blob/e6364fe3d62c2befe34bc56471cfb317a218cd01/behave4cmd0/log/steps.py#L283-L302
iclavera/learning_to_adapt
bd7d99ba402521c96631e7d09714128f549db0f1
learning_to_adapt/mujoco_py/mjtypes.py
python
MjvOptionWrapper.ptr
(self)
return self._wrapped
[]
def ptr(self): return self._wrapped
[ "def", "ptr", "(", "self", ")", ":", "return", "self", ".", "_wrapped" ]
https://github.com/iclavera/learning_to_adapt/blob/bd7d99ba402521c96631e7d09714128f549db0f1/learning_to_adapt/mujoco_py/mjtypes.py#L1417-L1418
khanhnamle1994/natural-language-processing
01d450d5ac002b0156ef4cf93a07cb508c1bcdc5
assignment1/.env/lib/python2.7/site-packages/pkg_resources/__init__.py
python
WorkingSet.resolve
(self, requirements, env=None, installer=None, replace_conflicting=False, extras=None)
return to_activate
List all distributions needed to (recursively) meet `requirements` `requirements` must be a sequence of ``Requirement`` objects. `env`, if supplied, should be an ``Environment`` instance. If not supplied, it defaults to all distributions available within any entry or distribution in the working set. `installer`, if supplied, will be invoked with each requirement that cannot be met by an already-installed distribution; it should return a ``Distribution`` or ``None``. Unless `replace_conflicting=True`, raises a VersionConflict exception if any requirements are found on the path that have the correct name but the wrong version. Otherwise, if an `installer` is supplied it will be invoked to obtain the correct version of the requirement and activate it. `extras` is a list of the extras to be used with these requirements. This is important because extra requirements may look like `my_req; extra = "my_extra"`, which would otherwise be interpreted as a purely optional requirement. Instead, we want to be able to assert that these requirements are truly required.
List all distributions needed to (recursively) meet `requirements`
[ "List", "all", "distributions", "needed", "to", "(", "recursively", ")", "meet", "requirements" ]
def resolve(self, requirements, env=None, installer=None, replace_conflicting=False, extras=None): """List all distributions needed to (recursively) meet `requirements` `requirements` must be a sequence of ``Requirement`` objects. `env`, if supplied, should be an ``Environment`` instance. If not supplied, it defaults to all distributions available within any entry or distribution in the working set. `installer`, if supplied, will be invoked with each requirement that cannot be met by an already-installed distribution; it should return a ``Distribution`` or ``None``. Unless `replace_conflicting=True`, raises a VersionConflict exception if any requirements are found on the path that have the correct name but the wrong version. Otherwise, if an `installer` is supplied it will be invoked to obtain the correct version of the requirement and activate it. `extras` is a list of the extras to be used with these requirements. This is important because extra requirements may look like `my_req; extra = "my_extra"`, which would otherwise be interpreted as a purely optional requirement. Instead, we want to be able to assert that these requirements are truly required. """ # set up the stack requirements = list(requirements)[::-1] # set of processed requirements processed = {} # key -> dist best = {} to_activate = [] req_extras = _ReqExtras() # Mapping of requirement to set of distributions that required it; # useful for reporting info about conflicts. required_by = collections.defaultdict(set) while requirements: # process dependencies breadth-first req = requirements.pop(0) if req in processed: # Ignore cyclic or redundant dependencies continue if not req_extras.markers_pass(req, extras): continue dist = best.get(req.key) if dist is None: # Find the best distribution and add it to the map dist = self.by_key.get(req.key) if dist is None or (dist not in req and replace_conflicting): ws = self if env is None: if dist is None: env = Environment(self.entries) else: # Use an empty environment and workingset to avoid # any further conflicts with the conflicting # distribution env = Environment([]) ws = WorkingSet([]) dist = best[req.key] = env.best_match( req, ws, installer, replace_conflicting=replace_conflicting ) if dist is None: requirers = required_by.get(req, None) raise DistributionNotFound(req, requirers) to_activate.append(dist) if dist not in req: # Oops, the "best" so far conflicts with a dependency dependent_req = required_by[req] raise VersionConflict(dist, req).with_context(dependent_req) # push the new requirements onto the stack new_requirements = dist.requires(req.extras)[::-1] requirements.extend(new_requirements) # Register the new requirements needed by req for new_requirement in new_requirements: required_by[new_requirement].add(req.project_name) req_extras[new_requirement] = req.extras processed[req] = True # return list of distros to activate return to_activate
[ "def", "resolve", "(", "self", ",", "requirements", ",", "env", "=", "None", ",", "installer", "=", "None", ",", "replace_conflicting", "=", "False", ",", "extras", "=", "None", ")", ":", "# set up the stack", "requirements", "=", "list", "(", "requirements"...
https://github.com/khanhnamle1994/natural-language-processing/blob/01d450d5ac002b0156ef4cf93a07cb508c1bcdc5/assignment1/.env/lib/python2.7/site-packages/pkg_resources/__init__.py#L799-L889
Map-A-Droid/MAD
81375b5c9ccc5ca3161eb487aa81469d40ded221
mapadroid/madmin/routes/config.py
python
MADminConfig.settings
(self)
return redirect(url_for('settings_devices'), code=302)
[]
def settings(self): return redirect(url_for('settings_devices'), code=302)
[ "def", "settings", "(", "self", ")", ":", "return", "redirect", "(", "url_for", "(", "'settings_devices'", ")", ",", "code", "=", "302", ")" ]
https://github.com/Map-A-Droid/MAD/blob/81375b5c9ccc5ca3161eb487aa81469d40ded221/mapadroid/madmin/routes/config.py#L446-L447
lykops/lykops
ed7e35d0c1abb1eacf7ab365e041347d0862c0a7
library/security/encryption/AES256/api.py
python
Using_AES256._split_header
(self, data)
return (b_header, b_ciphertext)
对加密数据进行分割,分为加密头和加密数据 :parm data :需要分割的加密数据
对加密数据进行分割,分为加密头和加密数据 :parm data :需要分割的加密数据
[ "对加密数据进行分割,分为加密头和加密数据", ":", "parm", "data", ":需要分割的加密数据" ]
def _split_header(self, data): ''' 对加密数据进行分割,分为加密头和加密数据 :parm data :需要分割的加密数据 ''' result = obj2bytes(data) if result[0] : data = result[1] else : data = string2bytes(data) b_data = data.split(b'\n') b_header = b_data[0].strip() b_ciphertext = b''.join(b_data[1:]) return (b_header, b_ciphertext)
[ "def", "_split_header", "(", "self", ",", "data", ")", ":", "result", "=", "obj2bytes", "(", "data", ")", "if", "result", "[", "0", "]", ":", "data", "=", "result", "[", "1", "]", "else", ":", "data", "=", "string2bytes", "(", "data", ")", "b_data"...
https://github.com/lykops/lykops/blob/ed7e35d0c1abb1eacf7ab365e041347d0862c0a7/library/security/encryption/AES256/api.py#L368-L386
PyQt5/PyQt
d2bbfc9fd6f3fdb5ed5404983cdd0848aa654cf0
QScrollArea/QQSettingPanel.py
python
Window.onItemClicked
(self, item)
左侧item
左侧item
[ "左侧item" ]
def onItemClicked(self, item): """左侧item""" row = self.listWidget.row(item) # 获取点击的item的索引 # 由于右侧的widget是按照命名widget_0 widget_1这样比较规范的方法,可以通过getattr找到 widget = getattr(self, 'widget_%d' % row, None) if not widget: return # 定位右侧位置并滚动 self._blockSignals = True self.scrollArea.verticalScrollBar().setSliderPosition(widget.pos().y()) self._blockSignals = False
[ "def", "onItemClicked", "(", "self", ",", "item", ")", ":", "row", "=", "self", ".", "listWidget", ".", "row", "(", "item", ")", "# 获取点击的item的索引", "# 由于右侧的widget是按照命名widget_0 widget_1这样比较规范的方法,可以通过getattr找到", "widget", "=", "getattr", "(", "self", ",", "'widget_%d...
https://github.com/PyQt5/PyQt/blob/d2bbfc9fd6f3fdb5ed5404983cdd0848aa654cf0/QScrollArea/QQSettingPanel.py#L46-L56
holzschu/Carnets
44effb10ddfc6aa5c8b0687582a724ba82c6b547
Library/lib/python3.7/site-packages/pandas-0.24.2-py3.7-macosx-10.9-x86_64.egg/pandas/core/internals/blocks.py
python
Block.is_datelike
(self)
return self.is_datetime or self.is_timedelta
return True if I am a non-datelike
return True if I am a non-datelike
[ "return", "True", "if", "I", "am", "a", "non", "-", "datelike" ]
def is_datelike(self): """ return True if I am a non-datelike """ return self.is_datetime or self.is_timedelta
[ "def", "is_datelike", "(", "self", ")", ":", "return", "self", ".", "is_datetime", "or", "self", ".", "is_timedelta" ]
https://github.com/holzschu/Carnets/blob/44effb10ddfc6aa5c8b0687582a724ba82c6b547/Library/lib/python3.7/site-packages/pandas-0.24.2-py3.7-macosx-10.9-x86_64.egg/pandas/core/internals/blocks.py#L142-L144
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/rings/asymptotic/growth_group.py
python
MonomialGrowthGroup.factory
(cls, base, var, extend_by_non_growth_group=False, return_factors=False, **kwds)
r""" Create a monomial growth group. INPUT: - ``base``, ``var``, keywords -- use in the initialization of the exponential growth group; see :class:`MonomialGrowthGroup` for details. - ``extend_by_non_growth_group`` -- a boolean (default ``False``). If set, then the growth group consists of two parts, one part dealing with the absolute values of the bases and one for their arguments. - ``return_factors`` -- a boolean (default: ``False``). If set, then a tuple of the (cartesian) factors of this growth group is returned. OUTPUT: A growth group or tuple of growth groups. EXAMPLES:: sage: from sage.rings.asymptotic.growth_group import MonomialGrowthGroup sage: from sage.groups.misc_gps.imaginary_groups import ImaginaryGroup sage: MonomialGrowthGroup.factory(ZZ, 'n') Growth Group n^ZZ sage: MonomialGrowthGroup.factory(ImaginaryGroup(ZZ), 'n') Growth Group n^(ZZ*I) TESTS:: sage: MonomialGrowthGroup.factory(ZZ, 'n', return_factors=True) (Growth Group n^ZZ,) sage: MonomialGrowthGroup.factory(ZZ, 'n', extend_by_non_growth_group=True) Growth Group n^ZZ * n^(ZZ*I) sage: MonomialGrowthGroup.factory(ZZ, 'n', return_factors=True, ....: extend_by_non_growth_group=True) (Growth Group n^ZZ, Growth Group n^(ZZ*I))
r""" Create a monomial growth group.
[ "r", "Create", "a", "monomial", "growth", "group", "." ]
def factory(cls, base, var, extend_by_non_growth_group=False, return_factors=False, **kwds): r""" Create a monomial growth group. INPUT: - ``base``, ``var``, keywords -- use in the initialization of the exponential growth group; see :class:`MonomialGrowthGroup` for details. - ``extend_by_non_growth_group`` -- a boolean (default ``False``). If set, then the growth group consists of two parts, one part dealing with the absolute values of the bases and one for their arguments. - ``return_factors`` -- a boolean (default: ``False``). If set, then a tuple of the (cartesian) factors of this growth group is returned. OUTPUT: A growth group or tuple of growth groups. EXAMPLES:: sage: from sage.rings.asymptotic.growth_group import MonomialGrowthGroup sage: from sage.groups.misc_gps.imaginary_groups import ImaginaryGroup sage: MonomialGrowthGroup.factory(ZZ, 'n') Growth Group n^ZZ sage: MonomialGrowthGroup.factory(ImaginaryGroup(ZZ), 'n') Growth Group n^(ZZ*I) TESTS:: sage: MonomialGrowthGroup.factory(ZZ, 'n', return_factors=True) (Growth Group n^ZZ,) sage: MonomialGrowthGroup.factory(ZZ, 'n', extend_by_non_growth_group=True) Growth Group n^ZZ * n^(ZZ*I) sage: MonomialGrowthGroup.factory(ZZ, 'n', return_factors=True, ....: extend_by_non_growth_group=True) (Growth Group n^ZZ, Growth Group n^(ZZ*I)) """ from sage.categories.cartesian_product import cartesian_product from sage.groups.misc_gps.imaginary_groups import ImaginaryGroup if isinstance(base, ImaginaryGroup): groups = (cls._non_growth_group_class_(base, var, **kwds),) elif extend_by_non_growth_group: M = cls(base, var, **kwds) groups = (M, M.non_growth_group()) else: groups = (cls(base, var, **kwds),) if return_factors: return tuple(groups) else: return cartesian_product(groups)
[ "def", "factory", "(", "cls", ",", "base", ",", "var", ",", "extend_by_non_growth_group", "=", "False", ",", "return_factors", "=", "False", ",", "*", "*", "kwds", ")", ":", "from", "sage", ".", "categories", ".", "cartesian_product", "import", "cartesian_pr...
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/rings/asymptotic/growth_group.py#L3771-L3830
jilljenn/tryalgo
46da31aea9a0ff58819e360c987f9506b21f6e9d
tryalgo/laser_mirrors.py
python
laser_mirrors
(rows, cols, mir)
return None
Orienting mirrors to allow reachability by laser beam :param int rows: :param int cols: rows and cols are the dimension of the grid :param mir: list of mirror coordinates, except mir[0]= laser entrance, mir[-1]= laser exit. :complexity: :math:`O(2^n)`
Orienting mirrors to allow reachability by laser beam
[ "Orienting", "mirrors", "to", "allow", "reachability", "by", "laser", "beam" ]
def laser_mirrors(rows, cols, mir): """Orienting mirrors to allow reachability by laser beam :param int rows: :param int cols: rows and cols are the dimension of the grid :param mir: list of mirror coordinates, except mir[0]= laser entrance, mir[-1]= laser exit. :complexity: :math:`O(2^n)` """ # build structures n = len(mir) orien = [None] * (n + 2) orien[n] = 0 # arbitrary orientations orien[n + 1] = 0 succ = [[None for direc in range(4)] for i in range(n + 2)] L = [(mir[i][0], mir[i][1], i) for i in range(n)] L.append((0, -1, n)) # enter L.append((0, cols, n + 1)) # exit last_r, last_i = None, None for (r, c, i) in sorted(L): # sweep by row if last_r == r: succ[i][LEFT] = last_i succ[last_i][RIGHT] = i last_r, last_i = r, i last_c = None for (r, c, i) in sorted(L, key=lambda rci: (rci[1], rci[0])): if last_c == c: # sweep by column succ[i][UP] = last_i succ[last_i][DOWN] = i last_c, last_i = c, i if solve(succ, orien, n, RIGHT): # exploration return orien[:n] return None
[ "def", "laser_mirrors", "(", "rows", ",", "cols", ",", "mir", ")", ":", "# build structures", "n", "=", "len", "(", "mir", ")", "orien", "=", "[", "None", "]", "*", "(", "n", "+", "2", ")", "orien", "[", "n", "]", "=", "0", "# arbitrary orientation...
https://github.com/jilljenn/tryalgo/blob/46da31aea9a0ff58819e360c987f9506b21f6e9d/tryalgo/laser_mirrors.py#L21-L54
Abjad/abjad
d0646dfbe83db3dc5ab268f76a0950712b87b7fd
abjad/parsers/parser.py
python
GuileProxy.skip
(self, duration)
return leaf
r""" Handles LilyPond ``\skip`` command.
r""" Handles LilyPond ``\skip`` command.
[ "r", "Handles", "LilyPond", "\\", "skip", "command", "." ]
def skip(self, duration): r""" Handles LilyPond ``\skip`` command. """ leaf = Skip(duration.duration) if duration.multiplier is not None: attach(duration.multiplier, leaf) return leaf
[ "def", "skip", "(", "self", ",", "duration", ")", ":", "leaf", "=", "Skip", "(", "duration", ".", "duration", ")", "if", "duration", ".", "multiplier", "is", "not", "None", ":", "attach", "(", "duration", ".", "multiplier", ",", "leaf", ")", "return", ...
https://github.com/Abjad/abjad/blob/d0646dfbe83db3dc5ab268f76a0950712b87b7fd/abjad/parsers/parser.py#L475-L482
metabrainz/picard
535bf8c7d9363ffc7abb3f69418ec11823c38118
picard/script/functions.py
python
func_eq
(parser, x, y)
[]
def func_eq(parser, x, y): if x == y: return "1" else: return ""
[ "def", "func_eq", "(", "parser", ",", "x", ",", "y", ")", ":", "if", "x", "==", "y", ":", "return", "\"1\"", "else", ":", "return", "\"\"" ]
https://github.com/metabrainz/picard/blob/535bf8c7d9363ffc7abb3f69418ec11823c38118/picard/script/functions.py#L662-L666
plotly/plotly.py
cfad7862594b35965c0e000813bd7805e8494a5b
packages/python/plotly/plotly/graph_objs/layout/_title.py
python
Title.x
(self)
return self["x"]
Sets the x position with respect to `xref` in normalized coordinates from 0 (left) to 1 (right). The 'x' property is a number and may be specified as: - An int or float in the interval [0, 1] Returns ------- int|float
Sets the x position with respect to `xref` in normalized coordinates from 0 (left) to 1 (right). The 'x' property is a number and may be specified as: - An int or float in the interval [0, 1]
[ "Sets", "the", "x", "position", "with", "respect", "to", "xref", "in", "normalized", "coordinates", "from", "0", "(", "left", ")", "to", "1", "(", "right", ")", ".", "The", "x", "property", "is", "a", "number", "and", "may", "be", "specified", "as", ...
def x(self): """ Sets the x position with respect to `xref` in normalized coordinates from 0 (left) to 1 (right). The 'x' property is a number and may be specified as: - An int or float in the interval [0, 1] Returns ------- int|float """ return self["x"]
[ "def", "x", "(", "self", ")", ":", "return", "self", "[", "\"x\"", "]" ]
https://github.com/plotly/plotly.py/blob/cfad7862594b35965c0e000813bd7805e8494a5b/packages/python/plotly/plotly/graph_objs/layout/_title.py#L139-L151
tobiasfshr/MOTSFusion
32fa6d7d3282c5046e45842370d225fa5a06603e
external/BB2SegNet/refinement_net/network/deeplab/core/preprocess_utils.py
python
resolve_shape
(tensor, rank=None, scope=None)
Fully resolves the shape of a Tensor. Use as much as possible the shape components already known during graph creation and resolve the remaining ones during runtime. Args: tensor: Input tensor whose shape we query. rank: The rank of the tensor, provided that we know it. scope: Optional name scope. Returns: shape: The full shape of the tensor.
Fully resolves the shape of a Tensor.
[ "Fully", "resolves", "the", "shape", "of", "a", "Tensor", "." ]
def resolve_shape(tensor, rank=None, scope=None): """Fully resolves the shape of a Tensor. Use as much as possible the shape components already known during graph creation and resolve the remaining ones during runtime. Args: tensor: Input tensor whose shape we query. rank: The rank of the tensor, provided that we know it. scope: Optional name scope. Returns: shape: The full shape of the tensor. """ with tf.name_scope(scope, 'resolve_shape', [tensor]): if rank is not None: shape = tensor.get_shape().with_rank(rank).as_list() else: shape = tensor.get_shape().as_list() if None in shape: shape_dynamic = tf.shape(tensor) for i in range(len(shape)): if shape[i] is None: shape[i] = shape_dynamic[i] return shape
[ "def", "resolve_shape", "(", "tensor", ",", "rank", "=", "None", ",", "scope", "=", "None", ")", ":", "with", "tf", ".", "name_scope", "(", "scope", ",", "'resolve_shape'", ",", "[", "tensor", "]", ")", ":", "if", "rank", "is", "not", "None", ":", ...
https://github.com/tobiasfshr/MOTSFusion/blob/32fa6d7d3282c5046e45842370d225fa5a06603e/external/BB2SegNet/refinement_net/network/deeplab/core/preprocess_utils.py#L317-L343
openstack/barbican
a9d2b133c8dc3307974f119f9a2b23a4ba82e8ce
barbican/common/config.py
python
list_opts
()
[]
def list_opts(): yield None, context_opts yield None, common_opts yield None, host_opts yield None, db_opts yield None, _options.eventlet_backdoor_opts yield retry_opt_group, retry_opts yield queue_opt_group, queue_opts yield ks_queue_opt_group, ks_queue_opts yield quota_opt_group, quota_opts
[ "def", "list_opts", "(", ")", ":", "yield", "None", ",", "context_opts", "yield", "None", ",", "common_opts", "yield", "None", ",", "host_opts", "yield", "None", ",", "db_opts", "yield", "None", ",", "_options", ".", "eventlet_backdoor_opts", "yield", "retry_o...
https://github.com/openstack/barbican/blob/a9d2b133c8dc3307974f119f9a2b23a4ba82e8ce/barbican/common/config.py#L236-L245
textX/textX
452b684d434c557a63ff7ae2b014770c29669e4c
textx/registration.py
python
register_generator
(generator_desc_or_language, target=None, description='', generator=None)
Programmatically register a generator. Args: generator_desc_or_language (GeneratorDesc or str): If GeneratorDesc is given other parameters are not used. For other parameters see `GeneratorDesc`.
Programmatically register a generator.
[ "Programmatically", "register", "a", "generator", "." ]
def register_generator(generator_desc_or_language, target=None, description='', generator=None): """ Programmatically register a generator. Args: generator_desc_or_language (GeneratorDesc or str): If GeneratorDesc is given other parameters are not used. For other parameters see `GeneratorDesc`. """ global generators if generators is None: generator_descriptions() if not isinstance(generator_desc_or_language, GeneratorDesc): generator_desc = GeneratorDesc( language=generator_desc_or_language, target=target, description=description, generator=generator ) else: generator_desc = generator_desc_or_language lang_gens = generators.setdefault(generator_desc.language.lower(), {}) if generator_desc.target.lower() in lang_gens: raise TextXRegistrationError( 'Generator "{}->{}" already registered.'.format( generator_desc.language, generator_desc.target)) lang_gens[generator_desc.target.lower()] = generator_desc
[ "def", "register_generator", "(", "generator_desc_or_language", ",", "target", "=", "None", ",", "description", "=", "''", ",", "generator", "=", "None", ")", ":", "global", "generators", "if", "generators", "is", "None", ":", "generator_descriptions", "(", ")",...
https://github.com/textX/textX/blob/452b684d434c557a63ff7ae2b014770c29669e4c/textx/registration.py#L203-L232
jtriley/StarCluster
bc7c950e73f193eac9aab986b6764939cfdad978
starcluster/cluster.py
python
ClusterValidator.validate
(self)
Checks that all cluster template settings are valid and raises an exception.ClusterValidationError exception if not.
Checks that all cluster template settings are valid and raises an exception.ClusterValidationError exception if not.
[ "Checks", "that", "all", "cluster", "template", "settings", "are", "valid", "and", "raises", "an", "exception", ".", "ClusterValidationError", "exception", "if", "not", "." ]
def validate(self): """ Checks that all cluster template settings are valid and raises an exception.ClusterValidationError exception if not. """ log.info("Validating cluster template settings...") try: self.validate_required_settings() self.validate_vpc() self.validate_dns_prefix() self.validate_spot_bid() self.validate_cluster_size() self.validate_cluster_user() self.validate_shell_setting() self.validate_permission_settings() self.validate_credentials() self.validate_keypair() self.validate_zone() self.validate_ebs_settings() self.validate_ebs_aws_settings() self.validate_image_settings() self.validate_instance_types() self.validate_userdata() log.info('Cluster template settings are valid') return True except exception.ClusterValidationError as e: e.msg = 'Cluster settings are not valid:\n%s' % e.msg raise
[ "def", "validate", "(", "self", ")", ":", "log", ".", "info", "(", "\"Validating cluster template settings...\"", ")", "try", ":", "self", ".", "validate_required_settings", "(", ")", "self", ".", "validate_vpc", "(", ")", "self", ".", "validate_dns_prefix", "("...
https://github.com/jtriley/StarCluster/blob/bc7c950e73f193eac9aab986b6764939cfdad978/starcluster/cluster.py#L1798-L1825
googledatalab/pydatalab
1c86e26a0d24e3bc8097895ddeab4d0607be4c40
datalab/bigquery/_table.py
python
Table.to_query
(self, fields=None)
return _query.Query('SELECT %s FROM %s' % (fields, self._repr_sql_()), context=self._context)
Return a Query for this Table. Args: fields: the fields to return. If None, all fields will be returned. This can be a string which will be injected into the Query after SELECT, or a list of field names. Returns: A Query object that will return the specified fields from the records in the Table.
Return a Query for this Table.
[ "Return", "a", "Query", "for", "this", "Table", "." ]
def to_query(self, fields=None): """ Return a Query for this Table. Args: fields: the fields to return. If None, all fields will be returned. This can be a string which will be injected into the Query after SELECT, or a list of field names. Returns: A Query object that will return the specified fields from the records in the Table. """ # Do import here to avoid top-level circular dependencies. from . import _query if fields is None: fields = '*' elif isinstance(fields, list): fields = ','.join(fields) return _query.Query('SELECT %s FROM %s' % (fields, self._repr_sql_()), context=self._context)
[ "def", "to_query", "(", "self", ",", "fields", "=", "None", ")", ":", "# Do import here to avoid top-level circular dependencies.", "from", ".", "import", "_query", "if", "fields", "is", "None", ":", "fields", "=", "'*'", "elif", "isinstance", "(", "fields", ","...
https://github.com/googledatalab/pydatalab/blob/1c86e26a0d24e3bc8097895ddeab4d0607be4c40/datalab/bigquery/_table.py#L914-L930
kubernetes-client/python
47b9da9de2d02b2b7a34fbe05afb44afd130d73a
kubernetes/client/models/v1_volume_error.py
python
V1VolumeError.message
(self)
return self._message
Gets the message of this V1VolumeError. # noqa: E501 String detailing the error encountered during Attach or Detach operation. This string may be logged, so it should not contain sensitive information. # noqa: E501 :return: The message of this V1VolumeError. # noqa: E501 :rtype: str
Gets the message of this V1VolumeError. # noqa: E501
[ "Gets", "the", "message", "of", "this", "V1VolumeError", ".", "#", "noqa", ":", "E501" ]
def message(self): """Gets the message of this V1VolumeError. # noqa: E501 String detailing the error encountered during Attach or Detach operation. This string may be logged, so it should not contain sensitive information. # noqa: E501 :return: The message of this V1VolumeError. # noqa: E501 :rtype: str """ return self._message
[ "def", "message", "(", "self", ")", ":", "return", "self", ".", "_message" ]
https://github.com/kubernetes-client/python/blob/47b9da9de2d02b2b7a34fbe05afb44afd130d73a/kubernetes/client/models/v1_volume_error.py#L61-L69
mcfletch/pyopengl
02d11dad9ff18e50db10e975c4756e17bf198464
OpenGL/GL/INTEL/fragment_shader_ordering.py
python
glInitFragmentShaderOrderingINTEL
()
return extensions.hasGLExtension( _EXTENSION_NAME )
Return boolean indicating whether this extension is available
Return boolean indicating whether this extension is available
[ "Return", "boolean", "indicating", "whether", "this", "extension", "is", "available" ]
def glInitFragmentShaderOrderingINTEL(): '''Return boolean indicating whether this extension is available''' from OpenGL import extensions return extensions.hasGLExtension( _EXTENSION_NAME )
[ "def", "glInitFragmentShaderOrderingINTEL", "(", ")", ":", "from", "OpenGL", "import", "extensions", "return", "extensions", ".", "hasGLExtension", "(", "_EXTENSION_NAME", ")" ]
https://github.com/mcfletch/pyopengl/blob/02d11dad9ff18e50db10e975c4756e17bf198464/OpenGL/GL/INTEL/fragment_shader_ordering.py#L45-L48
sendgrid/sendgrid-python
df13b78b0cdcb410b4516f6761c4d3138edd4b2d
sendgrid/helpers/mail/batch_id.py
python
BatchId.get
(self)
return self.batch_id
Get a JSON-ready representation of this BatchId object. :returns: The BatchId, ready for use in a request body. :rtype: string
Get a JSON-ready representation of this BatchId object.
[ "Get", "a", "JSON", "-", "ready", "representation", "of", "this", "BatchId", "object", "." ]
def get(self): """ Get a JSON-ready representation of this BatchId object. :returns: The BatchId, ready for use in a request body. :rtype: string """ return self.batch_id
[ "def", "get", "(", "self", ")", ":", "return", "self", ".", "batch_id" ]
https://github.com/sendgrid/sendgrid-python/blob/df13b78b0cdcb410b4516f6761c4d3138edd4b2d/sendgrid/helpers/mail/batch_id.py#L43-L50
pypa/pipenv
b21baade71a86ab3ee1429f71fbc14d4f95fb75d
pipenv/vendor/dparse/parser.py
python
RequirementsTXTParser.parse
(self)
Parses a requirements.txt-like file
Parses a requirements.txt-like file
[ "Parses", "a", "requirements", ".", "txt", "-", "like", "file" ]
def parse(self): """ Parses a requirements.txt-like file """ index_server = None for num, line in enumerate(self.iter_lines()): line = line.rstrip() if not line: continue if line.startswith('#'): # comments are lines that start with # only continue if line.startswith('-i') or \ line.startswith('--index-url') or \ line.startswith('--extra-index-url'): # this file is using a private index server, try to parse it index_server = self.parse_index_server(line) continue elif self.obj.path and (line.startswith('-r') or line.startswith('--requirement')): self.obj.resolved_files.append(self.resolve_file(self.obj.path, line)) elif line.startswith('-f') or line.startswith('--find-links') or \ line.startswith('--no-index') or line.startswith('--allow-external') or \ line.startswith('--allow-unverified') or line.startswith('-Z') or \ line.startswith('--always-unzip'): continue elif self.is_marked_line(line): continue else: try: parseable_line = line # multiline requirements are not parseable if "\\" in line: parseable_line = line.replace("\\", "") for next_line in self.iter_lines(num + 1): parseable_line += next_line.strip().replace("\\", "") line += "\n" + next_line if "\\" in next_line: continue break # ignore multiline requirements if they are marked if self.is_marked_line(parseable_line): continue hashes = [] if "--hash" in parseable_line: parseable_line, hashes = Parser.parse_hashes(parseable_line) req = RequirementsTXTLineParser.parse(parseable_line) if req: req.hashes = hashes req.index_server = index_server # replace the requirements line with the 'real' line req.line = line self.obj.dependencies.append(req) except ValueError: continue
[ "def", "parse", "(", "self", ")", ":", "index_server", "=", "None", "for", "num", ",", "line", "in", "enumerate", "(", "self", ".", "iter_lines", "(", ")", ")", ":", "line", "=", "line", ".", "rstrip", "(", ")", "if", "not", "line", ":", "continue"...
https://github.com/pypa/pipenv/blob/b21baade71a86ab3ee1429f71fbc14d4f95fb75d/pipenv/vendor/dparse/parser.py#L207-L264