partition stringclasses 3 values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1 value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
test | walk_egg | Walk an unpacked egg's contents, skipping the metadata directory | environment/lib/python2.7/site-packages/distribute-0.6.31-py2.7.egg/setuptools/command/bdist_egg.py | def walk_egg(egg_dir):
"""Walk an unpacked egg's contents, skipping the metadata directory"""
walker = os.walk(egg_dir)
base,dirs,files = walker.next()
if 'EGG-INFO' in dirs:
dirs.remove('EGG-INFO')
yield base,dirs,files
for bdf in walker:
yield bdf | def walk_egg(egg_dir):
"""Walk an unpacked egg's contents, skipping the metadata directory"""
walker = os.walk(egg_dir)
base,dirs,files = walker.next()
if 'EGG-INFO' in dirs:
dirs.remove('EGG-INFO')
yield base,dirs,files
for bdf in walker:
yield bdf | [
"Walk",
"an",
"unpacked",
"egg",
"s",
"contents",
"skipping",
"the",
"metadata",
"directory"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/distribute-0.6.31-py2.7.egg/setuptools/command/bdist_egg.py#L379-L387 | [
"def",
"walk_egg",
"(",
"egg_dir",
")",
":",
"walker",
"=",
"os",
".",
"walk",
"(",
"egg_dir",
")",
"base",
",",
"dirs",
",",
"files",
"=",
"walker",
".",
"next",
"(",
")",
"if",
"'EGG-INFO'",
"in",
"dirs",
":",
"dirs",
".",
"remove",
"(",
"'EGG-INFO'",
")",
"yield",
"base",
",",
"dirs",
",",
"files",
"for",
"bdf",
"in",
"walker",
":",
"yield",
"bdf"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | scan_module | Check whether module possibly uses unsafe-for-zipfile stuff | environment/lib/python2.7/site-packages/distribute-0.6.31-py2.7.egg/setuptools/command/bdist_egg.py | def scan_module(egg_dir, base, name, stubs):
"""Check whether module possibly uses unsafe-for-zipfile stuff"""
filename = os.path.join(base,name)
if filename[:-1] in stubs:
return True # Extension module
pkg = base[len(egg_dir)+1:].replace(os.sep,'.')
module = pkg+(pkg and '.' or '')+os.path.splitext(name)[0]
if sys.version_info < (3, 3):
skip = 8 # skip magic & date
else:
skip = 12 # skip magic & date & file size
f = open(filename,'rb'); f.read(skip)
code = marshal.load(f); f.close()
safe = True
symbols = dict.fromkeys(iter_symbols(code))
for bad in ['__file__', '__path__']:
if bad in symbols:
log.warn("%s: module references %s", module, bad)
safe = False
if 'inspect' in symbols:
for bad in [
'getsource', 'getabsfile', 'getsourcefile', 'getfile'
'getsourcelines', 'findsource', 'getcomments', 'getframeinfo',
'getinnerframes', 'getouterframes', 'stack', 'trace'
]:
if bad in symbols:
log.warn("%s: module MAY be using inspect.%s", module, bad)
safe = False
if '__name__' in symbols and '__main__' in symbols and '.' not in module:
if sys.version[:3]=="2.4": # -m works w/zipfiles in 2.5
log.warn("%s: top-level module may be 'python -m' script", module)
safe = False
return safe | def scan_module(egg_dir, base, name, stubs):
"""Check whether module possibly uses unsafe-for-zipfile stuff"""
filename = os.path.join(base,name)
if filename[:-1] in stubs:
return True # Extension module
pkg = base[len(egg_dir)+1:].replace(os.sep,'.')
module = pkg+(pkg and '.' or '')+os.path.splitext(name)[0]
if sys.version_info < (3, 3):
skip = 8 # skip magic & date
else:
skip = 12 # skip magic & date & file size
f = open(filename,'rb'); f.read(skip)
code = marshal.load(f); f.close()
safe = True
symbols = dict.fromkeys(iter_symbols(code))
for bad in ['__file__', '__path__']:
if bad in symbols:
log.warn("%s: module references %s", module, bad)
safe = False
if 'inspect' in symbols:
for bad in [
'getsource', 'getabsfile', 'getsourcefile', 'getfile'
'getsourcelines', 'findsource', 'getcomments', 'getframeinfo',
'getinnerframes', 'getouterframes', 'stack', 'trace'
]:
if bad in symbols:
log.warn("%s: module MAY be using inspect.%s", module, bad)
safe = False
if '__name__' in symbols and '__main__' in symbols and '.' not in module:
if sys.version[:3]=="2.4": # -m works w/zipfiles in 2.5
log.warn("%s: top-level module may be 'python -m' script", module)
safe = False
return safe | [
"Check",
"whether",
"module",
"possibly",
"uses",
"unsafe",
"-",
"for",
"-",
"zipfile",
"stuff"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/distribute-0.6.31-py2.7.egg/setuptools/command/bdist_egg.py#L420-L453 | [
"def",
"scan_module",
"(",
"egg_dir",
",",
"base",
",",
"name",
",",
"stubs",
")",
":",
"filename",
"=",
"os",
".",
"path",
".",
"join",
"(",
"base",
",",
"name",
")",
"if",
"filename",
"[",
":",
"-",
"1",
"]",
"in",
"stubs",
":",
"return",
"True",
"# Extension module",
"pkg",
"=",
"base",
"[",
"len",
"(",
"egg_dir",
")",
"+",
"1",
":",
"]",
".",
"replace",
"(",
"os",
".",
"sep",
",",
"'.'",
")",
"module",
"=",
"pkg",
"+",
"(",
"pkg",
"and",
"'.'",
"or",
"''",
")",
"+",
"os",
".",
"path",
".",
"splitext",
"(",
"name",
")",
"[",
"0",
"]",
"if",
"sys",
".",
"version_info",
"<",
"(",
"3",
",",
"3",
")",
":",
"skip",
"=",
"8",
"# skip magic & date",
"else",
":",
"skip",
"=",
"12",
"# skip magic & date & file size",
"f",
"=",
"open",
"(",
"filename",
",",
"'rb'",
")",
"f",
".",
"read",
"(",
"skip",
")",
"code",
"=",
"marshal",
".",
"load",
"(",
"f",
")",
"f",
".",
"close",
"(",
")",
"safe",
"=",
"True",
"symbols",
"=",
"dict",
".",
"fromkeys",
"(",
"iter_symbols",
"(",
"code",
")",
")",
"for",
"bad",
"in",
"[",
"'__file__'",
",",
"'__path__'",
"]",
":",
"if",
"bad",
"in",
"symbols",
":",
"log",
".",
"warn",
"(",
"\"%s: module references %s\"",
",",
"module",
",",
"bad",
")",
"safe",
"=",
"False",
"if",
"'inspect'",
"in",
"symbols",
":",
"for",
"bad",
"in",
"[",
"'getsource'",
",",
"'getabsfile'",
",",
"'getsourcefile'",
",",
"'getfile'",
"'getsourcelines'",
",",
"'findsource'",
",",
"'getcomments'",
",",
"'getframeinfo'",
",",
"'getinnerframes'",
",",
"'getouterframes'",
",",
"'stack'",
",",
"'trace'",
"]",
":",
"if",
"bad",
"in",
"symbols",
":",
"log",
".",
"warn",
"(",
"\"%s: module MAY be using inspect.%s\"",
",",
"module",
",",
"bad",
")",
"safe",
"=",
"False",
"if",
"'__name__'",
"in",
"symbols",
"and",
"'__main__'",
"in",
"symbols",
"and",
"'.'",
"not",
"in",
"module",
":",
"if",
"sys",
".",
"version",
"[",
":",
"3",
"]",
"==",
"\"2.4\"",
":",
"# -m works w/zipfiles in 2.5",
"log",
".",
"warn",
"(",
"\"%s: top-level module may be 'python -m' script\"",
",",
"module",
")",
"safe",
"=",
"False",
"return",
"safe"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | bdist_egg.make_init_files | Create missing package __init__ files | environment/lib/python2.7/site-packages/distribute-0.6.31-py2.7.egg/setuptools/command/bdist_egg.py | def make_init_files(self):
"""Create missing package __init__ files"""
init_files = []
for base,dirs,files in walk_egg(self.bdist_dir):
if base==self.bdist_dir:
# don't put an __init__ in the root
continue
for name in files:
if name.endswith('.py'):
if '__init__.py' not in files:
pkg = base[len(self.bdist_dir)+1:].replace(os.sep,'.')
if self.distribution.has_contents_for(pkg):
log.warn("Creating missing __init__.py for %s",pkg)
filename = os.path.join(base,'__init__.py')
if not self.dry_run:
f = open(filename,'w'); f.write(NS_PKG_STUB)
f.close()
init_files.append(filename)
break
else:
# not a package, don't traverse to subdirectories
dirs[:] = []
return init_files | def make_init_files(self):
"""Create missing package __init__ files"""
init_files = []
for base,dirs,files in walk_egg(self.bdist_dir):
if base==self.bdist_dir:
# don't put an __init__ in the root
continue
for name in files:
if name.endswith('.py'):
if '__init__.py' not in files:
pkg = base[len(self.bdist_dir)+1:].replace(os.sep,'.')
if self.distribution.has_contents_for(pkg):
log.warn("Creating missing __init__.py for %s",pkg)
filename = os.path.join(base,'__init__.py')
if not self.dry_run:
f = open(filename,'w'); f.write(NS_PKG_STUB)
f.close()
init_files.append(filename)
break
else:
# not a package, don't traverse to subdirectories
dirs[:] = []
return init_files | [
"Create",
"missing",
"package",
"__init__",
"files"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/distribute-0.6.31-py2.7.egg/setuptools/command/bdist_egg.py#L268-L291 | [
"def",
"make_init_files",
"(",
"self",
")",
":",
"init_files",
"=",
"[",
"]",
"for",
"base",
",",
"dirs",
",",
"files",
"in",
"walk_egg",
"(",
"self",
".",
"bdist_dir",
")",
":",
"if",
"base",
"==",
"self",
".",
"bdist_dir",
":",
"# don't put an __init__ in the root",
"continue",
"for",
"name",
"in",
"files",
":",
"if",
"name",
".",
"endswith",
"(",
"'.py'",
")",
":",
"if",
"'__init__.py'",
"not",
"in",
"files",
":",
"pkg",
"=",
"base",
"[",
"len",
"(",
"self",
".",
"bdist_dir",
")",
"+",
"1",
":",
"]",
".",
"replace",
"(",
"os",
".",
"sep",
",",
"'.'",
")",
"if",
"self",
".",
"distribution",
".",
"has_contents_for",
"(",
"pkg",
")",
":",
"log",
".",
"warn",
"(",
"\"Creating missing __init__.py for %s\"",
",",
"pkg",
")",
"filename",
"=",
"os",
".",
"path",
".",
"join",
"(",
"base",
",",
"'__init__.py'",
")",
"if",
"not",
"self",
".",
"dry_run",
":",
"f",
"=",
"open",
"(",
"filename",
",",
"'w'",
")",
"f",
".",
"write",
"(",
"NS_PKG_STUB",
")",
"f",
".",
"close",
"(",
")",
"init_files",
".",
"append",
"(",
"filename",
")",
"break",
"else",
":",
"# not a package, don't traverse to subdirectories",
"dirs",
"[",
":",
"]",
"=",
"[",
"]",
"return",
"init_files"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | launch_new_instance | Create and run the IPython controller | environment/lib/python2.7/site-packages/IPython/parallel/apps/ipcontrollerapp.py | def launch_new_instance():
"""Create and run the IPython controller"""
if sys.platform == 'win32':
# make sure we don't get called from a multiprocessing subprocess
# this can result in infinite Controllers being started on Windows
# which doesn't have a proper fork, so multiprocessing is wonky
# this only comes up when IPython has been installed using vanilla
# setuptools, and *not* distribute.
import multiprocessing
p = multiprocessing.current_process()
# the main process has name 'MainProcess'
# subprocesses will have names like 'Process-1'
if p.name != 'MainProcess':
# we are a subprocess, don't start another Controller!
return
app = IPControllerApp.instance()
app.initialize()
app.start() | def launch_new_instance():
"""Create and run the IPython controller"""
if sys.platform == 'win32':
# make sure we don't get called from a multiprocessing subprocess
# this can result in infinite Controllers being started on Windows
# which doesn't have a proper fork, so multiprocessing is wonky
# this only comes up when IPython has been installed using vanilla
# setuptools, and *not* distribute.
import multiprocessing
p = multiprocessing.current_process()
# the main process has name 'MainProcess'
# subprocesses will have names like 'Process-1'
if p.name != 'MainProcess':
# we are a subprocess, don't start another Controller!
return
app = IPControllerApp.instance()
app.initialize()
app.start() | [
"Create",
"and",
"run",
"the",
"IPython",
"controller"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/apps/ipcontrollerapp.py#L469-L487 | [
"def",
"launch_new_instance",
"(",
")",
":",
"if",
"sys",
".",
"platform",
"==",
"'win32'",
":",
"# make sure we don't get called from a multiprocessing subprocess",
"# this can result in infinite Controllers being started on Windows",
"# which doesn't have a proper fork, so multiprocessing is wonky",
"# this only comes up when IPython has been installed using vanilla",
"# setuptools, and *not* distribute.",
"import",
"multiprocessing",
"p",
"=",
"multiprocessing",
".",
"current_process",
"(",
")",
"# the main process has name 'MainProcess'",
"# subprocesses will have names like 'Process-1'",
"if",
"p",
".",
"name",
"!=",
"'MainProcess'",
":",
"# we are a subprocess, don't start another Controller!",
"return",
"app",
"=",
"IPControllerApp",
".",
"instance",
"(",
")",
"app",
".",
"initialize",
"(",
")",
"app",
".",
"start",
"(",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | IPControllerApp.save_connection_dict | save a connection dict to json file. | environment/lib/python2.7/site-packages/IPython/parallel/apps/ipcontrollerapp.py | def save_connection_dict(self, fname, cdict):
"""save a connection dict to json file."""
c = self.config
url = cdict['url']
location = cdict['location']
if not location:
try:
proto,ip,port = split_url(url)
except AssertionError:
pass
else:
try:
location = socket.gethostbyname_ex(socket.gethostname())[2][-1]
except (socket.gaierror, IndexError):
self.log.warn("Could not identify this machine's IP, assuming 127.0.0.1."
" You may need to specify '--location=<external_ip_address>' to help"
" IPython decide when to connect via loopback.")
location = '127.0.0.1'
cdict['location'] = location
fname = os.path.join(self.profile_dir.security_dir, fname)
self.log.info("writing connection info to %s", fname)
with open(fname, 'w') as f:
f.write(json.dumps(cdict, indent=2))
os.chmod(fname, stat.S_IRUSR|stat.S_IWUSR) | def save_connection_dict(self, fname, cdict):
"""save a connection dict to json file."""
c = self.config
url = cdict['url']
location = cdict['location']
if not location:
try:
proto,ip,port = split_url(url)
except AssertionError:
pass
else:
try:
location = socket.gethostbyname_ex(socket.gethostname())[2][-1]
except (socket.gaierror, IndexError):
self.log.warn("Could not identify this machine's IP, assuming 127.0.0.1."
" You may need to specify '--location=<external_ip_address>' to help"
" IPython decide when to connect via loopback.")
location = '127.0.0.1'
cdict['location'] = location
fname = os.path.join(self.profile_dir.security_dir, fname)
self.log.info("writing connection info to %s", fname)
with open(fname, 'w') as f:
f.write(json.dumps(cdict, indent=2))
os.chmod(fname, stat.S_IRUSR|stat.S_IWUSR) | [
"save",
"a",
"connection",
"dict",
"to",
"json",
"file",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/apps/ipcontrollerapp.py#L209-L232 | [
"def",
"save_connection_dict",
"(",
"self",
",",
"fname",
",",
"cdict",
")",
":",
"c",
"=",
"self",
".",
"config",
"url",
"=",
"cdict",
"[",
"'url'",
"]",
"location",
"=",
"cdict",
"[",
"'location'",
"]",
"if",
"not",
"location",
":",
"try",
":",
"proto",
",",
"ip",
",",
"port",
"=",
"split_url",
"(",
"url",
")",
"except",
"AssertionError",
":",
"pass",
"else",
":",
"try",
":",
"location",
"=",
"socket",
".",
"gethostbyname_ex",
"(",
"socket",
".",
"gethostname",
"(",
")",
")",
"[",
"2",
"]",
"[",
"-",
"1",
"]",
"except",
"(",
"socket",
".",
"gaierror",
",",
"IndexError",
")",
":",
"self",
".",
"log",
".",
"warn",
"(",
"\"Could not identify this machine's IP, assuming 127.0.0.1.\"",
"\" You may need to specify '--location=<external_ip_address>' to help\"",
"\" IPython decide when to connect via loopback.\"",
")",
"location",
"=",
"'127.0.0.1'",
"cdict",
"[",
"'location'",
"]",
"=",
"location",
"fname",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"profile_dir",
".",
"security_dir",
",",
"fname",
")",
"self",
".",
"log",
".",
"info",
"(",
"\"writing connection info to %s\"",
",",
"fname",
")",
"with",
"open",
"(",
"fname",
",",
"'w'",
")",
"as",
"f",
":",
"f",
".",
"write",
"(",
"json",
".",
"dumps",
"(",
"cdict",
",",
"indent",
"=",
"2",
")",
")",
"os",
".",
"chmod",
"(",
"fname",
",",
"stat",
".",
"S_IRUSR",
"|",
"stat",
".",
"S_IWUSR",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | IPControllerApp.load_config_from_json | load config from existing json connector files. | environment/lib/python2.7/site-packages/IPython/parallel/apps/ipcontrollerapp.py | def load_config_from_json(self):
"""load config from existing json connector files."""
c = self.config
self.log.debug("loading config from JSON")
# load from engine config
fname = os.path.join(self.profile_dir.security_dir, self.engine_json_file)
self.log.info("loading connection info from %s", fname)
with open(fname) as f:
cfg = json.loads(f.read())
key = cfg['exec_key']
# json gives unicode, Session.key wants bytes
c.Session.key = key.encode('ascii')
xport,addr = cfg['url'].split('://')
c.HubFactory.engine_transport = xport
ip,ports = addr.split(':')
c.HubFactory.engine_ip = ip
c.HubFactory.regport = int(ports)
self.location = cfg['location']
if not self.engine_ssh_server:
self.engine_ssh_server = cfg['ssh']
# load client config
fname = os.path.join(self.profile_dir.security_dir, self.client_json_file)
self.log.info("loading connection info from %s", fname)
with open(fname) as f:
cfg = json.loads(f.read())
assert key == cfg['exec_key'], "exec_key mismatch between engine and client keys"
xport,addr = cfg['url'].split('://')
c.HubFactory.client_transport = xport
ip,ports = addr.split(':')
c.HubFactory.client_ip = ip
if not self.ssh_server:
self.ssh_server = cfg['ssh']
assert int(ports) == c.HubFactory.regport, "regport mismatch" | def load_config_from_json(self):
"""load config from existing json connector files."""
c = self.config
self.log.debug("loading config from JSON")
# load from engine config
fname = os.path.join(self.profile_dir.security_dir, self.engine_json_file)
self.log.info("loading connection info from %s", fname)
with open(fname) as f:
cfg = json.loads(f.read())
key = cfg['exec_key']
# json gives unicode, Session.key wants bytes
c.Session.key = key.encode('ascii')
xport,addr = cfg['url'].split('://')
c.HubFactory.engine_transport = xport
ip,ports = addr.split(':')
c.HubFactory.engine_ip = ip
c.HubFactory.regport = int(ports)
self.location = cfg['location']
if not self.engine_ssh_server:
self.engine_ssh_server = cfg['ssh']
# load client config
fname = os.path.join(self.profile_dir.security_dir, self.client_json_file)
self.log.info("loading connection info from %s", fname)
with open(fname) as f:
cfg = json.loads(f.read())
assert key == cfg['exec_key'], "exec_key mismatch between engine and client keys"
xport,addr = cfg['url'].split('://')
c.HubFactory.client_transport = xport
ip,ports = addr.split(':')
c.HubFactory.client_ip = ip
if not self.ssh_server:
self.ssh_server = cfg['ssh']
assert int(ports) == c.HubFactory.regport, "regport mismatch" | [
"load",
"config",
"from",
"existing",
"json",
"connector",
"files",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/apps/ipcontrollerapp.py#L234-L266 | [
"def",
"load_config_from_json",
"(",
"self",
")",
":",
"c",
"=",
"self",
".",
"config",
"self",
".",
"log",
".",
"debug",
"(",
"\"loading config from JSON\"",
")",
"# load from engine config",
"fname",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"profile_dir",
".",
"security_dir",
",",
"self",
".",
"engine_json_file",
")",
"self",
".",
"log",
".",
"info",
"(",
"\"loading connection info from %s\"",
",",
"fname",
")",
"with",
"open",
"(",
"fname",
")",
"as",
"f",
":",
"cfg",
"=",
"json",
".",
"loads",
"(",
"f",
".",
"read",
"(",
")",
")",
"key",
"=",
"cfg",
"[",
"'exec_key'",
"]",
"# json gives unicode, Session.key wants bytes",
"c",
".",
"Session",
".",
"key",
"=",
"key",
".",
"encode",
"(",
"'ascii'",
")",
"xport",
",",
"addr",
"=",
"cfg",
"[",
"'url'",
"]",
".",
"split",
"(",
"'://'",
")",
"c",
".",
"HubFactory",
".",
"engine_transport",
"=",
"xport",
"ip",
",",
"ports",
"=",
"addr",
".",
"split",
"(",
"':'",
")",
"c",
".",
"HubFactory",
".",
"engine_ip",
"=",
"ip",
"c",
".",
"HubFactory",
".",
"regport",
"=",
"int",
"(",
"ports",
")",
"self",
".",
"location",
"=",
"cfg",
"[",
"'location'",
"]",
"if",
"not",
"self",
".",
"engine_ssh_server",
":",
"self",
".",
"engine_ssh_server",
"=",
"cfg",
"[",
"'ssh'",
"]",
"# load client config",
"fname",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"profile_dir",
".",
"security_dir",
",",
"self",
".",
"client_json_file",
")",
"self",
".",
"log",
".",
"info",
"(",
"\"loading connection info from %s\"",
",",
"fname",
")",
"with",
"open",
"(",
"fname",
")",
"as",
"f",
":",
"cfg",
"=",
"json",
".",
"loads",
"(",
"f",
".",
"read",
"(",
")",
")",
"assert",
"key",
"==",
"cfg",
"[",
"'exec_key'",
"]",
",",
"\"exec_key mismatch between engine and client keys\"",
"xport",
",",
"addr",
"=",
"cfg",
"[",
"'url'",
"]",
".",
"split",
"(",
"'://'",
")",
"c",
".",
"HubFactory",
".",
"client_transport",
"=",
"xport",
"ip",
",",
"ports",
"=",
"addr",
".",
"split",
"(",
"':'",
")",
"c",
".",
"HubFactory",
".",
"client_ip",
"=",
"ip",
"if",
"not",
"self",
".",
"ssh_server",
":",
"self",
".",
"ssh_server",
"=",
"cfg",
"[",
"'ssh'",
"]",
"assert",
"int",
"(",
"ports",
")",
"==",
"c",
".",
"HubFactory",
".",
"regport",
",",
"\"regport mismatch\""
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | IPControllerApp.load_secondary_config | secondary config, loading from JSON and setting defaults | environment/lib/python2.7/site-packages/IPython/parallel/apps/ipcontrollerapp.py | def load_secondary_config(self):
"""secondary config, loading from JSON and setting defaults"""
if self.reuse_files:
try:
self.load_config_from_json()
except (AssertionError,IOError) as e:
self.log.error("Could not load config from JSON: %s" % e)
else:
# successfully loaded config from JSON, and reuse=True
# no need to wite back the same file
self.write_connection_files = False
# switch Session.key default to secure
default_secure(self.config)
self.log.debug("Config changed")
self.log.debug(repr(self.config)) | def load_secondary_config(self):
"""secondary config, loading from JSON and setting defaults"""
if self.reuse_files:
try:
self.load_config_from_json()
except (AssertionError,IOError) as e:
self.log.error("Could not load config from JSON: %s" % e)
else:
# successfully loaded config from JSON, and reuse=True
# no need to wite back the same file
self.write_connection_files = False
# switch Session.key default to secure
default_secure(self.config)
self.log.debug("Config changed")
self.log.debug(repr(self.config)) | [
"secondary",
"config",
"loading",
"from",
"JSON",
"and",
"setting",
"defaults"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/apps/ipcontrollerapp.py#L282-L297 | [
"def",
"load_secondary_config",
"(",
"self",
")",
":",
"if",
"self",
".",
"reuse_files",
":",
"try",
":",
"self",
".",
"load_config_from_json",
"(",
")",
"except",
"(",
"AssertionError",
",",
"IOError",
")",
"as",
"e",
":",
"self",
".",
"log",
".",
"error",
"(",
"\"Could not load config from JSON: %s\"",
"%",
"e",
")",
"else",
":",
"# successfully loaded config from JSON, and reuse=True",
"# no need to wite back the same file",
"self",
".",
"write_connection_files",
"=",
"False",
"# switch Session.key default to secure",
"default_secure",
"(",
"self",
".",
"config",
")",
"self",
".",
"log",
".",
"debug",
"(",
"\"Config changed\"",
")",
"self",
".",
"log",
".",
"debug",
"(",
"repr",
"(",
"self",
".",
"config",
")",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | script_args | single decorator for adding script args | environment/lib/python2.7/site-packages/IPython/core/magics/script.py | def script_args(f):
"""single decorator for adding script args"""
args = [
magic_arguments.argument(
'--out', type=str,
help="""The variable in which to store stdout from the script.
If the script is backgrounded, this will be the stdout *pipe*,
instead of the stderr text itself.
"""
),
magic_arguments.argument(
'--err', type=str,
help="""The variable in which to store stderr from the script.
If the script is backgrounded, this will be the stderr *pipe*,
instead of the stderr text itself.
"""
),
magic_arguments.argument(
'--bg', action="store_true",
help="""Whether to run the script in the background.
If given, the only way to see the output of the command is
with --out/err.
"""
),
magic_arguments.argument(
'--proc', type=str,
help="""The variable in which to store Popen instance.
This is used only when --bg option is given.
"""
),
]
for arg in args:
f = arg(f)
return f | def script_args(f):
"""single decorator for adding script args"""
args = [
magic_arguments.argument(
'--out', type=str,
help="""The variable in which to store stdout from the script.
If the script is backgrounded, this will be the stdout *pipe*,
instead of the stderr text itself.
"""
),
magic_arguments.argument(
'--err', type=str,
help="""The variable in which to store stderr from the script.
If the script is backgrounded, this will be the stderr *pipe*,
instead of the stderr text itself.
"""
),
magic_arguments.argument(
'--bg', action="store_true",
help="""Whether to run the script in the background.
If given, the only way to see the output of the command is
with --out/err.
"""
),
magic_arguments.argument(
'--proc', type=str,
help="""The variable in which to store Popen instance.
This is used only when --bg option is given.
"""
),
]
for arg in args:
f = arg(f)
return f | [
"single",
"decorator",
"for",
"adding",
"script",
"args"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/core/magics/script.py#L40-L73 | [
"def",
"script_args",
"(",
"f",
")",
":",
"args",
"=",
"[",
"magic_arguments",
".",
"argument",
"(",
"'--out'",
",",
"type",
"=",
"str",
",",
"help",
"=",
"\"\"\"The variable in which to store stdout from the script.\n If the script is backgrounded, this will be the stdout *pipe*,\n instead of the stderr text itself.\n \"\"\"",
")",
",",
"magic_arguments",
".",
"argument",
"(",
"'--err'",
",",
"type",
"=",
"str",
",",
"help",
"=",
"\"\"\"The variable in which to store stderr from the script.\n If the script is backgrounded, this will be the stderr *pipe*,\n instead of the stderr text itself.\n \"\"\"",
")",
",",
"magic_arguments",
".",
"argument",
"(",
"'--bg'",
",",
"action",
"=",
"\"store_true\"",
",",
"help",
"=",
"\"\"\"Whether to run the script in the background.\n If given, the only way to see the output of the command is\n with --out/err.\n \"\"\"",
")",
",",
"magic_arguments",
".",
"argument",
"(",
"'--proc'",
",",
"type",
"=",
"str",
",",
"help",
"=",
"\"\"\"The variable in which to store Popen instance.\n This is used only when --bg option is given.\n \"\"\"",
")",
",",
"]",
"for",
"arg",
"in",
"args",
":",
"f",
"=",
"arg",
"(",
"f",
")",
"return",
"f"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | exec_args | decorator for adding block/targets args for execution
applied to %pxconfig and %%px | environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py | def exec_args(f):
"""decorator for adding block/targets args for execution
applied to %pxconfig and %%px
"""
args = [
magic_arguments.argument('-b', '--block', action="store_const",
const=True, dest='block',
help="use blocking (sync) execution",
),
magic_arguments.argument('-a', '--noblock', action="store_const",
const=False, dest='block',
help="use non-blocking (async) execution",
),
magic_arguments.argument('-t', '--targets', type=str,
help="specify the targets on which to execute",
),
magic_arguments.argument('--verbose', action="store_const",
const=True, dest="set_verbose",
help="print a message at each execution",
),
magic_arguments.argument('--no-verbose', action="store_const",
const=False, dest="set_verbose",
help="don't print any messages",
),
]
for a in args:
f = a(f)
return f | def exec_args(f):
"""decorator for adding block/targets args for execution
applied to %pxconfig and %%px
"""
args = [
magic_arguments.argument('-b', '--block', action="store_const",
const=True, dest='block',
help="use blocking (sync) execution",
),
magic_arguments.argument('-a', '--noblock', action="store_const",
const=False, dest='block',
help="use non-blocking (async) execution",
),
magic_arguments.argument('-t', '--targets', type=str,
help="specify the targets on which to execute",
),
magic_arguments.argument('--verbose', action="store_const",
const=True, dest="set_verbose",
help="print a message at each execution",
),
magic_arguments.argument('--no-verbose', action="store_const",
const=False, dest="set_verbose",
help="don't print any messages",
),
]
for a in args:
f = a(f)
return f | [
"decorator",
"for",
"adding",
"block",
"/",
"targets",
"args",
"for",
"execution",
"applied",
"to",
"%pxconfig",
"and",
"%%px"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py#L56-L84 | [
"def",
"exec_args",
"(",
"f",
")",
":",
"args",
"=",
"[",
"magic_arguments",
".",
"argument",
"(",
"'-b'",
",",
"'--block'",
",",
"action",
"=",
"\"store_const\"",
",",
"const",
"=",
"True",
",",
"dest",
"=",
"'block'",
",",
"help",
"=",
"\"use blocking (sync) execution\"",
",",
")",
",",
"magic_arguments",
".",
"argument",
"(",
"'-a'",
",",
"'--noblock'",
",",
"action",
"=",
"\"store_const\"",
",",
"const",
"=",
"False",
",",
"dest",
"=",
"'block'",
",",
"help",
"=",
"\"use non-blocking (async) execution\"",
",",
")",
",",
"magic_arguments",
".",
"argument",
"(",
"'-t'",
",",
"'--targets'",
",",
"type",
"=",
"str",
",",
"help",
"=",
"\"specify the targets on which to execute\"",
",",
")",
",",
"magic_arguments",
".",
"argument",
"(",
"'--verbose'",
",",
"action",
"=",
"\"store_const\"",
",",
"const",
"=",
"True",
",",
"dest",
"=",
"\"set_verbose\"",
",",
"help",
"=",
"\"print a message at each execution\"",
",",
")",
",",
"magic_arguments",
".",
"argument",
"(",
"'--no-verbose'",
",",
"action",
"=",
"\"store_const\"",
",",
"const",
"=",
"False",
",",
"dest",
"=",
"\"set_verbose\"",
",",
"help",
"=",
"\"don't print any messages\"",
",",
")",
",",
"]",
"for",
"a",
"in",
"args",
":",
"f",
"=",
"a",
"(",
"f",
")",
"return",
"f"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | output_args | decorator for output-formatting args
applied to %pxresult and %%px | environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py | def output_args(f):
"""decorator for output-formatting args
applied to %pxresult and %%px
"""
args = [
magic_arguments.argument('-r', action="store_const", dest='groupby',
const='order',
help="collate outputs in order (same as group-outputs=order)"
),
magic_arguments.argument('-e', action="store_const", dest='groupby',
const='engine',
help="group outputs by engine (same as group-outputs=engine)"
),
magic_arguments.argument('--group-outputs', dest='groupby', type=str,
choices=['engine', 'order', 'type'], default='type',
help="""Group the outputs in a particular way.
Choices are:
type: group outputs of all engines by type (stdout, stderr, displaypub, etc.).
engine: display all output for each engine together.
order: like type, but individual displaypub output from each engine is collated.
For example, if multiple plots are generated by each engine, the first
figure of each engine will be displayed, then the second of each, etc.
"""
),
magic_arguments.argument('-o', '--out', dest='save_name', type=str,
help="""store the AsyncResult object for this computation
in the global namespace under this name.
"""
),
]
for a in args:
f = a(f)
return f | def output_args(f):
"""decorator for output-formatting args
applied to %pxresult and %%px
"""
args = [
magic_arguments.argument('-r', action="store_const", dest='groupby',
const='order',
help="collate outputs in order (same as group-outputs=order)"
),
magic_arguments.argument('-e', action="store_const", dest='groupby',
const='engine',
help="group outputs by engine (same as group-outputs=engine)"
),
magic_arguments.argument('--group-outputs', dest='groupby', type=str,
choices=['engine', 'order', 'type'], default='type',
help="""Group the outputs in a particular way.
Choices are:
type: group outputs of all engines by type (stdout, stderr, displaypub, etc.).
engine: display all output for each engine together.
order: like type, but individual displaypub output from each engine is collated.
For example, if multiple plots are generated by each engine, the first
figure of each engine will be displayed, then the second of each, etc.
"""
),
magic_arguments.argument('-o', '--out', dest='save_name', type=str,
help="""store the AsyncResult object for this computation
in the global namespace under this name.
"""
),
]
for a in args:
f = a(f)
return f | [
"decorator",
"for",
"output",
"-",
"formatting",
"args",
"applied",
"to",
"%pxresult",
"and",
"%%px"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py#L86-L123 | [
"def",
"output_args",
"(",
"f",
")",
":",
"args",
"=",
"[",
"magic_arguments",
".",
"argument",
"(",
"'-r'",
",",
"action",
"=",
"\"store_const\"",
",",
"dest",
"=",
"'groupby'",
",",
"const",
"=",
"'order'",
",",
"help",
"=",
"\"collate outputs in order (same as group-outputs=order)\"",
")",
",",
"magic_arguments",
".",
"argument",
"(",
"'-e'",
",",
"action",
"=",
"\"store_const\"",
",",
"dest",
"=",
"'groupby'",
",",
"const",
"=",
"'engine'",
",",
"help",
"=",
"\"group outputs by engine (same as group-outputs=engine)\"",
")",
",",
"magic_arguments",
".",
"argument",
"(",
"'--group-outputs'",
",",
"dest",
"=",
"'groupby'",
",",
"type",
"=",
"str",
",",
"choices",
"=",
"[",
"'engine'",
",",
"'order'",
",",
"'type'",
"]",
",",
"default",
"=",
"'type'",
",",
"help",
"=",
"\"\"\"Group the outputs in a particular way.\n \n Choices are:\n \n type: group outputs of all engines by type (stdout, stderr, displaypub, etc.).\n \n engine: display all output for each engine together.\n\n order: like type, but individual displaypub output from each engine is collated.\n For example, if multiple plots are generated by each engine, the first\n figure of each engine will be displayed, then the second of each, etc.\n \"\"\"",
")",
",",
"magic_arguments",
".",
"argument",
"(",
"'-o'",
",",
"'--out'",
",",
"dest",
"=",
"'save_name'",
",",
"type",
"=",
"str",
",",
"help",
"=",
"\"\"\"store the AsyncResult object for this computation\n in the global namespace under this name.\n \"\"\"",
")",
",",
"]",
"for",
"a",
"in",
"args",
":",
"f",
"=",
"a",
"(",
"f",
")",
"return",
"f"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | ParallelMagics.pxconfig | configure default targets/blocking for %px magics | environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py | def pxconfig(self, line):
"""configure default targets/blocking for %px magics"""
args = magic_arguments.parse_argstring(self.pxconfig, line)
if args.targets:
self.view.targets = self._eval_target_str(args.targets)
if args.block is not None:
self.view.block = args.block
if args.set_verbose is not None:
self.verbose = args.set_verbose | def pxconfig(self, line):
"""configure default targets/blocking for %px magics"""
args = magic_arguments.parse_argstring(self.pxconfig, line)
if args.targets:
self.view.targets = self._eval_target_str(args.targets)
if args.block is not None:
self.view.block = args.block
if args.set_verbose is not None:
self.verbose = args.set_verbose | [
"configure",
"default",
"targets",
"/",
"blocking",
"for",
"%px",
"magics"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py#L177-L185 | [
"def",
"pxconfig",
"(",
"self",
",",
"line",
")",
":",
"args",
"=",
"magic_arguments",
".",
"parse_argstring",
"(",
"self",
".",
"pxconfig",
",",
"line",
")",
"if",
"args",
".",
"targets",
":",
"self",
".",
"view",
".",
"targets",
"=",
"self",
".",
"_eval_target_str",
"(",
"args",
".",
"targets",
")",
"if",
"args",
".",
"block",
"is",
"not",
"None",
":",
"self",
".",
"view",
".",
"block",
"=",
"args",
".",
"block",
"if",
"args",
".",
"set_verbose",
"is",
"not",
"None",
":",
"self",
".",
"verbose",
"=",
"args",
".",
"set_verbose"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | ParallelMagics.result | Print the result of the last asynchronous %px command.
This lets you recall the results of %px computations after
asynchronous submission (block=False).
Examples
--------
::
In [23]: %px os.getpid()
Async parallel execution on engine(s): all
In [24]: %pxresult
Out[8:10]: 60920
Out[9:10]: 60921
Out[10:10]: 60922
Out[11:10]: 60923 | environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py | def result(self, line=''):
"""Print the result of the last asynchronous %px command.
This lets you recall the results of %px computations after
asynchronous submission (block=False).
Examples
--------
::
In [23]: %px os.getpid()
Async parallel execution on engine(s): all
In [24]: %pxresult
Out[8:10]: 60920
Out[9:10]: 60921
Out[10:10]: 60922
Out[11:10]: 60923
"""
args = magic_arguments.parse_argstring(self.result, line)
if self.last_result is None:
raise UsageError(NO_LAST_RESULT)
self.last_result.get()
self.last_result.display_outputs(groupby=args.groupby) | def result(self, line=''):
"""Print the result of the last asynchronous %px command.
This lets you recall the results of %px computations after
asynchronous submission (block=False).
Examples
--------
::
In [23]: %px os.getpid()
Async parallel execution on engine(s): all
In [24]: %pxresult
Out[8:10]: 60920
Out[9:10]: 60921
Out[10:10]: 60922
Out[11:10]: 60923
"""
args = magic_arguments.parse_argstring(self.result, line)
if self.last_result is None:
raise UsageError(NO_LAST_RESULT)
self.last_result.get()
self.last_result.display_outputs(groupby=args.groupby) | [
"Print",
"the",
"result",
"of",
"the",
"last",
"asynchronous",
"%px",
"command",
".",
"This",
"lets",
"you",
"recall",
"the",
"results",
"of",
"%px",
"computations",
"after",
"asynchronous",
"submission",
"(",
"block",
"=",
"False",
")",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py#L190-L215 | [
"def",
"result",
"(",
"self",
",",
"line",
"=",
"''",
")",
":",
"args",
"=",
"magic_arguments",
".",
"parse_argstring",
"(",
"self",
".",
"result",
",",
"line",
")",
"if",
"self",
".",
"last_result",
"is",
"None",
":",
"raise",
"UsageError",
"(",
"NO_LAST_RESULT",
")",
"self",
".",
"last_result",
".",
"get",
"(",
")",
"self",
".",
"last_result",
".",
"display_outputs",
"(",
"groupby",
"=",
"args",
".",
"groupby",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | ParallelMagics.parallel_execute | implementation used by %px and %%parallel | environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py | def parallel_execute(self, cell, block=None, groupby='type', save_name=None):
"""implementation used by %px and %%parallel"""
# defaults:
block = self.view.block if block is None else block
base = "Parallel" if block else "Async parallel"
targets = self.view.targets
if isinstance(targets, list) and len(targets) > 10:
str_targets = str(targets[:4])[:-1] + ', ..., ' + str(targets[-4:])[1:]
else:
str_targets = str(targets)
if self.verbose:
print base + " execution on engine(s): %s" % str_targets
result = self.view.execute(cell, silent=False, block=False)
self.last_result = result
if save_name:
self.shell.user_ns[save_name] = result
if block:
result.get()
result.display_outputs(groupby)
else:
# return AsyncResult only on non-blocking submission
return result | def parallel_execute(self, cell, block=None, groupby='type', save_name=None):
"""implementation used by %px and %%parallel"""
# defaults:
block = self.view.block if block is None else block
base = "Parallel" if block else "Async parallel"
targets = self.view.targets
if isinstance(targets, list) and len(targets) > 10:
str_targets = str(targets[:4])[:-1] + ', ..., ' + str(targets[-4:])[1:]
else:
str_targets = str(targets)
if self.verbose:
print base + " execution on engine(s): %s" % str_targets
result = self.view.execute(cell, silent=False, block=False)
self.last_result = result
if save_name:
self.shell.user_ns[save_name] = result
if block:
result.get()
result.display_outputs(groupby)
else:
# return AsyncResult only on non-blocking submission
return result | [
"implementation",
"used",
"by",
"%px",
"and",
"%%parallel"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py#L236-L263 | [
"def",
"parallel_execute",
"(",
"self",
",",
"cell",
",",
"block",
"=",
"None",
",",
"groupby",
"=",
"'type'",
",",
"save_name",
"=",
"None",
")",
":",
"# defaults:",
"block",
"=",
"self",
".",
"view",
".",
"block",
"if",
"block",
"is",
"None",
"else",
"block",
"base",
"=",
"\"Parallel\"",
"if",
"block",
"else",
"\"Async parallel\"",
"targets",
"=",
"self",
".",
"view",
".",
"targets",
"if",
"isinstance",
"(",
"targets",
",",
"list",
")",
"and",
"len",
"(",
"targets",
")",
">",
"10",
":",
"str_targets",
"=",
"str",
"(",
"targets",
"[",
":",
"4",
"]",
")",
"[",
":",
"-",
"1",
"]",
"+",
"', ..., '",
"+",
"str",
"(",
"targets",
"[",
"-",
"4",
":",
"]",
")",
"[",
"1",
":",
"]",
"else",
":",
"str_targets",
"=",
"str",
"(",
"targets",
")",
"if",
"self",
".",
"verbose",
":",
"print",
"base",
"+",
"\" execution on engine(s): %s\"",
"%",
"str_targets",
"result",
"=",
"self",
".",
"view",
".",
"execute",
"(",
"cell",
",",
"silent",
"=",
"False",
",",
"block",
"=",
"False",
")",
"self",
".",
"last_result",
"=",
"result",
"if",
"save_name",
":",
"self",
".",
"shell",
".",
"user_ns",
"[",
"save_name",
"]",
"=",
"result",
"if",
"block",
":",
"result",
".",
"get",
"(",
")",
"result",
".",
"display_outputs",
"(",
"groupby",
")",
"else",
":",
"# return AsyncResult only on non-blocking submission",
"return",
"result"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | ParallelMagics.cell_px | Executes the cell in parallel.
Examples
--------
::
In [24]: %%px --noblock
....: a = os.getpid()
Async parallel execution on engine(s): all
In [25]: %%px
....: print a
[stdout:0] 1234
[stdout:1] 1235
[stdout:2] 1236
[stdout:3] 1237 | environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py | def cell_px(self, line='', cell=None):
"""Executes the cell in parallel.
Examples
--------
::
In [24]: %%px --noblock
....: a = os.getpid()
Async parallel execution on engine(s): all
In [25]: %%px
....: print a
[stdout:0] 1234
[stdout:1] 1235
[stdout:2] 1236
[stdout:3] 1237
"""
args = magic_arguments.parse_argstring(self.cell_px, line)
if args.targets:
save_targets = self.view.targets
self.view.targets = self._eval_target_str(args.targets)
try:
return self.parallel_execute(cell, block=args.block,
groupby=args.groupby,
save_name=args.save_name,
)
finally:
if args.targets:
self.view.targets = save_targets | def cell_px(self, line='', cell=None):
"""Executes the cell in parallel.
Examples
--------
::
In [24]: %%px --noblock
....: a = os.getpid()
Async parallel execution on engine(s): all
In [25]: %%px
....: print a
[stdout:0] 1234
[stdout:1] 1235
[stdout:2] 1236
[stdout:3] 1237
"""
args = magic_arguments.parse_argstring(self.cell_px, line)
if args.targets:
save_targets = self.view.targets
self.view.targets = self._eval_target_str(args.targets)
try:
return self.parallel_execute(cell, block=args.block,
groupby=args.groupby,
save_name=args.save_name,
)
finally:
if args.targets:
self.view.targets = save_targets | [
"Executes",
"the",
"cell",
"in",
"parallel",
".",
"Examples",
"--------",
"::"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py#L269-L300 | [
"def",
"cell_px",
"(",
"self",
",",
"line",
"=",
"''",
",",
"cell",
"=",
"None",
")",
":",
"args",
"=",
"magic_arguments",
".",
"parse_argstring",
"(",
"self",
".",
"cell_px",
",",
"line",
")",
"if",
"args",
".",
"targets",
":",
"save_targets",
"=",
"self",
".",
"view",
".",
"targets",
"self",
".",
"view",
".",
"targets",
"=",
"self",
".",
"_eval_target_str",
"(",
"args",
".",
"targets",
")",
"try",
":",
"return",
"self",
".",
"parallel_execute",
"(",
"cell",
",",
"block",
"=",
"args",
".",
"block",
",",
"groupby",
"=",
"args",
".",
"groupby",
",",
"save_name",
"=",
"args",
".",
"save_name",
",",
")",
"finally",
":",
"if",
"args",
".",
"targets",
":",
"self",
".",
"view",
".",
"targets",
"=",
"save_targets"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | ParallelMagics._enable_autopx | Enable %autopx mode by saving the original run_cell and installing
pxrun_cell. | environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py | def _enable_autopx(self):
"""Enable %autopx mode by saving the original run_cell and installing
pxrun_cell.
"""
# override run_cell
self._original_run_cell = self.shell.run_cell
self.shell.run_cell = self.pxrun_cell
self._autopx = True
print "%autopx enabled" | def _enable_autopx(self):
"""Enable %autopx mode by saving the original run_cell and installing
pxrun_cell.
"""
# override run_cell
self._original_run_cell = self.shell.run_cell
self.shell.run_cell = self.pxrun_cell
self._autopx = True
print "%autopx enabled" | [
"Enable",
"%autopx",
"mode",
"by",
"saving",
"the",
"original",
"run_cell",
"and",
"installing",
"pxrun_cell",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py#L335-L344 | [
"def",
"_enable_autopx",
"(",
"self",
")",
":",
"# override run_cell",
"self",
".",
"_original_run_cell",
"=",
"self",
".",
"shell",
".",
"run_cell",
"self",
".",
"shell",
".",
"run_cell",
"=",
"self",
".",
"pxrun_cell",
"self",
".",
"_autopx",
"=",
"True",
"print",
"\"%autopx enabled\""
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | ParallelMagics._disable_autopx | Disable %autopx by restoring the original InteractiveShell.run_cell. | environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py | def _disable_autopx(self):
"""Disable %autopx by restoring the original InteractiveShell.run_cell.
"""
if self._autopx:
self.shell.run_cell = self._original_run_cell
self._autopx = False
print "%autopx disabled" | def _disable_autopx(self):
"""Disable %autopx by restoring the original InteractiveShell.run_cell.
"""
if self._autopx:
self.shell.run_cell = self._original_run_cell
self._autopx = False
print "%autopx disabled" | [
"Disable",
"%autopx",
"by",
"restoring",
"the",
"original",
"InteractiveShell",
".",
"run_cell",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py#L346-L352 | [
"def",
"_disable_autopx",
"(",
"self",
")",
":",
"if",
"self",
".",
"_autopx",
":",
"self",
".",
"shell",
".",
"run_cell",
"=",
"self",
".",
"_original_run_cell",
"self",
".",
"_autopx",
"=",
"False",
"print",
"\"%autopx disabled\""
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | ParallelMagics.pxrun_cell | drop-in replacement for InteractiveShell.run_cell.
This executes code remotely, instead of in the local namespace.
See InteractiveShell.run_cell for details. | environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py | def pxrun_cell(self, raw_cell, store_history=False, silent=False):
"""drop-in replacement for InteractiveShell.run_cell.
This executes code remotely, instead of in the local namespace.
See InteractiveShell.run_cell for details.
"""
if (not raw_cell) or raw_cell.isspace():
return
ipself = self.shell
with ipself.builtin_trap:
cell = ipself.prefilter_manager.prefilter_lines(raw_cell)
# Store raw and processed history
if store_history:
ipself.history_manager.store_inputs(ipself.execution_count,
cell, raw_cell)
# ipself.logger.log(cell, raw_cell)
cell_name = ipself.compile.cache(cell, ipself.execution_count)
try:
ast.parse(cell, filename=cell_name)
except (OverflowError, SyntaxError, ValueError, TypeError,
MemoryError):
# Case 1
ipself.showsyntaxerror()
ipself.execution_count += 1
return None
except NameError:
# ignore name errors, because we don't know the remote keys
pass
if store_history:
# Write output to the database. Does nothing unless
# history output logging is enabled.
ipself.history_manager.store_output(ipself.execution_count)
# Each cell is a *single* input, regardless of how many lines it has
ipself.execution_count += 1
if re.search(r'get_ipython\(\)\.magic\(u?["\']%?autopx', cell):
self._disable_autopx()
return False
else:
try:
result = self.view.execute(cell, silent=False, block=False)
except:
ipself.showtraceback()
return True
else:
if self.view.block:
try:
result.get()
except:
self.shell.showtraceback()
return True
else:
with ipself.builtin_trap:
result.display_outputs()
return False | def pxrun_cell(self, raw_cell, store_history=False, silent=False):
"""drop-in replacement for InteractiveShell.run_cell.
This executes code remotely, instead of in the local namespace.
See InteractiveShell.run_cell for details.
"""
if (not raw_cell) or raw_cell.isspace():
return
ipself = self.shell
with ipself.builtin_trap:
cell = ipself.prefilter_manager.prefilter_lines(raw_cell)
# Store raw and processed history
if store_history:
ipself.history_manager.store_inputs(ipself.execution_count,
cell, raw_cell)
# ipself.logger.log(cell, raw_cell)
cell_name = ipself.compile.cache(cell, ipself.execution_count)
try:
ast.parse(cell, filename=cell_name)
except (OverflowError, SyntaxError, ValueError, TypeError,
MemoryError):
# Case 1
ipself.showsyntaxerror()
ipself.execution_count += 1
return None
except NameError:
# ignore name errors, because we don't know the remote keys
pass
if store_history:
# Write output to the database. Does nothing unless
# history output logging is enabled.
ipself.history_manager.store_output(ipself.execution_count)
# Each cell is a *single* input, regardless of how many lines it has
ipself.execution_count += 1
if re.search(r'get_ipython\(\)\.magic\(u?["\']%?autopx', cell):
self._disable_autopx()
return False
else:
try:
result = self.view.execute(cell, silent=False, block=False)
except:
ipself.showtraceback()
return True
else:
if self.view.block:
try:
result.get()
except:
self.shell.showtraceback()
return True
else:
with ipself.builtin_trap:
result.display_outputs()
return False | [
"drop",
"-",
"in",
"replacement",
"for",
"InteractiveShell",
".",
"run_cell",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/magics.py#L354-L416 | [
"def",
"pxrun_cell",
"(",
"self",
",",
"raw_cell",
",",
"store_history",
"=",
"False",
",",
"silent",
"=",
"False",
")",
":",
"if",
"(",
"not",
"raw_cell",
")",
"or",
"raw_cell",
".",
"isspace",
"(",
")",
":",
"return",
"ipself",
"=",
"self",
".",
"shell",
"with",
"ipself",
".",
"builtin_trap",
":",
"cell",
"=",
"ipself",
".",
"prefilter_manager",
".",
"prefilter_lines",
"(",
"raw_cell",
")",
"# Store raw and processed history",
"if",
"store_history",
":",
"ipself",
".",
"history_manager",
".",
"store_inputs",
"(",
"ipself",
".",
"execution_count",
",",
"cell",
",",
"raw_cell",
")",
"# ipself.logger.log(cell, raw_cell)",
"cell_name",
"=",
"ipself",
".",
"compile",
".",
"cache",
"(",
"cell",
",",
"ipself",
".",
"execution_count",
")",
"try",
":",
"ast",
".",
"parse",
"(",
"cell",
",",
"filename",
"=",
"cell_name",
")",
"except",
"(",
"OverflowError",
",",
"SyntaxError",
",",
"ValueError",
",",
"TypeError",
",",
"MemoryError",
")",
":",
"# Case 1",
"ipself",
".",
"showsyntaxerror",
"(",
")",
"ipself",
".",
"execution_count",
"+=",
"1",
"return",
"None",
"except",
"NameError",
":",
"# ignore name errors, because we don't know the remote keys",
"pass",
"if",
"store_history",
":",
"# Write output to the database. Does nothing unless",
"# history output logging is enabled.",
"ipself",
".",
"history_manager",
".",
"store_output",
"(",
"ipself",
".",
"execution_count",
")",
"# Each cell is a *single* input, regardless of how many lines it has",
"ipself",
".",
"execution_count",
"+=",
"1",
"if",
"re",
".",
"search",
"(",
"r'get_ipython\\(\\)\\.magic\\(u?[\"\\']%?autopx'",
",",
"cell",
")",
":",
"self",
".",
"_disable_autopx",
"(",
")",
"return",
"False",
"else",
":",
"try",
":",
"result",
"=",
"self",
".",
"view",
".",
"execute",
"(",
"cell",
",",
"silent",
"=",
"False",
",",
"block",
"=",
"False",
")",
"except",
":",
"ipself",
".",
"showtraceback",
"(",
")",
"return",
"True",
"else",
":",
"if",
"self",
".",
"view",
".",
"block",
":",
"try",
":",
"result",
".",
"get",
"(",
")",
"except",
":",
"self",
".",
"shell",
".",
"showtraceback",
"(",
")",
"return",
"True",
"else",
":",
"with",
"ipself",
".",
"builtin_trap",
":",
"result",
".",
"display_outputs",
"(",
")",
"return",
"False"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | run_heartbeat | Internal ``CLOCK_CHANNEL`` consumer to process task runs | src/sisy/consumers.py | def run_heartbeat(message):
"""Internal ``CLOCK_CHANNEL`` consumer to process task runs"""
then = arrow.get(message['time'])
now = arrow.get()
if (now - then) > timezone.timedelta(seconds=(TICK_FREQ+1)):
pass # discard old ticks
else:
Task.run_tasks() | def run_heartbeat(message):
"""Internal ``CLOCK_CHANNEL`` consumer to process task runs"""
then = arrow.get(message['time'])
now = arrow.get()
if (now - then) > timezone.timedelta(seconds=(TICK_FREQ+1)):
pass # discard old ticks
else:
Task.run_tasks() | [
"Internal",
"CLOCK_CHANNEL",
"consumer",
"to",
"process",
"task",
"runs"
] | phoikoi/sisy | python | https://github.com/phoikoi/sisy/blob/840c5463ab65488d34e99531f230e61f755d2d69/src/sisy/consumers.py#L19-L27 | [
"def",
"run_heartbeat",
"(",
"message",
")",
":",
"then",
"=",
"arrow",
".",
"get",
"(",
"message",
"[",
"'time'",
"]",
")",
"now",
"=",
"arrow",
".",
"get",
"(",
")",
"if",
"(",
"now",
"-",
"then",
")",
">",
"timezone",
".",
"timedelta",
"(",
"seconds",
"=",
"(",
"TICK_FREQ",
"+",
"1",
")",
")",
":",
"pass",
"# discard old ticks",
"else",
":",
"Task",
".",
"run_tasks",
"(",
")"
] | 840c5463ab65488d34e99531f230e61f755d2d69 |
test | run_task | Internal ``RUN_TASK`` consumer to run the task's callable | src/sisy/consumers.py | def run_task(message):
"""Internal ``RUN_TASK`` consumer to run the task's callable"""
task = Task.objects.get(pk=message['id'])
if task.allow_overlap:
task.run(message)
else:
if not task.running:
task.running = True
task.save()
try:
task.run(message)
finally:
task.running = False
task.save() | def run_task(message):
"""Internal ``RUN_TASK`` consumer to run the task's callable"""
task = Task.objects.get(pk=message['id'])
if task.allow_overlap:
task.run(message)
else:
if not task.running:
task.running = True
task.save()
try:
task.run(message)
finally:
task.running = False
task.save() | [
"Internal",
"RUN_TASK",
"consumer",
"to",
"run",
"the",
"task",
"s",
"callable"
] | phoikoi/sisy | python | https://github.com/phoikoi/sisy/blob/840c5463ab65488d34e99531f230e61f755d2d69/src/sisy/consumers.py#L29-L42 | [
"def",
"run_task",
"(",
"message",
")",
":",
"task",
"=",
"Task",
".",
"objects",
".",
"get",
"(",
"pk",
"=",
"message",
"[",
"'id'",
"]",
")",
"if",
"task",
".",
"allow_overlap",
":",
"task",
".",
"run",
"(",
"message",
")",
"else",
":",
"if",
"not",
"task",
".",
"running",
":",
"task",
".",
"running",
"=",
"True",
"task",
".",
"save",
"(",
")",
"try",
":",
"task",
".",
"run",
"(",
"message",
")",
"finally",
":",
"task",
".",
"running",
"=",
"False",
"task",
".",
"save",
"(",
")"
] | 840c5463ab65488d34e99531f230e61f755d2d69 |
test | remove_task | Internal ``KILL_TASK`` consumer to remove retired tasks | src/sisy/consumers.py | def remove_task(message):
"""Internal ``KILL_TASK`` consumer to remove retired tasks"""
task = Task.objects.get(pk=message['id'])
task.delete() | def remove_task(message):
"""Internal ``KILL_TASK`` consumer to remove retired tasks"""
task = Task.objects.get(pk=message['id'])
task.delete() | [
"Internal",
"KILL_TASK",
"consumer",
"to",
"remove",
"retired",
"tasks"
] | phoikoi/sisy | python | https://github.com/phoikoi/sisy/blob/840c5463ab65488d34e99531f230e61f755d2d69/src/sisy/consumers.py#L44-L47 | [
"def",
"remove_task",
"(",
"message",
")",
":",
"task",
"=",
"Task",
".",
"objects",
".",
"get",
"(",
"pk",
"=",
"message",
"[",
"'id'",
"]",
")",
"task",
".",
"delete",
"(",
")"
] | 840c5463ab65488d34e99531f230e61f755d2d69 |
test | patch_protocol_for_agent | Patch the protocol's makeConnection and connectionLost methods to make the
protocol and its transport behave more like what `Agent` expects.
While `Agent` is the driving force behind this, other clients and servers
will no doubt have similar requirements. | txfake/fake_connection.py | def patch_protocol_for_agent(protocol):
"""
Patch the protocol's makeConnection and connectionLost methods to make the
protocol and its transport behave more like what `Agent` expects.
While `Agent` is the driving force behind this, other clients and servers
will no doubt have similar requirements.
"""
old_makeConnection = protocol.makeConnection
old_connectionLost = protocol.connectionLost
def new_makeConnection(transport):
patch_transport_fake_push_producer(transport)
patch_transport_abortConnection(transport, protocol)
return old_makeConnection(transport)
def new_connectionLost(reason):
# Replace ConnectionDone with ConnectionAborted if we aborted.
if protocol._fake_connection_aborted and reason.check(ConnectionDone):
reason = Failure(ConnectionAborted())
return old_connectionLost(reason)
protocol.makeConnection = new_makeConnection
protocol.connectionLost = new_connectionLost
protocol._fake_connection_aborted = False | def patch_protocol_for_agent(protocol):
"""
Patch the protocol's makeConnection and connectionLost methods to make the
protocol and its transport behave more like what `Agent` expects.
While `Agent` is the driving force behind this, other clients and servers
will no doubt have similar requirements.
"""
old_makeConnection = protocol.makeConnection
old_connectionLost = protocol.connectionLost
def new_makeConnection(transport):
patch_transport_fake_push_producer(transport)
patch_transport_abortConnection(transport, protocol)
return old_makeConnection(transport)
def new_connectionLost(reason):
# Replace ConnectionDone with ConnectionAborted if we aborted.
if protocol._fake_connection_aborted and reason.check(ConnectionDone):
reason = Failure(ConnectionAborted())
return old_connectionLost(reason)
protocol.makeConnection = new_makeConnection
protocol.connectionLost = new_connectionLost
protocol._fake_connection_aborted = False | [
"Patch",
"the",
"protocol",
"s",
"makeConnection",
"and",
"connectionLost",
"methods",
"to",
"make",
"the",
"protocol",
"and",
"its",
"transport",
"behave",
"more",
"like",
"what",
"Agent",
"expects",
"."
] | jerith/txfake | python | https://github.com/jerith/txfake/blob/5c1cda2b9a56458c254d0d9476b6c426d57f5757/txfake/fake_connection.py#L176-L200 | [
"def",
"patch_protocol_for_agent",
"(",
"protocol",
")",
":",
"old_makeConnection",
"=",
"protocol",
".",
"makeConnection",
"old_connectionLost",
"=",
"protocol",
".",
"connectionLost",
"def",
"new_makeConnection",
"(",
"transport",
")",
":",
"patch_transport_fake_push_producer",
"(",
"transport",
")",
"patch_transport_abortConnection",
"(",
"transport",
",",
"protocol",
")",
"return",
"old_makeConnection",
"(",
"transport",
")",
"def",
"new_connectionLost",
"(",
"reason",
")",
":",
"# Replace ConnectionDone with ConnectionAborted if we aborted.",
"if",
"protocol",
".",
"_fake_connection_aborted",
"and",
"reason",
".",
"check",
"(",
"ConnectionDone",
")",
":",
"reason",
"=",
"Failure",
"(",
"ConnectionAborted",
"(",
")",
")",
"return",
"old_connectionLost",
"(",
"reason",
")",
"protocol",
".",
"makeConnection",
"=",
"new_makeConnection",
"protocol",
".",
"connectionLost",
"=",
"new_connectionLost",
"protocol",
".",
"_fake_connection_aborted",
"=",
"False"
] | 5c1cda2b9a56458c254d0d9476b6c426d57f5757 |
test | patch_if_missing | Patch a method onto an object if it isn't already there. | txfake/fake_connection.py | def patch_if_missing(obj, name, method):
"""
Patch a method onto an object if it isn't already there.
"""
setattr(obj, name, getattr(obj, name, method)) | def patch_if_missing(obj, name, method):
"""
Patch a method onto an object if it isn't already there.
"""
setattr(obj, name, getattr(obj, name, method)) | [
"Patch",
"a",
"method",
"onto",
"an",
"object",
"if",
"it",
"isn",
"t",
"already",
"there",
"."
] | jerith/txfake | python | https://github.com/jerith/txfake/blob/5c1cda2b9a56458c254d0d9476b6c426d57f5757/txfake/fake_connection.py#L203-L207 | [
"def",
"patch_if_missing",
"(",
"obj",
",",
"name",
",",
"method",
")",
":",
"setattr",
"(",
"obj",
",",
"name",
",",
"getattr",
"(",
"obj",
",",
"name",
",",
"method",
")",
")"
] | 5c1cda2b9a56458c254d0d9476b6c426d57f5757 |
test | patch_transport_fake_push_producer | Patch the three methods belonging to IPushProducer onto the transport if it
doesn't already have them. (`Agent` assumes its transport has these.) | txfake/fake_connection.py | def patch_transport_fake_push_producer(transport):
"""
Patch the three methods belonging to IPushProducer onto the transport if it
doesn't already have them. (`Agent` assumes its transport has these.)
"""
patch_if_missing(transport, 'pauseProducing', lambda: None)
patch_if_missing(transport, 'resumeProducing', lambda: None)
patch_if_missing(transport, 'stopProducing', transport.loseConnection) | def patch_transport_fake_push_producer(transport):
"""
Patch the three methods belonging to IPushProducer onto the transport if it
doesn't already have them. (`Agent` assumes its transport has these.)
"""
patch_if_missing(transport, 'pauseProducing', lambda: None)
patch_if_missing(transport, 'resumeProducing', lambda: None)
patch_if_missing(transport, 'stopProducing', transport.loseConnection) | [
"Patch",
"the",
"three",
"methods",
"belonging",
"to",
"IPushProducer",
"onto",
"the",
"transport",
"if",
"it",
"doesn",
"t",
"already",
"have",
"them",
".",
"(",
"Agent",
"assumes",
"its",
"transport",
"has",
"these",
".",
")"
] | jerith/txfake | python | https://github.com/jerith/txfake/blob/5c1cda2b9a56458c254d0d9476b6c426d57f5757/txfake/fake_connection.py#L210-L217 | [
"def",
"patch_transport_fake_push_producer",
"(",
"transport",
")",
":",
"patch_if_missing",
"(",
"transport",
",",
"'pauseProducing'",
",",
"lambda",
":",
"None",
")",
"patch_if_missing",
"(",
"transport",
",",
"'resumeProducing'",
",",
"lambda",
":",
"None",
")",
"patch_if_missing",
"(",
"transport",
",",
"'stopProducing'",
",",
"transport",
".",
"loseConnection",
")"
] | 5c1cda2b9a56458c254d0d9476b6c426d57f5757 |
test | patch_transport_abortConnection | Patch abortConnection() onto the transport if it doesn't already have it.
(`Agent` assumes its transport has this.) | txfake/fake_connection.py | def patch_transport_abortConnection(transport, protocol):
"""
Patch abortConnection() onto the transport if it doesn't already have it.
(`Agent` assumes its transport has this.)
"""
def abortConnection():
protocol._fake_connection_aborted = True
transport.loseConnection()
patch_if_missing(transport, 'abortConnection', abortConnection) | def patch_transport_abortConnection(transport, protocol):
"""
Patch abortConnection() onto the transport if it doesn't already have it.
(`Agent` assumes its transport has this.)
"""
def abortConnection():
protocol._fake_connection_aborted = True
transport.loseConnection()
patch_if_missing(transport, 'abortConnection', abortConnection) | [
"Patch",
"abortConnection",
"()",
"onto",
"the",
"transport",
"if",
"it",
"doesn",
"t",
"already",
"have",
"it",
".",
"(",
"Agent",
"assumes",
"its",
"transport",
"has",
"this",
".",
")"
] | jerith/txfake | python | https://github.com/jerith/txfake/blob/5c1cda2b9a56458c254d0d9476b6c426d57f5757/txfake/fake_connection.py#L220-L228 | [
"def",
"patch_transport_abortConnection",
"(",
"transport",
",",
"protocol",
")",
":",
"def",
"abortConnection",
"(",
")",
":",
"protocol",
".",
"_fake_connection_aborted",
"=",
"True",
"transport",
".",
"loseConnection",
"(",
")",
"patch_if_missing",
"(",
"transport",
",",
"'abortConnection'",
",",
"abortConnection",
")"
] | 5c1cda2b9a56458c254d0d9476b6c426d57f5757 |
test | FakeConnection.accept_connection | Accept a pending connection. | txfake/fake_connection.py | def accept_connection(self):
"""
Accept a pending connection.
"""
assert self.pending, "Connection is not pending."
self.server_protocol = self.server.server_factory.buildProtocol(None)
self._accept_d.callback(
FakeServerProtocolWrapper(self, self.server_protocol))
return self.await_connected() | def accept_connection(self):
"""
Accept a pending connection.
"""
assert self.pending, "Connection is not pending."
self.server_protocol = self.server.server_factory.buildProtocol(None)
self._accept_d.callback(
FakeServerProtocolWrapper(self, self.server_protocol))
return self.await_connected() | [
"Accept",
"a",
"pending",
"connection",
"."
] | jerith/txfake | python | https://github.com/jerith/txfake/blob/5c1cda2b9a56458c254d0d9476b6c426d57f5757/txfake/fake_connection.py#L123-L131 | [
"def",
"accept_connection",
"(",
"self",
")",
":",
"assert",
"self",
".",
"pending",
",",
"\"Connection is not pending.\"",
"self",
".",
"server_protocol",
"=",
"self",
".",
"server",
".",
"server_factory",
".",
"buildProtocol",
"(",
"None",
")",
"self",
".",
"_accept_d",
".",
"callback",
"(",
"FakeServerProtocolWrapper",
"(",
"self",
",",
"self",
".",
"server_protocol",
")",
")",
"return",
"self",
".",
"await_connected",
"(",
")"
] | 5c1cda2b9a56458c254d0d9476b6c426d57f5757 |
test | FakeConnection.reject_connection | Reject a pending connection. | txfake/fake_connection.py | def reject_connection(self, reason=None):
"""
Reject a pending connection.
"""
assert self.pending, "Connection is not pending."
if reason is None:
reason = ConnectionRefusedError()
self._accept_d.errback(reason) | def reject_connection(self, reason=None):
"""
Reject a pending connection.
"""
assert self.pending, "Connection is not pending."
if reason is None:
reason = ConnectionRefusedError()
self._accept_d.errback(reason) | [
"Reject",
"a",
"pending",
"connection",
"."
] | jerith/txfake | python | https://github.com/jerith/txfake/blob/5c1cda2b9a56458c254d0d9476b6c426d57f5757/txfake/fake_connection.py#L133-L140 | [
"def",
"reject_connection",
"(",
"self",
",",
"reason",
"=",
"None",
")",
":",
"assert",
"self",
".",
"pending",
",",
"\"Connection is not pending.\"",
"if",
"reason",
"is",
"None",
":",
"reason",
"=",
"ConnectionRefusedError",
"(",
")",
"self",
".",
"_accept_d",
".",
"errback",
"(",
"reason",
")"
] | 5c1cda2b9a56458c254d0d9476b6c426d57f5757 |
test | FakeHttpServer.get_agent | Returns an IAgent that makes requests to this fake server. | txfake/fake_connection.py | def get_agent(self, reactor=None, contextFactory=None):
"""
Returns an IAgent that makes requests to this fake server.
"""
return ProxyAgentWithContext(
self.endpoint, reactor=reactor, contextFactory=contextFactory) | def get_agent(self, reactor=None, contextFactory=None):
"""
Returns an IAgent that makes requests to this fake server.
"""
return ProxyAgentWithContext(
self.endpoint, reactor=reactor, contextFactory=contextFactory) | [
"Returns",
"an",
"IAgent",
"that",
"makes",
"requests",
"to",
"this",
"fake",
"server",
"."
] | jerith/txfake | python | https://github.com/jerith/txfake/blob/5c1cda2b9a56458c254d0d9476b6c426d57f5757/txfake/fake_connection.py#L268-L273 | [
"def",
"get_agent",
"(",
"self",
",",
"reactor",
"=",
"None",
",",
"contextFactory",
"=",
"None",
")",
":",
"return",
"ProxyAgentWithContext",
"(",
"self",
".",
"endpoint",
",",
"reactor",
"=",
"reactor",
",",
"contextFactory",
"=",
"contextFactory",
")"
] | 5c1cda2b9a56458c254d0d9476b6c426d57f5757 |
test | SaveHookMixin.form_valid | Calls pre and post save hooks. | django_baseline/views.py | def form_valid(self, form):
"""
Calls pre and post save hooks.
"""
self.object = form.save(commit=False)
# Invoke pre_save hook, and allow it to abort the saving
# process and do a redirect.
response = self.pre_save(self.object)
if response:
return response
self.object.save()
form.save_m2m()
self.post_save(self.object)
return HttpResponseRedirect(self.get_success_url()) | def form_valid(self, form):
"""
Calls pre and post save hooks.
"""
self.object = form.save(commit=False)
# Invoke pre_save hook, and allow it to abort the saving
# process and do a redirect.
response = self.pre_save(self.object)
if response:
return response
self.object.save()
form.save_m2m()
self.post_save(self.object)
return HttpResponseRedirect(self.get_success_url()) | [
"Calls",
"pre",
"and",
"post",
"save",
"hooks",
"."
] | theduke/django-baseline | python | https://github.com/theduke/django-baseline/blob/7be8b956e53c70b35f34e1783a8fe8f716955afb/django_baseline/views.py#L141-L157 | [
"def",
"form_valid",
"(",
"self",
",",
"form",
")",
":",
"self",
".",
"object",
"=",
"form",
".",
"save",
"(",
"commit",
"=",
"False",
")",
"# Invoke pre_save hook, and allow it to abort the saving",
"# process and do a redirect.",
"response",
"=",
"self",
".",
"pre_save",
"(",
"self",
".",
"object",
")",
"if",
"response",
":",
"return",
"response",
"self",
".",
"object",
".",
"save",
"(",
")",
"form",
".",
"save_m2m",
"(",
")",
"self",
".",
"post_save",
"(",
"self",
".",
"object",
")",
"return",
"HttpResponseRedirect",
"(",
"self",
".",
"get_success_url",
"(",
")",
")"
] | 7be8b956e53c70b35f34e1783a8fe8f716955afb |
test | SaveHookMixin.delete | Calls pre and post delete hooks for DelteViews. | django_baseline/views.py | def delete(self, request, *args, **kwargs):
"""
Calls pre and post delete hooks for DelteViews.
"""
self.object = self.get_object()
success_url = self.get_success_url()
self.pre_delete(self.object)
self.object.delete()
self.post_delete(self.object)
return HttpResponseRedirect(success_url) | def delete(self, request, *args, **kwargs):
"""
Calls pre and post delete hooks for DelteViews.
"""
self.object = self.get_object()
success_url = self.get_success_url()
self.pre_delete(self.object)
self.object.delete()
self.post_delete(self.object)
return HttpResponseRedirect(success_url) | [
"Calls",
"pre",
"and",
"post",
"delete",
"hooks",
"for",
"DelteViews",
"."
] | theduke/django-baseline | python | https://github.com/theduke/django-baseline/blob/7be8b956e53c70b35f34e1783a8fe8f716955afb/django_baseline/views.py#L160-L171 | [
"def",
"delete",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"success_url",
"=",
"self",
".",
"get_success_url",
"(",
")",
"self",
".",
"pre_delete",
"(",
"self",
".",
"object",
")",
"self",
".",
"object",
".",
"delete",
"(",
")",
"self",
".",
"post_delete",
"(",
"self",
".",
"object",
")",
"return",
"HttpResponseRedirect",
"(",
"success_url",
")"
] | 7be8b956e53c70b35f34e1783a8fe8f716955afb |
test | UserViewMixin.get_initial | Supply user object as initial data for the specified user_field(s). | django_baseline/views.py | def get_initial(self):
"""
Supply user object as initial data for the specified user_field(s).
"""
data = super(UserViewMixin, self).get_initial()
for k in self.user_field:
data[k] = self.request.user
return data | def get_initial(self):
"""
Supply user object as initial data for the specified user_field(s).
"""
data = super(UserViewMixin, self).get_initial()
for k in self.user_field:
data[k] = self.request.user
return data | [
"Supply",
"user",
"object",
"as",
"initial",
"data",
"for",
"the",
"specified",
"user_field",
"(",
"s",
")",
"."
] | theduke/django-baseline | python | https://github.com/theduke/django-baseline/blob/7be8b956e53c70b35f34e1783a8fe8f716955afb/django_baseline/views.py#L237-L246 | [
"def",
"get_initial",
"(",
"self",
")",
":",
"data",
"=",
"super",
"(",
"UserViewMixin",
",",
"self",
")",
".",
"get_initial",
"(",
")",
"for",
"k",
"in",
"self",
".",
"user_field",
":",
"data",
"[",
"k",
"]",
"=",
"self",
".",
"request",
".",
"user",
"return",
"data"
] | 7be8b956e53c70b35f34e1783a8fe8f716955afb |
test | UserViewMixin.pre_save | Use SaveHookMixin pre_save to set the user. | django_baseline/views.py | def pre_save(self, instance):
super(UserViewMixin, self).pre_save(instance)
"""
Use SaveHookMixin pre_save to set the user.
"""
if self.request.user.is_authenticated():
for field in self.user_field:
setattr(instance, field, self.request.user) | def pre_save(self, instance):
super(UserViewMixin, self).pre_save(instance)
"""
Use SaveHookMixin pre_save to set the user.
"""
if self.request.user.is_authenticated():
for field in self.user_field:
setattr(instance, field, self.request.user) | [
"Use",
"SaveHookMixin",
"pre_save",
"to",
"set",
"the",
"user",
"."
] | theduke/django-baseline | python | https://github.com/theduke/django-baseline/blob/7be8b956e53c70b35f34e1783a8fe8f716955afb/django_baseline/views.py#L249-L257 | [
"def",
"pre_save",
"(",
"self",
",",
"instance",
")",
":",
"super",
"(",
"UserViewMixin",
",",
"self",
")",
".",
"pre_save",
"(",
"instance",
")",
"if",
"self",
".",
"request",
".",
"user",
".",
"is_authenticated",
"(",
")",
":",
"for",
"field",
"in",
"self",
".",
"user_field",
":",
"setattr",
"(",
"instance",
",",
"field",
",",
"self",
".",
"request",
".",
"user",
")"
] | 7be8b956e53c70b35f34e1783a8fe8f716955afb |
test | SummaryReporter.report | Writes a report summarizing coverage statistics per module.
`outfile` is a file object to write the summary to. | virtualEnvironment/lib/python2.7/site-packages/coverage/summary.py | def report(self, morfs, outfile=None):
"""Writes a report summarizing coverage statistics per module.
`outfile` is a file object to write the summary to.
"""
self.find_code_units(morfs)
# Prepare the formatting strings
max_name = max([len(cu.name) for cu in self.code_units] + [5])
fmt_name = "%%- %ds " % max_name
fmt_err = "%s %s: %s\n"
header = (fmt_name % "Name") + " Stmts Miss"
fmt_coverage = fmt_name + "%6d %6d"
if self.branches:
header += " Branch BrMiss"
fmt_coverage += " %6d %6d"
width100 = Numbers.pc_str_width()
header += "%*s" % (width100+4, "Cover")
fmt_coverage += "%%%ds%%%%" % (width100+3,)
if self.config.show_missing:
header += " Missing"
fmt_coverage += " %s"
rule = "-" * len(header) + "\n"
header += "\n"
fmt_coverage += "\n"
if not outfile:
outfile = sys.stdout
# Write the header
outfile.write(header)
outfile.write(rule)
total = Numbers()
for cu in self.code_units:
try:
analysis = self.coverage._analyze(cu)
nums = analysis.numbers
args = (cu.name, nums.n_statements, nums.n_missing)
if self.branches:
args += (nums.n_branches, nums.n_missing_branches)
args += (nums.pc_covered_str,)
if self.config.show_missing:
args += (analysis.missing_formatted(),)
outfile.write(fmt_coverage % args)
total += nums
except KeyboardInterrupt: # pragma: not covered
raise
except:
report_it = not self.config.ignore_errors
if report_it:
typ, msg = sys.exc_info()[:2]
if typ is NotPython and not cu.should_be_python():
report_it = False
if report_it:
outfile.write(fmt_err % (cu.name, typ.__name__, msg))
if total.n_files > 1:
outfile.write(rule)
args = ("TOTAL", total.n_statements, total.n_missing)
if self.branches:
args += (total.n_branches, total.n_missing_branches)
args += (total.pc_covered_str,)
if self.config.show_missing:
args += ("",)
outfile.write(fmt_coverage % args)
return total.pc_covered | def report(self, morfs, outfile=None):
"""Writes a report summarizing coverage statistics per module.
`outfile` is a file object to write the summary to.
"""
self.find_code_units(morfs)
# Prepare the formatting strings
max_name = max([len(cu.name) for cu in self.code_units] + [5])
fmt_name = "%%- %ds " % max_name
fmt_err = "%s %s: %s\n"
header = (fmt_name % "Name") + " Stmts Miss"
fmt_coverage = fmt_name + "%6d %6d"
if self.branches:
header += " Branch BrMiss"
fmt_coverage += " %6d %6d"
width100 = Numbers.pc_str_width()
header += "%*s" % (width100+4, "Cover")
fmt_coverage += "%%%ds%%%%" % (width100+3,)
if self.config.show_missing:
header += " Missing"
fmt_coverage += " %s"
rule = "-" * len(header) + "\n"
header += "\n"
fmt_coverage += "\n"
if not outfile:
outfile = sys.stdout
# Write the header
outfile.write(header)
outfile.write(rule)
total = Numbers()
for cu in self.code_units:
try:
analysis = self.coverage._analyze(cu)
nums = analysis.numbers
args = (cu.name, nums.n_statements, nums.n_missing)
if self.branches:
args += (nums.n_branches, nums.n_missing_branches)
args += (nums.pc_covered_str,)
if self.config.show_missing:
args += (analysis.missing_formatted(),)
outfile.write(fmt_coverage % args)
total += nums
except KeyboardInterrupt: # pragma: not covered
raise
except:
report_it = not self.config.ignore_errors
if report_it:
typ, msg = sys.exc_info()[:2]
if typ is NotPython and not cu.should_be_python():
report_it = False
if report_it:
outfile.write(fmt_err % (cu.name, typ.__name__, msg))
if total.n_files > 1:
outfile.write(rule)
args = ("TOTAL", total.n_statements, total.n_missing)
if self.branches:
args += (total.n_branches, total.n_missing_branches)
args += (total.pc_covered_str,)
if self.config.show_missing:
args += ("",)
outfile.write(fmt_coverage % args)
return total.pc_covered | [
"Writes",
"a",
"report",
"summarizing",
"coverage",
"statistics",
"per",
"module",
"."
] | tnkteja/myhelp | python | https://github.com/tnkteja/myhelp/blob/fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb/virtualEnvironment/lib/python2.7/site-packages/coverage/summary.py#L17-L86 | [
"def",
"report",
"(",
"self",
",",
"morfs",
",",
"outfile",
"=",
"None",
")",
":",
"self",
".",
"find_code_units",
"(",
"morfs",
")",
"# Prepare the formatting strings",
"max_name",
"=",
"max",
"(",
"[",
"len",
"(",
"cu",
".",
"name",
")",
"for",
"cu",
"in",
"self",
".",
"code_units",
"]",
"+",
"[",
"5",
"]",
")",
"fmt_name",
"=",
"\"%%- %ds \"",
"%",
"max_name",
"fmt_err",
"=",
"\"%s %s: %s\\n\"",
"header",
"=",
"(",
"fmt_name",
"%",
"\"Name\"",
")",
"+",
"\" Stmts Miss\"",
"fmt_coverage",
"=",
"fmt_name",
"+",
"\"%6d %6d\"",
"if",
"self",
".",
"branches",
":",
"header",
"+=",
"\" Branch BrMiss\"",
"fmt_coverage",
"+=",
"\" %6d %6d\"",
"width100",
"=",
"Numbers",
".",
"pc_str_width",
"(",
")",
"header",
"+=",
"\"%*s\"",
"%",
"(",
"width100",
"+",
"4",
",",
"\"Cover\"",
")",
"fmt_coverage",
"+=",
"\"%%%ds%%%%\"",
"%",
"(",
"width100",
"+",
"3",
",",
")",
"if",
"self",
".",
"config",
".",
"show_missing",
":",
"header",
"+=",
"\" Missing\"",
"fmt_coverage",
"+=",
"\" %s\"",
"rule",
"=",
"\"-\"",
"*",
"len",
"(",
"header",
")",
"+",
"\"\\n\"",
"header",
"+=",
"\"\\n\"",
"fmt_coverage",
"+=",
"\"\\n\"",
"if",
"not",
"outfile",
":",
"outfile",
"=",
"sys",
".",
"stdout",
"# Write the header",
"outfile",
".",
"write",
"(",
"header",
")",
"outfile",
".",
"write",
"(",
"rule",
")",
"total",
"=",
"Numbers",
"(",
")",
"for",
"cu",
"in",
"self",
".",
"code_units",
":",
"try",
":",
"analysis",
"=",
"self",
".",
"coverage",
".",
"_analyze",
"(",
"cu",
")",
"nums",
"=",
"analysis",
".",
"numbers",
"args",
"=",
"(",
"cu",
".",
"name",
",",
"nums",
".",
"n_statements",
",",
"nums",
".",
"n_missing",
")",
"if",
"self",
".",
"branches",
":",
"args",
"+=",
"(",
"nums",
".",
"n_branches",
",",
"nums",
".",
"n_missing_branches",
")",
"args",
"+=",
"(",
"nums",
".",
"pc_covered_str",
",",
")",
"if",
"self",
".",
"config",
".",
"show_missing",
":",
"args",
"+=",
"(",
"analysis",
".",
"missing_formatted",
"(",
")",
",",
")",
"outfile",
".",
"write",
"(",
"fmt_coverage",
"%",
"args",
")",
"total",
"+=",
"nums",
"except",
"KeyboardInterrupt",
":",
"# pragma: not covered",
"raise",
"except",
":",
"report_it",
"=",
"not",
"self",
".",
"config",
".",
"ignore_errors",
"if",
"report_it",
":",
"typ",
",",
"msg",
"=",
"sys",
".",
"exc_info",
"(",
")",
"[",
":",
"2",
"]",
"if",
"typ",
"is",
"NotPython",
"and",
"not",
"cu",
".",
"should_be_python",
"(",
")",
":",
"report_it",
"=",
"False",
"if",
"report_it",
":",
"outfile",
".",
"write",
"(",
"fmt_err",
"%",
"(",
"cu",
".",
"name",
",",
"typ",
".",
"__name__",
",",
"msg",
")",
")",
"if",
"total",
".",
"n_files",
">",
"1",
":",
"outfile",
".",
"write",
"(",
"rule",
")",
"args",
"=",
"(",
"\"TOTAL\"",
",",
"total",
".",
"n_statements",
",",
"total",
".",
"n_missing",
")",
"if",
"self",
".",
"branches",
":",
"args",
"+=",
"(",
"total",
".",
"n_branches",
",",
"total",
".",
"n_missing_branches",
")",
"args",
"+=",
"(",
"total",
".",
"pc_covered_str",
",",
")",
"if",
"self",
".",
"config",
".",
"show_missing",
":",
"args",
"+=",
"(",
"\"\"",
",",
")",
"outfile",
".",
"write",
"(",
"fmt_coverage",
"%",
"args",
")",
"return",
"total",
".",
"pc_covered"
] | fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb |
test | _get_compiled_ext | Official way to get the extension of compiled files (.pyc or .pyo) | environment/lib/python2.7/site-packages/IPython/extensions/autoreload.py | def _get_compiled_ext():
"""Official way to get the extension of compiled files (.pyc or .pyo)"""
for ext, mode, typ in imp.get_suffixes():
if typ == imp.PY_COMPILED:
return ext | def _get_compiled_ext():
"""Official way to get the extension of compiled files (.pyc or .pyo)"""
for ext, mode, typ in imp.get_suffixes():
if typ == imp.PY_COMPILED:
return ext | [
"Official",
"way",
"to",
"get",
"the",
"extension",
"of",
"compiled",
"files",
"(",
".",
"pyc",
"or",
".",
"pyo",
")"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/extensions/autoreload.py#L132-L136 | [
"def",
"_get_compiled_ext",
"(",
")",
":",
"for",
"ext",
",",
"mode",
",",
"typ",
"in",
"imp",
".",
"get_suffixes",
"(",
")",
":",
"if",
"typ",
"==",
"imp",
".",
"PY_COMPILED",
":",
"return",
"ext"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | update_class | Replace stuff in the __dict__ of a class, and upgrade
method code objects | environment/lib/python2.7/site-packages/IPython/extensions/autoreload.py | def update_class(old, new):
"""Replace stuff in the __dict__ of a class, and upgrade
method code objects"""
for key in old.__dict__.keys():
old_obj = getattr(old, key)
try:
new_obj = getattr(new, key)
except AttributeError:
# obsolete attribute: remove it
try:
delattr(old, key)
except (AttributeError, TypeError):
pass
continue
if update_generic(old_obj, new_obj): continue
try:
setattr(old, key, getattr(new, key))
except (AttributeError, TypeError):
pass | def update_class(old, new):
"""Replace stuff in the __dict__ of a class, and upgrade
method code objects"""
for key in old.__dict__.keys():
old_obj = getattr(old, key)
try:
new_obj = getattr(new, key)
except AttributeError:
# obsolete attribute: remove it
try:
delattr(old, key)
except (AttributeError, TypeError):
pass
continue
if update_generic(old_obj, new_obj): continue
try:
setattr(old, key, getattr(new, key))
except (AttributeError, TypeError):
pass | [
"Replace",
"stuff",
"in",
"the",
"__dict__",
"of",
"a",
"class",
"and",
"upgrade",
"method",
"code",
"objects"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/extensions/autoreload.py#L272-L293 | [
"def",
"update_class",
"(",
"old",
",",
"new",
")",
":",
"for",
"key",
"in",
"old",
".",
"__dict__",
".",
"keys",
"(",
")",
":",
"old_obj",
"=",
"getattr",
"(",
"old",
",",
"key",
")",
"try",
":",
"new_obj",
"=",
"getattr",
"(",
"new",
",",
"key",
")",
"except",
"AttributeError",
":",
"# obsolete attribute: remove it",
"try",
":",
"delattr",
"(",
"old",
",",
"key",
")",
"except",
"(",
"AttributeError",
",",
"TypeError",
")",
":",
"pass",
"continue",
"if",
"update_generic",
"(",
"old_obj",
",",
"new_obj",
")",
":",
"continue",
"try",
":",
"setattr",
"(",
"old",
",",
"key",
",",
"getattr",
"(",
"new",
",",
"key",
")",
")",
"except",
"(",
"AttributeError",
",",
"TypeError",
")",
":",
"pass"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | ModuleReloader.check | Check whether some modules need to be reloaded. | environment/lib/python2.7/site-packages/IPython/extensions/autoreload.py | def check(self, check_all=False):
"""Check whether some modules need to be reloaded."""
if not self.enabled and not check_all:
return
if check_all or self.check_all:
modules = sys.modules.keys()
else:
modules = self.modules.keys()
for modname in modules:
m = sys.modules.get(modname, None)
if modname in self.skip_modules:
continue
if not hasattr(m, '__file__'):
continue
if m.__name__ == '__main__':
# we cannot reload(__main__)
continue
filename = m.__file__
path, ext = os.path.splitext(filename)
if ext.lower() == '.py':
ext = PY_COMPILED_EXT
pyc_filename = pyfile.cache_from_source(filename)
py_filename = filename
else:
pyc_filename = filename
try:
py_filename = pyfile.source_from_cache(filename)
except ValueError:
continue
try:
pymtime = os.stat(py_filename).st_mtime
if pymtime <= os.stat(pyc_filename).st_mtime:
continue
if self.failed.get(py_filename, None) == pymtime:
continue
except OSError:
continue
try:
superreload(m, reload, self.old_objects)
if py_filename in self.failed:
del self.failed[py_filename]
except:
print >> sys.stderr, "[autoreload of %s failed: %s]" % (
modname, traceback.format_exc(1))
self.failed[py_filename] = pymtime | def check(self, check_all=False):
"""Check whether some modules need to be reloaded."""
if not self.enabled and not check_all:
return
if check_all or self.check_all:
modules = sys.modules.keys()
else:
modules = self.modules.keys()
for modname in modules:
m = sys.modules.get(modname, None)
if modname in self.skip_modules:
continue
if not hasattr(m, '__file__'):
continue
if m.__name__ == '__main__':
# we cannot reload(__main__)
continue
filename = m.__file__
path, ext = os.path.splitext(filename)
if ext.lower() == '.py':
ext = PY_COMPILED_EXT
pyc_filename = pyfile.cache_from_source(filename)
py_filename = filename
else:
pyc_filename = filename
try:
py_filename = pyfile.source_from_cache(filename)
except ValueError:
continue
try:
pymtime = os.stat(py_filename).st_mtime
if pymtime <= os.stat(pyc_filename).st_mtime:
continue
if self.failed.get(py_filename, None) == pymtime:
continue
except OSError:
continue
try:
superreload(m, reload, self.old_objects)
if py_filename in self.failed:
del self.failed[py_filename]
except:
print >> sys.stderr, "[autoreload of %s failed: %s]" % (
modname, traceback.format_exc(1))
self.failed[py_filename] = pymtime | [
"Check",
"whether",
"some",
"modules",
"need",
"to",
"be",
"reloaded",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/extensions/autoreload.py#L195-L249 | [
"def",
"check",
"(",
"self",
",",
"check_all",
"=",
"False",
")",
":",
"if",
"not",
"self",
".",
"enabled",
"and",
"not",
"check_all",
":",
"return",
"if",
"check_all",
"or",
"self",
".",
"check_all",
":",
"modules",
"=",
"sys",
".",
"modules",
".",
"keys",
"(",
")",
"else",
":",
"modules",
"=",
"self",
".",
"modules",
".",
"keys",
"(",
")",
"for",
"modname",
"in",
"modules",
":",
"m",
"=",
"sys",
".",
"modules",
".",
"get",
"(",
"modname",
",",
"None",
")",
"if",
"modname",
"in",
"self",
".",
"skip_modules",
":",
"continue",
"if",
"not",
"hasattr",
"(",
"m",
",",
"'__file__'",
")",
":",
"continue",
"if",
"m",
".",
"__name__",
"==",
"'__main__'",
":",
"# we cannot reload(__main__)",
"continue",
"filename",
"=",
"m",
".",
"__file__",
"path",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"filename",
")",
"if",
"ext",
".",
"lower",
"(",
")",
"==",
"'.py'",
":",
"ext",
"=",
"PY_COMPILED_EXT",
"pyc_filename",
"=",
"pyfile",
".",
"cache_from_source",
"(",
"filename",
")",
"py_filename",
"=",
"filename",
"else",
":",
"pyc_filename",
"=",
"filename",
"try",
":",
"py_filename",
"=",
"pyfile",
".",
"source_from_cache",
"(",
"filename",
")",
"except",
"ValueError",
":",
"continue",
"try",
":",
"pymtime",
"=",
"os",
".",
"stat",
"(",
"py_filename",
")",
".",
"st_mtime",
"if",
"pymtime",
"<=",
"os",
".",
"stat",
"(",
"pyc_filename",
")",
".",
"st_mtime",
":",
"continue",
"if",
"self",
".",
"failed",
".",
"get",
"(",
"py_filename",
",",
"None",
")",
"==",
"pymtime",
":",
"continue",
"except",
"OSError",
":",
"continue",
"try",
":",
"superreload",
"(",
"m",
",",
"reload",
",",
"self",
".",
"old_objects",
")",
"if",
"py_filename",
"in",
"self",
".",
"failed",
":",
"del",
"self",
".",
"failed",
"[",
"py_filename",
"]",
"except",
":",
"print",
">>",
"sys",
".",
"stderr",
",",
"\"[autoreload of %s failed: %s]\"",
"%",
"(",
"modname",
",",
"traceback",
".",
"format_exc",
"(",
"1",
")",
")",
"self",
".",
"failed",
"[",
"py_filename",
"]",
"=",
"pymtime"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | editor | Open the default editor at the given filename and linenumber.
This is IPython's default editor hook, you can use it as an example to
write your own modified one. To set your own editor function as the
new editor hook, call ip.set_hook('editor',yourfunc). | environment/lib/python2.7/site-packages/IPython/core/hooks.py | def editor(self, filename, linenum=None, wait=True):
"""Open the default editor at the given filename and linenumber.
This is IPython's default editor hook, you can use it as an example to
write your own modified one. To set your own editor function as the
new editor hook, call ip.set_hook('editor',yourfunc)."""
# IPython configures a default editor at startup by reading $EDITOR from
# the environment, and falling back on vi (unix) or notepad (win32).
editor = self.editor
# marker for at which line to open the file (for existing objects)
if linenum is None or editor=='notepad':
linemark = ''
else:
linemark = '+%d' % int(linenum)
# Enclose in quotes if necessary and legal
if ' ' in editor and os.path.isfile(editor) and editor[0] != '"':
editor = '"%s"' % editor
# Call the actual editor
proc = subprocess.Popen('%s %s %s' % (editor, linemark, filename),
shell=True)
if wait and proc.wait() != 0:
raise TryNext() | def editor(self, filename, linenum=None, wait=True):
"""Open the default editor at the given filename and linenumber.
This is IPython's default editor hook, you can use it as an example to
write your own modified one. To set your own editor function as the
new editor hook, call ip.set_hook('editor',yourfunc)."""
# IPython configures a default editor at startup by reading $EDITOR from
# the environment, and falling back on vi (unix) or notepad (win32).
editor = self.editor
# marker for at which line to open the file (for existing objects)
if linenum is None or editor=='notepad':
linemark = ''
else:
linemark = '+%d' % int(linenum)
# Enclose in quotes if necessary and legal
if ' ' in editor and os.path.isfile(editor) and editor[0] != '"':
editor = '"%s"' % editor
# Call the actual editor
proc = subprocess.Popen('%s %s %s' % (editor, linemark, filename),
shell=True)
if wait and proc.wait() != 0:
raise TryNext() | [
"Open",
"the",
"default",
"editor",
"at",
"the",
"given",
"filename",
"and",
"linenumber",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/core/hooks.py#L58-L83 | [
"def",
"editor",
"(",
"self",
",",
"filename",
",",
"linenum",
"=",
"None",
",",
"wait",
"=",
"True",
")",
":",
"# IPython configures a default editor at startup by reading $EDITOR from",
"# the environment, and falling back on vi (unix) or notepad (win32).",
"editor",
"=",
"self",
".",
"editor",
"# marker for at which line to open the file (for existing objects)",
"if",
"linenum",
"is",
"None",
"or",
"editor",
"==",
"'notepad'",
":",
"linemark",
"=",
"''",
"else",
":",
"linemark",
"=",
"'+%d'",
"%",
"int",
"(",
"linenum",
")",
"# Enclose in quotes if necessary and legal",
"if",
"' '",
"in",
"editor",
"and",
"os",
".",
"path",
".",
"isfile",
"(",
"editor",
")",
"and",
"editor",
"[",
"0",
"]",
"!=",
"'\"'",
":",
"editor",
"=",
"'\"%s\"'",
"%",
"editor",
"# Call the actual editor",
"proc",
"=",
"subprocess",
".",
"Popen",
"(",
"'%s %s %s'",
"%",
"(",
"editor",
",",
"linemark",
",",
"filename",
")",
",",
"shell",
"=",
"True",
")",
"if",
"wait",
"and",
"proc",
".",
"wait",
"(",
")",
"!=",
"0",
":",
"raise",
"TryNext",
"(",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | fix_error_editor | Open the editor at the given filename, linenumber, column and
show an error message. This is used for correcting syntax errors.
The current implementation only has special support for the VIM editor,
and falls back on the 'editor' hook if VIM is not used.
Call ip.set_hook('fix_error_editor',youfunc) to use your own function, | environment/lib/python2.7/site-packages/IPython/core/hooks.py | def fix_error_editor(self,filename,linenum,column,msg):
"""Open the editor at the given filename, linenumber, column and
show an error message. This is used for correcting syntax errors.
The current implementation only has special support for the VIM editor,
and falls back on the 'editor' hook if VIM is not used.
Call ip.set_hook('fix_error_editor',youfunc) to use your own function,
"""
def vim_quickfix_file():
t = tempfile.NamedTemporaryFile()
t.write('%s:%d:%d:%s\n' % (filename,linenum,column,msg))
t.flush()
return t
if os.path.basename(self.editor) != 'vim':
self.hooks.editor(filename,linenum)
return
t = vim_quickfix_file()
try:
if os.system('vim --cmd "set errorformat=%f:%l:%c:%m" -q ' + t.name):
raise TryNext()
finally:
t.close() | def fix_error_editor(self,filename,linenum,column,msg):
"""Open the editor at the given filename, linenumber, column and
show an error message. This is used for correcting syntax errors.
The current implementation only has special support for the VIM editor,
and falls back on the 'editor' hook if VIM is not used.
Call ip.set_hook('fix_error_editor',youfunc) to use your own function,
"""
def vim_quickfix_file():
t = tempfile.NamedTemporaryFile()
t.write('%s:%d:%d:%s\n' % (filename,linenum,column,msg))
t.flush()
return t
if os.path.basename(self.editor) != 'vim':
self.hooks.editor(filename,linenum)
return
t = vim_quickfix_file()
try:
if os.system('vim --cmd "set errorformat=%f:%l:%c:%m" -q ' + t.name):
raise TryNext()
finally:
t.close() | [
"Open",
"the",
"editor",
"at",
"the",
"given",
"filename",
"linenumber",
"column",
"and",
"show",
"an",
"error",
"message",
".",
"This",
"is",
"used",
"for",
"correcting",
"syntax",
"errors",
".",
"The",
"current",
"implementation",
"only",
"has",
"special",
"support",
"for",
"the",
"VIM",
"editor",
"and",
"falls",
"back",
"on",
"the",
"editor",
"hook",
"if",
"VIM",
"is",
"not",
"used",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/core/hooks.py#L86-L107 | [
"def",
"fix_error_editor",
"(",
"self",
",",
"filename",
",",
"linenum",
",",
"column",
",",
"msg",
")",
":",
"def",
"vim_quickfix_file",
"(",
")",
":",
"t",
"=",
"tempfile",
".",
"NamedTemporaryFile",
"(",
")",
"t",
".",
"write",
"(",
"'%s:%d:%d:%s\\n'",
"%",
"(",
"filename",
",",
"linenum",
",",
"column",
",",
"msg",
")",
")",
"t",
".",
"flush",
"(",
")",
"return",
"t",
"if",
"os",
".",
"path",
".",
"basename",
"(",
"self",
".",
"editor",
")",
"!=",
"'vim'",
":",
"self",
".",
"hooks",
".",
"editor",
"(",
"filename",
",",
"linenum",
")",
"return",
"t",
"=",
"vim_quickfix_file",
"(",
")",
"try",
":",
"if",
"os",
".",
"system",
"(",
"'vim --cmd \"set errorformat=%f:%l:%c:%m\" -q '",
"+",
"t",
".",
"name",
")",
":",
"raise",
"TryNext",
"(",
")",
"finally",
":",
"t",
".",
"close",
"(",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | clipboard_get | Get text from the clipboard. | environment/lib/python2.7/site-packages/IPython/core/hooks.py | def clipboard_get(self):
""" Get text from the clipboard.
"""
from IPython.lib.clipboard import (
osx_clipboard_get, tkinter_clipboard_get,
win32_clipboard_get
)
if sys.platform == 'win32':
chain = [win32_clipboard_get, tkinter_clipboard_get]
elif sys.platform == 'darwin':
chain = [osx_clipboard_get, tkinter_clipboard_get]
else:
chain = [tkinter_clipboard_get]
dispatcher = CommandChainDispatcher()
for func in chain:
dispatcher.add(func)
text = dispatcher()
return text | def clipboard_get(self):
""" Get text from the clipboard.
"""
from IPython.lib.clipboard import (
osx_clipboard_get, tkinter_clipboard_get,
win32_clipboard_get
)
if sys.platform == 'win32':
chain = [win32_clipboard_get, tkinter_clipboard_get]
elif sys.platform == 'darwin':
chain = [osx_clipboard_get, tkinter_clipboard_get]
else:
chain = [tkinter_clipboard_get]
dispatcher = CommandChainDispatcher()
for func in chain:
dispatcher.add(func)
text = dispatcher()
return text | [
"Get",
"text",
"from",
"the",
"clipboard",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/core/hooks.py#L213-L230 | [
"def",
"clipboard_get",
"(",
"self",
")",
":",
"from",
"IPython",
".",
"lib",
".",
"clipboard",
"import",
"(",
"osx_clipboard_get",
",",
"tkinter_clipboard_get",
",",
"win32_clipboard_get",
")",
"if",
"sys",
".",
"platform",
"==",
"'win32'",
":",
"chain",
"=",
"[",
"win32_clipboard_get",
",",
"tkinter_clipboard_get",
"]",
"elif",
"sys",
".",
"platform",
"==",
"'darwin'",
":",
"chain",
"=",
"[",
"osx_clipboard_get",
",",
"tkinter_clipboard_get",
"]",
"else",
":",
"chain",
"=",
"[",
"tkinter_clipboard_get",
"]",
"dispatcher",
"=",
"CommandChainDispatcher",
"(",
")",
"for",
"func",
"in",
"chain",
":",
"dispatcher",
".",
"add",
"(",
"func",
")",
"text",
"=",
"dispatcher",
"(",
")",
"return",
"text"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | CommandChainDispatcher.add | Add a func to the cmd chain with given priority | environment/lib/python2.7/site-packages/IPython/core/hooks.py | def add(self, func, priority=0):
""" Add a func to the cmd chain with given priority """
self.chain.append((priority, func))
self.chain.sort(key=lambda x: x[0]) | def add(self, func, priority=0):
""" Add a func to the cmd chain with given priority """
self.chain.append((priority, func))
self.chain.sort(key=lambda x: x[0]) | [
"Add",
"a",
"func",
"to",
"the",
"cmd",
"chain",
"with",
"given",
"priority"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/core/hooks.py#L147-L150 | [
"def",
"add",
"(",
"self",
",",
"func",
",",
"priority",
"=",
"0",
")",
":",
"self",
".",
"chain",
".",
"append",
"(",
"(",
"priority",
",",
"func",
")",
")",
"self",
".",
"chain",
".",
"sort",
"(",
"key",
"=",
"lambda",
"x",
":",
"x",
"[",
"0",
"]",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | get_metadata | Try to create a Distribution 'path_or_module'.
o 'path_or_module' may be a module object.
o If a string, 'path_or_module' may point to an sdist file, a bdist
file, an installed package, or a working checkout (if it contains
PKG-INFO).
o Return None if 'path_or_module' can't be parsed. | virtualEnvironment/lib/python2.7/site-packages/pkginfo/utils.py | def get_metadata(path_or_module, metadata_version=None):
""" Try to create a Distribution 'path_or_module'.
o 'path_or_module' may be a module object.
o If a string, 'path_or_module' may point to an sdist file, a bdist
file, an installed package, or a working checkout (if it contains
PKG-INFO).
o Return None if 'path_or_module' can't be parsed.
"""
if isinstance(path_or_module, ModuleType):
try:
return Installed(path_or_module, metadata_version)
except (ValueError, IOError): #pragma NO COVER
pass
try:
__import__(path_or_module)
except ImportError:
pass
else:
try:
return Installed(path_or_module, metadata_version)
except (ValueError, IOError): #pragma NO COVER
pass
if os.path.isfile(path_or_module):
try:
return SDist(path_or_module, metadata_version)
except (ValueError, IOError):
pass
try:
return BDist(path_or_module, metadata_version)
except (ValueError, IOError): #pragma NO COVER
pass
try:
return Wheel(path_or_module, metadata_version)
except (ValueError, IOError): #pragma NO COVER
pass
if os.path.isdir(path_or_module):
try:
return Develop(path_or_module, metadata_version)
except (ValueError, IOError): #pragma NO COVER
pass | def get_metadata(path_or_module, metadata_version=None):
""" Try to create a Distribution 'path_or_module'.
o 'path_or_module' may be a module object.
o If a string, 'path_or_module' may point to an sdist file, a bdist
file, an installed package, or a working checkout (if it contains
PKG-INFO).
o Return None if 'path_or_module' can't be parsed.
"""
if isinstance(path_or_module, ModuleType):
try:
return Installed(path_or_module, metadata_version)
except (ValueError, IOError): #pragma NO COVER
pass
try:
__import__(path_or_module)
except ImportError:
pass
else:
try:
return Installed(path_or_module, metadata_version)
except (ValueError, IOError): #pragma NO COVER
pass
if os.path.isfile(path_or_module):
try:
return SDist(path_or_module, metadata_version)
except (ValueError, IOError):
pass
try:
return BDist(path_or_module, metadata_version)
except (ValueError, IOError): #pragma NO COVER
pass
try:
return Wheel(path_or_module, metadata_version)
except (ValueError, IOError): #pragma NO COVER
pass
if os.path.isdir(path_or_module):
try:
return Develop(path_or_module, metadata_version)
except (ValueError, IOError): #pragma NO COVER
pass | [
"Try",
"to",
"create",
"a",
"Distribution",
"path_or_module",
".",
"o",
"path_or_module",
"may",
"be",
"a",
"module",
"object",
"."
] | tnkteja/myhelp | python | https://github.com/tnkteja/myhelp/blob/fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb/virtualEnvironment/lib/python2.7/site-packages/pkginfo/utils.py#L10-L57 | [
"def",
"get_metadata",
"(",
"path_or_module",
",",
"metadata_version",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"path_or_module",
",",
"ModuleType",
")",
":",
"try",
":",
"return",
"Installed",
"(",
"path_or_module",
",",
"metadata_version",
")",
"except",
"(",
"ValueError",
",",
"IOError",
")",
":",
"#pragma NO COVER",
"pass",
"try",
":",
"__import__",
"(",
"path_or_module",
")",
"except",
"ImportError",
":",
"pass",
"else",
":",
"try",
":",
"return",
"Installed",
"(",
"path_or_module",
",",
"metadata_version",
")",
"except",
"(",
"ValueError",
",",
"IOError",
")",
":",
"#pragma NO COVER",
"pass",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"path_or_module",
")",
":",
"try",
":",
"return",
"SDist",
"(",
"path_or_module",
",",
"metadata_version",
")",
"except",
"(",
"ValueError",
",",
"IOError",
")",
":",
"pass",
"try",
":",
"return",
"BDist",
"(",
"path_or_module",
",",
"metadata_version",
")",
"except",
"(",
"ValueError",
",",
"IOError",
")",
":",
"#pragma NO COVER",
"pass",
"try",
":",
"return",
"Wheel",
"(",
"path_or_module",
",",
"metadata_version",
")",
"except",
"(",
"ValueError",
",",
"IOError",
")",
":",
"#pragma NO COVER",
"pass",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"path_or_module",
")",
":",
"try",
":",
"return",
"Develop",
"(",
"path_or_module",
",",
"metadata_version",
")",
"except",
"(",
"ValueError",
",",
"IOError",
")",
":",
"#pragma NO COVER",
"pass"
] | fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb |
test | Pdb.configure | Configure which kinds of exceptions trigger plugin. | environment/lib/python2.7/site-packages/nose/plugins/debug.py | def configure(self, options, conf):
"""Configure which kinds of exceptions trigger plugin.
"""
self.conf = conf
self.enabled = options.debugErrors or options.debugFailures
self.enabled_for_errors = options.debugErrors
self.enabled_for_failures = options.debugFailures | def configure(self, options, conf):
"""Configure which kinds of exceptions trigger plugin.
"""
self.conf = conf
self.enabled = options.debugErrors or options.debugFailures
self.enabled_for_errors = options.debugErrors
self.enabled_for_failures = options.debugFailures | [
"Configure",
"which",
"kinds",
"of",
"exceptions",
"trigger",
"plugin",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/nose/plugins/debug.py#L32-L38 | [
"def",
"configure",
"(",
"self",
",",
"options",
",",
"conf",
")",
":",
"self",
".",
"conf",
"=",
"conf",
"self",
".",
"enabled",
"=",
"options",
".",
"debugErrors",
"or",
"options",
".",
"debugFailures",
"self",
".",
"enabled_for_errors",
"=",
"options",
".",
"debugErrors",
"self",
".",
"enabled_for_failures",
"=",
"options",
".",
"debugFailures"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | obfuscate | Given a string representing an email address,
returns a mailto link with rot13 JavaScript obfuscation.
Accepts an optional argument to use as the link text;
otherwise uses the email address itself. | toolware/templatetags/email.py | def obfuscate(email, linktext=None, autoescape=None):
"""
Given a string representing an email address,
returns a mailto link with rot13 JavaScript obfuscation.
Accepts an optional argument to use as the link text;
otherwise uses the email address itself.
"""
if autoescape:
esc = conditional_escape
else:
esc = lambda x: x
email = re.sub('@', '\\\\100', re.sub('\.', '\\\\056', esc(email))).encode('rot13')
if linktext:
linktext = esc(linktext).encode('rot13')
else:
linktext = email
rotten_link = """<script type="text/javascript">document.write \
("<n uers=\\\"znvygb:%s\\\">%s<\\057n>".replace(/[a-zA-Z]/g, \
function(c){return String.fromCharCode((c<="Z"?90:122)>=\
(c=c.charCodeAt(0)+13)?c:c-26);}));</script>""" % (email, linktext)
return mark_safe(rotten_link) | def obfuscate(email, linktext=None, autoescape=None):
"""
Given a string representing an email address,
returns a mailto link with rot13 JavaScript obfuscation.
Accepts an optional argument to use as the link text;
otherwise uses the email address itself.
"""
if autoescape:
esc = conditional_escape
else:
esc = lambda x: x
email = re.sub('@', '\\\\100', re.sub('\.', '\\\\056', esc(email))).encode('rot13')
if linktext:
linktext = esc(linktext).encode('rot13')
else:
linktext = email
rotten_link = """<script type="text/javascript">document.write \
("<n uers=\\\"znvygb:%s\\\">%s<\\057n>".replace(/[a-zA-Z]/g, \
function(c){return String.fromCharCode((c<="Z"?90:122)>=\
(c=c.charCodeAt(0)+13)?c:c-26);}));</script>""" % (email, linktext)
return mark_safe(rotten_link) | [
"Given",
"a",
"string",
"representing",
"an",
"email",
"address",
"returns",
"a",
"mailto",
"link",
"with",
"rot13",
"JavaScript",
"obfuscation",
"."
] | un33k/django-toolware | python | https://github.com/un33k/django-toolware/blob/973f3e003dc38b812897dab88455bee37dcaf931/toolware/templatetags/email.py#L10-L34 | [
"def",
"obfuscate",
"(",
"email",
",",
"linktext",
"=",
"None",
",",
"autoescape",
"=",
"None",
")",
":",
"if",
"autoescape",
":",
"esc",
"=",
"conditional_escape",
"else",
":",
"esc",
"=",
"lambda",
"x",
":",
"x",
"email",
"=",
"re",
".",
"sub",
"(",
"'@'",
",",
"'\\\\\\\\100'",
",",
"re",
".",
"sub",
"(",
"'\\.'",
",",
"'\\\\\\\\056'",
",",
"esc",
"(",
"email",
")",
")",
")",
".",
"encode",
"(",
"'rot13'",
")",
"if",
"linktext",
":",
"linktext",
"=",
"esc",
"(",
"linktext",
")",
".",
"encode",
"(",
"'rot13'",
")",
"else",
":",
"linktext",
"=",
"email",
"rotten_link",
"=",
"\"\"\"<script type=\"text/javascript\">document.write \\\n (\"<n uers=\\\\\\\"znvygb:%s\\\\\\\">%s<\\\\057n>\".replace(/[a-zA-Z]/g, \\\n function(c){return String.fromCharCode((c<=\"Z\"?90:122)>=\\\n (c=c.charCodeAt(0)+13)?c:c-26);}));</script>\"\"\"",
"%",
"(",
"email",
",",
"linktext",
")",
"return",
"mark_safe",
"(",
"rotten_link",
")"
] | 973f3e003dc38b812897dab88455bee37dcaf931 |
test | roundplus | given an number, this fuction rounds the number as the following examples:
87 -> 87, 100 -> 100+, 188 -> 100+, 999 -> 900+, 1001 -> 1000+, ...etc | toolware/templatetags/rounder.py | def roundplus(number):
"""
given an number, this fuction rounds the number as the following examples:
87 -> 87, 100 -> 100+, 188 -> 100+, 999 -> 900+, 1001 -> 1000+, ...etc
"""
num = str(number)
if not num.isdigit():
return num
num = str(number)
digits = len(num)
rounded = '100+'
if digits < 3:
rounded = num
elif digits == 3:
rounded = num[0] + '00+'
elif digits == 4:
rounded = num[0] + 'K+'
elif digits == 5:
rounded = num[:1] + 'K+'
else:
rounded = '100K+'
return rounded | def roundplus(number):
"""
given an number, this fuction rounds the number as the following examples:
87 -> 87, 100 -> 100+, 188 -> 100+, 999 -> 900+, 1001 -> 1000+, ...etc
"""
num = str(number)
if not num.isdigit():
return num
num = str(number)
digits = len(num)
rounded = '100+'
if digits < 3:
rounded = num
elif digits == 3:
rounded = num[0] + '00+'
elif digits == 4:
rounded = num[0] + 'K+'
elif digits == 5:
rounded = num[:1] + 'K+'
else:
rounded = '100K+'
return rounded | [
"given",
"an",
"number",
"this",
"fuction",
"rounds",
"the",
"number",
"as",
"the",
"following",
"examples",
":",
"87",
"-",
">",
"87",
"100",
"-",
">",
"100",
"+",
"188",
"-",
">",
"100",
"+",
"999",
"-",
">",
"900",
"+",
"1001",
"-",
">",
"1000",
"+",
"...",
"etc"
] | un33k/django-toolware | python | https://github.com/un33k/django-toolware/blob/973f3e003dc38b812897dab88455bee37dcaf931/toolware/templatetags/rounder.py#L10-L34 | [
"def",
"roundplus",
"(",
"number",
")",
":",
"num",
"=",
"str",
"(",
"number",
")",
"if",
"not",
"num",
".",
"isdigit",
"(",
")",
":",
"return",
"num",
"num",
"=",
"str",
"(",
"number",
")",
"digits",
"=",
"len",
"(",
"num",
")",
"rounded",
"=",
"'100+'",
"if",
"digits",
"<",
"3",
":",
"rounded",
"=",
"num",
"elif",
"digits",
"==",
"3",
":",
"rounded",
"=",
"num",
"[",
"0",
"]",
"+",
"'00+'",
"elif",
"digits",
"==",
"4",
":",
"rounded",
"=",
"num",
"[",
"0",
"]",
"+",
"'K+'",
"elif",
"digits",
"==",
"5",
":",
"rounded",
"=",
"num",
"[",
":",
"1",
"]",
"+",
"'K+'",
"else",
":",
"rounded",
"=",
"'100K+'",
"return",
"rounded"
] | 973f3e003dc38b812897dab88455bee37dcaf931 |
test | import_item | Import and return bar given the string foo.bar. | environment/lib/python2.7/site-packages/IPython/utils/importstring.py | def import_item(name):
"""Import and return bar given the string foo.bar."""
package = '.'.join(name.split('.')[0:-1])
obj = name.split('.')[-1]
# Note: the original code for this was the following. We've left it
# visible for now in case the new implementation shows any problems down
# the road, to make it easier on anyone looking for a problem. This code
# should be removed once we're comfortable we didn't break anything.
## execString = 'from %s import %s' % (package, obj)
## try:
## exec execString
## except SyntaxError:
## raise ImportError("Invalid class specification: %s" % name)
## exec 'temp = %s' % obj
## return temp
if package:
module = __import__(package,fromlist=[obj])
try:
pak = module.__dict__[obj]
except KeyError:
raise ImportError('No module named %s' % obj)
return pak
else:
return __import__(obj) | def import_item(name):
"""Import and return bar given the string foo.bar."""
package = '.'.join(name.split('.')[0:-1])
obj = name.split('.')[-1]
# Note: the original code for this was the following. We've left it
# visible for now in case the new implementation shows any problems down
# the road, to make it easier on anyone looking for a problem. This code
# should be removed once we're comfortable we didn't break anything.
## execString = 'from %s import %s' % (package, obj)
## try:
## exec execString
## except SyntaxError:
## raise ImportError("Invalid class specification: %s" % name)
## exec 'temp = %s' % obj
## return temp
if package:
module = __import__(package,fromlist=[obj])
try:
pak = module.__dict__[obj]
except KeyError:
raise ImportError('No module named %s' % obj)
return pak
else:
return __import__(obj) | [
"Import",
"and",
"return",
"bar",
"given",
"the",
"string",
"foo",
".",
"bar",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/utils/importstring.py#L21-L47 | [
"def",
"import_item",
"(",
"name",
")",
":",
"package",
"=",
"'.'",
".",
"join",
"(",
"name",
".",
"split",
"(",
"'.'",
")",
"[",
"0",
":",
"-",
"1",
"]",
")",
"obj",
"=",
"name",
".",
"split",
"(",
"'.'",
")",
"[",
"-",
"1",
"]",
"# Note: the original code for this was the following. We've left it",
"# visible for now in case the new implementation shows any problems down",
"# the road, to make it easier on anyone looking for a problem. This code",
"# should be removed once we're comfortable we didn't break anything.",
"## execString = 'from %s import %s' % (package, obj)",
"## try:",
"## exec execString",
"## except SyntaxError:",
"## raise ImportError(\"Invalid class specification: %s\" % name)",
"## exec 'temp = %s' % obj",
"## return temp",
"if",
"package",
":",
"module",
"=",
"__import__",
"(",
"package",
",",
"fromlist",
"=",
"[",
"obj",
"]",
")",
"try",
":",
"pak",
"=",
"module",
".",
"__dict__",
"[",
"obj",
"]",
"except",
"KeyError",
":",
"raise",
"ImportError",
"(",
"'No module named %s'",
"%",
"obj",
")",
"return",
"pak",
"else",
":",
"return",
"__import__",
"(",
"obj",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | try_passwordless_ssh | Attempt to make an ssh connection without a password.
This is mainly used for requiring password input only once
when many tunnels may be connected to the same server.
If paramiko is None, the default for the platform is chosen. | environment/lib/python2.7/site-packages/IPython/external/ssh/tunnel.py | def try_passwordless_ssh(server, keyfile, paramiko=None):
"""Attempt to make an ssh connection without a password.
This is mainly used for requiring password input only once
when many tunnels may be connected to the same server.
If paramiko is None, the default for the platform is chosen.
"""
if paramiko is None:
paramiko = sys.platform == 'win32'
if not paramiko:
f = _try_passwordless_openssh
else:
f = _try_passwordless_paramiko
return f(server, keyfile) | def try_passwordless_ssh(server, keyfile, paramiko=None):
"""Attempt to make an ssh connection without a password.
This is mainly used for requiring password input only once
when many tunnels may be connected to the same server.
If paramiko is None, the default for the platform is chosen.
"""
if paramiko is None:
paramiko = sys.platform == 'win32'
if not paramiko:
f = _try_passwordless_openssh
else:
f = _try_passwordless_paramiko
return f(server, keyfile) | [
"Attempt",
"to",
"make",
"an",
"ssh",
"connection",
"without",
"a",
"password",
".",
"This",
"is",
"mainly",
"used",
"for",
"requiring",
"password",
"input",
"only",
"once",
"when",
"many",
"tunnels",
"may",
"be",
"connected",
"to",
"the",
"same",
"server",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/external/ssh/tunnel.py#L74-L87 | [
"def",
"try_passwordless_ssh",
"(",
"server",
",",
"keyfile",
",",
"paramiko",
"=",
"None",
")",
":",
"if",
"paramiko",
"is",
"None",
":",
"paramiko",
"=",
"sys",
".",
"platform",
"==",
"'win32'",
"if",
"not",
"paramiko",
":",
"f",
"=",
"_try_passwordless_openssh",
"else",
":",
"f",
"=",
"_try_passwordless_paramiko",
"return",
"f",
"(",
"server",
",",
"keyfile",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | _try_passwordless_openssh | Try passwordless login with shell ssh command. | environment/lib/python2.7/site-packages/IPython/external/ssh/tunnel.py | def _try_passwordless_openssh(server, keyfile):
"""Try passwordless login with shell ssh command."""
if pexpect is None:
raise ImportError("pexpect unavailable, use paramiko")
cmd = 'ssh -f '+ server
if keyfile:
cmd += ' -i ' + keyfile
cmd += ' exit'
p = pexpect.spawn(cmd)
while True:
try:
p.expect('[Pp]assword:', timeout=.1)
except pexpect.TIMEOUT:
continue
except pexpect.EOF:
return True
else:
return False | def _try_passwordless_openssh(server, keyfile):
"""Try passwordless login with shell ssh command."""
if pexpect is None:
raise ImportError("pexpect unavailable, use paramiko")
cmd = 'ssh -f '+ server
if keyfile:
cmd += ' -i ' + keyfile
cmd += ' exit'
p = pexpect.spawn(cmd)
while True:
try:
p.expect('[Pp]assword:', timeout=.1)
except pexpect.TIMEOUT:
continue
except pexpect.EOF:
return True
else:
return False | [
"Try",
"passwordless",
"login",
"with",
"shell",
"ssh",
"command",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/external/ssh/tunnel.py#L89-L106 | [
"def",
"_try_passwordless_openssh",
"(",
"server",
",",
"keyfile",
")",
":",
"if",
"pexpect",
"is",
"None",
":",
"raise",
"ImportError",
"(",
"\"pexpect unavailable, use paramiko\"",
")",
"cmd",
"=",
"'ssh -f '",
"+",
"server",
"if",
"keyfile",
":",
"cmd",
"+=",
"' -i '",
"+",
"keyfile",
"cmd",
"+=",
"' exit'",
"p",
"=",
"pexpect",
".",
"spawn",
"(",
"cmd",
")",
"while",
"True",
":",
"try",
":",
"p",
".",
"expect",
"(",
"'[Pp]assword:'",
",",
"timeout",
"=",
".1",
")",
"except",
"pexpect",
".",
"TIMEOUT",
":",
"continue",
"except",
"pexpect",
".",
"EOF",
":",
"return",
"True",
"else",
":",
"return",
"False"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | _try_passwordless_paramiko | Try passwordless login with paramiko. | environment/lib/python2.7/site-packages/IPython/external/ssh/tunnel.py | def _try_passwordless_paramiko(server, keyfile):
"""Try passwordless login with paramiko."""
if paramiko is None:
msg = "Paramiko unavaliable, "
if sys.platform == 'win32':
msg += "Paramiko is required for ssh tunneled connections on Windows."
else:
msg += "use OpenSSH."
raise ImportError(msg)
username, server, port = _split_server(server)
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
try:
client.connect(server, port, username=username, key_filename=keyfile,
look_for_keys=True)
except paramiko.AuthenticationException:
return False
else:
client.close()
return True | def _try_passwordless_paramiko(server, keyfile):
"""Try passwordless login with paramiko."""
if paramiko is None:
msg = "Paramiko unavaliable, "
if sys.platform == 'win32':
msg += "Paramiko is required for ssh tunneled connections on Windows."
else:
msg += "use OpenSSH."
raise ImportError(msg)
username, server, port = _split_server(server)
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
try:
client.connect(server, port, username=username, key_filename=keyfile,
look_for_keys=True)
except paramiko.AuthenticationException:
return False
else:
client.close()
return True | [
"Try",
"passwordless",
"login",
"with",
"paramiko",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/external/ssh/tunnel.py#L108-L128 | [
"def",
"_try_passwordless_paramiko",
"(",
"server",
",",
"keyfile",
")",
":",
"if",
"paramiko",
"is",
"None",
":",
"msg",
"=",
"\"Paramiko unavaliable, \"",
"if",
"sys",
".",
"platform",
"==",
"'win32'",
":",
"msg",
"+=",
"\"Paramiko is required for ssh tunneled connections on Windows.\"",
"else",
":",
"msg",
"+=",
"\"use OpenSSH.\"",
"raise",
"ImportError",
"(",
"msg",
")",
"username",
",",
"server",
",",
"port",
"=",
"_split_server",
"(",
"server",
")",
"client",
"=",
"paramiko",
".",
"SSHClient",
"(",
")",
"client",
".",
"load_system_host_keys",
"(",
")",
"client",
".",
"set_missing_host_key_policy",
"(",
"paramiko",
".",
"WarningPolicy",
"(",
")",
")",
"try",
":",
"client",
".",
"connect",
"(",
"server",
",",
"port",
",",
"username",
"=",
"username",
",",
"key_filename",
"=",
"keyfile",
",",
"look_for_keys",
"=",
"True",
")",
"except",
"paramiko",
".",
"AuthenticationException",
":",
"return",
"False",
"else",
":",
"client",
".",
"close",
"(",
")",
"return",
"True"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | tunnel_connection | Connect a socket to an address via an ssh tunnel.
This is a wrapper for socket.connect(addr), when addr is not accessible
from the local machine. It simply creates an ssh tunnel using the remaining args,
and calls socket.connect('tcp://localhost:lport') where lport is the randomly
selected local port of the tunnel. | environment/lib/python2.7/site-packages/IPython/external/ssh/tunnel.py | def tunnel_connection(socket, addr, server, keyfile=None, password=None, paramiko=None, timeout=60):
"""Connect a socket to an address via an ssh tunnel.
This is a wrapper for socket.connect(addr), when addr is not accessible
from the local machine. It simply creates an ssh tunnel using the remaining args,
and calls socket.connect('tcp://localhost:lport') where lport is the randomly
selected local port of the tunnel.
"""
new_url, tunnel = open_tunnel(addr, server, keyfile=keyfile, password=password, paramiko=paramiko, timeout=timeout)
socket.connect(new_url)
return tunnel | def tunnel_connection(socket, addr, server, keyfile=None, password=None, paramiko=None, timeout=60):
"""Connect a socket to an address via an ssh tunnel.
This is a wrapper for socket.connect(addr), when addr is not accessible
from the local machine. It simply creates an ssh tunnel using the remaining args,
and calls socket.connect('tcp://localhost:lport') where lport is the randomly
selected local port of the tunnel.
"""
new_url, tunnel = open_tunnel(addr, server, keyfile=keyfile, password=password, paramiko=paramiko, timeout=timeout)
socket.connect(new_url)
return tunnel | [
"Connect",
"a",
"socket",
"to",
"an",
"address",
"via",
"an",
"ssh",
"tunnel",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/external/ssh/tunnel.py#L131-L142 | [
"def",
"tunnel_connection",
"(",
"socket",
",",
"addr",
",",
"server",
",",
"keyfile",
"=",
"None",
",",
"password",
"=",
"None",
",",
"paramiko",
"=",
"None",
",",
"timeout",
"=",
"60",
")",
":",
"new_url",
",",
"tunnel",
"=",
"open_tunnel",
"(",
"addr",
",",
"server",
",",
"keyfile",
"=",
"keyfile",
",",
"password",
"=",
"password",
",",
"paramiko",
"=",
"paramiko",
",",
"timeout",
"=",
"timeout",
")",
"socket",
".",
"connect",
"(",
"new_url",
")",
"return",
"tunnel"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | open_tunnel | Open a tunneled connection from a 0MQ url.
For use inside tunnel_connection.
Returns
-------
(url, tunnel): The 0MQ url that has been forwarded, and the tunnel object | environment/lib/python2.7/site-packages/IPython/external/ssh/tunnel.py | def open_tunnel(addr, server, keyfile=None, password=None, paramiko=None, timeout=60):
"""Open a tunneled connection from a 0MQ url.
For use inside tunnel_connection.
Returns
-------
(url, tunnel): The 0MQ url that has been forwarded, and the tunnel object
"""
lport = select_random_ports(1)[0]
transport, addr = addr.split('://')
ip,rport = addr.split(':')
rport = int(rport)
if paramiko is None:
paramiko = sys.platform == 'win32'
if paramiko:
tunnelf = paramiko_tunnel
else:
tunnelf = openssh_tunnel
tunnel = tunnelf(lport, rport, server, remoteip=ip, keyfile=keyfile, password=password, timeout=timeout)
return 'tcp://127.0.0.1:%i'%lport, tunnel | def open_tunnel(addr, server, keyfile=None, password=None, paramiko=None, timeout=60):
"""Open a tunneled connection from a 0MQ url.
For use inside tunnel_connection.
Returns
-------
(url, tunnel): The 0MQ url that has been forwarded, and the tunnel object
"""
lport = select_random_ports(1)[0]
transport, addr = addr.split('://')
ip,rport = addr.split(':')
rport = int(rport)
if paramiko is None:
paramiko = sys.platform == 'win32'
if paramiko:
tunnelf = paramiko_tunnel
else:
tunnelf = openssh_tunnel
tunnel = tunnelf(lport, rport, server, remoteip=ip, keyfile=keyfile, password=password, timeout=timeout)
return 'tcp://127.0.0.1:%i'%lport, tunnel | [
"Open",
"a",
"tunneled",
"connection",
"from",
"a",
"0MQ",
"url",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/external/ssh/tunnel.py#L145-L168 | [
"def",
"open_tunnel",
"(",
"addr",
",",
"server",
",",
"keyfile",
"=",
"None",
",",
"password",
"=",
"None",
",",
"paramiko",
"=",
"None",
",",
"timeout",
"=",
"60",
")",
":",
"lport",
"=",
"select_random_ports",
"(",
"1",
")",
"[",
"0",
"]",
"transport",
",",
"addr",
"=",
"addr",
".",
"split",
"(",
"'://'",
")",
"ip",
",",
"rport",
"=",
"addr",
".",
"split",
"(",
"':'",
")",
"rport",
"=",
"int",
"(",
"rport",
")",
"if",
"paramiko",
"is",
"None",
":",
"paramiko",
"=",
"sys",
".",
"platform",
"==",
"'win32'",
"if",
"paramiko",
":",
"tunnelf",
"=",
"paramiko_tunnel",
"else",
":",
"tunnelf",
"=",
"openssh_tunnel",
"tunnel",
"=",
"tunnelf",
"(",
"lport",
",",
"rport",
",",
"server",
",",
"remoteip",
"=",
"ip",
",",
"keyfile",
"=",
"keyfile",
",",
"password",
"=",
"password",
",",
"timeout",
"=",
"timeout",
")",
"return",
"'tcp://127.0.0.1:%i'",
"%",
"lport",
",",
"tunnel"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | openssh_tunnel | Create an ssh tunnel using command-line ssh that connects port lport
on this machine to localhost:rport on server. The tunnel
will automatically close when not in use, remaining open
for a minimum of timeout seconds for an initial connection.
This creates a tunnel redirecting `localhost:lport` to `remoteip:rport`,
as seen from `server`.
keyfile and password may be specified, but ssh config is checked for defaults.
Parameters
----------
lport : int
local port for connecting to the tunnel from this machine.
rport : int
port on the remote machine to connect to.
server : str
The ssh server to connect to. The full ssh server string will be parsed.
user@server:port
remoteip : str [Default: 127.0.0.1]
The remote ip, specifying the destination of the tunnel.
Default is localhost, which means that the tunnel would redirect
localhost:lport on this machine to localhost:rport on the *server*.
keyfile : str; path to public key file
This specifies a key to be used in ssh login, default None.
Regular default ssh keys will be used without specifying this argument.
password : str;
Your ssh password to the ssh server. Note that if this is left None,
you will be prompted for it if passwordless key based login is unavailable.
timeout : int [default: 60]
The time (in seconds) after which no activity will result in the tunnel
closing. This prevents orphaned tunnels from running forever. | environment/lib/python2.7/site-packages/IPython/external/ssh/tunnel.py | def openssh_tunnel(lport, rport, server, remoteip='127.0.0.1', keyfile=None, password=None, timeout=60):
"""Create an ssh tunnel using command-line ssh that connects port lport
on this machine to localhost:rport on server. The tunnel
will automatically close when not in use, remaining open
for a minimum of timeout seconds for an initial connection.
This creates a tunnel redirecting `localhost:lport` to `remoteip:rport`,
as seen from `server`.
keyfile and password may be specified, but ssh config is checked for defaults.
Parameters
----------
lport : int
local port for connecting to the tunnel from this machine.
rport : int
port on the remote machine to connect to.
server : str
The ssh server to connect to. The full ssh server string will be parsed.
user@server:port
remoteip : str [Default: 127.0.0.1]
The remote ip, specifying the destination of the tunnel.
Default is localhost, which means that the tunnel would redirect
localhost:lport on this machine to localhost:rport on the *server*.
keyfile : str; path to public key file
This specifies a key to be used in ssh login, default None.
Regular default ssh keys will be used without specifying this argument.
password : str;
Your ssh password to the ssh server. Note that if this is left None,
you will be prompted for it if passwordless key based login is unavailable.
timeout : int [default: 60]
The time (in seconds) after which no activity will result in the tunnel
closing. This prevents orphaned tunnels from running forever.
"""
if pexpect is None:
raise ImportError("pexpect unavailable, use paramiko_tunnel")
ssh="ssh "
if keyfile:
ssh += "-i " + keyfile
if ':' in server:
server, port = server.split(':')
ssh += " -p %s" % port
cmd = "%s -f -L 127.0.0.1:%i:%s:%i %s sleep %i" % (
ssh, lport, remoteip, rport, server, timeout)
tunnel = pexpect.spawn(cmd)
failed = False
while True:
try:
tunnel.expect('[Pp]assword:', timeout=.1)
except pexpect.TIMEOUT:
continue
except pexpect.EOF:
if tunnel.exitstatus:
print (tunnel.exitstatus)
print (tunnel.before)
print (tunnel.after)
raise RuntimeError("tunnel '%s' failed to start"%(cmd))
else:
return tunnel.pid
else:
if failed:
print("Password rejected, try again")
password=None
if password is None:
password = getpass("%s's password: "%(server))
tunnel.sendline(password)
failed = True | def openssh_tunnel(lport, rport, server, remoteip='127.0.0.1', keyfile=None, password=None, timeout=60):
"""Create an ssh tunnel using command-line ssh that connects port lport
on this machine to localhost:rport on server. The tunnel
will automatically close when not in use, remaining open
for a minimum of timeout seconds for an initial connection.
This creates a tunnel redirecting `localhost:lport` to `remoteip:rport`,
as seen from `server`.
keyfile and password may be specified, but ssh config is checked for defaults.
Parameters
----------
lport : int
local port for connecting to the tunnel from this machine.
rport : int
port on the remote machine to connect to.
server : str
The ssh server to connect to. The full ssh server string will be parsed.
user@server:port
remoteip : str [Default: 127.0.0.1]
The remote ip, specifying the destination of the tunnel.
Default is localhost, which means that the tunnel would redirect
localhost:lport on this machine to localhost:rport on the *server*.
keyfile : str; path to public key file
This specifies a key to be used in ssh login, default None.
Regular default ssh keys will be used without specifying this argument.
password : str;
Your ssh password to the ssh server. Note that if this is left None,
you will be prompted for it if passwordless key based login is unavailable.
timeout : int [default: 60]
The time (in seconds) after which no activity will result in the tunnel
closing. This prevents orphaned tunnels from running forever.
"""
if pexpect is None:
raise ImportError("pexpect unavailable, use paramiko_tunnel")
ssh="ssh "
if keyfile:
ssh += "-i " + keyfile
if ':' in server:
server, port = server.split(':')
ssh += " -p %s" % port
cmd = "%s -f -L 127.0.0.1:%i:%s:%i %s sleep %i" % (
ssh, lport, remoteip, rport, server, timeout)
tunnel = pexpect.spawn(cmd)
failed = False
while True:
try:
tunnel.expect('[Pp]assword:', timeout=.1)
except pexpect.TIMEOUT:
continue
except pexpect.EOF:
if tunnel.exitstatus:
print (tunnel.exitstatus)
print (tunnel.before)
print (tunnel.after)
raise RuntimeError("tunnel '%s' failed to start"%(cmd))
else:
return tunnel.pid
else:
if failed:
print("Password rejected, try again")
password=None
if password is None:
password = getpass("%s's password: "%(server))
tunnel.sendline(password)
failed = True | [
"Create",
"an",
"ssh",
"tunnel",
"using",
"command",
"-",
"line",
"ssh",
"that",
"connects",
"port",
"lport",
"on",
"this",
"machine",
"to",
"localhost",
":",
"rport",
"on",
"server",
".",
"The",
"tunnel",
"will",
"automatically",
"close",
"when",
"not",
"in",
"use",
"remaining",
"open",
"for",
"a",
"minimum",
"of",
"timeout",
"seconds",
"for",
"an",
"initial",
"connection",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/external/ssh/tunnel.py#L170-L240 | [
"def",
"openssh_tunnel",
"(",
"lport",
",",
"rport",
",",
"server",
",",
"remoteip",
"=",
"'127.0.0.1'",
",",
"keyfile",
"=",
"None",
",",
"password",
"=",
"None",
",",
"timeout",
"=",
"60",
")",
":",
"if",
"pexpect",
"is",
"None",
":",
"raise",
"ImportError",
"(",
"\"pexpect unavailable, use paramiko_tunnel\"",
")",
"ssh",
"=",
"\"ssh \"",
"if",
"keyfile",
":",
"ssh",
"+=",
"\"-i \"",
"+",
"keyfile",
"if",
"':'",
"in",
"server",
":",
"server",
",",
"port",
"=",
"server",
".",
"split",
"(",
"':'",
")",
"ssh",
"+=",
"\" -p %s\"",
"%",
"port",
"cmd",
"=",
"\"%s -f -L 127.0.0.1:%i:%s:%i %s sleep %i\"",
"%",
"(",
"ssh",
",",
"lport",
",",
"remoteip",
",",
"rport",
",",
"server",
",",
"timeout",
")",
"tunnel",
"=",
"pexpect",
".",
"spawn",
"(",
"cmd",
")",
"failed",
"=",
"False",
"while",
"True",
":",
"try",
":",
"tunnel",
".",
"expect",
"(",
"'[Pp]assword:'",
",",
"timeout",
"=",
".1",
")",
"except",
"pexpect",
".",
"TIMEOUT",
":",
"continue",
"except",
"pexpect",
".",
"EOF",
":",
"if",
"tunnel",
".",
"exitstatus",
":",
"print",
"(",
"tunnel",
".",
"exitstatus",
")",
"print",
"(",
"tunnel",
".",
"before",
")",
"print",
"(",
"tunnel",
".",
"after",
")",
"raise",
"RuntimeError",
"(",
"\"tunnel '%s' failed to start\"",
"%",
"(",
"cmd",
")",
")",
"else",
":",
"return",
"tunnel",
".",
"pid",
"else",
":",
"if",
"failed",
":",
"print",
"(",
"\"Password rejected, try again\"",
")",
"password",
"=",
"None",
"if",
"password",
"is",
"None",
":",
"password",
"=",
"getpass",
"(",
"\"%s's password: \"",
"%",
"(",
"server",
")",
")",
"tunnel",
".",
"sendline",
"(",
"password",
")",
"failed",
"=",
"True"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | paramiko_tunnel | launch a tunner with paramiko in a subprocess. This should only be used
when shell ssh is unavailable (e.g. Windows).
This creates a tunnel redirecting `localhost:lport` to `remoteip:rport`,
as seen from `server`.
If you are familiar with ssh tunnels, this creates the tunnel:
ssh server -L localhost:lport:remoteip:rport
keyfile and password may be specified, but ssh config is checked for defaults.
Parameters
----------
lport : int
local port for connecting to the tunnel from this machine.
rport : int
port on the remote machine to connect to.
server : str
The ssh server to connect to. The full ssh server string will be parsed.
user@server:port
remoteip : str [Default: 127.0.0.1]
The remote ip, specifying the destination of the tunnel.
Default is localhost, which means that the tunnel would redirect
localhost:lport on this machine to localhost:rport on the *server*.
keyfile : str; path to public key file
This specifies a key to be used in ssh login, default None.
Regular default ssh keys will be used without specifying this argument.
password : str;
Your ssh password to the ssh server. Note that if this is left None,
you will be prompted for it if passwordless key based login is unavailable.
timeout : int [default: 60]
The time (in seconds) after which no activity will result in the tunnel
closing. This prevents orphaned tunnels from running forever. | environment/lib/python2.7/site-packages/IPython/external/ssh/tunnel.py | def paramiko_tunnel(lport, rport, server, remoteip='127.0.0.1', keyfile=None, password=None, timeout=60):
"""launch a tunner with paramiko in a subprocess. This should only be used
when shell ssh is unavailable (e.g. Windows).
This creates a tunnel redirecting `localhost:lport` to `remoteip:rport`,
as seen from `server`.
If you are familiar with ssh tunnels, this creates the tunnel:
ssh server -L localhost:lport:remoteip:rport
keyfile and password may be specified, but ssh config is checked for defaults.
Parameters
----------
lport : int
local port for connecting to the tunnel from this machine.
rport : int
port on the remote machine to connect to.
server : str
The ssh server to connect to. The full ssh server string will be parsed.
user@server:port
remoteip : str [Default: 127.0.0.1]
The remote ip, specifying the destination of the tunnel.
Default is localhost, which means that the tunnel would redirect
localhost:lport on this machine to localhost:rport on the *server*.
keyfile : str; path to public key file
This specifies a key to be used in ssh login, default None.
Regular default ssh keys will be used without specifying this argument.
password : str;
Your ssh password to the ssh server. Note that if this is left None,
you will be prompted for it if passwordless key based login is unavailable.
timeout : int [default: 60]
The time (in seconds) after which no activity will result in the tunnel
closing. This prevents orphaned tunnels from running forever.
"""
if paramiko is None:
raise ImportError("Paramiko not available")
if password is None:
if not _try_passwordless_paramiko(server, keyfile):
password = getpass("%s's password: "%(server))
p = Process(target=_paramiko_tunnel,
args=(lport, rport, server, remoteip),
kwargs=dict(keyfile=keyfile, password=password))
p.daemon=False
p.start()
atexit.register(_shutdown_process, p)
return p | def paramiko_tunnel(lport, rport, server, remoteip='127.0.0.1', keyfile=None, password=None, timeout=60):
"""launch a tunner with paramiko in a subprocess. This should only be used
when shell ssh is unavailable (e.g. Windows).
This creates a tunnel redirecting `localhost:lport` to `remoteip:rport`,
as seen from `server`.
If you are familiar with ssh tunnels, this creates the tunnel:
ssh server -L localhost:lport:remoteip:rport
keyfile and password may be specified, but ssh config is checked for defaults.
Parameters
----------
lport : int
local port for connecting to the tunnel from this machine.
rport : int
port on the remote machine to connect to.
server : str
The ssh server to connect to. The full ssh server string will be parsed.
user@server:port
remoteip : str [Default: 127.0.0.1]
The remote ip, specifying the destination of the tunnel.
Default is localhost, which means that the tunnel would redirect
localhost:lport on this machine to localhost:rport on the *server*.
keyfile : str; path to public key file
This specifies a key to be used in ssh login, default None.
Regular default ssh keys will be used without specifying this argument.
password : str;
Your ssh password to the ssh server. Note that if this is left None,
you will be prompted for it if passwordless key based login is unavailable.
timeout : int [default: 60]
The time (in seconds) after which no activity will result in the tunnel
closing. This prevents orphaned tunnels from running forever.
"""
if paramiko is None:
raise ImportError("Paramiko not available")
if password is None:
if not _try_passwordless_paramiko(server, keyfile):
password = getpass("%s's password: "%(server))
p = Process(target=_paramiko_tunnel,
args=(lport, rport, server, remoteip),
kwargs=dict(keyfile=keyfile, password=password))
p.daemon=False
p.start()
atexit.register(_shutdown_process, p)
return p | [
"launch",
"a",
"tunner",
"with",
"paramiko",
"in",
"a",
"subprocess",
".",
"This",
"should",
"only",
"be",
"used",
"when",
"shell",
"ssh",
"is",
"unavailable",
"(",
"e",
".",
"g",
".",
"Windows",
")",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/external/ssh/tunnel.py#L254-L307 | [
"def",
"paramiko_tunnel",
"(",
"lport",
",",
"rport",
",",
"server",
",",
"remoteip",
"=",
"'127.0.0.1'",
",",
"keyfile",
"=",
"None",
",",
"password",
"=",
"None",
",",
"timeout",
"=",
"60",
")",
":",
"if",
"paramiko",
"is",
"None",
":",
"raise",
"ImportError",
"(",
"\"Paramiko not available\"",
")",
"if",
"password",
"is",
"None",
":",
"if",
"not",
"_try_passwordless_paramiko",
"(",
"server",
",",
"keyfile",
")",
":",
"password",
"=",
"getpass",
"(",
"\"%s's password: \"",
"%",
"(",
"server",
")",
")",
"p",
"=",
"Process",
"(",
"target",
"=",
"_paramiko_tunnel",
",",
"args",
"=",
"(",
"lport",
",",
"rport",
",",
"server",
",",
"remoteip",
")",
",",
"kwargs",
"=",
"dict",
"(",
"keyfile",
"=",
"keyfile",
",",
"password",
"=",
"password",
")",
")",
"p",
".",
"daemon",
"=",
"False",
"p",
".",
"start",
"(",
")",
"atexit",
".",
"register",
"(",
"_shutdown_process",
",",
"p",
")",
"return",
"p"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | _paramiko_tunnel | Function for actually starting a paramiko tunnel, to be passed
to multiprocessing.Process(target=this), and not called directly. | environment/lib/python2.7/site-packages/IPython/external/ssh/tunnel.py | def _paramiko_tunnel(lport, rport, server, remoteip, keyfile=None, password=None):
"""Function for actually starting a paramiko tunnel, to be passed
to multiprocessing.Process(target=this), and not called directly.
"""
username, server, port = _split_server(server)
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
try:
client.connect(server, port, username=username, key_filename=keyfile,
look_for_keys=True, password=password)
# except paramiko.AuthenticationException:
# if password is None:
# password = getpass("%s@%s's password: "%(username, server))
# client.connect(server, port, username=username, password=password)
# else:
# raise
except Exception as e:
print ('*** Failed to connect to %s:%d: %r' % (server, port, e))
sys.exit(1)
# print ('Now forwarding port %d to %s:%d ...' % (lport, server, rport))
try:
forward_tunnel(lport, remoteip, rport, client.get_transport())
except KeyboardInterrupt:
print ('SIGINT: Port forwarding stopped cleanly')
sys.exit(0)
except Exception as e:
print ("Port forwarding stopped uncleanly: %s"%e)
sys.exit(255) | def _paramiko_tunnel(lport, rport, server, remoteip, keyfile=None, password=None):
"""Function for actually starting a paramiko tunnel, to be passed
to multiprocessing.Process(target=this), and not called directly.
"""
username, server, port = _split_server(server)
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
try:
client.connect(server, port, username=username, key_filename=keyfile,
look_for_keys=True, password=password)
# except paramiko.AuthenticationException:
# if password is None:
# password = getpass("%s@%s's password: "%(username, server))
# client.connect(server, port, username=username, password=password)
# else:
# raise
except Exception as e:
print ('*** Failed to connect to %s:%d: %r' % (server, port, e))
sys.exit(1)
# print ('Now forwarding port %d to %s:%d ...' % (lport, server, rport))
try:
forward_tunnel(lport, remoteip, rport, client.get_transport())
except KeyboardInterrupt:
print ('SIGINT: Port forwarding stopped cleanly')
sys.exit(0)
except Exception as e:
print ("Port forwarding stopped uncleanly: %s"%e)
sys.exit(255) | [
"Function",
"for",
"actually",
"starting",
"a",
"paramiko",
"tunnel",
"to",
"be",
"passed",
"to",
"multiprocessing",
".",
"Process",
"(",
"target",
"=",
"this",
")",
"and",
"not",
"called",
"directly",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/external/ssh/tunnel.py#L313-L344 | [
"def",
"_paramiko_tunnel",
"(",
"lport",
",",
"rport",
",",
"server",
",",
"remoteip",
",",
"keyfile",
"=",
"None",
",",
"password",
"=",
"None",
")",
":",
"username",
",",
"server",
",",
"port",
"=",
"_split_server",
"(",
"server",
")",
"client",
"=",
"paramiko",
".",
"SSHClient",
"(",
")",
"client",
".",
"load_system_host_keys",
"(",
")",
"client",
".",
"set_missing_host_key_policy",
"(",
"paramiko",
".",
"WarningPolicy",
"(",
")",
")",
"try",
":",
"client",
".",
"connect",
"(",
"server",
",",
"port",
",",
"username",
"=",
"username",
",",
"key_filename",
"=",
"keyfile",
",",
"look_for_keys",
"=",
"True",
",",
"password",
"=",
"password",
")",
"# except paramiko.AuthenticationException:",
"# if password is None:",
"# password = getpass(\"%s@%s's password: \"%(username, server))",
"# client.connect(server, port, username=username, password=password)",
"# else:",
"# raise",
"except",
"Exception",
"as",
"e",
":",
"print",
"(",
"'*** Failed to connect to %s:%d: %r'",
"%",
"(",
"server",
",",
"port",
",",
"e",
")",
")",
"sys",
".",
"exit",
"(",
"1",
")",
"# print ('Now forwarding port %d to %s:%d ...' % (lport, server, rport))",
"try",
":",
"forward_tunnel",
"(",
"lport",
",",
"remoteip",
",",
"rport",
",",
"client",
".",
"get_transport",
"(",
")",
")",
"except",
"KeyboardInterrupt",
":",
"print",
"(",
"'SIGINT: Port forwarding stopped cleanly'",
")",
"sys",
".",
"exit",
"(",
"0",
")",
"except",
"Exception",
"as",
"e",
":",
"print",
"(",
"\"Port forwarding stopped uncleanly: %s\"",
"%",
"e",
")",
"sys",
".",
"exit",
"(",
"255",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | spin_first | Call spin() to sync state prior to calling the method. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def spin_first(f, self, *args, **kwargs):
"""Call spin() to sync state prior to calling the method."""
self.spin()
return f(self, *args, **kwargs) | def spin_first(f, self, *args, **kwargs):
"""Call spin() to sync state prior to calling the method."""
self.spin()
return f(self, *args, **kwargs) | [
"Call",
"spin",
"()",
"to",
"sync",
"state",
"prior",
"to",
"calling",
"the",
"method",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L66-L69 | [
"def",
"spin_first",
"(",
"f",
",",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"spin",
"(",
")",
"return",
"f",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client._update_engines | Update our engines dict and _ids from a dict of the form: {id:uuid}. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def _update_engines(self, engines):
"""Update our engines dict and _ids from a dict of the form: {id:uuid}."""
for k,v in engines.iteritems():
eid = int(k)
self._engines[eid] = v
self._ids.append(eid)
self._ids = sorted(self._ids)
if sorted(self._engines.keys()) != range(len(self._engines)) and \
self._task_scheme == 'pure' and self._task_socket:
self._stop_scheduling_tasks() | def _update_engines(self, engines):
"""Update our engines dict and _ids from a dict of the form: {id:uuid}."""
for k,v in engines.iteritems():
eid = int(k)
self._engines[eid] = v
self._ids.append(eid)
self._ids = sorted(self._ids)
if sorted(self._engines.keys()) != range(len(self._engines)) and \
self._task_scheme == 'pure' and self._task_socket:
self._stop_scheduling_tasks() | [
"Update",
"our",
"engines",
"dict",
"and",
"_ids",
"from",
"a",
"dict",
"of",
"the",
"form",
":",
"{",
"id",
":",
"uuid",
"}",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L519-L528 | [
"def",
"_update_engines",
"(",
"self",
",",
"engines",
")",
":",
"for",
"k",
",",
"v",
"in",
"engines",
".",
"iteritems",
"(",
")",
":",
"eid",
"=",
"int",
"(",
"k",
")",
"self",
".",
"_engines",
"[",
"eid",
"]",
"=",
"v",
"self",
".",
"_ids",
".",
"append",
"(",
"eid",
")",
"self",
".",
"_ids",
"=",
"sorted",
"(",
"self",
".",
"_ids",
")",
"if",
"sorted",
"(",
"self",
".",
"_engines",
".",
"keys",
"(",
")",
")",
"!=",
"range",
"(",
"len",
"(",
"self",
".",
"_engines",
")",
")",
"and",
"self",
".",
"_task_scheme",
"==",
"'pure'",
"and",
"self",
".",
"_task_socket",
":",
"self",
".",
"_stop_scheduling_tasks",
"(",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client._stop_scheduling_tasks | Stop scheduling tasks because an engine has been unregistered
from a pure ZMQ scheduler. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def _stop_scheduling_tasks(self):
"""Stop scheduling tasks because an engine has been unregistered
from a pure ZMQ scheduler.
"""
self._task_socket.close()
self._task_socket = None
msg = "An engine has been unregistered, and we are using pure " +\
"ZMQ task scheduling. Task farming will be disabled."
if self.outstanding:
msg += " If you were running tasks when this happened, " +\
"some `outstanding` msg_ids may never resolve."
warnings.warn(msg, RuntimeWarning) | def _stop_scheduling_tasks(self):
"""Stop scheduling tasks because an engine has been unregistered
from a pure ZMQ scheduler.
"""
self._task_socket.close()
self._task_socket = None
msg = "An engine has been unregistered, and we are using pure " +\
"ZMQ task scheduling. Task farming will be disabled."
if self.outstanding:
msg += " If you were running tasks when this happened, " +\
"some `outstanding` msg_ids may never resolve."
warnings.warn(msg, RuntimeWarning) | [
"Stop",
"scheduling",
"tasks",
"because",
"an",
"engine",
"has",
"been",
"unregistered",
"from",
"a",
"pure",
"ZMQ",
"scheduler",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L530-L541 | [
"def",
"_stop_scheduling_tasks",
"(",
"self",
")",
":",
"self",
".",
"_task_socket",
".",
"close",
"(",
")",
"self",
".",
"_task_socket",
"=",
"None",
"msg",
"=",
"\"An engine has been unregistered, and we are using pure \"",
"+",
"\"ZMQ task scheduling. Task farming will be disabled.\"",
"if",
"self",
".",
"outstanding",
":",
"msg",
"+=",
"\" If you were running tasks when this happened, \"",
"+",
"\"some `outstanding` msg_ids may never resolve.\"",
"warnings",
".",
"warn",
"(",
"msg",
",",
"RuntimeWarning",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client._build_targets | Turn valid target IDs or 'all' into two lists:
(int_ids, uuids). | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def _build_targets(self, targets):
"""Turn valid target IDs or 'all' into two lists:
(int_ids, uuids).
"""
if not self._ids:
# flush notification socket if no engines yet, just in case
if not self.ids:
raise error.NoEnginesRegistered("Can't build targets without any engines")
if targets is None:
targets = self._ids
elif isinstance(targets, basestring):
if targets.lower() == 'all':
targets = self._ids
else:
raise TypeError("%r not valid str target, must be 'all'"%(targets))
elif isinstance(targets, int):
if targets < 0:
targets = self.ids[targets]
if targets not in self._ids:
raise IndexError("No such engine: %i"%targets)
targets = [targets]
if isinstance(targets, slice):
indices = range(len(self._ids))[targets]
ids = self.ids
targets = [ ids[i] for i in indices ]
if not isinstance(targets, (tuple, list, xrange)):
raise TypeError("targets by int/slice/collection of ints only, not %s"%(type(targets)))
return [cast_bytes(self._engines[t]) for t in targets], list(targets) | def _build_targets(self, targets):
"""Turn valid target IDs or 'all' into two lists:
(int_ids, uuids).
"""
if not self._ids:
# flush notification socket if no engines yet, just in case
if not self.ids:
raise error.NoEnginesRegistered("Can't build targets without any engines")
if targets is None:
targets = self._ids
elif isinstance(targets, basestring):
if targets.lower() == 'all':
targets = self._ids
else:
raise TypeError("%r not valid str target, must be 'all'"%(targets))
elif isinstance(targets, int):
if targets < 0:
targets = self.ids[targets]
if targets not in self._ids:
raise IndexError("No such engine: %i"%targets)
targets = [targets]
if isinstance(targets, slice):
indices = range(len(self._ids))[targets]
ids = self.ids
targets = [ ids[i] for i in indices ]
if not isinstance(targets, (tuple, list, xrange)):
raise TypeError("targets by int/slice/collection of ints only, not %s"%(type(targets)))
return [cast_bytes(self._engines[t]) for t in targets], list(targets) | [
"Turn",
"valid",
"target",
"IDs",
"or",
"all",
"into",
"two",
"lists",
":",
"(",
"int_ids",
"uuids",
")",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L543-L574 | [
"def",
"_build_targets",
"(",
"self",
",",
"targets",
")",
":",
"if",
"not",
"self",
".",
"_ids",
":",
"# flush notification socket if no engines yet, just in case",
"if",
"not",
"self",
".",
"ids",
":",
"raise",
"error",
".",
"NoEnginesRegistered",
"(",
"\"Can't build targets without any engines\"",
")",
"if",
"targets",
"is",
"None",
":",
"targets",
"=",
"self",
".",
"_ids",
"elif",
"isinstance",
"(",
"targets",
",",
"basestring",
")",
":",
"if",
"targets",
".",
"lower",
"(",
")",
"==",
"'all'",
":",
"targets",
"=",
"self",
".",
"_ids",
"else",
":",
"raise",
"TypeError",
"(",
"\"%r not valid str target, must be 'all'\"",
"%",
"(",
"targets",
")",
")",
"elif",
"isinstance",
"(",
"targets",
",",
"int",
")",
":",
"if",
"targets",
"<",
"0",
":",
"targets",
"=",
"self",
".",
"ids",
"[",
"targets",
"]",
"if",
"targets",
"not",
"in",
"self",
".",
"_ids",
":",
"raise",
"IndexError",
"(",
"\"No such engine: %i\"",
"%",
"targets",
")",
"targets",
"=",
"[",
"targets",
"]",
"if",
"isinstance",
"(",
"targets",
",",
"slice",
")",
":",
"indices",
"=",
"range",
"(",
"len",
"(",
"self",
".",
"_ids",
")",
")",
"[",
"targets",
"]",
"ids",
"=",
"self",
".",
"ids",
"targets",
"=",
"[",
"ids",
"[",
"i",
"]",
"for",
"i",
"in",
"indices",
"]",
"if",
"not",
"isinstance",
"(",
"targets",
",",
"(",
"tuple",
",",
"list",
",",
"xrange",
")",
")",
":",
"raise",
"TypeError",
"(",
"\"targets by int/slice/collection of ints only, not %s\"",
"%",
"(",
"type",
"(",
"targets",
")",
")",
")",
"return",
"[",
"cast_bytes",
"(",
"self",
".",
"_engines",
"[",
"t",
"]",
")",
"for",
"t",
"in",
"targets",
"]",
",",
"list",
"(",
"targets",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client._connect | setup all our socket connections to the cluster. This is called from
__init__. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def _connect(self, sshserver, ssh_kwargs, timeout):
"""setup all our socket connections to the cluster. This is called from
__init__."""
# Maybe allow reconnecting?
if self._connected:
return
self._connected=True
def connect_socket(s, url):
url = util.disambiguate_url(url, self._config['location'])
if self._ssh:
return tunnel.tunnel_connection(s, url, sshserver, **ssh_kwargs)
else:
return s.connect(url)
self.session.send(self._query_socket, 'connection_request')
# use Poller because zmq.select has wrong units in pyzmq 2.1.7
poller = zmq.Poller()
poller.register(self._query_socket, zmq.POLLIN)
# poll expects milliseconds, timeout is seconds
evts = poller.poll(timeout*1000)
if not evts:
raise error.TimeoutError("Hub connection request timed out")
idents,msg = self.session.recv(self._query_socket,mode=0)
if self.debug:
pprint(msg)
msg = Message(msg)
content = msg.content
self._config['registration'] = dict(content)
if content.status == 'ok':
ident = self.session.bsession
if content.mux:
self._mux_socket = self._context.socket(zmq.DEALER)
self._mux_socket.setsockopt(zmq.IDENTITY, ident)
connect_socket(self._mux_socket, content.mux)
if content.task:
self._task_scheme, task_addr = content.task
self._task_socket = self._context.socket(zmq.DEALER)
self._task_socket.setsockopt(zmq.IDENTITY, ident)
connect_socket(self._task_socket, task_addr)
if content.notification:
self._notification_socket = self._context.socket(zmq.SUB)
connect_socket(self._notification_socket, content.notification)
self._notification_socket.setsockopt(zmq.SUBSCRIBE, b'')
# if content.query:
# self._query_socket = self._context.socket(zmq.DEALER)
# self._query_socket.setsockopt(zmq.IDENTITY, self.session.bsession)
# connect_socket(self._query_socket, content.query)
if content.control:
self._control_socket = self._context.socket(zmq.DEALER)
self._control_socket.setsockopt(zmq.IDENTITY, ident)
connect_socket(self._control_socket, content.control)
if content.iopub:
self._iopub_socket = self._context.socket(zmq.SUB)
self._iopub_socket.setsockopt(zmq.SUBSCRIBE, b'')
self._iopub_socket.setsockopt(zmq.IDENTITY, ident)
connect_socket(self._iopub_socket, content.iopub)
self._update_engines(dict(content.engines))
else:
self._connected = False
raise Exception("Failed to connect!") | def _connect(self, sshserver, ssh_kwargs, timeout):
"""setup all our socket connections to the cluster. This is called from
__init__."""
# Maybe allow reconnecting?
if self._connected:
return
self._connected=True
def connect_socket(s, url):
url = util.disambiguate_url(url, self._config['location'])
if self._ssh:
return tunnel.tunnel_connection(s, url, sshserver, **ssh_kwargs)
else:
return s.connect(url)
self.session.send(self._query_socket, 'connection_request')
# use Poller because zmq.select has wrong units in pyzmq 2.1.7
poller = zmq.Poller()
poller.register(self._query_socket, zmq.POLLIN)
# poll expects milliseconds, timeout is seconds
evts = poller.poll(timeout*1000)
if not evts:
raise error.TimeoutError("Hub connection request timed out")
idents,msg = self.session.recv(self._query_socket,mode=0)
if self.debug:
pprint(msg)
msg = Message(msg)
content = msg.content
self._config['registration'] = dict(content)
if content.status == 'ok':
ident = self.session.bsession
if content.mux:
self._mux_socket = self._context.socket(zmq.DEALER)
self._mux_socket.setsockopt(zmq.IDENTITY, ident)
connect_socket(self._mux_socket, content.mux)
if content.task:
self._task_scheme, task_addr = content.task
self._task_socket = self._context.socket(zmq.DEALER)
self._task_socket.setsockopt(zmq.IDENTITY, ident)
connect_socket(self._task_socket, task_addr)
if content.notification:
self._notification_socket = self._context.socket(zmq.SUB)
connect_socket(self._notification_socket, content.notification)
self._notification_socket.setsockopt(zmq.SUBSCRIBE, b'')
# if content.query:
# self._query_socket = self._context.socket(zmq.DEALER)
# self._query_socket.setsockopt(zmq.IDENTITY, self.session.bsession)
# connect_socket(self._query_socket, content.query)
if content.control:
self._control_socket = self._context.socket(zmq.DEALER)
self._control_socket.setsockopt(zmq.IDENTITY, ident)
connect_socket(self._control_socket, content.control)
if content.iopub:
self._iopub_socket = self._context.socket(zmq.SUB)
self._iopub_socket.setsockopt(zmq.SUBSCRIBE, b'')
self._iopub_socket.setsockopt(zmq.IDENTITY, ident)
connect_socket(self._iopub_socket, content.iopub)
self._update_engines(dict(content.engines))
else:
self._connected = False
raise Exception("Failed to connect!") | [
"setup",
"all",
"our",
"socket",
"connections",
"to",
"the",
"cluster",
".",
"This",
"is",
"called",
"from",
"__init__",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L576-L637 | [
"def",
"_connect",
"(",
"self",
",",
"sshserver",
",",
"ssh_kwargs",
",",
"timeout",
")",
":",
"# Maybe allow reconnecting?",
"if",
"self",
".",
"_connected",
":",
"return",
"self",
".",
"_connected",
"=",
"True",
"def",
"connect_socket",
"(",
"s",
",",
"url",
")",
":",
"url",
"=",
"util",
".",
"disambiguate_url",
"(",
"url",
",",
"self",
".",
"_config",
"[",
"'location'",
"]",
")",
"if",
"self",
".",
"_ssh",
":",
"return",
"tunnel",
".",
"tunnel_connection",
"(",
"s",
",",
"url",
",",
"sshserver",
",",
"*",
"*",
"ssh_kwargs",
")",
"else",
":",
"return",
"s",
".",
"connect",
"(",
"url",
")",
"self",
".",
"session",
".",
"send",
"(",
"self",
".",
"_query_socket",
",",
"'connection_request'",
")",
"# use Poller because zmq.select has wrong units in pyzmq 2.1.7",
"poller",
"=",
"zmq",
".",
"Poller",
"(",
")",
"poller",
".",
"register",
"(",
"self",
".",
"_query_socket",
",",
"zmq",
".",
"POLLIN",
")",
"# poll expects milliseconds, timeout is seconds",
"evts",
"=",
"poller",
".",
"poll",
"(",
"timeout",
"*",
"1000",
")",
"if",
"not",
"evts",
":",
"raise",
"error",
".",
"TimeoutError",
"(",
"\"Hub connection request timed out\"",
")",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"self",
".",
"_query_socket",
",",
"mode",
"=",
"0",
")",
"if",
"self",
".",
"debug",
":",
"pprint",
"(",
"msg",
")",
"msg",
"=",
"Message",
"(",
"msg",
")",
"content",
"=",
"msg",
".",
"content",
"self",
".",
"_config",
"[",
"'registration'",
"]",
"=",
"dict",
"(",
"content",
")",
"if",
"content",
".",
"status",
"==",
"'ok'",
":",
"ident",
"=",
"self",
".",
"session",
".",
"bsession",
"if",
"content",
".",
"mux",
":",
"self",
".",
"_mux_socket",
"=",
"self",
".",
"_context",
".",
"socket",
"(",
"zmq",
".",
"DEALER",
")",
"self",
".",
"_mux_socket",
".",
"setsockopt",
"(",
"zmq",
".",
"IDENTITY",
",",
"ident",
")",
"connect_socket",
"(",
"self",
".",
"_mux_socket",
",",
"content",
".",
"mux",
")",
"if",
"content",
".",
"task",
":",
"self",
".",
"_task_scheme",
",",
"task_addr",
"=",
"content",
".",
"task",
"self",
".",
"_task_socket",
"=",
"self",
".",
"_context",
".",
"socket",
"(",
"zmq",
".",
"DEALER",
")",
"self",
".",
"_task_socket",
".",
"setsockopt",
"(",
"zmq",
".",
"IDENTITY",
",",
"ident",
")",
"connect_socket",
"(",
"self",
".",
"_task_socket",
",",
"task_addr",
")",
"if",
"content",
".",
"notification",
":",
"self",
".",
"_notification_socket",
"=",
"self",
".",
"_context",
".",
"socket",
"(",
"zmq",
".",
"SUB",
")",
"connect_socket",
"(",
"self",
".",
"_notification_socket",
",",
"content",
".",
"notification",
")",
"self",
".",
"_notification_socket",
".",
"setsockopt",
"(",
"zmq",
".",
"SUBSCRIBE",
",",
"b''",
")",
"# if content.query:",
"# self._query_socket = self._context.socket(zmq.DEALER)",
"# self._query_socket.setsockopt(zmq.IDENTITY, self.session.bsession)",
"# connect_socket(self._query_socket, content.query)",
"if",
"content",
".",
"control",
":",
"self",
".",
"_control_socket",
"=",
"self",
".",
"_context",
".",
"socket",
"(",
"zmq",
".",
"DEALER",
")",
"self",
".",
"_control_socket",
".",
"setsockopt",
"(",
"zmq",
".",
"IDENTITY",
",",
"ident",
")",
"connect_socket",
"(",
"self",
".",
"_control_socket",
",",
"content",
".",
"control",
")",
"if",
"content",
".",
"iopub",
":",
"self",
".",
"_iopub_socket",
"=",
"self",
".",
"_context",
".",
"socket",
"(",
"zmq",
".",
"SUB",
")",
"self",
".",
"_iopub_socket",
".",
"setsockopt",
"(",
"zmq",
".",
"SUBSCRIBE",
",",
"b''",
")",
"self",
".",
"_iopub_socket",
".",
"setsockopt",
"(",
"zmq",
".",
"IDENTITY",
",",
"ident",
")",
"connect_socket",
"(",
"self",
".",
"_iopub_socket",
",",
"content",
".",
"iopub",
")",
"self",
".",
"_update_engines",
"(",
"dict",
"(",
"content",
".",
"engines",
")",
")",
"else",
":",
"self",
".",
"_connected",
"=",
"False",
"raise",
"Exception",
"(",
"\"Failed to connect!\"",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client._unwrap_exception | unwrap exception, and remap engine_id to int. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def _unwrap_exception(self, content):
"""unwrap exception, and remap engine_id to int."""
e = error.unwrap_exception(content)
# print e.traceback
if e.engine_info:
e_uuid = e.engine_info['engine_uuid']
eid = self._engines[e_uuid]
e.engine_info['engine_id'] = eid
return e | def _unwrap_exception(self, content):
"""unwrap exception, and remap engine_id to int."""
e = error.unwrap_exception(content)
# print e.traceback
if e.engine_info:
e_uuid = e.engine_info['engine_uuid']
eid = self._engines[e_uuid]
e.engine_info['engine_id'] = eid
return e | [
"unwrap",
"exception",
"and",
"remap",
"engine_id",
"to",
"int",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L643-L651 | [
"def",
"_unwrap_exception",
"(",
"self",
",",
"content",
")",
":",
"e",
"=",
"error",
".",
"unwrap_exception",
"(",
"content",
")",
"# print e.traceback",
"if",
"e",
".",
"engine_info",
":",
"e_uuid",
"=",
"e",
".",
"engine_info",
"[",
"'engine_uuid'",
"]",
"eid",
"=",
"self",
".",
"_engines",
"[",
"e_uuid",
"]",
"e",
".",
"engine_info",
"[",
"'engine_id'",
"]",
"=",
"eid",
"return",
"e"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client._register_engine | Register a new engine, and update our connection info. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def _register_engine(self, msg):
"""Register a new engine, and update our connection info."""
content = msg['content']
eid = content['id']
d = {eid : content['queue']}
self._update_engines(d) | def _register_engine(self, msg):
"""Register a new engine, and update our connection info."""
content = msg['content']
eid = content['id']
d = {eid : content['queue']}
self._update_engines(d) | [
"Register",
"a",
"new",
"engine",
"and",
"update",
"our",
"connection",
"info",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L673-L678 | [
"def",
"_register_engine",
"(",
"self",
",",
"msg",
")",
":",
"content",
"=",
"msg",
"[",
"'content'",
"]",
"eid",
"=",
"content",
"[",
"'id'",
"]",
"d",
"=",
"{",
"eid",
":",
"content",
"[",
"'queue'",
"]",
"}",
"self",
".",
"_update_engines",
"(",
"d",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client._unregister_engine | Unregister an engine that has died. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def _unregister_engine(self, msg):
"""Unregister an engine that has died."""
content = msg['content']
eid = int(content['id'])
if eid in self._ids:
self._ids.remove(eid)
uuid = self._engines.pop(eid)
self._handle_stranded_msgs(eid, uuid)
if self._task_socket and self._task_scheme == 'pure':
self._stop_scheduling_tasks() | def _unregister_engine(self, msg):
"""Unregister an engine that has died."""
content = msg['content']
eid = int(content['id'])
if eid in self._ids:
self._ids.remove(eid)
uuid = self._engines.pop(eid)
self._handle_stranded_msgs(eid, uuid)
if self._task_socket and self._task_scheme == 'pure':
self._stop_scheduling_tasks() | [
"Unregister",
"an",
"engine",
"that",
"has",
"died",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L680-L691 | [
"def",
"_unregister_engine",
"(",
"self",
",",
"msg",
")",
":",
"content",
"=",
"msg",
"[",
"'content'",
"]",
"eid",
"=",
"int",
"(",
"content",
"[",
"'id'",
"]",
")",
"if",
"eid",
"in",
"self",
".",
"_ids",
":",
"self",
".",
"_ids",
".",
"remove",
"(",
"eid",
")",
"uuid",
"=",
"self",
".",
"_engines",
".",
"pop",
"(",
"eid",
")",
"self",
".",
"_handle_stranded_msgs",
"(",
"eid",
",",
"uuid",
")",
"if",
"self",
".",
"_task_socket",
"and",
"self",
".",
"_task_scheme",
"==",
"'pure'",
":",
"self",
".",
"_stop_scheduling_tasks",
"(",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client._handle_stranded_msgs | Handle messages known to be on an engine when the engine unregisters.
It is possible that this will fire prematurely - that is, an engine will
go down after completing a result, and the client will be notified
of the unregistration and later receive the successful result. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def _handle_stranded_msgs(self, eid, uuid):
"""Handle messages known to be on an engine when the engine unregisters.
It is possible that this will fire prematurely - that is, an engine will
go down after completing a result, and the client will be notified
of the unregistration and later receive the successful result.
"""
outstanding = self._outstanding_dict[uuid]
for msg_id in list(outstanding):
if msg_id in self.results:
# we already
continue
try:
raise error.EngineError("Engine %r died while running task %r"%(eid, msg_id))
except:
content = error.wrap_exception()
# build a fake message:
parent = {}
header = {}
parent['msg_id'] = msg_id
header['engine'] = uuid
header['date'] = datetime.now()
msg = dict(parent_header=parent, header=header, content=content)
self._handle_apply_reply(msg) | def _handle_stranded_msgs(self, eid, uuid):
"""Handle messages known to be on an engine when the engine unregisters.
It is possible that this will fire prematurely - that is, an engine will
go down after completing a result, and the client will be notified
of the unregistration and later receive the successful result.
"""
outstanding = self._outstanding_dict[uuid]
for msg_id in list(outstanding):
if msg_id in self.results:
# we already
continue
try:
raise error.EngineError("Engine %r died while running task %r"%(eid, msg_id))
except:
content = error.wrap_exception()
# build a fake message:
parent = {}
header = {}
parent['msg_id'] = msg_id
header['engine'] = uuid
header['date'] = datetime.now()
msg = dict(parent_header=parent, header=header, content=content)
self._handle_apply_reply(msg) | [
"Handle",
"messages",
"known",
"to",
"be",
"on",
"an",
"engine",
"when",
"the",
"engine",
"unregisters",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L693-L718 | [
"def",
"_handle_stranded_msgs",
"(",
"self",
",",
"eid",
",",
"uuid",
")",
":",
"outstanding",
"=",
"self",
".",
"_outstanding_dict",
"[",
"uuid",
"]",
"for",
"msg_id",
"in",
"list",
"(",
"outstanding",
")",
":",
"if",
"msg_id",
"in",
"self",
".",
"results",
":",
"# we already",
"continue",
"try",
":",
"raise",
"error",
".",
"EngineError",
"(",
"\"Engine %r died while running task %r\"",
"%",
"(",
"eid",
",",
"msg_id",
")",
")",
"except",
":",
"content",
"=",
"error",
".",
"wrap_exception",
"(",
")",
"# build a fake message:",
"parent",
"=",
"{",
"}",
"header",
"=",
"{",
"}",
"parent",
"[",
"'msg_id'",
"]",
"=",
"msg_id",
"header",
"[",
"'engine'",
"]",
"=",
"uuid",
"header",
"[",
"'date'",
"]",
"=",
"datetime",
".",
"now",
"(",
")",
"msg",
"=",
"dict",
"(",
"parent_header",
"=",
"parent",
",",
"header",
"=",
"header",
",",
"content",
"=",
"content",
")",
"self",
".",
"_handle_apply_reply",
"(",
"msg",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client._handle_execute_reply | Save the reply to an execute_request into our results.
execute messages are never actually used. apply is used instead. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def _handle_execute_reply(self, msg):
"""Save the reply to an execute_request into our results.
execute messages are never actually used. apply is used instead.
"""
parent = msg['parent_header']
msg_id = parent['msg_id']
if msg_id not in self.outstanding:
if msg_id in self.history:
print ("got stale result: %s"%msg_id)
else:
print ("got unknown result: %s"%msg_id)
else:
self.outstanding.remove(msg_id)
content = msg['content']
header = msg['header']
# construct metadata:
md = self.metadata[msg_id]
md.update(self._extract_metadata(header, parent, content))
# is this redundant?
self.metadata[msg_id] = md
e_outstanding = self._outstanding_dict[md['engine_uuid']]
if msg_id in e_outstanding:
e_outstanding.remove(msg_id)
# construct result:
if content['status'] == 'ok':
self.results[msg_id] = ExecuteReply(msg_id, content, md)
elif content['status'] == 'aborted':
self.results[msg_id] = error.TaskAborted(msg_id)
elif content['status'] == 'resubmitted':
# TODO: handle resubmission
pass
else:
self.results[msg_id] = self._unwrap_exception(content) | def _handle_execute_reply(self, msg):
"""Save the reply to an execute_request into our results.
execute messages are never actually used. apply is used instead.
"""
parent = msg['parent_header']
msg_id = parent['msg_id']
if msg_id not in self.outstanding:
if msg_id in self.history:
print ("got stale result: %s"%msg_id)
else:
print ("got unknown result: %s"%msg_id)
else:
self.outstanding.remove(msg_id)
content = msg['content']
header = msg['header']
# construct metadata:
md = self.metadata[msg_id]
md.update(self._extract_metadata(header, parent, content))
# is this redundant?
self.metadata[msg_id] = md
e_outstanding = self._outstanding_dict[md['engine_uuid']]
if msg_id in e_outstanding:
e_outstanding.remove(msg_id)
# construct result:
if content['status'] == 'ok':
self.results[msg_id] = ExecuteReply(msg_id, content, md)
elif content['status'] == 'aborted':
self.results[msg_id] = error.TaskAborted(msg_id)
elif content['status'] == 'resubmitted':
# TODO: handle resubmission
pass
else:
self.results[msg_id] = self._unwrap_exception(content) | [
"Save",
"the",
"reply",
"to",
"an",
"execute_request",
"into",
"our",
"results",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L720-L758 | [
"def",
"_handle_execute_reply",
"(",
"self",
",",
"msg",
")",
":",
"parent",
"=",
"msg",
"[",
"'parent_header'",
"]",
"msg_id",
"=",
"parent",
"[",
"'msg_id'",
"]",
"if",
"msg_id",
"not",
"in",
"self",
".",
"outstanding",
":",
"if",
"msg_id",
"in",
"self",
".",
"history",
":",
"print",
"(",
"\"got stale result: %s\"",
"%",
"msg_id",
")",
"else",
":",
"print",
"(",
"\"got unknown result: %s\"",
"%",
"msg_id",
")",
"else",
":",
"self",
".",
"outstanding",
".",
"remove",
"(",
"msg_id",
")",
"content",
"=",
"msg",
"[",
"'content'",
"]",
"header",
"=",
"msg",
"[",
"'header'",
"]",
"# construct metadata:",
"md",
"=",
"self",
".",
"metadata",
"[",
"msg_id",
"]",
"md",
".",
"update",
"(",
"self",
".",
"_extract_metadata",
"(",
"header",
",",
"parent",
",",
"content",
")",
")",
"# is this redundant?",
"self",
".",
"metadata",
"[",
"msg_id",
"]",
"=",
"md",
"e_outstanding",
"=",
"self",
".",
"_outstanding_dict",
"[",
"md",
"[",
"'engine_uuid'",
"]",
"]",
"if",
"msg_id",
"in",
"e_outstanding",
":",
"e_outstanding",
".",
"remove",
"(",
"msg_id",
")",
"# construct result:",
"if",
"content",
"[",
"'status'",
"]",
"==",
"'ok'",
":",
"self",
".",
"results",
"[",
"msg_id",
"]",
"=",
"ExecuteReply",
"(",
"msg_id",
",",
"content",
",",
"md",
")",
"elif",
"content",
"[",
"'status'",
"]",
"==",
"'aborted'",
":",
"self",
".",
"results",
"[",
"msg_id",
"]",
"=",
"error",
".",
"TaskAborted",
"(",
"msg_id",
")",
"elif",
"content",
"[",
"'status'",
"]",
"==",
"'resubmitted'",
":",
"# TODO: handle resubmission",
"pass",
"else",
":",
"self",
".",
"results",
"[",
"msg_id",
"]",
"=",
"self",
".",
"_unwrap_exception",
"(",
"content",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client._flush_notifications | Flush notifications of engine registrations waiting
in ZMQ queue. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def _flush_notifications(self):
"""Flush notifications of engine registrations waiting
in ZMQ queue."""
idents,msg = self.session.recv(self._notification_socket, mode=zmq.NOBLOCK)
while msg is not None:
if self.debug:
pprint(msg)
msg_type = msg['header']['msg_type']
handler = self._notification_handlers.get(msg_type, None)
if handler is None:
raise Exception("Unhandled message type: %s"%msg.msg_type)
else:
handler(msg)
idents,msg = self.session.recv(self._notification_socket, mode=zmq.NOBLOCK) | def _flush_notifications(self):
"""Flush notifications of engine registrations waiting
in ZMQ queue."""
idents,msg = self.session.recv(self._notification_socket, mode=zmq.NOBLOCK)
while msg is not None:
if self.debug:
pprint(msg)
msg_type = msg['header']['msg_type']
handler = self._notification_handlers.get(msg_type, None)
if handler is None:
raise Exception("Unhandled message type: %s"%msg.msg_type)
else:
handler(msg)
idents,msg = self.session.recv(self._notification_socket, mode=zmq.NOBLOCK) | [
"Flush",
"notifications",
"of",
"engine",
"registrations",
"waiting",
"in",
"ZMQ",
"queue",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L797-L810 | [
"def",
"_flush_notifications",
"(",
"self",
")",
":",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"self",
".",
"_notification_socket",
",",
"mode",
"=",
"zmq",
".",
"NOBLOCK",
")",
"while",
"msg",
"is",
"not",
"None",
":",
"if",
"self",
".",
"debug",
":",
"pprint",
"(",
"msg",
")",
"msg_type",
"=",
"msg",
"[",
"'header'",
"]",
"[",
"'msg_type'",
"]",
"handler",
"=",
"self",
".",
"_notification_handlers",
".",
"get",
"(",
"msg_type",
",",
"None",
")",
"if",
"handler",
"is",
"None",
":",
"raise",
"Exception",
"(",
"\"Unhandled message type: %s\"",
"%",
"msg",
".",
"msg_type",
")",
"else",
":",
"handler",
"(",
"msg",
")",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"self",
".",
"_notification_socket",
",",
"mode",
"=",
"zmq",
".",
"NOBLOCK",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client._flush_results | Flush task or queue results waiting in ZMQ queue. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def _flush_results(self, sock):
"""Flush task or queue results waiting in ZMQ queue."""
idents,msg = self.session.recv(sock, mode=zmq.NOBLOCK)
while msg is not None:
if self.debug:
pprint(msg)
msg_type = msg['header']['msg_type']
handler = self._queue_handlers.get(msg_type, None)
if handler is None:
raise Exception("Unhandled message type: %s"%msg.msg_type)
else:
handler(msg)
idents,msg = self.session.recv(sock, mode=zmq.NOBLOCK) | def _flush_results(self, sock):
"""Flush task or queue results waiting in ZMQ queue."""
idents,msg = self.session.recv(sock, mode=zmq.NOBLOCK)
while msg is not None:
if self.debug:
pprint(msg)
msg_type = msg['header']['msg_type']
handler = self._queue_handlers.get(msg_type, None)
if handler is None:
raise Exception("Unhandled message type: %s"%msg.msg_type)
else:
handler(msg)
idents,msg = self.session.recv(sock, mode=zmq.NOBLOCK) | [
"Flush",
"task",
"or",
"queue",
"results",
"waiting",
"in",
"ZMQ",
"queue",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L812-L824 | [
"def",
"_flush_results",
"(",
"self",
",",
"sock",
")",
":",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"sock",
",",
"mode",
"=",
"zmq",
".",
"NOBLOCK",
")",
"while",
"msg",
"is",
"not",
"None",
":",
"if",
"self",
".",
"debug",
":",
"pprint",
"(",
"msg",
")",
"msg_type",
"=",
"msg",
"[",
"'header'",
"]",
"[",
"'msg_type'",
"]",
"handler",
"=",
"self",
".",
"_queue_handlers",
".",
"get",
"(",
"msg_type",
",",
"None",
")",
"if",
"handler",
"is",
"None",
":",
"raise",
"Exception",
"(",
"\"Unhandled message type: %s\"",
"%",
"msg",
".",
"msg_type",
")",
"else",
":",
"handler",
"(",
"msg",
")",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"sock",
",",
"mode",
"=",
"zmq",
".",
"NOBLOCK",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client._flush_control | Flush replies from the control channel waiting
in the ZMQ queue.
Currently: ignore them. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def _flush_control(self, sock):
"""Flush replies from the control channel waiting
in the ZMQ queue.
Currently: ignore them."""
if self._ignored_control_replies <= 0:
return
idents,msg = self.session.recv(sock, mode=zmq.NOBLOCK)
while msg is not None:
self._ignored_control_replies -= 1
if self.debug:
pprint(msg)
idents,msg = self.session.recv(sock, mode=zmq.NOBLOCK) | def _flush_control(self, sock):
"""Flush replies from the control channel waiting
in the ZMQ queue.
Currently: ignore them."""
if self._ignored_control_replies <= 0:
return
idents,msg = self.session.recv(sock, mode=zmq.NOBLOCK)
while msg is not None:
self._ignored_control_replies -= 1
if self.debug:
pprint(msg)
idents,msg = self.session.recv(sock, mode=zmq.NOBLOCK) | [
"Flush",
"replies",
"from",
"the",
"control",
"channel",
"waiting",
"in",
"the",
"ZMQ",
"queue",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L826-L838 | [
"def",
"_flush_control",
"(",
"self",
",",
"sock",
")",
":",
"if",
"self",
".",
"_ignored_control_replies",
"<=",
"0",
":",
"return",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"sock",
",",
"mode",
"=",
"zmq",
".",
"NOBLOCK",
")",
"while",
"msg",
"is",
"not",
"None",
":",
"self",
".",
"_ignored_control_replies",
"-=",
"1",
"if",
"self",
".",
"debug",
":",
"pprint",
"(",
"msg",
")",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"sock",
",",
"mode",
"=",
"zmq",
".",
"NOBLOCK",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client._flush_ignored_control | flush ignored control replies | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def _flush_ignored_control(self):
"""flush ignored control replies"""
while self._ignored_control_replies > 0:
self.session.recv(self._control_socket)
self._ignored_control_replies -= 1 | def _flush_ignored_control(self):
"""flush ignored control replies"""
while self._ignored_control_replies > 0:
self.session.recv(self._control_socket)
self._ignored_control_replies -= 1 | [
"flush",
"ignored",
"control",
"replies"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L840-L844 | [
"def",
"_flush_ignored_control",
"(",
"self",
")",
":",
"while",
"self",
".",
"_ignored_control_replies",
">",
"0",
":",
"self",
".",
"session",
".",
"recv",
"(",
"self",
".",
"_control_socket",
")",
"self",
".",
"_ignored_control_replies",
"-=",
"1"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client._flush_iopub | Flush replies from the iopub channel waiting
in the ZMQ queue. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def _flush_iopub(self, sock):
"""Flush replies from the iopub channel waiting
in the ZMQ queue.
"""
idents,msg = self.session.recv(sock, mode=zmq.NOBLOCK)
while msg is not None:
if self.debug:
pprint(msg)
parent = msg['parent_header']
# ignore IOPub messages with no parent.
# Caused by print statements or warnings from before the first execution.
if not parent:
continue
msg_id = parent['msg_id']
content = msg['content']
header = msg['header']
msg_type = msg['header']['msg_type']
# init metadata:
md = self.metadata[msg_id]
if msg_type == 'stream':
name = content['name']
s = md[name] or ''
md[name] = s + content['data']
elif msg_type == 'pyerr':
md.update({'pyerr' : self._unwrap_exception(content)})
elif msg_type == 'pyin':
md.update({'pyin' : content['code']})
elif msg_type == 'display_data':
md['outputs'].append(content)
elif msg_type == 'pyout':
md['pyout'] = content
elif msg_type == 'status':
# idle message comes after all outputs
if content['execution_state'] == 'idle':
md['outputs_ready'] = True
else:
# unhandled msg_type (status, etc.)
pass
# reduntant?
self.metadata[msg_id] = md
idents,msg = self.session.recv(sock, mode=zmq.NOBLOCK) | def _flush_iopub(self, sock):
"""Flush replies from the iopub channel waiting
in the ZMQ queue.
"""
idents,msg = self.session.recv(sock, mode=zmq.NOBLOCK)
while msg is not None:
if self.debug:
pprint(msg)
parent = msg['parent_header']
# ignore IOPub messages with no parent.
# Caused by print statements or warnings from before the first execution.
if not parent:
continue
msg_id = parent['msg_id']
content = msg['content']
header = msg['header']
msg_type = msg['header']['msg_type']
# init metadata:
md = self.metadata[msg_id]
if msg_type == 'stream':
name = content['name']
s = md[name] or ''
md[name] = s + content['data']
elif msg_type == 'pyerr':
md.update({'pyerr' : self._unwrap_exception(content)})
elif msg_type == 'pyin':
md.update({'pyin' : content['code']})
elif msg_type == 'display_data':
md['outputs'].append(content)
elif msg_type == 'pyout':
md['pyout'] = content
elif msg_type == 'status':
# idle message comes after all outputs
if content['execution_state'] == 'idle':
md['outputs_ready'] = True
else:
# unhandled msg_type (status, etc.)
pass
# reduntant?
self.metadata[msg_id] = md
idents,msg = self.session.recv(sock, mode=zmq.NOBLOCK) | [
"Flush",
"replies",
"from",
"the",
"iopub",
"channel",
"waiting",
"in",
"the",
"ZMQ",
"queue",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L851-L895 | [
"def",
"_flush_iopub",
"(",
"self",
",",
"sock",
")",
":",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"sock",
",",
"mode",
"=",
"zmq",
".",
"NOBLOCK",
")",
"while",
"msg",
"is",
"not",
"None",
":",
"if",
"self",
".",
"debug",
":",
"pprint",
"(",
"msg",
")",
"parent",
"=",
"msg",
"[",
"'parent_header'",
"]",
"# ignore IOPub messages with no parent.",
"# Caused by print statements or warnings from before the first execution.",
"if",
"not",
"parent",
":",
"continue",
"msg_id",
"=",
"parent",
"[",
"'msg_id'",
"]",
"content",
"=",
"msg",
"[",
"'content'",
"]",
"header",
"=",
"msg",
"[",
"'header'",
"]",
"msg_type",
"=",
"msg",
"[",
"'header'",
"]",
"[",
"'msg_type'",
"]",
"# init metadata:",
"md",
"=",
"self",
".",
"metadata",
"[",
"msg_id",
"]",
"if",
"msg_type",
"==",
"'stream'",
":",
"name",
"=",
"content",
"[",
"'name'",
"]",
"s",
"=",
"md",
"[",
"name",
"]",
"or",
"''",
"md",
"[",
"name",
"]",
"=",
"s",
"+",
"content",
"[",
"'data'",
"]",
"elif",
"msg_type",
"==",
"'pyerr'",
":",
"md",
".",
"update",
"(",
"{",
"'pyerr'",
":",
"self",
".",
"_unwrap_exception",
"(",
"content",
")",
"}",
")",
"elif",
"msg_type",
"==",
"'pyin'",
":",
"md",
".",
"update",
"(",
"{",
"'pyin'",
":",
"content",
"[",
"'code'",
"]",
"}",
")",
"elif",
"msg_type",
"==",
"'display_data'",
":",
"md",
"[",
"'outputs'",
"]",
".",
"append",
"(",
"content",
")",
"elif",
"msg_type",
"==",
"'pyout'",
":",
"md",
"[",
"'pyout'",
"]",
"=",
"content",
"elif",
"msg_type",
"==",
"'status'",
":",
"# idle message comes after all outputs",
"if",
"content",
"[",
"'execution_state'",
"]",
"==",
"'idle'",
":",
"md",
"[",
"'outputs_ready'",
"]",
"=",
"True",
"else",
":",
"# unhandled msg_type (status, etc.)",
"pass",
"# reduntant?",
"self",
".",
"metadata",
"[",
"msg_id",
"]",
"=",
"md",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"sock",
",",
"mode",
"=",
"zmq",
".",
"NOBLOCK",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.activate | Create a DirectView and register it with IPython magics
Defines the magics `%px, %autopx, %pxresult, %%px`
Parameters
----------
targets: int, list of ints, or 'all'
The engines on which the view's magics will run
suffix: str [default: '']
The suffix, if any, for the magics. This allows you to have
multiple views associated with parallel magics at the same time.
e.g. ``rc.activate(targets=0, suffix='0')`` will give you
the magics ``%px0``, ``%pxresult0``, etc. for running magics just
on engine 0. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def activate(self, targets='all', suffix=''):
"""Create a DirectView and register it with IPython magics
Defines the magics `%px, %autopx, %pxresult, %%px`
Parameters
----------
targets: int, list of ints, or 'all'
The engines on which the view's magics will run
suffix: str [default: '']
The suffix, if any, for the magics. This allows you to have
multiple views associated with parallel magics at the same time.
e.g. ``rc.activate(targets=0, suffix='0')`` will give you
the magics ``%px0``, ``%pxresult0``, etc. for running magics just
on engine 0.
"""
view = self.direct_view(targets)
view.block = True
view.activate(suffix)
return view | def activate(self, targets='all', suffix=''):
"""Create a DirectView and register it with IPython magics
Defines the magics `%px, %autopx, %pxresult, %%px`
Parameters
----------
targets: int, list of ints, or 'all'
The engines on which the view's magics will run
suffix: str [default: '']
The suffix, if any, for the magics. This allows you to have
multiple views associated with parallel magics at the same time.
e.g. ``rc.activate(targets=0, suffix='0')`` will give you
the magics ``%px0``, ``%pxresult0``, etc. for running magics just
on engine 0.
"""
view = self.direct_view(targets)
view.block = True
view.activate(suffix)
return view | [
"Create",
"a",
"DirectView",
"and",
"register",
"it",
"with",
"IPython",
"magics",
"Defines",
"the",
"magics",
"%px",
"%autopx",
"%pxresult",
"%%px",
"Parameters",
"----------",
"targets",
":",
"int",
"list",
"of",
"ints",
"or",
"all",
"The",
"engines",
"on",
"which",
"the",
"view",
"s",
"magics",
"will",
"run",
"suffix",
":",
"str",
"[",
"default",
":",
"]",
"The",
"suffix",
"if",
"any",
"for",
"the",
"magics",
".",
"This",
"allows",
"you",
"to",
"have",
"multiple",
"views",
"associated",
"with",
"parallel",
"magics",
"at",
"the",
"same",
"time",
".",
"e",
".",
"g",
".",
"rc",
".",
"activate",
"(",
"targets",
"=",
"0",
"suffix",
"=",
"0",
")",
"will",
"give",
"you",
"the",
"magics",
"%px0",
"%pxresult0",
"etc",
".",
"for",
"running",
"magics",
"just",
"on",
"engine",
"0",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L925-L946 | [
"def",
"activate",
"(",
"self",
",",
"targets",
"=",
"'all'",
",",
"suffix",
"=",
"''",
")",
":",
"view",
"=",
"self",
".",
"direct_view",
"(",
"targets",
")",
"view",
".",
"block",
"=",
"True",
"view",
".",
"activate",
"(",
"suffix",
")",
"return",
"view"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client._spin_every | target func for use in spin_thread | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def _spin_every(self, interval=1):
"""target func for use in spin_thread"""
while True:
if self._stop_spinning.is_set():
return
time.sleep(interval)
self.spin() | def _spin_every(self, interval=1):
"""target func for use in spin_thread"""
while True:
if self._stop_spinning.is_set():
return
time.sleep(interval)
self.spin() | [
"target",
"func",
"for",
"use",
"in",
"spin_thread"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L958-L964 | [
"def",
"_spin_every",
"(",
"self",
",",
"interval",
"=",
"1",
")",
":",
"while",
"True",
":",
"if",
"self",
".",
"_stop_spinning",
".",
"is_set",
"(",
")",
":",
"return",
"time",
".",
"sleep",
"(",
"interval",
")",
"self",
".",
"spin",
"(",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.spin_thread | call Client.spin() in a background thread on some regular interval
This helps ensure that messages don't pile up too much in the zmq queue
while you are working on other things, or just leaving an idle terminal.
It also helps limit potential padding of the `received` timestamp
on AsyncResult objects, used for timings.
Parameters
----------
interval : float, optional
The interval on which to spin the client in the background thread
(simply passed to time.sleep).
Notes
-----
For precision timing, you may want to use this method to put a bound
on the jitter (in seconds) in `received` timestamps used
in AsyncResult.wall_time. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def spin_thread(self, interval=1):
"""call Client.spin() in a background thread on some regular interval
This helps ensure that messages don't pile up too much in the zmq queue
while you are working on other things, or just leaving an idle terminal.
It also helps limit potential padding of the `received` timestamp
on AsyncResult objects, used for timings.
Parameters
----------
interval : float, optional
The interval on which to spin the client in the background thread
(simply passed to time.sleep).
Notes
-----
For precision timing, you may want to use this method to put a bound
on the jitter (in seconds) in `received` timestamps used
in AsyncResult.wall_time.
"""
if self._spin_thread is not None:
self.stop_spin_thread()
self._stop_spinning.clear()
self._spin_thread = Thread(target=self._spin_every, args=(interval,))
self._spin_thread.daemon = True
self._spin_thread.start() | def spin_thread(self, interval=1):
"""call Client.spin() in a background thread on some regular interval
This helps ensure that messages don't pile up too much in the zmq queue
while you are working on other things, or just leaving an idle terminal.
It also helps limit potential padding of the `received` timestamp
on AsyncResult objects, used for timings.
Parameters
----------
interval : float, optional
The interval on which to spin the client in the background thread
(simply passed to time.sleep).
Notes
-----
For precision timing, you may want to use this method to put a bound
on the jitter (in seconds) in `received` timestamps used
in AsyncResult.wall_time.
"""
if self._spin_thread is not None:
self.stop_spin_thread()
self._stop_spinning.clear()
self._spin_thread = Thread(target=self._spin_every, args=(interval,))
self._spin_thread.daemon = True
self._spin_thread.start() | [
"call",
"Client",
".",
"spin",
"()",
"in",
"a",
"background",
"thread",
"on",
"some",
"regular",
"interval",
"This",
"helps",
"ensure",
"that",
"messages",
"don",
"t",
"pile",
"up",
"too",
"much",
"in",
"the",
"zmq",
"queue",
"while",
"you",
"are",
"working",
"on",
"other",
"things",
"or",
"just",
"leaving",
"an",
"idle",
"terminal",
".",
"It",
"also",
"helps",
"limit",
"potential",
"padding",
"of",
"the",
"received",
"timestamp",
"on",
"AsyncResult",
"objects",
"used",
"for",
"timings",
".",
"Parameters",
"----------",
"interval",
":",
"float",
"optional",
"The",
"interval",
"on",
"which",
"to",
"spin",
"the",
"client",
"in",
"the",
"background",
"thread",
"(",
"simply",
"passed",
"to",
"time",
".",
"sleep",
")",
".",
"Notes",
"-----",
"For",
"precision",
"timing",
"you",
"may",
"want",
"to",
"use",
"this",
"method",
"to",
"put",
"a",
"bound",
"on",
"the",
"jitter",
"(",
"in",
"seconds",
")",
"in",
"received",
"timestamps",
"used",
"in",
"AsyncResult",
".",
"wall_time",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L966-L995 | [
"def",
"spin_thread",
"(",
"self",
",",
"interval",
"=",
"1",
")",
":",
"if",
"self",
".",
"_spin_thread",
"is",
"not",
"None",
":",
"self",
".",
"stop_spin_thread",
"(",
")",
"self",
".",
"_stop_spinning",
".",
"clear",
"(",
")",
"self",
".",
"_spin_thread",
"=",
"Thread",
"(",
"target",
"=",
"self",
".",
"_spin_every",
",",
"args",
"=",
"(",
"interval",
",",
")",
")",
"self",
".",
"_spin_thread",
".",
"daemon",
"=",
"True",
"self",
".",
"_spin_thread",
".",
"start",
"(",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.stop_spin_thread | stop background spin_thread, if any | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def stop_spin_thread(self):
"""stop background spin_thread, if any"""
if self._spin_thread is not None:
self._stop_spinning.set()
self._spin_thread.join()
self._spin_thread = None | def stop_spin_thread(self):
"""stop background spin_thread, if any"""
if self._spin_thread is not None:
self._stop_spinning.set()
self._spin_thread.join()
self._spin_thread = None | [
"stop",
"background",
"spin_thread",
"if",
"any"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L997-L1002 | [
"def",
"stop_spin_thread",
"(",
"self",
")",
":",
"if",
"self",
".",
"_spin_thread",
"is",
"not",
"None",
":",
"self",
".",
"_stop_spinning",
".",
"set",
"(",
")",
"self",
".",
"_spin_thread",
".",
"join",
"(",
")",
"self",
".",
"_spin_thread",
"=",
"None"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.spin | Flush any registration notifications and execution results
waiting in the ZMQ queue. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def spin(self):
"""Flush any registration notifications and execution results
waiting in the ZMQ queue.
"""
if self._notification_socket:
self._flush_notifications()
if self._iopub_socket:
self._flush_iopub(self._iopub_socket)
if self._mux_socket:
self._flush_results(self._mux_socket)
if self._task_socket:
self._flush_results(self._task_socket)
if self._control_socket:
self._flush_control(self._control_socket)
if self._query_socket:
self._flush_ignored_hub_replies() | def spin(self):
"""Flush any registration notifications and execution results
waiting in the ZMQ queue.
"""
if self._notification_socket:
self._flush_notifications()
if self._iopub_socket:
self._flush_iopub(self._iopub_socket)
if self._mux_socket:
self._flush_results(self._mux_socket)
if self._task_socket:
self._flush_results(self._task_socket)
if self._control_socket:
self._flush_control(self._control_socket)
if self._query_socket:
self._flush_ignored_hub_replies() | [
"Flush",
"any",
"registration",
"notifications",
"and",
"execution",
"results",
"waiting",
"in",
"the",
"ZMQ",
"queue",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1004-L1019 | [
"def",
"spin",
"(",
"self",
")",
":",
"if",
"self",
".",
"_notification_socket",
":",
"self",
".",
"_flush_notifications",
"(",
")",
"if",
"self",
".",
"_iopub_socket",
":",
"self",
".",
"_flush_iopub",
"(",
"self",
".",
"_iopub_socket",
")",
"if",
"self",
".",
"_mux_socket",
":",
"self",
".",
"_flush_results",
"(",
"self",
".",
"_mux_socket",
")",
"if",
"self",
".",
"_task_socket",
":",
"self",
".",
"_flush_results",
"(",
"self",
".",
"_task_socket",
")",
"if",
"self",
".",
"_control_socket",
":",
"self",
".",
"_flush_control",
"(",
"self",
".",
"_control_socket",
")",
"if",
"self",
".",
"_query_socket",
":",
"self",
".",
"_flush_ignored_hub_replies",
"(",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.wait | waits on one or more `jobs`, for up to `timeout` seconds.
Parameters
----------
jobs : int, str, or list of ints and/or strs, or one or more AsyncResult objects
ints are indices to self.history
strs are msg_ids
default: wait on all outstanding messages
timeout : float
a time in seconds, after which to give up.
default is -1, which means no timeout
Returns
-------
True : when all msg_ids are done
False : timeout reached, some msg_ids still outstanding | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def wait(self, jobs=None, timeout=-1):
"""waits on one or more `jobs`, for up to `timeout` seconds.
Parameters
----------
jobs : int, str, or list of ints and/or strs, or one or more AsyncResult objects
ints are indices to self.history
strs are msg_ids
default: wait on all outstanding messages
timeout : float
a time in seconds, after which to give up.
default is -1, which means no timeout
Returns
-------
True : when all msg_ids are done
False : timeout reached, some msg_ids still outstanding
"""
tic = time.time()
if jobs is None:
theids = self.outstanding
else:
if isinstance(jobs, (int, basestring, AsyncResult)):
jobs = [jobs]
theids = set()
for job in jobs:
if isinstance(job, int):
# index access
job = self.history[job]
elif isinstance(job, AsyncResult):
map(theids.add, job.msg_ids)
continue
theids.add(job)
if not theids.intersection(self.outstanding):
return True
self.spin()
while theids.intersection(self.outstanding):
if timeout >= 0 and ( time.time()-tic ) > timeout:
break
time.sleep(1e-3)
self.spin()
return len(theids.intersection(self.outstanding)) == 0 | def wait(self, jobs=None, timeout=-1):
"""waits on one or more `jobs`, for up to `timeout` seconds.
Parameters
----------
jobs : int, str, or list of ints and/or strs, or one or more AsyncResult objects
ints are indices to self.history
strs are msg_ids
default: wait on all outstanding messages
timeout : float
a time in seconds, after which to give up.
default is -1, which means no timeout
Returns
-------
True : when all msg_ids are done
False : timeout reached, some msg_ids still outstanding
"""
tic = time.time()
if jobs is None:
theids = self.outstanding
else:
if isinstance(jobs, (int, basestring, AsyncResult)):
jobs = [jobs]
theids = set()
for job in jobs:
if isinstance(job, int):
# index access
job = self.history[job]
elif isinstance(job, AsyncResult):
map(theids.add, job.msg_ids)
continue
theids.add(job)
if not theids.intersection(self.outstanding):
return True
self.spin()
while theids.intersection(self.outstanding):
if timeout >= 0 and ( time.time()-tic ) > timeout:
break
time.sleep(1e-3)
self.spin()
return len(theids.intersection(self.outstanding)) == 0 | [
"waits",
"on",
"one",
"or",
"more",
"jobs",
"for",
"up",
"to",
"timeout",
"seconds",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1021-L1064 | [
"def",
"wait",
"(",
"self",
",",
"jobs",
"=",
"None",
",",
"timeout",
"=",
"-",
"1",
")",
":",
"tic",
"=",
"time",
".",
"time",
"(",
")",
"if",
"jobs",
"is",
"None",
":",
"theids",
"=",
"self",
".",
"outstanding",
"else",
":",
"if",
"isinstance",
"(",
"jobs",
",",
"(",
"int",
",",
"basestring",
",",
"AsyncResult",
")",
")",
":",
"jobs",
"=",
"[",
"jobs",
"]",
"theids",
"=",
"set",
"(",
")",
"for",
"job",
"in",
"jobs",
":",
"if",
"isinstance",
"(",
"job",
",",
"int",
")",
":",
"# index access",
"job",
"=",
"self",
".",
"history",
"[",
"job",
"]",
"elif",
"isinstance",
"(",
"job",
",",
"AsyncResult",
")",
":",
"map",
"(",
"theids",
".",
"add",
",",
"job",
".",
"msg_ids",
")",
"continue",
"theids",
".",
"add",
"(",
"job",
")",
"if",
"not",
"theids",
".",
"intersection",
"(",
"self",
".",
"outstanding",
")",
":",
"return",
"True",
"self",
".",
"spin",
"(",
")",
"while",
"theids",
".",
"intersection",
"(",
"self",
".",
"outstanding",
")",
":",
"if",
"timeout",
">=",
"0",
"and",
"(",
"time",
".",
"time",
"(",
")",
"-",
"tic",
")",
">",
"timeout",
":",
"break",
"time",
".",
"sleep",
"(",
"1e-3",
")",
"self",
".",
"spin",
"(",
")",
"return",
"len",
"(",
"theids",
".",
"intersection",
"(",
"self",
".",
"outstanding",
")",
")",
"==",
"0"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.clear | Clear the namespace in target(s). | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def clear(self, targets=None, block=None):
"""Clear the namespace in target(s)."""
block = self.block if block is None else block
targets = self._build_targets(targets)[0]
for t in targets:
self.session.send(self._control_socket, 'clear_request', content={}, ident=t)
error = False
if block:
self._flush_ignored_control()
for i in range(len(targets)):
idents,msg = self.session.recv(self._control_socket,0)
if self.debug:
pprint(msg)
if msg['content']['status'] != 'ok':
error = self._unwrap_exception(msg['content'])
else:
self._ignored_control_replies += len(targets)
if error:
raise error | def clear(self, targets=None, block=None):
"""Clear the namespace in target(s)."""
block = self.block if block is None else block
targets = self._build_targets(targets)[0]
for t in targets:
self.session.send(self._control_socket, 'clear_request', content={}, ident=t)
error = False
if block:
self._flush_ignored_control()
for i in range(len(targets)):
idents,msg = self.session.recv(self._control_socket,0)
if self.debug:
pprint(msg)
if msg['content']['status'] != 'ok':
error = self._unwrap_exception(msg['content'])
else:
self._ignored_control_replies += len(targets)
if error:
raise error | [
"Clear",
"the",
"namespace",
"in",
"target",
"(",
"s",
")",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1071-L1089 | [
"def",
"clear",
"(",
"self",
",",
"targets",
"=",
"None",
",",
"block",
"=",
"None",
")",
":",
"block",
"=",
"self",
".",
"block",
"if",
"block",
"is",
"None",
"else",
"block",
"targets",
"=",
"self",
".",
"_build_targets",
"(",
"targets",
")",
"[",
"0",
"]",
"for",
"t",
"in",
"targets",
":",
"self",
".",
"session",
".",
"send",
"(",
"self",
".",
"_control_socket",
",",
"'clear_request'",
",",
"content",
"=",
"{",
"}",
",",
"ident",
"=",
"t",
")",
"error",
"=",
"False",
"if",
"block",
":",
"self",
".",
"_flush_ignored_control",
"(",
")",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"targets",
")",
")",
":",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"self",
".",
"_control_socket",
",",
"0",
")",
"if",
"self",
".",
"debug",
":",
"pprint",
"(",
"msg",
")",
"if",
"msg",
"[",
"'content'",
"]",
"[",
"'status'",
"]",
"!=",
"'ok'",
":",
"error",
"=",
"self",
".",
"_unwrap_exception",
"(",
"msg",
"[",
"'content'",
"]",
")",
"else",
":",
"self",
".",
"_ignored_control_replies",
"+=",
"len",
"(",
"targets",
")",
"if",
"error",
":",
"raise",
"error"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.abort | Abort specific jobs from the execution queues of target(s).
This is a mechanism to prevent jobs that have already been submitted
from executing.
Parameters
----------
jobs : msg_id, list of msg_ids, or AsyncResult
The jobs to be aborted
If unspecified/None: abort all outstanding jobs. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def abort(self, jobs=None, targets=None, block=None):
"""Abort specific jobs from the execution queues of target(s).
This is a mechanism to prevent jobs that have already been submitted
from executing.
Parameters
----------
jobs : msg_id, list of msg_ids, or AsyncResult
The jobs to be aborted
If unspecified/None: abort all outstanding jobs.
"""
block = self.block if block is None else block
jobs = jobs if jobs is not None else list(self.outstanding)
targets = self._build_targets(targets)[0]
msg_ids = []
if isinstance(jobs, (basestring,AsyncResult)):
jobs = [jobs]
bad_ids = filter(lambda obj: not isinstance(obj, (basestring, AsyncResult)), jobs)
if bad_ids:
raise TypeError("Invalid msg_id type %r, expected str or AsyncResult"%bad_ids[0])
for j in jobs:
if isinstance(j, AsyncResult):
msg_ids.extend(j.msg_ids)
else:
msg_ids.append(j)
content = dict(msg_ids=msg_ids)
for t in targets:
self.session.send(self._control_socket, 'abort_request',
content=content, ident=t)
error = False
if block:
self._flush_ignored_control()
for i in range(len(targets)):
idents,msg = self.session.recv(self._control_socket,0)
if self.debug:
pprint(msg)
if msg['content']['status'] != 'ok':
error = self._unwrap_exception(msg['content'])
else:
self._ignored_control_replies += len(targets)
if error:
raise error | def abort(self, jobs=None, targets=None, block=None):
"""Abort specific jobs from the execution queues of target(s).
This is a mechanism to prevent jobs that have already been submitted
from executing.
Parameters
----------
jobs : msg_id, list of msg_ids, or AsyncResult
The jobs to be aborted
If unspecified/None: abort all outstanding jobs.
"""
block = self.block if block is None else block
jobs = jobs if jobs is not None else list(self.outstanding)
targets = self._build_targets(targets)[0]
msg_ids = []
if isinstance(jobs, (basestring,AsyncResult)):
jobs = [jobs]
bad_ids = filter(lambda obj: not isinstance(obj, (basestring, AsyncResult)), jobs)
if bad_ids:
raise TypeError("Invalid msg_id type %r, expected str or AsyncResult"%bad_ids[0])
for j in jobs:
if isinstance(j, AsyncResult):
msg_ids.extend(j.msg_ids)
else:
msg_ids.append(j)
content = dict(msg_ids=msg_ids)
for t in targets:
self.session.send(self._control_socket, 'abort_request',
content=content, ident=t)
error = False
if block:
self._flush_ignored_control()
for i in range(len(targets)):
idents,msg = self.session.recv(self._control_socket,0)
if self.debug:
pprint(msg)
if msg['content']['status'] != 'ok':
error = self._unwrap_exception(msg['content'])
else:
self._ignored_control_replies += len(targets)
if error:
raise error | [
"Abort",
"specific",
"jobs",
"from",
"the",
"execution",
"queues",
"of",
"target",
"(",
"s",
")",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1093-L1139 | [
"def",
"abort",
"(",
"self",
",",
"jobs",
"=",
"None",
",",
"targets",
"=",
"None",
",",
"block",
"=",
"None",
")",
":",
"block",
"=",
"self",
".",
"block",
"if",
"block",
"is",
"None",
"else",
"block",
"jobs",
"=",
"jobs",
"if",
"jobs",
"is",
"not",
"None",
"else",
"list",
"(",
"self",
".",
"outstanding",
")",
"targets",
"=",
"self",
".",
"_build_targets",
"(",
"targets",
")",
"[",
"0",
"]",
"msg_ids",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"jobs",
",",
"(",
"basestring",
",",
"AsyncResult",
")",
")",
":",
"jobs",
"=",
"[",
"jobs",
"]",
"bad_ids",
"=",
"filter",
"(",
"lambda",
"obj",
":",
"not",
"isinstance",
"(",
"obj",
",",
"(",
"basestring",
",",
"AsyncResult",
")",
")",
",",
"jobs",
")",
"if",
"bad_ids",
":",
"raise",
"TypeError",
"(",
"\"Invalid msg_id type %r, expected str or AsyncResult\"",
"%",
"bad_ids",
"[",
"0",
"]",
")",
"for",
"j",
"in",
"jobs",
":",
"if",
"isinstance",
"(",
"j",
",",
"AsyncResult",
")",
":",
"msg_ids",
".",
"extend",
"(",
"j",
".",
"msg_ids",
")",
"else",
":",
"msg_ids",
".",
"append",
"(",
"j",
")",
"content",
"=",
"dict",
"(",
"msg_ids",
"=",
"msg_ids",
")",
"for",
"t",
"in",
"targets",
":",
"self",
".",
"session",
".",
"send",
"(",
"self",
".",
"_control_socket",
",",
"'abort_request'",
",",
"content",
"=",
"content",
",",
"ident",
"=",
"t",
")",
"error",
"=",
"False",
"if",
"block",
":",
"self",
".",
"_flush_ignored_control",
"(",
")",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"targets",
")",
")",
":",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"self",
".",
"_control_socket",
",",
"0",
")",
"if",
"self",
".",
"debug",
":",
"pprint",
"(",
"msg",
")",
"if",
"msg",
"[",
"'content'",
"]",
"[",
"'status'",
"]",
"!=",
"'ok'",
":",
"error",
"=",
"self",
".",
"_unwrap_exception",
"(",
"msg",
"[",
"'content'",
"]",
")",
"else",
":",
"self",
".",
"_ignored_control_replies",
"+=",
"len",
"(",
"targets",
")",
"if",
"error",
":",
"raise",
"error"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.shutdown | Terminates one or more engine processes, optionally including the hub.
Parameters
----------
targets: list of ints or 'all' [default: all]
Which engines to shutdown.
hub: bool [default: False]
Whether to include the Hub. hub=True implies targets='all'.
block: bool [default: self.block]
Whether to wait for clean shutdown replies or not.
restart: bool [default: False]
NOT IMPLEMENTED
whether to restart engines after shutting them down. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def shutdown(self, targets='all', restart=False, hub=False, block=None):
"""Terminates one or more engine processes, optionally including the hub.
Parameters
----------
targets: list of ints or 'all' [default: all]
Which engines to shutdown.
hub: bool [default: False]
Whether to include the Hub. hub=True implies targets='all'.
block: bool [default: self.block]
Whether to wait for clean shutdown replies or not.
restart: bool [default: False]
NOT IMPLEMENTED
whether to restart engines after shutting them down.
"""
if restart:
raise NotImplementedError("Engine restart is not yet implemented")
block = self.block if block is None else block
if hub:
targets = 'all'
targets = self._build_targets(targets)[0]
for t in targets:
self.session.send(self._control_socket, 'shutdown_request',
content={'restart':restart},ident=t)
error = False
if block or hub:
self._flush_ignored_control()
for i in range(len(targets)):
idents,msg = self.session.recv(self._control_socket, 0)
if self.debug:
pprint(msg)
if msg['content']['status'] != 'ok':
error = self._unwrap_exception(msg['content'])
else:
self._ignored_control_replies += len(targets)
if hub:
time.sleep(0.25)
self.session.send(self._query_socket, 'shutdown_request')
idents,msg = self.session.recv(self._query_socket, 0)
if self.debug:
pprint(msg)
if msg['content']['status'] != 'ok':
error = self._unwrap_exception(msg['content'])
if error:
raise error | def shutdown(self, targets='all', restart=False, hub=False, block=None):
"""Terminates one or more engine processes, optionally including the hub.
Parameters
----------
targets: list of ints or 'all' [default: all]
Which engines to shutdown.
hub: bool [default: False]
Whether to include the Hub. hub=True implies targets='all'.
block: bool [default: self.block]
Whether to wait for clean shutdown replies or not.
restart: bool [default: False]
NOT IMPLEMENTED
whether to restart engines after shutting them down.
"""
if restart:
raise NotImplementedError("Engine restart is not yet implemented")
block = self.block if block is None else block
if hub:
targets = 'all'
targets = self._build_targets(targets)[0]
for t in targets:
self.session.send(self._control_socket, 'shutdown_request',
content={'restart':restart},ident=t)
error = False
if block or hub:
self._flush_ignored_control()
for i in range(len(targets)):
idents,msg = self.session.recv(self._control_socket, 0)
if self.debug:
pprint(msg)
if msg['content']['status'] != 'ok':
error = self._unwrap_exception(msg['content'])
else:
self._ignored_control_replies += len(targets)
if hub:
time.sleep(0.25)
self.session.send(self._query_socket, 'shutdown_request')
idents,msg = self.session.recv(self._query_socket, 0)
if self.debug:
pprint(msg)
if msg['content']['status'] != 'ok':
error = self._unwrap_exception(msg['content'])
if error:
raise error | [
"Terminates",
"one",
"or",
"more",
"engine",
"processes",
"optionally",
"including",
"the",
"hub",
".",
"Parameters",
"----------",
"targets",
":",
"list",
"of",
"ints",
"or",
"all",
"[",
"default",
":",
"all",
"]",
"Which",
"engines",
"to",
"shutdown",
".",
"hub",
":",
"bool",
"[",
"default",
":",
"False",
"]",
"Whether",
"to",
"include",
"the",
"Hub",
".",
"hub",
"=",
"True",
"implies",
"targets",
"=",
"all",
".",
"block",
":",
"bool",
"[",
"default",
":",
"self",
".",
"block",
"]",
"Whether",
"to",
"wait",
"for",
"clean",
"shutdown",
"replies",
"or",
"not",
".",
"restart",
":",
"bool",
"[",
"default",
":",
"False",
"]",
"NOT",
"IMPLEMENTED",
"whether",
"to",
"restart",
"engines",
"after",
"shutting",
"them",
"down",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1142-L1191 | [
"def",
"shutdown",
"(",
"self",
",",
"targets",
"=",
"'all'",
",",
"restart",
"=",
"False",
",",
"hub",
"=",
"False",
",",
"block",
"=",
"None",
")",
":",
"if",
"restart",
":",
"raise",
"NotImplementedError",
"(",
"\"Engine restart is not yet implemented\"",
")",
"block",
"=",
"self",
".",
"block",
"if",
"block",
"is",
"None",
"else",
"block",
"if",
"hub",
":",
"targets",
"=",
"'all'",
"targets",
"=",
"self",
".",
"_build_targets",
"(",
"targets",
")",
"[",
"0",
"]",
"for",
"t",
"in",
"targets",
":",
"self",
".",
"session",
".",
"send",
"(",
"self",
".",
"_control_socket",
",",
"'shutdown_request'",
",",
"content",
"=",
"{",
"'restart'",
":",
"restart",
"}",
",",
"ident",
"=",
"t",
")",
"error",
"=",
"False",
"if",
"block",
"or",
"hub",
":",
"self",
".",
"_flush_ignored_control",
"(",
")",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"targets",
")",
")",
":",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"self",
".",
"_control_socket",
",",
"0",
")",
"if",
"self",
".",
"debug",
":",
"pprint",
"(",
"msg",
")",
"if",
"msg",
"[",
"'content'",
"]",
"[",
"'status'",
"]",
"!=",
"'ok'",
":",
"error",
"=",
"self",
".",
"_unwrap_exception",
"(",
"msg",
"[",
"'content'",
"]",
")",
"else",
":",
"self",
".",
"_ignored_control_replies",
"+=",
"len",
"(",
"targets",
")",
"if",
"hub",
":",
"time",
".",
"sleep",
"(",
"0.25",
")",
"self",
".",
"session",
".",
"send",
"(",
"self",
".",
"_query_socket",
",",
"'shutdown_request'",
")",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"self",
".",
"_query_socket",
",",
"0",
")",
"if",
"self",
".",
"debug",
":",
"pprint",
"(",
"msg",
")",
"if",
"msg",
"[",
"'content'",
"]",
"[",
"'status'",
"]",
"!=",
"'ok'",
":",
"error",
"=",
"self",
".",
"_unwrap_exception",
"(",
"msg",
"[",
"'content'",
"]",
")",
"if",
"error",
":",
"raise",
"error"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.send_apply_request | construct and send an apply message via a socket.
This is the principal method with which all engine execution is performed by views. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def send_apply_request(self, socket, f, args=None, kwargs=None, subheader=None, track=False,
ident=None):
"""construct and send an apply message via a socket.
This is the principal method with which all engine execution is performed by views.
"""
if self._closed:
raise RuntimeError("Client cannot be used after its sockets have been closed")
# defaults:
args = args if args is not None else []
kwargs = kwargs if kwargs is not None else {}
subheader = subheader if subheader is not None else {}
# validate arguments
if not callable(f) and not isinstance(f, Reference):
raise TypeError("f must be callable, not %s"%type(f))
if not isinstance(args, (tuple, list)):
raise TypeError("args must be tuple or list, not %s"%type(args))
if not isinstance(kwargs, dict):
raise TypeError("kwargs must be dict, not %s"%type(kwargs))
if not isinstance(subheader, dict):
raise TypeError("subheader must be dict, not %s"%type(subheader))
bufs = util.pack_apply_message(f,args,kwargs)
msg = self.session.send(socket, "apply_request", buffers=bufs, ident=ident,
subheader=subheader, track=track)
msg_id = msg['header']['msg_id']
self.outstanding.add(msg_id)
if ident:
# possibly routed to a specific engine
if isinstance(ident, list):
ident = ident[-1]
if ident in self._engines.values():
# save for later, in case of engine death
self._outstanding_dict[ident].add(msg_id)
self.history.append(msg_id)
self.metadata[msg_id]['submitted'] = datetime.now()
return msg | def send_apply_request(self, socket, f, args=None, kwargs=None, subheader=None, track=False,
ident=None):
"""construct and send an apply message via a socket.
This is the principal method with which all engine execution is performed by views.
"""
if self._closed:
raise RuntimeError("Client cannot be used after its sockets have been closed")
# defaults:
args = args if args is not None else []
kwargs = kwargs if kwargs is not None else {}
subheader = subheader if subheader is not None else {}
# validate arguments
if not callable(f) and not isinstance(f, Reference):
raise TypeError("f must be callable, not %s"%type(f))
if not isinstance(args, (tuple, list)):
raise TypeError("args must be tuple or list, not %s"%type(args))
if not isinstance(kwargs, dict):
raise TypeError("kwargs must be dict, not %s"%type(kwargs))
if not isinstance(subheader, dict):
raise TypeError("subheader must be dict, not %s"%type(subheader))
bufs = util.pack_apply_message(f,args,kwargs)
msg = self.session.send(socket, "apply_request", buffers=bufs, ident=ident,
subheader=subheader, track=track)
msg_id = msg['header']['msg_id']
self.outstanding.add(msg_id)
if ident:
# possibly routed to a specific engine
if isinstance(ident, list):
ident = ident[-1]
if ident in self._engines.values():
# save for later, in case of engine death
self._outstanding_dict[ident].add(msg_id)
self.history.append(msg_id)
self.metadata[msg_id]['submitted'] = datetime.now()
return msg | [
"construct",
"and",
"send",
"an",
"apply",
"message",
"via",
"a",
"socket",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1204-L1246 | [
"def",
"send_apply_request",
"(",
"self",
",",
"socket",
",",
"f",
",",
"args",
"=",
"None",
",",
"kwargs",
"=",
"None",
",",
"subheader",
"=",
"None",
",",
"track",
"=",
"False",
",",
"ident",
"=",
"None",
")",
":",
"if",
"self",
".",
"_closed",
":",
"raise",
"RuntimeError",
"(",
"\"Client cannot be used after its sockets have been closed\"",
")",
"# defaults:",
"args",
"=",
"args",
"if",
"args",
"is",
"not",
"None",
"else",
"[",
"]",
"kwargs",
"=",
"kwargs",
"if",
"kwargs",
"is",
"not",
"None",
"else",
"{",
"}",
"subheader",
"=",
"subheader",
"if",
"subheader",
"is",
"not",
"None",
"else",
"{",
"}",
"# validate arguments",
"if",
"not",
"callable",
"(",
"f",
")",
"and",
"not",
"isinstance",
"(",
"f",
",",
"Reference",
")",
":",
"raise",
"TypeError",
"(",
"\"f must be callable, not %s\"",
"%",
"type",
"(",
"f",
")",
")",
"if",
"not",
"isinstance",
"(",
"args",
",",
"(",
"tuple",
",",
"list",
")",
")",
":",
"raise",
"TypeError",
"(",
"\"args must be tuple or list, not %s\"",
"%",
"type",
"(",
"args",
")",
")",
"if",
"not",
"isinstance",
"(",
"kwargs",
",",
"dict",
")",
":",
"raise",
"TypeError",
"(",
"\"kwargs must be dict, not %s\"",
"%",
"type",
"(",
"kwargs",
")",
")",
"if",
"not",
"isinstance",
"(",
"subheader",
",",
"dict",
")",
":",
"raise",
"TypeError",
"(",
"\"subheader must be dict, not %s\"",
"%",
"type",
"(",
"subheader",
")",
")",
"bufs",
"=",
"util",
".",
"pack_apply_message",
"(",
"f",
",",
"args",
",",
"kwargs",
")",
"msg",
"=",
"self",
".",
"session",
".",
"send",
"(",
"socket",
",",
"\"apply_request\"",
",",
"buffers",
"=",
"bufs",
",",
"ident",
"=",
"ident",
",",
"subheader",
"=",
"subheader",
",",
"track",
"=",
"track",
")",
"msg_id",
"=",
"msg",
"[",
"'header'",
"]",
"[",
"'msg_id'",
"]",
"self",
".",
"outstanding",
".",
"add",
"(",
"msg_id",
")",
"if",
"ident",
":",
"# possibly routed to a specific engine",
"if",
"isinstance",
"(",
"ident",
",",
"list",
")",
":",
"ident",
"=",
"ident",
"[",
"-",
"1",
"]",
"if",
"ident",
"in",
"self",
".",
"_engines",
".",
"values",
"(",
")",
":",
"# save for later, in case of engine death",
"self",
".",
"_outstanding_dict",
"[",
"ident",
"]",
".",
"add",
"(",
"msg_id",
")",
"self",
".",
"history",
".",
"append",
"(",
"msg_id",
")",
"self",
".",
"metadata",
"[",
"msg_id",
"]",
"[",
"'submitted'",
"]",
"=",
"datetime",
".",
"now",
"(",
")",
"return",
"msg"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.send_execute_request | construct and send an execute request via a socket. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def send_execute_request(self, socket, code, silent=True, subheader=None, ident=None):
"""construct and send an execute request via a socket.
"""
if self._closed:
raise RuntimeError("Client cannot be used after its sockets have been closed")
# defaults:
subheader = subheader if subheader is not None else {}
# validate arguments
if not isinstance(code, basestring):
raise TypeError("code must be text, not %s" % type(code))
if not isinstance(subheader, dict):
raise TypeError("subheader must be dict, not %s" % type(subheader))
content = dict(code=code, silent=bool(silent), user_variables=[], user_expressions={})
msg = self.session.send(socket, "execute_request", content=content, ident=ident,
subheader=subheader)
msg_id = msg['header']['msg_id']
self.outstanding.add(msg_id)
if ident:
# possibly routed to a specific engine
if isinstance(ident, list):
ident = ident[-1]
if ident in self._engines.values():
# save for later, in case of engine death
self._outstanding_dict[ident].add(msg_id)
self.history.append(msg_id)
self.metadata[msg_id]['submitted'] = datetime.now()
return msg | def send_execute_request(self, socket, code, silent=True, subheader=None, ident=None):
"""construct and send an execute request via a socket.
"""
if self._closed:
raise RuntimeError("Client cannot be used after its sockets have been closed")
# defaults:
subheader = subheader if subheader is not None else {}
# validate arguments
if not isinstance(code, basestring):
raise TypeError("code must be text, not %s" % type(code))
if not isinstance(subheader, dict):
raise TypeError("subheader must be dict, not %s" % type(subheader))
content = dict(code=code, silent=bool(silent), user_variables=[], user_expressions={})
msg = self.session.send(socket, "execute_request", content=content, ident=ident,
subheader=subheader)
msg_id = msg['header']['msg_id']
self.outstanding.add(msg_id)
if ident:
# possibly routed to a specific engine
if isinstance(ident, list):
ident = ident[-1]
if ident in self._engines.values():
# save for later, in case of engine death
self._outstanding_dict[ident].add(msg_id)
self.history.append(msg_id)
self.metadata[msg_id]['submitted'] = datetime.now()
return msg | [
"construct",
"and",
"send",
"an",
"execute",
"request",
"via",
"a",
"socket",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1248-L1283 | [
"def",
"send_execute_request",
"(",
"self",
",",
"socket",
",",
"code",
",",
"silent",
"=",
"True",
",",
"subheader",
"=",
"None",
",",
"ident",
"=",
"None",
")",
":",
"if",
"self",
".",
"_closed",
":",
"raise",
"RuntimeError",
"(",
"\"Client cannot be used after its sockets have been closed\"",
")",
"# defaults:",
"subheader",
"=",
"subheader",
"if",
"subheader",
"is",
"not",
"None",
"else",
"{",
"}",
"# validate arguments",
"if",
"not",
"isinstance",
"(",
"code",
",",
"basestring",
")",
":",
"raise",
"TypeError",
"(",
"\"code must be text, not %s\"",
"%",
"type",
"(",
"code",
")",
")",
"if",
"not",
"isinstance",
"(",
"subheader",
",",
"dict",
")",
":",
"raise",
"TypeError",
"(",
"\"subheader must be dict, not %s\"",
"%",
"type",
"(",
"subheader",
")",
")",
"content",
"=",
"dict",
"(",
"code",
"=",
"code",
",",
"silent",
"=",
"bool",
"(",
"silent",
")",
",",
"user_variables",
"=",
"[",
"]",
",",
"user_expressions",
"=",
"{",
"}",
")",
"msg",
"=",
"self",
".",
"session",
".",
"send",
"(",
"socket",
",",
"\"execute_request\"",
",",
"content",
"=",
"content",
",",
"ident",
"=",
"ident",
",",
"subheader",
"=",
"subheader",
")",
"msg_id",
"=",
"msg",
"[",
"'header'",
"]",
"[",
"'msg_id'",
"]",
"self",
".",
"outstanding",
".",
"add",
"(",
"msg_id",
")",
"if",
"ident",
":",
"# possibly routed to a specific engine",
"if",
"isinstance",
"(",
"ident",
",",
"list",
")",
":",
"ident",
"=",
"ident",
"[",
"-",
"1",
"]",
"if",
"ident",
"in",
"self",
".",
"_engines",
".",
"values",
"(",
")",
":",
"# save for later, in case of engine death",
"self",
".",
"_outstanding_dict",
"[",
"ident",
"]",
".",
"add",
"(",
"msg_id",
")",
"self",
".",
"history",
".",
"append",
"(",
"msg_id",
")",
"self",
".",
"metadata",
"[",
"msg_id",
"]",
"[",
"'submitted'",
"]",
"=",
"datetime",
".",
"now",
"(",
")",
"return",
"msg"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.load_balanced_view | construct a DirectView object.
If no arguments are specified, create a LoadBalancedView
using all engines.
Parameters
----------
targets: list,slice,int,etc. [default: use all engines]
The subset of engines across which to load-balance | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def load_balanced_view(self, targets=None):
"""construct a DirectView object.
If no arguments are specified, create a LoadBalancedView
using all engines.
Parameters
----------
targets: list,slice,int,etc. [default: use all engines]
The subset of engines across which to load-balance
"""
if targets == 'all':
targets = None
if targets is not None:
targets = self._build_targets(targets)[1]
return LoadBalancedView(client=self, socket=self._task_socket, targets=targets) | def load_balanced_view(self, targets=None):
"""construct a DirectView object.
If no arguments are specified, create a LoadBalancedView
using all engines.
Parameters
----------
targets: list,slice,int,etc. [default: use all engines]
The subset of engines across which to load-balance
"""
if targets == 'all':
targets = None
if targets is not None:
targets = self._build_targets(targets)[1]
return LoadBalancedView(client=self, socket=self._task_socket, targets=targets) | [
"construct",
"a",
"DirectView",
"object",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1289-L1305 | [
"def",
"load_balanced_view",
"(",
"self",
",",
"targets",
"=",
"None",
")",
":",
"if",
"targets",
"==",
"'all'",
":",
"targets",
"=",
"None",
"if",
"targets",
"is",
"not",
"None",
":",
"targets",
"=",
"self",
".",
"_build_targets",
"(",
"targets",
")",
"[",
"1",
"]",
"return",
"LoadBalancedView",
"(",
"client",
"=",
"self",
",",
"socket",
"=",
"self",
".",
"_task_socket",
",",
"targets",
"=",
"targets",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.direct_view | construct a DirectView object.
If no targets are specified, create a DirectView using all engines.
rc.direct_view('all') is distinguished from rc[:] in that 'all' will
evaluate the target engines at each execution, whereas rc[:] will connect to
all *current* engines, and that list will not change.
That is, 'all' will always use all engines, whereas rc[:] will not use
engines added after the DirectView is constructed.
Parameters
----------
targets: list,slice,int,etc. [default: use all engines]
The engines to use for the View | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def direct_view(self, targets='all'):
"""construct a DirectView object.
If no targets are specified, create a DirectView using all engines.
rc.direct_view('all') is distinguished from rc[:] in that 'all' will
evaluate the target engines at each execution, whereas rc[:] will connect to
all *current* engines, and that list will not change.
That is, 'all' will always use all engines, whereas rc[:] will not use
engines added after the DirectView is constructed.
Parameters
----------
targets: list,slice,int,etc. [default: use all engines]
The engines to use for the View
"""
single = isinstance(targets, int)
# allow 'all' to be lazily evaluated at each execution
if targets != 'all':
targets = self._build_targets(targets)[1]
if single:
targets = targets[0]
return DirectView(client=self, socket=self._mux_socket, targets=targets) | def direct_view(self, targets='all'):
"""construct a DirectView object.
If no targets are specified, create a DirectView using all engines.
rc.direct_view('all') is distinguished from rc[:] in that 'all' will
evaluate the target engines at each execution, whereas rc[:] will connect to
all *current* engines, and that list will not change.
That is, 'all' will always use all engines, whereas rc[:] will not use
engines added after the DirectView is constructed.
Parameters
----------
targets: list,slice,int,etc. [default: use all engines]
The engines to use for the View
"""
single = isinstance(targets, int)
# allow 'all' to be lazily evaluated at each execution
if targets != 'all':
targets = self._build_targets(targets)[1]
if single:
targets = targets[0]
return DirectView(client=self, socket=self._mux_socket, targets=targets) | [
"construct",
"a",
"DirectView",
"object",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1307-L1331 | [
"def",
"direct_view",
"(",
"self",
",",
"targets",
"=",
"'all'",
")",
":",
"single",
"=",
"isinstance",
"(",
"targets",
",",
"int",
")",
"# allow 'all' to be lazily evaluated at each execution",
"if",
"targets",
"!=",
"'all'",
":",
"targets",
"=",
"self",
".",
"_build_targets",
"(",
"targets",
")",
"[",
"1",
"]",
"if",
"single",
":",
"targets",
"=",
"targets",
"[",
"0",
"]",
"return",
"DirectView",
"(",
"client",
"=",
"self",
",",
"socket",
"=",
"self",
".",
"_mux_socket",
",",
"targets",
"=",
"targets",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.get_result | Retrieve a result by msg_id or history index, wrapped in an AsyncResult object.
If the client already has the results, no request to the Hub will be made.
This is a convenient way to construct AsyncResult objects, which are wrappers
that include metadata about execution, and allow for awaiting results that
were not submitted by this Client.
It can also be a convenient way to retrieve the metadata associated with
blocking execution, since it always retrieves
Examples
--------
::
In [10]: r = client.apply()
Parameters
----------
indices_or_msg_ids : integer history index, str msg_id, or list of either
The indices or msg_ids of indices to be retrieved
block : bool
Whether to wait for the result to be done
Returns
-------
AsyncResult
A single AsyncResult object will always be returned.
AsyncHubResult
A subclass of AsyncResult that retrieves results from the Hub | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def get_result(self, indices_or_msg_ids=None, block=None):
"""Retrieve a result by msg_id or history index, wrapped in an AsyncResult object.
If the client already has the results, no request to the Hub will be made.
This is a convenient way to construct AsyncResult objects, which are wrappers
that include metadata about execution, and allow for awaiting results that
were not submitted by this Client.
It can also be a convenient way to retrieve the metadata associated with
blocking execution, since it always retrieves
Examples
--------
::
In [10]: r = client.apply()
Parameters
----------
indices_or_msg_ids : integer history index, str msg_id, or list of either
The indices or msg_ids of indices to be retrieved
block : bool
Whether to wait for the result to be done
Returns
-------
AsyncResult
A single AsyncResult object will always be returned.
AsyncHubResult
A subclass of AsyncResult that retrieves results from the Hub
"""
block = self.block if block is None else block
if indices_or_msg_ids is None:
indices_or_msg_ids = -1
if not isinstance(indices_or_msg_ids, (list,tuple)):
indices_or_msg_ids = [indices_or_msg_ids]
theids = []
for id in indices_or_msg_ids:
if isinstance(id, int):
id = self.history[id]
if not isinstance(id, basestring):
raise TypeError("indices must be str or int, not %r"%id)
theids.append(id)
local_ids = filter(lambda msg_id: msg_id in self.history or msg_id in self.results, theids)
remote_ids = filter(lambda msg_id: msg_id not in local_ids, theids)
if remote_ids:
ar = AsyncHubResult(self, msg_ids=theids)
else:
ar = AsyncResult(self, msg_ids=theids)
if block:
ar.wait()
return ar | def get_result(self, indices_or_msg_ids=None, block=None):
"""Retrieve a result by msg_id or history index, wrapped in an AsyncResult object.
If the client already has the results, no request to the Hub will be made.
This is a convenient way to construct AsyncResult objects, which are wrappers
that include metadata about execution, and allow for awaiting results that
were not submitted by this Client.
It can also be a convenient way to retrieve the metadata associated with
blocking execution, since it always retrieves
Examples
--------
::
In [10]: r = client.apply()
Parameters
----------
indices_or_msg_ids : integer history index, str msg_id, or list of either
The indices or msg_ids of indices to be retrieved
block : bool
Whether to wait for the result to be done
Returns
-------
AsyncResult
A single AsyncResult object will always be returned.
AsyncHubResult
A subclass of AsyncResult that retrieves results from the Hub
"""
block = self.block if block is None else block
if indices_or_msg_ids is None:
indices_or_msg_ids = -1
if not isinstance(indices_or_msg_ids, (list,tuple)):
indices_or_msg_ids = [indices_or_msg_ids]
theids = []
for id in indices_or_msg_ids:
if isinstance(id, int):
id = self.history[id]
if not isinstance(id, basestring):
raise TypeError("indices must be str or int, not %r"%id)
theids.append(id)
local_ids = filter(lambda msg_id: msg_id in self.history or msg_id in self.results, theids)
remote_ids = filter(lambda msg_id: msg_id not in local_ids, theids)
if remote_ids:
ar = AsyncHubResult(self, msg_ids=theids)
else:
ar = AsyncResult(self, msg_ids=theids)
if block:
ar.wait()
return ar | [
"Retrieve",
"a",
"result",
"by",
"msg_id",
"or",
"history",
"index",
"wrapped",
"in",
"an",
"AsyncResult",
"object",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1338-L1401 | [
"def",
"get_result",
"(",
"self",
",",
"indices_or_msg_ids",
"=",
"None",
",",
"block",
"=",
"None",
")",
":",
"block",
"=",
"self",
".",
"block",
"if",
"block",
"is",
"None",
"else",
"block",
"if",
"indices_or_msg_ids",
"is",
"None",
":",
"indices_or_msg_ids",
"=",
"-",
"1",
"if",
"not",
"isinstance",
"(",
"indices_or_msg_ids",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"indices_or_msg_ids",
"=",
"[",
"indices_or_msg_ids",
"]",
"theids",
"=",
"[",
"]",
"for",
"id",
"in",
"indices_or_msg_ids",
":",
"if",
"isinstance",
"(",
"id",
",",
"int",
")",
":",
"id",
"=",
"self",
".",
"history",
"[",
"id",
"]",
"if",
"not",
"isinstance",
"(",
"id",
",",
"basestring",
")",
":",
"raise",
"TypeError",
"(",
"\"indices must be str or int, not %r\"",
"%",
"id",
")",
"theids",
".",
"append",
"(",
"id",
")",
"local_ids",
"=",
"filter",
"(",
"lambda",
"msg_id",
":",
"msg_id",
"in",
"self",
".",
"history",
"or",
"msg_id",
"in",
"self",
".",
"results",
",",
"theids",
")",
"remote_ids",
"=",
"filter",
"(",
"lambda",
"msg_id",
":",
"msg_id",
"not",
"in",
"local_ids",
",",
"theids",
")",
"if",
"remote_ids",
":",
"ar",
"=",
"AsyncHubResult",
"(",
"self",
",",
"msg_ids",
"=",
"theids",
")",
"else",
":",
"ar",
"=",
"AsyncResult",
"(",
"self",
",",
"msg_ids",
"=",
"theids",
")",
"if",
"block",
":",
"ar",
".",
"wait",
"(",
")",
"return",
"ar"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.resubmit | Resubmit one or more tasks.
in-flight tasks may not be resubmitted.
Parameters
----------
indices_or_msg_ids : integer history index, str msg_id, or list of either
The indices or msg_ids of indices to be retrieved
block : bool
Whether to wait for the result to be done
Returns
-------
AsyncHubResult
A subclass of AsyncResult that retrieves results from the Hub | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def resubmit(self, indices_or_msg_ids=None, subheader=None, block=None):
"""Resubmit one or more tasks.
in-flight tasks may not be resubmitted.
Parameters
----------
indices_or_msg_ids : integer history index, str msg_id, or list of either
The indices or msg_ids of indices to be retrieved
block : bool
Whether to wait for the result to be done
Returns
-------
AsyncHubResult
A subclass of AsyncResult that retrieves results from the Hub
"""
block = self.block if block is None else block
if indices_or_msg_ids is None:
indices_or_msg_ids = -1
if not isinstance(indices_or_msg_ids, (list,tuple)):
indices_or_msg_ids = [indices_or_msg_ids]
theids = []
for id in indices_or_msg_ids:
if isinstance(id, int):
id = self.history[id]
if not isinstance(id, basestring):
raise TypeError("indices must be str or int, not %r"%id)
theids.append(id)
content = dict(msg_ids = theids)
self.session.send(self._query_socket, 'resubmit_request', content)
zmq.select([self._query_socket], [], [])
idents,msg = self.session.recv(self._query_socket, zmq.NOBLOCK)
if self.debug:
pprint(msg)
content = msg['content']
if content['status'] != 'ok':
raise self._unwrap_exception(content)
mapping = content['resubmitted']
new_ids = [ mapping[msg_id] for msg_id in theids ]
ar = AsyncHubResult(self, msg_ids=new_ids)
if block:
ar.wait()
return ar | def resubmit(self, indices_or_msg_ids=None, subheader=None, block=None):
"""Resubmit one or more tasks.
in-flight tasks may not be resubmitted.
Parameters
----------
indices_or_msg_ids : integer history index, str msg_id, or list of either
The indices or msg_ids of indices to be retrieved
block : bool
Whether to wait for the result to be done
Returns
-------
AsyncHubResult
A subclass of AsyncResult that retrieves results from the Hub
"""
block = self.block if block is None else block
if indices_or_msg_ids is None:
indices_or_msg_ids = -1
if not isinstance(indices_or_msg_ids, (list,tuple)):
indices_or_msg_ids = [indices_or_msg_ids]
theids = []
for id in indices_or_msg_ids:
if isinstance(id, int):
id = self.history[id]
if not isinstance(id, basestring):
raise TypeError("indices must be str or int, not %r"%id)
theids.append(id)
content = dict(msg_ids = theids)
self.session.send(self._query_socket, 'resubmit_request', content)
zmq.select([self._query_socket], [], [])
idents,msg = self.session.recv(self._query_socket, zmq.NOBLOCK)
if self.debug:
pprint(msg)
content = msg['content']
if content['status'] != 'ok':
raise self._unwrap_exception(content)
mapping = content['resubmitted']
new_ids = [ mapping[msg_id] for msg_id in theids ]
ar = AsyncHubResult(self, msg_ids=new_ids)
if block:
ar.wait()
return ar | [
"Resubmit",
"one",
"or",
"more",
"tasks",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1404-L1459 | [
"def",
"resubmit",
"(",
"self",
",",
"indices_or_msg_ids",
"=",
"None",
",",
"subheader",
"=",
"None",
",",
"block",
"=",
"None",
")",
":",
"block",
"=",
"self",
".",
"block",
"if",
"block",
"is",
"None",
"else",
"block",
"if",
"indices_or_msg_ids",
"is",
"None",
":",
"indices_or_msg_ids",
"=",
"-",
"1",
"if",
"not",
"isinstance",
"(",
"indices_or_msg_ids",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"indices_or_msg_ids",
"=",
"[",
"indices_or_msg_ids",
"]",
"theids",
"=",
"[",
"]",
"for",
"id",
"in",
"indices_or_msg_ids",
":",
"if",
"isinstance",
"(",
"id",
",",
"int",
")",
":",
"id",
"=",
"self",
".",
"history",
"[",
"id",
"]",
"if",
"not",
"isinstance",
"(",
"id",
",",
"basestring",
")",
":",
"raise",
"TypeError",
"(",
"\"indices must be str or int, not %r\"",
"%",
"id",
")",
"theids",
".",
"append",
"(",
"id",
")",
"content",
"=",
"dict",
"(",
"msg_ids",
"=",
"theids",
")",
"self",
".",
"session",
".",
"send",
"(",
"self",
".",
"_query_socket",
",",
"'resubmit_request'",
",",
"content",
")",
"zmq",
".",
"select",
"(",
"[",
"self",
".",
"_query_socket",
"]",
",",
"[",
"]",
",",
"[",
"]",
")",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"self",
".",
"_query_socket",
",",
"zmq",
".",
"NOBLOCK",
")",
"if",
"self",
".",
"debug",
":",
"pprint",
"(",
"msg",
")",
"content",
"=",
"msg",
"[",
"'content'",
"]",
"if",
"content",
"[",
"'status'",
"]",
"!=",
"'ok'",
":",
"raise",
"self",
".",
"_unwrap_exception",
"(",
"content",
")",
"mapping",
"=",
"content",
"[",
"'resubmitted'",
"]",
"new_ids",
"=",
"[",
"mapping",
"[",
"msg_id",
"]",
"for",
"msg_id",
"in",
"theids",
"]",
"ar",
"=",
"AsyncHubResult",
"(",
"self",
",",
"msg_ids",
"=",
"new_ids",
")",
"if",
"block",
":",
"ar",
".",
"wait",
"(",
")",
"return",
"ar"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.result_status | Check on the status of the result(s) of the apply request with `msg_ids`.
If status_only is False, then the actual results will be retrieved, else
only the status of the results will be checked.
Parameters
----------
msg_ids : list of msg_ids
if int:
Passed as index to self.history for convenience.
status_only : bool (default: True)
if False:
Retrieve the actual results of completed tasks.
Returns
-------
results : dict
There will always be the keys 'pending' and 'completed', which will
be lists of msg_ids that are incomplete or complete. If `status_only`
is False, then completed results will be keyed by their `msg_id`. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def result_status(self, msg_ids, status_only=True):
"""Check on the status of the result(s) of the apply request with `msg_ids`.
If status_only is False, then the actual results will be retrieved, else
only the status of the results will be checked.
Parameters
----------
msg_ids : list of msg_ids
if int:
Passed as index to self.history for convenience.
status_only : bool (default: True)
if False:
Retrieve the actual results of completed tasks.
Returns
-------
results : dict
There will always be the keys 'pending' and 'completed', which will
be lists of msg_ids that are incomplete or complete. If `status_only`
is False, then completed results will be keyed by their `msg_id`.
"""
if not isinstance(msg_ids, (list,tuple)):
msg_ids = [msg_ids]
theids = []
for msg_id in msg_ids:
if isinstance(msg_id, int):
msg_id = self.history[msg_id]
if not isinstance(msg_id, basestring):
raise TypeError("msg_ids must be str, not %r"%msg_id)
theids.append(msg_id)
completed = []
local_results = {}
# comment this block out to temporarily disable local shortcut:
for msg_id in theids:
if msg_id in self.results:
completed.append(msg_id)
local_results[msg_id] = self.results[msg_id]
theids.remove(msg_id)
if theids: # some not locally cached
content = dict(msg_ids=theids, status_only=status_only)
msg = self.session.send(self._query_socket, "result_request", content=content)
zmq.select([self._query_socket], [], [])
idents,msg = self.session.recv(self._query_socket, zmq.NOBLOCK)
if self.debug:
pprint(msg)
content = msg['content']
if content['status'] != 'ok':
raise self._unwrap_exception(content)
buffers = msg['buffers']
else:
content = dict(completed=[],pending=[])
content['completed'].extend(completed)
if status_only:
return content
failures = []
# load cached results into result:
content.update(local_results)
# update cache with results:
for msg_id in sorted(theids):
if msg_id in content['completed']:
rec = content[msg_id]
parent = rec['header']
header = rec['result_header']
rcontent = rec['result_content']
iodict = rec['io']
if isinstance(rcontent, str):
rcontent = self.session.unpack(rcontent)
md = self.metadata[msg_id]
md.update(self._extract_metadata(header, parent, rcontent))
if rec.get('received'):
md['received'] = rec['received']
md.update(iodict)
if rcontent['status'] == 'ok':
if header['msg_type'] == 'apply_reply':
res,buffers = util.unserialize_object(buffers)
elif header['msg_type'] == 'execute_reply':
res = ExecuteReply(msg_id, rcontent, md)
else:
raise KeyError("unhandled msg type: %r" % header[msg_type])
else:
res = self._unwrap_exception(rcontent)
failures.append(res)
self.results[msg_id] = res
content[msg_id] = res
if len(theids) == 1 and failures:
raise failures[0]
error.collect_exceptions(failures, "result_status")
return content | def result_status(self, msg_ids, status_only=True):
"""Check on the status of the result(s) of the apply request with `msg_ids`.
If status_only is False, then the actual results will be retrieved, else
only the status of the results will be checked.
Parameters
----------
msg_ids : list of msg_ids
if int:
Passed as index to self.history for convenience.
status_only : bool (default: True)
if False:
Retrieve the actual results of completed tasks.
Returns
-------
results : dict
There will always be the keys 'pending' and 'completed', which will
be lists of msg_ids that are incomplete or complete. If `status_only`
is False, then completed results will be keyed by their `msg_id`.
"""
if not isinstance(msg_ids, (list,tuple)):
msg_ids = [msg_ids]
theids = []
for msg_id in msg_ids:
if isinstance(msg_id, int):
msg_id = self.history[msg_id]
if not isinstance(msg_id, basestring):
raise TypeError("msg_ids must be str, not %r"%msg_id)
theids.append(msg_id)
completed = []
local_results = {}
# comment this block out to temporarily disable local shortcut:
for msg_id in theids:
if msg_id in self.results:
completed.append(msg_id)
local_results[msg_id] = self.results[msg_id]
theids.remove(msg_id)
if theids: # some not locally cached
content = dict(msg_ids=theids, status_only=status_only)
msg = self.session.send(self._query_socket, "result_request", content=content)
zmq.select([self._query_socket], [], [])
idents,msg = self.session.recv(self._query_socket, zmq.NOBLOCK)
if self.debug:
pprint(msg)
content = msg['content']
if content['status'] != 'ok':
raise self._unwrap_exception(content)
buffers = msg['buffers']
else:
content = dict(completed=[],pending=[])
content['completed'].extend(completed)
if status_only:
return content
failures = []
# load cached results into result:
content.update(local_results)
# update cache with results:
for msg_id in sorted(theids):
if msg_id in content['completed']:
rec = content[msg_id]
parent = rec['header']
header = rec['result_header']
rcontent = rec['result_content']
iodict = rec['io']
if isinstance(rcontent, str):
rcontent = self.session.unpack(rcontent)
md = self.metadata[msg_id]
md.update(self._extract_metadata(header, parent, rcontent))
if rec.get('received'):
md['received'] = rec['received']
md.update(iodict)
if rcontent['status'] == 'ok':
if header['msg_type'] == 'apply_reply':
res,buffers = util.unserialize_object(buffers)
elif header['msg_type'] == 'execute_reply':
res = ExecuteReply(msg_id, rcontent, md)
else:
raise KeyError("unhandled msg type: %r" % header[msg_type])
else:
res = self._unwrap_exception(rcontent)
failures.append(res)
self.results[msg_id] = res
content[msg_id] = res
if len(theids) == 1 and failures:
raise failures[0]
error.collect_exceptions(failures, "result_status")
return content | [
"Check",
"on",
"the",
"status",
"of",
"the",
"result",
"(",
"s",
")",
"of",
"the",
"apply",
"request",
"with",
"msg_ids",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1462-L1565 | [
"def",
"result_status",
"(",
"self",
",",
"msg_ids",
",",
"status_only",
"=",
"True",
")",
":",
"if",
"not",
"isinstance",
"(",
"msg_ids",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"msg_ids",
"=",
"[",
"msg_ids",
"]",
"theids",
"=",
"[",
"]",
"for",
"msg_id",
"in",
"msg_ids",
":",
"if",
"isinstance",
"(",
"msg_id",
",",
"int",
")",
":",
"msg_id",
"=",
"self",
".",
"history",
"[",
"msg_id",
"]",
"if",
"not",
"isinstance",
"(",
"msg_id",
",",
"basestring",
")",
":",
"raise",
"TypeError",
"(",
"\"msg_ids must be str, not %r\"",
"%",
"msg_id",
")",
"theids",
".",
"append",
"(",
"msg_id",
")",
"completed",
"=",
"[",
"]",
"local_results",
"=",
"{",
"}",
"# comment this block out to temporarily disable local shortcut:",
"for",
"msg_id",
"in",
"theids",
":",
"if",
"msg_id",
"in",
"self",
".",
"results",
":",
"completed",
".",
"append",
"(",
"msg_id",
")",
"local_results",
"[",
"msg_id",
"]",
"=",
"self",
".",
"results",
"[",
"msg_id",
"]",
"theids",
".",
"remove",
"(",
"msg_id",
")",
"if",
"theids",
":",
"# some not locally cached",
"content",
"=",
"dict",
"(",
"msg_ids",
"=",
"theids",
",",
"status_only",
"=",
"status_only",
")",
"msg",
"=",
"self",
".",
"session",
".",
"send",
"(",
"self",
".",
"_query_socket",
",",
"\"result_request\"",
",",
"content",
"=",
"content",
")",
"zmq",
".",
"select",
"(",
"[",
"self",
".",
"_query_socket",
"]",
",",
"[",
"]",
",",
"[",
"]",
")",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"self",
".",
"_query_socket",
",",
"zmq",
".",
"NOBLOCK",
")",
"if",
"self",
".",
"debug",
":",
"pprint",
"(",
"msg",
")",
"content",
"=",
"msg",
"[",
"'content'",
"]",
"if",
"content",
"[",
"'status'",
"]",
"!=",
"'ok'",
":",
"raise",
"self",
".",
"_unwrap_exception",
"(",
"content",
")",
"buffers",
"=",
"msg",
"[",
"'buffers'",
"]",
"else",
":",
"content",
"=",
"dict",
"(",
"completed",
"=",
"[",
"]",
",",
"pending",
"=",
"[",
"]",
")",
"content",
"[",
"'completed'",
"]",
".",
"extend",
"(",
"completed",
")",
"if",
"status_only",
":",
"return",
"content",
"failures",
"=",
"[",
"]",
"# load cached results into result:",
"content",
".",
"update",
"(",
"local_results",
")",
"# update cache with results:",
"for",
"msg_id",
"in",
"sorted",
"(",
"theids",
")",
":",
"if",
"msg_id",
"in",
"content",
"[",
"'completed'",
"]",
":",
"rec",
"=",
"content",
"[",
"msg_id",
"]",
"parent",
"=",
"rec",
"[",
"'header'",
"]",
"header",
"=",
"rec",
"[",
"'result_header'",
"]",
"rcontent",
"=",
"rec",
"[",
"'result_content'",
"]",
"iodict",
"=",
"rec",
"[",
"'io'",
"]",
"if",
"isinstance",
"(",
"rcontent",
",",
"str",
")",
":",
"rcontent",
"=",
"self",
".",
"session",
".",
"unpack",
"(",
"rcontent",
")",
"md",
"=",
"self",
".",
"metadata",
"[",
"msg_id",
"]",
"md",
".",
"update",
"(",
"self",
".",
"_extract_metadata",
"(",
"header",
",",
"parent",
",",
"rcontent",
")",
")",
"if",
"rec",
".",
"get",
"(",
"'received'",
")",
":",
"md",
"[",
"'received'",
"]",
"=",
"rec",
"[",
"'received'",
"]",
"md",
".",
"update",
"(",
"iodict",
")",
"if",
"rcontent",
"[",
"'status'",
"]",
"==",
"'ok'",
":",
"if",
"header",
"[",
"'msg_type'",
"]",
"==",
"'apply_reply'",
":",
"res",
",",
"buffers",
"=",
"util",
".",
"unserialize_object",
"(",
"buffers",
")",
"elif",
"header",
"[",
"'msg_type'",
"]",
"==",
"'execute_reply'",
":",
"res",
"=",
"ExecuteReply",
"(",
"msg_id",
",",
"rcontent",
",",
"md",
")",
"else",
":",
"raise",
"KeyError",
"(",
"\"unhandled msg type: %r\"",
"%",
"header",
"[",
"msg_type",
"]",
")",
"else",
":",
"res",
"=",
"self",
".",
"_unwrap_exception",
"(",
"rcontent",
")",
"failures",
".",
"append",
"(",
"res",
")",
"self",
".",
"results",
"[",
"msg_id",
"]",
"=",
"res",
"content",
"[",
"msg_id",
"]",
"=",
"res",
"if",
"len",
"(",
"theids",
")",
"==",
"1",
"and",
"failures",
":",
"raise",
"failures",
"[",
"0",
"]",
"error",
".",
"collect_exceptions",
"(",
"failures",
",",
"\"result_status\"",
")",
"return",
"content"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.queue_status | Fetch the status of engine queues.
Parameters
----------
targets : int/str/list of ints/strs
the engines whose states are to be queried.
default : all
verbose : bool
Whether to return lengths only, or lists of ids for each element | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def queue_status(self, targets='all', verbose=False):
"""Fetch the status of engine queues.
Parameters
----------
targets : int/str/list of ints/strs
the engines whose states are to be queried.
default : all
verbose : bool
Whether to return lengths only, or lists of ids for each element
"""
if targets == 'all':
# allow 'all' to be evaluated on the engine
engine_ids = None
else:
engine_ids = self._build_targets(targets)[1]
content = dict(targets=engine_ids, verbose=verbose)
self.session.send(self._query_socket, "queue_request", content=content)
idents,msg = self.session.recv(self._query_socket, 0)
if self.debug:
pprint(msg)
content = msg['content']
status = content.pop('status')
if status != 'ok':
raise self._unwrap_exception(content)
content = rekey(content)
if isinstance(targets, int):
return content[targets]
else:
return content | def queue_status(self, targets='all', verbose=False):
"""Fetch the status of engine queues.
Parameters
----------
targets : int/str/list of ints/strs
the engines whose states are to be queried.
default : all
verbose : bool
Whether to return lengths only, or lists of ids for each element
"""
if targets == 'all':
# allow 'all' to be evaluated on the engine
engine_ids = None
else:
engine_ids = self._build_targets(targets)[1]
content = dict(targets=engine_ids, verbose=verbose)
self.session.send(self._query_socket, "queue_request", content=content)
idents,msg = self.session.recv(self._query_socket, 0)
if self.debug:
pprint(msg)
content = msg['content']
status = content.pop('status')
if status != 'ok':
raise self._unwrap_exception(content)
content = rekey(content)
if isinstance(targets, int):
return content[targets]
else:
return content | [
"Fetch",
"the",
"status",
"of",
"engine",
"queues",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1568-L1598 | [
"def",
"queue_status",
"(",
"self",
",",
"targets",
"=",
"'all'",
",",
"verbose",
"=",
"False",
")",
":",
"if",
"targets",
"==",
"'all'",
":",
"# allow 'all' to be evaluated on the engine",
"engine_ids",
"=",
"None",
"else",
":",
"engine_ids",
"=",
"self",
".",
"_build_targets",
"(",
"targets",
")",
"[",
"1",
"]",
"content",
"=",
"dict",
"(",
"targets",
"=",
"engine_ids",
",",
"verbose",
"=",
"verbose",
")",
"self",
".",
"session",
".",
"send",
"(",
"self",
".",
"_query_socket",
",",
"\"queue_request\"",
",",
"content",
"=",
"content",
")",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"self",
".",
"_query_socket",
",",
"0",
")",
"if",
"self",
".",
"debug",
":",
"pprint",
"(",
"msg",
")",
"content",
"=",
"msg",
"[",
"'content'",
"]",
"status",
"=",
"content",
".",
"pop",
"(",
"'status'",
")",
"if",
"status",
"!=",
"'ok'",
":",
"raise",
"self",
".",
"_unwrap_exception",
"(",
"content",
")",
"content",
"=",
"rekey",
"(",
"content",
")",
"if",
"isinstance",
"(",
"targets",
",",
"int",
")",
":",
"return",
"content",
"[",
"targets",
"]",
"else",
":",
"return",
"content"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.purge_results | Tell the Hub to forget results.
Individual results can be purged by msg_id, or the entire
history of specific targets can be purged.
Use `purge_results('all')` to scrub everything from the Hub's db.
Parameters
----------
jobs : str or list of str or AsyncResult objects
the msg_ids whose results should be forgotten.
targets : int/str/list of ints/strs
The targets, by int_id, whose entire history is to be purged.
default : None | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def purge_results(self, jobs=[], targets=[]):
"""Tell the Hub to forget results.
Individual results can be purged by msg_id, or the entire
history of specific targets can be purged.
Use `purge_results('all')` to scrub everything from the Hub's db.
Parameters
----------
jobs : str or list of str or AsyncResult objects
the msg_ids whose results should be forgotten.
targets : int/str/list of ints/strs
The targets, by int_id, whose entire history is to be purged.
default : None
"""
if not targets and not jobs:
raise ValueError("Must specify at least one of `targets` and `jobs`")
if targets:
targets = self._build_targets(targets)[1]
# construct msg_ids from jobs
if jobs == 'all':
msg_ids = jobs
else:
msg_ids = []
if isinstance(jobs, (basestring,AsyncResult)):
jobs = [jobs]
bad_ids = filter(lambda obj: not isinstance(obj, (basestring, AsyncResult)), jobs)
if bad_ids:
raise TypeError("Invalid msg_id type %r, expected str or AsyncResult"%bad_ids[0])
for j in jobs:
if isinstance(j, AsyncResult):
msg_ids.extend(j.msg_ids)
else:
msg_ids.append(j)
content = dict(engine_ids=targets, msg_ids=msg_ids)
self.session.send(self._query_socket, "purge_request", content=content)
idents, msg = self.session.recv(self._query_socket, 0)
if self.debug:
pprint(msg)
content = msg['content']
if content['status'] != 'ok':
raise self._unwrap_exception(content) | def purge_results(self, jobs=[], targets=[]):
"""Tell the Hub to forget results.
Individual results can be purged by msg_id, or the entire
history of specific targets can be purged.
Use `purge_results('all')` to scrub everything from the Hub's db.
Parameters
----------
jobs : str or list of str or AsyncResult objects
the msg_ids whose results should be forgotten.
targets : int/str/list of ints/strs
The targets, by int_id, whose entire history is to be purged.
default : None
"""
if not targets and not jobs:
raise ValueError("Must specify at least one of `targets` and `jobs`")
if targets:
targets = self._build_targets(targets)[1]
# construct msg_ids from jobs
if jobs == 'all':
msg_ids = jobs
else:
msg_ids = []
if isinstance(jobs, (basestring,AsyncResult)):
jobs = [jobs]
bad_ids = filter(lambda obj: not isinstance(obj, (basestring, AsyncResult)), jobs)
if bad_ids:
raise TypeError("Invalid msg_id type %r, expected str or AsyncResult"%bad_ids[0])
for j in jobs:
if isinstance(j, AsyncResult):
msg_ids.extend(j.msg_ids)
else:
msg_ids.append(j)
content = dict(engine_ids=targets, msg_ids=msg_ids)
self.session.send(self._query_socket, "purge_request", content=content)
idents, msg = self.session.recv(self._query_socket, 0)
if self.debug:
pprint(msg)
content = msg['content']
if content['status'] != 'ok':
raise self._unwrap_exception(content) | [
"Tell",
"the",
"Hub",
"to",
"forget",
"results",
"."
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1601-L1647 | [
"def",
"purge_results",
"(",
"self",
",",
"jobs",
"=",
"[",
"]",
",",
"targets",
"=",
"[",
"]",
")",
":",
"if",
"not",
"targets",
"and",
"not",
"jobs",
":",
"raise",
"ValueError",
"(",
"\"Must specify at least one of `targets` and `jobs`\"",
")",
"if",
"targets",
":",
"targets",
"=",
"self",
".",
"_build_targets",
"(",
"targets",
")",
"[",
"1",
"]",
"# construct msg_ids from jobs",
"if",
"jobs",
"==",
"'all'",
":",
"msg_ids",
"=",
"jobs",
"else",
":",
"msg_ids",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"jobs",
",",
"(",
"basestring",
",",
"AsyncResult",
")",
")",
":",
"jobs",
"=",
"[",
"jobs",
"]",
"bad_ids",
"=",
"filter",
"(",
"lambda",
"obj",
":",
"not",
"isinstance",
"(",
"obj",
",",
"(",
"basestring",
",",
"AsyncResult",
")",
")",
",",
"jobs",
")",
"if",
"bad_ids",
":",
"raise",
"TypeError",
"(",
"\"Invalid msg_id type %r, expected str or AsyncResult\"",
"%",
"bad_ids",
"[",
"0",
"]",
")",
"for",
"j",
"in",
"jobs",
":",
"if",
"isinstance",
"(",
"j",
",",
"AsyncResult",
")",
":",
"msg_ids",
".",
"extend",
"(",
"j",
".",
"msg_ids",
")",
"else",
":",
"msg_ids",
".",
"append",
"(",
"j",
")",
"content",
"=",
"dict",
"(",
"engine_ids",
"=",
"targets",
",",
"msg_ids",
"=",
"msg_ids",
")",
"self",
".",
"session",
".",
"send",
"(",
"self",
".",
"_query_socket",
",",
"\"purge_request\"",
",",
"content",
"=",
"content",
")",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"self",
".",
"_query_socket",
",",
"0",
")",
"if",
"self",
".",
"debug",
":",
"pprint",
"(",
"msg",
")",
"content",
"=",
"msg",
"[",
"'content'",
"]",
"if",
"content",
"[",
"'status'",
"]",
"!=",
"'ok'",
":",
"raise",
"self",
".",
"_unwrap_exception",
"(",
"content",
")"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.hub_history | Get the Hub's history
Just like the Client, the Hub has a history, which is a list of msg_ids.
This will contain the history of all clients, and, depending on configuration,
may contain history across multiple cluster sessions.
Any msg_id returned here is a valid argument to `get_result`.
Returns
-------
msg_ids : list of strs
list of all msg_ids, ordered by task submission time. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def hub_history(self):
"""Get the Hub's history
Just like the Client, the Hub has a history, which is a list of msg_ids.
This will contain the history of all clients, and, depending on configuration,
may contain history across multiple cluster sessions.
Any msg_id returned here is a valid argument to `get_result`.
Returns
-------
msg_ids : list of strs
list of all msg_ids, ordered by task submission time.
"""
self.session.send(self._query_socket, "history_request", content={})
idents, msg = self.session.recv(self._query_socket, 0)
if self.debug:
pprint(msg)
content = msg['content']
if content['status'] != 'ok':
raise self._unwrap_exception(content)
else:
return content['history'] | def hub_history(self):
"""Get the Hub's history
Just like the Client, the Hub has a history, which is a list of msg_ids.
This will contain the history of all clients, and, depending on configuration,
may contain history across multiple cluster sessions.
Any msg_id returned here is a valid argument to `get_result`.
Returns
-------
msg_ids : list of strs
list of all msg_ids, ordered by task submission time.
"""
self.session.send(self._query_socket, "history_request", content={})
idents, msg = self.session.recv(self._query_socket, 0)
if self.debug:
pprint(msg)
content = msg['content']
if content['status'] != 'ok':
raise self._unwrap_exception(content)
else:
return content['history'] | [
"Get",
"the",
"Hub",
"s",
"history"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1650-L1675 | [
"def",
"hub_history",
"(",
"self",
")",
":",
"self",
".",
"session",
".",
"send",
"(",
"self",
".",
"_query_socket",
",",
"\"history_request\"",
",",
"content",
"=",
"{",
"}",
")",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"self",
".",
"_query_socket",
",",
"0",
")",
"if",
"self",
".",
"debug",
":",
"pprint",
"(",
"msg",
")",
"content",
"=",
"msg",
"[",
"'content'",
"]",
"if",
"content",
"[",
"'status'",
"]",
"!=",
"'ok'",
":",
"raise",
"self",
".",
"_unwrap_exception",
"(",
"content",
")",
"else",
":",
"return",
"content",
"[",
"'history'",
"]"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | Client.db_query | Query the Hub's TaskRecord database
This will return a list of task record dicts that match `query`
Parameters
----------
query : mongodb query dict
The search dict. See mongodb query docs for details.
keys : list of strs [optional]
The subset of keys to be returned. The default is to fetch everything but buffers.
'msg_id' will *always* be included. | environment/lib/python2.7/site-packages/IPython/parallel/client/client.py | def db_query(self, query, keys=None):
"""Query the Hub's TaskRecord database
This will return a list of task record dicts that match `query`
Parameters
----------
query : mongodb query dict
The search dict. See mongodb query docs for details.
keys : list of strs [optional]
The subset of keys to be returned. The default is to fetch everything but buffers.
'msg_id' will *always* be included.
"""
if isinstance(keys, basestring):
keys = [keys]
content = dict(query=query, keys=keys)
self.session.send(self._query_socket, "db_request", content=content)
idents, msg = self.session.recv(self._query_socket, 0)
if self.debug:
pprint(msg)
content = msg['content']
if content['status'] != 'ok':
raise self._unwrap_exception(content)
records = content['records']
buffer_lens = content['buffer_lens']
result_buffer_lens = content['result_buffer_lens']
buffers = msg['buffers']
has_bufs = buffer_lens is not None
has_rbufs = result_buffer_lens is not None
for i,rec in enumerate(records):
# relink buffers
if has_bufs:
blen = buffer_lens[i]
rec['buffers'], buffers = buffers[:blen],buffers[blen:]
if has_rbufs:
blen = result_buffer_lens[i]
rec['result_buffers'], buffers = buffers[:blen],buffers[blen:]
return records | def db_query(self, query, keys=None):
"""Query the Hub's TaskRecord database
This will return a list of task record dicts that match `query`
Parameters
----------
query : mongodb query dict
The search dict. See mongodb query docs for details.
keys : list of strs [optional]
The subset of keys to be returned. The default is to fetch everything but buffers.
'msg_id' will *always* be included.
"""
if isinstance(keys, basestring):
keys = [keys]
content = dict(query=query, keys=keys)
self.session.send(self._query_socket, "db_request", content=content)
idents, msg = self.session.recv(self._query_socket, 0)
if self.debug:
pprint(msg)
content = msg['content']
if content['status'] != 'ok':
raise self._unwrap_exception(content)
records = content['records']
buffer_lens = content['buffer_lens']
result_buffer_lens = content['result_buffer_lens']
buffers = msg['buffers']
has_bufs = buffer_lens is not None
has_rbufs = result_buffer_lens is not None
for i,rec in enumerate(records):
# relink buffers
if has_bufs:
blen = buffer_lens[i]
rec['buffers'], buffers = buffers[:blen],buffers[blen:]
if has_rbufs:
blen = result_buffer_lens[i]
rec['result_buffers'], buffers = buffers[:blen],buffers[blen:]
return records | [
"Query",
"the",
"Hub",
"s",
"TaskRecord",
"database"
] | cloud9ers/gurumate | python | https://github.com/cloud9ers/gurumate/blob/075dc74d1ee62a8c6b7a8bf2b271364f01629d1e/environment/lib/python2.7/site-packages/IPython/parallel/client/client.py#L1678-L1719 | [
"def",
"db_query",
"(",
"self",
",",
"query",
",",
"keys",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"keys",
",",
"basestring",
")",
":",
"keys",
"=",
"[",
"keys",
"]",
"content",
"=",
"dict",
"(",
"query",
"=",
"query",
",",
"keys",
"=",
"keys",
")",
"self",
".",
"session",
".",
"send",
"(",
"self",
".",
"_query_socket",
",",
"\"db_request\"",
",",
"content",
"=",
"content",
")",
"idents",
",",
"msg",
"=",
"self",
".",
"session",
".",
"recv",
"(",
"self",
".",
"_query_socket",
",",
"0",
")",
"if",
"self",
".",
"debug",
":",
"pprint",
"(",
"msg",
")",
"content",
"=",
"msg",
"[",
"'content'",
"]",
"if",
"content",
"[",
"'status'",
"]",
"!=",
"'ok'",
":",
"raise",
"self",
".",
"_unwrap_exception",
"(",
"content",
")",
"records",
"=",
"content",
"[",
"'records'",
"]",
"buffer_lens",
"=",
"content",
"[",
"'buffer_lens'",
"]",
"result_buffer_lens",
"=",
"content",
"[",
"'result_buffer_lens'",
"]",
"buffers",
"=",
"msg",
"[",
"'buffers'",
"]",
"has_bufs",
"=",
"buffer_lens",
"is",
"not",
"None",
"has_rbufs",
"=",
"result_buffer_lens",
"is",
"not",
"None",
"for",
"i",
",",
"rec",
"in",
"enumerate",
"(",
"records",
")",
":",
"# relink buffers",
"if",
"has_bufs",
":",
"blen",
"=",
"buffer_lens",
"[",
"i",
"]",
"rec",
"[",
"'buffers'",
"]",
",",
"buffers",
"=",
"buffers",
"[",
":",
"blen",
"]",
",",
"buffers",
"[",
"blen",
":",
"]",
"if",
"has_rbufs",
":",
"blen",
"=",
"result_buffer_lens",
"[",
"i",
"]",
"rec",
"[",
"'result_buffers'",
"]",
",",
"buffers",
"=",
"buffers",
"[",
":",
"blen",
"]",
",",
"buffers",
"[",
"blen",
":",
"]",
"return",
"records"
] | 075dc74d1ee62a8c6b7a8bf2b271364f01629d1e |
test | _opcode_set | Return a set of opcodes by the names in `names`. | virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py | def _opcode_set(*names):
"""Return a set of opcodes by the names in `names`."""
s = set()
for name in names:
try:
s.add(_opcode(name))
except KeyError:
pass
return s | def _opcode_set(*names):
"""Return a set of opcodes by the names in `names`."""
s = set()
for name in names:
try:
s.add(_opcode(name))
except KeyError:
pass
return s | [
"Return",
"a",
"set",
"of",
"opcodes",
"by",
"the",
"names",
"in",
"names",
"."
] | tnkteja/myhelp | python | https://github.com/tnkteja/myhelp/blob/fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb/virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py#L282-L290 | [
"def",
"_opcode_set",
"(",
"*",
"names",
")",
":",
"s",
"=",
"set",
"(",
")",
"for",
"name",
"in",
"names",
":",
"try",
":",
"s",
".",
"add",
"(",
"_opcode",
"(",
"name",
")",
")",
"except",
"KeyError",
":",
"pass",
"return",
"s"
] | fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb |
test | CodeParser._get_byte_parser | Create a ByteParser on demand. | virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py | def _get_byte_parser(self):
"""Create a ByteParser on demand."""
if not self._byte_parser:
self._byte_parser = \
ByteParser(text=self.text, filename=self.filename)
return self._byte_parser | def _get_byte_parser(self):
"""Create a ByteParser on demand."""
if not self._byte_parser:
self._byte_parser = \
ByteParser(text=self.text, filename=self.filename)
return self._byte_parser | [
"Create",
"a",
"ByteParser",
"on",
"demand",
"."
] | tnkteja/myhelp | python | https://github.com/tnkteja/myhelp/blob/fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb/virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py#L69-L74 | [
"def",
"_get_byte_parser",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_byte_parser",
":",
"self",
".",
"_byte_parser",
"=",
"ByteParser",
"(",
"text",
"=",
"self",
".",
"text",
",",
"filename",
"=",
"self",
".",
"filename",
")",
"return",
"self",
".",
"_byte_parser"
] | fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb |
test | CodeParser.lines_matching | Find the lines matching one of a list of regexes.
Returns a set of line numbers, the lines that contain a match for one
of the regexes in `regexes`. The entire line needn't match, just a
part of it. | virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py | def lines_matching(self, *regexes):
"""Find the lines matching one of a list of regexes.
Returns a set of line numbers, the lines that contain a match for one
of the regexes in `regexes`. The entire line needn't match, just a
part of it.
"""
regex_c = re.compile(join_regex(regexes))
matches = set()
for i, ltext in enumerate(self.lines):
if regex_c.search(ltext):
matches.add(i+1)
return matches | def lines_matching(self, *regexes):
"""Find the lines matching one of a list of regexes.
Returns a set of line numbers, the lines that contain a match for one
of the regexes in `regexes`. The entire line needn't match, just a
part of it.
"""
regex_c = re.compile(join_regex(regexes))
matches = set()
for i, ltext in enumerate(self.lines):
if regex_c.search(ltext):
matches.add(i+1)
return matches | [
"Find",
"the",
"lines",
"matching",
"one",
"of",
"a",
"list",
"of",
"regexes",
"."
] | tnkteja/myhelp | python | https://github.com/tnkteja/myhelp/blob/fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb/virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py#L77-L90 | [
"def",
"lines_matching",
"(",
"self",
",",
"*",
"regexes",
")",
":",
"regex_c",
"=",
"re",
".",
"compile",
"(",
"join_regex",
"(",
"regexes",
")",
")",
"matches",
"=",
"set",
"(",
")",
"for",
"i",
",",
"ltext",
"in",
"enumerate",
"(",
"self",
".",
"lines",
")",
":",
"if",
"regex_c",
".",
"search",
"(",
"ltext",
")",
":",
"matches",
".",
"add",
"(",
"i",
"+",
"1",
")",
"return",
"matches"
] | fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb |
test | CodeParser._raw_parse | Parse the source to find the interesting facts about its lines.
A handful of member fields are updated. | virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py | def _raw_parse(self):
"""Parse the source to find the interesting facts about its lines.
A handful of member fields are updated.
"""
# Find lines which match an exclusion pattern.
if self.exclude:
self.excluded = self.lines_matching(self.exclude)
# Tokenize, to find excluded suites, to find docstrings, and to find
# multi-line statements.
indent = 0
exclude_indent = 0
excluding = False
prev_toktype = token.INDENT
first_line = None
empty = True
tokgen = generate_tokens(self.text)
for toktype, ttext, (slineno, _), (elineno, _), ltext in tokgen:
if self.show_tokens: # pragma: not covered
print("%10s %5s %-20r %r" % (
tokenize.tok_name.get(toktype, toktype),
nice_pair((slineno, elineno)), ttext, ltext
))
if toktype == token.INDENT:
indent += 1
elif toktype == token.DEDENT:
indent -= 1
elif toktype == token.NAME and ttext == 'class':
# Class definitions look like branches in the byte code, so
# we need to exclude them. The simplest way is to note the
# lines with the 'class' keyword.
self.classdefs.add(slineno)
elif toktype == token.OP and ttext == ':':
if not excluding and elineno in self.excluded:
# Start excluding a suite. We trigger off of the colon
# token so that the #pragma comment will be recognized on
# the same line as the colon.
exclude_indent = indent
excluding = True
elif toktype == token.STRING and prev_toktype == token.INDENT:
# Strings that are first on an indented line are docstrings.
# (a trick from trace.py in the stdlib.) This works for
# 99.9999% of cases. For the rest (!) see:
# http://stackoverflow.com/questions/1769332/x/1769794#1769794
self.docstrings.update(range(slineno, elineno+1))
elif toktype == token.NEWLINE:
if first_line is not None and elineno != first_line:
# We're at the end of a line, and we've ended on a
# different line than the first line of the statement,
# so record a multi-line range.
rng = (first_line, elineno)
for l in range(first_line, elineno+1):
self.multiline[l] = rng
first_line = None
if ttext.strip() and toktype != tokenize.COMMENT:
# A non-whitespace token.
empty = False
if first_line is None:
# The token is not whitespace, and is the first in a
# statement.
first_line = slineno
# Check whether to end an excluded suite.
if excluding and indent <= exclude_indent:
excluding = False
if excluding:
self.excluded.add(elineno)
prev_toktype = toktype
# Find the starts of the executable statements.
if not empty:
self.statement_starts.update(self.byte_parser._find_statements()) | def _raw_parse(self):
"""Parse the source to find the interesting facts about its lines.
A handful of member fields are updated.
"""
# Find lines which match an exclusion pattern.
if self.exclude:
self.excluded = self.lines_matching(self.exclude)
# Tokenize, to find excluded suites, to find docstrings, and to find
# multi-line statements.
indent = 0
exclude_indent = 0
excluding = False
prev_toktype = token.INDENT
first_line = None
empty = True
tokgen = generate_tokens(self.text)
for toktype, ttext, (slineno, _), (elineno, _), ltext in tokgen:
if self.show_tokens: # pragma: not covered
print("%10s %5s %-20r %r" % (
tokenize.tok_name.get(toktype, toktype),
nice_pair((slineno, elineno)), ttext, ltext
))
if toktype == token.INDENT:
indent += 1
elif toktype == token.DEDENT:
indent -= 1
elif toktype == token.NAME and ttext == 'class':
# Class definitions look like branches in the byte code, so
# we need to exclude them. The simplest way is to note the
# lines with the 'class' keyword.
self.classdefs.add(slineno)
elif toktype == token.OP and ttext == ':':
if not excluding and elineno in self.excluded:
# Start excluding a suite. We trigger off of the colon
# token so that the #pragma comment will be recognized on
# the same line as the colon.
exclude_indent = indent
excluding = True
elif toktype == token.STRING and prev_toktype == token.INDENT:
# Strings that are first on an indented line are docstrings.
# (a trick from trace.py in the stdlib.) This works for
# 99.9999% of cases. For the rest (!) see:
# http://stackoverflow.com/questions/1769332/x/1769794#1769794
self.docstrings.update(range(slineno, elineno+1))
elif toktype == token.NEWLINE:
if first_line is not None and elineno != first_line:
# We're at the end of a line, and we've ended on a
# different line than the first line of the statement,
# so record a multi-line range.
rng = (first_line, elineno)
for l in range(first_line, elineno+1):
self.multiline[l] = rng
first_line = None
if ttext.strip() and toktype != tokenize.COMMENT:
# A non-whitespace token.
empty = False
if first_line is None:
# The token is not whitespace, and is the first in a
# statement.
first_line = slineno
# Check whether to end an excluded suite.
if excluding and indent <= exclude_indent:
excluding = False
if excluding:
self.excluded.add(elineno)
prev_toktype = toktype
# Find the starts of the executable statements.
if not empty:
self.statement_starts.update(self.byte_parser._find_statements()) | [
"Parse",
"the",
"source",
"to",
"find",
"the",
"interesting",
"facts",
"about",
"its",
"lines",
"."
] | tnkteja/myhelp | python | https://github.com/tnkteja/myhelp/blob/fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb/virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py#L92-L167 | [
"def",
"_raw_parse",
"(",
"self",
")",
":",
"# Find lines which match an exclusion pattern.",
"if",
"self",
".",
"exclude",
":",
"self",
".",
"excluded",
"=",
"self",
".",
"lines_matching",
"(",
"self",
".",
"exclude",
")",
"# Tokenize, to find excluded suites, to find docstrings, and to find",
"# multi-line statements.",
"indent",
"=",
"0",
"exclude_indent",
"=",
"0",
"excluding",
"=",
"False",
"prev_toktype",
"=",
"token",
".",
"INDENT",
"first_line",
"=",
"None",
"empty",
"=",
"True",
"tokgen",
"=",
"generate_tokens",
"(",
"self",
".",
"text",
")",
"for",
"toktype",
",",
"ttext",
",",
"(",
"slineno",
",",
"_",
")",
",",
"(",
"elineno",
",",
"_",
")",
",",
"ltext",
"in",
"tokgen",
":",
"if",
"self",
".",
"show_tokens",
":",
"# pragma: not covered",
"print",
"(",
"\"%10s %5s %-20r %r\"",
"%",
"(",
"tokenize",
".",
"tok_name",
".",
"get",
"(",
"toktype",
",",
"toktype",
")",
",",
"nice_pair",
"(",
"(",
"slineno",
",",
"elineno",
")",
")",
",",
"ttext",
",",
"ltext",
")",
")",
"if",
"toktype",
"==",
"token",
".",
"INDENT",
":",
"indent",
"+=",
"1",
"elif",
"toktype",
"==",
"token",
".",
"DEDENT",
":",
"indent",
"-=",
"1",
"elif",
"toktype",
"==",
"token",
".",
"NAME",
"and",
"ttext",
"==",
"'class'",
":",
"# Class definitions look like branches in the byte code, so",
"# we need to exclude them. The simplest way is to note the",
"# lines with the 'class' keyword.",
"self",
".",
"classdefs",
".",
"add",
"(",
"slineno",
")",
"elif",
"toktype",
"==",
"token",
".",
"OP",
"and",
"ttext",
"==",
"':'",
":",
"if",
"not",
"excluding",
"and",
"elineno",
"in",
"self",
".",
"excluded",
":",
"# Start excluding a suite. We trigger off of the colon",
"# token so that the #pragma comment will be recognized on",
"# the same line as the colon.",
"exclude_indent",
"=",
"indent",
"excluding",
"=",
"True",
"elif",
"toktype",
"==",
"token",
".",
"STRING",
"and",
"prev_toktype",
"==",
"token",
".",
"INDENT",
":",
"# Strings that are first on an indented line are docstrings.",
"# (a trick from trace.py in the stdlib.) This works for",
"# 99.9999% of cases. For the rest (!) see:",
"# http://stackoverflow.com/questions/1769332/x/1769794#1769794",
"self",
".",
"docstrings",
".",
"update",
"(",
"range",
"(",
"slineno",
",",
"elineno",
"+",
"1",
")",
")",
"elif",
"toktype",
"==",
"token",
".",
"NEWLINE",
":",
"if",
"first_line",
"is",
"not",
"None",
"and",
"elineno",
"!=",
"first_line",
":",
"# We're at the end of a line, and we've ended on a",
"# different line than the first line of the statement,",
"# so record a multi-line range.",
"rng",
"=",
"(",
"first_line",
",",
"elineno",
")",
"for",
"l",
"in",
"range",
"(",
"first_line",
",",
"elineno",
"+",
"1",
")",
":",
"self",
".",
"multiline",
"[",
"l",
"]",
"=",
"rng",
"first_line",
"=",
"None",
"if",
"ttext",
".",
"strip",
"(",
")",
"and",
"toktype",
"!=",
"tokenize",
".",
"COMMENT",
":",
"# A non-whitespace token.",
"empty",
"=",
"False",
"if",
"first_line",
"is",
"None",
":",
"# The token is not whitespace, and is the first in a",
"# statement.",
"first_line",
"=",
"slineno",
"# Check whether to end an excluded suite.",
"if",
"excluding",
"and",
"indent",
"<=",
"exclude_indent",
":",
"excluding",
"=",
"False",
"if",
"excluding",
":",
"self",
".",
"excluded",
".",
"add",
"(",
"elineno",
")",
"prev_toktype",
"=",
"toktype",
"# Find the starts of the executable statements.",
"if",
"not",
"empty",
":",
"self",
".",
"statement_starts",
".",
"update",
"(",
"self",
".",
"byte_parser",
".",
"_find_statements",
"(",
")",
")"
] | fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb |
test | CodeParser.first_line | Return the first line number of the statement including `line`. | virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py | def first_line(self, line):
"""Return the first line number of the statement including `line`."""
rng = self.multiline.get(line)
if rng:
first_line = rng[0]
else:
first_line = line
return first_line | def first_line(self, line):
"""Return the first line number of the statement including `line`."""
rng = self.multiline.get(line)
if rng:
first_line = rng[0]
else:
first_line = line
return first_line | [
"Return",
"the",
"first",
"line",
"number",
"of",
"the",
"statement",
"including",
"line",
"."
] | tnkteja/myhelp | python | https://github.com/tnkteja/myhelp/blob/fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb/virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py#L169-L176 | [
"def",
"first_line",
"(",
"self",
",",
"line",
")",
":",
"rng",
"=",
"self",
".",
"multiline",
".",
"get",
"(",
"line",
")",
"if",
"rng",
":",
"first_line",
"=",
"rng",
"[",
"0",
"]",
"else",
":",
"first_line",
"=",
"line",
"return",
"first_line"
] | fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb |
test | CodeParser.first_lines | Map the line numbers in `lines` to the correct first line of the
statement.
Skip any line mentioned in any of the sequences in `ignores`.
Returns a set of the first lines. | virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py | def first_lines(self, lines, *ignores):
"""Map the line numbers in `lines` to the correct first line of the
statement.
Skip any line mentioned in any of the sequences in `ignores`.
Returns a set of the first lines.
"""
ignore = set()
for ign in ignores:
ignore.update(ign)
lset = set()
for l in lines:
if l in ignore:
continue
new_l = self.first_line(l)
if new_l not in ignore:
lset.add(new_l)
return lset | def first_lines(self, lines, *ignores):
"""Map the line numbers in `lines` to the correct first line of the
statement.
Skip any line mentioned in any of the sequences in `ignores`.
Returns a set of the first lines.
"""
ignore = set()
for ign in ignores:
ignore.update(ign)
lset = set()
for l in lines:
if l in ignore:
continue
new_l = self.first_line(l)
if new_l not in ignore:
lset.add(new_l)
return lset | [
"Map",
"the",
"line",
"numbers",
"in",
"lines",
"to",
"the",
"correct",
"first",
"line",
"of",
"the",
"statement",
"."
] | tnkteja/myhelp | python | https://github.com/tnkteja/myhelp/blob/fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb/virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py#L178-L197 | [
"def",
"first_lines",
"(",
"self",
",",
"lines",
",",
"*",
"ignores",
")",
":",
"ignore",
"=",
"set",
"(",
")",
"for",
"ign",
"in",
"ignores",
":",
"ignore",
".",
"update",
"(",
"ign",
")",
"lset",
"=",
"set",
"(",
")",
"for",
"l",
"in",
"lines",
":",
"if",
"l",
"in",
"ignore",
":",
"continue",
"new_l",
"=",
"self",
".",
"first_line",
"(",
"l",
")",
"if",
"new_l",
"not",
"in",
"ignore",
":",
"lset",
".",
"add",
"(",
"new_l",
")",
"return",
"lset"
] | fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb |
test | CodeParser.parse_source | Parse source text to find executable lines, excluded lines, etc.
Return values are 1) a set of executable line numbers, and 2) a set of
excluded line numbers.
Reported line numbers are normalized to the first line of multi-line
statements. | virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py | def parse_source(self):
"""Parse source text to find executable lines, excluded lines, etc.
Return values are 1) a set of executable line numbers, and 2) a set of
excluded line numbers.
Reported line numbers are normalized to the first line of multi-line
statements.
"""
try:
self._raw_parse()
except (tokenize.TokenError, IndentationError):
_, tokerr, _ = sys.exc_info()
msg, lineno = tokerr.args
raise NotPython(
"Couldn't parse '%s' as Python source: '%s' at %s" %
(self.filename, msg, lineno)
)
excluded_lines = self.first_lines(self.excluded)
lines = self.first_lines(
self.statement_starts,
excluded_lines,
self.docstrings
)
return lines, excluded_lines | def parse_source(self):
"""Parse source text to find executable lines, excluded lines, etc.
Return values are 1) a set of executable line numbers, and 2) a set of
excluded line numbers.
Reported line numbers are normalized to the first line of multi-line
statements.
"""
try:
self._raw_parse()
except (tokenize.TokenError, IndentationError):
_, tokerr, _ = sys.exc_info()
msg, lineno = tokerr.args
raise NotPython(
"Couldn't parse '%s' as Python source: '%s' at %s" %
(self.filename, msg, lineno)
)
excluded_lines = self.first_lines(self.excluded)
lines = self.first_lines(
self.statement_starts,
excluded_lines,
self.docstrings
)
return lines, excluded_lines | [
"Parse",
"source",
"text",
"to",
"find",
"executable",
"lines",
"excluded",
"lines",
"etc",
"."
] | tnkteja/myhelp | python | https://github.com/tnkteja/myhelp/blob/fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb/virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py#L199-L226 | [
"def",
"parse_source",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"_raw_parse",
"(",
")",
"except",
"(",
"tokenize",
".",
"TokenError",
",",
"IndentationError",
")",
":",
"_",
",",
"tokerr",
",",
"_",
"=",
"sys",
".",
"exc_info",
"(",
")",
"msg",
",",
"lineno",
"=",
"tokerr",
".",
"args",
"raise",
"NotPython",
"(",
"\"Couldn't parse '%s' as Python source: '%s' at %s\"",
"%",
"(",
"self",
".",
"filename",
",",
"msg",
",",
"lineno",
")",
")",
"excluded_lines",
"=",
"self",
".",
"first_lines",
"(",
"self",
".",
"excluded",
")",
"lines",
"=",
"self",
".",
"first_lines",
"(",
"self",
".",
"statement_starts",
",",
"excluded_lines",
",",
"self",
".",
"docstrings",
")",
"return",
"lines",
",",
"excluded_lines"
] | fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb |
test | CodeParser.arcs | Get information about the arcs available in the code.
Returns a sorted list of line number pairs. Line numbers have been
normalized to the first line of multiline statements. | virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py | def arcs(self):
"""Get information about the arcs available in the code.
Returns a sorted list of line number pairs. Line numbers have been
normalized to the first line of multiline statements.
"""
all_arcs = []
for l1, l2 in self.byte_parser._all_arcs():
fl1 = self.first_line(l1)
fl2 = self.first_line(l2)
if fl1 != fl2:
all_arcs.append((fl1, fl2))
return sorted(all_arcs) | def arcs(self):
"""Get information about the arcs available in the code.
Returns a sorted list of line number pairs. Line numbers have been
normalized to the first line of multiline statements.
"""
all_arcs = []
for l1, l2 in self.byte_parser._all_arcs():
fl1 = self.first_line(l1)
fl2 = self.first_line(l2)
if fl1 != fl2:
all_arcs.append((fl1, fl2))
return sorted(all_arcs) | [
"Get",
"information",
"about",
"the",
"arcs",
"available",
"in",
"the",
"code",
"."
] | tnkteja/myhelp | python | https://github.com/tnkteja/myhelp/blob/fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb/virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py#L228-L241 | [
"def",
"arcs",
"(",
"self",
")",
":",
"all_arcs",
"=",
"[",
"]",
"for",
"l1",
",",
"l2",
"in",
"self",
".",
"byte_parser",
".",
"_all_arcs",
"(",
")",
":",
"fl1",
"=",
"self",
".",
"first_line",
"(",
"l1",
")",
"fl2",
"=",
"self",
".",
"first_line",
"(",
"l2",
")",
"if",
"fl1",
"!=",
"fl2",
":",
"all_arcs",
".",
"append",
"(",
"(",
"fl1",
",",
"fl2",
")",
")",
"return",
"sorted",
"(",
"all_arcs",
")"
] | fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb |
test | CodeParser.exit_counts | Get a mapping from line numbers to count of exits from that line.
Excluded lines are excluded. | virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py | def exit_counts(self):
"""Get a mapping from line numbers to count of exits from that line.
Excluded lines are excluded.
"""
excluded_lines = self.first_lines(self.excluded)
exit_counts = {}
for l1, l2 in self.arcs():
if l1 < 0:
# Don't ever report -1 as a line number
continue
if l1 in excluded_lines:
# Don't report excluded lines as line numbers.
continue
if l2 in excluded_lines:
# Arcs to excluded lines shouldn't count.
continue
if l1 not in exit_counts:
exit_counts[l1] = 0
exit_counts[l1] += 1
# Class definitions have one extra exit, so remove one for each:
for l in self.classdefs:
# Ensure key is there: classdefs can include excluded lines.
if l in exit_counts:
exit_counts[l] -= 1
return exit_counts | def exit_counts(self):
"""Get a mapping from line numbers to count of exits from that line.
Excluded lines are excluded.
"""
excluded_lines = self.first_lines(self.excluded)
exit_counts = {}
for l1, l2 in self.arcs():
if l1 < 0:
# Don't ever report -1 as a line number
continue
if l1 in excluded_lines:
# Don't report excluded lines as line numbers.
continue
if l2 in excluded_lines:
# Arcs to excluded lines shouldn't count.
continue
if l1 not in exit_counts:
exit_counts[l1] = 0
exit_counts[l1] += 1
# Class definitions have one extra exit, so remove one for each:
for l in self.classdefs:
# Ensure key is there: classdefs can include excluded lines.
if l in exit_counts:
exit_counts[l] -= 1
return exit_counts | [
"Get",
"a",
"mapping",
"from",
"line",
"numbers",
"to",
"count",
"of",
"exits",
"from",
"that",
"line",
"."
] | tnkteja/myhelp | python | https://github.com/tnkteja/myhelp/blob/fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb/virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py#L244-L272 | [
"def",
"exit_counts",
"(",
"self",
")",
":",
"excluded_lines",
"=",
"self",
".",
"first_lines",
"(",
"self",
".",
"excluded",
")",
"exit_counts",
"=",
"{",
"}",
"for",
"l1",
",",
"l2",
"in",
"self",
".",
"arcs",
"(",
")",
":",
"if",
"l1",
"<",
"0",
":",
"# Don't ever report -1 as a line number",
"continue",
"if",
"l1",
"in",
"excluded_lines",
":",
"# Don't report excluded lines as line numbers.",
"continue",
"if",
"l2",
"in",
"excluded_lines",
":",
"# Arcs to excluded lines shouldn't count.",
"continue",
"if",
"l1",
"not",
"in",
"exit_counts",
":",
"exit_counts",
"[",
"l1",
"]",
"=",
"0",
"exit_counts",
"[",
"l1",
"]",
"+=",
"1",
"# Class definitions have one extra exit, so remove one for each:",
"for",
"l",
"in",
"self",
".",
"classdefs",
":",
"# Ensure key is there: classdefs can include excluded lines.",
"if",
"l",
"in",
"exit_counts",
":",
"exit_counts",
"[",
"l",
"]",
"-=",
"1",
"return",
"exit_counts"
] | fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb |
test | ByteParser.child_parsers | Iterate over all the code objects nested within this one.
The iteration includes `self` as its first value. | virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py | def child_parsers(self):
"""Iterate over all the code objects nested within this one.
The iteration includes `self` as its first value.
"""
children = CodeObjects(self.code)
return [ByteParser(code=c, text=self.text) for c in children] | def child_parsers(self):
"""Iterate over all the code objects nested within this one.
The iteration includes `self` as its first value.
"""
children = CodeObjects(self.code)
return [ByteParser(code=c, text=self.text) for c in children] | [
"Iterate",
"over",
"all",
"the",
"code",
"objects",
"nested",
"within",
"this",
"one",
"."
] | tnkteja/myhelp | python | https://github.com/tnkteja/myhelp/blob/fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb/virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py#L367-L374 | [
"def",
"child_parsers",
"(",
"self",
")",
":",
"children",
"=",
"CodeObjects",
"(",
"self",
".",
"code",
")",
"return",
"[",
"ByteParser",
"(",
"code",
"=",
"c",
",",
"text",
"=",
"self",
".",
"text",
")",
"for",
"c",
"in",
"children",
"]"
] | fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb |
test | ByteParser._bytes_lines | Map byte offsets to line numbers in `code`.
Uses co_lnotab described in Python/compile.c to map byte offsets to
line numbers. Produces a sequence: (b0, l0), (b1, l1), ...
Only byte offsets that correspond to line numbers are included in the
results. | virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py | def _bytes_lines(self):
"""Map byte offsets to line numbers in `code`.
Uses co_lnotab described in Python/compile.c to map byte offsets to
line numbers. Produces a sequence: (b0, l0), (b1, l1), ...
Only byte offsets that correspond to line numbers are included in the
results.
"""
# Adapted from dis.py in the standard library.
byte_increments = bytes_to_ints(self.code.co_lnotab[0::2])
line_increments = bytes_to_ints(self.code.co_lnotab[1::2])
last_line_num = None
line_num = self.code.co_firstlineno
byte_num = 0
for byte_incr, line_incr in zip(byte_increments, line_increments):
if byte_incr:
if line_num != last_line_num:
yield (byte_num, line_num)
last_line_num = line_num
byte_num += byte_incr
line_num += line_incr
if line_num != last_line_num:
yield (byte_num, line_num) | def _bytes_lines(self):
"""Map byte offsets to line numbers in `code`.
Uses co_lnotab described in Python/compile.c to map byte offsets to
line numbers. Produces a sequence: (b0, l0), (b1, l1), ...
Only byte offsets that correspond to line numbers are included in the
results.
"""
# Adapted from dis.py in the standard library.
byte_increments = bytes_to_ints(self.code.co_lnotab[0::2])
line_increments = bytes_to_ints(self.code.co_lnotab[1::2])
last_line_num = None
line_num = self.code.co_firstlineno
byte_num = 0
for byte_incr, line_incr in zip(byte_increments, line_increments):
if byte_incr:
if line_num != last_line_num:
yield (byte_num, line_num)
last_line_num = line_num
byte_num += byte_incr
line_num += line_incr
if line_num != last_line_num:
yield (byte_num, line_num) | [
"Map",
"byte",
"offsets",
"to",
"line",
"numbers",
"in",
"code",
"."
] | tnkteja/myhelp | python | https://github.com/tnkteja/myhelp/blob/fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb/virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py#L376-L401 | [
"def",
"_bytes_lines",
"(",
"self",
")",
":",
"# Adapted from dis.py in the standard library.",
"byte_increments",
"=",
"bytes_to_ints",
"(",
"self",
".",
"code",
".",
"co_lnotab",
"[",
"0",
":",
":",
"2",
"]",
")",
"line_increments",
"=",
"bytes_to_ints",
"(",
"self",
".",
"code",
".",
"co_lnotab",
"[",
"1",
":",
":",
"2",
"]",
")",
"last_line_num",
"=",
"None",
"line_num",
"=",
"self",
".",
"code",
".",
"co_firstlineno",
"byte_num",
"=",
"0",
"for",
"byte_incr",
",",
"line_incr",
"in",
"zip",
"(",
"byte_increments",
",",
"line_increments",
")",
":",
"if",
"byte_incr",
":",
"if",
"line_num",
"!=",
"last_line_num",
":",
"yield",
"(",
"byte_num",
",",
"line_num",
")",
"last_line_num",
"=",
"line_num",
"byte_num",
"+=",
"byte_incr",
"line_num",
"+=",
"line_incr",
"if",
"line_num",
"!=",
"last_line_num",
":",
"yield",
"(",
"byte_num",
",",
"line_num",
")"
] | fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb |
test | ByteParser._find_statements | Find the statements in `self.code`.
Produce a sequence of line numbers that start statements. Recurses
into all code objects reachable from `self.code`. | virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py | def _find_statements(self):
"""Find the statements in `self.code`.
Produce a sequence of line numbers that start statements. Recurses
into all code objects reachable from `self.code`.
"""
for bp in self.child_parsers():
# Get all of the lineno information from this code.
for _, l in bp._bytes_lines():
yield l | def _find_statements(self):
"""Find the statements in `self.code`.
Produce a sequence of line numbers that start statements. Recurses
into all code objects reachable from `self.code`.
"""
for bp in self.child_parsers():
# Get all of the lineno information from this code.
for _, l in bp._bytes_lines():
yield l | [
"Find",
"the",
"statements",
"in",
"self",
".",
"code",
"."
] | tnkteja/myhelp | python | https://github.com/tnkteja/myhelp/blob/fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb/virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py#L403-L413 | [
"def",
"_find_statements",
"(",
"self",
")",
":",
"for",
"bp",
"in",
"self",
".",
"child_parsers",
"(",
")",
":",
"# Get all of the lineno information from this code.",
"for",
"_",
",",
"l",
"in",
"bp",
".",
"_bytes_lines",
"(",
")",
":",
"yield",
"l"
] | fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb |
test | ByteParser._block_stack_repr | Get a string version of `block_stack`, for debugging. | virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py | def _block_stack_repr(self, block_stack):
"""Get a string version of `block_stack`, for debugging."""
blocks = ", ".join(
["(%s, %r)" % (dis.opname[b[0]], b[1]) for b in block_stack]
)
return "[" + blocks + "]" | def _block_stack_repr(self, block_stack):
"""Get a string version of `block_stack`, for debugging."""
blocks = ", ".join(
["(%s, %r)" % (dis.opname[b[0]], b[1]) for b in block_stack]
)
return "[" + blocks + "]" | [
"Get",
"a",
"string",
"version",
"of",
"block_stack",
"for",
"debugging",
"."
] | tnkteja/myhelp | python | https://github.com/tnkteja/myhelp/blob/fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb/virtualEnvironment/lib/python2.7/site-packages/coverage/parser.py#L415-L420 | [
"def",
"_block_stack_repr",
"(",
"self",
",",
"block_stack",
")",
":",
"blocks",
"=",
"\", \"",
".",
"join",
"(",
"[",
"\"(%s, %r)\"",
"%",
"(",
"dis",
".",
"opname",
"[",
"b",
"[",
"0",
"]",
"]",
",",
"b",
"[",
"1",
"]",
")",
"for",
"b",
"in",
"block_stack",
"]",
")",
"return",
"\"[\"",
"+",
"blocks",
"+",
"\"]\""
] | fb3a4809d448ad14d5b2e6ddf2e7e89ad52b71cb |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.