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
HCIILAB/DeRPN
21e6738ee1f7d3f159ee48d435c543e773f8ce99
caffe/examples/pycaffe/layers/pascal_multilabel_datalayers.py
python
BatchLoader.load_next_image
(self)
return self.transformer.preprocess(im), multilabel
Load the next image in a batch.
Load the next image in a batch.
[ "Load", "the", "next", "image", "in", "a", "batch", "." ]
def load_next_image(self): """ Load the next image in a batch. """ # Did we finish an epoch? if self._cur == len(self.indexlist): self._cur = 0 shuffle(self.indexlist) # Load an image index = self.indexlist[self._cur] # Get the image index image_file_name = index + '.jpg' im = np.asarray(Image.open( osp.join(self.pascal_root, 'JPEGImages', image_file_name))) im = scipy.misc.imresize(im, self.im_shape) # resize # do a simple horizontal flip as data augmentation flip = np.random.choice(2)*2-1 im = im[:, ::flip, :] # Load and prepare ground truth multilabel = np.zeros(20).astype(np.float32) anns = load_pascal_annotation(index, self.pascal_root) for label in anns['gt_classes']: # in the multilabel problem we don't care how MANY instances # there are of each class. Only if they are present. # The "-1" is b/c we are not interested in the background # class. multilabel[label - 1] = 1 self._cur += 1 return self.transformer.preprocess(im), multilabel
[ "def", "load_next_image", "(", "self", ")", ":", "# Did we finish an epoch?", "if", "self", ".", "_cur", "==", "len", "(", "self", ".", "indexlist", ")", ":", "self", ".", "_cur", "=", "0", "shuffle", "(", "self", ".", "indexlist", ")", "# Load an image", ...
https://github.com/HCIILAB/DeRPN/blob/21e6738ee1f7d3f159ee48d435c543e773f8ce99/caffe/examples/pycaffe/layers/pascal_multilabel_datalayers.py#L106-L137
orbingol/NURBS-Python
8ae8b127eb0b130a25a6c81e98e90f319733bca0
geomdl/visualization/VisVTK.py
python
VisConfig.__init__
(self, **kwargs)
[]
def __init__(self, **kwargs): super(VisConfig, self).__init__(**kwargs) self._bg = ( # background colors (0.5, 0.5, 0.5), (0.2, 0.2, 0.2), (0.25, 0.5, 0.75), (1.0, 1.0, 0.0), (1.0, 0.5, 0.0), (0.5, 0.0, 1.0), (0.0, 0.0, 0.0), (1.0, 1.0, 1.0) ) self._bg_id = 0 # used for keeping track of the background numbering self.display_ctrlpts = kwargs.get('ctrlpts', True) self.display_evalpts = kwargs.get('evalpts', True) self.display_bbox = kwargs.get('bbox', False) self.display_trims = kwargs.get('trims', True) self.trim_size = kwargs.get('trim_size', 4) self.figure_size = kwargs.get('figure_size', (800, 600)) # size of the render window self.line_width = kwargs.get('line_width', 1.0) self.figure_image_filename = "temp-figure.png"
[ "def", "__init__", "(", "self", ",", "*", "*", "kwargs", ")", ":", "super", "(", "VisConfig", ",", "self", ")", ".", "__init__", "(", "*", "*", "kwargs", ")", "self", ".", "_bg", "=", "(", "# background colors", "(", "0.5", ",", "0.5", ",", "0.5", ...
https://github.com/orbingol/NURBS-Python/blob/8ae8b127eb0b130a25a6c81e98e90f319733bca0/geomdl/visualization/VisVTK.py#L32-L46
dingmyu/D4LCN
9258bfb31376b97ab16abee31bd0fec131236c7a
models/resnet.py
python
resnet101
(pretrained=False, **kwargs)
return model
Constructs a ResNet-101 model. Args: pretrained (bool): If True, returns a model pre-trained on ImageNet
Constructs a ResNet-101 model. Args: pretrained (bool): If True, returns a model pre-trained on ImageNet
[ "Constructs", "a", "ResNet", "-", "101", "model", ".", "Args", ":", "pretrained", "(", "bool", ")", ":", "If", "True", "returns", "a", "model", "pre", "-", "trained", "on", "ImageNet" ]
def resnet101(pretrained=False, **kwargs): """Constructs a ResNet-101 model. Args: pretrained (bool): If True, returns a model pre-trained on ImageNet """ model = ResNet(Bottleneck, [3, 4, 23, 3], **kwargs) if pretrained: model.load_state_dict(model_zoo.load_url(model_urls['resnet101']), strict=False) return model
[ "def", "resnet101", "(", "pretrained", "=", "False", ",", "*", "*", "kwargs", ")", ":", "model", "=", "ResNet", "(", "Bottleneck", ",", "[", "3", ",", "4", ",", "23", ",", "3", "]", ",", "*", "*", "kwargs", ")", "if", "pretrained", ":", "model", ...
https://github.com/dingmyu/D4LCN/blob/9258bfb31376b97ab16abee31bd0fec131236c7a/models/resnet.py#L254-L262
caiiiac/Machine-Learning-with-Python
1a26c4467da41ca4ebc3d5bd789ea942ef79422f
MachineLearning/venv/lib/python3.5/site-packages/pandas/core/indexes/base.py
python
Index._assert_can_do_op
(self, value)
Check value is valid for scalar op
Check value is valid for scalar op
[ "Check", "value", "is", "valid", "for", "scalar", "op" ]
def _assert_can_do_op(self, value): """ Check value is valid for scalar op """ if not lib.isscalar(value): msg = "'value' must be a scalar, passed: {0}" raise TypeError(msg.format(type(value).__name__))
[ "def", "_assert_can_do_op", "(", "self", ",", "value", ")", ":", "if", "not", "lib", ".", "isscalar", "(", "value", ")", ":", "msg", "=", "\"'value' must be a scalar, passed: {0}\"", "raise", "TypeError", "(", "msg", ".", "format", "(", "type", "(", "value",...
https://github.com/caiiiac/Machine-Learning-with-Python/blob/1a26c4467da41ca4ebc3d5bd789ea942ef79422f/MachineLearning/venv/lib/python3.5/site-packages/pandas/core/indexes/base.py#L1045-L1049
crdoconnor/strictyaml
b456066a763285532fd75cd274d4a275d8499d6c
hitch/key.py
python
reformat
()
Reformat using black and then relint.
Reformat using black and then relint.
[ "Reformat", "using", "black", "and", "then", "relint", "." ]
def reformat(): """ Reformat using black and then relint. """ toolkit.reformat()
[ "def", "reformat", "(", ")", ":", "toolkit", ".", "reformat", "(", ")" ]
https://github.com/crdoconnor/strictyaml/blob/b456066a763285532fd75cd274d4a275d8499d6c/hitch/key.py#L145-L149
pyfa-org/Pyfa
feaa52c36beeda21ab380fc74d8f871b81d49729
gui/setEditor.py
python
ImplantSetEditor.exportPatterns
(self, event)
Event fired when export to clipboard button is clicked
Event fired when export to clipboard button is clicked
[ "Event", "fired", "when", "export", "to", "clipboard", "button", "is", "clicked" ]
def exportPatterns(self, event): """Event fired when export to clipboard button is clicked""" sIS = ImplantSets.getInstance() toClipboard(sIS.exportSets()) self.stNotice.SetLabel(_t("Sets exported to clipboard"))
[ "def", "exportPatterns", "(", "self", ",", "event", ")", ":", "sIS", "=", "ImplantSets", ".", "getInstance", "(", ")", "toClipboard", "(", "sIS", ".", "exportSets", "(", ")", ")", "self", ".", "stNotice", ".", "SetLabel", "(", "_t", "(", "\"Sets exported...
https://github.com/pyfa-org/Pyfa/blob/feaa52c36beeda21ab380fc74d8f871b81d49729/gui/setEditor.py#L224-L229
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/lib/python2.7/site-packages/setuptools/_vendor/pyparsing.py
python
lineno
(loc,strg)
return strg.count("\n",0,loc) + 1
Returns current line number within a string, counting newlines as line separators. The first line is number 1. Note: the default parsing behavior is to expand tabs in the input string before starting the parsing process. See L{I{ParserElement.parseString}<ParserElement.parseString>} for more information on parsing strings containing C{<TAB>}s, and suggested methods to maintain a consistent view of the parsed string, the parse location, and line and column positions within the parsed string.
Returns current line number within a string, counting newlines as line separators. The first line is number 1.
[ "Returns", "current", "line", "number", "within", "a", "string", "counting", "newlines", "as", "line", "separators", ".", "The", "first", "line", "is", "number", "1", "." ]
def lineno(loc,strg): """Returns current line number within a string, counting newlines as line separators. The first line is number 1. Note: the default parsing behavior is to expand tabs in the input string before starting the parsing process. See L{I{ParserElement.parseString}<ParserElement.parseString>} for more information on parsing strings containing C{<TAB>}s, and suggested methods to maintain a consistent view of the parsed string, the parse location, and line and column positions within the parsed string. """ return strg.count("\n",0,loc) + 1
[ "def", "lineno", "(", "loc", ",", "strg", ")", ":", "return", "strg", ".", "count", "(", "\"\\n\"", ",", "0", ",", "loc", ")", "+", "1" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/lib/python2.7/site-packages/setuptools/_vendor/pyparsing.py#L958-L968
huggingface/transformers
623b4f7c63f60cce917677ee704d6c93ee960b4b
src/transformers/utils/dummy_pytorch_quantization_and_torch_objects.py
python
QDQBertForTokenClassification.from_pretrained
(cls, *args, **kwargs)
[]
def from_pretrained(cls, *args, **kwargs): requires_backends(cls, ["pytorch_quantization", "torch"])
[ "def", "from_pretrained", "(", "cls", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "requires_backends", "(", "cls", ",", "[", "\"pytorch_quantization\"", ",", "\"torch\"", "]", ")" ]
https://github.com/huggingface/transformers/blob/623b4f7c63f60cce917677ee704d6c93ee960b4b/src/transformers/utils/dummy_pytorch_quantization_and_torch_objects.py#L73-L74
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/lib/python2.7/site-packages/attr/_make.py
python
_CountingAttr.__init__
(self, default, validator, repr, cmp, hash, init, converter, metadata, type)
[]
def __init__(self, default, validator, repr, cmp, hash, init, converter, metadata, type): _CountingAttr.cls_counter += 1 self.counter = _CountingAttr.cls_counter self._default = default # If validator is a list/tuple, wrap it using helper validator. if validator and isinstance(validator, (list, tuple)): self._validator = and_(*validator) else: self._validator = validator self.repr = repr self.cmp = cmp self.hash = hash self.init = init self.converter = converter self.metadata = metadata self.type = type
[ "def", "__init__", "(", "self", ",", "default", ",", "validator", ",", "repr", ",", "cmp", ",", "hash", ",", "init", ",", "converter", ",", "metadata", ",", "type", ")", ":", "_CountingAttr", ".", "cls_counter", "+=", "1", "self", ".", "counter", "=", ...
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/lib/python2.7/site-packages/attr/_make.py#L1350-L1366
dropbox/dropbox-sdk-python
015437429be224732990041164a21a0501235db1
dropbox/team_log.py
python
EventDetails.is_shared_link_remove_expiry_details
(self)
return self._tag == 'shared_link_remove_expiry_details'
Check if the union tag is ``shared_link_remove_expiry_details``. :rtype: bool
Check if the union tag is ``shared_link_remove_expiry_details``.
[ "Check", "if", "the", "union", "tag", "is", "shared_link_remove_expiry_details", "." ]
def is_shared_link_remove_expiry_details(self): """ Check if the union tag is ``shared_link_remove_expiry_details``. :rtype: bool """ return self._tag == 'shared_link_remove_expiry_details'
[ "def", "is_shared_link_remove_expiry_details", "(", "self", ")", ":", "return", "self", ".", "_tag", "==", "'shared_link_remove_expiry_details'" ]
https://github.com/dropbox/dropbox-sdk-python/blob/015437429be224732990041164a21a0501235db1/dropbox/team_log.py#L15727-L15733
AppScale/gts
46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9
AppServer/google/appengine/ext/mapreduce/base_handler.py
python
TaskQueueHandler.task_retry_count
(self)
return int(self.request.headers.get("X-AppEngine-TaskExecutionCount", 0))
Number of times this task has been retried.
Number of times this task has been retried.
[ "Number", "of", "times", "this", "task", "has", "been", "retried", "." ]
def task_retry_count(self): """Number of times this task has been retried.""" return int(self.request.headers.get("X-AppEngine-TaskExecutionCount", 0))
[ "def", "task_retry_count", "(", "self", ")", ":", "return", "int", "(", "self", ".", "request", ".", "headers", ".", "get", "(", "\"X-AppEngine-TaskExecutionCount\"", ",", "0", ")", ")" ]
https://github.com/AppScale/gts/blob/46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9/AppServer/google/appengine/ext/mapreduce/base_handler.py#L165-L167
crossbario/autobahn-python
fa9f2da0c5005574e63456a3a04f00e405744014
autobahn/wamp/auth.py
python
derive_scram_credential
(email: str, password: str, salt: Optional[bytes] = None)
return credential
Derive WAMP-SCRAM credentials from user email and password. The SCRAM parameters used are the following (these are also contained in the returned credentials): * kdf ``argon2id-13`` * time cost ``4096`` * memory cost ``512`` * parallelism ``1`` See `draft-irtf-cfrg-argon2 <https://datatracker.ietf.org/doc/draft-irtf-cfrg-argon2/>`__ and `argon2-cffi <https://argon2-cffi.readthedocs.io/en/stable/>`__. :param email: User email. :param password: User password. :param salt: Optional salt to use (must be 16 bytes long). If none is given, compute salt from email as ``salt = SHA256(email)[:16]``. :return: WAMP-SCRAM credentials. When serialized, the returned credentials can be copy-pasted into the ``config.json`` node configuration for a Crossbar.io node.
Derive WAMP-SCRAM credentials from user email and password. The SCRAM parameters used are the following (these are also contained in the returned credentials):
[ "Derive", "WAMP", "-", "SCRAM", "credentials", "from", "user", "email", "and", "password", ".", "The", "SCRAM", "parameters", "used", "are", "the", "following", "(", "these", "are", "also", "contained", "in", "the", "returned", "credentials", ")", ":" ]
def derive_scram_credential(email: str, password: str, salt: Optional[bytes] = None) -> Dict: """ Derive WAMP-SCRAM credentials from user email and password. The SCRAM parameters used are the following (these are also contained in the returned credentials): * kdf ``argon2id-13`` * time cost ``4096`` * memory cost ``512`` * parallelism ``1`` See `draft-irtf-cfrg-argon2 <https://datatracker.ietf.org/doc/draft-irtf-cfrg-argon2/>`__ and `argon2-cffi <https://argon2-cffi.readthedocs.io/en/stable/>`__. :param email: User email. :param password: User password. :param salt: Optional salt to use (must be 16 bytes long). If none is given, compute salt from email as ``salt = SHA256(email)[:16]``. :return: WAMP-SCRAM credentials. When serialized, the returned credentials can be copy-pasted into the ``config.json`` node configuration for a Crossbar.io node. """ assert HAS_ARGON, 'missing dependency argon2' from argon2.low_level import hash_secret from argon2.low_level import Type # derive salt from email if not salt: m = hashlib.sha256() m.update(email.encode('utf8')) salt = m.digest()[:16] assert len(salt) == 16 hash_data = hash_secret( secret=password.encode('utf8'), salt=salt, time_cost=4096, memory_cost=512, parallelism=1, hash_len=32, type=Type.ID, version=19, ) _, tag, v, params, _, salted_password = hash_data.decode('ascii').split('$') assert tag == 'argon2id' assert v == 'v=19' # argon's version 1.3 is represented as 0x13, which is 19 decimal... params = { k: v for k, v in [x.split('=') for x in params.split(',')] } salted_password = salted_password.encode('ascii') client_key = hmac.new(salted_password, b"Client Key", hashlib.sha256).digest() stored_key = hashlib.new('sha256', client_key).digest() server_key = hmac.new(salted_password, b"Server Key", hashlib.sha256).digest() credential = { "kdf": "argon2id-13", "memory": int(params['m']), "iterations": int(params['t']), "salt": binascii.b2a_hex(salt).decode('ascii'), "stored-key": binascii.b2a_hex(stored_key).decode('ascii'), "server-key": binascii.b2a_hex(server_key).decode('ascii'), } return credential
[ "def", "derive_scram_credential", "(", "email", ":", "str", ",", "password", ":", "str", ",", "salt", ":", "Optional", "[", "bytes", "]", "=", "None", ")", "->", "Dict", ":", "assert", "HAS_ARGON", ",", "'missing dependency argon2'", "from", "argon2", ".", ...
https://github.com/crossbario/autobahn-python/blob/fa9f2da0c5005574e63456a3a04f00e405744014/autobahn/wamp/auth.py#L610-L673
smicallef/spiderfoot
fd4bf9394c9ab3ecc90adc3115c56349fb23165b
modules/sfp_dns_for_family.py
python
sfp_dns_for_family.setup
(self, sfc, userOpts=dict())
[]
def setup(self, sfc, userOpts=dict()): self.sf = sfc self.results = self.tempStorage() for opt in list(userOpts.keys()): self.opts[opt] = userOpts[opt]
[ "def", "setup", "(", "self", ",", "sfc", ",", "userOpts", "=", "dict", "(", ")", ")", ":", "self", ".", "sf", "=", "sfc", "self", ".", "results", "=", "self", ".", "tempStorage", "(", ")", "for", "opt", "in", "list", "(", "userOpts", ".", "keys",...
https://github.com/smicallef/spiderfoot/blob/fd4bf9394c9ab3ecc90adc3115c56349fb23165b/modules/sfp_dns_for_family.py#L48-L53
aaPanel/BaoTa
9bb1336f31ae2893ab513af7a3efed633338c64b
class/ssh_terminal.py
python
ssh_terminal.history_send
(self,send_data)
@name 从发送实体保存命令 @author hwliang<2020-08-12> @param send_data<string> 数据实体 @return void
[]
def history_send(self,send_data): ''' @name 从发送实体保存命令 @author hwliang<2020-08-12> @param send_data<string> 数据实体 @return void ''' if not send_data: return his_path = self._save_path + self._host if not os.path.exists(his_path): return his_file = his_path + '/history.pl' #上下切换命令 if send_data in ["\x1b[A","\x1b[B"]: self._last_cmd_tip = 2 return #左移光标 if send_data in ["\x1b[C"]: self._last_num -= 1 return # 右移光标 if send_data in ["\x1b[D"]: self._last_num += 1 return #退格 if send_data == "\x7f": self._last_cmd = self._last_cmd[:-1] return #过滤特殊符号 if send_data in ["\x1b[C","\x1b[D","\x1b[K","\x07","\x08","\x03","\x01","\x02","\x04","\x05","\x06","\x1bOB","\x1bOA","\x1b[8P","\x1b","\x1b[4P","\x1b[6P","\x1b[5P"]: return #Tab补全处理 if send_data == "\t": self._last_cmd_tip = 1 return if str(send_data).find("\x1b") != -1: return if send_data[-1] in ['\r','\n']: if not self._last_cmd: return his_shell = [int(time.time()),self._client,self._user,self._last_cmd] public.writeFile(his_file, json.dumps(his_shell) + "\n","a+") self._last_cmd = "" #超过50M则保留最新的20000行 if os.stat(his_file).st_size > 52428800: his_tmp = public.GetNumLines(his_file,20000) public.writeFile(his_file, his_tmp) else: if self._last_num >= 0: self._last_cmd += send_data else: self._last_cmd.insert(len(self._last_cmd) + self._last_num, send_data)
[ "def", "history_send", "(", "self", ",", "send_data", ")", ":", "if", "not", "send_data", ":", "return", "his_path", "=", "self", ".", "_save_path", "+", "self", ".", "_host", "if", "not", "os", ".", "path", ".", "exists", "(", "his_path", ")", ":", ...
https://github.com/aaPanel/BaoTa/blob/9bb1336f31ae2893ab513af7a3efed633338c64b/class/ssh_terminal.py#L593-L652
pymedusa/Medusa
1405fbb6eb8ef4d20fcca24c32ddca52b11f0f38
medusa/databases/main_db.py
python
AddManualSearched.test
(self)
return self.connection.version >= (44, 3)
Test if the version is < 44.3
Test if the version is < 44.3
[ "Test", "if", "the", "version", "is", "<", "44", ".", "3" ]
def test(self): """ Test if the version is < 44.3 """ return self.connection.version >= (44, 3)
[ "def", "test", "(", "self", ")", ":", "return", "self", ".", "connection", ".", "version", ">=", "(", "44", ",", "3", ")" ]
https://github.com/pymedusa/Medusa/blob/1405fbb6eb8ef4d20fcca24c32ddca52b11f0f38/medusa/databases/main_db.py#L421-L425
custom-components/ble_monitor
64f9cb064781c6ddc5089657d3710b31d10fe1ba
custom_components/ble_monitor/__init__.py
python
BLEmonitor.__init__
(self, config)
Init.
Init.
[ "Init", "." ]
def __init__(self, config): """Init.""" self.dataqueue = { "binary": janus.Queue(), "measuring": janus.Queue(), "tracker": janus.Queue(), } self.config = config self.dumpthread = None
[ "def", "__init__", "(", "self", ",", "config", ")", ":", "self", ".", "dataqueue", "=", "{", "\"binary\"", ":", "janus", ".", "Queue", "(", ")", ",", "\"measuring\"", ":", "janus", ".", "Queue", "(", ")", ",", "\"tracker\"", ":", "janus", ".", "Queue...
https://github.com/custom-components/ble_monitor/blob/64f9cb064781c6ddc5089657d3710b31d10fe1ba/custom_components/ble_monitor/__init__.py#L427-L435
mesalock-linux/mesapy
ed546d59a21b36feb93e2309d5c6b75aa0ad95c9
pypy/module/imp/__init__.py
python
Module.__init__
(self, space, *args)
NOT_RPYTHON
NOT_RPYTHON
[ "NOT_RPYTHON" ]
def __init__(self, space, *args): "NOT_RPYTHON" MixedModule.__init__(self, space, *args) from pypy.module.posix.interp_posix import add_fork_hook from pypy.module.imp import interp_imp add_fork_hook('before', interp_imp.acquire_lock) add_fork_hook('parent', interp_imp.release_lock) add_fork_hook('child', interp_imp.reinit_lock)
[ "def", "__init__", "(", "self", ",", "space", ",", "*", "args", ")", ":", "MixedModule", ".", "__init__", "(", "self", ",", "space", ",", "*", "args", ")", "from", "pypy", ".", "module", ".", "posix", ".", "interp_posix", "import", "add_fork_hook", "fr...
https://github.com/mesalock-linux/mesapy/blob/ed546d59a21b36feb93e2309d5c6b75aa0ad95c9/pypy/module/imp/__init__.py#L44-L51
angr/angr
4b04d56ace135018083d36d9083805be8146688b
angr/engines/pcode/behavior.py
python
OpBehaviorIntOr.__init__
(self)
[]
def __init__(self): super().__init__(OpCode.INT_OR, False)
[ "def", "__init__", "(", "self", ")", ":", "super", "(", ")", ".", "__init__", "(", "OpCode", ".", "INT_OR", ",", "False", ")" ]
https://github.com/angr/angr/blob/4b04d56ace135018083d36d9083805be8146688b/angr/engines/pcode/behavior.py#L281-L282
jcartledge/sublime-worksheet
44b2ba96d02759b485adbf85c1a2c9d45cc39599
repl/ftfy/__init__.py
python
fix_text_segment
(text, normalization='NFKC', entities=True)
return text
Apply fixes to text in a single chunk. This could be a line of text within a larger run of `fix_text`, or it could be a larger amount of text that you are certain is all in the same encoding.
Apply fixes to text in a single chunk. This could be a line of text within a larger run of `fix_text`, or it could be a larger amount of text that you are certain is all in the same encoding.
[ "Apply", "fixes", "to", "text", "in", "a", "single", "chunk", ".", "This", "could", "be", "a", "line", "of", "text", "within", "a", "larger", "run", "of", "fix_text", "or", "it", "could", "be", "a", "larger", "amount", "of", "text", "that", "you", "a...
def fix_text_segment(text, normalization='NFKC', entities=True): """ Apply fixes to text in a single chunk. This could be a line of text within a larger run of `fix_text`, or it could be a larger amount of text that you are certain is all in the same encoding. """ if isinstance(text, bytes): raise UnicodeError(BYTES_ERROR_TEXT) text = remove_terminal_escapes(text) if entities: text = unescape_html(text) text = fix_bad_encoding(text) text = text.translate(CONTROL_CHARS) if normalization is not None: text = unicodedata.normalize(normalization, text) text = uncurl_quotes(text) text = remove_bom(text) return text
[ "def", "fix_text_segment", "(", "text", ",", "normalization", "=", "'NFKC'", ",", "entities", "=", "True", ")", ":", "if", "isinstance", "(", "text", ",", "bytes", ")", ":", "raise", "UnicodeError", "(", "BYTES_ERROR_TEXT", ")", "text", "=", "remove_terminal...
https://github.com/jcartledge/sublime-worksheet/blob/44b2ba96d02759b485adbf85c1a2c9d45cc39599/repl/ftfy/__init__.py#L156-L173
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/Python-2.7.9/Lib/wave.py
python
Wave_write.__del__
(self)
[]
def __del__(self): self.close()
[ "def", "__del__", "(", "self", ")", ":", "self", ".", "close", "(", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/Python-2.7.9/Lib/wave.py#L328-L329
WerWolv/EdiZon_CheatsConfigsAndScripts
d16d36c7509c01dca770f402babd83ff2e9ae6e7
Scripts/lib/python3.5/imaplib.py
python
IMAP4.partial
(self, message_num, message_part, start, length)
return self._untagged_response(typ, dat, 'FETCH')
Fetch truncated part of a message. (typ, [data, ...]) = <instance>.partial(message_num, message_part, start, length) 'data' is tuple of message part envelope and data.
Fetch truncated part of a message.
[ "Fetch", "truncated", "part", "of", "a", "message", "." ]
def partial(self, message_num, message_part, start, length): """Fetch truncated part of a message. (typ, [data, ...]) = <instance>.partial(message_num, message_part, start, length) 'data' is tuple of message part envelope and data. """ name = 'PARTIAL' typ, dat = self._simple_command(name, message_num, message_part, start, length) return self._untagged_response(typ, dat, 'FETCH')
[ "def", "partial", "(", "self", ",", "message_num", ",", "message_part", ",", "start", ",", "length", ")", ":", "name", "=", "'PARTIAL'", "typ", ",", "dat", "=", "self", ".", "_simple_command", "(", "name", ",", "message_num", ",", "message_part", ",", "s...
https://github.com/WerWolv/EdiZon_CheatsConfigsAndScripts/blob/d16d36c7509c01dca770f402babd83ff2e9ae6e7/Scripts/lib/python3.5/imaplib.py#L660-L669
autonomousvision/occupancy_networks
406f79468fb8b57b3e76816aaa73b1915c53ad22
im2mesh/common.py
python
get_camera_args
(data, loc_field=None, scale_field=None, device=None)
return kwargs
Returns dictionary of camera arguments. Args: data (dict): data dictionary loc_field (str): name of location field scale_field (str): name of scale field device (device): pytorch device
Returns dictionary of camera arguments.
[ "Returns", "dictionary", "of", "camera", "arguments", "." ]
def get_camera_args(data, loc_field=None, scale_field=None, device=None): ''' Returns dictionary of camera arguments. Args: data (dict): data dictionary loc_field (str): name of location field scale_field (str): name of scale field device (device): pytorch device ''' Rt = data['inputs.world_mat'].to(device) K = data['inputs.camera_mat'].to(device) if loc_field is not None: loc = data[loc_field].to(device) else: loc = torch.zeros(K.size(0), 3, device=K.device, dtype=K.dtype) if scale_field is not None: scale = data[scale_field].to(device) else: scale = torch.zeros(K.size(0), device=K.device, dtype=K.dtype) Rt = fix_Rt_camera(Rt, loc, scale) K = fix_K_camera(K, img_size=137.) kwargs = {'Rt': Rt, 'K': K} return kwargs
[ "def", "get_camera_args", "(", "data", ",", "loc_field", "=", "None", ",", "scale_field", "=", "None", ",", "device", "=", "None", ")", ":", "Rt", "=", "data", "[", "'inputs.world_mat'", "]", ".", "to", "(", "device", ")", "K", "=", "data", "[", "'in...
https://github.com/autonomousvision/occupancy_networks/blob/406f79468fb8b57b3e76816aaa73b1915c53ad22/im2mesh/common.py#L248-L273
PythonOT/POT
be0ed1dcd0b65ec804e454f1a2d3c0d227c0ddbe
ot/backend.py
python
Backend.repeat
(self, a, repeats, axis=None)
r""" Repeats elements of a tensor. This function follows the api from :any:`numpy.repeat` See: https://numpy.org/doc/stable/reference/generated/numpy.repeat.html
r""" Repeats elements of a tensor.
[ "r", "Repeats", "elements", "of", "a", "tensor", "." ]
def repeat(self, a, repeats, axis=None): r""" Repeats elements of a tensor. This function follows the api from :any:`numpy.repeat` See: https://numpy.org/doc/stable/reference/generated/numpy.repeat.html """ raise NotImplementedError()
[ "def", "repeat", "(", "self", ",", "a", ",", "repeats", ",", "axis", "=", "None", ")", ":", "raise", "NotImplementedError", "(", ")" ]
https://github.com/PythonOT/POT/blob/be0ed1dcd0b65ec804e454f1a2d3c0d227c0ddbe/ot/backend.py#L489-L497
pyga/parsley
c89b3f0e09a9501f285a14ae446a77a56ee99942
ometa/interp.py
python
TrampolinedGrammarInterpreter.parse_Exactly
(self, spec)
Accept a one or more characters that equal the given spec.
Accept a one or more characters that equal the given spec.
[ "Accept", "a", "one", "or", "more", "characters", "that", "equal", "the", "given", "spec", "." ]
def parse_Exactly(self, spec): """ Accept a one or more characters that equal the given spec. """ wanted = spec.data result = [] for c in wanted: try: val, p = self.input.head() except EOFError: yield _feed_me val, p = self.input.head() result.append(val) if val == c: self.input = self.input.tail() else: raise self.err(p.withMessage(expected(None, wanted))) yield ''.join(result), p
[ "def", "parse_Exactly", "(", "self", ",", "spec", ")", ":", "wanted", "=", "spec", ".", "data", "result", "=", "[", "]", "for", "c", "in", "wanted", ":", "try", ":", "val", ",", "p", "=", "self", ".", "input", ".", "head", "(", ")", "except", "...
https://github.com/pyga/parsley/blob/c89b3f0e09a9501f285a14ae446a77a56ee99942/ometa/interp.py#L184-L201
tav/pylibs
3c16b843681f54130ee6a022275289cadb2f2a69
paramiko/transport.py
python
Transport.getpeername
(self)
return gp()
Return the address of the remote side of this Transport, if possible. This is effectively a wrapper around C{'getpeername'} on the underlying socket. If the socket-like object has no C{'getpeername'} method, then C{("unknown", 0)} is returned. @return: the address if the remote host, if known @rtype: tuple(str, int)
Return the address of the remote side of this Transport, if possible. This is effectively a wrapper around C{'getpeername'} on the underlying socket. If the socket-like object has no C{'getpeername'} method, then C{("unknown", 0)} is returned.
[ "Return", "the", "address", "of", "the", "remote", "side", "of", "this", "Transport", "if", "possible", ".", "This", "is", "effectively", "a", "wrapper", "around", "C", "{", "getpeername", "}", "on", "the", "underlying", "socket", ".", "If", "the", "socket...
def getpeername(self): """ Return the address of the remote side of this Transport, if possible. This is effectively a wrapper around C{'getpeername'} on the underlying socket. If the socket-like object has no C{'getpeername'} method, then C{("unknown", 0)} is returned. @return: the address if the remote host, if known @rtype: tuple(str, int) """ gp = getattr(self.sock, 'getpeername', None) if gp is None: return ('unknown', 0) return gp()
[ "def", "getpeername", "(", "self", ")", ":", "gp", "=", "getattr", "(", "self", ".", "sock", ",", "'getpeername'", ",", "None", ")", "if", "gp", "is", "None", ":", "return", "(", "'unknown'", ",", "0", ")", "return", "gp", "(", ")" ]
https://github.com/tav/pylibs/blob/3c16b843681f54130ee6a022275289cadb2f2a69/paramiko/transport.py#L1340-L1353
clinton-hall/nzbToMedia
27669389216902d1085660167e7bda0bd8527ecf
libs/win/six.py
python
add_metaclass
(metaclass)
return wrapper
Class decorator for creating a class with a metaclass.
Class decorator for creating a class with a metaclass.
[ "Class", "decorator", "for", "creating", "a", "class", "with", "a", "metaclass", "." ]
def add_metaclass(metaclass): """Class decorator for creating a class with a metaclass.""" def wrapper(cls): orig_vars = cls.__dict__.copy() slots = orig_vars.get('__slots__') if slots is not None: if isinstance(slots, str): slots = [slots] for slots_var in slots: orig_vars.pop(slots_var) orig_vars.pop('__dict__', None) orig_vars.pop('__weakref__', None) if hasattr(cls, '__qualname__'): orig_vars['__qualname__'] = cls.__qualname__ return metaclass(cls.__name__, cls.__bases__, orig_vars) return wrapper
[ "def", "add_metaclass", "(", "metaclass", ")", ":", "def", "wrapper", "(", "cls", ")", ":", "orig_vars", "=", "cls", ".", "__dict__", ".", "copy", "(", ")", "slots", "=", "orig_vars", ".", "get", "(", "'__slots__'", ")", "if", "slots", "is", "not", "...
https://github.com/clinton-hall/nzbToMedia/blob/27669389216902d1085660167e7bda0bd8527ecf/libs/win/six.py#L835-L850
cloudera/hue
23f02102d4547c17c32bd5ea0eb24e9eadd657a4
desktop/core/ext-py/zope.interface-4.5.0/src/zope/interface/declarations.py
python
classImplements
(cls, *interfaces)
Declare additional interfaces implemented for instances of a class The arguments after the class are one or more interfaces or interface specifications (``IDeclaration`` objects). The interfaces given (including the interfaces in the specifications) are added to any interfaces previously declared.
Declare additional interfaces implemented for instances of a class
[ "Declare", "additional", "interfaces", "implemented", "for", "instances", "of", "a", "class" ]
def classImplements(cls, *interfaces): """Declare additional interfaces implemented for instances of a class The arguments after the class are one or more interfaces or interface specifications (``IDeclaration`` objects). The interfaces given (including the interfaces in the specifications) are added to any interfaces previously declared. """ spec = implementedBy(cls) spec.declared += tuple(_normalizeargs(interfaces)) # compute the bases bases = [] seen = {} for b in spec.declared: if b not in seen: seen[b] = 1 bases.append(b) if spec.inherit is not None: for c in spec.inherit.__bases__: b = implementedBy(c) if b not in seen: seen[b] = 1 bases.append(b) spec.__bases__ = tuple(bases)
[ "def", "classImplements", "(", "cls", ",", "*", "interfaces", ")", ":", "spec", "=", "implementedBy", "(", "cls", ")", "spec", ".", "declared", "+=", "tuple", "(", "_normalizeargs", "(", "interfaces", ")", ")", "# compute the bases", "bases", "=", "[", "]"...
https://github.com/cloudera/hue/blob/23f02102d4547c17c32bd5ea0eb24e9eadd657a4/desktop/core/ext-py/zope.interface-4.5.0/src/zope/interface/declarations.py#L315-L343
DataDog/integrations-core
934674b29d94b70ccc008f76ea172d0cdae05e1e
sonarqube/datadog_checks/sonarqube/config_models/defaults.py
python
instance_timeout
(field, value)
return 10
[]
def instance_timeout(field, value): return 10
[ "def", "instance_timeout", "(", "field", ",", "value", ")", ":", "return", "10" ]
https://github.com/DataDog/integrations-core/blob/934674b29d94b70ccc008f76ea172d0cdae05e1e/sonarqube/datadog_checks/sonarqube/config_models/defaults.py#L237-L238
ztosec/hunter
4ee5cca8dc5fc5d7e631e935517bd0f493c30a37
SqlmapCelery/sqlmap/lib/request/basic.py
python
checkCharEncoding
(encoding, warn=True)
return encoding
Checks encoding name, repairs common misspellings and adjusts to proper namings used in codecs module >>> checkCharEncoding('iso-8858', False) 'iso8859-1' >>> checkCharEncoding('en_us', False) 'utf8'
Checks encoding name, repairs common misspellings and adjusts to proper namings used in codecs module
[ "Checks", "encoding", "name", "repairs", "common", "misspellings", "and", "adjusts", "to", "proper", "namings", "used", "in", "codecs", "module" ]
def checkCharEncoding(encoding, warn=True): """ Checks encoding name, repairs common misspellings and adjusts to proper namings used in codecs module >>> checkCharEncoding('iso-8858', False) 'iso8859-1' >>> checkCharEncoding('en_us', False) 'utf8' """ if encoding: encoding = encoding.lower() else: return encoding # Reference: http://www.destructor.de/charsets/index.htm translate = {"windows-874": "iso-8859-11", "utf-8859-1": "utf8", "en_us": "utf8", "macintosh": "iso-8859-1", "euc_tw": "big5_tw", "th": "tis-620", "unicode": "utf8", "utc8": "utf8", "ebcdic": "ebcdic-cp-be", "iso-8859": "iso8859-1", "ansi": "ascii", "gbk2312": "gbk", "windows-31j": "cp932", "en": "us"} for delimiter in (';', ',', '('): if delimiter in encoding: encoding = encoding[:encoding.find(delimiter)].strip() encoding = encoding.replace("&quot", "") # popular typos/errors if "8858" in encoding: encoding = encoding.replace("8858", "8859") # iso-8858 -> iso-8859 elif "8559" in encoding: encoding = encoding.replace("8559", "8859") # iso-8559 -> iso-8859 elif "8895" in encoding: encoding = encoding.replace("8895", "8859") # iso-8895 -> iso-8859 elif "5889" in encoding: encoding = encoding.replace("5889", "8859") # iso-5889 -> iso-8859 elif "5589" in encoding: encoding = encoding.replace("5589", "8859") # iso-5589 -> iso-8859 elif "2313" in encoding: encoding = encoding.replace("2313", "2312") # gb2313 -> gb2312 elif encoding.startswith("x-"): encoding = encoding[len("x-"):] # x-euc-kr -> euc-kr / x-mac-turkish -> mac-turkish elif "windows-cp" in encoding: encoding = encoding.replace("windows-cp", "windows") # windows-cp-1254 -> windows-1254 # name adjustment for compatibility if encoding.startswith("8859"): encoding = "iso-%s" % encoding elif encoding.startswith("cp-"): encoding = "cp%s" % encoding[3:] elif encoding.startswith("euc-"): encoding = "euc_%s" % encoding[4:] elif encoding.startswith("windows") and not encoding.startswith("windows-"): encoding = "windows-%s" % encoding[7:] elif encoding.find("iso-88") > 0: encoding = encoding[encoding.find("iso-88"):] elif encoding.startswith("is0-"): encoding = "iso%s" % encoding[4:] elif encoding.find("ascii") > 0: encoding = "ascii" elif encoding.find("utf8") > 0: encoding = "utf8" elif encoding.find("utf-8") > 0: encoding = "utf-8" # Reference: http://philip.html5.org/data/charsets-2.html if encoding in translate: encoding = translate[encoding] elif encoding in ("null", "{charset}", "charset", "*") or not re.search(r"\w", encoding): return None # Reference: http://www.iana.org/assignments/character-sets # Reference: http://docs.python.org/library/codecs.html try: codecs.lookup(encoding.encode(UNICODE_ENCODING) if isinstance(encoding, unicode) else encoding) except (LookupError, ValueError): if warn: warnMsg = "unknown web page charset '%s'. " % encoding warnMsg += "Please report by e-mail to 'dev@sqlmap.org'" singleTimeLogMessage(warnMsg, logging.WARN, encoding) encoding = None if encoding: try: unicode(randomStr(), encoding) except: if warn: warnMsg = "invalid web page charset '%s'" % encoding singleTimeLogMessage(warnMsg, logging.WARN, encoding) encoding = None return encoding
[ "def", "checkCharEncoding", "(", "encoding", ",", "warn", "=", "True", ")", ":", "if", "encoding", ":", "encoding", "=", "encoding", ".", "lower", "(", ")", "else", ":", "return", "encoding", "# Reference: http://www.destructor.de/charsets/index.htm", "translate", ...
https://github.com/ztosec/hunter/blob/4ee5cca8dc5fc5d7e631e935517bd0f493c30a37/SqlmapCelery/sqlmap/lib/request/basic.py#L141-L230
beeware/colosseum
cbf974be54fd7f6fddbe7285704cfaf7a866c5c5
src/colosseum/dimensions.py
python
Size.ratio
(self)
return self._ratio
[]
def ratio(self): return self._ratio
[ "def", "ratio", "(", "self", ")", ":", "return", "self", ".", "_ratio" ]
https://github.com/beeware/colosseum/blob/cbf974be54fd7f6fddbe7285704cfaf7a866c5c5/src/colosseum/dimensions.py#L75-L76
pascalw/Airplayer
cb6f6a393710a31f934e3c09de4f689158d23b50
airplayer/lib/jsonrpclib/jsonrpc.py
python
Payload.request
(self, method, params=[])
return request
[]
def request(self, method, params=[]): if type(method) not in types.StringTypes: raise ValueError('Method name must be a string.') if not self.id: self.id = random_id() request = { 'id':self.id, 'method':method } if params: request['params'] = params if self.version >= 2: request['jsonrpc'] = str(self.version) return request
[ "def", "request", "(", "self", ",", "method", ",", "params", "=", "[", "]", ")", ":", "if", "type", "(", "method", ")", "not", "in", "types", ".", "StringTypes", ":", "raise", "ValueError", "(", "'Method name must be a string.'", ")", "if", "not", "self"...
https://github.com/pascalw/Airplayer/blob/cb6f6a393710a31f934e3c09de4f689158d23b50/airplayer/lib/jsonrpclib/jsonrpc.py#L389-L399
PlasmaPy/PlasmaPy
78d63e341216475ce3318e1409296480407c9019
plasmapy/diagnostics/langmuir.py
python
_fit_func_lin
(x, x0, y0, c0)
return y0 + c0 * (x - x0)
r"""Linear fitting function.
r"""Linear fitting function.
[ "r", "Linear", "fitting", "function", "." ]
def _fit_func_lin(x, x0, y0, c0): r"""Linear fitting function.""" return y0 + c0 * (x - x0)
[ "def", "_fit_func_lin", "(", "x", ",", "x0", ",", "y0", ",", "c0", ")", ":", "return", "y0", "+", "c0", "*", "(", "x", "-", "x0", ")" ]
https://github.com/PlasmaPy/PlasmaPy/blob/78d63e341216475ce3318e1409296480407c9019/plasmapy/diagnostics/langmuir.py#L43-L46
Jenyay/outwiker
50530cf7b3f71480bb075b2829bc0669773b835b
plugins/webpage/webpage/libs/email/_header_value_parser.py
python
get_dot_atom
(value)
return dot_atom, value
dot-atom = [CFWS] dot-atom-text [CFWS] Any place we can have a dot atom, we could instead have an rfc2047 encoded word.
dot-atom = [CFWS] dot-atom-text [CFWS]
[ "dot", "-", "atom", "=", "[", "CFWS", "]", "dot", "-", "atom", "-", "text", "[", "CFWS", "]" ]
def get_dot_atom(value): """ dot-atom = [CFWS] dot-atom-text [CFWS] Any place we can have a dot atom, we could instead have an rfc2047 encoded word. """ dot_atom = DotAtom() if value[0] in CFWS_LEADER: token, value = get_cfws(value) dot_atom.append(token) if value.startswith('=?'): try: token, value = get_encoded_word(value) except errors.HeaderParseError: # XXX: need to figure out how to register defects when # appropriate here. token, value = get_dot_atom_text(value) else: token, value = get_dot_atom_text(value) dot_atom.append(token) if value and value[0] in CFWS_LEADER: token, value = get_cfws(value) dot_atom.append(token) return dot_atom, value
[ "def", "get_dot_atom", "(", "value", ")", ":", "dot_atom", "=", "DotAtom", "(", ")", "if", "value", "[", "0", "]", "in", "CFWS_LEADER", ":", "token", ",", "value", "=", "get_cfws", "(", "value", ")", "dot_atom", ".", "append", "(", "token", ")", "if"...
https://github.com/Jenyay/outwiker/blob/50530cf7b3f71480bb075b2829bc0669773b835b/plugins/webpage/webpage/libs/email/_header_value_parser.py#L1698-L1721
dpgaspar/Flask-AppBuilder
557249f33b66d02a48c1322ef21324b815abe18e
flask_appbuilder/validators.py
python
default_password_complexity
(password: str)
FAB's default password complexity validator, set FAB_PASSWORD_COMPLEXITY_ENABLED to True to enable it
FAB's default password complexity validator, set FAB_PASSWORD_COMPLEXITY_ENABLED to True to enable it
[ "FAB", "s", "default", "password", "complexity", "validator", "set", "FAB_PASSWORD_COMPLEXITY_ENABLED", "to", "True", "to", "enable", "it" ]
def default_password_complexity(password: str) -> None: """ FAB's default password complexity validator, set FAB_PASSWORD_COMPLEXITY_ENABLED to True to enable it """ match = re.search(password_complexity_regex, password) if not match: raise PasswordComplexityValidationError( gettext( "Must have at least two capital letters," " one special character, two digits, three lower case letters and" " a minimal length of 10." ) )
[ "def", "default_password_complexity", "(", "password", ":", "str", ")", "->", "None", ":", "match", "=", "re", ".", "search", "(", "password_complexity_regex", ",", "password", ")", "if", "not", "match", ":", "raise", "PasswordComplexityValidationError", "(", "g...
https://github.com/dpgaspar/Flask-AppBuilder/blob/557249f33b66d02a48c1322ef21324b815abe18e/flask_appbuilder/validators.py#L79-L92
oilshell/oil
94388e7d44a9ad879b12615f6203b38596b5a2d3
Python-2.7.13/Lib/plat-mac/PixMapWrapper.py
python
PixMapWrapper._unstuff
(self, element)
return struct.unpack(fmt, self._header[offset:offset+struct.calcsize(fmt)])[0]
[]
def _unstuff(self, element): offset = _pmElemOffset[element] fmt = _pmElemFormat[element] return struct.unpack(fmt, self._header[offset:offset+struct.calcsize(fmt)])[0]
[ "def", "_unstuff", "(", "self", ",", "element", ")", ":", "offset", "=", "_pmElemOffset", "[", "element", "]", "fmt", "=", "_pmElemFormat", "[", "element", "]", "return", "struct", ".", "unpack", "(", "fmt", ",", "self", ".", "_header", "[", "offset", ...
https://github.com/oilshell/oil/blob/94388e7d44a9ad879b12615f6203b38596b5a2d3/Python-2.7.13/Lib/plat-mac/PixMapWrapper.py#L93-L96
larryhastings/gilectomy
4315ec3f1d6d4f813cc82ce27a24e7f784dbfc1a
Lib/asyncio/tasks.py
python
Task.current_task
(cls, loop=None)
return cls._current_tasks.get(loop)
Return the currently running task in an event loop or None. By default the current task for the current event loop is returned. None is returned when called not in the context of a Task.
Return the currently running task in an event loop or None.
[ "Return", "the", "currently", "running", "task", "in", "an", "event", "loop", "or", "None", "." ]
def current_task(cls, loop=None): """Return the currently running task in an event loop or None. By default the current task for the current event loop is returned. None is returned when called not in the context of a Task. """ if loop is None: loop = events.get_event_loop() return cls._current_tasks.get(loop)
[ "def", "current_task", "(", "cls", ",", "loop", "=", "None", ")", ":", "if", "loop", "is", "None", ":", "loop", "=", "events", ".", "get_event_loop", "(", ")", "return", "cls", ".", "_current_tasks", ".", "get", "(", "loop", ")" ]
https://github.com/larryhastings/gilectomy/blob/4315ec3f1d6d4f813cc82ce27a24e7f784dbfc1a/Lib/asyncio/tasks.py#L49-L58
sametmax/Django--an-app-at-a-time
99eddf12ead76e6dfbeb09ce0bae61e282e22f8a
ignore_this_directory/django/contrib/admin/options.py
python
ModelAdmin.response_delete
(self, request, obj_display, obj_id)
return HttpResponseRedirect(post_url)
Determine the HttpResponse for the delete_view stage.
Determine the HttpResponse for the delete_view stage.
[ "Determine", "the", "HttpResponse", "for", "the", "delete_view", "stage", "." ]
def response_delete(self, request, obj_display, obj_id): """ Determine the HttpResponse for the delete_view stage. """ opts = self.model._meta if IS_POPUP_VAR in request.POST: popup_response_data = json.dumps({ 'action': 'delete', 'value': str(obj_id), }) return TemplateResponse(request, self.popup_response_template or [ 'admin/%s/%s/popup_response.html' % (opts.app_label, opts.model_name), 'admin/%s/popup_response.html' % opts.app_label, 'admin/popup_response.html', ], { 'popup_response_data': popup_response_data, }) self.message_user( request, _('The %(name)s "%(obj)s" was deleted successfully.') % { 'name': opts.verbose_name, 'obj': obj_display, }, messages.SUCCESS, ) if self.has_change_permission(request, None): post_url = reverse( 'admin:%s_%s_changelist' % (opts.app_label, opts.model_name), current_app=self.admin_site.name, ) preserved_filters = self.get_preserved_filters(request) post_url = add_preserved_filters( {'preserved_filters': preserved_filters, 'opts': opts}, post_url ) else: post_url = reverse('admin:index', current_app=self.admin_site.name) return HttpResponseRedirect(post_url)
[ "def", "response_delete", "(", "self", ",", "request", ",", "obj_display", ",", "obj_id", ")", ":", "opts", "=", "self", ".", "model", ".", "_meta", "if", "IS_POPUP_VAR", "in", "request", ".", "POST", ":", "popup_response_data", "=", "json", ".", "dumps", ...
https://github.com/sametmax/Django--an-app-at-a-time/blob/99eddf12ead76e6dfbeb09ce0bae61e282e22f8a/ignore_this_directory/django/contrib/admin/options.py#L1411-L1450
zzzeek/sqlalchemy
fc5c54fcd4d868c2a4c7ac19668d72f506fe821e
lib/sqlalchemy/engine/interfaces.py
python
Connectable.execute
(self, object_, *multiparams, **params)
Executes the given construct and returns a :class:`_result.Result`.
Executes the given construct and returns a :class:`_result.Result`.
[ "Executes", "the", "given", "construct", "and", "returns", "a", ":", "class", ":", "_result", ".", "Result", "." ]
def execute(self, object_, *multiparams, **params): """Executes the given construct and returns a :class:`_result.Result`. """ raise NotImplementedError()
[ "def", "execute", "(", "self", ",", "object_", ",", "*", "multiparams", ",", "*", "*", "params", ")", ":", "raise", "NotImplementedError", "(", ")" ]
https://github.com/zzzeek/sqlalchemy/blob/fc5c54fcd4d868c2a4c7ac19668d72f506fe821e/lib/sqlalchemy/engine/interfaces.py#L1567-L1572
yt-project/yt
dc7b24f9b266703db4c843e329c6c8644d47b824
yt/visualization/volume_rendering/scene.py
python
Scene.__init__
(self)
r"""Create a new Scene instance
r"""Create a new Scene instance
[ "r", "Create", "a", "new", "Scene", "instance" ]
def __init__(self): r"""Create a new Scene instance""" super().__init__() self.sources = OrderedDict() self._last_render = None # A non-public attribute used to get around the fact that we can't # pass kwargs into _repr_png_() self._sigma_clip = None
[ "def", "__init__", "(", "self", ")", ":", "super", "(", ")", ".", "__init__", "(", ")", "self", ".", "sources", "=", "OrderedDict", "(", ")", "self", ".", "_last_render", "=", "None", "# A non-public attribute used to get around the fact that we can't", "# pass kw...
https://github.com/yt-project/yt/blob/dc7b24f9b266703db4c843e329c6c8644d47b824/yt/visualization/volume_rendering/scene.py#L76-L83
catap/namebench
9913a7a1a7955a3759eb18cbe73b421441a7a00f
nb_third_party/jinja2/filters.py
python
do_int
(value, default=0)
Convert the value into an integer. If the conversion doesn't work it will return ``0``. You can override this default using the first parameter.
Convert the value into an integer. If the conversion doesn't work it will return ``0``. You can override this default using the first parameter.
[ "Convert", "the", "value", "into", "an", "integer", ".", "If", "the", "conversion", "doesn", "t", "work", "it", "will", "return", "0", ".", "You", "can", "override", "this", "default", "using", "the", "first", "parameter", "." ]
def do_int(value, default=0): """Convert the value into an integer. If the conversion doesn't work it will return ``0``. You can override this default using the first parameter. """ try: return int(value) except (TypeError, ValueError): # this quirk is necessary so that "42.23"|int gives 42. try: return int(float(value)) except (TypeError, ValueError): return default
[ "def", "do_int", "(", "value", ",", "default", "=", "0", ")", ":", "try", ":", "return", "int", "(", "value", ")", "except", "(", "TypeError", ",", "ValueError", ")", ":", "# this quirk is necessary so that \"42.23\"|int gives 42.", "try", ":", "return", "int"...
https://github.com/catap/namebench/blob/9913a7a1a7955a3759eb18cbe73b421441a7a00f/nb_third_party/jinja2/filters.py#L405-L417
paulvangentcom/python_corona_simulation
a5dddd3e13d2bb768a9294d85ab27329be9a21dd
old/simple_simulation.py
python
infect
(population, infection_range, infection_chance, frame)
return population
finds new infections Keyword arguments -----------------
finds new infections Keyword arguments -----------------
[ "finds", "new", "infections", "Keyword", "arguments", "-----------------" ]
def infect(population, infection_range, infection_chance, frame): '''finds new infections Keyword arguments ----------------- ''' #find new infections infected_previous_step = population[population[:,6] == 1] new_infections = [] #if less than half are infected, slice based on infected (to speed up computation) if len(infected_previous_step) < (pop_size // 2): for patient in infected_previous_step: #define infection zone for patient infection_zone = [patient[1] - infection_range, patient[2] - infection_range, patient[1] + infection_range, patient[2] + infection_range] #find healthy people surrounding infected patient indices = np.int32(population[:,0][(infection_zone[0] < population[:,1]) & (population[:,1] < infection_zone[2]) & (infection_zone[1] < population [:,2]) & (population[:,2] < infection_zone[3]) & (population[:,6] == 0)]) for idx in indices: #roll die to see if healthy person will be infected if np.random.random() < infection_chance: population[idx][6] = 1 population[idx][8] = frame new_infections.append(idx) else: #if more than half are infected slice based in healthy people (to speed up computation) healthy_previous_step = population[population[:,6] == 0] sick_previous_step = population[population[:,6] == 1] for person in healthy_previous_step: #define infecftion range around healthy person infection_zone = [person[1] - infection_range, person[2] - infection_range, person[1] + infection_range, person[2] + infection_range] if person[6] == 0: #if person is not already infected, find if infected are nearby #find infected nearby healthy person poplen = len(sick_previous_step[:,6][(infection_zone[0] < sick_previous_step[:,1]) & (sick_previous_step[:,1] < infection_zone[2]) & (infection_zone[1] < sick_previous_step [:,2]) & (sick_previous_step[:,2] < infection_zone[3]) & (sick_previous_step[:,6] == 1)]) if poplen > 0: if np.random.random() < (infection_chance * poplen): #roll die to see if healthy person will be infected population[np.int32(person[0])][6] = 1 population[np.int32(person[0])][8] = frame new_infections.append(np.int32(person[0])) if len(new_infections) > 0: print('at timestep %i these people got sick: %s' %(frame, new_infections)) return population
[ "def", "infect", "(", "population", ",", "infection_range", ",", "infection_chance", ",", "frame", ")", ":", "#find new infections", "infected_previous_step", "=", "population", "[", "population", "[", ":", ",", "6", "]", "==", "1", "]", "new_infections", "=", ...
https://github.com/paulvangentcom/python_corona_simulation/blob/a5dddd3e13d2bb768a9294d85ab27329be9a21dd/old/simple_simulation.py#L172-L234
omz/PythonistaAppTemplate
f560f93f8876d82a21d108977f90583df08d55af
PythonistaAppTemplate/PythonistaKit.framework/pylib/site-packages/flask/helpers.py
python
find_package
(import_name)
return None, package_path
Finds a package and returns the prefix (or None if the package is not installed) as well as the folder that contains the package or module as a tuple. The package path returned is the module that would have to be added to the pythonpath in order to make it possible to import the module. The prefix is the path below which a UNIX like folder structure exists (lib, share etc.).
Finds a package and returns the prefix (or None if the package is not installed) as well as the folder that contains the package or module as a tuple. The package path returned is the module that would have to be added to the pythonpath in order to make it possible to import the module. The prefix is the path below which a UNIX like folder structure exists (lib, share etc.).
[ "Finds", "a", "package", "and", "returns", "the", "prefix", "(", "or", "None", "if", "the", "package", "is", "not", "installed", ")", "as", "well", "as", "the", "folder", "that", "contains", "the", "package", "or", "module", "as", "a", "tuple", ".", "T...
def find_package(import_name): """Finds a package and returns the prefix (or None if the package is not installed) as well as the folder that contains the package or module as a tuple. The package path returned is the module that would have to be added to the pythonpath in order to make it possible to import the module. The prefix is the path below which a UNIX like folder structure exists (lib, share etc.). """ root_mod_name = import_name.split('.')[0] loader = pkgutil.get_loader(root_mod_name) if loader is None or import_name == '__main__': # import name is not found, or interactive/main module package_path = os.getcwd() else: # For .egg, zipimporter does not have get_filename until Python 2.7. if hasattr(loader, 'get_filename'): filename = loader.get_filename(root_mod_name) elif hasattr(loader, 'archive'): # zipimporter's loader.archive points to the .egg or .zip # archive filename is dropped in call to dirname below. filename = loader.archive else: # At least one loader is missing both get_filename and archive: # Google App Engine's HardenedModulesHook # # Fall back to imports. __import__(import_name) filename = sys.modules[import_name].__file__ package_path = os.path.abspath(os.path.dirname(filename)) # package_path ends with __init__.py for a package if loader.is_package(root_mod_name): package_path = os.path.dirname(package_path) site_parent, site_folder = os.path.split(package_path) py_prefix = os.path.abspath(sys.prefix) if package_path.startswith(py_prefix): return py_prefix, package_path elif site_folder.lower() == 'site-packages': parent, folder = os.path.split(site_parent) # Windows like installations if folder.lower() == 'lib': base_dir = parent # UNIX like installations elif os.path.basename(parent).lower() == 'lib': base_dir = os.path.dirname(parent) else: base_dir = site_parent return base_dir, package_path return None, package_path
[ "def", "find_package", "(", "import_name", ")", ":", "root_mod_name", "=", "import_name", ".", "split", "(", "'.'", ")", "[", "0", "]", "loader", "=", "pkgutil", ".", "get_loader", "(", "root_mod_name", ")", "if", "loader", "is", "None", "or", "import_name...
https://github.com/omz/PythonistaAppTemplate/blob/f560f93f8876d82a21d108977f90583df08d55af/PythonistaAppTemplate/PythonistaKit.framework/pylib/site-packages/flask/helpers.py#L652-L700
ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework
cb692f527e4e819b6c228187c5702d990a180043
external/Scripting Engine/Xenotix Python Scripting Engine/bin/x86/Debug/Lib/runpy.py
python
_run_module_code
(code, init_globals=None, mod_name=None, mod_fname=None, mod_loader=None, pkg_name=None)
return mod_globals.copy()
Helper to run code in new namespace with sys modified
Helper to run code in new namespace with sys modified
[ "Helper", "to", "run", "code", "in", "new", "namespace", "with", "sys", "modified" ]
def _run_module_code(code, init_globals=None, mod_name=None, mod_fname=None, mod_loader=None, pkg_name=None): """Helper to run code in new namespace with sys modified""" with _TempModule(mod_name) as temp_module, _ModifiedArgv0(mod_fname): mod_globals = temp_module.module.__dict__ _run_code(code, mod_globals, init_globals, mod_name, mod_fname, mod_loader, pkg_name) # Copy the globals of the temporary module, as they # may be cleared when the temporary module goes away return mod_globals.copy()
[ "def", "_run_module_code", "(", "code", ",", "init_globals", "=", "None", ",", "mod_name", "=", "None", ",", "mod_fname", "=", "None", ",", "mod_loader", "=", "None", ",", "pkg_name", "=", "None", ")", ":", "with", "_TempModule", "(", "mod_name", ")", "a...
https://github.com/ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework/blob/cb692f527e4e819b6c228187c5702d990a180043/external/Scripting Engine/Xenotix Python Scripting Engine/bin/x86/Debug/Lib/runpy.py#L75-L85
mithril-global/GoAgentX
788fbd5e1c824c75cf98a9aef8a6d4ec8df25e95
GoAgentX.app/Contents/PlugIns/shadowsocks.gxbundle/Contents/Resources/bin/python/M2Crypto/ftpslib.py
python
FTP_TLS.auth_tls
(self)
Secure the control connection per AUTH TLS, aka AUTH TLS-C.
Secure the control connection per AUTH TLS, aka AUTH TLS-C.
[ "Secure", "the", "control", "connection", "per", "AUTH", "TLS", "aka", "AUTH", "TLS", "-", "C", "." ]
def auth_tls(self): """Secure the control connection per AUTH TLS, aka AUTH TLS-C.""" self.voidcmd('AUTH TLS') s = SSL.Connection(self.ssl_ctx, self.sock) s.setup_ssl() s.set_connect_state() s.connect_ssl() self.sock = s self.file = self.sock.makefile()
[ "def", "auth_tls", "(", "self", ")", ":", "self", ".", "voidcmd", "(", "'AUTH TLS'", ")", "s", "=", "SSL", ".", "Connection", "(", "self", ".", "ssl_ctx", ",", "self", ".", "sock", ")", "s", ".", "setup_ssl", "(", ")", "s", ".", "set_connect_state", ...
https://github.com/mithril-global/GoAgentX/blob/788fbd5e1c824c75cf98a9aef8a6d4ec8df25e95/GoAgentX.app/Contents/PlugIns/shadowsocks.gxbundle/Contents/Resources/bin/python/M2Crypto/ftpslib.py#L58-L66
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/combinat/cluster_algebra_quiver/cluster_seed.py
python
ClusterSeed.mutation_class
(self, depth=infinity, show_depth=False, return_paths=False, up_to_equivalence=True, only_sink_source=False)
return list( S for S in self.mutation_class_iter( depth=depth, show_depth=show_depth, return_paths=return_paths, up_to_equivalence=up_to_equivalence, only_sink_source=only_sink_source ) )
r""" Return the mutation class of ``self`` with respect to certain constraints. .. NOTE:: Vertex labels are not tracked in this method. .. SEEALSO:: :meth:`mutation_class_iter` INPUT: - ``depth`` -- (default: ``infinity`) integer, only seeds with distance at most depth from ``self`` are returned - ``show_depth`` -- (default: ``False``) if ``True``, the actual depth of the mutation is shown - ``return_paths`` -- (default: ``False``) if ``True``, a shortest path of mutation sequences from self to the given quiver is returned as well - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only seeds up to equivalence are considered - ``sink_source`` -- (default: ``False``) if ``True``, only mutations at sinks and sources are applied EXAMPLES: - for examples see :meth:`mutation_class_iter` TESTS:: sage: A = ClusterSeed(['A',3]).mutation_class()
r""" Return the mutation class of ``self`` with respect to certain constraints.
[ "r", "Return", "the", "mutation", "class", "of", "self", "with", "respect", "to", "certain", "constraints", "." ]
def mutation_class(self, depth=infinity, show_depth=False, return_paths=False, up_to_equivalence=True, only_sink_source=False): r""" Return the mutation class of ``self`` with respect to certain constraints. .. NOTE:: Vertex labels are not tracked in this method. .. SEEALSO:: :meth:`mutation_class_iter` INPUT: - ``depth`` -- (default: ``infinity`) integer, only seeds with distance at most depth from ``self`` are returned - ``show_depth`` -- (default: ``False``) if ``True``, the actual depth of the mutation is shown - ``return_paths`` -- (default: ``False``) if ``True``, a shortest path of mutation sequences from self to the given quiver is returned as well - ``up_to_equivalence`` -- (default: ``True``) if ``True``, only seeds up to equivalence are considered - ``sink_source`` -- (default: ``False``) if ``True``, only mutations at sinks and sources are applied EXAMPLES: - for examples see :meth:`mutation_class_iter` TESTS:: sage: A = ClusterSeed(['A',3]).mutation_class() """ if depth is infinity and not self.is_finite(): raise ValueError('The mutation class can - for infinite types - only be computed up to a given depth') return list( S for S in self.mutation_class_iter( depth=depth, show_depth=show_depth, return_paths=return_paths, up_to_equivalence=up_to_equivalence, only_sink_source=only_sink_source ) )
[ "def", "mutation_class", "(", "self", ",", "depth", "=", "infinity", ",", "show_depth", "=", "False", ",", "return_paths", "=", "False", ",", "up_to_equivalence", "=", "True", ",", "only_sink_source", "=", "False", ")", ":", "if", "depth", "is", "infinity", ...
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py#L3519-L3557
AppScale/gts
46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9
AppServer/google/net/proto2/python/public/service.py
python
RpcController.NotifyOnCancel
(self, callback)
Sets a callback to invoke on cancel. Asks that the given callback be called when the RPC is canceled. The callback will always be called exactly once. If the RPC completes without being canceled, the callback will be called after completion. If the RPC has already been canceled when NotifyOnCancel() is called, the callback will be called immediately. NotifyOnCancel() must be called no more than once per request.
Sets a callback to invoke on cancel.
[ "Sets", "a", "callback", "to", "invoke", "on", "cancel", "." ]
def NotifyOnCancel(self, callback): """Sets a callback to invoke on cancel. Asks that the given callback be called when the RPC is canceled. The callback will always be called exactly once. If the RPC completes without being canceled, the callback will be called after completion. If the RPC has already been canceled when NotifyOnCancel() is called, the callback will be called immediately. NotifyOnCancel() must be called no more than once per request. """ raise NotImplementedError
[ "def", "NotifyOnCancel", "(", "self", ",", "callback", ")", ":", "raise", "NotImplementedError" ]
https://github.com/AppScale/gts/blob/46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9/AppServer/google/net/proto2/python/public/service.py#L176-L187
catap/namebench
9913a7a1a7955a3759eb18cbe73b421441a7a00f
libnamebench/geoip.py
python
GetInfoForCountry
(country_name_or_code)
Get code, name, lat and lon for a given country name or code.
Get code, name, lat and lon for a given country name or code.
[ "Get", "code", "name", "lat", "and", "lon", "for", "a", "given", "country", "name", "or", "code", "." ]
def GetInfoForCountry(country_name_or_code): """Get code, name, lat and lon for a given country name or code.""" match = False partial_match = False if not country_name_or_code: return None if len(country_name_or_code) == 2: country_code = country_name_or_code.upper() country_name = False else: country_name = country_name_or_code country_code = False for row in ReadCountryData(): lat, lon = row['coords'].split(',') if country_code: if row['code'] == country_code: return row['code'], row['name'], lat, lon elif country_name: if re.match("^%s$" % country_name, row['name'], re.I): return row['code'], row['name'], lat, lon elif re.search('^%s \(' % country_name, row['name'], re.I): return row['code'], row['name'], lat, lon elif re.search('\(%s\)' % country_name, row['name'], re.I): return row['code'], row['name'], lat, lon elif re.match("^%s" % country_name, row['name'], re.I): match = (row['code'], row['name'], lat, lon) elif re.search(country_name, row['name'], re.I): partial_match = (row['code'], row['name'], lat, lon) if match: print "Could not find explicit entry for '%s', good match: %s" % (country_name_or_code, match) return match elif partial_match: print "Could not find explicit entry for '%s', partial match: %s" % (country_name_or_code, partial_match) return partial_match else: print "'%s' does not match any countries in our list." % country_name_or_code return (None, None, None, None)
[ "def", "GetInfoForCountry", "(", "country_name_or_code", ")", ":", "match", "=", "False", "partial_match", "=", "False", "if", "not", "country_name_or_code", ":", "return", "None", "if", "len", "(", "country_name_or_code", ")", "==", "2", ":", "country_code", "=...
https://github.com/catap/namebench/blob/9913a7a1a7955a3759eb18cbe73b421441a7a00f/libnamebench/geoip.py#L75-L114
golismero/golismero
7d605b937e241f51c1ca4f47b20f755eeefb9d76
thirdparty_libs/nltk/sem/drt.py
python
DrsDrawer._get_centered_top
(self, top, full_height, item_height)
return top + (full_height - item_height) / 2
Get the y-coordinate of the point that a figure should start at if its height is 'item_height' and it needs to be centered in an area that starts at 'top' and is 'full_height' tall.
Get the y-coordinate of the point that a figure should start at if its height is 'item_height' and it needs to be centered in an area that starts at 'top' and is 'full_height' tall.
[ "Get", "the", "y", "-", "coordinate", "of", "the", "point", "that", "a", "figure", "should", "start", "at", "if", "its", "height", "is", "item_height", "and", "it", "needs", "to", "be", "centered", "in", "an", "area", "that", "starts", "at", "top", "an...
def _get_centered_top(self, top, full_height, item_height): """Get the y-coordinate of the point that a figure should start at if its height is 'item_height' and it needs to be centered in an area that starts at 'top' and is 'full_height' tall.""" return top + (full_height - item_height) / 2
[ "def", "_get_centered_top", "(", "self", ",", "top", ",", "full_height", ",", "item_height", ")", ":", "return", "top", "+", "(", "full_height", "-", "item_height", ")", "/", "2" ]
https://github.com/golismero/golismero/blob/7d605b937e241f51c1ca4f47b20f755eeefb9d76/thirdparty_libs/nltk/sem/drt.py#L1038-L1042
triaquae/triaquae
bbabf736b3ba56a0c6498e7f04e16c13b8b8f2b9
TriAquae/models/django/contrib/admin/templatetags/log.py
python
get_admin_log
(parser, token)
return AdminLogNode(limit=tokens[1], varname=tokens[3], user=(len(tokens) > 5 and tokens[5] or None))
Populates a template variable with the admin log for the given criteria. Usage:: {% get_admin_log [limit] as [varname] for_user [context_var_containing_user_obj] %} Examples:: {% get_admin_log 10 as admin_log for_user 23 %} {% get_admin_log 10 as admin_log for_user user %} {% get_admin_log 10 as admin_log %} Note that ``context_var_containing_user_obj`` can be a hard-coded integer (user ID) or the name of a template context variable containing the user object whose ID you want.
Populates a template variable with the admin log for the given criteria.
[ "Populates", "a", "template", "variable", "with", "the", "admin", "log", "for", "the", "given", "criteria", "." ]
def get_admin_log(parser, token): """ Populates a template variable with the admin log for the given criteria. Usage:: {% get_admin_log [limit] as [varname] for_user [context_var_containing_user_obj] %} Examples:: {% get_admin_log 10 as admin_log for_user 23 %} {% get_admin_log 10 as admin_log for_user user %} {% get_admin_log 10 as admin_log %} Note that ``context_var_containing_user_obj`` can be a hard-coded integer (user ID) or the name of a template context variable containing the user object whose ID you want. """ tokens = token.contents.split() if len(tokens) < 4: raise template.TemplateSyntaxError( "'get_admin_log' statements require two arguments") if not tokens[1].isdigit(): raise template.TemplateSyntaxError( "First argument to 'get_admin_log' must be an integer") if tokens[2] != 'as': raise template.TemplateSyntaxError( "Second argument to 'get_admin_log' must be 'as'") if len(tokens) > 4: if tokens[4] != 'for_user': raise template.TemplateSyntaxError( "Fourth argument to 'get_admin_log' must be 'for_user'") return AdminLogNode(limit=tokens[1], varname=tokens[3], user=(len(tokens) > 5 and tokens[5] or None))
[ "def", "get_admin_log", "(", "parser", ",", "token", ")", ":", "tokens", "=", "token", ".", "contents", ".", "split", "(", ")", "if", "len", "(", "tokens", ")", "<", "4", ":", "raise", "template", ".", "TemplateSyntaxError", "(", "\"'get_admin_log' stateme...
https://github.com/triaquae/triaquae/blob/bbabf736b3ba56a0c6498e7f04e16c13b8b8f2b9/TriAquae/models/django/contrib/admin/templatetags/log.py#L24-L56
LeGoffLoic/Nodz
0ee255c62883f7a374a9de6cbcf555e3352e5dec
nodz_main.py
python
Nodz.mouseReleaseEvent
(self, event)
Apply tablet zoom, dragging and selection.
Apply tablet zoom, dragging and selection.
[ "Apply", "tablet", "zoom", "dragging", "and", "selection", "." ]
def mouseReleaseEvent(self, event): """ Apply tablet zoom, dragging and selection. """ # Zoom the View. if self.currentState == '.ZOOM_VIEW': self.offset = 0 self.zoomDirection = 0 self.zoomIncr = 0 self.setInteractive(True) # Drag View. elif self.currentState == 'DRAG_VIEW': self.setCursor(QtCore.Qt.ArrowCursor) self.setInteractive(True) # Selection. elif self.currentState == 'SELECTION': self.rubberband.setGeometry(QtCore.QRect(self.origin, event.pos()).normalized()) painterPath = self._releaseRubberband() self.setInteractive(True) self.scene().setSelectionArea(painterPath) # Add Selection. elif self.currentState == 'ADD_SELECTION': self.rubberband.setGeometry(QtCore.QRect(self.origin, event.pos()).normalized()) painterPath = self._releaseRubberband() self.setInteractive(True) for item in self.scene().items(painterPath): item.setSelected(True) # Subtract Selection. elif self.currentState == 'SUBTRACT_SELECTION': self.rubberband.setGeometry(QtCore.QRect(self.origin, event.pos()).normalized()) painterPath = self._releaseRubberband() self.setInteractive(True) for item in self.scene().items(painterPath): item.setSelected(False) # Toggle Selection elif self.currentState == 'TOGGLE_SELECTION': self.rubberband.setGeometry(QtCore.QRect(self.origin, event.pos()).normalized()) painterPath = self._releaseRubberband() self.setInteractive(True) for item in self.scene().items(painterPath): if item.isSelected(): item.setSelected(False) else: item.setSelected(True) self.currentState = 'DEFAULT' super(Nodz, self).mouseReleaseEvent(event)
[ "def", "mouseReleaseEvent", "(", "self", ",", "event", ")", ":", "# Zoom the View.", "if", "self", ".", "currentState", "==", "'.ZOOM_VIEW'", ":", "self", ".", "offset", "=", "0", "self", ".", "zoomDirection", "=", "0", "self", ".", "zoomIncr", "=", "0", ...
https://github.com/LeGoffLoic/Nodz/blob/0ee255c62883f7a374a9de6cbcf555e3352e5dec/nodz_main.py#L219-L281
odlgroup/odl
0b088df8dc4621c68b9414c3deff9127f4c4f11d
odl/space/npy_tensors.py
python
NumpyTensorSpace.is_weighted
(self)
return not ( isinstance(self.weighting, NumpyTensorSpaceConstWeighting) and self.weighting.const == 1.0)
Return ``True`` if the space is not weighted by constant 1.0.
Return ``True`` if the space is not weighted by constant 1.0.
[ "Return", "True", "if", "the", "space", "is", "not", "weighted", "by", "constant", "1", ".", "0", "." ]
def is_weighted(self): """Return ``True`` if the space is not weighted by constant 1.0.""" return not ( isinstance(self.weighting, NumpyTensorSpaceConstWeighting) and self.weighting.const == 1.0)
[ "def", "is_weighted", "(", "self", ")", ":", "return", "not", "(", "isinstance", "(", "self", ".", "weighting", ",", "NumpyTensorSpaceConstWeighting", ")", "and", "self", ".", "weighting", ".", "const", "==", "1.0", ")" ]
https://github.com/odlgroup/odl/blob/0b088df8dc4621c68b9414c3deff9127f4c4f11d/odl/space/npy_tensors.py#L308-L312
timkpaine/pyEX
254acd2b0cf7cb7183100106f4ecc11d1860c46a
pyEX/stats/stats.py
python
dailyDF
(*args, **kwargs)
return _toDatetime(pd.DataFrame(daily(*args, **kwargs)))
[]
def dailyDF(*args, **kwargs): return _toDatetime(pd.DataFrame(daily(*args, **kwargs)))
[ "def", "dailyDF", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "_toDatetime", "(", "pd", ".", "DataFrame", "(", "daily", "(", "*", "args", ",", "*", "*", "kwargs", ")", ")", ")" ]
https://github.com/timkpaine/pyEX/blob/254acd2b0cf7cb7183100106f4ecc11d1860c46a/pyEX/stats/stats.py#L174-L175
aws/sagemaker-containers
526dda90d636c7fb0c25791e6c57d077bd972000
src/sagemaker_containers/_env.py
python
TrainingEnv.input_config_dir
(self)
return self._input_config_dir
The directory where standard SageMaker configuration files are located, e.g. /opt/ml/input/config/. SageMaker training creates the following files in this folder when training starts: - `hyperparameters.json`: Amazon SageMaker makes the hyperparameters in a CreateTrainingJob request available in this file. - `inputdataconfig.json`: You specify data channel information in the InputDataConfig parameter in a CreateTrainingJob request. Amazon SageMaker makes this information available in this file. - `resourceconfig.json`: name of the current host and all host containers in the training More information about this files can be find here: https://docs.aws.amazon.com/sagemaker/latest/dg/your-algorithms-training-algo.html Returns: str: the path of the input directory, e.g. /opt/ml/input/config/
The directory where standard SageMaker configuration files are located, e.g. /opt/ml/input/config/. SageMaker training creates the following files in this folder when training starts: - `hyperparameters.json`: Amazon SageMaker makes the hyperparameters in a CreateTrainingJob request available in this file. - `inputdataconfig.json`: You specify data channel information in the InputDataConfig parameter in a CreateTrainingJob request. Amazon SageMaker makes this information available in this file. - `resourceconfig.json`: name of the current host and all host containers in the training More information about this files can be find here: https://docs.aws.amazon.com/sagemaker/latest/dg/your-algorithms-training-algo.html Returns: str: the path of the input directory, e.g. /opt/ml/input/config/
[ "The", "directory", "where", "standard", "SageMaker", "configuration", "files", "are", "located", "e", ".", "g", ".", "/", "opt", "/", "ml", "/", "input", "/", "config", "/", ".", "SageMaker", "training", "creates", "the", "following", "files", "in", "this...
def input_config_dir(self): # type: () -> str """The directory where standard SageMaker configuration files are located, e.g. /opt/ml/input/config/. SageMaker training creates the following files in this folder when training starts: - `hyperparameters.json`: Amazon SageMaker makes the hyperparameters in a CreateTrainingJob request available in this file. - `inputdataconfig.json`: You specify data channel information in the InputDataConfig parameter in a CreateTrainingJob request. Amazon SageMaker makes this information available in this file. - `resourceconfig.json`: name of the current host and all host containers in the training More information about this files can be find here: https://docs.aws.amazon.com/sagemaker/latest/dg/your-algorithms-training-algo.html Returns: str: the path of the input directory, e.g. /opt/ml/input/config/ """ return self._input_config_dir
[ "def", "input_config_dir", "(", "self", ")", ":", "# type: () -> str", "return", "self", ".", "_input_config_dir" ]
https://github.com/aws/sagemaker-containers/blob/526dda90d636c7fb0c25791e6c57d077bd972000/src/sagemaker_containers/_env.py#L751-L767
python-telegram-bot/python-telegram-bot
ade1529986f5b6d394a65372d6a27045a70725b2
examples/nestedconversationbot.py
python
show_data
(update: Update, context: CallbackContext)
return SHOWING
Pretty print gathered data.
Pretty print gathered data.
[ "Pretty", "print", "gathered", "data", "." ]
def show_data(update: Update, context: CallbackContext) -> str: """Pretty print gathered data.""" def prettyprint(user_data: Dict[str, Any], level: str) -> str: people = user_data.get(level) if not people: return '\nNo information yet.' text = '' if level == SELF: for person in user_data[level]: text += f"\nName: {person.get(NAME, '-')}, Age: {person.get(AGE, '-')}" else: male, female = _name_switcher(level) for person in user_data[level]: gender = female if person[GENDER] == FEMALE else male text += f"\n{gender}: Name: {person.get(NAME, '-')}, Age: {person.get(AGE, '-')}" return text user_data = context.user_data text = f"Yourself:{prettyprint(user_data, SELF)}" text += f"\n\nParents:{prettyprint(user_data, PARENTS)}" text += f"\n\nChildren:{prettyprint(user_data, CHILDREN)}" buttons = [[InlineKeyboardButton(text='Back', callback_data=str(END))]] keyboard = InlineKeyboardMarkup(buttons) update.callback_query.answer() update.callback_query.edit_message_text(text=text, reply_markup=keyboard) user_data[START_OVER] = True return SHOWING
[ "def", "show_data", "(", "update", ":", "Update", ",", "context", ":", "CallbackContext", ")", "->", "str", ":", "def", "prettyprint", "(", "user_data", ":", "Dict", "[", "str", ",", "Any", "]", ",", "level", ":", "str", ")", "->", "str", ":", "peopl...
https://github.com/python-telegram-bot/python-telegram-bot/blob/ade1529986f5b6d394a65372d6a27045a70725b2/examples/nestedconversationbot.py#L120-L152
replit-archive/empythoned
977ec10ced29a3541a4973dc2b59910805695752
dist/lib/python2.7/email/message.py
python
Message.get_param
(self, param, failobj=None, header='content-type', unquote=True)
return failobj
Return the parameter value if found in the Content-Type header. Optional failobj is the object to return if there is no Content-Type header, or the Content-Type header has no such parameter. Optional header is the header to search instead of Content-Type. Parameter keys are always compared case insensitively. The return value can either be a string, or a 3-tuple if the parameter was RFC 2231 encoded. When it's a 3-tuple, the elements of the value are of the form (CHARSET, LANGUAGE, VALUE). Note that both CHARSET and LANGUAGE can be None, in which case you should consider VALUE to be encoded in the us-ascii charset. You can usually ignore LANGUAGE. Your application should be prepared to deal with 3-tuple return values, and can convert the parameter to a Unicode string like so: param = msg.get_param('foo') if isinstance(param, tuple): param = unicode(param[2], param[0] or 'us-ascii') In any case, the parameter value (either the returned string, or the VALUE item in the 3-tuple) is always unquoted, unless unquote is set to False.
Return the parameter value if found in the Content-Type header.
[ "Return", "the", "parameter", "value", "if", "found", "in", "the", "Content", "-", "Type", "header", "." ]
def get_param(self, param, failobj=None, header='content-type', unquote=True): """Return the parameter value if found in the Content-Type header. Optional failobj is the object to return if there is no Content-Type header, or the Content-Type header has no such parameter. Optional header is the header to search instead of Content-Type. Parameter keys are always compared case insensitively. The return value can either be a string, or a 3-tuple if the parameter was RFC 2231 encoded. When it's a 3-tuple, the elements of the value are of the form (CHARSET, LANGUAGE, VALUE). Note that both CHARSET and LANGUAGE can be None, in which case you should consider VALUE to be encoded in the us-ascii charset. You can usually ignore LANGUAGE. Your application should be prepared to deal with 3-tuple return values, and can convert the parameter to a Unicode string like so: param = msg.get_param('foo') if isinstance(param, tuple): param = unicode(param[2], param[0] or 'us-ascii') In any case, the parameter value (either the returned string, or the VALUE item in the 3-tuple) is always unquoted, unless unquote is set to False. """ if header not in self: return failobj for k, v in self._get_params_preserve(failobj, header): if k.lower() == param.lower(): if unquote: return _unquotevalue(v) else: return v return failobj
[ "def", "get_param", "(", "self", ",", "param", ",", "failobj", "=", "None", ",", "header", "=", "'content-type'", ",", "unquote", "=", "True", ")", ":", "if", "header", "not", "in", "self", ":", "return", "failobj", "for", "k", ",", "v", "in", "self"...
https://github.com/replit-archive/empythoned/blob/977ec10ced29a3541a4973dc2b59910805695752/dist/lib/python2.7/email/message.py#L535-L569
makerbot/ReplicatorG
d6f2b07785a5a5f1e172fb87cb4303b17c575d5d
skein_engines/skeinforge-35/skeinforge_application/skeinforge_plugins/craft_plugins/temperature.py
python
TemperatureRepository.__init__
(self)
Set the default settings, execute title & settings fileName.
Set the default settings, execute title & settings fileName.
[ "Set", "the", "default", "settings", "execute", "title", "&", "settings", "fileName", "." ]
def __init__(self): "Set the default settings, execute title & settings fileName." skeinforge_profile.addListsToCraftTypeRepository('skeinforge_application.skeinforge_plugins.craft_plugins.temperature.html', self ) self.fileNameInput = settings.FileNameInput().getFromFileName( fabmetheus_interpret.getGNUTranslatorGcodeFileTypeTuples(), 'Open File for Temperature', self, '') self.activateTemperature = settings.BooleanSetting().getFromValue('Activate Temperature:', self, True ) settings.LabelSeparator().getFromRepository(self) settings.LabelDisplay().getFromName('- Rate -', self ) self.coolingRate = settings.FloatSpin().getFromValue( 1.0, 'Cooling Rate (Celcius/second):', self, 20.0, 3.0 ) self.heatingRate = settings.FloatSpin().getFromValue( 1.0, 'Heating Rate (Celcius/second):', self, 20.0, 10.0 ) settings.LabelSeparator().getFromRepository(self) settings.LabelDisplay().getFromName('- Temperature -', self ) self.baseTemperature = settings.FloatSpin().getFromValue( 140.0, 'Base Temperature (Celcius):', self, 260.0, 200.0 ) self.interfaceTemperature = settings.FloatSpin().getFromValue( 140.0, 'Interface Temperature (Celcius):', self, 260.0, 200.0 ) self.objectFirstLayerInfillTemperature = settings.FloatSpin().getFromValue( 140.0, 'Object First Layer Infill Temperature (Celcius):', self, 260.0, 195.0 ) self.objectFirstLayerPerimeterTemperature = settings.FloatSpin().getFromValue( 140.0, 'Object First Layer Perimeter Temperature (Celcius):', self, 260.0, 220.0 ) self.objectNextLayersTemperature = settings.FloatSpin().getFromValue( 140.0, 'Object Next Layers Temperature (Celcius):', self, 260.0, 230.0 ) self.supportLayersTemperature = settings.FloatSpin().getFromValue( 140.0, 'Support Layers Temperature (Celcius):', self, 260.0, 200.0 ) self.supportedLayersTemperature = settings.FloatSpin().getFromValue( 140.0, 'Supported Layers Temperature (Celcius):', self, 260.0, 230.0 ) self.executeTitle = 'Temperature'
[ "def", "__init__", "(", "self", ")", ":", "skeinforge_profile", ".", "addListsToCraftTypeRepository", "(", "'skeinforge_application.skeinforge_plugins.craft_plugins.temperature.html'", ",", "self", ")", "self", ".", "fileNameInput", "=", "settings", ".", "FileNameInput", "(...
https://github.com/makerbot/ReplicatorG/blob/d6f2b07785a5a5f1e172fb87cb4303b17c575d5d/skein_engines/skeinforge-35/skeinforge_application/skeinforge_plugins/craft_plugins/temperature.py#L142-L160
FriedAppleTeam/FRAPL
89c14d57e0cc77b915fe1e95f60e9e1847699103
Framework/FridaLink/FridaLink/Core/HookEngine.py
python
HookEngineProtocol.handleHookInstBreakOnce
(self, screenEA = None)
[]
def handleHookInstBreakOnce(self, screenEA = None): if screenEA is not None: address = screenEA else: address = ScreenEA() self.handleQuickInstHook(address, True, True)
[ "def", "handleHookInstBreakOnce", "(", "self", ",", "screenEA", "=", "None", ")", ":", "if", "screenEA", "is", "not", "None", ":", "address", "=", "screenEA", "else", ":", "address", "=", "ScreenEA", "(", ")", "self", ".", "handleQuickInstHook", "(", "addr...
https://github.com/FriedAppleTeam/FRAPL/blob/89c14d57e0cc77b915fe1e95f60e9e1847699103/Framework/FridaLink/FridaLink/Core/HookEngine.py#L175-L181
DataDog/integrations-core
934674b29d94b70ccc008f76ea172d0cdae05e1e
nginx_ingress_controller/datadog_checks/nginx_ingress_controller/config_models/defaults.py
python
instance_empty_default_hostname
(field, value)
return False
[]
def instance_empty_default_hostname(field, value): return False
[ "def", "instance_empty_default_hostname", "(", "field", ",", "value", ")", ":", "return", "False" ]
https://github.com/DataDog/integrations-core/blob/934674b29d94b70ccc008f76ea172d0cdae05e1e/nginx_ingress_controller/datadog_checks/nginx_ingress_controller/config_models/defaults.py#L73-L74
JiYou/openstack
8607dd488bde0905044b303eb6e52bdea6806923
chap19/monitor/monitor/monitor/openstack/common/setup.py
python
_get_revno
(git_dir)
return len(revlist.splitlines())
Return the number of commits since the most recent tag. We use git-describe to find this out, but if there are no tags then we fall back to counting commits since the beginning of time.
Return the number of commits since the most recent tag.
[ "Return", "the", "number", "of", "commits", "since", "the", "most", "recent", "tag", "." ]
def _get_revno(git_dir): """Return the number of commits since the most recent tag. We use git-describe to find this out, but if there are no tags then we fall back to counting commits since the beginning of time. """ describe = _run_shell_command( "git --git-dir=%s describe --always" % git_dir) if "-" in describe: return describe.rsplit("-", 2)[-2] # no tags found revlist = _run_shell_command( "git --git-dir=%s rev-list --abbrev-commit HEAD" % git_dir) return len(revlist.splitlines())
[ "def", "_get_revno", "(", "git_dir", ")", ":", "describe", "=", "_run_shell_command", "(", "\"git --git-dir=%s describe --always\"", "%", "git_dir", ")", "if", "\"-\"", "in", "describe", ":", "return", "describe", ".", "rsplit", "(", "\"-\"", ",", "2", ")", "[...
https://github.com/JiYou/openstack/blob/8607dd488bde0905044b303eb6e52bdea6806923/chap19/monitor/monitor/monitor/openstack/common/setup.py#L280-L295
4shadoww/hakkuframework
409a11fc3819d251f86faa3473439f8c19066a21
lib/scapy/arch/linux.py
python
VEthPair.up
(self)
set veth pair links up :raises subprocess.CalledProcessError if operation fails
set veth pair links up :raises subprocess.CalledProcessError if operation fails
[ "set", "veth", "pair", "links", "up", ":", "raises", "subprocess", ".", "CalledProcessError", "if", "operation", "fails" ]
def up(self): # type: () -> None """ set veth pair links up :raises subprocess.CalledProcessError if operation fails """ for idx in [0, 1]: subprocess.check_call(["ip", "link", "set", self.ifaces[idx], "up"])
[ "def", "up", "(", "self", ")", ":", "# type: () -> None", "for", "idx", "in", "[", "0", ",", "1", "]", ":", "subprocess", ".", "check_call", "(", "[", "\"ip\"", ",", "\"link\"", ",", "\"set\"", ",", "self", ".", "ifaces", "[", "idx", "]", ",", "\"u...
https://github.com/4shadoww/hakkuframework/blob/409a11fc3819d251f86faa3473439f8c19066a21/lib/scapy/arch/linux.py#L674-L681
nschloe/quadpy
c4c076d8ddfa968486a2443a95e2fb3780dcde0f
src/quadpy/t2/_albrecht_collatz.py
python
albrecht_collatz
()
return T2Scheme("Albrecht-Collatz", d, 3, source, tol=2.776e-16)
[]
def albrecht_collatz(): d = {"d3_aa": [[frac(1, 30), frac(9, 30)], [frac(1, 2), frac(1, 6)]]} return T2Scheme("Albrecht-Collatz", d, 3, source, tol=2.776e-16)
[ "def", "albrecht_collatz", "(", ")", ":", "d", "=", "{", "\"d3_aa\"", ":", "[", "[", "frac", "(", "1", ",", "30", ")", ",", "frac", "(", "9", ",", "30", ")", "]", ",", "[", "frac", "(", "1", ",", "2", ")", ",", "frac", "(", "1", ",", "6",...
https://github.com/nschloe/quadpy/blob/c4c076d8ddfa968486a2443a95e2fb3780dcde0f/src/quadpy/t2/_albrecht_collatz.py#L18-L20
PyCQA/astroid
a815443f62faae05249621a396dcf0afd884a619
astroid/nodes/node_classes.py
python
If.block_range
(self, lineno)
return self._elsed_block_range(lineno, self.orelse, self.body[0].fromlineno - 1)
Get a range from the given line number to where this node ends. :param lineno: The line number to start the range at. :type lineno: int :returns: The range of line numbers that this node belongs to, starting at the given line number. :rtype: tuple(int, int)
Get a range from the given line number to where this node ends.
[ "Get", "a", "range", "from", "the", "given", "line", "number", "to", "where", "this", "node", "ends", "." ]
def block_range(self, lineno): """Get a range from the given line number to where this node ends. :param lineno: The line number to start the range at. :type lineno: int :returns: The range of line numbers that this node belongs to, starting at the given line number. :rtype: tuple(int, int) """ if lineno == self.body[0].fromlineno: return lineno, lineno if lineno <= self.body[-1].tolineno: return lineno, self.body[-1].tolineno return self._elsed_block_range(lineno, self.orelse, self.body[0].fromlineno - 1)
[ "def", "block_range", "(", "self", ",", "lineno", ")", ":", "if", "lineno", "==", "self", ".", "body", "[", "0", "]", ".", "fromlineno", ":", "return", "lineno", ",", "lineno", "if", "lineno", "<=", "self", ".", "body", "[", "-", "1", "]", ".", "...
https://github.com/PyCQA/astroid/blob/a815443f62faae05249621a396dcf0afd884a619/astroid/nodes/node_classes.py#L3094-L3108
beeware/toga
090370a943bdeefcdbe035b1621fbc7caeebdf1a
src/cocoa/toga_cocoa/widgets/canvas.py
python
Canvas.set_on_resize
(self, handler)
No special handling required.
No special handling required.
[ "No", "special", "handling", "required", "." ]
def set_on_resize(self, handler): """No special handling required.""" pass
[ "def", "set_on_resize", "(", "self", ",", "handler", ")", ":", "pass" ]
https://github.com/beeware/toga/blob/090370a943bdeefcdbe035b1621fbc7caeebdf1a/src/cocoa/toga_cocoa/widgets/canvas.py#L271-L273
openshift/openshift-tools
1188778e728a6e4781acf728123e5b356380fe6f
openshift/installer/vendored/openshift-ansible-3.9.14-1/roles/openshift_facts/library/openshift_facts.py
python
set_url_facts_if_unset
(facts)
return facts
Set url facts if not already present in facts dict Args: facts (dict): existing facts Returns: dict: the facts dict updated with the generated url facts if they were not already present
Set url facts if not already present in facts dict
[ "Set", "url", "facts", "if", "not", "already", "present", "in", "facts", "dict" ]
def set_url_facts_if_unset(facts): """ Set url facts if not already present in facts dict Args: facts (dict): existing facts Returns: dict: the facts dict updated with the generated url facts if they were not already present """ if 'master' in facts: hostname = facts['common']['hostname'] cluster_hostname = facts['master'].get('cluster_hostname') cluster_public_hostname = facts['master'].get('cluster_public_hostname') public_hostname = facts['common']['public_hostname'] api_hostname = cluster_hostname if cluster_hostname else hostname api_public_hostname = cluster_public_hostname if cluster_public_hostname else public_hostname console_path = facts['master']['console_path'] etcd_hosts = facts['master']['etcd_hosts'] use_ssl = dict( api=facts['master']['api_use_ssl'], public_api=facts['master']['api_use_ssl'], loopback_api=facts['master']['api_use_ssl'], console=facts['master']['console_use_ssl'], public_console=facts['master']['console_use_ssl'], etcd=facts['master']['etcd_use_ssl'] ) ports = dict( api=facts['master']['api_port'], public_api=facts['master']['api_port'], loopback_api=facts['master']['api_port'], console=facts['master']['console_port'], public_console=facts['master']['console_port'], etcd=facts['master']['etcd_port'], ) etcd_urls = [] if etcd_hosts != '': facts['master']['etcd_port'] = ports['etcd'] for host in etcd_hosts: etcd_urls.append(format_url(use_ssl['etcd'], host, ports['etcd'])) else: etcd_urls = [format_url(use_ssl['etcd'], hostname, ports['etcd'])] facts['master'].setdefault('etcd_urls', etcd_urls) prefix_hosts = [('api', api_hostname), ('public_api', api_public_hostname), ('loopback_api', hostname)] for prefix, host in prefix_hosts: facts['master'].setdefault(prefix + '_url', format_url(use_ssl[prefix], host, ports[prefix])) r_lhn = "{0}:{1}".format(hostname, ports['api']).replace('.', '-') r_lhu = "system:openshift-master/{0}:{1}".format(api_hostname, ports['api']).replace('.', '-') facts['master'].setdefault('loopback_cluster_name', r_lhn) facts['master'].setdefault('loopback_context_name', "default/{0}/system:openshift-master".format(r_lhn)) facts['master'].setdefault('loopback_user', r_lhu) prefix_hosts = [('console', api_hostname), ('public_console', api_public_hostname)] for prefix, host in prefix_hosts: facts['master'].setdefault(prefix + '_url', format_url(use_ssl[prefix], host, ports[prefix], console_path)) return facts
[ "def", "set_url_facts_if_unset", "(", "facts", ")", ":", "if", "'master'", "in", "facts", ":", "hostname", "=", "facts", "[", "'common'", "]", "[", "'hostname'", "]", "cluster_hostname", "=", "facts", "[", "'master'", "]", ".", "get", "(", "'cluster_hostname...
https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/openshift/installer/vendored/openshift-ansible-3.9.14-1/roles/openshift_facts/library/openshift_facts.py#L406-L477
zapier/email-reply-parser
f67a872de3c7bebe3bd836afec60ab3f1201e8a6
email_reply_parser/__init__.py
python
EmailMessage.reply
(self)
return '\n'.join(reply)
Captures reply message within email
Captures reply message within email
[ "Captures", "reply", "message", "within", "email" ]
def reply(self): """ Captures reply message within email """ reply = [] for f in self.fragments: if not (f.hidden or f.quoted): reply.append(f.content) return '\n'.join(reply)
[ "def", "reply", "(", "self", ")", ":", "reply", "=", "[", "]", "for", "f", "in", "self", ".", "fragments", ":", "if", "not", "(", "f", ".", "hidden", "or", "f", ".", "quoted", ")", ":", "reply", ".", "append", "(", "f", ".", "content", ")", "...
https://github.com/zapier/email-reply-parser/blob/f67a872de3c7bebe3bd836afec60ab3f1201e8a6/email_reply_parser/__init__.py#L83-L90
Chia-Network/chia-blockchain
34d44c1324ae634a0896f7b02eaa2802af9526cd
chia/farmer/farmer_api.py
python
FarmerAPI.new_proof_of_space
( self, new_proof_of_space: harvester_protocol.NewProofOfSpace, peer: ws.WSChiaConnection )
This is a response from the harvester, for a NewChallenge. Here we check if the proof of space is sufficiently good, and if so, we ask for the whole proof.
This is a response from the harvester, for a NewChallenge. Here we check if the proof of space is sufficiently good, and if so, we ask for the whole proof.
[ "This", "is", "a", "response", "from", "the", "harvester", "for", "a", "NewChallenge", ".", "Here", "we", "check", "if", "the", "proof", "of", "space", "is", "sufficiently", "good", "and", "if", "so", "we", "ask", "for", "the", "whole", "proof", "." ]
async def new_proof_of_space( self, new_proof_of_space: harvester_protocol.NewProofOfSpace, peer: ws.WSChiaConnection ): """ This is a response from the harvester, for a NewChallenge. Here we check if the proof of space is sufficiently good, and if so, we ask for the whole proof. """ if new_proof_of_space.sp_hash not in self.farmer.number_of_responses: self.farmer.number_of_responses[new_proof_of_space.sp_hash] = 0 self.farmer.cache_add_time[new_proof_of_space.sp_hash] = uint64(int(time.time())) max_pos_per_sp = 5 if self.farmer.constants.NETWORK_TYPE != NetworkType.MAINNET: # This is meant to make testnets more stable, when difficulty is very low if self.farmer.number_of_responses[new_proof_of_space.sp_hash] > max_pos_per_sp: self.farmer.log.info( f"Surpassed {max_pos_per_sp} PoSpace for one SP, no longer submitting PoSpace for signage point " f"{new_proof_of_space.sp_hash}" ) return None if new_proof_of_space.sp_hash not in self.farmer.sps: self.farmer.log.warning( f"Received response for a signage point that we do not have {new_proof_of_space.sp_hash}" ) return None sps = self.farmer.sps[new_proof_of_space.sp_hash] for sp in sps: computed_quality_string = new_proof_of_space.proof.verify_and_get_quality_string( self.farmer.constants, new_proof_of_space.challenge_hash, new_proof_of_space.sp_hash, ) if computed_quality_string is None: self.farmer.log.error(f"Invalid proof of space {new_proof_of_space.proof}") return None self.farmer.number_of_responses[new_proof_of_space.sp_hash] += 1 required_iters: uint64 = calculate_iterations_quality( self.farmer.constants.DIFFICULTY_CONSTANT_FACTOR, computed_quality_string, new_proof_of_space.proof.size, sp.difficulty, new_proof_of_space.sp_hash, ) # If the iters are good enough to make a block, proceed with the block making flow if required_iters < calculate_sp_interval_iters(self.farmer.constants, sp.sub_slot_iters): # Proceed at getting the signatures for this PoSpace request = harvester_protocol.RequestSignatures( new_proof_of_space.plot_identifier, new_proof_of_space.challenge_hash, new_proof_of_space.sp_hash, [sp.challenge_chain_sp, sp.reward_chain_sp], ) if new_proof_of_space.sp_hash not in self.farmer.proofs_of_space: self.farmer.proofs_of_space[new_proof_of_space.sp_hash] = [] self.farmer.proofs_of_space[new_proof_of_space.sp_hash].append( ( new_proof_of_space.plot_identifier, new_proof_of_space.proof, ) ) self.farmer.cache_add_time[new_proof_of_space.sp_hash] = uint64(int(time.time())) self.farmer.quality_str_to_identifiers[computed_quality_string] = ( new_proof_of_space.plot_identifier, new_proof_of_space.challenge_hash, new_proof_of_space.sp_hash, peer.peer_node_id, ) self.farmer.cache_add_time[computed_quality_string] = uint64(int(time.time())) await peer.send_message(make_msg(ProtocolMessageTypes.request_signatures, request)) p2_singleton_puzzle_hash = new_proof_of_space.proof.pool_contract_puzzle_hash if p2_singleton_puzzle_hash is not None: # Otherwise, send the proof of space to the pool # When we win a block, we also send the partial to the pool if p2_singleton_puzzle_hash not in self.farmer.pool_state: self.farmer.log.info(f"Did not find pool info for {p2_singleton_puzzle_hash}") return pool_state_dict: Dict = self.farmer.pool_state[p2_singleton_puzzle_hash] pool_url = pool_state_dict["pool_config"].pool_url if pool_url == "": return if pool_state_dict["current_difficulty"] is None: self.farmer.log.warning( f"No pool specific difficulty has been set for {p2_singleton_puzzle_hash}, " f"check communication with the pool, skipping this partial to {pool_url}." ) return required_iters = calculate_iterations_quality( self.farmer.constants.DIFFICULTY_CONSTANT_FACTOR, computed_quality_string, new_proof_of_space.proof.size, pool_state_dict["current_difficulty"], new_proof_of_space.sp_hash, ) if required_iters >= calculate_sp_interval_iters( self.farmer.constants, self.farmer.constants.POOL_SUB_SLOT_ITERS ): self.farmer.log.info( f"Proof of space not good enough for pool {pool_url}: {pool_state_dict['current_difficulty']}" ) return authentication_token_timeout = pool_state_dict["authentication_token_timeout"] if authentication_token_timeout is None: self.farmer.log.warning( f"No pool specific authentication_token_timeout has been set for {p2_singleton_puzzle_hash}" f", check communication with the pool." ) return # Submit partial to pool is_eos = new_proof_of_space.signage_point_index == 0 payload = PostPartialPayload( pool_state_dict["pool_config"].launcher_id, get_current_authentication_token(authentication_token_timeout), new_proof_of_space.proof, new_proof_of_space.sp_hash, is_eos, peer.peer_node_id, ) # The plot key is 2/2 so we need the harvester's half of the signature m_to_sign = payload.get_hash() request = harvester_protocol.RequestSignatures( new_proof_of_space.plot_identifier, new_proof_of_space.challenge_hash, new_proof_of_space.sp_hash, [m_to_sign], ) response: Any = await peer.request_signatures(request) if not isinstance(response, harvester_protocol.RespondSignatures): self.farmer.log.error(f"Invalid response from harvester: {response}") return assert len(response.message_signatures) == 1 plot_signature: Optional[G2Element] = None for sk in self.farmer.get_private_keys(): pk = sk.get_g1() if pk == response.farmer_pk: agg_pk = ProofOfSpace.generate_plot_public_key(response.local_pk, pk, True) assert agg_pk == new_proof_of_space.proof.plot_public_key sig_farmer = AugSchemeMPL.sign(sk, m_to_sign, agg_pk) taproot_sk: PrivateKey = ProofOfSpace.generate_taproot_sk(response.local_pk, pk) taproot_sig: G2Element = AugSchemeMPL.sign(taproot_sk, m_to_sign, agg_pk) plot_signature = AugSchemeMPL.aggregate( [sig_farmer, response.message_signatures[0][1], taproot_sig] ) assert AugSchemeMPL.verify(agg_pk, m_to_sign, plot_signature) authentication_pk = pool_state_dict["pool_config"].authentication_public_key if bytes(authentication_pk) is None: self.farmer.log.error(f"No authentication sk for {authentication_pk}") return authentication_sk: PrivateKey = self.farmer.authentication_keys[bytes(authentication_pk)] authentication_signature = AugSchemeMPL.sign(authentication_sk, m_to_sign) assert plot_signature is not None agg_sig: G2Element = AugSchemeMPL.aggregate([plot_signature, authentication_signature]) post_partial_request: PostPartialRequest = PostPartialRequest(payload, agg_sig) self.farmer.log.info( f"Submitting partial for {post_partial_request.payload.launcher_id.hex()} to {pool_url}" ) pool_state_dict["points_found_since_start"] += pool_state_dict["current_difficulty"] pool_state_dict["points_found_24h"].append((time.time(), pool_state_dict["current_difficulty"])) try: async with aiohttp.ClientSession() as session: async with session.post( f"{pool_url}/partial", json=post_partial_request.to_json_dict(), ssl=ssl_context_for_root(get_mozilla_ca_crt(), log=self.farmer.log), headers={"User-Agent": f"Chia Blockchain v.{__version__}"}, ) as resp: if resp.ok: pool_response: Dict = json.loads(await resp.text()) self.farmer.log.info(f"Pool response: {pool_response}") if "error_code" in pool_response: self.farmer.log.error( f"Error in pooling: " f"{pool_response['error_code'], pool_response['error_message']}" ) pool_state_dict["pool_errors_24h"].append(pool_response) if pool_response["error_code"] == PoolErrorCode.PROOF_NOT_GOOD_ENOUGH.value: self.farmer.log.error( "Partial not good enough, forcing pool farmer update to " "get our current difficulty." ) pool_state_dict["next_farmer_update"] = 0 await self.farmer.update_pool_state() else: new_difficulty = pool_response["new_difficulty"] pool_state_dict["points_acknowledged_since_start"] += new_difficulty pool_state_dict["points_acknowledged_24h"].append((time.time(), new_difficulty)) pool_state_dict["current_difficulty"] = new_difficulty else: self.farmer.log.error(f"Error sending partial to {pool_url}, {resp.status}") except Exception as e: self.farmer.log.error(f"Error connecting to pool: {e}") return return
[ "async", "def", "new_proof_of_space", "(", "self", ",", "new_proof_of_space", ":", "harvester_protocol", ".", "NewProofOfSpace", ",", "peer", ":", "ws", ".", "WSChiaConnection", ")", ":", "if", "new_proof_of_space", ".", "sp_hash", "not", "in", "self", ".", "far...
https://github.com/Chia-Network/chia-blockchain/blob/34d44c1324ae634a0896f7b02eaa2802af9526cd/chia/farmer/farmer_api.py#L52-L266
linxid/Machine_Learning_Study_Path
558e82d13237114bbb8152483977806fc0c222af
Machine Learning In Action/Chapter8-Regression/venv/Lib/site-packages/pip-9.0.1-py3.6.egg/pip/_vendor/html5lib/treebuilders/base.py
python
TreeBuilder.generateImpliedEndTags
(self, exclude=None)
[]
def generateImpliedEndTags(self, exclude=None): name = self.openElements[-1].name # XXX td, th and tr are not actually needed if (name in frozenset(("dd", "dt", "li", "option", "optgroup", "p", "rp", "rt")) and name != exclude): self.openElements.pop() # XXX This is not entirely what the specification says. We should # investigate it more closely. self.generateImpliedEndTags(exclude)
[ "def", "generateImpliedEndTags", "(", "self", ",", "exclude", "=", "None", ")", ":", "name", "=", "self", ".", "openElements", "[", "-", "1", "]", ".", "name", "# XXX td, th and tr are not actually needed", "if", "(", "name", "in", "frozenset", "(", "(", "\"...
https://github.com/linxid/Machine_Learning_Study_Path/blob/558e82d13237114bbb8152483977806fc0c222af/Machine Learning In Action/Chapter8-Regression/venv/Lib/site-packages/pip-9.0.1-py3.6.egg/pip/_vendor/html5lib/treebuilders/base.py#L359-L367
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/helpers/entity.py
python
Entity.icon
(self)
return None
Return the icon to use in the frontend, if any.
Return the icon to use in the frontend, if any.
[ "Return", "the", "icon", "to", "use", "in", "the", "frontend", "if", "any", "." ]
def icon(self) -> str | None: """Return the icon to use in the frontend, if any.""" if hasattr(self, "_attr_icon"): return self._attr_icon if hasattr(self, "entity_description"): return self.entity_description.icon return None
[ "def", "icon", "(", "self", ")", "->", "str", "|", "None", ":", "if", "hasattr", "(", "self", ",", "\"_attr_icon\"", ")", ":", "return", "self", ".", "_attr_icon", "if", "hasattr", "(", "self", ",", "\"entity_description\"", ")", ":", "return", "self", ...
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/helpers/entity.py#L382-L388
IntelPython/sdc
1ebf55c00ef38dfbd401a70b3945e352a5a38b87
examples/series/series_groupby.py
python
series_groupby
()
return S.groupby(by).mean()
[]
def series_groupby(): S = pd.Series([390., 350., 30., 20.]) by = np.asarray([0, 1, 0, 1]) # Expect Series of pd.Series([210.0, 185.0], index=[0, 1]) return S.groupby(by).mean()
[ "def", "series_groupby", "(", ")", ":", "S", "=", "pd", ".", "Series", "(", "[", "390.", ",", "350.", ",", "30.", ",", "20.", "]", ")", "by", "=", "np", ".", "asarray", "(", "[", "0", ",", "1", ",", "0", ",", "1", "]", ")", "# Expect Series o...
https://github.com/IntelPython/sdc/blob/1ebf55c00ef38dfbd401a70b3945e352a5a38b87/examples/series/series_groupby.py#L39-L44
robhagemans/pcbasic
c3a043b46af66623a801e18a38175be077251ada
pcbasic/basic/converter/lister.py
python
Lister.token_to_line_number
(self, trail)
return struct.unpack_from('<H', trail, 2)[0]
Unpack a line number token trail, -1 if end of program.
Unpack a line number token trail, -1 if end of program.
[ "Unpack", "a", "line", "number", "token", "trail", "-", "1", "if", "end", "of", "program", "." ]
def token_to_line_number(self, trail): """Unpack a line number token trail, -1 if end of program.""" if len(trail) < 4 or trail[:2] == b'\0\0': return -1 return struct.unpack_from('<H', trail, 2)[0]
[ "def", "token_to_line_number", "(", "self", ",", "trail", ")", ":", "if", "len", "(", "trail", ")", "<", "4", "or", "trail", "[", ":", "2", "]", "==", "b'\\0\\0'", ":", "return", "-", "1", "return", "struct", ".", "unpack_from", "(", "'<H'", ",", "...
https://github.com/robhagemans/pcbasic/blob/c3a043b46af66623a801e18a38175be077251ada/pcbasic/basic/converter/lister.py#L53-L57
google/capirca
679e3885e3a5e5e129dc2dfab204ec44d63b26a4
capirca/lib/aclgenerator.py
python
ACLGenerator._GetSupportedTokens
(self)
return supported_tokens, supported_sub_tokens
Build our supported tokens and sub tokens. Returns: tuple containing the supported tokens and sub tokens. Raises: UnsupportedFilterError: Raised when token is not supported.
Build our supported tokens and sub tokens.
[ "Build", "our", "supported", "tokens", "and", "sub", "tokens", "." ]
def _GetSupportedTokens(self): """Build our supported tokens and sub tokens. Returns: tuple containing the supported tokens and sub tokens. Raises: UnsupportedFilterError: Raised when token is not supported. """ supported_tokens, supported_sub_tokens = self._BuildTokens() # make sure we don't have subtokens that are not listed. This should not # occur unless a platform's tokens/subtokens are changed. undefined_st = set(supported_sub_tokens) - supported_tokens if undefined_st: raise UnsupportedFilterError( 'Found undefined sub tokens missing from the supported token list! ' 'These must match. (%s)' % ' '.join(undefined_st)) # all good. return supported_tokens, supported_sub_tokens
[ "def", "_GetSupportedTokens", "(", "self", ")", ":", "supported_tokens", ",", "supported_sub_tokens", "=", "self", ".", "_BuildTokens", "(", ")", "# make sure we don't have subtokens that are not listed. This should not", "# occur unless a platform's tokens/subtokens are changed.", ...
https://github.com/google/capirca/blob/679e3885e3a5e5e129dc2dfab204ec44d63b26a4/capirca/lib/aclgenerator.py#L382-L399
huggingface/transformers
623b4f7c63f60cce917677ee704d6c93ee960b4b
src/transformers/models/blenderbot/modeling_blenderbot.py
python
BlenderbotPreTrainedModel._set_gradient_checkpointing
(self, module, value=False)
[]
def _set_gradient_checkpointing(self, module, value=False): if isinstance(module, (BlenderbotDecoder, BlenderbotEncoder)): module.gradient_checkpointing = value
[ "def", "_set_gradient_checkpointing", "(", "self", ",", "module", ",", "value", "=", "False", ")", ":", "if", "isinstance", "(", "module", ",", "(", "BlenderbotDecoder", ",", "BlenderbotEncoder", ")", ")", ":", "module", ".", "gradient_checkpointing", "=", "va...
https://github.com/huggingface/transformers/blob/623b4f7c63f60cce917677ee704d6c93ee960b4b/src/transformers/models/blenderbot/modeling_blenderbot.py#L476-L478
minerllabs/minerl
0123527c334c96ebb3f0cf313df1552fa4302691
minerl/herobraine/hero/handlers/translation.py
python
KeymapTranslationHandler.to_hero
(self, x)
What does it mean to do a keymap translation here? Since hero sends things as commands perhaps we could generalize this beyond observations.
What does it mean to do a keymap translation here? Since hero sends things as commands perhaps we could generalize this beyond observations.
[ "What", "does", "it", "mean", "to", "do", "a", "keymap", "translation", "here?", "Since", "hero", "sends", "things", "as", "commands", "perhaps", "we", "could", "generalize", "this", "beyond", "observations", "." ]
def to_hero(self, x) -> str: """What does it mean to do a keymap translation here? Since hero sends things as commands perhaps we could generalize this beyond observations. """ raise NotImplementedError()
[ "def", "to_hero", "(", "self", ",", "x", ")", "->", "str", ":", "raise", "NotImplementedError", "(", ")" ]
https://github.com/minerllabs/minerl/blob/0123527c334c96ebb3f0cf313df1552fa4302691/minerl/herobraine/hero/handlers/translation.py#L92-L97
pventuzelo/octopus
e8b8c5a9d5f6d9c63605afe9ef1528ab481ec983
octopus/engine/disassembler.py
python
Disassembler.disassemble
(self, bytecode=None, offset=0, r_format='list')
Generic method to disassemble bytecode :param bytecode: bytecode sequence :param offset: start offset :param r_format: output format ('list'/'text'/'reverse') :type bytecode: bytes, str :type offset: int :type r_format: list, str, dict :return: dissassembly result depending of r_format :rtype: list, str, dict
Generic method to disassemble bytecode
[ "Generic", "method", "to", "disassemble", "bytecode" ]
def disassemble(self, bytecode=None, offset=0, r_format='list'): """Generic method to disassemble bytecode :param bytecode: bytecode sequence :param offset: start offset :param r_format: output format ('list'/'text'/'reverse') :type bytecode: bytes, str :type offset: int :type r_format: list, str, dict :return: dissassembly result depending of r_format :rtype: list, str, dict """ # reinitialize class variable self.attributes_reset() self.bytecode = bytecode if bytecode else self.bytecode if not self.bytecode: raise BytecodeEmptyException() self.bytecode = bytecode_to_bytes(self.bytecode) while offset < len(self.bytecode): instr = self.disassemble_opcode(self.bytecode[offset:], offset) offset += instr.size self.instructions.append(instr) # fill reverse instructions self.reverse_instructions = {k: v for k, v in enumerate(self.instructions)} # return instructions if r_format == 'list': return self.instructions elif r_format == 'text': return '\n'.join(map(str, self.instructions)) elif r_format == 'reverse': return self.reverse_instructions
[ "def", "disassemble", "(", "self", ",", "bytecode", "=", "None", ",", "offset", "=", "0", ",", "r_format", "=", "'list'", ")", ":", "# reinitialize class variable", "self", ".", "attributes_reset", "(", ")", "self", ".", "bytecode", "=", "bytecode", "if", ...
https://github.com/pventuzelo/octopus/blob/e8b8c5a9d5f6d9c63605afe9ef1528ab481ec983/octopus/engine/disassembler.py#L27-L63
GoogleCloudPlatform/PerfKitBenchmarker
6e3412d7d5e414b8ca30ed5eaf970cef1d919a67
perfkitbenchmarker/benchmark_spec.py
python
BenchmarkSpec.ConstructNfsService
(self)
Construct the NFS service object. Creates an NFS Service only if an NFS disk is found in the disk_specs.
Construct the NFS service object.
[ "Construct", "the", "NFS", "service", "object", "." ]
def ConstructNfsService(self): """Construct the NFS service object. Creates an NFS Service only if an NFS disk is found in the disk_specs. """ if self.nfs_service: logging.info('NFS service already created: %s', self.nfs_service) return for group_spec in self.vms_to_boot.values(): if not group_spec.disk_spec or not group_spec.vm_count: continue disk_spec = group_spec.disk_spec if disk_spec.disk_type != disk.NFS: continue # Choose which nfs_service to create. if disk_spec.nfs_ip_address: self.nfs_service = nfs_service.StaticNfsService(disk_spec) elif disk_spec.nfs_managed: cloud = group_spec.cloud providers.LoadProvider(cloud) nfs_class = nfs_service.GetNfsServiceClass(cloud) self.nfs_service = nfs_class(disk_spec, group_spec.vm_spec.zone) else: self.nfs_service = nfs_service.UnmanagedNfsService(disk_spec, self.vms[0]) logging.debug('NFS service %s', self.nfs_service) break
[ "def", "ConstructNfsService", "(", "self", ")", ":", "if", "self", ".", "nfs_service", ":", "logging", ".", "info", "(", "'NFS service already created: %s'", ",", "self", ".", "nfs_service", ")", "return", "for", "group_spec", "in", "self", ".", "vms_to_boot", ...
https://github.com/GoogleCloudPlatform/PerfKitBenchmarker/blob/6e3412d7d5e414b8ca30ed5eaf970cef1d919a67/perfkitbenchmarker/benchmark_spec.py#L371-L397
Pyomo/pyomo
dbd4faee151084f343b893cc2b0c04cf2b76fd92
pyomo/contrib/pynumero/sparse/block_matrix.py
python
BlockMatrix.copy_structure
(self)
return result
Makes a copy of the structure of this BlockMatrix. This proivides a light-weighted copy of each block in this BlockMatrix. The blocks in the resulting matrix have the same shape as in the original matrices but not the same number of nonzeros. Returns ------- BlockMatrix
Makes a copy of the structure of this BlockMatrix. This proivides a light-weighted copy of each block in this BlockMatrix. The blocks in the resulting matrix have the same shape as in the original matrices but not the same number of nonzeros.
[ "Makes", "a", "copy", "of", "the", "structure", "of", "this", "BlockMatrix", ".", "This", "proivides", "a", "light", "-", "weighted", "copy", "of", "each", "block", "in", "this", "BlockMatrix", ".", "The", "blocks", "in", "the", "resulting", "matrix", "hav...
def copy_structure(self): """ Makes a copy of the structure of this BlockMatrix. This proivides a light-weighted copy of each block in this BlockMatrix. The blocks in the resulting matrix have the same shape as in the original matrices but not the same number of nonzeros. Returns ------- BlockMatrix """ m, n = self.bshape result = BlockMatrix(m, n) for row in range(m): if self.is_row_size_defined(row): result.set_row_size(row, self.get_row_size(row)) for col in range(n): if self.is_col_size_defined(col): result.set_col_size(col, self.get_col_size(col)) ii, jj = np.nonzero(self._block_mask) for i, j in zip(ii, jj): if isinstance(self._blocks[i, j], BlockMatrix): result.set_block(i, j, self._blocks[i, j].copy_structure()) else: nrows, ncols = self._blocks[i, j].shape result.set_block(i, j, coo_matrix((nrows, ncols))) return result
[ "def", "copy_structure", "(", "self", ")", ":", "m", ",", "n", "=", "self", ".", "bshape", "result", "=", "BlockMatrix", "(", "m", ",", "n", ")", "for", "row", "in", "range", "(", "m", ")", ":", "if", "self", ".", "is_row_size_defined", "(", "row",...
https://github.com/Pyomo/pyomo/blob/dbd4faee151084f343b893cc2b0c04cf2b76fd92/pyomo/contrib/pynumero/sparse/block_matrix.py#L734-L761
wxWidgets/Phoenix
b2199e299a6ca6d866aa6f3d0888499136ead9d6
wx/lib/ogl/basic.py
python
Shape.HitTest
(self, x, y)
return False
Given a point on a canvas, returns `True` if the point was on the shape, and returns the nearest attachment point and distance from the given point and target. :param `x`: the x position :param `y`: the y position
Given a point on a canvas, returns `True` if the point was on the shape, and returns the nearest attachment point and distance from the given point and target.
[ "Given", "a", "point", "on", "a", "canvas", "returns", "True", "if", "the", "point", "was", "on", "the", "shape", "and", "returns", "the", "nearest", "attachment", "point", "and", "distance", "from", "the", "given", "point", "and", "target", "." ]
def HitTest(self, x, y): """ Given a point on a canvas, returns `True` if the point was on the shape, and returns the nearest attachment point and distance from the given point and target. :param `x`: the x position :param `y`: the y position """ width, height = self.GetBoundingBoxMax() if abs(width) < 4: width = 4.0 if abs(height) < 4: height = 4.0 width += 4 # Allowance for inaccurate mousing height += 4 left = self._xpos - width / 2.0 top = self._ypos - height / 2.0 right = self._xpos + width / 2.0 bottom = self._ypos + height / 2.0 nearest_attachment = 0 # If within the bounding box, check the attachment points # within the object. if x >= left and x <= right and y >= top and y <= bottom: n = self.GetNumberOfAttachments() nearest = 999999 # GetAttachmentPosition[Edge] takes a logical attachment position, # i.e. if it's rotated through 90%, position 0 is East-facing. for i in range(n): e = self.GetAttachmentPositionEdge(i) if e: xp, yp = e l = math.sqrt(((xp - x) * (xp - x)) + (yp - y) * (yp - y)) if l < nearest: nearest = l nearest_attachment = i return nearest_attachment, nearest return False
[ "def", "HitTest", "(", "self", ",", "x", ",", "y", ")", ":", "width", ",", "height", "=", "self", ".", "GetBoundingBoxMax", "(", ")", "if", "abs", "(", "width", ")", "<", "4", ":", "width", "=", "4.0", "if", "abs", "(", "height", ")", "<", "4",...
https://github.com/wxWidgets/Phoenix/blob/b2199e299a6ca6d866aa6f3d0888499136ead9d6/wx/lib/ogl/basic.py#L624-L669
cloudera/hue
23f02102d4547c17c32bd5ea0eb24e9eadd657a4
desktop/core/ext-py/boto-2.46.1/boto/opsworks/layer1.py
python
OpsWorksConnection.stop_stack
(self, stack_id)
return self.make_request(action='StopStack', body=json.dumps(params))
Stops a specified stack. **Required Permissions**: To use this action, an IAM user must have a Manage permissions level for the stack, or an attached policy that explicitly grants permissions. For more information on user permissions, see `Managing User Permissions`_. :type stack_id: string :param stack_id: The stack ID.
Stops a specified stack.
[ "Stops", "a", "specified", "stack", "." ]
def stop_stack(self, stack_id): """ Stops a specified stack. **Required Permissions**: To use this action, an IAM user must have a Manage permissions level for the stack, or an attached policy that explicitly grants permissions. For more information on user permissions, see `Managing User Permissions`_. :type stack_id: string :param stack_id: The stack ID. """ params = {'StackId': stack_id, } return self.make_request(action='StopStack', body=json.dumps(params))
[ "def", "stop_stack", "(", "self", ",", "stack_id", ")", ":", "params", "=", "{", "'StackId'", ":", "stack_id", ",", "}", "return", "self", ".", "make_request", "(", "action", "=", "'StopStack'", ",", "body", "=", "json", ".", "dumps", "(", "params", ")...
https://github.com/cloudera/hue/blob/23f02102d4547c17c32bd5ea0eb24e9eadd657a4/desktop/core/ext-py/boto-2.46.1/boto/opsworks/layer1.py#L2356-L2372
feliam/pysymemu
ad02e52122099d537372eb4d11fd5024b8a3857f
cpu.py
python
Cpu.DEC
(cpu, dest)
Decrements by 1. Subtracts 1 from the destination operand, while preserving the state of the CF flag. The destination operand can be a register or a memory location. This instruction allows a loop counter to be updated without disturbing the CF flag. (To perform a decrement operation that updates the CF flag, use a SUB instruction with an immediate operand of 1.) The instruction's 64-bit mode default operation size is 32 bits. The OF, SF, ZF, AF, and PF flags are set according to the result:: DEST = DEST - 1; @param cpu: current CPU. @param dest: destination operand.
Decrements by 1. Subtracts 1 from the destination operand, while preserving the state of the CF flag. The destination operand can be a register or a memory location. This instruction allows a loop counter to be updated without disturbing the CF flag. (To perform a decrement operation that updates the CF flag, use a SUB instruction with an immediate operand of 1.) The instruction's 64-bit mode default operation size is 32 bits.
[ "Decrements", "by", "1", ".", "Subtracts", "1", "from", "the", "destination", "operand", "while", "preserving", "the", "state", "of", "the", "CF", "flag", ".", "The", "destination", "operand", "can", "be", "a", "register", "or", "a", "memory", "location", ...
def DEC(cpu, dest): ''' Decrements by 1. Subtracts 1 from the destination operand, while preserving the state of the CF flag. The destination operand can be a register or a memory location. This instruction allows a loop counter to be updated without disturbing the CF flag. (To perform a decrement operation that updates the CF flag, use a SUB instruction with an immediate operand of 1.) The instruction's 64-bit mode default operation size is 32 bits. The OF, SF, ZF, AF, and PF flags are set according to the result:: DEST = DEST - 1; @param cpu: current CPU. @param dest: destination operand. ''' arg0 = dest.read() res = dest.write(arg0-1) #Affected Flags o..szapc cpu.calculateFlags('DEC', dest.size, res)
[ "def", "DEC", "(", "cpu", ",", "dest", ")", ":", "arg0", "=", "dest", ".", "read", "(", ")", "res", "=", "dest", ".", "write", "(", "arg0", "-", "1", ")", "#Affected Flags o..szapc", "cpu", ".", "calculateFlags", "(", "'DEC'", ",", "dest", ".", "si...
https://github.com/feliam/pysymemu/blob/ad02e52122099d537372eb4d11fd5024b8a3857f/cpu.py#L1687-L1707
interpretml/interpret-text
d74efc985270aaa2b3ab779408597d9505e9ea1d
python/interpret_text/experimental/introspective_rationale/explainer.py
python
IntrospectiveRationaleExplainer.train
(self, *args, **kwargs)
return self.fit(*args, **kwargs)
Optionally pretrain the generator's introspective classifier, then train the explainer's model on the training data, with testing at the end of every epoch.
Optionally pretrain the generator's introspective classifier, then train the explainer's model on the training data, with testing at the end of every epoch.
[ "Optionally", "pretrain", "the", "generator", "s", "introspective", "classifier", "then", "train", "the", "explainer", "s", "model", "on", "the", "training", "data", "with", "testing", "at", "the", "end", "of", "every", "epoch", "." ]
def train(self, *args, **kwargs): """ Optionally pretrain the generator's introspective classifier, then train the explainer's model on the training data, with testing at the end of every epoch. """ return self.fit(*args, **kwargs)
[ "def", "train", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "fit", "(", "*", "args", ",", "*", "*", "kwargs", ")" ]
https://github.com/interpretml/interpret-text/blob/d74efc985270aaa2b3ab779408597d9505e9ea1d/python/interpret_text/experimental/introspective_rationale/explainer.py#L282-L287
JacquesLucke/animation_nodes
b1e3ace8dcb0a771fd882fc3ac4e490b009fa0d1
animation_nodes/node_link_conversion.py
python
ConvertNormalToEuler.insert
(self, nodeTree, origin, target, dataOrigin)
[]
def insert(self, nodeTree, origin, target, dataOrigin): insertLinkedNode(nodeTree, "an_DirectionToRotationNode", origin, target)
[ "def", "insert", "(", "self", ",", "nodeTree", ",", "origin", ",", "target", ",", "dataOrigin", ")", ":", "insertLinkedNode", "(", "nodeTree", ",", "\"an_DirectionToRotationNode\"", ",", "origin", ",", "target", ")" ]
https://github.com/JacquesLucke/animation_nodes/blob/b1e3ace8dcb0a771fd882fc3ac4e490b009fa0d1/animation_nodes/node_link_conversion.py#L116-L117
holzschu/Carnets
44effb10ddfc6aa5c8b0687582a724ba82c6b547
Library/lib/python3.7/site-packages/tornado-6.0.1-py3.7-macosx-12.1-iPad6,7.egg/tornado/web.py
python
RequestHandler.xsrf_form_html
(self)
return ( '<input type="hidden" name="_xsrf" value="' + escape.xhtml_escape(self.xsrf_token) + '"/>' )
An HTML ``<input/>`` element to be included with all POST forms. It defines the ``_xsrf`` input value, which we check on all POST requests to prevent cross-site request forgery. If you have set the ``xsrf_cookies`` application setting, you must include this HTML within all of your HTML forms. In a template, this method should be called with ``{% module xsrf_form_html() %}`` See `check_xsrf_cookie()` above for more information.
An HTML ``<input/>`` element to be included with all POST forms.
[ "An", "HTML", "<input", "/", ">", "element", "to", "be", "included", "with", "all", "POST", "forms", "." ]
def xsrf_form_html(self) -> str: """An HTML ``<input/>`` element to be included with all POST forms. It defines the ``_xsrf`` input value, which we check on all POST requests to prevent cross-site request forgery. If you have set the ``xsrf_cookies`` application setting, you must include this HTML within all of your HTML forms. In a template, this method should be called with ``{% module xsrf_form_html() %}`` See `check_xsrf_cookie()` above for more information. """ return ( '<input type="hidden" name="_xsrf" value="' + escape.xhtml_escape(self.xsrf_token) + '"/>' )
[ "def", "xsrf_form_html", "(", "self", ")", "->", "str", ":", "return", "(", "'<input type=\"hidden\" name=\"_xsrf\" value=\"'", "+", "escape", ".", "xhtml_escape", "(", "self", ".", "xsrf_token", ")", "+", "'\"/>'", ")" ]
https://github.com/holzschu/Carnets/blob/44effb10ddfc6aa5c8b0687582a724ba82c6b547/Library/lib/python3.7/site-packages/tornado-6.0.1-py3.7-macosx-12.1-iPad6,7.egg/tornado/web.py#L1524-L1541
Ridter/MyJSRat
1be0b812eff4898618fb4cb4f678efdb360d7368
MyJSRat.py
python
myHandler.log_message
(self, format, *args)
return
Custom Log Handler to Spit out on to stderr
Custom Log Handler to Spit out on to stderr
[ "Custom", "Log", "Handler", "to", "Spit", "out", "on", "to", "stderr" ]
def log_message(self, format, *args): """ Custom Log Handler to Spit out on to stderr """ return
[ "def", "log_message", "(", "self", ",", "format", ",", "*", "args", ")", ":", "return" ]
https://github.com/Ridter/MyJSRat/blob/1be0b812eff4898618fb4cb4f678efdb360d7368/MyJSRat.py#L241-L243
Anorov/PySocks
c2fa43cbe1091e799e248e8e4433978916791a8b
socks.py
python
socksocket.get_proxy_sockname
(self)
return self.proxy_sockname
Returns the bound IP address and port number at the proxy.
Returns the bound IP address and port number at the proxy.
[ "Returns", "the", "bound", "IP", "address", "and", "port", "number", "at", "the", "proxy", "." ]
def get_proxy_sockname(self): """Returns the bound IP address and port number at the proxy.""" return self.proxy_sockname
[ "def", "get_proxy_sockname", "(", "self", ")", ":", "return", "self", ".", "proxy_sockname" ]
https://github.com/Anorov/PySocks/blob/c2fa43cbe1091e799e248e8e4433978916791a8b/socks.py#L418-L420
quantmind/pulsar
fee44e871954aa6ca36d00bb5a3739abfdb89b26
pulsar/apps/wsgi/wrappers.py
python
WsgiRequest.absolute_uri
(self, location=None, scheme=None, **query)
Builds an absolute URI from ``location`` and variables available in this request. If no ``location`` is specified, the relative URI is built from :meth:`full_path`.
Builds an absolute URI from ``location`` and variables available in this request.
[ "Builds", "an", "absolute", "URI", "from", "location", "and", "variables", "available", "in", "this", "request", "." ]
def absolute_uri(self, location=None, scheme=None, **query): """Builds an absolute URI from ``location`` and variables available in this request. If no ``location`` is specified, the relative URI is built from :meth:`full_path`. """ if not is_absolute_uri(location): if location or location is None: location = self.full_path(location, **query) if not scheme: scheme = self.is_secure and 'https' or 'http' base = '%s://%s' % (scheme, self.get_host()) return '%s%s' % (base, location) elif not scheme: return iri_to_uri(location) else: raise ValueError('Absolute location with scheme not valid')
[ "def", "absolute_uri", "(", "self", ",", "location", "=", "None", ",", "scheme", "=", "None", ",", "*", "*", "query", ")", ":", "if", "not", "is_absolute_uri", "(", "location", ")", ":", "if", "location", "or", "location", "is", "None", ":", "location"...
https://github.com/quantmind/pulsar/blob/fee44e871954aa6ca36d00bb5a3739abfdb89b26/pulsar/apps/wsgi/wrappers.py#L367-L384
StanfordVL/taskonomy
9f814867b5fe4165860862211e8e99b0f200144d
taskbank/lib/data/load_ops.py
python
rescale_image
(im, new_scale=[-1.,1.], current_scale=None, no_clip=False)
return im
Rescales an image pixel values to target_scale Args: img: A np.float_32 array, assumed between [0,1] new_scale: [min,max] current_scale: If not supplied, it is assumed to be in: [0, 1]: if dtype=float [0, 2^16]: if dtype=uint [0, 255]: if dtype=ubyte Returns: rescaled_image
Rescales an image pixel values to target_scale Args: img: A np.float_32 array, assumed between [0,1] new_scale: [min,max] current_scale: If not supplied, it is assumed to be in: [0, 1]: if dtype=float [0, 2^16]: if dtype=uint [0, 255]: if dtype=ubyte Returns: rescaled_image
[ "Rescales", "an", "image", "pixel", "values", "to", "target_scale", "Args", ":", "img", ":", "A", "np", ".", "float_32", "array", "assumed", "between", "[", "0", "1", "]", "new_scale", ":", "[", "min", "max", "]", "current_scale", ":", "If", "not", "su...
def rescale_image(im, new_scale=[-1.,1.], current_scale=None, no_clip=False): """ Rescales an image pixel values to target_scale Args: img: A np.float_32 array, assumed between [0,1] new_scale: [min,max] current_scale: If not supplied, it is assumed to be in: [0, 1]: if dtype=float [0, 2^16]: if dtype=uint [0, 255]: if dtype=ubyte Returns: rescaled_image """ im = skimage.img_as_float(im).astype(np.float32) if current_scale is not None: min_val, max_val = current_scale if not no_clip: im = np.clip(im, min_val, max_val) im = im - min_val im /= (max_val - min_val) min_val, max_val = new_scale im *= (max_val - min_val) im += min_val return im
[ "def", "rescale_image", "(", "im", ",", "new_scale", "=", "[", "-", "1.", ",", "1.", "]", ",", "current_scale", "=", "None", ",", "no_clip", "=", "False", ")", ":", "im", "=", "skimage", ".", "img_as_float", "(", "im", ")", ".", "astype", "(", "np"...
https://github.com/StanfordVL/taskonomy/blob/9f814867b5fe4165860862211e8e99b0f200144d/taskbank/lib/data/load_ops.py#L246-L271
QUANTAXIS/QUANTAXIS
d6eccb97c8385854aa596d6ba8d70ec0655519ff
QUANTAXIS/QAFetch/QAbinance.py
python
QA_fetch_binance_kline_min
( symbol, start_time, end_time, frequency, callback_func=None )
Get the latest symbol‘s candlestick data with time slices 时间倒序切片获取算法,是各大交易所获取1min数据的神器,因为大部分交易所直接请求跨月跨年的1min分钟数据 会直接返回空值,只有将 start_epoch,end_epoch 切片细分到 200/300 bar 以内,才能正确返回 kline, 火币和binance,OKEx 均为如此,用上面那个函数的方式去直接请求上万bar 的分钟 kline 数据是不会有结果的。
Get the latest symbol‘s candlestick data with time slices 时间倒序切片获取算法,是各大交易所获取1min数据的神器,因为大部分交易所直接请求跨月跨年的1min分钟数据 会直接返回空值,只有将 start_epoch,end_epoch 切片细分到 200/300 bar 以内,才能正确返回 kline, 火币和binance,OKEx 均为如此,用上面那个函数的方式去直接请求上万bar 的分钟 kline 数据是不会有结果的。
[ "Get", "the", "latest", "symbol‘s", "candlestick", "data", "with", "time", "slices", "时间倒序切片获取算法,是各大交易所获取1min数据的神器,因为大部分交易所直接请求跨月跨年的1min分钟数据", "会直接返回空值,只有将", "start_epoch,end_epoch", "切片细分到", "200", "/", "300", "bar", "以内,才能正确返回", "kline,", "火币和binance,OKEx", "均为如此,用上面那个函数的方式...
def QA_fetch_binance_kline_min( symbol, start_time, end_time, frequency, callback_func=None ): """ Get the latest symbol‘s candlestick data with time slices 时间倒序切片获取算法,是各大交易所获取1min数据的神器,因为大部分交易所直接请求跨月跨年的1min分钟数据 会直接返回空值,只有将 start_epoch,end_epoch 切片细分到 200/300 bar 以内,才能正确返回 kline, 火币和binance,OKEx 均为如此,用上面那个函数的方式去直接请求上万bar 的分钟 kline 数据是不会有结果的。 """ reqParams = {} reqParams['from'] = end_time - FREQUENCY_SHIFTING[frequency] reqParams['to'] = end_time requested_counter = 1 datas = list() while (reqParams['to'] > start_time): if ((reqParams['from'] > QA_util_datetime_to_Unix_timestamp())) or \ ((reqParams['from'] > reqParams['to'])): # 出现“未来”时间,一般是默认时区设置,或者时间窗口滚动前移错误造成的 QA_util_log_info( 'A unexpected \'Future\' timestamp got, Please check self.missing_data_list_func param \'tzlocalize\' set. More info: {:s}@{:s} at {:s} but current time is {}' .format( symbol, frequency, QA_util_print_timestamp(reqParams['from']), QA_util_print_timestamp( QA_util_datetime_to_Unix_timestamp() ) ) ) # 跳到下一个时间段 reqParams['to'] = int(reqParams['from'] - 1) reqParams['from'] = int(reqParams['from'] - FREQUENCY_SHIFTING[frequency]) continue klines = QA_fetch_binance_kline_with_auto_retry( symbol, reqParams['from'], reqParams['to'], frequency, ) if (klines is None) or \ (len(klines) == 0) or \ ('error' in klines): # 出错放弃 break reqParams['to'] = int(reqParams['from'] - 1) reqParams['from'] = int(reqParams['from'] - FREQUENCY_SHIFTING[frequency]) if (callback_func is not None): frame = format_binance_data_fields(klines, symbol, frequency) callback_func(frame, Binance2QA_FREQUENCY_DICT[frequency]) if (len(klines) == 0): return None
[ "def", "QA_fetch_binance_kline_min", "(", "symbol", ",", "start_time", ",", "end_time", ",", "frequency", ",", "callback_func", "=", "None", ")", ":", "reqParams", "=", "{", "}", "reqParams", "[", "'from'", "]", "=", "end_time", "-", "FREQUENCY_SHIFTING", "[",...
https://github.com/QUANTAXIS/QUANTAXIS/blob/d6eccb97c8385854aa596d6ba8d70ec0655519ff/QUANTAXIS/QAFetch/QAbinance.py#L307-L366
NervanaSystems/neon
8c3fb8a93b4a89303467b25817c60536542d08bd
neon/data/ticker.py
python
Task.fill_buffers
(self, time_steps, inputs, outputs, in_tensor, out_tensor, mask)
Prepare data for delivery to device. Arguments: time_steps (int): Number of time steps in this minibatch. inputs (numpy array): Inputs numpy array outputs (numpy array): Outputs numpy array in_tensor (Tensor): Device buffer holding inputs out_tensor (Tensor): Device buffer holding outputs mask (numpy array): Device buffer for the output mask
Prepare data for delivery to device.
[ "Prepare", "data", "for", "delivery", "to", "device", "." ]
def fill_buffers(self, time_steps, inputs, outputs, in_tensor, out_tensor, mask): """ Prepare data for delivery to device. Arguments: time_steps (int): Number of time steps in this minibatch. inputs (numpy array): Inputs numpy array outputs (numpy array): Outputs numpy array in_tensor (Tensor): Device buffer holding inputs out_tensor (Tensor): Device buffer holding outputs mask (numpy array): Device buffer for the output mask """ # Put inputs and outputs, which are too small, into properly shaped arrays columns = time_steps * self.be.bsz inC = np.zeros((self.nin, self.max_columns)) outC = np.zeros((self.nout, self.max_columns)) inC[:, :columns] = inputs outC[:, :columns] = outputs # Copy those arrays to device in_tensor.set(inC) out_tensor.set(outC) # Set a mask over the unused part of the buffer mask[:, :columns] = 1 mask[:, columns:] = 0
[ "def", "fill_buffers", "(", "self", ",", "time_steps", ",", "inputs", ",", "outputs", ",", "in_tensor", ",", "out_tensor", ",", "mask", ")", ":", "# Put inputs and outputs, which are too small, into properly shaped arrays", "columns", "=", "time_steps", "*", "self", "...
https://github.com/NervanaSystems/neon/blob/8c3fb8a93b4a89303467b25817c60536542d08bd/neon/data/ticker.py#L45-L70
anyoptimization/pymoo
c6426a721d95c932ae6dbb610e09b6c1b0e13594
pymoo/algorithms/soo/nonconvex/cmaes.py
python
CMAES.__init__
(self, x0=None, sigma=0.1, normalize=True, parallelize=True, maxfevals=np.inf, tolfun=1e-11, tolx=1e-11, restarts=0, restart_from_best='False', incpopsize=2, eval_initial_x=False, noise_handler=None, noise_change_sigma_exponent=1, noise_kappa_exponent=0, bipop=False, cmaes_verbose=-9, verb_log=0, display=CMAESDisplay(), **kwargs )
Parameters ---------- x0 : list or `numpy.ndarray` initial guess of minimum solution before the application of the geno-phenotype transformation according to the ``transformation`` option. It can also be a string holding a Python expression that is evaluated to yield the initial guess - this is important in case restarts are performed so that they start from different places. Otherwise ``x0`` can also be a `cma.CMAEvolutionStrategy` object instance, in that case ``sigma0`` can be ``None``. sigma : float Initial standard deviation in each coordinate. ``sigma0`` should be about 1/4th of the search domain width (where the optimum is to be expected). The variables in ``objective_function`` should be scaled such that they presumably have similar sensitivity. See also `ScaleCoordinates`. parallelize : bool Whether the objective function should be called for each single evaluation or batch wise. restarts : int, default 0 Number of restarts with increasing population size, see also parameter ``incpopsize``, implementing the IPOP-CMA-ES restart strategy, see also parameter ``bipop``; to restart from different points (recommended), pass ``x0`` as a string. restart_from_best : bool, default false Which point to restart from incpopsize : int Multiplier for increasing the population size ``popsize`` before each restart eval_initial_x : bool Evaluate initial solution, for ``None`` only with elitist option noise_handler : class A ``NoiseHandler`` class or instance or ``None``. Example: ``cma.fmin(f, 6 * [1], 1, noise_handler=cma.NoiseHandler(6))`` see ``help(cma.NoiseHandler)``. noise_change_sigma_exponent : int Exponent for the sigma increment provided by the noise handler for additional noise treatment. 0 means no sigma change. noise_kappa_exponent : int Instead of applying reevaluations, the "number of evaluations" is (ab)used as scaling factor kappa (experimental). bipop : bool If `True`, run as BIPOP-CMA-ES; BIPOP is a special restart strategy switching between two population sizings - small (like the default CMA, but with more focused search) and large (progressively increased as in IPOP). This makes the algorithm perform well both on functions with many regularly or irregularly arranged local optima (the latter by frequently restarting with small populations). For the `bipop` parameter to actually take effect, also select non-zero number of (IPOP) restarts; the recommended setting is ``restarts<=9`` and `x0` passed as a string using `numpy.rand` to generate initial solutions. Note that small-population restarts do not count into the total restart count. AdaptSigma : True Or False or any CMAAdaptSigmaBase class e.g. CMAAdaptSigmaTPA, CMAAdaptSigmaCSA CMA_active : True Negative update, conducted after the original update CMA_activefac : 1 Learning rate multiplier for active update CMA_cmean : 1 Learning rate for the mean value CMA_const_trace : False Normalize trace, 1, True, "arithm", "geom", "aeig", "geig" are valid CMA_diagonal : 0*100*N/popsize**0.5 Number of iterations with diagonal covariance matrix, True for always CMA_eigenmethod : np.linalg.eigh or cma.utilities.math.eig or pygsl.eigen.eigenvectors CMA_elitist : False or "initial" or True Elitism likely impairs global search performance CMA_injections_threshold_keep_len : 0 Keep length if Mahalanobis length is below the given relative threshold CMA_mirrors : popsize < 6 Values <0.5 are interpreted as fraction, values >1 as numbers (rounded), otherwise about 0.16 is used CMA_mirrormethod : int, default 2, 0=unconditional, 1=selective, 2=selective with delay CMA_mu : None Parents selection parameter, default is popsize // 2 CMA_on : 1 Multiplier for all covariance matrix updates CMA_sampler : None A class or instance that implements the interface of `cma.interfaces.StatisticalModelSamplerWithZeroMeanBaseClass` CMA_sampler_options : dict Options passed to `CMA_sampler` class init as keyword arguments CMA_rankmu : 1.0 Multiplier for rank-mu update learning rate of covariance matrix CMA_rankone : 1.0 Multiplier for rank-one update learning rate of covariance matrix CMA_recombination_weights : None A list, see class RecombinationWeights, overwrites CMA_mu and popsize options CMA_dampsvec_fac : np.Inf Tentative and subject to changes, 0.5 would be a "default" damping for sigma vector update CMA_dampsvec_fade : 0.1 Tentative fading out parameter for sigma vector update CMA_teststds : None Factors for non-isotropic initial distr. of C, mainly for test purpose, see CMA_stds for production CMA_stds : None Multipliers for sigma0 in each coordinate, not represented in C, makes scaling_of_variables obsolete CSA_dampfac : 1 Positive multiplier for step-size damping, 0.3 is close to optimal on the sphere CSA_damp_mueff_exponent : 0.5 Zero would mean no dependency of damping on mueff, useful with CSA_disregard_length option CSA_disregard_length : False True is untested, also changes respective parameters CSA_clip_length_value : None Poorly tested, [0, 0] means const length N**0.5, [-1, 1] allows a variation of +- N/(N+2), etc. CSA_squared : False Use squared length for sigma-adaptation ', BoundaryHandler : BoundTransform or BoundPenalty, unused when ``bounds in (None, [None, None])`` conditioncov_alleviate : [1e8, 1e12] When to alleviate the condition in the coordinates and in main axes eval_final_mean : True Evaluate the final mean, which is a favorite return candidate fixed_variables : None Dictionary with index-value pairs like dict(0=1.1, 2=0.1) that are not optimized ftarget : -inf Target function value, minimization integer_variables : [] Index list, invokes basic integer handling: prevent std dev to become too small in the given variables maxfevals : inf Maximum number of function evaluations maxiter : 100 + 150 * (N+3)**2 // popsize**0.5 Maximum number of iterations mean_shift_line_samples : False Sample two new solutions colinear to previous mean shift mindx : 0 Minimal std in any arbitrary direction, cave interference with tol minstd : 0 Minimal std (scalar or vector) in any coordinate direction, cave interference with tol maxstd : inf Maximal std in any coordinate direction pc_line_samples : False One line sample along the evolution path pc popsize : 4+int(3*np.log(N)) Population size, AKA lambda, number of new solution per iteration randn : np.random.randn Randn(lam, N) must return an np.array of shape (lam, N), see also cma.utilities.math.randhss signals_filename : None cma_signals.in # read versatile options from this file which contains a single options dict, e.g. ``dict("timeout"=0)`` to stop, string-values are evaluated, e.g. "np.inf" is valid termination_callback : None A function returning True for termination, called in `stop` with `self` as argument, could be abused for side effects timeout : inf Stop if timeout seconds are exceeded, the string "2.5 * 60**2" evaluates to 2 hours and 30 minutes tolconditioncov : 1e14 Stop if the condition of the covariance matrix is above `tolconditioncov` tolfacupx : 1e3 Termination when step-size increases by tolfacupx (diverges). That is, the initial step-size was chosen far too small and better solutions were found far away from the initial solution x0 tolupsigma : 1e20 Sigma/sigma0 > tolupsigma * max(eivenvals(C)**0.5) indicates "creeping behavior" with usually minor improvements tolfun : 1e-11 Termination criterion: tolerance in function value, quite useful tolfunhist : 1e-12 Termination criterion: tolerance in function value history tolstagnation : int(100 + 100 * N**1.5 / popsize) Termination if no improvement over tolstagnation iterations tolx : 1e-11 Termination criterion: tolerance in x-changes typical_x : None Used with scaling_of_variables', updatecovwait : None Number of iterations without distribution update, name is subject to future changes cmaes_verbose : 3 Verbosity e.g. of initial/final message, -1 is very quiet, -9 maximally quiet, may not be fully implemented verb_append : 0 Initial evaluation counter, if append, do not overwrite output files verb_disp : 100 Verbosity: display console output every verb_disp iteration verb_filenameprefix : str CMADataLogger.default_prefix + Output path and filenames prefix verb_log : 1 Verbosity: write data to files every verb_log iteration, writing can be time critical on fast to evaluate functions verb_plot : 0 In fmin(): plot() is called every verb_plot iteration verb_time : True Output timings on console vv : dict Versatile set or dictionary for hacking purposes, value found in self.opts["vv"] kwargs : dict A dictionary with additional options passed to the constructor of class ``CMAEvolutionStrategy``, see ``cma.CMAOptions`` () for a list of available options.
[]
def __init__(self, x0=None, sigma=0.1, normalize=True, parallelize=True, maxfevals=np.inf, tolfun=1e-11, tolx=1e-11, restarts=0, restart_from_best='False', incpopsize=2, eval_initial_x=False, noise_handler=None, noise_change_sigma_exponent=1, noise_kappa_exponent=0, bipop=False, cmaes_verbose=-9, verb_log=0, display=CMAESDisplay(), **kwargs ): """ Parameters ---------- x0 : list or `numpy.ndarray` initial guess of minimum solution before the application of the geno-phenotype transformation according to the ``transformation`` option. It can also be a string holding a Python expression that is evaluated to yield the initial guess - this is important in case restarts are performed so that they start from different places. Otherwise ``x0`` can also be a `cma.CMAEvolutionStrategy` object instance, in that case ``sigma0`` can be ``None``. sigma : float Initial standard deviation in each coordinate. ``sigma0`` should be about 1/4th of the search domain width (where the optimum is to be expected). The variables in ``objective_function`` should be scaled such that they presumably have similar sensitivity. See also `ScaleCoordinates`. parallelize : bool Whether the objective function should be called for each single evaluation or batch wise. restarts : int, default 0 Number of restarts with increasing population size, see also parameter ``incpopsize``, implementing the IPOP-CMA-ES restart strategy, see also parameter ``bipop``; to restart from different points (recommended), pass ``x0`` as a string. restart_from_best : bool, default false Which point to restart from incpopsize : int Multiplier for increasing the population size ``popsize`` before each restart eval_initial_x : bool Evaluate initial solution, for ``None`` only with elitist option noise_handler : class A ``NoiseHandler`` class or instance or ``None``. Example: ``cma.fmin(f, 6 * [1], 1, noise_handler=cma.NoiseHandler(6))`` see ``help(cma.NoiseHandler)``. noise_change_sigma_exponent : int Exponent for the sigma increment provided by the noise handler for additional noise treatment. 0 means no sigma change. noise_kappa_exponent : int Instead of applying reevaluations, the "number of evaluations" is (ab)used as scaling factor kappa (experimental). bipop : bool If `True`, run as BIPOP-CMA-ES; BIPOP is a special restart strategy switching between two population sizings - small (like the default CMA, but with more focused search) and large (progressively increased as in IPOP). This makes the algorithm perform well both on functions with many regularly or irregularly arranged local optima (the latter by frequently restarting with small populations). For the `bipop` parameter to actually take effect, also select non-zero number of (IPOP) restarts; the recommended setting is ``restarts<=9`` and `x0` passed as a string using `numpy.rand` to generate initial solutions. Note that small-population restarts do not count into the total restart count. AdaptSigma : True Or False or any CMAAdaptSigmaBase class e.g. CMAAdaptSigmaTPA, CMAAdaptSigmaCSA CMA_active : True Negative update, conducted after the original update CMA_activefac : 1 Learning rate multiplier for active update CMA_cmean : 1 Learning rate for the mean value CMA_const_trace : False Normalize trace, 1, True, "arithm", "geom", "aeig", "geig" are valid CMA_diagonal : 0*100*N/popsize**0.5 Number of iterations with diagonal covariance matrix, True for always CMA_eigenmethod : np.linalg.eigh or cma.utilities.math.eig or pygsl.eigen.eigenvectors CMA_elitist : False or "initial" or True Elitism likely impairs global search performance CMA_injections_threshold_keep_len : 0 Keep length if Mahalanobis length is below the given relative threshold CMA_mirrors : popsize < 6 Values <0.5 are interpreted as fraction, values >1 as numbers (rounded), otherwise about 0.16 is used CMA_mirrormethod : int, default 2, 0=unconditional, 1=selective, 2=selective with delay CMA_mu : None Parents selection parameter, default is popsize // 2 CMA_on : 1 Multiplier for all covariance matrix updates CMA_sampler : None A class or instance that implements the interface of `cma.interfaces.StatisticalModelSamplerWithZeroMeanBaseClass` CMA_sampler_options : dict Options passed to `CMA_sampler` class init as keyword arguments CMA_rankmu : 1.0 Multiplier for rank-mu update learning rate of covariance matrix CMA_rankone : 1.0 Multiplier for rank-one update learning rate of covariance matrix CMA_recombination_weights : None A list, see class RecombinationWeights, overwrites CMA_mu and popsize options CMA_dampsvec_fac : np.Inf Tentative and subject to changes, 0.5 would be a "default" damping for sigma vector update CMA_dampsvec_fade : 0.1 Tentative fading out parameter for sigma vector update CMA_teststds : None Factors for non-isotropic initial distr. of C, mainly for test purpose, see CMA_stds for production CMA_stds : None Multipliers for sigma0 in each coordinate, not represented in C, makes scaling_of_variables obsolete CSA_dampfac : 1 Positive multiplier for step-size damping, 0.3 is close to optimal on the sphere CSA_damp_mueff_exponent : 0.5 Zero would mean no dependency of damping on mueff, useful with CSA_disregard_length option CSA_disregard_length : False True is untested, also changes respective parameters CSA_clip_length_value : None Poorly tested, [0, 0] means const length N**0.5, [-1, 1] allows a variation of +- N/(N+2), etc. CSA_squared : False Use squared length for sigma-adaptation ', BoundaryHandler : BoundTransform or BoundPenalty, unused when ``bounds in (None, [None, None])`` conditioncov_alleviate : [1e8, 1e12] When to alleviate the condition in the coordinates and in main axes eval_final_mean : True Evaluate the final mean, which is a favorite return candidate fixed_variables : None Dictionary with index-value pairs like dict(0=1.1, 2=0.1) that are not optimized ftarget : -inf Target function value, minimization integer_variables : [] Index list, invokes basic integer handling: prevent std dev to become too small in the given variables maxfevals : inf Maximum number of function evaluations maxiter : 100 + 150 * (N+3)**2 // popsize**0.5 Maximum number of iterations mean_shift_line_samples : False Sample two new solutions colinear to previous mean shift mindx : 0 Minimal std in any arbitrary direction, cave interference with tol minstd : 0 Minimal std (scalar or vector) in any coordinate direction, cave interference with tol maxstd : inf Maximal std in any coordinate direction pc_line_samples : False One line sample along the evolution path pc popsize : 4+int(3*np.log(N)) Population size, AKA lambda, number of new solution per iteration randn : np.random.randn Randn(lam, N) must return an np.array of shape (lam, N), see also cma.utilities.math.randhss signals_filename : None cma_signals.in # read versatile options from this file which contains a single options dict, e.g. ``dict("timeout"=0)`` to stop, string-values are evaluated, e.g. "np.inf" is valid termination_callback : None A function returning True for termination, called in `stop` with `self` as argument, could be abused for side effects timeout : inf Stop if timeout seconds are exceeded, the string "2.5 * 60**2" evaluates to 2 hours and 30 minutes tolconditioncov : 1e14 Stop if the condition of the covariance matrix is above `tolconditioncov` tolfacupx : 1e3 Termination when step-size increases by tolfacupx (diverges). That is, the initial step-size was chosen far too small and better solutions were found far away from the initial solution x0 tolupsigma : 1e20 Sigma/sigma0 > tolupsigma * max(eivenvals(C)**0.5) indicates "creeping behavior" with usually minor improvements tolfun : 1e-11 Termination criterion: tolerance in function value, quite useful tolfunhist : 1e-12 Termination criterion: tolerance in function value history tolstagnation : int(100 + 100 * N**1.5 / popsize) Termination if no improvement over tolstagnation iterations tolx : 1e-11 Termination criterion: tolerance in x-changes typical_x : None Used with scaling_of_variables', updatecovwait : None Number of iterations without distribution update, name is subject to future changes cmaes_verbose : 3 Verbosity e.g. of initial/final message, -1 is very quiet, -9 maximally quiet, may not be fully implemented verb_append : 0 Initial evaluation counter, if append, do not overwrite output files verb_disp : 100 Verbosity: display console output every verb_disp iteration verb_filenameprefix : str CMADataLogger.default_prefix + Output path and filenames prefix verb_log : 1 Verbosity: write data to files every verb_log iteration, writing can be time critical on fast to evaluate functions verb_plot : 0 In fmin(): plot() is called every verb_plot iteration verb_time : True Output timings on console vv : dict Versatile set or dictionary for hacking purposes, value found in self.opts["vv"] kwargs : dict A dictionary with additional options passed to the constructor of class ``CMAEvolutionStrategy``, see ``cma.CMAOptions`` () for a list of available options. """ super().__init__(x0=x0, display=display, **kwargs) self.es = None self.cma = None self.normalize = normalize self.norm = None self.sigma = sigma self.restarts = restarts self.restart_from_best = restart_from_best self.incpopsize = incpopsize self.eval_initial_x = eval_initial_x self.noise_handler = noise_handler self.noise_change_sigma_exponent = noise_change_sigma_exponent self.noise_kappa_exponent = noise_kappa_exponent self.bipop = bipop self.options = dict( verbose=cmaes_verbose, verb_log=verb_log, maxfevals=maxfevals, tolfun=tolfun, tolx=tolx, **kwargs ) self.default_termination = NoTermination() self.send_array_to_yield = True self.parallelize = parallelize self.al = None
[ "def", "__init__", "(", "self", ",", "x0", "=", "None", ",", "sigma", "=", "0.1", ",", "normalize", "=", "True", ",", "parallelize", "=", "True", ",", "maxfevals", "=", "np", ".", "inf", ",", "tolfun", "=", "1e-11", ",", "tolx", "=", "1e-11", ",", ...
https://github.com/anyoptimization/pymoo/blob/c6426a721d95c932ae6dbb610e09b6c1b0e13594/pymoo/algorithms/soo/nonconvex/cmaes.py#L50-L366
tanjiti/packet_analysis
457008a3e37a67b18be99dbf178ee78d5b0820c4
protocol_parse/mysqlauth.py
python
MySQLAuth.__parse_client_data
(self, sep='\x00')
return auth_detail
:return:
[]
def __parse_client_data(self, sep='\x00'): """ :return: """ auth_detail = [] data_c2s_data_list = self.__split_mysql_data(self.data_c2s) for item in data_c2s_data_list: # 1. find Login Request len_of_data_c2s = len(item) if len_of_data_c2s < 36: # packet header: 4 # client capabilities: 4 # max packet: 4 # charset: 1 # reserved : 23 continue packetnumber = item[3] # make sure the packet number is 1 if packetnumber != "01": continue # make sure the reserved 23 byte is all 00 is_reserved_ok = 1 for i in item[13:36]: if i != "00": is_reserved_ok = 0 break if is_reserved_ok != 1: continue client_capabilities = bin(int("".join([item[5], item[4]]), base=16)) is_ssl = client_capabilities[-12] # check is connect db is_connect_db = client_capabilities[-4] # check if swith to ssl after handshake if len_of_data_c2s == 36: if is_ssl == '1': self.is_ssl = True logging.debug( "[MYSQL_SSL]: %s:%s -> %s:%s %f %f" % (self.src_ip, self.src_port, self.dst_ip, self.dst_port, self.ts_start, self.ts_end)) continue # get the user name # string end with 00 user = "" db = "" pos_00 = 0 for i in range(36, len_of_data_c2s): if item[i] == "00": pos_00 = i break user = user + chr(int(item[i], base=16)) len_of_passwd = int(item[pos_00 + 1], base=16) passwd = "" if len_of_passwd > 0: passwd = "".join(item[pos_00 + 2:pos_00 + 2 + len_of_passwd + 1]) if is_connect_db == '1': pos_of_db = pos_00 + 1 + len_of_passwd + 1 for i in range(pos_of_db, len_of_data_c2s): if item[i] == "00": break db = db + chr(int(item[i], base=16)) # user/database_name crack_detail = "%s%s%s%s%s%s" % (sep, user, sep, passwd, sep, db) auth_detail.append(crack_detail) return auth_detail
[ "def", "__parse_client_data", "(", "self", ",", "sep", "=", "'\\x00'", ")", ":", "auth_detail", "=", "[", "]", "data_c2s_data_list", "=", "self", ".", "__split_mysql_data", "(", "self", ".", "data_c2s", ")", "for", "item", "in", "data_c2s_data_list", ":", "#...
https://github.com/tanjiti/packet_analysis/blob/457008a3e37a67b18be99dbf178ee78d5b0820c4/protocol_parse/mysqlauth.py#L101-L182
gramps-project/gramps
04d4651a43eb210192f40a9f8c2bad8ee8fa3753
gramps/plugins/tool/verify.py
python
Disconnected.broken
(self)
return (len(self.obj.get_parent_family_handle_list()) + len(self.obj.get_family_handle_list()) == 0)
return boolean indicating whether this rule is violated
return boolean indicating whether this rule is violated
[ "return", "boolean", "indicating", "whether", "this", "rule", "is", "violated" ]
def broken(self): """ return boolean indicating whether this rule is violated """ return (len(self.obj.get_parent_family_handle_list()) + len(self.obj.get_family_handle_list()) == 0)
[ "def", "broken", "(", "self", ")", ":", "return", "(", "len", "(", "self", ".", "obj", ".", "get_parent_family_handle_list", "(", ")", ")", "+", "len", "(", "self", ".", "obj", ".", "get_family_handle_list", "(", ")", ")", "==", "0", ")" ]
https://github.com/gramps-project/gramps/blob/04d4651a43eb210192f40a9f8c2bad8ee8fa3753/gramps/plugins/tool/verify.py#L1681-L1684
peering-manager/peering-manager
62c870fb9caa6dfc056feb77c595d45bc3c4988a
peeringdb/filters.py
python
NetworkIXLanFilterSet.search
(self, queryset, name, value)
return queryset.filter(qs_filter)
[]
def search(self, queryset, name, value): if not value.strip(): return queryset qs_filter = Q(net__name__icontains=value) try: qs_filter |= Q(asn=int(value.strip())) except ValueError: pass return queryset.filter(qs_filter)
[ "def", "search", "(", "self", ",", "queryset", ",", "name", ",", "value", ")", ":", "if", "not", "value", ".", "strip", "(", ")", ":", "return", "queryset", "qs_filter", "=", "Q", "(", "net__name__icontains", "=", "value", ")", "try", ":", "qs_filter",...
https://github.com/peering-manager/peering-manager/blob/62c870fb9caa6dfc056feb77c595d45bc3c4988a/peeringdb/filters.py#L28-L37
ericflo/django-pagination
d1a8f0f9fb21c5aa14c76e2f872d8eca13e5244d
pagination/paginator.py
python
FinitePage.has_next
(self)
return True
Checks for one more item than last on this page.
Checks for one more item than last on this page.
[ "Checks", "for", "one", "more", "item", "than", "last", "on", "this", "page", "." ]
def has_next(self): """ Checks for one more item than last on this page. """ try: next_item = self.paginator.object_list[self.paginator.per_page] except IndexError: return False return True
[ "def", "has_next", "(", "self", ")", ":", "try", ":", "next_item", "=", "self", ".", "paginator", ".", "object_list", "[", "self", ".", "paginator", ".", "per_page", "]", "except", "IndexError", ":", "return", "False", "return", "True" ]
https://github.com/ericflo/django-pagination/blob/d1a8f0f9fb21c5aa14c76e2f872d8eca13e5244d/pagination/paginator.py#L155-L163
jgagneastro/coffeegrindsize
22661ebd21831dba4cf32bfc6ba59fe3d49f879c
App/dist/coffeegrindsize.app/Contents/Resources/lib/python3.7/matplotlib/axes/_base.py
python
_AxesBase.set_axis_on
(self)
Turn the x- and y-axis on. This affects the axis lines, ticks, ticklabels, grid and axis labels.
Turn the x- and y-axis on.
[ "Turn", "the", "x", "-", "and", "y", "-", "axis", "on", "." ]
def set_axis_on(self): """ Turn the x- and y-axis on. This affects the axis lines, ticks, ticklabels, grid and axis labels. """ self.axison = True self.stale = True
[ "def", "set_axis_on", "(", "self", ")", ":", "self", ".", "axison", "=", "True", "self", ".", "stale", "=", "True" ]
https://github.com/jgagneastro/coffeegrindsize/blob/22661ebd21831dba4cf32bfc6ba59fe3d49f879c/App/dist/coffeegrindsize.app/Contents/Resources/lib/python3.7/matplotlib/axes/_base.py#L3007-L3014
project-alice-assistant/ProjectAlice
9e0ba019643bdae0a5535c9fa4180739231dc361
core/webApi/model/SkillsApi.py
python
SkillsApi.checkUpdate
(self, skillName: str)
return jsonify(success=True)
check for updates for the specified skill :param skillName: :return:
check for updates for the specified skill :param skillName: :return:
[ "check", "for", "updates", "for", "the", "specified", "skill", ":", "param", "skillName", ":", ":", "return", ":" ]
def checkUpdate(self, skillName: str) -> Response: """ check for updates for the specified skill :param skillName: :return: """ if skillName not in self.SkillManager.allSkills: return self.skillNotFound() update = self.SkillManager.checkForSkillUpdates(skillToCheck=skillName) if update: self.SkillManager.updateSkills(skills=update) return jsonify(success=True)
[ "def", "checkUpdate", "(", "self", ",", "skillName", ":", "str", ")", "->", "Response", ":", "if", "skillName", "not", "in", "self", ".", "SkillManager", ".", "allSkills", ":", "return", "self", ".", "skillNotFound", "(", ")", "update", "=", "self", ".",...
https://github.com/project-alice-assistant/ProjectAlice/blob/9e0ba019643bdae0a5535c9fa4180739231dc361/core/webApi/model/SkillsApi.py#L236-L249
holzschu/Carnets
44effb10ddfc6aa5c8b0687582a724ba82c6b547
Library/lib/python3.7/site-packages/pip/_vendor/html5lib/treewalkers/base.py
python
TreeWalker.unknown
(self, nodeType)
return self.error("Unknown node type: " + nodeType)
Handles unknown node types
Handles unknown node types
[ "Handles", "unknown", "node", "types" ]
def unknown(self, nodeType): """Handles unknown node types""" return self.error("Unknown node type: " + nodeType)
[ "def", "unknown", "(", "self", ",", "nodeType", ")", ":", "return", "self", ".", "error", "(", "\"Unknown node type: \"", "+", "nodeType", ")" ]
https://github.com/holzschu/Carnets/blob/44effb10ddfc6aa5c8b0687582a724ba82c6b547/Library/lib/python3.7/site-packages/pip/_vendor/html5lib/treewalkers/base.py#L175-L177
nccgroup/BLESuite
0e2e534f7d9beaa8e9d76223959a60b064f61e22
blesuite/gatt_procedures.py
python
gatt_procedure_discover_primary_services
(connection_manager, connection, device)
return device
Scans device associated with BLEConnection for all primary services and stores them in the provided BLEDevice. :param connection_manager: BLEConnectionManager that can send request to the peer device associated with the supplied connection. :type connection_manager: BLEConnectionManager :param connection: BLEConnection that is associated with the target peer device :type connection: BLEConnection :param device: BLEDevice object that represents the peer device :type device: BLEDevice :return: Poplulated BLEDevice :rtype: BLEDevice
Scans device associated with BLEConnection for all primary services and stores them in the provided BLEDevice.
[ "Scans", "device", "associated", "with", "BLEConnection", "for", "all", "primary", "services", "and", "stores", "them", "in", "the", "provided", "BLEDevice", "." ]
def gatt_procedure_discover_primary_services(connection_manager, connection, device): """ Scans device associated with BLEConnection for all primary services and stores them in the provided BLEDevice. :param connection_manager: BLEConnectionManager that can send request to the peer device associated with the supplied connection. :type connection_manager: BLEConnectionManager :param connection: BLEConnection that is associated with the target peer device :type connection: BLEConnection :param device: BLEDevice object that represents the peer device :type device: BLEDevice :return: Poplulated BLEDevice :rtype: BLEDevice """ from blesuite.pybt.gatt import UUID import struct bluetooth_base_addr = "00000000-0000-1000-8000-00805F9B34FB".replace('-', '') next_start_handle = 0x0001 connection_handle = connection.connection_handle while True: if not connection_manager.is_connected(connection): logger.debug("Primary service discovery: device not connected! Reconnecting...") connection_manager.connect(connection) request = connection_manager.stack_connection.read_by_group_type_sync(next_start_handle, 0xffff, UUID(0x2800), connection_handle) if request.has_error(): logger.debug("Primary service discovery error when reading from handle:%s, " "continuing" % hex(next_start_handle)) break logger.debug("Response received. Stored packet len: %s", request.response.pkt.length) length = request.response.pkt.length service_data = request.response.pkt.data next_start_handle = None if length == 6: # 4 byte uuid, 2 2-byte handles logger.debug("We've got services with 16-bit UUIDs!") services = [] i = 0 end_loop = False while i < len(service_data): services.append(service_data[i:i+6]) i += 6 # print "Services:", services for service in services: start = struct.unpack("<h", service[:2])[0] end = struct.unpack("<h", service[2:4])[0] uuid_16 = struct.unpack("<h", service[4:])[0] conversion = (uuid_16 * (2 ** 96)) + int(bluetooth_base_addr, 16) uuid_128 = struct.pack(">QQ", (conversion >> 64) & 0xFFFFFFFFFFFFFFFF, conversion & 0xFFFFFFFFFFFFFFFF).encode('hex') uuid_128 = '-'.join((uuid_128[:8], uuid_128[8:12], uuid_128[12:16], uuid_128[16:20], uuid_128[20:])) if end == -1: end = 0xffff if start == -1: start = 0xffff device.add_service(start, end, uuid_128) if end >= 0xFFFF or end < 0: end_loop = True if next_start_handle is None or end >= next_start_handle: next_start_handle = end + 1 if end_loop: logger.debug("End of primary service discovery!") break elif length == 20: # 16 byte uuid, 2 2-byte handles logger.debug("We've got services with 128-bit UUIDs!") start = struct.unpack("<h", service_data[:2])[0] end = struct.unpack("<h", service_data[2:4])[0] uuid_128 = struct.unpack("<QQ", service_data[4:]) uuid_128 = "%016x%016x" % (uuid_128[1], uuid_128[0]) # print "UUID128:", uuid_128 uuid_128 = '-'.join((uuid_128[:8], uuid_128[8:12], uuid_128[12:16], uuid_128[16:20], uuid_128[20:])) if end == -1: end = 0xffff if start == -1: start = 0xffff device.add_service(start, end, uuid_128) if end >= 0xFFFF or end < 0: logger.debug("End of primary service discovery!") break next_start_handle = end + 1 else: logger.error("UNEXPECTED PRIMARY SERVICE DISCOVERY RESPONSE. BAILING") break return device
[ "def", "gatt_procedure_discover_primary_services", "(", "connection_manager", ",", "connection", ",", "device", ")", ":", "from", "blesuite", ".", "pybt", ".", "gatt", "import", "UUID", "import", "struct", "bluetooth_base_addr", "=", "\"00000000-0000-1000-8000-00805F9B34F...
https://github.com/nccgroup/BLESuite/blob/0e2e534f7d9beaa8e9d76223959a60b064f61e22/blesuite/gatt_procedures.py#L423-L509
RexYing/diffpool
8dfb97cf60c2376ac804761837b9966f1d302acb
gen/feat.py
python
GaussianFeatureGen.__init__
(self, mu, sigma)
[]
def __init__(self, mu, sigma): self.mu = mu self.sigma = sigma
[ "def", "__init__", "(", "self", ",", "mu", ",", "sigma", ")", ":", "self", ".", "mu", "=", "mu", "self", ".", "sigma", "=", "sigma" ]
https://github.com/RexYing/diffpool/blob/8dfb97cf60c2376ac804761837b9966f1d302acb/gen/feat.py#L20-L22
hydroshare/hydroshare
7ba563b55412f283047fb3ef6da367d41dec58c6
hs_tools_resource/app_launch_helper.py
python
get_app_dict
(user, resource, default_resource_term_dict)
return [default_resource_term_dict, hs_term_dict_user, hs_term_dict_file]
[]
def get_app_dict(user, resource, default_resource_term_dict): hs_term_dict_user = {} hs_term_dict_user["HS_USR_NAME"] = user.username if user.is_authenticated() else "anonymous" hs_term_dict_file = {} # HS_JS_AGG_KEY and HS_JS_FILE_KEY are overwritten by jquery to launch the url specific to each # file hs_term_dict_file["HS_AGG_PATH"] = "HS_JS_AGG_KEY" hs_term_dict_file["HS_FILE_PATH"] = "HS_JS_FILE_KEY" hs_term_dict_file["HS_MAIN_FILE"] = "HS_JS_MAIN_FILE_KEY" default_resource_term_dict.update(resource.get_hs_term_dict()) return [default_resource_term_dict, hs_term_dict_user, hs_term_dict_file]
[ "def", "get_app_dict", "(", "user", ",", "resource", ",", "default_resource_term_dict", ")", ":", "hs_term_dict_user", "=", "{", "}", "hs_term_dict_user", "[", "\"HS_USR_NAME\"", "]", "=", "user", ".", "username", "if", "user", ".", "is_authenticated", "(", ")",...
https://github.com/hydroshare/hydroshare/blob/7ba563b55412f283047fb3ef6da367d41dec58c6/hs_tools_resource/app_launch_helper.py#L113-L123
VirtueSecurity/aws-extender
d123b7e1a845847709ba3a481f11996bddc68a1c
BappModules/boto/iam/connection.py
python
IAMConnection.list_instance_profiles_for_role
(self, role_name, marker=None, max_items=None)
return self.get_response('ListInstanceProfilesForRole', params, list_marker='InstanceProfiles')
Lists the instance profiles that have the specified associated role. If there are none, the action returns an empty list. :type role_name: string :param role_name: The name of the role to list instance profiles for. :type marker: string :param marker: Use this parameter only when paginating results, and only in a subsequent request after you've received a response where the results are truncated. Set it to the value of the Marker element in the response you just received. :type max_items: int :param max_items: Use this parameter only when paginating results to indicate the maximum number of user names you want in the response.
Lists the instance profiles that have the specified associated role. If there are none, the action returns an empty list.
[ "Lists", "the", "instance", "profiles", "that", "have", "the", "specified", "associated", "role", ".", "If", "there", "are", "none", "the", "action", "returns", "an", "empty", "list", "." ]
def list_instance_profiles_for_role(self, role_name, marker=None, max_items=None): """ Lists the instance profiles that have the specified associated role. If there are none, the action returns an empty list. :type role_name: string :param role_name: The name of the role to list instance profiles for. :type marker: string :param marker: Use this parameter only when paginating results, and only in a subsequent request after you've received a response where the results are truncated. Set it to the value of the Marker element in the response you just received. :type max_items: int :param max_items: Use this parameter only when paginating results to indicate the maximum number of user names you want in the response. """ params = {'RoleName': role_name} if marker is not None: params['Marker'] = marker if max_items is not None: params['MaxItems'] = max_items return self.get_response('ListInstanceProfilesForRole', params, list_marker='InstanceProfiles')
[ "def", "list_instance_profiles_for_role", "(", "self", ",", "role_name", ",", "marker", "=", "None", ",", "max_items", "=", "None", ")", ":", "params", "=", "{", "'RoleName'", ":", "role_name", "}", "if", "marker", "is", "not", "None", ":", "params", "[", ...
https://github.com/VirtueSecurity/aws-extender/blob/d123b7e1a845847709ba3a481f11996bddc68a1c/BappModules/boto/iam/connection.py#L1263-L1288