id_within_dataset
int64
1
55.5k
snippet
stringlengths
19
14.2k
tokens
listlengths
6
1.63k
nl
stringlengths
6
352
split_within_dataset
stringclasses
1 value
is_duplicated
bool
2 classes
52,005
def RequiresPackage(package_name): def Decorator(test_function): @functools.wraps(test_function) def Wrapper(*args, **kwargs): try: pkg_resources.get_distribution(package_name) except pkg_resources.DistributionNotFound: raise unittest.SkipTest(('Skipping, package %s not installed' % package_name)) ...
[ "def", "RequiresPackage", "(", "package_name", ")", ":", "def", "Decorator", "(", "test_function", ")", ":", "@", "functools", ".", "wraps", "(", "test_function", ")", "def", "Wrapper", "(", "*", "args", ",", "**", "kwargs", ")", ":", "try", ":", "pkg_re...
skip this test if required package isnt present .
train
false
52,006
@not_implemented_for('directed') def fiedler_vector(G, weight='weight', normalized=False, tol=1e-08, method='tracemin'): if (len(G) < 2): raise nx.NetworkXError('graph has less than two nodes.') G = _preprocess_graph(G, weight) if (not nx.is_connected(G)): raise nx.NetworkXError('graph is not connected.') if (l...
[ "@", "not_implemented_for", "(", "'directed'", ")", "def", "fiedler_vector", "(", "G", ",", "weight", "=", "'weight'", ",", "normalized", "=", "False", ",", "tol", "=", "1e-08", ",", "method", "=", "'tracemin'", ")", ":", "if", "(", "len", "(", "G", ")...
return the fiedler vector of a connected undirected graph .
train
false
52,010
def edgelist_for_workflow_steps(steps): edges = [] steps_to_index = dict(((step, i) for (i, step) in enumerate(steps))) for step in steps: edges.append((steps_to_index[step], steps_to_index[step])) for conn in step.input_connections: edges.append((steps_to_index[conn.output_step], steps_to_index[conn.input_st...
[ "def", "edgelist_for_workflow_steps", "(", "steps", ")", ":", "edges", "=", "[", "]", "steps_to_index", "=", "dict", "(", "(", "(", "step", ",", "i", ")", "for", "(", "i", ",", "step", ")", "in", "enumerate", "(", "steps", ")", ")", ")", "for", "st...
create a list of tuples representing edges between workflowsteps based on associated workflowstepconnections .
train
false
52,012
def dup_lshift(f, n, K): if (not f): return f else: return (f + ([K.zero] * n))
[ "def", "dup_lshift", "(", "f", ",", "n", ",", "K", ")", ":", "if", "(", "not", "f", ")", ":", "return", "f", "else", ":", "return", "(", "f", "+", "(", "[", "K", ".", "zero", "]", "*", "n", ")", ")" ]
efficiently multiply f by x**n in k[x] .
train
false
52,013
def freqs(b, a, worN=None, plot=None): if (worN is None): w = findfreqs(b, a, 200) elif isinstance(worN, int): N = worN w = findfreqs(b, a, N) else: w = worN w = atleast_1d(w) s = (1j * w) h = (polyval(b, s) / polyval(a, s)) if (plot is not None): plot(w, h) return (w, h)
[ "def", "freqs", "(", "b", ",", "a", ",", "worN", "=", "None", ",", "plot", "=", "None", ")", ":", "if", "(", "worN", "is", "None", ")", ":", "w", "=", "findfreqs", "(", "b", ",", "a", ",", "200", ")", "elif", "isinstance", "(", "worN", ",", ...
compute frequency response of analog filter .
train
false
52,014
def getChainMatrixSVG(matrixSVG, xmlElement): matrixSVG = matrixSVG.getOtherTimesSelf(getMatrixSVG(xmlElement).tricomplex) if (xmlElement.parent != None): matrixSVG = getChainMatrixSVG(matrixSVG, xmlElement.parent) return matrixSVG
[ "def", "getChainMatrixSVG", "(", "matrixSVG", ",", "xmlElement", ")", ":", "matrixSVG", "=", "matrixSVG", ".", "getOtherTimesSelf", "(", "getMatrixSVG", "(", "xmlElement", ")", ".", "tricomplex", ")", "if", "(", "xmlElement", ".", "parent", "!=", "None", ")", ...
get chain matrixsvg by svgelement .
train
false
52,015
def ctrl_c(signum, frame): SHUTDOWN_EVENT.set() print_('\nCancelling...') sys.exit(0)
[ "def", "ctrl_c", "(", "signum", ",", "frame", ")", ":", "SHUTDOWN_EVENT", ".", "set", "(", ")", "print_", "(", "'\\nCancelling...'", ")", "sys", ".", "exit", "(", "0", ")" ]
catch ctrl-c key sequence and set a shutdown_event for our threaded operations .
train
false
52,016
def denoms(eq, symbols=None): pot = preorder_traversal(eq) dens = set() for p in pot: den = denom(p) if (den is S.One): continue for d in Mul.make_args(den): dens.add(d) if (not symbols): return dens rv = [] for d in dens: free = d.free_symbols if any(((s in free) for s in symbols)): rv.appen...
[ "def", "denoms", "(", "eq", ",", "symbols", "=", "None", ")", ":", "pot", "=", "preorder_traversal", "(", "eq", ")", "dens", "=", "set", "(", ")", "for", "p", "in", "pot", ":", "den", "=", "denom", "(", "p", ")", "if", "(", "den", "is", "S", ...
return set of all denominators that appear in eq that contain any symbol in iterable symbols; if symbols is none then all denominators will be returned .
train
false
52,017
def Unicode2Str(s, d): return s.encode()
[ "def", "Unicode2Str", "(", "s", ",", "d", ")", ":", "return", "s", ".", "encode", "(", ")" ]
convert a unicode object to a string using the default encoding .
train
false
52,019
@conf.commands.register def p0f(pkt): (db, sig) = packet2p0f(pkt) if db: pb = db.get_base() else: pb = [] if (not pb): warning('p0f base empty.') return [] r = [] max = (len(sig[4].split(',')) + 5) for b in pb: d = p0f_correl(sig, b) if (d == max): r.append((b[6], b[7], (b[1] - pkt[IP].ttl))) ret...
[ "@", "conf", ".", "commands", ".", "register", "def", "p0f", "(", "pkt", ")", ":", "(", "db", ",", "sig", ")", "=", "packet2p0f", "(", "pkt", ")", "if", "db", ":", "pb", "=", "db", ".", "get_base", "(", ")", "else", ":", "pb", "=", "[", "]", ...
passive os fingerprinting: which os emitted this tcp packet ? p0f -> accuracy .
train
true
52,020
def load_ptb_dataset(path='data/ptb/'): print 'Load or Download Penn TreeBank (PTB) dataset > {}'.format(path) filename = 'simple-examples.tgz' url = 'http://www.fit.vutbr.cz/~imikolov/rnnlm/' maybe_download_and_extract(filename, path, url, extract=True) data_path = os.path.join(path, 'simple-examples', 'data') t...
[ "def", "load_ptb_dataset", "(", "path", "=", "'data/ptb/'", ")", ":", "print", "'Load or Download Penn TreeBank (PTB) dataset > {}'", ".", "format", "(", "path", ")", "filename", "=", "'simple-examples.tgz'", "url", "=", "'http://www.fit.vutbr.cz/~imikolov/rnnlm/'", "maybe_...
penn treebank dataset is used in many language modeling papers .
train
true
52,021
def test_successful_update(config_stub, basedir, download_stub, data_tmpdir, tmpdir, win_registry, caplog): config_stub.data = {'content': {'host-block-lists': generic_blocklists(tmpdir), 'host-blocking-enabled': True, 'host-blocking-whitelist': None}} host_blocker = adblock.HostBlocker() host_blocker.adblock_update...
[ "def", "test_successful_update", "(", "config_stub", ",", "basedir", ",", "download_stub", ",", "data_tmpdir", ",", "tmpdir", ",", "win_registry", ",", "caplog", ")", ":", "config_stub", ".", "data", "=", "{", "'content'", ":", "{", "'host-block-lists'", ":", ...
ensure hosts from host-block-lists are blocked after an update .
train
false
52,023
def set_clipboard(text): if (not text): return clipboard = QtWidgets.QApplication.clipboard() clipboard.setText(text, QtGui.QClipboard.Clipboard) clipboard.setText(text, QtGui.QClipboard.Selection) persist_clipboard()
[ "def", "set_clipboard", "(", "text", ")", ":", "if", "(", "not", "text", ")", ":", "return", "clipboard", "=", "QtWidgets", ".", "QApplication", ".", "clipboard", "(", ")", "clipboard", ".", "setText", "(", "text", ",", "QtGui", ".", "QClipboard", ".", ...
sets the copy/paste buffer to text .
train
false
52,024
def cancelRepository(repository): getReadRepository(repository) for setting in repository.displayEntities: if (setting in repository.preferences): setting.setStateToValue()
[ "def", "cancelRepository", "(", "repository", ")", ":", "getReadRepository", "(", "repository", ")", "for", "setting", "in", "repository", ".", "displayEntities", ":", "if", "(", "setting", "in", "repository", ".", "preferences", ")", ":", "setting", ".", "set...
read the repository then set all the entities to the read repository values .
train
false
52,025
def _filter_activity_by_user(activity_list, users=[]): if (not len(users)): return activity_list new_list = [] for activity in activity_list: if (activity.user_id not in users): new_list.append(activity) return new_list
[ "def", "_filter_activity_by_user", "(", "activity_list", ",", "users", "=", "[", "]", ")", ":", "if", "(", "not", "len", "(", "users", ")", ")", ":", "return", "activity_list", "new_list", "=", "[", "]", "for", "activity", "in", "activity_list", ":", "if...
return the given activity_list with activities from the specified users removed .
train
false
52,027
def create_router(name, ext_network=None, admin_state_up=True, profile=None): conn = _auth(profile) return conn.create_router(name, ext_network, admin_state_up)
[ "def", "create_router", "(", "name", ",", "ext_network", "=", "None", ",", "admin_state_up", "=", "True", ",", "profile", "=", "None", ")", ":", "conn", "=", "_auth", "(", "profile", ")", "return", "conn", ".", "create_router", "(", "name", ",", "ext_net...
creates a new router cli example: .
train
true
52,028
def raise_http_conflict_for_instance_invalid_state(exc, action, server_id): attr = exc.kwargs.get('attr') state = exc.kwargs.get('state') if ((attr is not None) and (state is not None)): msg = (_("Cannot '%(action)s' instance %(server_id)s while it is in %(attr)s %(state)s") % {'action': action, 'attr': attr, 'sta...
[ "def", "raise_http_conflict_for_instance_invalid_state", "(", "exc", ",", "action", ",", "server_id", ")", ":", "attr", "=", "exc", ".", "kwargs", ".", "get", "(", "'attr'", ")", "state", "=", "exc", ".", "kwargs", ".", "get", "(", "'state'", ")", "if", ...
return a webob .
train
false
52,029
def random_genome(): alphabet = TestAlphabet() new_genome = '' for letter in range(3): new_genome += random.choice(alphabet.letters) return MutableSeq(new_genome, alphabet)
[ "def", "random_genome", "(", ")", ":", "alphabet", "=", "TestAlphabet", "(", ")", "new_genome", "=", "''", "for", "letter", "in", "range", "(", "3", ")", ":", "new_genome", "+=", "random", ".", "choice", "(", "alphabet", ".", "letters", ")", "return", ...
return a random genome string .
train
false
52,030
def chconfig(cmd, *args, **kwargs): for k in kwargs.keys(): if k.startswith('__pub_'): kwargs.pop(k) if (('dracr.' + cmd) not in __salt__): ret = {'retcode': (-1), 'message': (('dracr.' + cmd) + ' is not available')} else: ret = __salt__[('dracr.' + cmd)](*args, **kwargs) if (cmd == 'change_password'): i...
[ "def", "chconfig", "(", "cmd", ",", "*", "args", ",", "**", "kwargs", ")", ":", "for", "k", "in", "kwargs", ".", "keys", "(", ")", ":", "if", "k", ".", "startswith", "(", "'__pub_'", ")", ":", "kwargs", ".", "pop", "(", "k", ")", "if", "(", "...
this function is called by the :mod:salt .
train
true
52,031
def pythonpath(): return {'pythonpath': sys.path}
[ "def", "pythonpath", "(", ")", ":", "return", "{", "'pythonpath'", ":", "sys", ".", "path", "}" ]
return the python path .
train
false
52,034
@register.filter def docs_url(path_name): return get_docs_url(path_name)
[ "@", "register", ".", "filter", "def", "docs_url", "(", "path_name", ")", ":", "return", "get_docs_url", "(", "path_name", ")" ]
returns the absolute url to path_name in the rtd docs .
train
false
52,035
def demo_grid_with_each_cbar_labelled(fig): grid = ImageGrid(fig, 144, nrows_ncols=(2, 2), axes_pad=(0.45, 0.15), label_mode='1', share_all=True, cbar_location='right', cbar_mode='each', cbar_size='7%', cbar_pad='2%') (Z, extent) = get_demo_image() limits = ((0, 1), ((-2), 2), ((-1.7), 1.4), ((-1.5), 1)) for i in r...
[ "def", "demo_grid_with_each_cbar_labelled", "(", "fig", ")", ":", "grid", "=", "ImageGrid", "(", "fig", ",", "144", ",", "nrows_ncols", "=", "(", "2", ",", "2", ")", ",", "axes_pad", "=", "(", "0.45", ",", "0.15", ")", ",", "label_mode", "=", "'1'", ...
a grid of 2x2 images .
train
false
52,036
def depart_snippet_latex(self, node): pass
[ "def", "depart_snippet_latex", "(", "self", ",", "node", ")", ":", "pass" ]
latex document generator depart handler .
train
false
52,037
def start_request(request_id): with _request_states_lock: _request_states[request_id] = RequestState(request_id)
[ "def", "start_request", "(", "request_id", ")", ":", "with", "_request_states_lock", ":", "_request_states", "[", "request_id", "]", "=", "RequestState", "(", "request_id", ")" ]
starts a request with the provided request id .
train
false
52,038
def revrt(X, m=None): if (m is None): m = len(X) i = int(((m // 2) + 1)) y = (X[:i] + (np.r_[(0, X[i:], 0)] * 1j)) return (np.fft.irfft(y) * m)
[ "def", "revrt", "(", "X", ",", "m", "=", "None", ")", ":", "if", "(", "m", "is", "None", ")", ":", "m", "=", "len", "(", "X", ")", "i", "=", "int", "(", "(", "(", "m", "//", "2", ")", "+", "1", ")", ")", "y", "=", "(", "X", "[", ":"...
inverse of forrt .
train
false
52,039
def wait_started(name, path=None, timeout=300): if (not exists(name, path=path)): raise CommandExecutionError('Container {0} does does exists'.format(name)) if (not (state(name, path=path) == 'running')): raise CommandExecutionError('Container {0} is not running'.format(name)) ret = False if running_systemd(nam...
[ "def", "wait_started", "(", "name", ",", "path", "=", "None", ",", "timeout", "=", "300", ")", ":", "if", "(", "not", "exists", "(", "name", ",", "path", "=", "path", ")", ")", ":", "raise", "CommandExecutionError", "(", "'Container {0} does does exists'",...
check that the system has fully inited this is actually very important for systemd based containers see URL path path to the container parent default: /var/lib/lxc .
train
true
52,040
def three_to_one(s): i = d3_to_index[s] return dindex_to_1[i]
[ "def", "three_to_one", "(", "s", ")", ":", "i", "=", "d3_to_index", "[", "s", "]", "return", "dindex_to_1", "[", "i", "]" ]
three letter code to one letter code .
train
false
52,041
def serialize_type(name, accessor, types): name = name.strip() description = type_description(name, types) if ('struct' in description): return serialize_struct_type(name, accessor, types) elif ('template' in description): return serialize_type_with_template(name, accessor, types) else: cast = description.ge...
[ "def", "serialize_type", "(", "name", ",", "accessor", ",", "types", ")", ":", "name", "=", "name", ".", "strip", "(", ")", "description", "=", "type_description", "(", "name", ",", "types", ")", "if", "(", "'struct'", "in", "description", ")", ":", "r...
returns a serialization statement for the given type .
train
false
52,042
def roles_trans(): roles = {} for role in ROLE_PERMISSIONS: roles[role] = trans_role(role) return roles
[ "def", "roles_trans", "(", ")", ":", "roles", "=", "{", "}", "for", "role", "in", "ROLE_PERMISSIONS", ":", "roles", "[", "role", "]", "=", "trans_role", "(", "role", ")", "return", "roles" ]
return dict of roles with translation .
train
false
52,043
def _check_pandas_index_arguments(index, defaults): if (not any((isinstance(index, k) for k in (list, tuple)))): index = [index] invalid_choices = [e for e in index if (e not in defaults)] if invalid_choices: options = [', '.join(e) for e in [invalid_choices, defaults]] raise ValueError(("[%s] is not an valid ...
[ "def", "_check_pandas_index_arguments", "(", "index", ",", "defaults", ")", ":", "if", "(", "not", "any", "(", "(", "isinstance", "(", "index", ",", "k", ")", "for", "k", "in", "(", "list", ",", "tuple", ")", ")", ")", ")", ":", "index", "=", "[", ...
check pandas index arguments .
train
false
52,045
def create_update_gitdir(): if (not os.path.exists(gitdname)): retcode = subprocess.call(('git clone ' + repo), shell=True, stdout=sys.stdout, stderr=sys.stderr) if (retcode != 0): msg = 'There was a problem cloning the repo' raise Exception(msg) else: shutil.rmtree(gitdname) create_update_gitdir()
[ "def", "create_update_gitdir", "(", ")", ":", "if", "(", "not", "os", ".", "path", ".", "exists", "(", "gitdname", ")", ")", ":", "retcode", "=", "subprocess", ".", "call", "(", "(", "'git clone '", "+", "repo", ")", ",", "shell", "=", "True", ",", ...
creates a directory for local repo if it doesnt exist .
train
false
52,046
def zk_group_path(key): project = key.app() if key.name_space(): namespace = key.name_space() else: namespace = ':default' first_element = key.path().element(0) kind = first_element.type() if first_element.has_id(): suffix = ':{}'.format(first_element.id()) else: suffix = '::{}'.format(first_element.name...
[ "def", "zk_group_path", "(", "key", ")", ":", "project", "=", "key", ".", "app", "(", ")", "if", "key", ".", "name_space", "(", ")", ":", "namespace", "=", "key", ".", "name_space", "(", ")", "else", ":", "namespace", "=", "':default'", "first_element"...
retrieve the zookeeper lock path for a given entity key .
train
false
52,048
def create_linear_initializer(input_size): stddev = (1 / math.sqrt(input_size)) return tf.truncated_normal_initializer(stddev=stddev)
[ "def", "create_linear_initializer", "(", "input_size", ")", ":", "stddev", "=", "(", "1", "/", "math", ".", "sqrt", "(", "input_size", ")", ")", "return", "tf", ".", "truncated_normal_initializer", "(", "stddev", "=", "stddev", ")" ]
returns a default initializer for weights or bias of a linear module .
train
false
52,049
def getProgramsMenuPath(): if (not platform.isWinNT()): return 'C:\\Windows\\Start Menu\\Programs' keyname = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders' hShellFolders = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, keyname, 0, win32con.KEY_READ) return win32api.RegQueryValueEx(hSh...
[ "def", "getProgramsMenuPath", "(", ")", ":", "if", "(", "not", "platform", ".", "isWinNT", "(", ")", ")", ":", "return", "'C:\\\\Windows\\\\Start Menu\\\\Programs'", "keyname", "=", "'SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Explorer\\\\Shell Folders'", "hShellFo...
get the path to the programs menu .
train
false
52,050
def get_cpi(): rdint = vs.random() request = Request((vs.MACRO_URL % (vs.P_TYPE['http'], vs.DOMAINS['sina'], rdint, vs.MACRO_TYPE[1], 0, 600, rdint))) text = urlopen(request, timeout=10).read() text = (text.decode('gbk') if ct.PY3 else text) regSym = re.compile('\\,count:(.*?)\\}') datastr = regSym.findall(text) ...
[ "def", "get_cpi", "(", ")", ":", "rdint", "=", "vs", ".", "random", "(", ")", "request", "=", "Request", "(", "(", "vs", ".", "MACRO_URL", "%", "(", "vs", ".", "P_TYPE", "[", "'http'", "]", ",", "vs", ".", "DOMAINS", "[", "'sina'", "]", ",", "r...
return dataframe month :统计月份 cpi :价格指数 .
train
false
52,051
def tree_lookup_path(lookup_obj, root_sha, path): tree = lookup_obj(root_sha) if (not isinstance(tree, Tree)): raise NotTreeError(root_sha) return tree.lookup_path(lookup_obj, path)
[ "def", "tree_lookup_path", "(", "lookup_obj", ",", "root_sha", ",", "path", ")", ":", "tree", "=", "lookup_obj", "(", "root_sha", ")", "if", "(", "not", "isinstance", "(", "tree", ",", "Tree", ")", ")", ":", "raise", "NotTreeError", "(", "root_sha", ")",...
look up an object in a git tree .
train
false
52,052
def album_for_id(album_id): out = [] for plugin in find_plugins(): res = plugin.album_for_id(album_id) if res: out.append(res) return out
[ "def", "album_for_id", "(", "album_id", ")", ":", "out", "=", "[", "]", "for", "plugin", "in", "find_plugins", "(", ")", ":", "res", "=", "plugin", ".", "album_for_id", "(", "album_id", ")", "if", "res", ":", "out", ".", "append", "(", "res", ")", ...
get albuminfo objects for a given id string .
train
false
52,053
def imsave(fname, arr, format_str=None): return _imread.imsave(fname, arr, formatstr=format_str)
[ "def", "imsave", "(", "fname", ",", "arr", ",", "format_str", "=", "None", ")", ":", "return", "_imread", ".", "imsave", "(", "fname", ",", "arr", ",", "formatstr", "=", "format_str", ")" ]
save an image to disk .
train
false
52,054
def _fixupRandomEncoderParams(params, minVal, maxVal, minResolution): encodersDict = params['modelConfig']['modelParams']['sensorParams']['encoders'] for encoder in encodersDict.itervalues(): if (encoder is not None): if (encoder['type'] == 'RandomDistributedScalarEncoder'): resolution = max(minResolution, (...
[ "def", "_fixupRandomEncoderParams", "(", "params", ",", "minVal", ",", "maxVal", ",", "minResolution", ")", ":", "encodersDict", "=", "params", "[", "'modelConfig'", "]", "[", "'modelParams'", "]", "[", "'sensorParams'", "]", "[", "'encoders'", "]", "for", "en...
given model params .
train
true
52,055
def openstack(registry, xml_parent, data): tag_prefix = 'jenkins.plugins.openstack.compute.' if ('instances' in data): clouds_build_wrapper = XML.SubElement(xml_parent, (tag_prefix + 'JCloudsBuildWrapper')) instances_wrapper = XML.SubElement(clouds_build_wrapper, 'instancesToRun') for instance in data['instance...
[ "def", "openstack", "(", "registry", ",", "xml_parent", ",", "data", ")", ":", "tag_prefix", "=", "'jenkins.plugins.openstack.compute.'", "if", "(", "'instances'", "in", "data", ")", ":", "clouds_build_wrapper", "=", "XML", ".", "SubElement", "(", "xml_parent", ...
yaml: openstack provision slaves from openstack on demand .
train
false
52,056
def is_cache_stale(cache_file, cache_expiration_time, refresh=False): if refresh: return True if (os.path.isfile(cache_file) and (os.path.getsize(cache_file) > 0)): mod_time = os.path.getmtime(cache_file) current_time = time.time() if ((mod_time + cache_expiration_time) > current_time): return False retur...
[ "def", "is_cache_stale", "(", "cache_file", ",", "cache_expiration_time", ",", "refresh", "=", "False", ")", ":", "if", "refresh", ":", "return", "True", "if", "(", "os", ".", "path", ".", "isfile", "(", "cache_file", ")", "and", "(", "os", ".", "path", ...
determines if cache file has expired .
train
false
52,057
def sp(value): return dpi2px(value, 'sp')
[ "def", "sp", "(", "value", ")", ":", "return", "dpi2px", "(", "value", ",", "'sp'", ")" ]
convert from scale-independent pixels to pixels .
train
false
52,058
def selector(module): if (module.params['target'] == 'host'): target = Host(module.params, module) target.site_facts() elif (module.params['target'] == 'hostgroup'): if (module.params['fullpath'] is not None): target = Hostgroup(module.params, module) target.site_facts() else: module.fail_json(msg="P...
[ "def", "selector", "(", "module", ")", ":", "if", "(", "module", ".", "params", "[", "'target'", "]", "==", "'host'", ")", ":", "target", "=", "Host", "(", "module", ".", "params", ",", "module", ")", "target", ".", "site_facts", "(", ")", "elif", ...
figure out which object and which actions to take given the right parameters .
train
false
52,059
def iter_token_lines(tokenlist): line = [] for (token, c) in explode_tokens(tokenlist): line.append((token, c)) if (c == u'\n'): (yield line) line = [] (yield line)
[ "def", "iter_token_lines", "(", "tokenlist", ")", ":", "line", "=", "[", "]", "for", "(", "token", ",", "c", ")", "in", "explode_tokens", "(", "tokenlist", ")", ":", "line", ".", "append", "(", "(", "token", ",", "c", ")", ")", "if", "(", "c", "=...
iterator that yields tokenlists for each line .
train
true
52,061
def _check_orphans(cursor): orphans = cursor.all('\n select username\n from participants\n where not exists (select * from elsewhere where elsewhere.participant=username)\n and not exists (select * from absorptions where archived_as=username)\n ') assert (len(orphans) == 0), 'm...
[ "def", "_check_orphans", "(", "cursor", ")", ":", "orphans", "=", "cursor", ".", "all", "(", "'\\n select username\\n from participants\\n where not exists (select * from elsewhere where elsewhere.participant=username)\\n and not exists (select * from abs...
finds participants that * does not have corresponding elsewhere account * have not been absorbed by other participant these are broken because new participants arise from elsewhere and elsewhere is detached only by take over which makes a note in absorptions if it removes the last elsewhere account .
train
false
52,062
def get_first_day(dt, d_years=0, d_months=0): dt = getdate(dt) (overflow_years, month) = divmod(((dt.month + d_months) - 1), 12) year = ((dt.year + d_years) + overflow_years) return datetime.date(year, (month + 1), 1)
[ "def", "get_first_day", "(", "dt", ",", "d_years", "=", "0", ",", "d_months", "=", "0", ")", ":", "dt", "=", "getdate", "(", "dt", ")", "(", "overflow_years", ",", "month", ")", "=", "divmod", "(", "(", "(", "dt", ".", "month", "+", "d_months", "...
returns the first day of the month for the date specified by date object also adds d_years and d_months if specified .
train
false
52,063
def hex_decoding(t): nums = t[1:].split('%') return ''.join((chr(int(n, 16)) for n in nums))
[ "def", "hex_decoding", "(", "t", ")", ":", "nums", "=", "t", "[", "1", ":", "]", ".", "split", "(", "'%'", ")", "return", "''", ".", "join", "(", "(", "chr", "(", "int", "(", "n", ",", "16", ")", ")", "for", "n", "in", "nums", ")", ")" ]
hex decoding method .
train
false
52,064
def transport_channel_id(transport, is_server, channel_id_type): if (channel_id_type is None): return None if (channel_id_type not in [u'tls-unique']): raise Exception('invalid channel ID type {}'.format(channel_id_type)) if hasattr(transport, '_tlsConnection'): if is_server: tls_finished_msg = transport._t...
[ "def", "transport_channel_id", "(", "transport", ",", "is_server", ",", "channel_id_type", ")", ":", "if", "(", "channel_id_type", "is", "None", ")", ":", "return", "None", "if", "(", "channel_id_type", "not", "in", "[", "u'tls-unique'", "]", ")", ":", "rais...
application-layer user authentication protocols are vulnerable to generic credential forwarding attacks .
train
false
52,066
def _a_encode_bool(value, mapping): return [('0T' if value else '0F')]
[ "def", "_a_encode_bool", "(", "value", ",", "mapping", ")", ":", "return", "[", "(", "'0T'", "if", "value", "else", "'0F'", ")", "]" ]
true --> [0 .
train
false
52,067
def expand_action(data): if isinstance(data, string_types): return (u'{"index":{}}', data) data = data.copy() op_type = data.pop(u'_op_type', u'index') action = {op_type: {}} for key in (u'_index', u'_parent', u'_percolate', u'_routing', u'_timestamp', u'_ttl', u'_type', u'_version', u'_version_type', u'_id', u'...
[ "def", "expand_action", "(", "data", ")", ":", "if", "isinstance", "(", "data", ",", "string_types", ")", ":", "return", "(", "u'{\"index\":{}}'", ",", "data", ")", "data", "=", "data", ".", "copy", "(", ")", "op_type", "=", "data", ".", "pop", "(", ...
from one document or action definition passed in by the user extract the action/data lines needed for elasticsearchs :meth:~elasticsearch .
train
false
52,068
def blue(text, attrib=None): return colorize(text, 'blue', attrib)
[ "def", "blue", "(", "text", ",", "attrib", "=", "None", ")", ":", "return", "colorize", "(", "text", ",", "'blue'", ",", "attrib", ")" ]
wrapper for colorize .
train
false
52,069
def copy_volume(src, dest, size_in_m, blocksize, sync=False, execute=utils.execute, ionice=None, throttle=None, sparse=False): if (isinstance(src, six.string_types) and isinstance(dest, six.string_types)): if (not throttle): throttle = throttling.Throttle.get_default() with throttle.subcommand(src, dest) as thr...
[ "def", "copy_volume", "(", "src", ",", "dest", ",", "size_in_m", ",", "blocksize", ",", "sync", "=", "False", ",", "execute", "=", "utils", ".", "execute", ",", "ionice", "=", "None", ",", "throttle", "=", "None", ",", "sparse", "=", "False", ")", ":...
copy data from the source volume to the destination volume .
train
false
52,070
def quote_query(string): parsed = urlparse(string) string = string.replace(parsed.query, quote(parsed.query, u'/=&'), 1) return string
[ "def", "quote_query", "(", "string", ")", ":", "parsed", "=", "urlparse", "(", "string", ")", "string", "=", "string", ".", "replace", "(", "parsed", ".", "query", ",", "quote", "(", "parsed", ".", "query", ",", "u'/=&'", ")", ",", "1", ")", "return"...
quotes the query parameters .
train
false
52,071
def mutate_image_dict_to_v1(image): visibility = image.pop('visibility') is_image_public = ('public' == visibility) image['is_public'] = is_image_public return image
[ "def", "mutate_image_dict_to_v1", "(", "image", ")", ":", "visibility", "=", "image", ".", "pop", "(", "'visibility'", ")", "is_image_public", "=", "(", "'public'", "==", "visibility", ")", "image", "[", "'is_public'", "]", "=", "is_image_public", "return", "i...
replaces a v2-style image dictionarys visibility member with the equivalent v1-style is_public member .
train
false
52,072
def same(*values): if (not values): return True (first, rest) = (values[0], values[1:]) return all(((value == first) for value in rest))
[ "def", "same", "(", "*", "values", ")", ":", "if", "(", "not", "values", ")", ":", "return", "True", "(", "first", ",", "rest", ")", "=", "(", "values", "[", "0", "]", ",", "values", "[", "1", ":", "]", ")", "return", "all", "(", "(", "(", ...
check if all values in a sequence are equal .
train
true
52,073
def lscsum0(lx): lx = numpy.asarray(lx) bases = lx.max(0) x = numpy.exp((lx - bases)) ssum = x.sum(0) result = (numpy.log(ssum) + bases) try: conventional = numpy.log(numpy.exp(lx).sum(0)) if (not similar(result, conventional)): if (numpy.isinf(conventional).any() and (not numpy.isinf(result).any())): ...
[ "def", "lscsum0", "(", "lx", ")", ":", "lx", "=", "numpy", ".", "asarray", "(", "lx", ")", "bases", "=", "lx", ".", "max", "(", "0", ")", "x", "=", "numpy", ".", "exp", "(", "(", "lx", "-", "bases", ")", ")", "ssum", "=", "x", ".", "sum", ...
accepts log-values as input .
train
true
52,074
def shanks(A, k, n, m=1): table = [A.subs(k, Integer(j)).doit() for j in range(((n + m) + 2))] table2 = table[:] for i in range(1, (m + 1)): for j in range(i, ((n + m) + 1)): (x, y, z) = (table[(j - 1)], table[j], table[(j + 1)]) table2[j] = (((z * x) - (y ** 2)) / ((z + x) - (2 * y))) table = table2[:] r...
[ "def", "shanks", "(", "A", ",", "k", ",", "n", ",", "m", "=", "1", ")", ":", "table", "=", "[", "A", ".", "subs", "(", "k", ",", "Integer", "(", "j", ")", ")", ".", "doit", "(", ")", "for", "j", "in", "range", "(", "(", "(", "n", "+", ...
calculate an approximation for lim k->oo a(k) using the n-term shanks transformation s(a)(n) .
train
false
52,075
def extract_question_values(question, required_fields, is_reviewer): response = {'value': {'type': 'string'}, 'comments': COMMENTS_SCHEMA, 'extra': {'type': 'array'}} if (question.get('type') == 'object'): response['value'] = get_object_jsonschema(question, required_fields, is_reviewer) elif (question.get('type') ...
[ "def", "extract_question_values", "(", "question", ",", "required_fields", ",", "is_reviewer", ")", ":", "response", "=", "{", "'value'", ":", "{", "'type'", ":", "'string'", "}", ",", "'comments'", ":", "COMMENTS_SCHEMA", ",", "'extra'", ":", "{", "'type'", ...
pulls structure for value .
train
false
52,076
def sanitize_separators(value): if settings.USE_L10N: decimal_separator = get_format('DECIMAL_SEPARATOR') if isinstance(value, six.string_types): parts = [] if (decimal_separator in value): (value, decimals) = value.split(decimal_separator, 1) parts.append(decimals) if settings.USE_THOUSAND_SEPARA...
[ "def", "sanitize_separators", "(", "value", ")", ":", "if", "settings", ".", "USE_L10N", ":", "decimal_separator", "=", "get_format", "(", "'DECIMAL_SEPARATOR'", ")", "if", "isinstance", "(", "value", ",", "six", ".", "string_types", ")", ":", "parts", "=", ...
sanitizes a value according to the current decimal and thousand separator setting .
train
false
52,077
def connected_server_and_client(case, server_factory, client_factory): def connect_client(listening_port): return TCP4ClientEndpoint(reactor, '127.0.0.1', listening_port.getHost().port).connect(client_factory) return listen(case, TCP4ServerEndpoint(reactor, 0), server_factory).addCallback(connect_client)
[ "def", "connected_server_and_client", "(", "case", ",", "server_factory", ",", "client_factory", ")", ":", "def", "connect_client", "(", "listening_port", ")", ":", "return", "TCP4ClientEndpoint", "(", "reactor", ",", "'127.0.0.1'", ",", "listening_port", ".", "getH...
create a server and client connected to that server .
train
false
52,078
def _prepare_colorarray(arr): arr = np.asanyarray(arr) if ((arr.ndim not in [3, 4]) or (arr.shape[(-1)] != 3)): msg = ((('the input array must be have a shape == (.., ..,[ ..,] 3)), ' + 'got (') + ', '.join(map(str, arr.shape))) + ')') raise ValueError(msg) return dtype.img_as_float(arr)
[ "def", "_prepare_colorarray", "(", "arr", ")", ":", "arr", "=", "np", ".", "asanyarray", "(", "arr", ")", "if", "(", "(", "arr", ".", "ndim", "not", "in", "[", "3", ",", "4", "]", ")", "or", "(", "arr", ".", "shape", "[", "(", "-", "1", ")", ...
check the shape of the array and convert it to floating point representation .
train
false
52,079
def image_from_x(x): if isinstance(x, type(u'')): return image_from_path(x) if hasattr(x, u'read'): return image_from_data(x.read()) if isinstance(x, (bytes, QImage)): return image_from_data(x) if isinstance(x, bytearray): return image_from_data(bytes(x)) if isinstance(x, QPixmap): return x.toImage() ra...
[ "def", "image_from_x", "(", "x", ")", ":", "if", "isinstance", "(", "x", ",", "type", "(", "u''", ")", ")", ":", "return", "image_from_path", "(", "x", ")", "if", "hasattr", "(", "x", ",", "u'read'", ")", ":", "return", "image_from_data", "(", "x", ...
create an image from a bytestring or a path or a file like object .
train
false
52,080
def test_nospace(): entry = tokenize('(foo(one two))')[0] assert (entry.start_line == 1) assert (entry.start_column == 1) assert (entry.end_line == 1) assert (entry.end_column == 14) entry = entry[1] assert (entry.start_line == 1) assert (entry.start_column == 5) assert (entry.end_line == 1) assert (entry.end...
[ "def", "test_nospace", "(", ")", ":", "entry", "=", "tokenize", "(", "'(foo(one two))'", ")", "[", "0", "]", "assert", "(", "entry", ".", "start_line", "==", "1", ")", "assert", "(", "entry", ".", "start_column", "==", "1", ")", "assert", "(", "entry",...
ensure we can tokenize without spaces if we have to .
train
false
52,082
def add_to_path(path): if (not os.path.isdir(path)): raise RuntimeError('Tried to add nonexisting path') def _samefile(x, y): if (x == y): return True try: return os.path.samefile(x, y) except (IOError, OSError, AttributeError): return False sys.path[:] = [x for x in sys.path if (not _samefile(path,...
[ "def", "add_to_path", "(", "path", ")", ":", "if", "(", "not", "os", ".", "path", ".", "isdir", "(", "path", ")", ")", ":", "raise", "RuntimeError", "(", "'Tried to add nonexisting path'", ")", "def", "_samefile", "(", "x", ",", "y", ")", ":", "if", ...
adds an entry to sys .
train
false
52,083
def _get_info_from_caches(app, env, account, container=None): info = _get_info_from_infocache(env, account, container) if (info is None): info = _get_info_from_memcache(app, env, account, container) return info
[ "def", "_get_info_from_caches", "(", "app", ",", "env", ",", "account", ",", "container", "=", "None", ")", ":", "info", "=", "_get_info_from_infocache", "(", "env", ",", "account", ",", "container", ")", "if", "(", "info", "is", "None", ")", ":", "info"...
get the cached info from env or memcache in that order .
train
false
52,084
def _prompt_choice(var_name, options): choice_map = OrderedDict(((u'{0}'.format(i), value) for (i, value) in enumerate(options, 1) if (value[0] != 'test'))) choices = choice_map.keys() default = u'1' choice_lines = [u'{0} - {1} - {2}'.format(c[0], c[1][0], c[1][1]) for c in choice_map.items()] prompt = u'\n'.join(...
[ "def", "_prompt_choice", "(", "var_name", ",", "options", ")", ":", "choice_map", "=", "OrderedDict", "(", "(", "(", "u'{0}'", ".", "format", "(", "i", ")", ",", "value", ")", "for", "(", "i", ",", "value", ")", "in", "enumerate", "(", "options", ","...
prompt the user to choose between a list of options .
train
false
52,085
def flatten_dict(data, flattened=None, old_key=None): flattened = (flattened or {}) old_key = (old_key or []) for (key, value) in data.iteritems(): new_key = (old_key + [key]) if (isinstance(value, list) and value and isinstance(value[0], dict)): flattened = flatten_list(value, flattened, new_key) else: ...
[ "def", "flatten_dict", "(", "data", ",", "flattened", "=", "None", ",", "old_key", "=", "None", ")", ":", "flattened", "=", "(", "flattened", "or", "{", "}", ")", "old_key", "=", "(", "old_key", "or", "[", "]", ")", "for", "(", "key", ",", "value",...
flatten a dict .
train
false
52,086
@flake8ext def check_assert_called_once_with(logical_line, filename): if ('neutron/tests/' in filename): if ('.assert_called_once_with(' in logical_line): return uncased_line = logical_line.lower().replace('_', '') check_calls = ['.assertcalledonce', '.calledoncewith'] if any((x for x in check_calls if (x i...
[ "@", "flake8ext", "def", "check_assert_called_once_with", "(", "logical_line", ",", "filename", ")", ":", "if", "(", "'neutron/tests/'", "in", "filename", ")", ":", "if", "(", "'.assert_called_once_with('", "in", "logical_line", ")", ":", "return", "uncased_line", ...
n322 - try to detect unintended calls of nonexistent mock methods like: assert_called_once assertcalledoncewith assert_has_called called_once_with .
train
false
52,087
def test_ada_sample_wt_fit(): ada = ADASYN(random_state=RND_SEED) assert_raises(RuntimeError, ada.sample, X, Y)
[ "def", "test_ada_sample_wt_fit", "(", ")", ":", "ada", "=", "ADASYN", "(", "random_state", "=", "RND_SEED", ")", "assert_raises", "(", "RuntimeError", ",", "ada", ".", "sample", ",", "X", ",", "Y", ")" ]
test either if an error is raised when sample is called before fitting .
train
false
52,089
@task.task(ignore_result=True) def retry_open_graph_shares_for_user(user): from django_facebook.models import OpenGraphShare shares = OpenGraphShare.objects.recently_failed().filter(user=user)[:1000] shares = list(shares) logger.info('retrying %s shares for user %s', len(shares), user) for share in shares: retry...
[ "@", "task", ".", "task", "(", "ignore_result", "=", "True", ")", "def", "retry_open_graph_shares_for_user", "(", "user", ")", ":", "from", "django_facebook", ".", "models", "import", "OpenGraphShare", "shares", "=", "OpenGraphShare", ".", "objects", ".", "recen...
we retry the open graph shares for a user when he gets a new access token .
train
false
52,090
@contextmanager def inside_transaction(): savepoint = transaction.savepoint() try: (yield) except Exception: transaction.savepoint_rollback(savepoint) raise else: transaction.savepoint_commit(savepoint)
[ "@", "contextmanager", "def", "inside_transaction", "(", ")", ":", "savepoint", "=", "transaction", ".", "savepoint", "(", ")", "try", ":", "(", "yield", ")", "except", "Exception", ":", "transaction", ".", "savepoint_rollback", "(", "savepoint", ")", "raise",...
perform the database operations inside a transaction .
train
false
52,091
def poly_between(x, ylower, yupper): if any((isinstance(var, np.ma.MaskedArray) for var in [ylower, yupper, x])): numpy = np.ma else: numpy = np Nx = len(x) if (not cbook.iterable(ylower)): ylower = (ylower * numpy.ones(Nx)) if (not cbook.iterable(yupper)): yupper = (yupper * numpy.ones(Nx)) x = numpy.con...
[ "def", "poly_between", "(", "x", ",", "ylower", ",", "yupper", ")", ":", "if", "any", "(", "(", "isinstance", "(", "var", ",", "np", ".", "ma", ".", "MaskedArray", ")", "for", "var", "in", "[", "ylower", ",", "yupper", ",", "x", "]", ")", ")", ...
given a sequence of *x* .
train
false
52,092
def lookupPointer(name, timeout=None): return getResolver().lookupPointer(name, timeout)
[ "def", "lookupPointer", "(", "name", ",", "timeout", "=", "None", ")", ":", "return", "getResolver", "(", ")", ".", "lookupPointer", "(", "name", ",", "timeout", ")" ]
perform a ptr record lookup .
train
false
52,094
def convert_DateProperty(model, prop, kwargs): if (prop.auto_now or prop.auto_now_add): return None kwargs.setdefault('format', '%Y-%m-%d') return f.DateField(**kwargs)
[ "def", "convert_DateProperty", "(", "model", ",", "prop", ",", "kwargs", ")", ":", "if", "(", "prop", ".", "auto_now", "or", "prop", ".", "auto_now_add", ")", ":", "return", "None", "kwargs", ".", "setdefault", "(", "'format'", ",", "'%Y-%m-%d'", ")", "r...
returns a form field for a db .
train
false
52,095
def path_wrapper(func): def wrapped(node, context=None, _func=func, **kwargs): 'wrapper function handling context' if (context is None): context = InferenceContext() context.push(node) yielded = set() for res in _func(node, context, **kwargs): if (res.__class__ is Instance): ares = res._proxied ...
[ "def", "path_wrapper", "(", "func", ")", ":", "def", "wrapped", "(", "node", ",", "context", "=", "None", ",", "_func", "=", "func", ",", "**", "kwargs", ")", ":", "if", "(", "context", "is", "None", ")", ":", "context", "=", "InferenceContext", "(",...
return the given infer function wrapped to handle the path .
train
false
52,096
def rrelu(layer, **kwargs): nonlinearity = getattr(layer, 'nonlinearity', None) if (nonlinearity is not None): layer.nonlinearity = nonlinearities.identity return RandomizedRectifierLayer(layer, **kwargs)
[ "def", "rrelu", "(", "layer", ",", "**", "kwargs", ")", ":", "nonlinearity", "=", "getattr", "(", "layer", ",", "'nonlinearity'", ",", "None", ")", "if", "(", "nonlinearity", "is", "not", "None", ")", ":", "layer", ".", "nonlinearity", "=", "nonlineariti...
convenience function to apply randomized rectify to a given layers output .
train
false
52,098
def isPosInf(value): return ((_sign(value) == 0) and (_exponent(value) == 2047) and _zero_mantissa(value))
[ "def", "isPosInf", "(", "value", ")", ":", "return", "(", "(", "_sign", "(", "value", ")", "==", "0", ")", "and", "(", "_exponent", "(", "value", ")", "==", "2047", ")", "and", "_zero_mantissa", "(", "value", ")", ")" ]
determine if the argument is a ieee 754 positive infinity value .
train
false
52,100
def lookupFor(typeCode): return _fieldsRegistry[typeCode]
[ "def", "lookupFor", "(", "typeCode", ")", ":", "return", "_fieldsRegistry", "[", "typeCode", "]" ]
return field definition class for the given type code .
train
false
52,101
@testing.requires_testing_data def test_label_io_and_time_course_estimates(): stc = read_source_estimate(stc_fname) label = read_label(real_label_fname) stc_label = stc.in_label(label) assert_true((len(stc_label.times) == stc_label.data.shape[1])) assert_true((len(stc_label.vertices[0]) == stc_label.data.shape[0])...
[ "@", "testing", ".", "requires_testing_data", "def", "test_label_io_and_time_course_estimates", "(", ")", ":", "stc", "=", "read_source_estimate", "(", "stc_fname", ")", "label", "=", "read_label", "(", "real_label_fname", ")", "stc_label", "=", "stc", ".", "in_labe...
test io for label + stc files .
train
false
52,102
def _calc_beta(rk, rk_norm, rk1, rk1_norm): rkk1 = (rk1[0] - rk[0]) size = np.sqrt(np.dot(rkk1, rkk1)) rkk1 /= size num = (rk_norm + np.dot(rk, rkk1)) den = (rk1_norm + np.dot(rk1, rkk1)) res = (np.log((num / den)) / size) return res
[ "def", "_calc_beta", "(", "rk", ",", "rk_norm", ",", "rk1", ",", "rk1_norm", ")", ":", "rkk1", "=", "(", "rk1", "[", "0", "]", "-", "rk", "[", "0", "]", ")", "size", "=", "np", ".", "sqrt", "(", "np", ".", "dot", "(", "rkk1", ",", "rkk1", "...
these coefficients are used to calculate the magic vector omega .
train
false
52,103
def base64encode(value): return base64.b64encode(value)
[ "def", "base64encode", "(", "value", ")", ":", "return", "base64", ".", "b64encode", "(", "value", ")" ]
encodes string value from plain to base64 format .
train
false
52,104
def topological_sort_as_sets(dependency_graph): todo = dependency_graph.copy() while todo: current = {node for (node, deps) in todo.items() if (len(deps) == 0)} if (not current): raise ValueError('Cyclic dependency in graph: {}'.format(', '.join((repr(x) for x in todo.items())))) (yield current) todo = {no...
[ "def", "topological_sort_as_sets", "(", "dependency_graph", ")", ":", "todo", "=", "dependency_graph", ".", "copy", "(", ")", "while", "todo", ":", "current", "=", "{", "node", "for", "(", "node", ",", "deps", ")", "in", "todo", ".", "items", "(", ")", ...
variation of kahns algorithm that returns sets .
train
false
52,105
def create_buffer(length): return array.array('B', (_dummy_s * length))
[ "def", "create_buffer", "(", "length", ")", ":", "return", "array", ".", "array", "(", "'B'", ",", "(", "_dummy_s", "*", "length", ")", ")" ]
create a buffer to be passed to a read function .
train
false
52,106
def np_datetime64_compat(s, *args, **kwargs): if (not _np_version_under1p11): s = tz_replacer(s) return np.datetime64(s, *args, **kwargs)
[ "def", "np_datetime64_compat", "(", "s", ",", "*", "args", ",", "**", "kwargs", ")", ":", "if", "(", "not", "_np_version_under1p11", ")", ":", "s", "=", "tz_replacer", "(", "s", ")", "return", "np", ".", "datetime64", "(", "s", ",", "*", "args", ",",...
provide compat for construction of strings to numpy datetime64s with tz-changes in 1 .
train
true
52,108
def _assert_complete_surface(surf): from .source_space import _get_solids tot_angle = 0.0 cm = surf['rr'].mean(axis=0) logger.info(('%s CM is %6.2f %6.2f %6.2f mm' % (_surf_name[surf['id']], (1000 * cm[0]), (1000 * cm[1]), (1000 * cm[2])))) tot_angle = _get_solids(surf['rr'][surf['tris']], cm[np.newaxis, :])[0] i...
[ "def", "_assert_complete_surface", "(", "surf", ")", ":", "from", ".", "source_space", "import", "_get_solids", "tot_angle", "=", "0.0", "cm", "=", "surf", "[", "'rr'", "]", ".", "mean", "(", "axis", "=", "0", ")", "logger", ".", "info", "(", "(", "'%s...
check the sum of solid angles as seen from inside .
train
false
52,109
def GetFeeds(client): feed_service = client.GetService('FeedService', 'v201609') feeds = [] more_pages = True selector = {'fields': ['Id', 'Name', 'Attributes'], 'predicates': [{'field': 'Origin', 'operator': 'EQUALS', 'values': ['USER']}, {'field': 'FeedStatus', 'operator': 'EQUALS', 'values': ['ENABLED']}], 'pagi...
[ "def", "GetFeeds", "(", "client", ")", ":", "feed_service", "=", "client", ".", "GetService", "(", "'FeedService'", ",", "'v201609'", ")", "feeds", "=", "[", "]", "more_pages", "=", "True", "selector", "=", "{", "'fields'", ":", "[", "'Id'", ",", "'Name'...
returns a list of all enabled feeds .
train
true
52,110
@_define_event def post_execute(): pass
[ "@", "_define_event", "def", "post_execute", "(", ")", ":", "pass" ]
fires after code is executed in response to user/frontend action .
train
false
52,112
def cooperate(iterator): return _theCooperator.cooperate(iterator)
[ "def", "cooperate", "(", "iterator", ")", ":", "return", "_theCooperator", ".", "cooperate", "(", "iterator", ")" ]
start running the given iterator as a long-running cooperative task .
train
false
52,114
def local_repo_to_remote(): with lcd(LOGDIR): put(local_path='le.tar.gz', remote_path='') run('tar xzf le.tar.gz')
[ "def", "local_repo_to_remote", "(", ")", ":", "with", "lcd", "(", "LOGDIR", ")", ":", "put", "(", "local_path", "=", "'le.tar.gz'", ",", "remote_path", "=", "''", ")", "run", "(", "'tar xzf le.tar.gz'", ")" ]
copies local tarball of repo to remote .
train
false
52,115
def get_full_dict(lang): if (not lang): return {} if (getattr(frappe.local, u'lang_full_dict', None) is not None): return frappe.local.lang_full_dict frappe.local.lang_full_dict = load_lang(lang) try: user_translations = get_user_translations(lang) except Exception: user_translations = None if user_transl...
[ "def", "get_full_dict", "(", "lang", ")", ":", "if", "(", "not", "lang", ")", ":", "return", "{", "}", "if", "(", "getattr", "(", "frappe", ".", "local", ",", "u'lang_full_dict'", ",", "None", ")", "is", "not", "None", ")", ":", "return", "frappe", ...
load and return the entire translations dictionary for a language from :meth:frape .
train
false
52,116
def unsafe(f): f.unsafe_callable = True return f
[ "def", "unsafe", "(", "f", ")", ":", "f", ".", "unsafe_callable", "=", "True", "return", "f" ]
mark a function or method as unsafe:: @unsafe def delete: pass .
train
false
52,118
def filter_fastq(input_seqs_f, output_seqs_f, seqs_to_keep, negate=False, seqid_f=None): if (seqid_f is None): seqs_to_keep_lookup = {}.fromkeys([seq_id.split()[0] for seq_id in seqs_to_keep]) if (not negate): def keep_seq(seq_id): return (seq_id.split()[0] in seqs_to_keep_lookup) else: def keep_seq(se...
[ "def", "filter_fastq", "(", "input_seqs_f", ",", "output_seqs_f", ",", "seqs_to_keep", ",", "negate", "=", "False", ",", "seqid_f", "=", "None", ")", ":", "if", "(", "seqid_f", "is", "None", ")", ":", "seqs_to_keep_lookup", "=", "{", "}", ".", "fromkeys", ...
write filtered input_seqs to output_seqs_f which contains only seqs_to_keep input_seqs can be the output of parse_fasta or parse_fastq .
train
false
52,123
def ar2lhs(ar): return (- ar[1:])
[ "def", "ar2lhs", "(", "ar", ")", ":", "return", "(", "-", "ar", "[", "1", ":", "]", ")" ]
convert full lagpolynomial into a reduced .
train
false
52,124
def config_from_file(filename, config=None): if config: try: with open(filename, 'w') as fdesc: fdesc.write(json.dumps(config)) except IOError as error: _LOGGER.error('Saving config file failed: %s', error) return False return config elif os.path.isfile(filename): try: with open(filename, 'r')...
[ "def", "config_from_file", "(", "filename", ",", "config", "=", "None", ")", ":", "if", "config", ":", "try", ":", "with", "open", "(", "filename", ",", "'w'", ")", "as", "fdesc", ":", "fdesc", ".", "write", "(", "json", ".", "dumps", "(", "config", ...
small configuration file management function .
train
true
52,125
def read_rels(archive): xml_source = archive.read(ARC_WORKBOOK_RELS) tree = fromstring(xml_source) for element in safe_iterator(tree, ('{%s}Relationship' % PKG_REL_NS)): rId = element.get('Id') pth = element.get('Target') typ = element.get('Type') if pth.startswith('/xl'): pth = pth.replace('/xl', 'xl') ...
[ "def", "read_rels", "(", "archive", ")", ":", "xml_source", "=", "archive", ".", "read", "(", "ARC_WORKBOOK_RELS", ")", "tree", "=", "fromstring", "(", "xml_source", ")", "for", "element", "in", "safe_iterator", "(", "tree", ",", "(", "'{%s}Relationship'", "...
read relationships for a workbook .
train
true
52,126
@transaction.non_atomic_requests @require_POST @ensure_csrf_cookie @cache_control(no_cache=True, no_store=True, must_revalidate=True) @require_level('staff') def get_problem_responses(request, course_id): course_key = CourseKey.from_string(course_id) problem_location = request.POST.get('problem_location', '') try: ...
[ "@", "transaction", ".", "non_atomic_requests", "@", "require_POST", "@", "ensure_csrf_cookie", "@", "cache_control", "(", "no_cache", "=", "True", ",", "no_store", "=", "True", ",", "must_revalidate", "=", "True", ")", "@", "require_level", "(", "'staff'", ")",...
initiate generation of a csv file containing all student answers to a given problem .
train
false
52,127
def _arity(f): if (sys.version_info < (3,)): return len(inspect.getargspec(f)[0]) else: param = inspect.signature(f).parameters.values() return len([p for p in param if (p.kind == p.POSITIONAL_OR_KEYWORD)])
[ "def", "_arity", "(", "f", ")", ":", "if", "(", "sys", ".", "version_info", "<", "(", "3", ",", ")", ")", ":", "return", "len", "(", "inspect", ".", "getargspec", "(", "f", ")", "[", "0", "]", ")", "else", ":", "param", "=", "inspect", ".", "...
python 2 and 3 compatible version that do not raise a deprecation warning .
train
false
52,128
def _format_for_table(plugins): return [[data[u'name'], data[u'version'], data[u'description'], data[u'authors'], data[u'home']] for data in plugins]
[ "def", "_format_for_table", "(", "plugins", ")", ":", "return", "[", "[", "data", "[", "u'name'", "]", ",", "data", "[", "u'version'", "]", ",", "data", "[", "u'description'", "]", ",", "data", "[", "u'authors'", "]", ",", "data", "[", "u'home'", "]", ...
take a list of plugins and format it for the table on the ui .
train
false
52,129
def showFPS(texw, texh): global frames, t0 t = time.time() if ((t - t0) > 1.0): fps = (frames / (t - t0)) titlestr = ('%sx%s texture, %.1f FPS' % (texw, texh, fps)) glfw.glfwSetWindowTitle(window, titlestr) t0 = t frames = 0 frames += 1
[ "def", "showFPS", "(", "texw", ",", "texh", ")", ":", "global", "frames", ",", "t0", "t", "=", "time", ".", "time", "(", ")", "if", "(", "(", "t", "-", "t0", ")", ">", "1.0", ")", ":", "fps", "=", "(", "frames", "/", "(", "t", "-", "t0", ...
showfps - calculate and report texture size and frames per second in the window title bar .
train
false
52,130
def _validate_device_list(data, valid_values=None): if (not data): msg = _('Cannot create a gateway with an empty device list') return msg try: for device in data: err_msg = attributes._validate_dict(device, key_specs={DEVICE_ID_ATTR: {'type:regex': attributes.UUID_PATTERN, 'required': True}, IFACE_NAME_ATTR...
[ "def", "_validate_device_list", "(", "data", ",", "valid_values", "=", "None", ")", ":", "if", "(", "not", "data", ")", ":", "msg", "=", "_", "(", "'Cannot create a gateway with an empty device list'", ")", "return", "msg", "try", ":", "for", "device", "in", ...
validate the list of service definitions .
train
false