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
rootpy/rootpy
3926935e1f2100d8ba68070c2ab44055d4800f73
rootpy/plotting/base.py
python
Plottable.GetMarkerColor
(self, mode=None)
return self._markercolor(mode)
*mode* may be 'root', 'mpl', or None to return the ROOT, matplotlib, or input value.
*mode* may be 'root', 'mpl', or None to return the ROOT, matplotlib, or input value.
[ "*", "mode", "*", "may", "be", "root", "mpl", "or", "None", "to", "return", "the", "ROOT", "matplotlib", "or", "input", "value", "." ]
def GetMarkerColor(self, mode=None): """ *mode* may be 'root', 'mpl', or None to return the ROOT, matplotlib, or input value. """ return self._markercolor(mode)
[ "def", "GetMarkerColor", "(", "self", ",", "mode", "=", "None", ")", ":", "return", "self", ".", "_markercolor", "(", "mode", ")" ]
https://github.com/rootpy/rootpy/blob/3926935e1f2100d8ba68070c2ab44055d4800f73/rootpy/plotting/base.py#L387-L392
aio-libs/aiohttp-cors
1627c08638e4c83022abffacab753b09896d1b9a
aiohttp_cors/urldispatcher_router_adapter.py
python
ResourcesUrlDispatcherRouterAdapter.get_non_preflight_request_config
(self, request: web.Request)
return defaulted_config
Get stored CORS configuration for routing entity that handles specified request.
Get stored CORS configuration for routing entity that handles specified request.
[ "Get", "stored", "CORS", "configuration", "for", "routing", "entity", "that", "handles", "specified", "request", "." ]
def get_non_preflight_request_config(self, request: web.Request): """Get stored CORS configuration for routing entity that handles specified request.""" assert self.is_cors_enabled_on_request(request) resource = self._request_resource(request) resource_config = self._resource_config[resource] # Take Route config (if any) with defaults from Resource CORS # configuration and global defaults. route = request.match_info.route if _is_web_view(route, strict=False): method_config = request.match_info.handler.get_request_config( request, request.method) else: method_config = resource_config.method_config.get(request.method, {}) defaulted_config = collections.ChainMap( method_config, resource_config.default_config, self._default_config) return defaulted_config
[ "def", "get_non_preflight_request_config", "(", "self", ",", "request", ":", "web", ".", "Request", ")", ":", "assert", "self", ".", "is_cors_enabled_on_request", "(", "request", ")", "resource", "=", "self", ".", "_request_resource", "(", "request", ")", "resou...
https://github.com/aio-libs/aiohttp-cors/blob/1627c08638e4c83022abffacab753b09896d1b9a/aiohttp_cors/urldispatcher_router_adapter.py#L302-L324
Tautulli/Tautulli
2410eb33805aaac4bd1c5dad0f71e4f15afaf742
lib/cherrypy/_cperror.py
python
_be_ie_unfriendly
(status)
[]
def _be_ie_unfriendly(status): response = cherrypy.serving.response # For some statuses, Internet Explorer 5+ shows "friendly error # messages" instead of our response.body if the body is smaller # than a given size. Fix this by returning a body over that size # (by adding whitespace). # See http://support.microsoft.com/kb/q218155/ s = _ie_friendly_error_sizes.get(status, 0) if s: s += 1 # Since we are issuing an HTTP error status, we assume that # the entity is short, and we should just collapse it. content = response.collapse_body() content_length = len(content) if content_length and content_length < s: # IN ADDITION: the response must be written to IE # in one chunk or it will still get replaced! Bah. content = content + (b' ' * (s - content_length)) response.body = content response.headers['Content-Length'] = str(len(content))
[ "def", "_be_ie_unfriendly", "(", "status", ")", ":", "response", "=", "cherrypy", ".", "serving", ".", "response", "# For some statuses, Internet Explorer 5+ shows \"friendly error", "# messages\" instead of our response.body if the body is smaller", "# than a given size. Fix this by r...
https://github.com/Tautulli/Tautulli/blob/2410eb33805aaac4bd1c5dad0f71e4f15afaf742/lib/cherrypy/_cperror.py#L557-L577
qLab/qLib
a34f45d22fe7315991bb822824c035fbc9a2a5e8
scripts/python/qliblabels.py
python
apply_naming
(node)
.
.
[ "." ]
def apply_naming(node): '''.''' """ TODO: make sure to - remove _all_ known prefixes as well, when necessary - rename to a default name if previous tagging had an explicit naming scheme """ pass c = node.type().category().name().lower()
[ "def", "apply_naming", "(", "node", ")", ":", "\"\"\"\n\tTODO: make sure to\n\t- remove _all_ known prefixes as well, when necessary\n\t- rename to a default name if previous tagging had an explicit naming scheme\n\t\"\"\"", "pass", "c", "=", "node", ".", "type", "(", ")", ".", "cate...
https://github.com/qLab/qLib/blob/a34f45d22fe7315991bb822824c035fbc9a2a5e8/scripts/python/qliblabels.py#L225-L233
saltstack/salt
fae5bc757ad0f1716483ce7ae180b451545c2058
salt/grains/core.py
python
_bsd_cpudata
(osdata)
return grains
Return CPU information for BSD-like systems
Return CPU information for BSD-like systems
[ "Return", "CPU", "information", "for", "BSD", "-", "like", "systems" ]
def _bsd_cpudata(osdata): """ Return CPU information for BSD-like systems """ # Provides: # cpuarch # num_cpus # cpu_model # cpu_flags sysctl = salt.utils.path.which("sysctl") arch = salt.utils.path.which("arch") cmds = {} if sysctl: cmds.update( { "num_cpus": "{} -n hw.ncpu".format(sysctl), "cpuarch": "{} -n hw.machine".format(sysctl), "cpu_model": "{} -n hw.model".format(sysctl), } ) if arch and osdata["kernel"] == "OpenBSD": cmds["cpuarch"] = "{} -s".format(arch) if osdata["kernel"] == "Darwin": cmds["cpu_model"] = "{} -n machdep.cpu.brand_string".format(sysctl) cmds["cpu_flags"] = "{} -n machdep.cpu.features".format(sysctl) grains = {k: __salt__["cmd.run"](v) for k, v in cmds.items()} if "cpu_flags" in grains and isinstance(grains["cpu_flags"], str): grains["cpu_flags"] = grains["cpu_flags"].split(" ") if osdata["kernel"] == "NetBSD": grains["cpu_flags"] = [] for line in __salt__["cmd.run"]("cpuctl identify 0").splitlines(): cpu_match = re.match(r"cpu[0-9]:\ features[0-9]?\ .+<(.+)>", line) if cpu_match: flag = cpu_match.group(1).split(",") grains["cpu_flags"].extend(flag) if osdata["kernel"] == "FreeBSD" and os.path.isfile("/var/run/dmesg.boot"): grains["cpu_flags"] = [] # TODO: at least it needs to be tested for BSD other then FreeBSD with salt.utils.files.fopen("/var/run/dmesg.boot", "r") as _fp: cpu_here = False for line in _fp: if line.startswith("CPU: "): cpu_here = True # starts CPU descr continue if cpu_here: if not line.startswith(" "): break # game over if "Features" in line: start = line.find("<") end = line.find(">") if start > 0 and end > 0: flag = line[start + 1 : end].split(",") grains["cpu_flags"].extend(flag) try: grains["num_cpus"] = int(grains["num_cpus"]) except ValueError: grains["num_cpus"] = 1 return grains
[ "def", "_bsd_cpudata", "(", "osdata", ")", ":", "# Provides:", "# cpuarch", "# num_cpus", "# cpu_model", "# cpu_flags", "sysctl", "=", "salt", ".", "utils", ".", "path", ".", "which", "(", "\"sysctl\"", ")", "arch", "=", "salt", ".", "utils", ".", "p...
https://github.com/saltstack/salt/blob/fae5bc757ad0f1716483ce7ae180b451545c2058/salt/grains/core.py#L365-L430
CalebBell/thermo
572a47d1b03d49fe609b8d5f826fa6a7cde00828
thermo/property_package.py
python
PropertyPackage.plot_TP
(self, zs, Tmin=None, Tmax=None, pts=50, branches=[], ignore_errors=True, values=False)
[]
def plot_TP(self, zs, Tmin=None, Tmax=None, pts=50, branches=[], ignore_errors=True, values=False): # pragma: no cover if not has_matplotlib() and not values: raise Exception('Optional dependency matplotlib is required for plotting') if not Tmin: Tmin = min(self.Tms) if not Tmax: Tmax = min(self.Tcs) Ts = np.linspace(Tmin, Tmax, pts) P_dews = [] P_bubbles = [] branch = bool(len(branches)) if branch: branch_Ps = [[] for i in range(len(branches))] else: branch_Ps = None for T in Ts: try: self.flash(T=T, VF=0, zs=zs) P_bubbles.append(self.P) except Exception as e: if ignore_errors: P_bubbles.append(None) else: raise e try: self.flash(T=T, VF=1, zs=zs) P_dews.append(self.P) except Exception as e: if ignore_errors: P_dews.append(None) else: raise e if branch: for VF, Ps in zip(branches, branch_Ps): try: self.flash(T=T, VF=VF, zs=zs) Ps.append(self.P) except Exception as e: if ignore_errors: Ps.append(None) else: raise e if values: return Ts, P_dews, P_bubbles, branch_Ps import matplotlib.pyplot as plt plt.plot(Ts, P_dews, label='TP dew point curve') plt.plot(Ts, P_bubbles, label='TP bubble point curve') plt.xlabel('System temperature, K') plt.ylabel('System pressure, Pa') plt.title('PT system curve, zs=%s' %zs) if branch: for VF, Ps in zip(branches, branch_Ps): plt.plot(Ts, Ps, label='TP curve for VF=%s'%VF) plt.legend(loc='best') plt.show()
[ "def", "plot_TP", "(", "self", ",", "zs", ",", "Tmin", "=", "None", ",", "Tmax", "=", "None", ",", "pts", "=", "50", ",", "branches", "=", "[", "]", ",", "ignore_errors", "=", "True", ",", "values", "=", "False", ")", ":", "# pragma: no cover", "if...
https://github.com/CalebBell/thermo/blob/572a47d1b03d49fe609b8d5f826fa6a7cde00828/thermo/property_package.py#L852-L908
JoneXiong/oejia_weshop
36e74b9892661ab6ef508a20b6d6922ae990f3f5
const.py
python
SortedDict.insert
(self, index, key, value)
Inserts the key, value pair before the item with the given index.
Inserts the key, value pair before the item with the given index.
[ "Inserts", "the", "key", "value", "pair", "before", "the", "item", "with", "the", "given", "index", "." ]
def insert(self, index, key, value): """Inserts the key, value pair before the item with the given index.""" warnings.warn( "SortedDict.insert is deprecated", PendingDeprecationWarning, stacklevel=2 ) if key in self.keyOrder: n = self.keyOrder.index(key) del self.keyOrder[n] if n < index: index -= 1 self.keyOrder.insert(index, key) super(SortedDict, self).__setitem__(key, value)
[ "def", "insert", "(", "self", ",", "index", ",", "key", ",", "value", ")", ":", "warnings", ".", "warn", "(", "\"SortedDict.insert is deprecated\"", ",", "PendingDeprecationWarning", ",", "stacklevel", "=", "2", ")", "if", "key", "in", "self", ".", "keyOrder...
https://github.com/JoneXiong/oejia_weshop/blob/36e74b9892661ab6ef508a20b6d6922ae990f3f5/const.py#L119-L131
IronLanguages/main
a949455434b1fda8c783289e897e78a9a0caabb5
External.LCA_RESTRICTED/Languages/CPython/27/Lib/robotparser.py
python
RobotFileParser.read
(self)
Reads the robots.txt URL and feeds it to the parser.
Reads the robots.txt URL and feeds it to the parser.
[ "Reads", "the", "robots", ".", "txt", "URL", "and", "feeds", "it", "to", "the", "parser", "." ]
def read(self): """Reads the robots.txt URL and feeds it to the parser.""" opener = URLopener() f = opener.open(self.url) lines = [line.strip() for line in f] f.close() self.errcode = opener.errcode if self.errcode in (401, 403): self.disallow_all = True elif self.errcode >= 400: self.allow_all = True elif self.errcode == 200 and lines: self.parse(lines)
[ "def", "read", "(", "self", ")", ":", "opener", "=", "URLopener", "(", ")", "f", "=", "opener", ".", "open", "(", "self", ".", "url", ")", "lines", "=", "[", "line", ".", "strip", "(", ")", "for", "line", "in", "f", "]", "f", ".", "close", "(...
https://github.com/IronLanguages/main/blob/a949455434b1fda8c783289e897e78a9a0caabb5/External.LCA_RESTRICTED/Languages/CPython/27/Lib/robotparser.py#L54-L66
DeepRNN/image_captioning
ee6936c3a1a8872ae7b055cfc8762fa323b01412
utils/coco/pycocoevalcap/cider/cider_scorer.py
python
CiderScorer.cook_append
(self, test, refs)
called by constructor and __iadd__ to avoid creating new instances.
called by constructor and __iadd__ to avoid creating new instances.
[ "called", "by", "constructor", "and", "__iadd__", "to", "avoid", "creating", "new", "instances", "." ]
def cook_append(self, test, refs): '''called by constructor and __iadd__ to avoid creating new instances.''' if refs is not None: self.crefs.append(cook_refs(refs)) if test is not None: self.ctest.append(cook_test(test)) ## N.B.: -1 else: self.ctest.append(None)
[ "def", "cook_append", "(", "self", ",", "test", ",", "refs", ")", ":", "if", "refs", "is", "not", "None", ":", "self", ".", "crefs", ".", "append", "(", "cook_refs", "(", "refs", ")", ")", "if", "test", "is", "not", "None", ":", "self", ".", "cte...
https://github.com/DeepRNN/image_captioning/blob/ee6936c3a1a8872ae7b055cfc8762fa323b01412/utils/coco/pycocoevalcap/cider/cider_scorer.py#L68-L76
tendenci/tendenci
0f2c348cc0e7d41bc56f50b00ce05544b083bf1d
tendenci/apps/helpdesk/models.py
python
Ticket._get_priority_css_class
(self)
Return the bootstrap class corresponding to the priority.
Return the bootstrap class corresponding to the priority.
[ "Return", "the", "bootstrap", "class", "corresponding", "to", "the", "priority", "." ]
def _get_priority_css_class(self): """ Return the bootstrap class corresponding to the priority. """ if self.priority == 2: return "warning" elif self.priority == 1: return "danger" else: return ""
[ "def", "_get_priority_css_class", "(", "self", ")", ":", "if", "self", ".", "priority", "==", "2", ":", "return", "\"warning\"", "elif", "self", ".", "priority", "==", "1", ":", "return", "\"danger\"", "else", ":", "return", "\"\"" ]
https://github.com/tendenci/tendenci/blob/0f2c348cc0e7d41bc56f50b00ce05544b083bf1d/tendenci/apps/helpdesk/models.py#L435-L444
quodlibet/quodlibet
e3099c89f7aa6524380795d325cc14630031886c
quodlibet/ext/events/searchprovider.py
python
get_gs_provider_files
()
return ini_files
Return all installed search provider files for GNOME Shell
Return all installed search provider files for GNOME Shell
[ "Return", "all", "installed", "search", "provider", "files", "for", "GNOME", "Shell" ]
def get_gs_provider_files(): """Return all installed search provider files for GNOME Shell""" ini_files = [] for d in xdg_get_system_data_dirs(): path = os.path.join(d, "gnome-shell", "search-providers") try: for entry in os.listdir(path): if entry.endswith(".ini"): ini_files.append(os.path.join(path, entry)) except EnvironmentError: pass return ini_files
[ "def", "get_gs_provider_files", "(", ")", ":", "ini_files", "=", "[", "]", "for", "d", "in", "xdg_get_system_data_dirs", "(", ")", ":", "path", "=", "os", ".", "path", ".", "join", "(", "d", ",", "\"gnome-shell\"", ",", "\"search-providers\"", ")", "try", ...
https://github.com/quodlibet/quodlibet/blob/e3099c89f7aa6524380795d325cc14630031886c/quodlibet/ext/events/searchprovider.py#L42-L54
styxit/HTPC-Manager
490697460b4fa1797106aece27d873bc256b2ff1
libs/formencode/htmlrename.py
python
rename
(form, rename_func)
return p.text()
Rename all the form fields in the form (a string), using rename_func rename_func will be called with one argument, the name of the field, and should return a new name.
Rename all the form fields in the form (a string), using rename_func
[ "Rename", "all", "the", "form", "fields", "in", "the", "form", "(", "a", "string", ")", "using", "rename_func" ]
def rename(form, rename_func): """ Rename all the form fields in the form (a string), using rename_func rename_func will be called with one argument, the name of the field, and should return a new name. """ p = RenamingParser(rename_func) p.feed(form) p.close() return p.text()
[ "def", "rename", "(", "form", ",", "rename_func", ")", ":", "p", "=", "RenamingParser", "(", "rename_func", ")", "p", ".", "feed", "(", "form", ")", "p", ".", "close", "(", ")", "return", "p", ".", "text", "(", ")" ]
https://github.com/styxit/HTPC-Manager/blob/490697460b4fa1797106aece27d873bc256b2ff1/libs/formencode/htmlrename.py#L10-L20
ethereum/py-evm
026ee20f8d9b70d7c1b6a4fb9484d5489d425e54
eth/db/header.py
python
HeaderDB._find_new_ancestors
(cls, db: DatabaseAPI, header: BlockHeaderAPI, genesis_parent_hash: Hash32)
Returns the chain leading up from the given header until (but not including) the first ancestor it has in common with our canonical chain. If D is the canonical head in the following chain, and F is the new header, then this function returns (F, E). A - B - C - D \ E - F
Returns the chain leading up from the given header until (but not including) the first ancestor it has in common with our canonical chain.
[ "Returns", "the", "chain", "leading", "up", "from", "the", "given", "header", "until", "(", "but", "not", "including", ")", "the", "first", "ancestor", "it", "has", "in", "common", "with", "our", "canonical", "chain", "." ]
def _find_new_ancestors(cls, db: DatabaseAPI, header: BlockHeaderAPI, genesis_parent_hash: Hash32) -> Iterable[BlockHeaderAPI]: """ Returns the chain leading up from the given header until (but not including) the first ancestor it has in common with our canonical chain. If D is the canonical head in the following chain, and F is the new header, then this function returns (F, E). A - B - C - D \ E - F """ h = header while True: try: orig = cls._get_canonical_block_header_by_number(db, h.block_number) except HeaderNotFound: # This just means the block is not on the canonical chain. pass else: if orig.hash == h.hash: # Found the common ancestor, stop. break # Found a new ancestor yield h if h.parent_hash == genesis_parent_hash: break else: try: h = cls._get_block_header_by_hash(db, h.parent_hash) except HeaderNotFound: # We must have hit a checkpoint parent, return early break
[ "def", "_find_new_ancestors", "(", "cls", ",", "db", ":", "DatabaseAPI", ",", "header", ":", "BlockHeaderAPI", ",", "genesis_parent_hash", ":", "Hash32", ")", "->", "Iterable", "[", "BlockHeaderAPI", "]", ":", "h", "=", "header", "while", "True", ":", "try",...
https://github.com/ethereum/py-evm/blob/026ee20f8d9b70d7c1b6a4fb9484d5489d425e54/eth/db/header.py#L562-L599
google/grr
8ad8a4d2c5a93c92729206b7771af19d92d4f915
grr/server/grr_response_server/gui/api_call_robot_router.py
python
ApiRobotCreateFlowHandler.Handle
(self, args, context=None)
return delegate.Handle(delegate_args, context=context)
[]
def Handle(self, args, context=None): if not args.client_id: raise RuntimeError("Client id has to be specified.") if not args.flow.name: raise RuntimeError("Flow name is not specified.") delegate = api_flow.ApiCreateFlowHandler() # Note that runner_args are dropped. From all the arguments We use only # the flow name and the arguments. delegate_args = api_flow.ApiCreateFlowArgs(client_id=args.client_id) delegate_args.flow.name = self.override_flow_name or args.flow.name delegate_args.flow.args = self.override_flow_args or args.flow.args return delegate.Handle(delegate_args, context=context)
[ "def", "Handle", "(", "self", ",", "args", ",", "context", "=", "None", ")", ":", "if", "not", "args", ".", "client_id", ":", "raise", "RuntimeError", "(", "\"Client id has to be specified.\"", ")", "if", "not", "args", ".", "flow", ".", "name", ":", "ra...
https://github.com/google/grr/blob/8ad8a4d2c5a93c92729206b7771af19d92d4f915/grr/server/grr_response_server/gui/api_call_robot_router.py#L100-L113
fkie/multimaster_fkie
3d23df29d25d71a75c66bbd3cc6e9cbb255724d8
fkie_node_manager/src/fkie_node_manager/parameter_dialog.py
python
ArrayEntry.value
(self, with_tags=False, only_changed=False)
return result
Retruns a dictionary for an entry of an array, e.g. {name: value}. If with_tags is True it looks like: {name: {':value': value, ':type': type}} :rtype: dict
Retruns a dictionary for an entry of an array, e.g. {name: value}. If with_tags is True it looks like: {name: {':value': value, ':type': type}} :rtype: dict
[ "Retruns", "a", "dictionary", "for", "an", "entry", "of", "an", "array", "e", ".", "g", ".", "{", "name", ":", "value", "}", ".", "If", "with_tags", "is", "True", "it", "looks", "like", ":", "{", "name", ":", "{", ":", "value", ":", "value", ":",...
def value(self, with_tags=False, only_changed=False): ''' Retruns a dictionary for an entry of an array, e.g. {name: value}. If with_tags is True it looks like: {name: {':value': value, ':type': type}} :rtype: dict ''' result = dict() for param in self.params: val = param.value(with_tags) if val or not only_changed: result[param.name()] = val return result
[ "def", "value", "(", "self", ",", "with_tags", "=", "False", ",", "only_changed", "=", "False", ")", ":", "result", "=", "dict", "(", ")", "for", "param", "in", "self", ".", "params", ":", "val", "=", "param", ".", "value", "(", "with_tags", ")", "...
https://github.com/fkie/multimaster_fkie/blob/3d23df29d25d71a75c66bbd3cc6e9cbb255724d8/fkie_node_manager/src/fkie_node_manager/parameter_dialog.py#L785-L796
smart-mobile-software/gitstack
d9fee8f414f202143eb6e620529e8e5539a2af56
python/Lib/distutils/sysconfig.py
python
get_config_var
(name)
return get_config_vars().get(name)
Return the value of a single variable using the dictionary returned by 'get_config_vars()'. Equivalent to get_config_vars().get(name)
Return the value of a single variable using the dictionary returned by 'get_config_vars()'. Equivalent to get_config_vars().get(name)
[ "Return", "the", "value", "of", "a", "single", "variable", "using", "the", "dictionary", "returned", "by", "get_config_vars", "()", ".", "Equivalent", "to", "get_config_vars", "()", ".", "get", "(", "name", ")" ]
def get_config_var(name): """Return the value of a single variable using the dictionary returned by 'get_config_vars()'. Equivalent to get_config_vars().get(name) """ return get_config_vars().get(name)
[ "def", "get_config_var", "(", "name", ")", ":", "return", "get_config_vars", "(", ")", ".", "get", "(", "name", ")" ]
https://github.com/smart-mobile-software/gitstack/blob/d9fee8f414f202143eb6e620529e8e5539a2af56/python/Lib/distutils/sysconfig.py#L566-L571
yuxiaokui/Intranet-Penetration
f57678a204840c83cbf3308e3470ae56c5ff514b
proxy/XX-Net/code/default/python27/1.0/lib/tokenize.py
python
generate_tokens
(readline)
The generate_tokens() generator requires one argument, readline, which must be a callable object which provides the same interface as the readline() method of built-in file objects. Each call to the function should return one line of input as a string. Alternately, readline can be a callable function terminating with StopIteration: readline = open(myfile).next # Example of alternate readline The generator produces 5-tuples with these members: the token type; the token string; a 2-tuple (srow, scol) of ints specifying the row and column where the token begins in the source; a 2-tuple (erow, ecol) of ints specifying the row and column where the token ends in the source; and the line on which the token was found. The line passed is the logical line; continuation lines are included.
The generate_tokens() generator requires one argument, readline, which must be a callable object which provides the same interface as the readline() method of built-in file objects. Each call to the function should return one line of input as a string. Alternately, readline can be a callable function terminating with StopIteration: readline = open(myfile).next # Example of alternate readline
[ "The", "generate_tokens", "()", "generator", "requires", "one", "argument", "readline", "which", "must", "be", "a", "callable", "object", "which", "provides", "the", "same", "interface", "as", "the", "readline", "()", "method", "of", "built", "-", "in", "file"...
def generate_tokens(readline): """ The generate_tokens() generator requires one argument, readline, which must be a callable object which provides the same interface as the readline() method of built-in file objects. Each call to the function should return one line of input as a string. Alternately, readline can be a callable function terminating with StopIteration: readline = open(myfile).next # Example of alternate readline The generator produces 5-tuples with these members: the token type; the token string; a 2-tuple (srow, scol) of ints specifying the row and column where the token begins in the source; a 2-tuple (erow, ecol) of ints specifying the row and column where the token ends in the source; and the line on which the token was found. The line passed is the logical line; continuation lines are included. """ lnum = parenlev = continued = 0 namechars, numchars = string.ascii_letters + '_', '0123456789' contstr, needcont = '', 0 contline = None indents = [0] while 1: # loop over lines in stream try: line = readline() except StopIteration: line = '' lnum += 1 pos, max = 0, len(line) if contstr: # continued string if not line: raise TokenError, ("EOF in multi-line string", strstart) endmatch = endprog.match(line) if endmatch: pos = end = endmatch.end(0) yield (STRING, contstr + line[:end], strstart, (lnum, end), contline + line) contstr, needcont = '', 0 contline = None elif needcont and line[-2:] != '\\\n' and line[-3:] != '\\\r\n': yield (ERRORTOKEN, contstr + line, strstart, (lnum, len(line)), contline) contstr = '' contline = None continue else: contstr = contstr + line contline = contline + line continue elif parenlev == 0 and not continued: # new statement if not line: break column = 0 while pos < max: # measure leading whitespace if line[pos] == ' ': column += 1 elif line[pos] == '\t': column = (column//tabsize + 1)*tabsize elif line[pos] == '\f': column = 0 else: break pos += 1 if pos == max: break if line[pos] in '#\r\n': # skip comments or blank lines if line[pos] == '#': comment_token = line[pos:].rstrip('\r\n') nl_pos = pos + len(comment_token) yield (COMMENT, comment_token, (lnum, pos), (lnum, pos + len(comment_token)), line) yield (NL, line[nl_pos:], (lnum, nl_pos), (lnum, len(line)), line) else: yield ((NL, COMMENT)[line[pos] == '#'], line[pos:], (lnum, pos), (lnum, len(line)), line) continue if column > indents[-1]: # count indents or dedents indents.append(column) yield (INDENT, line[:pos], (lnum, 0), (lnum, pos), line) while column < indents[-1]: if column not in indents: raise IndentationError( "unindent does not match any outer indentation level", ("<tokenize>", lnum, pos, line)) indents = indents[:-1] yield (DEDENT, '', (lnum, pos), (lnum, pos), line) else: # continued statement if not line: raise TokenError, ("EOF in multi-line statement", (lnum, 0)) continued = 0 while pos < max: pseudomatch = pseudoprog.match(line, pos) if pseudomatch: # scan for tokens start, end = pseudomatch.span(1) spos, epos, pos = (lnum, start), (lnum, end), end if start == end: continue token, initial = line[start:end], line[start] if initial in numchars or \ (initial == '.' and token != '.'): # ordinary number yield (NUMBER, token, spos, epos, line) elif initial in '\r\n': yield (NL if parenlev > 0 else NEWLINE, token, spos, epos, line) elif initial == '#': assert not token.endswith("\n") yield (COMMENT, token, spos, epos, line) elif token in triple_quoted: endprog = endprogs[token] endmatch = endprog.match(line, pos) if endmatch: # all on one line pos = endmatch.end(0) token = line[start:pos] yield (STRING, token, spos, (lnum, pos), line) else: strstart = (lnum, start) # multiple lines contstr = line[start:] contline = line break elif initial in single_quoted or \ token[:2] in single_quoted or \ token[:3] in single_quoted: if token[-1] == '\n': # continued string strstart = (lnum, start) endprog = (endprogs[initial] or endprogs[token[1]] or endprogs[token[2]]) contstr, needcont = line[start:], 1 contline = line break else: # ordinary string yield (STRING, token, spos, epos, line) elif initial in namechars: # ordinary name yield (NAME, token, spos, epos, line) elif initial == '\\': # continued stmt continued = 1 else: if initial in '([{': parenlev += 1 elif initial in ')]}': parenlev -= 1 yield (OP, token, spos, epos, line) else: yield (ERRORTOKEN, line[pos], (lnum, pos), (lnum, pos+1), line) pos += 1 for indent in indents[1:]: # pop remaining indent levels yield (DEDENT, '', (lnum, 0), (lnum, 0), '') yield (ENDMARKER, '', (lnum, 0), (lnum, 0), '')
[ "def", "generate_tokens", "(", "readline", ")", ":", "lnum", "=", "parenlev", "=", "continued", "=", "0", "namechars", ",", "numchars", "=", "string", ".", "ascii_letters", "+", "'_'", ",", "'0123456789'", "contstr", ",", "needcont", "=", "''", ",", "0", ...
https://github.com/yuxiaokui/Intranet-Penetration/blob/f57678a204840c83cbf3308e3470ae56c5ff514b/proxy/XX-Net/code/default/python27/1.0/lib/tokenize.py#L287-L442
antlong/picka
3f048b803a32213b4e3b64ccc64a4a78997f790c
picka/picka.py
python
email
(length=8, domain='@example.com')
return AttrDict( { "length": length, "domain": domain, "email": ''.join(choice( ascii_lowercase) for _ in range( length)) + domain } )
Generates an email address.
Generates an email address.
[ "Generates", "an", "email", "address", "." ]
def email(length=8, domain='@example.com'): # todo: remove args on length and domain. """Generates an email address.""" return AttrDict( { "length": length, "domain": domain, "email": ''.join(choice( ascii_lowercase) for _ in range( length)) + domain } )
[ "def", "email", "(", "length", "=", "8", ",", "domain", "=", "'@example.com'", ")", ":", "# todo: remove args on length and domain.", "return", "AttrDict", "(", "{", "\"length\"", ":", "length", ",", "\"domain\"", ":", "domain", ",", "\"email\"", ":", "''", "....
https://github.com/antlong/picka/blob/3f048b803a32213b4e3b64ccc64a4a78997f790c/picka/picka.py#L723-L734
Phylliade/ikpy
3966be998ce0ece1d1068dd11b5f2c42b172cf30
contrib/transformations.py
python
distance
(p1, p2)
return sqrt(x * x + y * y + z * z)
Cartesian distance between two PoseStamped or PoseLists :param p1: point 1 (list, Pose or PoseStamped) :param p2: point 2 (list, Pose or PoseStamped) :return: cartesian distance (float)
Cartesian distance between two PoseStamped or PoseLists :param p1: point 1 (list, Pose or PoseStamped) :param p2: point 2 (list, Pose or PoseStamped) :return: cartesian distance (float)
[ "Cartesian", "distance", "between", "two", "PoseStamped", "or", "PoseLists", ":", "param", "p1", ":", "point", "1", "(", "list", "Pose", "or", "PoseStamped", ")", ":", "param", "p2", ":", "point", "2", "(", "list", "Pose", "or", "PoseStamped", ")", ":", ...
def distance(p1, p2): """ Cartesian distance between two PoseStamped or PoseLists :param p1: point 1 (list, Pose or PoseStamped) :param p2: point 2 (list, Pose or PoseStamped) :return: cartesian distance (float) """ def xyz(some_pose): if isinstance(some_pose, PoseStamped): return some_pose.pose.position.x, some_pose.pose.position.y, some_pose.pose.position.z elif isinstance(some_pose, Pose): return some_pose.position.x, some_pose.position.y, some_pose.position.z elif _is_indexable(some_pose[0]): return some_pose[0][0], some_pose[0][1], some_pose[0][2] else: return some_pose[0], some_pose[1], some_pose[2] x1, y1, z1 = xyz(p1) x2, y2, z2 = xyz(p2) x = x1 - x2 y = y1 - y2 z = z1 - z2 return sqrt(x * x + y * y + z * z)
[ "def", "distance", "(", "p1", ",", "p2", ")", ":", "def", "xyz", "(", "some_pose", ")", ":", "if", "isinstance", "(", "some_pose", ",", "PoseStamped", ")", ":", "return", "some_pose", ".", "pose", ".", "position", ".", "x", ",", "some_pose", ".", "po...
https://github.com/Phylliade/ikpy/blob/3966be998ce0ece1d1068dd11b5f2c42b172cf30/contrib/transformations.py#L244-L268
materialsproject/pymatgen
8128f3062a334a2edd240e4062b5b9bdd1ae6f58
pymatgen/io/nwchem.py
python
NwInput.from_string
(cls, string_input)
return NwInput( mol, tasks=tasks, directives=directives, geometry_options=geom_options, symmetry_options=symmetry_options, memory_options=memory_options, )
Read an NwInput from a string. Currently tested to work with files generated from this class itself. Args: string_input: string_input to parse. Returns: NwInput object
Read an NwInput from a string. Currently tested to work with files generated from this class itself.
[ "Read", "an", "NwInput", "from", "a", "string", ".", "Currently", "tested", "to", "work", "with", "files", "generated", "from", "this", "class", "itself", "." ]
def from_string(cls, string_input): """ Read an NwInput from a string. Currently tested to work with files generated from this class itself. Args: string_input: string_input to parse. Returns: NwInput object """ directives = [] tasks = [] charge = None spin_multiplicity = None title = None basis_set = None basis_set_option = None theory_directives = {} geom_options = None symmetry_options = None memory_options = None lines = string_input.strip().split("\n") while len(lines) > 0: l = lines.pop(0).strip() if l == "": continue toks = l.split() if toks[0].lower() == "geometry": geom_options = toks[1:] l = lines.pop(0).strip() toks = l.split() if toks[0].lower() == "symmetry": symmetry_options = toks[1:] l = lines.pop(0).strip() # Parse geometry species = [] coords = [] while l.lower() != "end": toks = l.split() species.append(toks[0]) coords.append([float(i) for i in toks[1:]]) l = lines.pop(0).strip() mol = Molecule(species, coords) elif toks[0].lower() == "charge": charge = int(toks[1]) elif toks[0].lower() == "title": title = l[5:].strip().strip('"') elif toks[0].lower() == "basis": # Parse basis sets l = lines.pop(0).strip() basis_set = {} while l.lower() != "end": toks = l.split() basis_set[toks[0]] = toks[-1].strip('"') l = lines.pop(0).strip() elif toks[0].lower() in NwTask.theories: # read the basis_set_option if len(toks) > 1: basis_set_option = toks[1] # Parse theory directives. theory = toks[0].lower() l = lines.pop(0).strip() theory_directives[theory] = {} while l.lower() != "end": toks = l.split() theory_directives[theory][toks[0]] = toks[-1] if toks[0] == "mult": spin_multiplicity = float(toks[1]) l = lines.pop(0).strip() elif toks[0].lower() == "task": tasks.append( NwTask( charge=charge, spin_multiplicity=spin_multiplicity, title=title, theory=toks[1], operation=toks[2], basis_set=basis_set, basis_set_option=basis_set_option, theory_directives=theory_directives.get(toks[1]), ) ) elif toks[0].lower() == "memory": memory_options = " ".join(toks[1:]) else: directives.append(l.strip().split()) return NwInput( mol, tasks=tasks, directives=directives, geometry_options=geom_options, symmetry_options=symmetry_options, memory_options=memory_options, )
[ "def", "from_string", "(", "cls", ",", "string_input", ")", ":", "directives", "=", "[", "]", "tasks", "=", "[", "]", "charge", "=", "None", "spin_multiplicity", "=", "None", "title", "=", "None", "basis_set", "=", "None", "basis_set_option", "=", "None", ...
https://github.com/materialsproject/pymatgen/blob/8128f3062a334a2edd240e4062b5b9bdd1ae6f58/pymatgen/io/nwchem.py#L435-L531
iGio90/Dwarf
bb3011cdffd209c7e3f5febe558053bf649ca69c
dwarf_debugger/lib/utils.py
python
do_shell_command
(cmd, timeout=60)
Execute cmd
Execute cmd
[ "Execute", "cmd" ]
def do_shell_command(cmd, timeout=60): """ Execute cmd """ try: # capture output is only supported in py 3.7 if sys.version_info.minor >= 7: result = subprocess.run( cmd.split(' '), timeout=timeout, capture_output=True) else: result = subprocess.run( cmd.split(' '), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=timeout ) if result.stderr: return result.stderr.decode('utf8') return result.stdout.decode('utf8') except subprocess.TimeoutExpired: return None
[ "def", "do_shell_command", "(", "cmd", ",", "timeout", "=", "60", ")", ":", "try", ":", "# capture output is only supported in py 3.7", "if", "sys", ".", "version_info", ".", "minor", ">=", "7", ":", "result", "=", "subprocess", ".", "run", "(", "cmd", ".", ...
https://github.com/iGio90/Dwarf/blob/bb3011cdffd209c7e3f5febe558053bf649ca69c/dwarf_debugger/lib/utils.py#L29-L51
goace/personal-file-sharing-center
4a5b903b003f2db1306e77c5e51b6660fc5dbc6a
web/wsgiserver/__init__.py
python
WSGIPathInfoDispatcher.__call__
(self, environ, start_response)
return ['']
[]
def __call__(self, environ, start_response): path = environ["PATH_INFO"] or "/" for p, app in self.apps: # The apps list should be sorted by length, descending. if path.startswith(p + "/") or path == p: environ = environ.copy() environ["SCRIPT_NAME"] = environ["SCRIPT_NAME"] + p environ["PATH_INFO"] = path[len(p):] return app(environ, start_response) start_response('404 Not Found', [('Content-Type', 'text/plain'), ('Content-Length', '0')]) return ['']
[ "def", "__call__", "(", "self", ",", "environ", ",", "start_response", ")", ":", "path", "=", "environ", "[", "\"PATH_INFO\"", "]", "or", "\"/\"", "for", "p", ",", "app", "in", "self", ".", "apps", ":", "# The apps list should be sorted by length, descending.", ...
https://github.com/goace/personal-file-sharing-center/blob/4a5b903b003f2db1306e77c5e51b6660fc5dbc6a/web/wsgiserver/__init__.py#L2206-L2218
aws/sagemaker-containers
526dda90d636c7fb0c25791e6c57d077bd972000
src/sagemaker_containers/_logging.py
python
get_logger
()
return logging.getLogger("sagemaker-containers")
Returns a logger with the name 'sagemaker-containers', creating it if necessary.
Returns a logger with the name 'sagemaker-containers', creating it if necessary.
[ "Returns", "a", "logger", "with", "the", "name", "sagemaker", "-", "containers", "creating", "it", "if", "necessary", "." ]
def get_logger(): """Returns a logger with the name 'sagemaker-containers', creating it if necessary. """ return logging.getLogger("sagemaker-containers")
[ "def", "get_logger", "(", ")", ":", "return", "logging", ".", "getLogger", "(", "\"sagemaker-containers\"", ")" ]
https://github.com/aws/sagemaker-containers/blob/526dda90d636c7fb0c25791e6c57d077bd972000/src/sagemaker_containers/_logging.py#L22-L26
fastnlp/fastNLP
fb645d370f4cc1b00c7dbb16c1ff4542327c46e5
reproduction/Summarization/Baseline/transformer/Models.py
python
get_sinusoid_encoding_table
(n_position, d_hid, padding_idx=None)
return torch.FloatTensor(sinusoid_table)
Sinusoid position encoding table
Sinusoid position encoding table
[ "Sinusoid", "position", "encoding", "table" ]
def get_sinusoid_encoding_table(n_position, d_hid, padding_idx=None): ''' Sinusoid position encoding table ''' def cal_angle(position, hid_idx): return position / np.power(10000, 2 * (hid_idx // 2) / d_hid) def get_posi_angle_vec(position): return [cal_angle(position, hid_j) for hid_j in range(d_hid)] sinusoid_table = np.array([get_posi_angle_vec(pos_i) for pos_i in range(n_position)]) sinusoid_table[:, 0::2] = np.sin(sinusoid_table[:, 0::2]) # dim 2i sinusoid_table[:, 1::2] = np.cos(sinusoid_table[:, 1::2]) # dim 2i+1 if padding_idx is not None: # zero vector for padding dimension sinusoid_table[padding_idx] = 0. return torch.FloatTensor(sinusoid_table)
[ "def", "get_sinusoid_encoding_table", "(", "n_position", ",", "d_hid", ",", "padding_idx", "=", "None", ")", ":", "def", "cal_angle", "(", "position", ",", "hid_idx", ")", ":", "return", "position", "/", "np", ".", "power", "(", "10000", ",", "2", "*", "...
https://github.com/fastnlp/fastNLP/blob/fb645d370f4cc1b00c7dbb16c1ff4542327c46e5/reproduction/Summarization/Baseline/transformer/Models.py#L16-L34
LuxCoreRender/BlendLuxCore
bf31ca58501d54c02acd97001b6db7de81da7cbf
draw/viewport.py
python
FrameBuffer.__init__
(self, engine, context, scene)
[]
def __init__(self, engine, context, scene): filmsize = utils.calc_filmsize(scene, context) self._width, self._height = filmsize self._border = utils.calc_blender_border(scene, context) self._offset_x, self._offset_y = self._calc_offset(context, scene, self._border) self._pixel_size = int(scene.luxcore.viewport.pixel_size) if utils.is_valid_camera(scene.camera) and not utils.in_material_shading_mode(context): pipeline = scene.camera.data.luxcore.imagepipeline self._transparent = pipeline.transparent_film else: self._transparent = False if self._transparent: bufferdepth = 4 self._buffertype = bgl.GL_RGBA self._output_type = pyluxcore.FilmOutputType.RGBA_IMAGEPIPELINE else: bufferdepth = 3 self._buffertype = bgl.GL_RGB self._output_type = pyluxcore.FilmOutputType.RGB_IMAGEPIPELINE self.buffer = bgl.Buffer(bgl.GL_FLOAT, [self._width * self._height * bufferdepth]) self._init_opengl(engine, scene) # Denoiser self._noisy_file_path = self._make_denoiser_filepath("noisy") self._albedo_file_path = self._make_denoiser_filepath("albedo") self._normal_file_path = self._make_denoiser_filepath("normal") self._denoised_file_path = self._make_denoiser_filepath("denoised") current_dir = dirname(os.path.realpath(__file__)) addon_dir = dirname(current_dir) # Go up one level self._denoiser_path = which("oidnDenoise", path=os.path.join(addon_dir, "bin") + os.pathsep + os.environ["PATH"]) self._denoiser_process = None self.denoiser_result_cached = False
[ "def", "__init__", "(", "self", ",", "engine", ",", "context", ",", "scene", ")", ":", "filmsize", "=", "utils", ".", "calc_filmsize", "(", "scene", ",", "context", ")", "self", ".", "_width", ",", "self", ".", "_height", "=", "filmsize", "self", ".", ...
https://github.com/LuxCoreRender/BlendLuxCore/blob/bf31ca58501d54c02acd97001b6db7de81da7cbf/draw/viewport.py#L46-L81
jisaacks/GitGutter
1badb94bd1827f4b3f96fd90c26bf1b348783ff9
modules/handler.py
python
GitGutterHandler.diff_line_change
(self, row)
return ([], -1, -1, {})
Use cached diff result to extract the changes of a certain line. Arguments: row (int): The row to find the changes for Returns: tuple: The tuple contains 4 items of information about changes around the row with (deleted_lines, start, size, meta).
Use cached diff result to extract the changes of a certain line.
[ "Use", "cached", "diff", "result", "to", "extract", "the", "changes", "of", "a", "certain", "line", "." ]
def diff_line_change(self, row): """Use cached diff result to extract the changes of a certain line. Arguments: row (int): The row to find the changes for Returns: tuple: The tuple contains 4 items of information about changes around the row with (deleted_lines, start, size, meta). """ hunk_re = r'^@@ \-(\d+),?(\d*) \+(\d+),?(\d*) @@' hunks = re.finditer(hunk_re, self._git_diff_cache, re.MULTILINE) # if wrap is disable avoid wrapping wrap = self.settings.get('next_prev_change_wrap') # we also want to extract the position of the surrounding changes first_change = prev_change = next_change = None for hunk in hunks: _, _, start, size = hunk.groups() start = int(start) size = int(size or 1) if first_change is None: first_change = start # special handling to also match the line below deleted # content if size == 0 and row == start + 1: pass # continue if the hunk is before the line elif start + size < row: prev_change = start continue # break if the hunk is after the line elif row < start: break # in the following the line is inside the hunk try: next_hunk = next(hunks) hunk_end = next_hunk.start() next_change = int(next_hunk.group(3)) except: hunk_end = len(self._git_diff_cache) if not wrap: if prev_change is None: prev_change = start if next_change is None: next_change = start # if prev change is None set it to the wrap around the # document: prev -> last hunk, next -> first hunk if prev_change is None: try: remaining_hunks = list(hunks) if remaining_hunks: last_hunk = remaining_hunks[-1] prev_change = int(last_hunk.group(3)) elif next_change is not None: prev_change = next_change else: prev_change = start except: prev_change = start if next_change is None: next_change = first_change # extract the content of the hunk hunk_content = self._git_diff_cache[hunk.start():hunk_end] # store all deleted lines (starting with -) hunk_lines = hunk_content.splitlines()[1:] deleted_lines = [ line[1:] for line in hunk_lines if line.startswith("-") ] added_lines = [line[1:] for line in hunk_lines if line.startswith("+")] meta = { "added_lines": added_lines, "first_change": first_change, "next_change": next_change, "prev_change": prev_change } return (deleted_lines, start, size, meta) return ([], -1, -1, {})
[ "def", "diff_line_change", "(", "self", ",", "row", ")", ":", "hunk_re", "=", "r'^@@ \\-(\\d+),?(\\d*) \\+(\\d+),?(\\d*) @@'", "hunks", "=", "re", ".", "finditer", "(", "hunk_re", ",", "self", ".", "_git_diff_cache", ",", "re", ".", "MULTILINE", ")", "# if wrap ...
https://github.com/jisaacks/GitGutter/blob/1badb94bd1827f4b3f96fd90c26bf1b348783ff9/modules/handler.py#L478-L559
siegfried415/portia-dashboard
b1e116ea95afd736caf55df5d16e6da28c124eec
slybot/slybot/item.py
python
SlybotFieldDescriptor.__init__
(self, name, description, field_type_processor, required=False)
Create a new SlybotFieldDescriptor with the given name and description. The field_type_processor is used for extraction and is publicly available
Create a new SlybotFieldDescriptor with the given name and description. The field_type_processor is used for extraction and is publicly available
[ "Create", "a", "new", "SlybotFieldDescriptor", "with", "the", "given", "name", "and", "description", ".", "The", "field_type_processor", "is", "used", "for", "extraction", "and", "is", "publicly", "available" ]
def __init__(self, name, description, field_type_processor, required=False): """Create a new SlybotFieldDescriptor with the given name and description. The field_type_processor is used for extraction and is publicly available """ FieldDescriptor.__init__(self, name, description, field_type_processor.extract, required) # add an adapt method self.adapt = field_type_processor.adapt self._processor = field_type_processor
[ "def", "__init__", "(", "self", ",", "name", ",", "description", ",", "field_type_processor", ",", "required", "=", "False", ")", ":", "FieldDescriptor", ".", "__init__", "(", "self", ",", "name", ",", "description", ",", "field_type_processor", ".", "extract"...
https://github.com/siegfried415/portia-dashboard/blob/b1e116ea95afd736caf55df5d16e6da28c124eec/slybot/slybot/item.py#L61-L69
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/lib/python2.7/site-packages/sqlalchemy/sql/selectable.py
python
Select.append_from
(self, fromclause)
append the given FromClause expression to this select() construct's FROM clause. This is an **in-place** mutation method; the :meth:`~.Select.select_from` method is preferred, as it provides standard :term:`method chaining`.
append the given FromClause expression to this select() construct's FROM clause.
[ "append", "the", "given", "FromClause", "expression", "to", "this", "select", "()", "construct", "s", "FROM", "clause", "." ]
def append_from(self, fromclause): """append the given FromClause expression to this select() construct's FROM clause. This is an **in-place** mutation method; the :meth:`~.Select.select_from` method is preferred, as it provides standard :term:`method chaining`. """ self._reset_exported() fromclause = _interpret_as_from(fromclause) self._from_obj = self._from_obj.union([fromclause])
[ "def", "append_from", "(", "self", ",", "fromclause", ")", ":", "self", ".", "_reset_exported", "(", ")", "fromclause", "=", "_interpret_as_from", "(", "fromclause", ")", "self", ".", "_from_obj", "=", "self", ".", "_from_obj", ".", "union", "(", "[", "fro...
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/lib/python2.7/site-packages/sqlalchemy/sql/selectable.py#L3419-L3430
omz/PythonistaAppTemplate
f560f93f8876d82a21d108977f90583df08d55af
PythonistaAppTemplate/PythonistaKit.framework/pylib/SimpleXMLRPCServer.py
python
SimpleXMLRPCRequestHandler.log_request
(self, code='-', size='-')
Selectively log an accepted request.
Selectively log an accepted request.
[ "Selectively", "log", "an", "accepted", "request", "." ]
def log_request(self, code='-', size='-'): """Selectively log an accepted request.""" if self.server.logRequests: BaseHTTPServer.BaseHTTPRequestHandler.log_request(self, code, size)
[ "def", "log_request", "(", "self", ",", "code", "=", "'-'", ",", "size", "=", "'-'", ")", ":", "if", "self", ".", "server", ".", "logRequests", ":", "BaseHTTPServer", ".", "BaseHTTPRequestHandler", ".", "log_request", "(", "self", ",", "code", ",", "size...
https://github.com/omz/PythonistaAppTemplate/blob/f560f93f8876d82a21d108977f90583df08d55af/PythonistaAppTemplate/PythonistaKit.framework/pylib/SimpleXMLRPCServer.py#L563-L567
pympler/pympler
8019a883eec547d91ecda6ba12669d4f4504c625
pympler/classtracker.py
python
ClassTracker.__init__
(self, stream: Optional[IO] = None)
Creates a new `ClassTracker` object. :param stream: Output stream to use when printing statistics via ``stats``.
Creates a new `ClassTracker` object.
[ "Creates", "a", "new", "ClassTracker", "object", "." ]
def __init__(self, stream: Optional[IO] = None): """ Creates a new `ClassTracker` object. :param stream: Output stream to use when printing statistics via ``stats``. """ # Dictionaries of TrackedObject objects associated with the actual # objects that are tracked. 'index' uses the class name as the key and # associates a list of tracked objects. It contains all TrackedObject # instances, including those of dead objects. self.index = defaultdict(list) # type: Dict[str, List[TrackedObject]] # 'objects' uses the id (address) as the key and associates the tracked # object with it. TrackedObject's referring to dead objects are # replaced lazily, i.e. when the id is recycled by another tracked # object. self.objects = {} # type: Dict[int, Any] # List of `Snapshot` objects. self.snapshots = [] # type: List[Snapshot] # Time series of instance count for each tracked class. self.history = defaultdict(list) \ # type: Dict[str, List[Tuple[float, int]]] # Keep objects alive by holding a strong reference. self._keepalive = [] # type: List[Any] # Dictionary of class observers identified by classname. self._observers = {} # type: Dict[type, _ClassObserver] # Thread object responsible for background monitoring self._periodic_thread = None # type: Optional[PeriodicThread] self._stream = stream
[ "def", "__init__", "(", "self", ",", "stream", ":", "Optional", "[", "IO", "]", "=", "None", ")", ":", "# Dictionaries of TrackedObject objects associated with the actual", "# objects that are tracked. 'index' uses the class name as the key and", "# associates a list of tracked obj...
https://github.com/pympler/pympler/blob/8019a883eec547d91ecda6ba12669d4f4504c625/pympler/classtracker.py#L258-L293
pazz/alot
52f11f089df19cf336ad0983368e880dc5364149
alot/buffers/thread.py
python
ThreadBuffer.focus_selected_message
(self)
focus the summary line of currently focussed message
focus the summary line of currently focussed message
[ "focus", "the", "summary", "line", "of", "currently", "focussed", "message" ]
def focus_selected_message(self): """focus the summary line of currently focussed message""" # move focus to summary (root of current MessageTree) self.set_focus(self.get_selected_message_position())
[ "def", "focus_selected_message", "(", "self", ")", ":", "# move focus to summary (root of current MessageTree)", "self", ".", "set_focus", "(", "self", ".", "get_selected_message_position", "(", ")", ")" ]
https://github.com/pazz/alot/blob/52f11f089df19cf336ad0983368e880dc5364149/alot/buffers/thread.py#L196-L199
TheAlgorithms/Python
9af2eef9b3761bf51580dedfb6fa7136ca0c5c2c
dynamic_programming/max_sub_array.py
python
max_sub_array
(nums: list[int])
return best
Finds the contiguous subarray which has the largest sum and return its sum. >>> max_sub_array([-2, 1, -3, 4, -1, 2, 1, -5, 4]) 6 An empty (sub)array has sum 0. >>> max_sub_array([]) 0 If all elements are negative, the largest subarray would be the empty array, having the sum 0. >>> max_sub_array([-1, -2, -3]) 0 >>> max_sub_array([5, -2, -3]) 5 >>> max_sub_array([31, -41, 59, 26, -53, 58, 97, -93, -23, 84]) 187
Finds the contiguous subarray which has the largest sum and return its sum.
[ "Finds", "the", "contiguous", "subarray", "which", "has", "the", "largest", "sum", "and", "return", "its", "sum", "." ]
def max_sub_array(nums: list[int]) -> int: """ Finds the contiguous subarray which has the largest sum and return its sum. >>> max_sub_array([-2, 1, -3, 4, -1, 2, 1, -5, 4]) 6 An empty (sub)array has sum 0. >>> max_sub_array([]) 0 If all elements are negative, the largest subarray would be the empty array, having the sum 0. >>> max_sub_array([-1, -2, -3]) 0 >>> max_sub_array([5, -2, -3]) 5 >>> max_sub_array([31, -41, 59, 26, -53, 58, 97, -93, -23, 84]) 187 """ best = 0 current = 0 for i in nums: current += i if current < 0: current = 0 best = max(best, current) return best
[ "def", "max_sub_array", "(", "nums", ":", "list", "[", "int", "]", ")", "->", "int", ":", "best", "=", "0", "current", "=", "0", "for", "i", "in", "nums", ":", "current", "+=", "i", "if", "current", "<", "0", ":", "current", "=", "0", "best", "...
https://github.com/TheAlgorithms/Python/blob/9af2eef9b3761bf51580dedfb6fa7136ca0c5c2c/dynamic_programming/max_sub_array.py#L41-L68
roglew/guppy-proxy
01df16be71dd9f23d7de415a315821659c29bc63
guppyproxy/proxy.py
python
HTTPRequest.body
(self, bs)
[]
def body(self, bs): self.headers_only = False if type(bs) is str: self._body = bs.encode() elif type(bs) is bytes: self._body = bs else: raise Exception("invalid body type: {}".format(type(bs))) self.headers.set("Content-Length", str(len(self._body)))
[ "def", "body", "(", "self", ",", "bs", ")", ":", "self", ".", "headers_only", "=", "False", "if", "type", "(", "bs", ")", "is", "str", ":", "self", ".", "_body", "=", "bs", ".", "encode", "(", ")", "elif", "type", "(", "bs", ")", "is", "bytes",...
https://github.com/roglew/guppy-proxy/blob/01df16be71dd9f23d7de415a315821659c29bc63/guppyproxy/proxy.py#L339-L347
googleads/google-ads-python
2a1d6062221f6aad1992a6bcca0e7e4a93d2db86
google/ads/googleads/v9/services/services/feed_item_set_service/client.py
python
FeedItemSetServiceClient.parse_common_organization_path
(path: str)
return m.groupdict() if m else {}
Parse a organization path into its component segments.
Parse a organization path into its component segments.
[ "Parse", "a", "organization", "path", "into", "its", "component", "segments", "." ]
def parse_common_organization_path(path: str) -> Dict[str, str]: """Parse a organization path into its component segments.""" m = re.match(r"^organizations/(?P<organization>.+?)$", path) return m.groupdict() if m else {}
[ "def", "parse_common_organization_path", "(", "path", ":", "str", ")", "->", "Dict", "[", "str", ",", "str", "]", ":", "m", "=", "re", ".", "match", "(", "r\"^organizations/(?P<organization>.+?)$\"", ",", "path", ")", "return", "m", ".", "groupdict", "(", ...
https://github.com/googleads/google-ads-python/blob/2a1d6062221f6aad1992a6bcca0e7e4a93d2db86/google/ads/googleads/v9/services/services/feed_item_set_service/client.py#L240-L243
gwpy/gwpy
82becd78d166a32985cb657a54d0d39f6a207739
gwpy/plot/gps.py
python
GPSScale.get_transform
(self)
[]
def get_transform(self): # get current settings epoch = self.get_epoch() unit = self.get_unit() # dynamically set epoch and/or unit if None if unit is None: self.set_unit(self._auto_unit(self.axis)) if epoch is None: self.set_epoch(self._auto_epoch(self.axis)) # build transform on-the-fly try: return self.GPSTransform(unit=self.get_unit(), epoch=self.get_epoch()) finally: # reset to current settings self.set_epoch(epoch) self.set_unit(unit)
[ "def", "get_transform", "(", "self", ")", ":", "# get current settings", "epoch", "=", "self", ".", "get_epoch", "(", ")", "unit", "=", "self", ".", "get_unit", "(", ")", "# dynamically set epoch and/or unit if None", "if", "unit", "is", "None", ":", "self", "...
https://github.com/gwpy/gwpy/blob/82becd78d166a32985cb657a54d0d39f6a207739/gwpy/plot/gps.py#L455-L472
openbmc/openbmc
5f4109adae05f4d6925bfe960007d52f98c61086
meta-security/lib/oeqa/runtime/cases/smack.py
python
SmackChangeSelfLabelPrivilege.test_privileged_change_self_label
(self)
Test if privileged process (with CAP_MAC_ADMIN privilege) can change its label.
Test if privileged process (with CAP_MAC_ADMIN privilege) can change its label.
[ "Test", "if", "privileged", "process", "(", "with", "CAP_MAC_ADMIN", "privilege", ")", "can", "change", "its", "label", "." ]
def test_privileged_change_self_label(self): '''Test if privileged process (with CAP_MAC_ADMIN privilege) can change its label. ''' labelf = "/proc/self/attr/current" command = "/bin/sh -c 'echo PRIVILEGED >%s; cat %s'" %(labelf, labelf) status, output = self.target.run( "notroot.py 0 %s %s" %(self.current_label, command)) self.assertIn("PRIVILEGED", output, "Privilege process did not change label.Output: %s" %output)
[ "def", "test_privileged_change_self_label", "(", "self", ")", ":", "labelf", "=", "\"/proc/self/attr/current\"", "command", "=", "\"/bin/sh -c 'echo PRIVILEGED >%s; cat %s'\"", "%", "(", "labelf", ",", "labelf", ")", "status", ",", "output", "=", "self", ".", "target"...
https://github.com/openbmc/openbmc/blob/5f4109adae05f4d6925bfe960007d52f98c61086/meta-security/lib/oeqa/runtime/cases/smack.py#L134-L146
AppScale/gts
46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9
AppServer/lib/django-1.2/django/db/backends/__init__.py
python
BaseDatabaseIntrospection.sequence_list
(self)
return sequence_list
Returns a list of information about all DB sequences for all models in all apps.
Returns a list of information about all DB sequences for all models in all apps.
[ "Returns", "a", "list", "of", "information", "about", "all", "DB", "sequences", "for", "all", "models", "in", "all", "apps", "." ]
def sequence_list(self): "Returns a list of information about all DB sequences for all models in all apps." from django.db import models, router apps = models.get_apps() sequence_list = [] for app in apps: for model in models.get_models(app): if not model._meta.managed: continue if not router.allow_syncdb(self.connection.alias, model): continue for f in model._meta.local_fields: if isinstance(f, models.AutoField): sequence_list.append({'table': model._meta.db_table, 'column': f.column}) break # Only one AutoField is allowed per model, so don't bother continuing. for f in model._meta.local_many_to_many: # If this is an m2m using an intermediate table, # we don't need to reset the sequence. if f.rel.through is None: sequence_list.append({'table': f.m2m_db_table(), 'column': None}) return sequence_list
[ "def", "sequence_list", "(", "self", ")", ":", "from", "django", ".", "db", "import", "models", ",", "router", "apps", "=", "models", ".", "get_apps", "(", ")", "sequence_list", "=", "[", "]", "for", "app", "in", "apps", ":", "for", "model", "in", "m...
https://github.com/AppScale/gts/blob/46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9/AppServer/lib/django-1.2/django/db/backends/__init__.py#L541-L565
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/helpers/entity_registry.py
python
async_setup_entity_restore
(hass: HomeAssistant, registry: EntityRegistry)
Set up the entity restore mechanism.
Set up the entity restore mechanism.
[ "Set", "up", "the", "entity", "restore", "mechanism", "." ]
def async_setup_entity_restore(hass: HomeAssistant, registry: EntityRegistry) -> None: """Set up the entity restore mechanism.""" @callback def cleanup_restored_states_filter(event: Event) -> bool: """Clean up restored states filter.""" return bool(event.data["action"] == "remove") @callback def cleanup_restored_states(event: Event) -> None: """Clean up restored states.""" state = hass.states.get(event.data["entity_id"]) if state is None or not state.attributes.get(ATTR_RESTORED): return hass.states.async_remove(event.data["entity_id"], context=event.context) hass.bus.async_listen( EVENT_ENTITY_REGISTRY_UPDATED, cleanup_restored_states, event_filter=cleanup_restored_states_filter, ) if hass.is_running: return @callback def _write_unavailable_states(_: Event) -> None: """Make sure state machine contains entry for each registered entity.""" existing = set(hass.states.async_entity_ids()) for entry in registry.entities.values(): if entry.entity_id in existing or entry.disabled: continue entry.write_unavailable_state(hass) hass.bus.async_listen(EVENT_HOMEASSISTANT_START, _write_unavailable_states)
[ "def", "async_setup_entity_restore", "(", "hass", ":", "HomeAssistant", ",", "registry", ":", "EntityRegistry", ")", "->", "None", ":", "@", "callback", "def", "cleanup_restored_states_filter", "(", "event", ":", "Event", ")", "->", "bool", ":", "\"\"\"Clean up re...
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/helpers/entity_registry.py#L801-L839
holzschu/Carnets
44effb10ddfc6aa5c8b0687582a724ba82c6b547
Library/lib/python3.7/site-packages/pandas-0.24.2-py3.7-macosx-10.9-x86_64.egg/pandas/core/generic.py
python
NDFrame._reindex_axes
(self, axes, level, limit, tolerance, method, fill_value, copy)
return obj
Perform the reindex for all the axes.
Perform the reindex for all the axes.
[ "Perform", "the", "reindex", "for", "all", "the", "axes", "." ]
def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy): """Perform the reindex for all the axes.""" obj = self for a in self._AXIS_ORDERS: labels = axes[a] if labels is None: continue ax = self._get_axis(a) new_index, indexer = ax.reindex(labels, level=level, limit=limit, tolerance=tolerance, method=method) axis = self._get_axis_number(a) obj = obj._reindex_with_indexers({axis: [new_index, indexer]}, fill_value=fill_value, copy=copy, allow_dups=False) return obj
[ "def", "_reindex_axes", "(", "self", ",", "axes", ",", "level", ",", "limit", ",", "tolerance", ",", "method", ",", "fill_value", ",", "copy", ")", ":", "obj", "=", "self", "for", "a", "in", "self", ".", "_AXIS_ORDERS", ":", "labels", "=", "axes", "[...
https://github.com/holzschu/Carnets/blob/44effb10ddfc6aa5c8b0687582a724ba82c6b547/Library/lib/python3.7/site-packages/pandas-0.24.2-py3.7-macosx-10.9-x86_64.egg/pandas/core/generic.py#L4358-L4376
MobileChromeApps/mobile-chrome-apps
ab60c264e23624917a8ac9973d43a0b44e5f96c4
chrome-cordova/gcmServer/xmpp/protocol.py
python
DataItem.setField
(self,name)
return self.addChild(node=DataField(name))
Create if nessessary or get the existing datafield object with name 'name' and return it.
Create if nessessary or get the existing datafield object with name 'name' and return it.
[ "Create", "if", "nessessary", "or", "get", "the", "existing", "datafield", "object", "with", "name", "name", "and", "return", "it", "." ]
def setField(self,name): """ Create if nessessary or get the existing datafield object with name 'name' and return it. """ f=self.getField(name) if f: return f return self.addChild(node=DataField(name))
[ "def", "setField", "(", "self", ",", "name", ")", ":", "f", "=", "self", ".", "getField", "(", "name", ")", "if", "f", ":", "return", "f", "return", "self", ".", "addChild", "(", "node", "=", "DataField", "(", "name", ")", ")" ]
https://github.com/MobileChromeApps/mobile-chrome-apps/blob/ab60c264e23624917a8ac9973d43a0b44e5f96c4/chrome-cordova/gcmServer/xmpp/protocol.py#L743-L747
tp4a/teleport
1fafd34f1f775d2cf80ea4af6e44468d8e0b24ad
server/www/packages/packages-windows/x86/mako/util.py
python
update_wrapper
(decorated, fn)
return decorated
[]
def update_wrapper(decorated, fn): decorated.__wrapped__ = fn decorated.__name__ = fn.__name__ return decorated
[ "def", "update_wrapper", "(", "decorated", ",", "fn", ")", ":", "decorated", ".", "__wrapped__", "=", "fn", "decorated", ".", "__name__", "=", "fn", ".", "__name__", "return", "decorated" ]
https://github.com/tp4a/teleport/blob/1fafd34f1f775d2cf80ea4af6e44468d8e0b24ad/server/www/packages/packages-windows/x86/mako/util.py#L19-L22
microsoft/azure-devops-python-api
451cade4c475482792cbe9e522c1fee32393139e
azure-devops/azure/devops/v5_1/git/git_client_base.py
python
GitClientBase.get_pull_request_iterations
(self, repository_id, pull_request_id, project=None, include_commits=None)
return self._deserialize('[GitPullRequestIteration]', self._unwrap_collection(response))
GetPullRequestIterations. Get the list of iterations for the specified pull request. :param str repository_id: ID or name of the repository. :param int pull_request_id: ID of the pull request. :param str project: Project ID or project name :param bool include_commits: If true, include the commits associated with each iteration in the response. :rtype: [GitPullRequestIteration]
GetPullRequestIterations. Get the list of iterations for the specified pull request. :param str repository_id: ID or name of the repository. :param int pull_request_id: ID of the pull request. :param str project: Project ID or project name :param bool include_commits: If true, include the commits associated with each iteration in the response. :rtype: [GitPullRequestIteration]
[ "GetPullRequestIterations", ".", "Get", "the", "list", "of", "iterations", "for", "the", "specified", "pull", "request", ".", ":", "param", "str", "repository_id", ":", "ID", "or", "name", "of", "the", "repository", ".", ":", "param", "int", "pull_request_id",...
def get_pull_request_iterations(self, repository_id, pull_request_id, project=None, include_commits=None): """GetPullRequestIterations. Get the list of iterations for the specified pull request. :param str repository_id: ID or name of the repository. :param int pull_request_id: ID of the pull request. :param str project: Project ID or project name :param bool include_commits: If true, include the commits associated with each iteration in the response. :rtype: [GitPullRequestIteration] """ route_values = {} if project is not None: route_values['project'] = self._serialize.url('project', project, 'str') if repository_id is not None: route_values['repositoryId'] = self._serialize.url('repository_id', repository_id, 'str') if pull_request_id is not None: route_values['pullRequestId'] = self._serialize.url('pull_request_id', pull_request_id, 'int') query_parameters = {} if include_commits is not None: query_parameters['includeCommits'] = self._serialize.query('include_commits', include_commits, 'bool') response = self._send(http_method='GET', location_id='d43911ee-6958-46b0-a42b-8445b8a0d004', version='5.1', route_values=route_values, query_parameters=query_parameters) return self._deserialize('[GitPullRequestIteration]', self._unwrap_collection(response))
[ "def", "get_pull_request_iterations", "(", "self", ",", "repository_id", ",", "pull_request_id", ",", "project", "=", "None", ",", "include_commits", "=", "None", ")", ":", "route_values", "=", "{", "}", "if", "project", "is", "not", "None", ":", "route_values...
https://github.com/microsoft/azure-devops-python-api/blob/451cade4c475482792cbe9e522c1fee32393139e/azure-devops/azure/devops/v5_1/git/git_client_base.py#L1531-L1555
sightmachine/SimpleCV
6c4d61b6d1d9d856b471910107cad0838954d2b2
SimpleCV/MachineLearning/query_imgs/flickrapi2.py
python
FlickrAPI.__getCachedToken
(self)
Read and return a cached token, or None if not found. The token is read from the cached token file, which is basically the entire RSP response containing the auth element.
Read and return a cached token, or None if not found.
[ "Read", "and", "return", "a", "cached", "token", "or", "None", "if", "not", "found", "." ]
def __getCachedToken(self): """Read and return a cached token, or None if not found. The token is read from the cached token file, which is basically the entire RSP response containing the auth element. """ try: f = file(self.__getCachedTokenFilename(), "r") data = f.read() f.close() rsp = XMLNode.parseXML(data) return rsp.auth[0].token[0].elementText except IOError: return None
[ "def", "__getCachedToken", "(", "self", ")", ":", "try", ":", "f", "=", "file", "(", "self", ".", "__getCachedTokenFilename", "(", ")", ",", "\"r\"", ")", "data", "=", "f", ".", "read", "(", ")", "f", ".", "close", "(", ")", "rsp", "=", "XMLNode", ...
https://github.com/sightmachine/SimpleCV/blob/6c4d61b6d1d9d856b471910107cad0838954d2b2/SimpleCV/MachineLearning/query_imgs/flickrapi2.py#L403-L421
openshift/openshift-tools
1188778e728a6e4781acf728123e5b356380fe6f
openshift/installer/vendored/openshift-ansible-3.9.14-1/roles/lib_vendored_deps/library/oc_adm_manage_node.py
python
Utils._write
(filename, contents)
Actually write the file contents to disk. This helps with mocking.
Actually write the file contents to disk. This helps with mocking.
[ "Actually", "write", "the", "file", "contents", "to", "disk", ".", "This", "helps", "with", "mocking", "." ]
def _write(filename, contents): ''' Actually write the file contents to disk. This helps with mocking. ''' with open(filename, 'w') as sfd: sfd.write(str(contents))
[ "def", "_write", "(", "filename", ",", "contents", ")", ":", "with", "open", "(", "filename", ",", "'w'", ")", "as", "sfd", ":", "sfd", ".", "write", "(", "str", "(", "contents", ")", ")" ]
https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/openshift/installer/vendored/openshift-ansible-3.9.14-1/roles/lib_vendored_deps/library/oc_adm_manage_node.py#L1176-L1180
kamalgill/flask-appengine-template
11760f83faccbb0d0afe416fc58e67ecfb4643c2
src/lib/click/core.py
python
Parameter.__init__
(self, param_decls=None, type=None, required=False, default=None, callback=None, nargs=None, metavar=None, expose_value=True, is_eager=False, envvar=None)
[]
def __init__(self, param_decls=None, type=None, required=False, default=None, callback=None, nargs=None, metavar=None, expose_value=True, is_eager=False, envvar=None): self.name, self.opts, self.secondary_opts = \ self._parse_decls(param_decls or (), expose_value) self.type = convert_type(type, default) # Default nargs to what the type tells us if we have that # information available. if nargs is None: if self.type.is_composite: nargs = self.type.arity else: nargs = 1 self.required = required self.callback = callback self.nargs = nargs self.multiple = False self.expose_value = expose_value self.default = default self.is_eager = is_eager self.metavar = metavar self.envvar = envvar
[ "def", "__init__", "(", "self", ",", "param_decls", "=", "None", ",", "type", "=", "None", ",", "required", "=", "False", ",", "default", "=", "None", ",", "callback", "=", "None", ",", "nargs", "=", "None", ",", "metavar", "=", "None", ",", "expose_...
https://github.com/kamalgill/flask-appengine-template/blob/11760f83faccbb0d0afe416fc58e67ecfb4643c2/src/lib/click/core.py#L1262-L1286
laszukdawid/PyEMD
9caf51c6cd1bc1e869d67d002310c1e81cba541a
PyEMD/compact.py
python
pade6
(vec, h)
return TDMAsolver(Da, Db, Dc, rhs)
6th Order compact finite difference scheme (non-periodic BC). Lele, S. K. - Compact finite difference schemes with spectral-like resolution. Journal of Computational Physics 103 (1992) 16-42
6th Order compact finite difference scheme (non-periodic BC).
[ "6th", "Order", "compact", "finite", "difference", "scheme", "(", "non", "-", "periodic", "BC", ")", "." ]
def pade6(vec, h): """ 6th Order compact finite difference scheme (non-periodic BC). Lele, S. K. - Compact finite difference schemes with spectral-like resolution. Journal of Computational Physics 103 (1992) 16-42 """ n = len(vec) rhs = np.zeros(n) a = 14.0 / 18.0 b = 1.0 / 36.0 rhs[2:-2] = (vec[3:-1] - vec[1:-3]) * (a / h) + (vec[4:] - vec[0:-4]) * (b / h) # boundaries: rhs[0] = ( (-197.0 / 60.0) * vec[0] + (-5.0 / 12.0) * vec[1] + 5.0 * vec[2] + (-5.0 / 3.0) * vec[3] + (5.0 / 12.0) * vec[4] + (-1.0 / 20.0) * vec[5] ) / h rhs[1] = ( (-20.0 / 33.0) * vec[0] + (-35.0 / 132.0) * vec[1] + (34.0 / 33.0) * vec[2] + (-7.0 / 33.0) * vec[3] + (2.0 / 33.0) * vec[4] + (-1.0 / 132.0) * vec[5] ) / h rhs[-1] = ( (197.0 / 60.0) * vec[-1] + (5.0 / 12.0) * vec[-2] + (-5.0) * vec[-3] + (5.0 / 3.0) * vec[-4] + (-5.0 / 12.0) * vec[-5] + (1.0 / 20.0) * vec[-6] ) / h rhs[-2] = ( (20.0 / 33.0) * vec[-1] + (35.0 / 132.0) * vec[-2] + (-34.0 / 33.0) * vec[-3] + (7.0 / 33.0) * vec[-4] + (-2.0 / 33.0) * vec[-5] + (1.0 / 132.0) * vec[-6] ) / h alpha1 = 5.0 # j = 1 and n alpha2 = 2.0 / 11 # j = 2 and n-1 alpha = 1.0 / 3.0 Db = np.ones(n) Da = alpha * np.ones(n) Dc = alpha * np.ones(n) # boundaries: Da[1] = alpha2 Da[-1] = alpha1 Da[-2] = alpha2 Dc[0] = alpha1 Dc[1] = alpha2 Dc[-2] = alpha2 return TDMAsolver(Da, Db, Dc, rhs)
[ "def", "pade6", "(", "vec", ",", "h", ")", ":", "n", "=", "len", "(", "vec", ")", "rhs", "=", "np", ".", "zeros", "(", "n", ")", "a", "=", "14.0", "/", "18.0", "b", "=", "1.0", "/", "36.0", "rhs", "[", "2", ":", "-", "2", "]", "=", "(",...
https://github.com/laszukdawid/PyEMD/blob/9caf51c6cd1bc1e869d67d002310c1e81cba541a/PyEMD/compact.py#L93-L161
golismero/golismero
7d605b937e241f51c1ca4f47b20f755eeefb9d76
thirdparty_libs/django/http/request.py
python
QueryDict.copy
(self)
return self.__deepcopy__({})
Returns a mutable copy of this object.
Returns a mutable copy of this object.
[ "Returns", "a", "mutable", "copy", "of", "this", "object", "." ]
def copy(self): """Returns a mutable copy of this object.""" return self.__deepcopy__({})
[ "def", "copy", "(", "self", ")", ":", "return", "self", ".", "__deepcopy__", "(", "{", "}", ")" ]
https://github.com/golismero/golismero/blob/7d605b937e241f51c1ca4f47b20f755eeefb9d76/thirdparty_libs/django/http/request.py#L366-L368
encode/django-rest-framework
c5be86a6dbf3d21b00a296af5994fa075826bf0b
rest_framework/schemas/coreapi.py
python
is_enabled
()
return issubclass(api_settings.DEFAULT_SCHEMA_CLASS, AutoSchema)
Is CoreAPI Mode enabled?
Is CoreAPI Mode enabled?
[ "Is", "CoreAPI", "Mode", "enabled?" ]
def is_enabled(): """Is CoreAPI Mode enabled?""" return issubclass(api_settings.DEFAULT_SCHEMA_CLASS, AutoSchema)
[ "def", "is_enabled", "(", ")", ":", "return", "issubclass", "(", "api_settings", ".", "DEFAULT_SCHEMA_CLASS", ",", "AutoSchema", ")" ]
https://github.com/encode/django-rest-framework/blob/c5be86a6dbf3d21b00a296af5994fa075826bf0b/rest_framework/schemas/coreapi.py#L610-L612
pwnieexpress/pwn_plug_sources
1a23324f5dc2c3de20f9c810269b6a29b2758cad
src/plecost/xgoogle/BeautifulSoup.py
python
PageElement.substituteEncoding
(self, str, encoding=None)
return str.replace("%SOUP-ENCODING%", encoding)
[]
def substituteEncoding(self, str, encoding=None): encoding = encoding or "utf-8" return str.replace("%SOUP-ENCODING%", encoding)
[ "def", "substituteEncoding", "(", "self", ",", "str", ",", "encoding", "=", "None", ")", ":", "encoding", "=", "encoding", "or", "\"utf-8\"", "return", "str", ".", "replace", "(", "\"%SOUP-ENCODING%\"", ",", "encoding", ")" ]
https://github.com/pwnieexpress/pwn_plug_sources/blob/1a23324f5dc2c3de20f9c810269b6a29b2758cad/src/plecost/xgoogle/BeautifulSoup.py#L370-L372
securityclippy/elasticintel
aa08d3e9f5ab1c000128e95161139ce97ff0e334
ingest_feed_lambda/pandas/io/formats/style.py
python
Styler._translate
(self)
return dict(head=head, cellstyle=cellstyle, body=body, uuid=uuid, precision=precision, table_styles=table_styles, caption=caption, table_attributes=self.table_attributes)
Convert the DataFrame in `self.data` and the attrs from `_build_styles` into a dictionary of {head, body, uuid, cellstyle}
Convert the DataFrame in `self.data` and the attrs from `_build_styles` into a dictionary of {head, body, uuid, cellstyle}
[ "Convert", "the", "DataFrame", "in", "self", ".", "data", "and", "the", "attrs", "from", "_build_styles", "into", "a", "dictionary", "of", "{", "head", "body", "uuid", "cellstyle", "}" ]
def _translate(self): """ Convert the DataFrame in `self.data` and the attrs from `_build_styles` into a dictionary of {head, body, uuid, cellstyle} """ table_styles = self.table_styles or [] caption = self.caption ctx = self.ctx precision = self.precision uuid = self.uuid or str(uuid1()).replace("-", "_") ROW_HEADING_CLASS = "row_heading" COL_HEADING_CLASS = "col_heading" INDEX_NAME_CLASS = "index_name" DATA_CLASS = "data" BLANK_CLASS = "blank" BLANK_VALUE = "" def format_attr(pair): return "{key}={value}".format(**pair) # for sparsifying a MultiIndex idx_lengths = _get_level_lengths(self.index) col_lengths = _get_level_lengths(self.columns) cell_context = dict() n_rlvls = self.data.index.nlevels n_clvls = self.data.columns.nlevels rlabels = self.data.index.tolist() clabels = self.data.columns.tolist() if n_rlvls == 1: rlabels = [[x] for x in rlabels] if n_clvls == 1: clabels = [[x] for x in clabels] clabels = list(zip(*clabels)) cellstyle = [] head = [] for r in range(n_clvls): # Blank for Index columns... row_es = [{"type": "th", "value": BLANK_VALUE, "display_value": BLANK_VALUE, "is_visible": True, "class": " ".join([BLANK_CLASS])}] * (n_rlvls - 1) # ... except maybe the last for columns.names name = self.data.columns.names[r] cs = [BLANK_CLASS if name is None else INDEX_NAME_CLASS, "level{lvl}".format(lvl=r)] name = BLANK_VALUE if name is None else name row_es.append({"type": "th", "value": name, "display_value": name, "class": " ".join(cs), "is_visible": True}) if clabels: for c, value in enumerate(clabels[r]): cs = [COL_HEADING_CLASS, "level{lvl}".format(lvl=r), "col{col}".format(col=c)] cs.extend(cell_context.get( "col_headings", {}).get(r, {}).get(c, [])) es = { "type": "th", "value": value, "display_value": value, "class": " ".join(cs), "is_visible": _is_visible(c, r, col_lengths), } colspan = col_lengths.get((r, c), 0) if colspan > 1: es["attributes"] = [ format_attr({"key": "colspan", "value": colspan}) ] row_es.append(es) head.append(row_es) if self.data.index.names and _any_not_none(*self.data.index.names): index_header_row = [] for c, name in enumerate(self.data.index.names): cs = [INDEX_NAME_CLASS, "level{lvl}".format(lvl=c)] name = '' if name is None else name index_header_row.append({"type": "th", "value": name, "class": " ".join(cs)}) index_header_row.extend( [{"type": "th", "value": BLANK_VALUE, "class": " ".join([BLANK_CLASS]) }] * len(clabels[0])) head.append(index_header_row) body = [] for r, idx in enumerate(self.data.index): row_es = [] for c, value in enumerate(rlabels[r]): rid = [ROW_HEADING_CLASS, "level{lvl}".format(lvl=c), "row{row}".format(row=r)] es = { "type": "th", "is_visible": _is_visible(r, c, idx_lengths), "value": value, "display_value": value, "id": "_".join(rid[1:]), "class": " ".join(rid) } rowspan = idx_lengths.get((c, r), 0) if rowspan > 1: es["attributes"] = [ format_attr({"key": "rowspan", "value": rowspan}) ] row_es.append(es) for c, col in enumerate(self.data.columns): cs = [DATA_CLASS, "row{row}".format(row=r), "col{col}".format(col=c)] cs.extend(cell_context.get("data", {}).get(r, {}).get(c, [])) formatter = self._display_funcs[(r, c)] value = self.data.iloc[r, c] row_es.append({ "type": "td", "value": value, "class": " ".join(cs), "id": "_".join(cs[1:]), "display_value": formatter(value) }) props = [] for x in ctx[r, c]: # have to handle empty styles like [''] if x.count(":"): props.append(x.split(":")) else: props.append(['', '']) cellstyle.append({'props': props, 'selector': "row{row}_col{col}" .format(row=r, col=c)}) body.append(row_es) return dict(head=head, cellstyle=cellstyle, body=body, uuid=uuid, precision=precision, table_styles=table_styles, caption=caption, table_attributes=self.table_attributes)
[ "def", "_translate", "(", "self", ")", ":", "table_styles", "=", "self", ".", "table_styles", "or", "[", "]", "caption", "=", "self", ".", "caption", "ctx", "=", "self", ".", "ctx", "precision", "=", "self", ".", "precision", "uuid", "=", "self", ".", ...
https://github.com/securityclippy/elasticintel/blob/aa08d3e9f5ab1c000128e95161139ce97ff0e334/ingest_feed_lambda/pandas/io/formats/style.py#L181-L328
davidhalter/parso
ee5edaf22ff3941cbdfa4efd8cb3e8f69779fd56
parso/python/tree.py
python
Module.__init__
(self, children)
[]
def __init__(self, children): super().__init__(children) self._used_names = None
[ "def", "__init__", "(", "self", ",", "children", ")", ":", "super", "(", ")", ".", "__init__", "(", "children", ")", "self", ".", "_used_names", "=", "None" ]
https://github.com/davidhalter/parso/blob/ee5edaf22ff3941cbdfa4efd8cb3e8f69779fd56/parso/python/tree.py#L386-L388
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/rings/number_field/number_field_ideal.py
python
basis_to_module
(B, K)
return M.span_of_basis(C)
r""" Given a basis `B` of elements for a `\ZZ`-submodule of a number field `K`, return the corresponding `\ZZ`-submodule. EXAMPLES:: sage: K.<w> = NumberField(x^4 + 1) sage: from sage.rings.number_field.number_field_ideal import basis_to_module sage: basis_to_module([K.0, K.0^2 + 3], K) Free module of degree 4 and rank 2 over Integer Ring User basis matrix: [0 1 0 0] [3 0 1 0]
r""" Given a basis `B` of elements for a `\ZZ`-submodule of a number field `K`, return the corresponding `\ZZ`-submodule.
[ "r", "Given", "a", "basis", "B", "of", "elements", "for", "a", "\\", "ZZ", "-", "submodule", "of", "a", "number", "field", "K", "return", "the", "corresponding", "\\", "ZZ", "-", "submodule", "." ]
def basis_to_module(B, K): r""" Given a basis `B` of elements for a `\ZZ`-submodule of a number field `K`, return the corresponding `\ZZ`-submodule. EXAMPLES:: sage: K.<w> = NumberField(x^4 + 1) sage: from sage.rings.number_field.number_field_ideal import basis_to_module sage: basis_to_module([K.0, K.0^2 + 3], K) Free module of degree 4 and rank 2 over Integer Ring User basis matrix: [0 1 0 0] [3 0 1 0] """ V, from_V, to_V = K.absolute_vector_space() M = ZZ**(V.dimension()) C = [to_V(K(b)) for b in B] return M.span_of_basis(C)
[ "def", "basis_to_module", "(", "B", ",", "K", ")", ":", "V", ",", "from_V", ",", "to_V", "=", "K", ".", "absolute_vector_space", "(", ")", "M", "=", "ZZ", "**", "(", "V", ".", "dimension", "(", ")", ")", "C", "=", "[", "to_V", "(", "K", "(", ...
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/rings/number_field/number_field_ideal.py#L1693-L1711
lxtGH/OctaveConv_pytorch
079f7da29d55c2eeed8985d33f0b2f765d7a469e
libs/nn/resnet_adaptiveconv.py
python
PixelAwareResnet50
(pretrained=False, **kwargs)
return model
Constructs a ResNet-50 model. Args: pretrained (bool): If True, returns a model pre-trained on ImageNet
Constructs a ResNet-50 model.
[ "Constructs", "a", "ResNet", "-", "50", "model", "." ]
def PixelAwareResnet50(pretrained=False, **kwargs): """Constructs a ResNet-50 model. Args: pretrained (bool): If True, returns a model pre-trained on ImageNet """ model = ResNet(PixelAwareAdaptiveBottleneck, [3, 4, 6, 3], **kwargs) return model
[ "def", "PixelAwareResnet50", "(", "pretrained", "=", "False", ",", "*", "*", "kwargs", ")", ":", "model", "=", "ResNet", "(", "PixelAwareAdaptiveBottleneck", ",", "[", "3", ",", "4", ",", "6", ",", "3", "]", ",", "*", "*", "kwargs", ")", "return", "m...
https://github.com/lxtGH/OctaveConv_pytorch/blob/079f7da29d55c2eeed8985d33f0b2f765d7a469e/libs/nn/resnet_adaptiveconv.py#L278-L285
catalyst-team/catalyst
678dc06eda1848242df010b7f34adb572def2598
catalyst/callbacks/scheduler.py
python
LRFinder.on_batch_end
(self, runner: "IRunner")
Batch end hook. Make scheduler step and stops iterating if needed. Args: runner: current runner Raises: KeyboardInterrupt: at the end of LRFinder
Batch end hook. Make scheduler step and stops iterating if needed.
[ "Batch", "end", "hook", ".", "Make", "scheduler", "step", "and", "stops", "iterating", "if", "needed", "." ]
def on_batch_end(self, runner: "IRunner"): """Batch end hook. Make scheduler step and stops iterating if needed. Args: runner: current runner Raises: KeyboardInterrupt: at the end of LRFinder """ super().on_batch_end(runner=runner) if self.iteration > self.num_steps: # runner.need_early_stop = True raise KeyboardInterrupt("End of LRFinder")
[ "def", "on_batch_end", "(", "self", ",", "runner", ":", "\"IRunner\"", ")", ":", "super", "(", ")", ".", "on_batch_end", "(", "runner", "=", "runner", ")", "if", "self", ".", "iteration", ">", "self", ".", "num_steps", ":", "# runner.need_early_stop = True",...
https://github.com/catalyst-team/catalyst/blob/678dc06eda1848242df010b7f34adb572def2598/catalyst/callbacks/scheduler.py#L426-L438
thonny/thonny
39d96f7dc6a12845daed3424eb42bb57712cbf93
thonny/plugins/micropython/uf2dialog.py
python
Uf2FlashingDialog._get_vid_pids_to_wait_for
(self)
return set()
If result is non-empty then the process completes until a device with one of the vid-pid pairs appears
If result is non-empty then the process completes until a device with one of the vid-pid pairs appears
[ "If", "result", "is", "non", "-", "empty", "then", "the", "process", "completes", "until", "a", "device", "with", "one", "of", "the", "vid", "-", "pid", "pairs", "appears" ]
def _get_vid_pids_to_wait_for(self): """If result is non-empty then the process completes until a device with one of the vid-pid pairs appears""" return set()
[ "def", "_get_vid_pids_to_wait_for", "(", "self", ")", ":", "return", "set", "(", ")" ]
https://github.com/thonny/thonny/blob/39d96f7dc6a12845daed3424eb42bb57712cbf93/thonny/plugins/micropython/uf2dialog.py#L265-L267
F8LEFT/DecLLVM
d38e45e3d0dd35634adae1d0cf7f96f3bd96e74c
python/idc.py
python
GetLastBmask
(enum_id)
return idaapi.get_last_bmask(enum_id)
Get last bitmask in the enum (bitfield) @param enum_id: id of enum @return: the biggest bitmask or -1 no bitmasks are defined yet All bitmasks are sorted by their values as unsigned longs.
Get last bitmask in the enum (bitfield)
[ "Get", "last", "bitmask", "in", "the", "enum", "(", "bitfield", ")" ]
def GetLastBmask(enum_id): """ Get last bitmask in the enum (bitfield) @param enum_id: id of enum @return: the biggest bitmask or -1 no bitmasks are defined yet All bitmasks are sorted by their values as unsigned longs. """ return idaapi.get_last_bmask(enum_id)
[ "def", "GetLastBmask", "(", "enum_id", ")", ":", "return", "idaapi", ".", "get_last_bmask", "(", "enum_id", ")" ]
https://github.com/F8LEFT/DecLLVM/blob/d38e45e3d0dd35634adae1d0cf7f96f3bd96e74c/python/idc.py#L5920-L5929
robotlearn/pyrobolearn
9cd7c060723fda7d2779fa255ac998c2c82b8436
pyrobolearn/robots/robot.py
python
Robot.has_floating_base
(self)
return not self.fixed_base
Return True if the robot has a floating base (i.e. floating root link). Otherwise, it is a fixed base. Returns: bool: True if the robot has a floating base.
Return True if the robot has a floating base (i.e. floating root link). Otherwise, it is a fixed base.
[ "Return", "True", "if", "the", "robot", "has", "a", "floating", "base", "(", "i", ".", "e", ".", "floating", "root", "link", ")", ".", "Otherwise", "it", "is", "a", "fixed", "base", "." ]
def has_floating_base(self): """ Return True if the robot has a floating base (i.e. floating root link). Otherwise, it is a fixed base. Returns: bool: True if the robot has a floating base. """ # return self.floating_base return not self.fixed_base
[ "def", "has_floating_base", "(", "self", ")", ":", "# return self.floating_base", "return", "not", "self", ".", "fixed_base" ]
https://github.com/robotlearn/pyrobolearn/blob/9cd7c060723fda7d2779fa255ac998c2c82b8436/pyrobolearn/robots/robot.py#L554-L562
catalyst-team/catalyst
678dc06eda1848242df010b7f34adb572def2598
catalyst/contrib/datasets/mnist.py
python
MnistQGDataset.targets
(self)
return self._mnist.targets
Labels of digits
Labels of digits
[ "Labels", "of", "digits" ]
def targets(self) -> torch.Tensor: """Labels of digits""" return self._mnist.targets
[ "def", "targets", "(", "self", ")", "->", "torch", ".", "Tensor", ":", "return", "self", ".", "_mnist", ".", "targets" ]
https://github.com/catalyst-team/catalyst/blob/678dc06eda1848242df010b7f34adb572def2598/catalyst/contrib/datasets/mnist.py#L351-L353
certbot/certbot
30b066f08260b73fc26256b5484a180468b9d0a6
acme/acme/mixins.py
python
ResourceMixin.to_partial_json
(self)
return _safe_jobj_compliance(super(), 'to_partial_json', 'resource')
See josepy.JSONDeserializable.to_partial_json()
See josepy.JSONDeserializable.to_partial_json()
[ "See", "josepy", ".", "JSONDeserializable", ".", "to_partial_json", "()" ]
def to_partial_json(self) -> Dict[str, Any]: """See josepy.JSONDeserializable.to_partial_json()""" return _safe_jobj_compliance(super(), 'to_partial_json', 'resource')
[ "def", "to_partial_json", "(", "self", ")", "->", "Dict", "[", "str", ",", "Any", "]", ":", "return", "_safe_jobj_compliance", "(", "super", "(", ")", ",", "'to_partial_json'", ",", "'resource'", ")" ]
https://github.com/certbot/certbot/blob/30b066f08260b73fc26256b5484a180468b9d0a6/acme/acme/mixins.py#L33-L36
quentinhardy/odat
364b94cc662dcbb95a0b28880c6a71ddfc66dd6b
texttable.py
python
Texttable._has_header
(self)
return self._deco & Texttable.HEADER > 0
Return a boolean, if header line is required or not
Return a boolean, if header line is required or not
[ "Return", "a", "boolean", "if", "header", "line", "is", "required", "or", "not" ]
def _has_header(self): """Return a boolean, if header line is required or not """ return self._deco & Texttable.HEADER > 0
[ "def", "_has_header", "(", "self", ")", ":", "return", "self", ".", "_deco", "&", "Texttable", ".", "HEADER", ">", "0" ]
https://github.com/quentinhardy/odat/blob/364b94cc662dcbb95a0b28880c6a71ddfc66dd6b/texttable.py#L445-L449
modflowpy/flopy
eecd1ad193c5972093c9712e5c4b7a83284f0688
flopy/modflow/mfmnw2.py
python
Mnw.get_default_spd_dtype
(structured=True)
Get the default stress period data dtype Parameters ---------- structured : bool Boolean that defines if a structured (True) or unstructured (False) dtype will be created (default is True). Not implemented for unstructured. Returns ------- dtype : np.dtype
Get the default stress period data dtype
[ "Get", "the", "default", "stress", "period", "data", "dtype" ]
def get_default_spd_dtype(structured=True): """ Get the default stress period data dtype Parameters ---------- structured : bool Boolean that defines if a structured (True) or unstructured (False) dtype will be created (default is True). Not implemented for unstructured. Returns ------- dtype : np.dtype """ if structured: return np.dtype( [ ("k", int), ("i", int), ("j", int), ("per", int), ("qdes", np.float32), ("capmult", int), ("cprime", np.float32), ("hlim", np.float32), ("qcut", int), ("qfrcmn", np.float32), ("qfrcmx", np.float32), ] ) else: raise NotImplementedError( "Mnw2: get_default_spd_dtype not implemented for " "unstructured grids" )
[ "def", "get_default_spd_dtype", "(", "structured", "=", "True", ")", ":", "if", "structured", ":", "return", "np", ".", "dtype", "(", "[", "(", "\"k\"", ",", "int", ")", ",", "(", "\"i\"", ",", "int", ")", ",", "(", "\"j\"", ",", "int", ")", ",", ...
https://github.com/modflowpy/flopy/blob/eecd1ad193c5972093c9712e5c4b7a83284f0688/flopy/modflow/mfmnw2.py#L528-L564
huggingface/transformers
623b4f7c63f60cce917677ee704d6c93ee960b4b
src/transformers/models/big_bird/tokenization_big_bird.py
python
BigBirdTokenizer._tokenize
(self, text: str)
return self.sp_model.encode(text, out_type=str)
Take as input a string and return a list of strings (tokens) for words/sub-words
Take as input a string and return a list of strings (tokens) for words/sub-words
[ "Take", "as", "input", "a", "string", "and", "return", "a", "list", "of", "strings", "(", "tokens", ")", "for", "words", "/", "sub", "-", "words" ]
def _tokenize(self, text: str) -> List[str]: """Take as input a string and return a list of strings (tokens) for words/sub-words""" return self.sp_model.encode(text, out_type=str)
[ "def", "_tokenize", "(", "self", ",", "text", ":", "str", ")", "->", "List", "[", "str", "]", ":", "return", "self", ".", "sp_model", ".", "encode", "(", "text", ",", "out_type", "=", "str", ")" ]
https://github.com/huggingface/transformers/blob/623b4f7c63f60cce917677ee704d6c93ee960b4b/src/transformers/models/big_bird/tokenization_big_bird.py#L166-L168
IronLanguages/ironpython3
7a7bb2a872eeab0d1009fc8a6e24dca43f65b693
Src/StdLib/Lib/logging/handlers.py
python
SMTPHandler.emit
(self, record)
Emit a record. Format the record and send it to the specified addressees.
Emit a record.
[ "Emit", "a", "record", "." ]
def emit(self, record): """ Emit a record. Format the record and send it to the specified addressees. """ try: import smtplib from email.message import EmailMessage import email.utils port = self.mailport if not port: port = smtplib.SMTP_PORT smtp = smtplib.SMTP(self.mailhost, port, timeout=self.timeout) msg = EmailMessage() msg['From'] = self.fromaddr msg['To'] = ','.join(self.toaddrs) msg['Subject'] = self.getSubject(record) msg['Date'] = email.utils.localtime() msg.set_content(self.format(record)) if self.username: if self.secure is not None: smtp.ehlo() smtp.starttls(*self.secure) smtp.ehlo() smtp.login(self.username, self.password) smtp.send_message(msg) smtp.quit() except Exception: self.handleError(record)
[ "def", "emit", "(", "self", ",", "record", ")", ":", "try", ":", "import", "smtplib", "from", "email", ".", "message", "import", "EmailMessage", "import", "email", ".", "utils", "port", "=", "self", ".", "mailport", "if", "not", "port", ":", "port", "=...
https://github.com/IronLanguages/ironpython3/blob/7a7bb2a872eeab0d1009fc8a6e24dca43f65b693/Src/StdLib/Lib/logging/handlers.py#L960-L990
lohriialo/photoshop-scripting-python
6b97da967a5d0a45e54f7c99631b29773b923f09
api_reference/photoshop_CC_2018.py
python
LayerComp.__iter__
(self)
return win32com.client.util.Iterator(ob, None)
Return a Python iterator for this object
Return a Python iterator for this object
[ "Return", "a", "Python", "iterator", "for", "this", "object" ]
def __iter__(self): "Return a Python iterator for this object" try: ob = self._oleobj_.InvokeTypes(-4,LCID,3,(13, 10),()) except pythoncom.error: raise TypeError("This object does not support enumeration") return win32com.client.util.Iterator(ob, None)
[ "def", "__iter__", "(", "self", ")", ":", "try", ":", "ob", "=", "self", ".", "_oleobj_", ".", "InvokeTypes", "(", "-", "4", ",", "LCID", ",", "3", ",", "(", "13", ",", "10", ")", ",", "(", ")", ")", "except", "pythoncom", ".", "error", ":", ...
https://github.com/lohriialo/photoshop-scripting-python/blob/6b97da967a5d0a45e54f7c99631b29773b923f09/api_reference/photoshop_CC_2018.py#L1998-L2004
SteveDoyle2/pyNastran
eda651ac2d4883d95a34951f8a002ff94f642a1a
pyNastran/bdf/bdf_interface/add_card.py
python
AddCards.add_spline4
(self, eid: int, caero: int, aelist: int, setg: int, dz: float, method: str, usage: str, nelements: int, melements: int, comment: str='')
return spline
Creates a SPLINE4 card, which defines a curved Infinite Plate, Thin Plate, or Finite Plate Spline. Parameters ---------- eid : int spline id caero : int CAEROx id that defines the plane of the spline box1 / box2 : int First/last box id that is used by the spline setg : int SETx id that defines the list of GRID points that are used by the surface spline dz : float; default=0.0 linear attachment flexibility dz = 0.; spline passes through all grid points method : str; default=IPS method for spline fit valid_methods = {IPS, TPS, FPS} IPS : Harder-Desmarais Infinite Plate Spline TPS : Thin Plate Spline FPS : Finite Plate Spline usage : str; default=BOTH Spline usage flag to determine whether this spline applies to the force transformation, displacement transformation, or both valid_usage = {FORCE, DISP, BOTH} nelements / melements : int; default=10 The number of FE elements along the local spline x/y-axis if using the FPS option comment : str; default='' a comment for the card
Creates a SPLINE4 card, which defines a curved Infinite Plate, Thin Plate, or Finite Plate Spline.
[ "Creates", "a", "SPLINE4", "card", "which", "defines", "a", "curved", "Infinite", "Plate", "Thin", "Plate", "or", "Finite", "Plate", "Spline", "." ]
def add_spline4(self, eid: int, caero: int, aelist: int, setg: int, dz: float, method: str, usage: str, nelements: int, melements: int, comment: str='') -> SPLINE4: """ Creates a SPLINE4 card, which defines a curved Infinite Plate, Thin Plate, or Finite Plate Spline. Parameters ---------- eid : int spline id caero : int CAEROx id that defines the plane of the spline box1 / box2 : int First/last box id that is used by the spline setg : int SETx id that defines the list of GRID points that are used by the surface spline dz : float; default=0.0 linear attachment flexibility dz = 0.; spline passes through all grid points method : str; default=IPS method for spline fit valid_methods = {IPS, TPS, FPS} IPS : Harder-Desmarais Infinite Plate Spline TPS : Thin Plate Spline FPS : Finite Plate Spline usage : str; default=BOTH Spline usage flag to determine whether this spline applies to the force transformation, displacement transformation, or both valid_usage = {FORCE, DISP, BOTH} nelements / melements : int; default=10 The number of FE elements along the local spline x/y-axis if using the FPS option comment : str; default='' a comment for the card """ spline = SPLINE4(eid, caero, aelist, setg, dz, method, usage, nelements, melements, comment=comment) self._add_methods._add_spline_object(spline) return spline
[ "def", "add_spline4", "(", "self", ",", "eid", ":", "int", ",", "caero", ":", "int", ",", "aelist", ":", "int", ",", "setg", ":", "int", ",", "dz", ":", "float", ",", "method", ":", "str", ",", "usage", ":", "str", ",", "nelements", ":", "int", ...
https://github.com/SteveDoyle2/pyNastran/blob/eda651ac2d4883d95a34951f8a002ff94f642a1a/pyNastran/bdf/bdf_interface/add_card.py#L5379-L5421
quodlibet/quodlibet
e3099c89f7aa6524380795d325cc14630031886c
quodlibet/library/file.py
python
FileLibrary.get_masked
(self, mount_point)
return list(self._masked.get(mount_point, {}).values())
List of items for a mount point
List of items for a mount point
[ "List", "of", "items", "for", "a", "mount", "point" ]
def get_masked(self, mount_point): """List of items for a mount point""" return list(self._masked.get(mount_point, {}).values())
[ "def", "get_masked", "(", "self", ",", "mount_point", ")", ":", "return", "list", "(", "self", ".", "_masked", ".", "get", "(", "mount_point", ",", "{", "}", ")", ".", "values", "(", ")", ")" ]
https://github.com/quodlibet/quodlibet/blob/e3099c89f7aa6524380795d325cc14630031886c/quodlibet/library/file.py#L314-L317
aws-samples/aws-kube-codesuite
ab4e5ce45416b83bffb947ab8d234df5437f4fca
src/kubernetes/client/apis/core_v1_api.py
python
CoreV1Api.replace_node
(self, name, body, **kwargs)
replace the specified Node This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please define a `callback` function to be invoked when receiving the response. >>> def callback_function(response): >>> pprint(response) >>> >>> thread = api.replace_node(name, body, callback=callback_function) :param callback function: The callback function for asynchronous request. (optional) :param str name: name of the Node (required) :param V1Node body: (required) :param str pretty: If 'true', then the output is pretty printed. :return: V1Node If the method is called asynchronously, returns the request thread.
replace the specified Node This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please define a `callback` function to be invoked when receiving the response. >>> def callback_function(response): >>> pprint(response) >>> >>> thread = api.replace_node(name, body, callback=callback_function)
[ "replace", "the", "specified", "Node", "This", "method", "makes", "a", "synchronous", "HTTP", "request", "by", "default", ".", "To", "make", "an", "asynchronous", "HTTP", "request", "please", "define", "a", "callback", "function", "to", "be", "invoked", "when"...
def replace_node(self, name, body, **kwargs): """ replace the specified Node This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please define a `callback` function to be invoked when receiving the response. >>> def callback_function(response): >>> pprint(response) >>> >>> thread = api.replace_node(name, body, callback=callback_function) :param callback function: The callback function for asynchronous request. (optional) :param str name: name of the Node (required) :param V1Node body: (required) :param str pretty: If 'true', then the output is pretty printed. :return: V1Node If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('callback'): return self.replace_node_with_http_info(name, body, **kwargs) else: (data) = self.replace_node_with_http_info(name, body, **kwargs) return data
[ "def", "replace_node", "(", "self", ",", "name", ",", "body", ",", "*", "*", "kwargs", ")", ":", "kwargs", "[", "'_return_http_data_only'", "]", "=", "True", "if", "kwargs", ".", "get", "(", "'callback'", ")", ":", "return", "self", ".", "replace_node_wi...
https://github.com/aws-samples/aws-kube-codesuite/blob/ab4e5ce45416b83bffb947ab8d234df5437f4fca/src/kubernetes/client/apis/core_v1_api.py#L28562-L28587
websauna/websauna
a57de54fb8a3fae859f24f373f0292e1e4b3c344
websauna/system/user/views.py
python
reset_password
(request: Request)
return { 'form': form.render( appstruct=dict( user=user.friendly_name ) ) }
Reset password view. User arrives on the page and enters the new password. :param request: Pyramid request. :return: Context to be used by the renderer.
Reset password view.
[ "Reset", "password", "view", "." ]
def reset_password(request: Request) -> dict: """Reset password view. User arrives on the page and enters the new password. :param request: Pyramid request. :return: Context to be used by the renderer. """ schema = request.registry.getUtility(IResetPasswordSchema) schema = schema().bind(request=request) form = request.registry.getUtility(IResetPasswordForm) form = form(schema) code = request.matchdict.get('code', None) credential_activity_service = get_credential_activity_service(request) user = credential_activity_service.get_user_for_password_reset_token(code) if not user: raise HTTPNotFound("Invalid password reset code") if request.method == 'POST': try: controls = request.POST.items() captured = form.validate(controls) except deform.ValidationFailure as e: return {'form': e.render(), 'errors': e.error.children} password = captured['password'] return credential_activity_service.reset_password(code, password) # Question screen return { 'form': form.render( appstruct=dict( user=user.friendly_name ) ) }
[ "def", "reset_password", "(", "request", ":", "Request", ")", "->", "dict", ":", "schema", "=", "request", ".", "registry", ".", "getUtility", "(", "IResetPasswordSchema", ")", "schema", "=", "schema", "(", ")", ".", "bind", "(", "request", "=", "request",...
https://github.com/websauna/websauna/blob/a57de54fb8a3fae859f24f373f0292e1e4b3c344/websauna/system/user/views.py#L228-L262
constverum/ProxyBroker
d21aae8575fc3a95493233ecfd2c7cf47b36b069
proxybroker/providers.py
python
Provider._get
(self, url, data=None, headers=None, method='GET')
return page
[]
async def _get(self, url, data=None, headers=None, method='GET'): page = '' try: timeout = aiohttp.ClientTimeout(total=self._timeout) async with self._sem_provider, self._session.request( method, url, data=data, headers=headers, timeout=timeout ) as resp: page = await resp.text() if resp.status != 200: log.debug( 'url: %s\nheaders: %s\ncookies: %s\npage:\n%s' % (url, resp.headers, resp.cookies, page) ) raise BadStatusError('Status: %s' % resp.status) except ( UnicodeDecodeError, BadStatusError, asyncio.TimeoutError, aiohttp.ClientOSError, aiohttp.ClientResponseError, aiohttp.ServerDisconnectedError, ) as e: page = '' log.debug('%s is failed. Error: %r;' % (url, e)) return page
[ "async", "def", "_get", "(", "self", ",", "url", ",", "data", "=", "None", ",", "headers", "=", "None", ",", "method", "=", "'GET'", ")", ":", "page", "=", "''", "try", ":", "timeout", "=", "aiohttp", ".", "ClientTimeout", "(", "total", "=", "self"...
https://github.com/constverum/ProxyBroker/blob/d21aae8575fc3a95493233ecfd2c7cf47b36b069/proxybroker/providers.py#L131-L155
chubin/cheat.sh
46d1a5f73c6b88da15d809154245dbf234e9479e
lib/adapter/adapter.py
python
Adapter.current_state_command
(cls)
Get current state of repository (current revision). This is used to find what cache entries should be invalidated.
Get current state of repository (current revision). This is used to find what cache entries should be invalidated.
[ "Get", "current", "state", "of", "repository", "(", "current", "revision", ")", ".", "This", "is", "used", "to", "find", "what", "cache", "entries", "should", "be", "invalidated", "." ]
def current_state_command(cls): """ Get current state of repository (current revision). This is used to find what cache entries should be invalidated. """ if not cls._repository_url: return None local_repository_dir = cls.local_repository_location() if not local_repository_dir: return None # in this case `update` has to be implemented # in the distinct adapter subclass raise RuntimeError( "Do not known how to handle this repository: %s" % cls._repository_url)
[ "def", "current_state_command", "(", "cls", ")", ":", "if", "not", "cls", ".", "_repository_url", ":", "return", "None", "local_repository_dir", "=", "cls", ".", "local_repository_location", "(", ")", "if", "not", "local_repository_dir", ":", "return", "None", "...
https://github.com/chubin/cheat.sh/blob/46d1a5f73c6b88da15d809154245dbf234e9479e/lib/adapter/adapter.py#L251-L267
quay/quay
b7d325ed42827db9eda2d9f341cb5a6cdfd155a6
data/model/image.py
python
get_min_id_for_sec_scan
(version)
return Image.select(fn.Min(Image.id)).where(Image.security_indexed_engine < version).scalar()
Gets the minimum id for a clair sec scan.
Gets the minimum id for a clair sec scan.
[ "Gets", "the", "minimum", "id", "for", "a", "clair", "sec", "scan", "." ]
def get_min_id_for_sec_scan(version): """ Gets the minimum id for a clair sec scan. """ return Image.select(fn.Min(Image.id)).where(Image.security_indexed_engine < version).scalar()
[ "def", "get_min_id_for_sec_scan", "(", "version", ")", ":", "return", "Image", ".", "select", "(", "fn", ".", "Min", "(", "Image", ".", "id", ")", ")", ".", "where", "(", "Image", ".", "security_indexed_engine", "<", "version", ")", ".", "scalar", "(", ...
https://github.com/quay/quay/blob/b7d325ed42827db9eda2d9f341cb5a6cdfd155a6/data/model/image.py#L502-L506
tacnetsol/ghidra_scripts
5c4d24bc7166f672015003572daeeb04d2e1f30e
utils/mipsrop.py
python
is_jump
(ins)
return flow.isCall() or flow.isJump() or flow.isTerminal()
Is instruction a jump (or call). :param ins: Instruction to inspect. :type ins: ghidra.program.model.listing.Instruction :returns: True if instruction is a jump, False otherwise.
Is instruction a jump (or call).
[ "Is", "instruction", "a", "jump", "(", "or", "call", ")", "." ]
def is_jump(ins): """ Is instruction a jump (or call). :param ins: Instruction to inspect. :type ins: ghidra.program.model.listing.Instruction :returns: True if instruction is a jump, False otherwise. """ flow = ins.getFlowType() return flow.isCall() or flow.isJump() or flow.isTerminal()
[ "def", "is_jump", "(", "ins", ")", ":", "flow", "=", "ins", ".", "getFlowType", "(", ")", "return", "flow", ".", "isCall", "(", ")", "or", "flow", ".", "isJump", "(", ")", "or", "flow", ".", "isTerminal", "(", ")" ]
https://github.com/tacnetsol/ghidra_scripts/blob/5c4d24bc7166f672015003572daeeb04d2e1f30e/utils/mipsrop.py#L783-L793
sfyc23/EverydayWechat
6b81d03dde92cfef584428bc1e59d2858e94204e
everyday_wechat/control/weather/sojson.py
python
get_sojson_weather
(city_name, is_tomorrow=False)
获取天气信息。网址:https://www.sojson.com/blog/305.html . :param city_name: str,城市名 :return: str ,例如:2019-06-12 星期三 晴 南风 3-4级 高温 22.0℃ 低温 18.0℃ 愿你拥有比阳光明媚的心情
获取天气信息。网址:https://www.sojson.com/blog/305.html . :param city_name: str,城市名 :return: str ,例如:2019-06-12 星期三 晴 南风 3-4级 高温 22.0℃ 低温 18.0℃ 愿你拥有比阳光明媚的心情
[ "获取天气信息。网址:https", ":", "//", "www", ".", "sojson", ".", "com", "/", "blog", "/", "305", ".", "html", ".", ":", "param", "city_name", ":", "str", "城市名", ":", "return", ":", "str", "例如:2019", "-", "06", "-", "12", "星期三", "晴", "南风", "3", "-", "4级",...
def get_sojson_weather(city_name, is_tomorrow=False): """ 获取天气信息。网址:https://www.sojson.com/blog/305.html . :param city_name: str,城市名 :return: str ,例如:2019-06-12 星期三 晴 南风 3-4级 高温 22.0℃ 低温 18.0℃ 愿你拥有比阳光明媚的心情 """ if is_tomorrow: return get_sojson_weather_tomorrow(city_name) if not city_name: return None city_code = CITY_CODE_DICT.get(city_name, None) if not city_code: print('没有此城市的消息...') return None print('获取天气信息...') weather_url = 'http://t.weather.sojson.com/api/weather/city/{}'.format(city_code) try: resp = requests.get(url=weather_url) if resp.status_code == 200: # print(resp.text) weather_dict = resp.json() # 今日天气 # { # "sunrise": "04:45", # "high": "高温 34.0℃", # "low": "低温 25.0℃", # "sunset": "19:37", # "aqi": 145, # "ymd": "2019-06-12", # "week": "星期三", # "fx": "西南风", # "fl": "3-4级", # "type": "多云", # "notice": "阴晴之间,谨防紫外线侵扰" # } if weather_dict.get('status') == 200: today_weather = weather_dict.get('data').get('forecast')[0] today_date = datetime.now().strftime('%Y-%m-%d') # 这个天气的接口更新不及时,有时候当天1点的时候,还是昨天的天气信息,如果天气不一致,则取下一天(今天)的数据 weather_today = today_weather['ymd'] if today_date != weather_today: today_weather = weather_dict.get('data').get('forecast')[1] weather_info = MSG_TODAY.format( city_name=city_name, _date=today_weather['ymd'], week=today_weather['week'], _type=today_weather['type'], low_temp=today_weather['low'], high_temp=today_weather['high'], speed=today_weather['fx'] + today_weather['fl'], notice=today_weather['notice'], ) return weather_info else: print('天气请求出错:{}'.format(weather_dict.get('message'))) except Exception as exception: print(str(exception)) return None
[ "def", "get_sojson_weather", "(", "city_name", ",", "is_tomorrow", "=", "False", ")", ":", "if", "is_tomorrow", ":", "return", "get_sojson_weather_tomorrow", "(", "city_name", ")", "if", "not", "city_name", ":", "return", "None", "city_code", "=", "CITY_CODE_DICT"...
https://github.com/sfyc23/EverydayWechat/blob/6b81d03dde92cfef584428bc1e59d2858e94204e/everyday_wechat/control/weather/sojson.py#L18-L80
AnasAboureada/Penetration-Testing-Study-Notes
8152fd609cf818dba2f07e060738a24c56221687
scripts/string_decode.py
python
MD5APR
()
[]
def MD5APR(): hs='$apr1$qAUKoKlG$3LuCncByN76eLxZAh/Ldr1' if len(hash)==len(hs) and hash.isdigit()==False and hash.isalpha()==False and hash[0:4].find('$apr')==0: jerar.append("108020")
[ "def", "MD5APR", "(", ")", ":", "hs", "=", "'$apr1$qAUKoKlG$3LuCncByN76eLxZAh/Ldr1'", "if", "len", "(", "hash", ")", "==", "len", "(", "hs", ")", "and", "hash", ".", "isdigit", "(", ")", "==", "False", "and", "hash", ".", "isalpha", "(", ")", "==", "...
https://github.com/AnasAboureada/Penetration-Testing-Study-Notes/blob/8152fd609cf818dba2f07e060738a24c56221687/scripts/string_decode.py#L265-L268
interpretml/DiCE
e6a1dc3893799a364da993d4a368b7ccfabe4447
dice_ml/explainer_interfaces/explainer_base.py
python
ExplainerBase.is_cf_valid
(self, model_score)
Check if a cf belongs to the target class or target range.
Check if a cf belongs to the target class or target range.
[ "Check", "if", "a", "cf", "belongs", "to", "the", "target", "class", "or", "target", "range", "." ]
def is_cf_valid(self, model_score): """Check if a cf belongs to the target class or target range. """ # Converting to single prediction if the prediction is provided as a # singleton array correct_dim = 1 if self.model.model_type == ModelTypes.Classifier else 0 if hasattr(model_score, "shape") and len(model_score.shape) > correct_dim: model_score = model_score[0] # Converting target_cf_class to a scalar (tf/torch have it as (1,1) shape) if self.model.model_type == ModelTypes.Classifier: target_cf_class = self.target_cf_class if hasattr(self.target_cf_class, "shape"): if len(self.target_cf_class.shape) == 1: target_cf_class = self.target_cf_class[0] elif len(self.target_cf_class.shape) == 2: target_cf_class = self.target_cf_class[0][0] target_cf_class = int(target_cf_class) if self.num_output_nodes == 1: # for tensorflow/pytorch models pred_1 = model_score[0] validity = True if \ ((target_cf_class == 0 and pred_1 <= self.stopping_threshold) or (target_cf_class == 1 and pred_1 >= self.stopping_threshold)) else False return validity if self.num_output_nodes == 2: # binary pred_1 = model_score[self.num_output_nodes-1] validity = True if \ ((target_cf_class == 0 and pred_1 <= self.stopping_threshold) or (target_cf_class == 1 and pred_1 >= self.stopping_threshold)) else False return validity else: # multiclass return np.argmax(model_score) == target_cf_class else: return self.target_cf_range[0] <= model_score and model_score <= self.target_cf_range[1]
[ "def", "is_cf_valid", "(", "self", ",", "model_score", ")", ":", "# Converting to single prediction if the prediction is provided as a", "# singleton array", "correct_dim", "=", "1", "if", "self", ".", "model", ".", "model_type", "==", "ModelTypes", ".", "Classifier", "...
https://github.com/interpretml/DiCE/blob/e6a1dc3893799a364da993d4a368b7ccfabe4447/dice_ml/explainer_interfaces/explainer_base.py#L601-L634
jliljebl/flowblade
995313a509b80e99eb1ad550d945bdda5995093b
flowblade-trunk/Flowblade/clipmenuaction.py
python
MatchFrameWriter.__init__
(self, clip, clip_frame, track, display_on_right)
[]
def __init__(self, clip, clip_frame, track, display_on_right): self.clip = clip self.clip_frame = clip_frame self.track = track self.display_on_right = display_on_right
[ "def", "__init__", "(", "self", ",", "clip", ",", "clip_frame", ",", "track", ",", "display_on_right", ")", ":", "self", ".", "clip", "=", "clip", "self", ".", "clip_frame", "=", "clip_frame", "self", ".", "track", "=", "track", "self", ".", "display_on_...
https://github.com/jliljebl/flowblade/blob/995313a509b80e99eb1ad550d945bdda5995093b/flowblade-trunk/Flowblade/clipmenuaction.py#L654-L658
TarrySingh/Artificial-Intelligence-Deep-Learning-Machine-Learning-Tutorials
5bb97d7e3ffd913abddb4cfa7d78a1b4c868890e
deep-learning/1-pixel-attack/networks/capsulenet/capsulelayers.py
python
CapsuleLayer.call
(self, inputs, training=None)
return K.reshape(outputs, [-1, self.num_capsule, self.dim_vector])
# Begin: inputs_hat computation V1 ---------------------------------------------------------------------# # Compute `inputs * W` by expanding the first dim of W. More time-consuming and need batch_size. # w_tiled.shape = [batch_size, input_num_capsule, num_capsule, input_dim_vector, dim_vector] w_tiled = K.tile(K.expand_dims(self.W, 0), [self.batch_size, 1, 1, 1, 1]) # Transformed vectors, inputs_hat.shape = [None, input_num_capsule, num_capsule, 1, dim_vector] inputs_hat = K.batch_dot(inputs_tiled, w_tiled, [4, 3]) # End: inputs_hat computation V1 ---------------------------------------------------------------------#
# Begin: inputs_hat computation V1 ---------------------------------------------------------------------# # Compute `inputs * W` by expanding the first dim of W. More time-consuming and need batch_size. # w_tiled.shape = [batch_size, input_num_capsule, num_capsule, input_dim_vector, dim_vector] w_tiled = K.tile(K.expand_dims(self.W, 0), [self.batch_size, 1, 1, 1, 1]) # Transformed vectors, inputs_hat.shape = [None, input_num_capsule, num_capsule, 1, dim_vector] inputs_hat = K.batch_dot(inputs_tiled, w_tiled, [4, 3]) # End: inputs_hat computation V1 ---------------------------------------------------------------------#
[ "#", "Begin", ":", "inputs_hat", "computation", "V1", "---------------------------------------------------------------------", "#", "#", "Compute", "inputs", "*", "W", "by", "expanding", "the", "first", "dim", "of", "W", ".", "More", "time", "-", "consuming", "and",...
def call(self, inputs, training=None): # inputs.shape=[None, input_num_capsule, input_dim_vector] # Expand dims to [None, input_num_capsule, 1, 1, input_dim_vector] inputs_expand = K.expand_dims(K.expand_dims(inputs, 2), 2) # Replicate num_capsule dimension to prepare being multiplied by W # Now it has shape = [None, input_num_capsule, num_capsule, 1, input_dim_vector] inputs_tiled = K.tile(inputs_expand, [1, 1, self.num_capsule, 1, 1]) """ # Begin: inputs_hat computation V1 ---------------------------------------------------------------------# # Compute `inputs * W` by expanding the first dim of W. More time-consuming and need batch_size. # w_tiled.shape = [batch_size, input_num_capsule, num_capsule, input_dim_vector, dim_vector] w_tiled = K.tile(K.expand_dims(self.W, 0), [self.batch_size, 1, 1, 1, 1]) # Transformed vectors, inputs_hat.shape = [None, input_num_capsule, num_capsule, 1, dim_vector] inputs_hat = K.batch_dot(inputs_tiled, w_tiled, [4, 3]) # End: inputs_hat computation V1 ---------------------------------------------------------------------# """ # Begin: inputs_hat computation V2 ---------------------------------------------------------------------# # Compute `inputs * W` by scanning inputs_tiled on dimension 0. This is faster but requires Tensorflow. # inputs_hat.shape = [None, input_num_capsule, num_capsule, 1, dim_vector] inputs_hat = tf.scan(lambda ac, x: K.batch_dot(x, self.W, [3, 2]), elems=inputs_tiled, initializer=K.zeros([self.input_num_capsule, self.num_capsule, 1, self.dim_vector])) # End: inputs_hat computation V2 ---------------------------------------------------------------------# """ # Begin: routing algorithm V1, dynamic ------------------------------------------------------------# def body(i, b, outputs): c = tf.nn.softmax(b, dim=2) # dim=2 is the num_capsule dimension outputs = squash(K.sum(c * inputs_hat, 1, keepdims=True)) if i != 1: b = b + K.sum(inputs_hat * outputs, -1, keepdims=True) return [i-1, b, outputs] cond = lambda i, b, inputs_hat: i > 0 loop_vars = [K.constant(self.num_routing), self.bias, K.sum(inputs_hat, 1, keepdims=True)] shape_invariants = [tf.TensorShape([]), tf.TensorShape([None, self.input_num_capsule, self.num_capsule, 1, 1]), tf.TensorShape([None, 1, self.num_capsule, 1, self.dim_vector])] _, _, outputs = tf.while_loop(cond, body, loop_vars, shape_invariants) # End: routing algorithm V1, dynamic ------------------------------------------------------------# """ # Begin: routing algorithm V2, static -----------------------------------------------------------# # Routing algorithm V2. Use iteration. V2 and V1 both work without much difference on performance assert self.num_routing > 0, 'The num_routing should be > 0.' for i in range(self.num_routing): c = tf.nn.softmax(self.bias, axis=2) # dim=2 is the num_capsule dimension # outputs.shape=[None, 1, num_capsule, 1, dim_vector] outputs = squash(K.sum(c * inputs_hat, 1, keepdims=True)) # last iteration needs not compute bias which will not be passed to the graph any more anyway. if i != self.num_routing - 1: # self.bias = K.update_add(self.bias, K.sum(inputs_hat * outputs, [0, -1], keepdims=True)) self.bias += K.sum(inputs_hat * outputs, -1, keepdims=True) # tf.summary.histogram('BigBee', self.bias) # for debugging # End: routing algorithm V2, static ------------------------------------------------------------# return K.reshape(outputs, [-1, self.num_capsule, self.dim_vector])
[ "def", "call", "(", "self", ",", "inputs", ",", "training", "=", "None", ")", ":", "# inputs.shape=[None, input_num_capsule, input_dim_vector]", "# Expand dims to [None, input_num_capsule, 1, 1, input_dim_vector]", "inputs_expand", "=", "K", ".", "expand_dims", "(", "K", "....
https://github.com/TarrySingh/Artificial-Intelligence-Deep-Learning-Machine-Learning-Tutorials/blob/5bb97d7e3ffd913abddb4cfa7d78a1b4c868890e/deep-learning/1-pixel-attack/networks/capsulenet/capsulelayers.py#L106-L166
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/vera/climate.py
python
VeraThermostat.operation
(self)
return self.vera_device.get_hvac_mode()
Return current operation ie. heat, cool, idle.
Return current operation ie. heat, cool, idle.
[ "Return", "current", "operation", "ie", ".", "heat", "cool", "idle", "." ]
def operation(self) -> str: """Return current operation ie. heat, cool, idle.""" return self.vera_device.get_hvac_mode()
[ "def", "operation", "(", "self", ")", "->", "str", ":", "return", "self", ".", "vera_device", ".", "get_hvac_mode", "(", ")" ]
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/vera/climate.py#L136-L138
lonePatient/BERT-NER-Pytorch
bc9276185539c59bbd3d310ea808fea2b618fedf
callback/lr_scheduler.py
python
ReduceLRWDOnPlateau.epoch_step
(self, metrics, epoch)
[]
def epoch_step(self, metrics, epoch): current = metrics if current is None: warnings.warn('Learning Rate Plateau Reducing requires metrics available!', RuntimeWarning) else: if self.in_cooldown(): self.cooldown_counter -= 1 self.wait = 0 if self.monitor_op(current, self.best): self.best = current self.wait = 0 elif not self.in_cooldown(): if self.wait >= self.patience: for param_group in self.optimizer.param_groups: old_lr = float(param_group['lr']) if old_lr > self.min_lr + self.eps: new_lr = old_lr * self.factor new_lr = max(new_lr, self.min_lr) param_group['lr'] = new_lr if self.verbose > 0: print('\nEpoch %d: reducing learning rate to %s.' % (epoch, new_lr)) if param_group['weight_decay'] != 0: old_weight_decay = float(param_group['weight_decay']) new_weight_decay = max(old_weight_decay * self.factor, self.min_lr) if old_weight_decay > new_weight_decay + self.eps: param_group['weight_decay'] = new_weight_decay if self.verbose: print('\nEpoch {epoch}: reducing weight decay factor of group {i} to {new_weight_decay:.4e}.') self.cooldown_counter = self.cooldown self.wait = 0 self.wait += 1
[ "def", "epoch_step", "(", "self", ",", "metrics", ",", "epoch", ")", ":", "current", "=", "metrics", "if", "current", "is", "None", ":", "warnings", ".", "warn", "(", "'Learning Rate Plateau Reducing requires metrics available!'", ",", "RuntimeWarning", ")", "else...
https://github.com/lonePatient/BERT-NER-Pytorch/blob/bc9276185539c59bbd3d310ea808fea2b618fedf/callback/lr_scheduler.py#L351-L382
meduza-corp/interstellar
40a801ccd7856491726f5a126621d9318cabe2e1
gsutil/third_party/python-gflags/gflags.py
python
FlagValues.MainModuleHelp
(self)
return self.ModuleHelp(_GetMainModule())
Describe the key flags of the main module. Returns: string describing the key flags of a module.
Describe the key flags of the main module.
[ "Describe", "the", "key", "flags", "of", "the", "main", "module", "." ]
def MainModuleHelp(self): """Describe the key flags of the main module. Returns: string describing the key flags of a module. """ return self.ModuleHelp(_GetMainModule())
[ "def", "MainModuleHelp", "(", "self", ")", ":", "return", "self", ".", "ModuleHelp", "(", "_GetMainModule", "(", ")", ")" ]
https://github.com/meduza-corp/interstellar/blob/40a801ccd7856491726f5a126621d9318cabe2e1/gsutil/third_party/python-gflags/gflags.py#L1428-L1434
linxid/Machine_Learning_Study_Path
558e82d13237114bbb8152483977806fc0c222af
Machine Learning In Action/Chapter5-LogisticRegression/venv/Lib/encodings/zlib_codec.py
python
getregentry
()
return codecs.CodecInfo( name='zlib', encode=zlib_encode, decode=zlib_decode, incrementalencoder=IncrementalEncoder, incrementaldecoder=IncrementalDecoder, streamreader=StreamReader, streamwriter=StreamWriter, _is_text_encoding=False, )
[]
def getregentry(): return codecs.CodecInfo( name='zlib', encode=zlib_encode, decode=zlib_decode, incrementalencoder=IncrementalEncoder, incrementaldecoder=IncrementalDecoder, streamreader=StreamReader, streamwriter=StreamWriter, _is_text_encoding=False, )
[ "def", "getregentry", "(", ")", ":", "return", "codecs", ".", "CodecInfo", "(", "name", "=", "'zlib'", ",", "encode", "=", "zlib_encode", ",", "decode", "=", "zlib_decode", ",", "incrementalencoder", "=", "IncrementalEncoder", ",", "incrementaldecoder", "=", "...
https://github.com/linxid/Machine_Learning_Study_Path/blob/558e82d13237114bbb8152483977806fc0c222af/Machine Learning In Action/Chapter5-LogisticRegression/venv/Lib/encodings/zlib_codec.py#L67-L77
sio2project/oioioi
adeb6a7b278b6bed853405e525f87fd2726c06ac
oioioi/problems/views.py
python
filter_problems_by_origin
(problems, origin_tags)
return problems
The filters are almost always logical ANDed, the only exception to this are OriginInfoValues within their OriginInfoCategory, which are logical ORred - it is possible to search for example for tasks from round "1 or 2" and year "2011 or 2012 or 2013". Searching in Problemset from the Task Archive relies on this behaviour.
The filters are almost always logical ANDed, the only exception to this are OriginInfoValues within their OriginInfoCategory, which are logical ORred - it is possible to search for example for tasks from round "1 or 2" and year "2011 or 2012 or 2013". Searching in Problemset from the Task Archive relies on this behaviour.
[ "The", "filters", "are", "almost", "always", "logical", "ANDed", "the", "only", "exception", "to", "this", "are", "OriginInfoValues", "within", "their", "OriginInfoCategory", "which", "are", "logical", "ORred", "-", "it", "is", "possible", "to", "search", "for",...
def filter_problems_by_origin(problems, origin_tags): """The filters are almost always logical ANDed, the only exception to this are OriginInfoValues within their OriginInfoCategory, which are logical ORred - it is possible to search for example for tasks from round "1 or 2" and year "2011 or 2012 or 2013". Searching in Problemset from the Task Archive relies on this behaviour. """ info = {} for tag in origin_tags: tag = tag.split('_') if len(tag) in (1, 2): if not OriginTag.objects.filter(name=tag[0]).exists(): raise Http404 if tag[0] not in info: info[tag[0]] = {} if len(tag) == 2: value = OriginInfoValue.objects.filter( parent_tag__name=tag[0], value=tag[1] ) if not value.exists(): raise Http404 value = value.get() category = value.category.name if category not in info[tag[0]]: # pk=None doesn't match any problem, needed for logical OR info[tag[0]][category] = Q(pk=None) info[tag[0]][category] |= Q(origininfovalue__value=value.value) else: raise Http404 for tag, categories in info.items(): problems = problems.filter(origintag__name=tag) for category, q in categories.items(): problems = problems.filter(q) return problems
[ "def", "filter_problems_by_origin", "(", "problems", ",", "origin_tags", ")", ":", "info", "=", "{", "}", "for", "tag", "in", "origin_tags", ":", "tag", "=", "tag", ".", "split", "(", "'_'", ")", "if", "len", "(", "tag", ")", "in", "(", "1", ",", "...
https://github.com/sio2project/oioioi/blob/adeb6a7b278b6bed853405e525f87fd2726c06ac/oioioi/problems/views.py#L219-L258
aiidateam/aiida-core
c743a335480f8bb3a5e4ebd2463a31f9f3b9f9b2
aiida/engine/runners.py
python
Runner.stop
(self)
Stop the internal event loop.
Stop the internal event loop.
[ "Stop", "the", "internal", "event", "loop", "." ]
def stop(self) -> None: """Stop the internal event loop.""" self._loop.stop()
[ "def", "stop", "(", "self", ")", "->", "None", ":", "self", ".", "_loop", ".", "stop", "(", ")" ]
https://github.com/aiidateam/aiida-core/blob/c743a335480f8bb3a5e4ebd2463a31f9f3b9f9b2/aiida/engine/runners.py#L151-L153
gwpy/gwpy
82becd78d166a32985cb657a54d0d39f6a207739
gwpy/timeseries/core.py
python
TimeSeriesBase.epoch
(self, epoch)
[]
def epoch(self, epoch): if epoch is None: del self.t0 elif isinstance(epoch, Time): self.t0 = epoch.gps else: try: self.t0 = to_gps(epoch) except TypeError: self.t0 = epoch
[ "def", "epoch", "(", "self", ",", "epoch", ")", ":", "if", "epoch", "is", "None", ":", "del", "self", ".", "t0", "elif", "isinstance", "(", "epoch", ",", "Time", ")", ":", "self", ".", "t0", "=", "epoch", ".", "gps", "else", ":", "try", ":", "s...
https://github.com/gwpy/gwpy/blob/82becd78d166a32985cb657a54d0d39f6a207739/gwpy/timeseries/core.py#L219-L228
pyparallel/pyparallel
11e8c6072d48c8f13641925d17b147bf36ee0ba3
Lib/codecs.py
python
getwriter
(encoding)
return lookup(encoding).streamwriter
Lookup up the codec for the given encoding and return its StreamWriter class or factory function. Raises a LookupError in case the encoding cannot be found.
Lookup up the codec for the given encoding and return its StreamWriter class or factory function.
[ "Lookup", "up", "the", "codec", "for", "the", "given", "encoding", "and", "return", "its", "StreamWriter", "class", "or", "factory", "function", "." ]
def getwriter(encoding): """ Lookup up the codec for the given encoding and return its StreamWriter class or factory function. Raises a LookupError in case the encoding cannot be found. """ return lookup(encoding).streamwriter
[ "def", "getwriter", "(", "encoding", ")", ":", "return", "lookup", "(", "encoding", ")", ".", "streamwriter" ]
https://github.com/pyparallel/pyparallel/blob/11e8c6072d48c8f13641925d17b147bf36ee0ba3/Lib/codecs.py#L1001-L1009
zatosource/zato
2a9d273f06f9d776fbfeb53e73855af6e40fa208
code/zato-server/src/zato/server/file_transfer/observer/local_.py
python
LocalObserver.move_file
(self, path_from, path_to, _ignored_event, _ignored_snapshot_maker)
Moves a file to a selected directory.
Moves a file to a selected directory.
[ "Moves", "a", "file", "to", "a", "selected", "directory", "." ]
def move_file(self, path_from, path_to, _ignored_event, _ignored_snapshot_maker): """ Moves a file to a selected directory. """ shutil_copy(path_from, path_to)
[ "def", "move_file", "(", "self", ",", "path_from", ",", "path_to", ",", "_ignored_event", ",", "_ignored_snapshot_maker", ")", ":", "shutil_copy", "(", "path_from", ",", "path_to", ")" ]
https://github.com/zatosource/zato/blob/2a9d273f06f9d776fbfeb53e73855af6e40fa208/code/zato-server/src/zato/server/file_transfer/observer/local_.py#L68-L71
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/rpi_gpio/cover.py
python
RPiGPIOCover.close_cover
(self, **kwargs)
Close the cover.
Close the cover.
[ "Close", "the", "cover", "." ]
def close_cover(self, **kwargs): """Close the cover.""" if not self.is_closed: self._trigger()
[ "def", "close_cover", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "not", "self", ".", "is_closed", ":", "self", ".", "_trigger", "(", ")" ]
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/rpi_gpio/cover.py#L131-L134
biolab/orange3
41685e1c7b1d1babe680113685a2d44bcc9fec0b
Orange/widgets/data/owdatasets.py
python
UniformHeightDelegate.sizeHint
(self, option, index)
return sh
[]
def sizeHint(self, option, index): # type: (QStyleOptionViewItem, QModelIndex) -> QSize opt = QStyleOptionViewItem(option) self.initStyleOption(option, index) opt.features |= QStyleOptionViewItem.HasDecoration widget = option.widget style = widget.style() if widget is not None else QApplication.style() sh = style.sizeFromContents( QStyle.CT_ItemViewItem, opt, QSize(), widget) return sh
[ "def", "sizeHint", "(", "self", ",", "option", ",", "index", ")", ":", "# type: (QStyleOptionViewItem, QModelIndex) -> QSize", "opt", "=", "QStyleOptionViewItem", "(", "option", ")", "self", ".", "initStyleOption", "(", "option", ",", "index", ")", "opt", ".", "...
https://github.com/biolab/orange3/blob/41685e1c7b1d1babe680113685a2d44bcc9fec0b/Orange/widgets/data/owdatasets.py#L64-L73
holzschu/Carnets
44effb10ddfc6aa5c8b0687582a724ba82c6b547
Library/lib/python3.7/site-packages/numpy-1.16.0-py3.7-macosx-10.9-x86_64.egg/numpy/distutils/misc_util.py
python
Configuration.__init__
(self, package_name=None, parent_name=None, top_path=None, package_path=None, caller_level=1, setup_name='setup.py', **attrs)
Construct configuration instance of a package. package_name -- name of the package Ex.: 'distutils' parent_name -- name of the parent package Ex.: 'numpy' top_path -- directory of the toplevel package Ex.: the directory where the numpy package source sits package_path -- directory of package. Will be computed by magic from the directory of the caller module if not specified Ex.: the directory where numpy.distutils is caller_level -- frame level to caller namespace, internal parameter.
Construct configuration instance of a package.
[ "Construct", "configuration", "instance", "of", "a", "package", "." ]
def __init__(self, package_name=None, parent_name=None, top_path=None, package_path=None, caller_level=1, setup_name='setup.py', **attrs): """Construct configuration instance of a package. package_name -- name of the package Ex.: 'distutils' parent_name -- name of the parent package Ex.: 'numpy' top_path -- directory of the toplevel package Ex.: the directory where the numpy package source sits package_path -- directory of package. Will be computed by magic from the directory of the caller module if not specified Ex.: the directory where numpy.distutils is caller_level -- frame level to caller namespace, internal parameter. """ self.name = dot_join(parent_name, package_name) self.version = None caller_frame = get_frame(caller_level) self.local_path = get_path_from_frame(caller_frame, top_path) # local_path -- directory of a file (usually setup.py) that # defines a configuration() function. # local_path -- directory of a file (usually setup.py) that # defines a configuration() function. if top_path is None: top_path = self.local_path self.local_path = '' if package_path is None: package_path = self.local_path elif os.path.isdir(njoin(self.local_path, package_path)): package_path = njoin(self.local_path, package_path) if not os.path.isdir(package_path or '.'): raise ValueError("%r is not a directory" % (package_path,)) self.top_path = top_path self.package_path = package_path # this is the relative path in the installed package self.path_in_package = os.path.join(*self.name.split('.')) self.list_keys = self._list_keys[:] self.dict_keys = self._dict_keys[:] for n in self.list_keys: v = copy.copy(attrs.get(n, [])) setattr(self, n, as_list(v)) for n in self.dict_keys: v = copy.copy(attrs.get(n, {})) setattr(self, n, v) known_keys = self.list_keys + self.dict_keys self.extra_keys = self._extra_keys[:] for n in attrs.keys(): if n in known_keys: continue a = attrs[n] setattr(self, n, a) if isinstance(a, list): self.list_keys.append(n) elif isinstance(a, dict): self.dict_keys.append(n) else: self.extra_keys.append(n) if os.path.exists(njoin(package_path, '__init__.py')): self.packages.append(self.name) self.package_dir[self.name] = package_path self.options = dict( ignore_setup_xxx_py = False, assume_default_configuration = False, delegate_options_to_subpackages = False, quiet = False, ) caller_instance = None for i in range(1, 3): try: f = get_frame(i) except ValueError: break try: caller_instance = eval('self', f.f_globals, f.f_locals) break except NameError: pass if isinstance(caller_instance, self.__class__): if caller_instance.options['delegate_options_to_subpackages']: self.set_options(**caller_instance.options) self.setup_name = setup_name
[ "def", "__init__", "(", "self", ",", "package_name", "=", "None", ",", "parent_name", "=", "None", ",", "top_path", "=", "None", ",", "package_path", "=", "None", ",", "caller_level", "=", "1", ",", "setup_name", "=", "'setup.py'", ",", "*", "*", "attrs"...
https://github.com/holzschu/Carnets/blob/44effb10ddfc6aa5c8b0687582a724ba82c6b547/Library/lib/python3.7/site-packages/numpy-1.16.0-py3.7-macosx-10.9-x86_64.egg/numpy/distutils/misc_util.py#L742-L837
TRI-ML/packnet-sfm
f59b1d615777a9987285a10e45b5d87b0369fa7d
packnet_sfm/datasets/kitti_dataset.py
python
KITTIDataset._get_imu2cam_transform
(self, image_file)
return imu2cam
Gets the transformation between IMU an camera from an image file
Gets the transformation between IMU an camera from an image file
[ "Gets", "the", "transformation", "between", "IMU", "an", "camera", "from", "an", "image", "file" ]
def _get_imu2cam_transform(self, image_file): """Gets the transformation between IMU an camera from an image file""" parent_folder = self._get_parent_folder(image_file) if image_file in self.imu2velo_calib_cache: return self.imu2velo_calib_cache[image_file] cam2cam = read_calib_file(os.path.join(parent_folder, CALIB_FILE['cam2cam'])) imu2velo = read_calib_file(os.path.join(parent_folder, CALIB_FILE['imu2velo'])) velo2cam = read_calib_file(os.path.join(parent_folder, CALIB_FILE['velo2cam'])) velo2cam_mat = transform_from_rot_trans(velo2cam['R'], velo2cam['T']) imu2velo_mat = transform_from_rot_trans(imu2velo['R'], imu2velo['T']) cam_2rect_mat = transform_from_rot_trans(cam2cam['R_rect_00'], np.zeros(3)) imu2cam = cam_2rect_mat @ velo2cam_mat @ imu2velo_mat self.imu2velo_calib_cache[image_file] = imu2cam return imu2cam
[ "def", "_get_imu2cam_transform", "(", "self", ",", "image_file", ")", ":", "parent_folder", "=", "self", ".", "_get_parent_folder", "(", "image_file", ")", "if", "image_file", "in", "self", ".", "imu2velo_calib_cache", ":", "return", "self", ".", "imu2velo_calib_c...
https://github.com/TRI-ML/packnet-sfm/blob/f59b1d615777a9987285a10e45b5d87b0369fa7d/packnet_sfm/datasets/kitti_dataset.py#L282-L298
FederatedAI/FATE
32540492623568ecd1afcb367360133616e02fa3
python/fate_arch/storage/localfs/_table.py
python
StorageTable._count
(self)
return count
[]
def _count(self): count = 0 for _ in self._as_generator(): count += 1 return count
[ "def", "_count", "(", "self", ")", ":", "count", "=", "0", "for", "_", "in", "self", ".", "_as_generator", "(", ")", ":", "count", "+=", "1", "return", "count" ]
https://github.com/FederatedAI/FATE/blob/32540492623568ecd1afcb367360133616e02fa3/python/fate_arch/storage/localfs/_table.py#L96-L100
mit-han-lab/data-efficient-gans
6858275f08f43a33026844c8c2ac4e703e8a07ba
DiffAugment-stylegan2/dnnlib/submission/run_context.py
python
RunContext.__exit__
(self, exc_type: Any, exc_value: Any, traceback: Any)
[]
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None: self.close()
[ "def", "__exit__", "(", "self", ",", "exc_type", ":", "Any", ",", "exc_value", ":", "Any", ",", "traceback", ":", "Any", ")", "->", "None", ":", "self", ".", "close", "(", ")" ]
https://github.com/mit-han-lab/data-efficient-gans/blob/6858275f08f43a33026844c8c2ac4e703e8a07ba/DiffAugment-stylegan2/dnnlib/submission/run_context.py#L60-L61
jiangxufeng/v2rayL
27f89dfe3a8e22f4dd191cc1cc1e7fd9aef3e683
v2rayL-GUI/v2rayL_api.py
python
V2rayL.connect
(self, region, flag)
连接VPN :param region: VPN别名 :param flag: 是否是正常连接/更新端口重连 :return:
连接VPN :param region: VPN别名 :param flag: 是否是正常连接/更新端口重连 :return:
[ "连接VPN", ":", "param", "region", ":", "VPN别名", ":", "param", "flag", ":", "是否是正常连接", "/", "更新端口重连", ":", "return", ":" ]
def connect(self, region, flag): """ 连接VPN :param region: VPN别名 :param flag: 是否是正常连接/更新端口重连 :return: """ if not flag: self.subs.setconf(region, self.current_status.http, self.current_status.socks, self.current_status.proxy) try: output = subprocess.getoutput(["sudo systemctl status v2rayL.service"]) if "Active: active" in output: subprocess.call(["sudo systemctl restart v2rayL.service"], shell=True) else: subprocess.call(["sudo systemctl start v2rayL.service"], shell=True) output = subprocess.getoutput(["sudo systemctl status v2rayL.service"]) if "Active: active" not in output: raise MyException("v2rayL.service 启动失败") except: raise MyException("连接失败,请尝试更新订阅后再次连接或检查v2rayL.service是否正常运行") else: self.current_status.current = region with open("/etc/v2rayL/ncurrent", "wb") as jf: pickle.dump(self.current_status, jf)
[ "def", "connect", "(", "self", ",", "region", ",", "flag", ")", ":", "if", "not", "flag", ":", "self", ".", "subs", ".", "setconf", "(", "region", ",", "self", ".", "current_status", ".", "http", ",", "self", ".", "current_status", ".", "socks", ",",...
https://github.com/jiangxufeng/v2rayL/blob/27f89dfe3a8e22f4dd191cc1cc1e7fd9aef3e683/v2rayL-GUI/v2rayL_api.py#L90-L113
NervanaSystems/neon
8c3fb8a93b4a89303467b25817c60536542d08bd
examples/skip-thought/data_loader.py
python
load_json
(fname)
return data
load json object from file
load json object from file
[ "load", "json", "object", "from", "file" ]
def load_json(fname): """ load json object from file """ with open(fname) as f: data = json.load(f) return data
[ "def", "load_json", "(", "fname", ")", ":", "with", "open", "(", "fname", ")", "as", "f", ":", "data", "=", "json", ".", "load", "(", "f", ")", "return", "data" ]
https://github.com/NervanaSystems/neon/blob/8c3fb8a93b4a89303467b25817c60536542d08bd/examples/skip-thought/data_loader.py#L31-L37
cloudera/impyla
0c736af4cad2bade9b8e313badc08ec50e81c948
impala/_thrift_gen/beeswax/BeeswaxService.py
python
query_result.write
(self, oprot)
[]
def write(self, oprot): if oprot._fast_encode is not None and self.thrift_spec is not None: oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) return oprot.writeStructBegin('query_result') if self.success is not None: oprot.writeFieldBegin('success', TType.STRUCT, 0) self.success.write(oprot) oprot.writeFieldEnd() if self.error is not None: oprot.writeFieldBegin('error', TType.STRUCT, 1) self.error.write(oprot) oprot.writeFieldEnd() oprot.writeFieldStop() oprot.writeStructEnd()
[ "def", "write", "(", "self", ",", "oprot", ")", ":", "if", "oprot", ".", "_fast_encode", "is", "not", "None", "and", "self", ".", "thrift_spec", "is", "not", "None", ":", "oprot", ".", "trans", ".", "write", "(", "oprot", ".", "_fast_encode", "(", "s...
https://github.com/cloudera/impyla/blob/0c736af4cad2bade9b8e313badc08ec50e81c948/impala/_thrift_gen/beeswax/BeeswaxService.py#L987-L1001
wistful/SublimeAutoPEP8
ea8bbdd811f7987cb8106aa099fa885df8a5a9b2
sublimeautopep8lib/pycodestyle.py
python
whitespace_around_operator
(logical_line)
r"""Avoid extraneous whitespace around an operator. Okay: a = 12 + 3 E221: a = 4 + 5 E222: a = 4 + 5 E223: a = 4\t+ 5 E224: a = 4 +\t5
r"""Avoid extraneous whitespace around an operator.
[ "r", "Avoid", "extraneous", "whitespace", "around", "an", "operator", "." ]
def whitespace_around_operator(logical_line): r"""Avoid extraneous whitespace around an operator. Okay: a = 12 + 3 E221: a = 4 + 5 E222: a = 4 + 5 E223: a = 4\t+ 5 E224: a = 4 +\t5 """ for match in OPERATOR_REGEX.finditer(logical_line): before, after = match.groups() if '\t' in before: yield match.start(1), "E223 tab before operator" elif len(before) > 1: yield match.start(1), "E221 multiple spaces before operator" if '\t' in after: yield match.start(2), "E224 tab after operator" elif len(after) > 1: yield match.start(2), "E222 multiple spaces after operator"
[ "def", "whitespace_around_operator", "(", "logical_line", ")", ":", "for", "match", "in", "OPERATOR_REGEX", ".", "finditer", "(", "logical_line", ")", ":", "before", ",", "after", "=", "match", ".", "groups", "(", ")", "if", "'\\t'", "in", "before", ":", "...
https://github.com/wistful/SublimeAutoPEP8/blob/ea8bbdd811f7987cb8106aa099fa885df8a5a9b2/sublimeautopep8lib/pycodestyle.py#L821-L841
bububa/MongoHub
7f761c424741d88bb234426b74b4092c40fb4987
Resources/pymongo/database.py
python
Database.last_status
(self)
return self._command({"getlasterror": 1})
Get status information from the last operation. Returns a SON object with status information.
Get status information from the last operation.
[ "Get", "status", "information", "from", "the", "last", "operation", "." ]
def last_status(self): """Get status information from the last operation. Returns a SON object with status information. """ return self._command({"getlasterror": 1})
[ "def", "last_status", "(", "self", ")", ":", "return", "self", ".", "_command", "(", "{", "\"getlasterror\"", ":", "1", "}", ")" ]
https://github.com/bububa/MongoHub/blob/7f761c424741d88bb234426b74b4092c40fb4987/Resources/pymongo/database.py#L291-L296
liangliangyy/DjangoBlog
51d3cb9a29964904b6d59da3b771bb2454fd16ee
blog/models.py
python
Article.get_category_tree
(self)
return names
[]
def get_category_tree(self): tree = self.category.get_category_tree() names = list(map(lambda c: (c.name, c.get_absolute_url()), tree)) return names
[ "def", "get_category_tree", "(", "self", ")", ":", "tree", "=", "self", ".", "category", ".", "get_category_tree", "(", ")", "names", "=", "list", "(", "map", "(", "lambda", "c", ":", "(", "c", ".", "name", ",", "c", ".", "get_absolute_url", "(", ")"...
https://github.com/liangliangyy/DjangoBlog/blob/51d3cb9a29964904b6d59da3b771bb2454fd16ee/blog/models.py#L128-L132
omz/PythonistaAppTemplate
f560f93f8876d82a21d108977f90583df08d55af
PythonistaAppTemplate/PythonistaKit.framework/pylib_ext/matplotlib/ticker.py
python
LogLocator.base
(self, base)
set the base of the log scaling (major tick every base**i, i integer)
set the base of the log scaling (major tick every base**i, i integer)
[ "set", "the", "base", "of", "the", "log", "scaling", "(", "major", "tick", "every", "base", "**", "i", "i", "integer", ")" ]
def base(self, base): """ set the base of the log scaling (major tick every base**i, i integer) """ self._base = base + 0.0
[ "def", "base", "(", "self", ",", "base", ")", ":", "self", ".", "_base", "=", "base", "+", "0.0" ]
https://github.com/omz/PythonistaAppTemplate/blob/f560f93f8876d82a21d108977f90583df08d55af/PythonistaAppTemplate/PythonistaKit.framework/pylib_ext/matplotlib/ticker.py#L1393-L1397
debian-calibre/calibre
020fc81d3936a64b2ac51459ecb796666ab6a051
src/calibre/ebooks/rtf2xml/field_strings.py
python
FieldStrings.__include_text_func
(self, field_name, name, line)
return [None, None, the_string]
Required: field_name -- the first word in the string name --the changed name according to the dictionary line -- the string to be parse Returns: The name of the field Logic:
Required: field_name -- the first word in the string name --the changed name according to the dictionary line -- the string to be parse Returns: The name of the field Logic:
[ "Required", ":", "field_name", "--", "the", "first", "word", "in", "the", "string", "name", "--", "the", "changed", "name", "according", "to", "the", "dictionary", "line", "--", "the", "string", "to", "be", "parse", "Returns", ":", "The", "name", "of", "...
def __include_text_func(self, field_name, name, line): """ Required: field_name -- the first word in the string name --the changed name according to the dictionary line -- the string to be parse Returns: The name of the field Logic: """ the_string = name match_group = re.search(self.__format_text_exp, line) if match_group: name = match_group.group(1) changed_name = self.__text_format_dict.get(name) if changed_name: the_string += '<format>%s' % changed_name else: sys.stderr.write('module is fields_string\n') sys.stderr.write('method is __parse_num_type\n') sys.stderr.write('no dictionary entry for %s\n' % name) match_group = re.search(self.__filter_switch, line) if match_group: arg = match_group.group(1) the_string += '<filter>%s' % arg # \c "txt" "file name" # want "file name" so must get rid of \c "txt" line = re.sub(self.__filter_switch, '', line) match_group = re.search(self.__quote_exp, line) if match_group: arg = match_group.group(1) arg = arg.replace('"', "&quot;") the_string += '<argument>%s' % arg else: sys.stderr.write('Module is field_strings\n') sys.stderr.write('method is include_text_func\n') sys.stderr.write('no argument for include text\n') index = line.find('\\!') if index > -1: the_string += '<no-field-update>true' return [None, None, the_string]
[ "def", "__include_text_func", "(", "self", ",", "field_name", ",", "name", ",", "line", ")", ":", "the_string", "=", "name", "match_group", "=", "re", ".", "search", "(", "self", ".", "__format_text_exp", ",", "line", ")", "if", "match_group", ":", "name",...
https://github.com/debian-calibre/calibre/blob/020fc81d3936a64b2ac51459ecb796666ab6a051/src/calibre/ebooks/rtf2xml/field_strings.py#L442-L482