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
OctoPrint/OctoPrint
4b12b0e6f06c3abfb31b1840a0605e2de8e911d2
src/octoprint/vendor/flask_principal.py
python
Permission.issubset
(self, other)
return ( self.needs.issubset(other.needs) and self.excludes.issubset(other.excludes) )
Whether this permission needs are a subset of another :param other: The other permission
Whether this permission needs are a subset of another
[ "Whether", "this", "permission", "needs", "are", "a", "subset", "of", "another" ]
def issubset(self, other): """Whether this permission needs are a subset of another :param other: The other permission """ return ( self.needs.issubset(other.needs) and self.excludes.issubset(other.excludes) )
[ "def", "issubset", "(", "self", ",", "other", ")", ":", "return", "(", "self", ".", "needs", ".", "issubset", "(", "other", ".", "needs", ")", "and", "self", ".", "excludes", ".", "issubset", "(", "other", ".", "excludes", ")", ")" ]
https://github.com/OctoPrint/OctoPrint/blob/4b12b0e6f06c3abfb31b1840a0605e2de8e911d2/src/octoprint/vendor/flask_principal.py#L318-L326
realpython/book2-exercises
cde325eac8e6d8cff2316601c2e5b36bb46af7d0
web2py/venv/lib/python2.7/site-packages/pip/index.py
python
PackageFinder._link_package_versions
(self, link, search)
return InstallationCandidate(search.supplied, version, link)
Return an InstallationCandidate or None
Return an InstallationCandidate or None
[ "Return", "an", "InstallationCandidate", "or", "None" ]
def _link_package_versions(self, link, search): """Return an InstallationCandidate or None""" version = None if link.egg_fragment: egg_info = link.egg_fragment ext = link.ext else: egg_info, ext = link.splitext() if not ext: self._log_skipped_link(link, 'not a file') return if ext not in SUPPORTED_EXTENSIONS: self._log_skipped_link( link, 'unsupported archive format: %s' % ext) return if "binary" not in search.formats and ext == wheel_ext: self._log_skipped_link( link, 'No binaries permitted for %s' % search.supplied) return if "macosx10" in link.path and ext == '.zip': self._log_skipped_link(link, 'macosx10 one') return if ext == wheel_ext: try: wheel = Wheel(link.filename) except InvalidWheelFilename: self._log_skipped_link(link, 'invalid wheel filename') return if canonicalize_name(wheel.name) != search.canonical: self._log_skipped_link( link, 'wrong project name (not %s)' % search.supplied) return if not wheel.supported(self.valid_tags): self._log_skipped_link( link, 'it is not compatible with this Python') return version = wheel.version # This should be up by the search.ok_binary check, but see issue 2700. if "source" not in search.formats and ext != wheel_ext: self._log_skipped_link( link, 'No sources permitted for %s' % search.supplied) return if not version: version = egg_info_matches(egg_info, search.supplied, link) if version is None: self._log_skipped_link( link, 'wrong project name (not %s)' % search.supplied) return match = self._py_version_re.search(version) if match: version = version[:match.start()] py_version = match.group(1) if py_version != sys.version[:3]: self._log_skipped_link( link, 'Python version is incorrect') return try: support_this_python = check_requires_python(link.requires_python) except specifiers.InvalidSpecifier: logger.debug("Package %s has an invalid Requires-Python entry: %s", link.filename, link.requires_python) support_this_python = True if not support_this_python: logger.debug("The package %s is incompatible with the python" "version in use. Acceptable python versions are:%s", link, link.requires_python) return logger.debug('Found link %s, version: %s', link, version) return InstallationCandidate(search.supplied, version, link)
[ "def", "_link_package_versions", "(", "self", ",", "link", ",", "search", ")", ":", "version", "=", "None", "if", "link", ".", "egg_fragment", ":", "egg_info", "=", "link", ".", "egg_fragment", "ext", "=", "link", ".", "ext", "else", ":", "egg_info", ","...
https://github.com/realpython/book2-exercises/blob/cde325eac8e6d8cff2316601c2e5b36bb46af7d0/web2py/venv/lib/python2.7/site-packages/pip/index.py#L605-L680
Ha0Tang/SelectionGAN
80aa7ad9f79f643c28633c40c621f208f3fb0121
person_transfer/models/PATN.py
python
TransferModel.save
(self, label)
[]
def save(self, label): self.save_network(self.netG1, 'netG1', label, self.gpu_ids) self.save_network(self.netG2, 'netG2', label, self.gpu_ids) if self.opt.with_D_PB: self.save_network(self.netD_PB, 'netD_PB', label, self.gpu_ids) if self.opt.with_D_PP: self.save_network(self.netD_PP, 'netD_PP', label, self.gpu_ids)
[ "def", "save", "(", "self", ",", "label", ")", ":", "self", ".", "save_network", "(", "self", ".", "netG1", ",", "'netG1'", ",", "label", ",", "self", ".", "gpu_ids", ")", "self", ".", "save_network", "(", "self", ".", "netG2", ",", "'netG2'", ",", ...
https://github.com/Ha0Tang/SelectionGAN/blob/80aa7ad9f79f643c28633c40c621f208f3fb0121/person_transfer/models/PATN.py#L311-L317
robhagemans/pcbasic
c3a043b46af66623a801e18a38175be077251ada
pcbasic/basic/devices/disk.py
python
dos_to_native_name
(native_path, dosname, isdir)
return None
Find a matching native file name for a given normalised DOS name.
Find a matching native file name for a given normalised DOS name.
[ "Find", "a", "matching", "native", "file", "name", "for", "a", "given", "normalised", "DOS", "name", "." ]
def dos_to_native_name(native_path, dosname, isdir): """Find a matching native file name for a given normalised DOS name.""" try: uni_name = dosname.decode('ascii') except UnicodeDecodeError: # non-ascii characters are not allowable for DOS filenames, no match return None # check if the 8.3 uppercase exists, prefer if so if istype(native_path, uni_name, isdir): return uni_name # otherwise try in lexicographic order try: all_names = os.listdir(native_path) except EnvironmentError: # report no match if listdir fails return None for f in sorted(all_names): # we won't match non-ascii anyway try: ascii_name = f.encode('ascii') except UnicodeEncodeError: continue # don't match long names or non-legal dos names if dos_is_legal_name(ascii_name): try_name = dos_normalise_name(ascii_name) if try_name == dosname and istype(native_path, f, isdir): return f return None
[ "def", "dos_to_native_name", "(", "native_path", ",", "dosname", ",", "isdir", ")", ":", "try", ":", "uni_name", "=", "dosname", ".", "decode", "(", "'ascii'", ")", "except", "UnicodeDecodeError", ":", "# non-ascii characters are not allowable for DOS filenames, no matc...
https://github.com/robhagemans/pcbasic/blob/c3a043b46af66623a801e18a38175be077251ada/pcbasic/basic/devices/disk.py#L179-L206
PaddlePaddle/PaddleSpeech
26524031d242876b7fdb71582b0b3a7ea45c7d9d
paddlespeech/s2t/training/updaters/standard_updater.py
python
StandardUpdater.state_dict
(self)
return state_dict
State dict of a Updater, model, optimizers/schedulers and updater state are included.
State dict of a Updater, model, optimizers/schedulers and updater state are included.
[ "State", "dict", "of", "a", "Updater", "model", "optimizers", "/", "schedulers", "and", "updater", "state", "are", "included", "." ]
def state_dict(self): """State dict of a Updater, model, optimizers/schedulers and updater state are included.""" state_dict = super().state_dict() for name, model in self.models.items(): state_dict[f"{name}_params"] = model.state_dict() for name, optim in self.optimizers.items(): state_dict[f"{name}_optimizer"] = optim.state_dict() return state_dict
[ "def", "state_dict", "(", "self", ")", ":", "state_dict", "=", "super", "(", ")", ".", "state_dict", "(", ")", "for", "name", ",", "model", "in", "self", ".", "models", ".", "items", "(", ")", ":", "state_dict", "[", "f\"{name}_params\"", "]", "=", "...
https://github.com/PaddlePaddle/PaddleSpeech/blob/26524031d242876b7fdb71582b0b3a7ea45c7d9d/paddlespeech/s2t/training/updaters/standard_updater.py#L179-L187
stratosphereips/Manati
20e55d49edf00f8503807c62397d02a0dad9ddff
manati/api_manager/models.py
python
ExternalModuleManager.find_by_event
(self, event_name)
return etss
[]
def find_by_event(self, event_name): ets= ExternalModule.objects.filter(run_in_events__contains=event_name)\ .exclude(status=ExternalModule.MODULES_STATUS.removed).distinct() etss = [] for et in ets: run_in_events = json.loads(et.run_in_events) if event_name in run_in_events: etss.append(et) return etss
[ "def", "find_by_event", "(", "self", ",", "event_name", ")", ":", "ets", "=", "ExternalModule", ".", "objects", ".", "filter", "(", "run_in_events__contains", "=", "event_name", ")", ".", "exclude", "(", "status", "=", "ExternalModule", ".", "MODULES_STATUS", ...
https://github.com/stratosphereips/Manati/blob/20e55d49edf00f8503807c62397d02a0dad9ddff/manati/api_manager/models.py#L54-L62
sdaps/sdaps
51d1072185223f5e48512661e2c1e8399d63e876
sdaps/gui/buddies.py
python
centered_circle
(cr, x, y, radius)
[]
def centered_circle(cr, x, y, radius): inner_ellipse(cr, x - radius, y - radius, 2*radius, 2*radius)
[ "def", "centered_circle", "(", "cr", ",", "x", ",", "y", ",", "radius", ")", ":", "inner_ellipse", "(", "cr", ",", "x", "-", "radius", ",", "y", "-", "radius", ",", "2", "*", "radius", ",", "2", "*", "radius", ")" ]
https://github.com/sdaps/sdaps/blob/51d1072185223f5e48512661e2c1e8399d63e876/sdaps/gui/buddies.py#L70-L71
KalleHallden/AutoTimer
2d954216700c4930baa154e28dbddc34609af7ce
env/lib/python2.7/site-packages/pip/_vendor/ipaddress.py
python
_IPAddressBase._prefix_from_prefix_string
(cls, prefixlen_str)
return prefixlen
Return prefix length from a numeric string Args: prefixlen_str: The string to be converted Returns: An integer, the prefix length. Raises: NetmaskValueError: If the input is not a valid netmask
Return prefix length from a numeric string
[ "Return", "prefix", "length", "from", "a", "numeric", "string" ]
def _prefix_from_prefix_string(cls, prefixlen_str): """Return prefix length from a numeric string Args: prefixlen_str: The string to be converted Returns: An integer, the prefix length. Raises: NetmaskValueError: If the input is not a valid netmask """ # int allows a leading +/- as well as surrounding whitespace, # so we ensure that isn't the case if not _BaseV4._DECIMAL_DIGITS.issuperset(prefixlen_str): cls._report_invalid_netmask(prefixlen_str) try: prefixlen = int(prefixlen_str) except ValueError: cls._report_invalid_netmask(prefixlen_str) if not (0 <= prefixlen <= cls._max_prefixlen): cls._report_invalid_netmask(prefixlen_str) return prefixlen
[ "def", "_prefix_from_prefix_string", "(", "cls", ",", "prefixlen_str", ")", ":", "# int allows a leading +/- as well as surrounding whitespace,", "# so we ensure that isn't the case", "if", "not", "_BaseV4", ".", "_DECIMAL_DIGITS", ".", "issuperset", "(", "prefixlen_str", ")", ...
https://github.com/KalleHallden/AutoTimer/blob/2d954216700c4930baa154e28dbddc34609af7ce/env/lib/python2.7/site-packages/pip/_vendor/ipaddress.py#L600-L622
apache/tvm
6eb4ed813ebcdcd9558f0906a1870db8302ff1e0
python/tvm/autotvm/graph_tuner/base_graph_tuner.py
python
BaseGraphTuner.get_optimal_records
(self)
return ret
Convert optimal record dictionary to a list of records with ascending order of node index in graph. Returns ------- sch_list : list of tuple List of records with ascending order of node index in graph.
Convert optimal record dictionary to a list of records with ascending order of node index in graph.
[ "Convert", "optimal", "record", "dictionary", "to", "a", "list", "of", "records", "with", "ascending", "order", "of", "node", "index", "in", "graph", "." ]
def get_optimal_records(self): """Convert optimal record dictionary to a list of records with ascending order of node index in graph. Returns ------- sch_list : list of tuple List of records with ascending order of node index in graph. """ ordered_index_list = sorted(self._optimal_record_dict.keys()) ret = [] for index in ordered_index_list: node_entry = self._node_list[index] if node_entry["op"] not in self._target_ops: continue ret.append(node_entry["record_candidates"][self._optimal_record_dict[index]]) return ret
[ "def", "get_optimal_records", "(", "self", ")", ":", "ordered_index_list", "=", "sorted", "(", "self", ".", "_optimal_record_dict", ".", "keys", "(", ")", ")", "ret", "=", "[", "]", "for", "index", "in", "ordered_index_list", ":", "node_entry", "=", "self", ...
https://github.com/apache/tvm/blob/6eb4ed813ebcdcd9558f0906a1870db8302ff1e0/python/tvm/autotvm/graph_tuner/base_graph_tuner.py#L556-L572
ilastik/ilastik
6acd2c554bc517e9c8ddad3623a7aaa2e6970c28
lazyflow/request/request.py
python
RequestPool.__len__
(self)
Returns the number of requests that we haven't discarded yet and therefore haven't completely finished. This len will decrease until the RequestPool has completed or failed.
Returns the number of requests that we haven't discarded yet and therefore haven't completely finished.
[ "Returns", "the", "number", "of", "requests", "that", "we", "haven", "t", "discarded", "yet", "and", "therefore", "haven", "t", "completely", "finished", "." ]
def __len__(self): """ Returns the number of requests that we haven't discarded yet and therefore haven't completely finished. This len will decrease until the RequestPool has completed or failed. """ with self._set_lock: return len(self._unsubmitted_requests) + len(self._active_requests) + len(self._finishing_requests)
[ "def", "__len__", "(", "self", ")", ":", "with", "self", ".", "_set_lock", ":", "return", "len", "(", "self", ".", "_unsubmitted_requests", ")", "+", "len", "(", "self", ".", "_active_requests", ")", "+", "len", "(", "self", ".", "_finishing_requests", "...
https://github.com/ilastik/ilastik/blob/6acd2c554bc517e9c8ddad3623a7aaa2e6970c28/lazyflow/request/request.py#L1286-L1294
SAP-archive/PyHDB
667ed1f069ca9282deb792a6dde987c1ab488362
pyhdb/protocol/parts.py
python
Parameters.pack_lob_data
(remaining_size, payload, row_header_start_pos, row_lobs)
return unwritten_lobs
After parameter row has been written, append the lobs and update the corresponding lob headers with lob position and lob size: :param payload: payload object (io.BytesIO instance) :param row_header_start_pos: absolute position of start position of row within payload :param row_lobs: list of row buffer instance (containing binary encoded lob data, header position and DataType)
After parameter row has been written, append the lobs and update the corresponding lob headers with lob position and lob size: :param payload: payload object (io.BytesIO instance) :param row_header_start_pos: absolute position of start position of row within payload :param row_lobs: list of row buffer instance (containing binary encoded lob data, header position and DataType)
[ "After", "parameter", "row", "has", "been", "written", "append", "the", "lobs", "and", "update", "the", "corresponding", "lob", "headers", "with", "lob", "position", "and", "lob", "size", ":", ":", "param", "payload", ":", "payload", "object", "(", "io", "...
def pack_lob_data(remaining_size, payload, row_header_start_pos, row_lobs): """ After parameter row has been written, append the lobs and update the corresponding lob headers with lob position and lob size: :param payload: payload object (io.BytesIO instance) :param row_header_start_pos: absolute position of start position of row within payload :param row_lobs: list of row buffer instance (containing binary encoded lob data, header position and DataType) """ unwritten_lobs = collections.deque() for lob_buffer in row_lobs: # Calculate relative position of lob within the binary packed parameter row. # Add +1, Hana counts from 1, not 0! rel_lob_pos = payload.tell() - row_header_start_pos + 1 # Calculate how much space is left in message for lob data: max_data_to_write = min(lob_buffer.encoded_lob_size, remaining_size - payload.tell()) payload.write(lob_buffer.encoded_data.read(max_data_to_write)) is_last_data = max_data_to_write == lob_buffer.encoded_lob_size if not is_last_data: # lob has not been written (partially or entirely) into message -> register for further write requests unwritten_lobs.append(lob_buffer) # Write position and size of lob data into lob header block: payload.seek(lob_buffer.lob_header_pos) payload.write(lob_buffer.DataType.prepare(None, length=max_data_to_write, position=rel_lob_pos, is_last_data=is_last_data)) # Set pointer back to end for further writing payload.seek(0, io.SEEK_END) return unwritten_lobs
[ "def", "pack_lob_data", "(", "remaining_size", ",", "payload", ",", "row_header_start_pos", ",", "row_lobs", ")", ":", "unwritten_lobs", "=", "collections", ".", "deque", "(", ")", "for", "lob_buffer", "in", "row_lobs", ":", "# Calculate relative position of lob withi...
https://github.com/SAP-archive/PyHDB/blob/667ed1f069ca9282deb792a6dde987c1ab488362/pyhdb/protocol/parts.py#L545-L573
ni/nidaqmx-python
62fc6b48cbbb330fe1bcc9aedadc86610a1269b6
nidaqmx/_task_modules/triggering/start_trigger.py
python
StartTrigger.anlg_edge_lvl
(self)
[]
def anlg_edge_lvl(self): cfunc = lib_importer.windll.DAQmxResetAnlgEdgeStartTrigLvl if cfunc.argtypes is None: with cfunc.arglock: if cfunc.argtypes is None: cfunc.argtypes = [ lib_importer.task_handle] error_code = cfunc( self._handle) check_for_error(error_code)
[ "def", "anlg_edge_lvl", "(", "self", ")", ":", "cfunc", "=", "lib_importer", ".", "windll", ".", "DAQmxResetAnlgEdgeStartTrigLvl", "if", "cfunc", ".", "argtypes", "is", "None", ":", "with", "cfunc", ".", "arglock", ":", "if", "cfunc", ".", "argtypes", "is", ...
https://github.com/ni/nidaqmx-python/blob/62fc6b48cbbb330fe1bcc9aedadc86610a1269b6/nidaqmx/_task_modules/triggering/start_trigger.py#L434-L444
bnpy/bnpy
d5b311e8f58ccd98477f4a0c8a4d4982e3fca424
bnpy/allocmodel/topics/HDPTopicModel.py
python
HDPTopicModel.update_global_params_VB
(self, SS, rho=None, mergeCompA=None, mergeCompB=None, sortorder=None, **kwargs)
Update global parameters.
Update global parameters.
[ "Update", "global", "parameters", "." ]
def update_global_params_VB(self, SS, rho=None, mergeCompA=None, mergeCompB=None, sortorder=None, **kwargs): ''' Update global parameters. ''' if mergeCompA is None: # Standard case: # Update via gradient descent. rho, omega = self._find_optimum_rhoomega(SS, **kwargs) else: # Special update case for merges: # Fast, heuristic update for rho and omega directly from existing # values beta = rho2beta_active(self.rho) beta[mergeCompA] += beta[mergeCompB] beta = np.delete(beta, mergeCompB, axis=0) rho = beta2rho(beta, SS.K) omega = self.omega omega[mergeCompA] += omega[mergeCompB] omega = np.delete(omega, mergeCompB, axis=0) self.rho = rho self.omega = omega self.K = SS.K self.ClearCache()
[ "def", "update_global_params_VB", "(", "self", ",", "SS", ",", "rho", "=", "None", ",", "mergeCompA", "=", "None", ",", "mergeCompB", "=", "None", ",", "sortorder", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "mergeCompA", "is", "None", ":", ...
https://github.com/bnpy/bnpy/blob/d5b311e8f58ccd98477f4a0c8a4d4982e3fca424/bnpy/allocmodel/topics/HDPTopicModel.py#L431-L455
hypothesis/h
25ef1b8d94889df86ace5a084f1aa0effd9f4e25
h/services/group.py
python
GroupService.groupids_created_by
(self, user)
return [ g.pubid for g in self.session.query(Group.pubid).filter_by(creator=user) ]
Return a list of pubids which the user created. If the passed-in user is ``None``, this returns an empty list. :type user: `h.models.user.User` or None
Return a list of pubids which the user created.
[ "Return", "a", "list", "of", "pubids", "which", "the", "user", "created", "." ]
def groupids_created_by(self, user): """ Return a list of pubids which the user created. If the passed-in user is ``None``, this returns an empty list. :type user: `h.models.user.User` or None """ if user is None: return [] return [ g.pubid for g in self.session.query(Group.pubid).filter_by(creator=user) ]
[ "def", "groupids_created_by", "(", "self", ",", "user", ")", ":", "if", "user", "is", "None", ":", "return", "[", "]", "return", "[", "g", ".", "pubid", "for", "g", "in", "self", ".", "session", ".", "query", "(", "Group", ".", "pubid", ")", ".", ...
https://github.com/hypothesis/h/blob/25ef1b8d94889df86ace5a084f1aa0effd9f4e25/h/services/group.py#L107-L120
falconry/falcon
ee97769eab6a951864876202474133446aa50297
falcon/asgi/app.py
python
App._handle_exception
(self, req, resp, ex, params, ws=None)
return False
Handle an exception raised from mw or a responder. Args: ex: Exception to handle req: Current request object to pass to the handler registered for the given exception type resp: Current response object to pass to the handler registered for the given exception type. Will be ``None`` in the case of a WebSocket request. params: Responder params to pass to the handler registered for the given exception type Keyword Args: ws: WebSocket instance in the case that the error was raised while handling a WebSocket connection. Returns: bool: ``True`` if a handler was found and called for the exception, ``False`` otherwise.
Handle an exception raised from mw or a responder.
[ "Handle", "an", "exception", "raised", "from", "mw", "or", "a", "responder", "." ]
async def _handle_exception(self, req, resp, ex, params, ws=None): """Handle an exception raised from mw or a responder. Args: ex: Exception to handle req: Current request object to pass to the handler registered for the given exception type resp: Current response object to pass to the handler registered for the given exception type. Will be ``None`` in the case of a WebSocket request. params: Responder params to pass to the handler registered for the given exception type Keyword Args: ws: WebSocket instance in the case that the error was raised while handling a WebSocket connection. Returns: bool: ``True`` if a handler was found and called for the exception, ``False`` otherwise. """ err_handler = self._find_error_handler(ex) if resp: # NOTE(caselit): Reset body, data and media before calling the handler resp.text = resp.data = resp.media = None if err_handler is not None: try: kwargs = {} if ws and 'ws' in falcon.util.get_argnames(err_handler): kwargs['ws'] = ws await err_handler(req, resp, ex, params, **kwargs) except HTTPStatus as status: self._compose_status_response(req, resp, status) except HTTPError as error: self._compose_error_response(req, resp, error) return True # NOTE(kgriffs): No error handlers are defined for ex # and it is not one of (HTTPStatus, HTTPError), since it # would have matched one of the corresponding default # handlers. return False
[ "async", "def", "_handle_exception", "(", "self", ",", "req", ",", "resp", ",", "ex", ",", "params", ",", "ws", "=", "None", ")", ":", "err_handler", "=", "self", ".", "_find_error_handler", "(", "ex", ")", "if", "resp", ":", "# NOTE(caselit): Reset body, ...
https://github.com/falconry/falcon/blob/ee97769eab6a951864876202474133446aa50297/falcon/asgi/app.py#L1061-L1108
privacyidea/privacyidea
9490c12ddbf77a34ac935b082d09eb583dfafa2c
privacyidea/models.py
python
PeriodicTaskLastRun.__init__
(self, periodictask_id, node, timestamp)
:param periodictask_id: ID of the periodic task we are referring to :param node: Node name as unicode :param timestamp: Time of the last run as a datetime. A timezone must not be set! We require the time to be given in UTC.
:param periodictask_id: ID of the periodic task we are referring to :param node: Node name as unicode :param timestamp: Time of the last run as a datetime. A timezone must not be set! We require the time to be given in UTC.
[ ":", "param", "periodictask_id", ":", "ID", "of", "the", "periodic", "task", "we", "are", "referring", "to", ":", "param", "node", ":", "Node", "name", "as", "unicode", ":", "param", "timestamp", ":", "Time", "of", "the", "last", "run", "as", "a", "dat...
def __init__(self, periodictask_id, node, timestamp): """ :param periodictask_id: ID of the periodic task we are referring to :param node: Node name as unicode :param timestamp: Time of the last run as a datetime. A timezone must not be set! We require the time to be given in UTC. """ self.periodictask_id = periodictask_id self.node = node self.timestamp = timestamp self.save()
[ "def", "__init__", "(", "self", ",", "periodictask_id", ",", "node", ",", "timestamp", ")", ":", "self", ".", "periodictask_id", "=", "periodictask_id", "self", ".", "node", "=", "node", "self", ".", "timestamp", "=", "timestamp", "self", ".", "save", "(",...
https://github.com/privacyidea/privacyidea/blob/9490c12ddbf77a34ac935b082d09eb583dfafa2c/privacyidea/models.py#L2994-L3004
nltk/nltk_contrib
c9da2c29777ca9df650740145f1f4a375ccac961
nltk_contrib/mit/six863/semantics/logic.py
python
Parser.next
(self)
Parse the next complete expression from the stream and return it.
Parse the next complete expression from the stream and return it.
[ "Parse", "the", "next", "complete", "expression", "from", "the", "stream", "and", "return", "it", "." ]
def next(self): """Parse the next complete expression from the stream and return it.""" tok = self.token() if tok in [Parser.LAMBDA, Parser.SOME, Parser.ALL]: # Expression is a lambda expression: \x.M # or a some expression: some x.M if tok == Parser.LAMBDA: factory = self.make_LambdaExpression elif tok == Parser.SOME: factory = self.make_SomeExpression elif tok == Parser.ALL: factory = self.make_AllExpression else: raise ValueError(tok) vars = [self.token()] while self.isVariable(self.token(0)): # Support expressions like: \x y.M == \x.\y.M # and: some x y.M == some x.some y.M vars.append(self.token()) tok = self.token() if tok != Parser.DOT: raise Error, "parse error, unexpected token: %s" % tok term = self.next() accum = factory(Variable(vars.pop()), term) while vars: accum = factory(Variable(vars.pop()), accum) return accum elif tok == Parser.OPEN: # Expression is an application expression: (M N) first = self.next() second = self.next() exps = [] while self.token(0) != Parser.CLOSE: # Support expressions like: (M N P) == ((M N) P) exps.append(self.next()) tok = self.token() # swallow the close token assert tok == Parser.CLOSE if isinstance(second, Operator): accum = self.make_ApplicationExpression(second, first) else: accum = self.make_ApplicationExpression(first, second) while exps: exp, exps = exps[0], exps[1:] accum = self.make_ApplicationExpression(accum, exp) return accum elif tok in self.constants: # Expression is a simple constant expression: a return ConstantExpression(Constant(tok)) elif tok in Parser.OPS: # Expression is a boolean operator or the equality symbol return Operator(tok) elif is_indvar(tok): # Expression is a boolean operator or the equality symbol return IndVariableExpression(Variable(tok)) else: if self.isVariable(tok): # Expression is a simple variable expression: x return VariableExpression(Variable(tok)) else: raise Error, "parse error, unexpected token: %s" % tok
[ "def", "next", "(", "self", ")", ":", "tok", "=", "self", ".", "token", "(", ")", "if", "tok", "in", "[", "Parser", ".", "LAMBDA", ",", "Parser", ".", "SOME", ",", "Parser", ".", "ALL", "]", ":", "# Expression is a lambda expression: \\x.M", "# or a some...
https://github.com/nltk/nltk_contrib/blob/c9da2c29777ca9df650740145f1f4a375ccac961/nltk_contrib/mit/six863/semantics/logic.py#L657-L724
mcneel/rhinoscriptsyntax
c49bd0bf24c2513bdcb84d1bf307144489600fd9
Scripts/rhinoscript/surface.py
python
AddSrfPt
(points)
return rc
Creates a new surface from either 3 or 4 corner points. Parameters: points ([point, point, point, point]): list of either 3 or 4 corner points Returns: guid: The identifier of the new object if successful. None: if not successful, or on error. Example: import rhinoscriptsyntax as rs points = rs.GetPoints(True, message1="Pick 3 or 4 corner points") if points: rs.AddSrfPt(points) See Also: AddEdgeSrf AddSrfControlPtGrid AddSrfPtGrid
Creates a new surface from either 3 or 4 corner points. Parameters: points ([point, point, point, point]): list of either 3 or 4 corner points Returns: guid: The identifier of the new object if successful. None: if not successful, or on error. Example: import rhinoscriptsyntax as rs points = rs.GetPoints(True, message1="Pick 3 or 4 corner points") if points: rs.AddSrfPt(points) See Also: AddEdgeSrf AddSrfControlPtGrid AddSrfPtGrid
[ "Creates", "a", "new", "surface", "from", "either", "3", "or", "4", "corner", "points", ".", "Parameters", ":", "points", "(", "[", "point", "point", "point", "point", "]", ")", ":", "list", "of", "either", "3", "or", "4", "corner", "points", "Returns"...
def AddSrfPt(points): """Creates a new surface from either 3 or 4 corner points. Parameters: points ([point, point, point, point]): list of either 3 or 4 corner points Returns: guid: The identifier of the new object if successful. None: if not successful, or on error. Example: import rhinoscriptsyntax as rs points = rs.GetPoints(True, message1="Pick 3 or 4 corner points") if points: rs.AddSrfPt(points) See Also: AddEdgeSrf AddSrfControlPtGrid AddSrfPtGrid """ points = rhutil.coerce3dpointlist(points, True) surface=None if len(points)==3: surface = Rhino.Geometry.NurbsSurface.CreateFromCorners(points[0], points[1], points[2]) elif len(points)==4: surface = Rhino.Geometry.NurbsSurface.CreateFromCorners(points[0], points[1], points[2], points[3]) if surface is None: return scriptcontext.errorhandler() rc = scriptcontext.doc.Objects.AddSurface(surface) if rc==System.Guid.Empty: return scriptcontext.errorhandler() scriptcontext.doc.Views.Redraw() return rc
[ "def", "AddSrfPt", "(", "points", ")", ":", "points", "=", "rhutil", ".", "coerce3dpointlist", "(", "points", ",", "True", ")", "surface", "=", "None", "if", "len", "(", "points", ")", "==", "3", ":", "surface", "=", "Rhino", ".", "Geometry", ".", "N...
https://github.com/mcneel/rhinoscriptsyntax/blob/c49bd0bf24c2513bdcb84d1bf307144489600fd9/Scripts/rhinoscript/surface.py#L648-L674
aewallin/openvoronoi
c4366904dc7ac40c189e95ebb014db7e4b137b86
python_examples/ttt/ttt_0_single_glyph.py
python
center
(segs, exts, tscale)
return out
translate segments so they are centered around (0,0)
translate segments so they are centered around (0,0)
[ "translate", "segments", "so", "they", "are", "centered", "around", "(", "0", "0", ")" ]
def center(segs, exts, tscale): """ translate segments so they are centered around (0,0) """ minx = tscale * exts.minx maxx = tscale * exts.maxx miny = tscale * exts.miny maxy = tscale * exts.maxy meanx = minx + 0.5 * (maxx - minx) meany = miny + 0.5 * (maxy - miny) out = translate(segs, -meanx, -meany) return out
[ "def", "center", "(", "segs", ",", "exts", ",", "tscale", ")", ":", "minx", "=", "tscale", "*", "exts", ".", "minx", "maxx", "=", "tscale", "*", "exts", ".", "maxx", "miny", "=", "tscale", "*", "exts", ".", "miny", "maxy", "=", "tscale", "*", "ex...
https://github.com/aewallin/openvoronoi/blob/c4366904dc7ac40c189e95ebb014db7e4b137b86/python_examples/ttt/ttt_0_single_glyph.py#L78-L88
yuxiaokui/Intranet-Penetration
f57678a204840c83cbf3308e3470ae56c5ff514b
proxy/XX-Net/code/default/python27/1.0/lib/runpy.py
python
_run_module_as_main
(mod_name, alter_argv=True)
return _run_code(code, main_globals, None, "__main__", fname, loader, pkg_name)
Runs the designated module in the __main__ namespace Note that the executed module will have full access to the __main__ namespace. If this is not desirable, the run_module() function should be used to run the module code in a fresh namespace. At the very least, these variables in __main__ will be overwritten: __name__ __file__ __loader__ __package__
Runs the designated module in the __main__ namespace
[ "Runs", "the", "designated", "module", "in", "the", "__main__", "namespace" ]
def _run_module_as_main(mod_name, alter_argv=True): """Runs the designated module in the __main__ namespace Note that the executed module will have full access to the __main__ namespace. If this is not desirable, the run_module() function should be used to run the module code in a fresh namespace. At the very least, these variables in __main__ will be overwritten: __name__ __file__ __loader__ __package__ """ try: if alter_argv or mod_name != "__main__": # i.e. -m switch mod_name, loader, code, fname = _get_module_details(mod_name) else: # i.e. directory or zipfile execution mod_name, loader, code, fname = _get_main_module_details() except ImportError as exc: msg = "%s: %s" % (sys.executable, str(exc)) sys.exit(msg) pkg_name = mod_name.rpartition('.')[0] main_globals = sys.modules["__main__"].__dict__ if alter_argv: sys.argv[0] = fname return _run_code(code, main_globals, None, "__main__", fname, loader, pkg_name)
[ "def", "_run_module_as_main", "(", "mod_name", ",", "alter_argv", "=", "True", ")", ":", "try", ":", "if", "alter_argv", "or", "mod_name", "!=", "\"__main__\"", ":", "# i.e. -m switch", "mod_name", ",", "loader", ",", "code", ",", "fname", "=", "_get_module_de...
https://github.com/yuxiaokui/Intranet-Penetration/blob/f57678a204840c83cbf3308e3470ae56c5ff514b/proxy/XX-Net/code/default/python27/1.0/lib/runpy.py#L136-L162
ray-project/ray
703c1610348615dcb8c2d141a0c46675084660f5
rllib/policy/policy_template.py
python
build_policy_class
( name: str, framework: str, *, loss_fn: Optional[Callable[[ Policy, ModelV2, Type[TorchDistributionWrapper], SampleBatch ], Union[TensorType, List[TensorType]]]], get_default_config: Optional[Callable[[], TrainerConfigDict]] = None, stats_fn: Optional[Callable[[Policy, SampleBatch], Dict[ str, TensorType]]] = None, postprocess_fn: Optional[Callable[[ Policy, SampleBatch, Optional[Dict[Any, SampleBatch]], Optional[ "Episode"] ], SampleBatch]] = None, extra_action_out_fn: Optional[Callable[[ Policy, Dict[str, TensorType], List[TensorType], ModelV2, TorchDistributionWrapper ], Dict[str, TensorType]]] = None, extra_grad_process_fn: Optional[Callable[[ Policy, "torch.optim.Optimizer", TensorType ], Dict[str, TensorType]]] = None, # TODO: (sven) Replace "fetches" with "process". extra_learn_fetches_fn: Optional[Callable[[Policy], Dict[ str, TensorType]]] = None, optimizer_fn: Optional[Callable[[Policy, TrainerConfigDict], "torch.optim.Optimizer"]] = None, validate_spaces: Optional[Callable[ [Policy, gym.Space, gym.Space, TrainerConfigDict], None]] = None, before_init: Optional[Callable[ [Policy, gym.Space, gym.Space, TrainerConfigDict], None]] = None, before_loss_init: Optional[Callable[[ Policy, gym.spaces.Space, gym.spaces.Space, TrainerConfigDict ], None]] = None, after_init: Optional[Callable[ [Policy, gym.Space, gym.Space, TrainerConfigDict], None]] = None, _after_loss_init: Optional[Callable[[ Policy, gym.spaces.Space, gym.spaces.Space, TrainerConfigDict ], None]] = None, action_sampler_fn: Optional[Callable[[TensorType, List[ TensorType]], Tuple[TensorType, TensorType]]] = None, action_distribution_fn: Optional[Callable[[ Policy, ModelV2, TensorType, TensorType, TensorType ], Tuple[TensorType, type, List[TensorType]]]] = None, make_model: Optional[Callable[[ Policy, gym.spaces.Space, gym.spaces.Space, TrainerConfigDict ], ModelV2]] = None, make_model_and_action_dist: Optional[Callable[[ Policy, gym.spaces.Space, gym.spaces.Space, TrainerConfigDict ], Tuple[ModelV2, Type[TorchDistributionWrapper]]]] = None, compute_gradients_fn: Optional[Callable[[Policy, SampleBatch], Tuple[ ModelGradients, dict]]] = None, apply_gradients_fn: Optional[Callable[ [Policy, "torch.optim.Optimizer"], None]] = None, mixins: Optional[List[type]] = None, get_batch_divisibility_req: Optional[Callable[[Policy], int]] = None )
return policy_cls
Helper function for creating a new Policy class at runtime. Supports frameworks JAX and PyTorch. Args: name (str): name of the policy (e.g., "PPOTorchPolicy") framework (str): Either "jax" or "torch". loss_fn (Optional[Callable[[Policy, ModelV2, Type[TorchDistributionWrapper], SampleBatch], Union[TensorType, List[TensorType]]]]): Callable that returns a loss tensor. get_default_config (Optional[Callable[[None], TrainerConfigDict]]): Optional callable that returns the default config to merge with any overrides. If None, uses only(!) the user-provided PartialTrainerConfigDict as dict for this Policy. postprocess_fn (Optional[Callable[[Policy, SampleBatch, Optional[Dict[Any, SampleBatch]], Optional["Episode"]], SampleBatch]]): Optional callable for post-processing experience batches (called after the super's `postprocess_trajectory` method). stats_fn (Optional[Callable[[Policy, SampleBatch], Dict[str, TensorType]]]): Optional callable that returns a dict of values given the policy and training batch. If None, will use `TorchPolicy.extra_grad_info()` instead. The stats dict is used for logging (e.g. in TensorBoard). extra_action_out_fn (Optional[Callable[[Policy, Dict[str, TensorType], List[TensorType], ModelV2, TorchDistributionWrapper]], Dict[str, TensorType]]]): Optional callable that returns a dict of extra values to include in experiences. If None, no extra computations will be performed. extra_grad_process_fn (Optional[Callable[[Policy, "torch.optim.Optimizer", TensorType], Dict[str, TensorType]]]): Optional callable that is called after gradients are computed and returns a processing info dict. If None, will call the `TorchPolicy.extra_grad_process()` method instead. # TODO: (sven) dissolve naming mismatch between "learn" and "compute.." extra_learn_fetches_fn (Optional[Callable[[Policy], Dict[str, TensorType]]]): Optional callable that returns a dict of extra tensors from the policy after loss evaluation. If None, will call the `TorchPolicy.extra_compute_grad_fetches()` method instead. optimizer_fn (Optional[Callable[[Policy, TrainerConfigDict], "torch.optim.Optimizer"]]): Optional callable that returns a torch optimizer given the policy and config. If None, will call the `TorchPolicy.optimizer()` method instead (which returns a torch Adam optimizer). validate_spaces (Optional[Callable[[Policy, gym.Space, gym.Space, TrainerConfigDict], None]]): Optional callable that takes the Policy, observation_space, action_space, and config to check for correctness. If None, no spaces checking will be done. before_init (Optional[Callable[[Policy, gym.Space, gym.Space, TrainerConfigDict], None]]): Optional callable to run at the beginning of `Policy.__init__` that takes the same arguments as the Policy constructor. If None, this step will be skipped. before_loss_init (Optional[Callable[[Policy, gym.spaces.Space, gym.spaces.Space, TrainerConfigDict], None]]): Optional callable to run prior to loss init. If None, this step will be skipped. after_init (Optional[Callable[[Policy, gym.Space, gym.Space, TrainerConfigDict], None]]): DEPRECATED: Use `before_loss_init` instead. _after_loss_init (Optional[Callable[[Policy, gym.spaces.Space, gym.spaces.Space, TrainerConfigDict], None]]): Optional callable to run after the loss init. If None, this step will be skipped. This will be deprecated at some point and renamed into `after_init` to match `build_tf_policy()` behavior. action_sampler_fn (Optional[Callable[[TensorType, List[TensorType]], Tuple[TensorType, TensorType]]]): Optional callable returning a sampled action and its log-likelihood given some (obs and state) inputs. If None, will either use `action_distribution_fn` or compute actions by calling self.model, then sampling from the so parameterized action distribution. action_distribution_fn (Optional[Callable[[Policy, ModelV2, TensorType, TensorType, TensorType], Tuple[TensorType, Type[TorchDistributionWrapper], List[TensorType]]]]): A callable that takes the Policy, Model, the observation batch, an explore-flag, a timestep, and an is_training flag and returns a tuple of a) distribution inputs (parameters), b) a dist-class to generate an action distribution object from, and c) internal-state outputs (empty list if not applicable). If None, will either use `action_sampler_fn` or compute actions by calling self.model, then sampling from the parameterized action distribution. make_model (Optional[Callable[[Policy, gym.spaces.Space, gym.spaces.Space, TrainerConfigDict], ModelV2]]): Optional callable that takes the same arguments as Policy.__init__ and returns a model instance. The distribution class will be determined automatically. Note: Only one of `make_model` or `make_model_and_action_dist` should be provided. If both are None, a default Model will be created. make_model_and_action_dist (Optional[Callable[[Policy, gym.spaces.Space, gym.spaces.Space, TrainerConfigDict], Tuple[ModelV2, Type[TorchDistributionWrapper]]]]): Optional callable that takes the same arguments as Policy.__init__ and returns a tuple of model instance and torch action distribution class. Note: Only one of `make_model` or `make_model_and_action_dist` should be provided. If both are None, a default Model will be created. compute_gradients_fn (Optional[Callable[ [Policy, SampleBatch], Tuple[ModelGradients, dict]]]): Optional callable that the sampled batch an computes the gradients w.r. to the loss function. If None, will call the `TorchPolicy.compute_gradients()` method instead. apply_gradients_fn (Optional[Callable[[Policy, "torch.optim.Optimizer"], None]]): Optional callable that takes a grads list and applies these to the Model's parameters. If None, will call the `TorchPolicy.apply_gradients()` method instead. mixins (Optional[List[type]]): Optional list of any class mixins for the returned policy class. These mixins will be applied in order and will have higher precedence than the TorchPolicy class. get_batch_divisibility_req (Optional[Callable[[Policy], int]]): Optional callable that returns the divisibility requirement for sample batches. If None, will assume a value of 1. Returns: Type[TorchPolicy]: TorchPolicy child class constructed from the specified args.
Helper function for creating a new Policy class at runtime.
[ "Helper", "function", "for", "creating", "a", "new", "Policy", "class", "at", "runtime", "." ]
def build_policy_class( name: str, framework: str, *, loss_fn: Optional[Callable[[ Policy, ModelV2, Type[TorchDistributionWrapper], SampleBatch ], Union[TensorType, List[TensorType]]]], get_default_config: Optional[Callable[[], TrainerConfigDict]] = None, stats_fn: Optional[Callable[[Policy, SampleBatch], Dict[ str, TensorType]]] = None, postprocess_fn: Optional[Callable[[ Policy, SampleBatch, Optional[Dict[Any, SampleBatch]], Optional[ "Episode"] ], SampleBatch]] = None, extra_action_out_fn: Optional[Callable[[ Policy, Dict[str, TensorType], List[TensorType], ModelV2, TorchDistributionWrapper ], Dict[str, TensorType]]] = None, extra_grad_process_fn: Optional[Callable[[ Policy, "torch.optim.Optimizer", TensorType ], Dict[str, TensorType]]] = None, # TODO: (sven) Replace "fetches" with "process". extra_learn_fetches_fn: Optional[Callable[[Policy], Dict[ str, TensorType]]] = None, optimizer_fn: Optional[Callable[[Policy, TrainerConfigDict], "torch.optim.Optimizer"]] = None, validate_spaces: Optional[Callable[ [Policy, gym.Space, gym.Space, TrainerConfigDict], None]] = None, before_init: Optional[Callable[ [Policy, gym.Space, gym.Space, TrainerConfigDict], None]] = None, before_loss_init: Optional[Callable[[ Policy, gym.spaces.Space, gym.spaces.Space, TrainerConfigDict ], None]] = None, after_init: Optional[Callable[ [Policy, gym.Space, gym.Space, TrainerConfigDict], None]] = None, _after_loss_init: Optional[Callable[[ Policy, gym.spaces.Space, gym.spaces.Space, TrainerConfigDict ], None]] = None, action_sampler_fn: Optional[Callable[[TensorType, List[ TensorType]], Tuple[TensorType, TensorType]]] = None, action_distribution_fn: Optional[Callable[[ Policy, ModelV2, TensorType, TensorType, TensorType ], Tuple[TensorType, type, List[TensorType]]]] = None, make_model: Optional[Callable[[ Policy, gym.spaces.Space, gym.spaces.Space, TrainerConfigDict ], ModelV2]] = None, make_model_and_action_dist: Optional[Callable[[ Policy, gym.spaces.Space, gym.spaces.Space, TrainerConfigDict ], Tuple[ModelV2, Type[TorchDistributionWrapper]]]] = None, compute_gradients_fn: Optional[Callable[[Policy, SampleBatch], Tuple[ ModelGradients, dict]]] = None, apply_gradients_fn: Optional[Callable[ [Policy, "torch.optim.Optimizer"], None]] = None, mixins: Optional[List[type]] = None, get_batch_divisibility_req: Optional[Callable[[Policy], int]] = None ) -> Type[TorchPolicy]: """Helper function for creating a new Policy class at runtime. Supports frameworks JAX and PyTorch. Args: name (str): name of the policy (e.g., "PPOTorchPolicy") framework (str): Either "jax" or "torch". loss_fn (Optional[Callable[[Policy, ModelV2, Type[TorchDistributionWrapper], SampleBatch], Union[TensorType, List[TensorType]]]]): Callable that returns a loss tensor. get_default_config (Optional[Callable[[None], TrainerConfigDict]]): Optional callable that returns the default config to merge with any overrides. If None, uses only(!) the user-provided PartialTrainerConfigDict as dict for this Policy. postprocess_fn (Optional[Callable[[Policy, SampleBatch, Optional[Dict[Any, SampleBatch]], Optional["Episode"]], SampleBatch]]): Optional callable for post-processing experience batches (called after the super's `postprocess_trajectory` method). stats_fn (Optional[Callable[[Policy, SampleBatch], Dict[str, TensorType]]]): Optional callable that returns a dict of values given the policy and training batch. If None, will use `TorchPolicy.extra_grad_info()` instead. The stats dict is used for logging (e.g. in TensorBoard). extra_action_out_fn (Optional[Callable[[Policy, Dict[str, TensorType], List[TensorType], ModelV2, TorchDistributionWrapper]], Dict[str, TensorType]]]): Optional callable that returns a dict of extra values to include in experiences. If None, no extra computations will be performed. extra_grad_process_fn (Optional[Callable[[Policy, "torch.optim.Optimizer", TensorType], Dict[str, TensorType]]]): Optional callable that is called after gradients are computed and returns a processing info dict. If None, will call the `TorchPolicy.extra_grad_process()` method instead. # TODO: (sven) dissolve naming mismatch between "learn" and "compute.." extra_learn_fetches_fn (Optional[Callable[[Policy], Dict[str, TensorType]]]): Optional callable that returns a dict of extra tensors from the policy after loss evaluation. If None, will call the `TorchPolicy.extra_compute_grad_fetches()` method instead. optimizer_fn (Optional[Callable[[Policy, TrainerConfigDict], "torch.optim.Optimizer"]]): Optional callable that returns a torch optimizer given the policy and config. If None, will call the `TorchPolicy.optimizer()` method instead (which returns a torch Adam optimizer). validate_spaces (Optional[Callable[[Policy, gym.Space, gym.Space, TrainerConfigDict], None]]): Optional callable that takes the Policy, observation_space, action_space, and config to check for correctness. If None, no spaces checking will be done. before_init (Optional[Callable[[Policy, gym.Space, gym.Space, TrainerConfigDict], None]]): Optional callable to run at the beginning of `Policy.__init__` that takes the same arguments as the Policy constructor. If None, this step will be skipped. before_loss_init (Optional[Callable[[Policy, gym.spaces.Space, gym.spaces.Space, TrainerConfigDict], None]]): Optional callable to run prior to loss init. If None, this step will be skipped. after_init (Optional[Callable[[Policy, gym.Space, gym.Space, TrainerConfigDict], None]]): DEPRECATED: Use `before_loss_init` instead. _after_loss_init (Optional[Callable[[Policy, gym.spaces.Space, gym.spaces.Space, TrainerConfigDict], None]]): Optional callable to run after the loss init. If None, this step will be skipped. This will be deprecated at some point and renamed into `after_init` to match `build_tf_policy()` behavior. action_sampler_fn (Optional[Callable[[TensorType, List[TensorType]], Tuple[TensorType, TensorType]]]): Optional callable returning a sampled action and its log-likelihood given some (obs and state) inputs. If None, will either use `action_distribution_fn` or compute actions by calling self.model, then sampling from the so parameterized action distribution. action_distribution_fn (Optional[Callable[[Policy, ModelV2, TensorType, TensorType, TensorType], Tuple[TensorType, Type[TorchDistributionWrapper], List[TensorType]]]]): A callable that takes the Policy, Model, the observation batch, an explore-flag, a timestep, and an is_training flag and returns a tuple of a) distribution inputs (parameters), b) a dist-class to generate an action distribution object from, and c) internal-state outputs (empty list if not applicable). If None, will either use `action_sampler_fn` or compute actions by calling self.model, then sampling from the parameterized action distribution. make_model (Optional[Callable[[Policy, gym.spaces.Space, gym.spaces.Space, TrainerConfigDict], ModelV2]]): Optional callable that takes the same arguments as Policy.__init__ and returns a model instance. The distribution class will be determined automatically. Note: Only one of `make_model` or `make_model_and_action_dist` should be provided. If both are None, a default Model will be created. make_model_and_action_dist (Optional[Callable[[Policy, gym.spaces.Space, gym.spaces.Space, TrainerConfigDict], Tuple[ModelV2, Type[TorchDistributionWrapper]]]]): Optional callable that takes the same arguments as Policy.__init__ and returns a tuple of model instance and torch action distribution class. Note: Only one of `make_model` or `make_model_and_action_dist` should be provided. If both are None, a default Model will be created. compute_gradients_fn (Optional[Callable[ [Policy, SampleBatch], Tuple[ModelGradients, dict]]]): Optional callable that the sampled batch an computes the gradients w.r. to the loss function. If None, will call the `TorchPolicy.compute_gradients()` method instead. apply_gradients_fn (Optional[Callable[[Policy, "torch.optim.Optimizer"], None]]): Optional callable that takes a grads list and applies these to the Model's parameters. If None, will call the `TorchPolicy.apply_gradients()` method instead. mixins (Optional[List[type]]): Optional list of any class mixins for the returned policy class. These mixins will be applied in order and will have higher precedence than the TorchPolicy class. get_batch_divisibility_req (Optional[Callable[[Policy], int]]): Optional callable that returns the divisibility requirement for sample batches. If None, will assume a value of 1. Returns: Type[TorchPolicy]: TorchPolicy child class constructed from the specified args. """ original_kwargs = locals().copy() parent_cls = TorchPolicy base = add_mixins(parent_cls, mixins) class policy_cls(base): def __init__(self, obs_space, action_space, config): # Set up the config from possible default-config fn and given # config arg. if get_default_config: config = dict(get_default_config(), **config) self.config = config # Set the DL framework for this Policy. self.framework = self.config["framework"] = framework # Validate observation- and action-spaces. if validate_spaces: validate_spaces(self, obs_space, action_space, self.config) # Do some pre-initialization steps. if before_init: before_init(self, obs_space, action_space, self.config) # Model is customized (use default action dist class). if make_model: assert make_model_and_action_dist is None, \ "Either `make_model` or `make_model_and_action_dist`" \ " must be None!" self.model = make_model(self, obs_space, action_space, config) dist_class, _ = ModelCatalog.get_action_dist( action_space, self.config["model"], framework=framework) # Model and action dist class are customized. elif make_model_and_action_dist: self.model, dist_class = make_model_and_action_dist( self, obs_space, action_space, config) # Use default model and default action dist. else: dist_class, logit_dim = ModelCatalog.get_action_dist( action_space, self.config["model"], framework=framework) self.model = ModelCatalog.get_model_v2( obs_space=obs_space, action_space=action_space, num_outputs=logit_dim, model_config=self.config["model"], framework=framework) # Make sure, we passed in a correct Model factory. model_cls = TorchModelV2 if framework == "torch" else JAXModelV2 assert isinstance(self.model, model_cls), \ "ERROR: Generated Model must be a TorchModelV2 object!" # Call the framework-specific Policy constructor. self.parent_cls = parent_cls self.parent_cls.__init__( self, observation_space=obs_space, action_space=action_space, config=config, model=self.model, loss=None if self.config["in_evaluation"] else loss_fn, action_distribution_class=dist_class, action_sampler_fn=action_sampler_fn, action_distribution_fn=action_distribution_fn, max_seq_len=config["model"]["max_seq_len"], get_batch_divisibility_req=get_batch_divisibility_req, ) # Merge Model's view requirements into Policy's. self.view_requirements.update(self.model.view_requirements) _before_loss_init = before_loss_init or after_init if _before_loss_init: _before_loss_init(self, self.observation_space, self.action_space, config) # Perform test runs through postprocessing- and loss functions. self._initialize_loss_from_dummy_batch( auto_remove_unneeded_view_reqs=True, stats_fn=None if self.config["in_evaluation"] else stats_fn, ) if _after_loss_init: _after_loss_init(self, obs_space, action_space, config) # Got to reset global_timestep again after this fake run-through. self.global_timestep = 0 @override(Policy) def postprocess_trajectory(self, sample_batch, other_agent_batches=None, episode=None): # Do all post-processing always with no_grad(). # Not using this here will introduce a memory leak # in torch (issue #6962). with self._no_grad_context(): # Call super's postprocess_trajectory first. sample_batch = super().postprocess_trajectory( sample_batch, other_agent_batches, episode) if postprocess_fn: return postprocess_fn(self, sample_batch, other_agent_batches, episode) return sample_batch @override(parent_cls) def extra_grad_process(self, optimizer, loss): """Called after optimizer.zero_grad() and loss.backward() calls. Allows for gradient processing before optimizer.step() is called. E.g. for gradient clipping. """ if extra_grad_process_fn: return extra_grad_process_fn(self, optimizer, loss) else: return parent_cls.extra_grad_process(self, optimizer, loss) @override(parent_cls) def extra_compute_grad_fetches(self): if extra_learn_fetches_fn: fetches = convert_to_numpy(extra_learn_fetches_fn(self)) # Auto-add empty learner stats dict if needed. return dict({LEARNER_STATS_KEY: {}}, **fetches) else: return parent_cls.extra_compute_grad_fetches(self) @override(parent_cls) def compute_gradients(self, batch): if compute_gradients_fn: return compute_gradients_fn(self, batch) else: return parent_cls.compute_gradients(self, batch) @override(parent_cls) def apply_gradients(self, gradients): if apply_gradients_fn: apply_gradients_fn(self, gradients) else: parent_cls.apply_gradients(self, gradients) @override(parent_cls) def extra_action_out(self, input_dict, state_batches, model, action_dist): with self._no_grad_context(): if extra_action_out_fn: stats_dict = extra_action_out_fn( self, input_dict, state_batches, model, action_dist) else: stats_dict = parent_cls.extra_action_out( self, input_dict, state_batches, model, action_dist) return self._convert_to_numpy(stats_dict) @override(parent_cls) def optimizer(self): if optimizer_fn: optimizers = optimizer_fn(self, self.config) else: optimizers = parent_cls.optimizer(self) return optimizers @override(parent_cls) def extra_grad_info(self, train_batch): with self._no_grad_context(): if stats_fn: stats_dict = stats_fn(self, train_batch) else: stats_dict = self.parent_cls.extra_grad_info( self, train_batch) return self._convert_to_numpy(stats_dict) def _no_grad_context(self): if self.framework == "torch": return torch.no_grad() return NullContextManager() def _convert_to_numpy(self, data): if self.framework == "torch": return convert_to_numpy(data) return data def with_updates(**overrides): """Creates a Torch|JAXPolicy cls based on settings of another one. Keyword Args: **overrides: The settings (passed into `build_torch_policy`) that should be different from the class that this method is called on. Returns: type: A new Torch|JAXPolicy sub-class. Examples: >> MySpecialDQNPolicyClass = DQNTorchPolicy.with_updates( .. name="MySpecialDQNPolicyClass", .. loss_function=[some_new_loss_function], .. ) """ return build_policy_class(**dict(original_kwargs, **overrides)) policy_cls.with_updates = staticmethod(with_updates) policy_cls.__name__ = name policy_cls.__qualname__ = name return policy_cls
[ "def", "build_policy_class", "(", "name", ":", "str", ",", "framework", ":", "str", ",", "*", ",", "loss_fn", ":", "Optional", "[", "Callable", "[", "[", "Policy", ",", "ModelV2", ",", "Type", "[", "TorchDistributionWrapper", "]", ",", "SampleBatch", "]", ...
https://github.com/ray-project/ray/blob/703c1610348615dcb8c2d141a0c46675084660f5/rllib/policy/policy_template.py#L30-L406
TencentCloud/tencentcloud-sdk-python
3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2
tencentcloud/cdn/v20180606/cdn_client.py
python
CdnClient.DescribeTopData
(self, request)
DescribeTopData 通过入参 Metric 和 Filter 组合不同,可以查询以下排序数据: + 依据总流量、总请求数对访问 IP 排序,从大至小返回 TOP 100 IP + 依据总流量、总请求数对访问 Refer 排序,从大至小返回 TOP 100 Refer + 依据总流量、总请求数对访问 设备 排序,从大至小返回 设备类型 + 依据总流量、总请求数对访问 操作系统 排序,从大至小返回 操作系统 + 依据总流量、总请求数对访问 浏览器 排序,从大至小返回 浏览器 注意: + 仅支持 90 天内数据查询,且从2021年09月20日开始有数据 + 本接口为beta版,尚未正式全量发布 :param request: Request instance for DescribeTopData. :type request: :class:`tencentcloud.cdn.v20180606.models.DescribeTopDataRequest` :rtype: :class:`tencentcloud.cdn.v20180606.models.DescribeTopDataResponse`
DescribeTopData 通过入参 Metric 和 Filter 组合不同,可以查询以下排序数据:
[ "DescribeTopData", "通过入参", "Metric", "和", "Filter", "组合不同,可以查询以下排序数据:" ]
def DescribeTopData(self, request): """DescribeTopData 通过入参 Metric 和 Filter 组合不同,可以查询以下排序数据: + 依据总流量、总请求数对访问 IP 排序,从大至小返回 TOP 100 IP + 依据总流量、总请求数对访问 Refer 排序,从大至小返回 TOP 100 Refer + 依据总流量、总请求数对访问 设备 排序,从大至小返回 设备类型 + 依据总流量、总请求数对访问 操作系统 排序,从大至小返回 操作系统 + 依据总流量、总请求数对访问 浏览器 排序,从大至小返回 浏览器 注意: + 仅支持 90 天内数据查询,且从2021年09月20日开始有数据 + 本接口为beta版,尚未正式全量发布 :param request: Request instance for DescribeTopData. :type request: :class:`tencentcloud.cdn.v20180606.models.DescribeTopDataRequest` :rtype: :class:`tencentcloud.cdn.v20180606.models.DescribeTopDataResponse` """ try: params = request._serialize() body = self.call("DescribeTopData", params) response = json.loads(body) if "Error" not in response["Response"]: model = models.DescribeTopDataResponse() model._deserialize(response["Response"]) return model else: code = response["Response"]["Error"]["Code"] message = response["Response"]["Error"]["Message"] reqid = response["Response"]["RequestId"] raise TencentCloudSDKException(code, message, reqid) except Exception as e: if isinstance(e, TencentCloudSDKException): raise else: raise TencentCloudSDKException(e.message, e.message)
[ "def", "DescribeTopData", "(", "self", ",", "request", ")", ":", "try", ":", "params", "=", "request", ".", "_serialize", "(", ")", "body", "=", "self", ".", "call", "(", "\"DescribeTopData\"", ",", "params", ")", "response", "=", "json", ".", "loads", ...
https://github.com/TencentCloud/tencentcloud-sdk-python/blob/3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2/tencentcloud/cdn/v20180606/cdn_client.py#L1177-L1212
wxWidgets/Phoenix
b2199e299a6ca6d866aa6f3d0888499136ead9d6
wx/lib/ogl/basic.py
python
ShapeEvtHandler.OnDrawBranches
(self, dc, erase = False)
The draw branches handler.
The draw branches handler.
[ "The", "draw", "branches", "handler", "." ]
def OnDrawBranches(self, dc, erase = False): """The draw branches handler.""" if self._previousHandler: self._previousHandler.OnDrawBranches(dc, erase = erase)
[ "def", "OnDrawBranches", "(", "self", ",", "dc", ",", "erase", "=", "False", ")", ":", "if", "self", ".", "_previousHandler", ":", "self", ".", "_previousHandler", ".", "OnDrawBranches", "(", "dc", ",", "erase", "=", "erase", ")" ]
https://github.com/wxWidgets/Phoenix/blob/b2199e299a6ca6d866aa6f3d0888499136ead9d6/wx/lib/ogl/basic.py#L171-L174
google/turbinia
4559d4af9267762a8995cfc415099a80a22ee4d3
turbinia/workers/analysis/jupyter.py
python
JupyterAnalysisTask.run
(self, evidence, result)
return result
Run the Jupyter worker. Args: evidence (Evidence object): The evidence to process result (TurbiniaTaskResult): The object to place task results into. Returns: TurbiniaTaskResult object.
Run the Jupyter worker.
[ "Run", "the", "Jupyter", "worker", "." ]
def run(self, evidence, result): """Run the Jupyter worker. Args: evidence (Evidence object): The evidence to process result (TurbiniaTaskResult): The object to place task results into. Returns: TurbiniaTaskResult object. """ # Where to store the resulting output file. output_file_name = 'jupyter_analysis.txt' output_file_path = os.path.join(self.output_dir, output_file_name) # What type of evidence we should output. output_evidence = ReportText(source_path=output_file_path) # Read the config file. jupyter_config = open(evidence.local_path, 'r').read() # Extract the config and return the report (report, priority, summary) = self.analyse_config(jupyter_config) output_evidence.text_data = report result.report_priority = priority result.report_data = report # Write the report to the output file. with open(output_file_path, 'w', encoding='utf-8') as fh: fh.write(output_evidence.text_data) fh.write('\n') # Add the resulting evidence to the result object. result.add_evidence(output_evidence, evidence.config) result.close(self, success=True, status=summary) return result
[ "def", "run", "(", "self", ",", "evidence", ",", "result", ")", ":", "# Where to store the resulting output file.", "output_file_name", "=", "'jupyter_analysis.txt'", "output_file_path", "=", "os", ".", "path", ".", "join", "(", "self", ".", "output_dir", ",", "ou...
https://github.com/google/turbinia/blob/4559d4af9267762a8995cfc415099a80a22ee4d3/turbinia/workers/analysis/jupyter.py#L35-L72
hakril/PythonForWindows
61e027a678d5b87aa64fcf8a37a6661a86236589
windows/rpc/ndr.py
python
NdrConformantArray.unpack_conformant
(cls, stream, size)
return res
[]
def unpack_conformant(cls, stream, size): res = [cls.MEMBER_TYPE.unpack(stream) for i in range(size)] stream.align(4) return res
[ "def", "unpack_conformant", "(", "cls", ",", "stream", ",", "size", ")", ":", "res", "=", "[", "cls", ".", "MEMBER_TYPE", ".", "unpack", "(", "stream", ")", "for", "i", "in", "range", "(", "size", ")", "]", "stream", ".", "align", "(", "4", ")", ...
https://github.com/hakril/PythonForWindows/blob/61e027a678d5b87aa64fcf8a37a6661a86236589/windows/rpc/ndr.py#L451-L454
sahana/eden
1696fa50e90ce967df69f66b571af45356cc18da
controllers/xforms.py
python
uses_requirement
(requirement, field)
return False
Check if a given database field uses the specified requirement (IS_IN_SET, IS_INT_IN_RANGE, etc) @todo: deprecate
Check if a given database field uses the specified requirement (IS_IN_SET, IS_INT_IN_RANGE, etc)
[ "Check", "if", "a", "given", "database", "field", "uses", "the", "specified", "requirement", "(", "IS_IN_SET", "IS_INT_IN_RANGE", "etc", ")" ]
def uses_requirement(requirement, field): """ Check if a given database field uses the specified requirement (IS_IN_SET, IS_INT_IN_RANGE, etc) @todo: deprecate """ if hasattr(field.requires, "other") or requirement in str(field.requires): if hasattr(field.requires, "other"): if requirement in str(field.requires.other): return True elif requirement in str(field.requires): return True return False
[ "def", "uses_requirement", "(", "requirement", ",", "field", ")", ":", "if", "hasattr", "(", "field", ".", "requires", ",", "\"other\"", ")", "or", "requirement", "in", "str", "(", "field", ".", "requires", ")", ":", "if", "hasattr", "(", "field", ".", ...
https://github.com/sahana/eden/blob/1696fa50e90ce967df69f66b571af45356cc18da/controllers/xforms.py#L122-L136
autorope/donkeycar
a3df79a3573127dff31fc9b2953588056875b214
donkeycar/utils.py
python
map_range
(x, X_min, X_max, Y_min, Y_max)
return int(y)
Linear mapping between two ranges of values
Linear mapping between two ranges of values
[ "Linear", "mapping", "between", "two", "ranges", "of", "values" ]
def map_range(x, X_min, X_max, Y_min, Y_max): ''' Linear mapping between two ranges of values ''' X_range = X_max - X_min Y_range = Y_max - Y_min XY_ratio = X_range/Y_range y = ((x-X_min) / XY_ratio + Y_min) // 1 return int(y)
[ "def", "map_range", "(", "x", ",", "X_min", ",", "X_max", ",", "Y_min", ",", "Y_max", ")", ":", "X_range", "=", "X_max", "-", "X_min", "Y_range", "=", "Y_max", "-", "Y_min", "XY_ratio", "=", "X_range", "/", "Y_range", "y", "=", "(", "(", "x", "-", ...
https://github.com/autorope/donkeycar/blob/a3df79a3573127dff31fc9b2953588056875b214/donkeycar/utils.py#L284-L294
securesystemslab/zippy
ff0e84ac99442c2c55fe1d285332cfd4e185e089
zippy/lib-python/3/tkinter/__init__.py
python
Wm.wm_withdraw
(self)
return self.tk.call('wm', 'withdraw', self._w)
Withdraw this widget from the screen such that it is unmapped and forgotten by the window manager. Re-draw it with wm_deiconify.
Withdraw this widget from the screen such that it is unmapped and forgotten by the window manager. Re-draw it with wm_deiconify.
[ "Withdraw", "this", "widget", "from", "the", "screen", "such", "that", "it", "is", "unmapped", "and", "forgotten", "by", "the", "window", "manager", ".", "Re", "-", "draw", "it", "with", "wm_deiconify", "." ]
def wm_withdraw(self): """Withdraw this widget from the screen such that it is unmapped and forgotten by the window manager. Re-draw it with wm_deiconify.""" return self.tk.call('wm', 'withdraw', self._w)
[ "def", "wm_withdraw", "(", "self", ")", ":", "return", "self", ".", "tk", ".", "call", "(", "'wm'", ",", "'withdraw'", ",", "self", ".", "_w", ")" ]
https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/lib-python/3/tkinter/__init__.py#L1643-L1646
Azure/azure-linux-extensions
a42ef718c746abab2b3c6a21da87b29e76364558
Common/libpsutil/py2.7-glibc-2.12+/psutil/__init__.py
python
test
()
List info of all currently running processes emulating ps aux output.
List info of all currently running processes emulating ps aux output.
[ "List", "info", "of", "all", "currently", "running", "processes", "emulating", "ps", "aux", "output", "." ]
def test(): """List info of all currently running processes emulating ps aux output. """ import datetime today_day = datetime.date.today() templ = "%-10s %5s %4s %4s %7s %7s %-13s %5s %7s %s" attrs = ['pid', 'cpu_percent', 'memory_percent', 'name', 'cpu_times', 'create_time', 'memory_info'] if _POSIX: attrs.append('uids') attrs.append('terminal') print(templ % ("USER", "PID", "%CPU", "%MEM", "VSZ", "RSS", "TTY", "START", "TIME", "COMMAND")) for p in process_iter(): try: pinfo = p.as_dict(attrs, ad_value='') except NoSuchProcess: pass else: if pinfo['create_time']: ctime = datetime.datetime.fromtimestamp(pinfo['create_time']) if ctime.date() == today_day: ctime = ctime.strftime("%H:%M") else: ctime = ctime.strftime("%b%d") else: ctime = '' cputime = time.strftime("%M:%S", time.localtime(sum(pinfo['cpu_times']))) try: user = p.username() except KeyError: if _POSIX: if pinfo['uids']: user = str(pinfo['uids'].real) else: user = '' else: raise except Error: user = '' if _WINDOWS and '\\' in user: user = user.split('\\')[1] vms = pinfo['memory_info'] and \ int(pinfo['memory_info'].vms / 1024) or '?' rss = pinfo['memory_info'] and \ int(pinfo['memory_info'].rss / 1024) or '?' memp = pinfo['memory_percent'] and \ round(pinfo['memory_percent'], 1) or '?' print(templ % ( user[:10], pinfo['pid'], pinfo['cpu_percent'], memp, vms, rss, pinfo.get('terminal', '') or '?', ctime, cputime, pinfo['name'].strip() or '?'))
[ "def", "test", "(", ")", ":", "import", "datetime", "today_day", "=", "datetime", ".", "date", ".", "today", "(", ")", "templ", "=", "\"%-10s %5s %4s %4s %7s %7s %-13s %5s %7s %s\"", "attrs", "=", "[", "'pid'", ",", "'cpu_percent'", ",", "'memory_percent'", ","...
https://github.com/Azure/azure-linux-extensions/blob/a42ef718c746abab2b3c6a21da87b29e76364558/Common/libpsutil/py2.7-glibc-2.12+/psutil/__init__.py#L1909-L1970
sk1712/gcn_metric_learning
50abd52bcd29d2d1ccfc27cbffe71b91c0629c7e
lib/models_siamese.py
python
base_model._bias_variable
(self, shape, regularization=True)
return var
[]
def _bias_variable(self, shape, regularization=True): # initial = tf.constant_initializer(0.1) initial = tf.constant_initializer(0.0) var = tf.get_variable('bias', shape, tf.float32, initializer=initial) if regularization: self.regularizers.append(tf.nn.l2_loss(var)) tf.summary.histogram(var.op.name, var) return var
[ "def", "_bias_variable", "(", "self", ",", "shape", ",", "regularization", "=", "True", ")", ":", "# initial = tf.constant_initializer(0.1)", "initial", "=", "tf", ".", "constant_initializer", "(", "0.0", ")", "var", "=", "tf", ".", "get_variable", "(", "'bias'"...
https://github.com/sk1712/gcn_metric_learning/blob/50abd52bcd29d2d1ccfc27cbffe71b91c0629c7e/lib/models_siamese.py#L312-L320
securesystemslab/zippy
ff0e84ac99442c2c55fe1d285332cfd4e185e089
zippy/lib-python/3/plat-sunos5/STROPTS.py
python
RW_LOCK_HELD
(x)
return (rw_lock_held((x)))
[]
def RW_LOCK_HELD(x): return (rw_lock_held((x)))
[ "def", "RW_LOCK_HELD", "(", "x", ")", ":", "return", "(", "rw_lock_held", "(", "(", "x", ")", ")", ")" ]
https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/lib-python/3/plat-sunos5/STROPTS.py#L337-L337
bpython/bpython
189da3ecbaa30212b8ba73aeb321b6a6a324348b
bpython/repl.py
python
Interpreter.showtraceback
(self)
This needs to override the default traceback thing so it can put it into a pretty colour and maybe other stuff, I don't know
This needs to override the default traceback thing so it can put it into a pretty colour and maybe other stuff, I don't know
[ "This", "needs", "to", "override", "the", "default", "traceback", "thing", "so", "it", "can", "put", "it", "into", "a", "pretty", "colour", "and", "maybe", "other", "stuff", "I", "don", "t", "know" ]
def showtraceback(self): """This needs to override the default traceback thing so it can put it into a pretty colour and maybe other stuff, I don't know""" try: t, v, tb = sys.exc_info() sys.last_type = t sys.last_value = v sys.last_traceback = tb tblist = traceback.extract_tb(tb) del tblist[:1] for i, (fname, lineno, module, something) in enumerate(tblist): # strip linecache line number if self.bpython_input_re.match(fname): fname = "<input>" tblist[i] = (fname, lineno, module, something) l = traceback.format_list(tblist) if l: l.insert(0, "Traceback (most recent call last):\n") l[len(l) :] = traceback.format_exception_only(t, v) finally: pass self.writetb(l)
[ "def", "showtraceback", "(", "self", ")", ":", "try", ":", "t", ",", "v", ",", "tb", "=", "sys", ".", "exc_info", "(", ")", "sys", ".", "last_type", "=", "t", "sys", ".", "last_value", "=", "v", "sys", ".", "last_traceback", "=", "tb", "tblist", ...
https://github.com/bpython/bpython/blob/189da3ecbaa30212b8ba73aeb321b6a6a324348b/bpython/repl.py#L186-L211
projecthamster/hamster
19d160090de30e756bdc3122ff935bdaa86e2843
waflib/Runner.py
python
Parallel.skip
(self, tsk)
Mark a task as skipped/up-to-date
Mark a task as skipped/up-to-date
[ "Mark", "a", "task", "as", "skipped", "/", "up", "-", "to", "-", "date" ]
def skip(self, tsk): """ Mark a task as skipped/up-to-date """ tsk.hasrun = Task.SKIPPED self.mark_finished(tsk)
[ "def", "skip", "(", "self", ",", "tsk", ")", ":", "tsk", ".", "hasrun", "=", "Task", ".", "SKIPPED", "self", ".", "mark_finished", "(", "tsk", ")" ]
https://github.com/projecthamster/hamster/blob/19d160090de30e756bdc3122ff935bdaa86e2843/waflib/Runner.py#L405-L410
mrahtz/learning-from-human-preferences
3fca07c4c3fd20bec307f4405684461437d9e215
a2c/common/schedules.py
python
ConstantSchedule.value
(self, t)
return self._v
See Schedule.value
See Schedule.value
[ "See", "Schedule", ".", "value" ]
def value(self, t): """See Schedule.value""" return self._v
[ "def", "value", "(", "self", ",", "t", ")", ":", "return", "self", ".", "_v" ]
https://github.com/mrahtz/learning-from-human-preferences/blob/3fca07c4c3fd20bec307f4405684461437d9e215/a2c/common/schedules.py#L29-L31
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/lib/python2.7/site-packages/whoosh/automata/fsa.py
python
FSA.get_labels
(self, src)
return iter(self.transitions.get(src, []))
[]
def get_labels(self, src): return iter(self.transitions.get(src, []))
[ "def", "get_labels", "(", "self", ",", "src", ")", ":", "return", "iter", "(", "self", ".", "transitions", ".", "get", "(", "src", ",", "[", "]", ")", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/lib/python2.7/site-packages/whoosh/automata/fsa.py#L66-L67
holzschu/Carnets
44effb10ddfc6aa5c8b0687582a724ba82c6b547
Library/lib/python3.7/site-packages/matplotlib-3.0.3-py3.7-macosx-10.9-x86_64.egg/matplotlib/afm.py
python
AFM.get_vertical_stem_width
(self)
return self._header.get(b'StdVW', None)
Return the standard vertical stem width as float, or *None* if not specified in AFM file.
Return the standard vertical stem width as float, or *None* if not specified in AFM file.
[ "Return", "the", "standard", "vertical", "stem", "width", "as", "float", "or", "*", "None", "*", "if", "not", "specified", "in", "AFM", "file", "." ]
def get_vertical_stem_width(self): """ Return the standard vertical stem width as float, or *None* if not specified in AFM file. """ return self._header.get(b'StdVW', None)
[ "def", "get_vertical_stem_width", "(", "self", ")", ":", "return", "self", ".", "_header", ".", "get", "(", "b'StdVW'", ",", "None", ")" ]
https://github.com/holzschu/Carnets/blob/44effb10ddfc6aa5c8b0687582a724ba82c6b547/Library/lib/python3.7/site-packages/matplotlib-3.0.3-py3.7-macosx-10.9-x86_64.egg/matplotlib/afm.py#L557-L562
MillionIntegrals/vel
f3ce7da64362ad207f40f2c0d58d9300a25df3e8
vel/rl/env_roller/transition_replay_env_roller.py
python
TransitionReplayEnvRoller.rollout
(self, batch_info: BatchInfo, model: RlModel, number_of_steps: int)
return Trajectories( num_steps=accumulated_tensors['observations'].size(0), num_envs=accumulated_tensors['observations'].size(1), environment_information=episode_information, transition_tensors=accumulated_tensors, rollout_tensors={} ).to_transitions()
Calculate env rollout
Calculate env rollout
[ "Calculate", "env", "rollout" ]
def rollout(self, batch_info: BatchInfo, model: RlModel, number_of_steps: int) -> Rollout: """ Calculate env rollout """ assert not model.is_recurrent, "Replay env roller does not support recurrent models" accumulator = TensorAccumulator() episode_information = [] # List of dictionaries with episode information for step_idx in range(number_of_steps): step = model.step(self.last_observation) if self.action_noise is not None: step['actions'] = self.action_noise(step['actions'], batch_info=batch_info) replay_extra_information = {} accumulator.add('observations', self.last_observation_cpu) # Add step to the tensor accumulator for name, tensor in step.items(): tensor_cpu = tensor.cpu() accumulator.add(name, tensor_cpu) if name != 'actions': replay_extra_information[name] = tensor_cpu.numpy() actions_numpy = step['actions'].detach().cpu().numpy() new_obs, new_rewards, new_dones, new_infos = self.environment.step(actions_numpy) # Store rollout in the experience replay buffer self.replay_buffer.store_transition( frame=self.last_observation_cpu.numpy(), action=actions_numpy, reward=new_rewards, done=new_dones, extra_info=replay_extra_information ) if self.ret_rms is not None: self.accumulated_returns = new_rewards + self.discount_factor * self.accumulated_returns self.ret_rms.update(self.accumulated_returns) # Done is flagged true when the episode has ended AND the frame we see is already a first frame from the # next episode dones_tensor = torch.from_numpy(new_dones.astype(np.float32)).clone() accumulator.add('dones', dones_tensor) if self.action_noise is not None: self.action_noise.reset_training_state(dones_tensor, batch_info=batch_info) self.accumulated_returns = self.accumulated_returns * (1.0 - new_dones.astype(np.float32)) self.last_observation_cpu = torch.from_numpy(new_obs).clone() self.last_observation = self.last_observation_cpu.to(self.device) if self.ret_rms is not None: new_rewards = np.clip(new_rewards / np.sqrt(self.ret_rms.var + 1e-8), -self.clip_obs, self.clip_obs) accumulator.add('rewards', torch.from_numpy(new_rewards.astype(np.float32)).clone()) episode_information.append(new_infos) accumulated_tensors = accumulator.result() return Trajectories( num_steps=accumulated_tensors['observations'].size(0), num_envs=accumulated_tensors['observations'].size(1), environment_information=episode_information, transition_tensors=accumulated_tensors, rollout_tensors={} ).to_transitions()
[ "def", "rollout", "(", "self", ",", "batch_info", ":", "BatchInfo", ",", "model", ":", "RlModel", ",", "number_of_steps", ":", "int", ")", "->", "Rollout", ":", "assert", "not", "model", ".", "is_recurrent", ",", "\"Replay env roller does not support recurrent mod...
https://github.com/MillionIntegrals/vel/blob/f3ce7da64362ad207f40f2c0d58d9300a25df3e8/vel/rl/env_roller/transition_replay_env_roller.py#L55-L124
pretix/pretix
96f694cf61345f54132cd26cdeb07d5d11b34232
src/pretix/base/shredder.py
python
BaseDataShredder.require_download_confirmation
(self)
return self.tax_relevant
Indicates whether the data of this shredder needs to be downloaded, before it is actually shredded. By default this value is equal to the tax relevant flag.
Indicates whether the data of this shredder needs to be downloaded, before it is actually shredded. By default this value is equal to the tax relevant flag.
[ "Indicates", "whether", "the", "data", "of", "this", "shredder", "needs", "to", "be", "downloaded", "before", "it", "is", "actually", "shredded", ".", "By", "default", "this", "value", "is", "equal", "to", "the", "tax", "relevant", "flag", "." ]
def require_download_confirmation(self): """ Indicates whether the data of this shredder needs to be downloaded, before it is actually shredded. By default this value is equal to the tax relevant flag. """ return self.tax_relevant
[ "def", "require_download_confirmation", "(", "self", ")", ":", "return", "self", ".", "tax_relevant" ]
https://github.com/pretix/pretix/blob/96f694cf61345f54132cd26cdeb07d5d11b34232/src/pretix/base/shredder.py#L121-L126
dimagi/commcare-hq
d67ff1d3b4c51fa050c19e60c3253a79d3452a39
corehq/util/models.py
python
ForeignValue.__set_name__
(self, owner, name)
[]
def __set_name__(self, owner, name): other_names = getattr(owner, "_ForeignValue_names", []) owner._ForeignValue_names = other_names + [name]
[ "def", "__set_name__", "(", "self", ",", "owner", ",", "name", ")", ":", "other_names", "=", "getattr", "(", "owner", ",", "\"_ForeignValue_names\"", ",", "[", "]", ")", "owner", ".", "_ForeignValue_names", "=", "other_names", "+", "[", "name", "]" ]
https://github.com/dimagi/commcare-hq/blob/d67ff1d3b4c51fa050c19e60c3253a79d3452a39/corehq/util/models.py#L286-L288
ternaus/kaggle_dstl_submission
7de6ebad72d0fa3b0756ce67f9d7b5ea3e60b33a
src/visualize.py
python
plot_polygons
(fig, ax, polygonsList)
return legend_patches
Plot descrates.PolygonPatch from list of polygons objs for each CLASS
Plot descrates.PolygonPatch from list of polygons objs for each CLASS
[ "Plot", "descrates", ".", "PolygonPatch", "from", "list", "of", "polygons", "objs", "for", "each", "CLASS" ]
def plot_polygons(fig, ax, polygonsList): ''' Plot descrates.PolygonPatch from list of polygons objs for each CLASS ''' legend_patches = [] for cType in polygonsList: print('{} : {} \tcount = {}'.format(cType, CLASSES[cType], len(polygonsList[cType]))) legend_patches.append(Patch(color=COLORS[cType], label='{} ({})'.format(CLASSES[cType], len(polygonsList[cType])))) for polygon in polygonsList[cType]: mpl_poly = PolygonPatch(polygon, color=COLORS[cType], lw=0, alpha=0.7, zorder=ZORDER[cType]) ax.add_patch(mpl_poly) # ax.relim() ax.autoscale_view() ax.set_title('Objects') ax.set_xticks([]) ax.set_yticks([]) return legend_patches
[ "def", "plot_polygons", "(", "fig", ",", "ax", ",", "polygonsList", ")", ":", "legend_patches", "=", "[", "]", "for", "cType", "in", "polygonsList", ":", "print", "(", "'{} : {} \\tcount = {}'", ".", "format", "(", "cType", ",", "CLASSES", "[", "cType", "]...
https://github.com/ternaus/kaggle_dstl_submission/blob/7de6ebad72d0fa3b0756ce67f9d7b5ea3e60b33a/src/visualize.py#L171-L192
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/litterrobot/switch.py
python
LitterRobotPanelLockoutSwitch.icon
(self)
return "mdi:lock" if self.is_on else "mdi:lock-open"
Return the icon.
Return the icon.
[ "Return", "the", "icon", "." ]
def icon(self) -> str: """Return the icon.""" return "mdi:lock" if self.is_on else "mdi:lock-open"
[ "def", "icon", "(", "self", ")", "->", "str", ":", "return", "\"mdi:lock\"", "if", "self", ".", "is_on", "else", "\"mdi:lock-open\"" ]
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/litterrobot/switch.py#L51-L53
Thriftpy/thriftpy2
8755065bdd3a51b55cbab488fe628027f2c060db
thriftpy2/parser/parser.py
python
p_const
(p)
const : CONST field_type IDENTIFIER '=' const_value | CONST field_type IDENTIFIER '=' const_value sep
const : CONST field_type IDENTIFIER '=' const_value | CONST field_type IDENTIFIER '=' const_value sep
[ "const", ":", "CONST", "field_type", "IDENTIFIER", "=", "const_value", "|", "CONST", "field_type", "IDENTIFIER", "=", "const_value", "sep" ]
def p_const(p): '''const : CONST field_type IDENTIFIER '=' const_value | CONST field_type IDENTIFIER '=' const_value sep''' try: val = _cast(p[2], p.lineno(3))(p[5]) except AssertionError: raise ThriftParserError('Type error for constant %s at line %d' % (p[3], p.lineno(3))) setattr(thrift_stack[-1], p[3], val) _add_thrift_meta('consts', val)
[ "def", "p_const", "(", "p", ")", ":", "try", ":", "val", "=", "_cast", "(", "p", "[", "2", "]", ",", "p", ".", "lineno", "(", "3", ")", ")", "(", "p", "[", "5", "]", ")", "except", "AssertionError", ":", "raise", "ThriftParserError", "(", "'Typ...
https://github.com/Thriftpy/thriftpy2/blob/8755065bdd3a51b55cbab488fe628027f2c060db/thriftpy2/parser/parser.py#L106-L116
david-abel/simple_rl
d8fe6007efb4840377f085a4e35ba89aaa2cdf6d
simple_rl/abstraction/state_abs/indicator_funcs.py
python
_q_eps_approx_indicator
(state_x, state_y, vi, actions, epsilon=0.0)
return True
Args: state_x (State) state_y (State) vi (ValueIteration) actions (list) Returns: (bool): true iff: max |Q(state_x,a) - Q(state_y, a)| <= epsilon
Args: state_x (State) state_y (State) vi (ValueIteration) actions (list)
[ "Args", ":", "state_x", "(", "State", ")", "state_y", "(", "State", ")", "vi", "(", "ValueIteration", ")", "actions", "(", "list", ")" ]
def _q_eps_approx_indicator(state_x, state_y, vi, actions, epsilon=0.0): ''' Args: state_x (State) state_y (State) vi (ValueIteration) actions (list) Returns: (bool): true iff: max |Q(state_x,a) - Q(state_y, a)| <= epsilon ''' for a in actions: q_x = vi.get_q_value(state_x, a) q_y = vi.get_q_value(state_y, a) if abs(q_x - q_y) > epsilon: return False return True
[ "def", "_q_eps_approx_indicator", "(", "state_x", ",", "state_y", ",", "vi", ",", "actions", ",", "epsilon", "=", "0.0", ")", ":", "for", "a", "in", "actions", ":", "q_x", "=", "vi", ".", "get_q_value", "(", "state_x", ",", "a", ")", "q_y", "=", "vi"...
https://github.com/david-abel/simple_rl/blob/d8fe6007efb4840377f085a4e35ba89aaa2cdf6d/simple_rl/abstraction/state_abs/indicator_funcs.py#L47-L66
securesystemslab/zippy
ff0e84ac99442c2c55fe1d285332cfd4e185e089
zippy/benchmarks/src/benchmarks/whoosh/src/whoosh/fields.py
python
NUMERIC.__setstate__
(self, d)
[]
def __setstate__(self, d): self.__dict__.update(d) self._struct = struct.Struct(">" + self.sortable_typecode) if "min_value" not in d: d["min_value"], d["max_value"] = self._min_max()
[ "def", "__setstate__", "(", "self", ",", "d", ")", ":", "self", ".", "__dict__", ".", "update", "(", "d", ")", "self", ".", "_struct", "=", "struct", ".", "Struct", "(", "\">\"", "+", "self", ".", "sortable_typecode", ")", "if", "\"min_value\"", "not",...
https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/benchmarks/src/benchmarks/whoosh/src/whoosh/fields.py#L516-L520
bnpy/bnpy
d5b311e8f58ccd98477f4a0c8a4d4982e3fca424
bnpy/learnalg/zzzdeprecated/ParallelMOVBAlg.py
python
ParallelMOVBAlg.memoizedSummaryStep
(self, hmodel, SS, SSchunk, batchID)
return SS
Execute summary step on current batch and update aggregated SS. Returns -------- SS : updated aggregate suff stats
Execute summary step on current batch and update aggregated SS.
[ "Execute", "summary", "step", "on", "current", "batch", "and", "update", "aggregated", "SS", "." ]
def memoizedSummaryStep(self, hmodel, SS, SSchunk, batchID): ''' Execute summary step on current batch and update aggregated SS. Returns -------- SS : updated aggregate suff stats ''' if batchID in self.SSmemory: oldSSchunk = self.load_batch_suff_stat_from_memory(batchID) assert oldSSchunk.K == SS.K SS -= oldSSchunk if SS is None: SS = SSchunk.copy() else: assert SSchunk.K == SS.K SS += SSchunk self.save_batch_suff_stat_to_memory(batchID, SSchunk) # Force aggregated suff stats to obey required constraints. # This avoids numerical issues caused by incremental updates if hasattr(hmodel.allocModel, 'forceSSInBounds'): hmodel.allocModel.forceSSInBounds(SS) if hasattr(hmodel.obsModel, 'forceSSInBounds'): hmodel.obsModel.forceSSInBounds(SS) return SS
[ "def", "memoizedSummaryStep", "(", "self", ",", "hmodel", ",", "SS", ",", "SSchunk", ",", "batchID", ")", ":", "if", "batchID", "in", "self", ".", "SSmemory", ":", "oldSSchunk", "=", "self", ".", "load_batch_suff_stat_from_memory", "(", "batchID", ")", "asse...
https://github.com/bnpy/bnpy/blob/d5b311e8f58ccd98477f4a0c8a4d4982e3fca424/bnpy/learnalg/zzzdeprecated/ParallelMOVBAlg.py#L160-L184
dragonfly/dragonfly
a579b5eadf452e23b07d4caf27b402703b0012b7
dragonfly/nn/nn_domains.py
python
neural_nets_are_equal
(net1, net2)
return is_true
Returns true if both net1 and net2 are equal.
Returns true if both net1 and net2 are equal.
[ "Returns", "true", "if", "both", "net1", "and", "net2", "are", "equal", "." ]
def neural_nets_are_equal(net1, net2): """ Returns true if both net1 and net2 are equal. """ is_true = True for key in net1.__dict__.keys(): val1 = net1.__dict__[key] val2 = net2.__dict__[key] is_true = True if isinstance(val1, dict): for val_key in val1.keys(): is_true = is_true and np.all(val1[val_key] == val2[val_key]) elif hasattr(val1, '__iter__'): is_true = is_true and np.all(val1 == val2) else: is_true = is_true and val1 == val2 if not is_true: # break here if necessary return is_true return is_true
[ "def", "neural_nets_are_equal", "(", "net1", ",", "net2", ")", ":", "is_true", "=", "True", "for", "key", "in", "net1", ".", "__dict__", ".", "keys", "(", ")", ":", "val1", "=", "net1", ".", "__dict__", "[", "key", "]", "val2", "=", "net2", ".", "_...
https://github.com/dragonfly/dragonfly/blob/a579b5eadf452e23b07d4caf27b402703b0012b7/dragonfly/nn/nn_domains.py#L172-L189
mcahny/vps
138503edbc9e70de744dc0c9fa4b71c799a94d5d
mmdet/models/flow_modules/flow_modules.py
python
conv
(in_planes, out_planes, kernel_size=3, stride=1, dilation=1)
return nn.Sequential( nn.Conv2d(in_planes, out_planes, kernel_size=kernel_size, stride=stride, dilation=dilation, padding=((kernel_size - 1) * dilation) // 2, bias=True), nn.LeakyReLU(0.1, inplace=True))
[]
def conv(in_planes, out_planes, kernel_size=3, stride=1, dilation=1): return nn.Sequential( nn.Conv2d(in_planes, out_planes, kernel_size=kernel_size, stride=stride, dilation=dilation, padding=((kernel_size - 1) * dilation) // 2, bias=True), nn.LeakyReLU(0.1, inplace=True))
[ "def", "conv", "(", "in_planes", ",", "out_planes", ",", "kernel_size", "=", "3", ",", "stride", "=", "1", ",", "dilation", "=", "1", ")", ":", "return", "nn", ".", "Sequential", "(", "nn", ".", "Conv2d", "(", "in_planes", ",", "out_planes", ",", "ke...
https://github.com/mcahny/vps/blob/138503edbc9e70de744dc0c9fa4b71c799a94d5d/mmdet/models/flow_modules/flow_modules.py#L29-L34
Bitmessage/PyBitmessage
97612b049e0453867d6d90aa628f8e7b007b4d85
src/bitmessageqt/foldertree.py
python
AddressBookCompleter.pathFromIndex
(self, index)
return part1 + autoString + part2
Perform autocompletion (reimplemented QCompleter method)
Perform autocompletion (reimplemented QCompleter method)
[ "Perform", "autocompletion", "(", "reimplemented", "QCompleter", "method", ")" ]
def pathFromIndex(self, index): """Perform autocompletion (reimplemented QCompleter method)""" autoString = unicode( index.data(QtCore.Qt.EditRole).toString().toUtf8(), 'utf-8') text = unicode(self.widget().text().toUtf8(), 'utf-8') # If cursor position was saved, restore it, else save it if self.cursorPos != -1: self.widget().setCursorPosition(self.cursorPos) else: self.cursorPos = self.widget().cursorPosition() # Get current prosition curIndex = self.widget().cursorPosition() # prev_delimiter_index should actually point at final white space # AFTER the delimiter # Get index of last delimiter before current position prevDelimiterIndex = text[0:curIndex].rfind(";") while text[prevDelimiterIndex + 1] == " ": prevDelimiterIndex += 1 # Get index of first delimiter after current position # (or EOL if no delimiter after cursor) nextDelimiterIndex = text.find(";", curIndex) if nextDelimiterIndex == -1: nextDelimiterIndex = len(text) # Get part of string that occurs before cursor part1 = text[0:prevDelimiterIndex + 1] # Get string value from before auto finished string is selected # pre = text[prevDelimiterIndex + 1:curIndex - 1] # Get part of string that occurs AFTER cursor part2 = text[nextDelimiterIndex:] return part1 + autoString + part2
[ "def", "pathFromIndex", "(", "self", ",", "index", ")", ":", "autoString", "=", "unicode", "(", "index", ".", "data", "(", "QtCore", ".", "Qt", ".", "EditRole", ")", ".", "toString", "(", ")", ".", "toUtf8", "(", ")", ",", "'utf-8'", ")", "text", "...
https://github.com/Bitmessage/PyBitmessage/blob/97612b049e0453867d6d90aa628f8e7b007b4d85/src/bitmessageqt/foldertree.py#L590-L627
jacoxu/encoder_decoder
6829c3bc42105aedfd1b8a81c81be19df4326c0a
keras/backend/theano_backend.py
python
batch_flatten
(x)
return x
Turn a n-D tensor into a 2D tensor where the first dimension is conserved.
Turn a n-D tensor into a 2D tensor where the first dimension is conserved.
[ "Turn", "a", "n", "-", "D", "tensor", "into", "a", "2D", "tensor", "where", "the", "first", "dimension", "is", "conserved", "." ]
def batch_flatten(x): '''Turn a n-D tensor into a 2D tensor where the first dimension is conserved. ''' x = T.reshape(x, (x.shape[0], T.prod(x.shape) // x.shape[0])) return x
[ "def", "batch_flatten", "(", "x", ")", ":", "x", "=", "T", ".", "reshape", "(", "x", ",", "(", "x", ".", "shape", "[", "0", "]", ",", "T", ".", "prod", "(", "x", ".", "shape", ")", "//", "x", ".", "shape", "[", "0", "]", ")", ")", "return...
https://github.com/jacoxu/encoder_decoder/blob/6829c3bc42105aedfd1b8a81c81be19df4326c0a/keras/backend/theano_backend.py#L310-L315
openstack/sahara
c4f4d29847d5bcca83d49ef7e9a3378458462a79
sahara/api/middleware/version_discovery.py
python
VersionResponseMiddlewareV1._get_versions
(self, req)
return version_response
Populate the version response with APIv1 stuff.
Populate the version response with APIv1 stuff.
[ "Populate", "the", "version", "response", "with", "APIv1", "stuff", "." ]
def _get_versions(self, req): """Populate the version response with APIv1 stuff.""" version_response = { "versions": [ {"id": "v1.0", "status": "SUPPORTED", "links": self._get_links("1.0", req) }, {"id": "v1.1", "status": "CURRENT", "links": self._get_links("1.1", req) } ] } return version_response
[ "def", "_get_versions", "(", "self", ",", "req", ")", ":", "version_response", "=", "{", "\"versions\"", ":", "[", "{", "\"id\"", ":", "\"v1.0\"", ",", "\"status\"", ":", "\"SUPPORTED\"", ",", "\"links\"", ":", "self", ".", "_get_links", "(", "\"1.0\"", ",...
https://github.com/openstack/sahara/blob/c4f4d29847d5bcca83d49ef7e9a3378458462a79/sahara/api/middleware/version_discovery.py#L40-L54
securesystemslab/zippy
ff0e84ac99442c2c55fe1d285332cfd4e185e089
zippy/lib-python/3/xml/dom/pulldom.py
python
DOMEventStream.__next__
(self)
[]
def __next__(self): rc = self.getEvent() if rc: return rc raise StopIteration
[ "def", "__next__", "(", "self", ")", ":", "rc", "=", "self", ".", "getEvent", "(", ")", "if", "rc", ":", "return", "rc", "raise", "StopIteration" ]
https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/lib-python/3/xml/dom/pulldom.py#L226-L230
cms-dev/cms
0401c5336b34b1731736045da4877fef11889274
cms/db/fsobject.py
python
FSObject.delete
(self)
Delete this file.
Delete this file.
[ "Delete", "this", "file", "." ]
def delete(self): """Delete this file. """ LargeObject.unlink(self.loid) self.sa_session.delete(self)
[ "def", "delete", "(", "self", ")", ":", "LargeObject", ".", "unlink", "(", "self", ".", "loid", ")", "self", ".", "sa_session", ".", "delete", "(", "self", ")" ]
https://github.com/cms-dev/cms/blob/0401c5336b34b1731736045da4877fef11889274/cms/db/fsobject.py#L394-L399
triaquae/triaquae
bbabf736b3ba56a0c6498e7f04e16c13b8b8f2b9
TriAquae/models/Centos_6.4/paramiko/sftp_file.py
python
SFTPFile._prefetch_thread
(self, chunks)
[]
def _prefetch_thread(self, chunks): # do these read requests in a temporary thread because there may be # a lot of them, so it may block. for offset, length in chunks: self.sftp._async_request(self, CMD_READ, self.handle, long(offset), int(length))
[ "def", "_prefetch_thread", "(", "self", ",", "chunks", ")", ":", "# do these read requests in a temporary thread because there may be", "# a lot of them, so it may block.", "for", "offset", ",", "length", "in", "chunks", ":", "self", ".", "sftp", ".", "_async_request", "(...
https://github.com/triaquae/triaquae/blob/bbabf736b3ba56a0c6498e7f04e16c13b8b8f2b9/TriAquae/models/Centos_6.4/paramiko/sftp_file.py#L456-L460
JosephLai241/URS
9f8cf3a3adb9aa5079dfc7bfd7832b53358ee40f
urs/praw_scrapers/static_scrapers/Redditor.py
python
GetInteractions.get
(limit, reddit, redditor)
return skeleton
Get Redditor information and interactions. Calls previously defined private methods: GetInteractions._make_json_skeleton() GetInteractions._get_user_info() GetInteractions._get_user_interactions() Parameters ---------- limit: str String denoting n_results returned reddit: PRAW Reddit object redditor: PRAW Redditor object Returns ------- skeleton: dict Dictionary containing all Redditor data
Get Redditor information and interactions.
[ "Get", "Redditor", "information", "and", "interactions", "." ]
def get(limit, reddit, redditor): """ Get Redditor information and interactions. Calls previously defined private methods: GetInteractions._make_json_skeleton() GetInteractions._get_user_info() GetInteractions._get_user_interactions() Parameters ---------- limit: str String denoting n_results returned reddit: PRAW Reddit object redditor: PRAW Redditor object Returns ------- skeleton: dict Dictionary containing all Redditor data """ redditor, skeleton = GetInteractions._make_json_skeleton(limit, reddit, redditor) GetInteractions._get_user_info(redditor, skeleton) GetInteractions._get_user_interactions(limit, redditor, skeleton) return skeleton
[ "def", "get", "(", "limit", ",", "reddit", ",", "redditor", ")", ":", "redditor", ",", "skeleton", "=", "GetInteractions", ".", "_make_json_skeleton", "(", "limit", ",", "reddit", ",", "redditor", ")", "GetInteractions", ".", "_get_user_info", "(", "redditor",...
https://github.com/JosephLai241/URS/blob/9f8cf3a3adb9aa5079dfc7bfd7832b53358ee40f/urs/praw_scrapers/static_scrapers/Redditor.py#L485-L512
ganeti/ganeti
d340a9ddd12f501bef57da421b5f9b969a4ba905
lib/server/noded.py
python
NodeRequestHandler.perspective_bdev_sizes
(params)
return backend.GetBlockDevSizes(devices)
Query the list of block devices
Query the list of block devices
[ "Query", "the", "list", "of", "block", "devices" ]
def perspective_bdev_sizes(params): """Query the list of block devices """ devices = params[0] return backend.GetBlockDevSizes(devices)
[ "def", "perspective_bdev_sizes", "(", "params", ")", ":", "devices", "=", "params", "[", "0", "]", "return", "backend", ".", "GetBlockDevSizes", "(", "devices", ")" ]
https://github.com/ganeti/ganeti/blob/d340a9ddd12f501bef57da421b5f9b969a4ba905/lib/server/noded.py#L544-L549
madengr/ham2mon
db9834ce923c1919602bf33cb47720daba9bc6ea
apps/ham2mon.py
python
main
(screen)
Start scanner with GUI interface Initialize and set up screen Create windows Create scanner object Executes scan cycles Update windows Process keyboard strokes
Start scanner with GUI interface
[ "Start", "scanner", "with", "GUI", "interface" ]
def main(screen): """Start scanner with GUI interface Initialize and set up screen Create windows Create scanner object Executes scan cycles Update windows Process keyboard strokes """ # pylint: disable=too-many-statements # pylint: disable-msg=R0914 # Use the curses.wrapper() to crash cleanly # Note the screen object is passed from the wrapper() # http://stackoverflow.com/questions/9854511/python-curses-dilemma # The issue is the debuuger won't work with the wrapper() # Nor does the python optiosn parser # So enable the next 2 lines and don't pass screen to main() #screen = curses.initscr() #curses.start_color() # Setup the screen cursesgui.setup_screen(screen) # Create windows specwin = cursesgui.SpectrumWindow(screen) chanwin = cursesgui.ChannelWindow(screen) lockoutwin = cursesgui.LockoutWindow(screen) rxwin = cursesgui.RxWindow(screen) # Create scanner object ask_samp_rate = PARSER.ask_samp_rate num_demod = PARSER.num_demod type_demod = PARSER.type_demod hw_args = PARSER.hw_args record = PARSER.record play = PARSER.play lockout_file_name = PARSER.lockout_file_name priority_file_name = PARSER.priority_file_name freq_correction = PARSER.freq_correction audio_bps = PARSER.audio_bps scanner = scnr.Scanner(ask_samp_rate, num_demod, type_demod, hw_args, freq_correction, record, lockout_file_name, priority_file_name, play, audio_bps) # Set the paramaters scanner.set_center_freq(PARSER.center_freq) scanner.set_gain(PARSER.gain_db) scanner.set_if_gain(PARSER.if_gain_db) scanner.set_bb_gain(PARSER.bb_gain_db) scanner.set_squelch(PARSER.squelch_db) scanner.set_volume(PARSER.volume_db) scanner.set_threshold(PARSER.threshold_db) # Get the initial settings for GUI rxwin.center_freq = scanner.center_freq rxwin.samp_rate = scanner.samp_rate rxwin.gain_db = scanner.gain_db rxwin.if_gain_db = scanner.if_gain_db rxwin.bb_gain_db = scanner.bb_gain_db rxwin.squelch_db = scanner.squelch_db rxwin.volume_db = scanner.volume_db rxwin.record = scanner.record rxwin.type_demod = type_demod rxwin.lockout_file_name = scanner.lockout_file_name rxwin.priority_file_name = scanner.priority_file_name specwin.threshold_db = scanner.threshold_db while 1: # No need to go faster than 10 Hz rate of GNU Radio probe time.sleep(0.1) # Initiate a scan cycle scanner.scan_cycle() # Update the spectrum, channel, and rx displays specwin.draw_spectrum(scanner.spectrum) chanwin.draw_channels(scanner.gui_tuned_channels) lockoutwin.draw_channels(scanner.gui_lockout_channels) rxwin.draw_rx() # Update physical screen curses.doupdate() # Get keystroke keyb = screen.getch() # Send keystroke to spectrum window and update scanner if True if specwin.proc_keyb(keyb): scanner.set_threshold(specwin.threshold_db) # Send keystroke to RX window and update scanner if True if rxwin.proc_keyb_hard(keyb): # Set and update frequency scanner.set_center_freq(rxwin.center_freq) rxwin.center_freq = scanner.center_freq if rxwin.proc_keyb_soft(keyb): # Set and update RF gain scanner.set_gain(rxwin.gain_db) rxwin.gain_db = scanner.gain_db # Set and update IF gain scanner.set_if_gain(rxwin.if_gain_db) rxwin.if_gain_db = scanner.if_gain_db # Set and update BB gain scanner.set_bb_gain(rxwin.bb_gain_db) rxwin.bb_gain_db = scanner.bb_gain_db # Set and update squelch scanner.set_squelch(rxwin.squelch_db) rxwin.squelch_db = scanner.squelch_db # Set and update volume scanner.set_volume(rxwin.volume_db) rxwin.volume_db = scanner.volume_db # Send keystroke to lockout window and update lockout channels if True if lockoutwin.proc_keyb_set_lockout(keyb) and rxwin.freq_entry == 'None': # Subtract 48 from ascii keyb value to obtain 0 - 9 idx = keyb - 48 scanner.add_lockout(idx) if lockoutwin.proc_keyb_clear_lockout(keyb): scanner.clear_lockout()
[ "def", "main", "(", "screen", ")", ":", "# pylint: disable=too-many-statements", "# pylint: disable-msg=R0914", "# Use the curses.wrapper() to crash cleanly", "# Note the screen object is passed from the wrapper()", "# http://stackoverflow.com/questions/9854511/python-curses-dilemma", "# The i...
https://github.com/madengr/ham2mon/blob/db9834ce923c1919602bf33cb47720daba9bc6ea/apps/ham2mon.py#L15-L137
SteveDoyle2/pyNastran
eda651ac2d4883d95a34951f8a002ff94f642a1a
pyNastran/bdf/cards/optimization.py
python
DVPREL2._verify
(self, xref)
Verifies all methods for this object work Parameters ---------- xref : bool has this model been cross referenced
Verifies all methods for this object work
[ "Verifies", "all", "methods", "for", "this", "object", "work" ]
def _verify(self, xref): """ Verifies all methods for this object work Parameters ---------- xref : bool has this model been cross referenced """ pass
[ "def", "_verify", "(", "self", ",", "xref", ")", ":", "pass" ]
https://github.com/SteveDoyle2/pyNastran/blob/eda651ac2d4883d95a34951f8a002ff94f642a1a/pyNastran/bdf/cards/optimization.py#L5233-L5243
google/pyringe
76dff5d1ac29cd5e7bf32677654a83291a15ad8a
pyringe/payload/libpython.py
python
PyCodeObjectPtr.addr2line
(self, addrq)
return lineno
Get the line number for a given bytecode offset Analogous to PyCode_Addr2Line; translated from pseudocode in Objects/lnotab_notes.txt
Get the line number for a given bytecode offset
[ "Get", "the", "line", "number", "for", "a", "given", "bytecode", "offset" ]
def addr2line(self, addrq): ''' Get the line number for a given bytecode offset Analogous to PyCode_Addr2Line; translated from pseudocode in Objects/lnotab_notes.txt ''' co_lnotab = self.pyop_field('co_lnotab').proxyval(set()) # Initialize lineno to co_firstlineno as per PyCode_Addr2Line # not 0, as lnotab_notes.txt has it: lineno = int_from_int(self.field('co_firstlineno')) addr = 0 for addr_incr, line_incr in zip(co_lnotab[::2], co_lnotab[1::2]): addr += ord(addr_incr) if addr > addrq: return lineno lineno += ord(line_incr) return lineno
[ "def", "addr2line", "(", "self", ",", "addrq", ")", ":", "co_lnotab", "=", "self", ".", "pyop_field", "(", "'co_lnotab'", ")", ".", "proxyval", "(", "set", "(", ")", ")", "# Initialize lineno to co_firstlineno as per PyCode_Addr2Line", "# not 0, as lnotab_notes.txt ha...
https://github.com/google/pyringe/blob/76dff5d1ac29cd5e7bf32677654a83291a15ad8a/pyringe/payload/libpython.py#L592-L611
pyparallel/pyparallel
11e8c6072d48c8f13641925d17b147bf36ee0ba3
Lib/site-packages/pip-7.1.2-py3.3.egg/pip/_vendor/requests/packages/urllib3/packages/ordered_dict.py
python
OrderedDict.__init__
(self, *args, **kwds)
Initialize an ordered dictionary. Signature is the same as for regular dictionaries, but keyword arguments are not recommended because their insertion order is arbitrary.
Initialize an ordered dictionary. Signature is the same as for regular dictionaries, but keyword arguments are not recommended because their insertion order is arbitrary.
[ "Initialize", "an", "ordered", "dictionary", ".", "Signature", "is", "the", "same", "as", "for", "regular", "dictionaries", "but", "keyword", "arguments", "are", "not", "recommended", "because", "their", "insertion", "order", "is", "arbitrary", "." ]
def __init__(self, *args, **kwds): '''Initialize an ordered dictionary. Signature is the same as for regular dictionaries, but keyword arguments are not recommended because their insertion order is arbitrary. ''' if len(args) > 1: raise TypeError('expected at most 1 arguments, got %d' % len(args)) try: self.__root except AttributeError: self.__root = root = [] # sentinel node root[:] = [root, root, None] self.__map = {} self.__update(*args, **kwds)
[ "def", "__init__", "(", "self", ",", "*", "args", ",", "*", "*", "kwds", ")", ":", "if", "len", "(", "args", ")", ">", "1", ":", "raise", "TypeError", "(", "'expected at most 1 arguments, got %d'", "%", "len", "(", "args", ")", ")", "try", ":", "self...
https://github.com/pyparallel/pyparallel/blob/11e8c6072d48c8f13641925d17b147bf36ee0ba3/Lib/site-packages/pip-7.1.2-py3.3.egg/pip/_vendor/requests/packages/urllib3/packages/ordered_dict.py#L28-L42
TencentCloud/tencentcloud-sdk-python
3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2
tencentcloud/ecm/v20190719/models.py
python
DescribePeakNetworkOverviewResponse.__init__
(self)
r""" :param PeakNetworkRegionSet: 网络峰值数组。 注意:此字段可能返回 null,表示取不到有效值。 :type PeakNetworkRegionSet: list of PeakNetworkRegionInfo :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str
r""" :param PeakNetworkRegionSet: 网络峰值数组。 注意:此字段可能返回 null,表示取不到有效值。 :type PeakNetworkRegionSet: list of PeakNetworkRegionInfo :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str
[ "r", ":", "param", "PeakNetworkRegionSet", ":", "网络峰值数组。", "注意:此字段可能返回", "null,表示取不到有效值。", ":", "type", "PeakNetworkRegionSet", ":", "list", "of", "PeakNetworkRegionInfo", ":", "param", "RequestId", ":", "唯一请求", "ID,每次请求都会返回。定位问题时需要提供该次请求的", "RequestId。", ":", "type", ...
def __init__(self): r""" :param PeakNetworkRegionSet: 网络峰值数组。 注意:此字段可能返回 null,表示取不到有效值。 :type PeakNetworkRegionSet: list of PeakNetworkRegionInfo :param RequestId: 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 :type RequestId: str """ self.PeakNetworkRegionSet = None self.RequestId = None
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "PeakNetworkRegionSet", "=", "None", "self", ".", "RequestId", "=", "None" ]
https://github.com/TencentCloud/tencentcloud-sdk-python/blob/3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2/tencentcloud/ecm/v20190719/models.py#L4257-L4266
TengXiaoDai/DistributedCrawling
f5c2439e6ce68dd9b49bde084d76473ff9ed4963
Lib/linecache.py
python
clearcache
()
Clear the cache entirely.
Clear the cache entirely.
[ "Clear", "the", "cache", "entirely", "." ]
def clearcache(): """Clear the cache entirely.""" global cache cache = {}
[ "def", "clearcache", "(", ")", ":", "global", "cache", "cache", "=", "{", "}" ]
https://github.com/TengXiaoDai/DistributedCrawling/blob/f5c2439e6ce68dd9b49bde084d76473ff9ed4963/Lib/linecache.py#L30-L34
TengXiaoDai/DistributedCrawling
f5c2439e6ce68dd9b49bde084d76473ff9ed4963
Lib/site-packages/pip/_vendor/pkg_resources/__init__.py
python
EntryPoint.parse
(cls, src, dist=None)
return cls(res['name'], res['module'], attrs, extras, dist)
Parse a single entry point from string `src` Entry point syntax follows the form:: name = some.module:some.attr [extra1, extra2] The entry name and module name are required, but the ``:attrs`` and ``[extras]`` parts are optional
Parse a single entry point from string `src`
[ "Parse", "a", "single", "entry", "point", "from", "string", "src" ]
def parse(cls, src, dist=None): """Parse a single entry point from string `src` Entry point syntax follows the form:: name = some.module:some.attr [extra1, extra2] The entry name and module name are required, but the ``:attrs`` and ``[extras]`` parts are optional """ m = cls.pattern.match(src) if not m: msg = "EntryPoint must be in 'name=module:attrs [extras]' format" raise ValueError(msg, src) res = m.groupdict() extras = cls._parse_extras(res['extras']) attrs = res['attr'].split('.') if res['attr'] else () return cls(res['name'], res['module'], attrs, extras, dist)
[ "def", "parse", "(", "cls", ",", "src", ",", "dist", "=", "None", ")", ":", "m", "=", "cls", ".", "pattern", ".", "match", "(", "src", ")", "if", "not", "m", ":", "msg", "=", "\"EntryPoint must be in 'name=module:attrs [extras]' format\"", "raise", "ValueE...
https://github.com/TengXiaoDai/DistributedCrawling/blob/f5c2439e6ce68dd9b49bde084d76473ff9ed4963/Lib/site-packages/pip/_vendor/pkg_resources/__init__.py#L2321-L2338
TencentCloud/tencentcloud-sdk-python
3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2
tencentcloud/emr/v20190103/models.py
python
InquiryPriceScaleOutInstanceRequest.__init__
(self)
r""" :param TimeUnit: 扩容的时间单位。取值范围: <li>s:表示秒。PayMode取值为0时,TimeUnit只能取值为s。</li> <li>m:表示月份。PayMode取值为1时,TimeUnit只能取值为m。</li> :type TimeUnit: str :param TimeSpan: 扩容的时长。结合TimeUnit一起使用。 <li>TimeUnit为s时,该参数只能填写3600,表示按量计费实例。</li> <li>TimeUnit为m时,该参数填写的数字表示包年包月实例的购买时长,如1表示购买一个月</li> :type TimeSpan: int :param ZoneId: 实例所属的可用区ID,例如100003。该参数可以通过调用 [DescribeZones](https://cloud.tencent.com/document/api/213/15707) 的返回值中的ZoneId字段来获取。 :type ZoneId: int :param PayMode: 实例计费模式。取值范围: <li>0:表示按量计费。</li> <li>1:表示包年包月。</li> :type PayMode: int :param InstanceId: 实例ID。 :type InstanceId: str :param CoreCount: 扩容的Core节点数量。 :type CoreCount: int :param TaskCount: 扩容的Task节点数量。 :type TaskCount: int :param Currency: 货币种类。取值范围: <li>CNY:表示人民币。</li> :type Currency: str :param RouterCount: 扩容的Router节点数量。 :type RouterCount: int :param MasterCount: 扩容的Master节点数量。 :type MasterCount: int
r""" :param TimeUnit: 扩容的时间单位。取值范围: <li>s:表示秒。PayMode取值为0时,TimeUnit只能取值为s。</li> <li>m:表示月份。PayMode取值为1时,TimeUnit只能取值为m。</li> :type TimeUnit: str :param TimeSpan: 扩容的时长。结合TimeUnit一起使用。 <li>TimeUnit为s时,该参数只能填写3600,表示按量计费实例。</li> <li>TimeUnit为m时,该参数填写的数字表示包年包月实例的购买时长,如1表示购买一个月</li> :type TimeSpan: int :param ZoneId: 实例所属的可用区ID,例如100003。该参数可以通过调用 [DescribeZones](https://cloud.tencent.com/document/api/213/15707) 的返回值中的ZoneId字段来获取。 :type ZoneId: int :param PayMode: 实例计费模式。取值范围: <li>0:表示按量计费。</li> <li>1:表示包年包月。</li> :type PayMode: int :param InstanceId: 实例ID。 :type InstanceId: str :param CoreCount: 扩容的Core节点数量。 :type CoreCount: int :param TaskCount: 扩容的Task节点数量。 :type TaskCount: int :param Currency: 货币种类。取值范围: <li>CNY:表示人民币。</li> :type Currency: str :param RouterCount: 扩容的Router节点数量。 :type RouterCount: int :param MasterCount: 扩容的Master节点数量。 :type MasterCount: int
[ "r", ":", "param", "TimeUnit", ":", "扩容的时间单位。取值范围:", "<li", ">", "s:表示秒。PayMode取值为0时,TimeUnit只能取值为s。<", "/", "li", ">", "<li", ">", "m:表示月份。PayMode取值为1时,TimeUnit只能取值为m。<", "/", "li", ">", ":", "type", "TimeUnit", ":", "str", ":", "param", "TimeSpan", ":", "扩容的时长...
def __init__(self): r""" :param TimeUnit: 扩容的时间单位。取值范围: <li>s:表示秒。PayMode取值为0时,TimeUnit只能取值为s。</li> <li>m:表示月份。PayMode取值为1时,TimeUnit只能取值为m。</li> :type TimeUnit: str :param TimeSpan: 扩容的时长。结合TimeUnit一起使用。 <li>TimeUnit为s时,该参数只能填写3600,表示按量计费实例。</li> <li>TimeUnit为m时,该参数填写的数字表示包年包月实例的购买时长,如1表示购买一个月</li> :type TimeSpan: int :param ZoneId: 实例所属的可用区ID,例如100003。该参数可以通过调用 [DescribeZones](https://cloud.tencent.com/document/api/213/15707) 的返回值中的ZoneId字段来获取。 :type ZoneId: int :param PayMode: 实例计费模式。取值范围: <li>0:表示按量计费。</li> <li>1:表示包年包月。</li> :type PayMode: int :param InstanceId: 实例ID。 :type InstanceId: str :param CoreCount: 扩容的Core节点数量。 :type CoreCount: int :param TaskCount: 扩容的Task节点数量。 :type TaskCount: int :param Currency: 货币种类。取值范围: <li>CNY:表示人民币。</li> :type Currency: str :param RouterCount: 扩容的Router节点数量。 :type RouterCount: int :param MasterCount: 扩容的Master节点数量。 :type MasterCount: int """ self.TimeUnit = None self.TimeSpan = None self.ZoneId = None self.PayMode = None self.InstanceId = None self.CoreCount = None self.TaskCount = None self.Currency = None self.RouterCount = None self.MasterCount = None
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "TimeUnit", "=", "None", "self", ".", "TimeSpan", "=", "None", "self", ".", "ZoneId", "=", "None", "self", ".", "PayMode", "=", "None", "self", ".", "InstanceId", "=", "None", "self", ".", "CoreC...
https://github.com/TencentCloud/tencentcloud-sdk-python/blob/3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2/tencentcloud/emr/v20190103/models.py#L1780-L1819
nanoporetech/medaka
2b83074fe3b6a6ec971614bfc6804f543fe1e5f0
medaka/medaka.py
python
medaka_parser
()
return parser
Create the medaka command-line interface.
Create the medaka command-line interface.
[ "Create", "the", "medaka", "command", "-", "line", "interface", "." ]
def medaka_parser(): """Create the medaka command-line interface.""" from medaka import __version__ parser = argparse.ArgumentParser('medaka', formatter_class=argparse.ArgumentDefaultsHelpFormatter) subparsers = parser.add_subparsers(title='subcommands', description='valid commands', help='additional help', dest='command') subparsers.required = True parser.add_argument('--version', action='version', version='%(prog)s {}'.format(__version__)) # Compress bam file_ext rparser = subparsers.add_parser('compress_bam', help='Compress an alignment into RLE form. ', parents=[_log_level(), _regions_or_bed_args()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) rparser.set_defaults(func=medaka.rle.compress_bam) rparser.add_argument('bam_input', help='Bam file to compress.') rparser.add_argument('bam_output', help='Output bam file.') rparser.add_argument('ref_fname', help='Reference fasta file used for `bam_input`.') rparser.add_argument('--threads', type=int, default=1, help='Number of threads for parallel execution.') rparser.add_argument( '--use_fast5_info', metavar='<fast5_dir> <index>', default=None, nargs=2, help=( 'Root directory containing the fast5 files and .tsv file with ' 'columns filename and read_id.')) # Creation of feature files fparser = subparsers.add_parser('features', help='Create features for inference.', parents=[_log_level(), _chunking_feature_args(), _regions_or_bed_args()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) fparser.set_defaults(func=medaka.features.create_samples) fparser.add_argument('bam', help='Input alignments.', action=CheckBam) fparser.add_argument('output', help='Output features file.') fparser.add_argument('--truth', help='Bam of truth aligned to ref to create features for training.') fparser.add_argument('--truth_haplotag', help='Two-letter tag defining haplotype of alignments for polyploidy labels.') fparser.add_argument('--threads', type=int, default=1, help='Number of threads for parallel execution.') # TODO: enable other label schemes. fparser.add_argument('--label_scheme', default='HaploidLabelScheme', help='Labelling scheme.', choices=sorted(medaka.labels.label_schemes)) fparser.add_argument('--label_scheme_args', action=StoreDict, nargs='+', default=dict(), metavar="KEY1=VAL1 KEY2=VAL2a,VAL2b...", help="Label scheme key-word arguments.") fparser.add_argument('--feature_encoder', default='CountsFeatureEncoder', help='FeatureEncoder used to create the features.', choices=sorted(medaka.features.feature_encoders)) fparser.add_argument('--feature_encoder_args', action=StoreDict, nargs='+', default=dict(), metavar="KEY1=VAL1 KEY2=VAL2a,VAL2b...", help="Feature encoder key-word arguments.") # Training program tparser = subparsers.add_parser('train', help='Train a model from features.', parents=[_log_level()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) tparser.set_defaults(func=medaka.training.train) tparser.add_argument('features', nargs='+', help='Paths to training data.') tparser.add_argument('--train_name', type=str, default='keras_train', help='Name for training run.') tparser.add_argument('--model', action=ResolveModel, help='Model definition and initial weights .hdf, or .yml with kwargs to build model.') tparser.add_argument('--epochs', type=int, default=5000, help='Maximum number of trainig epochs.') tparser.add_argument('--batch_size', type=int, default=100, help='Training batch size.') tparser.add_argument('--max_samples', type=int, default=float("inf"), help='Only train on max_samples.') tparser.add_argument('--mini_epochs', type=int, default=1, help='Reduce fraction of data per epoch by this factor') tparser.add_argument('--seed', type=int, help='Seed for random batch shuffling.') tparser.add_argument('--threads_io', type=int, default=1, help='Number of threads for parallel IO.') tparser.add_argument('--device', type=int, default=0, help='GPU device to use.') tparser.add_argument('--optimizer', type=str, default='rmsprop', choices=['nadam','rmsprop'], help='Optimizer to use.') tparser.add_argument('--optim_args', action=StoreDict, default=None, nargs='+', metavar="KEY1=VAL1,KEY2=VAL2...", help="Optimizer key-word arguments.") vgrp = tparser.add_mutually_exclusive_group() vgrp.add_argument('--validation_split', type=float, default=0.2, help='Fraction of data to validate on.') vgrp.add_argument('--validation_features', nargs='+', default=None, help='Paths to validation data') # Consensus from bam input # NB: any args added here should be set to default values in smolecule:main() # to avoid attribute errors in that program. cparser = subparsers.add_parser('consensus', help='Run inference from a trained model and alignments.', parents=[_log_level(), _chunking_feature_args(), _regions_or_bed_args(), _model_arg(), _rg_arg()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) cparser.set_defaults(func=medaka.prediction.predict) cparser.add_argument('bam', help='Input alignments.', action=CheckBam) cparser.add_argument('output', help='Output file.') cparser.add_argument('--threads', type=int, default=1, help='Number of threads used by inference.') cparser.add_argument('--bam_workers', type=int, default=2, help='Number of workers used to prepare data from bam.') cparser.add_argument('--bam_chunk', type=int, default=int(1e6), help='Size of reference chunks each worker parses from bam. (can be used to control memory use).') cparser.add_argument('--check_output', action='store_true', default=False, help='Verify integrity of output file after inference.') cparser.add_argument('--save_features', action='store_true', default=False, help='Save features with consensus probabilities.') tag_group = cparser.add_argument_group('filter tag', 'Filtering alignments by an integer valued tag.') tag_group.add_argument('--tag_name', type=str, help='Two-letter tag name.') tag_group.add_argument('--tag_value', type=int, help='Value of tag.') tag_group.add_argument('--tag_keep_missing', action='store_true', help='Keep alignments when tag is missing.') # Consensus from single-molecules with subreads smparser = subparsers.add_parser('smolecule', help='Create consensus sequences from single-molecule reads.', parents=[_log_level(), _chunking_feature_args(batch_size=100, chunk_len=1000, chunk_ovlp=500), _model_arg()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) smparser.set_defaults(func=medaka.smolecule.main) smparser.add_argument('output', help='Output directory.') smparser.add_argument('fasta', nargs='+', help='Single-molecule reads, one file per read.') smparser.add_argument('--method', choices=['racon', 'spoa'], default='spoa', help='Pre-medaka consensus generation method.') smparser.add_argument('--depth', type=int, default=3, help='Minimum subread count.') smparser.add_argument('--length', type=int, default=400, help='Minimum median subread length.') smparser.add_argument('--threads', type=int, default=1, help='Number of threads used by inference.') smparser.add_argument('--check_output', action='store_true', default=False, help='Verify integrity of output file after inference.') smparser.add_argument('--save_features', action='store_true', default=False, help='Save features with consensus probabilities.') # Consensus from features input cfparser = subparsers.add_parser('consensus_from_features', help='Run inference from a trained model on existing features.', parents=[_log_level(), _model_arg()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) # TODO: why doesn't this have a .set_defaults? cfparser.add_argument('features', nargs='+', help='Pregenerated features (from medaka features).') # Compression of fasta/q to quality-RLE fastq rleparser = subparsers.add_parser('fastrle', help='Create run-length encoded fastq (lengths in quality track).', parents=[_log_level()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) rleparser.set_defaults(func=fastrle) rleparser.add_argument('input', help='Input fasta/q. may be gzip compressed.') rleparser.add_argument('--block_size', action=CheckBlockSize, default=94, type=int, help='Block size for hompolymer splitting, e.g. with a value of blocksize=3, AAAA -> A3 A1.') # Post-processing of consensus outputs sparser = subparsers.add_parser('stitch', help='Stitch together output from medaka consensus into final output.', parents=[_log_level(), _region_ref_names()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) sparser.set_defaults(func=medaka.stitch.stitch) sparser.add_argument('inputs', help='Consensus .hdf files.', nargs='+') sparser.add_argument('draft', help='Draft .fasta. Consensus gaps will be filled with unpolished ' 'draft sequence to avoid contig fragmentation.') sparser.add_argument('output', help='Output .fasta.', default='consensus.fasta') sparser.add_argument('--threads', help='Number of worker processes to use.', default=1, type=int) sparser.add_argument('--no-fillgaps', help="Don't fill gaps in consensus sequence with draft sequence.", default=True, action='store_false', dest='fillgaps') var_parser = subparsers.add_parser('variant', help='Decode probabilities to VCF.', parents=[_log_level(), _region_ref_names()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) var_parser.set_defaults(func=medaka.variant.variants_from_hdf) var_parser.add_argument('ref_fasta', help='Reference sequence .fasta file.') var_parser.add_argument('inputs', nargs='+', help='Consensus .hdf files.') var_parser.add_argument('output', help='Output .vcf.', default='medaka.vcf') var_parser.add_argument('--verbose', action='store_true', help='Populate VCF info fields.') var_parser.add_argument('--ambig_ref', action='store_true', help='Decode variants at ambiguous reference positions.') var_parser.add_argument('--gvcf', action='store_true', help='Output VCF records for reference loci predicted to be non-variant.') # TODO do we still need this? snp_parser = subparsers.add_parser('snp', help='Decode probabilities to SNPs.', parents=[_log_level(), _region_ref_names()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) snp_parser.set_defaults(func=medaka.variant.snps_from_hdf) snp_parser.add_argument('ref_fasta', help='Reference sequence .fasta file.') snp_parser.add_argument('inputs', nargs='+', help='Consensus .hdf files.') snp_parser.add_argument('output', help='Output .vcf.', default='medaka.vcf') snp_parser.add_argument('--threshold', default=0.04, type=float, help='Threshold for considering secondary calls. A value of 1 will result in haploid decoding.') snp_parser.add_argument('--ref_vcf', default=None, help='Reference vcf.') snp_parser.add_argument('--verbose', action='store_true', help='Populate VCF info fields.') # Tools toolparser = subparsers.add_parser('tools', help='tools subcommand.', parents=[_log_level()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) toolsubparsers = toolparser.add_subparsers(title='tools', description='valid tool commands', help='additional help', dest='tool_command') # merge two haploid VCFs into a diploid VCF. h2dparser = toolsubparsers.add_parser('haploid2diploid', help='Merge two haploid VCFs into a diploid VCF.', parents=[_log_level()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) h2dparser.set_defaults(func=medaka.vcf.haploid2diploid) h2dparser.add_argument('vcf1', help='Input .vcf file.') h2dparser.add_argument('vcf2', help='Input .vcf file.') h2dparser.add_argument('ref_fasta', help='Reference .fasta file.') h2dparser.add_argument('vcfout', help='Output .vcf.') h2dparser.add_argument('--discard_phase', default=False, action='store_true', help='output unphased diploid vcf') h2dparser.add_argument('--adjacent', action='store_true', help=('Merge adjacent variants (i.e. variants with non-overlapping genomic ranges) instead' + ' of just overlapping ones. If set to True, all runs of adjacent variants will be' + ' merged including those which appear in just one of the input VCFs.')) h2dparser.add_argument('--split_mnp', action='store_true', help='Split each mnp into multiple snps.') # split a diploid VCF into two haploid VCFs. d2hparser = toolsubparsers.add_parser('diploid2haploid', help='Split a diploid VCF into two haploid VCFs.', parents=[_log_level()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) d2hparser.set_defaults(func=medaka.vcf.diploid2haploid) d2hparser.add_argument('vcf', help='Input .vcf file.') d2hparser.add_argument('--notrim', action='store_true', help='Do not trim variant to minimal ref and alt and update pos.') # classify variants in a vcf writing new vcfs containing subs, indels etc. clparser = toolsubparsers.add_parser('classify_variants', help='Classify variants and write vcf for each type and subtype.', parents=[_log_level()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) clparser.set_defaults(func=medaka.vcf.classify_variants) clparser.add_argument('vcf', help='Input .vcf file.') clparser.add_argument('--replace_info', action='store_true', help='Replace info tag (useful for visual inspection of types).') # annotate vcf with read depth and supporting reads info annparser = toolsubparsers.add_parser('annotate', help='Annotate vcf with read depth and supporting reads info fields.', parents=[_log_level(), _rg_arg()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) annparser.set_defaults(func=medaka.vcf.annotate_vcf_n_reads) annparser.add_argument('vcf', help='Input .vcf file.') annparser.add_argument('ref_fasta', help='Reference .fasta file.') annparser.add_argument('bam', help='Input alignments.', action=CheckBam) annparser.add_argument('vcfout', help='Output .vcf.') annparser.add_argument('--chunk_size', default=500000, type=int, help='Chunk size for building pileups.') annparser.add_argument('--pad', default=25, type=int, help='Padding width either side of variant for realignment.') annparser.add_argument('--dpsp', default=False, action='store_true', help='Calulate depth and alignment score of spanning reads') # call variants by alignment of a consensus sequence to a reference c2vparser = toolsubparsers.add_parser('consensus2vcf', help='Call variants by alignment of a consensus sequence to a reference.', parents=[_log_level(), _align_chunking(), _region_ref_names()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) c2vparser.set_defaults(func=medaka.variant.vcf_from_fasta) c2vparser.add_argument('consensus', help='Input consensus .fasta file.') c2vparser.add_argument('ref_fasta', help='Reference .fasta file.') c2vparser.add_argument('--bam', help='Existing bam file.') c2vparser.add_argument('--out_prefix', default='consensus2vcf', help='Output prefix for .bam and .vcf files.') # convert a vcf to tsv tsvparser = toolsubparsers.add_parser('vcf2tsv', help='convert vcf to tsv, unpacking info and sample columns.', parents=[_log_level()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) tsvparser.set_defaults(func=medaka.vcf.vcf2tsv) tsvparser.add_argument('vcf', help='Input .vcf file.') # find homozygous and heterozygous regions in a VCF hzregparser = toolsubparsers.add_parser('homozygous_regions', help='Find homozygous regions from a diploid vcf.', parents=[_log_level()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) hzregparser.set_defaults(func=medaka.vcf.get_homozygous_regions) hzregparser.add_argument('vcf', help='Input .vcf file.') hzregparser.add_argument('region', help='Genomic region within which to find homozygous sub-regions.') hzregparser.add_argument('--min_len', type=int, default=1000, help='Minimum region length.') hzregparser.add_argument('--suffix', help='Output suffix.', default='regions.txt') # resolve model and print full model file path to screen rmparser = toolsubparsers.add_parser('resolve_model', help='Resolve model and print full file path.', parents=[_log_level(), _model_arg()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) rmparser.set_defaults(func=print_model_path) # check if feature encoder is RLE rleparser = toolsubparsers.add_parser('is_rle_model', help='Check if a model is an RLE model.', parents=[_model_arg()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) rleparser.set_defaults(func=is_rle_model) # Request alignments parameters for model alignmentparser = toolsubparsers.add_parser('get_alignment_params', help='Get alignment parameters appropriate for a model', parents=[_model_arg()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) alignmentparser.set_defaults(func=print_alignment_params) # append RLE tags to a bam from hdf rlebamparser = toolsubparsers.add_parser('rlebam', description='Add RLE tags from HDF to bam. (input bam from stdin)', formatter_class=argparse.ArgumentDefaultsHelpFormatter) rlebamparser.add_argument('read_index', help='Two column .tsv mapping read_ids to .hdf filepaths.') rlebamparser.add_argument('--workers', type=int, default=4, help='Number of worker processes.') rlebamparser.set_defaults(func=medaka.rle.rlebam) # print all model tags followed by default lmparser = toolsubparsers.add_parser('list_models', help='List all models.', parents=[_log_level(), _model_arg()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) lmparser.set_defaults(func=print_all_models) # write a bed file of regions spanned by a hdf feature / probs file. bdparser = toolsubparsers.add_parser('hdf_to_bed', help='Write a bed file of regions spanned by a hdf file.', parents=[_log_level()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) bdparser.set_defaults(func=medaka.variant.samples_to_bed) bdparser.add_argument('inputs', nargs='+', help='Consensus .hdf files.') bdparser.add_argument('output', help='Output .bed.', default='medaka.bed') # resolve all available models, downloading missing ones. dwnldparser = toolsubparsers.add_parser('download_models', help='Download model files for any models not already installed.', parents=[_log_level()], formatter_class=argparse.ArgumentDefaultsHelpFormatter) dwnldparser.add_argument( '--models', nargs='+', default=medaka.options.allowed_models, help='Model(s) to download to cache.') dwnldparser.set_defaults(func=download_models) return parser
[ "def", "medaka_parser", "(", ")", ":", "from", "medaka", "import", "__version__", "parser", "=", "argparse", ".", "ArgumentParser", "(", "'medaka'", ",", "formatter_class", "=", "argparse", ".", "ArgumentDefaultsHelpFormatter", ")", "subparsers", "=", "parser", "....
https://github.com/nanoporetech/medaka/blob/2b83074fe3b6a6ec971614bfc6804f543fe1e5f0/medaka/medaka.py#L341-L678
DataDog/integrations-core
934674b29d94b70ccc008f76ea172d0cdae05e1e
ibm_mq/datadog_checks/ibm_mq/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/ibm_mq/datadog_checks/ibm_mq/config_models/__init__.py#L19-L20
bobbui/json-logging-python
efbe367527203a88e0fec9f81ccb2f1e9252b1bf
json_logging/framework/sanic/__init__.py
python
SanicRequestInfoExtractor.support_global_request_object
()
return False
[]
def support_global_request_object(): return False
[ "def", "support_global_request_object", "(", ")", ":", "return", "False" ]
https://github.com/bobbui/json-logging-python/blob/efbe367527203a88e0fec9f81ccb2f1e9252b1bf/json_logging/framework/sanic/__init__.py#L88-L89
cobbler/cobbler
eed8cdca3e970c8aa1d199e80b8c8f19b3f940cc
cobbler/remote.py
python
CobblerXMLRPCInterface.get_items
(self, what: str)
return self.xmlrpc_hacks(items)
Individual list elements are the same for get_item. :param what: is the name of a Cobbler object type, as described for get_item. :return: This returns a list of dicts.
Individual list elements are the same for get_item.
[ "Individual", "list", "elements", "are", "the", "same", "for", "get_item", "." ]
def get_items(self, what: str): """ Individual list elements are the same for get_item. :param what: is the name of a Cobbler object type, as described for get_item. :return: This returns a list of dicts. """ items = [x.to_dict() for x in self.api.get_items(what)] return self.xmlrpc_hacks(items)
[ "def", "get_items", "(", "self", ",", "what", ":", "str", ")", ":", "items", "=", "[", "x", ".", "to_dict", "(", ")", "for", "x", "in", "self", ".", "api", ".", "get_items", "(", "what", ")", "]", "return", "self", ".", "xmlrpc_hacks", "(", "item...
https://github.com/cobbler/cobbler/blob/eed8cdca3e970c8aa1d199e80b8c8f19b3f940cc/cobbler/remote.py#L835-L843
vivisect/vivisect
37b0b655d8dedfcf322e86b0f144b096e48d547e
envi/__init__.py
python
Opcode.getTargets
(self, emu=None)
return remote_branches
Determines the targets of call/branch instructions. Fall throughs are not considered as targets. Deref branches are resolved. Returns ((bva, bflags),...) addr can be None in cases where the branch target cannot be computed. (for example, if BR_DEREF flag is set and cannot read the memory) Once resolved, the BR_DEREF flag is removed from branch flags.
Determines the targets of call/branch instructions. Fall throughs are not considered as targets. Deref branches are resolved.
[ "Determines", "the", "targets", "of", "call", "/", "branch", "instructions", ".", "Fall", "throughs", "are", "not", "considered", "as", "targets", ".", "Deref", "branches", "are", "resolved", "." ]
def getTargets(self, emu=None): """ Determines the targets of call/branch instructions. Fall throughs are not considered as targets. Deref branches are resolved. Returns ((bva, bflags),...) addr can be None in cases where the branch target cannot be computed. (for example, if BR_DEREF flag is set and cannot read the memory) Once resolved, the BR_DEREF flag is removed from branch flags. """ remote_branches = [] for bva, bflags in self.getBranches(emu=emu): if bflags & BR_FALL: continue if bva and (bflags & BR_DEREF): if emu is not None: bva = emu.readMemoryFormat(bva, '<P')[0] bflags &= (~BR_DEREF) else: bva = None remote_branches.append((bva, bflags)) return remote_branches
[ "def", "getTargets", "(", "self", ",", "emu", "=", "None", ")", ":", "remote_branches", "=", "[", "]", "for", "bva", ",", "bflags", "in", "self", ".", "getBranches", "(", "emu", "=", "emu", ")", ":", "if", "bflags", "&", "BR_FALL", ":", "continue", ...
https://github.com/vivisect/vivisect/blob/37b0b655d8dedfcf322e86b0f144b096e48d547e/envi/__init__.py#L433-L458
python-diamond/Diamond
7000e16cfdf4508ed9291fc4b3800592557b2431
src/diamond/handler/hostedgraphite.py
python
HostedGraphiteHandler.flush
(self)
[]
def flush(self): self.graphite.flush()
[ "def", "flush", "(", "self", ")", ":", "self", ".", "graphite", ".", "flush", "(", ")" ]
https://github.com/python-diamond/Diamond/blob/7000e16cfdf4508ed9291fc4b3800592557b2431/src/diamond/handler/hostedgraphite.py#L91-L92
CellProfiler/CellProfiler
a90e17e4d258c6f3900238be0f828e0b4bd1b293
cellprofiler/modules/measurecolocalization.py
python
MeasureColocalization.get_image_pairs
(self)
Yield all permutations of pairs of images to correlate Yields the pairs of images in a canonical order.
Yield all permutations of pairs of images to correlate
[ "Yield", "all", "permutations", "of", "pairs", "of", "images", "to", "correlate" ]
def get_image_pairs(self): """Yield all permutations of pairs of images to correlate Yields the pairs of images in a canonical order. """ for i in range(len(self.images_list.value) - 1): for j in range(i + 1, len(self.images_list.value)): yield ( self.images_list.value[i], self.images_list.value[j], )
[ "def", "get_image_pairs", "(", "self", ")", ":", "for", "i", "in", "range", "(", "len", "(", "self", ".", "images_list", ".", "value", ")", "-", "1", ")", ":", "for", "j", "in", "range", "(", "i", "+", "1", ",", "len", "(", "self", ".", "images...
https://github.com/CellProfiler/CellProfiler/blob/a90e17e4d258c6f3900238be0f828e0b4bd1b293/cellprofiler/modules/measurecolocalization.py#L323-L333
tensorwerk/hangar-py
a6deb22854a6c9e9709011b91c1c0eeda7f47bb0
src/hangar/backends/numpy_10.py
python
NUMPY_10_FileHandles.read_data
(self, hashVal: NUMPY_10_DataHashSpec)
return out
Read data from disk written in the numpy_00 fmtBackend Parameters ---------- hashVal : NUMPY_10_DataHashSpec record specification stored in the db Returns ------- np.ndarray tensor data stored at the provided hashVal specification. Raises ------ RuntimeError If the recorded checksum does not match the received checksum. Notes ----- TO AVOID DATA LOSS / CORRUPTION: * On a read operation, we copy memmap subarray tensor data to a new `np.ndarray` instance so as to prevent writes on a raw memmap result slice (a `np.memmap` instance) from propogating to data on disk. * This is an issue for reads from a write-enabled checkout where data was just written, since the np flag "WRITEABLE" and "OWNDATA" will be true, and writes to the returned array would be overwrite that data slice on disk. * For read-only checkouts, modifications to the resultant array would perform a "copy on write"-like operation which would be propogated to all future reads of the subarray from that process, but which would not be persisted to disk.
Read data from disk written in the numpy_00 fmtBackend
[ "Read", "data", "from", "disk", "written", "in", "the", "numpy_00", "fmtBackend" ]
def read_data(self, hashVal: NUMPY_10_DataHashSpec) -> np.ndarray: """Read data from disk written in the numpy_00 fmtBackend Parameters ---------- hashVal : NUMPY_10_DataHashSpec record specification stored in the db Returns ------- np.ndarray tensor data stored at the provided hashVal specification. Raises ------ RuntimeError If the recorded checksum does not match the received checksum. Notes ----- TO AVOID DATA LOSS / CORRUPTION: * On a read operation, we copy memmap subarray tensor data to a new `np.ndarray` instance so as to prevent writes on a raw memmap result slice (a `np.memmap` instance) from propogating to data on disk. * This is an issue for reads from a write-enabled checkout where data was just written, since the np flag "WRITEABLE" and "OWNDATA" will be true, and writes to the returned array would be overwrite that data slice on disk. * For read-only checkouts, modifications to the resultant array would perform a "copy on write"-like operation which would be propogated to all future reads of the subarray from that process, but which would not be persisted to disk. """ srcSlc = (hashVal.collection_idx, *[slice(0, x) for x in hashVal.shape]) try: res = self.Fp[hashVal.uid][srcSlc] except TypeError: self.Fp[hashVal.uid] = self.Fp[hashVal.uid]() res = self.Fp[hashVal.uid][srcSlc] except KeyError: process_dir = self.STAGEDIR if self.mode == 'a' else self.STOREDIR if Path(process_dir, f'{hashVal.uid}.npy').is_file(): file_pth = self.DATADIR.joinpath(f'{hashVal.uid}.npy') self.rFp[hashVal.uid] = open_memmap(file_pth, 'r') res = self.Fp[hashVal.uid][srcSlc] else: raise out = np.array(res, dtype=res.dtype, order='C') if xxh64_hexdigest(out) != hashVal.checksum: raise RuntimeError( f'DATA CORRUPTION Checksum {xxh64_hexdigest(out)} != recorded {hashVal}') return out
[ "def", "read_data", "(", "self", ",", "hashVal", ":", "NUMPY_10_DataHashSpec", ")", "->", "np", ".", "ndarray", ":", "srcSlc", "=", "(", "hashVal", ".", "collection_idx", ",", "*", "[", "slice", "(", "0", ",", "x", ")", "for", "x", "in", "hashVal", "...
https://github.com/tensorwerk/hangar-py/blob/a6deb22854a6c9e9709011b91c1c0eeda7f47bb0/src/hangar/backends/numpy_10.py#L336-L392
sethmlarson/virtualbox-python
984a6e2cb0e8996f4df40f4444c1528849f1c70d
virtualbox/library.py
python
IGuestScreenInfo.primary
(self)
return ret
Get bool value for 'primary
Get bool value for 'primary
[ "Get", "bool", "value", "for", "primary" ]
def primary(self): """Get bool value for 'primary'""" ret = self._get_attr("primary") return ret
[ "def", "primary", "(", "self", ")", ":", "ret", "=", "self", ".", "_get_attr", "(", "\"primary\"", ")", "return", "ret" ]
https://github.com/sethmlarson/virtualbox-python/blob/984a6e2cb0e8996f4df40f4444c1528849f1c70d/virtualbox/library.py#L28596-L28599
metabrainz/picard
535bf8c7d9363ffc7abb3f69418ec11823c38118
picard/tagger.py
python
main
(localedir=None, autoupdate=True)
[]
def main(localedir=None, autoupdate=True): # Some libs (ie. Phonon) require those to be set QtWidgets.QApplication.setApplicationName(PICARD_APP_NAME) QtWidgets.QApplication.setOrganizationName(PICARD_ORG_NAME) QtWidgets.QApplication.setDesktopFileName(PICARD_DESKTOP_NAME) # Allow High DPI Support QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps) QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling) # HighDpiScaleFactorRoundingPolicy is available since Qt 5.14. This is # required to support fractional scaling on Windows properly. # It causes issues without scaling on Linux, see https://tickets.metabrainz.org/browse/PICARD-1948 if IS_WIN and hasattr(QtGui.QGuiApplication, 'setHighDpiScaleFactorRoundingPolicy'): QtGui.QGuiApplication.setHighDpiScaleFactorRoundingPolicy( QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) # Enable mnemonics on all platforms, even macOS QtGui.qt_set_sequence_auto_mnemonic(True) signal.signal(signal.SIGINT, signal.SIG_DFL) picard_args, unparsed_args = process_picard_args() if picard_args.version: return version() if picard_args.long_version: return longversion() try: from PyQt5.QtDBus import QDBusConnection dbus = QDBusConnection.sessionBus() dbus.registerService(PICARD_APP_ID) except ImportError: pass tagger = Tagger(picard_args, unparsed_args, localedir, autoupdate) # Initialize Qt default translations translator = QtCore.QTranslator() locale = QtCore.QLocale() translation_path = QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath) log.debug("Looking for Qt locale %s in %s", locale.name(), translation_path) if translator.load(locale, "qtbase_", directory=translation_path): tagger.installTranslator(translator) else: log.debug('Qt locale %s not available', locale.name()) tagger.startTimer(1000) sys.exit(tagger.run())
[ "def", "main", "(", "localedir", "=", "None", ",", "autoupdate", "=", "True", ")", ":", "# Some libs (ie. Phonon) require those to be set", "QtWidgets", ".", "QApplication", ".", "setApplicationName", "(", "PICARD_APP_NAME", ")", "QtWidgets", ".", "QApplication", ".",...
https://github.com/metabrainz/picard/blob/535bf8c7d9363ffc7abb3f69418ec11823c38118/picard/tagger.py#L1040-L1087
mrDoctorWho/vk4xmpp
e8f25a16832adb6b93fe8b50afdc9547e429389b
gateway.py
python
VK.getGroupData
(self, gid, fields=None)
Gets group data (only name so far) Args: gid: the group id fields: a list of advanced fields to receive Returns: The group information
Gets group data (only name so far) Args: gid: the group id fields: a list of advanced fields to receive Returns: The group information
[ "Gets", "group", "data", "(", "only", "name", "so", "far", ")", "Args", ":", "gid", ":", "the", "group", "id", "fields", ":", "a", "list", "of", "advanced", "fields", "to", "receive", "Returns", ":", "The", "group", "information" ]
def getGroupData(self, gid, fields=None): """ Gets group data (only name so far) Args: gid: the group id fields: a list of advanced fields to receive Returns: The group information """ fields = fields or ["name"] data = self.method("groups.getById", {"group_id": abs(gid), "fields": str.join(",", fields)}) if data: data = data[0] return data raise RuntimeError("Unable to get group data for %d" % gid)
[ "def", "getGroupData", "(", "self", ",", "gid", ",", "fields", "=", "None", ")", ":", "fields", "=", "fields", "or", "[", "\"name\"", "]", "data", "=", "self", ".", "method", "(", "\"groups.getById\"", ",", "{", "\"group_id\"", ":", "abs", "(", "gid", ...
https://github.com/mrDoctorWho/vk4xmpp/blob/e8f25a16832adb6b93fe8b50afdc9547e429389b/gateway.py#L581-L595
bitprophet/ssh
e8bdad4c82a50158a749233dca58c29e47c60b76
ssh/channel.py
python
Channel.get_name
(self)
return self._name
Get the name of this channel that was previously set by L{set_name}. @return: the name of this channel. @rtype: str
Get the name of this channel that was previously set by L{set_name}.
[ "Get", "the", "name", "of", "this", "channel", "that", "was", "previously", "set", "by", "L", "{", "set_name", "}", "." ]
def get_name(self): """ Get the name of this channel that was previously set by L{set_name}. @return: the name of this channel. @rtype: str """ return self._name
[ "def", "get_name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
https://github.com/bitprophet/ssh/blob/e8bdad4c82a50158a749233dca58c29e47c60b76/ssh/channel.py#L429-L436
IntelPython/sdc
1ebf55c00ef38dfbd401a70b3945e352a5a38b87
sdc/extensions/indexes/int64_index_ext.py
python
pd_int64_index_contains_overload
(self, val)
return pd_int64_index_contains_impl
[]
def pd_int64_index_contains_overload(self, val): if not isinstance(self, Int64IndexType): return None _func_name = 'Operator contains().' ty_checker = TypeChecker(_func_name) if not (isinstance(val, types.Integer)): ty_checker.raise_exc(val, 'integer scalar', 'val') def pd_int64_index_contains_impl(self, val): # TO-DO: add operator.contains support for arrays in Numba found = 0 for i in prange(len(self._data)): if val == self._data[i]: found += 1 return found > 0 return pd_int64_index_contains_impl
[ "def", "pd_int64_index_contains_overload", "(", "self", ",", "val", ")", ":", "if", "not", "isinstance", "(", "self", ",", "Int64IndexType", ")", ":", "return", "None", "_func_name", "=", "'Operator contains().'", "ty_checker", "=", "TypeChecker", "(", "_func_name...
https://github.com/IntelPython/sdc/blob/1ebf55c00ef38dfbd401a70b3945e352a5a38b87/sdc/extensions/indexes/int64_index_ext.py#L253-L272
andresriancho/w3af
cd22e5252243a87aaa6d0ddea47cf58dacfe00a9
w3af/core/ui/gui/tools/encdec.py
python
utf8_barebyte_encoding
(t)
return t.encode("utf8")
UTF-8 Bare byte Encoding, just a normal UTF-8 encoding. >>> utf8_barebyte_encoding("A") 'A' >>> utf8_barebyte_encoding("Año") 'A\\xc3\\xb1o'
UTF-8 Bare byte Encoding, just a normal UTF-8 encoding.
[ "UTF", "-", "8", "Bare", "byte", "Encoding", "just", "a", "normal", "UTF", "-", "8", "encoding", "." ]
def utf8_barebyte_encoding(t): """UTF-8 Bare byte Encoding, just a normal UTF-8 encoding. >>> utf8_barebyte_encoding("A") 'A' >>> utf8_barebyte_encoding("Año") 'A\\xc3\\xb1o' """ return t.encode("utf8")
[ "def", "utf8_barebyte_encoding", "(", "t", ")", ":", "return", "t", ".", "encode", "(", "\"utf8\"", ")" ]
https://github.com/andresriancho/w3af/blob/cd22e5252243a87aaa6d0ddea47cf58dacfe00a9/w3af/core/ui/gui/tools/encdec.py#L488-L496
AppScale/gts
46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9
AppServer/lib/django-1.5/django/views/generic/edit.py
python
ModelFormMixin.get_form_kwargs
(self)
return kwargs
Returns the keyword arguments for instantiating the form.
Returns the keyword arguments for instantiating the form.
[ "Returns", "the", "keyword", "arguments", "for", "instantiating", "the", "form", "." ]
def get_form_kwargs(self): """ Returns the keyword arguments for instantiating the form. """ kwargs = super(ModelFormMixin, self).get_form_kwargs() kwargs.update({'instance': self.object}) return kwargs
[ "def", "get_form_kwargs", "(", "self", ")", ":", "kwargs", "=", "super", "(", "ModelFormMixin", ",", "self", ")", ".", "get_form_kwargs", "(", ")", "kwargs", ".", "update", "(", "{", "'instance'", ":", "self", ".", "object", "}", ")", "return", "kwargs" ...
https://github.com/AppScale/gts/blob/46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9/AppServer/lib/django-1.5/django/views/generic/edit.py#L100-L106
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/combinat/ncsf_qsym/combinatorics.py
python
coeff_lp
(J,I)
return prod(K[-1] for K in J.refinement_splitting(I))
r""" Returns the coefficient `lp_{J,I}` as defined in [NCSF]_. INPUT: - ``J`` -- a composition - ``I`` -- a composition refining ``J`` OUTPUT: - integer EXAMPLES:: sage: from sage.combinat.ncsf_qsym.combinatorics import coeff_lp sage: coeff_lp(Composition([1,1,1]), Composition([2,1])) 1 sage: coeff_lp(Composition([2,1]), Composition([3])) 1
r""" Returns the coefficient `lp_{J,I}` as defined in [NCSF]_.
[ "r", "Returns", "the", "coefficient", "lp_", "{", "J", "I", "}", "as", "defined", "in", "[", "NCSF", "]", "_", "." ]
def coeff_lp(J,I): r""" Returns the coefficient `lp_{J,I}` as defined in [NCSF]_. INPUT: - ``J`` -- a composition - ``I`` -- a composition refining ``J`` OUTPUT: - integer EXAMPLES:: sage: from sage.combinat.ncsf_qsym.combinatorics import coeff_lp sage: coeff_lp(Composition([1,1,1]), Composition([2,1])) 1 sage: coeff_lp(Composition([2,1]), Composition([3])) 1 """ return prod(K[-1] for K in J.refinement_splitting(I))
[ "def", "coeff_lp", "(", "J", ",", "I", ")", ":", "return", "prod", "(", "K", "[", "-", "1", "]", "for", "K", "in", "J", ".", "refinement_splitting", "(", "I", ")", ")" ]
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/combinat/ncsf_qsym/combinatorics.py#L55-L76
AstroPrint/AstroBox
e7e3b8a7d33ea85fcb6b2696869c0d719ceb8b75
src/octoprint/util/__init__.py
python
silentRemove
(file)
Silently removes a file. Does not raise an error if the file doesn't exist. @param file the path of the file to be removed
Silently removes a file. Does not raise an error if the file doesn't exist.
[ "Silently", "removes", "a", "file", ".", "Does", "not", "raise", "an", "error", "if", "the", "file", "doesn", "t", "exist", "." ]
def silentRemove(file): """ Silently removes a file. Does not raise an error if the file doesn't exist. @param file the path of the file to be removed """ try: os.remove(file) except OSError: pass
[ "def", "silentRemove", "(", "file", ")", ":", "try", ":", "os", ".", "remove", "(", "file", ")", "except", "OSError", ":", "pass" ]
https://github.com/AstroPrint/AstroBox/blob/e7e3b8a7d33ea85fcb6b2696869c0d719ceb8b75/src/octoprint/util/__init__.py#L186-L196
usnistgov/fipy
6809b180b41a11de988a48655575df7e142c93b9
versioneer.py
python
render_pep440_pre
(pieces)
return rendered
TAG[.post.devDISTANCE] -- No -dirty. Exceptions: 1: no tags. 0.post.devDISTANCE
TAG[.post.devDISTANCE] -- No -dirty.
[ "TAG", "[", ".", "post", ".", "devDISTANCE", "]", "--", "No", "-", "dirty", "." ]
def render_pep440_pre(pieces): """TAG[.post.devDISTANCE] -- No -dirty. Exceptions: 1: no tags. 0.post.devDISTANCE """ if pieces["closest-tag"]: rendered = pieces["closest-tag"] if pieces["distance"]: rendered += ".post.dev%d" % pieces["distance"] else: # exception #1 rendered = "0.post.dev%d" % pieces["distance"] return rendered
[ "def", "render_pep440_pre", "(", "pieces", ")", ":", "if", "pieces", "[", "\"closest-tag\"", "]", ":", "rendered", "=", "pieces", "[", "\"closest-tag\"", "]", "if", "pieces", "[", "\"distance\"", "]", ":", "rendered", "+=", "\".post.dev%d\"", "%", "pieces", ...
https://github.com/usnistgov/fipy/blob/6809b180b41a11de988a48655575df7e142c93b9/versioneer.py#L1261-L1274
donnemartin/gitsome
d7c57abc7cb66e9c910a844f15d4536866da3310
xonsh/ptk2/shell.py
python
PromptToolkit2Shell.continuation_tokens
(self, width, line_number, is_soft_wrap=False)
return PygmentsTokens(toks)
Displays dots in multiline prompt
Displays dots in multiline prompt
[ "Displays", "dots", "in", "multiline", "prompt" ]
def continuation_tokens(self, width, line_number, is_soft_wrap=False): """Displays dots in multiline prompt""" if is_soft_wrap: return "" width = width - 1 dots = builtins.__xonsh__.env.get("MULTILINE_PROMPT") dots = dots() if callable(dots) else dots if dots is None: return [(Token, " " * (width + 1))] basetoks = self.format_color(dots) baselen = sum(len(t[1]) for t in basetoks) if baselen == 0: return [(Token, " " * (width + 1))] toks = basetoks * (width // baselen) n = width % baselen count = 0 for tok in basetoks: slen = len(tok[1]) newcount = slen + count if slen == 0: continue elif newcount <= n: toks.append(tok) else: toks.append((tok[0], tok[1][: n - count])) count = newcount if n <= count: break toks.append((Token, " ")) # final space return PygmentsTokens(toks)
[ "def", "continuation_tokens", "(", "self", ",", "width", ",", "line_number", ",", "is_soft_wrap", "=", "False", ")", ":", "if", "is_soft_wrap", ":", "return", "\"\"", "width", "=", "width", "-", "1", "dots", "=", "builtins", ".", "__xonsh__", ".", "env", ...
https://github.com/donnemartin/gitsome/blob/d7c57abc7cb66e9c910a844f15d4536866da3310/xonsh/ptk2/shell.py#L244-L273
gammapy/gammapy
735b25cd5bbed35e2004d633621896dcd5295e8b
gammapy/modeling/models/temporal.py
python
LightCurveTemplateTemporalModel.read
(cls, path)
return cls(Table.read(filename), filename=filename)
Read lightcurve model table from FITS file. TODO: This doesn't read the XML part of the model yet.
Read lightcurve model table from FITS file.
[ "Read", "lightcurve", "model", "table", "from", "FITS", "file", "." ]
def read(cls, path): """Read lightcurve model table from FITS file. TODO: This doesn't read the XML part of the model yet. """ filename = str(make_path(path)) return cls(Table.read(filename), filename=filename)
[ "def", "read", "(", "cls", ",", "path", ")", ":", "filename", "=", "str", "(", "make_path", "(", "path", ")", ")", "return", "cls", "(", "Table", ".", "read", "(", "filename", ")", ",", "filename", "=", "filename", ")" ]
https://github.com/gammapy/gammapy/blob/735b25cd5bbed35e2004d633621896dcd5295e8b/gammapy/modeling/models/temporal.py#L408-L414
BillBillBillBill/Tickeys-linux
2df31b8665004c58a5d4ab05277f245267d96364
tickeys/kivy_32/kivy/storage/__init__.py
python
AbstractStore.async_clear
(self, callback)
Asynchronous version of :meth:`clear`.
Asynchronous version of :meth:`clear`.
[ "Asynchronous", "version", "of", ":", "meth", ":", "clear", "." ]
def async_clear(self, callback): '''Asynchronous version of :meth:`clear`. ''' self._schedule(self.store_clear_async, callback=callback)
[ "def", "async_clear", "(", "self", ",", "callback", ")", ":", "self", ".", "_schedule", "(", "self", ".", "store_clear_async", ",", "callback", "=", "callback", ")" ]
https://github.com/BillBillBillBill/Tickeys-linux/blob/2df31b8665004c58a5d4ab05277f245267d96364/tickeys/kivy_32/kivy/storage/__init__.py#L281-L284
GoogleCloudPlatform/PerfKitBenchmarker
6e3412d7d5e414b8ca30ed5eaf970cef1d919a67
perfkitbenchmarker/linux_benchmarks/speccpu2006_benchmark.py
python
Prepare
(benchmark_spec)
Installs SPEC CPU2006 on the target vm. Args: benchmark_spec: The benchmark specification. Contains all data that is required to run the benchmark.
Installs SPEC CPU2006 on the target vm.
[ "Installs", "SPEC", "CPU2006", "on", "the", "target", "vm", "." ]
def Prepare(benchmark_spec): """Installs SPEC CPU2006 on the target vm. Args: benchmark_spec: The benchmark specification. Contains all data that is required to run the benchmark. """ vm = benchmark_spec.vms[0] vm.Install('speccpu2006') # Set attribute outside of the install function, so benchmark will work # even with --install_packages=False. config = speccpu2006.GetSpecInstallConfig(vm.GetScratchDir()) setattr(vm, speccpu.VM_STATE_ATTR, config)
[ "def", "Prepare", "(", "benchmark_spec", ")", ":", "vm", "=", "benchmark_spec", ".", "vms", "[", "0", "]", "vm", ".", "Install", "(", "'speccpu2006'", ")", "# Set attribute outside of the install function, so benchmark will work", "# even with --install_packages=False.", ...
https://github.com/GoogleCloudPlatform/PerfKitBenchmarker/blob/6e3412d7d5e414b8ca30ed5eaf970cef1d919a67/perfkitbenchmarker/linux_benchmarks/speccpu2006_benchmark.py#L66-L78
jbjorne/TEES
caf19a4a1352ac59f5dc13a8684cc42ce4342d9d
Utils/ElementTreeUtils.py
python
setDefaultElement
(parent, name)
return element
[]
def setDefaultElement(parent, name): element = parent.find(name) if element == None: element = ElementTree.Element(name) parent.append(element) return element
[ "def", "setDefaultElement", "(", "parent", ",", "name", ")", ":", "element", "=", "parent", ".", "find", "(", "name", ")", "if", "element", "==", "None", ":", "element", "=", "ElementTree", ".", "Element", "(", "name", ")", "parent", ".", "append", "("...
https://github.com/jbjorne/TEES/blob/caf19a4a1352ac59f5dc13a8684cc42ce4342d9d/Utils/ElementTreeUtils.py#L360-L365
edfungus/Crouton
ada98b3930192938a48909072b45cb84b945f875
clients/esp8266_clients/venv/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/packages/ordered_dict.py
python
OrderedDict.popitem
(self, last=True)
return key, value
od.popitem() -> (k, v), return and remove a (key, value) pair. Pairs are returned in LIFO order if last is true or FIFO order if false.
od.popitem() -> (k, v), return and remove a (key, value) pair. Pairs are returned in LIFO order if last is true or FIFO order if false.
[ "od", ".", "popitem", "()", "-", ">", "(", "k", "v", ")", "return", "and", "remove", "a", "(", "key", "value", ")", "pair", ".", "Pairs", "are", "returned", "in", "LIFO", "order", "if", "last", "is", "true", "or", "FIFO", "order", "if", "false", ...
def popitem(self, last=True): '''od.popitem() -> (k, v), return and remove a (key, value) pair. Pairs are returned in LIFO order if last is true or FIFO order if false. ''' if not self: raise KeyError('dictionary is empty') root = self.__root if last: link = root[0] link_prev = link[0] link_prev[1] = root root[0] = link_prev else: link = root[1] link_next = link[1] root[1] = link_next link_next[0] = root key = link[2] del self.__map[key] value = dict.pop(self, key) return key, value
[ "def", "popitem", "(", "self", ",", "last", "=", "True", ")", ":", "if", "not", "self", ":", "raise", "KeyError", "(", "'dictionary is empty'", ")", "root", "=", "self", ".", "__root", "if", "last", ":", "link", "=", "root", "[", "0", "]", "link_prev...
https://github.com/edfungus/Crouton/blob/ada98b3930192938a48909072b45cb84b945f875/clients/esp8266_clients/venv/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/packages/ordered_dict.py#L91-L112
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/graphs/generators/classical_geometries.py
python
SymplecticDualPolarGraph
(m, q)
return G
r""" Return the Symplectic Dual Polar Graph `DSp(m,q)`. For more information on Symplectic Dual Polar graphs, see [BCN1989]_ and Sect. 2.3.1 of [Coh1981]_. INPUT: - ``m,q`` -- integers; `q` must be a prime power, and `m` must be even EXAMPLES:: sage: G = graphs.SymplecticDualPolarGraph(6,3); G # not tested (long time) Symplectic Dual Polar Graph DSp(6, 3): Graph on 1120 vertices sage: G.is_distance_regular(parameters=True) # not tested (long time) ([39, 36, 27, None], [None, 1, 4, 13]) TESTS:: sage: G = graphs.SymplecticDualPolarGraph(6,2); G Symplectic Dual Polar Graph DSp(6, 2): Graph on 135 vertices sage: G.is_distance_regular(parameters=True) ([14, 12, 8, None], [None, 1, 3, 7]) sage: graphs.SymplecticDualPolarGraph(6,6) Traceback (most recent call last): ... GAPError: Error, <subfield> must be a prime or a finite field
r""" Return the Symplectic Dual Polar Graph `DSp(m,q)`.
[ "r", "Return", "the", "Symplectic", "Dual", "Polar", "Graph", "DSp", "(", "m", "q", ")", "." ]
def SymplecticDualPolarGraph(m, q): r""" Return the Symplectic Dual Polar Graph `DSp(m,q)`. For more information on Symplectic Dual Polar graphs, see [BCN1989]_ and Sect. 2.3.1 of [Coh1981]_. INPUT: - ``m,q`` -- integers; `q` must be a prime power, and `m` must be even EXAMPLES:: sage: G = graphs.SymplecticDualPolarGraph(6,3); G # not tested (long time) Symplectic Dual Polar Graph DSp(6, 3): Graph on 1120 vertices sage: G.is_distance_regular(parameters=True) # not tested (long time) ([39, 36, 27, None], [None, 1, 4, 13]) TESTS:: sage: G = graphs.SymplecticDualPolarGraph(6,2); G Symplectic Dual Polar Graph DSp(6, 2): Graph on 135 vertices sage: G.is_distance_regular(parameters=True) ([14, 12, 8, None], [None, 1, 3, 7]) sage: graphs.SymplecticDualPolarGraph(6,6) Traceback (most recent call last): ... GAPError: Error, <subfield> must be a prime or a finite field """ from sage.libs.gap.libgap import libgap G = _polar_graph(m, q, libgap.SymplecticGroup(m, q), intersection_size=int((q**(m/2-1)-1)/(q-1))) G.relabel() G.name("Symplectic Dual Polar Graph DSp" + str((m, q))) if m == 4: G.name(G.name()+'; GQ'+str((q,q))) return G
[ "def", "SymplecticDualPolarGraph", "(", "m", ",", "q", ")", ":", "from", "sage", ".", "libs", ".", "gap", ".", "libgap", "import", "libgap", "G", "=", "_polar_graph", "(", "m", ",", "q", ",", "libgap", ".", "SymplecticGroup", "(", "m", ",", "q", ")",...
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/graphs/generators/classical_geometries.py#L773-L810
Vector35/binaryninja-api
d9661f34eec6855d495a10eaafc2a8e2679756a7
python/flowgraph.py
python
FlowGraphLayoutRequest.graph
(self)
return CoreFlowGraph(core.BNGetGraphForFlowGraphLayoutRequest(self.handle))
Flow graph that is being processed (read-only)
Flow graph that is being processed (read-only)
[ "Flow", "graph", "that", "is", "being", "processed", "(", "read", "-", "only", ")" ]
def graph(self): """Flow graph that is being processed (read-only)""" return CoreFlowGraph(core.BNGetGraphForFlowGraphLayoutRequest(self.handle))
[ "def", "graph", "(", "self", ")", ":", "return", "CoreFlowGraph", "(", "core", ".", "BNGetGraphForFlowGraphLayoutRequest", "(", "self", ".", "handle", ")", ")" ]
https://github.com/Vector35/binaryninja-api/blob/d9661f34eec6855d495a10eaafc2a8e2679756a7/python/flowgraph.py#L363-L365
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/functions/exp_integral.py
python
Function_cos_integral._evalf_
(self, z, parent=None, algorithm=None)
return mpmath_utils_call(mpmath.ci, z, parent=parent)
EXAMPLES:: sage: N(cos_integral(1e23)) < 1e-20 True sage: N(cos_integral(10^-10), digits=30) -22.4486352650389239795759024568 sage: cos_integral(ComplexField(100)(I)) 0.83786694098020824089467857943 + 1.5707963267948966192313216916*I
EXAMPLES::
[ "EXAMPLES", "::" ]
def _evalf_(self, z, parent=None, algorithm=None): """ EXAMPLES:: sage: N(cos_integral(1e23)) < 1e-20 True sage: N(cos_integral(10^-10), digits=30) -22.4486352650389239795759024568 sage: cos_integral(ComplexField(100)(I)) 0.83786694098020824089467857943 + 1.5707963267948966192313216916*I """ import mpmath return mpmath_utils_call(mpmath.ci, z, parent=parent)
[ "def", "_evalf_", "(", "self", ",", "z", ",", "parent", "=", "None", ",", "algorithm", "=", "None", ")", ":", "import", "mpmath", "return", "mpmath_utils_call", "(", "mpmath", ".", "ci", ",", "z", ",", "parent", "=", "parent", ")" ]
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/functions/exp_integral.py#L997-L1010
weewx/weewx
cb594fce224560bd8696050fc5c7843c7839320e
bin/weewx/restx.py
python
StdRESTful.shutDown_thread
(q, t)
Function to shut down a thread.
Function to shut down a thread.
[ "Function", "to", "shut", "down", "a", "thread", "." ]
def shutDown_thread(q, t): """Function to shut down a thread.""" if q and t.is_alive(): # Put a None in the queue to signal the thread to shutdown q.put(None) # Wait up to 20 seconds for the thread to exit: t.join(20.0) if t.is_alive(): log.error("Unable to shut down %s thread", t.name) else: log.debug("Shut down %s thread.", t.name)
[ "def", "shutDown_thread", "(", "q", ",", "t", ")", ":", "if", "q", "and", "t", ".", "is_alive", "(", ")", ":", "# Put a None in the queue to signal the thread to shutdown", "q", ".", "put", "(", "None", ")", "# Wait up to 20 seconds for the thread to exit:", "t", ...
https://github.com/weewx/weewx/blob/cb594fce224560bd8696050fc5c7843c7839320e/bin/weewx/restx.py#L149-L159
Esri/ArcREST
ab240fde2b0200f61d4a5f6df033516e53f2f416
src/arcrest/manageorg/_content.py
python
Group.id
(self)
return self._groupId
gets the group id
gets the group id
[ "gets", "the", "group", "id" ]
def id(self): """gets the group id""" return self._groupId
[ "def", "id", "(", "self", ")", ":", "return", "self", ".", "_groupId" ]
https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcrest/manageorg/_content.py#L3108-L3110
HymanLiuTS/flaskTs
286648286976e85d9b9a5873632331efcafe0b21
flasky/lib/python2.7/site-packages/wheel/bdist_wheel.py
python
bdist_wheel.add_requirements
(self, metadata_path)
Add additional requirements from setup.cfg to file metadata_path
Add additional requirements from setup.cfg to file metadata_path
[ "Add", "additional", "requirements", "from", "setup", ".", "cfg", "to", "file", "metadata_path" ]
def add_requirements(self, metadata_path): """Add additional requirements from setup.cfg to file metadata_path""" additional = list(self.setupcfg_requirements()) if not additional: return pkg_info = read_pkg_info(metadata_path) if 'Provides-Extra' in pkg_info or 'Requires-Dist' in pkg_info: warnings.warn('setup.cfg requirements overwrite values from setup.py') del pkg_info['Provides-Extra'] del pkg_info['Requires-Dist'] for k, v in additional: pkg_info[k] = v write_pkg_info(metadata_path, pkg_info)
[ "def", "add_requirements", "(", "self", ",", "metadata_path", ")", ":", "additional", "=", "list", "(", "self", ".", "setupcfg_requirements", "(", ")", ")", "if", "not", "additional", ":", "return", "pkg_info", "=", "read_pkg_info", "(", "metadata_path", ")", ...
https://github.com/HymanLiuTS/flaskTs/blob/286648286976e85d9b9a5873632331efcafe0b21/flasky/lib/python2.7/site-packages/wheel/bdist_wheel.py#L347-L358
hirofumi0810/tensorflow_end2end_speech_recognition
65b9728089d5e92b25b92384a67419d970399a64
models/encoders/core/rnn_util.py
python
sequence_length
(inputs, time_major=True, dtype=tf.int32)
return seq_len
Inspect the length of the sequence of input data. Args: inputs: A tensor of size `[B, T, input_size]` time_major (bool, optional): set True if inputs is time-major dtype (optional): default is tf.int32 Returns: seq_len: A tensor of size `[B,]`
Inspect the length of the sequence of input data. Args: inputs: A tensor of size `[B, T, input_size]` time_major (bool, optional): set True if inputs is time-major dtype (optional): default is tf.int32 Returns: seq_len: A tensor of size `[B,]`
[ "Inspect", "the", "length", "of", "the", "sequence", "of", "input", "data", ".", "Args", ":", "inputs", ":", "A", "tensor", "of", "size", "[", "B", "T", "input_size", "]", "time_major", "(", "bool", "optional", ")", ":", "set", "True", "if", "inputs", ...
def sequence_length(inputs, time_major=True, dtype=tf.int32): """Inspect the length of the sequence of input data. Args: inputs: A tensor of size `[B, T, input_size]` time_major (bool, optional): set True if inputs is time-major dtype (optional): default is tf.int32 Returns: seq_len: A tensor of size `[B,]` """ time_axis = 0 if time_major else 1 with tf.variable_scope("seq_len"): used = tf.sign(tf.reduce_max(tf.abs(inputs), axis=2)) seq_len = tf.reduce_sum(used, axis=time_axis) seq_len = tf.cast(seq_len, dtype) return seq_len
[ "def", "sequence_length", "(", "inputs", ",", "time_major", "=", "True", ",", "dtype", "=", "tf", ".", "int32", ")", ":", "time_axis", "=", "0", "if", "time_major", "else", "1", "with", "tf", ".", "variable_scope", "(", "\"seq_len\"", ")", ":", "used", ...
https://github.com/hirofumi0810/tensorflow_end2end_speech_recognition/blob/65b9728089d5e92b25b92384a67419d970399a64/models/encoders/core/rnn_util.py#L13-L27
dimagi/commcare-hq
d67ff1d3b4c51fa050c19e60c3253a79d3452a39
corehq/apps/app_manager/suite_xml/features/mobile_ucr.py
python
_get_select_details
(config)
return models.Detail(custom_xml=Detail( id=_get_select_detail_id(config), title=Text( locale=Locale(id=id_strings.report_menu()), ), fields=[ Field( header=Header( text=Text( locale=Locale(id=id_strings.report_name_header()), ) ), template=Template( text=Text( locale=Locale(id=id_strings.report_name(config.uuid)) ) ), ) ] ).serialize().decode('utf-8'))
[]
def _get_select_details(config): return models.Detail(custom_xml=Detail( id=_get_select_detail_id(config), title=Text( locale=Locale(id=id_strings.report_menu()), ), fields=[ Field( header=Header( text=Text( locale=Locale(id=id_strings.report_name_header()), ) ), template=Template( text=Text( locale=Locale(id=id_strings.report_name(config.uuid)) ) ), ) ] ).serialize().decode('utf-8'))
[ "def", "_get_select_details", "(", "config", ")", ":", "return", "models", ".", "Detail", "(", "custom_xml", "=", "Detail", "(", "id", "=", "_get_select_detail_id", "(", "config", ")", ",", "title", "=", "Text", "(", "locale", "=", "Locale", "(", "id", "...
https://github.com/dimagi/commcare-hq/blob/d67ff1d3b4c51fa050c19e60c3253a79d3452a39/corehq/apps/app_manager/suite_xml/features/mobile_ucr.py#L160-L180
sunpy/sunpy
528579df0a4c938c133bd08971ba75c131b189a7
sunpy/net/scraper.py
python
Scraper._URL_followsPattern
(self, url)
return False
Check whether the url provided follows the pattern.
Check whether the url provided follows the pattern.
[ "Check", "whether", "the", "url", "provided", "follows", "the", "pattern", "." ]
def _URL_followsPattern(self, url): """ Check whether the url provided follows the pattern. """ pattern = self.pattern for k, v in TIME_CONVERSIONS.items(): pattern = pattern.replace(k, v) matches = re.match(pattern, url) if matches: return matches.end() == matches.endpos return False
[ "def", "_URL_followsPattern", "(", "self", ",", "url", ")", ":", "pattern", "=", "self", ".", "pattern", "for", "k", ",", "v", "in", "TIME_CONVERSIONS", ".", "items", "(", ")", ":", "pattern", "=", "pattern", ".", "replace", "(", "k", ",", "v", ")", ...
https://github.com/sunpy/sunpy/blob/528579df0a4c938c133bd08971ba75c131b189a7/sunpy/net/scraper.py#L169-L179
autotest/autotest
4614ae5f550cc888267b9a419e4b90deb54f8fae
client/shared/utils.py
python
get_children_pids
(ppid)
return (system_output("ps -L --ppid=%d -o lwp" % ppid).split('\n')[1:])
Get all PIDs of children/threads of parent ppid param ppid: parent PID return: list of PIDs of all children/threads of ppid
Get all PIDs of children/threads of parent ppid param ppid: parent PID return: list of PIDs of all children/threads of ppid
[ "Get", "all", "PIDs", "of", "children", "/", "threads", "of", "parent", "ppid", "param", "ppid", ":", "parent", "PID", "return", ":", "list", "of", "PIDs", "of", "all", "children", "/", "threads", "of", "ppid" ]
def get_children_pids(ppid): """ Get all PIDs of children/threads of parent ppid param ppid: parent PID return: list of PIDs of all children/threads of ppid """ return (system_output("ps -L --ppid=%d -o lwp" % ppid).split('\n')[1:])
[ "def", "get_children_pids", "(", "ppid", ")", ":", "return", "(", "system_output", "(", "\"ps -L --ppid=%d -o lwp\"", "%", "ppid", ")", ".", "split", "(", "'\\n'", ")", "[", "1", ":", "]", ")" ]
https://github.com/autotest/autotest/blob/4614ae5f550cc888267b9a419e4b90deb54f8fae/client/shared/utils.py#L1144-L1150
NVIDIA/DeepLearningExamples
589604d49e016cd9ef4525f7abcc9c7b826cfc5e
PyTorch/LanguageModeling/BART/bart/modeling/modeling_bart.py
python
BartEncoder.forward
( self, input_ids=None, attention_mask=None, head_mask=None, inputs_embeds=None, output_attentions=None, output_hidden_states=None, return_dict=None, )
return BaseModelOutput( last_hidden_state=hidden_states, hidden_states=encoder_states, attentions=all_attentions )
r""" Args: input_ids (:obj:`torch.LongTensor` of shape :obj:`(batch_size, sequence_length)`): Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide it. Indices can be obtained using :class:`~transformers.BartTokenizer`. See :meth:`transformers.PreTrainedTokenizer.encode` and :meth:`transformers.PreTrainedTokenizer.__call__` for details. `What are input IDs? <../glossary.html#input-ids>`__ attention_mask (:obj:`torch.Tensor` of shape :obj:`(batch_size, sequence_length)`, `optional`): Mask to avoid performing attention on padding token indices. Mask values selected in ``[0, 1]``: - 1 for tokens that are **not masked**, - 0 for tokens that are **masked**. `What are attention masks? <../glossary.html#attention-mask>`__ head_mask (:obj:`torch.Tensor` of shape :obj:`(num_layers, num_heads)`, `optional`): Mask to nullify selected heads of the attention modules. Mask values selected in ``[0, 1]``: - 1 indicates the head is **not masked**, - 0 indicates the heas is **masked**. inputs_embeds (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length, hidden_size)`, `optional`): Optionally, instead of passing :obj:`input_ids` you can choose to directly pass an embedded representation. This is useful if you want more control over how to convert :obj:`input_ids` indices into associated vectors than the model's internal embedding lookup matrix. output_attentions (:obj:`bool`, `optional`): Whether or not to return the attentions tensors of all attention layers. See ``attentions`` under returned tensors for more detail. output_hidden_states (:obj:`bool`, `optional`): Whether or not to return the hidden states of all layers. See ``hidden_states`` under returned tensors for more detail. return_dict (:obj:`bool`, `optional`): Whether or not to return a :class:`~transformers.file_utils.ModelOutput` instead of a plain tuple.
r""" Args: input_ids (:obj:`torch.LongTensor` of shape :obj:`(batch_size, sequence_length)`): Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide it. Indices can be obtained using :class:`~transformers.BartTokenizer`. See :meth:`transformers.PreTrainedTokenizer.encode` and :meth:`transformers.PreTrainedTokenizer.__call__` for details. `What are input IDs? <../glossary.html#input-ids>`__ attention_mask (:obj:`torch.Tensor` of shape :obj:`(batch_size, sequence_length)`, `optional`): Mask to avoid performing attention on padding token indices. Mask values selected in ``[0, 1]``: - 1 for tokens that are **not masked**, - 0 for tokens that are **masked**. `What are attention masks? <../glossary.html#attention-mask>`__ head_mask (:obj:`torch.Tensor` of shape :obj:`(num_layers, num_heads)`, `optional`): Mask to nullify selected heads of the attention modules. Mask values selected in ``[0, 1]``: - 1 indicates the head is **not masked**, - 0 indicates the heas is **masked**. inputs_embeds (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length, hidden_size)`, `optional`): Optionally, instead of passing :obj:`input_ids` you can choose to directly pass an embedded representation. This is useful if you want more control over how to convert :obj:`input_ids` indices into associated vectors than the model's internal embedding lookup matrix. output_attentions (:obj:`bool`, `optional`): Whether or not to return the attentions tensors of all attention layers. See ``attentions`` under returned tensors for more detail. output_hidden_states (:obj:`bool`, `optional`): Whether or not to return the hidden states of all layers. See ``hidden_states`` under returned tensors for more detail. return_dict (:obj:`bool`, `optional`): Whether or not to return a :class:`~transformers.file_utils.ModelOutput` instead of a plain tuple.
[ "r", "Args", ":", "input_ids", "(", ":", "obj", ":", "torch", ".", "LongTensor", "of", "shape", ":", "obj", ":", "(", "batch_size", "sequence_length", ")", ")", ":", "Indices", "of", "input", "sequence", "tokens", "in", "the", "vocabulary", ".", "Padding...
def forward( self, input_ids=None, attention_mask=None, head_mask=None, inputs_embeds=None, output_attentions=None, output_hidden_states=None, return_dict=None, ): r""" Args: input_ids (:obj:`torch.LongTensor` of shape :obj:`(batch_size, sequence_length)`): Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide it. Indices can be obtained using :class:`~transformers.BartTokenizer`. See :meth:`transformers.PreTrainedTokenizer.encode` and :meth:`transformers.PreTrainedTokenizer.__call__` for details. `What are input IDs? <../glossary.html#input-ids>`__ attention_mask (:obj:`torch.Tensor` of shape :obj:`(batch_size, sequence_length)`, `optional`): Mask to avoid performing attention on padding token indices. Mask values selected in ``[0, 1]``: - 1 for tokens that are **not masked**, - 0 for tokens that are **masked**. `What are attention masks? <../glossary.html#attention-mask>`__ head_mask (:obj:`torch.Tensor` of shape :obj:`(num_layers, num_heads)`, `optional`): Mask to nullify selected heads of the attention modules. Mask values selected in ``[0, 1]``: - 1 indicates the head is **not masked**, - 0 indicates the heas is **masked**. inputs_embeds (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length, hidden_size)`, `optional`): Optionally, instead of passing :obj:`input_ids` you can choose to directly pass an embedded representation. This is useful if you want more control over how to convert :obj:`input_ids` indices into associated vectors than the model's internal embedding lookup matrix. output_attentions (:obj:`bool`, `optional`): Whether or not to return the attentions tensors of all attention layers. See ``attentions`` under returned tensors for more detail. output_hidden_states (:obj:`bool`, `optional`): Whether or not to return the hidden states of all layers. See ``hidden_states`` under returned tensors for more detail. return_dict (:obj:`bool`, `optional`): Whether or not to return a :class:`~transformers.file_utils.ModelOutput` instead of a plain tuple. """ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions output_hidden_states = ( output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states ) return_dict = return_dict if return_dict is not None else self.config.use_return_dict # retrieve input_ids and inputs_embeds if input_ids is not None and inputs_embeds is not None: raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time") elif input_ids is not None: input_shape = input_ids.size() input_ids = input_ids.view(-1, input_shape[-1]) elif inputs_embeds is not None: input_shape = inputs_embeds.size()[:-1] else: raise ValueError("You have to specify either input_ids or inputs_embeds") if inputs_embeds is None: inputs_embeds = self.embed_tokens(input_ids) * self.embed_scale embed_pos = self.embed_positions(input_shape) hidden_states = inputs_embeds + embed_pos hidden_states = self.layernorm_embedding(hidden_states) hidden_states = F.dropout(hidden_states, p=self.dropout, training=self.training) # expand attention_mask if attention_mask is not None: # [bsz, seq_len] -> [bsz, 1, tgt_seq_len, src_seq_len] attention_mask = _expand_mask(attention_mask, inputs_embeds.dtype) if self.fp16: attention_mask = attention_mask.to(torch.float16) if self.fp16: hidden_states = hidden_states.to(torch.float16) encoder_states = () if output_hidden_states else None all_attentions = () if output_attentions else None # check if head_mask has a correct number of layers specified if desired if head_mask is not None: assert head_mask.size()[0] == ( len(self.layers) ), f"The head_mask should be specified for {len(self.layers)} layers, but it is for {head_mask.size()[0]}." for idx, encoder_layer in enumerate(self.layers): if output_hidden_states: encoder_states = encoder_states + (hidden_states,) # add LayerDrop (see https://arxiv.org/abs/1909.11556 for description) dropout_probability = random.uniform(0, 1) if self.training and (dropout_probability < self.layerdrop): # skip the layer layer_outputs = (None, None) else: if getattr(self.config, "gradient_checkpointing", False) and self.training: def create_custom_forward(module): def custom_forward(*inputs): return module(*inputs, output_attentions) return custom_forward layer_outputs = torch.utils.checkpoint.checkpoint( create_custom_forward(encoder_layer), hidden_states, attention_mask, (head_mask[idx] if head_mask is not None else None), ) else: layer_outputs = encoder_layer( hidden_states, attention_mask, layer_head_mask=(head_mask[idx] if head_mask is not None else None), output_attentions=output_attentions, ) hidden_states = layer_outputs[0] if output_attentions: all_attentions = all_attentions + (layer_outputs[1],) if output_hidden_states: encoder_states = encoder_states + (hidden_states,) if not return_dict: return tuple(v for v in [hidden_states, encoder_states, all_attentions] if v is not None) return BaseModelOutput( last_hidden_state=hidden_states, hidden_states=encoder_states, attentions=all_attentions )
[ "def", "forward", "(", "self", ",", "input_ids", "=", "None", ",", "attention_mask", "=", "None", ",", "head_mask", "=", "None", ",", "inputs_embeds", "=", "None", ",", "output_attentions", "=", "None", ",", "output_hidden_states", "=", "None", ",", "return_...
https://github.com/NVIDIA/DeepLearningExamples/blob/589604d49e016cd9ef4525f7abcc9c7b826cfc5e/PyTorch/LanguageModeling/BART/bart/modeling/modeling_bart.py#L669-L797
msprev/panzer
9a45452c3d6bb7890e96f67f3ef93e0e03057e47
panzer/document.py
python
Document.jsonfilter
(self)
pipe through external command listed in filters
pipe through external command listed in filters
[ "pipe", "through", "external", "command", "listed", "in", "filters" ]
def jsonfilter(self): """ pipe through external command listed in filters """ to_run = [entry for entry in self.runlist if entry['kind'] == 'filter'] if not to_run: return info.log('INFO', 'panzer', info.pretty_title('filter')) # Run commands for i, entry in enumerate(self.runlist): if entry['kind'] != 'filter': continue # - add debugging info command = [entry['command']] + entry['arguments'] filename = os.path.basename(entry['command']) info.log('INFO', 'panzer', info.pretty_runlist_entry(i, len(self.runlist), entry['command'], entry['arguments'])) info.log('DEBUG', 'panzer', 'run "%s"' % ' '.join(command)) # - run the command and log any errors stderr = str() try: entry['status'] = const.RUNNING self.json_message() # Set up incoming pipe in_pipe = json.dumps(self.ast) # Set up outgoing pipe in case of failure out_pipe = in_pipe process = subprocess.Popen(' '.join(command), stderr=subprocess.PIPE, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True) in_pipe_bytes = in_pipe.encode(const.ENCODING) out_pipe_bytes, stderr_bytes = \ process.communicate(input=in_pipe_bytes) entry['status'] = const.DONE out_pipe = out_pipe_bytes.decode(const.ENCODING) stderr = stderr_bytes.decode(const.ENCODING) if stderr: entry['stderr'] = info.decode_stderr_json(stderr) except OSError as err: entry['status'] = const.FAILED info.log('ERROR', filename, err) continue except Exception: entry['status'] = const.FAILED raise finally: # remove embedded json message info.log_stderr(stderr, filename) # 4. Update document's data with output from commands try: self.ast = json.loads(out_pipe) self.json_message(clear=True) except ValueError: info.log('ERROR', 'panzer', 'failed to receive json object from filter' '---skipping filter') continue
[ "def", "jsonfilter", "(", "self", ")", ":", "to_run", "=", "[", "entry", "for", "entry", "in", "self", ".", "runlist", "if", "entry", "[", "'kind'", "]", "==", "'filter'", "]", "if", "not", "to_run", ":", "return", "info", ".", "log", "(", "'INFO'", ...
https://github.com/msprev/panzer/blob/9a45452c3d6bb7890e96f67f3ef93e0e03057e47/panzer/document.py#L476-L537
postlund/pyatv
4ed1f5539f37d86d80272663d1f2ea34a6c41ec4
pyatv/interface.py
python
BaseConfig.properties
(self)
return self._properties
Return Zeroconf properties.
Return Zeroconf properties.
[ "Return", "Zeroconf", "properties", "." ]
def properties(self) -> Mapping[str, Mapping[str, str]]: """Return Zeroconf properties.""" return self._properties
[ "def", "properties", "(", "self", ")", "->", "Mapping", "[", "str", ",", "Mapping", "[", "str", ",", "str", "]", "]", ":", "return", "self", ".", "_properties" ]
https://github.com/postlund/pyatv/blob/4ed1f5539f37d86d80272663d1f2ea34a6c41ec4/pyatv/interface.py#L1079-L1081