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
ulif/diceware
5d909b5e2f8efdd8dfe53a4f68c50f7710961dc0
diceware/config.py
python
string_to_wlist_list
(text)
return [name for name in re.split(RE_WLIST_NAME, text) if name != ""]
Split string into list of valid wordlist names.
Split string into list of valid wordlist names.
[ "Split", "string", "into", "list", "of", "valid", "wordlist", "names", "." ]
def string_to_wlist_list(text): """Split string into list of valid wordlist names. """ return [name for name in re.split(RE_WLIST_NAME, text) if name != ""]
[ "def", "string_to_wlist_list", "(", "text", ")", ":", "return", "[", "name", "for", "name", "in", "re", ".", "split", "(", "RE_WLIST_NAME", ",", "text", ")", "if", "name", "!=", "\"\"", "]" ]
https://github.com/ulif/diceware/blob/5d909b5e2f8efdd8dfe53a4f68c50f7710961dc0/diceware/config.py#L70-L73
appliedsec/pygeoip
2a725df0b727e8b08f217ab84f7b8243c42554f5
pygeoip/__init__.py
python
GeoIP.region_by_addr
(self, addr)
return self._get_region(ipnum)
Returns dictionary containing `country_code` and `region_code`. :arg addr: IP address (e.g. 203.0.113.30)
Returns dictionary containing `country_code` and `region_code`.
[ "Returns", "dictionary", "containing", "country_code", "and", "region_code", "." ]
def region_by_addr(self, addr): """ Returns dictionary containing `country_code` and `region_code`. :arg addr: IP address (e.g. 203.0.113.30) """ if self._databaseType not in const.REGION_CITY_EDITIONS: message = 'Invalid database type, expected Region or City' raise GeoIPError(message) ipnum = util.ip2long(addr) return self._get_region(ipnum)
[ "def", "region_by_addr", "(", "self", ",", "addr", ")", ":", "if", "self", ".", "_databaseType", "not", "in", "const", ".", "REGION_CITY_EDITIONS", ":", "message", "=", "'Invalid database type, expected Region or City'", "raise", "GeoIPError", "(", "message", ")", ...
https://github.com/appliedsec/pygeoip/blob/2a725df0b727e8b08f217ab84f7b8243c42554f5/pygeoip/__init__.py#L564-L575
securesystemslab/zippy
ff0e84ac99442c2c55fe1d285332cfd4e185e089
zippy/lib-python/3/mailbox.py
python
MaildirMessage.get_flags
(self)
Return as a string the flags that are set.
Return as a string the flags that are set.
[ "Return", "as", "a", "string", "the", "flags", "that", "are", "set", "." ]
def get_flags(self): """Return as a string the flags that are set.""" if self._info.startswith('2,'): return self._info[2:] else: return ''
[ "def", "get_flags", "(", "self", ")", ":", "if", "self", ".", "_info", ".", "startswith", "(", "'2,'", ")", ":", "return", "self", ".", "_info", "[", "2", ":", "]", "else", ":", "return", "''" ]
https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/lib-python/3/mailbox.py#L1501-L1506
biolab/orange3
41685e1c7b1d1babe680113685a2d44bcc9fec0b
Orange/widgets/utils/graphicstextlist.py
python
TextListWidget.__setup
(self)
[]
def __setup(self) -> None: self.__clear() font = self.__effectiveFont if self.__autoScale else self.font() assert self.__group is None group = QGraphicsItemGroup() for text in self.__items: t = QGraphicsSimpleTextItem(group) t.setFont(font) t.setText(text) t.setData(0, text) self.__textitems.append(t) group.setParentItem(self) self.__group = group
[ "def", "__setup", "(", "self", ")", "->", "None", ":", "self", ".", "__clear", "(", ")", "font", "=", "self", ".", "__effectiveFont", "if", "self", ".", "__autoScale", "else", "self", ".", "font", "(", ")", "assert", "self", ".", "__group", "is", "No...
https://github.com/biolab/orange3/blob/41685e1c7b1d1babe680113685a2d44bcc9fec0b/Orange/widgets/utils/graphicstextlist.py#L248-L260
peering-manager/peering-manager
62c870fb9caa6dfc056feb77c595d45bc3c4988a
peering/views.py
python
CommunityDetails.get_context
(self, request, **kwargs)
return { "instance": get_object_or_404(self.queryset, **kwargs), "active_tab": "main", }
[]
def get_context(self, request, **kwargs): return { "instance": get_object_or_404(self.queryset, **kwargs), "active_tab": "main", }
[ "def", "get_context", "(", "self", ",", "request", ",", "*", "*", "kwargs", ")", ":", "return", "{", "\"instance\"", ":", "get_object_or_404", "(", "self", ".", "queryset", ",", "*", "*", "kwargs", ")", ",", "\"active_tab\"", ":", "\"main\"", ",", "}" ]
https://github.com/peering-manager/peering-manager/blob/62c870fb9caa6dfc056feb77c595d45bc3c4988a/peering/views.py#L448-L452
rikdz/GraphWriter
f228420aa48697dfb7a1ced3a62f955031664ed3
vectorize.py
python
dataset.bszFn
(self,e,l,c)
return c+len(e.out)
[]
def bszFn(self,e,l,c): return c+len(e.out)
[ "def", "bszFn", "(", "self", ",", "e", ",", "l", ",", "c", ")", ":", "return", "c", "+", "len", "(", "e", ".", "out", ")" ]
https://github.com/rikdz/GraphWriter/blob/f228420aa48697dfb7a1ced3a62f955031664ed3/vectorize.py#L160-L161
haiwen/seafile-docker
2d2461d4c8cab3458ec9832611c419d47506c300
scripts_9.0/setup-seafile-mysql.py
python
main
()
[]
def main(): if len(sys.argv) > 2 and sys.argv[1] == 'auto': sys.argv.remove('auto') parser = argparse.ArgumentParser() parser.add_argument('-n', '--server-name', help='server name') parser.add_argument('-i', '--server-ip', help='server ip or domain') parser.add_argument('-p', '--fileserver-port', help='fileserver port') parser.add_argument('-d', '--seafile-dir', help='seafile dir to store seafile data') parser.add_argument('-e', '--use-existing-db', help='use mysql existing dbs or create new dbs, ' '0: create new dbs 1: use existing dbs') parser.add_argument('-o', '--mysql-host', help='mysql host') parser.add_argument('-t', '--mysql-port', help='mysql port') parser.add_argument('-u', '--mysql-user', help='mysql user name') parser.add_argument('-w', '--mysql-user-passwd', help='mysql user password') parser.add_argument('-q', '--mysql-user-host', help='mysql user host') parser.add_argument('-r', '--mysql-root-passwd', help='mysql root password') parser.add_argument('-c', '--ccnet-db', help='ccnet db name') parser.add_argument('-s', '--seafile-db', help='seafile db name') parser.add_argument('-b', '--seahub-db', help='seahub db name') args = parser.parse_args() try: check_params(args) except (InvalidAnswer, InvalidParams) as e: print(Utils.highlight('\n%s\n' % e)) sys.exit(-1) global db_config if need_pause: Utils.welcome() warnings.filterwarnings('ignore', category=pymysql.Warning) env_mgr.check_pre_condiction() # Part 1: collect configuration ccnet_config.ask_questions() seafile_config.ask_questions() seahub_config.ask_questions() pro_config.ask_questions() # pylint: disable=redefined-variable-type if not db_config: if AbstractDBConfigurator.ask_use_existing_db(): db_config = ExistingDBConfigurator() else: db_config = NewDBConfigurator() db_config.ask_questions() report_config() # Part 2: generate configuration db_config.generate() ccnet_config.generate() seafile_config.generate() seafdav_config.generate() gunicorn_config.generate() seahub_config.generate() pro_config.generate() seahub_config.prepare_avatar_dir() # db_config.create_seahub_admin() user_manuals_handler.copy_user_manuals() #create_seafile_server_symlink() set_file_perm() report_success()
[ "def", "main", "(", ")", ":", "if", "len", "(", "sys", ".", "argv", ")", ">", "2", "and", "sys", ".", "argv", "[", "1", "]", "==", "'auto'", ":", "sys", ".", "argv", ".", "remove", "(", "'auto'", ")", "parser", "=", "argparse", ".", "ArgumentPa...
https://github.com/haiwen/seafile-docker/blob/2d2461d4c8cab3458ec9832611c419d47506c300/scripts_9.0/setup-seafile-mysql.py#L1412-L1482
MycroftAI/mycroft-precise
e1a635e9675047eb86f64ca489a1b941321c489a
precise/model.py
python
load_precise_model
(model_name: str)
return load_keras().models.load_model(model_name)
Loads a Keras model from file, handling custom loss function
Loads a Keras model from file, handling custom loss function
[ "Loads", "a", "Keras", "model", "from", "file", "handling", "custom", "loss", "function" ]
def load_precise_model(model_name: str) -> Any: """Loads a Keras model from file, handling custom loss function""" if not model_name.endswith('.net'): print('Warning: Unknown model type, ', model_name) inject_params(model_name) return load_keras().models.load_model(model_name)
[ "def", "load_precise_model", "(", "model_name", ":", "str", ")", "->", "Any", ":", "if", "not", "model_name", ".", "endswith", "(", "'.net'", ")", ":", "print", "(", "'Warning: Unknown model type, '", ",", "model_name", ")", "inject_params", "(", "model_name", ...
https://github.com/MycroftAI/mycroft-precise/blob/e1a635e9675047eb86f64ca489a1b941321c489a/precise/model.py#L48-L54
IronLanguages/ironpython3
7a7bb2a872eeab0d1009fc8a6e24dca43f65b693
Src/StdLib/Lib/xmlrpc/client.py
python
Binary.decode
(self, data)
[]
def decode(self, data): self.data = base64.decodebytes(data)
[ "def", "decode", "(", "self", ",", "data", ")", ":", "self", ".", "data", "=", "base64", ".", "decodebytes", "(", "data", ")" ]
https://github.com/IronLanguages/ironpython3/blob/7a7bb2a872eeab0d1009fc8a6e24dca43f65b693/Src/StdLib/Lib/xmlrpc/client.py#L414-L415
s-leger/archipack
5a6243bf1edf08a6b429661ce291dacb551e5f8a
pygeos/op_union.py
python
CascadedUnion.reduceToGeometries
(self, geomTree)
return geoms
* Reduces a tree of geometries to a list of geometries * by recursively unioning the subtrees in the list. * * @param geomTree a tree-structured list of geometries * @return a list of Geometrys
* Reduces a tree of geometries to a list of geometries * by recursively unioning the subtrees in the list. * *
[ "*", "Reduces", "a", "tree", "of", "geometries", "to", "a", "list", "of", "geometries", "*", "by", "recursively", "unioning", "the", "subtrees", "in", "the", "list", ".", "*", "*" ]
def reduceToGeometries(self, geomTree): """ * Reduces a tree of geometries to a list of geometries * by recursively unioning the subtrees in the list. * * @param geomTree a tree-structured list of geometries * @return a list of Geometrys """ # logger.debug("%s.reduceToGeometries:\n%s", type(self).__name__, geomTree) geoms = [] for item in geomTree: if item.t == ItemsListItem.item_is_list: geom = self.unionTree(item.l) geoms.append(geom) elif item.t == ItemsListItem.item_is_geometry: geoms.append(item.g) else: assert(0), "should never be reached" return geoms
[ "def", "reduceToGeometries", "(", "self", ",", "geomTree", ")", ":", "# logger.debug(\"%s.reduceToGeometries:\\n%s\", type(self).__name__, geomTree)", "geoms", "=", "[", "]", "for", "item", "in", "geomTree", ":", "if", "item", ".", "t", "==", "ItemsListItem", ".", "...
https://github.com/s-leger/archipack/blob/5a6243bf1edf08a6b429661ce291dacb551e5f8a/pygeos/op_union.py#L150-L170
chainer/chainerui
91c5c26d9154a008079dbb0bcbf69b5590d105f7
chainerui/views/result.py
python
ResultAPI.get
(self, id=None, project_id=None)
get.
get.
[ "get", "." ]
def get(self, id=None, project_id=None): """get.""" logs_limit = request.args.get('logs_limit', default=-1, type=int) is_unregistered = request.args.get( 'is_unregistered', default=False, type=bool) project = db.session.query(Project).filter_by( id=project_id).first() if project is None: return jsonify({ 'project': None, 'message': 'No interface defined for URL.' }), 404 if id is None: path = request.args.get('path_name', default=None) if path is not None: result = db.session.query(Result).filter_by( path_name=path).first() if result is None: return jsonify({ 'result': None, 'message': 'Result path \'%s\' is not found' % path }), 400 return jsonify({'result': result.serialize}) collect_results(project) results = db.session.query(Result).\ filter_by(project_id=project_id).\ filter_by(is_unregistered=is_unregistered).\ all() # NOTE: To improve performance, aggregate commit phase. By set # `commit=False`, implicit transaction is not closed, UPDATE query # is not committed. Consequently a process of serializing does not # have to call SELECT query again. for result in results: crawl_result(result, commit=False) db.session.commit() rs = [r.serialize_with_sampled_logs(logs_limit) for r in results] return jsonify({'results': rs}) else: result = db.session.query(Result).\ filter_by(id=id).\ filter_by(is_unregistered=False).\ first() if result is None: return jsonify({ 'result': None, 'message': 'No interface defined for URL.' }), 404 result = crawl_result(result) return jsonify({ 'result': result.serialize_with_sampled_logs(logs_limit) })
[ "def", "get", "(", "self", ",", "id", "=", "None", ",", "project_id", "=", "None", ")", ":", "logs_limit", "=", "request", ".", "args", ".", "get", "(", "'logs_limit'", ",", "default", "=", "-", "1", ",", "type", "=", "int", ")", "is_unregistered", ...
https://github.com/chainer/chainerui/blob/91c5c26d9154a008079dbb0bcbf69b5590d105f7/chainerui/views/result.py#L17-L78
dbt-labs/dbt-core
e943b9fc842535e958ef4fd0b8703adc91556bc6
core/dbt/task/runnable.py
python
GraphRunnableTask.run
(self)
return result
Run dbt for the query, based on the graph.
Run dbt for the query, based on the graph.
[ "Run", "dbt", "for", "the", "query", "based", "on", "the", "graph", "." ]
def run(self): """ Run dbt for the query, based on the graph. """ self._runtime_initialize() if self._flattened_nodes is None: raise InternalException( 'after _runtime_initialize, _flattened_nodes was still None' ) if len(self._flattened_nodes) == 0: with TextOnly(): fire_event(EmptyLine()) msg = "Nothing to do. Try checking your model " \ "configs and model specification args" warn_or_error(msg, log_fmt=warning_tag('{}')) result = self.get_result( results=[], generated_at=datetime.utcnow(), elapsed_time=0.0, ) else: with TextOnly(): fire_event(EmptyLine()) selected_uids = frozenset(n.unique_id for n in self._flattened_nodes) result = self.execute_with_hooks(selected_uids) if flags.WRITE_JSON: self.write_manifest() self.write_result(result) self.task_end_messages(result.results) return result
[ "def", "run", "(", "self", ")", ":", "self", ".", "_runtime_initialize", "(", ")", "if", "self", ".", "_flattened_nodes", "is", "None", ":", "raise", "InternalException", "(", "'after _runtime_initialize, _flattened_nodes was still None'", ")", "if", "len", "(", "...
https://github.com/dbt-labs/dbt-core/blob/e943b9fc842535e958ef4fd0b8703adc91556bc6/core/dbt/task/runnable.py#L450-L483
readbeyond/aeneas
4d200a050690903b30b3d885b44714fecb23f18a
bin/aeneas_check_setup.py
python
print_info
(msg)
Print an info message
Print an info message
[ "Print", "an", "info", "message" ]
def print_info(msg): """ Print an info message """ print(u"[INFO] %s" % (msg))
[ "def", "print_info", "(", "msg", ")", ":", "print", "(", "u\"[INFO] %s\"", "%", "(", "msg", ")", ")" ]
https://github.com/readbeyond/aeneas/blob/4d200a050690903b30b3d885b44714fecb23f18a/bin/aeneas_check_setup.py#L65-L67
learningequality/ka-lite
571918ea668013dcf022286ea85eff1c5333fb8b
kalite/packages/bundled/django/db/utils.py
python
ConnectionHandler.ensure_defaults
(self, alias)
Puts the defaults into the settings dictionary for a given connection where no settings is provided.
Puts the defaults into the settings dictionary for a given connection where no settings is provided.
[ "Puts", "the", "defaults", "into", "the", "settings", "dictionary", "for", "a", "given", "connection", "where", "no", "settings", "is", "provided", "." ]
def ensure_defaults(self, alias): """ Puts the defaults into the settings dictionary for a given connection where no settings is provided. """ try: conn = self.databases[alias] except KeyError: raise ConnectionDoesNotExist("The connection %s doesn't exist" % alias) conn.setdefault('ENGINE', 'django.db.backends.dummy') if conn['ENGINE'] == 'django.db.backends.' or not conn['ENGINE']: conn['ENGINE'] = 'django.db.backends.dummy' conn.setdefault('OPTIONS', {}) conn.setdefault('TIME_ZONE', 'UTC' if settings.USE_TZ else settings.TIME_ZONE) for setting in ['NAME', 'USER', 'PASSWORD', 'HOST', 'PORT']: conn.setdefault(setting, '') for setting in ['TEST_CHARSET', 'TEST_COLLATION', 'TEST_NAME', 'TEST_MIRROR']: conn.setdefault(setting, None)
[ "def", "ensure_defaults", "(", "self", ",", "alias", ")", ":", "try", ":", "conn", "=", "self", ".", "databases", "[", "alias", "]", "except", "KeyError", ":", "raise", "ConnectionDoesNotExist", "(", "\"The connection %s doesn't exist\"", "%", "alias", ")", "c...
https://github.com/learningequality/ka-lite/blob/571918ea668013dcf022286ea85eff1c5333fb8b/kalite/packages/bundled/django/db/utils.py#L67-L85
GeorgeSeif/Semantic-Segmentation-Suite
f04c94c2077a957bca0e8509b8ed2861769c4ba6
frontends/se_resnext.py
python
constant_xavier_initializer
(shape, group, dtype=tf.float32, uniform=True)
Initializer function.
Initializer function.
[ "Initializer", "function", "." ]
def constant_xavier_initializer(shape, group, dtype=tf.float32, uniform=True): """Initializer function.""" if not dtype.is_floating: raise TypeError('Cannot create initializer for non-floating point type.') # Estimating fan_in and fan_out is not possible to do perfectly, but we try. # This is the right thing for matrix multiply and convolutions. if shape: fan_in = float(shape[-2]) if len(shape) > 1 else float(shape[-1]) fan_out = float(shape[-1])/group else: fan_in = 1.0 fan_out = 1.0 for dim in shape[:-2]: fan_in *= float(dim) fan_out *= float(dim) # Average number of inputs and output connections. n = (fan_in + fan_out) / 2.0 if uniform: # To get stddev = math.sqrt(factor / n) need to adjust for uniform. limit = math.sqrt(3.0 * 1.0 / n) return tf.random_uniform(shape, -limit, limit, dtype, seed=None) else: # To get stddev = math.sqrt(factor / n) need to adjust for truncated. trunc_stddev = math.sqrt(1.3 * 1.0 / n) return tf.truncated_normal(shape, 0.0, trunc_stddev, dtype, seed=None)
[ "def", "constant_xavier_initializer", "(", "shape", ",", "group", ",", "dtype", "=", "tf", ".", "float32", ",", "uniform", "=", "True", ")", ":", "if", "not", "dtype", ".", "is_floating", ":", "raise", "TypeError", "(", "'Cannot create initializer for non-floati...
https://github.com/GeorgeSeif/Semantic-Segmentation-Suite/blob/f04c94c2077a957bca0e8509b8ed2861769c4ba6/frontends/se_resnext.py#L14-L39
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/Python-2.7.9/Lib/idlelib/EditorWindow.py
python
EditorWindow.RemoveKeybindings
(self)
Remove the keybindings before they are changed.
Remove the keybindings before they are changed.
[ "Remove", "the", "keybindings", "before", "they", "are", "changed", "." ]
def RemoveKeybindings(self): "Remove the keybindings before they are changed." # Called from configDialog.py self.Bindings.default_keydefs = keydefs = idleConf.GetCurrentKeySet() for event, keylist in keydefs.items(): self.text.event_delete(event, *keylist) for extensionName in self.get_standard_extension_names(): xkeydefs = idleConf.GetExtensionBindings(extensionName) if xkeydefs: for event, keylist in xkeydefs.items(): self.text.event_delete(event, *keylist)
[ "def", "RemoveKeybindings", "(", "self", ")", ":", "# Called from configDialog.py", "self", ".", "Bindings", ".", "default_keydefs", "=", "keydefs", "=", "idleConf", ".", "GetCurrentKeySet", "(", ")", "for", "event", ",", "keylist", "in", "keydefs", ".", "items"...
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/Python-2.7.9/Lib/idlelib/EditorWindow.py#L814-L824
apache/libcloud
90971e17bfd7b6bb97b2489986472c531cc8e140
libcloud/compute/drivers/cloudsigma.py
python
CloudSigma_1_0_NodeDriver.ex_set_node_configuration
(self, node, **kwargs)
return response.status == 200 and response.body != ""
Update a node configuration. Changing most of the parameters requires node to be stopped. :param node: Node which should be used :type node: :class:`libcloud.compute.base.Node` :param kwargs: keyword arguments :type kwargs: ``dict`` :rtype: ``bool``
Update a node configuration. Changing most of the parameters requires node to be stopped.
[ "Update", "a", "node", "configuration", ".", "Changing", "most", "of", "the", "parameters", "requires", "node", "to", "be", "stopped", "." ]
def ex_set_node_configuration(self, node, **kwargs): """ Update a node configuration. Changing most of the parameters requires node to be stopped. :param node: Node which should be used :type node: :class:`libcloud.compute.base.Node` :param kwargs: keyword arguments :type kwargs: ``dict`` :rtype: ``bool`` """ valid_keys = ( "^name$", "^parent$", "^cpu$", "^smp$", "^mem$", "^boot$", "^nic:0:model$", "^nic:0:dhcp", "^nic:1:model$", "^nic:1:vlan$", "^nic:1:mac$", "^vnc:ip$", "^vnc:password$", "^vnc:tls", "^ide:[0-1]:[0-1](:media)?$", "^scsi:0:[0-7](:media)?$", "^block:[0-7](:media)?$", ) invalid_keys = [] keys = list(kwargs.keys()) for key in keys: matches = False for regex in valid_keys: if re.match(regex, key): matches = True break if not matches: invalid_keys.append(key) if invalid_keys: raise CloudSigmaException( "Invalid configuration key specified: %s" % (",".join(invalid_keys)) ) response = self.connection.request( action="/servers/%s/set" % (node.id), data=dict2str(kwargs), method="POST" ) return response.status == 200 and response.body != ""
[ "def", "ex_set_node_configuration", "(", "self", ",", "node", ",", "*", "*", "kwargs", ")", ":", "valid_keys", "=", "(", "\"^name$\"", ",", "\"^parent$\"", ",", "\"^cpu$\"", ",", "\"^smp$\"", ",", "\"^mem$\"", ",", "\"^boot$\"", ",", "\"^nic:0:model$\"", ",", ...
https://github.com/apache/libcloud/blob/90971e17bfd7b6bb97b2489986472c531cc8e140/libcloud/compute/drivers/cloudsigma.py#L516-L569
fniephaus/alfred-pocket
c8ff8b23d708a746cce2888398cc566bef687a14
src/workflow/workflow.py
python
Workflow.decode
(self, text, encoding=None, normalization=None)
return unicodedata.normalize(normalization, text)
Return ``text`` as normalised unicode. If ``encoding`` and/or ``normalization`` is ``None``, the ``input_encoding``and ``normalization`` parameters passed to :class:`Workflow` are used. :param text: string :type text: encoded or Unicode string. If ``text`` is already a Unicode string, it will only be normalised. :param encoding: The text encoding to use to decode ``text`` to Unicode. :type encoding: ``unicode`` or ``None`` :param normalization: The nomalisation form to apply to ``text``. :type normalization: ``unicode`` or ``None`` :returns: decoded and normalised ``unicode`` :class:`Workflow` uses "NFC" normalisation by default. This is the standard for Python and will work well with data from the web (via :mod:`~workflow.web` or :mod:`json`). macOS, on the other hand, uses "NFD" normalisation (nearly), so data coming from the system (e.g. via :mod:`subprocess` or :func:`os.listdir`/:mod:`os.path`) may not match. You should either normalise this data, too, or change the default normalisation used by :class:`Workflow`.
Return ``text`` as normalised unicode.
[ "Return", "text", "as", "normalised", "unicode", "." ]
def decode(self, text, encoding=None, normalization=None): """Return ``text`` as normalised unicode. If ``encoding`` and/or ``normalization`` is ``None``, the ``input_encoding``and ``normalization`` parameters passed to :class:`Workflow` are used. :param text: string :type text: encoded or Unicode string. If ``text`` is already a Unicode string, it will only be normalised. :param encoding: The text encoding to use to decode ``text`` to Unicode. :type encoding: ``unicode`` or ``None`` :param normalization: The nomalisation form to apply to ``text``. :type normalization: ``unicode`` or ``None`` :returns: decoded and normalised ``unicode`` :class:`Workflow` uses "NFC" normalisation by default. This is the standard for Python and will work well with data from the web (via :mod:`~workflow.web` or :mod:`json`). macOS, on the other hand, uses "NFD" normalisation (nearly), so data coming from the system (e.g. via :mod:`subprocess` or :func:`os.listdir`/:mod:`os.path`) may not match. You should either normalise this data, too, or change the default normalisation used by :class:`Workflow`. """ encoding = encoding or self._input_encoding normalization = normalization or self._normalizsation if not isinstance(text, unicode): text = unicode(text, encoding) return unicodedata.normalize(normalization, text)
[ "def", "decode", "(", "self", ",", "text", ",", "encoding", "=", "None", ",", "normalization", "=", "None", ")", ":", "encoding", "=", "encoding", "or", "self", ".", "_input_encoding", "normalization", "=", "normalization", "or", "self", ".", "_normalizsatio...
https://github.com/fniephaus/alfred-pocket/blob/c8ff8b23d708a746cce2888398cc566bef687a14/src/workflow/workflow.py#L2671-L2703
NoGameNoLife00/mybolg
afe17ea5bfe405e33766e5682c43a4262232ee12
libs/sqlalchemy/orm/interfaces.py
python
MapperProperty.post_instrument_class
(self, mapper)
Perform instrumentation adjustments that need to occur after init() has completed.
Perform instrumentation adjustments that need to occur after init() has completed.
[ "Perform", "instrumentation", "adjustments", "that", "need", "to", "occur", "after", "init", "()", "has", "completed", "." ]
def post_instrument_class(self, mapper): """Perform instrumentation adjustments that need to occur after init() has completed. """ pass
[ "def", "post_instrument_class", "(", "self", ",", "mapper", ")", ":", "pass" ]
https://github.com/NoGameNoLife00/mybolg/blob/afe17ea5bfe405e33766e5682c43a4262232ee12/libs/sqlalchemy/orm/interfaces.py#L184-L189
pytroll/satpy
09e51f932048f98cce7919a4ff8bd2ec01e1ae98
satpy/writers/__init__.py
python
DecisionTree._find_match
(self, curr_level, remaining_match_keys, query_dict)
return match
Find a match.
Find a match.
[ "Find", "a", "match", "." ]
def _find_match(self, curr_level, remaining_match_keys, query_dict): """Find a match.""" if len(remaining_match_keys) == 0: # we're at the bottom level, we must have found something return curr_level match = self._find_match_if_known( curr_level, remaining_match_keys, query_dict) if match is None and self.any_key in curr_level: # if we couldn't find it using the attribute then continue with # the other attributes down the 'any' path match = self._find_match( curr_level[self.any_key], remaining_match_keys[1:], query_dict) return match
[ "def", "_find_match", "(", "self", ",", "curr_level", ",", "remaining_match_keys", ",", "query_dict", ")", ":", "if", "len", "(", "remaining_match_keys", ")", "==", "0", ":", "# we're at the bottom level, we must have found something", "return", "curr_level", "match", ...
https://github.com/pytroll/satpy/blob/09e51f932048f98cce7919a4ff8bd2ec01e1ae98/satpy/writers/__init__.py#L993-L1009
byt3bl33d3r/pth-toolkit
3641cdc76c0f52275315c9b18bf08b22521bd4d7
lib/python2.7/site-packages/samba/samba3/__init__.py
python
IdmapDatabase.get_user_hwm
(self)
return fetch_uint32(self.tdb, IDMAP_HWM_USER)
Obtain the user high-water mark.
Obtain the user high-water mark.
[ "Obtain", "the", "user", "high", "-", "water", "mark", "." ]
def get_user_hwm(self): """Obtain the user high-water mark.""" return fetch_uint32(self.tdb, IDMAP_HWM_USER)
[ "def", "get_user_hwm", "(", "self", ")", ":", "return", "fetch_uint32", "(", "self", ".", "tdb", ",", "IDMAP_HWM_USER", ")" ]
https://github.com/byt3bl33d3r/pth-toolkit/blob/3641cdc76c0f52275315c9b18bf08b22521bd4d7/lib/python2.7/site-packages/samba/samba3/__init__.py#L192-L194
mrlesmithjr/Ansible
d44f0dc0d942bdf3bf7334b307e6048f0ee16e36
roles/ansible-vsphere-management/scripts/pdns/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.py
python
copyfile
(src, dst)
Copy data from src to dst
Copy data from src to dst
[ "Copy", "data", "from", "src", "to", "dst" ]
def copyfile(src, dst): """Copy data from src to dst""" if _samefile(src, dst): raise Error("`%s` and `%s` are the same file" % (src, dst)) for fn in [src, dst]: try: st = os.stat(fn) except OSError: # File most likely does not exist pass else: # XXX What about other special files? (sockets, devices...) if stat.S_ISFIFO(st.st_mode): raise SpecialFileError("`%s` is a named pipe" % fn) with open(src, 'rb') as fsrc: with open(dst, 'wb') as fdst: copyfileobj(fsrc, fdst)
[ "def", "copyfile", "(", "src", ",", "dst", ")", ":", "if", "_samefile", "(", "src", ",", "dst", ")", ":", "raise", "Error", "(", "\"`%s` and `%s` are the same file\"", "%", "(", "src", ",", "dst", ")", ")", "for", "fn", "in", "[", "src", ",", "dst", ...
https://github.com/mrlesmithjr/Ansible/blob/d44f0dc0d942bdf3bf7334b307e6048f0ee16e36/roles/ansible-vsphere-management/scripts/pdns/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.py#L87-L105
yt-project/yt
dc7b24f9b266703db4c843e329c6c8644d47b824
yt/utilities/sdf.py
python
SDFIndex.get_key_ijk
(self, i1, i2, i3, level=None)
return self.get_key(np.array([i1, i2, i3]), level=level)
[]
def get_key_ijk(self, i1, i2, i3, level=None): return self.get_key(np.array([i1, i2, i3]), level=level)
[ "def", "get_key_ijk", "(", "self", ",", "i1", ",", "i2", ",", "i3", ",", "level", "=", "None", ")", ":", "return", "self", ".", "get_key", "(", "np", ".", "array", "(", "[", "i1", ",", "i2", ",", "i3", "]", ")", ",", "level", "=", "level", ")...
https://github.com/yt-project/yt/blob/dc7b24f9b266703db4c843e329c6c8644d47b824/yt/utilities/sdf.py#L755-L756
dask/dask
c2b962fec1ba45440fe928869dc64cfe9cc36506
dask/array/overlap.py
python
ensure_minimum_chunksize
(size, chunks)
return tuple(output)
Determine new chunks to ensure that every chunk >= size Parameters ---------- size: int The maximum size of any chunk. chunks: tuple Chunks along one axis, e.g. ``(3, 3, 2)`` Examples -------- >>> ensure_minimum_chunksize(10, (20, 20, 1)) (20, 11, 10) >>> ensure_minimum_chunksize(3, (1, 1, 3)) (5,) See Also -------- overlap
Determine new chunks to ensure that every chunk >= size
[ "Determine", "new", "chunks", "to", "ensure", "that", "every", "chunk", ">", "=", "size" ]
def ensure_minimum_chunksize(size, chunks): """Determine new chunks to ensure that every chunk >= size Parameters ---------- size: int The maximum size of any chunk. chunks: tuple Chunks along one axis, e.g. ``(3, 3, 2)`` Examples -------- >>> ensure_minimum_chunksize(10, (20, 20, 1)) (20, 11, 10) >>> ensure_minimum_chunksize(3, (1, 1, 3)) (5,) See Also -------- overlap """ if size <= min(chunks): return chunks # add too-small chunks to chunks before them output = [] new = 0 for c in chunks: if c < size: if new > size + (size - c): output.append(new - (size - c)) new = size else: new += c if new >= size: output.append(new) new = 0 if c >= size: new += c if new >= size: output.append(new) elif len(output) >= 1: output[-1] += new else: raise ValueError( f"The overlapping depth {size} is larger than your " f"array {sum(chunks)}." ) return tuple(output)
[ "def", "ensure_minimum_chunksize", "(", "size", ",", "chunks", ")", ":", "if", "size", "<=", "min", "(", "chunks", ")", ":", "return", "chunks", "# add too-small chunks to chunks before them", "output", "=", "[", "]", "new", "=", "0", "for", "c", "in", "chun...
https://github.com/dask/dask/blob/c2b962fec1ba45440fe928869dc64cfe9cc36506/dask/array/overlap.py#L310-L358
obspy/obspy
0ee5a0d2db293c8d5d4c3b1f148a6c5a85fea55f
obspy/io/stationxml/core.py
python
_write_network
(parent, network, level)
Helper function converting a Network instance to an etree.Element.
Helper function converting a Network instance to an etree.Element.
[ "Helper", "function", "converting", "a", "Network", "instance", "to", "an", "etree", ".", "Element", "." ]
def _write_network(parent, network, level): """ Helper function converting a Network instance to an etree.Element. """ attribs = _get_base_node_attributes(network) network_elem = etree.SubElement(parent, "Network", attribs) _write_base_node(network_elem, network) for operator in network.operators: operator_elem = etree.SubElement(network_elem, "Operator") etree.SubElement(operator_elem, "Agency").text = str(operator.agency) for contact in operator.contacts: _write_person(operator_elem, contact, "Contact") etree.SubElement(operator_elem, "WebSite").text = operator.website _write_extra(operator_elem, operator) # Add the two, network specific fields. if network.total_number_of_stations is not None: etree.SubElement(network_elem, "TotalNumberStations").text = \ str(network.total_number_of_stations) if network.selected_number_of_stations is not None: etree.SubElement(network_elem, "SelectedNumberStations").text = \ str(network.selected_number_of_stations) if level == "network": return for station in network.stations: _write_station(network_elem, station, level)
[ "def", "_write_network", "(", "parent", ",", "network", ",", "level", ")", ":", "attribs", "=", "_get_base_node_attributes", "(", "network", ")", "network_elem", "=", "etree", ".", "SubElement", "(", "parent", ",", "\"Network\"", ",", "attribs", ")", "_write_b...
https://github.com/obspy/obspy/blob/0ee5a0d2db293c8d5d4c3b1f148a6c5a85fea55f/obspy/io/stationxml/core.py#L992-L1020
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/lib/python2.7/site-packages/wtforms/fields/core.py
python
FieldList.__iter__
(self)
return iter(self.entries)
[]
def __iter__(self): return iter(self.entries)
[ "def", "__iter__", "(", "self", ")", ":", "return", "iter", "(", "self", ".", "entries", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/lib/python2.7/site-packages/wtforms/fields/core.py#L976-L977
ambujraj/hacktoberfest2018
53df2cac8b3404261131a873352ec4f2ffa3544d
MAC_changer/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/urllib3/poolmanager.py
python
PoolManager.connection_from_url
(self, url, pool_kwargs=None)
return self.connection_from_host(u.host, port=u.port, scheme=u.scheme, pool_kwargs=pool_kwargs)
Similar to :func:`urllib3.connectionpool.connection_from_url`. If ``pool_kwargs`` is not provided and a new pool needs to be constructed, ``self.connection_pool_kw`` is used to initialize the :class:`urllib3.connectionpool.ConnectionPool`. If ``pool_kwargs`` is provided, it is used instead. Note that if a new pool does not need to be created for the request, the provided ``pool_kwargs`` are not used.
Similar to :func:`urllib3.connectionpool.connection_from_url`.
[ "Similar", "to", ":", "func", ":", "urllib3", ".", "connectionpool", ".", "connection_from_url", "." ]
def connection_from_url(self, url, pool_kwargs=None): """ Similar to :func:`urllib3.connectionpool.connection_from_url`. If ``pool_kwargs`` is not provided and a new pool needs to be constructed, ``self.connection_pool_kw`` is used to initialize the :class:`urllib3.connectionpool.ConnectionPool`. If ``pool_kwargs`` is provided, it is used instead. Note that if a new pool does not need to be created for the request, the provided ``pool_kwargs`` are not used. """ u = parse_url(url) return self.connection_from_host(u.host, port=u.port, scheme=u.scheme, pool_kwargs=pool_kwargs)
[ "def", "connection_from_url", "(", "self", ",", "url", ",", "pool_kwargs", "=", "None", ")", ":", "u", "=", "parse_url", "(", "url", ")", "return", "self", ".", "connection_from_host", "(", "u", ".", "host", ",", "port", "=", "u", ".", "port", ",", "...
https://github.com/ambujraj/hacktoberfest2018/blob/53df2cac8b3404261131a873352ec4f2ffa3544d/MAC_changer/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/urllib3/poolmanager.py#L266-L279
SHI-Labs/Decoupled-Classification-Refinement
16202b48eb9cbf79a9b130a98e8c209d4f24693e
fpn_dcr/core/module.py
python
Module.update_metric
(self, eval_metric, labels)
Evaluate and accumulate evaluation metric on outputs of the last forward computation. Parameters ---------- eval_metric : EvalMetric labels : list of NDArray Typically `data_batch.label`.
Evaluate and accumulate evaluation metric on outputs of the last forward computation.
[ "Evaluate", "and", "accumulate", "evaluation", "metric", "on", "outputs", "of", "the", "last", "forward", "computation", "." ]
def update_metric(self, eval_metric, labels): """Evaluate and accumulate evaluation metric on outputs of the last forward computation. Parameters ---------- eval_metric : EvalMetric labels : list of NDArray Typically `data_batch.label`. """ self._exec_group.update_metric(eval_metric, labels)
[ "def", "update_metric", "(", "self", ",", "eval_metric", ",", "labels", ")", ":", "self", ".", "_exec_group", ".", "update_metric", "(", "eval_metric", ",", "labels", ")" ]
https://github.com/SHI-Labs/Decoupled-Classification-Refinement/blob/16202b48eb9cbf79a9b130a98e8c209d4f24693e/fpn_dcr/core/module.py#L664-L673
tensorflow/lingvo
ce10019243d954c3c3ebe739f7589b5eebfdf907
lingvo/core/program.py
python
BaseProgram.BuildTpuSubgraph
(self)
Sub classes should construct a model/graph to be executed by Run. Specific to TPU execution, this may involve a @tpu_function.on_device_training_loop etc.
Sub classes should construct a model/graph to be executed by Run.
[ "Sub", "classes", "should", "construct", "a", "model", "/", "graph", "to", "be", "executed", "by", "Run", "." ]
def BuildTpuSubgraph(self): """Sub classes should construct a model/graph to be executed by Run. Specific to TPU execution, this may involve a @tpu_function.on_device_training_loop etc. """ raise NotImplementedError()
[ "def", "BuildTpuSubgraph", "(", "self", ")", ":", "raise", "NotImplementedError", "(", ")" ]
https://github.com/tensorflow/lingvo/blob/ce10019243d954c3c3ebe739f7589b5eebfdf907/lingvo/core/program.py#L301-L307
mlrun/mlrun
4c120719d64327a34b7ee1ab08fb5e01b258b00a
mlrun/frameworks/pytorch/callbacks/tensorboard_logging_callback.py
python
_PyTorchTensorboardLogger._write_scalar_to_tensorboard
(self, name: str, value: float, step: int)
Write the scalar's value into its plot. :param name: The plot's name. :param value: The value to add to the plot. :param step: The iteration / epoch the value belongs to.
Write the scalar's value into its plot.
[ "Write", "the", "scalar", "s", "value", "into", "its", "plot", "." ]
def _write_scalar_to_tensorboard(self, name: str, value: float, step: int): """ Write the scalar's value into its plot. :param name: The plot's name. :param value: The value to add to the plot. :param step: The iteration / epoch the value belongs to. """ self._summary_writer.add_scalar( tag=name, scalar_value=value, global_step=step, )
[ "def", "_write_scalar_to_tensorboard", "(", "self", ",", "name", ":", "str", ",", "value", ":", "float", ",", "step", ":", "int", ")", ":", "self", ".", "_summary_writer", ".", "add_scalar", "(", "tag", "=", "name", ",", "scalar_value", "=", "value", ","...
https://github.com/mlrun/mlrun/blob/4c120719d64327a34b7ee1ab08fb5e01b258b00a/mlrun/frameworks/pytorch/callbacks/tensorboard_logging_callback.py#L164-L174
JiYou/openstack
8607dd488bde0905044b303eb6e52bdea6806923
packages/source/nova/nova/db/api.py
python
agent_build_create
(context, values)
return IMPL.agent_build_create(context, values)
Create a new agent build entry.
Create a new agent build entry.
[ "Create", "a", "new", "agent", "build", "entry", "." ]
def agent_build_create(context, values): """Create a new agent build entry.""" return IMPL.agent_build_create(context, values)
[ "def", "agent_build_create", "(", "context", ",", "values", ")", ":", "return", "IMPL", ".", "agent_build_create", "(", "context", ",", "values", ")" ]
https://github.com/JiYou/openstack/blob/8607dd488bde0905044b303eb6e52bdea6806923/packages/source/nova/nova/db/api.py#L1384-L1386
python-pillow/Pillow
fd2b07c454b20e1e9af0cea64923b21250f8f8d6
src/PIL/Image.py
python
Image.close
(self)
Closes the file pointer, if possible. This operation will destroy the image core and release its memory. The image data will be unusable afterward. This function is required to close images that have multiple frames or have not had their file read and closed by the :py:meth:`~PIL.Image.Image.load` method. See :ref:`file-handling` for more information.
Closes the file pointer, if possible.
[ "Closes", "the", "file", "pointer", "if", "possible", "." ]
def close(self): """ Closes the file pointer, if possible. This operation will destroy the image core and release its memory. The image data will be unusable afterward. This function is required to close images that have multiple frames or have not had their file read and closed by the :py:meth:`~PIL.Image.Image.load` method. See :ref:`file-handling` for more information. """ try: if hasattr(self, "_close__fp"): self._close__fp() if self.fp: self.fp.close() self.fp = None except Exception as msg: logger.debug("Error closing: %s", msg) if getattr(self, "map", None): self.map = None # Instead of simply setting to None, we're setting up a # deferred error that will better explain that the core image # object is gone. self.im = deferred_error(ValueError("Operation on closed image"))
[ "def", "close", "(", "self", ")", ":", "try", ":", "if", "hasattr", "(", "self", ",", "\"_close__fp\"", ")", ":", "self", ".", "_close__fp", "(", ")", "if", "self", ".", "fp", ":", "self", ".", "fp", ".", "close", "(", ")", "self", ".", "fp", "...
https://github.com/python-pillow/Pillow/blob/fd2b07c454b20e1e9af0cea64923b21250f8f8d6/src/PIL/Image.py#L560-L587
fluentpython/example-code-2e
80f7f84274a47579e59c29a4657691525152c9d5
11-pythonic-obj/vector2d_v1.py
python
Vector2d.__iter__
(self)
return (i for i in (self.x, self.y))
[]
def __iter__(self): return (i for i in (self.x, self.y))
[ "def", "__iter__", "(", "self", ")", ":", "return", "(", "i", "for", "i", "in", "(", "self", ".", "x", ",", "self", ".", "y", ")", ")" ]
https://github.com/fluentpython/example-code-2e/blob/80f7f84274a47579e59c29a4657691525152c9d5/11-pythonic-obj/vector2d_v1.py#L47-L48
Blizzard/heroprotocol
3d36eaf44fc4c8ff3331c2ae2f1dc08a94535f1c
heroprotocol/versions/protocol74238.py
python
decode_replay_attributes_events
(contents)
return attributes
Decodes and yields each attribute from the contents byte string.
Decodes and yields each attribute from the contents byte string.
[ "Decodes", "and", "yields", "each", "attribute", "from", "the", "contents", "byte", "string", "." ]
def decode_replay_attributes_events(contents): """Decodes and yields each attribute from the contents byte string.""" buffer = BitPackedBuffer(contents, 'little') attributes = {} if not buffer.done(): attributes['source'] = buffer.read_bits(8) attributes['mapNamespace'] = buffer.read_bits(32) _ = buffer.read_bits(32) attributes['scopes'] = {} while not buffer.done(): value = {} value['namespace'] = buffer.read_bits(32) value['attrid'] = attrid = buffer.read_bits(32) scope = buffer.read_bits(8) value['value'] = buffer.read_aligned_bytes(4)[::-1].strip(b'\x00') if not scope in attributes['scopes']: attributes['scopes'][scope] = {} if not attrid in attributes['scopes'][scope]: attributes['scopes'][scope][attrid] = [] attributes['scopes'][scope][attrid].append(value) return attributes
[ "def", "decode_replay_attributes_events", "(", "contents", ")", ":", "buffer", "=", "BitPackedBuffer", "(", "contents", ",", "'little'", ")", "attributes", "=", "{", "}", "if", "not", "buffer", ".", "done", "(", ")", ":", "attributes", "[", "'source'", "]", ...
https://github.com/Blizzard/heroprotocol/blob/3d36eaf44fc4c8ff3331c2ae2f1dc08a94535f1c/heroprotocol/versions/protocol74238.py#L452-L472
wucng/TensorExpand
4ea58f64f5c5082b278229b799c9f679536510b7
TensorExpand/Object detection/RFCN/RFCN-tensorflow/Utils/MultiGather.py
python
gatherTopK
(t, k, others=[], sorted=False)
return res
[]
def gatherTopK(t, k, others=[], sorted=False): res=[] with tf.name_scope("gather_top_k"): isMoreThanK = tf.shape(t)[-1]>k values, indices = tf.cond(isMoreThanK, lambda: tuple(tf.nn.top_k(t, k=k, sorted=sorted)), lambda: (t, tf.zeros((0,1), tf.int32))) indices = tf.reshape(indices, [-1,1]) res.append(values) for o in others: res.append(tf.cond(isMoreThanK, lambda: tf.gather_nd(o, indices), lambda: o)) return res
[ "def", "gatherTopK", "(", "t", ",", "k", ",", "others", "=", "[", "]", ",", "sorted", "=", "False", ")", ":", "res", "=", "[", "]", "with", "tf", ".", "name_scope", "(", "\"gather_top_k\"", ")", ":", "isMoreThanK", "=", "tf", ".", "shape", "(", "...
https://github.com/wucng/TensorExpand/blob/4ea58f64f5c5082b278229b799c9f679536510b7/TensorExpand/Object detection/RFCN/RFCN-tensorflow/Utils/MultiGather.py#L26-L37
TDAmeritrade/stumpy
7c97df98cb4095afae775ab71870d4d5a14776c7
stumpy/core.py
python
_get_array_ranges
(a, n_chunks, truncate)
return array_ranges
Given an input array, split it into `n_chunks`. Parameters ---------- a : numpy.ndarray An array to be split n_chunks : int Number of chunks to split the array into truncate : bool If `truncate=True`, truncate the rows of `array_ranges` if there are not enough elements in `a` to be chunked up into `n_chunks`. Otherwise, if `truncate=False`, all extra chunks will have their start and stop indices set to `a.shape[0]`. Returns ------- array_ranges : numpy.ndarray A two column array where each row consists of a start and (exclusive) stop index pair. The first column contains the start indices and the second column contains the stop indices.
Given an input array, split it into `n_chunks`.
[ "Given", "an", "input", "array", "split", "it", "into", "n_chunks", "." ]
def _get_array_ranges(a, n_chunks, truncate): """ Given an input array, split it into `n_chunks`. Parameters ---------- a : numpy.ndarray An array to be split n_chunks : int Number of chunks to split the array into truncate : bool If `truncate=True`, truncate the rows of `array_ranges` if there are not enough elements in `a` to be chunked up into `n_chunks`. Otherwise, if `truncate=False`, all extra chunks will have their start and stop indices set to `a.shape[0]`. Returns ------- array_ranges : numpy.ndarray A two column array where each row consists of a start and (exclusive) stop index pair. The first column contains the start indices and the second column contains the stop indices. """ array_ranges = np.zeros((n_chunks, 2), dtype=np.int64) if a.shape[0] > 0 and n_chunks > 0: cumsum = a.cumsum() / a.sum() insert = np.linspace(0, 1, n_chunks + 1)[1:-1] idx = 1 + np.searchsorted(cumsum, insert) array_ranges[1:, 0] = idx # Fill the first column with start indices array_ranges[:-1, 1] = idx # Fill the second column with exclusive stop indices array_ranges[-1, 1] = a.shape[0] # Handle the stop index for the final chunk diff_idx = np.diff(idx) if np.any(diff_idx == 0): row_truncation_idx = np.argmin(diff_idx) + 2 array_ranges[row_truncation_idx:, 0] = a.shape[0] array_ranges[row_truncation_idx - 1 :, 1] = a.shape[0] if truncate: array_ranges = array_ranges[:row_truncation_idx] return array_ranges
[ "def", "_get_array_ranges", "(", "a", ",", "n_chunks", ",", "truncate", ")", ":", "array_ranges", "=", "np", ".", "zeros", "(", "(", "n_chunks", ",", "2", ")", ",", "dtype", "=", "np", ".", "int64", ")", "if", "a", ".", "shape", "[", "0", "]", ">...
https://github.com/TDAmeritrade/stumpy/blob/7c97df98cb4095afae775ab71870d4d5a14776c7/stumpy/core.py#L1709-L1751
SteveDoyle2/pyNastran
eda651ac2d4883d95a34951f8a002ff94f642a1a
pyNastran/gui/qt_files/gui_qt_common.py
python
GuiQtCommon.on_disp
(self, icase, apply_fringe=False, update_legend_window=True, show_msg=True, stop_on_failure=False)
Sets the icase data to the active displacement
Sets the icase data to the active displacement
[ "Sets", "the", "icase", "data", "to", "the", "active", "displacement" ]
def on_disp(self, icase, apply_fringe=False, update_legend_window=True, show_msg=True, stop_on_failure=False): """Sets the icase data to the active displacement""" is_disp = True self._on_disp_vector(icase, is_disp, apply_fringe, update_legend_window, show_msg=show_msg, stop_on_failure=stop_on_failure) self.res_widget.result_case_window.treeView.disp.setChecked(True)
[ "def", "on_disp", "(", "self", ",", "icase", ",", "apply_fringe", "=", "False", ",", "update_legend_window", "=", "True", ",", "show_msg", "=", "True", ",", "stop_on_failure", "=", "False", ")", ":", "is_disp", "=", "True", "self", ".", "_on_disp_vector", ...
https://github.com/SteveDoyle2/pyNastran/blob/eda651ac2d4883d95a34951f8a002ff94f642a1a/pyNastran/gui/qt_files/gui_qt_common.py#L647-L653
clinton-hall/nzbToMedia
27669389216902d1085660167e7bda0bd8527ecf
libs/common/beets/util/__init__.py
python
sorted_walk
(path, ignore=(), ignore_hidden=False, logger=None)
Like `os.walk`, but yields things in case-insensitive sorted, breadth-first order. Directory and file names matching any glob pattern in `ignore` are skipped. If `logger` is provided, then warning messages are logged there when a directory cannot be listed.
Like `os.walk`, but yields things in case-insensitive sorted, breadth-first order. Directory and file names matching any glob pattern in `ignore` are skipped. If `logger` is provided, then warning messages are logged there when a directory cannot be listed.
[ "Like", "os", ".", "walk", "but", "yields", "things", "in", "case", "-", "insensitive", "sorted", "breadth", "-", "first", "order", ".", "Directory", "and", "file", "names", "matching", "any", "glob", "pattern", "in", "ignore", "are", "skipped", ".", "If",...
def sorted_walk(path, ignore=(), ignore_hidden=False, logger=None): """Like `os.walk`, but yields things in case-insensitive sorted, breadth-first order. Directory and file names matching any glob pattern in `ignore` are skipped. If `logger` is provided, then warning messages are logged there when a directory cannot be listed. """ # Make sure the pathes aren't Unicode strings. path = bytestring_path(path) ignore = [bytestring_path(i) for i in ignore] # Get all the directories and files at this level. try: contents = os.listdir(syspath(path)) except OSError as exc: if logger: logger.warning(u'could not list directory {0}: {1}'.format( displayable_path(path), exc.strerror )) return dirs = [] files = [] for base in contents: base = bytestring_path(base) # Skip ignored filenames. skip = False for pat in ignore: if fnmatch.fnmatch(base, pat): skip = True break if skip: continue # Add to output as either a file or a directory. cur = os.path.join(path, base) if (ignore_hidden and not hidden.is_hidden(cur)) or not ignore_hidden: if os.path.isdir(syspath(cur)): dirs.append(base) else: files.append(base) # Sort lists (case-insensitive) and yield the current level. dirs.sort(key=bytes.lower) files.sort(key=bytes.lower) yield (path, dirs, files) # Recurse into directories. for base in dirs: cur = os.path.join(path, base) # yield from sorted_walk(...) for res in sorted_walk(cur, ignore, ignore_hidden, logger): yield res
[ "def", "sorted_walk", "(", "path", ",", "ignore", "=", "(", ")", ",", "ignore_hidden", "=", "False", ",", "logger", "=", "None", ")", ":", "# Make sure the pathes aren't Unicode strings.", "path", "=", "bytestring_path", "(", "path", ")", "ignore", "=", "[", ...
https://github.com/clinton-hall/nzbToMedia/blob/27669389216902d1085660167e7bda0bd8527ecf/libs/common/beets/util/__init__.py#L170-L221
tensorflow/transform
bc5c3da6aebe9c8780da806e7e8103959c242863
tensorflow_transform/graph_tools.py
python
get_dependent_inputs
(graph, input_tensors, output_tensors)
return { name: tensor for name, tensor in input_tensors.items() if name in dependent_inputs }
Returns tensors in input_tensors that (transitively) produce output_tensors. Args: graph: A `tf.Graph`. It could be the (intermediate) output tf graph in any transform phase (including phase 0 where no tensor replacement has yet happened). input_tensors: A dict of logical name to `tf.Tensor`, `tf.SparseTensor`, or `tf.RaggedTensor`. Logical name doesn't have any implications in this method and can be anything. In some cases it is the feature name corresponding to the input tensor. output_tensors: A dict of logical name to `tf.Tensor`, `tf.SparseTensor`, or `tf.RaggedTensor`, or a list of `tf.Tensor`, `tf.SparseTensor`, or `tf.RaggedTensor`. Returns: A dict of logical name to `tf.Tensor`, `tf.SparseTensor`, or `tf.RaggedTensor` that are filtered from input_tensors (transitively) producing output_tensors
Returns tensors in input_tensors that (transitively) produce output_tensors.
[ "Returns", "tensors", "in", "input_tensors", "that", "(", "transitively", ")", "produce", "output_tensors", "." ]
def get_dependent_inputs(graph, input_tensors, output_tensors): """Returns tensors in input_tensors that (transitively) produce output_tensors. Args: graph: A `tf.Graph`. It could be the (intermediate) output tf graph in any transform phase (including phase 0 where no tensor replacement has yet happened). input_tensors: A dict of logical name to `tf.Tensor`, `tf.SparseTensor`, or `tf.RaggedTensor`. Logical name doesn't have any implications in this method and can be anything. In some cases it is the feature name corresponding to the input tensor. output_tensors: A dict of logical name to `tf.Tensor`, `tf.SparseTensor`, or `tf.RaggedTensor`, or a list of `tf.Tensor`, `tf.SparseTensor`, or `tf.RaggedTensor`. Returns: A dict of logical name to `tf.Tensor`, `tf.SparseTensor`, or `tf.RaggedTensor` that are filtered from input_tensors (transitively) producing output_tensors """ if isinstance(output_tensors, list): output_container = output_tensors else: output_container = output_tensors.values() # Since this method may be called before all tensor replacements are ready, to # fulfill the precondition of InitializableGraphAnalyzer, we fake the # readiness of tensor replacements. Note that the readiness of replacement # tensors doesn't affect the correctness of dependencies tracing. tensor_sinks = graph.get_collection(analyzer_nodes.TENSOR_REPLACEMENTS) sink_tensors_ready = [(sink.tensor, False) for sink in tensor_sinks] graph_analyzer = _QuietInitializableGraphAnalyzer(graph, input_tensors, sink_tensors_ready) dependent_inputs = {} for output_tensor in output_container: dependent_inputs.update(graph_analyzer.get_dependent_inputs(output_tensor)) return { name: tensor for name, tensor in input_tensors.items() if name in dependent_inputs }
[ "def", "get_dependent_inputs", "(", "graph", ",", "input_tensors", ",", "output_tensors", ")", ":", "if", "isinstance", "(", "output_tensors", ",", "list", ")", ":", "output_container", "=", "output_tensors", "else", ":", "output_container", "=", "output_tensors", ...
https://github.com/tensorflow/transform/blob/bc5c3da6aebe9c8780da806e7e8103959c242863/tensorflow_transform/graph_tools.py#L772-L812
securesystemslab/zippy
ff0e84ac99442c2c55fe1d285332cfd4e185e089
zippy/benchmarks/src/benchmarks/sympy/sympy/assumptions/handlers/ntheory.py
python
AskEvenHandler.NumberSymbol
(expr, assumptions)
return AskEvenHandler._number(expr, assumptions)
[]
def NumberSymbol(expr, assumptions): return AskEvenHandler._number(expr, assumptions)
[ "def", "NumberSymbol", "(", "expr", ",", "assumptions", ")", ":", "return", "AskEvenHandler", ".", "_number", "(", "expr", ",", "assumptions", ")" ]
https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/benchmarks/src/benchmarks/sympy/sympy/assumptions/handlers/ntheory.py#L197-L198
JimmXinu/FanFicFare
bc149a2deb2636320fe50a3e374af6eef8f61889
included_dependencies/requests/sessions.py
python
SessionRedirectMixin.get_redirect_target
(self, resp)
return None
Receives a Response. Returns a redirect URI or ``None``
Receives a Response. Returns a redirect URI or ``None``
[ "Receives", "a", "Response", ".", "Returns", "a", "redirect", "URI", "or", "None" ]
def get_redirect_target(self, resp): """Receives a Response. Returns a redirect URI or ``None``""" # Due to the nature of how requests processes redirects this method will # be called at least once upon the original response and at least twice # on each subsequent redirect response (if any). # If a custom mixin is used to handle this logic, it may be advantageous # to cache the redirect location onto the response object as a private # attribute. if resp.is_redirect: location = resp.headers['location'] # Currently the underlying http module on py3 decode headers # in latin1, but empirical evidence suggests that latin1 is very # rarely used with non-ASCII characters in HTTP headers. # It is more likely to get UTF8 header rather than latin1. # This causes incorrect handling of UTF8 encoded location headers. # To solve this, we re-encode the location in latin1. if is_py3: location = location.encode('latin1') return to_native_string(location, 'utf8') return None
[ "def", "get_redirect_target", "(", "self", ",", "resp", ")", ":", "# Due to the nature of how requests processes redirects this method will", "# be called at least once upon the original response and at least twice", "# on each subsequent redirect response (if any).", "# If a custom mixin is u...
https://github.com/JimmXinu/FanFicFare/blob/bc149a2deb2636320fe50a3e374af6eef8f61889/included_dependencies/requests/sessions.py#L98-L117
keiffster/program-y
8c99b56f8c32f01a7b9887b5daae9465619d0385
src/programy/parser/factory.py
python
NodeFactory.nodes
(self)
return self._nodes_config
[]
def nodes(self): return self._nodes_config
[ "def", "nodes", "(", "self", ")", ":", "return", "self", ".", "_nodes_config" ]
https://github.com/keiffster/program-y/blob/8c99b56f8c32f01a7b9887b5daae9465619d0385/src/programy/parser/factory.py#L32-L33
ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework
cb692f527e4e819b6c228187c5702d990a180043
external/Scripting Engine/Xenotix Python Scripting Engine/packages/IronPython.StdLib.2.7.4/content/Lib/email/message.py
python
Message.add_header
(self, _name, _value, **_params)
Extended header setting. name is the header field to add. keyword arguments can be used to set additional parameters for the header field, with underscores converted to dashes. Normally the parameter will be added as key="value" unless value is None, in which case only the key will be added. If a parameter value contains non-ASCII characters it must be specified as a three-tuple of (charset, language, value), in which case it will be encoded according to RFC2231 rules. Example: msg.add_header('content-disposition', 'attachment', filename='bud.gif')
Extended header setting.
[ "Extended", "header", "setting", "." ]
def add_header(self, _name, _value, **_params): """Extended header setting. name is the header field to add. keyword arguments can be used to set additional parameters for the header field, with underscores converted to dashes. Normally the parameter will be added as key="value" unless value is None, in which case only the key will be added. If a parameter value contains non-ASCII characters it must be specified as a three-tuple of (charset, language, value), in which case it will be encoded according to RFC2231 rules. Example: msg.add_header('content-disposition', 'attachment', filename='bud.gif') """ parts = [] for k, v in _params.items(): if v is None: parts.append(k.replace('_', '-')) else: parts.append(_formatparam(k.replace('_', '-'), v)) if _value is not None: parts.insert(0, _value) self._headers.append((_name, SEMISPACE.join(parts)))
[ "def", "add_header", "(", "self", ",", "_name", ",", "_value", ",", "*", "*", "_params", ")", ":", "parts", "=", "[", "]", "for", "k", ",", "v", "in", "_params", ".", "items", "(", ")", ":", "if", "v", "is", "None", ":", "parts", ".", "append",...
https://github.com/ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework/blob/cb692f527e4e819b6c228187c5702d990a180043/external/Scripting Engine/Xenotix Python Scripting Engine/packages/IronPython.StdLib.2.7.4/content/Lib/email/message.py#L388-L411
python-quantities/python-quantities
ffd231e4859fb9e05aea5bf537311404183f51ad
quantities/umath.py
python
arctanh
(x, out=None)
return Quantity( np.arctanh(x.rescale(dimensionless).magnitude, out), dimensionless, copy=False )
Raises a ValueError if input cannot be rescaled to a dimensionless quantity.
Raises a ValueError if input cannot be rescaled to a dimensionless quantity.
[ "Raises", "a", "ValueError", "if", "input", "cannot", "be", "rescaled", "to", "a", "dimensionless", "quantity", "." ]
def arctanh(x, out=None): """ Raises a ValueError if input cannot be rescaled to a dimensionless quantity. """ if not isinstance(x, Quantity): return np.arctanh(x, out) return Quantity( np.arctanh(x.rescale(dimensionless).magnitude, out), dimensionless, copy=False )
[ "def", "arctanh", "(", "x", ",", "out", "=", "None", ")", ":", "if", "not", "isinstance", "(", "x", ",", "Quantity", ")", ":", "return", "np", ".", "arctanh", "(", "x", ",", "out", ")", "return", "Quantity", "(", "np", ".", "arctanh", "(", "x", ...
https://github.com/python-quantities/python-quantities/blob/ffd231e4859fb9e05aea5bf537311404183f51ad/quantities/umath.py#L355-L367
frescobaldi/frescobaldi
301cc977fc4ba7caa3df9e4bf905212ad5d06912
frescobaldi_app/view.py
python
View.dropEvent
(self, ev)
Called when something is dropped. Calls dropEvent() of MainWindow if URLs are dropped.
Called when something is dropped.
[ "Called", "when", "something", "is", "dropped", "." ]
def dropEvent(self, ev): """Called when something is dropped. Calls dropEvent() of MainWindow if URLs are dropped. """ if ev.mimeData().hasUrls(): self.window().dropEvent(ev) else: super(View, self).dropEvent(ev)
[ "def", "dropEvent", "(", "self", ",", "ev", ")", ":", "if", "ev", ".", "mimeData", "(", ")", ".", "hasUrls", "(", ")", ":", "self", ".", "window", "(", ")", ".", "dropEvent", "(", "ev", ")", "else", ":", "super", "(", "View", ",", "self", ")", ...
https://github.com/frescobaldi/frescobaldi/blob/301cc977fc4ba7caa3df9e4bf905212ad5d06912/frescobaldi_app/view.py#L182-L191
HuberTRoy/MusicBox
82fdf21809b7f018c616c4d1c78cfbf04cd5d9e3
MusicPlayer/widgets/base.py
python
ScrollArea.maximumValue
(self)
return self.verticalScrollBar().maximum()
[]
def maximumValue(self): return self.verticalScrollBar().maximum()
[ "def", "maximumValue", "(", "self", ")", ":", "return", "self", ".", "verticalScrollBar", "(", ")", ".", "maximum", "(", ")" ]
https://github.com/HuberTRoy/MusicBox/blob/82fdf21809b7f018c616c4d1c78cfbf04cd5d9e3/MusicPlayer/widgets/base.py#L150-L151
WerWolv/EdiZon_CheatsConfigsAndScripts
d16d36c7509c01dca770f402babd83ff2e9ae6e7
Scripts/lib/python3.5/numbers.py
python
Real.__rfloordiv__
(self, other)
other // self: The floor() of other/self.
other // self: The floor() of other/self.
[ "other", "//", "self", ":", "The", "floor", "()", "of", "other", "/", "self", "." ]
def __rfloordiv__(self, other): """other // self: The floor() of other/self.""" raise NotImplementedError
[ "def", "__rfloordiv__", "(", "self", ",", "other", ")", ":", "raise", "NotImplementedError" ]
https://github.com/WerWolv/EdiZon_CheatsConfigsAndScripts/blob/d16d36c7509c01dca770f402babd83ff2e9ae6e7/Scripts/lib/python3.5/numbers.py#L219-L221
CacheBrowser/cachebrowser
4bf1d58e5c82a0dbaa878f7725c830d472f5326e
cachebrowser/ipc.py
python
IPCRouter.rpc_request
(self, client_id, request_id, method, params)
[]
def rpc_request(self, client_id, request_id, method, params): if method not in self.rpc_clients: logger.error("RPC request received for '{}', but route does not exist".format(method)) # TODO Give error pass self.rpc_pending_requests[request_id] = client_id target_client_id = self.rpc_clients.get(method, None) if target_client_id is not None: client = self.clients.get(target_client_id, None) if client is not None: client.send_rpc_request(request_id, method, params)
[ "def", "rpc_request", "(", "self", ",", "client_id", ",", "request_id", ",", "method", ",", "params", ")", ":", "if", "method", "not", "in", "self", ".", "rpc_clients", ":", "logger", ".", "error", "(", "\"RPC request received for '{}', but route does not exist\""...
https://github.com/CacheBrowser/cachebrowser/blob/4bf1d58e5c82a0dbaa878f7725c830d472f5326e/cachebrowser/ipc.py#L54-L65
holzschu/Carnets
44effb10ddfc6aa5c8b0687582a724ba82c6b547
Library/lib/python3.7/urllib/request.py
python
urlopen
(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, *, cafile=None, capath=None, cadefault=False, context=None)
return opener.open(url, data, timeout)
Open the URL url, which can be either a string or a Request object. *data* must be an object specifying additional data to be sent to the server, or None if no such data is needed. See Request for details. urllib.request module uses HTTP/1.1 and includes a "Connection:close" header in its HTTP requests. The optional *timeout* parameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout setting will be used). This only works for HTTP, HTTPS and FTP connections. If *context* is specified, it must be a ssl.SSLContext instance describing the various SSL options. See HTTPSConnection for more details. The optional *cafile* and *capath* parameters specify a set of trusted CA certificates for HTTPS requests. cafile should point to a single file containing a bundle of CA certificates, whereas capath should point to a directory of hashed certificate files. More information can be found in ssl.SSLContext.load_verify_locations(). The *cadefault* parameter is ignored. This function always returns an object which can work as a context manager and has methods such as * geturl() - return the URL of the resource retrieved, commonly used to determine if a redirect was followed * info() - return the meta-information of the page, such as headers, in the form of an email.message_from_string() instance (see Quick Reference to HTTP Headers) * getcode() - return the HTTP status code of the response. Raises URLError on errors. For HTTP and HTTPS URLs, this function returns a http.client.HTTPResponse object slightly modified. In addition to the three new methods above, the msg attribute contains the same information as the reason attribute --- the reason phrase returned by the server --- instead of the response headers as it is specified in the documentation for HTTPResponse. For FTP, file, and data URLs and requests explicitly handled by legacy URLopener and FancyURLopener classes, this function returns a urllib.response.addinfourl object. Note that None may be returned if no handler handles the request (though the default installed global OpenerDirector uses UnknownHandler to ensure this never happens). In addition, if proxy settings are detected (for example, when a *_proxy environment variable like http_proxy is set), ProxyHandler is default installed and makes sure the requests are handled through the proxy.
Open the URL url, which can be either a string or a Request object.
[ "Open", "the", "URL", "url", "which", "can", "be", "either", "a", "string", "or", "a", "Request", "object", "." ]
def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, *, cafile=None, capath=None, cadefault=False, context=None): '''Open the URL url, which can be either a string or a Request object. *data* must be an object specifying additional data to be sent to the server, or None if no such data is needed. See Request for details. urllib.request module uses HTTP/1.1 and includes a "Connection:close" header in its HTTP requests. The optional *timeout* parameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout setting will be used). This only works for HTTP, HTTPS and FTP connections. If *context* is specified, it must be a ssl.SSLContext instance describing the various SSL options. See HTTPSConnection for more details. The optional *cafile* and *capath* parameters specify a set of trusted CA certificates for HTTPS requests. cafile should point to a single file containing a bundle of CA certificates, whereas capath should point to a directory of hashed certificate files. More information can be found in ssl.SSLContext.load_verify_locations(). The *cadefault* parameter is ignored. This function always returns an object which can work as a context manager and has methods such as * geturl() - return the URL of the resource retrieved, commonly used to determine if a redirect was followed * info() - return the meta-information of the page, such as headers, in the form of an email.message_from_string() instance (see Quick Reference to HTTP Headers) * getcode() - return the HTTP status code of the response. Raises URLError on errors. For HTTP and HTTPS URLs, this function returns a http.client.HTTPResponse object slightly modified. In addition to the three new methods above, the msg attribute contains the same information as the reason attribute --- the reason phrase returned by the server --- instead of the response headers as it is specified in the documentation for HTTPResponse. For FTP, file, and data URLs and requests explicitly handled by legacy URLopener and FancyURLopener classes, this function returns a urllib.response.addinfourl object. Note that None may be returned if no handler handles the request (though the default installed global OpenerDirector uses UnknownHandler to ensure this never happens). In addition, if proxy settings are detected (for example, when a *_proxy environment variable like http_proxy is set), ProxyHandler is default installed and makes sure the requests are handled through the proxy. ''' global _opener if cafile or capath or cadefault: import warnings warnings.warn("cafile, cpath and cadefault are deprecated, use a " "custom context instead.", DeprecationWarning, 2) if context is not None: raise ValueError( "You can't pass both context and any of cafile, capath, and " "cadefault" ) if not _have_ssl: raise ValueError('SSL support not available') context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH, cafile=cafile, capath=capath) https_handler = HTTPSHandler(context=context) opener = build_opener(https_handler) elif context: https_handler = HTTPSHandler(context=context) opener = build_opener(https_handler) elif _opener is None: _opener = opener = build_opener() else: opener = _opener return opener.open(url, data, timeout)
[ "def", "urlopen", "(", "url", ",", "data", "=", "None", ",", "timeout", "=", "socket", ".", "_GLOBAL_DEFAULT_TIMEOUT", ",", "*", ",", "cafile", "=", "None", ",", "capath", "=", "None", ",", "cadefault", "=", "False", ",", "context", "=", "None", ")", ...
https://github.com/holzschu/Carnets/blob/44effb10ddfc6aa5c8b0687582a724ba82c6b547/Library/lib/python3.7/urllib/request.py#L139-L222
AppScale/gts
46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9
AppServer/lib/antlr3/antlr3/tree.py
python
BaseTree.addChildren
(self, children)
Add all elements of kids list as children of this node
Add all elements of kids list as children of this node
[ "Add", "all", "elements", "of", "kids", "list", "as", "children", "of", "this", "node" ]
def addChildren(self, children): """Add all elements of kids list as children of this node""" self.children += children
[ "def", "addChildren", "(", "self", ",", "children", ")", ":", "self", ".", "children", "+=", "children" ]
https://github.com/AppScale/gts/blob/46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9/AppServer/lib/antlr3/antlr3/tree.py#L741-L744
yt-project/yt
dc7b24f9b266703db4c843e329c6c8644d47b824
yt/visualization/plot_modifications.py
python
MarkerAnnotateCallback.__init__
(self, pos, marker="x", coord_system="data", plot_args=None)
[]
def __init__(self, pos, marker="x", coord_system="data", plot_args=None): def_plot_args = {"color": "w", "s": 50} self.pos = pos self.marker = marker if plot_args is None: plot_args = def_plot_args self.plot_args = plot_args self.coord_system = coord_system self.transform = None
[ "def", "__init__", "(", "self", ",", "pos", ",", "marker", "=", "\"x\"", ",", "coord_system", "=", "\"data\"", ",", "plot_args", "=", "None", ")", ":", "def_plot_args", "=", "{", "\"color\"", ":", "\"w\"", ",", "\"s\"", ":", "50", "}", "self", ".", "...
https://github.com/yt-project/yt/blob/dc7b24f9b266703db4c843e329c6c8644d47b824/yt/visualization/plot_modifications.py#L1536-L1544
robotlearn/pyrobolearn
9cd7c060723fda7d2779fa255ac998c2c82b8436
pyrobolearn/rewards/geometric_rewards.py
python
SphericalReward.__init__
(self, bodies, link_ids=-1, attached_body=None, attached_link_id=-1, position=None, orientation=None, radius=1, theta=(0, 2*np.pi), phi=(0, np.pi), radius_reward_range=None, theta_reward_ranges=None, height_reward_range=None, interpolation='linear', simulator=None)
Initialize the spherical reward. Args: bodies (int, Body, list[int], list[Body]): the bodies or body unique ids that we should check if they are inside the sphere. link_ids (int, list[int]): the link id associated to each body. By default, it is -1 for the base. attached_body (Body, int, None): the body instance or unique id to which the spherical reward is attached to. If None, it will be attached to the world frame. attached_link_id (int, None): the link id to which the reward is attached to. By default, it is -1 for the base. position (np.array/list/tuple[float[3]], None): local position of the spherical reward. If None, it will be the origin (0,0,0). orientation (np.array/list/tuple[float[4]], None): local orientation (expressed as a quaternion [x,y,z,w]) of the spherical reward. If None, it will be the unit quaternion [0,0,0,1]. radius (float, tuple[float[2]]): radius of the sphere. If two radii are provided, the first one is the inner radius and the second one is the outer radius of the sphere. theta (tuple[float[2]]): the lower and upper bounds of the theta angle. phi (tuple[float[2]]): the lower and upper bounds of the phi angle. radius_reward_range (list[tuple[float[2]]], list/tuple[float[2]]): If a list / tuple of 2 floats, it is the lower and upper bounds of the reward range. If a list of tuple of 2 floats, for each item in the list, it must be a tuple of length 2 `(r,v)` where the first item represents the radius value `r` and the second item represents the associated reward value `v`. theta_reward_ranges (list[tuple[float[2]]], list/tuple[float[2]]): If a list / tuple of 2 floats, it is the lower and upper bounds of the reward range. If a list of tuple of 2 floats, for each item in the list, it must be a tuple of length 2 `(t,v)` where the first item represents the theta angle value `t` and the second item represents the associated reward value `v`. height_reward_range (list[tuple[float[2]]], list/tuple[float[2]]): If a list / tuple of 2 floats, it is the lower and upper bounds of the reward range. If a list of tuple of 2 floats, for each item in the list, it must be a tuple of length 2 `(h,v)` where the first item represents the height value `h` and the second item represents the associated reward value `v`. interpolation (str): the interpolation method to use for the given reward ranges. Currently, you can select between 'linear' or 'step'. simulator (Simulator, None): if the given bodies are all unique ids, the simulator instance has to be provided.
Initialize the spherical reward.
[ "Initialize", "the", "spherical", "reward", "." ]
def __init__(self, bodies, link_ids=-1, attached_body=None, attached_link_id=-1, position=None, orientation=None, radius=1, theta=(0, 2*np.pi), phi=(0, np.pi), radius_reward_range=None, theta_reward_ranges=None, height_reward_range=None, interpolation='linear', simulator=None): """ Initialize the spherical reward. Args: bodies (int, Body, list[int], list[Body]): the bodies or body unique ids that we should check if they are inside the sphere. link_ids (int, list[int]): the link id associated to each body. By default, it is -1 for the base. attached_body (Body, int, None): the body instance or unique id to which the spherical reward is attached to. If None, it will be attached to the world frame. attached_link_id (int, None): the link id to which the reward is attached to. By default, it is -1 for the base. position (np.array/list/tuple[float[3]], None): local position of the spherical reward. If None, it will be the origin (0,0,0). orientation (np.array/list/tuple[float[4]], None): local orientation (expressed as a quaternion [x,y,z,w]) of the spherical reward. If None, it will be the unit quaternion [0,0,0,1]. radius (float, tuple[float[2]]): radius of the sphere. If two radii are provided, the first one is the inner radius and the second one is the outer radius of the sphere. theta (tuple[float[2]]): the lower and upper bounds of the theta angle. phi (tuple[float[2]]): the lower and upper bounds of the phi angle. radius_reward_range (list[tuple[float[2]]], list/tuple[float[2]]): If a list / tuple of 2 floats, it is the lower and upper bounds of the reward range. If a list of tuple of 2 floats, for each item in the list, it must be a tuple of length 2 `(r,v)` where the first item represents the radius value `r` and the second item represents the associated reward value `v`. theta_reward_ranges (list[tuple[float[2]]], list/tuple[float[2]]): If a list / tuple of 2 floats, it is the lower and upper bounds of the reward range. If a list of tuple of 2 floats, for each item in the list, it must be a tuple of length 2 `(t,v)` where the first item represents the theta angle value `t` and the second item represents the associated reward value `v`. height_reward_range (list[tuple[float[2]]], list/tuple[float[2]]): If a list / tuple of 2 floats, it is the lower and upper bounds of the reward range. If a list of tuple of 2 floats, for each item in the list, it must be a tuple of length 2 `(h,v)` where the first item represents the height value `h` and the second item represents the associated reward value `v`. interpolation (str): the interpolation method to use for the given reward ranges. Currently, you can select between 'linear' or 'step'. simulator (Simulator, None): if the given bodies are all unique ids, the simulator instance has to be provided. """ pass
[ "def", "__init__", "(", "self", ",", "bodies", ",", "link_ids", "=", "-", "1", ",", "attached_body", "=", "None", ",", "attached_link_id", "=", "-", "1", ",", "position", "=", "None", ",", "orientation", "=", "None", ",", "radius", "=", "1", ",", "th...
https://github.com/robotlearn/pyrobolearn/blob/9cd7c060723fda7d2779fa255ac998c2c82b8436/pyrobolearn/rewards/geometric_rewards.py#L49-L88
makehumancommunity/makehuman
8006cf2cc851624619485658bb933a4244bbfd7c
makehuman/core/transformations.py
python
affine_matrix_from_points
(v0, v1, shear=True, scale=True, usesvd=True)
return M
Return affine transform matrix to register two point sets. v0 and v1 are shape (ndims, \*) arrays of at least ndims non-homogeneous coordinates, where ndims is the dimensionality of the coordinate space. If shear is False, a similarity transformation matrix is returned. If also scale is False, a rigid/Eucledian transformation matrix is returned. By default the algorithm by Hartley and Zissermann [15] is used. If usesvd is True, similarity and Eucledian transformation matrices are calculated by minimizing the weighted sum of squared deviations (RMSD) according to the algorithm by Kabsch [8]. Otherwise, and if ndims is 3, the quaternion based algorithm by Horn [9] is used, which is slower when using this Python implementation. The returned matrix performs rotation, translation and uniform scaling (if specified). >>> v0 = [[0, 1031, 1031, 0], [0, 0, 1600, 1600]] >>> v1 = [[675, 826, 826, 677], [55, 52, 281, 277]] >>> affine_matrix_from_points(v0, v1) array([[ 0.14549, 0.00062, 675.50008], [ 0.00048, 0.14094, 53.24971], [ 0. , 0. , 1. ]]) >>> T = translation_matrix(numpy.random.random(3)-0.5) >>> R = random_rotation_matrix(numpy.random.random(3)) >>> S = scale_matrix(random.random()) >>> M = concatenate_matrices(T, R, S) >>> v0 = (numpy.random.rand(4, 100) - 0.5) * 20 >>> v0[3] = 1 >>> v1 = numpy.dot(M, v0) >>> v0[:3] += numpy.random.normal(0, 1e-8, 300).reshape(3, -1) >>> M = affine_matrix_from_points(v0[:3], v1[:3]) >>> numpy.allclose(v1, numpy.dot(M, v0)) True More examples in superimposition_matrix()
Return affine transform matrix to register two point sets.
[ "Return", "affine", "transform", "matrix", "to", "register", "two", "point", "sets", "." ]
def affine_matrix_from_points(v0, v1, shear=True, scale=True, usesvd=True): """Return affine transform matrix to register two point sets. v0 and v1 are shape (ndims, \*) arrays of at least ndims non-homogeneous coordinates, where ndims is the dimensionality of the coordinate space. If shear is False, a similarity transformation matrix is returned. If also scale is False, a rigid/Eucledian transformation matrix is returned. By default the algorithm by Hartley and Zissermann [15] is used. If usesvd is True, similarity and Eucledian transformation matrices are calculated by minimizing the weighted sum of squared deviations (RMSD) according to the algorithm by Kabsch [8]. Otherwise, and if ndims is 3, the quaternion based algorithm by Horn [9] is used, which is slower when using this Python implementation. The returned matrix performs rotation, translation and uniform scaling (if specified). >>> v0 = [[0, 1031, 1031, 0], [0, 0, 1600, 1600]] >>> v1 = [[675, 826, 826, 677], [55, 52, 281, 277]] >>> affine_matrix_from_points(v0, v1) array([[ 0.14549, 0.00062, 675.50008], [ 0.00048, 0.14094, 53.24971], [ 0. , 0. , 1. ]]) >>> T = translation_matrix(numpy.random.random(3)-0.5) >>> R = random_rotation_matrix(numpy.random.random(3)) >>> S = scale_matrix(random.random()) >>> M = concatenate_matrices(T, R, S) >>> v0 = (numpy.random.rand(4, 100) - 0.5) * 20 >>> v0[3] = 1 >>> v1 = numpy.dot(M, v0) >>> v0[:3] += numpy.random.normal(0, 1e-8, 300).reshape(3, -1) >>> M = affine_matrix_from_points(v0[:3], v1[:3]) >>> numpy.allclose(v1, numpy.dot(M, v0)) True More examples in superimposition_matrix() """ v0 = numpy.array(v0, dtype=numpy.float64, copy=True) v1 = numpy.array(v1, dtype=numpy.float64, copy=True) ndims = v0.shape[0] if ndims < 2 or v0.shape[1] < ndims or v0.shape != v1.shape: raise ValueError("input arrays are of wrong shape or type") # move centroids to origin t0 = -numpy.mean(v0, axis=1) M0 = numpy.identity(ndims+1) M0[:ndims, ndims] = t0 v0 += t0.reshape(ndims, 1) t1 = -numpy.mean(v1, axis=1) M1 = numpy.identity(ndims+1) M1[:ndims, ndims] = t1 v1 += t1.reshape(ndims, 1) if shear: # Affine transformation A = numpy.concatenate((v0, v1), axis=0) u, s, vh = numpy.linalg.svd(A.T) vh = vh[:ndims].T B = vh[:ndims] C = vh[ndims:2*ndims] t = numpy.dot(C, numpy.linalg.pinv(B)) t = numpy.concatenate((t, numpy.zeros((ndims, 1))), axis=1) M = numpy.vstack((t, ((0.0,)*ndims) + (1.0,))) elif usesvd or ndims != 3: # Rigid transformation via SVD of covariance matrix u, s, vh = numpy.linalg.svd(numpy.dot(v1, v0.T)) # rotation matrix from SVD orthonormal bases R = numpy.dot(u, vh) if numpy.linalg.det(R) < 0.0: # R does not constitute right handed system R -= numpy.outer(u[:, ndims-1], vh[ndims-1, :]*2.0) s[-1] *= -1.0 # homogeneous transformation matrix M = numpy.identity(ndims+1) M[:ndims, :ndims] = R else: # Rigid transformation matrix via quaternion # compute symmetric matrix N xx, yy, zz = numpy.sum(v0 * v1, axis=1) xy, yz, zx = numpy.sum(v0 * numpy.roll(v1, -1, axis=0), axis=1) xz, yx, zy = numpy.sum(v0 * numpy.roll(v1, -2, axis=0), axis=1) N = [[xx+yy+zz, 0.0, 0.0, 0.0], [yz-zy, xx-yy-zz, 0.0, 0.0], [zx-xz, xy+yx, yy-xx-zz, 0.0], [xy-yx, zx+xz, yz+zy, zz-xx-yy]] # quaternion: eigenvector corresponding to most positive eigenvalue w, V = numpy.linalg.eigh(N) q = V[:, numpy.argmax(w)] q /= vector_norm(q) # unit quaternion # homogeneous transformation matrix M = quaternion_matrix(q) if scale and not shear: # Affine transformation; scale is ratio of RMS deviations from centroid v0 *= v0 v1 *= v1 M[:ndims, :ndims] *= math.sqrt(numpy.sum(v1) / numpy.sum(v0)) # move centroids back M = numpy.dot(numpy.linalg.inv(M1), numpy.dot(M, M0)) M /= M[ndims, ndims] return M
[ "def", "affine_matrix_from_points", "(", "v0", ",", "v1", ",", "shear", "=", "True", ",", "scale", "=", "True", ",", "usesvd", "=", "True", ")", ":", "v0", "=", "numpy", ".", "array", "(", "v0", ",", "dtype", "=", "numpy", ".", "float64", ",", "cop...
https://github.com/makehumancommunity/makehuman/blob/8006cf2cc851624619485658bb933a4244bbfd7c/makehuman/core/transformations.py#L904-L1010
makerbot/ReplicatorG
d6f2b07785a5a5f1e172fb87cb4303b17c575d5d
skein_engines/skeinforge-50/fabmetheus_utilities/svg_reader.py
python
getMatrixSVG
(elementNode)
return matrixSVG
Get matrixSVG by svgElement.
Get matrixSVG by svgElement.
[ "Get", "matrixSVG", "by", "svgElement", "." ]
def getMatrixSVG(elementNode): "Get matrixSVG by svgElement." matrixSVG = MatrixSVG() if 'transform' not in elementNode.attributes: return matrixSVG transformWords = [] for transformWord in elementNode.attributes['transform'].replace(')', '(').split('('): transformWordStrip = transformWord.strip() if transformWordStrip != '': # workaround for split(character) bug which leaves an extra empty element transformWords.append(transformWordStrip) global globalGetTricomplexDictionary getTricomplexDictionaryKeys = globalGetTricomplexDictionary.keys() for transformWordIndex, transformWord in enumerate(transformWords): if transformWord in getTricomplexDictionaryKeys: transformString = transformWords[transformWordIndex + 1].replace(',', ' ') matrixSVG = matrixSVG.getSelfTimesOther(globalGetTricomplexDictionary[ transformWord ](transformString.split())) return matrixSVG
[ "def", "getMatrixSVG", "(", "elementNode", ")", ":", "matrixSVG", "=", "MatrixSVG", "(", ")", "if", "'transform'", "not", "in", "elementNode", ".", "attributes", ":", "return", "matrixSVG", "transformWords", "=", "[", "]", "for", "transformWord", "in", "elemen...
https://github.com/makerbot/ReplicatorG/blob/d6f2b07785a5a5f1e172fb87cb4303b17c575d5d/skein_engines/skeinforge-50/fabmetheus_utilities/svg_reader.py#L181-L197
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/config/area_registry.py
python
_entry_dict
(entry)
return {"area_id": entry.id, "name": entry.name, "picture": entry.picture}
Convert entry to API format.
Convert entry to API format.
[ "Convert", "entry", "to", "API", "format", "." ]
def _entry_dict(entry): """Convert entry to API format.""" return {"area_id": entry.id, "name": entry.name, "picture": entry.picture}
[ "def", "_entry_dict", "(", "entry", ")", ":", "return", "{", "\"area_id\"", ":", "entry", ".", "id", ",", "\"name\"", ":", "entry", ".", "name", ",", "\"picture\"", ":", "entry", ".", "picture", "}" ]
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/config/area_registry.py#L101-L103
ring04h/wyportmap
c4201e2313504e780a7f25238eba2a2d3223e739
sqlalchemy/orm/loading.py
python
merge_result
(querylib, query, iterator, load=True)
Merge a result into this :class:`.Query` object's Session.
Merge a result into this :class:`.Query` object's Session.
[ "Merge", "a", "result", "into", "this", ":", "class", ":", ".", "Query", "object", "s", "Session", "." ]
def merge_result(querylib, query, iterator, load=True): """Merge a result into this :class:`.Query` object's Session.""" session = query.session if load: # flush current contents if we expect to load data session._autoflush() autoflush = session.autoflush try: session.autoflush = False single_entity = len(query._entities) == 1 if single_entity: if isinstance(query._entities[0], querylib._MapperEntity): result = [session._merge( attributes.instance_state(instance), attributes.instance_dict(instance), load=load, _recursive={}) for instance in iterator] else: result = list(iterator) else: mapped_entities = [i for i, e in enumerate(query._entities) if isinstance(e, querylib._MapperEntity)] result = [] keys = [ent._label_name for ent in query._entities] for row in iterator: newrow = list(row) for i in mapped_entities: if newrow[i] is not None: newrow[i] = session._merge( attributes.instance_state(newrow[i]), attributes.instance_dict(newrow[i]), load=load, _recursive={}) result.append(util.KeyedTuple(newrow, keys)) return iter(result) finally: session.autoflush = autoflush
[ "def", "merge_result", "(", "querylib", ",", "query", ",", "iterator", ",", "load", "=", "True", ")", ":", "session", "=", "query", ".", "session", "if", "load", ":", "# flush current contents if we expect to load data", "session", ".", "_autoflush", "(", ")", ...
https://github.com/ring04h/wyportmap/blob/c4201e2313504e780a7f25238eba2a2d3223e739/sqlalchemy/orm/loading.py#L103-L141
vlachoudis/bCNC
67126b4894dabf6579baf47af8d0f9b7de35e6e3
bCNC/lib/svg_elements.py
python
Circle._name
(self)
return self.__class__.__name__
[]
def _name(self): return self.__class__.__name__
[ "def", "_name", "(", "self", ")", ":", "return", "self", ".", "__class__", ".", "__name__" ]
https://github.com/vlachoudis/bCNC/blob/67126b4894dabf6579baf47af8d0f9b7de35e6e3/bCNC/lib/svg_elements.py#L6188-L6189
pylessard/python-udsoncan
79b20e5d91eed78c9a3137a4c1511ce5d832ae9c
udsoncan/client.py
python
Client.request_seed
(self, level, data=bytes())
return response
Requests a seed to unlock a security level with the :ref:`SecurityAccess<SecurityAccess>` service :Effective configuration: ``exception_on_<type>_response`` :param level: The security level to unlock. If value is even, it will be converted to the corresponding odd value :type level: int :param data: The data to send to the server :type data: bytes :return: The server response parsed by :meth:`SecurityAccess.interpret_response<udsoncan.services.SecurityAccess.interpret_response>` :rtype: :ref:`Response<Response>`
Requests a seed to unlock a security level with the :ref:`SecurityAccess<SecurityAccess>` service
[ "Requests", "a", "seed", "to", "unlock", "a", "security", "level", "with", "the", ":", "ref", ":", "SecurityAccess<SecurityAccess", ">", "service" ]
def request_seed(self, level, data=bytes()): """ Requests a seed to unlock a security level with the :ref:`SecurityAccess<SecurityAccess>` service :Effective configuration: ``exception_on_<type>_response`` :param level: The security level to unlock. If value is even, it will be converted to the corresponding odd value :type level: int :param data: The data to send to the server :type data: bytes :return: The server response parsed by :meth:`SecurityAccess.interpret_response<udsoncan.services.SecurityAccess.interpret_response>` :rtype: :ref:`Response<Response>` """ req = services.SecurityAccess.make_request(level, mode=services.SecurityAccess.Mode.RequestSeed, data=data) self.logger.info('%s - Requesting seed to unlock security access level 0x%02x' % (self.service_log_prefix(services.SecurityAccess), req.subfunction)) # level may be corrected by service. response = self.send_request(req) if response is None: return services.SecurityAccess.interpret_response(response, mode=services.SecurityAccess.Mode.RequestSeed) expected_level = services.SecurityAccess.normalize_level(mode=services.SecurityAccess.Mode.RequestSeed, level=level) received_level = response.service_data.security_level_echo if expected_level != received_level: raise UnexpectedResponseException(response, "Response subfunction received from server (0x%02x) does not match the requested subfunction (0x%02x)" % (received_level, expected_level)) self.logger.debug('Received seed [%s]' % (binascii.hexlify(response.service_data.seed))) return response
[ "def", "request_seed", "(", "self", ",", "level", ",", "data", "=", "bytes", "(", ")", ")", ":", "req", "=", "services", ".", "SecurityAccess", ".", "make_request", "(", "level", ",", "mode", "=", "services", ".", "SecurityAccess", ".", "Mode", ".", "R...
https://github.com/pylessard/python-udsoncan/blob/79b20e5d91eed78c9a3137a4c1511ce5d832ae9c/udsoncan/client.py#L207-L238
awslabs/aws-lambda-powertools-python
0c6ac0fe183476140ee1df55fe9fa1cc20925577
aws_lambda_powertools/utilities/data_classes/appsync_authorizer_event.py
python
AppSyncAuthorizerResponse.asdict
(self)
return response
Return the response as a dict
Return the response as a dict
[ "Return", "the", "response", "as", "a", "dict" ]
def asdict(self) -> dict: """Return the response as a dict""" response: Dict = {"isAuthorized": self.authorize} if self.max_age is not None: response["ttlOverride"] = self.max_age if self.deny_fields: response["deniedFields"] = self.deny_fields if self.resolver_context: response["resolverContext"] = self.resolver_context return response
[ "def", "asdict", "(", "self", ")", "->", "dict", ":", "response", ":", "Dict", "=", "{", "\"isAuthorized\"", ":", "self", ".", "authorize", "}", "if", "self", ".", "max_age", "is", "not", "None", ":", "response", "[", "\"ttlOverride\"", "]", "=", "self...
https://github.com/awslabs/aws-lambda-powertools-python/blob/0c6ac0fe183476140ee1df55fe9fa1cc20925577/aws_lambda_powertools/utilities/data_classes/appsync_authorizer_event.py#L103-L116
dcsync/pycobalt
d3a630bfadaeeb6c99aad28f226abe48f6b4acca
pycobalt/aggressor.py
python
bspunnel_local
(*args, fork=None, sync=True)
return engine.call('bspunnel_local', args, fork=fork, sync=sync)
r""" Documentation from https://www.cobaltstrike.com/aggressor-script/functions.html: Spawn and tunnel an agent through this Beacon (via a target localhost-only reverse port forward). Note: this reverse port forward tunnel traverses through the Beacon chain to the team server and, via the team server, out through the requesting Cobalt Strike client. Arguments $1 - the id for the beacon. This may be an array or a single ID. $2 - the host of the controller $3 - the port of the controller $4 - a file with position-independent code to execute in a temporary process. Example bspunnel_local($1, "127.0.0.1", 4444, script_resource("agent.bin"));
r""" Documentation from https://www.cobaltstrike.com/aggressor-script/functions.html:
[ "r", "Documentation", "from", "https", ":", "//", "www", ".", "cobaltstrike", ".", "com", "/", "aggressor", "-", "script", "/", "functions", ".", "html", ":" ]
def bspunnel_local(*args, fork=None, sync=True): r""" Documentation from https://www.cobaltstrike.com/aggressor-script/functions.html: Spawn and tunnel an agent through this Beacon (via a target localhost-only reverse port forward). Note: this reverse port forward tunnel traverses through the Beacon chain to the team server and, via the team server, out through the requesting Cobalt Strike client. Arguments $1 - the id for the beacon. This may be an array or a single ID. $2 - the host of the controller $3 - the port of the controller $4 - a file with position-independent code to execute in a temporary process. Example bspunnel_local($1, "127.0.0.1", 4444, script_resource("agent.bin")); """ return engine.call('bspunnel_local', args, fork=fork, sync=sync)
[ "def", "bspunnel_local", "(", "*", "args", ",", "fork", "=", "None", ",", "sync", "=", "True", ")", ":", "return", "engine", ".", "call", "(", "'bspunnel_local'", ",", "args", ",", "fork", "=", "fork", ",", "sync", "=", "sync", ")" ]
https://github.com/dcsync/pycobalt/blob/d3a630bfadaeeb6c99aad28f226abe48f6b4acca/pycobalt/aggressor.py#L3372-L3387
JaniceWuo/MovieRecommend
4c86db64ca45598917d304f535413df3bc9fea65
movierecommend/venv1/Lib/site-packages/django/db/backends/base/operations.py
python
BaseDatabaseOperations.last_insert_id
(self, cursor, table_name, pk_name)
return cursor.lastrowid
Given a cursor object that has just performed an INSERT statement into a table that has an auto-incrementing ID, returns the newly created ID. This method also receives the table name and the name of the primary-key column.
Given a cursor object that has just performed an INSERT statement into a table that has an auto-incrementing ID, returns the newly created ID.
[ "Given", "a", "cursor", "object", "that", "has", "just", "performed", "an", "INSERT", "statement", "into", "a", "table", "that", "has", "an", "auto", "-", "incrementing", "ID", "returns", "the", "newly", "created", "ID", "." ]
def last_insert_id(self, cursor, table_name, pk_name): """ Given a cursor object that has just performed an INSERT statement into a table that has an auto-incrementing ID, returns the newly created ID. This method also receives the table name and the name of the primary-key column. """ return cursor.lastrowid
[ "def", "last_insert_id", "(", "self", ",", "cursor", ",", "table_name", ",", "pk_name", ")", ":", "return", "cursor", ".", "lastrowid" ]
https://github.com/JaniceWuo/MovieRecommend/blob/4c86db64ca45598917d304f535413df3bc9fea65/movierecommend/venv1/Lib/site-packages/django/db/backends/base/operations.py#L227-L235
bbc/brave
88d4454412ee5acfa5ecf2ac5bc8cf75766c7be5
brave/connections/connection.py
python
Connection._get_pad_to_connect_tee_to
(self, audio_or_video)
return queue.get_static_pad('sink')
Returns the pad of the queue that should be connected to from the source's 'tee' element.
Returns the pad of the queue that should be connected to from the source's 'tee' element.
[ "Returns", "the", "pad", "of", "the", "queue", "that", "should", "be", "connected", "to", "from", "the", "source", "s", "tee", "element", "." ]
def _get_pad_to_connect_tee_to(self, audio_or_video): ''' Returns the pad of the queue that should be connected to from the source's 'tee' element. ''' queue = self._queue_into_intersink[audio_or_video] if not queue: self.logger.error('Failed to connect tee to queue: cannot find queue') return return queue.get_static_pad('sink')
[ "def", "_get_pad_to_connect_tee_to", "(", "self", ",", "audio_or_video", ")", ":", "queue", "=", "self", ".", "_queue_into_intersink", "[", "audio_or_video", "]", "if", "not", "queue", ":", "self", ".", "logger", ".", "error", "(", "'Failed to connect tee to queue...
https://github.com/bbc/brave/blob/88d4454412ee5acfa5ecf2ac5bc8cf75766c7be5/brave/connections/connection.py#L168-L177
Carlos-Zen/blockchain-python
e28a4886cce03a790fe0a57fcd9896fa7b4b239f
rpc.py
python
RpcServer.get_blockchain
(self)
return bcdb.find_all()
[]
def get_blockchain(self): bcdb = BlockChainDB() return bcdb.find_all()
[ "def", "get_blockchain", "(", "self", ")", ":", "bcdb", "=", "BlockChainDB", "(", ")", "return", "bcdb", ".", "find_all", "(", ")" ]
https://github.com/Carlos-Zen/blockchain-python/blob/e28a4886cce03a790fe0a57fcd9896fa7b4b239f/rpc.py#L19-L21
translate/translate
72816df696b5263abfe80ab59129b299b85ae749
translate/storage/dtd.py
python
dtdunit.source
(self, source)
Sets the definition to the quoted value of source
Sets the definition to the quoted value of source
[ "Sets", "the", "definition", "to", "the", "quoted", "value", "of", "source" ]
def source(self, source): """Sets the definition to the quoted value of source""" if self.android: self.definition = quoteforandroid(source) else: self.definition = quotefordtd(source) self._rich_source = None
[ "def", "source", "(", "self", ",", "source", ")", ":", "if", "self", ".", "android", ":", "self", ".", "definition", "=", "quoteforandroid", "(", "source", ")", "else", ":", "self", ".", "definition", "=", "quotefordtd", "(", "source", ")", "self", "."...
https://github.com/translate/translate/blob/72816df696b5263abfe80ab59129b299b85ae749/translate/storage/dtd.py#L250-L256
kanzure/nanoengineer
874e4c9f8a9190f093625b267f9767e19f82e6c4
cad/src/graphics/widgets/GLPane_drawingset_methods.py
python
GLPane_drawingset_methods._call_func_that_draws_model
(self, func, prefunc = None, postfunc = None, bare_primitives = None, drawing_phase = None, whole_model = True )
return res
If whole_model is False (*not* the default): Call func() between calls of self._before_drawing_csdls(**kws) and self._after_drawing_csdls(). Return whatever func() returns (or raise whatever exception it raises, but call _after_drawing_csdls even when raising an exception). func should usually be something which calls before/after_drawing_model inside it, e.g. one of the standard functions for drawing the entire model (e.g. part.draw or graphicsMode.Draw), or self._call_func_that_draws_objects which draws a portion of the model between those methods. If whole_model is True (default): Sometimes act as above, but other times do the same drawing that func would have done, without actually calling it, by reusing cached DrawingSets whenever nothing changed to make them out of date. Either way, always call prefunc (if provided) before, and postfunc (if provided) after, calling or not calling func. Those calls participate in the effect of our exception-protection and drawing_phase behaviors, but they stay out of the whole_model- related optimizations (so they are called even if func is not). @warning: prefunc and postfunc are not called between _before_drawing_csdls and _after_drawing_csdls, so they should not use csdls for drawing. (If we need to revise this, we might want to pass a list of funcs rather than a single func, with each one optimized separately for sometimes not being called; or more likely, refactor this entirely to make each func and its redraw-vs-reuse conditions a GraphicsRule object.) @param bare_primitives: passed to _before_drawing_csdls. @param drawing_phase: if provided, drawing_phase must be '?' on entry; we'll set it as specified only during this call. If not provided, we don't check it or change it (typically, in that case, caller ought to do something to set it properly itself). The value of drawing_phase matters and needs to correspond to what's drawn by func, because it determines the "drawingset_cache" (see that term in the code for details). @param whole_model: whether func draws the whole model. Default True. Permits optimizations when the model appearance doesn't change since it was last drawn.
If whole_model is False (*not* the default):
[ "If", "whole_model", "is", "False", "(", "*", "not", "*", "the", "default", ")", ":" ]
def _call_func_that_draws_model(self, func, prefunc = None, postfunc = None, bare_primitives = None, drawing_phase = None, whole_model = True ): """ If whole_model is False (*not* the default): Call func() between calls of self._before_drawing_csdls(**kws) and self._after_drawing_csdls(). Return whatever func() returns (or raise whatever exception it raises, but call _after_drawing_csdls even when raising an exception). func should usually be something which calls before/after_drawing_model inside it, e.g. one of the standard functions for drawing the entire model (e.g. part.draw or graphicsMode.Draw), or self._call_func_that_draws_objects which draws a portion of the model between those methods. If whole_model is True (default): Sometimes act as above, but other times do the same drawing that func would have done, without actually calling it, by reusing cached DrawingSets whenever nothing changed to make them out of date. Either way, always call prefunc (if provided) before, and postfunc (if provided) after, calling or not calling func. Those calls participate in the effect of our exception-protection and drawing_phase behaviors, but they stay out of the whole_model- related optimizations (so they are called even if func is not). @warning: prefunc and postfunc are not called between _before_drawing_csdls and _after_drawing_csdls, so they should not use csdls for drawing. (If we need to revise this, we might want to pass a list of funcs rather than a single func, with each one optimized separately for sometimes not being called; or more likely, refactor this entirely to make each func and its redraw-vs-reuse conditions a GraphicsRule object.) @param bare_primitives: passed to _before_drawing_csdls. @param drawing_phase: if provided, drawing_phase must be '?' on entry; we'll set it as specified only during this call. If not provided, we don't check it or change it (typically, in that case, caller ought to do something to set it properly itself). The value of drawing_phase matters and needs to correspond to what's drawn by func, because it determines the "drawingset_cache" (see that term in the code for details). @param whole_model: whether func draws the whole model. Default True. Permits optimizations when the model appearance doesn't change since it was last drawn. """ # as of 090317, defined only here, called here and elsewhere # (in many places); likely to remain unchanged in our API for other # methods and client objects, even after planned upcoming refactoring, # though we may replace *some* of its calls with something modified, # as if inlining the refactored form. # todo: convert some older callers to pass drawing_phase # rather than implementing their own similar behavior. if drawing_phase is not None: assert self.drawing_phase == '?' self.set_drawing_phase(drawing_phase) if prefunc: try: prefunc() except: msg = "bug: exception in %r calling prefunc %r: skipping it" % (self, prefunc) print_compact_traceback(msg + ": ") pass pass if whole_model: dset_change_indicator = self._whole_model_drawingset_change_indicator() # note: if this is not false, then if a certain debug_pref is enabled, # then if we'd use a drawingset_cache and one already # exists and has the same value of dset_change_indicator # saved from our last use of that cache, we assume there # is no need to remake the drawingsets and therefore # no need to call func at all; instead we just redraw # the saved drawingsets. This is never correct -- in practice # some faster but nonnull alternative to func would need # to be called -- but is useful for testing the maximum # speedup possible from an "incremental remake of drawing" # optimization, and is a prototype for correct versions # of similar optimizations. [bruce 090309] else: dset_change_indicator = None skip_dset_remake = self._before_drawing_csdls( bare_primitives = bare_primitives, dset_change_indicator = dset_change_indicator ) # WARNING: if skip_dset_remake, we are REQUIRED (as of 090313) # (not just permitted, as before) # [or at least we would have been if I had finished implementing # usage tracking -- see comment elsewhere for status -- bruce 090317] # to do nothing to any of our cached dsets or csdl collectors # (i.e. to do no drawing) before calling _after_drawing_csdls. # Fortunately we call it just below, so it's easy to verify # this requirement -- just don't forget to think about this # if you modify the following code. (### Todo: refactor this to # make it more failsafe, e.g. pass func to a single method # which encapsulates _before_drawing_csdls and _after_drawing_csdls... # but wait, isn't *this* method that single method? Ok, just make # them private [done] and document them as only for use by this # method [done]. Or maybe a smaller part of this really *should* be # a single method.... [yes, or worse -- 090317]) error = True res = None try: if not skip_dset_remake: res = func() error = False finally: # (note: this is usually what does much of the actual drawing # requested by func()) self._after_drawing_csdls( error, reuse_cached_dsets_unchanged = skip_dset_remake, dset_change_indicator = dset_change_indicator ) if postfunc: try: postfunc() except: msg = "bug: exception in %r calling postfunc %r: skipping it" % (self, postfunc) print_compact_traceback(msg + ": ") pass pass if drawing_phase is not None: self.set_drawing_phase('?') return res
[ "def", "_call_func_that_draws_model", "(", "self", ",", "func", ",", "prefunc", "=", "None", ",", "postfunc", "=", "None", ",", "bare_primitives", "=", "None", ",", "drawing_phase", "=", "None", ",", "whole_model", "=", "True", ")", ":", "# as of 090317, defin...
https://github.com/kanzure/nanoengineer/blob/874e4c9f8a9190f093625b267f9767e19f82e6c4/cad/src/graphics/widgets/GLPane_drawingset_methods.py#L383-L519
modflowpy/flopy
eecd1ad193c5972093c9712e5c4b7a83284f0688
flopy/export/metadata.py
python
acdd.geospatial_bounds_vertical_crs
(self)
return epsg.get(self.vertical_datum)
The vertical coordinate reference system (CRS) for the Z axis of the point coordinates in the geospatial_bounds attribute.
The vertical coordinate reference system (CRS) for the Z axis of the point coordinates in the geospatial_bounds attribute.
[ "The", "vertical", "coordinate", "reference", "system", "(", "CRS", ")", "for", "the", "Z", "axis", "of", "the", "point", "coordinates", "in", "the", "geospatial_bounds", "attribute", "." ]
def geospatial_bounds_vertical_crs(self): """ The vertical coordinate reference system (CRS) for the Z axis of the point coordinates in the geospatial_bounds attribute. """ epsg = {"NGVD29": "EPSG:5702", "NAVD88": "EPSG:5703"} return epsg.get(self.vertical_datum)
[ "def", "geospatial_bounds_vertical_crs", "(", "self", ")", ":", "epsg", "=", "{", "\"NGVD29\"", ":", "\"EPSG:5702\"", ",", "\"NAVD88\"", ":", "\"EPSG:5703\"", "}", "return", "epsg", ".", "get", "(", "self", ".", "vertical_datum", ")" ]
https://github.com/modflowpy/flopy/blob/eecd1ad193c5972093c9712e5c4b7a83284f0688/flopy/export/metadata.py#L162-L168
caiiiac/Machine-Learning-with-Python
1a26c4467da41ca4ebc3d5bd789ea942ef79422f
MachineLearning/venv/lib/python3.5/site-packages/scipy/spatial/distance.py
python
chebyshev
(u, v)
return max(abs(u - v))
Computes the Chebyshev distance. Computes the Chebyshev distance between two 1-D arrays `u` and `v`, which is defined as .. math:: \\max_i {|u_i-v_i|}. Parameters ---------- u : (N,) array_like Input vector. v : (N,) array_like Input vector. Returns ------- chebyshev : double The Chebyshev distance between vectors `u` and `v`.
Computes the Chebyshev distance.
[ "Computes", "the", "Chebyshev", "distance", "." ]
def chebyshev(u, v): """ Computes the Chebyshev distance. Computes the Chebyshev distance between two 1-D arrays `u` and `v`, which is defined as .. math:: \\max_i {|u_i-v_i|}. Parameters ---------- u : (N,) array_like Input vector. v : (N,) array_like Input vector. Returns ------- chebyshev : double The Chebyshev distance between vectors `u` and `v`. """ u = _validate_vector(u) v = _validate_vector(v) return max(abs(u - v))
[ "def", "chebyshev", "(", "u", ",", "v", ")", ":", "u", "=", "_validate_vector", "(", "u", ")", "v", "=", "_validate_vector", "(", "v", ")", "return", "max", "(", "abs", "(", "u", "-", "v", ")", ")" ]
https://github.com/caiiiac/Machine-Learning-with-Python/blob/1a26c4467da41ca4ebc3d5bd789ea942ef79422f/MachineLearning/venv/lib/python3.5/site-packages/scipy/spatial/distance.py#L753-L779
inventree/InvenTree
4a5e4a88ac3e91d64a21e8cab3708ecbc6e2bd8b
InvenTree/label/models.py
python
PartLabel.get_context_data
(self, request)
return { 'part': part, 'category': part.category, 'name': part.name, 'description': part.description, 'IPN': part.IPN, 'revision': part.revision, 'qr_data': part.format_barcode(brief=True), 'qr_url': part.format_barcode(url=True, request=request), 'parameters': part.parameters_map(), }
Generate context data for each provided Part object
Generate context data for each provided Part object
[ "Generate", "context", "data", "for", "each", "provided", "Part", "object" ]
def get_context_data(self, request): """ Generate context data for each provided Part object """ part = self.object_to_print return { 'part': part, 'category': part.category, 'name': part.name, 'description': part.description, 'IPN': part.IPN, 'revision': part.revision, 'qr_data': part.format_barcode(brief=True), 'qr_url': part.format_barcode(url=True, request=request), 'parameters': part.parameters_map(), }
[ "def", "get_context_data", "(", "self", ",", "request", ")", ":", "part", "=", "self", ".", "object_to_print", "return", "{", "'part'", ":", "part", ",", "'category'", ":", "part", ".", "category", ",", "'name'", ":", "part", ".", "name", ",", "'descript...
https://github.com/inventree/InvenTree/blob/4a5e4a88ac3e91d64a21e8cab3708ecbc6e2bd8b/InvenTree/label/models.py#L387-L404
rowliny/DiffHelper
ab3a96f58f9579d0023aed9ebd785f4edf26f8af
Tool/SitePackages/nltk/sem/logic.py
python
NegatedExpression.visit
(self, function, combinator)
return combinator([function(self.term)])
:see: Expression.visit()
:see: Expression.visit()
[ ":", "see", ":", "Expression", ".", "visit", "()" ]
def visit(self, function, combinator): """:see: Expression.visit()""" return combinator([function(self.term)])
[ "def", "visit", "(", "self", ",", "function", ",", "combinator", ")", ":", "return", "combinator", "(", "[", "function", "(", "self", ".", "term", ")", "]", ")" ]
https://github.com/rowliny/DiffHelper/blob/ab3a96f58f9579d0023aed9ebd785f4edf26f8af/Tool/SitePackages/nltk/sem/logic.py#L1781-L1783
ynvb/DIE
453fbdf137bfe0510e760df73441d41d35ea74d6
DIE/UI/ParserView.py
python
ParserView._add_parser_data
(self)
Add parser data to the parser widget model @return:
Add parser data to the parser widget model
[ "Add", "parser", "data", "to", "the", "parser", "widget", "model" ]
def _add_parser_data(self): """ Add parser data to the parser widget model @return: """ row = 0 parser_list = self.data_parser.get_parser_list() if not "headers" in parser_list: return header_list = parser_list["headers"] header_list.insert(0, "Plugin Name") del parser_list["headers"] # Remove headers item self.ptable_widget.setHeaderLabels(header_list) self.ptable_widget.setColumnWidth(0, 200) self.ptable_widget.setColumnWidth(1, 500) self.ptable_widget.setColumnWidth(2, 80) self.ptable_widget.setColumnWidth(3, 80) self.ptable_widget.setColumnWidth(4, 200) root_item = self.ptable_widget.invisibleRootItem() for parser in parser_list: current_row_item = QtWidgets.QTreeWidgetItem() current_row_item.setFlags(QtCore.Qt.ItemIsEnabled) current_row_item.setText(0, parser) num_columns = len(parser_list[parser]) for column in xrange(0, num_columns): currext_text = str(parser_list[parser][column]) current_row_item.setText(column+1, currext_text) root_item.insertChild(row, current_row_item) row += 1
[ "def", "_add_parser_data", "(", "self", ")", ":", "row", "=", "0", "parser_list", "=", "self", ".", "data_parser", ".", "get_parser_list", "(", ")", "if", "not", "\"headers\"", "in", "parser_list", ":", "return", "header_list", "=", "parser_list", "[", "\"he...
https://github.com/ynvb/DIE/blob/453fbdf137bfe0510e760df73441d41d35ea74d6/DIE/UI/ParserView.py#L38-L74
google/sre_yield
3af063a0054c4646608b43b941fbfcbe4e01214a
sre_yield/fastdivmod.py
python
divmod_iter_basic
(x, by, chunk=None)
Generate successive (x % by); x /= by, the obvious way. Chunk is ignored.
Generate successive (x % by); x /= by, the obvious way.
[ "Generate", "successive", "(", "x", "%", "by", ")", ";", "x", "/", "=", "by", "the", "obvious", "way", "." ]
def divmod_iter_basic(x, by, chunk=None): """Generate successive (x % by); x /= by, the obvious way. Chunk is ignored. """ while x: x, m = divmod(x, by) yield m
[ "def", "divmod_iter_basic", "(", "x", ",", "by", ",", "chunk", "=", "None", ")", ":", "while", "x", ":", "x", ",", "m", "=", "divmod", "(", "x", ",", "by", ")", "yield", "m" ]
https://github.com/google/sre_yield/blob/3af063a0054c4646608b43b941fbfcbe4e01214a/sre_yield/fastdivmod.py#L98-L105
nate-parrott/Flashlight
c3a7c7278a1cccf8918e7543faffc68e863ff5ab
PluginDirectories/1/NightFoxAmbient.bundle/requests/models.py
python
RequestEncodingMixin._encode_params
(data)
Encode parameters in a piece of data. Will successfully encode parameters when passed as a dict or a list of 2-tuples. Order is retained if data is a list of 2-tuples but arbitrary if parameters are supplied as a dict.
Encode parameters in a piece of data.
[ "Encode", "parameters", "in", "a", "piece", "of", "data", "." ]
def _encode_params(data): """Encode parameters in a piece of data. Will successfully encode parameters when passed as a dict or a list of 2-tuples. Order is retained if data is a list of 2-tuples but arbitrary if parameters are supplied as a dict. """ if isinstance(data, (str, bytes)): return data elif hasattr(data, 'read'): return data elif hasattr(data, '__iter__'): result = [] for k, vs in to_key_val_list(data): if isinstance(vs, basestring) or not hasattr(vs, '__iter__'): vs = [vs] for v in vs: if v is not None: result.append( (k.encode('utf-8') if isinstance(k, str) else k, v.encode('utf-8') if isinstance(v, str) else v)) return urlencode(result, doseq=True) else: return data
[ "def", "_encode_params", "(", "data", ")", ":", "if", "isinstance", "(", "data", ",", "(", "str", ",", "bytes", ")", ")", ":", "return", "data", "elif", "hasattr", "(", "data", ",", "'read'", ")", ":", "return", "data", "elif", "hasattr", "(", "data"...
https://github.com/nate-parrott/Flashlight/blob/c3a7c7278a1cccf8918e7543faffc68e863ff5ab/PluginDirectories/1/NightFoxAmbient.bundle/requests/models.py#L75-L99
sendgrid/sendgrid-python
df13b78b0cdcb410b4516f6761c4d3138edd4b2d
sendgrid/helpers/mail/mail.py
python
Mail.add_personalization
(self, personalization, index=0)
Add a Personalization object :param personalization: Add a Personalization object :type personalization: Personalization :param index: The index where to add the Personalization :type index: int
Add a Personalization object
[ "Add", "a", "Personalization", "object" ]
def add_personalization(self, personalization, index=0): """Add a Personalization object :param personalization: Add a Personalization object :type personalization: Personalization :param index: The index where to add the Personalization :type index: int """ self._personalizations = self._ensure_append( personalization, self._personalizations, index)
[ "def", "add_personalization", "(", "self", ",", "personalization", ",", "index", "=", "0", ")", ":", "self", ".", "_personalizations", "=", "self", ".", "_ensure_append", "(", "personalization", ",", "self", ".", "_personalizations", ",", "index", ")" ]
https://github.com/sendgrid/sendgrid-python/blob/df13b78b0cdcb410b4516f6761c4d3138edd4b2d/sendgrid/helpers/mail/mail.py#L200-L209
onaio/onadata
89ad16744e8f247fb748219476f6ac295869a95f
onadata/apps/api/management/commands/reset_rest_services.py
python
Command.handle
(self, *args, **options)
[]
def handle(self, *args, **options): self.stdout.write("Task started ...") # Delete old bamboo rest service RestService.objects.filter(name='bamboo').delete() # Get all the rest services for rest in queryset_iterator(RestService.objects.all()): rest.save() self.stdout.write("Task ended ...")
[ "def", "handle", "(", "self", ",", "*", "args", ",", "*", "*", "options", ")", ":", "self", ".", "stdout", ".", "write", "(", "\"Task started ...\"", ")", "# Delete old bamboo rest service", "RestService", ".", "objects", ".", "filter", "(", "name", "=", "...
https://github.com/onaio/onadata/blob/89ad16744e8f247fb748219476f6ac295869a95f/onadata/apps/api/management/commands/reset_rest_services.py#L19-L29
KhronosGroup/OpenXR-SDK-Source
76756e2e7849b15466d29bee7d80cada92865550
external/python/jinja2/filters.py
python
make_attrgetter
(environment, attribute, postprocess=None)
return attrgetter
Returns a callable that looks up the given attribute from a passed object with the rules of the environment. Dots are allowed to access attributes of attributes. Integer parts in paths are looked up as integers.
Returns a callable that looks up the given attribute from a passed object with the rules of the environment. Dots are allowed to access attributes of attributes. Integer parts in paths are looked up as integers.
[ "Returns", "a", "callable", "that", "looks", "up", "the", "given", "attribute", "from", "a", "passed", "object", "with", "the", "rules", "of", "the", "environment", ".", "Dots", "are", "allowed", "to", "access", "attributes", "of", "attributes", ".", "Intege...
def make_attrgetter(environment, attribute, postprocess=None): """Returns a callable that looks up the given attribute from a passed object with the rules of the environment. Dots are allowed to access attributes of attributes. Integer parts in paths are looked up as integers. """ if attribute is None: attribute = [] elif isinstance(attribute, string_types): attribute = [int(x) if x.isdigit() else x for x in attribute.split('.')] else: attribute = [attribute] def attrgetter(item): for part in attribute: item = environment.getitem(item, part) if postprocess is not None: item = postprocess(item) return item return attrgetter
[ "def", "make_attrgetter", "(", "environment", ",", "attribute", ",", "postprocess", "=", "None", ")", ":", "if", "attribute", "is", "None", ":", "attribute", "=", "[", "]", "elif", "isinstance", "(", "attribute", ",", "string_types", ")", ":", "attribute", ...
https://github.com/KhronosGroup/OpenXR-SDK-Source/blob/76756e2e7849b15466d29bee7d80cada92865550/external/python/jinja2/filters.py#L62-L84
CJWorkbench/cjworkbench
e0b878d8ff819817fa049a4126efcbfcec0b50e6
cjwstate/models/stored_object.py
python
_delete_from_s3_pre_delete
(sender, instance, **kwargs)
Delete file from S3, pre-delete. Why pre-delete and not post-delete? Because our user expects the file to be _gone_, completely, forever -- that's what "delete" means to the user. If deletion fails, we need the link to remain in our database -- that's how the user will know it isn't deleted.
Delete file from S3, pre-delete.
[ "Delete", "file", "from", "S3", "pre", "-", "delete", "." ]
def _delete_from_s3_pre_delete(sender, instance, **kwargs): """Delete file from S3, pre-delete. Why pre-delete and not post-delete? Because our user expects the file to be _gone_, completely, forever -- that's what "delete" means to the user. If deletion fails, we need the link to remain in our database -- that's how the user will know it isn't deleted. """ if instance.key: s3.remove(s3.StoredObjectsBucket, instance.key)
[ "def", "_delete_from_s3_pre_delete", "(", "sender", ",", "instance", ",", "*", "*", "kwargs", ")", ":", "if", "instance", ".", "key", ":", "s3", ".", "remove", "(", "s3", ".", "StoredObjectsBucket", ",", "instance", ".", "key", ")" ]
https://github.com/CJWorkbench/cjworkbench/blob/e0b878d8ff819817fa049a4126efcbfcec0b50e6/cjwstate/models/stored_object.py#L50-L59
happinesslz/TANet
2d4b2ab99b8e57c03671b0f1531eab7dca8f3c1f
pointpillars_with_TANet/second/pytorch/train.py
python
flat_nested_json_dict
(json_dict, sep=".")
return flatted
flat a nested json-like dict. this function make shadow copy.
flat a nested json-like dict. this function make shadow copy.
[ "flat", "a", "nested", "json", "-", "like", "dict", ".", "this", "function", "make", "shadow", "copy", "." ]
def flat_nested_json_dict(json_dict, sep=".") -> dict: """flat a nested json-like dict. this function make shadow copy. """ flatted = {} for k, v in json_dict.items(): if isinstance(v, dict): _flat_nested_json_dict(v, flatted, sep, k) else: flatted[k] = v return flatted
[ "def", "flat_nested_json_dict", "(", "json_dict", ",", "sep", "=", "\".\"", ")", "->", "dict", ":", "flatted", "=", "{", "}", "for", "k", ",", "v", "in", "json_dict", ".", "items", "(", ")", ":", "if", "isinstance", "(", "v", ",", "dict", ")", ":",...
https://github.com/happinesslz/TANet/blob/2d4b2ab99b8e57c03671b0f1531eab7dca8f3c1f/pointpillars_with_TANet/second/pytorch/train.py#L51-L60
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_hxb2/lib/python3.5/site-packages/django/contrib/gis/gdal/geometries.py
python
OGRGeometry.convex_hull
(self)
return self._geomgen(capi.geom_convex_hull)
Returns the smallest convex Polygon that contains all the points in this Geometry.
Returns the smallest convex Polygon that contains all the points in this Geometry.
[ "Returns", "the", "smallest", "convex", "Polygon", "that", "contains", "all", "the", "points", "in", "this", "Geometry", "." ]
def convex_hull(self): """ Returns the smallest convex Polygon that contains all the points in this Geometry. """ return self._geomgen(capi.geom_convex_hull)
[ "def", "convex_hull", "(", "self", ")", ":", "return", "self", ".", "_geomgen", "(", "capi", ".", "geom_convex_hull", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_hxb2/lib/python3.5/site-packages/django/contrib/gis/gdal/geometries.py#L459-L464
hyperledger/fabric-sdk-py
8ee33a8981887e37950dc0f36a7ec63b3a5ba5c3
hfc/fabric/client.py
python
Client.peers
(self)
return self._peers
Get the peers instance in the network. :return: peers as dict
Get the peers instance in the network.
[ "Get", "the", "peers", "instance", "in", "the", "network", "." ]
def peers(self): """ Get the peers instance in the network. :return: peers as dict """ return self._peers
[ "def", "peers", "(", "self", ")", ":", "return", "self", ".", "_peers" ]
https://github.com/hyperledger/fabric-sdk-py/blob/8ee33a8981887e37950dc0f36a7ec63b3a5ba5c3/hfc/fabric/client.py#L397-L403
VirtueSecurity/aws-extender
d123b7e1a845847709ba3a481f11996bddc68a1c
BappModules/boto/rds/__init__.py
python
connect_to_region
(region_name, **kw_params)
return connect('rds', region_name, region_cls=RDSRegionInfo, connection_cls=RDSConnection, **kw_params)
Given a valid region name, return a :class:`boto.rds.RDSConnection`. Any additional parameters after the region_name are passed on to the connect method of the region object. :type: str :param region_name: The name of the region to connect to. :rtype: :class:`boto.rds.RDSConnection` or ``None`` :return: A connection to the given region, or None if an invalid region name is given
Given a valid region name, return a :class:`boto.rds.RDSConnection`. Any additional parameters after the region_name are passed on to the connect method of the region object.
[ "Given", "a", "valid", "region", "name", "return", "a", ":", "class", ":", "boto", ".", "rds", ".", "RDSConnection", ".", "Any", "additional", "parameters", "after", "the", "region_name", "are", "passed", "on", "to", "the", "connect", "method", "of", "the"...
def connect_to_region(region_name, **kw_params): """ Given a valid region name, return a :class:`boto.rds.RDSConnection`. Any additional parameters after the region_name are passed on to the connect method of the region object. :type: str :param region_name: The name of the region to connect to. :rtype: :class:`boto.rds.RDSConnection` or ``None`` :return: A connection to the given region, or None if an invalid region name is given """ return connect('rds', region_name, region_cls=RDSRegionInfo, connection_cls=RDSConnection, **kw_params)
[ "def", "connect_to_region", "(", "region_name", ",", "*", "*", "kw_params", ")", ":", "return", "connect", "(", "'rds'", ",", "region_name", ",", "region_cls", "=", "RDSRegionInfo", ",", "connection_cls", "=", "RDSConnection", ",", "*", "*", "kw_params", ")" ]
https://github.com/VirtueSecurity/aws-extender/blob/d123b7e1a845847709ba3a481f11996bddc68a1c/BappModules/boto/rds/__init__.py#L53-L68
IronLanguages/main
a949455434b1fda8c783289e897e78a9a0caabb5
External.LCA_RESTRICTED/Languages/CPython/27/Lib/decimal.py
python
Decimal._rescale
(self, exp, rounding)
return _dec_from_triple(self._sign, coeff, exp)
Rescale self so that the exponent is exp, either by padding with zeros or by truncating digits, using the given rounding mode. Specials are returned without change. This operation is quiet: it raises no flags, and uses no information from the context. exp = exp to scale to (an integer) rounding = rounding mode
Rescale self so that the exponent is exp, either by padding with zeros or by truncating digits, using the given rounding mode.
[ "Rescale", "self", "so", "that", "the", "exponent", "is", "exp", "either", "by", "padding", "with", "zeros", "or", "by", "truncating", "digits", "using", "the", "given", "rounding", "mode", "." ]
def _rescale(self, exp, rounding): """Rescale self so that the exponent is exp, either by padding with zeros or by truncating digits, using the given rounding mode. Specials are returned without change. This operation is quiet: it raises no flags, and uses no information from the context. exp = exp to scale to (an integer) rounding = rounding mode """ if self._is_special: return Decimal(self) if not self: return _dec_from_triple(self._sign, '0', exp) if self._exp >= exp: # pad answer with zeros if necessary return _dec_from_triple(self._sign, self._int + '0'*(self._exp - exp), exp) # too many digits; round and lose data. If self.adjusted() < # exp-1, replace self by 10**(exp-1) before rounding digits = len(self._int) + self._exp - exp if digits < 0: self = _dec_from_triple(self._sign, '1', exp-1) digits = 0 this_function = self._pick_rounding_function[rounding] changed = this_function(self, digits) coeff = self._int[:digits] or '0' if changed == 1: coeff = str(int(coeff)+1) return _dec_from_triple(self._sign, coeff, exp)
[ "def", "_rescale", "(", "self", ",", "exp", ",", "rounding", ")", ":", "if", "self", ".", "_is_special", ":", "return", "Decimal", "(", "self", ")", "if", "not", "self", ":", "return", "_dec_from_triple", "(", "self", ".", "_sign", ",", "'0'", ",", "...
https://github.com/IronLanguages/main/blob/a949455434b1fda8c783289e897e78a9a0caabb5/External.LCA_RESTRICTED/Languages/CPython/27/Lib/decimal.py#L2480-L2512
taomujian/linbing
fe772a58f41e3b046b51a866bdb7e4655abaf51a
python/app/thirdparty/dirsearch/thirdparty/requests/cookies.py
python
merge_cookies
(cookiejar, cookies)
return cookiejar
Add cookies to cookiejar and returns a merged CookieJar. :param cookiejar: CookieJar object to add the cookies to. :param cookies: Dictionary or CookieJar object to be added. :rtype: CookieJar
Add cookies to cookiejar and returns a merged CookieJar.
[ "Add", "cookies", "to", "cookiejar", "and", "returns", "a", "merged", "CookieJar", "." ]
def merge_cookies(cookiejar, cookies): """Add cookies to cookiejar and returns a merged CookieJar. :param cookiejar: CookieJar object to add the cookies to. :param cookies: Dictionary or CookieJar object to be added. :rtype: CookieJar """ if not isinstance(cookiejar, cookielib.CookieJar): raise ValueError('You can only merge into CookieJar') if isinstance(cookies, dict): cookiejar = cookiejar_from_dict( cookies, cookiejar=cookiejar, overwrite=False) elif isinstance(cookies, cookielib.CookieJar): try: cookiejar.update(cookies) except AttributeError: for cookie_in_jar in cookies: cookiejar.set_cookie(cookie_in_jar) return cookiejar
[ "def", "merge_cookies", "(", "cookiejar", ",", "cookies", ")", ":", "if", "not", "isinstance", "(", "cookiejar", ",", "cookielib", ".", "CookieJar", ")", ":", "raise", "ValueError", "(", "'You can only merge into CookieJar'", ")", "if", "isinstance", "(", "cooki...
https://github.com/taomujian/linbing/blob/fe772a58f41e3b046b51a866bdb7e4655abaf51a/python/app/thirdparty/dirsearch/thirdparty/requests/cookies.py#L529-L549
geomet/geomet
f7cfaa350cde44a16db21d2678ef5d245e7afda5
geomet/esri.py
python
_dump_geojson_polyline
(obj, srid=None)
return {"paths": coordinates, "spatialReference": {"wkid": srid}}
Loads GeoJSON to Esri JSON for Geometry type LineString and MultiLineString.
Loads GeoJSON to Esri JSON for Geometry type LineString and MultiLineString.
[ "Loads", "GeoJSON", "to", "Esri", "JSON", "for", "Geometry", "type", "LineString", "and", "MultiLineString", "." ]
def _dump_geojson_polyline(obj, srid=None): """ Loads GeoJSON to Esri JSON for Geometry type LineString and MultiLineString. """ coordkey = 'coordinates' if obj['type'].lower() == 'linestring': coordinates = [obj[coordkey]] else: coordinates = obj[coordkey] srid = _extract_geojson_srid(obj) or srid return {"paths": coordinates, "spatialReference": {"wkid": srid}}
[ "def", "_dump_geojson_polyline", "(", "obj", ",", "srid", "=", "None", ")", ":", "coordkey", "=", "'coordinates'", "if", "obj", "[", "'type'", "]", ".", "lower", "(", ")", "==", "'linestring'", ":", "coordinates", "=", "[", "obj", "[", "coordkey", "]", ...
https://github.com/geomet/geomet/blob/f7cfaa350cde44a16db21d2678ef5d245e7afda5/geomet/esri.py#L127-L139
SanPen/GridCal
d3f4566d2d72c11c7e910c9d162538ef0e60df31
src/GridCal/Engine/Simulations/OPF/opf_templates.py
python
Opf.get_shadow_prices
(self)
return val.transpose()
Extract values fro the 2D array of LP variables :return: 2D numpy array
Extract values fro the 2D array of LP variables :return: 2D numpy array
[ "Extract", "values", "fro", "the", "2D", "array", "of", "LP", "variables", ":", "return", ":", "2D", "numpy", "array" ]
def get_shadow_prices(self): """ Extract values fro the 2D array of LP variables :return: 2D numpy array """ val = np.zeros(self.nodal_restrictions.shape) for i in range(val.shape[0]): if self.nodal_restrictions[i].pi is not None: val[i] = - self.nodal_restrictions[i].pi return val.transpose()
[ "def", "get_shadow_prices", "(", "self", ")", ":", "val", "=", "np", ".", "zeros", "(", "self", ".", "nodal_restrictions", ".", "shape", ")", "for", "i", "in", "range", "(", "val", ".", "shape", "[", "0", "]", ")", ":", "if", "self", ".", "nodal_re...
https://github.com/SanPen/GridCal/blob/d3f4566d2d72c11c7e910c9d162538ef0e60df31/src/GridCal/Engine/Simulations/OPF/opf_templates.py#L250-L259
dcsync/pycobalt
d3a630bfadaeeb6c99aad28f226abe48f6b4acca
pycobalt/aggressor.py
python
bcancel
(*args, fork=None, sync=True)
return engine.call('bcancel', args, fork=fork, sync=sync)
r""" Documentation from https://www.cobaltstrike.com/aggressor-script/functions.html: Cancel a file download Arguments $1 - the id for the beacon. This may be an array or a single ID. $2 - the file to cancel or a wildcard. Example item "&Cancel Downloads" { bcancel($1, "*"); }
r""" Documentation from https://www.cobaltstrike.com/aggressor-script/functions.html:
[ "r", "Documentation", "from", "https", ":", "//", "www", ".", "cobaltstrike", ".", "com", "/", "aggressor", "-", "script", "/", "functions", ".", "html", ":" ]
def bcancel(*args, fork=None, sync=True): r""" Documentation from https://www.cobaltstrike.com/aggressor-script/functions.html: Cancel a file download Arguments $1 - the id for the beacon. This may be an array or a single ID. $2 - the file to cancel or a wildcard. Example item "&Cancel Downloads" { bcancel($1, "*"); } """ return engine.call('bcancel', args, fork=fork, sync=sync)
[ "def", "bcancel", "(", "*", "args", ",", "fork", "=", "None", ",", "sync", "=", "True", ")", ":", "return", "engine", ".", "call", "(", "'bcancel'", ",", "args", ",", "fork", "=", "fork", ",", "sync", "=", "sync", ")" ]
https://github.com/dcsync/pycobalt/blob/d3a630bfadaeeb6c99aad28f226abe48f6b4acca/pycobalt/aggressor.py#L763-L778
istresearch/scrapy-cluster
01861c2dca1563aab740417d315cc4ebf9b73f72
rest/rest_service.py
python
RestService._setup_redis
(self)
Returns a Redis Client
Returns a Redis Client
[ "Returns", "a", "Redis", "Client" ]
def _setup_redis(self): """Returns a Redis Client""" if not self.closed: try: self.logger.debug("Creating redis connection to host " + str(self.settings['REDIS_HOST'])) self.redis_conn = redis.StrictRedis(host=self.settings['REDIS_HOST'], port=self.settings['REDIS_PORT'], db=self.settings['REDIS_DB'], password=self.settings['REDIS_PASSWORD'], decode_responses=True, socket_timeout=self.settings.get('REDIS_SOCKET_TIMEOUT'), socket_connect_timeout=self.settings.get('REDIS_SOCKET_TIMEOUT')) self.redis_conn.info() self.redis_connected = True self.logger.info("Successfully connected to redis") except KeyError as e: self.logger.error('Missing setting named ' + str(e), {'ex': traceback.format_exc()}) except: self.logger.error("Couldn't initialize redis client.", {'ex': traceback.format_exc()}) raise
[ "def", "_setup_redis", "(", "self", ")", ":", "if", "not", "self", ".", "closed", ":", "try", ":", "self", ".", "logger", ".", "debug", "(", "\"Creating redis connection to host \"", "+", "str", "(", "self", ".", "settings", "[", "'REDIS_HOST'", "]", ")", ...
https://github.com/istresearch/scrapy-cluster/blob/01861c2dca1563aab740417d315cc4ebf9b73f72/rest/rest_service.py#L347-L369
roclark/sportsipy
c19f545d3376d62ded6304b137dc69238ac620a9
sportsipy/nhl/teams.py
python
Team.save_percentage
(self)
return self._save_percentage
Returns a ``float`` denoting the percentage of shots the team has saved during the season. Percentage ranges from 0-1.
Returns a ``float`` denoting the percentage of shots the team has saved during the season. Percentage ranges from 0-1.
[ "Returns", "a", "float", "denoting", "the", "percentage", "of", "shots", "the", "team", "has", "saved", "during", "the", "season", ".", "Percentage", "ranges", "from", "0", "-", "1", "." ]
def save_percentage(self): """ Returns a ``float`` denoting the percentage of shots the team has saved during the season. Percentage ranges from 0-1. """ return self._save_percentage
[ "def", "save_percentage", "(", "self", ")", ":", "return", "self", ".", "_save_percentage" ]
https://github.com/roclark/sportsipy/blob/c19f545d3376d62ded6304b137dc69238ac620a9/sportsipy/nhl/teams.py#L421-L426
buke/GreenOdoo
3d8c55d426fb41fdb3f2f5a1533cfe05983ba1df
runtime/python/lib/python2.7/difflib.py
python
IS_LINE_JUNK
(line, pat=re.compile(r"\s*#?\s*$").match)
return pat(line) is not None
r""" Return 1 for ignorable line: iff `line` is blank or contains a single '#'. Examples: >>> IS_LINE_JUNK('\n') True >>> IS_LINE_JUNK(' # \n') True >>> IS_LINE_JUNK('hello\n') False
r""" Return 1 for ignorable line: iff `line` is blank or contains a single '#'.
[ "r", "Return", "1", "for", "ignorable", "line", ":", "iff", "line", "is", "blank", "or", "contains", "a", "single", "#", "." ]
def IS_LINE_JUNK(line, pat=re.compile(r"\s*#?\s*$").match): r""" Return 1 for ignorable line: iff `line` is blank or contains a single '#'. Examples: >>> IS_LINE_JUNK('\n') True >>> IS_LINE_JUNK(' # \n') True >>> IS_LINE_JUNK('hello\n') False """ return pat(line) is not None
[ "def", "IS_LINE_JUNK", "(", "line", ",", "pat", "=", "re", ".", "compile", "(", "r\"\\s*#?\\s*$\"", ")", ".", "match", ")", ":", "return", "pat", "(", "line", ")", "is", "not", "None" ]
https://github.com/buke/GreenOdoo/blob/3d8c55d426fb41fdb3f2f5a1533cfe05983ba1df/runtime/python/lib/python2.7/difflib.py#L1108-L1122
meduza-corp/interstellar
40a801ccd7856491726f5a126621d9318cabe2e1
gsutil/third_party/boto/boto/s3/bucket.py
python
Bucket.get_website_configuration_obj
(self, headers=None)
return config
Get the website configuration as a :class:`boto.s3.website.WebsiteConfiguration` object.
Get the website configuration as a :class:`boto.s3.website.WebsiteConfiguration` object.
[ "Get", "the", "website", "configuration", "as", "a", ":", "class", ":", "boto", ".", "s3", ".", "website", ".", "WebsiteConfiguration", "object", "." ]
def get_website_configuration_obj(self, headers=None): """Get the website configuration as a :class:`boto.s3.website.WebsiteConfiguration` object. """ config_xml = self.get_website_configuration_xml(headers=headers) config = website.WebsiteConfiguration() h = handler.XmlHandler(config, self) xml.sax.parseString(config_xml, h) return config
[ "def", "get_website_configuration_obj", "(", "self", ",", "headers", "=", "None", ")", ":", "config_xml", "=", "self", ".", "get_website_configuration_xml", "(", "headers", "=", "headers", ")", "config", "=", "website", ".", "WebsiteConfiguration", "(", ")", "h"...
https://github.com/meduza-corp/interstellar/blob/40a801ccd7856491726f5a126621d9318cabe2e1/gsutil/third_party/boto/boto/s3/bucket.py#L1461-L1469
aim-uofa/AdelaiDet
fffb2ca1fbca88ec4d96e9ebc285bffe5027a947
adet/modeling/backbone/bifpn.py
python
SingleBiFPN.forward
(self, feats)
return output_feats
Args: input (dict[str->Tensor]): mapping feature map name (e.g., "p5") to feature map tensor for each feature level in high to low resolution order. Returns: dict[str->Tensor]: mapping from feature map name to FPN feature map tensor in high to low resolution order. Returned feature names follow the FPN paper convention: "p<stage>", where stage has stride = 2 ** stage e.g., ["n2", "n3", ..., "n6"].
Args: input (dict[str->Tensor]): mapping feature map name (e.g., "p5") to feature map tensor for each feature level in high to low resolution order.
[ "Args", ":", "input", "(", "dict", "[", "str", "-", ">", "Tensor", "]", ")", ":", "mapping", "feature", "map", "name", "(", "e", ".", "g", ".", "p5", ")", "to", "feature", "map", "tensor", "for", "each", "feature", "level", "in", "high", "to", "l...
def forward(self, feats): """ Args: input (dict[str->Tensor]): mapping feature map name (e.g., "p5") to feature map tensor for each feature level in high to low resolution order. Returns: dict[str->Tensor]: mapping from feature map name to FPN feature map tensor in high to low resolution order. Returned feature names follow the FPN paper convention: "p<stage>", where stage has stride = 2 ** stage e.g., ["n2", "n3", ..., "n6"]. """ feats = [_ for _ in feats] num_levels = len(feats) num_output_connections = [0 for _ in feats] for fnode in self.nodes: feat_level = fnode["feat_level"] inputs_offsets = fnode["inputs_offsets"] inputs_offsets_str = "_".join(map(str, inputs_offsets)) input_nodes = [] _, _, target_h, target_w = feats[feat_level].size() for input_offset in inputs_offsets: num_output_connections[input_offset] += 1 input_node = feats[input_offset] # reduction if input_node.size(1) != self.out_channels: name = "lateral_{}_f{}".format(input_offset, feat_level) input_node = self.__getattr__(name)(input_node) # maybe downsample _, _, h, w = input_node.size() if h > target_h and w > target_w: height_stride_size = int((h - 1) // target_h + 1) width_stride_size = int((w - 1) // target_w + 1) assert height_stride_size == width_stride_size == 2 input_node = F.max_pool2d( input_node, kernel_size=(height_stride_size + 1, width_stride_size + 1), stride=(height_stride_size, width_stride_size), padding=1 ) elif h <= target_h and w <= target_w: if h < target_h or w < target_w: input_node = F.interpolate( input_node, size=(target_h, target_w), mode="nearest" ) else: raise NotImplementedError() input_nodes.append(input_node) # attention name = "weights_f{}_{}".format(feat_level, inputs_offsets_str) weights = F.relu(self.__getattr__(name)) norm_weights = weights / (weights.sum() + 0.0001) new_node = torch.stack(input_nodes, dim=-1) new_node = (norm_weights * new_node).sum(dim=-1) new_node = swish(new_node) name = "outputs_f{}_{}".format(feat_level, inputs_offsets_str) feats.append(self.__getattr__(name)(new_node)) num_output_connections.append(0) output_feats = [] for idx in range(num_levels): for i, fnode in enumerate(reversed(self.nodes)): if fnode['feat_level'] == idx: output_feats.append(feats[-1 - i]) break else: raise ValueError() return output_feats
[ "def", "forward", "(", "self", ",", "feats", ")", ":", "feats", "=", "[", "_", "for", "_", "in", "feats", "]", "num_levels", "=", "len", "(", "feats", ")", "num_output_connections", "=", "[", "0", "for", "_", "in", "feats", "]", "for", "fnode", "in...
https://github.com/aim-uofa/AdelaiDet/blob/fffb2ca1fbca88ec4d96e9ebc285bffe5027a947/adet/modeling/backbone/bifpn.py#L203-L277
google/grr
8ad8a4d2c5a93c92729206b7771af19d92d4f915
grr/server/grr_response_server/maintenance_utils.py
python
InitGRRRootAPI
()
return api.GrrApi( connector=api_shell_raw_access_lib.RawConnector( context=api_call_context.ApiCallContext(username="GRRConfigUpdater"), page_size=_GRR_API_PAGE_SIZE)).root
[]
def InitGRRRootAPI(): return api.GrrApi( connector=api_shell_raw_access_lib.RawConnector( context=api_call_context.ApiCallContext(username="GRRConfigUpdater"), page_size=_GRR_API_PAGE_SIZE)).root
[ "def", "InitGRRRootAPI", "(", ")", ":", "return", "api", ".", "GrrApi", "(", "connector", "=", "api_shell_raw_access_lib", ".", "RawConnector", "(", "context", "=", "api_call_context", ".", "ApiCallContext", "(", "username", "=", "\"GRRConfigUpdater\"", ")", ",", ...
https://github.com/google/grr/blob/8ad8a4d2c5a93c92729206b7771af19d92d4f915/grr/server/grr_response_server/maintenance_utils.py#L25-L30
shiweibsw/Translation-Tools
2fbbf902364e557fa7017f9a74a8797b7440c077
venv/Lib/site-packages/pip-9.0.3-py3.6.egg/pip/_vendor/html5lib/_ihatexml.py
python
hexToInt
(hex_str)
return int(hex_str, 16)
[]
def hexToInt(hex_str): return int(hex_str, 16)
[ "def", "hexToInt", "(", "hex_str", ")", ":", "return", "int", "(", "hex_str", ",", "16", ")" ]
https://github.com/shiweibsw/Translation-Tools/blob/2fbbf902364e557fa7017f9a74a8797b7440c077/venv/Lib/site-packages/pip-9.0.3-py3.6.egg/pip/_vendor/html5lib/_ihatexml.py#L165-L166
quantumlib/Cirq
89f88b01d69222d3f1ec14d649b7b3a85ed9211f
examples/stabilizer_code.py
python
StabilizerCode.encode
( self, additional_qubits: List[cirq.Qid], unencoded_qubits: List[cirq.Qid] )
return circuit
Creates a circuit that encodes the qubits using the code words. Args: additional_qubits: The list of self.n - self.k qubits needed to encode the qubit. unencoded_qubits: The list of self.k qubits that contain the original message. Returns: A circuit where the self.n qubits are the encoded qubits.
Creates a circuit that encodes the qubits using the code words.
[ "Creates", "a", "circuit", "that", "encodes", "the", "qubits", "using", "the", "code", "words", "." ]
def encode( self, additional_qubits: List[cirq.Qid], unencoded_qubits: List[cirq.Qid] ) -> cirq.Circuit: """Creates a circuit that encodes the qubits using the code words. Args: additional_qubits: The list of self.n - self.k qubits needed to encode the qubit. unencoded_qubits: The list of self.k qubits that contain the original message. Returns: A circuit where the self.n qubits are the encoded qubits. """ assert len(additional_qubits) == self.n - self.k assert len(unencoded_qubits) == self.k qubits = additional_qubits + unencoded_qubits circuit = cirq.Circuit() # Equation 4.8: # This follows the improvements of: # https://cs269q.stanford.edu/projects2019/stabilizer_code_report_Y.pdf for r, x in enumerate(self.logical_Xs): for j in range(self.r, self.n - self.k): # By constructions, the first r rows can never contain a Z, as # r is defined by the Gaussian elimination as the rank. if x[j] == 'X' or x[j] == 'Y': circuit.append( cirq.ControlledOperation( [unencoded_qubits[r]], cirq.X(additional_qubits[j]) ) ) gate_dict = {'X': cirq.X, 'Y': cirq.Y, 'Z': cirq.Z} for r in range(self.r): circuit.append(cirq.H(qubits[r])) # Let's consider the first stabilizer: # The reason for adding S gate is Y gate we used is the complex format (i.e. to # make it Hermitian). It has following four cases: (ignore the phase factor) # (I+X@P_2...P_k)|0...0> = |0...0> + |1>|\psi> # (I+Y@P_2...P_k)|0...0> = |0...0> + i|1>|\psi> # The other forms are not possible in the standard form, by construction. # The first case means we need [1,1] vector and controlled gates and in the # second case we need [1, i] vector and controlled gates. Corresponding, it is # the first column of H and the first column of SH respectively. # For the other stabilizers, the process can be repeated, as by definition they # commute. if self.M[r][r] == 'Y' or self.M[r][r] == 'Z': circuit.append(cirq.S(qubits[r])) for n in range(self.n): if n == r: continue if self.M[r][n] == 'I': continue op = gate_dict[self.M[r][n]] circuit.append(cirq.ControlledOperation([qubits[r]], op(qubits[n]))) # At this stage, the state vector should be equal to equations 3.17 and 3.18. return circuit
[ "def", "encode", "(", "self", ",", "additional_qubits", ":", "List", "[", "cirq", ".", "Qid", "]", ",", "unencoded_qubits", ":", "List", "[", "cirq", ".", "Qid", "]", ")", "->", "cirq", ".", "Circuit", ":", "assert", "len", "(", "additional_qubits", ")...
https://github.com/quantumlib/Cirq/blob/89f88b01d69222d3f1ec14d649b7b3a85ed9211f/examples/stabilizer_code.py#L202-L265
poljar/weechat-matrix
b88614e557399e8b3b623a3d29b2694acc019a44
main.py
python
buffer_command_cb
(data, _, command)
return W.WEECHAT_RC_OK
Override the buffer command to allow switching buffers by short name.
Override the buffer command to allow switching buffers by short name.
[ "Override", "the", "buffer", "command", "to", "allow", "switching", "buffers", "by", "short", "name", "." ]
def buffer_command_cb(data, _, command): """Override the buffer command to allow switching buffers by short name.""" command = command[7:].strip() buffer_subcommands = ["list", "add", "clear", "move", "swap", "cycle", "merge", "unmerge", "hide", "unhide", "renumber", "close", "notify", "localvar", "set", "get"] if not command: return W.WEECHAT_RC_OK command_words = command.split() if len(command_words) >= 1: if command_words[0] in buffer_subcommands: return W.WEECHAT_RC_OK elif command_words[0].startswith("*"): return W.WEECHAT_RC_OK try: int(command_words[0]) return W.WEECHAT_RC_OK except ValueError: pass room_buffers = [] for server in SERVERS.values(): room_buffers.extend(server.room_buffers.values()) sorted_buffers = sorted( room_buffers, key=lambda b: b.weechat_buffer.number ) for room_buffer in sorted_buffers: buffer = room_buffer.weechat_buffer if command in buffer.short_name: displayed = W.current_buffer() == buffer._ptr if displayed: continue W.buffer_set(buffer._ptr, 'display', '1') return W.WEECHAT_RC_OK_EAT return W.WEECHAT_RC_OK
[ "def", "buffer_command_cb", "(", "data", ",", "_", ",", "command", ")", ":", "command", "=", "command", "[", "7", ":", "]", ".", "strip", "(", ")", "buffer_subcommands", "=", "[", "\"list\"", ",", "\"add\"", ",", "\"clear\"", ",", "\"move\"", ",", "\"s...
https://github.com/poljar/weechat-matrix/blob/b88614e557399e8b3b623a3d29b2694acc019a44/main.py#L629-L677
n1nj4sec/pr0cks
c98188b205a06b5bdb5ec3eea99dde4d8bf1f577
socks.py
python
socksocket.getproxypeername
(self)
return _orgsocket.getpeername(self)
getproxypeername() -> address info Returns the IP and port number of the proxy.
getproxypeername() -> address info Returns the IP and port number of the proxy.
[ "getproxypeername", "()", "-", ">", "address", "info", "Returns", "the", "IP", "and", "port", "number", "of", "the", "proxy", "." ]
def getproxypeername(self): """getproxypeername() -> address info Returns the IP and port number of the proxy. """ return _orgsocket.getpeername(self)
[ "def", "getproxypeername", "(", "self", ")", ":", "return", "_orgsocket", ".", "getpeername", "(", "self", ")" ]
https://github.com/n1nj4sec/pr0cks/blob/c98188b205a06b5bdb5ec3eea99dde4d8bf1f577/socks.py#L256-L260
postgres/pgadmin4
374c5e952fa594d749fadf1f88076c1cba8c5f64
web/pgadmin/browser/server_groups/servers/pgagent/__init__.py
python
JobView.delete
(self, gid, sid, jid=None)
return make_json_response(success=1)
Delete the pgAgent Job.
Delete the pgAgent Job.
[ "Delete", "the", "pgAgent", "Job", "." ]
def delete(self, gid, sid, jid=None): """Delete the pgAgent Job.""" if jid is None: data = request.form if request.form else json.loads( request.data, encoding='utf-8' ) else: data = {'ids': [jid]} for jid in data['ids']: status, res = self.conn.execute_void( render_template( "/".join([self.template_path, self._DELETE_SQL]), jid=jid, conn=self.conn ) ) if not status: return internal_server_error(errormsg=res) return make_json_response(success=1)
[ "def", "delete", "(", "self", ",", "gid", ",", "sid", ",", "jid", "=", "None", ")", ":", "if", "jid", "is", "None", ":", "data", "=", "request", ".", "form", "if", "request", ".", "form", "else", "json", ".", "loads", "(", "request", ".", "data",...
https://github.com/postgres/pgadmin4/blob/374c5e952fa594d749fadf1f88076c1cba8c5f64/web/pgadmin/browser/server_groups/servers/pgagent/__init__.py#L392-L412
rytilahti/python-miio
b6e53dd16fac77915426e7592e2528b78ef65190
miio/airconditioningcompanion.py
python
AirConditioningCompanion.send_command
(self, command: str)
return self.send("send_cmd", [str(command)])
Send a command to the air conditioner. :param str command: Command to execute
Send a command to the air conditioner.
[ "Send", "a", "command", "to", "the", "air", "conditioner", "." ]
def send_command(self, command: str): """Send a command to the air conditioner. :param str command: Command to execute """ return self.send("send_cmd", [str(command)])
[ "def", "send_command", "(", "self", ",", "command", ":", "str", ")", ":", "return", "self", ".", "send", "(", "\"send_cmd\"", ",", "[", "str", "(", "command", ")", "]", ")" ]
https://github.com/rytilahti/python-miio/blob/b6e53dd16fac77915426e7592e2528b78ef65190/miio/airconditioningcompanion.py#L352-L357
XX-net/XX-Net
a9898cfcf0084195fb7e69b6bc834e59aecdf14f
python3.8.2/Lib/imaplib.py
python
IMAP4.status
(self, mailbox, names)
return self._untagged_response(typ, dat, name)
Request named status conditions for mailbox. (typ, [data]) = <instance>.status(mailbox, names)
Request named status conditions for mailbox.
[ "Request", "named", "status", "conditions", "for", "mailbox", "." ]
def status(self, mailbox, names): """Request named status conditions for mailbox. (typ, [data]) = <instance>.status(mailbox, names) """ name = 'STATUS' #if self.PROTOCOL_VERSION == 'IMAP4': # Let the server decide! # raise self.error('%s unimplemented in IMAP4 (obtain IMAP4rev1 server, or re-code)' % name) typ, dat = self._simple_command(name, mailbox, names) return self._untagged_response(typ, dat, name)
[ "def", "status", "(", "self", ",", "mailbox", ",", "names", ")", ":", "name", "=", "'STATUS'", "#if self.PROTOCOL_VERSION == 'IMAP4': # Let the server decide!", "# raise self.error('%s unimplemented in IMAP4 (obtain IMAP4rev1 server, or re-code)' % name)", "typ", ",", "dat", ...
https://github.com/XX-net/XX-Net/blob/a9898cfcf0084195fb7e69b6bc834e59aecdf14f/python3.8.2/Lib/imaplib.py#L823-L832
openshift/openshift-tools
1188778e728a6e4781acf728123e5b356380fe6f
openshift/installer/vendored/openshift-ansible-3.11.28-1/roles/openshift_health_checker/openshift_checks/docker_storage.py
python
DockerStorage.get_vg_free
(self, pool)
return size
Determine which VG to examine according to the pool name. Return: size vgs reports. Pool name is the only indicator currently available from the Docker API driver info. We assume a name that looks like "vg--name-docker--pool"; vg and lv names with inner hyphens doubled, joined by a hyphen.
Determine which VG to examine according to the pool name. Return: size vgs reports. Pool name is the only indicator currently available from the Docker API driver info. We assume a name that looks like "vg--name-docker--pool"; vg and lv names with inner hyphens doubled, joined by a hyphen.
[ "Determine", "which", "VG", "to", "examine", "according", "to", "the", "pool", "name", ".", "Return", ":", "size", "vgs", "reports", ".", "Pool", "name", "is", "the", "only", "indicator", "currently", "available", "from", "the", "Docker", "API", "driver", ...
def get_vg_free(self, pool): """Determine which VG to examine according to the pool name. Return: size vgs reports. Pool name is the only indicator currently available from the Docker API driver info. We assume a name that looks like "vg--name-docker--pool"; vg and lv names with inner hyphens doubled, joined by a hyphen. """ match = re.match(r'((?:[^-]|--)+)-(?!-)', pool) # matches up to the first single hyphen if not match: # unlikely, but... be clear if we assumed wrong raise OpenShiftCheckException( "This host's Docker reports it is using a storage pool named '{}'.\n" "However this name does not have the expected format of 'vgname-lvname'\n" "so the available storage in the VG cannot be determined.".format(pool) ) vg_name = match.groups()[0].replace("--", "-") vgs_cmd = "/sbin/vgs --noheadings -o vg_free --units g --select vg_name=" + vg_name # should return free space like " 12.00g" if the VG exists; empty if it does not ret = self.execute_module("command", {"_raw_params": vgs_cmd}) if ret.get("failed") or ret.get("rc", 0) != 0: raise OpenShiftCheckException( "Is LVM installed? Failed to run /sbin/vgs " "to determine docker storage usage:\n" + ret.get("msg", "") ) size = ret.get("stdout", "").strip() if not size: raise OpenShiftCheckException( "This host's Docker reports it is using a storage pool named '{pool}'.\n" "which we expect to come from local VG '{vg}'.\n" "However, /sbin/vgs did not find this VG. Is Docker for this host" "running and using the storage on the host?".format(pool=pool, vg=vg_name) ) return size
[ "def", "get_vg_free", "(", "self", ",", "pool", ")", ":", "match", "=", "re", ".", "match", "(", "r'((?:[^-]|--)+)-(?!-)'", ",", "pool", ")", "# matches up to the first single hyphen", "if", "not", "match", ":", "# unlikely, but... be clear if we assumed wrong", "rais...
https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/openshift/installer/vendored/openshift-ansible-3.11.28-1/roles/openshift_health_checker/openshift_checks/docker_storage.py#L157-L188
TencentCloud/tencentcloud-sdk-python
3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2
tencentcloud/ame/v20190916/models.py
python
OfflineMusicDetail.__init__
(self)
r""" :param ItemId: 歌曲Id :type ItemId: str :param MusicName: 歌曲名称 :type MusicName: str :param OffRemark: 不可用原因 :type OffRemark: str :param OffTime: 不可用时间 :type OffTime: str
r""" :param ItemId: 歌曲Id :type ItemId: str :param MusicName: 歌曲名称 :type MusicName: str :param OffRemark: 不可用原因 :type OffRemark: str :param OffTime: 不可用时间 :type OffTime: str
[ "r", ":", "param", "ItemId", ":", "歌曲Id", ":", "type", "ItemId", ":", "str", ":", "param", "MusicName", ":", "歌曲名称", ":", "type", "MusicName", ":", "str", ":", "param", "OffRemark", ":", "不可用原因", ":", "type", "OffRemark", ":", "str", ":", "param", "O...
def __init__(self): r""" :param ItemId: 歌曲Id :type ItemId: str :param MusicName: 歌曲名称 :type MusicName: str :param OffRemark: 不可用原因 :type OffRemark: str :param OffTime: 不可用时间 :type OffTime: str """ self.ItemId = None self.MusicName = None self.OffRemark = None self.OffTime = None
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "ItemId", "=", "None", "self", ".", "MusicName", "=", "None", "self", ".", "OffRemark", "=", "None", "self", ".", "OffTime", "=", "None" ]
https://github.com/TencentCloud/tencentcloud-sdk-python/blob/3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2/tencentcloud/ame/v20190916/models.py#L1599-L1613