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 |
|---|---|---|---|---|---|
48,688 | def lfsr_autocorrelation(L, P, k):
if (not isinstance(L, list)):
raise TypeError(('L (=%s) must be a list' % L))
P = int(P)
k = int(k)
L0 = L[:P]
L1 = (L0 + L0[:k])
L2 = [((-1) ** (L1[i].to_int() + L1[(i + k)].to_int())) for i in range(P)]
tot = sum(L2)
return Rational(tot, P)
| [
"def",
"lfsr_autocorrelation",
"(",
"L",
",",
"P",
",",
"k",
")",
":",
"if",
"(",
"not",
"isinstance",
"(",
"L",
",",
"list",
")",
")",
":",
"raise",
"TypeError",
"(",
"(",
"'L (=%s) must be a list'",
"%",
"L",
")",
")",
"P",
"=",
"int",
"(",
"P",
... | this function computes the lfsr autocorrelation function . | train | false |
48,691 | def is_server_error(status):
return ((500 <= status) and (status <= 599))
| [
"def",
"is_server_error",
"(",
"status",
")",
":",
"return",
"(",
"(",
"500",
"<=",
"status",
")",
"and",
"(",
"status",
"<=",
"599",
")",
")"
] | check if http status code is server error . | train | false |
48,692 | @py3compat.doctest_refactor_print
def extract_vars(*names, **kw):
depth = kw.get('depth', 0)
callerNS = sys._getframe((depth + 1)).f_locals
return dict(((k, callerNS[k]) for k in names))
| [
"@",
"py3compat",
".",
"doctest_refactor_print",
"def",
"extract_vars",
"(",
"*",
"names",
",",
"**",
"kw",
")",
":",
"depth",
"=",
"kw",
".",
"get",
"(",
"'depth'",
",",
"0",
")",
"callerNS",
"=",
"sys",
".",
"_getframe",
"(",
"(",
"depth",
"+",
"1"... | extract a set of variables by name from another frame . | train | true |
48,693 | def current_metadata(items):
assert items
likelies = {}
consensus = {}
fields = ['artist', 'album', 'albumartist', 'year', 'disctotal', 'mb_albumid', 'label', 'catalognum', 'country', 'media', 'albumdisambig']
for field in fields:
values = [item[field] for item in items if item]
(likelies[field], freq) = plura... | [
"def",
"current_metadata",
"(",
"items",
")",
":",
"assert",
"items",
"likelies",
"=",
"{",
"}",
"consensus",
"=",
"{",
"}",
"fields",
"=",
"[",
"'artist'",
",",
"'album'",
",",
"'albumartist'",
",",
"'year'",
",",
"'disctotal'",
",",
"'mb_albumid'",
",",
... | extract the likely current metadata for an album given a list of its items . | train | false |
48,695 | def p_function_definition_3(t):
pass
| [
"def",
"p_function_definition_3",
"(",
"t",
")",
":",
"pass"
] | function_definition : declarator compound_statement . | train | false |
48,697 | @ssl_required
def aaq_step2(request, product_key):
return aaq(request, product_key=product_key, step=1)
| [
"@",
"ssl_required",
"def",
"aaq_step2",
"(",
"request",
",",
"product_key",
")",
":",
"return",
"aaq",
"(",
"request",
",",
"product_key",
"=",
"product_key",
",",
"step",
"=",
"1",
")"
] | step 2: the product is selected . | train | false |
48,698 | @handle_response_format
@treeio_login_required
def receivable_add(request, response_format='html'):
if request.POST:
if ('cancel' not in request.POST):
receivable = Liability()
form = ReceivableForm(request.user.profile, request.POST, instance=receivable)
if form.is_valid():
receivable = form.save(commi... | [
"@",
"handle_response_format",
"@",
"treeio_login_required",
"def",
"receivable_add",
"(",
"request",
",",
"response_format",
"=",
"'html'",
")",
":",
"if",
"request",
".",
"POST",
":",
"if",
"(",
"'cancel'",
"not",
"in",
"request",
".",
"POST",
")",
":",
"r... | new receivable form . | train | false |
48,699 | def format_remote_path(host, path):
if (host is None):
return path
return ('%s:%s' % (safe_ip_format(host), path))
| [
"def",
"format_remote_path",
"(",
"host",
",",
"path",
")",
":",
"if",
"(",
"host",
"is",
"None",
")",
":",
"return",
"path",
"return",
"(",
"'%s:%s'",
"%",
"(",
"safe_ip_format",
"(",
"host",
")",
",",
"path",
")",
")"
] | returns remote path in format acceptable for scp/rsync . | train | false |
48,701 | def typed_ordered_dict(key_type, value_type, default):
return (lambda setting: OrderedDict(((key_type(StringConverter(key)), (value_type(StringConverter(value)) if (value != '') else default)) for (key, value) in OrderedDict(setting).items())))
| [
"def",
"typed_ordered_dict",
"(",
"key_type",
",",
"value_type",
",",
"default",
")",
":",
"return",
"(",
"lambda",
"setting",
":",
"OrderedDict",
"(",
"(",
"(",
"key_type",
"(",
"StringConverter",
"(",
"key",
")",
")",
",",
"(",
"value_type",
"(",
"String... | creates a function that converts a setting into an ordered dict with the given types . | train | false |
48,702 | def get_file_writer(file_handle, do_gzip, do_bzip):
ofile = None
if (do_gzip and do_bzip):
raise ValueError(u'Cannot specify both bzip and gzip compression!')
if do_gzip:
ofile = gzip.GzipFile(fileobj=file_handle, mode=u'w')
elif do_bzip:
ofile = bz2file.open(file_handle, mode=u'w')
else:
ofile = file_hand... | [
"def",
"get_file_writer",
"(",
"file_handle",
",",
"do_gzip",
",",
"do_bzip",
")",
":",
"ofile",
"=",
"None",
"if",
"(",
"do_gzip",
"and",
"do_bzip",
")",
":",
"raise",
"ValueError",
"(",
"u'Cannot specify both bzip and gzip compression!'",
")",
"if",
"do_gzip",
... | generate and return a file object with specified compression . | train | false |
48,703 | def get_unique(content_type, object_pk, name=None, request=None, ip=None, user_agent=None, user=None):
if request:
if request.user.is_authenticated():
user = request.user
ip = user_agent = None
else:
user = None
ip = request.META.get('REMOTE_ADDR', '')
user_agent = request.META.get('HTTP_USER_AGENT'... | [
"def",
"get_unique",
"(",
"content_type",
",",
"object_pk",
",",
"name",
"=",
"None",
",",
"request",
"=",
"None",
",",
"ip",
"=",
"None",
",",
"user_agent",
"=",
"None",
",",
"user",
"=",
"None",
")",
":",
"if",
"request",
":",
"if",
"request",
".",... | extract a set of unique identifiers from the request . | train | false |
48,704 | def test_cache_deactivated_private_browsing(config_stub, tmpdir):
config_stub.data = {'storage': {'cache-size': 1024}, 'general': {'private-browsing': True}}
disk_cache = cache.DiskCache(str(tmpdir))
metadata = QNetworkCacheMetaData()
metadata.setUrl(QUrl('http://www.example.com/'))
assert metadata.isValid()
asse... | [
"def",
"test_cache_deactivated_private_browsing",
"(",
"config_stub",
",",
"tmpdir",
")",
":",
"config_stub",
".",
"data",
"=",
"{",
"'storage'",
":",
"{",
"'cache-size'",
":",
"1024",
"}",
",",
"'general'",
":",
"{",
"'private-browsing'",
":",
"True",
"}",
"}... | test if cache is deactivated in private-browsing mode . | train | false |
48,705 | def _FieldSkipper():
WIRETYPE_TO_SKIPPER = [_SkipVarint, _SkipFixed64, _SkipLengthDelimited, _SkipGroup, _EndGroup, _SkipFixed32, _RaiseInvalidWireType, _RaiseInvalidWireType]
wiretype_mask = wire_format.TAG_TYPE_MASK
local_ord = ord
def SkipField(buffer, pos, end, tag_bytes):
'Skips a field with the specified ta... | [
"def",
"_FieldSkipper",
"(",
")",
":",
"WIRETYPE_TO_SKIPPER",
"=",
"[",
"_SkipVarint",
",",
"_SkipFixed64",
",",
"_SkipLengthDelimited",
",",
"_SkipGroup",
",",
"_EndGroup",
",",
"_SkipFixed32",
",",
"_RaiseInvalidWireType",
",",
"_RaiseInvalidWireType",
"]",
"wiretyp... | constructs the skipfield function . | train | true |
48,706 | def transform_params(parameters):
transformed_parameters = {}
for (key, value) in iteritems(parameters):
if isinstance(value, (list, tuple, set)):
value = [convert_boolean(param) for param in value]
transformed_parameters[format_name(key)] = value
elif (value is not None):
transformed_parameters[format_n... | [
"def",
"transform_params",
"(",
"parameters",
")",
":",
"transformed_parameters",
"=",
"{",
"}",
"for",
"(",
"key",
",",
"value",
")",
"in",
"iteritems",
"(",
"parameters",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"(",
"list",
",",
"tuple",
",",
... | transform parameters . | train | false |
48,707 | def _checkNetmask(netmask, masklen):
num = long(netmask)
bits = masklen
while ((num & 1) == 0):
num = (num >> 1)
bits -= 1
if (bits == 0):
break
while (bits > 0):
if ((num & 1) == 0):
raise ValueError(("Netmask %s can't be expressed as an prefix." % hex(netmask)))
num = (num >> 1)
bits -= 1
| [
"def",
"_checkNetmask",
"(",
"netmask",
",",
"masklen",
")",
":",
"num",
"=",
"long",
"(",
"netmask",
")",
"bits",
"=",
"masklen",
"while",
"(",
"(",
"num",
"&",
"1",
")",
"==",
"0",
")",
":",
"num",
"=",
"(",
"num",
">>",
"1",
")",
"bits",
"-=... | checks if a netmask is expressable as e prefixlen . | train | false |
48,708 | def find_element_by_sizzle(driver, sizzle_selector):
elements = driver.find_elements_by_sizzle(sizzle_selector)
if elements:
return elements[0]
else:
raise NoSuchElementException('Unable to locate element by Sizzle: {selector}'.format(selector=sizzle_selector))
| [
"def",
"find_element_by_sizzle",
"(",
"driver",
",",
"sizzle_selector",
")",
":",
"elements",
"=",
"driver",
".",
"find_elements_by_sizzle",
"(",
"sizzle_selector",
")",
"if",
"elements",
":",
"return",
"elements",
"[",
"0",
"]",
"else",
":",
"raise",
"NoSuchEle... | finds an element by sizzle selector . | train | false |
48,709 | def garbagecollect(func):
def inner(*args, **kwargs):
result = func(*args, **kwargs)
gc.collect()
return result
return inner
| [
"def",
"garbagecollect",
"(",
"func",
")",
":",
"def",
"inner",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"result",
"=",
"func",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"gc",
".",
"collect",
"(",
")",
"return",
"result",
"return",
"inner... | decorate a function to invoke the garbage collector after each execution . | train | false |
48,710 | def _latexFromHtml(col, latex):
latex = re.sub('<br( /)?>|<div>', '\n', latex)
latex = stripHTML(latex)
return latex
| [
"def",
"_latexFromHtml",
"(",
"col",
",",
"latex",
")",
":",
"latex",
"=",
"re",
".",
"sub",
"(",
"'<br( /)?>|<div>'",
",",
"'\\n'",
",",
"latex",
")",
"latex",
"=",
"stripHTML",
"(",
"latex",
")",
"return",
"latex"
] | convert entities and fix newlines . | train | false |
48,711 | def randcplx(offset=(-1)):
return ((_randrat() + (I * _randrat())) + (I * (1 + offset)))
| [
"def",
"randcplx",
"(",
"offset",
"=",
"(",
"-",
"1",
")",
")",
":",
"return",
"(",
"(",
"_randrat",
"(",
")",
"+",
"(",
"I",
"*",
"_randrat",
"(",
")",
")",
")",
"+",
"(",
"I",
"*",
"(",
"1",
"+",
"offset",
")",
")",
")"
] | polys is not good with real coefficients . | train | false |
48,712 | @with_sitl
def test_227(connpath):
vehicle = connect(connpath, wait_ready=True)
def assert_commands(count):
vehicle.commands.download()
vehicle.commands.wait_ready()
assert_equals(len(vehicle.commands), count)
assert_commands(0)
vehicle.commands.add(Command(0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_A... | [
"@",
"with_sitl",
"def",
"test_227",
"(",
"connpath",
")",
":",
"vehicle",
"=",
"connect",
"(",
"connpath",
",",
"wait_ready",
"=",
"True",
")",
"def",
"assert_commands",
"(",
"count",
")",
":",
"vehicle",
".",
"commands",
".",
"download",
"(",
")",
"veh... | tests race condition when downloading items . | train | false |
48,713 | def kulsinski(u, v):
u = _validate_vector(u)
v = _validate_vector(v)
n = float(len(u))
(nff, nft, ntf, ntt) = _nbool_correspond_all(u, v)
return ((((ntf + nft) - ntt) + n) / ((ntf + nft) + n))
| [
"def",
"kulsinski",
"(",
"u",
",",
"v",
")",
":",
"u",
"=",
"_validate_vector",
"(",
"u",
")",
"v",
"=",
"_validate_vector",
"(",
"v",
")",
"n",
"=",
"float",
"(",
"len",
"(",
"u",
")",
")",
"(",
"nff",
",",
"nft",
",",
"ntf",
",",
"ntt",
")"... | computes the kulsinski dissimilarity between two boolean 1-d arrays . | train | false |
48,714 | def get_swap(transformed_list):
if (not all(((isinstance(device, DriverSwapBlockDevice) or ('swap_size' in device)) for device in transformed_list))):
return None
try:
return transformed_list.pop()
except IndexError:
return None
| [
"def",
"get_swap",
"(",
"transformed_list",
")",
":",
"if",
"(",
"not",
"all",
"(",
"(",
"(",
"isinstance",
"(",
"device",
",",
"DriverSwapBlockDevice",
")",
"or",
"(",
"'swap_size'",
"in",
"device",
")",
")",
"for",
"device",
"in",
"transformed_list",
")"... | get the swap device out of the list context . | train | false |
48,717 | def _read_ustring(fid, n_bytes):
return np.fromfile(fid, '>B', n_bytes)
| [
"def",
"_read_ustring",
"(",
"fid",
",",
"n_bytes",
")",
":",
"return",
"np",
".",
"fromfile",
"(",
"fid",
",",
"'>B'",
",",
"n_bytes",
")"
] | read unsigned character string . | train | false |
48,718 | @task
def sdist(ctx, deploy=False, remove_dist=False):
clean(ctx, remove_dist, create_dirs=True)
ctx.run(('python setup.py sdist' + (' register upload' if deploy else '')))
announce()
| [
"@",
"task",
"def",
"sdist",
"(",
"ctx",
",",
"deploy",
"=",
"False",
",",
"remove_dist",
"=",
"False",
")",
":",
"clean",
"(",
"ctx",
",",
"remove_dist",
",",
"create_dirs",
"=",
"True",
")",
"ctx",
".",
"run",
"(",
"(",
"'python setup.py sdist'",
"+"... | create source distribution . | train | false |
48,719 | def testLinkLimit(net, bw):
info(('*** Testing network %.2f Mbps bandwidth limit\n' % bw))
net.iperf()
| [
"def",
"testLinkLimit",
"(",
"net",
",",
"bw",
")",
":",
"info",
"(",
"(",
"'*** Testing network %.2f Mbps bandwidth limit\\n'",
"%",
"bw",
")",
")",
"net",
".",
"iperf",
"(",
")"
] | run bandwidth limit test . | train | false |
48,720 | @hug.get()
def hello(request):
return 'Hello World!'
| [
"@",
"hug",
".",
"get",
"(",
")",
"def",
"hello",
"(",
"request",
")",
":",
"return",
"'Hello World!'"
] | return a friendly http greeting . | train | false |
48,721 | def apply_features(feature_func, toks, labeled=None):
if (labeled is None):
labeled = (toks and isinstance(toks[0], (tuple, list)))
if labeled:
def lazy_func(labeled_token):
return (feature_func(labeled_token[0]), labeled_token[1])
return LazyMap(lazy_func, toks)
else:
return LazyMap(feature_func, toks)
| [
"def",
"apply_features",
"(",
"feature_func",
",",
"toks",
",",
"labeled",
"=",
"None",
")",
":",
"if",
"(",
"labeled",
"is",
"None",
")",
":",
"labeled",
"=",
"(",
"toks",
"and",
"isinstance",
"(",
"toks",
"[",
"0",
"]",
",",
"(",
"tuple",
",",
"l... | use the lazymap class to construct a lazy list-like object that is analogous to map . | train | false |
48,722 | def ZigZagDecode(value):
if (not (value & 1)):
return (value >> 1)
return ((value >> 1) ^ (~ 0))
| [
"def",
"ZigZagDecode",
"(",
"value",
")",
":",
"if",
"(",
"not",
"(",
"value",
"&",
"1",
")",
")",
":",
"return",
"(",
"value",
">>",
"1",
")",
"return",
"(",
"(",
"value",
">>",
"1",
")",
"^",
"(",
"~",
"0",
")",
")"
] | inverse of zigzagencode() . | train | false |
48,724 | @log_call
def task_get_all(context, filters=None, marker=None, limit=None, sort_key='created_at', sort_dir='desc'):
_task_soft_delete(context)
filters = (filters or {})
tasks = DATA['tasks'].values()
tasks = _filter_tasks(tasks, filters, context)
tasks = _sort_tasks(tasks, sort_key, sort_dir)
tasks = _paginate_ta... | [
"@",
"log_call",
"def",
"task_get_all",
"(",
"context",
",",
"filters",
"=",
"None",
",",
"marker",
"=",
"None",
",",
"limit",
"=",
"None",
",",
"sort_key",
"=",
"'created_at'",
",",
"sort_dir",
"=",
"'desc'",
")",
":",
"_task_soft_delete",
"(",
"context",... | get all tasks that match zero or more filters . | train | false |
48,725 | @task(name='unit')
def unittest(ctx, args='', options=''):
pytest(ctx, args, options)
| [
"@",
"task",
"(",
"name",
"=",
"'unit'",
")",
"def",
"unittest",
"(",
"ctx",
",",
"args",
"=",
"''",
",",
"options",
"=",
"''",
")",
":",
"pytest",
"(",
"ctx",
",",
"args",
",",
"options",
")"
] | run unit tests . | train | false |
48,726 | def deconstructible(*args, **kwargs):
path = kwargs.pop('path', None)
def decorator(klass):
def __new__(cls, *args, **kwargs):
obj = super(klass, cls).__new__(cls)
obj._constructor_args = (args, kwargs)
return obj
def deconstruct(obj):
'\n Returns a 3-tuple of class import path, positional ... | [
"def",
"deconstructible",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"path",
"=",
"kwargs",
".",
"pop",
"(",
"'path'",
",",
"None",
")",
"def",
"decorator",
"(",
"klass",
")",
":",
"def",
"__new__",
"(",
"cls",
",",
"*",
"args",
",",
"**",
... | class decorator that allow the decorated class to be serialized by the migrations subsystem . | train | false |
48,728 | def scharr_v(image, mask=None):
assert_nD(image, 2)
image = img_as_float(image)
result = convolve(image, VSCHARR_WEIGHTS)
return _mask_filter_result(result, mask)
| [
"def",
"scharr_v",
"(",
"image",
",",
"mask",
"=",
"None",
")",
":",
"assert_nD",
"(",
"image",
",",
"2",
")",
"image",
"=",
"img_as_float",
"(",
"image",
")",
"result",
"=",
"convolve",
"(",
"image",
",",
"VSCHARR_WEIGHTS",
")",
"return",
"_mask_filter_... | find the vertical edges of an image using the scharr transform . | train | false |
48,729 | def check_secret(form_instance, secret):
return (make_secret(form_instance) == secret)
| [
"def",
"check_secret",
"(",
"form_instance",
",",
"secret",
")",
":",
"return",
"(",
"make_secret",
"(",
"form_instance",
")",
"==",
"secret",
")"
] | returns true if received secret matches expected secret for form_instance . | train | false |
48,731 | def csrf_failure(request, reason='', template_name=CSRF_FAILURE_TEMPLATE_NAME):
from django.middleware.csrf import REASON_NO_REFERER, REASON_NO_CSRF_COOKIE
c = {'title': _('Forbidden'), 'main': _('CSRF verification failed. Request aborted.'), 'reason': reason, 'no_referer': (reason == REASON_NO_REFERER), 'no_referer1... | [
"def",
"csrf_failure",
"(",
"request",
",",
"reason",
"=",
"''",
",",
"template_name",
"=",
"CSRF_FAILURE_TEMPLATE_NAME",
")",
":",
"from",
"django",
".",
"middleware",
".",
"csrf",
"import",
"REASON_NO_REFERER",
",",
"REASON_NO_CSRF_COOKIE",
"c",
"=",
"{",
"'ti... | default view used when request fails csrf protection . | train | false |
48,732 | def test_join_inplace():
s = tensor.lscalar()
x = tensor.vector('x')
z = tensor.zeros((s,))
join = Join(view=0)
c = join(0, x, z, z)
f = theano.function([theano.In(x, borrow=True), s], theano.Out(c, borrow=True))
data = numpy.array([3, 4, 5], dtype=theano.config.floatX)
print(f(data, 0))
if (theano.config.mode... | [
"def",
"test_join_inplace",
"(",
")",
":",
"s",
"=",
"tensor",
".",
"lscalar",
"(",
")",
"x",
"=",
"tensor",
".",
"vector",
"(",
"'x'",
")",
"z",
"=",
"tensor",
".",
"zeros",
"(",
"(",
"s",
",",
")",
")",
"join",
"=",
"Join",
"(",
"view",
"=",
... | test join to work inplace . | train | false |
48,733 | def label(object, index=None):
object = Carbon.File.FSRef(object)
object_alias = object.FSNewAliasMinimal()
if (index is None):
return _getlabel(object_alias)
if ((index < 0) or (index > 7)):
index = 0
return _setlabel(object_alias, index)
| [
"def",
"label",
"(",
"object",
",",
"index",
"=",
"None",
")",
":",
"object",
"=",
"Carbon",
".",
"File",
".",
"FSRef",
"(",
"object",
")",
"object_alias",
"=",
"object",
".",
"FSNewAliasMinimal",
"(",
")",
"if",
"(",
"index",
"is",
"None",
")",
":",... | label: set or get the label of the item . | train | false |
48,734 | def extract_modes(spans):
rangelen = sorted([((x['to'] - x['from']) + 1) for x in spans])
deflen = sorted(rangelen, key=rangelen.count)[(-1)]
reprs = [str2fmt(x['str']) for x in spans]
deffmt = sorted(reprs, key=reprs.count)[(-1)]
return (deflen, deffmt)
| [
"def",
"extract_modes",
"(",
"spans",
")",
":",
"rangelen",
"=",
"sorted",
"(",
"[",
"(",
"(",
"x",
"[",
"'to'",
"]",
"-",
"x",
"[",
"'from'",
"]",
")",
"+",
"1",
")",
"for",
"x",
"in",
"spans",
"]",
")",
"deflen",
"=",
"sorted",
"(",
"rangelen... | extract the most common spans lengths and representation formats . | train | false |
48,735 | def _idnaText(octets):
try:
import idna
except ImportError:
return octets.decode('idna')
else:
return idna.decode(octets)
| [
"def",
"_idnaText",
"(",
"octets",
")",
":",
"try",
":",
"import",
"idna",
"except",
"ImportError",
":",
"return",
"octets",
".",
"decode",
"(",
"'idna'",
")",
"else",
":",
"return",
"idna",
".",
"decode",
"(",
"octets",
")"
] | convert some idna-encoded octets into some human-readable text . | train | false |
48,736 | def inputhook_wx3():
try:
app = wx.GetApp()
if (app is not None):
assert wx.Thread_IsMain()
if (not callable(signal.getsignal(signal.SIGINT))):
signal.signal(signal.SIGINT, signal.default_int_handler)
evtloop = wx.EventLoop()
ea = wx.EventLoopActivator(evtloop)
t = clock()
while (not stdin_re... | [
"def",
"inputhook_wx3",
"(",
")",
":",
"try",
":",
"app",
"=",
"wx",
".",
"GetApp",
"(",
")",
"if",
"(",
"app",
"is",
"not",
"None",
")",
":",
"assert",
"wx",
".",
"Thread_IsMain",
"(",
")",
"if",
"(",
"not",
"callable",
"(",
"signal",
".",
"gets... | run the wx event loop by processing pending events only . | train | true |
48,739 | def primary_key(name='id'):
return field(name, INTEGER, index=PRIMARY, optional=False)
| [
"def",
"primary_key",
"(",
"name",
"=",
"'id'",
")",
":",
"return",
"field",
"(",
"name",
",",
"INTEGER",
",",
"index",
"=",
"PRIMARY",
",",
"optional",
"=",
"False",
")"
] | returns an auto-incremented integer primary key field named "id" . | train | false |
48,740 | def check_entry_points(dist, attr, value):
try:
pkg_resources.EntryPoint.parse_map(value)
except ValueError as e:
raise DistutilsSetupError(e)
| [
"def",
"check_entry_points",
"(",
"dist",
",",
"attr",
",",
"value",
")",
":",
"try",
":",
"pkg_resources",
".",
"EntryPoint",
".",
"parse_map",
"(",
"value",
")",
"except",
"ValueError",
"as",
"e",
":",
"raise",
"DistutilsSetupError",
"(",
"e",
")"
] | verify that entry_points map is parseable . | train | true |
48,744 | def _host_find(context, session, src_aggregate, host_ref):
uuid = session.host.get_uuid(host_ref)
for (compute_host, host_uuid) in src_aggregate.metadetails.items():
if (host_uuid == uuid):
return compute_host
raise exception.NoValidHost(reason=('Host %(host_uuid)s could not be found from aggregate metadata: %(... | [
"def",
"_host_find",
"(",
"context",
",",
"session",
",",
"src_aggregate",
",",
"host_ref",
")",
":",
"uuid",
"=",
"session",
".",
"host",
".",
"get_uuid",
"(",
"host_ref",
")",
"for",
"(",
"compute_host",
",",
"host_uuid",
")",
"in",
"src_aggregate",
".",... | return the host from the xenapi host reference . | train | false |
48,745 | def SplitIntoComponents(str_in):
if str_in.startswith(('"', "'")):
return shlex.split(str_in)
else:
components = str_in.split(' ', 1)
if (len(components) > 1):
return ([components[0]] + SplitIntoComponents(components[1]))
else:
return components
| [
"def",
"SplitIntoComponents",
"(",
"str_in",
")",
":",
"if",
"str_in",
".",
"startswith",
"(",
"(",
"'\"'",
",",
"\"'\"",
")",
")",
":",
"return",
"shlex",
".",
"split",
"(",
"str_in",
")",
"else",
":",
"components",
"=",
"str_in",
".",
"split",
"(",
... | splits strings into space-separated components . | train | true |
48,746 | def cpu_online_map():
cpus = []
for line in open('/proc/cpuinfo', 'r').readlines():
if line.startswith('processor'):
cpus.append(line.split()[2])
return cpus
| [
"def",
"cpu_online_map",
"(",
")",
":",
"cpus",
"=",
"[",
"]",
"for",
"line",
"in",
"open",
"(",
"'/proc/cpuinfo'",
",",
"'r'",
")",
".",
"readlines",
"(",
")",
":",
"if",
"line",
".",
"startswith",
"(",
"'processor'",
")",
":",
"cpus",
".",
"append"... | check out the available cpu online map . | train | false |
48,747 | def get_connection_info(user=True):
(section, keypath) = reg_info(user)
url = None
try:
hive = _winreg.ConnectRegistry(None, section)
key = _winreg.OpenKey(hive, (keypath + '\\api'))
for i in range(0, _winreg.QueryInfoKey(key)[1]):
(name, value, val_type) = _winreg.EnumValue(key, i)
if (name == 'url'):
... | [
"def",
"get_connection_info",
"(",
"user",
"=",
"True",
")",
":",
"(",
"section",
",",
"keypath",
")",
"=",
"reg_info",
"(",
"user",
")",
"url",
"=",
"None",
"try",
":",
"hive",
"=",
"_winreg",
".",
"ConnectRegistry",
"(",
"None",
",",
"section",
")",
... | return url of the api running sabnzbd instance user == true will first try users registry . | train | false |
48,748 | @register.simple_tag()
def crispy_addon(field, append='', prepend='', form_show_labels=True):
if field:
context = Context({'field': field, 'form_show_errors': True, 'form_show_labels': form_show_labels})
template = loader.get_template(('%s/layout/prepended_appended_text.html' % get_template_pack()))
context['cri... | [
"@",
"register",
".",
"simple_tag",
"(",
")",
"def",
"crispy_addon",
"(",
"field",
",",
"append",
"=",
"''",
",",
"prepend",
"=",
"''",
",",
"form_show_labels",
"=",
"True",
")",
":",
"if",
"field",
":",
"context",
"=",
"Context",
"(",
"{",
"'field'",
... | renders a form field using bootstraps prepended or appended text:: {% crispy_addon form . | train | true |
48,749 | def s3_phone_represent(value):
if (not value):
return current.messages['NONE']
return ('%s%s' % (unichr(8206), s3_unicode(value)))
| [
"def",
"s3_phone_represent",
"(",
"value",
")",
":",
"if",
"(",
"not",
"value",
")",
":",
"return",
"current",
".",
"messages",
"[",
"'NONE'",
"]",
"return",
"(",
"'%s%s'",
"%",
"(",
"unichr",
"(",
"8206",
")",
",",
"s3_unicode",
"(",
"value",
")",
"... | ensure that phone numbers always show as ltr - otherwise + appears at the end which looks wrong even in rtl . | train | false |
48,750 | def generate_rsa_key_pair(key_size=2048):
private_key = rsa.generate_private_key(public_exponent=65537, key_size=key_size, backend=default_backend())
private_key_str = private_key.private_bytes(Encoding.PEM, PrivateFormat.PKCS8, NoEncryption())
public_key_str = private_key.public_key().public_bytes(Encoding.PEM, Pub... | [
"def",
"generate_rsa_key_pair",
"(",
"key_size",
"=",
"2048",
")",
":",
"private_key",
"=",
"rsa",
".",
"generate_private_key",
"(",
"public_exponent",
"=",
"65537",
",",
"key_size",
"=",
"key_size",
",",
"backend",
"=",
"default_backend",
"(",
")",
")",
"priv... | generates a public and private rsa pem encoded key pair . | train | false |
48,754 | def _net_write(sock, data, expiration):
current = 0
l = len(data)
while (current < l):
_wait_for_writable(sock, expiration)
current += sock.send(data[current:])
| [
"def",
"_net_write",
"(",
"sock",
",",
"data",
",",
"expiration",
")",
":",
"current",
"=",
"0",
"l",
"=",
"len",
"(",
"data",
")",
"while",
"(",
"current",
"<",
"l",
")",
":",
"_wait_for_writable",
"(",
"sock",
",",
"expiration",
")",
"current",
"+=... | write the specified data to the socket . | train | true |
48,756 | def _set_asn1_time(boundary, when):
if (not isinstance(when, bytes)):
raise TypeError('when must be a byte string')
set_result = _lib.ASN1_GENERALIZEDTIME_set_string(_ffi.cast('ASN1_GENERALIZEDTIME*', boundary), when)
if (set_result == 0):
dummy = _ffi.gc(_lib.ASN1_STRING_new(), _lib.ASN1_STRING_free)
_lib.ASN... | [
"def",
"_set_asn1_time",
"(",
"boundary",
",",
"when",
")",
":",
"if",
"(",
"not",
"isinstance",
"(",
"when",
",",
"bytes",
")",
")",
":",
"raise",
"TypeError",
"(",
"'when must be a byte string'",
")",
"set_result",
"=",
"_lib",
".",
"ASN1_GENERALIZEDTIME_set... | the the time value of an asn1 time object . | train | false |
48,757 | def _match_emr_step_stderr_path(path, step_id=None):
return _match_emr_step_log_path(path, 'stderr', step_id=step_id)
| [
"def",
"_match_emr_step_stderr_path",
"(",
"path",
",",
"step_id",
"=",
"None",
")",
":",
"return",
"_match_emr_step_log_path",
"(",
"path",
",",
"'stderr'",
",",
"step_id",
"=",
"step_id",
")"
] | match path of a step stderr log . | train | false |
48,758 | def query_issues(page, after):
return read_url(get_issues_url(page, after))
| [
"def",
"query_issues",
"(",
"page",
",",
"after",
")",
":",
"return",
"read_url",
"(",
"get_issues_url",
"(",
"page",
",",
"after",
")",
")"
] | hits the github api for a single page of closed issues and returns the data . | train | false |
48,759 | def convert_pep0():
check_paths()
pep0_path = os.path.join(settings.PEP_REPO_PATH, 'pep-0000.html')
pep0_content = open(pep0_path).read()
soup = BeautifulSoup(pep0_content)
body_children = list(soup.body.children)
header = body_children[3]
pep_content = body_children[7]
body_links = pep_content.find_all('a')
p... | [
"def",
"convert_pep0",
"(",
")",
":",
"check_paths",
"(",
")",
"pep0_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"settings",
".",
"PEP_REPO_PATH",
",",
"'pep-0000.html'",
")",
"pep0_content",
"=",
"open",
"(",
"pep0_path",
")",
".",
"read",
"(",
")"... | take existing generated pep-0000 . | train | false |
48,760 | def get_calls(mock_observer_func):
return [call_tuple[0][0].name for call_tuple in mock_observer_func.calls]
| [
"def",
"get_calls",
"(",
"mock_observer_func",
")",
":",
"return",
"[",
"call_tuple",
"[",
"0",
"]",
"[",
"0",
"]",
".",
"name",
"for",
"call_tuple",
"in",
"mock_observer_func",
".",
"calls",
"]"
] | given a mock ipluginobserver method . | train | false |
48,763 | def createPythonExtensionBuilder(env):
try:
pyext = env['BUILDERS']['PythonExtension']
except KeyError:
import SCons.Action
import SCons.Defaults
action = SCons.Action.Action('$PYEXTLINKCOM', '$PYEXTLINKCOMSTR')
action_list = [SCons.Defaults.SharedCheck, action]
pyext = SCons.Builder.Builder(action=action... | [
"def",
"createPythonExtensionBuilder",
"(",
"env",
")",
":",
"try",
":",
"pyext",
"=",
"env",
"[",
"'BUILDERS'",
"]",
"[",
"'PythonExtension'",
"]",
"except",
"KeyError",
":",
"import",
"SCons",
".",
"Action",
"import",
"SCons",
".",
"Defaults",
"action",
"=... | this is a utility function that creates the pythonextension builder in an environment if it is not there already . | train | false |
48,764 | def encrypt_password(password):
if (_security.password_hash == 'plaintext'):
return password
signed = get_hmac(password).decode('ascii')
return _pwd_context.encrypt(signed)
| [
"def",
"encrypt_password",
"(",
"password",
")",
":",
"if",
"(",
"_security",
".",
"password_hash",
"==",
"'plaintext'",
")",
":",
"return",
"password",
"signed",
"=",
"get_hmac",
"(",
"password",
")",
".",
"decode",
"(",
"'ascii'",
")",
"return",
"_pwd_cont... | encrypts the specified plaintext password using the configured encryption options . | train | false |
48,765 | def strip_email_quotes(text):
lines = text.splitlines()
matches = set()
for line in lines:
prefix = re.match('^(\\s*>[ >]*)', line)
if prefix:
matches.add(prefix.group(1))
else:
break
else:
prefix = long_substr(list(matches))
if prefix:
strip = len(prefix)
text = '\n'.join([ln[strip:] for ln i... | [
"def",
"strip_email_quotes",
"(",
"text",
")",
":",
"lines",
"=",
"text",
".",
"splitlines",
"(",
")",
"matches",
"=",
"set",
"(",
")",
"for",
"line",
"in",
"lines",
":",
"prefix",
"=",
"re",
".",
"match",
"(",
"'^(\\\\s*>[ >]*)'",
",",
"line",
")",
... | strip leading email quotation characters (>) . | train | true |
48,766 | def policy_exists(vhost, name, runas=None):
if ((runas is None) and (not salt.utils.is_windows())):
runas = salt.utils.get_user()
policies = list_policies(runas=runas)
return bool(((vhost in policies) and (name in policies[vhost])))
| [
"def",
"policy_exists",
"(",
"vhost",
",",
"name",
",",
"runas",
"=",
"None",
")",
":",
"if",
"(",
"(",
"runas",
"is",
"None",
")",
"and",
"(",
"not",
"salt",
".",
"utils",
".",
"is_windows",
"(",
")",
")",
")",
":",
"runas",
"=",
"salt",
".",
... | check to see if policy exists . | train | true |
48,767 | def p_expression_group_error(t):
(line_start, line_end) = t.linespan(2)
(pos_start, pos_end) = t.lexspan(2)
print ('Syntax error at %d:%d to %d:%d' % (line_start, pos_start, line_end, pos_end))
t[0] = 0
| [
"def",
"p_expression_group_error",
"(",
"t",
")",
":",
"(",
"line_start",
",",
"line_end",
")",
"=",
"t",
".",
"linespan",
"(",
"2",
")",
"(",
"pos_start",
",",
"pos_end",
")",
"=",
"t",
".",
"lexspan",
"(",
"2",
")",
"print",
"(",
"'Syntax error at %d... | expression : lparen error rparen . | train | false |
48,772 | def pre_track_containers_create_policy_stat(self, conn):
conn.executescript('\n CREATE TABLE policy_stat (\n storage_policy_index INTEGER PRIMARY KEY,\n object_count INTEGER DEFAULT 0,\n bytes_used INTEGER DEFAULT 0\n );\n INSERT OR IGNORE INTO policy_stat (\n ... | [
"def",
"pre_track_containers_create_policy_stat",
"(",
"self",
",",
"conn",
")",
":",
"conn",
".",
"executescript",
"(",
"'\\n CREATE TABLE policy_stat (\\n storage_policy_index INTEGER PRIMARY KEY,\\n object_count INTEGER DEFAULT 0,\\n bytes_used INTE... | copied from accountbroker before the container_count column was added . | train | false |
48,773 | def parse_failed_targets(test_registry, junit_xml_dir, error_handler):
failed_targets = defaultdict(set)
for name in os.listdir(junit_xml_dir):
if _JUNIT_XML_MATCHER.match(name):
try:
path = os.path.join(junit_xml_dir, name)
xml = XmlParser.from_file(path)
failures = int(xml.get_attribute(u'testsuite... | [
"def",
"parse_failed_targets",
"(",
"test_registry",
",",
"junit_xml_dir",
",",
"error_handler",
")",
":",
"failed_targets",
"=",
"defaultdict",
"(",
"set",
")",
"for",
"name",
"in",
"os",
".",
"listdir",
"(",
"junit_xml_dir",
")",
":",
"if",
"_JUNIT_XML_MATCHER... | parses junit xml reports and maps targets to the set of individual tests that failed . | train | false |
48,774 | def extract_bigram_feats(document, bigrams):
features = {}
for bigr in bigrams:
features['contains({0} - {1})'.format(bigr[0], bigr[1])] = (bigr in nltk.bigrams(document))
return features
| [
"def",
"extract_bigram_feats",
"(",
"document",
",",
"bigrams",
")",
":",
"features",
"=",
"{",
"}",
"for",
"bigr",
"in",
"bigrams",
":",
"features",
"[",
"'contains({0} - {1})'",
".",
"format",
"(",
"bigr",
"[",
"0",
"]",
",",
"bigr",
"[",
"1",
"]",
"... | populate a dictionary of bigram features . | train | false |
48,775 | def get_users_emails(send_type):
sql = "\n SELECT json_build_object(\n 'user_id', osf_guid._id,\n 'info', json_agg(\n json_build_object(\n 'message', nd.message,\n 'node_lineage', nd.node_lineage,\n '_id', nd._id\n ... | [
"def",
"get_users_emails",
"(",
"send_type",
")",
":",
"sql",
"=",
"\"\\n SELECT json_build_object(\\n 'user_id', osf_guid._id,\\n 'info', json_agg(\\n json_build_object(\\n 'message', nd.message,\\n 'node_lineage', nd.nod... | get all emails that need to be sent . | train | false |
48,776 | def get_conf_path(filename=None):
if sys.platform.startswith('linux'):
xdg_config_home = os.environ.get('XDG_CONFIG_HOME', '')
if (not xdg_config_home):
xdg_config_home = osp.join(get_home_dir(), '.config')
if (not osp.isdir(xdg_config_home)):
os.makedirs(xdg_config_home)
conf_dir = osp.join(xdg_config_h... | [
"def",
"get_conf_path",
"(",
"filename",
"=",
"None",
")",
":",
"if",
"sys",
".",
"platform",
".",
"startswith",
"(",
"'linux'",
")",
":",
"xdg_config_home",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'XDG_CONFIG_HOME'",
",",
"''",
")",
"if",
"(",
"n... | return absolute path for configuration file with specified filename . | train | true |
48,777 | def Decompression_rar(specific_file):
cmd = ((((('unrar x "' + specific_file) + '"') + ' "') + os.path.split(specific_file)[0]) + '"')
os.system(cmd)
| [
"def",
"Decompression_rar",
"(",
"specific_file",
")",
":",
"cmd",
"=",
"(",
"(",
"(",
"(",
"(",
"'unrar x \"'",
"+",
"specific_file",
")",
"+",
"'\"'",
")",
"+",
"' \"'",
")",
"+",
"os",
".",
"path",
".",
"split",
"(",
"specific_file",
")",
"[",
"0"... | decompression_rar if you want use this function . | train | false |
48,779 | @login_required
def message_list(request, mailbox=None, template_name='messages/message_list.html'):
message_list = _get_messages(request.user, mailbox)
return render_to_response(template_name, {'message_list': message_list, 'mailbox': (mailbox or 'archive')}, context_instance=RequestContext(request))
| [
"@",
"login_required",
"def",
"message_list",
"(",
"request",
",",
"mailbox",
"=",
"None",
",",
"template_name",
"=",
"'messages/message_list.html'",
")",
":",
"message_list",
"=",
"_get_messages",
"(",
"request",
".",
"user",
",",
"mailbox",
")",
"return",
"ren... | returns a list of user messages . | train | false |
48,780 | def pager(text):
global pager
pager = getpager()
pager(text)
| [
"def",
"pager",
"(",
"text",
")",
":",
"global",
"pager",
"pager",
"=",
"getpager",
"(",
")",
"pager",
"(",
"text",
")"
] | paging output . | train | false |
48,781 | def get_clients(node):
return [c for (c, i) in node.outputs[0].clients if (c != 'output')]
| [
"def",
"get_clients",
"(",
"node",
")",
":",
"return",
"[",
"c",
"for",
"(",
"c",
",",
"i",
")",
"in",
"node",
".",
"outputs",
"[",
"0",
"]",
".",
"clients",
"if",
"(",
"c",
"!=",
"'output'",
")",
"]"
] | used by erf/erfc opt to track less frequent op . | train | false |
48,782 | def split_context(method, args, kwargs):
pos = (len(getargspec(method).args) - 1)
if (pos < len(args)):
return (args[pos], args[:pos], kwargs)
else:
return (kwargs.pop('context', None), args, kwargs)
| [
"def",
"split_context",
"(",
"method",
",",
"args",
",",
"kwargs",
")",
":",
"pos",
"=",
"(",
"len",
"(",
"getargspec",
"(",
"method",
")",
".",
"args",
")",
"-",
"1",
")",
"if",
"(",
"pos",
"<",
"len",
"(",
"args",
")",
")",
":",
"return",
"("... | extract the context from a pair of positional and keyword arguments . | train | false |
48,785 | def iscsi_discover(portal_ip):
cmd = ('iscsiadm -m discovery -t sendtargets -p %s' % portal_ip)
output = utils.system_output(cmd, ignore_status=True)
session = ''
if ('Invalid' in output):
logging.debug(output)
else:
session = output
return session
| [
"def",
"iscsi_discover",
"(",
"portal_ip",
")",
":",
"cmd",
"=",
"(",
"'iscsiadm -m discovery -t sendtargets -p %s'",
"%",
"portal_ip",
")",
"output",
"=",
"utils",
".",
"system_output",
"(",
"cmd",
",",
"ignore_status",
"=",
"True",
")",
"session",
"=",
"''",
... | query from iscsi server for available targets . | train | false |
48,786 | def test_field_assign():
from IronPythonTest.BinderTest import KeywordBase
def f():
KeywordBase.SomeField = 42
AssertError(ValueError, f)
| [
"def",
"test_field_assign",
"(",
")",
":",
"from",
"IronPythonTest",
".",
"BinderTest",
"import",
"KeywordBase",
"def",
"f",
"(",
")",
":",
"KeywordBase",
".",
"SomeField",
"=",
"42",
"AssertError",
"(",
"ValueError",
",",
"f",
")"
] | assign to an instance field through the type . | train | false |
48,788 | def building_marker_fn(record):
if (record.asbestos == 1):
marker = 'hazmat'
else:
marker = 'residence'
priority = record.priority
if (priority == 1):
marker = ('%s_red' % marker)
elif (priority == 2):
marker = ('%s_yellow' % marker)
elif (priority == 3):
marker = ('%s_green' % marker)
mtable = db.gis_... | [
"def",
"building_marker_fn",
"(",
"record",
")",
":",
"if",
"(",
"record",
".",
"asbestos",
"==",
"1",
")",
":",
"marker",
"=",
"'hazmat'",
"else",
":",
"marker",
"=",
"'residence'",
"priority",
"=",
"record",
".",
"priority",
"if",
"(",
"priority",
"=="... | function to decide which marker to use for building assessments map @todo: legend @todo: move to templates . | train | false |
48,789 | def get_vcs_info(path):
for info in SUPPORTED:
vcs_path = osp.join(path, info['rootdir'])
if osp.isdir(vcs_path):
return info
| [
"def",
"get_vcs_info",
"(",
"path",
")",
":",
"for",
"info",
"in",
"SUPPORTED",
":",
"vcs_path",
"=",
"osp",
".",
"join",
"(",
"path",
",",
"info",
"[",
"'rootdir'",
"]",
")",
"if",
"osp",
".",
"isdir",
"(",
"vcs_path",
")",
":",
"return",
"info"
] | return support status dict if path is under vcs root . | train | true |
48,790 | def start_webserver(ip, port, webroot, handler=WebHandler):
web_server = _get_inst(ip, port)
if ((web_server is None) or web_server.is_down()):
web_server = HTTPServer((ip, port), webroot, handler)
_servers[(ip, port)] = web_server
server_thread = threading.Thread(target=web_server.serve_forever)
server_threa... | [
"def",
"start_webserver",
"(",
"ip",
",",
"port",
",",
"webroot",
",",
"handler",
"=",
"WebHandler",
")",
":",
"web_server",
"=",
"_get_inst",
"(",
"ip",
",",
"port",
")",
"if",
"(",
"(",
"web_server",
"is",
"None",
")",
"or",
"web_server",
".",
"is_do... | create a http server daemon . | train | false |
48,791 | def test_ordered_dict_value_validator():
schema = vol.Schema(cv.ordered_dict(cv.string))
with pytest.raises(vol.Invalid):
schema({'hello': None})
schema({'hello': 'world'})
schema = vol.Schema(cv.ordered_dict(int))
with pytest.raises(vol.Invalid):
schema({'hello': 'world'})
schema({'hello': 5})
| [
"def",
"test_ordered_dict_value_validator",
"(",
")",
":",
"schema",
"=",
"vol",
".",
"Schema",
"(",
"cv",
".",
"ordered_dict",
"(",
"cv",
".",
"string",
")",
")",
"with",
"pytest",
".",
"raises",
"(",
"vol",
".",
"Invalid",
")",
":",
"schema",
"(",
"{... | test ordered_dict validator . | train | false |
48,792 | def extract_special_queries(queries):
specials = {}
dc = queries.copy()
for i in queries:
if (i.startswith('__') and (i in FILTERS_LIST)):
specials[i] = queries[i]
del dc[i]
return (dc, specials)
| [
"def",
"extract_special_queries",
"(",
"queries",
")",
":",
"specials",
"=",
"{",
"}",
"dc",
"=",
"queries",
".",
"copy",
"(",
")",
"for",
"i",
"in",
"queries",
":",
"if",
"(",
"i",
".",
"startswith",
"(",
"'__'",
")",
"and",
"(",
"i",
"in",
"FILTE... | separate special queries from normal queries . | train | false |
48,793 | def _float_feature(value):
if (not isinstance(value, list)):
value = [value]
return tf.train.Feature(float_list=tf.train.FloatList(value=value))
| [
"def",
"_float_feature",
"(",
"value",
")",
":",
"if",
"(",
"not",
"isinstance",
"(",
"value",
",",
"list",
")",
")",
":",
"value",
"=",
"[",
"value",
"]",
"return",
"tf",
".",
"train",
".",
"Feature",
"(",
"float_list",
"=",
"tf",
".",
"train",
".... | wrapper for inserting float features into example proto . | train | true |
48,796 | @verbose
def find_eog_events(raw, event_id=998, l_freq=1, h_freq=10, filter_length='10s', ch_name=None, tstart=0, verbose=None):
eog_inds = _get_eog_channel_index(ch_name, raw)
logger.info(('EOG channel index for this subject is: %s' % eog_inds))
(eog, _) = raw[eog_inds, :]
eog_events = _find_eog_events(eog, event_... | [
"@",
"verbose",
"def",
"find_eog_events",
"(",
"raw",
",",
"event_id",
"=",
"998",
",",
"l_freq",
"=",
"1",
",",
"h_freq",
"=",
"10",
",",
"filter_length",
"=",
"'10s'",
",",
"ch_name",
"=",
"None",
",",
"tstart",
"=",
"0",
",",
"verbose",
"=",
"None... | locate eog artifacts . | train | false |
48,797 | def get_rendition_or_not_found(image, specs):
try:
return image.get_rendition(specs)
except SourceImageIOError:
Rendition = image.renditions.model
rendition = Rendition(image=image, width=0, height=0)
rendition.file.name = u'not-found'
return rendition
| [
"def",
"get_rendition_or_not_found",
"(",
"image",
",",
"specs",
")",
":",
"try",
":",
"return",
"image",
".",
"get_rendition",
"(",
"specs",
")",
"except",
"SourceImageIOError",
":",
"Rendition",
"=",
"image",
".",
"renditions",
".",
"model",
"rendition",
"="... | tries to get / create the rendition for the image or renders a not-found image if it does not exist . | train | false |
48,798 | def build_headers(api_token):
headers = {'X-Circonus-App-Name': 'ansible', 'Host': 'api.circonus.com', 'X-Circonus-Auth-Token': api_token, 'Accept': 'application/json'}
return headers
| [
"def",
"build_headers",
"(",
"api_token",
")",
":",
"headers",
"=",
"{",
"'X-Circonus-App-Name'",
":",
"'ansible'",
",",
"'Host'",
":",
"'api.circonus.com'",
",",
"'X-Circonus-Auth-Token'",
":",
"api_token",
",",
"'Accept'",
":",
"'application/json'",
"}",
"return",... | takes api token . | train | false |
48,799 | @gof.local_optimizer([sparse.Remove0])
def local_inplace_remove0(node):
if (isinstance(node.op, sparse.Remove0) and (not node.op.inplace)):
new_op = node.op.__class__(inplace=True)
new_node = new_op(*node.inputs)
return [new_node]
return False
| [
"@",
"gof",
".",
"local_optimizer",
"(",
"[",
"sparse",
".",
"Remove0",
"]",
")",
"def",
"local_inplace_remove0",
"(",
"node",
")",
":",
"if",
"(",
"isinstance",
"(",
"node",
".",
"op",
",",
"sparse",
".",
"Remove0",
")",
"and",
"(",
"not",
"node",
"... | optimization to insert inplace versions of remove0 . | train | false |
48,801 | def _check_rc(rc, errno=None):
if (rc == (-1)):
if (errno is None):
from zmq.backend import zmq_errno
errno = zmq_errno()
from zmq import EAGAIN, ETERM
if (errno == EINTR):
raise InterruptedSystemCall(errno)
elif (errno == EAGAIN):
raise Again(errno)
elif (errno == ETERM):
raise ContextTermina... | [
"def",
"_check_rc",
"(",
"rc",
",",
"errno",
"=",
"None",
")",
":",
"if",
"(",
"rc",
"==",
"(",
"-",
"1",
")",
")",
":",
"if",
"(",
"errno",
"is",
"None",
")",
":",
"from",
"zmq",
".",
"backend",
"import",
"zmq_errno",
"errno",
"=",
"zmq_errno",
... | internal utility for checking zmq return condition and raising the appropriate exception class . | train | false |
48,802 | def remove_headers(*headers):
def _decorator(func):
'\n Decorates the given function.\n '
@wraps(func)
def _inner(*args, **kwargs):
'\n Alters the response.\n '
response = func(*args, **kwargs)
remove_headers_from_response(response, *headers)
return response
retu... | [
"def",
"remove_headers",
"(",
"*",
"headers",
")",
":",
"def",
"_decorator",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"_inner",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"response",
"=",
"func",
"(",
"*",
"args",
",",
... | decorator that removes specific headers from the response . | train | false |
48,803 | def dmp_permute(f, P, u, K):
(F, H) = (dmp_to_dict(f, u), {})
for (exp, coeff) in F.items():
new_exp = ([0] * len(exp))
for (e, p) in zip(exp, P):
new_exp[p] = e
H[tuple(new_exp)] = coeff
return dmp_from_dict(H, u, K)
| [
"def",
"dmp_permute",
"(",
"f",
",",
"P",
",",
"u",
",",
"K",
")",
":",
"(",
"F",
",",
"H",
")",
"=",
"(",
"dmp_to_dict",
"(",
"f",
",",
"u",
")",
",",
"{",
"}",
")",
"for",
"(",
"exp",
",",
"coeff",
")",
"in",
"F",
".",
"items",
"(",
"... | return a polynomial in k[x_{p(1)} . | train | false |
48,804 | def _get_service_command_generator(run=utils.run):
global _service_command_generator
try:
return _service_command_generator
except NameError:
command_generator = _command_generators[get_name_of_init(run)]
_service_command_generator = _ServiceCommandGenerator(command_generator)
return _service_command_generat... | [
"def",
"_get_service_command_generator",
"(",
"run",
"=",
"utils",
".",
"run",
")",
":",
"global",
"_service_command_generator",
"try",
":",
"return",
"_service_command_generator",
"except",
"NameError",
":",
"command_generator",
"=",
"_command_generators",
"[",
"get_na... | lazy initializer for servicecommandgenerator using the auto-detect init command . | train | false |
48,805 | def json_splitter(buffer):
try:
(obj, index) = json_decoder.raw_decode(buffer)
rest = buffer[json.decoder.WHITESPACE.match(buffer, index).end():]
return (obj, rest)
except ValueError:
return None
| [
"def",
"json_splitter",
"(",
"buffer",
")",
":",
"try",
":",
"(",
"obj",
",",
"index",
")",
"=",
"json_decoder",
".",
"raw_decode",
"(",
"buffer",
")",
"rest",
"=",
"buffer",
"[",
"json",
".",
"decoder",
".",
"WHITESPACE",
".",
"match",
"(",
"buffer",
... | attempt to parse a json object from a buffer . | train | true |
48,806 | def filenameToModuleName(fn):
if isinstance(fn, bytes):
initPy = '__init__.py'
else:
initPy = '__init__.py'
fullName = os.path.abspath(fn)
base = os.path.basename(fn)
if (not base):
base = os.path.basename(fn[:(-1)])
modName = nativeString(os.path.splitext(base)[0])
while 1:
fullName = os.path.dirname(fu... | [
"def",
"filenameToModuleName",
"(",
"fn",
")",
":",
"if",
"isinstance",
"(",
"fn",
",",
"bytes",
")",
":",
"initPy",
"=",
"'__init__.py'",
"else",
":",
"initPy",
"=",
"'__init__.py'",
"fullName",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"fn",
")",
... | convert a name in the filesystem to the name of the python module it is . | train | false |
48,807 | def _package_conf_file_to_dir(file_name):
if (file_name in SUPPORTED_CONFS):
path = BASE_PATH.format(file_name)
if os.path.exists(path):
if os.path.isdir(path):
return False
else:
os.rename(path, (path + '.tmpbak'))
os.mkdir(path, 493)
with salt.utils.fopen((path + '.tmpbak')) as fh_:
fo... | [
"def",
"_package_conf_file_to_dir",
"(",
"file_name",
")",
":",
"if",
"(",
"file_name",
"in",
"SUPPORTED_CONFS",
")",
":",
"path",
"=",
"BASE_PATH",
".",
"format",
"(",
"file_name",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"if"... | convert a config file to a config directory . | train | false |
48,809 | def trigger_build(project, version=None, record=True, force=False, basic=False):
from readthedocs.projects.tasks import update_docs
from readthedocs.builds.models import Build
if project.skip:
return None
if (not version):
version = project.versions.get(slug=LATEST)
kwargs = dict(pk=project.pk, version_pk=vers... | [
"def",
"trigger_build",
"(",
"project",
",",
"version",
"=",
"None",
",",
"record",
"=",
"True",
",",
"force",
"=",
"False",
",",
"basic",
"=",
"False",
")",
":",
"from",
"readthedocs",
".",
"projects",
".",
"tasks",
"import",
"update_docs",
"from",
"rea... | trigger build for project and version if project has a build_queue . | train | false |
48,811 | def StringToMakefileVariable(string):
return re.sub('[^a-zA-Z0-9_]', '_', string)
| [
"def",
"StringToMakefileVariable",
"(",
"string",
")",
":",
"return",
"re",
".",
"sub",
"(",
"'[^a-zA-Z0-9_]'",
",",
"'_'",
",",
"string",
")"
] | convert a string to a value that is acceptable as a make variable name . | train | false |
48,813 | def map_base_attributes(cube, mapper_class, naming, locale=None):
base = [attr for attr in cube.all_attributes if attr.is_base]
mapper = mapper_class(cube, naming, locale)
mapped = {attr.ref: mapper[attr] for attr in base}
return (mapper.fact_name, mapped)
| [
"def",
"map_base_attributes",
"(",
"cube",
",",
"mapper_class",
",",
"naming",
",",
"locale",
"=",
"None",
")",
":",
"base",
"=",
"[",
"attr",
"for",
"attr",
"in",
"cube",
".",
"all_attributes",
"if",
"attr",
".",
"is_base",
"]",
"mapper",
"=",
"mapper_c... | map all base attributes of cube using mapping function mapper . | train | false |
48,814 | def user_has_perm_note(note, profile, request=None):
if (note.author and (note.author.id == profile.id)):
return True
if (request and (note.note_type == comm.REVIEWER_COMMENT)):
return acl.check_reviewer(request)
if (request and (note.note_type == comm.DEVELOPER_COMMENT) and acl.check_reviewer(request)):
retur... | [
"def",
"user_has_perm_note",
"(",
"note",
",",
"profile",
",",
"request",
"=",
"None",
")",
":",
"if",
"(",
"note",
".",
"author",
"and",
"(",
"note",
".",
"author",
".",
"id",
"==",
"profile",
".",
"id",
")",
")",
":",
"return",
"True",
"if",
"(",... | check if the user has read/write permissions on the given note . | train | false |
48,815 | def _get_k_p_a(font, left, right):
chars = (left + right)
args = [None, 1, cf.kCFTypeDictionaryKeyCallBacks, cf.kCFTypeDictionaryValueCallBacks]
attributes = cf.CFDictionaryCreateMutable(*args)
cf.CFDictionaryAddValue(attributes, kCTFontAttributeName, font)
string = cf.CFAttributedStringCreate(None, CFSTR(chars), ... | [
"def",
"_get_k_p_a",
"(",
"font",
",",
"left",
",",
"right",
")",
":",
"chars",
"=",
"(",
"left",
"+",
"right",
")",
"args",
"=",
"[",
"None",
",",
"1",
",",
"cf",
".",
"kCFTypeDictionaryKeyCallBacks",
",",
"cf",
".",
"kCFTypeDictionaryValueCallBacks",
"... | this actually calculates the kerning + advance . | train | true |
48,816 | def assert_series_equal(left, right, check_names=True, **kwargs):
try:
return tm.assert_series_equal(left, right, check_names=check_names, **kwargs)
except TypeError:
if check_names:
assert (left.name == right.name)
return tm.assert_series_equal(left, right, **kwargs)
| [
"def",
"assert_series_equal",
"(",
"left",
",",
"right",
",",
"check_names",
"=",
"True",
",",
"**",
"kwargs",
")",
":",
"try",
":",
"return",
"tm",
".",
"assert_series_equal",
"(",
"left",
",",
"right",
",",
"check_names",
"=",
"check_names",
",",
"**",
... | backwards compatibility wrapper for pandas . | train | false |
48,818 | def Indicator(pos, size, dtype):
x = numpy.zeros(size, dtype=dtype)
x[pos] = 1
return x
| [
"def",
"Indicator",
"(",
"pos",
",",
"size",
",",
"dtype",
")",
":",
"x",
"=",
"numpy",
".",
"zeros",
"(",
"size",
",",
"dtype",
"=",
"dtype",
")",
"x",
"[",
"pos",
"]",
"=",
"1",
"return",
"x"
] | returns an array of length size and type dtype that is everywhere 0 . | train | true |
48,819 | def upcast_scalar(dtype, scalar):
return (np.array([0], dtype=dtype) * scalar).dtype
| [
"def",
"upcast_scalar",
"(",
"dtype",
",",
"scalar",
")",
":",
"return",
"(",
"np",
".",
"array",
"(",
"[",
"0",
"]",
",",
"dtype",
"=",
"dtype",
")",
"*",
"scalar",
")",
".",
"dtype"
] | determine data type for binary operation between an array of type dtype and a scalar . | train | false |
48,820 | @mock_autoscaling
def test_create_launch_configuration_defaults():
conn = boto.connect_autoscale()
config = LaunchConfiguration(name=u'tester', image_id=u'ami-abcd1234', instance_type=u'm1.small')
conn.create_launch_configuration(config)
launch_config = conn.get_all_launch_configurations()[0]
launch_config.name.sh... | [
"@",
"mock_autoscaling",
"def",
"test_create_launch_configuration_defaults",
"(",
")",
":",
"conn",
"=",
"boto",
".",
"connect_autoscale",
"(",
")",
"config",
"=",
"LaunchConfiguration",
"(",
"name",
"=",
"u'tester'",
",",
"image_id",
"=",
"u'ami-abcd1234'",
",",
... | test with the minimum inputs and check that all of the proper defaults are assigned for the other attributes . | train | false |
48,821 | def fuzzy_not(v):
if (v is None):
return v
else:
return (not v)
| [
"def",
"fuzzy_not",
"(",
"v",
")",
":",
"if",
"(",
"v",
"is",
"None",
")",
":",
"return",
"v",
"else",
":",
"return",
"(",
"not",
"v",
")"
] | not in fuzzy logic return none if v is none else not v . | train | false |
48,822 | def test_cookie_jar_init(config_stub, fake_save_manager):
line_parser_stub = [COOKIE1, COOKIE2]
jar = cookies.CookieJar(line_parser=line_parser_stub)
assert fake_save_manager.add_saveable.called
assert (len(jar.allCookies()) == 2)
raw_cookies = [c.toRawForm().data() for c in jar.allCookies()]
assert (raw_cookies ... | [
"def",
"test_cookie_jar_init",
"(",
"config_stub",
",",
"fake_save_manager",
")",
":",
"line_parser_stub",
"=",
"[",
"COOKIE1",
",",
"COOKIE2",
"]",
"jar",
"=",
"cookies",
".",
"CookieJar",
"(",
"line_parser",
"=",
"line_parser_stub",
")",
"assert",
"fake_save_man... | test the cookiejar constructor . | train | false |
48,823 | def skip(reason):
return skipif(True, reason=reason)
| [
"def",
"skip",
"(",
"reason",
")",
":",
"return",
"skipif",
"(",
"True",
",",
"reason",
"=",
"reason",
")"
] | unconditionally skip the currently decorated test with the passed reason . | train | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.