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
IronLanguages/ironpython3
7a7bb2a872eeab0d1009fc8a6e24dca43f65b693
Src/StdLib/Lib/ssl.py
python
SSLSocket.do_handshake
(self, block=False)
Perform a TLS/SSL handshake.
Perform a TLS/SSL handshake.
[ "Perform", "a", "TLS", "/", "SSL", "handshake", "." ]
def do_handshake(self, block=False): """Perform a TLS/SSL handshake.""" self._check_connected() timeout = self.gettimeout() try: if timeout == 0.0 and block: self.settimeout(None) self._sslobj.do_handshake() finally: self.settimeout(timeout) if self.context.check_hostname: if not self.server_hostname: raise ValueError("check_hostname needs server_hostname " "argument") match_hostname(self.getpeercert(), self.server_hostname)
[ "def", "do_handshake", "(", "self", ",", "block", "=", "False", ")", ":", "self", ".", "_check_connected", "(", ")", "timeout", "=", "self", ".", "gettimeout", "(", ")", "try", ":", "if", "timeout", "==", "0.0", "and", "block", ":", "self", ".", "set...
https://github.com/IronLanguages/ironpython3/blob/7a7bb2a872eeab0d1009fc8a6e24dca43f65b693/Src/StdLib/Lib/ssl.py#L806-L821
golismero/golismero
7d605b937e241f51c1ca4f47b20f755eeefb9d76
tools/sqlmap/lib/core/option.py
python
_urllib2Opener
()
This function creates the urllib2 OpenerDirector.
This function creates the urllib2 OpenerDirector.
[ "This", "function", "creates", "the", "urllib2", "OpenerDirector", "." ]
def _urllib2Opener(): """ This function creates the urllib2 OpenerDirector. """ debugMsg = "creating HTTP requests opener object" logger.debug(debugMsg) handlers = [proxyHandler, authHandler, redirectHandler, rangeHandler, httpsHandler] if not conf.dropSetCookie: if not conf.loadCookies: conf.cj = cookielib.CookieJar() else: conf.cj = cookielib.MozillaCookieJar() resetCookieJar(conf.cj) handlers.append(urllib2.HTTPCookieProcessor(conf.cj)) # Reference: http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html if conf.keepAlive: warnMsg = "persistent HTTP(s) connections, Keep-Alive, has " warnMsg += "been disabled because of its incompatibility " if conf.proxy: warnMsg += "with HTTP(s) proxy" logger.warn(warnMsg) elif conf.authType: warnMsg += "with authentication methods" logger.warn(warnMsg) else: handlers.append(keepAliveHandler) opener = urllib2.build_opener(*handlers) urllib2.install_opener(opener)
[ "def", "_urllib2Opener", "(", ")", ":", "debugMsg", "=", "\"creating HTTP requests opener object\"", "logger", ".", "debug", "(", "debugMsg", ")", "handlers", "=", "[", "proxyHandler", ",", "authHandler", ",", "redirectHandler", ",", "rangeHandler", ",", "httpsHandl...
https://github.com/golismero/golismero/blob/7d605b937e241f51c1ca4f47b20f755eeefb9d76/tools/sqlmap/lib/core/option.py#L161-L195
WangYueFt/rfs
f8c837ba93c62dd0ac68a2f4019c619aa86b8421
models/util.py
python
create_model
(name, n_cls, dataset='miniImageNet')
return model
create model by name
create model by name
[ "create", "model", "by", "name" ]
def create_model(name, n_cls, dataset='miniImageNet'): """create model by name""" if dataset == 'miniImageNet' or dataset == 'tieredImageNet': if name.endswith('v2') or name.endswith('v3'): model = model_dict[name](num_classes=n_cls) elif name.startswith('resnet50'): print('use imagenet-style resnet50') model = model_dict[name](num_classes=n_cls) elif name.startswith('resnet') or name.startswith('seresnet'): model = model_dict[name](avg_pool=True, drop_rate=0.1, dropblock_size=5, num_classes=n_cls) elif name.startswith('wrn'): model = model_dict[name](num_classes=n_cls) elif name.startswith('convnet'): model = model_dict[name](num_classes=n_cls) else: raise NotImplementedError('model {} not supported in dataset {}:'.format(name, dataset)) elif dataset == 'CIFAR-FS' or dataset == 'FC100': if name.startswith('resnet') or name.startswith('seresnet'): model = model_dict[name](avg_pool=True, drop_rate=0.1, dropblock_size=2, num_classes=n_cls) elif name.startswith('convnet'): model = model_dict[name](num_classes=n_cls) else: raise NotImplementedError('model {} not supported in dataset {}:'.format(name, dataset)) else: raise NotImplementedError('dataset not supported: {}'.format(dataset)) return model
[ "def", "create_model", "(", "name", ",", "n_cls", ",", "dataset", "=", "'miniImageNet'", ")", ":", "if", "dataset", "==", "'miniImageNet'", "or", "dataset", "==", "'tieredImageNet'", ":", "if", "name", ".", "endswith", "(", "'v2'", ")", "or", "name", ".", ...
https://github.com/WangYueFt/rfs/blob/f8c837ba93c62dd0ac68a2f4019c619aa86b8421/models/util.py#L7-L33
scivision/PyLivestream
6c8243dd8ef76e2d441489198a346f5ed5bc262b
src/pylivestream/utils.py
python
run
(cmd: list[str])
FIXME: shell=True for Windows seems necessary to specify devices enclosed by "" quotes
FIXME: shell=True for Windows seems necessary to specify devices enclosed by "" quotes
[ "FIXME", ":", "shell", "=", "True", "for", "Windows", "seems", "necessary", "to", "specify", "devices", "enclosed", "by", "quotes" ]
def run(cmd: list[str]): """ FIXME: shell=True for Windows seems necessary to specify devices enclosed by "" quotes """ print("\n", " ".join(cmd), "\n") if sys.platform == "win32": subprocess.run(" ".join(cmd), shell=True) else: subprocess.run(cmd)
[ "def", "run", "(", "cmd", ":", "list", "[", "str", "]", ")", ":", "print", "(", "\"\\n\"", ",", "\" \"", ".", "join", "(", "cmd", ")", ",", "\"\\n\"", ")", "if", "sys", ".", "platform", "==", "\"win32\"", ":", "subprocess", ".", "run", "(", "\" \...
https://github.com/scivision/PyLivestream/blob/6c8243dd8ef76e2d441489198a346f5ed5bc262b/src/pylivestream/utils.py#L12-L22
Epistimio/orion
732e739d99561020dbe620760acf062ade746006
src/orion/algo/base.py
python
BaseAlgorithm.format_trial
(self, trial)
return trial
Format trial based on space transformations This will apply the reverse transformation on the trial and then transform it again. Some transformations are lossy and thus the trials suggested by the algorithm could be different when returned to `observe`. Using `format_trial` makes it possible for the algorithm to see the final version of the trial after back and forth transformations. This way it can recognise the trial in `observe` and also avoid duplicates that would have gone unnoticed during suggestion. Parameters ---------- trial : `orion.core.worker.trial.Trial` Trial from a `orion.algo.space.Space`.
Format trial based on space transformations
[ "Format", "trial", "based", "on", "space", "transformations" ]
def format_trial(self, trial): """Format trial based on space transformations This will apply the reverse transformation on the trial and then transform it again. Some transformations are lossy and thus the trials suggested by the algorithm could be different when returned to `observe`. Using `format_trial` makes it possible for the algorithm to see the final version of the trial after back and forth transformations. This way it can recognise the trial in `observe` and also avoid duplicates that would have gone unnoticed during suggestion. Parameters ---------- trial : `orion.core.worker.trial.Trial` Trial from a `orion.algo.space.Space`. """ if hasattr(self.space, "transform"): trial = self.space.transform(self.space.reverse(trial)) return trial
[ "def", "format_trial", "(", "self", ",", "trial", ")", ":", "if", "hasattr", "(", "self", ".", "space", ",", "\"transform\"", ")", ":", "trial", "=", "self", ".", "space", ".", "transform", "(", "self", ".", "space", ".", "reverse", "(", "trial", ")"...
https://github.com/Epistimio/orion/blob/732e739d99561020dbe620760acf062ade746006/src/orion/algo/base.py#L141-L162
kuri65536/python-for-android
26402a08fc46b09ef94e8d7a6bbc3a54ff9d0891
python-modules/twisted/twisted/internet/epollreactor.py
python
EPollReactor._add
(self, xer, primary, other, selectables, event, antievent)
Private method for adding a descriptor from the event loop. It takes care of adding it if new or modifying it if already added for another state (read -> read/write for example).
Private method for adding a descriptor from the event loop.
[ "Private", "method", "for", "adding", "a", "descriptor", "from", "the", "event", "loop", "." ]
def _add(self, xer, primary, other, selectables, event, antievent): """ Private method for adding a descriptor from the event loop. It takes care of adding it if new or modifying it if already added for another state (read -> read/write for example). """ fd = xer.fileno() if fd not in primary: cmd = _epoll.CTL_ADD flags = event if fd in other: flags |= antievent cmd = _epoll.CTL_MOD # epoll_ctl can raise all kinds of IOErrors, and every one # indicates a bug either in the reactor or application-code. # Let them all through so someone sees a traceback and fixes # something. We'll do the same thing for every other call to # this method in this file. self._poller._control(cmd, fd, flags) # Update our own tracking state *only* after the epoll call has # succeeded. Otherwise we may get out of sync. primary[fd] = 1 selectables[fd] = xer
[ "def", "_add", "(", "self", ",", "xer", ",", "primary", ",", "other", ",", "selectables", ",", "event", ",", "antievent", ")", ":", "fd", "=", "xer", ".", "fileno", "(", ")", "if", "fd", "not", "in", "primary", ":", "cmd", "=", "_epoll", ".", "CT...
https://github.com/kuri65536/python-for-android/blob/26402a08fc46b09ef94e8d7a6bbc3a54ff9d0891/python-modules/twisted/twisted/internet/epollreactor.py#L69-L93
bruderstein/PythonScript
df9f7071ddf3a079e3a301b9b53a6dc78cf1208f
PythonLib/tcl/tkinter/__init__.py
python
PanedWindow.remove
(self, child)
Remove the pane containing child from the panedwindow All geometry management options for child will be forgotten.
Remove the pane containing child from the panedwindow
[ "Remove", "the", "pane", "containing", "child", "from", "the", "panedwindow" ]
def remove(self, child): """Remove the pane containing child from the panedwindow All geometry management options for child will be forgotten. """ self.tk.call(self._w, 'forget', child)
[ "def", "remove", "(", "self", ",", "child", ")", ":", "self", ".", "tk", ".", "call", "(", "self", ".", "_w", ",", "'forget'", ",", "child", ")" ]
https://github.com/bruderstein/PythonScript/blob/df9f7071ddf3a079e3a301b9b53a6dc78cf1208f/PythonLib/tcl/tkinter/__init__.py#L4420-L4425
huggingface/transformers
623b4f7c63f60cce917677ee704d6c93ee960b4b
examples/research_projects/distillation/train.py
python
sanity_checks
(args)
A bunch of args sanity checks to perform even starting...
A bunch of args sanity checks to perform even starting...
[ "A", "bunch", "of", "args", "sanity", "checks", "to", "perform", "even", "starting", "..." ]
def sanity_checks(args): """ A bunch of args sanity checks to perform even starting... """ assert (args.mlm and args.alpha_mlm > 0.0) or (not args.mlm and args.alpha_mlm == 0.0) assert (args.alpha_mlm > 0.0 and args.alpha_clm == 0.0) or (args.alpha_mlm == 0.0 and args.alpha_clm > 0.0) if args.mlm: assert os.path.isfile(args.token_counts) assert (args.student_type in ["roberta", "distilbert"]) and (args.teacher_type in ["roberta", "bert"]) else: assert (args.student_type in ["gpt2"]) and (args.teacher_type in ["gpt2"]) assert args.teacher_type == args.student_type or ( args.student_type == "distilbert" and args.teacher_type == "bert" ) assert os.path.isfile(args.student_config) if args.student_pretrained_weights is not None: assert os.path.isfile(args.student_pretrained_weights) if args.freeze_token_type_embds: assert args.student_type in ["roberta"] assert args.alpha_ce >= 0.0 assert args.alpha_mlm >= 0.0 assert args.alpha_clm >= 0.0 assert args.alpha_mse >= 0.0 assert args.alpha_cos >= 0.0 assert args.alpha_ce + args.alpha_mlm + args.alpha_clm + args.alpha_mse + args.alpha_cos > 0.0
[ "def", "sanity_checks", "(", "args", ")", ":", "assert", "(", "args", ".", "mlm", "and", "args", ".", "alpha_mlm", ">", "0.0", ")", "or", "(", "not", "args", ".", "mlm", "and", "args", ".", "alpha_mlm", "==", "0.0", ")", "assert", "(", "args", ".",...
https://github.com/huggingface/transformers/blob/623b4f7c63f60cce917677ee704d6c93ee960b4b/examples/research_projects/distillation/train.py#L55-L82
Freeseer/freeseer
73c53ab6f1f22dfc89a782728f3b3070ee71b690
src/freeseer/frontend/record/record.py
python
RecordApp.load_backend
(self)
Prepares the backend for recording
Prepares the backend for recording
[ "Prepares", "the", "backend", "for", "recording" ]
def load_backend(self): """Prepares the backend for recording""" if self.current_presentation(): presentation = self.current_presentation() # If current presentation is no existant (empty talk database) # use a default recording name. else: presentation = Presentation(title=unicode("default")) initialized, self.recently_recorded_video = self.controller.load_backend(presentation) if initialized: return True else: return False
[ "def", "load_backend", "(", "self", ")", ":", "if", "self", ".", "current_presentation", "(", ")", ":", "presentation", "=", "self", ".", "current_presentation", "(", ")", "# If current presentation is no existant (empty talk database)", "# use a default recording name.", ...
https://github.com/Freeseer/freeseer/blob/73c53ab6f1f22dfc89a782728f3b3070ee71b690/src/freeseer/frontend/record/record.py#L556-L570
facebookresearch/detectron2
cb92ae1763cd7d3777c243f07749574cdaec6cb8
detectron2/modeling/meta_arch/dense_detector.py
python
DenseDetector.visualize_training
(self, batched_inputs, results)
A function used to visualize ground truth images and final network predictions. It shows ground truth bounding boxes on the original image and up to 20 predicted object bounding boxes on the original image. Args: batched_inputs (list): a list that contains input to the model. results (List[Instances]): a list of #images elements returned by forward_inference().
A function used to visualize ground truth images and final network predictions. It shows ground truth bounding boxes on the original image and up to 20 predicted object bounding boxes on the original image.
[ "A", "function", "used", "to", "visualize", "ground", "truth", "images", "and", "final", "network", "predictions", ".", "It", "shows", "ground", "truth", "bounding", "boxes", "on", "the", "original", "image", "and", "up", "to", "20", "predicted", "object", "...
def visualize_training(self, batched_inputs, results): """ A function used to visualize ground truth images and final network predictions. It shows ground truth bounding boxes on the original image and up to 20 predicted object bounding boxes on the original image. Args: batched_inputs (list): a list that contains input to the model. results (List[Instances]): a list of #images elements returned by forward_inference(). """ from detectron2.utils.visualizer import Visualizer assert len(batched_inputs) == len( results ), "Cannot visualize inputs and results of different sizes" storage = get_event_storage() max_boxes = 20 image_index = 0 # only visualize a single image img = batched_inputs[image_index]["image"] img = convert_image_to_rgb(img.permute(1, 2, 0), self.input_format) v_gt = Visualizer(img, None) v_gt = v_gt.overlay_instances(boxes=batched_inputs[image_index]["instances"].gt_boxes) anno_img = v_gt.get_image() processed_results = detector_postprocess(results[image_index], img.shape[0], img.shape[1]) predicted_boxes = processed_results.pred_boxes.tensor.detach().cpu().numpy() v_pred = Visualizer(img, None) v_pred = v_pred.overlay_instances(boxes=predicted_boxes[0:max_boxes]) prop_img = v_pred.get_image() vis_img = np.vstack((anno_img, prop_img)) vis_img = vis_img.transpose(2, 0, 1) vis_name = f"Top: GT bounding boxes; Bottom: {max_boxes} Highest Scoring Results" storage.put_image(vis_name, vis_img)
[ "def", "visualize_training", "(", "self", ",", "batched_inputs", ",", "results", ")", ":", "from", "detectron2", ".", "utils", ".", "visualizer", "import", "Visualizer", "assert", "len", "(", "batched_inputs", ")", "==", "len", "(", "results", ")", ",", "\"C...
https://github.com/facebookresearch/detectron2/blob/cb92ae1763cd7d3777c243f07749574cdaec6cb8/detectron2/modeling/meta_arch/dense_detector.py#L249-L282
daoluan/decode-Django
d46a858b45b56de48b0355f50dd9e45402d04cfd
Django-1.5.1/django/contrib/gis/db/models/fields.py
python
GeometryField.get_distance
(self, value, lookup_type, connection)
return connection.ops.get_distance(self, value, lookup_type)
Returns a distance number in units of the field. For example, if `D(km=1)` was passed in and the units of the field were in meters, then 1000 would be returned.
Returns a distance number in units of the field. For example, if `D(km=1)` was passed in and the units of the field were in meters, then 1000 would be returned.
[ "Returns", "a", "distance", "number", "in", "units", "of", "the", "field", ".", "For", "example", "if", "D", "(", "km", "=", "1", ")", "was", "passed", "in", "and", "the", "units", "of", "the", "field", "were", "in", "meters", "then", "1000", "would"...
def get_distance(self, value, lookup_type, connection): """ Returns a distance number in units of the field. For example, if `D(km=1)` was passed in and the units of the field were in meters, then 1000 would be returned. """ return connection.ops.get_distance(self, value, lookup_type)
[ "def", "get_distance", "(", "self", ",", "value", ",", "lookup_type", ",", "connection", ")", ":", "return", "connection", ".", "ops", ".", "get_distance", "(", "self", ",", "value", ",", "lookup_type", ")" ]
https://github.com/daoluan/decode-Django/blob/d46a858b45b56de48b0355f50dd9e45402d04cfd/Django-1.5.1/django/contrib/gis/db/models/fields.py#L134-L140
SheffieldML/GPy
bb1bc5088671f9316bc92a46d356734e34c2d5c0
GPy/kern/src/add.py
python
Add.__init__
(self, subkerns, name='sum')
[]
def __init__(self, subkerns, name='sum'): _newkerns = [] for kern in subkerns: if isinstance(kern, Add): for part in kern.parts: #kern.unlink_parameter(part) _newkerns.append(part.copy()) else: _newkerns.append(kern.copy()) super(Add, self).__init__(_newkerns, name) self._exact_psicomp = self._check_exact_psicomp()
[ "def", "__init__", "(", "self", ",", "subkerns", ",", "name", "=", "'sum'", ")", ":", "_newkerns", "=", "[", "]", "for", "kern", "in", "subkerns", ":", "if", "isinstance", "(", "kern", ",", "Add", ")", ":", "for", "part", "in", "kern", ".", "parts"...
https://github.com/SheffieldML/GPy/blob/bb1bc5088671f9316bc92a46d356734e34c2d5c0/GPy/kern/src/add.py#L20-L31
translate/virtaal
8b0a6fbf764ed92cc44a189499dec399c6423761
virtaal/controllers/checkscontroller.py
python
ChecksController.get_check_name
(self, check)
return name
Return the human readable form of the given check name.
Return the human readable form of the given check name.
[ "Return", "the", "human", "readable", "form", "of", "the", "given", "check", "name", "." ]
def get_check_name(self, check): """Return the human readable form of the given check name.""" name = check_names.get(check, None) if not name and check.startswith('check-'): check = check[len('check-'):] name = check_names.get(check, None) if not name: name = check return name
[ "def", "get_check_name", "(", "self", ",", "check", ")", ":", "name", "=", "check_names", ".", "get", "(", "check", ",", "None", ")", "if", "not", "name", "and", "check", ".", "startswith", "(", "'check-'", ")", ":", "check", "=", "check", "[", "len"...
https://github.com/translate/virtaal/blob/8b0a6fbf764ed92cc44a189499dec399c6423761/virtaal/controllers/checkscontroller.py#L214-L222
Tautulli/Tautulli
2410eb33805aaac4bd1c5dad0f71e4f15afaf742
lib/cheroot/wsgi.py
python
Gateway_u0._decode_value
(item)
return k, v.decode('ISO-8859-1')
[]
def _decode_value(item): k, v = item skip_keys = 'REQUEST_URI', 'wsgi.input' if not six.PY2 or not isinstance(v, bytes) or k in skip_keys: return k, v return k, v.decode('ISO-8859-1')
[ "def", "_decode_value", "(", "item", ")", ":", "k", ",", "v", "=", "item", "skip_keys", "=", "'REQUEST_URI'", ",", "'wsgi.input'", "if", "not", "six", ".", "PY2", "or", "not", "isinstance", "(", "v", ",", "bytes", ")", "or", "k", "in", "skip_keys", "...
https://github.com/Tautulli/Tautulli/blob/2410eb33805aaac4bd1c5dad0f71e4f15afaf742/lib/cheroot/wsgi.py#L360-L365
micropython/micropython-lib
cdd260f0792d04a1ded99171b4c7a2582b7856b4
python-stdlib/heapq/heapq.py
python
merge
(*iterables)
Merge multiple sorted inputs into a single sorted output. Similar to sorted(itertools.chain(*iterables)) but returns a generator, does not pull the data into memory all at once, and assumes that each of the input streams is already sorted (smallest to largest). >>> list(merge([1,3,5,7], [0,2,4,8], [5,10,15,20], [], [25])) [0, 1, 2, 3, 4, 5, 5, 7, 8, 10, 15, 20, 25]
Merge multiple sorted inputs into a single sorted output.
[ "Merge", "multiple", "sorted", "inputs", "into", "a", "single", "sorted", "output", "." ]
def merge(*iterables): """Merge multiple sorted inputs into a single sorted output. Similar to sorted(itertools.chain(*iterables)) but returns a generator, does not pull the data into memory all at once, and assumes that each of the input streams is already sorted (smallest to largest). >>> list(merge([1,3,5,7], [0,2,4,8], [5,10,15,20], [], [25])) [0, 1, 2, 3, 4, 5, 5, 7, 8, 10, 15, 20, 25] """ _heappop, _heapreplace, _StopIteration = heappop, heapreplace, StopIteration _len = len h = [] h_append = h.append for itnum, it in enumerate(map(iter, iterables)): try: next = it.__next__ h_append([next(), itnum, next]) except _StopIteration: pass heapify(h) while _len(h) > 1: try: while True: v, itnum, next = s = h[0] yield v s[0] = next() # raises StopIteration when exhausted _heapreplace(h, s) # restore heap condition except _StopIteration: _heappop(h) # remove empty iterator if h: # fast case when only a single iterator remains v, itnum, next = h[0] yield v yield from next.__self__
[ "def", "merge", "(", "*", "iterables", ")", ":", "_heappop", ",", "_heapreplace", ",", "_StopIteration", "=", "heappop", ",", "heapreplace", ",", "StopIteration", "_len", "=", "len", "h", "=", "[", "]", "h_append", "=", "h", ".", "append", "for", "itnum"...
https://github.com/micropython/micropython-lib/blob/cdd260f0792d04a1ded99171b4c7a2582b7856b4/python-stdlib/heapq/heapq.py#L377-L414
ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework
cb692f527e4e819b6c228187c5702d990a180043
external/Scripting Engine/Xenotix Python Scripting Engine/bin/x86/Debug/Lib/zipfile.py
python
ZipFile.close
(self)
Close the file, and for mode "w" and "a" write the ending records.
Close the file, and for mode "w" and "a" write the ending records.
[ "Close", "the", "file", "and", "for", "mode", "w", "and", "a", "write", "the", "ending", "records", "." ]
def close(self): """Close the file, and for mode "w" and "a" write the ending records.""" if self.fp is None: return if self.mode in ("w", "a") and self._didModify: # write ending records count = 0 pos1 = self.fp.tell() for zinfo in self.filelist: # write central directory count = count + 1 dt = zinfo.date_time dosdate = (dt[0] - 1980) << 9 | dt[1] << 5 | dt[2] dostime = dt[3] << 11 | dt[4] << 5 | (dt[5] // 2) extra = [] if zinfo.file_size > ZIP64_LIMIT \ or zinfo.compress_size > ZIP64_LIMIT: extra.append(zinfo.file_size) extra.append(zinfo.compress_size) file_size = 0xffffffff compress_size = 0xffffffff else: file_size = zinfo.file_size compress_size = zinfo.compress_size if zinfo.header_offset > ZIP64_LIMIT: extra.append(zinfo.header_offset) header_offset = 0xffffffffL else: header_offset = zinfo.header_offset extra_data = zinfo.extra if extra: # Append a ZIP64 field to the extra's extra_data = struct.pack( '<HH' + 'Q'*len(extra), 1, 8*len(extra), *extra) + extra_data extract_version = max(45, zinfo.extract_version) create_version = max(45, zinfo.create_version) else: extract_version = zinfo.extract_version create_version = zinfo.create_version try: filename, flag_bits = zinfo._encodeFilenameFlags() centdir = struct.pack(structCentralDir, stringCentralDir, create_version, zinfo.create_system, extract_version, zinfo.reserved, flag_bits, zinfo.compress_type, dostime, dosdate, zinfo.CRC, compress_size, file_size, len(filename), len(extra_data), len(zinfo.comment), 0, zinfo.internal_attr, zinfo.external_attr, header_offset) except DeprecationWarning: print >>sys.stderr, (structCentralDir, stringCentralDir, create_version, zinfo.create_system, extract_version, zinfo.reserved, zinfo.flag_bits, zinfo.compress_type, dostime, dosdate, zinfo.CRC, compress_size, file_size, len(zinfo.filename), len(extra_data), len(zinfo.comment), 0, zinfo.internal_attr, zinfo.external_attr, header_offset) raise self.fp.write(centdir) self.fp.write(filename) self.fp.write(extra_data) self.fp.write(zinfo.comment) pos2 = self.fp.tell() # Write end-of-zip-archive record centDirCount = count centDirSize = pos2 - pos1 centDirOffset = pos1 if (centDirCount >= ZIP_FILECOUNT_LIMIT or centDirOffset > ZIP64_LIMIT or centDirSize > ZIP64_LIMIT): # Need to write the ZIP64 end-of-archive records zip64endrec = struct.pack( structEndArchive64, stringEndArchive64, 44, 45, 45, 0, 0, centDirCount, centDirCount, centDirSize, centDirOffset) self.fp.write(zip64endrec) zip64locrec = struct.pack( structEndArchive64Locator, stringEndArchive64Locator, 0, pos2, 1) self.fp.write(zip64locrec) centDirCount = min(centDirCount, 0xFFFF) centDirSize = min(centDirSize, 0xFFFFFFFF) centDirOffset = min(centDirOffset, 0xFFFFFFFF) # check for valid comment length if len(self.comment) >= ZIP_MAX_COMMENT: if self.debug > 0: msg = 'Archive comment is too long; truncating to %d bytes' \ % ZIP_MAX_COMMENT self.comment = self.comment[:ZIP_MAX_COMMENT] endrec = struct.pack(structEndArchive, stringEndArchive, 0, 0, centDirCount, centDirCount, centDirSize, centDirOffset, len(self.comment)) self.fp.write(endrec) self.fp.write(self.comment) self.fp.flush() if not self._filePassed: self.fp.close() self.fp = None
[ "def", "close", "(", "self", ")", ":", "if", "self", ".", "fp", "is", "None", ":", "return", "if", "self", ".", "mode", "in", "(", "\"w\"", ",", "\"a\"", ")", "and", "self", ".", "_didModify", ":", "# write ending records", "count", "=", "0", "pos1",...
https://github.com/ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework/blob/cb692f527e4e819b6c228187c5702d990a180043/external/Scripting Engine/Xenotix Python Scripting Engine/bin/x86/Debug/Lib/zipfile.py#L1152-L1260
Xavier-Lam/wechat-django
258e193e9ec9558709e889fd105c9bf474b013e6
wechat_django/admin/views/user.py
python
WeChatUserAdmin.has_add_permission
(self, request)
return False
[]
def has_add_permission(self, request): return False
[ "def", "has_add_permission", "(", "self", ",", "request", ")", ":", "return", "False" ]
https://github.com/Xavier-Lam/wechat-django/blob/258e193e9ec9558709e889fd105c9bf474b013e6/wechat_django/admin/views/user.py#L130-L131
pyserial/pyserial-asyncio
44d470181af989fb35fbe5062f47f8eaf5b7939a
serial_asyncio/__init__.py
python
SerialTransport.set_write_buffer_limits
(self, high=None, low=None)
Set the high- and low-water limits for write flow control. These two values control when the protocol’s pause_writing()and resume_writing() methods are called. If specified, the low-water limit must be less than or equal to the high-water limit. Neither high nor low can be negative.
Set the high- and low-water limits for write flow control.
[ "Set", "the", "high", "-", "and", "low", "-", "water", "limits", "for", "write", "flow", "control", "." ]
def set_write_buffer_limits(self, high=None, low=None): """Set the high- and low-water limits for write flow control. These two values control when the protocol’s pause_writing()and resume_writing() methods are called. If specified, the low-water limit must be less than or equal to the high-water limit. Neither high nor low can be negative. """ self._set_write_buffer_limits(high=high, low=low) self._maybe_pause_protocol()
[ "def", "set_write_buffer_limits", "(", "self", ",", "high", "=", "None", ",", "low", "=", "None", ")", ":", "self", ".", "_set_write_buffer_limits", "(", "high", "=", "high", ",", "low", "=", "low", ")", "self", ".", "_maybe_pause_protocol", "(", ")" ]
https://github.com/pyserial/pyserial-asyncio/blob/44d470181af989fb35fbe5062f47f8eaf5b7939a/serial_asyncio/__init__.py#L162-L171
fabioz/PyDev.Debugger
0f8c02a010fe5690405da1dd30ed72326191ce63
pydevd_attach_to_process/winappdbg/system.py
python
System.adjust_privileges
(state, privileges)
Requests or drops privileges. @type state: bool @param state: C{True} to request, C{False} to drop. @type privileges: list(int) @param privileges: Privileges to request or drop. @raise WindowsError: Raises an exception on error.
Requests or drops privileges.
[ "Requests", "or", "drops", "privileges", "." ]
def adjust_privileges(state, privileges): """ Requests or drops privileges. @type state: bool @param state: C{True} to request, C{False} to drop. @type privileges: list(int) @param privileges: Privileges to request or drop. @raise WindowsError: Raises an exception on error. """ with win32.OpenProcessToken(win32.GetCurrentProcess(), win32.TOKEN_ADJUST_PRIVILEGES) as hToken: NewState = ( (priv, state) for priv in privileges ) win32.AdjustTokenPrivileges(hToken, NewState)
[ "def", "adjust_privileges", "(", "state", ",", "privileges", ")", ":", "with", "win32", ".", "OpenProcessToken", "(", "win32", ".", "GetCurrentProcess", "(", ")", ",", "win32", ".", "TOKEN_ADJUST_PRIVILEGES", ")", "as", "hToken", ":", "NewState", "=", "(", "...
https://github.com/fabioz/PyDev.Debugger/blob/0f8c02a010fe5690405da1dd30ed72326191ce63/pydevd_attach_to_process/winappdbg/system.py#L291-L306
hippich/Bitcoin-Poker-Room
b89e8c2df7a57d19d1aa6deff3f6a92ebe8134fa
lib/ppn/pokerengine/pokergame.py
python
PokerGame.canCheck
(self, serial)
return self.highestBetNotFold() <= self.getPlayer(serial).bet
Can check if all bets are equal
Can check if all bets are equal
[ "Can", "check", "if", "all", "bets", "are", "equal" ]
def canCheck(self, serial): """ Can check if all bets are equal """ if self.isBlindAnteRound(): return False return self.highestBetNotFold() <= self.getPlayer(serial).bet
[ "def", "canCheck", "(", "self", ",", "serial", ")", ":", "if", "self", ".", "isBlindAnteRound", "(", ")", ":", "return", "False", "return", "self", ".", "highestBetNotFold", "(", ")", "<=", "self", ".", "getPlayer", "(", "serial", ")", ".", "bet" ]
https://github.com/hippich/Bitcoin-Poker-Room/blob/b89e8c2df7a57d19d1aa6deff3f6a92ebe8134fa/lib/ppn/pokerengine/pokergame.py#L1895-L1901
Kkevsterrr/geneva
36d3585545d4cb3450ea0b166d8d5f20a64ed8d8
plugins/http/plugin.py
python
HTTPPluginRunner.__init__
(self, args)
Marks this plugin as enabled
Marks this plugin as enabled
[ "Marks", "this", "plugin", "as", "enabled" ]
def __init__(self, args): """ Marks this plugin as enabled """ self.enabled = True
[ "def", "__init__", "(", "self", ",", "args", ")", ":", "self", ".", "enabled", "=", "True" ]
https://github.com/Kkevsterrr/geneva/blob/36d3585545d4cb3450ea0b166d8d5f20a64ed8d8/plugins/http/plugin.py#L50-L54
google/tf-quant-finance
8fd723689ebf27ff4bb2bd2acb5f6091c5e07309
tf_quant_finance/datetime/holiday_calendar_factory.py
python
_tensor_is_not_empty
(t)
return bool(t)
Returns whether t is definitely not empty.
Returns whether t is definitely not empty.
[ "Returns", "whether", "t", "is", "definitely", "not", "empty", "." ]
def _tensor_is_not_empty(t): """Returns whether t is definitely not empty.""" # False means either empty or unknown. if t is None: return False if isinstance(t, np.ndarray): return t.size > 0 if isinstance(t, tf.Tensor): num_elem = t.shape.num_elements return num_elem is not None and num_elem > 0 # None means shape is unknown. return bool(t)
[ "def", "_tensor_is_not_empty", "(", "t", ")", ":", "# False means either empty or unknown.", "if", "t", "is", "None", ":", "return", "False", "if", "isinstance", "(", "t", ",", "np", ".", "ndarray", ")", ":", "return", "t", ".", "size", ">", "0", "if", "...
https://github.com/google/tf-quant-finance/blob/8fd723689ebf27ff4bb2bd2acb5f6091c5e07309/tf_quant_finance/datetime/holiday_calendar_factory.py#L96-L106
hkociemba/RubiksCube-TwophaseSolver
e5deb0a9c89bdc1f2db015da7c6c4b4293c9509c
package_src/twophase/cubie.py
python
CubieCube.__eq__
(self, other)
Define equality of two cubie cubes.
Define equality of two cubie cubes.
[ "Define", "equality", "of", "two", "cubie", "cubes", "." ]
def __eq__(self, other): """Define equality of two cubie cubes.""" if self.cp == other.cp and self.co == other.co and self.ep == other.ep and self.eo == other.eo: return True else: return False
[ "def", "__eq__", "(", "self", ",", "other", ")", ":", "if", "self", ".", "cp", "==", "other", ".", "cp", "and", "self", ".", "co", "==", "other", ".", "co", "and", "self", ".", "ep", "==", "other", ".", "ep", "and", "self", ".", "eo", "==", "...
https://github.com/hkociemba/RubiksCube-TwophaseSolver/blob/e5deb0a9c89bdc1f2db015da7c6c4b4293c9509c/package_src/twophase/cubie.py#L94-L99
smart-mobile-software/gitstack
d9fee8f414f202143eb6e620529e8e5539a2af56
python/Lib/codecs.py
python
getincrementaldecoder
(encoding)
return decoder
Lookup up the codec for the given encoding and return its IncrementalDecoder class or factory function. Raises a LookupError in case the encoding cannot be found or the codecs doesn't provide an incremental decoder.
Lookup up the codec for the given encoding and return its IncrementalDecoder class or factory function.
[ "Lookup", "up", "the", "codec", "for", "the", "given", "encoding", "and", "return", "its", "IncrementalDecoder", "class", "or", "factory", "function", "." ]
def getincrementaldecoder(encoding): """ Lookup up the codec for the given encoding and return its IncrementalDecoder class or factory function. Raises a LookupError in case the encoding cannot be found or the codecs doesn't provide an incremental decoder. """ decoder = lookup(encoding).incrementaldecoder if decoder is None: raise LookupError(encoding) return decoder
[ "def", "getincrementaldecoder", "(", "encoding", ")", ":", "decoder", "=", "lookup", "(", "encoding", ")", ".", "incrementaldecoder", "if", "decoder", "is", "None", ":", "raise", "LookupError", "(", "encoding", ")", "return", "decoder" ]
https://github.com/smart-mobile-software/gitstack/blob/d9fee8f414f202143eb6e620529e8e5539a2af56/python/Lib/codecs.py#L962-L974
EasyIME/PIME
0f1eee10169c1cb2eaa0b59a77fa6f931ecb33b3
python/python3/tornado/options.py
python
OptionParser.items
(self)
return [(opt.name, opt.value()) for name, opt in self._options.items()]
An iterable of (name, value) pairs. .. versionadded:: 3.1
An iterable of (name, value) pairs.
[ "An", "iterable", "of", "(", "name", "value", ")", "pairs", "." ]
def items(self) -> Iterable[Tuple[str, Any]]: """An iterable of (name, value) pairs. .. versionadded:: 3.1 """ return [(opt.name, opt.value()) for name, opt in self._options.items()]
[ "def", "items", "(", "self", ")", "->", "Iterable", "[", "Tuple", "[", "str", ",", "Any", "]", "]", ":", "return", "[", "(", "opt", ".", "name", ",", "opt", ".", "value", "(", ")", ")", "for", "name", ",", "opt", "in", "self", ".", "_options", ...
https://github.com/EasyIME/PIME/blob/0f1eee10169c1cb2eaa0b59a77fa6f931ecb33b3/python/python3/tornado/options.py#L173-L178
roytseng-tw/Detectron.pytorch
1b1c4ba58428b7277a45b0dce6cc1bce3744b86a
lib/utils/net.py
python
affine_grid_gen
(rois, input_size, grid_size)
return grid
[]
def affine_grid_gen(rois, input_size, grid_size): rois = rois.detach() x1 = rois[:, 1::4] / 16.0 y1 = rois[:, 2::4] / 16.0 x2 = rois[:, 3::4] / 16.0 y2 = rois[:, 4::4] / 16.0 height = input_size[0] width = input_size[1] zero = Variable(rois.data.new(rois.size(0), 1).zero_()) theta = torch.cat([\ (x2 - x1) / (width - 1), zero, (x1 + x2 - width + 1) / (width - 1), zero, (y2 - y1) / (height - 1), (y1 + y2 - height + 1) / (height - 1)], 1).view(-1, 2, 3) grid = F.affine_grid(theta, torch.Size((rois.size(0), 1, grid_size, grid_size))) return grid
[ "def", "affine_grid_gen", "(", "rois", ",", "input_size", ",", "grid_size", ")", ":", "rois", "=", "rois", ".", "detach", "(", ")", "x1", "=", "rois", "[", ":", ",", "1", ":", ":", "4", "]", "/", "16.0", "y1", "=", "rois", "[", ":", ",", "2", ...
https://github.com/roytseng-tw/Detectron.pytorch/blob/1b1c4ba58428b7277a45b0dce6cc1bce3744b86a/lib/utils/net.py#L110-L132
hydroshare/hydroshare
7ba563b55412f283047fb3ef6da367d41dec58c6
hs_file_types/nc_functions/nc_utils.py
python
get_nc_auxiliary_coordinate_variables
(nc_dataset)
return nc_auxiliary_coordinate_variables
(object) -> dict Return: the netCDF auxiliary coordinate variables Format: {'var_name': var_obj}
(object) -> dict
[ "(", "object", ")", "-", ">", "dict" ]
def get_nc_auxiliary_coordinate_variables(nc_dataset): """ (object) -> dict Return: the netCDF auxiliary coordinate variables Format: {'var_name': var_obj} """ nc_auxiliary_coordinate_variable_namelist = \ get_nc_auxiliary_coordinate_variable_namelist(nc_dataset) nc_auxiliary_coordinate_variables = {} for name in nc_auxiliary_coordinate_variable_namelist: if nc_dataset.variables.get(name, ''): nc_auxiliary_coordinate_variables[name] = nc_dataset.variables[name] return nc_auxiliary_coordinate_variables
[ "def", "get_nc_auxiliary_coordinate_variables", "(", "nc_dataset", ")", ":", "nc_auxiliary_coordinate_variable_namelist", "=", "get_nc_auxiliary_coordinate_variable_namelist", "(", "nc_dataset", ")", "nc_auxiliary_coordinate_variables", "=", "{", "}", "for", "name", "in", "nc_a...
https://github.com/hydroshare/hydroshare/blob/7ba563b55412f283047fb3ef6da367d41dec58c6/hs_file_types/nc_functions/nc_utils.py#L256-L271
atlassian-api/atlassian-python-api
6d8545a790c3aae10b75bdc225fb5c3a0aee44db
atlassian/bitbucket/cloud/repositories/pullRequests.py
python
Build.stopped
(self)
return self.get_data("state") == self.STATE_STOPPED
True if the build was stopped
True if the build was stopped
[ "True", "if", "the", "build", "was", "stopped" ]
def stopped(self): """True if the build was stopped""" return self.get_data("state") == self.STATE_STOPPED
[ "def", "stopped", "(", "self", ")", ":", "return", "self", ".", "get_data", "(", "\"state\"", ")", "==", "self", ".", "STATE_STOPPED" ]
https://github.com/atlassian-api/atlassian-python-api/blob/6d8545a790c3aae10b75bdc225fb5c3a0aee44db/atlassian/bitbucket/cloud/repositories/pullRequests.py#L530-L532
pwnieexpress/pwn_plug_sources
1a23324f5dc2c3de20f9c810269b6a29b2758cad
src/wifitap/scapy.py
python
SndRcvList.__init__
(self, res, name="Results", stats=None)
[]
def __init__(self, res, name="Results", stats=None): PacketList.__init__(self, res, name, stats)
[ "def", "__init__", "(", "self", ",", "res", ",", "name", "=", "\"Results\"", ",", "stats", "=", "None", ")", ":", "PacketList", ".", "__init__", "(", "self", ",", "res", ",", "name", ",", "stats", ")" ]
https://github.com/pwnieexpress/pwn_plug_sources/blob/1a23324f5dc2c3de20f9c810269b6a29b2758cad/src/wifitap/scapy.py#L3189-L3190
vadmium/python-altium
9e3cf5a16150e74ba2b7e6d1f2895e0ce16b9a05
vector/svg.py
python
Renderer.polygon
(self, points, *, offset=None, rotate=None, outline=None, fill=None, width=None)
[]
def polygon(self, points, *, offset=None, rotate=None, outline=None, fill=None, width=None): s = list() for (x, y) in points: s.append("{},{}".format(x, y * self.flip[1])) attrs = {"points": " ".join(s)} style = list() transform = self._offset(offset) if rotate is not None: transform.append("rotate({})".format(rotate)) self._closed(attrs, style, outline, fill, width) self.emptyelement("polygon", attrs, style=style, transform=transform)
[ "def", "polygon", "(", "self", ",", "points", ",", "*", ",", "offset", "=", "None", ",", "rotate", "=", "None", ",", "outline", "=", "None", ",", "fill", "=", "None", ",", "width", "=", "None", ")", ":", "s", "=", "list", "(", ")", "for", "(", ...
https://github.com/vadmium/python-altium/blob/9e3cf5a16150e74ba2b7e6d1f2895e0ce16b9a05/vector/svg.py#L156-L167
securesystemslab/zippy
ff0e84ac99442c2c55fe1d285332cfd4e185e089
zippy/lib-python/3/urllib/request.py
python
Request._parse
(self)
[]
def _parse(self): self.type, rest = splittype(self.full_url) if self.type is None: raise ValueError("unknown url type: %s" % self.full_url) self.host, self.selector = splithost(rest) if self.host: self.host = unquote(self.host)
[ "def", "_parse", "(", "self", ")", ":", "self", ".", "type", ",", "rest", "=", "splittype", "(", "self", ".", "full_url", ")", "if", "self", ".", "type", "is", "None", ":", "raise", "ValueError", "(", "\"unknown url type: %s\"", "%", "self", ".", "full...
https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/lib-python/3/urllib/request.py#L196-L202
IronLanguages/ironpython2
51fdedeeda15727717fb8268a805f71b06c0b9f1
Src/StdLib/Lib/xml/sax/saxutils.py
python
quoteattr
(data, entities={})
return data
Escape and quote an attribute value. Escape &, <, and > in a string of data, then quote it for use as an attribute value. The \" character will be escaped as well, if necessary. You can escape other strings of data by passing a dictionary as the optional entities parameter. The keys and values must all be strings; each key will be replaced with its corresponding value.
Escape and quote an attribute value.
[ "Escape", "and", "quote", "an", "attribute", "value", "." ]
def quoteattr(data, entities={}): """Escape and quote an attribute value. Escape &, <, and > in a string of data, then quote it for use as an attribute value. The \" character will be escaped as well, if necessary. You can escape other strings of data by passing a dictionary as the optional entities parameter. The keys and values must all be strings; each key will be replaced with its corresponding value. """ entities = entities.copy() entities.update({'\n': '&#10;', '\r': '&#13;', '\t':'&#9;'}) data = escape(data, entities) if '"' in data: if "'" in data: data = '"%s"' % data.replace('"', "&quot;") else: data = "'%s'" % data else: data = '"%s"' % data return data
[ "def", "quoteattr", "(", "data", ",", "entities", "=", "{", "}", ")", ":", "entities", "=", "entities", ".", "copy", "(", ")", "entities", ".", "update", "(", "{", "'\\n'", ":", "'&#10;'", ",", "'\\r'", ":", "'&#13;'", ",", "'\\t'", ":", "'&#9;'", ...
https://github.com/IronLanguages/ironpython2/blob/51fdedeeda15727717fb8268a805f71b06c0b9f1/Src/StdLib/Lib/xml/sax/saxutils.py#L53-L74
tensorflow/lingvo
ce10019243d954c3c3ebe739f7589b5eebfdf907
lingvo/core/py_utils.py
python
ReadFileLines
(file_path)
return lines
Read a text file and return the lines. If the file cannot be found at the given path, attempt to load it from the Lingvo package (useful for data dependencies in par files). Args: file_path: path to file, either absolute or relative to the bazel workspace. Returns: A list of lines from the file.
Read a text file and return the lines.
[ "Read", "a", "text", "file", "and", "return", "the", "lines", "." ]
def ReadFileLines(file_path): """Read a text file and return the lines. If the file cannot be found at the given path, attempt to load it from the Lingvo package (useful for data dependencies in par files). Args: file_path: path to file, either absolute or relative to the bazel workspace. Returns: A list of lines from the file. """ if not tf.io.gfile.exists(file_path): try: lines = pkgutil.get_data( 'lingvo', file_path.replace('lingvo/', '', 1)) if lines: lines = lines.splitlines(True) except IOError: # If pkgutil can't find the file, continue and let GFile raise the error. lines = None else: lines = None if not lines: with tf.io.gfile.GFile(file_path, 'r') as f: lines = f.readlines() return lines
[ "def", "ReadFileLines", "(", "file_path", ")", ":", "if", "not", "tf", ".", "io", ".", "gfile", ".", "exists", "(", "file_path", ")", ":", "try", ":", "lines", "=", "pkgutil", ".", "get_data", "(", "'lingvo'", ",", "file_path", ".", "replace", "(", "...
https://github.com/tensorflow/lingvo/blob/ce10019243d954c3c3ebe739f7589b5eebfdf907/lingvo/core/py_utils.py#L4950-L4978
binaryage/drydrop
2f27e15befd247255d89f9120eeee44851b82c4a
dryapp/jinja2/filters.py
python
do_last
(environment, seq)
Return the last item of a sequence.
Return the last item of a sequence.
[ "Return", "the", "last", "item", "of", "a", "sequence", "." ]
def do_last(environment, seq): """Return the last item of a sequence.""" try: return iter(reversed(seq)).next() except StopIteration: return environment.undefined('No last item, sequence was empty.')
[ "def", "do_last", "(", "environment", ",", "seq", ")", ":", "try", ":", "return", "iter", "(", "reversed", "(", "seq", ")", ")", ".", "next", "(", ")", "except", "StopIteration", ":", "return", "environment", ".", "undefined", "(", "'No last item, sequence...
https://github.com/binaryage/drydrop/blob/2f27e15befd247255d89f9120eeee44851b82c4a/dryapp/jinja2/filters.py#L268-L273
viewflow/viewflow
2389bd379a2ab22cc277585df7c09514e273541d
viewflow/nodes/view.py
python
View.__init__
(self, *args, **kwargs)
Instantiate a View node. :keyword assign_view: Overides default AssignView for the node :keyword unassign_view: Overides default UnassignView for the node
Instantiate a View node.
[ "Instantiate", "a", "View", "node", "." ]
def __init__(self, *args, **kwargs): """ Instantiate a View node. :keyword assign_view: Overides default AssignView for the node :keyword unassign_view: Overides default UnassignView for the node """ self._assign_view = kwargs.pop('assign_view', None) self._unassign_view = kwargs.pop('unassign_view', None) self._on_create = None super(View, self).__init__(*args, **kwargs)
[ "def", "__init__", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_assign_view", "=", "kwargs", ".", "pop", "(", "'assign_view'", ",", "None", ")", "self", ".", "_unassign_view", "=", "kwargs", ".", "pop", "(", "'unas...
https://github.com/viewflow/viewflow/blob/2389bd379a2ab22cc277585df7c09514e273541d/viewflow/nodes/view.py#L183-L193
psychopy/psychopy
01b674094f38d0e0bd51c45a6f66f671d7041696
psychopy/experiment/loops.py
python
StairHandler.__init__
(self, exp, name, nReps='50', startVal='', nReversals='', nUp=1, nDown=3, minVal=0, maxVal=1, stepSizes='[4,4,2,2,1]', stepType='db', endPoints=(0, 1), isTrials=True)
@param name: name of the loop e.g. trials @type name: string @param nReps: number of reps (for all conditions) @type nReps:int
[]
def __init__(self, exp, name, nReps='50', startVal='', nReversals='', nUp=1, nDown=3, minVal=0, maxVal=1, stepSizes='[4,4,2,2,1]', stepType='db', endPoints=(0, 1), isTrials=True): """ @param name: name of the loop e.g. trials @type name: string @param nReps: number of reps (for all conditions) @type nReps:int """ super(StairHandler, self).__init__() self.type = 'StairHandler' self.exp = exp self.order = ['name'] # make name come first (others don't matter) self.children = [] self.params = {} self.params['name'] = Param( name, valType='code', hint=_translate("Name of this loop"), label=_localized['Name']) self.params['nReps'] = Param( nReps, valType='num', inputType='spin', label=_localized['nReps'], hint=_translate("(Minimum) number of trials in the staircase")) self.params['start value'] = Param( startVal, valType='num', inputType='single', label=_localized['start value'], hint=_translate("The initial value of the parameter")) self.params['max value'] = Param( maxVal, valType='num', inputType='single', label=_localized['max value'], hint=_translate("The maximum value the parameter can take")) self.params['min value'] = Param( minVal, valType='num', inputType='single', label=_localized['min value'], hint=_translate("The minimum value the parameter can take")) self.params['step sizes'] = Param( stepSizes, valType='list', inputType='single', label=_localized['step sizes'], hint=_translate("The size of the jump at each step (can change" " on each 'reversal')")) self.params['step type'] = Param( stepType, valType='str', inputType='choice', allowedVals=['lin', 'log', 'db'], label=_localized['step type'], hint=_translate("The units of the step size (e.g. 'linear' will" " add/subtract that value each step, whereas " "'log' will ad that many log units)")) self.params['N up'] = Param( nUp, valType='num', inputType='spin', label=_localized['N up'], hint=_translate("The number of 'incorrect' answers before the " "value goes up")) self.params['N down'] = Param( nDown, valType='num', inputType='spin', label=_localized['N down'], hint=_translate("The number of 'correct' answers before the " "value goes down")) self.params['N reversals'] = Param( nReversals, valType='num', inputType='spin', label=_localized['N reversals'], hint=_translate("Minimum number of times the staircase must " "change direction before ending")) # these two are really just for making the dialog easier (they won't # be used to generate code) self.params['loopType'] = Param( 'staircase', valType='str', inputType='choice', allowedVals=['random', 'sequential', 'fullRandom', 'staircase', 'interleaved staircases'], label=_localized['loopType'], hint=_translate("How should the next trial value(s) be chosen?")) # NB this is added for the sake of the loop properties dialog self.params['endPoints'] = Param( list(endPoints), valType='num', inputType='spin', label=_localized['endPoints'], hint=_translate('Where to loop from and to (see values currently' ' shown in the flow view)')) self.params['isTrials'] = Param( isTrials, valType='bool', inputType='bool', updates=None, allowedUpdates=None, label=_localized["Is trials"], hint=_translate("Indicates that this loop generates TRIALS, " "rather than BLOCKS of trials or stimuli within" " a trial. It alters how data files are output"))
[ "def", "__init__", "(", "self", ",", "exp", ",", "name", ",", "nReps", "=", "'50'", ",", "startVal", "=", "''", ",", "nReversals", "=", "''", ",", "nUp", "=", "1", ",", "nDown", "=", "3", ",", "minVal", "=", "0", ",", "maxVal", "=", "1", ",", ...
https://github.com/psychopy/psychopy/blob/01b674094f38d0e0bd51c45a6f66f671d7041696/psychopy/experiment/loops.py#L340-L421
pympler/pympler
8019a883eec547d91ecda6ba12669d4f4504c625
run.py
python
run_unittests
(project_path, dirs=[], coverage=False)
Run unittests for all given test directories. If no tests are given, all unittests will be executed.
Run unittests for all given test directories.
[ "Run", "unittests", "for", "all", "given", "test", "directories", "." ]
def run_unittests(project_path, dirs=[], coverage=False): '''Run unittests for all given test directories. If no tests are given, all unittests will be executed. ''' # run unittests using test/runtest.py *dirs if not coverage: run_command(_Python_path, # use this Python binary os.path.join(project_path, 'test', 'runtest.py'), '-verbose', str(_Verbose + 1), '-clean', '-pre', *dirs) else: run_command(_Coverage, '-x', # use installed coverage tool os.path.join(project_path, 'test', 'runtest.py'), '-verbose', str(_Verbose + 1), '-clean', '-pre', *dirs) # get all modules from pympler source, print summary and make a copy of # each source module with coverage information (mod.py => mod.py,cover) mods = get_files(locations=[_Src_dir], pattern='*.py') run_command(_Coverage, '-r', *mods) # report run_command(_Coverage, '-a', *mods) # annotate coverage_out_file = '.coverage' if (os.path.exists(coverage_out_file) and not os.path.isdir(coverage_out_file)): os.unlink(coverage_out_file)
[ "def", "run_unittests", "(", "project_path", ",", "dirs", "=", "[", "]", ",", "coverage", "=", "False", ")", ":", "# run unittests using test/runtest.py *dirs", "if", "not", "coverage", ":", "run_command", "(", "_Python_path", ",", "# use this Python binary", "os",...
https://github.com/pympler/pympler/blob/8019a883eec547d91ecda6ba12669d4f4504c625/run.py#L146-L171
laramies/theHarvester
bee3174d427c3cc4048200190baca6efef38ce15
theHarvester/discovery/constants.py
python
google_workaround
(visit_url: str)
return correct_html
Function that makes a request on our behalf, if Google starts to block us :param visit_url: Url to scrape :return: Correct html that can be parsed by BS4
Function that makes a request on our behalf, if Google starts to block us :param visit_url: Url to scrape :return: Correct html that can be parsed by BS4
[ "Function", "that", "makes", "a", "request", "on", "our", "behalf", "if", "Google", "starts", "to", "block", "us", ":", "param", "visit_url", ":", "Url", "to", "scrape", ":", "return", ":", "Correct", "html", "that", "can", "be", "parsed", "by", "BS4" ]
async def google_workaround(visit_url: str) -> Union[bool, str]: """ Function that makes a request on our behalf, if Google starts to block us :param visit_url: Url to scrape :return: Correct html that can be parsed by BS4 """ url = 'https://websniffer.cc/' data = { 'Cookie': '', 'url': visit_url, 'submit': 'Submit', 'type': 'GET&http=1.1', 'uak': str(random.randint(4, 8)) # select random UA to send to Google } returned_html = await AsyncFetcher.post_fetch(url, headers={'User-Agent': Core.get_user_agent()}, data=data) returned_html = "This page appears when Google automatically detects requests coming from your computer network" \ if returned_html == "" else returned_html[0] returned_html = "" if 'Please Wait... | Cloudflare' in returned_html else returned_html if len(returned_html) == 0 or await search(returned_html) or '&lt;html' not in returned_html: # indicates that google is serving workaround a captcha # That means we will try out second option which will utilize proxies return True # the html we get is malformed for BS4 as there are no greater than or less than signs if '&lt;html&gt;' in returned_html: start_index = returned_html.index('&lt;html&gt;') else: start_index = returned_html.index('&lt;html') end_index = returned_html.index('&lt;/html&gt;') + 1 correct_html = returned_html[start_index:end_index] # Slice list to get the response's html correct_html = ''.join([ch.strip().replace('&lt;', '<').replace('&gt;', '>') for ch in correct_html]) return correct_html
[ "async", "def", "google_workaround", "(", "visit_url", ":", "str", ")", "->", "Union", "[", "bool", ",", "str", "]", ":", "url", "=", "'https://websniffer.cc/'", "data", "=", "{", "'Cookie'", ":", "''", ",", "'url'", ":", "visit_url", ",", "'submit'", ":...
https://github.com/laramies/theHarvester/blob/bee3174d427c3cc4048200190baca6efef38ce15/theHarvester/discovery/constants.py#L71-L105
TUDelft-CNS-ATM/bluesky
55a538a3cd936f33cff9df650c38924aa97557b1
bluesky/tools/misc.py
python
txt2lon
(lontxt)
return lon
txt2lat: input txt: N52'14'13.5 or N52
txt2lat: input txt: N52'14'13.5 or N52
[ "txt2lat", ":", "input", "txt", ":", "N52", "14", "13", ".", "5", "or", "N52" ]
def txt2lon(lontxt): """txt2lat: input txt: N52'14'13.5 or N52""" # It should first be checked if lontxt is a regular float, to avoid removing # the 'e' in a scientific-notation number. try: lon = float(lontxt) # Leading E will trigger error ansd means simply East,just as W = West = Negative except ValueError: txt = lontxt.upper().replace("E", "").replace("W", "-") # East positive, West negative neg = txt.count("-") > 0 # Use of "'" and '"' as delimiter for degrees/minutes/seconds # (also accept degree symbol chr(176)). Also "W002'" if txt.count("'") > 0 or txt.count('"') or txt.count(chr(176))> 0: # replace " or degree symbol and by a ' txt = txt.replace('"', "'").replace(chr(176),"'") degs = txt.split("'") div = 1 lon = 0.0 if neg: f = -1. else: f = 1. for xtxt in degs: if len(xtxt)>0.0: try: lon = lon + f * abs(float(xtxt)) / float(div) except ValueError: print("txt2lon value error:",lontxt) return 0.0 div = div * 60 else: # Cope with "W65"without "'" or '"', also "-65" or "--65" try: neg = txt.count("-") > 0 if neg: f = -1. else: f = 1. lon = f*abs(float(txt)) except ValueError: print("txt2lon value error:",lontxt) return 0.0 return lon
[ "def", "txt2lon", "(", "lontxt", ")", ":", "# It should first be checked if lontxt is a regular float, to avoid removing", "# the 'e' in a scientific-notation number.", "try", ":", "lon", "=", "float", "(", "lontxt", ")", "# Leading E will trigger error ansd means simply East,just as...
https://github.com/TUDelft-CNS-ATM/bluesky/blob/55a538a3cd936f33cff9df650c38924aa97557b1/bluesky/tools/misc.py#L240-L286
sabnzbd/sabnzbd
52d21e94d3cc6e30764a833fe2a256783d1a8931
sabnzbd/assembler.py
python
is_cloaked
(nzo: NzbObject, path: str, names: List[str])
return False
Return True if this is likely to be a cloaked encrypted post
Return True if this is likely to be a cloaked encrypted post
[ "Return", "True", "if", "this", "is", "likely", "to", "be", "a", "cloaked", "encrypted", "post" ]
def is_cloaked(nzo: NzbObject, path: str, names: List[str]) -> bool: """Return True if this is likely to be a cloaked encrypted post""" fname = os.path.splitext(get_filename(path.lower()))[0] for name in names: name = get_filename(name.lower()) name, ext = os.path.splitext(name) if ( ext == ".rar" and fname.startswith(name) and (len(fname) - len(name)) < 8 and len(names) < 3 and not RE_SUBS.search(fname) ): # Only warn once if nzo.encrypted == 0: logging.warning( T('Job "%s" is probably encrypted due to RAR with same name inside this RAR'), nzo.final_name ) nzo.encrypted = 1 return True elif "password" in name and ext not in SAFE_EXTS: # Only warn once if nzo.encrypted == 0: logging.warning(T('Job "%s" is probably encrypted: "password" in filename "%s"'), nzo.final_name, name) nzo.encrypted = 1 return True return False
[ "def", "is_cloaked", "(", "nzo", ":", "NzbObject", ",", "path", ":", "str", ",", "names", ":", "List", "[", "str", "]", ")", "->", "bool", ":", "fname", "=", "os", ".", "path", ".", "splitext", "(", "get_filename", "(", "path", ".", "lower", "(", ...
https://github.com/sabnzbd/sabnzbd/blob/52d21e94d3cc6e30764a833fe2a256783d1a8931/sabnzbd/assembler.py#L256-L282
lyl8213/Plate_Recognition-LPRnet
80e38c060e2b5c934f2ed6ec2ad254df1c0e398f
LPRtf3.py
python
sparse_tuple_from
(sequences, dtype=np.int32)
return indices, values, shape
Create a sparse representention of x. Args: sequences: a list of lists of type dtype where each element is a sequence Returns: A tuple with (indices, values, shape)
Create a sparse representention of x. Args: sequences: a list of lists of type dtype where each element is a sequence Returns: A tuple with (indices, values, shape)
[ "Create", "a", "sparse", "representention", "of", "x", ".", "Args", ":", "sequences", ":", "a", "list", "of", "lists", "of", "type", "dtype", "where", "each", "element", "is", "a", "sequence", "Returns", ":", "A", "tuple", "with", "(", "indices", "values...
def sparse_tuple_from(sequences, dtype=np.int32): """ Create a sparse representention of x. Args: sequences: a list of lists of type dtype where each element is a sequence Returns: A tuple with (indices, values, shape) """ indices = [] values = [] for n, seq in enumerate(sequences): indices.extend(zip([n] * len(seq), range(len(seq)))) values.extend(seq) indices = np.asarray(indices, dtype=np.int64) values = np.asarray(values, dtype=dtype) shape = np.asarray([len(sequences), np.asarray(indices).max(0)[1] + 1], dtype=np.int64) return indices, values, shape
[ "def", "sparse_tuple_from", "(", "sequences", ",", "dtype", "=", "np", ".", "int32", ")", ":", "indices", "=", "[", "]", "values", "=", "[", "]", "for", "n", ",", "seq", "in", "enumerate", "(", "sequences", ")", ":", "indices", ".", "extend", "(", ...
https://github.com/lyl8213/Plate_Recognition-LPRnet/blob/80e38c060e2b5c934f2ed6ec2ad254df1c0e398f/LPRtf3.py#L130-L149
scikit-learn/scikit-learn
1d1aadd0711b87d2a11c80aad15df6f8cf156712
sklearn/utils/extmath.py
python
squared_norm
(x)
return np.dot(x, x)
Squared Euclidean or Frobenius norm of x. Faster than norm(x) ** 2. Parameters ---------- x : array-like Returns ------- float The Euclidean norm when x is a vector, the Frobenius norm when x is a matrix (2-d array).
Squared Euclidean or Frobenius norm of x.
[ "Squared", "Euclidean", "or", "Frobenius", "norm", "of", "x", "." ]
def squared_norm(x): """Squared Euclidean or Frobenius norm of x. Faster than norm(x) ** 2. Parameters ---------- x : array-like Returns ------- float The Euclidean norm when x is a vector, the Frobenius norm when x is a matrix (2-d array). """ x = np.ravel(x, order="K") if np.issubdtype(x.dtype, np.integer): warnings.warn( "Array type is integer, np.dot may overflow. " "Data should be float type to avoid this issue", UserWarning, ) return np.dot(x, x)
[ "def", "squared_norm", "(", "x", ")", ":", "x", "=", "np", ".", "ravel", "(", "x", ",", "order", "=", "\"K\"", ")", "if", "np", ".", "issubdtype", "(", "x", ".", "dtype", ",", "np", ".", "integer", ")", ":", "warnings", ".", "warn", "(", "\"Arr...
https://github.com/scikit-learn/scikit-learn/blob/1d1aadd0711b87d2a11c80aad15df6f8cf156712/sklearn/utils/extmath.py#L26-L48
whipper-team/whipper
18a41b6c2880e577f9f1d7b1b6e7df0be7371378
whipper/extern/task/task.py
python
Task.start
(self, runner)
Start the task. Subclasses should chain up to me at the beginning. Subclass implementations should raise exceptions immediately in case of failure (using set(AndRaise)Exception) first, or do it later using those methods. If start doesn't raise an exception, the task should run until complete, or ``setException()`` and ``stop()``.
Start the task.
[ "Start", "the", "task", "." ]
def start(self, runner): """ Start the task. Subclasses should chain up to me at the beginning. Subclass implementations should raise exceptions immediately in case of failure (using set(AndRaise)Exception) first, or do it later using those methods. If start doesn't raise an exception, the task should run until complete, or ``setException()`` and ``stop()``. """ self.debug('starting') self.setProgress(self.progress) self.running = True self.runner = runner self._notifyListeners('started')
[ "def", "start", "(", "self", ",", "runner", ")", ":", "self", ".", "debug", "(", "'starting'", ")", "self", ".", "setProgress", "(", "self", ".", "progress", ")", "self", ".", "running", "=", "True", "self", ".", "runner", "=", "runner", "self", ".",...
https://github.com/whipper-team/whipper/blob/18a41b6c2880e577f9f1d7b1b6e7df0be7371378/whipper/extern/task/task.py#L117-L134
Source-Python-Dev-Team/Source.Python
d0ffd8ccbd1e9923c9bc44936f20613c1c76b7fb
addons/source-python/packages/source-python/weapons/restrictions.py
python
WeaponRestrictionHandler._unload_instance
(self)
Remove the instance from the manager.
Remove the instance from the manager.
[ "Remove", "the", "instance", "from", "the", "manager", "." ]
def _unload_instance(self): """Remove the instance from the manager.""" weapon_restriction_manager.remove_handler(self)
[ "def", "_unload_instance", "(", "self", ")", ":", "weapon_restriction_manager", ".", "remove_handler", "(", "self", ")" ]
https://github.com/Source-Python-Dev-Team/Source.Python/blob/d0ffd8ccbd1e9923c9bc44936f20613c1c76b7fb/addons/source-python/packages/source-python/weapons/restrictions.py#L372-L374
vlachoudis/bCNC
67126b4894dabf6579baf47af8d0f9b7de35e6e3
bCNC/ControlPage.py
python
abcDROFrame.setC0
(self, event=None)
[]
def setC0(self, event=None): self.app.mcontrol._wcsSet(None,None,None,None,None,"0")
[ "def", "setC0", "(", "self", ",", "event", "=", "None", ")", ":", "self", ".", "app", ".", "mcontrol", ".", "_wcsSet", "(", "None", ",", "None", ",", "None", ",", "None", ",", "None", ",", "\"0\"", ")" ]
https://github.com/vlachoudis/bCNC/blob/67126b4894dabf6579baf47af8d0f9b7de35e6e3/bCNC/ControlPage.py#L629-L630
PaddlePaddle/PGL
e48545f2814523c777b8a9a9188bf5a7f00d6e52
legacy/pgl/graph.py
python
Graph.outdegree
(self, nodes=None)
Return the outdegree of the given nodes. This function will return outdegree of given nodes. Args: nodes: Return the outdegree of given nodes, if nodes is None, return outdegree for all nodes Return: A numpy.array as the given nodes' outdegree.
Return the outdegree of the given nodes.
[ "Return", "the", "outdegree", "of", "the", "given", "nodes", "." ]
def outdegree(self, nodes=None): """Return the outdegree of the given nodes. This function will return outdegree of given nodes. Args: nodes: Return the outdegree of given nodes, if nodes is None, return outdegree for all nodes Return: A numpy.array as the given nodes' outdegree. """ if nodes is None: return self.adj_src_index.degree else: return self.adj_src_index.degree[nodes]
[ "def", "outdegree", "(", "self", ",", "nodes", "=", "None", ")", ":", "if", "nodes", "is", "None", ":", "return", "self", ".", "adj_src_index", ".", "degree", "else", ":", "return", "self", ".", "adj_src_index", ".", "degree", "[", "nodes", "]" ]
https://github.com/PaddlePaddle/PGL/blob/e48545f2814523c777b8a9a9188bf5a7f00d6e52/legacy/pgl/graph.py#L283-L298
securesystemslab/zippy
ff0e84ac99442c2c55fe1d285332cfd4e185e089
zippy/benchmarks/src/benchmarks/sympy/sympy/galgebra/ncutil.py
python
multilinear_product
(expr, fct)
If a sympy 'Expr' is of the form: expr = expr_i1i2...irj*a_i1*a_i2*...*a_ir or expr_0 where all the a_i are noncommuting symbols in basis and the expr's are commuting expressions then multilinear_product(expr) = expr_i1i2...ir*fct(a_i1, a_i2, ..., a_ir) bilinear_product(expr_0) = expr_0 where fct() is defined for r <= n the total number of bases
If a sympy 'Expr' is of the form:
[ "If", "a", "sympy", "Expr", "is", "of", "the", "form", ":" ]
def multilinear_product(expr, fct): """ If a sympy 'Expr' is of the form: expr = expr_i1i2...irj*a_i1*a_i2*...*a_ir or expr_0 where all the a_i are noncommuting symbols in basis and the expr's are commuting expressions then multilinear_product(expr) = expr_i1i2...ir*fct(a_i1, a_i2, ..., a_ir) bilinear_product(expr_0) = expr_0 where fct() is defined for r <= n the total number of bases """ if expr.is_commutative: # no bases in expr return expr if isinstance(expr, Mul): # bases in expr (coefs, bases) = expr.args_cnc() if len(coefs) == 0: # expr_ij = 1 coefs = [S.One] coef = Mul(*tuple(coefs)) new_bases = [] for base in bases: if isinstance(base, Pow): args = base.args new_bases += args[1] * [args[0]] else: new_bases.append(base) return coef * fct(new_bases)
[ "def", "multilinear_product", "(", "expr", ",", "fct", ")", ":", "if", "expr", ".", "is_commutative", ":", "# no bases in expr", "return", "expr", "if", "isinstance", "(", "expr", ",", "Mul", ")", ":", "# bases in expr", "(", "coefs", ",", "bases", ")", "=...
https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/benchmarks/src/benchmarks/sympy/sympy/galgebra/ncutil.py#L282-L312
tensorflow/tfx
b4a6b83269815ed12ba9df9e9154c7376fef2ea0
tfx/components/trainer/rewriting/rewriter.py
python
BaseRewriter._post_rewrite_validate
(self, rewritten_model: ModelDescription)
Perform post-rewrite validation. Args: rewritten_model: A `ModelDescription` object describing the location and type of the rewritten output. Raises: ValueError: If the rewritten model is not valid.
Perform post-rewrite validation.
[ "Perform", "post", "-", "rewrite", "validation", "." ]
def _post_rewrite_validate(self, rewritten_model: ModelDescription): """Perform post-rewrite validation. Args: rewritten_model: A `ModelDescription` object describing the location and type of the rewritten output. Raises: ValueError: If the rewritten model is not valid. """ pass
[ "def", "_post_rewrite_validate", "(", "self", ",", "rewritten_model", ":", "ModelDescription", ")", ":", "pass" ]
https://github.com/tensorflow/tfx/blob/b4a6b83269815ed12ba9df9e9154c7376fef2ea0/tfx/components/trainer/rewriting/rewriter.py#L72-L82
oilshell/oil
94388e7d44a9ad879b12615f6203b38596b5a2d3
Python-2.7.13/Lib/plat-freebsd8/IN.py
python
in_nullhost
(x)
return ((x).s_addr == INADDR_ANY)
[]
def in_nullhost(x): return ((x).s_addr == INADDR_ANY)
[ "def", "in_nullhost", "(", "x", ")", ":", "return", "(", "(", "x", ")", ".", "s_addr", "==", "INADDR_ANY", ")" ]
https://github.com/oilshell/oil/blob/94388e7d44a9ad879b12615f6203b38596b5a2d3/Python-2.7.13/Lib/plat-freebsd8/IN.py#L386-L386
open-io/oio-sds
16041950b6056a55d5ce7ca77795defe6dfa6c61
oio/common/tool.py
python
Tool.tasks_res_from_res_event
(res_event)
Convert the result event into a list (generator) of tasks result.
Convert the result event into a list (generator) of tasks result.
[ "Convert", "the", "result", "event", "into", "a", "list", "(", "generator", ")", "of", "tasks", "result", "." ]
def tasks_res_from_res_event(res_event): """ Convert the result event into a list (generator) of tasks result. """ raise NotImplementedError()
[ "def", "tasks_res_from_res_event", "(", "res_event", ")", ":", "raise", "NotImplementedError", "(", ")" ]
https://github.com/open-io/oio-sds/blob/16041950b6056a55d5ce7ca77795defe6dfa6c61/oio/common/tool.py#L110-L114
intrig-unicamp/mininet-wifi
3c8a8f63bd4aa043aa9c1ad16f304dec2916f5ba
mn_wifi/sumo/traci/_lane.py
python
LaneDomain.getMaxSpeed
(self, laneID)
return self._getUniversal(tc.VAR_MAXSPEED, laneID)
getMaxSpeed(string) -> double Returns the maximum allowed speed on the lane in m/s.
getMaxSpeed(string) -> double Returns the maximum allowed speed on the lane in m/s.
[ "getMaxSpeed", "(", "string", ")", "-", ">", "double", "Returns", "the", "maximum", "allowed", "speed", "on", "the", "lane", "in", "m", "/", "s", "." ]
def getMaxSpeed(self, laneID): """getMaxSpeed(string) -> double Returns the maximum allowed speed on the lane in m/s. """ return self._getUniversal(tc.VAR_MAXSPEED, laneID)
[ "def", "getMaxSpeed", "(", "self", ",", "laneID", ")", ":", "return", "self", ".", "_getUniversal", "(", "tc", ".", "VAR_MAXSPEED", ",", "laneID", ")" ]
https://github.com/intrig-unicamp/mininet-wifi/blob/3c8a8f63bd4aa043aa9c1ad16f304dec2916f5ba/mn_wifi/sumo/traci/_lane.py#L91-L95
wxWidgets/Phoenix
b2199e299a6ca6d866aa6f3d0888499136ead9d6
wx/lib/agw/cubecolourdialog.py
python
CustomPanel.OnSize
(self, event)
Handles the ``wx.EVT_SIZE`` for :class:`CustomPanel`. :param `event`: a :class:`wx.SizeEvent` event to be processed.
Handles the ``wx.EVT_SIZE`` for :class:`CustomPanel`.
[ "Handles", "the", "wx", ".", "EVT_SIZE", "for", ":", "class", ":", "CustomPanel", "." ]
def OnSize(self, event): """ Handles the ``wx.EVT_SIZE`` for :class:`CustomPanel`. :param `event`: a :class:`wx.SizeEvent` event to be processed. """ self.Refresh()
[ "def", "OnSize", "(", "self", ",", "event", ")", ":", "self", ".", "Refresh", "(", ")" ]
https://github.com/wxWidgets/Phoenix/blob/b2199e299a6ca6d866aa6f3d0888499136ead9d6/wx/lib/agw/cubecolourdialog.py#L2718-L2725
pykalman/pykalman
8d3f8e498b64d902016a0216bf2bcc8b262d917b
pykalman/sqrt/unscented.py
python
_unscented_transform
(points, f=None, points_noise=None, sigma2_noise=None)
return (points_pred, moments_pred)
Apply the Unscented Transform. Parameters ========== points : [n_points, n_dim_1] array points representing state to pass through `f` f : [n_dim_1, n_dim_3] -> [n_dim_2] function function to apply pass all points through points_noise : [n_points, n_dim_3] array points representing noise to pass through `f`, if any. sigma2_noise : [n_dim_2, n_dim_2] array square root of covariance matrix for additive noise Returns ======= points_pred : [n_points, n_dim_2] array points passed through f mu_pred : [n_dim_2] array empirical mean sigma2_pred : [n_dim_2, n_dim_2] array R s.t. R' R = empirical covariance
Apply the Unscented Transform.
[ "Apply", "the", "Unscented", "Transform", "." ]
def _unscented_transform(points, f=None, points_noise=None, sigma2_noise=None): '''Apply the Unscented Transform. Parameters ========== points : [n_points, n_dim_1] array points representing state to pass through `f` f : [n_dim_1, n_dim_3] -> [n_dim_2] function function to apply pass all points through points_noise : [n_points, n_dim_3] array points representing noise to pass through `f`, if any. sigma2_noise : [n_dim_2, n_dim_2] array square root of covariance matrix for additive noise Returns ======= points_pred : [n_points, n_dim_2] array points passed through f mu_pred : [n_dim_2] array empirical mean sigma2_pred : [n_dim_2, n_dim_2] array R s.t. R' R = empirical covariance ''' n_points, n_dim_state = points.points.shape (points, weights_mean, weights_covariance) = points # propagate points through f. Each column is a sample point if f is not None: if points_noise is None: points_pred = [f(points[i]) for i in range(n_points)] else: points_pred = [f(points[i], points_noise[i]) for i in range(n_points)] else: points_pred = points # make each row a predicted point points_pred = np.vstack(points_pred) points_pred = SigmaPoints(points_pred, weights_mean, weights_covariance) # calculate approximate mean, covariance moments_pred = points2moments( points_pred, sigma2_noise=sigma2_noise ) return (points_pred, moments_pred)
[ "def", "_unscented_transform", "(", "points", ",", "f", "=", "None", ",", "points_noise", "=", "None", ",", "sigma2_noise", "=", "None", ")", ":", "n_points", ",", "n_dim_state", "=", "points", ".", "points", ".", "shape", "(", "points", ",", "weights_mean...
https://github.com/pykalman/pykalman/blob/8d3f8e498b64d902016a0216bf2bcc8b262d917b/pykalman/sqrt/unscented.py#L207-L251
scikit-learn/scikit-learn
1d1aadd0711b87d2a11c80aad15df6f8cf156712
sklearn/ensemble/_gb.py
python
BaseGradientBoosting._check_params
(self)
Check validity of parameters and raise ValueError if not valid.
Check validity of parameters and raise ValueError if not valid.
[ "Check", "validity", "of", "parameters", "and", "raise", "ValueError", "if", "not", "valid", "." ]
def _check_params(self): """Check validity of parameters and raise ValueError if not valid.""" if self.n_estimators <= 0: raise ValueError( "n_estimators must be greater than 0 but was %r" % self.n_estimators ) if self.learning_rate <= 0.0: raise ValueError( "learning_rate must be greater than 0 but was %r" % self.learning_rate ) if ( self.loss not in self._SUPPORTED_LOSS or self.loss not in _gb_losses.LOSS_FUNCTIONS ): raise ValueError("Loss '{0:s}' not supported. ".format(self.loss)) # TODO: Remove in v1.2 if self.loss == "ls": warnings.warn( "The loss 'ls' was deprecated in v1.0 and " "will be removed in version 1.2. Use 'squared_error'" " which is equivalent.", FutureWarning, ) elif self.loss == "lad": warnings.warn( "The loss 'lad' was deprecated in v1.0 and " "will be removed in version 1.2. Use " "'absolute_error' which is equivalent.", FutureWarning, ) if self.loss == "deviance": loss_class = ( _gb_losses.MultinomialDeviance if len(self.classes_) > 2 else _gb_losses.BinomialDeviance ) else: loss_class = _gb_losses.LOSS_FUNCTIONS[self.loss] if is_classifier(self): self.loss_ = loss_class(self.n_classes_) elif self.loss in ("huber", "quantile"): self.loss_ = loss_class(self.alpha) else: self.loss_ = loss_class() if not (0.0 < self.subsample <= 1.0): raise ValueError("subsample must be in (0,1] but was %r" % self.subsample) if self.init is not None: # init must be an estimator or 'zero' if isinstance(self.init, BaseEstimator): self.loss_.check_init_estimator(self.init) elif not (isinstance(self.init, str) and self.init == "zero"): raise ValueError( "The init parameter must be an estimator or 'zero'. " "Got init={}".format(self.init) ) if not (0.0 < self.alpha < 1.0): raise ValueError("alpha must be in (0.0, 1.0) but was %r" % self.alpha) if isinstance(self.max_features, str): if self.max_features == "auto": if is_classifier(self): max_features = max(1, int(np.sqrt(self.n_features_in_))) else: max_features = self.n_features_in_ elif self.max_features == "sqrt": max_features = max(1, int(np.sqrt(self.n_features_in_))) elif self.max_features == "log2": max_features = max(1, int(np.log2(self.n_features_in_))) else: raise ValueError( "Invalid value for max_features: %r. " "Allowed string values are 'auto', 'sqrt' " "or 'log2'." % self.max_features ) elif self.max_features is None: max_features = self.n_features_in_ elif isinstance(self.max_features, numbers.Integral): max_features = self.max_features else: # float if 0.0 < self.max_features <= 1.0: max_features = max(int(self.max_features * self.n_features_in_), 1) else: raise ValueError("max_features must be in (0, n_features]") self.max_features_ = max_features if not isinstance(self.n_iter_no_change, (numbers.Integral, type(None))): raise ValueError( "n_iter_no_change should either be None or an integer. %r was passed" % self.n_iter_no_change )
[ "def", "_check_params", "(", "self", ")", ":", "if", "self", ".", "n_estimators", "<=", "0", ":", "raise", "ValueError", "(", "\"n_estimators must be greater than 0 but was %r\"", "%", "self", ".", "n_estimators", ")", "if", "self", ".", "learning_rate", "<=", "...
https://github.com/scikit-learn/scikit-learn/blob/1d1aadd0711b87d2a11c80aad15df6f8cf156712/sklearn/ensemble/_gb.py#L266-L365
eBay/accelerator
218d9a5e4451ac72b9e65df6c5b32e37d25136c8
accelerator/extras.py
python
_ListTypePreserver.__radd__
(self, other)
return self.__class__(list.__add__(other, self))
[]
def __radd__(self, other): if not isinstance(other, list): return NotImplemented return self.__class__(list.__add__(other, self))
[ "def", "__radd__", "(", "self", ",", "other", ")", ":", "if", "not", "isinstance", "(", "other", ",", "list", ")", ":", "return", "NotImplemented", "return", "self", ".", "__class__", "(", "list", ".", "__add__", "(", "other", ",", "self", ")", ")" ]
https://github.com/eBay/accelerator/blob/218d9a5e4451ac72b9e65df6c5b32e37d25136c8/accelerator/extras.py#L379-L382
sherlock-project/sherlock
a3e2f7c214509046c6f92ca4b3a755ef1763afa1
sherlock/sherlock.py
python
sherlock
(username, site_data, query_notify, tor=False, unique_tor=False, proxy=None, timeout=None)
return results_total
Run Sherlock Analysis. Checks for existence of username on various social media sites. Keyword Arguments: username -- String indicating username that report should be created against. site_data -- Dictionary containing all of the site data. query_notify -- Object with base type of QueryNotify(). This will be used to notify the caller about query results. tor -- Boolean indicating whether to use a tor circuit for the requests. unique_tor -- Boolean indicating whether to use a new tor circuit for each request. proxy -- String indicating the proxy URL timeout -- Time in seconds to wait before timing out request. Default is no timeout. Return Value: Dictionary containing results from report. Key of dictionary is the name of the social network site, and the value is another dictionary with the following keys: url_main: URL of main site. url_user: URL of user on site (if account exists). status: QueryResult() object indicating results of test for account existence. http_status: HTTP status code of query which checked for existence on site. response_text: Text that came back from request. May be None if there was an HTTP error when checking for existence.
Run Sherlock Analysis.
[ "Run", "Sherlock", "Analysis", "." ]
def sherlock(username, site_data, query_notify, tor=False, unique_tor=False, proxy=None, timeout=None): """Run Sherlock Analysis. Checks for existence of username on various social media sites. Keyword Arguments: username -- String indicating username that report should be created against. site_data -- Dictionary containing all of the site data. query_notify -- Object with base type of QueryNotify(). This will be used to notify the caller about query results. tor -- Boolean indicating whether to use a tor circuit for the requests. unique_tor -- Boolean indicating whether to use a new tor circuit for each request. proxy -- String indicating the proxy URL timeout -- Time in seconds to wait before timing out request. Default is no timeout. Return Value: Dictionary containing results from report. Key of dictionary is the name of the social network site, and the value is another dictionary with the following keys: url_main: URL of main site. url_user: URL of user on site (if account exists). status: QueryResult() object indicating results of test for account existence. http_status: HTTP status code of query which checked for existence on site. response_text: Text that came back from request. May be None if there was an HTTP error when checking for existence. """ # Notify caller that we are starting the query. query_notify.start(username) # Create session based on request methodology if tor or unique_tor: # Requests using Tor obfuscation underlying_request = TorRequest() underlying_session = underlying_request.session else: # Normal requests underlying_session = requests.session() underlying_request = requests.Request() # Limit number of workers to 20. # This is probably vastly overkill. if len(site_data) >= 20: max_workers=20 else: max_workers=len(site_data) # Create multi-threaded session for all requests. session = SherlockFuturesSession(max_workers=max_workers, session=underlying_session) # Results from analysis of all sites results_total = {} # First create futures for all requests. This allows for the requests to run in parallel for social_network, net_info in site_data.items(): # Results from analysis of this specific site results_site = {} # Record URL of main site results_site["url_main"] = net_info.get("urlMain") # A user agent is needed because some sites don't return the correct # information since they think that we are bots (Which we actually are...) headers = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0", } if "headers" in net_info: # Override/append any extra headers required by a given site. headers.update(net_info["headers"]) # URL of user on site (if it exists) url = interpolate_string(net_info["url"], username) # Don't make request if username is invalid for the site regex_check = net_info.get("regexCheck") if regex_check and re.search(regex_check, username) is None: # No need to do the check at the site: this user name is not allowed. results_site["status"] = QueryResult(username, social_network, url, QueryStatus.ILLEGAL) results_site["url_user"] = "" results_site["http_status"] = "" results_site["response_text"] = "" query_notify.update(results_site["status"]) else: # URL of user on site (if it exists) results_site["url_user"] = url url_probe = net_info.get("urlProbe") request_method = net_info.get("request_method") request_payload = net_info.get("request_payload") request = None if request_method is not None: if request_method == "GET": request = session.get elif request_method == "HEAD": request = session.head elif request_method == "POST": request = session.post elif request_method == "PUT": request = session.put else: raise RuntimeError( f"Unsupported request_method for {url}") if request_payload is not None: request_payload = interpolate_string(request_payload, username) if url_probe is None: # Probe URL is normal one seen by people out on the web. url_probe = url else: # There is a special URL for probing existence separate # from where the user profile normally can be found. url_probe = interpolate_string(url_probe, username) if request is None: if net_info["errorType"] == "status_code": # In most cases when we are detecting by status code, # it is not necessary to get the entire body: we can # detect fine with just the HEAD response. request = session.head else: # Either this detect method needs the content associated # with the GET response, or this specific website will # not respond properly unless we request the whole page. request = session.get if net_info["errorType"] == "response_url": # Site forwards request to a different URL if username not # found. Disallow the redirect so we can capture the # http status from the original URL request. allow_redirects = False else: # Allow whatever redirect that the site wants to do. # The final result of the request will be what is available. allow_redirects = True # This future starts running the request in a new thread, doesn't block the main thread if proxy is not None: proxies = {"http": proxy, "https": proxy} future = request(url=url_probe, headers=headers, proxies=proxies, allow_redirects=allow_redirects, timeout=timeout, json=request_payload ) else: future = request(url=url_probe, headers=headers, allow_redirects=allow_redirects, timeout=timeout, json=request_payload ) # Store future in data for access later net_info["request_future"] = future # Reset identify for tor (if needed) if unique_tor: underlying_request.reset_identity() # Add this site's results into final dictionary with all of the other results. results_total[social_network] = results_site # Open the file containing account links # Core logic: If tor requests, make them here. If multi-threaded requests, wait for responses for social_network, net_info in site_data.items(): # Retrieve results again results_site = results_total.get(social_network) # Retrieve other site information again url = results_site.get("url_user") status = results_site.get("status") if status is not None: # We have already determined the user doesn't exist here continue # Get the expected error type error_type = net_info["errorType"] # Retrieve future and ensure it has finished future = net_info["request_future"] r, error_text, expection_text = get_response(request_future=future, error_type=error_type, social_network=social_network) # Get response time for response of our request. try: response_time = r.elapsed except AttributeError: response_time = None # Attempt to get request information try: http_status = r.status_code except: http_status = "?" try: response_text = r.text.encode(r.encoding or "UTF-8") except: response_text = "" if error_text is not None: result = QueryResult(username, social_network, url, QueryStatus.UNKNOWN, query_time=response_time, context=error_text) elif error_type == "message": # error_flag True denotes no error found in the HTML # error_flag False denotes error found in the HTML error_flag = True errors=net_info.get("errorMsg") # errors will hold the error message # it can be string or list # by insinstance method we can detect that # and handle the case for strings as normal procedure # and if its list we can iterate the errors if isinstance(errors,str): # Checks if the error message is in the HTML # if error is present we will set flag to False if errors in r.text: error_flag = False else: # If it's list, it will iterate all the error message for error in errors: if error in r.text: error_flag = False break if error_flag: result = QueryResult(username, social_network, url, QueryStatus.CLAIMED, query_time=response_time) else: result = QueryResult(username, social_network, url, QueryStatus.AVAILABLE, query_time=response_time) elif error_type == "status_code": # Checks if the status code of the response is 2XX if not r.status_code >= 300 or r.status_code < 200: result = QueryResult(username, social_network, url, QueryStatus.CLAIMED, query_time=response_time) else: result = QueryResult(username, social_network, url, QueryStatus.AVAILABLE, query_time=response_time) elif error_type == "response_url": # For this detection method, we have turned off the redirect. # So, there is no need to check the response URL: it will always # match the request. Instead, we will ensure that the response # code indicates that the request was successful (i.e. no 404, or # forward to some odd redirect). if 200 <= r.status_code < 300: result = QueryResult(username, social_network, url, QueryStatus.CLAIMED, query_time=response_time) else: result = QueryResult(username, social_network, url, QueryStatus.AVAILABLE, query_time=response_time) else: # It should be impossible to ever get here... raise ValueError(f"Unknown Error Type '{error_type}' for " f"site '{social_network}'") # Notify caller about results of query. query_notify.update(result) # Save status of request results_site["status"] = result # Save results from request results_site["http_status"] = http_status results_site["response_text"] = response_text # Add this site's results into final dictionary with all of the other results. results_total[social_network] = results_site # Notify caller that all queries are finished. query_notify.finish() return results_total
[ "def", "sherlock", "(", "username", ",", "site_data", ",", "query_notify", ",", "tor", "=", "False", ",", "unique_tor", "=", "False", ",", "proxy", "=", "None", ",", "timeout", "=", "None", ")", ":", "# Notify caller that we are starting the query.", "query_noti...
https://github.com/sherlock-project/sherlock/blob/a3e2f7c214509046c6f92ca4b3a755ef1763afa1/sherlock/sherlock.py#L143-L451
buke/GreenOdoo
3d8c55d426fb41fdb3f2f5a1533cfe05983ba1df
runtime/python/lib/python2.7/site-packages/ZSI-2.0-py2.7.egg/ZSI/TCtimes.py
python
_localtimezone.dst
(self, dt)
return _zero
datetime -> DST offset in minutes east of UTC.
datetime -> DST offset in minutes east of UTC.
[ "datetime", "-", ">", "DST", "offset", "in", "minutes", "east", "of", "UTC", "." ]
def dst(self, dt): """datetime -> DST offset in minutes east of UTC.""" tt = _localtime(_mktime((dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1))) if tt.tm_isdst > 0: return _dstdiff return _zero
[ "def", "dst", "(", "self", ",", "dt", ")", ":", "tt", "=", "_localtime", "(", "_mktime", "(", "(", "dt", ".", "year", ",", "dt", ".", "month", ",", "dt", ".", "day", ",", "dt", ".", "hour", ",", "dt", ".", "minute", ",", "dt", ".", "second", ...
https://github.com/buke/GreenOdoo/blob/3d8c55d426fb41fdb3f2f5a1533cfe05983ba1df/runtime/python/lib/python2.7/site-packages/ZSI-2.0-py2.7.egg/ZSI/TCtimes.py#L30-L35
vladris/tinkerer
e6459e501ec14094e0448c5b0f628ef8666a3ac9
tinkerer/ext/author.py
python
AuthorDirective.run
(self)
return []
Called when parsing the document.
Called when parsing the document.
[ "Called", "when", "parsing", "the", "document", "." ]
def run(self): ''' Called when parsing the document. ''' env = self.state.document.settings.env # store author in metadata author = " ".join(self.arguments) if author == "default": author = env.config.author env.blog_metadata[env.docname].author = author return []
[ "def", "run", "(", "self", ")", ":", "env", "=", "self", ".", "state", ".", "document", ".", "settings", ".", "env", "# store author in metadata", "author", "=", "\" \"", ".", "join", "(", "self", ".", "arguments", ")", "if", "author", "==", "\"default\"...
https://github.com/vladris/tinkerer/blob/e6459e501ec14094e0448c5b0f628ef8666a3ac9/tinkerer/ext/author.py#L23-L35
ddbourgin/numpy-ml
b0359af5285fbf9699d64fd5ec059493228af03e
numpy_ml/neural_nets/modules/modules.py
python
SkipConnectionConvModule.parameters
(self)
return { "components": { "add3": self.add3.parameters, "conv1": self.conv1.parameters, "conv2": self.conv2.parameters, "conv_skip": self.conv_skip.parameters if hasattr(self, "conv_skip") else None, "batchnorm1": self.batchnorm1.parameters, "batchnorm2": self.batchnorm2.parameters, "batchnorm_skip": self.batchnorm_skip.parameters, } }
A dictionary of the module parameters.
A dictionary of the module parameters.
[ "A", "dictionary", "of", "the", "module", "parameters", "." ]
def parameters(self): """A dictionary of the module parameters.""" return { "components": { "add3": self.add3.parameters, "conv1": self.conv1.parameters, "conv2": self.conv2.parameters, "conv_skip": self.conv_skip.parameters if hasattr(self, "conv_skip") else None, "batchnorm1": self.batchnorm1.parameters, "batchnorm2": self.batchnorm2.parameters, "batchnorm_skip": self.batchnorm_skip.parameters, } }
[ "def", "parameters", "(", "self", ")", ":", "return", "{", "\"components\"", ":", "{", "\"add3\"", ":", "self", ".", "add3", ".", "parameters", ",", "\"conv1\"", ":", "self", ".", "conv1", ".", "parameters", ",", "\"conv2\"", ":", "self", ".", "conv2", ...
https://github.com/ddbourgin/numpy-ml/blob/b0359af5285fbf9699d64fd5ec059493228af03e/numpy_ml/neural_nets/modules/modules.py#L803-L817
artefactual/archivematica
4f4605453d5a8796f6a739fa9664921bdb3418f2
src/dashboard/src/contrib/mcp/client.py
python
MCPClient._rpc_sync_call
(self, ability, data=None, timeout=INFLIGHT_POLL_TIMEOUT)
return payload
Invoke remote method synchronously and with a deadline. When successful, it returns the payload of the response. Otherwise, it raises an exception. ``TimeoutError`` when the deadline was exceeded, ``RPCError`` when the worker failed abruptly, ``RPCServerError`` when the worker returned an error.
Invoke remote method synchronously and with a deadline.
[ "Invoke", "remote", "method", "synchronously", "and", "with", "a", "deadline", "." ]
def _rpc_sync_call(self, ability, data=None, timeout=INFLIGHT_POLL_TIMEOUT): """Invoke remote method synchronously and with a deadline. When successful, it returns the payload of the response. Otherwise, it raises an exception. ``TimeoutError`` when the deadline was exceeded, ``RPCError`` when the worker failed abruptly, ``RPCServerError`` when the worker returned an error. """ if data is None: data = b"" elif "user_id" not in data: data["user_id"] = self.user.id client = gearman.GearmanClient([self.server]) response = client.submit_job( six.ensure_binary(ability), six.moves.cPickle.dumps(data, protocol=0), background=False, wait_until_complete=True, poll_timeout=timeout, ) client.shutdown() if response.state == gearman.JOB_CREATED: raise TimeoutError(timeout) elif response.state != gearman.JOB_COMPLETE: raise RPCError("{} failed (check the logs)".format(ability)) payload = six.moves.cPickle.loads(response.result) if isinstance(payload, dict) and payload.get("error", False): raise RPCServerError(payload) return payload
[ "def", "_rpc_sync_call", "(", "self", ",", "ability", ",", "data", "=", "None", ",", "timeout", "=", "INFLIGHT_POLL_TIMEOUT", ")", ":", "if", "data", "is", "None", ":", "data", "=", "b\"\"", "elif", "\"user_id\"", "not", "in", "data", ":", "data", "[", ...
https://github.com/artefactual/archivematica/blob/4f4605453d5a8796f6a739fa9664921bdb3418f2/src/dashboard/src/contrib/mcp/client.py#L102-L130
imflyn/decoration-design-crawler
bfcbe1b7f1528a63e4d5189d645366fb3ec5bdc6
msic/core/service/bloom_filter_service.py
python
RedisBloomFilter.__init__
(self, redis_client: StrictRedis)
[]
def __init__(self, redis_client: StrictRedis): self.bit_size = 1 << 25 self.seeds = [5, 7, 11, 13, 31, 37, 61] self.redis = redis_client self.hash_dict = [] for i in range(self.seeds.__len__()): self.hash_dict.append(SimpleHash(self.bit_size, self.seeds[i]))
[ "def", "__init__", "(", "self", ",", "redis_client", ":", "StrictRedis", ")", ":", "self", ".", "bit_size", "=", "1", "<<", "25", "self", ".", "seeds", "=", "[", "5", ",", "7", ",", "11", ",", "13", ",", "31", ",", "37", ",", "61", "]", "self",...
https://github.com/imflyn/decoration-design-crawler/blob/bfcbe1b7f1528a63e4d5189d645366fb3ec5bdc6/msic/core/service/bloom_filter_service.py#L17-L23
ym2011/POC-EXP
206b22d3a6b2a172359678df33bbc5b2ad04b6c3
K8/Web-Exp/sqlmap/thirdparty/bottle/bottle.py
python
BaseRequest.script_name
(self)
return '/' + script_name + '/' if script_name else '/'
The initial portion of the URL's `path` that was removed by a higher level (server or routing middleware) before the application was called. This script path is returned with leading and tailing slashes.
The initial portion of the URL's `path` that was removed by a higher level (server or routing middleware) before the application was called. This script path is returned with leading and tailing slashes.
[ "The", "initial", "portion", "of", "the", "URL", "s", "path", "that", "was", "removed", "by", "a", "higher", "level", "(", "server", "or", "routing", "middleware", ")", "before", "the", "application", "was", "called", ".", "This", "script", "path", "is", ...
def script_name(self): """ The initial portion of the URL's `path` that was removed by a higher level (server or routing middleware) before the application was called. This script path is returned with leading and tailing slashes. """ script_name = self.environ.get('SCRIPT_NAME', '').strip('/') return '/' + script_name + '/' if script_name else '/'
[ "def", "script_name", "(", "self", ")", ":", "script_name", "=", "self", ".", "environ", ".", "get", "(", "'SCRIPT_NAME'", ",", "''", ")", ".", "strip", "(", "'/'", ")", "return", "'/'", "+", "script_name", "+", "'/'", "if", "script_name", "else", "'/'...
https://github.com/ym2011/POC-EXP/blob/206b22d3a6b2a172359678df33bbc5b2ad04b6c3/K8/Web-Exp/sqlmap/thirdparty/bottle/bottle.py#L1386-L1392
nextstrain/augur
a004d3f8f0b661fb0fb88cf07a43acc01d74de6a
augur/distance.py
python
get_distances_to_all_pairs
(tree, sequences_by_node_and_gene, distance_map, earliest_date=None, latest_date=None)
return distances_by_node
Calculate distances between each sample in the given sequences and all other samples in previous seasons using the given distance map. Parameters ---------- tree : Bio.Phylo a rooted tree whose node names match the given dictionary of sequences by node and gene sequences_by_node_and_gene : dict nucleotide or amino acid sequences by node name and gene distance_map : dict site-specific and, optionally, sequence-specific distances between two sequences earliest_date, latest_date : pandas.Timestamp earliest or latest date to consider a node for comparison to a given sample; used to define a range of previous seasons relative to the most recent samples in the given tree. Dates are open intervals (inclusive) for interval of previous seasons. The latest date is a closed lower bound on the interval of the current season. Returns ------- dict : distances calculated between each sample in the tree and all samples from previous samples with distances indexed by primary sample name and then past sample name
Calculate distances between each sample in the given sequences and all other samples in previous seasons using the given distance map.
[ "Calculate", "distances", "between", "each", "sample", "in", "the", "given", "sequences", "and", "all", "other", "samples", "in", "previous", "seasons", "using", "the", "given", "distance", "map", "." ]
def get_distances_to_all_pairs(tree, sequences_by_node_and_gene, distance_map, earliest_date=None, latest_date=None): """Calculate distances between each sample in the given sequences and all other samples in previous seasons using the given distance map. Parameters ---------- tree : Bio.Phylo a rooted tree whose node names match the given dictionary of sequences by node and gene sequences_by_node_and_gene : dict nucleotide or amino acid sequences by node name and gene distance_map : dict site-specific and, optionally, sequence-specific distances between two sequences earliest_date, latest_date : pandas.Timestamp earliest or latest date to consider a node for comparison to a given sample; used to define a range of previous seasons relative to the most recent samples in the given tree. Dates are open intervals (inclusive) for interval of previous seasons. The latest date is a closed lower bound on the interval of the current season. Returns ------- dict : distances calculated between each sample in the tree and all samples from previous samples with distances indexed by primary sample name and then past sample name """ if earliest_date is not None: earliest_date = timestamp_to_float(earliest_date) if latest_date is not None: latest_date = timestamp_to_float(latest_date) distances_by_node = {} # Calculate distance between each tip and all tips in previous seasons as # defined by the given latest date threshold. for node in tree.find_clades(terminal=True): # Skip nodes that were sampled on or prior to this date. if latest_date is not None and node.attr["num_date"] < latest_date: continue # Distances between this node and other nodes are indexed by the other # node name. distances_by_node[node.name] = {} # Find all nodes that were sampled prior to the given latest date. for past_node in tree.find_clades(terminal=True): # Calculate distance between current node and the past node. Allow # comparison between any two nodes if an earliest or latest date is # not given. if ((earliest_date is None or past_node.attr["num_date"] >= earliest_date) and (latest_date is None or past_node.attr["num_date"] <= latest_date)): distances_by_node[node.name][past_node.name] = get_distance_between_nodes( sequences_by_node_and_gene[past_node.name], sequences_by_node_and_gene[node.name], distance_map ) return distances_by_node
[ "def", "get_distances_to_all_pairs", "(", "tree", ",", "sequences_by_node_and_gene", ",", "distance_map", ",", "earliest_date", "=", "None", ",", "latest_date", "=", "None", ")", ":", "if", "earliest_date", "is", "not", "None", ":", "earliest_date", "=", "timestam...
https://github.com/nextstrain/augur/blob/a004d3f8f0b661fb0fb88cf07a43acc01d74de6a/augur/distance.py#L560-L624
ManyFace/ExtractDexFromOat
cec0a4230ecdab41188c1ea99fbda8bb6bbc84b2
oatParser/elf64.py
python
Elf64Sym.__init__
(self, buf)
[]
def __init__(self, buf): self.unpack(buf) self.name = ""
[ "def", "__init__", "(", "self", ",", "buf", ")", ":", "self", ".", "unpack", "(", "buf", ")", "self", ".", "name", "=", "\"\"" ]
https://github.com/ManyFace/ExtractDexFromOat/blob/cec0a4230ecdab41188c1ea99fbda8bb6bbc84b2/oatParser/elf64.py#L186-L188
ysymyth/3D-SDN
d7a4519bfd57d4c5d99dbdb6a53a82ba5b66ec9e
geometric/maskrcnn/utils.py
python
Dataset.load_mask
(self, image_id)
return mask, class_ids
Load instance masks for the given image. Different datasets use different ways to store masks. Override this method to load instance masks and return them in the form of am array of binary masks of shape [height, width, instances]. Returns: masks: A bool array of shape [height, width, instance count] with a binary mask per instance. class_ids: a 1D array of class IDs of the instance masks.
Load instance masks for the given image.
[ "Load", "instance", "masks", "for", "the", "given", "image", "." ]
def load_mask(self, image_id): """Load instance masks for the given image. Different datasets use different ways to store masks. Override this method to load instance masks and return them in the form of am array of binary masks of shape [height, width, instances]. Returns: masks: A bool array of shape [height, width, instance count] with a binary mask per instance. class_ids: a 1D array of class IDs of the instance masks. """ # Override this function to load a mask from your dataset. # Otherwise, it returns an empty mask. mask = np.empty([0, 0, 0]) class_ids = np.empty([0], np.int32) return mask, class_ids
[ "def", "load_mask", "(", "self", ",", "image_id", ")", ":", "# Override this function to load a mask from your dataset.", "# Otherwise, it returns an empty mask.", "mask", "=", "np", ".", "empty", "(", "[", "0", ",", "0", ",", "0", "]", ")", "class_ids", "=", "np"...
https://github.com/ysymyth/3D-SDN/blob/d7a4519bfd57d4c5d99dbdb6a53a82ba5b66ec9e/geometric/maskrcnn/utils.py#L253-L269
shlomif/PySolFC
780c399e6f68a95916d84e7e88a067e8fcbec1cc
pysollib/kivy/menubar.py
python
OptionsMenuDialog.buildTree
(self, tv, node)
menu.add_command(label=n_("&Fonts..."), command=self.mOptFonts) menu.add_command(label=n_("&Colors..."), command=self.mOptColors) menu.add_command(label=n_("Time&outs..."), command=self.mOptTimeouts) menu.add_separator()
menu.add_command(label=n_("&Fonts..."), command=self.mOptFonts) menu.add_command(label=n_("&Colors..."), command=self.mOptColors) menu.add_command(label=n_("Time&outs..."), command=self.mOptTimeouts) menu.add_separator()
[ "menu", ".", "add_command", "(", "label", "=", "n_", "(", "&Fonts", "...", ")", "command", "=", "self", ".", "mOptFonts", ")", "menu", ".", "add_command", "(", "label", "=", "n_", "(", "&Colors", "...", ")", "command", "=", "self", ".", "mOptColors", ...
def buildTree(self, tv, node): # ------------------------------------------- # Automatic play settings rg = tv.add_node( LTreeNode(text=_('Automatic play'))) if rg: self.addCheckNode(tv, rg, _('Auto face up'), self.menubar.tkopt.autofaceup, self.menubar.mOptAutoFaceUp) self.addCheckNode(tv, rg, _('Auto drop'), self.menubar.tkopt.autodrop, self.menubar.mOptAutoDrop) self.addCheckNode(tv, rg, _('Auto deal'), self.menubar.tkopt.autodeal, self.menubar.mOptAutoDeal) # submenu.add_separator() self.addCheckNode(tv, rg, _('Quick play'), self.menubar.tkopt.quickplay, self.menubar.mOptQuickPlay) # ------------------------------------------- # Player assistance rg = tv.add_node( LTreeNode(text=_('Assist level'))) if rg: self.addCheckNode(tv, rg, _('Enable undo'), self.menubar.tkopt.undo, self.menubar.mOptEnableUndo) self.addCheckNode(tv, rg, _('Enable bookmarks'), self.menubar.tkopt.bookmarks, self.menubar.mOptEnableBookmarks) self.addCheckNode(tv, rg, _('Enable hint'), self.menubar.tkopt.hint, self.menubar.mOptEnableHint) self.addCheckNode(tv, rg, _('Enable shuffle'), self.menubar.tkopt.shuffle, self.menubar.mOptEnableShuffle) self.addCheckNode(tv, rg, _('Enable highlight piles'), self.menubar.tkopt.highlight_piles, self.menubar.mOptEnableHighlightPiles) self.addCheckNode(tv, rg, _('Enable highlight cards'), self.menubar.tkopt.highlight_cards, self.menubar.mOptEnableHighlightCards) self.addCheckNode(tv, rg, _('Enable highlight same rank'), self.menubar.tkopt.highlight_samerank, self.menubar.mOptEnableHighlightSameRank) self.addCheckNode(tv, rg, _('Highlight no matching'), self.menubar.tkopt.highlight_not_matching, self.menubar.mOptEnableHighlightNotMatching) # submenu.add_separator() self.addCheckNode(tv, rg, _('Show removed tiles (in Mahjongg games)'), self.menubar.tkopt.mahjongg_show_removed, self.menubar.mOptMahjonggShowRemoved) self.addCheckNode(tv, rg, _('Show hint arrow (in Shisen-Sho games)'), self.menubar.tkopt.shisen_show_hint, self.menubar.mOptShisenShowHint) self.addCheckNode(tv, rg, _('Deal all cards (in Accordion type games)'), self.menubar.tkopt.accordion_deal_all, self.menubar.mOptAccordionDealAll) self.addCheckNode(tv, rg, _('Auto-remove first card (in Pegged games)'), self.menubar.tkopt.accordion_deal_all, self.menubar.mOptPeggedAutoRemove) # submenu.add_separator() # ------------------------------------------- # Language options rg = tv.add_node( LTreeNode(text=_('Language'))) if rg: self.addRadioNode(tv, rg, _('Default'), self.menubar.tkopt.language, '', self.menubar.mOptLanguage) self.addRadioNode(tv, rg, _('English'), self.menubar.tkopt.language, 'en', self.menubar.mOptLanguage) self.addRadioNode(tv, rg, _('German'), self.menubar.tkopt.language, 'de', self.menubar.mOptLanguage) self.addRadioNode(tv, rg, _('Italian'), self.menubar.tkopt.language, 'it', self.menubar.mOptLanguage) self.addRadioNode(tv, rg, _('Polish'), self.menubar.tkopt.language, 'pl', self.menubar.mOptLanguage) self.addRadioNode(tv, rg, _('Russian'), self.menubar.tkopt.language, 'ru', self.menubar.mOptLanguage) # ------------------------------------------- # Sound options rg = tv.add_node( LTreeNode(text=_('Sound'))) if rg: self.addCheckNode(tv, rg, _('Enable'), self.menubar.tkopt.sound, self.menubar.mOptSoundDialog) rg1 = tv.add_node( LTreeNode(text=_('Volume')), rg) if rg1: self.addRadioNode(tv, rg1, _('100%'), self.menubar.tkopt.sound_sample_volume, 100, self.menubar.mOptSoundSampleVol) self.addRadioNode(tv, rg1, _('75%'), self.menubar.tkopt.sound_sample_volume, 75, self.menubar.mOptSoundSampleVol) self.addRadioNode(tv, rg1, _('50%'), self.menubar.tkopt.sound_sample_volume, 50, self.menubar.mOptSoundSampleVol) self.addRadioNode(tv, rg1, _('25%'), self.menubar.tkopt.sound_sample_volume, 25, self.menubar.mOptSoundSampleVol) rg1 = tv.add_node( LTreeNode(text=_('Samples')), rg) if rg1: key = 'areyousure' self.addCheckNode( tv, rg1, _('are you sure'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'autodrop' self.addCheckNode( tv, rg1, _('auto drop'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'autoflip' self.addCheckNode( tv, rg1, _('auto flip'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'autopilotlost' self.addCheckNode( tv, rg1, _('auto pilot lost'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'autopilotwon' self.addCheckNode( tv, rg1, _('auto pilot won'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'deal' self.addCheckNode( tv, rg1, _('deal'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'dealwaste' self.addCheckNode( tv, rg1, _('deal waste'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'droppair' self.addCheckNode( tv, rg1, _('drop pair'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'drop' self.addCheckNode( tv, rg1, _('drop'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'flip' self.addCheckNode( tv, rg1, _('flip'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'move' self.addCheckNode( tv, rg1, _('move'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'nomove' self.addCheckNode( tv, rg1, _('no move'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'redo' self.addCheckNode( tv, rg1, _('redo'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'startdrag' self.addCheckNode( tv, rg1, _('start drag'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'turnwaste' self.addCheckNode( tv, rg1, _('turn waste'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'undo' self.addCheckNode( tv, rg1, _('undo'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'gamefinished' self.addCheckNode( tv, rg1, _('game finished'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'gamelost' self.addCheckNode( tv, rg1, _('game lost'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'gameperfect' self.addCheckNode( tv, rg1, _('game perfect'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'gamewon' self.addCheckNode( tv, rg1, _('game won'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) key = 'extra' self.addCheckNode( tv, rg1, _('Other'), self.menubar.tkopt.sound_sample_vars[key], self.make_vars_command(self.menubar.mOptSoundSample, key)) # ------------------------------------------- # Cardsets and card backside options rg = tv.add_node( LTreeNode(text=_('Cardsets'))) if rg: self.menubar.tkopt.cardset.set(self.app.cardset.index) csm = self.app.cardset_manager # cnt = csm.len() i = 0 while 1: cs = csm.get(i) if cs is None: break rg1 = self.addRadioNode(tv, rg, cs.name, self.menubar.tkopt.cardset, i, self.menubar.mOptCardset) if rg1: cbs = cs.backnames self.menubar.tkopt.cardbacks[i] = IntVar() self.menubar.tkopt.cardbacks[i].set(cs.backindex) bcnt = len(cbs) bi = 0 while 1: if bi == bcnt: break cb = cbs[bi] self.addRadioNode( tv, rg1, cb, self.menubar.tkopt.cardbacks[i], bi, self.make_vars_command( self.menubar.mOptSetCardback, i)) bi += 1 i += 1 # ------------------------------------------- # Table background settings rg = tv.add_node( LTreeNode(text=_('Table'))) if rg: rg1 = tv.add_node( LTreeNode(text=_('Solid colors')), rg) if rg1: key = 'table' self.addRadioNode( tv, rg1, _('Blue'), self.menubar.tkopt.color_vars[key], '#0082df', self.menubar.mOptTableColor) self.addRadioNode( tv, rg1, _('Green'), self.menubar.tkopt.color_vars[key], '#008200', self.menubar.mOptTableColor) self.addRadioNode( tv, rg1, _('Navy'), self.menubar.tkopt.color_vars[key], '#000086', self.menubar.mOptTableColor) self.addRadioNode( tv, rg1, _('Olive'), self.menubar.tkopt.color_vars[key], '#868200', self.menubar.mOptTableColor) self.addRadioNode( tv, rg1, _('Orange'), self.menubar.tkopt.color_vars[key], '#f79600', self.menubar.mOptTableColor) self.addRadioNode( tv, rg1, _('Teal'), self.menubar.tkopt.color_vars[key], '#008286', self.menubar.mOptTableColor) rg1 = tv.add_node( LTreeNode(text=_('Textures')), rg) rg2 = tv.add_node( LTreeNode(text=_('Images')), rg) if rg1 or rg2: tm = self.app.tabletile_manager # cnt = tm.len() i = 1 while True: ti = tm.get(i) if ti is None: break if ti.save_aspect == 0 and ti.stretch == 0 and rg1: self.addRadioNode(tv, rg1, ti.name, self.menubar.tkopt.tabletile, i, self.menubar.mOptTileSet) if (ti.save_aspect == 1 or ti.stretch == 1) and rg2: self.addRadioNode(tv, rg2, ti.name, self.menubar.tkopt.tabletile, i, self.menubar.mOptTileSet) i += 1 # ------------------------------------------- # Card view options rg = tv.add_node( LTreeNode(text=_('Card view'))) if rg: self.addCheckNode(tv, rg, _('Card shadow'), self.menubar.tkopt.shadow, self.menubar.mOptShadow) self.addCheckNode(tv, rg, _('Shade legal moves'), self.menubar.tkopt.shade, self.menubar.mOptShade) self.addCheckNode(tv, rg, _('Negative cards bottom'), self.menubar.tkopt.negative_bottom, self.menubar.mOptNegativeBottom) self.addCheckNode(tv, rg, _('Shrink face-down cards'), self.menubar.tkopt.shrink_face_down, self.menubar.mOptShrinkFaceDown) self.addCheckNode(tv, rg, _('Shade filled stacks'), self.menubar.tkopt.shade_filled_stacks, self.menubar.mOptShadeFilledStacks) # ------------------------------------------- # Animation settins rg = tv.add_node( LTreeNode(text=_('Animations'))) if rg: self.addRadioNode(tv, rg, _('None'), self.menubar.tkopt.animations, 0, self.menubar.mOptAnimations) self.addRadioNode(tv, rg, _('Very fast'), self.menubar.tkopt.animations, 1, self.menubar.mOptAnimations) self.addRadioNode(tv, rg, _('Fast'), self.menubar.tkopt.animations, 2, self.menubar.mOptAnimations) self.addRadioNode(tv, rg, _('Medium'), self.menubar.tkopt.animations, 3, self.menubar.mOptAnimations) self.addRadioNode(tv, rg, _('Slow'), self.menubar.tkopt.animations, 4, self.menubar.mOptAnimations) self.addRadioNode(tv, rg, _('Very slow'), self.menubar.tkopt.animations, 5, self.menubar.mOptAnimations) # submenu.add_separator() self.addCheckNode(tv, rg, _('Redeal animation'), self.menubar.tkopt.redeal_animation, self.menubar.mRedealAnimation) self.addCheckNode(tv, rg, _('Winning animation'), self.menubar.tkopt.win_animation, self.menubar.mWinAnimation) # ------------------------------------------- # Touch mode settings rg = tv.add_node( LTreeNode(text=_('Touch mode'))) if rg: self.addRadioNode(tv, rg, _('Drag-and-Drop'), self.menubar.tkopt.mouse_type, 'drag-n-drop', self.menubar.mOptMouseType) self.addRadioNode(tv, rg, _('Point-and-Click'), self.menubar.tkopt.mouse_type, 'point-n-click', self.menubar.mOptMouseType) # sinnlos mit touch-device: # self.addRadioNode(tv, rg, # 'Sticky mouse', # self.menubar.tkopt.mouse_type, u'sticky-mouse', # self.menubar.mOptMouseType) # submenu.add_separator() # sinnlos mit touch-device: # self.addCheckNode(tv, rg, # 'Use mouse for undo/redo', # self.menubar.tkopt.mouse_undo, # self.menubar.mOptMouseUndo) # submenu.add_separator() # ------------------------------------------- # TBD ? ''' menu.add_command(label=n_("&Fonts..."), command=self.mOptFonts) menu.add_command(label=n_("&Colors..."), command=self.mOptColors) menu.add_command(label=n_("Time&outs..."), command=self.mOptTimeouts) menu.add_separator() ''' # ------------------------------------------- # Toolbar options rg = tv.add_node( LTreeNode(text=_('Toolbar'))) if rg: self.addRadioNode(tv, rg, _('Hide'), self.menubar.tkopt.toolbar, 0, self.menubar.mOptToolbar) # not supported: Top, Bottom # self.addRadioNode(tv, rg, # 'Top', # self.menubar.tkopt.toolbar, 1, # self.menubar.mOptToolbar) # self.addRadioNode(tv, rg, # 'Bottom', # self.menubar.tkopt.toolbar, 2, # self.menubar.mOptToolbar) self.addRadioNode(tv, rg, _('Left'), self.menubar.tkopt.toolbar, 3, self.menubar.mOptToolbar) self.addRadioNode(tv, rg, _('Right'), self.menubar.tkopt.toolbar, 4, self.menubar.mOptToolbar) # ------------------------------------------- # Statusbar - not implemented ''' submenu = MfxMenu(menu, label=n_("Stat&usbar")) submenu.add_checkbutton( label=n_("Show &statusbar"), variable=self.tkopt.statusbar, command=self.mOptStatusbar) submenu.add_checkbutton( label=n_("Show &number of cards"), variable=self.tkopt.num_cards, command=self.mOptNumCards) submenu.add_checkbutton( label=n_("Show &help bar"), variable=self.tkopt.helpbar, command=self.mOptHelpbar) ''' # ------------------------------------------- # general options # self.addCheckNode(tv, None, # 'Save games geometry', # self.menubar.tkopt.save_games_geometry, # self.menubar.mOptSaveGamesGeometry) # self.addCheckNode(tv, None, # 'Demo logo', # self.menubar.tkopt.demo_logo, # self.menubar.mOptDemoLogo) self.addCheckNode(tv, None, _('Startup splash screen'), self.menubar.tkopt.splashscreen, self.menubar.mOptSplashscreen) self.addCheckNode(tv, None, _('Winning splash'), self.menubar.tkopt.display_win_message, self.menubar.mWinDialog)
[ "def", "buildTree", "(", "self", ",", "tv", ",", "node", ")", ":", "# -------------------------------------------", "# Automatic play settings", "rg", "=", "tv", ".", "add_node", "(", "LTreeNode", "(", "text", "=", "_", "(", "'Automatic play'", ")", ")", ")", ...
https://github.com/shlomif/PySolFC/blob/780c399e6f68a95916d84e7e88a067e8fcbec1cc/pysollib/kivy/menubar.py#L504-L1094
DataDog/integrations-core
934674b29d94b70ccc008f76ea172d0cdae05e1e
lighttpd/datadog_checks/lighttpd/config_models/__init__.py
python
ConfigMixin.config
(self)
return self._config_model_instance
[]
def config(self) -> InstanceConfig: return self._config_model_instance
[ "def", "config", "(", "self", ")", "->", "InstanceConfig", ":", "return", "self", ".", "_config_model_instance" ]
https://github.com/DataDog/integrations-core/blob/934674b29d94b70ccc008f76ea172d0cdae05e1e/lighttpd/datadog_checks/lighttpd/config_models/__init__.py#L19-L20
soft-matter/trackpy
a316c658ffd03d4b6fe705b9bedd63c1ab8276c0
trackpy/linking/legacy.py
python
TreeFinder.__init__
(self, points, search_range)
Takes a list of particles.
Takes a list of particles.
[ "Takes", "a", "list", "of", "particles", "." ]
def __init__(self, points, search_range): """Takes a list of particles.""" self.ndim = len(search_range) self.search_range = np.atleast_2d(search_range) if not isinstance(points, list): points = list(points) self.points = points self.rebuild()
[ "def", "__init__", "(", "self", ",", "points", ",", "search_range", ")", ":", "self", ".", "ndim", "=", "len", "(", "search_range", ")", "self", ".", "search_range", "=", "np", ".", "atleast_2d", "(", "search_range", ")", "if", "not", "isinstance", "(", ...
https://github.com/soft-matter/trackpy/blob/a316c658ffd03d4b6fe705b9bedd63c1ab8276c0/trackpy/linking/legacy.py#L207-L214
hzlzh/AlfredWorkflow.com
7055f14f6922c80ea5943839eb0caff11ae57255
Sources/Workflows/SearchKippt/alp/request/requests/cookies.py
python
RequestsCookieJar.__getstate__
(self)
return state
Unlike a normal CookieJar, this class is pickleable.
Unlike a normal CookieJar, this class is pickleable.
[ "Unlike", "a", "normal", "CookieJar", "this", "class", "is", "pickleable", "." ]
def __getstate__(self): """Unlike a normal CookieJar, this class is pickleable.""" state = self.__dict__.copy() # remove the unpickleable RLock object state.pop('_cookies_lock') return state
[ "def", "__getstate__", "(", "self", ")", ":", "state", "=", "self", ".", "__dict__", ".", "copy", "(", ")", "# remove the unpickleable RLock object", "state", ".", "pop", "(", "'_cookies_lock'", ")", "return", "state" ]
https://github.com/hzlzh/AlfredWorkflow.com/blob/7055f14f6922c80ea5943839eb0caff11ae57255/Sources/Workflows/SearchKippt/alp/request/requests/cookies.py#L296-L301
openatx/adbutils
ecddefa4a1888b71b0e379675245a05b8a2c8637
adbutils/__init__.py
python
AdbClient.wait_for
(self, serial: str = None, transport: str = 'any', state: str = "device", timeout: float=60)
Same as wait-for-TRANSPORT-STATE Args: serial (str): device serial [default None] transport (str): {any,usb,local} [default any] state (str): {device,recovery,rescue,sideload,bootloader,disconnect} [default device] timeout (float): max wait time [default 60] Raises: AdbError, AdbTimeout
Same as wait-for-TRANSPORT-STATE Args: serial (str): device serial [default None] transport (str): {any,usb,local} [default any] state (str): {device,recovery,rescue,sideload,bootloader,disconnect} [default device] timeout (float): max wait time [default 60] Raises: AdbError, AdbTimeout
[ "Same", "as", "wait", "-", "for", "-", "TRANSPORT", "-", "STATE", "Args", ":", "serial", "(", "str", ")", ":", "device", "serial", "[", "default", "None", "]", "transport", "(", "str", ")", ":", "{", "any", "usb", "local", "}", "[", "default", "any...
def wait_for(self, serial: str = None, transport: str = 'any', state: str = "device", timeout: float=60): """ Same as wait-for-TRANSPORT-STATE Args: serial (str): device serial [default None] transport (str): {any,usb,local} [default any] state (str): {device,recovery,rescue,sideload,bootloader,disconnect} [default device] timeout (float): max wait time [default 60] Raises: AdbError, AdbTimeout """ with self._connect(timeout=timeout) as c: cmds = [] if serial: cmds.extend(['host-serial', serial]) else: cmds.append('host') cmds.append("wait-for-" + transport + "-" + state) c.send_command(":".join(cmds)) c.check_okay() c.check_okay()
[ "def", "wait_for", "(", "self", ",", "serial", ":", "str", "=", "None", ",", "transport", ":", "str", "=", "'any'", ",", "state", ":", "str", "=", "\"device\"", ",", "timeout", ":", "float", "=", "60", ")", ":", "with", "self", ".", "_connect", "("...
https://github.com/openatx/adbutils/blob/ecddefa4a1888b71b0e379675245a05b8a2c8637/adbutils/__init__.py#L225-L245
fregu856/2D_detection
1f22a6d604d39f8f79fe916fcdbf40b5b668a39a
train.py
python
train_data_iterator
()
[]
def train_data_iterator(): random.shuffle(train_data) train_img_paths, train_bboxes_per_img = zip(*train_data) batch_pointer = 0 for step in range(no_of_batches): batch_imgs = np.zeros((batch_size, img_height, img_width, 3), dtype=np.float32) # (list of length batch_size, each element is a list of length # no_of_gt_bboxes_in_img containing the class labels (0=car, 1=pedestrian # etc.) of the ground truth bboxes in the image) class_labels_per_img = [] # (list of length batch_size, each element is a 2D array of shape # [no_of_gt_bboxes_in_img, 4], where each row is [center_x, center_y, w, h] # of each ground truth bbox in the image) gt_bboxes_per_img = [] # (list of length batch_size, each element is a list of length # no_of_gt_bboxes_in_img, where each element in turn is a list [delta_x, # delta_y, delta_w, delta_h] which describes how to transform the assigned # anchor into the ground truth bbox for each ground truth bbox in the image) gt_deltas_per_img = [] # (list of length batch_size, each element is a list of length # no_of_gt_bboxes_in_img containing the index of the assigned anchor # for each ground truth bbox in the image) anchor_indices_per_img = [] for i in range(batch_size): # read the next img: img_path = train_img_paths[batch_pointer + i] img = cv2.imread(img_path, -1) img = cv2.resize(img, (img_width, img_height)) img = img - train_mean_channels batch_imgs[i] = img img_bboxes = train_bboxes_per_img[batch_pointer + i] # (bbox format: [center_x, center_y, w, h, class_label] where # class_label is a string) img_class_labels = [model.class_string_to_label[b[4]] for b in img_bboxes] class_labels_per_img.append(img_class_labels) img_gt_bboxes = np.array([[b[0], b[1], b[2], b[3]] for b in img_bboxes]) # (bbox format: [center_x, center_y, w, h]. img_gt_bboxes has shape # [no_of_gt_bboxes_in_img, 4]) gt_bboxes_per_img.append(img_gt_bboxes) img_gt_deltas = [] img_anchor_indices = [] assigned_anchor_indices = [] for gt_bbox in img_gt_bboxes: IOUs = batch_IOU(model.anchor_bboxes, gt_bbox) # (IOUs has shape [anchors_per_img, ] and contains the IOU # between each anchor bbox and gt_bbox) anchor_idx = -1 sorted_anchor_indices_IOU = np.argsort(IOUs)[::-1] # (-1 gives descending order) # (the first element of sorted_anchor_indices_IOU is the index # of the anchor with the LARGEST IOU with gt_bbox etc.) for idx in sorted_anchor_indices_IOU: if IOUs[idx] <= 0: break if idx not in assigned_anchor_indices: assigned_anchor_indices.append(idx) anchor_idx = idx break if anchor_idx == -1: # (if all available IOUs equal 0:) # choose the available anchor which is closest to the ground # truth bbox w.r.t L2 norm: norms = np.sum(np.square(gt_bbox - model.anchor_bboxes), axis=1) sorted_anchor_indices_norm = np.argsort(norms) for idx in sorted_anchor_indices_norm: if idx not in assigned_anchor_indices: assigned_anchor_indices.append(idx) anchor_idx = idx break img_anchor_indices.append(anchor_idx) assigned_anchor_bbox = model.anchor_bboxes[anchor_idx] anchor_cx, anchor_cy, anchor_w, anchor_h = assigned_anchor_bbox gt_cx, gt_cy, gt_w, gt_h = gt_bbox gt_delta = [0]*4 gt_delta[0] = (gt_cx - anchor_cx)/anchor_w gt_delta[1] = (gt_cy - anchor_cy)/anchor_h gt_delta[2] = np.log(gt_w/anchor_w) gt_delta[3] = np.log(gt_h/anchor_h) img_gt_deltas.append(gt_delta) gt_deltas_per_img.append(img_gt_deltas) anchor_indices_per_img.append(img_anchor_indices) # (we now have batch_imgs, class_labels_per_img, gt_bboxes_per_img, # gt_deltas_per_img and anchor_indices_per_img) class_label_indices = [] mask_indices = [] gt_bbox_indices = [] gt_delta_values =[] gt_bbox_values = [] for i in range(batch_size): no_of_gt_bboxes_in_img = len(class_labels_per_img[i]) img_class_labels = class_labels_per_img[i] img_anchor_indices = anchor_indices_per_img[i] img_gt_deltas = gt_deltas_per_img[i] img_gt_bboxes = gt_bboxes_per_img[i] for j in range(no_of_gt_bboxes_in_img): class_label = img_class_labels[j] anchor_idx = img_anchor_indices[j] gt_delta = img_gt_deltas[j] gt_bbox = img_gt_bboxes[j] class_label_indices.append([i, anchor_idx, class_label]) mask_indices.append([i, anchor_idx]) gt_bbox_indices.extend([[i, anchor_idx, k] for k in range(4)]) gt_delta_values.extend(gt_delta) gt_bbox_values.extend(gt_bbox) # (we now have mask_indices, class_label_indices, gt_bbox_indices, # gt_delta_values and gt_bbox_values) batch_mask = sparse_to_dense(mask_indices, [batch_size, model.anchors_per_img], [1.0]*len(mask_indices)) batch_mask = np.reshape(batch_mask, [batch_size, model.anchors_per_img, 1]) batch_gt_deltas = sparse_to_dense(gt_bbox_indices, [batch_size, model.anchors_per_img, 4], gt_delta_values) batch_gt_bboxes = sparse_to_dense(gt_bbox_indices, [batch_size, model.anchors_per_img, 4], gt_bbox_values) batch_class_labels = sparse_to_dense(class_label_indices, [batch_size, model.anchors_per_img, no_of_classes], [1.0]*len(class_label_indices)) batch_pointer += batch_size yield (batch_imgs, batch_mask, batch_gt_deltas, batch_gt_bboxes, batch_class_labels)
[ "def", "train_data_iterator", "(", ")", ":", "random", ".", "shuffle", "(", "train_data", ")", "train_img_paths", ",", "train_bboxes_per_img", "=", "zip", "(", "*", "train_data", ")", "batch_pointer", "=", "0", "for", "step", "in", "range", "(", "no_of_batches...
https://github.com/fregu856/2D_detection/blob/1f22a6d604d39f8f79fe916fcdbf40b5b668a39a/train.py#L269-L411
rwightman/gen-efficientnet-pytorch
2d6623e956fbc9ac9c2f86ace2619e22ce7e2960
geffnet/gen_efficientnet.py
python
tf_efficientnet_b8_ap
(pretrained=False, **kwargs)
return model
EfficientNet-B8 AdvProp. Tensorflow compatible variant Paper: Adversarial Examples Improve Image Recognition (https://arxiv.org/abs/1911.09665)
EfficientNet-B8 AdvProp. Tensorflow compatible variant Paper: Adversarial Examples Improve Image Recognition (https://arxiv.org/abs/1911.09665)
[ "EfficientNet", "-", "B8", "AdvProp", ".", "Tensorflow", "compatible", "variant", "Paper", ":", "Adversarial", "Examples", "Improve", "Image", "Recognition", "(", "https", ":", "//", "arxiv", ".", "org", "/", "abs", "/", "1911", ".", "09665", ")" ]
def tf_efficientnet_b8_ap(pretrained=False, **kwargs): """ EfficientNet-B8 AdvProp. Tensorflow compatible variant Paper: Adversarial Examples Improve Image Recognition (https://arxiv.org/abs/1911.09665) """ # NOTE for train, drop_rate should be 0.5 kwargs['bn_eps'] = BN_EPS_TF_DEFAULT kwargs['pad_type'] = 'same' model = _gen_efficientnet( 'tf_efficientnet_b8_ap', channel_multiplier=2.2, depth_multiplier=3.6, pretrained=pretrained, **kwargs) return model
[ "def", "tf_efficientnet_b8_ap", "(", "pretrained", "=", "False", ",", "*", "*", "kwargs", ")", ":", "# NOTE for train, drop_rate should be 0.5", "kwargs", "[", "'bn_eps'", "]", "=", "BN_EPS_TF_DEFAULT", "kwargs", "[", "'pad_type'", "]", "=", "'same'", "model", "="...
https://github.com/rwightman/gen-efficientnet-pytorch/blob/2d6623e956fbc9ac9c2f86ace2619e22ce7e2960/geffnet/gen_efficientnet.py#L1149-L1158
CoinAlpha/hummingbot
36f6149c1644c07cd36795b915f38b8f49b798e7
hummingbot/connector/exchange/hitbtc/hitbtc_api_order_book_data_source.py
python
HitbtcAPIOrderBookDataSource.listen_for_trades
(self, ev_loop: asyncio.BaseEventLoop, output: asyncio.Queue)
Listen for trades using websocket trade channel
Listen for trades using websocket trade channel
[ "Listen", "for", "trades", "using", "websocket", "trade", "channel" ]
async def listen_for_trades(self, ev_loop: asyncio.BaseEventLoop, output: asyncio.Queue): """ Listen for trades using websocket trade channel """ while True: try: ws = HitbtcWebsocket() await ws.connect() for pair in self._trading_pairs: symbol = await HitbtcAPIOrderBookDataSource.exchange_symbol_associated_to_pair(pair) await ws.subscribe(Constants.WS_SUB["TRADES"], symbol) async for response in ws.on_message(): method: str = response.get("method", None) trades_data: str = response.get("params", None) if trades_data is None or method != Constants.WS_METHODS['TRADES_UPDATE']: continue pair: str = await self.trading_pair_associated_to_exchange_symbol(response["params"]["symbol"]) for trade in trades_data["data"]: trade: Dict[Any] = trade trade_timestamp: int = str_date_to_ts(trade["timestamp"]) trade_msg: OrderBookMessage = HitbtcOrderBook.trade_message_from_exchange( trade, trade_timestamp, metadata={"trading_pair": pair}) output.put_nowait(trade_msg) except asyncio.CancelledError: raise except Exception: self.logger().error("Unexpected error.", exc_info=True) await asyncio.sleep(5.0) finally: await ws.disconnect()
[ "async", "def", "listen_for_trades", "(", "self", ",", "ev_loop", ":", "asyncio", ".", "BaseEventLoop", ",", "output", ":", "asyncio", ".", "Queue", ")", ":", "while", "True", ":", "try", ":", "ws", "=", "HitbtcWebsocket", "(", ")", "await", "ws", ".", ...
https://github.com/CoinAlpha/hummingbot/blob/36f6149c1644c07cd36795b915f38b8f49b798e7/hummingbot/connector/exchange/hitbtc/hitbtc_api_order_book_data_source.py#L129-L166
whoosh-community/whoosh
5421f1ab3bb802114105b3181b7ce4f44ad7d0bb
src/whoosh/columns.py
python
CompressedBlockColumn.__init__
(self, level=3, blocksize=32, module="zlib")
:param level: the compression level to use. :param blocksize: the size (in KB) of each compressed block. :param module: a string containing the name of the compression module to use. The default is "zlib". The module should export "compress" and "decompress" functions.
:param level: the compression level to use. :param blocksize: the size (in KB) of each compressed block. :param module: a string containing the name of the compression module to use. The default is "zlib". The module should export "compress" and "decompress" functions.
[ ":", "param", "level", ":", "the", "compression", "level", "to", "use", ".", ":", "param", "blocksize", ":", "the", "size", "(", "in", "KB", ")", "of", "each", "compressed", "block", ".", ":", "param", "module", ":", "a", "string", "containing", "the",...
def __init__(self, level=3, blocksize=32, module="zlib"): """ :param level: the compression level to use. :param blocksize: the size (in KB) of each compressed block. :param module: a string containing the name of the compression module to use. The default is "zlib". The module should export "compress" and "decompress" functions. """ self._level = level self._blocksize = blocksize self._module = module
[ "def", "__init__", "(", "self", ",", "level", "=", "3", ",", "blocksize", "=", "32", ",", "module", "=", "\"zlib\"", ")", ":", "self", ".", "_level", "=", "level", "self", ".", "_blocksize", "=", "blocksize", "self", ".", "_module", "=", "module" ]
https://github.com/whoosh-community/whoosh/blob/5421f1ab3bb802114105b3181b7ce4f44ad7d0bb/src/whoosh/columns.py#L831-L842
toddlerya/NebulaSolarDash
286ff86f0ad3550c1c92323d45e24f01c5c6fcd5
lib/common_lib.py
python
LoadConf.__init__
(self)
初始化cfg
初始化cfg
[ "初始化cfg" ]
def __init__(self): """ 初始化cfg """ self.cfg = ConfigParser()
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "cfg", "=", "ConfigParser", "(", ")" ]
https://github.com/toddlerya/NebulaSolarDash/blob/286ff86f0ad3550c1c92323d45e24f01c5c6fcd5/lib/common_lib.py#L53-L57
bisohns/search-engine-parser
ede1355a1f63398d9217b8e502fbd6c52b53bf09
search_engine_parser/core/engines/baidu.py
python
Search.parse_soup
(self, soup)
return soup.find_all('div', {'id': re.compile(r"^\d{1,2}")}, class_="c-container")
Parses Baidu for a search query
Parses Baidu for a search query
[ "Parses", "Baidu", "for", "a", "search", "query" ]
def parse_soup(self, soup): """ Parses Baidu for a search query """ # Baidu search can be made deterministic via an id # Hence, a regex is used to match all eligible ids return soup.find_all('div', {'id': re.compile(r"^\d{1,2}")}, class_="c-container")
[ "def", "parse_soup", "(", "self", ",", "soup", ")", ":", "# Baidu search can be made deterministic via an id", "# Hence, a regex is used to match all eligible ids", "return", "soup", ".", "find_all", "(", "'div'", ",", "{", "'id'", ":", "re", ".", "compile", "(", "r\"...
https://github.com/bisohns/search-engine-parser/blob/ede1355a1f63398d9217b8e502fbd6c52b53bf09/search_engine_parser/core/engines/baidu.py#L31-L39
nschloe/quadpy
c4c076d8ddfa968486a2443a95e2fb3780dcde0f
src/quadpy/helpers/symmetries.py
python
expand_symmetries_points_only
(data, dim)
return points, counts
[]
def expand_symmetries_points_only(data, dim): points = [] counts = [] for key, points_raw in data.items(): fun = { "zero2": _zero, "zero3": _zero, "0": _zero, # "a": _a, "a0": _a0, # "d4_aa": _d4_aa, "d4_a0": _d4_a0, "c4": _c4, "d4_ab": _d4_ab, "c2_a0": _c2_a0, "c2_0a": _c2_0a, "sxy": _sxy, "c2": _c2, "sx": _sx, # "centroid": _centroid, "vertex": _vertex, "d3_ab": _d3_ab, "d3_aa": _d3_aa, "c3_ab": _c3_ab, "swap_ab": _swap_ab, "s2_static": _s2_static, # "d4.0": lambda r, dim: _d(4, 0, r), "d4.1": lambda r, dim: _d(4, 1, r), "d5.0": lambda r, dim: _d(5, 0, r), "d6.0": lambda r, dim: _d(6, 0, r), "d6.1": lambda r, dim: _d(6, 1, r), "d8.0": lambda r, dim: _d(8, 0, r), "d8.1": lambda r, dim: _d(8, 1, r), "d10.0": lambda r, dim: _d(10, 0, r), "d10.1": lambda r, dim: _d(10, 1, r), # "symm_r00": _symm_r00, "symm_rr0": _symm_rr0, "symm_rs0_roll": _symm_rs0_roll, "symm_rrr": _symm_rrr, "symm_rrs": _symm_rrs, "symm_rss_pm": _symm_rss_pm, # "plain": lambda vals, dim: vals.reshape(vals.shape[0], 1, -1), }[key] pts = fun(np.asarray(points_raw), dim) counts.append(pts.shape[1]) pts = pts.reshape(pts.shape[0], -1) points.append(pts) points = np.ascontiguousarray(np.concatenate(points, axis=1)) return points, counts
[ "def", "expand_symmetries_points_only", "(", "data", ",", "dim", ")", ":", "points", "=", "[", "]", "counts", "=", "[", "]", "for", "key", ",", "points_raw", "in", "data", ".", "items", "(", ")", ":", "fun", "=", "{", "\"zero2\"", ":", "_zero", ",", ...
https://github.com/nschloe/quadpy/blob/c4c076d8ddfa968486a2443a95e2fb3780dcde0f/src/quadpy/helpers/symmetries.py#L286-L343
hackingmaterials/atomate
bdca913591d22a6f71d4914c69f3ee191e2d96db
atomate/vasp/workflows/base/hubbard_hund_linresp.py
python
HubbardHundLinRespSet.poscar
(self)
return poscar
Custom Poscar for HubbardHundLinRespSet
Custom Poscar for HubbardHundLinRespSet
[ "Custom", "Poscar", "for", "HubbardHundLinRespSet" ]
def poscar(self): """ Custom Poscar for HubbardHundLinRespSet """ poscar = PoscarPerturb( structure=super().structure, num_perturb=self.num_perturb ) return poscar
[ "def", "poscar", "(", "self", ")", ":", "poscar", "=", "PoscarPerturb", "(", "structure", "=", "super", "(", ")", ".", "structure", ",", "num_perturb", "=", "self", ".", "num_perturb", ")", "return", "poscar" ]
https://github.com/hackingmaterials/atomate/blob/bdca913591d22a6f71d4914c69f3ee191e2d96db/atomate/vasp/workflows/base/hubbard_hund_linresp.py#L694-L701
osmr/imgclsmob
f2993d3ce73a2f7ddba05da3891defb08547d504
pytorch/pytorchcv/models/preresnet_cifar.py
python
preresnet272bn_svhn
(num_classes=10, **kwargs)
return get_preresnet_cifar(num_classes=num_classes, blocks=272, bottleneck=True, model_name="preresnet272bn_svhn", **kwargs)
PreResNet-272(BN) model for SVHN from 'Identity Mappings in Deep Residual Networks,' https://arxiv.org/abs/1603.05027. Parameters: ---------- num_classes : int, default 10 Number of classification classes. pretrained : bool, default False Whether to load the pretrained weights for model. root : str, default '~/.torch/models' Location for keeping the model parameters.
PreResNet-272(BN) model for SVHN from 'Identity Mappings in Deep Residual Networks,' https://arxiv.org/abs/1603.05027.
[ "PreResNet", "-", "272", "(", "BN", ")", "model", "for", "SVHN", "from", "Identity", "Mappings", "in", "Deep", "Residual", "Networks", "https", ":", "//", "arxiv", ".", "org", "/", "abs", "/", "1603", ".", "05027", "." ]
def preresnet272bn_svhn(num_classes=10, **kwargs): """ PreResNet-272(BN) model for SVHN from 'Identity Mappings in Deep Residual Networks,' https://arxiv.org/abs/1603.05027. Parameters: ---------- num_classes : int, default 10 Number of classification classes. pretrained : bool, default False Whether to load the pretrained weights for model. root : str, default '~/.torch/models' Location for keeping the model parameters. """ return get_preresnet_cifar(num_classes=num_classes, blocks=272, bottleneck=True, model_name="preresnet272bn_svhn", **kwargs)
[ "def", "preresnet272bn_svhn", "(", "num_classes", "=", "10", ",", "*", "*", "kwargs", ")", ":", "return", "get_preresnet_cifar", "(", "num_classes", "=", "num_classes", ",", "blocks", "=", "272", ",", "bottleneck", "=", "True", ",", "model_name", "=", "\"pre...
https://github.com/osmr/imgclsmob/blob/f2993d3ce73a2f7ddba05da3891defb08547d504/pytorch/pytorchcv/models/preresnet_cifar.py#L407-L422
initstring/evil-ssdp
ee76fb091c9befa4dd77a87f381c0de5fefdd78c
evil_ssdp.py
python
print_details
(args, local_ip, smb_server)
Prints a banner at runtime, informing the user of relevant details.
Prints a banner at runtime, informing the user of relevant details.
[ "Prints", "a", "banner", "at", "runtime", "informing", "the", "user", "of", "relevant", "details", "." ]
def print_details(args, local_ip, smb_server): """ Prints a banner at runtime, informing the user of relevant details. """ dev_url = 'http://{}:{}/ssdp/device-desc.xml'.format( local_ip, args.local_port) srv_url = 'http://{}:{}/ssdp/service-desc.xml'.format( local_ip, args.local_port) phish_url = 'http://{}:{}/ssdp/present.html'.format( local_ip, args.local_port) exfil_url = 'http://{}:{}/ssdp/data.dtd'.format(local_ip, args.local_port) smb_url = 'file://///{}/smb/hash.jpg'.format(smb_server) print("\n\n") print("########################################") print(PC.ok_box + "EVIL TEMPLATE: {}".format(args.template_dir)) print(PC.ok_box + "MSEARCH LISTENER: {}".format(args.interface)) print(PC.ok_box + "DEVICE DESCRIPTOR: {}".format(dev_url)) print(PC.ok_box + "SERVICE DESCRIPTOR: {}".format(srv_url)) print(PC.ok_box + "PHISHING PAGE: {}".format(phish_url)) if args.redirect_url: print(PC.ok_box + "REDIRECT URL: {}".format( args.redirect_url)) if args.is_auth: print(PC.ok_box + "AUTH ENABLED, REALM: {}".format(args.realm)) if 'xxe-exfil' in args.template_dir: print(PC.ok_box + "EXFIL PAGE: {}".format(exfil_url)) else: print(PC.ok_box + "SMB POINTER: {}".format(smb_url)) if args.analyze: print(PC.warn_box + "ANALYZE MODE: ENABLED") print("########################################") print("\n\n")
[ "def", "print_details", "(", "args", ",", "local_ip", ",", "smb_server", ")", ":", "dev_url", "=", "'http://{}:{}/ssdp/device-desc.xml'", ".", "format", "(", "local_ip", ",", "args", ".", "local_port", ")", "srv_url", "=", "'http://{}:{}/ssdp/service-desc.xml'", "."...
https://github.com/initstring/evil-ssdp/blob/ee76fb091c9befa4dd77a87f381c0de5fefdd78c/evil_ssdp.py#L569-L600
frenetic-lang/pyretic
30462692f3e9675158862755955b44f3a37ea21c
pyretic/vendor/hsa/headerspace/hs.py
python
headerspace.__init__
(self, length)
Constructor length is the length of packet headers in bytes.
Constructor length is the length of packet headers in bytes.
[ "Constructor", "length", "is", "the", "length", "of", "packet", "headers", "in", "bytes", "." ]
def __init__(self, length): ''' Constructor length is the length of packet headers in bytes. ''' # hs_list: list of all wildcards included. # hs_diff: for each wildcard in hs diff, a list of wildcard not # included in the headerspace. hs_diff elements should all be a subset # of corresponding element in hs_list. self.hs_list = [] self.hs_diff = [] # list of (tf,rule_id,port) that has been lazy evaluated self.lazy_rules = [] # list of (tf,rule_id,port) that has been evaluated on this headerspace self.applied_rules = [] self._length = length
[ "def", "__init__", "(", "self", ",", "length", ")", ":", "# hs_list: list of all wildcards included.", "# hs_diff: for each wildcard in hs diff, a list of wildcard not", "# included in the headerspace. hs_diff elements should all be a subset ", "# of corresponding element in hs_list.", "self...
https://github.com/frenetic-lang/pyretic/blob/30462692f3e9675158862755955b44f3a37ea21c/pyretic/vendor/hsa/headerspace/hs.py#L26-L41
selinon/selinon
3613153566d454022a138639f0375c63f490c4cb
selinon/edge.py
python
Edge.__init__
(self, nodes_from, nodes_to, predicate, flow, foreach, selective)
Initialize edge definition. :param nodes_from: nodes from where edge starts :type nodes_from: List[Node] :param nodes_to: nodes where edge ends :type nodes_to: List[Node] :param predicate: predicate condition :type predicate: Predicate :param flow: flow to which edge belongs to :type flow: Flow :param foreach: foreach defining function and import over which we want to iterate :type foreach: dict :param selective: selective run flow configuration :type selective: None|dict
Initialize edge definition.
[ "Initialize", "edge", "definition", "." ]
def __init__(self, nodes_from, nodes_to, predicate, flow, foreach, selective): """Initialize edge definition. :param nodes_from: nodes from where edge starts :type nodes_from: List[Node] :param nodes_to: nodes where edge ends :type nodes_to: List[Node] :param predicate: predicate condition :type predicate: Predicate :param flow: flow to which edge belongs to :type flow: Flow :param foreach: foreach defining function and import over which we want to iterate :type foreach: dict :param selective: selective run flow configuration :type selective: None|dict """ self.nodes_from = nodes_from self.nodes_to = nodes_to self.predicate = predicate self.flow = flow self.foreach = foreach self.selective = selective
[ "def", "__init__", "(", "self", ",", "nodes_from", ",", "nodes_to", ",", "predicate", ",", "flow", ",", "foreach", ",", "selective", ")", ":", "self", ".", "nodes_from", "=", "nodes_from", "self", ".", "nodes_to", "=", "nodes_to", "self", ".", "predicate",...
https://github.com/selinon/selinon/blob/3613153566d454022a138639f0375c63f490c4cb/selinon/edge.py#L20-L41
dmlc/dgl
8d14a739bc9e446d6c92ef83eafe5782398118de
python/dgl/distributed/server_state.py
python
ServerState.kv_store
(self)
return self._kv_store
Get data store.
Get data store.
[ "Get", "data", "store", "." ]
def kv_store(self): """Get data store.""" return self._kv_store
[ "def", "kv_store", "(", "self", ")", ":", "return", "self", ".", "_kv_store" ]
https://github.com/dmlc/dgl/blob/8d14a739bc9e446d6c92ef83eafe5782398118de/python/dgl/distributed/server_state.py#L55-L57
apple/ccs-calendarserver
13c706b985fb728b9aab42dc0fef85aae21921c3
txdav/caldav/datastore/scheduling/ischedule/scheduler.py
python
IScheduleScheduler.doSchedulingViaPOST
(self, remoteAddr, headers, body, calendar, originator, recipients)
Carry out iSchedule specific processing.
Carry out iSchedule specific processing.
[ "Carry", "out", "iSchedule", "specific", "processing", "." ]
def doSchedulingViaPOST(self, remoteAddr, headers, body, calendar, originator, recipients): """ Carry out iSchedule specific processing. """ self.remoteAddr = remoteAddr self.headers = headers self.verified = False if not self._podding and config.Scheduling.iSchedule.DKIM.Enabled: verifier = DKIMVerifier(self.headers, body, protocol_debug=config.Scheduling.iSchedule.DKIM.ProtocolDebug) try: yield verifier.verify() self.verified = True except DKIMMissingError: # Carry on processing, but we will do extra checks on the originator as we would # when DKIM is not enabled, so that any local policy via remoteservers.xml can be used. pass except DKIMVerificationError, e: # If DKIM is enabled and there was a DKIM header present, then fail msg = "Failed to verify DKIM signature" _debug_msg = str(e) log.debug("{msg}:{exc}", msg=msg, exc=_debug_msg,) if config.Scheduling.iSchedule.DKIM.ProtocolDebug: msg = "{}:{}".format(msg, _debug_msg,) raise HTTPError(self.errorResponse( responsecode.FORBIDDEN, (ischedule_namespace, "verification-failed"), msg, )) if self._podding and self.headers.getRawHeaders('x-calendarserver-itip-refreshonly', ("F"))[0] == "T": self.txn.doing_attendee_refresh = 1 # Normalize recipient addresses results = [] for recipient in recipients: normalized = yield normalizeCUAddress(recipient, normalizationLookup, self.txn.directoryService().recordWithCalendarUserAddress) self.recipientsNormalizationMap[normalized] = recipient results.append(normalized) recipients = results result = (yield super(IScheduleScheduler, self).doSchedulingViaPOST(originator, recipients, calendar)) returnValue(result)
[ "def", "doSchedulingViaPOST", "(", "self", ",", "remoteAddr", ",", "headers", ",", "body", ",", "calendar", ",", "originator", ",", "recipients", ")", ":", "self", ".", "remoteAddr", "=", "remoteAddr", "self", ".", "headers", "=", "headers", "self", ".", "...
https://github.com/apple/ccs-calendarserver/blob/13c706b985fb728b9aab42dc0fef85aae21921c3/txdav/caldav/datastore/scheduling/ischedule/scheduler.py#L147-L192
coala/coala-bears
7d21a59891b6ad048bbe28de097cbb5693c648c7
bears/python/VultureBear.py
python
_find_unused_code
(filenames)
:param filenames: List of filenames to check. :return: Generator of Result objects.
:param filenames: List of filenames to check. :return: Generator of Result objects.
[ ":", "param", "filenames", ":", "List", "of", "filenames", "to", "check", ".", ":", "return", ":", "Generator", "of", "Result", "objects", "." ]
def _find_unused_code(filenames): """ :param filenames: List of filenames to check. :return: Generator of Result objects. """ vulture = Vulture() vulture.scavenge(filenames) for item in vulture.get_unused_code(): yield Result.from_values(origin='VultureBear', message=item.message, file=item.filename, line=item.first_lineno, end_line=item.last_lineno, confidence=item.confidence)
[ "def", "_find_unused_code", "(", "filenames", ")", ":", "vulture", "=", "Vulture", "(", ")", "vulture", ".", "scavenge", "(", "filenames", ")", "for", "item", "in", "vulture", ".", "get_unused_code", "(", ")", ":", "yield", "Result", ".", "from_values", "(...
https://github.com/coala/coala-bears/blob/7d21a59891b6ad048bbe28de097cbb5693c648c7/bears/python/VultureBear.py#L7-L20
mysql/mysql-connector-python
c5460bcbb0dff8e4e48bf4af7a971c89bf486d85
lib/mysqlx/result.py
python
Result.get_generated_insert_id
(self)
return self._generated_id
Returns the generated insert id. .. deprecated:: 8.0.12
Returns the generated insert id.
[ "Returns", "the", "generated", "insert", "id", "." ]
def get_generated_insert_id(self): """Returns the generated insert id. .. deprecated:: 8.0.12 """ return self._generated_id
[ "def", "get_generated_insert_id", "(", "self", ")", ":", "return", "self", ".", "_generated_id" ]
https://github.com/mysql/mysql-connector-python/blob/c5460bcbb0dff8e4e48bf4af7a971c89bf486d85/lib/mysqlx/result.py#L911-L916
tp4a/teleport
1fafd34f1f775d2cf80ea4af6e44468d8e0b24ad
server/www/packages/packages-darwin/x64/tornado/iostream.py
python
SSLIOStream.reading
(self)
return self._handshake_reading or super(SSLIOStream, self).reading()
[]
def reading(self): return self._handshake_reading or super(SSLIOStream, self).reading()
[ "def", "reading", "(", "self", ")", ":", "return", "self", ".", "_handshake_reading", "or", "super", "(", "SSLIOStream", ",", "self", ")", ".", "reading", "(", ")" ]
https://github.com/tp4a/teleport/blob/1fafd34f1f775d2cf80ea4af6e44468d8e0b24ad/server/www/packages/packages-darwin/x64/tornado/iostream.py#L1490-L1491
googleapis/python-ndb
e780c81cde1016651afbfcad8180d9912722cf1b
google/cloud/ndb/model.py
python
ModelKey._get_value
(entity)
return entity._entity_key
Get the entity key from an entity. Args: entity (Model): An entity to get the entity key from. Returns: .Key: The entity key stored on ``entity``.
Get the entity key from an entity.
[ "Get", "the", "entity", "key", "from", "an", "entity", "." ]
def _get_value(entity): """Get the entity key from an entity. Args: entity (Model): An entity to get the entity key from. Returns: .Key: The entity key stored on ``entity``. """ return entity._entity_key
[ "def", "_get_value", "(", "entity", ")", ":", "return", "entity", ".", "_entity_key" ]
https://github.com/googleapis/python-ndb/blob/e780c81cde1016651afbfcad8180d9912722cf1b/google/cloud/ndb/model.py#L2328-L2337
ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework
cb692f527e4e819b6c228187c5702d990a180043
external/Scripting Engine/Xenotix Python Scripting Engine/packages/IronPython.StdLib.2.7.4/content/Lib/mailbox.py
python
mbox._generate_toc
(self)
Generate key-to-(start, stop) table of contents.
Generate key-to-(start, stop) table of contents.
[ "Generate", "key", "-", "to", "-", "(", "start", "stop", ")", "table", "of", "contents", "." ]
def _generate_toc(self): """Generate key-to-(start, stop) table of contents.""" starts, stops = [], [] self._file.seek(0) while True: line_pos = self._file.tell() line = self._file.readline() if line.startswith('From '): if len(stops) < len(starts): stops.append(line_pos - len(os.linesep)) starts.append(line_pos) elif line == '': stops.append(line_pos) break self._toc = dict(enumerate(zip(starts, stops))) self._next_key = len(self._toc) self._file_length = self._file.tell()
[ "def", "_generate_toc", "(", "self", ")", ":", "starts", ",", "stops", "=", "[", "]", ",", "[", "]", "self", ".", "_file", ".", "seek", "(", "0", ")", "while", "True", ":", "line_pos", "=", "self", ".", "_file", ".", "tell", "(", ")", "line", "...
https://github.com/ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework/blob/cb692f527e4e819b6c228187c5702d990a180043/external/Scripting Engine/Xenotix Python Scripting Engine/packages/IronPython.StdLib.2.7.4/content/Lib/mailbox.py#L793-L809
openshift/openshift-tools
1188778e728a6e4781acf728123e5b356380fe6f
openshift/installer/vendored/openshift-ansible-3.11.28-1/roles/lib_openshift/library/oc_adm_csr.py
python
Yedit.get_entry
(data, key, sep='.')
return data
Get an item from a dictionary with key notation a.b.c d = {'a': {'b': 'c'}}} key = a.b return c
Get an item from a dictionary with key notation a.b.c d = {'a': {'b': 'c'}}} key = a.b return c
[ "Get", "an", "item", "from", "a", "dictionary", "with", "key", "notation", "a", ".", "b", ".", "c", "d", "=", "{", "a", ":", "{", "b", ":", "c", "}}}", "key", "=", "a", ".", "b", "return", "c" ]
def get_entry(data, key, sep='.'): ''' Get an item from a dictionary with key notation a.b.c d = {'a': {'b': 'c'}}} key = a.b return c ''' if key == '': pass elif (not (key and Yedit.valid_key(key, sep)) and isinstance(data, (list, dict))): return None key_indexes = Yedit.parse_key(key, sep) for arr_ind, dict_key in key_indexes: if dict_key and isinstance(data, dict): data = data.get(dict_key) elif (arr_ind and isinstance(data, list) and int(arr_ind) <= len(data) - 1): data = data[int(arr_ind)] else: return None return data
[ "def", "get_entry", "(", "data", ",", "key", ",", "sep", "=", "'.'", ")", ":", "if", "key", "==", "''", ":", "pass", "elif", "(", "not", "(", "key", "and", "Yedit", ".", "valid_key", "(", "key", ",", "sep", ")", ")", "and", "isinstance", "(", "...
https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/openshift/installer/vendored/openshift-ansible-3.11.28-1/roles/lib_openshift/library/oc_adm_csr.py#L322-L344
grantjenks/python-sortedcontainers
dff7ef79a21b3f3ceb6a19868f302f0a680aa243
sortedcontainers/sorteddict.py
python
SortedDict.items
(self)
return SortedItemsView(self)
Return new sorted items view of the sorted dict's items. See :class:`SortedItemsView` for details. :return: new sorted items view
Return new sorted items view of the sorted dict's items.
[ "Return", "new", "sorted", "items", "view", "of", "the", "sorted", "dict", "s", "items", "." ]
def items(self): """Return new sorted items view of the sorted dict's items. See :class:`SortedItemsView` for details. :return: new sorted items view """ return SortedItemsView(self)
[ "def", "items", "(", "self", ")", ":", "return", "SortedItemsView", "(", "self", ")" ]
https://github.com/grantjenks/python-sortedcontainers/blob/dff7ef79a21b3f3ceb6a19868f302f0a680aa243/sortedcontainers/sorteddict.py#L363-L371
bbc/brave
88d4454412ee5acfa5ecf2ac5bc8cf75766c7be5
brave/connections/connection.py
python
Connection.has_video
(self)
return self.source.has_video() and self.dest.has_video()
True iff both the src and dest have video
True iff both the src and dest have video
[ "True", "iff", "both", "the", "src", "and", "dest", "have", "video" ]
def has_video(self): ''' True iff both the src and dest have video ''' return self.source.has_video() and self.dest.has_video()
[ "def", "has_video", "(", "self", ")", ":", "return", "self", ".", "source", ".", "has_video", "(", ")", "and", "self", ".", "dest", ".", "has_video", "(", ")" ]
https://github.com/bbc/brave/blob/88d4454412ee5acfa5ecf2ac5bc8cf75766c7be5/brave/connections/connection.py#L67-L71
compas-dev/compas
0b33f8786481f710115fb1ae5fe79abc2a9a5175
src/compas/geometry/_core/distance.py
python
distance_point_plane_signed
(point, plane)
return dot_vectors(vector, normal)
r"""Compute the signed distance from a point to a plane defined by origin point and normal. Parameters ---------- point : [float, float, float] or :class:`compas.geometry.Point` Point coordinates. plane : [point, vector] or :class:`compas.geometry.Plane` A point and a vector defining a plane. Returns ------- float Distance between point and plane. Notes ----- The distance from a point to a plane can be computed from the coefficients of the equation of the plane and the coordinates of the point [1]_. The equation of a plane is .. math:: Ax + By + Cz + D = 0 where .. math:: :nowrap: \begin{align} D &= - Ax_0 - Bx_0 - Cz_0 \\ Q &= (x_0, y_0, z_0) \\ N &= (A, B, C) \end{align} with :math:`Q` a point on the plane, and :math:`N` the normal vector at that point. The distance of any point :math:`P` to a plane is the value of the dot product of the vector from :math:`Q` to :math:`P` and the normal at :math:`Q`. References ---------- .. [1] Nykamp, D. *Distance from point to plane*. Available at: http://mathinsight.org/distance_point_plane. Examples -------- >>>
r"""Compute the signed distance from a point to a plane defined by origin point and normal.
[ "r", "Compute", "the", "signed", "distance", "from", "a", "point", "to", "a", "plane", "defined", "by", "origin", "point", "and", "normal", "." ]
def distance_point_plane_signed(point, plane): r"""Compute the signed distance from a point to a plane defined by origin point and normal. Parameters ---------- point : [float, float, float] or :class:`compas.geometry.Point` Point coordinates. plane : [point, vector] or :class:`compas.geometry.Plane` A point and a vector defining a plane. Returns ------- float Distance between point and plane. Notes ----- The distance from a point to a plane can be computed from the coefficients of the equation of the plane and the coordinates of the point [1]_. The equation of a plane is .. math:: Ax + By + Cz + D = 0 where .. math:: :nowrap: \begin{align} D &= - Ax_0 - Bx_0 - Cz_0 \\ Q &= (x_0, y_0, z_0) \\ N &= (A, B, C) \end{align} with :math:`Q` a point on the plane, and :math:`N` the normal vector at that point. The distance of any point :math:`P` to a plane is the value of the dot product of the vector from :math:`Q` to :math:`P` and the normal at :math:`Q`. References ---------- .. [1] Nykamp, D. *Distance from point to plane*. Available at: http://mathinsight.org/distance_point_plane. Examples -------- >>> """ base, normal = plane vector = subtract_vectors(point, base) return dot_vectors(vector, normal)
[ "def", "distance_point_plane_signed", "(", "point", ",", "plane", ")", ":", "base", ",", "normal", "=", "plane", "vector", "=", "subtract_vectors", "(", "point", ",", "base", ")", "return", "dot_vectors", "(", "vector", ",", "normal", ")" ]
https://github.com/compas-dev/compas/blob/0b33f8786481f710115fb1ae5fe79abc2a9a5175/src/compas/geometry/_core/distance.py#L374-L428
riptideio/pymodbus
c5772b35ae3f29d1947f3ab453d8d00df846459f
examples/contrib/sunspec_client.py
python
SunspecClient.__init__
(self, client)
Initialize a new instance of the client :param client: The modbus client to use
Initialize a new instance of the client
[ "Initialize", "a", "new", "instance", "of", "the", "client" ]
def __init__(self, client): """ Initialize a new instance of the client :param client: The modbus client to use """ self.client = client self.offset = SunspecOffsets.CommonBlock
[ "def", "__init__", "(", "self", ",", "client", ")", ":", "self", ".", "client", "=", "client", "self", ".", "offset", "=", "SunspecOffsets", ".", "CommonBlock" ]
https://github.com/riptideio/pymodbus/blob/c5772b35ae3f29d1947f3ab453d8d00df846459f/examples/contrib/sunspec_client.py#L209-L215
OfflineIMAP/offlineimap
e70d3992a0e9bb0fcdf3c94e1edf25a4124dfcd2
offlineimap/folder/LocalStatusSQLite.py
python
LocalStatusSQLiteFolder.purge
(self)
Remove any pre-existing database. Do not call in dry-run mode.
Remove any pre-existing database. Do not call in dry-run mode.
[ "Remove", "any", "pre", "-", "existing", "database", ".", "Do", "not", "call", "in", "dry", "-", "run", "mode", "." ]
def purge(self): """Remove any pre-existing database. Do not call in dry-run mode.""" try: os.unlink(self.filename) except OSError as e: self.ui.debug('', "could not remove file %s: %s"% (self.filename, e))
[ "def", "purge", "(", "self", ")", ":", "try", ":", "os", ".", "unlink", "(", "self", ".", "filename", ")", "except", "OSError", "as", "e", ":", "self", ".", "ui", ".", "debug", "(", "''", ",", "\"could not remove file %s: %s\"", "%", "(", "self", "."...
https://github.com/OfflineIMAP/offlineimap/blob/e70d3992a0e9bb0fcdf3c94e1edf25a4124dfcd2/offlineimap/folder/LocalStatusSQLite.py#L141-L148
tengxing/tensorflow-learn
4d41f2a27af346e4d2adb206ebbc25aafbe52be6
mnist/input_data.py
python
maybe_download
(filename, work_directory)
return filepath
Download the data from Yann's website, unless it's already here.
Download the data from Yann's website, unless it's already here.
[ "Download", "the", "data", "from", "Yann", "s", "website", "unless", "it", "s", "already", "here", "." ]
def maybe_download(filename, work_directory): """Download the data from Yann's website, unless it's already here.""" if not os.path.exists(work_directory): os.mkdir(work_directory) filepath = os.path.join(work_directory, filename) if not os.path.exists(filepath): filepath, _ = urllib.request.urlretrieve(SOURCE_URL + filename, filepath) statinfo = os.stat(filepath) print('Successfully downloaded', filename, statinfo.st_size, 'bytes.') return filepath
[ "def", "maybe_download", "(", "filename", ",", "work_directory", ")", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "work_directory", ")", ":", "os", ".", "mkdir", "(", "work_directory", ")", "filepath", "=", "os", ".", "path", ".", "join", ...
https://github.com/tengxing/tensorflow-learn/blob/4d41f2a27af346e4d2adb206ebbc25aafbe52be6/mnist/input_data.py#L34-L43
parkouss/webmacs
35f174303af8c9147825c45ad41ff35706fa8bfa
webmacs/commands/global.py
python
send_right
(ctx)
Send a key right event.
Send a key right event.
[ "Send", "a", "key", "right", "event", "." ]
def send_right(ctx): """Send a key right event.""" send_key_event(KeyPress.from_str("Right"))
[ "def", "send_right", "(", "ctx", ")", ":", "send_key_event", "(", "KeyPress", ".", "from_str", "(", "\"Right\"", ")", ")" ]
https://github.com/parkouss/webmacs/blob/35f174303af8c9147825c45ad41ff35706fa8bfa/webmacs/commands/global.py#L400-L402
Esri/ArcREST
ab240fde2b0200f61d4a5f6df033516e53f2f416
src/arcrest/manageags/_data.py
python
Data.validateAllDataItems
(self)
return self._post(url=url, param_dict=params, securityHandler=self._securityHandler, proxy_url=self._proxy_url, proxy_port=self._proxy_port)
validates all the items in the datastore
validates all the items in the datastore
[ "validates", "all", "the", "items", "in", "the", "datastore" ]
def validateAllDataItems(self): """ validates all the items in the datastore """ params = { "f" : "json"} url = self._url + "/validateAllDataItems" return self._post(url=url, param_dict=params, securityHandler=self._securityHandler, proxy_url=self._proxy_url, proxy_port=self._proxy_port)
[ "def", "validateAllDataItems", "(", "self", ")", ":", "params", "=", "{", "\"f\"", ":", "\"json\"", "}", "url", "=", "self", ".", "_url", "+", "\"/validateAllDataItems\"", "return", "self", ".", "_post", "(", "url", "=", "url", ",", "param_dict", "=", "p...
https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcrest/manageags/_data.py#L165-L173
geduldig/TwitterAPI
1cb89e8fc50b051707fb99d6c2bb235ada5faf1a
TwitterAPI/TwitterAPI.py
python
TwitterAPI.request
(self, resource, params=None, files=None, method_override=None, hydrate_type=HydrateType.NONE)
Request a Twitter REST API or Streaming API resource. :param resource: A Twitter endpoint (ex. "search/tweets") :param params: Dictionary with endpoint parameters or None (default) :param files: Dictionary with multipart-encoded file or None (default) :param method_override: Request method to override or None (default). If an endpoint supports more than one method, the default method is the first in the list of methods. :param hydrate_type: HydrateType or int Do not hydrate ('includes' field and all its content will be lost for non-streaming requests) - NONE or 0 (default) Append new field with '_hydrate' suffix with hydrate values - APPEND or 1 Replace current field value with hydrate values - REPLACE or 2 :returns: TwitterResponse :raises: TwitterConnectionError
Request a Twitter REST API or Streaming API resource.
[ "Request", "a", "Twitter", "REST", "API", "or", "Streaming", "API", "resource", "." ]
def request(self, resource, params=None, files=None, method_override=None, hydrate_type=HydrateType.NONE): """Request a Twitter REST API or Streaming API resource. :param resource: A Twitter endpoint (ex. "search/tweets") :param params: Dictionary with endpoint parameters or None (default) :param files: Dictionary with multipart-encoded file or None (default) :param method_override: Request method to override or None (default). If an endpoint supports more than one method, the default method is the first in the list of methods. :param hydrate_type: HydrateType or int Do not hydrate ('includes' field and all its content will be lost for non-streaming requests) - NONE or 0 (default) Append new field with '_hydrate' suffix with hydrate values - APPEND or 1 Replace current field value with hydrate values - REPLACE or 2 :returns: TwitterResponse :raises: TwitterConnectionError """ # check that the endpoint is valid resource, endpoint = self._get_endpoint(resource) if endpoint not in ENDPOINTS: raise Exception('Endpoint "%s" unsupported' % endpoint) # check that the method is valid if the endpoint supports more than one method method, subdomain = ENDPOINTS[endpoint] if not method_override and isinstance(method, list): method = method[0] # by default use first method in list elif isinstance(method, list): if method_override in method: method = method_override # use method_override else: raise Exception(f'Endpoint "{endpoint}" with method "{method_override}" unsupported') with requests.Session() as session: session.auth = self.auth session.headers = {'User-Agent': self.USER_AGENT} url = self._prepare_url(subdomain, resource) if self.version == '1.1' and 'stream' in subdomain: session.stream = True timeout = self.STREAMING_TIMEOUT if not params: params = {} params['delimited'] = 'length' params['stall_warnings'] = 'true' elif self.version == '2' and resource.endswith('/stream'): session.stream = True timeout = self.STREAMING_TIMEOUT else: session.stream = False timeout = self.REST_TIMEOUT d = p = j = None if method == 'POST': if self.version == '1.1': d = params else: j = params elif method == 'PUT': j = params else: p = params try: if False and method == 'PUT': session.headers['Content-type'] = 'application/json' data = params r = session.request( method, url, json=data) else: r = session.request( method, url, data=d, params=p, json=j, timeout=(self.CONNECTION_TIMEOUT, timeout), files=files, proxies=self.proxies) except (ConnectionError, ProtocolError, ReadTimeout, ReadTimeoutError, SSLError, ssl.SSLError, socket.error) as e: raise TwitterConnectionError(e) options = { 'api_version': self.version, 'is_stream': session.stream, 'hydrate_type': hydrate_type } return TwitterResponse(r, options)
[ "def", "request", "(", "self", ",", "resource", ",", "params", "=", "None", ",", "files", "=", "None", ",", "method_override", "=", "None", ",", "hydrate_type", "=", "HydrateType", ".", "NONE", ")", ":", "# check that the endpoint is valid", "resource", ",", ...
https://github.com/geduldig/TwitterAPI/blob/1cb89e8fc50b051707fb99d6c2bb235ada5faf1a/TwitterAPI/TwitterAPI.py#L145-L230
hyperledger/aries-cloudagent-python
2f36776e99f6053ae92eed8123b5b1b2e891c02a
aries_cloudagent/messaging/credential_definitions/routes.py
python
credential_definitions_send_credential_definition
(request: web.BaseRequest)
Request handler for sending a credential definition to the ledger. Args: request: aiohttp request object Returns: The credential definition identifier
Request handler for sending a credential definition to the ledger.
[ "Request", "handler", "for", "sending", "a", "credential", "definition", "to", "the", "ledger", "." ]
async def credential_definitions_send_credential_definition(request: web.BaseRequest): """ Request handler for sending a credential definition to the ledger. Args: request: aiohttp request object Returns: The credential definition identifier """ context: AdminRequestContext = request["context"] profile = context.profile outbound_handler = request["outbound_message_router"] create_transaction_for_endorser = json.loads( request.query.get("create_transaction_for_endorser", "false") ) write_ledger = not create_transaction_for_endorser endorser_did = None connection_id = request.query.get("conn_id") body = await request.json() schema_id = body.get("schema_id") support_revocation = bool(body.get("support_revocation")) tag = body.get("tag") rev_reg_size = body.get("revocation_registry_size") # check if we need to endorse if is_author_role(context.profile): # authors cannot write to the ledger write_ledger = False create_transaction_for_endorser = True if not connection_id: # author has not provided a connection id, so determine which to use connection_id = await get_endorser_connection_id(context.profile) if not connection_id: raise web.HTTPBadRequest(reason="No endorser connection found") if not write_ledger: try: async with profile.session() as session: connection_record = await ConnRecord.retrieve_by_id( session, connection_id ) except StorageNotFoundError as err: raise web.HTTPNotFound(reason=err.roll_up) from err except BaseModelError as err: raise web.HTTPBadRequest(reason=err.roll_up) from err async with profile.session() as session: endorser_info = await connection_record.metadata_get( session, "endorser_info" ) if not endorser_info: raise web.HTTPForbidden( reason="Endorser Info is not set up in " "connection metadata for this connection record" ) if "endorser_did" not in endorser_info.keys(): raise web.HTTPForbidden( reason=' "endorser_did" is not set in "endorser_info"' " in connection metadata for this connection record" ) endorser_did = endorser_info["endorser_did"] ledger = context.inject_or(BaseLedger) if not ledger: reason = "No ledger available" if not context.settings.get_value("wallet.type"): reason += ": missing wallet-type?" raise web.HTTPForbidden(reason=reason) issuer = context.inject(IndyIssuer) try: # even if in wallet, send it and raise if erroneously so async with ledger: (cred_def_id, cred_def, novel) = await shield( ledger.create_and_send_credential_definition( issuer, schema_id, signature_type=None, tag=tag, support_revocation=support_revocation, write_ledger=write_ledger, endorser_did=endorser_did, ) ) except (IndyIssuerError, LedgerError) as e: raise web.HTTPBadRequest(reason=e.message) from e meta_data = { "context": { "schema_id": schema_id, "support_revocation": support_revocation, "novel": novel, "tag": tag, "rev_reg_size": rev_reg_size, }, "processing": { "create_pending_rev_reg": True, }, } if not create_transaction_for_endorser: # Notify event issuer_did = cred_def_id.split(":")[0] meta_data["context"]["schema_id"] = schema_id meta_data["context"]["cred_def_id"] = cred_def_id meta_data["context"]["issuer_did"] = issuer_did meta_data["processing"]["auto_create_rev_reg"] = True await notify_cred_def_event(context.profile, cred_def_id, meta_data) return web.json_response({"credential_definition_id": cred_def_id}) else: meta_data["processing"]["auto_create_rev_reg"] = context.settings.get_value( "endorser.auto_create_rev_reg" ) transaction_mgr = TransactionManager(context.profile) try: transaction = await transaction_mgr.create_record( messages_attach=cred_def["signed_txn"], connection_id=connection_id, meta_data=meta_data, ) except StorageError as err: raise web.HTTPBadRequest(reason=err.roll_up) from err # if auto-request, send the request to the endorser if context.settings.get_value("endorser.auto_request"): try: transaction, transaction_request = await transaction_mgr.create_request( transaction=transaction, # TODO see if we need to parameterize these params # expires_time=expires_time, # endorser_write_txn=endorser_write_txn, ) except (StorageError, TransactionManagerError) as err: raise web.HTTPBadRequest(reason=err.roll_up) from err await outbound_handler(transaction_request, connection_id=connection_id) return web.json_response({"txn": transaction.serialize()})
[ "async", "def", "credential_definitions_send_credential_definition", "(", "request", ":", "web", ".", "BaseRequest", ")", ":", "context", ":", "AdminRequestContext", "=", "request", "[", "\"context\"", "]", "profile", "=", "context", ".", "profile", "outbound_handler"...
https://github.com/hyperledger/aries-cloudagent-python/blob/2f36776e99f6053ae92eed8123b5b1b2e891c02a/aries_cloudagent/messaging/credential_definitions/routes.py#L159-L304