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 |
|---|---|---|---|---|---|
26,365 | def cache_userdata(userterm, username, channel_id):
userterm = ''.join([t.strip().lower() for t in userterm.split(' ')])
g.username_query_cache[userterm] = (username, channel_id)
util.dbg('Cache data for username search query "{}": {} ({})'.format(userterm, username, channel_id))
while (len(g.username_query_cache) ... | [
"def",
"cache_userdata",
"(",
"userterm",
",",
"username",
",",
"channel_id",
")",
":",
"userterm",
"=",
"''",
".",
"join",
"(",
"[",
"t",
".",
"strip",
"(",
")",
".",
"lower",
"(",
")",
"for",
"t",
"in",
"userterm",
".",
"split",
"(",
"' '",
")",
... | cache user name and channel id tuple . | train | false |
26,366 | def call_blink(*args, **kwargs):
devices = _get_lights()
pause = kwargs.get('pause', 0)
res = dict()
for dev_id in ((('id' not in kwargs) and sorted(devices.keys())) or _get_devices(kwargs)):
state = devices[str(dev_id)]['state']['on']
_set(dev_id, ((state and Const.LAMP_OFF) or Const.LAMP_ON))
if pause:
t... | [
"def",
"call_blink",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"devices",
"=",
"_get_lights",
"(",
")",
"pause",
"=",
"kwargs",
".",
"get",
"(",
"'pause'",
",",
"0",
")",
"res",
"=",
"dict",
"(",
")",
"for",
"dev_id",
"in",
"(",
"(",
"(",
... | blink a lamp . | train | true |
26,367 | def package_installed(name, ignore_check=False, prevent_pending=False, image=None, restart=False):
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
old = __salt__['dism.installed_packages']()
package_info = __salt__['dism.package_info'](name)
if (package_info['Package Identity'] in old):
ret['co... | [
"def",
"package_installed",
"(",
"name",
",",
"ignore_check",
"=",
"False",
",",
"prevent_pending",
"=",
"False",
",",
"image",
"=",
"None",
",",
"restart",
"=",
"False",
")",
":",
"ret",
"=",
"{",
"'name'",
":",
"name",
",",
"'result'",
":",
"True",
"... | install a package . | train | true |
26,368 | def datetime_to_epoch(dt):
delta = (dt - epoch)
since_epoch = delta.total_seconds()
return since_epoch
| [
"def",
"datetime_to_epoch",
"(",
"dt",
")",
":",
"delta",
"=",
"(",
"dt",
"-",
"epoch",
")",
"since_epoch",
"=",
"delta",
".",
"total_seconds",
"(",
")",
"return",
"since_epoch"
] | convert datetime object to epoch with millisecond accuracy . | train | false |
26,369 | def dhcp_option_def(msg_type):
def f(cls):
_dhcp_option_unpackers[msg_type] = cls.unpack
cls.CODE = msg_type
return cls
return f
| [
"def",
"dhcp_option_def",
"(",
"msg_type",
")",
":",
"def",
"f",
"(",
"cls",
")",
":",
"_dhcp_option_unpackers",
"[",
"msg_type",
"]",
"=",
"cls",
".",
"unpack",
"cls",
".",
"CODE",
"=",
"msg_type",
"return",
"cls",
"return",
"f"
] | dpcp option decorator . | train | false |
26,372 | def logout_required(redirect):
def redirect_func(user):
return user.is_authenticated()
if hasattr(redirect, '__call__'):
return user_access_decorator(redirect_func, redirect_field=None, redirect_url_func=(lambda : reverse('home')))(redirect)
else:
return user_access_decorator(redirect_func, redirect_field=None... | [
"def",
"logout_required",
"(",
"redirect",
")",
":",
"def",
"redirect_func",
"(",
"user",
")",
":",
"return",
"user",
".",
"is_authenticated",
"(",
")",
"if",
"hasattr",
"(",
"redirect",
",",
"'__call__'",
")",
":",
"return",
"user_access_decorator",
"(",
"r... | requires that the user *not* be logged in . | train | false |
26,373 | def IsPathInSubdirectories(filename, subdirectories, normcase=os.path.normcase):
file_dir = normcase(os.path.dirname(os.path.abspath(filename)))
for parent in subdirectories:
fixed_parent = normcase(os.path.abspath(parent))
if (os.path.commonprefix([file_dir, fixed_parent]) == fixed_parent):
return True
retur... | [
"def",
"IsPathInSubdirectories",
"(",
"filename",
",",
"subdirectories",
",",
"normcase",
"=",
"os",
".",
"path",
".",
"normcase",
")",
":",
"file_dir",
"=",
"normcase",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"abspath",
"(",... | determines if a filename is contained within one of a set of directories . | train | false |
26,375 | def p_enum_specifier_3(t):
pass
| [
"def",
"p_enum_specifier_3",
"(",
"t",
")",
":",
"pass"
] | enum_specifier : enum id . | train | false |
26,377 | @snippet
def dataset_delete(client, _):
DATASET_NAME = ('dataset_delete_%d' % (_millis(),))
dataset = client.dataset(DATASET_NAME)
dataset.create()
assert dataset.exists()
dataset.delete()
assert (not dataset.exists())
| [
"@",
"snippet",
"def",
"dataset_delete",
"(",
"client",
",",
"_",
")",
":",
"DATASET_NAME",
"=",
"(",
"'dataset_delete_%d'",
"%",
"(",
"_millis",
"(",
")",
",",
")",
")",
"dataset",
"=",
"client",
".",
"dataset",
"(",
"DATASET_NAME",
")",
"dataset",
".",... | delete a dataset . | train | false |
26,378 | def submit_proctored_exam_results_report(request, course_key, features):
task_type = 'proctored_exam_results_report'
task_class = proctored_exam_results_csv
task_input = {'features': features}
task_key = ''
return submit_task(request, task_type, task_class, course_key, task_input, task_key)
| [
"def",
"submit_proctored_exam_results_report",
"(",
"request",
",",
"course_key",
",",
"features",
")",
":",
"task_type",
"=",
"'proctored_exam_results_report'",
"task_class",
"=",
"proctored_exam_results_csv",
"task_input",
"=",
"{",
"'features'",
":",
"features",
"}",
... | submits a task to generate a html file containing the executive summary report . | train | false |
26,379 | def patch_scenario_with_autoretry(scenario, max_attempts=3):
def scenario_run_with_retries(scenario_run, *args, **kwargs):
for attempt in range(1, (max_attempts + 1)):
if (not scenario_run(*args, **kwargs)):
if (attempt > 1):
message = u'AUTO-RETRY SCENARIO PASSED (after {0} attempts)'
print(message... | [
"def",
"patch_scenario_with_autoretry",
"(",
"scenario",
",",
"max_attempts",
"=",
"3",
")",
":",
"def",
"scenario_run_with_retries",
"(",
"scenario_run",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"for",
"attempt",
"in",
"range",
"(",
"1",
",",
"(",
... | monkey-patches :func:~behave . | train | false |
26,381 | def redefined_by_decorator(node):
if node.decorators:
for decorator in node.decorators.nodes:
if (isinstance(decorator, astroid.Getattr) and (getattr(decorator.expr, 'name', None) == node.name)):
return True
return False
| [
"def",
"redefined_by_decorator",
"(",
"node",
")",
":",
"if",
"node",
".",
"decorators",
":",
"for",
"decorator",
"in",
"node",
".",
"decorators",
".",
"nodes",
":",
"if",
"(",
"isinstance",
"(",
"decorator",
",",
"astroid",
".",
"Getattr",
")",
"and",
"... | return true if the object is a method redefined via decorator . | train | true |
26,382 | def function_exists(FunctionName, region=None, key=None, keyid=None, profile=None):
try:
func = _find_function(FunctionName, region=region, key=key, keyid=keyid, profile=profile)
return {'exists': bool(func)}
except ClientError as e:
return {'error': salt.utils.boto3.get_error(e)}
| [
"def",
"function_exists",
"(",
"FunctionName",
",",
"region",
"=",
"None",
",",
"key",
"=",
"None",
",",
"keyid",
"=",
"None",
",",
"profile",
"=",
"None",
")",
":",
"try",
":",
"func",
"=",
"_find_function",
"(",
"FunctionName",
",",
"region",
"=",
"r... | given a function name . | train | false |
26,383 | def getNewRepository():
return ExportRepository()
| [
"def",
"getNewRepository",
"(",
")",
":",
"return",
"ExportRepository",
"(",
")"
] | get new repository . | train | false |
26,384 | def test_suggestions(keyhint, key_config_stub):
key_config_stub.set_bindings_for('normal', OrderedDict([('aa', 'cmd-aa'), ('ab', 'cmd-ab'), ('aba', 'cmd-aba'), ('abb', 'cmd-abb'), ('xd', 'cmd-xd'), ('xe', 'cmd-xe')]))
keyhint.update_keyhint('normal', 'a')
assert (keyhint.text() == expected_text(('a', 'yellow', 'a', ... | [
"def",
"test_suggestions",
"(",
"keyhint",
",",
"key_config_stub",
")",
":",
"key_config_stub",
".",
"set_bindings_for",
"(",
"'normal'",
",",
"OrderedDict",
"(",
"[",
"(",
"'aa'",
",",
"'cmd-aa'",
")",
",",
"(",
"'ab'",
",",
"'cmd-ab'",
")",
",",
"(",
"'a... | test that keyhints are shown based on a prefix . | train | false |
26,385 | def sh3(cmd):
p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
(out, err) = p.communicate()
retcode = p.returncode
if retcode:
raise CalledProcessError(retcode, cmd)
else:
return (out.rstrip(), err.rstrip())
| [
"def",
"sh3",
"(",
"cmd",
")",
":",
"p",
"=",
"Popen",
"(",
"cmd",
",",
"stdout",
"=",
"PIPE",
",",
"stderr",
"=",
"PIPE",
",",
"shell",
"=",
"True",
")",
"(",
"out",
",",
"err",
")",
"=",
"p",
".",
"communicate",
"(",
")",
"retcode",
"=",
"p... | execute command in a subshell . | train | true |
26,386 | def _list_nodes_full(location=None):
provider = (__active_provider_name__ or 'ec2')
if (':' in provider):
comps = provider.split(':')
provider = comps[0]
params = {'Action': 'DescribeInstances'}
instances = aws.query(params, location=location, provider=provider, opts=__opts__, sigver='4')
if ('error' in instan... | [
"def",
"_list_nodes_full",
"(",
"location",
"=",
"None",
")",
":",
"provider",
"=",
"(",
"__active_provider_name__",
"or",
"'ec2'",
")",
"if",
"(",
"':'",
"in",
"provider",
")",
":",
"comps",
"=",
"provider",
".",
"split",
"(",
"':'",
")",
"provider",
"=... | return a list of the vms that in this location . | train | true |
26,387 | def performance(registry, xml_parent, data):
perf = XML.SubElement(xml_parent, 'hudson.plugins.performance.PerformancePublisher')
perf.set('plugin', 'performance')
types = ['ART', 'MRT', 'PRT']
mappings = [('failed-threshold', 'errorFailedThreshold', 0), ('unstable-threshold', 'errorUnstableThreshold', 0), ('unstab... | [
"def",
"performance",
"(",
"registry",
",",
"xml_parent",
",",
"data",
")",
":",
"perf",
"=",
"XML",
".",
"SubElement",
"(",
"xml_parent",
",",
"'hudson.plugins.performance.PerformancePublisher'",
")",
"perf",
".",
"set",
"(",
"'plugin'",
",",
"'performance'",
"... | returns the performance of a partition . | train | false |
26,388 | def _where(filename, dirs=[], env='PATH'):
if (not isinstance(dirs, list)):
dirs = [dirs]
if glob(filename):
return filename
paths = (([os.curdir] + os.environ[env].split(os.path.pathsep)) + dirs)
for path in paths:
for match in glob(os.path.join(path, filename)):
if match:
return os.path.normpath(matc... | [
"def",
"_where",
"(",
"filename",
",",
"dirs",
"=",
"[",
"]",
",",
"env",
"=",
"'PATH'",
")",
":",
"if",
"(",
"not",
"isinstance",
"(",
"dirs",
",",
"list",
")",
")",
":",
"dirs",
"=",
"[",
"dirs",
"]",
"if",
"glob",
"(",
"filename",
")",
":",
... | find file in current dir or system path . | train | true |
26,389 | def _netstat_route_linux():
ret = []
cmd = 'netstat -A inet -rn | tail -n+3'
out = __salt__['cmd.run'](cmd, python_shell=True)
for line in out.splitlines():
comps = line.split()
ret.append({'addr_family': 'inet', 'destination': comps[0], 'gateway': comps[1], 'netmask': comps[2], 'flags': comps[3], 'interface': ... | [
"def",
"_netstat_route_linux",
"(",
")",
":",
"ret",
"=",
"[",
"]",
"cmd",
"=",
"'netstat -A inet -rn | tail -n+3'",
"out",
"=",
"__salt__",
"[",
"'cmd.run'",
"]",
"(",
"cmd",
",",
"python_shell",
"=",
"True",
")",
"for",
"line",
"in",
"out",
".",
"splitli... | return netstat routing information for linux distros . | train | true |
26,390 | def system():
try:
import platform
print 'System : ', platform.system()
print 'OS version : ', platform.version()
print 'Python version :', platform.python_version()
try:
from cv2 import __version__
print ('Open CV version : ' + __version__)
except ImportError:
print ('Open CV2 version : ' + '2.1'... | [
"def",
"system",
"(",
")",
":",
"try",
":",
"import",
"platform",
"print",
"'System : '",
",",
"platform",
".",
"system",
"(",
")",
"print",
"'OS version : '",
",",
"platform",
".",
"version",
"(",
")",
"print",
"'Python version :'",
",",
"platform",
".",
... | returns the system/os name . | train | false |
26,391 | @config.change_filter('aliases', function=True)
def _update_aliases():
update([usertypes.Completion.command])
| [
"@",
"config",
".",
"change_filter",
"(",
"'aliases'",
",",
"function",
"=",
"True",
")",
"def",
"_update_aliases",
"(",
")",
":",
"update",
"(",
"[",
"usertypes",
".",
"Completion",
".",
"command",
"]",
")"
] | update completions that include command aliases . | train | false |
26,393 | def get_id(opts, cache_minion_id=False):
if (opts['root_dir'] is None):
root_dir = salt.syspaths.ROOT_DIR
else:
root_dir = opts['root_dir']
config_dir = salt.syspaths.CONFIG_DIR
if config_dir.startswith(salt.syspaths.ROOT_DIR):
config_dir = config_dir.split(salt.syspaths.ROOT_DIR, 1)[(-1)]
id_cache = os.path... | [
"def",
"get_id",
"(",
"opts",
",",
"cache_minion_id",
"=",
"False",
")",
":",
"if",
"(",
"opts",
"[",
"'root_dir'",
"]",
"is",
"None",
")",
":",
"root_dir",
"=",
"salt",
".",
"syspaths",
".",
"ROOT_DIR",
"else",
":",
"root_dir",
"=",
"opts",
"[",
"'r... | given vpc properties . | train | true |
26,394 | def key_id_or_name_as_string_n(index):
def transform_function(key):
id_or_name = _key_id_or_name_n(key, index)
if (not id_or_name):
return u''
return unicode(id_or_name)
return transform_function
| [
"def",
"key_id_or_name_as_string_n",
"(",
"index",
")",
":",
"def",
"transform_function",
"(",
"key",
")",
":",
"id_or_name",
"=",
"_key_id_or_name_n",
"(",
"key",
",",
"index",
")",
"if",
"(",
"not",
"id_or_name",
")",
":",
"return",
"u''",
"return",
"unico... | pull out the nth key id or name from a key which has parents . | train | false |
26,395 | def is_interactive():
return _is_interactive
| [
"def",
"is_interactive",
"(",
")",
":",
"return",
"_is_interactive"
] | return true if plot mode is interactive . | train | false |
26,396 | def is_shutting_down():
with __shutdown_mutex:
shutting_down = __shuting_down
return shutting_down
| [
"def",
"is_shutting_down",
"(",
")",
":",
"with",
"__shutdown_mutex",
":",
"shutting_down",
"=",
"__shuting_down",
"return",
"shutting_down"
] | returns true if the server is shutting down . | train | false |
26,397 | def jsbeautify(javascript):
if (not HAVE_JSBEAUTIFIER):
return javascript
with _jsbeautify_lock:
(origout, sys.stdout) = (sys.stdout, StringIO())
javascript = jsbeautifier.beautify(javascript)
if (sys.stdout.getvalue() not in _jsbeautify_blacklist):
log.warning('jsbeautifier returned error: %s', sys.stdout... | [
"def",
"jsbeautify",
"(",
"javascript",
")",
":",
"if",
"(",
"not",
"HAVE_JSBEAUTIFIER",
")",
":",
"return",
"javascript",
"with",
"_jsbeautify_lock",
":",
"(",
"origout",
",",
"sys",
".",
"stdout",
")",
"=",
"(",
"sys",
".",
"stdout",
",",
"StringIO",
"... | beautifies javascript through jsbeautifier and ignore some messages . | train | false |
26,398 | def emails_with_users_and_watches(subject, text_template, html_template, context_vars, users_and_watches, from_email=settings.TIDINGS_FROM_ADDRESS, default_locale=settings.WIKI_DEFAULT_LANGUAGE, **extra_kwargs):
@safe_translation
def _make_mail(locale, user, watch):
context_vars['user'] = user
context_vars['watch... | [
"def",
"emails_with_users_and_watches",
"(",
"subject",
",",
"text_template",
",",
"html_template",
",",
"context_vars",
",",
"users_and_watches",
",",
"from_email",
"=",
"settings",
".",
"TIDINGS_FROM_ADDRESS",
",",
"default_locale",
"=",
"settings",
".",
"WIKI_DEFAULT... | return iterable of emailmessages with user and watch values substituted . | train | false |
26,400 | def get_slotname(slot, host=None, admin_username=None, admin_password=None):
slots = list_slotnames(host=host, admin_username=admin_username, admin_password=admin_password)
slot = str(slot)
return slots[slot]['slotname']
| [
"def",
"get_slotname",
"(",
"slot",
",",
"host",
"=",
"None",
",",
"admin_username",
"=",
"None",
",",
"admin_password",
"=",
"None",
")",
":",
"slots",
"=",
"list_slotnames",
"(",
"host",
"=",
"host",
",",
"admin_username",
"=",
"admin_username",
",",
"ad... | get the name of a slot number in the chassis . | train | false |
26,401 | def find_item_at(scene, pos, order=Qt.DescendingOrder, type=None, name=None):
items = scene.items(pos, Qt.IntersectsItemShape, order)
for item in items:
if ((type is not None) and (not isinstance(item, type))):
continue
if ((name is not None) and isinstance(item, QObject) and (item.objectName() != name)):
c... | [
"def",
"find_item_at",
"(",
"scene",
",",
"pos",
",",
"order",
"=",
"Qt",
".",
"DescendingOrder",
",",
"type",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"items",
"=",
"scene",
".",
"items",
"(",
"pos",
",",
"Qt",
".",
"IntersectsItemShape",
",... | find an object in a :class:qgraphicsscene scene at pos . | train | false |
26,404 | def undeploy(jboss_config, deployment):
log.debug('======================== MODULE FUNCTION: jboss7.undeploy, deployment=%s', deployment)
command = 'undeploy {deployment} '.format(deployment=deployment)
return __salt__['jboss7_cli.run_command'](jboss_config, command)
| [
"def",
"undeploy",
"(",
"jboss_config",
",",
"deployment",
")",
":",
"log",
".",
"debug",
"(",
"'======================== MODULE FUNCTION: jboss7.undeploy, deployment=%s'",
",",
"deployment",
")",
"command",
"=",
"'undeploy {deployment} '",
".",
"format",
"(",
"deployment... | undeploy a webapp app the webapp context path url : URL the url of the server manager webapp timeout : 180 timeout for http request cli examples: . | train | true |
26,405 | def dictOf(key, value):
return Dict(ZeroOrMore(Group((key + value))))
| [
"def",
"dictOf",
"(",
"key",
",",
"value",
")",
":",
"return",
"Dict",
"(",
"ZeroOrMore",
"(",
"Group",
"(",
"(",
"key",
"+",
"value",
")",
")",
")",
")"
] | helper to easily and clearly define a dictionary by specifying the respective patterns for the key and value . | train | false |
26,406 | def _parse_task_syslog(lines):
result = {}
for record in _parse_hadoop_log4j_records(lines):
message = record['message']
m = _OPENING_FOR_READING_RE.match(message)
if m:
result['split'] = dict(path=m.group('path'))
continue
m = _YARN_INPUT_SPLIT_RE.match(message)
if m:
result['split'] = dict(path=m... | [
"def",
"_parse_task_syslog",
"(",
"lines",
")",
":",
"result",
"=",
"{",
"}",
"for",
"record",
"in",
"_parse_hadoop_log4j_records",
"(",
"lines",
")",
":",
"message",
"=",
"record",
"[",
"'message'",
"]",
"m",
"=",
"_OPENING_FOR_READING_RE",
".",
"match",
"(... | parse an error out of a syslog file . | train | false |
26,407 | def loopbackTLSConnectionInMemory(trustRoot, privateKey, serverCertificate, clientProtocols=None, serverProtocols=None, clientOptions=None):
if (clientOptions is None):
clientOptions = sslverify.OpenSSLCertificateOptions
clientCertOpts = clientOptions(trustRoot=trustRoot, acceptableProtocols=clientProtocols)
serve... | [
"def",
"loopbackTLSConnectionInMemory",
"(",
"trustRoot",
",",
"privateKey",
",",
"serverCertificate",
",",
"clientProtocols",
"=",
"None",
",",
"serverProtocols",
"=",
"None",
",",
"clientOptions",
"=",
"None",
")",
":",
"if",
"(",
"clientOptions",
"is",
"None",
... | create a loopback tls connection with the given trust and keys . | train | false |
26,408 | def shared_cluster_internal():
global _shared_cluster
if (_shared_cluster is None):
_shared_cluster = MiniHadoopCluster()
_shared_cluster.start()
atexit.register(_shared_cluster.stop)
return _shared_cluster
| [
"def",
"shared_cluster_internal",
"(",
")",
":",
"global",
"_shared_cluster",
"if",
"(",
"_shared_cluster",
"is",
"None",
")",
":",
"_shared_cluster",
"=",
"MiniHadoopCluster",
"(",
")",
"_shared_cluster",
".",
"start",
"(",
")",
"atexit",
".",
"register",
"(",
... | manages _shared_cluster . | train | false |
26,410 | def get_installed_tool_shed_repository(app, id):
rval = []
if isinstance(id, list):
return_list = True
else:
id = [id]
return_list = False
for i in id:
rval.append(app.install_model.context.query(app.install_model.ToolShedRepository).get(app.security.decode_id(i)))
if return_list:
return rval
return rva... | [
"def",
"get_installed_tool_shed_repository",
"(",
"app",
",",
"id",
")",
":",
"rval",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"id",
",",
"list",
")",
":",
"return_list",
"=",
"True",
"else",
":",
"id",
"=",
"[",
"id",
"]",
"return_list",
"=",
"False",
... | get a tool shed repository record from the galaxy database defined by the id . | train | false |
26,411 | def lcd(path):
return _change_cwd('lcwd', path)
| [
"def",
"lcd",
"(",
"path",
")",
":",
"return",
"_change_cwd",
"(",
"'lcwd'",
",",
"path",
")"
] | context manager for updating local current working directory . | train | false |
26,414 | @logic.validate(ckan.logic.schema.default_pagination_schema)
def dashboard_activity_list_html(context, data_dict):
activity_stream = dashboard_activity_list(context, data_dict)
model = context['model']
user_id = context['user']
offset = data_dict.get('offset', 0)
extra_vars = {'controller': 'user', 'action': 'dash... | [
"@",
"logic",
".",
"validate",
"(",
"ckan",
".",
"logic",
".",
"schema",
".",
"default_pagination_schema",
")",
"def",
"dashboard_activity_list_html",
"(",
"context",
",",
"data_dict",
")",
":",
"activity_stream",
"=",
"dashboard_activity_list",
"(",
"context",
",... | return the authorized users dashboard activity stream as html . | train | false |
26,415 | def id_to_name(config, short_name):
for (k, v) in list(config.items()):
if (v.get('id') == short_name):
return k
break
else:
raise Exception('No provider with id={0} found in the config!'.format(short_name))
| [
"def",
"id_to_name",
"(",
"config",
",",
"short_name",
")",
":",
"for",
"(",
"k",
",",
"v",
")",
"in",
"list",
"(",
"config",
".",
"items",
"(",
")",
")",
":",
"if",
"(",
"v",
".",
"get",
"(",
"'id'",
")",
"==",
"short_name",
")",
":",
"return"... | returns the provider :doc:config key based on its id value . | train | true |
26,416 | def arbitrary_state_transformation(deployment_state):
uuid = uuid4()
return deployment_state.transform(['nodes', uuid], NodeState(uuid=uuid, hostname=u'catcatdog'))
| [
"def",
"arbitrary_state_transformation",
"(",
"deployment_state",
")",
":",
"uuid",
"=",
"uuid4",
"(",
")",
"return",
"deployment_state",
".",
"transform",
"(",
"[",
"'nodes'",
",",
"uuid",
"]",
",",
"NodeState",
"(",
"uuid",
"=",
"uuid",
",",
"hostname",
"=... | make some change to a deployment state . | train | false |
26,417 | def getsebool(boolean):
return list_sebool().get(boolean, {})
| [
"def",
"getsebool",
"(",
"boolean",
")",
":",
"return",
"list_sebool",
"(",
")",
".",
"get",
"(",
"boolean",
",",
"{",
"}",
")"
] | return the information on a specific selinux boolean cli example: . | train | false |
26,419 | def test_wrap_long_type():
wrapped = wrap_value(long_type(0))
assert (type(wrapped) == HyInteger)
| [
"def",
"test_wrap_long_type",
"(",
")",
":",
"wrapped",
"=",
"wrap_value",
"(",
"long_type",
"(",
"0",
")",
")",
"assert",
"(",
"type",
"(",
"wrapped",
")",
"==",
"HyInteger",
")"
] | test conversion of integers . | train | false |
26,420 | def _random_range(**kwargs):
min_inclusive = kwargs.pop('min_inclusive', None)
max_inclusive = kwargs.pop('max_inclusive', None)
max_exclusive = kwargs.pop('max_exclusive', None)
randfunc = kwargs.pop('randfunc', None)
if kwargs:
raise ValueError(('Unknown keywords: ' + str(kwargs.keys)))
if (None not in (max_i... | [
"def",
"_random_range",
"(",
"**",
"kwargs",
")",
":",
"min_inclusive",
"=",
"kwargs",
".",
"pop",
"(",
"'min_inclusive'",
",",
"None",
")",
"max_inclusive",
"=",
"kwargs",
".",
"pop",
"(",
"'max_inclusive'",
",",
"None",
")",
"max_exclusive",
"=",
"kwargs",... | generate a random integer within a given internal . | train | false |
26,421 | def delete_multi(blob_keys, **options):
fut = delete_multi_async(blob_keys, **options)
fut.get_result()
| [
"def",
"delete_multi",
"(",
"blob_keys",
",",
"**",
"options",
")",
":",
"fut",
"=",
"delete_multi_async",
"(",
"blob_keys",
",",
"**",
"options",
")",
"fut",
".",
"get_result",
"(",
")"
] | deletes a sequence of keys . | train | false |
26,423 | @handle_response_format
@treeio_login_required
def mlist_edit(request, mlist_id, response_format='html'):
user = request.user.profile
mlist = get_object_or_404(MailingList, pk=mlist_id)
if (not user.has_permission(mlist, mode='w')):
return user_denied(request, message="You don't have access to this Mailing List", ... | [
"@",
"handle_response_format",
"@",
"treeio_login_required",
"def",
"mlist_edit",
"(",
"request",
",",
"mlist_id",
",",
"response_format",
"=",
"'html'",
")",
":",
"user",
"=",
"request",
".",
"user",
".",
"profile",
"mlist",
"=",
"get_object_or_404",
"(",
"Mail... | mailinglist edit page . | train | false |
26,424 | def test_meta_comments():
t = ascii.read(['#comment1', '# comment2 DCTB ', 'a,b,c', '1,2,3'])
assert (t.colnames == ['a', 'b', 'c'])
assert (t.meta['comments'] == ['comment1', 'comment2'])
| [
"def",
"test_meta_comments",
"(",
")",
":",
"t",
"=",
"ascii",
".",
"read",
"(",
"[",
"'#comment1'",
",",
"'# comment2 DCTB '",
",",
"'a,b,c'",
",",
"'1,2,3'",
"]",
")",
"assert",
"(",
"t",
".",
"colnames",
"==",
"[",
"'a'",
",",
"'b'",
",",
"'c'",
... | make sure that line comments are included in the meta attribute of the output table . | train | false |
26,425 | def test_prefilter():
pairs = [('2+2', '2+2')]
for (raw, correct) in pairs:
nt.assert_equal(ip.prefilter(raw), correct)
| [
"def",
"test_prefilter",
"(",
")",
":",
"pairs",
"=",
"[",
"(",
"'2+2'",
",",
"'2+2'",
")",
"]",
"for",
"(",
"raw",
",",
"correct",
")",
"in",
"pairs",
":",
"nt",
".",
"assert_equal",
"(",
"ip",
".",
"prefilter",
"(",
"raw",
")",
",",
"correct",
... | test user input conversions . | train | false |
26,426 | def get_interface_addresses():
try:
output = subprocess.check_output('ifconfig')
except subprocess.CalledProcessError:
return (['127.0.0.1'], [])
v4 = re.findall('inet (addr:)?([^ ]*)', output)
v6 = re.findall('inet6 (addr: )?([^ ]*)', output)
v4 = [e[1] for e in v4]
v6 = [e[1] for e in v6]
return (v4, v6)
| [
"def",
"get_interface_addresses",
"(",
")",
":",
"try",
":",
"output",
"=",
"subprocess",
".",
"check_output",
"(",
"'ifconfig'",
")",
"except",
"subprocess",
".",
"CalledProcessError",
":",
"return",
"(",
"[",
"'127.0.0.1'",
"]",
",",
"[",
"]",
")",
"v4",
... | get all ip addresses assigned to interfaces . | train | false |
26,427 | def notifier_program():
return wf().datafile(u'Notify.app/Contents/MacOS/applet')
| [
"def",
"notifier_program",
"(",
")",
":",
"return",
"wf",
"(",
")",
".",
"datafile",
"(",
"u'Notify.app/Contents/MacOS/applet'",
")"
] | return path to notifier applet executable . | train | false |
26,428 | def propagate_check_resource(cnxt, rpc_client, next_res_id, current_traversal, predecessors, sender_key, sender_data, is_update, adopt_stack_data):
def do_check(entity_id, data):
rpc_client.check_resource(cnxt, entity_id, current_traversal, data, is_update, adopt_stack_data)
sync_point.sync(cnxt, next_res_id, curre... | [
"def",
"propagate_check_resource",
"(",
"cnxt",
",",
"rpc_client",
",",
"next_res_id",
",",
"current_traversal",
",",
"predecessors",
",",
"sender_key",
",",
"sender_data",
",",
"is_update",
",",
"adopt_stack_data",
")",
":",
"def",
"do_check",
"(",
"entity_id",
"... | trigger processing of node if all of its dependencies are satisfied . | train | false |
26,429 | def _SkipVarint(buffer, pos, end):
while (ord(buffer[pos]) & 128):
pos += 1
pos += 1
if (pos > end):
raise _DecodeError('Truncated message.')
return pos
| [
"def",
"_SkipVarint",
"(",
"buffer",
",",
"pos",
",",
"end",
")",
":",
"while",
"(",
"ord",
"(",
"buffer",
"[",
"pos",
"]",
")",
"&",
"128",
")",
":",
"pos",
"+=",
"1",
"pos",
"+=",
"1",
"if",
"(",
"pos",
">",
"end",
")",
":",
"raise",
"_Deco... | skip a varint value . | train | true |
26,430 | def get_issues_list(project, auth=False, **params):
params.setdefault('state', 'closed')
url = 'https://api.github.com/repos/{project}/issues'.format(project=project)
if auth:
headers = make_auth_header()
else:
headers = None
pages = get_paged_request(url, headers=headers, **params)
return pages
| [
"def",
"get_issues_list",
"(",
"project",
",",
"auth",
"=",
"False",
",",
"**",
"params",
")",
":",
"params",
".",
"setdefault",
"(",
"'state'",
",",
"'closed'",
")",
"url",
"=",
"'https://api.github.com/repos/{project}/issues'",
".",
"format",
"(",
"project",
... | get issues list . | train | true |
26,431 | def _pick_leadfield(leadfield, forward, ch_names):
picks_fwd = pick_channels(forward['sol']['row_names'], ch_names)
return leadfield[picks_fwd]
| [
"def",
"_pick_leadfield",
"(",
"leadfield",
",",
"forward",
",",
"ch_names",
")",
":",
"picks_fwd",
"=",
"pick_channels",
"(",
"forward",
"[",
"'sol'",
"]",
"[",
"'row_names'",
"]",
",",
"ch_names",
")",
"return",
"leadfield",
"[",
"picks_fwd",
"]"
] | pick out correct lead field components . | train | false |
26,432 | def getTransformedVector3Blindly(tetragrid, vector3):
return Vector3(getTransformedByList(tetragrid[0], vector3), getTransformedByList(tetragrid[1], vector3), getTransformedByList(tetragrid[2], vector3))
| [
"def",
"getTransformedVector3Blindly",
"(",
"tetragrid",
",",
"vector3",
")",
":",
"return",
"Vector3",
"(",
"getTransformedByList",
"(",
"tetragrid",
"[",
"0",
"]",
",",
"vector3",
")",
",",
"getTransformedByList",
"(",
"tetragrid",
"[",
"1",
"]",
",",
"vecto... | get the vector3 multiplied by a tetragrid without checking if the tetragrid exists . | train | false |
26,433 | def _sub_labels(axis, subs=()):
fmt = axis.get_minor_formatter()
minor_tlocs = axis.get_minorticklocs()
fmt.set_locs(minor_tlocs)
coefs = (minor_tlocs / (10 ** np.floor(np.log10(minor_tlocs))))
label_expected = [(np.round(c) in subs) for c in coefs]
label_test = [(fmt(x) != u'') for x in minor_tlocs]
assert (lab... | [
"def",
"_sub_labels",
"(",
"axis",
",",
"subs",
"=",
"(",
")",
")",
":",
"fmt",
"=",
"axis",
".",
"get_minor_formatter",
"(",
")",
"minor_tlocs",
"=",
"axis",
".",
"get_minorticklocs",
"(",
")",
"fmt",
".",
"set_locs",
"(",
"minor_tlocs",
")",
"coefs",
... | test whether locator marks subs to be labeled . | train | false |
26,434 | def CentralMoment(xs, k):
mean = RawMoment(xs, 1)
return (sum((((x - mean) ** k) for x in xs)) / len(xs))
| [
"def",
"CentralMoment",
"(",
"xs",
",",
"k",
")",
":",
"mean",
"=",
"RawMoment",
"(",
"xs",
",",
"1",
")",
"return",
"(",
"sum",
"(",
"(",
"(",
"(",
"x",
"-",
"mean",
")",
"**",
"k",
")",
"for",
"x",
"in",
"xs",
")",
")",
"/",
"len",
"(",
... | computes the kth central moment of xs . | train | false |
26,438 | def _hungarian(cost_matrix):
state = _HungarianState(cost_matrix)
step = (None if (0 in cost_matrix.shape) else _step1)
while (step is not None):
step = step(state)
results = np.array(np.where((state.marked == 1))).T
if state.transposed:
results = results[:, ::(-1)]
return results
| [
"def",
"_hungarian",
"(",
"cost_matrix",
")",
":",
"state",
"=",
"_HungarianState",
"(",
"cost_matrix",
")",
"step",
"=",
"(",
"None",
"if",
"(",
"0",
"in",
"cost_matrix",
".",
"shape",
")",
"else",
"_step1",
")",
"while",
"(",
"step",
"is",
"not",
"No... | the hungarian algorithm . | train | false |
26,439 | def mminfo(source):
return MMFile.info(source)
| [
"def",
"mminfo",
"(",
"source",
")",
":",
"return",
"MMFile",
".",
"info",
"(",
"source",
")"
] | return size and storage parameters from matrix market file-like source . | train | false |
26,440 | def human_size(num, precision=3):
return (human_num(num, precision) + u'B')
| [
"def",
"human_size",
"(",
"num",
",",
"precision",
"=",
"3",
")",
":",
"return",
"(",
"human_num",
"(",
"num",
",",
"precision",
")",
"+",
"u'B'",
")"
] | convert bytes length to a human-readable version . | train | false |
26,442 | def ensuredir(path):
try:
os.makedirs(path)
except OSError as err:
if (not (err.errno == 17)):
raise
| [
"def",
"ensuredir",
"(",
"path",
")",
":",
"try",
":",
"os",
".",
"makedirs",
"(",
"path",
")",
"except",
"OSError",
"as",
"err",
":",
"if",
"(",
"not",
"(",
"err",
".",
"errno",
"==",
"17",
")",
")",
":",
"raise"
] | ensure that a path exists . | train | false |
26,443 | @pytest.mark.parametrize('resource_name', ['messages', 'drafts', 'files', 'events', 'folders', 'labels', 'calendars', 'contacts'])
def test_resource_views(resource_name, db, api_client, generic_account, message, thread, event, label, contact, folder):
if (resource_name == 'folders'):
api_client = new_api_client(db, ... | [
"@",
"pytest",
".",
"mark",
".",
"parametrize",
"(",
"'resource_name'",
",",
"[",
"'messages'",
",",
"'drafts'",
",",
"'files'",
",",
"'events'",
",",
"'folders'",
",",
"'labels'",
",",
"'calendars'",
",",
"'contacts'",
"]",
")",
"def",
"test_resource_views",
... | exercises various tests for views . | train | false |
26,444 | def mobile_test(f):
@wraps(f)
def wrapper(self, *args, **kw):
MobileTest._mobile_init(self)
return f(self, *args, **kw)
return wrapper
| [
"def",
"mobile_test",
"(",
"f",
")",
":",
"@",
"wraps",
"(",
"f",
")",
"def",
"wrapper",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kw",
")",
":",
"MobileTest",
".",
"_mobile_init",
"(",
"self",
")",
"return",
"f",
"(",
"self",
",",
"*",
"args",
... | test decorator for hitting mobile views . | train | false |
26,445 | def check_tuple_assignments(evaluator, types, name):
for (index, node) in name.assignment_indexes():
iterated = iterable.py__iter__(evaluator, types, node)
for _ in range((index + 1)):
try:
types = next(iterated)
except StopIteration:
types = set()
break
return types
| [
"def",
"check_tuple_assignments",
"(",
"evaluator",
",",
"types",
",",
"name",
")",
":",
"for",
"(",
"index",
",",
"node",
")",
"in",
"name",
".",
"assignment_indexes",
"(",
")",
":",
"iterated",
"=",
"iterable",
".",
"py__iter__",
"(",
"evaluator",
",",
... | checks if tuples are assigned . | train | false |
26,446 | def set_es_key(lookup_dict, term, value):
(value_dict, value_key) = _find_es_dict_by_key(lookup_dict, term)
if (value_dict is not None):
value_dict[value_key] = value
return True
return False
| [
"def",
"set_es_key",
"(",
"lookup_dict",
",",
"term",
",",
"value",
")",
":",
"(",
"value_dict",
",",
"value_key",
")",
"=",
"_find_es_dict_by_key",
"(",
"lookup_dict",
",",
"term",
")",
"if",
"(",
"value_dict",
"is",
"not",
"None",
")",
":",
"value_dict",... | looks up the location that the term maps to and sets it to the given value . | train | false |
26,448 | def transaction_before_request():
if view_has_annotation(NO_AUTO_TRANSACTION_ATTR):
return None
ctx = _request_ctx_stack.top
atomic = transaction.atomic()
atomic.__enter__()
ctx.current_atomic = atomic
| [
"def",
"transaction_before_request",
"(",
")",
":",
"if",
"view_has_annotation",
"(",
"NO_AUTO_TRANSACTION_ATTR",
")",
":",
"return",
"None",
"ctx",
"=",
"_request_ctx_stack",
".",
"top",
"atomic",
"=",
"transaction",
".",
"atomic",
"(",
")",
"atomic",
".",
"__e... | setup transaction before handling the request . | train | false |
26,449 | def grouped_correlation_row_generator(bt, pmf, category, gc_to_samples):
data = array([i for i in bt.iter_data(axis='observation')])
category_values = gc_to_samples.keys()
samples = gc_to_samples.values()
sample_inds = [[bt.index(i, axis='sample') for i in group] for group in samples]
try:
md_vals = []
for grp... | [
"def",
"grouped_correlation_row_generator",
"(",
"bt",
",",
"pmf",
",",
"category",
",",
"gc_to_samples",
")",
":",
"data",
"=",
"array",
"(",
"[",
"i",
"for",
"i",
"in",
"bt",
".",
"iter_data",
"(",
"axis",
"=",
"'observation'",
")",
"]",
")",
"category... | create generator for grouped correlation tests . | train | false |
26,450 | def sinh(x):
return Sinh()(x)
| [
"def",
"sinh",
"(",
"x",
")",
":",
"return",
"Sinh",
"(",
")",
"(",
"x",
")"
] | elementwise hyperbolic sine function . | train | false |
26,452 | def get_networkid(vm_):
networkid = config.get_cloud_config_value('networkid', vm_, __opts__)
if (networkid is not None):
return networkid
else:
return False
| [
"def",
"get_networkid",
"(",
"vm_",
")",
":",
"networkid",
"=",
"config",
".",
"get_cloud_config_value",
"(",
"'networkid'",
",",
"vm_",
",",
"__opts__",
")",
"if",
"(",
"networkid",
"is",
"not",
"None",
")",
":",
"return",
"networkid",
"else",
":",
"retur... | return the networkid to use . | train | true |
26,453 | def generate(bits, randfunc=None, e=65537):
if (bits < 1024):
raise ValueError('RSA modulus length must be >= 1024')
if (((e % 2) == 0) or (e < 3)):
raise ValueError('RSA public exponent must be a positive, odd integer larger than 2.')
if (randfunc is None):
randfunc = Random.get_random_bytes
d = n = Integer(... | [
"def",
"generate",
"(",
"bits",
",",
"randfunc",
"=",
"None",
",",
"e",
"=",
"65537",
")",
":",
"if",
"(",
"bits",
"<",
"1024",
")",
":",
"raise",
"ValueError",
"(",
"'RSA modulus length must be >= 1024'",
")",
"if",
"(",
"(",
"(",
"e",
"%",
"2",
")"... | generate a new private key on the given curve . | train | false |
26,454 | def add_dicts_by_key(in_dict1, in_dict2):
both = {}
for key1 in in_dict1:
for key2 in in_dict2:
if (key1 == key2):
both[key1] = (in_dict1[key1] + in_dict2[key2])
return both
| [
"def",
"add_dicts_by_key",
"(",
"in_dict1",
",",
"in_dict2",
")",
":",
"both",
"=",
"{",
"}",
"for",
"key1",
"in",
"in_dict1",
":",
"for",
"key2",
"in",
"in_dict2",
":",
"if",
"(",
"key1",
"==",
"key2",
")",
":",
"both",
"[",
"key1",
"]",
"=",
"(",... | combines two dictionaries and adds the values for those keys that are shared . | train | false |
26,455 | def _collect_delete_commands(base_mapper, uowtransaction, table, states_to_delete):
for (state, state_dict, mapper, connection, update_version_id) in states_to_delete:
if (table not in mapper._pks_by_table):
continue
params = {}
for col in mapper._pks_by_table[table]:
params[col.key] = value = mapper._get_... | [
"def",
"_collect_delete_commands",
"(",
"base_mapper",
",",
"uowtransaction",
",",
"table",
",",
"states_to_delete",
")",
":",
"for",
"(",
"state",
",",
"state_dict",
",",
"mapper",
",",
"connection",
",",
"update_version_id",
")",
"in",
"states_to_delete",
":",
... | identify values to use in delete statements for a list of states to be deleted . | train | false |
26,457 | def enableLoggingErrorDebugging():
print >>sys.stderr, 'WARNING'
print >>sys.stderr, ('WARNING: nupic.support.enableLoggingErrorDebugging() was called to install a debugging patch into all logging handlers that will cause the program to fail if a logging exception occurrs; this call is for debugging only and MUST be ... | [
"def",
"enableLoggingErrorDebugging",
"(",
")",
":",
"print",
">>",
"sys",
".",
"stderr",
",",
"'WARNING'",
"print",
">>",
"sys",
".",
"stderr",
",",
"(",
"'WARNING: nupic.support.enableLoggingErrorDebugging() was called to install a debugging patch into all logging handlers th... | overrides the python logging facilitys handler . | train | false |
26,459 | def parse_docstring(docstring):
ret = {}
ret['full'] = docstring
regex = '([ \\t]*):depends:[ \\t]+- (\\w+)[^\\n]*\\n(\\1[ \\t]+- (\\w+)[^\\n]*\\n)*'
match = re.search(regex, docstring, re.M)
if match:
deps = []
regex = '- (\\w+)'
for line in match.group(0).strip().splitlines():
deps.append(re.search(rege... | [
"def",
"parse_docstring",
"(",
"docstring",
")",
":",
"ret",
"=",
"{",
"}",
"ret",
"[",
"'full'",
"]",
"=",
"docstring",
"regex",
"=",
"'([ \\\\t]*):depends:[ \\\\t]+- (\\\\w+)[^\\\\n]*\\\\n(\\\\1[ \\\\t]+- (\\\\w+)[^\\\\n]*\\\\n)*'",
"match",
"=",
"re",
".",
"search",
... | parse out the parts of a docstring . | train | true |
26,460 | def _check_load_paths(load_path):
if ((load_path is None) or (not isinstance(load_path, six.string_types))):
return None
_paths = []
for _path in load_path.split(':'):
if (os.path.isabs(_path) and os.path.isdir(_path)):
_paths.append(_path)
else:
log.info('Invalid augeas_cfg load_path entry: %s removed',... | [
"def",
"_check_load_paths",
"(",
"load_path",
")",
":",
"if",
"(",
"(",
"load_path",
"is",
"None",
")",
"or",
"(",
"not",
"isinstance",
"(",
"load_path",
",",
"six",
".",
"string_types",
")",
")",
")",
":",
"return",
"None",
"_paths",
"=",
"[",
"]",
... | checks the validity of the load_path . | train | true |
26,461 | def prepare_disks(job, fs_desc, disk1_only=False, disk_list=None):
if (not fs_desc):
return (None, '', None)
if (not isinstance(fs_desc, partition.FsOptions)):
fs_desc = _legacy_str_to_test_flags(fs_desc)
if (not disk_list):
disk_list = get_disk_list()
mkfs_bin = ('mkfs.' + fs_desc.fstype)
if (fs_desc.fstype... | [
"def",
"prepare_disks",
"(",
"job",
",",
"fs_desc",
",",
"disk1_only",
"=",
"False",
",",
"disk_list",
"=",
"None",
")",
":",
"if",
"(",
"not",
"fs_desc",
")",
":",
"return",
"(",
"None",
",",
"''",
",",
"None",
")",
"if",
"(",
"not",
"isinstance",
... | prepare drive(s) to contain the file system type / options given in the description line fs_desc . | train | false |
26,464 | def date_to_datetime(x):
if ((not isinstance(x, datetime)) and isinstance(x, date)):
return datetime.combine(x, time())
return x
| [
"def",
"date_to_datetime",
"(",
"x",
")",
":",
"if",
"(",
"(",
"not",
"isinstance",
"(",
"x",
",",
"datetime",
")",
")",
"and",
"isinstance",
"(",
"x",
",",
"date",
")",
")",
":",
"return",
"datetime",
".",
"combine",
"(",
"x",
",",
"time",
"(",
... | convert a date into a datetime . | train | true |
26,466 | @testing.requires_testing_data
def test_io_trans():
tempdir = _TempDir()
os.mkdir(op.join(tempdir, 'sample'))
assert_raises(RuntimeError, _find_trans, 'sample', subjects_dir=tempdir)
trans0 = read_trans(fname)
fname1 = op.join(tempdir, 'sample', 'test-trans.fif')
trans0.save(fname1)
assert_true((fname1 == _find_... | [
"@",
"testing",
".",
"requires_testing_data",
"def",
"test_io_trans",
"(",
")",
":",
"tempdir",
"=",
"_TempDir",
"(",
")",
"os",
".",
"mkdir",
"(",
"op",
".",
"join",
"(",
"tempdir",
",",
"'sample'",
")",
")",
"assert_raises",
"(",
"RuntimeError",
",",
"... | test reading and writing of trans files . | train | false |
26,467 | def get_webshells(extension, force_extension=False):
return _get_file_list('webshell', extension, force_extension)
| [
"def",
"get_webshells",
"(",
"extension",
",",
"force_extension",
"=",
"False",
")",
":",
"return",
"_get_file_list",
"(",
"'webshell'",
",",
"extension",
",",
"force_extension",
")"
] | this method returns a webshell content to be used in exploits . | train | false |
26,469 | @snippet
def topic_delete(client, to_delete):
TOPIC_NAME = ('topic_delete-%d' % (_millis(),))
topic = client.topic(TOPIC_NAME)
topic.create()
assert topic.exists()
topic.delete()
assert (not topic.exists())
| [
"@",
"snippet",
"def",
"topic_delete",
"(",
"client",
",",
"to_delete",
")",
":",
"TOPIC_NAME",
"=",
"(",
"'topic_delete-%d'",
"%",
"(",
"_millis",
"(",
")",
",",
")",
")",
"topic",
"=",
"client",
".",
"topic",
"(",
"TOPIC_NAME",
")",
"topic",
".",
"cr... | delete a topic . | train | false |
26,470 | def getAllowedReturnURLs(relying_party_url):
(rp_url_after_redirects, return_to_urls) = services.getServiceEndpoints(relying_party_url, _extractReturnURL)
if (rp_url_after_redirects != relying_party_url):
raise RealmVerificationRedirected(relying_party_url, rp_url_after_redirects)
return return_to_urls
| [
"def",
"getAllowedReturnURLs",
"(",
"relying_party_url",
")",
":",
"(",
"rp_url_after_redirects",
",",
"return_to_urls",
")",
"=",
"services",
".",
"getServiceEndpoints",
"(",
"relying_party_url",
",",
"_extractReturnURL",
")",
"if",
"(",
"rp_url_after_redirects",
"!=",... | given a relying party discovery url return a list of return_to urls . | train | true |
26,471 | def get_pydoc_html(module):
doc = pydoc.HTMLDoc()
output = doc.docmodule(module)
loc = (doc.getdocloc(pydoc_mod) or '')
if loc:
loc = (('<br><a href="' + loc) + '">Module Docs</a>')
return (output.strip(), loc)
| [
"def",
"get_pydoc_html",
"(",
"module",
")",
":",
"doc",
"=",
"pydoc",
".",
"HTMLDoc",
"(",
")",
"output",
"=",
"doc",
".",
"docmodule",
"(",
"module",
")",
"loc",
"=",
"(",
"doc",
".",
"getdocloc",
"(",
"pydoc_mod",
")",
"or",
"''",
")",
"if",
"lo... | returns pydoc generated output as html . | train | false |
26,472 | def parse_quantifier(source, info, ch):
q = _QUANTIFIERS.get(ch)
if q:
return q
if (ch == '{'):
counts = parse_limited_quantifier(source)
if counts:
return counts
return None
| [
"def",
"parse_quantifier",
"(",
"source",
",",
"info",
",",
"ch",
")",
":",
"q",
"=",
"_QUANTIFIERS",
".",
"get",
"(",
"ch",
")",
"if",
"q",
":",
"return",
"q",
"if",
"(",
"ch",
"==",
"'{'",
")",
":",
"counts",
"=",
"parse_limited_quantifier",
"(",
... | parses a quantifier . | train | false |
26,474 | def importfile(path):
magic = imp.get_magic()
file = open(path, 'r')
if (file.read(len(magic)) == magic):
kind = imp.PY_COMPILED
else:
kind = imp.PY_SOURCE
file.close()
filename = os.path.basename(path)
(name, ext) = os.path.splitext(filename)
file = open(path, 'r')
try:
module = imp.load_module(name, fi... | [
"def",
"importfile",
"(",
"path",
")",
":",
"magic",
"=",
"imp",
".",
"get_magic",
"(",
")",
"file",
"=",
"open",
"(",
"path",
",",
"'r'",
")",
"if",
"(",
"file",
".",
"read",
"(",
"len",
"(",
"magic",
")",
")",
"==",
"magic",
")",
":",
"kind",... | import a python source file or compiled file given its path . | train | false |
26,475 | @register.filter
@stringfilter
def pretty_print_issue_status(status):
return BaseComment.issue_status_to_string(status)
| [
"@",
"register",
".",
"filter",
"@",
"stringfilter",
"def",
"pretty_print_issue_status",
"(",
"status",
")",
":",
"return",
"BaseComment",
".",
"issue_status_to_string",
"(",
"status",
")"
] | turns an issue status code into a human-readable status string . | train | false |
26,476 | def _wait_for_async(conn, request_id):
count = 0
log.debug('Waiting for asynchronous operation to complete')
result = conn.get_operation_status(request_id)
while (result.status == 'InProgress'):
count = (count + 1)
if (count > 120):
raise ValueError('Timed out waiting for async operation to complete.')
tim... | [
"def",
"_wait_for_async",
"(",
"conn",
",",
"request_id",
")",
":",
"count",
"=",
"0",
"log",
".",
"debug",
"(",
"'Waiting for asynchronous operation to complete'",
")",
"result",
"=",
"conn",
".",
"get_operation_status",
"(",
"request_id",
")",
"while",
"(",
"r... | helper function for azure tests . | train | true |
26,477 | def make_idx_data_cv(revs, word_idx_map, cv, max_l=51, k=300, filter_h=5):
(train, test) = ([], [])
for rev in revs:
sent = get_idx_from_sent(rev['text'], word_idx_map, max_l, k, filter_h)
sent.append(rev['y'])
if (rev['split'] == cv):
test.append(sent)
else:
train.append(sent)
train = np.array(train, ... | [
"def",
"make_idx_data_cv",
"(",
"revs",
",",
"word_idx_map",
",",
"cv",
",",
"max_l",
"=",
"51",
",",
"k",
"=",
"300",
",",
"filter_h",
"=",
"5",
")",
":",
"(",
"train",
",",
"test",
")",
"=",
"(",
"[",
"]",
",",
"[",
"]",
")",
"for",
"rev",
... | transforms sentences into a 2-d matrix . | train | false |
26,478 | def _listdir_local(path, kwargs):
request = file_service_pb.ListDirRequest()
response = file_service_pb.ListDirResponse()
request.set_path(path)
if (kwargs and kwargs.has_key('marker')):
request.set_marker(kwargs['marker'])
if (kwargs and kwargs.has_key('max-keys')):
request.set_max_keys(kwargs['max-keys'])
i... | [
"def",
"_listdir_local",
"(",
"path",
",",
"kwargs",
")",
":",
"request",
"=",
"file_service_pb",
".",
"ListDirRequest",
"(",
")",
"response",
"=",
"file_service_pb",
".",
"ListDirResponse",
"(",
")",
"request",
".",
"set_path",
"(",
"path",
")",
"if",
"(",
... | dev app server version of listdir . | train | false |
26,479 | def funshion_get_title_by_vid(vid):
html = get_content('http://pv.funshion.com/v5/video/profile?id={vid}&cl=aphone&uc=5'.format(vid=vid))
c = json.loads(html)
return c['name']
| [
"def",
"funshion_get_title_by_vid",
"(",
"vid",
")",
":",
"html",
"=",
"get_content",
"(",
"'http://pv.funshion.com/v5/video/profile?id={vid}&cl=aphone&uc=5'",
".",
"format",
"(",
"vid",
"=",
"vid",
")",
")",
"c",
"=",
"json",
".",
"loads",
"(",
"html",
")",
"re... | vid->str single video vid to title . | train | false |
26,480 | def _reshape(arg, shape):
if isinstance(arg, tuple):
raise TypeError('Composite batches not supported.')
assert (not isinstance(arg, list))
if isinstance(arg, (np.ndarray, theano.tensor.TensorVariable)):
return arg.reshape(shape)
elif isinstance(arg, theano.sparse.SparseVariable):
warnings.warn('Using pylearn... | [
"def",
"_reshape",
"(",
"arg",
",",
"shape",
")",
":",
"if",
"isinstance",
"(",
"arg",
",",
"tuple",
")",
":",
"raise",
"TypeError",
"(",
"'Composite batches not supported.'",
")",
"assert",
"(",
"not",
"isinstance",
"(",
"arg",
",",
"list",
")",
")",
"i... | reshapes a tensor . | train | false |
26,483 | def intersperse(string, counts, separator=''):
(left, rest, right) = intersperse_pat.match(string).groups()
def reverse(s):
return s[::(-1)]
splits = split(reverse(rest), counts)
res = separator.join(map(reverse, reverse(splits)))
return (((left + res) + right), (((len(splits) > 0) and (len(splits) - 1)) or 0))
| [
"def",
"intersperse",
"(",
"string",
",",
"counts",
",",
"separator",
"=",
"''",
")",
":",
"(",
"left",
",",
"rest",
",",
"right",
")",
"=",
"intersperse_pat",
".",
"match",
"(",
"string",
")",
".",
"groups",
"(",
")",
"def",
"reverse",
"(",
"s",
"... | see the asserts below for examples . | train | false |
26,484 | def get_email(invalid=False, optional=True):
invalid_prefix = 'There seem to be problems with that address. '
msg = 'Enter email address (used for urgent renewal and security notices)'
unsafe_suggestion = '\n\nIf you really want to skip this, you can run the client with --register-unsafely-without-email but make sur... | [
"def",
"get_email",
"(",
"invalid",
"=",
"False",
",",
"optional",
"=",
"True",
")",
":",
"invalid_prefix",
"=",
"'There seem to be problems with that address. '",
"msg",
"=",
"'Enter email address (used for urgent renewal and security notices)'",
"unsafe_suggestion",
"=",
"'... | returns the email address for a user . | train | false |
26,485 | def _get_dev_hostname(backend, instance=None):
port = _get_dev_port(backend, instance)
if (not port):
error = ('Backend not found: %s' % backend)
if (instance is not None):
error = ('%s.%d' % (error, instance))
raise InvalidBackendError(error)
host = os.environ.get('SERVER_NAME', 'localhost')
return ('%s:%... | [
"def",
"_get_dev_hostname",
"(",
"backend",
",",
"instance",
"=",
"None",
")",
":",
"port",
"=",
"_get_dev_port",
"(",
"backend",
",",
"instance",
")",
"if",
"(",
"not",
"port",
")",
":",
"error",
"=",
"(",
"'Backend not found: %s'",
"%",
"backend",
")",
... | returns the hostname of a backend [instance] in the dev_appserver . | train | false |
26,486 | def _validate_cluster_size(size):
try:
size = int(size)
except ValueError:
raise argparse.ArgumentTypeError(u'Must be an integer. Found {!r}'.format(size))
if ((size < MIN_CLUSTER_SIZE) or (size > MAX_CLUSTER_SIZE)):
raise argparse.ArgumentTypeError(u'Must be between {} and {}. Found {}.'.format(MIN_CLUSTER_SI... | [
"def",
"_validate_cluster_size",
"(",
"size",
")",
":",
"try",
":",
"size",
"=",
"int",
"(",
"size",
")",
"except",
"ValueError",
":",
"raise",
"argparse",
".",
"ArgumentTypeError",
"(",
"u'Must be an integer. Found {!r}'",
".",
"format",
"(",
"size",
")",
")"... | validate that user-input cluster size is supported by installer . | train | false |
26,487 | def _build_parent_list(policy_definition, admx_policy_definitions, return_full_policy_names, adml_policy_resources):
parent_list = []
policy_namespace = policy_definition.nsmap.keys()[0]
parent_category = policy_definition.xpath('{0}:parentCategory/@ref'.format(policy_namespace), namespaces=policy_definition.nsmap)
... | [
"def",
"_build_parent_list",
"(",
"policy_definition",
",",
"admx_policy_definitions",
",",
"return_full_policy_names",
",",
"adml_policy_resources",
")",
":",
"parent_list",
"=",
"[",
"]",
"policy_namespace",
"=",
"policy_definition",
".",
"nsmap",
".",
"keys",
"(",
... | helper function to build a list containing parent elements of the admx policy . | train | false |
26,488 | def SetProcessName(newname):
global _process_name
_process_name = newname
try:
from ctypes import cdll, byref, create_string_buffer
libc = cdll.LoadLibrary('libc.so.6')
buff = create_string_buffer((len(newname) + 1))
buff.value = newname
libc.prctl(15, byref(buff), 0, 0, 0)
except:
pass
| [
"def",
"SetProcessName",
"(",
"newname",
")",
":",
"global",
"_process_name",
"_process_name",
"=",
"newname",
"try",
":",
"from",
"ctypes",
"import",
"cdll",
",",
"byref",
",",
"create_string_buffer",
"libc",
"=",
"cdll",
".",
"LoadLibrary",
"(",
"'libc.so.6'",... | attempts to set the process name . | train | false |
26,490 | def set_dhcp_dns(iface):
cmd = ['netsh', 'interface', 'ip', 'set', 'dns', iface, 'dhcp']
__salt__['cmd.run'](cmd, python_shell=False)
return {'Interface': iface, 'DNS Server': 'DHCP'}
| [
"def",
"set_dhcp_dns",
"(",
"iface",
")",
":",
"cmd",
"=",
"[",
"'netsh'",
",",
"'interface'",
",",
"'ip'",
",",
"'set'",
",",
"'dns'",
",",
"iface",
",",
"'dhcp'",
"]",
"__salt__",
"[",
"'cmd.run'",
"]",
"(",
"cmd",
",",
"python_shell",
"=",
"False",
... | set dns source to dhcp on windows cli example: . | train | false |
26,491 | def symptom_LDAP_file_based_domain_specific_configs():
if ((not CONF.identity.domain_specific_drivers_enabled) or CONF.identity.domain_configurations_from_database):
return False
invalid_files = []
filedir = CONF.identity.domain_config_dir
if os.path.isdir(filedir):
for filename in os.listdir(filedir):
if (n... | [
"def",
"symptom_LDAP_file_based_domain_specific_configs",
"(",
")",
":",
"if",
"(",
"(",
"not",
"CONF",
".",
"identity",
".",
"domain_specific_drivers_enabled",
")",
"or",
"CONF",
".",
"identity",
".",
"domain_configurations_from_database",
")",
":",
"return",
"False"... | domain specific driver directory is invalid or contains invalid files . | train | false |
26,493 | def split_csp_str(s):
if isinstance(s, (list, tuple)):
return s
return list(set((i for i in s.strip().split(',') if i)))
| [
"def",
"split_csp_str",
"(",
"s",
")",
":",
"if",
"isinstance",
"(",
"s",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"return",
"s",
"return",
"list",
"(",
"set",
"(",
"(",
"i",
"for",
"i",
"in",
"s",
".",
"strip",
"(",
")",
".",
"split",
... | split commaseparated string . | train | false |
26,494 | def parallel_helper(obj, methodname, *args, **kwargs):
return getattr(obj, methodname)(*args, **kwargs)
| [
"def",
"parallel_helper",
"(",
"obj",
",",
"methodname",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"return",
"getattr",
"(",
"obj",
",",
"methodname",
")",
"(",
"*",
"args",
",",
"**",
"kwargs",
")"
] | helper to workaround python 2 limitations of pickling instance methods . | train | false |
26,495 | def _create_xblock_ancestor_info(xblock, course_outline):
ancestors = []
def collect_ancestor_info(ancestor, include_child_info=False):
'\n Collect xblock info regarding the specified xblock and its ancestors.\n '
if ancestor:
direct_children_only = (lambda parent: (parent == ancestor))
ancest... | [
"def",
"_create_xblock_ancestor_info",
"(",
"xblock",
",",
"course_outline",
")",
":",
"ancestors",
"=",
"[",
"]",
"def",
"collect_ancestor_info",
"(",
"ancestor",
",",
"include_child_info",
"=",
"False",
")",
":",
"if",
"ancestor",
":",
"direct_children_only",
"=... | returns information about the ancestors of an xblock . | train | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.