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
2,282
def parse257(resp): if (resp[:3] != '257'): raise error_reply(resp) if (resp[3:5] != ' "'): return '' dirname = '' i = 5 n = len(resp) while (i < n): c = resp[i] i = (i + 1) if (c == '"'): if ((i >= n) or (resp[i] != '"')): break i = (i + 1) dirname = (dirname + c) return dirname
[ "def", "parse257", "(", "resp", ")", ":", "if", "(", "resp", "[", ":", "3", "]", "!=", "'257'", ")", ":", "raise", "error_reply", "(", "resp", ")", "if", "(", "resp", "[", "3", ":", "5", "]", "!=", "' \"'", ")", ":", "return", "''", "dirname", ...
parse the 257 response for a mkd or pwd request .
train
false
2,283
def test_argument_destructuring(): can_compile(u'(fn [[a b]] (print a b))') cant_compile(u'(fn [[]] 0)')
[ "def", "test_argument_destructuring", "(", ")", ":", "can_compile", "(", "u'(fn [[a b]] (print a b))'", ")", "cant_compile", "(", "u'(fn [[]] 0)'", ")" ]
ensure argument destructuring compilers .
train
false
2,284
def export_languages_json(): languages = frappe.db.get_all(u'Language', fields=[u'name', u'language_name']) languages = [{u'name': d.language_name, u'code': d.name} for d in languages] languages.sort((lambda a, b: (1 if (a[u'code'] > b[u'code']) else (-1)))) with open(frappe.get_app_path(u'frappe', u'geo', u'langua...
[ "def", "export_languages_json", "(", ")", ":", "languages", "=", "frappe", ".", "db", ".", "get_all", "(", "u'Language'", ",", "fields", "=", "[", "u'name'", ",", "u'language_name'", "]", ")", "languages", "=", "[", "{", "u'name'", ":", "d", ".", "langua...
export list of all languages .
train
false
2,285
def getInsetSeparateLoopsFromAroundLoops(loops, radius, radiusAround, thresholdRatio=0.9): if (radius == 0.0): return loops isInset = (radius > 0) insetSeparateLoops = [] radius = abs(radius) radiusAround = max(abs(radiusAround), radius) points = getPointsFromLoops(loops, radiusAround, thresholdRatio) centers ...
[ "def", "getInsetSeparateLoopsFromAroundLoops", "(", "loops", ",", "radius", ",", "radiusAround", ",", "thresholdRatio", "=", "0.9", ")", ":", "if", "(", "radius", "==", "0.0", ")", ":", "return", "loops", "isInset", "=", "(", "radius", ">", "0", ")", "inse...
get the separate inset loops .
train
false
2,286
@profiler.trace def flavor_extra_delete(request, flavor_id, keys): flavor = novaclient(request).flavors.get(flavor_id) return flavor.unset_keys(keys)
[ "@", "profiler", ".", "trace", "def", "flavor_extra_delete", "(", "request", ",", "flavor_id", ",", "keys", ")", ":", "flavor", "=", "novaclient", "(", "request", ")", ".", "flavors", ".", "get", "(", "flavor_id", ")", "return", "flavor", ".", "unset_keys"...
unset the flavor extra spec keys .
train
false
2,288
@contextmanager def parallel_backend(backend, n_jobs=(-1), **backend_params): if isinstance(backend, _basestring): backend = BACKENDS[backend](**backend_params) old_backend_and_jobs = getattr(_backend, 'backend_and_jobs', None) try: _backend.backend_and_jobs = (backend, n_jobs) (yield (backend, n_jobs)) final...
[ "@", "contextmanager", "def", "parallel_backend", "(", "backend", ",", "n_jobs", "=", "(", "-", "1", ")", ",", "**", "backend_params", ")", ":", "if", "isinstance", "(", "backend", ",", "_basestring", ")", ":", "backend", "=", "BACKENDS", "[", "backend", ...
change the default backend used by parallel inside a with block .
train
false
2,289
def export_key(keyids=None, secret=False, user=None, gnupghome=None): gpg = _create_gpg(user, gnupghome) if isinstance(keyids, six.string_types): keyids = keyids.split(',') return gpg.export_keys(keyids, secret)
[ "def", "export_key", "(", "keyids", "=", "None", ",", "secret", "=", "False", ",", "user", "=", "None", ",", "gnupghome", "=", "None", ")", ":", "gpg", "=", "_create_gpg", "(", "user", ",", "gnupghome", ")", "if", "isinstance", "(", "keyids", ",", "s...
export a key from the gpg keychain keyids the key id(s) of the key(s) to be exported .
train
true
2,290
def is_executable_file(path): fpath = os.path.realpath(path) if (not os.path.isfile(fpath)): return False mode = os.stat(fpath).st_mode if (sys.platform.startswith('sunos') and (os.getuid() == 0)): return bool((mode & ((stat.S_IXUSR | stat.S_IXGRP) | stat.S_IXOTH))) return os.access(fpath, os.X_OK)
[ "def", "is_executable_file", "(", "path", ")", ":", "fpath", "=", "os", ".", "path", ".", "realpath", "(", "path", ")", "if", "(", "not", "os", ".", "path", ".", "isfile", "(", "fpath", ")", ")", ":", "return", "False", "mode", "=", "os", ".", "s...
checks that path is an executable regular file .
train
true
2,291
def inverse_permutation(perm): return permute_row_elements(arange(perm.shape[(-1)], dtype=perm.dtype), perm, inverse=True)
[ "def", "inverse_permutation", "(", "perm", ")", ":", "return", "permute_row_elements", "(", "arange", "(", "perm", ".", "shape", "[", "(", "-", "1", ")", "]", ",", "dtype", "=", "perm", ".", "dtype", ")", ",", "perm", ",", "inverse", "=", "True", ")"...
computes the inverse of permutations .
train
false
2,292
def _parse_id(s): match = re.search('[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}', s) if match: return match.group()
[ "def", "_parse_id", "(", "s", ")", ":", "match", "=", "re", ".", "search", "(", "'[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}'", ",", "s", ")", "if", "match", ":", "return", "match", ".", "group", "(", ")" ]
search for a musicbrainz id in the given string and return it .
train
false
2,293
def confusion_matrix(y_true, y_pred, labels=None, sample_weight=None): (y_type, y_true, y_pred) = _check_targets(y_true, y_pred) if (y_type not in ('binary', 'multiclass')): raise ValueError(('%s is not supported' % y_type)) if (labels is None): labels = unique_labels(y_true, y_pred) else: labels = np.asarray...
[ "def", "confusion_matrix", "(", "y_true", ",", "y_pred", ",", "labels", "=", "None", ",", "sample_weight", "=", "None", ")", ":", "(", "y_type", ",", "y_true", ",", "y_pred", ")", "=", "_check_targets", "(", "y_true", ",", "y_pred", ")", "if", "(", "y_...
compute confusion matrix args: res : evaluation results index : model index returns: confusion matrix .
train
false
2,294
def yields(value): return (isinstance(value, Future) or iscoroutine(value))
[ "def", "yields", "(", "value", ")", ":", "return", "(", "isinstance", "(", "value", ",", "Future", ")", "or", "iscoroutine", "(", "value", ")", ")" ]
returns true iff the value yields .
train
false
2,295
def dump_threads_on_sigquit(signum, frame): dump_traceback()
[ "def", "dump_threads_on_sigquit", "(", "signum", ",", "frame", ")", ":", "dump_traceback", "(", ")" ]
dump out the threads to stderr .
train
false
2,296
def _warn_software_properties(repo): log.warning("The 'python-software-properties' package is not installed. For more accurate support of PPA repositories, you should install this package.") log.warning('Best guess at ppa format: {0}'.format(repo))
[ "def", "_warn_software_properties", "(", "repo", ")", ":", "log", ".", "warning", "(", "\"The 'python-software-properties' package is not installed. For more accurate support of PPA repositories, you should install this package.\"", ")", "log", ".", "warning", "(", "'Best guess at pp...
warn of missing python-software-properties package .
train
false
2,297
@receiver(product_viewed) def receive_product_view(sender, product, user, request, response, **kwargs): return history.update(product, request, response)
[ "@", "receiver", "(", "product_viewed", ")", "def", "receive_product_view", "(", "sender", ",", "product", ",", "user", ",", "request", ",", "response", ",", "**", "kwargs", ")", ":", "return", "history", ".", "update", "(", "product", ",", "request", ",",...
receiver to handle viewing single product pages requires the request and response objects due to dependence on cookies .
train
false
2,299
def canonicalize_name(name): if ((not name) or (name == SEP)): return name elif (name[0] == SEP): return ('/' + '/'.join([x for x in name.split(SEP) if x])) else: return '/'.join([x for x in name.split(SEP) if x])
[ "def", "canonicalize_name", "(", "name", ")", ":", "if", "(", "(", "not", "name", ")", "or", "(", "name", "==", "SEP", ")", ")", ":", "return", "name", "elif", "(", "name", "[", "0", "]", "==", "SEP", ")", ":", "return", "(", "'/'", "+", "'/'",...
put name in canonical form .
train
false
2,300
def wire_HTTPConnection_to_WSGI(host, app): class HTTPConnectionDecorator(object, ): 'Decorator to mock the HTTPConecction class.\n\n Wraps the real HTTPConnection class so that when you instantiate\n the class you might instead get a fake instance.\n ' def __init__(self, wrapped): self.wra...
[ "def", "wire_HTTPConnection_to_WSGI", "(", "host", ",", "app", ")", ":", "class", "HTTPConnectionDecorator", "(", "object", ",", ")", ":", "def", "__init__", "(", "self", ",", "wrapped", ")", ":", "self", ".", "wrapped", "=", "wrapped", "def", "__call__", ...
monkeypatches httpconnection so that if you try to connect to host .
train
false
2,301
def RenderExpoCdf(lam, low, high, n=101): xs = np.linspace(low, high, n) ps = (1 - np.exp(((- lam) * xs))) return (xs, ps)
[ "def", "RenderExpoCdf", "(", "lam", ",", "low", ",", "high", ",", "n", "=", "101", ")", ":", "xs", "=", "np", ".", "linspace", "(", "low", ",", "high", ",", "n", ")", "ps", "=", "(", "1", "-", "np", ".", "exp", "(", "(", "(", "-", "lam", ...
generates sequences of xs and ps for an exponential cdf .
train
false
2,302
def create_file(): if (request.vars and (not (request.vars.token == session.token))): redirect(URL('logout')) try: anchor = (('#' + request.vars.id) if request.vars.id else '') if request.vars.app: app = get_app(request.vars.app) path = abspath(request.vars.location) else: if request.vars.dir: re...
[ "def", "create_file", "(", ")", ":", "if", "(", "request", ".", "vars", "and", "(", "not", "(", "request", ".", "vars", ".", "token", "==", "session", ".", "token", ")", ")", ")", ":", "redirect", "(", "URL", "(", "'logout'", ")", ")", "try", ":"...
create an empty file .
train
false
2,303
def run_in_dir(cmd, cwd, logstream=_RUN_DEFAULT_LOGSTREAM): old_dir = os.getcwd() try: os.chdir(cwd) __run_log(logstream, "running '%s' in '%s'", cmd, cwd) run(cmd, logstream=None) finally: os.chdir(old_dir)
[ "def", "run_in_dir", "(", "cmd", ",", "cwd", ",", "logstream", "=", "_RUN_DEFAULT_LOGSTREAM", ")", ":", "old_dir", "=", "os", ".", "getcwd", "(", ")", "try", ":", "os", ".", "chdir", "(", "cwd", ")", "__run_log", "(", "logstream", ",", "\"running '%s' in...
run the given command in the given working directory .
train
false
2,304
def test_itertools_islice_end(): from itertools import izip, islice it = izip([2, 3, 4], [4, 5, 6]) list(islice(it, 2)) for x in it: AreEqual(x, (4, 6))
[ "def", "test_itertools_islice_end", "(", ")", ":", "from", "itertools", "import", "izip", ",", "islice", "it", "=", "izip", "(", "[", "2", ",", "3", ",", "4", "]", ",", "[", "4", ",", "5", ",", "6", "]", ")", "list", "(", "islice", "(", "it", "...
islice shouldnt consume values after the limit specified by step .
train
false
2,305
def PrintPortfolio(pfl, with_returns=False): print 'Portfolio Title :', pfl.portfolio_title print 'Portfolio ID :', pfl.portfolio_id print ' Last updated :', pfl.updated.text d = pfl.portfolio_data print ' Currency :', d.currency_code if with_returns: print ' Gain % :', d.gain_perce...
[ "def", "PrintPortfolio", "(", "pfl", ",", "with_returns", "=", "False", ")", ":", "print", "'Portfolio Title :'", ",", "pfl", ".", "portfolio_title", "print", "'Portfolio ID :'", ",", "pfl", ".", "portfolio_id", "print", "' Last updated :'", ",", "pfl", ...
print single portfolio .
train
false
2,306
@pytest.mark.usefixtures('table_type') def test_init_and_ref_from_multidim_ndarray(table_type): for copy in (False, True): nd = np.array([(1, [10, 20]), (3, [30, 40])], dtype=[(str('a'), 'i8'), (str('b'), 'i8', (2,))]) t = table_type(nd, copy=copy) assert (t.colnames == ['a', 'b']) assert (t['a'].shape == (2,)...
[ "@", "pytest", ".", "mark", ".", "usefixtures", "(", "'table_type'", ")", "def", "test_init_and_ref_from_multidim_ndarray", "(", "table_type", ")", ":", "for", "copy", "in", "(", "False", ",", "True", ")", ":", "nd", "=", "np", ".", "array", "(", "[", "(...
test that initializing from an ndarray structured array with a multi-dim column works for both copy=false and true and that the referencing is as expected .
train
false
2,308
def _CheckAtom(atom): return _ValidateString(atom, 'atom', MAXIMUM_FIELD_ATOM_LENGTH, empty_ok=True)
[ "def", "_CheckAtom", "(", "atom", ")", ":", "return", "_ValidateString", "(", "atom", ",", "'atom'", ",", "MAXIMUM_FIELD_ATOM_LENGTH", ",", "empty_ok", "=", "True", ")" ]
checks the field atom is a valid string .
train
false
2,309
def make_property(info, prop, in_set): if in_set: return prop return prop.with_flags(case_flags=make_case_flags(info))
[ "def", "make_property", "(", "info", ",", "prop", ",", "in_set", ")", ":", "if", "in_set", ":", "return", "prop", "return", "prop", ".", "with_flags", "(", "case_flags", "=", "make_case_flags", "(", "info", ")", ")" ]
create the automagic property corresponding to a fact .
train
false
2,310
def send_email_for_expired_orders(email, event_name, invoice_id, order_url): send_email(to=email, action=MAIL_TO_EXPIRED_ORDERS, subject=MAILS[MAIL_TO_EXPIRED_ORDERS]['subject'].format(event_name=event_name), html=MAILS[MAIL_TO_EXPIRED_ORDERS]['message'].format(invoice_id=invoice_id, order_url=order_url))
[ "def", "send_email_for_expired_orders", "(", "email", ",", "event_name", ",", "invoice_id", ",", "order_url", ")", ":", "send_email", "(", "to", "=", "email", ",", "action", "=", "MAIL_TO_EXPIRED_ORDERS", ",", "subject", "=", "MAILS", "[", "MAIL_TO_EXPIRED_ORDERS"...
send email with order invoice link after purchase .
train
false
2,312
def resource_view_delete(context, data_dict): model = context['model'] id = _get_or_bust(data_dict, 'id') resource_view = model.ResourceView.get(id) if (not resource_view): raise NotFound context['resource_view'] = resource_view context['resource'] = model.Resource.get(resource_view.resource_id) _check_access(...
[ "def", "resource_view_delete", "(", "context", ",", "data_dict", ")", ":", "model", "=", "context", "[", "'model'", "]", "id", "=", "_get_or_bust", "(", "data_dict", ",", "'id'", ")", "resource_view", "=", "model", ".", "ResourceView", ".", "get", "(", "id...
delete a resource_view .
train
false
2,315
def test_read_config(): for config in config_fnames: cfg = _read_config(config) assert_true(all(((('unknown' not in block.lower()) and (block != '')) for block in cfg['user_blocks'])))
[ "def", "test_read_config", "(", ")", ":", "for", "config", "in", "config_fnames", ":", "cfg", "=", "_read_config", "(", "config", ")", "assert_true", "(", "all", "(", "(", "(", "(", "'unknown'", "not", "in", "block", ".", "lower", "(", ")", ")", "and",...
test read bti config file .
train
false
2,316
def slugize(slug): assert (name_pattern.match(slug) is not None) slug = slug.lower() for c in (' ', ',', '.', '_'): slug = slug.replace(c, '-') while ('--' in slug): slug = slug.replace('--', '-') slug = slug.strip('-') return slug
[ "def", "slugize", "(", "slug", ")", ":", "assert", "(", "name_pattern", ".", "match", "(", "slug", ")", "is", "not", "None", ")", "slug", "=", "slug", ".", "lower", "(", ")", "for", "c", "in", "(", "' '", ",", "','", ",", "'.'", ",", "'_'", ")"...
create a slug from a team name .
train
false
2,317
def _add_item(routing_key, body, message_id=None, delivery_mode=DELIVERY_DURABLE, headers=None, exchange=None, send_stats=True): if (not cfg.amqp_host): cfg.log.error(('Ignoring amqp message %r to %r' % (body, routing_key))) return if (not exchange): exchange = cfg.amqp_exchange chan = connection_manager.get_c...
[ "def", "_add_item", "(", "routing_key", ",", "body", ",", "message_id", "=", "None", ",", "delivery_mode", "=", "DELIVERY_DURABLE", ",", "headers", "=", "None", ",", "exchange", "=", "None", ",", "send_stats", "=", "True", ")", ":", "if", "(", "not", "cf...
adds an item onto a queue .
train
false
2,318
def _check_region_for_parsing(number, default_region): if (not _is_valid_region_code(default_region)): if ((number is None) or (len(number) == 0)): return False match = _PLUS_CHARS_PATTERN.match(number) if (match is None): return False return True
[ "def", "_check_region_for_parsing", "(", "number", ",", "default_region", ")", ":", "if", "(", "not", "_is_valid_region_code", "(", "default_region", ")", ")", ":", "if", "(", "(", "number", "is", "None", ")", "or", "(", "len", "(", "number", ")", "==", ...
checks to see that the region code used is valid .
train
true
2,319
def send_validation(strategy, backend, code): if (not strategy.request.session.session_key): strategy.request.session.create() template = u'activation' if strategy.request.session.pop(u'password_reset', False): template = u'reset' url = u'{}?verification_code={}&id={}&type={}'.format(reverse(u'social:complete',...
[ "def", "send_validation", "(", "strategy", ",", "backend", ",", "code", ")", ":", "if", "(", "not", "strategy", ".", "request", ".", "session", ".", "session_key", ")", ":", "strategy", ".", "request", ".", "session", ".", "create", "(", ")", "template",...
sends verification email .
train
false
2,321
def read_os_detection(remote_read): try: linux1 = remote_read('/etc/passwd') linux2 = remote_read('/etc/mtab') linux3 = remote_read('/proc/sys/kernel/ostype') except: pass else: if (('/bin/' in linux1) or ('rw' in linux2) or ('linux' in linux3.lower())): om.out.debug('Identified remote OS as Linux, retu...
[ "def", "read_os_detection", "(", "remote_read", ")", ":", "try", ":", "linux1", "=", "remote_read", "(", "'/etc/passwd'", ")", "linux2", "=", "remote_read", "(", "'/etc/mtab'", ")", "linux3", "=", "remote_read", "(", "'/proc/sys/kernel/ostype'", ")", "except", "...
uses the remote_read method to read remote files and determine what the remote os is .
train
false
2,324
def rewriter(condition, rewrite): def _rewriter(integral): (integrand, symbol) = integral if condition(*integral): rewritten = rewrite(*integral) if (rewritten != integrand): substep = integral_steps(rewritten, symbol) if ((not isinstance(substep, DontKnowRule)) and substep): return RewriteRule(...
[ "def", "rewriter", "(", "condition", ",", "rewrite", ")", ":", "def", "_rewriter", "(", "integral", ")", ":", "(", "integrand", ",", "symbol", ")", "=", "integral", "if", "condition", "(", "*", "integral", ")", ":", "rewritten", "=", "rewrite", "(", "*...
create a template field function that rewrites the given field with the given rewriting rules .
train
false
2,326
@core_helper def is_url(*args, **kw): if (not args): return False try: url = urlparse.urlparse(args[0]) except ValueError: return False default_valid_schemes = ('http', 'https', 'ftp') valid_schemes = config.get('ckan.valid_url_schemes', '').lower().split() return (url.scheme in (valid_schemes or default_va...
[ "@", "core_helper", "def", "is_url", "(", "*", "args", ",", "**", "kw", ")", ":", "if", "(", "not", "args", ")", ":", "return", "False", "try", ":", "url", "=", "urlparse", ".", "urlparse", "(", "args", "[", "0", "]", ")", "except", "ValueError", ...
return true if string is an http or ftp path .
train
false
2,327
def test_rename_mixin_columns(mixin_cols): t = QTable(mixin_cols) tc = t.copy() t.rename_column('m', 'mm') assert (t.colnames == ['i', 'a', 'b', 'mm']) if isinstance(t['mm'], table_helpers.ArrayWrapper): assert np.all((t['mm'].data == tc['m'].data)) elif isinstance(t['mm'], coordinates.SkyCoord): assert np.al...
[ "def", "test_rename_mixin_columns", "(", "mixin_cols", ")", ":", "t", "=", "QTable", "(", "mixin_cols", ")", "tc", "=", "t", ".", "copy", "(", ")", "t", ".", "rename_column", "(", "'m'", ",", "'mm'", ")", "assert", "(", "t", ".", "colnames", "==", "[...
rename a mixin column .
train
false
2,330
def json_formatter(fstring): if (fstring == '||'): fstring = '[]' else: fstring = fstring.replace(' ', '') fstring = fstring.replace('|', '') fstring = fstring.replace('}{', '},{') fstring = fstring.replace("{u'", "{'") fstring = fstring.replace(":u'", ":'") fstring = fstring.replace(",u'", ",'") fstr...
[ "def", "json_formatter", "(", "fstring", ")", ":", "if", "(", "fstring", "==", "'||'", ")", ":", "fstring", "=", "'[]'", "else", ":", "fstring", "=", "fstring", ".", "replace", "(", "' '", ",", "''", ")", "fstring", "=", "fstring", ".", "replace", "(...
properly format the key-value import string to json .
train
false
2,332
def urlsafe_b64encode(s): return b64encode(s).translate(_urlsafe_encode_translation)
[ "def", "urlsafe_b64encode", "(", "s", ")", ":", "return", "b64encode", "(", "s", ")", ".", "translate", "(", "_urlsafe_encode_translation", ")" ]
encode a string using a url-safe base64 alphabet .
train
false
2,333
@login_required @view def importer(request, test_js=False): person = request.user.get_profile() data = get_personal_data(person) data['citation_form'] = mysite.profile.forms.ManuallyAddACitationForm(auto_id=False) data['test_js'] = (test_js or request.GET.get('test', None)) return (request, 'profile/importer.html'...
[ "@", "login_required", "@", "view", "def", "importer", "(", "request", ",", "test_js", "=", "False", ")", ":", "person", "=", "request", ".", "user", ".", "get_profile", "(", ")", "data", "=", "get_personal_data", "(", "person", ")", "data", "[", "'citat...
get the logged-in users profile .
train
false
2,334
def _sub_clade(clade, term_names): term_clades = [clade.find_any(name) for name in term_names] sub_clade = clade.common_ancestor(term_clades) if (len(term_names) != sub_clade.count_terminals()): temp_clade = BaseTree.Clade() temp_clade.clades.extend(term_clades) for c in sub_clade.find_clades(terminal=False, o...
[ "def", "_sub_clade", "(", "clade", ",", "term_names", ")", ":", "term_clades", "=", "[", "clade", ".", "find_any", "(", "name", ")", "for", "name", "in", "term_names", "]", "sub_clade", "=", "clade", ".", "common_ancestor", "(", "term_clades", ")", "if", ...
extract a compatible subclade that only contains the given terminal names .
train
false
2,340
def dict_property(store, index): if hasattr(store, '__call__'): getter = (lambda self: store(self)[index]) setter = (lambda self, value: store(self).__setitem__(index, value)) elif isinstance(store, str): getter = (lambda self: self.__getattribute__(store)[index]) setter = (lambda self, value: self.__getattri...
[ "def", "dict_property", "(", "store", ",", "index", ")", ":", "if", "hasattr", "(", "store", ",", "'__call__'", ")", ":", "getter", "=", "(", "lambda", "self", ":", "store", "(", "self", ")", "[", "index", "]", ")", "setter", "=", "(", "lambda", "s...
helper to create class properties from a dictionary .
train
false
2,341
def get_host_id(kwargs=None, call=None): if (call == 'action'): raise SaltCloudSystemExit('The get_host_id function must be called with -f or --function.') if (kwargs is None): kwargs = {} name = kwargs.get('name', None) if (name is None): raise SaltCloudSystemExit('The get_host_id function requires a name.')...
[ "def", "get_host_id", "(", "kwargs", "=", "None", ",", "call", "=", "None", ")", ":", "if", "(", "call", "==", "'action'", ")", ":", "raise", "SaltCloudSystemExit", "(", "'The get_host_id function must be called with -f or --function.'", ")", "if", "(", "kwargs", ...
returns a hosts id from the given host name .
train
true
2,342
def equal_args(*args, **kwargs): key = args if kwargs: key += (_kwargs_separator + tuple(sorted(kwargs.items()))) return key
[ "def", "equal_args", "(", "*", "args", ",", "**", "kwargs", ")", ":", "key", "=", "args", "if", "kwargs", ":", "key", "+=", "(", "_kwargs_separator", "+", "tuple", "(", "sorted", "(", "kwargs", ".", "items", "(", ")", ")", ")", ")", "return", "key"...
a memoized key factory that compares the equality of a stable sort of the parameters .
train
true
2,348
@receiver(pre_save, sender=UserProfile) def user_profile_pre_save_callback(sender, **kwargs): user_profile = kwargs['instance'] if (user_profile.requires_parental_consent() and user_profile.has_profile_image): user_profile.profile_image_uploaded_at = None user_profile._changed_fields = get_changed_fields_dict(user...
[ "@", "receiver", "(", "pre_save", ",", "sender", "=", "UserProfile", ")", "def", "user_profile_pre_save_callback", "(", "sender", ",", "**", "kwargs", ")", ":", "user_profile", "=", "kwargs", "[", "'instance'", "]", "if", "(", "user_profile", ".", "requires_pa...
ensure consistency of a user profile before saving it .
train
false
2,351
def lazy_validate(request_body_schema, resource_to_validate): schema_validator = validators.SchemaValidator(request_body_schema) schema_validator.validate(resource_to_validate)
[ "def", "lazy_validate", "(", "request_body_schema", ",", "resource_to_validate", ")", ":", "schema_validator", "=", "validators", ".", "SchemaValidator", "(", "request_body_schema", ")", "schema_validator", ".", "validate", "(", "resource_to_validate", ")" ]
a non-decorator way to validate a request .
train
false
2,352
def request_content(url, **kwargs): response = request_response(url, **kwargs) if (response is not None): return response.content
[ "def", "request_content", "(", "url", ",", "**", "kwargs", ")", ":", "response", "=", "request_response", "(", "url", ",", "**", "kwargs", ")", "if", "(", "response", "is", "not", "None", ")", ":", "return", "response", ".", "content" ]
wrapper for request_response .
train
false
2,353
def compute_intensity(image_r, image_g=None, image_b=None): if ((image_g is None) or (image_b is None)): if (not ((image_g is None) and (image_b is None))): raise ValueError(u'please specify either a single image or red, green, and blue images.') return image_r intensity = (((image_r + image_g) + image_b) / 3....
[ "def", "compute_intensity", "(", "image_r", ",", "image_g", "=", "None", ",", "image_b", "=", "None", ")", ":", "if", "(", "(", "image_g", "is", "None", ")", "or", "(", "image_b", "is", "None", ")", ")", ":", "if", "(", "not", "(", "(", "image_g", ...
return a naive total intensity from the red .
train
false
2,354
def test_feature_fr_from_string2(): lang = Language('fr') feature = Feature.from_string(OUTLINED_FEATURE2, language=lang) assert_equals(feature.name, u'Faire plusieur choses en m\xeame temps') assert_equals(feature.description, u"De fa\xe7on \xe0 automatiser les tests\nEn tant que fain\xe9ant\nJ'utilise les plans d...
[ "def", "test_feature_fr_from_string2", "(", ")", ":", "lang", "=", "Language", "(", "'fr'", ")", "feature", "=", "Feature", ".", "from_string", "(", "OUTLINED_FEATURE2", ",", "language", "=", "lang", ")", "assert_equals", "(", "feature", ".", "name", ",", "u...
language: fr -> feature .
train
false
2,355
@ssl_required def aaq_step3(request, product_key, category_key): return aaq(request, product_key=product_key, category_key=category_key, step=1)
[ "@", "ssl_required", "def", "aaq_step3", "(", "request", ",", "product_key", ",", "category_key", ")", ":", "return", "aaq", "(", "request", ",", "product_key", "=", "product_key", ",", "category_key", "=", "category_key", ",", "step", "=", "1", ")" ]
step 3: the product and category is selected .
train
false
2,356
def get_permitted_actions(filter=None): if (filter is None): return RBACAgent.permitted_actions tmp_bunch = Bunch() [tmp_bunch.__dict__.__setitem__(k, v) for (k, v) in RBACAgent.permitted_actions.items() if k.startswith(filter)] return tmp_bunch
[ "def", "get_permitted_actions", "(", "filter", "=", "None", ")", ":", "if", "(", "filter", "is", "None", ")", ":", "return", "RBACAgent", ".", "permitted_actions", "tmp_bunch", "=", "Bunch", "(", ")", "[", "tmp_bunch", ".", "__dict__", ".", "__setitem__", ...
utility method to return a subset of rbacagents permitted actions .
train
false
2,357
def conv1d_mc1(input, filters, image_shape=None, filter_shape=None, border_mode='valid', subsample=(1,), filter_flip=True): if (image_shape is None): image_shape_mc1 = None else: image_shape_mc1 = (image_shape[0], image_shape[1], image_shape[2], 1) if (filter_shape is None): filter_shape_mc1 = None else: fi...
[ "def", "conv1d_mc1", "(", "input", ",", "filters", ",", "image_shape", "=", "None", ",", "filter_shape", "=", "None", ",", "border_mode", "=", "'valid'", ",", "subsample", "=", "(", "1", ",", ")", ",", "filter_flip", "=", "True", ")", ":", "if", "(", ...
using conv2d with height == 1 .
train
false
2,358
def update_feedback_email_retries(user_id): model = feedback_models.UnsentFeedbackEmailModel.get(user_id) time_since_buffered = (datetime.datetime.utcnow() - model.created_on).seconds if (time_since_buffered > feconf.DEFAULT_FEEDBACK_MESSAGE_EMAIL_COUNTDOWN_SECS): model.retries += 1 model.put()
[ "def", "update_feedback_email_retries", "(", "user_id", ")", ":", "model", "=", "feedback_models", ".", "UnsentFeedbackEmailModel", ".", "get", "(", "user_id", ")", "time_since_buffered", "=", "(", "datetime", ".", "datetime", ".", "utcnow", "(", ")", "-", "mode...
if sufficient time has passed .
train
false
2,359
def time_xlwt(): start_time = clock() workbook = xlwt.Workbook() worksheet = workbook.add_sheet('Sheet1') for row in range((row_max // 2)): for col in range(col_max): worksheet.write((row * 2), col, ('Row: %d Col: %d' % (row, col))) for col in range(col_max): worksheet.write(((row * 2) + 1), col, (row + c...
[ "def", "time_xlwt", "(", ")", ":", "start_time", "=", "clock", "(", ")", "workbook", "=", "xlwt", ".", "Workbook", "(", ")", "worksheet", "=", "workbook", ".", "add_sheet", "(", "'Sheet1'", ")", "for", "row", "in", "range", "(", "(", "row_max", "//", ...
run xlwt in default mode .
train
false
2,360
def latlon_to_grid(latlon): from MAVProxy.modules.lib.ANUGA import redfearn (zone, easting, northing) = redfearn.redfearn(latlon[0], latlon[1]) if (latlon[0] < 0): hemisphere = 'S' else: hemisphere = 'N' return UTMGrid(zone, easting, northing, hemisphere=hemisphere)
[ "def", "latlon_to_grid", "(", "latlon", ")", ":", "from", "MAVProxy", ".", "modules", ".", "lib", ".", "ANUGA", "import", "redfearn", "(", "zone", ",", "easting", ",", "northing", ")", "=", "redfearn", ".", "redfearn", "(", "latlon", "[", "0", "]", ","...
convert to grid reference .
train
true
2,362
def rgb2hed(rgb): return separate_stains(rgb, hed_from_rgb)
[ "def", "rgb2hed", "(", "rgb", ")", ":", "return", "separate_stains", "(", "rgb", ",", "hed_from_rgb", ")" ]
rgb to haematoxylin-eosin-dab color space conversion .
train
false
2,364
def get_preferred_file_contents_encoding(): return (locale.getpreferredencoding() or u'utf-8')
[ "def", "get_preferred_file_contents_encoding", "(", ")", ":", "return", "(", "locale", ".", "getpreferredencoding", "(", ")", "or", "u'utf-8'", ")" ]
get encoding preferred for file contents .
train
false
2,365
def normalize_letters(one_letter_code): if (one_letter_code == '.'): return 'X' else: return one_letter_code.upper()
[ "def", "normalize_letters", "(", "one_letter_code", ")", ":", "if", "(", "one_letter_code", "==", "'.'", ")", ":", "return", "'X'", "else", ":", "return", "one_letter_code", ".", "upper", "(", ")" ]
convert raf one-letter amino acid codes into iupac standard codes .
train
false
2,366
def get_documents(cls, ids): fields = cls.get_mapping()['properties'].keys() ret = cls.search().filter(id__in=ids).values_dict(*fields)[:len(ids)] return cls.reshape(ret)
[ "def", "get_documents", "(", "cls", ",", "ids", ")", ":", "fields", "=", "cls", ".", "get_mapping", "(", ")", "[", "'properties'", "]", ".", "keys", "(", ")", "ret", "=", "cls", ".", "search", "(", ")", ".", "filter", "(", "id__in", "=", "ids", "...
returns a list of es documents with specified ids and doctype :arg cls: the mapping type class with a .
train
false
2,369
def choose_ncv(k): return max(((2 * k) + 1), 20)
[ "def", "choose_ncv", "(", "k", ")", ":", "return", "max", "(", "(", "(", "2", "*", "k", ")", "+", "1", ")", ",", "20", ")" ]
choose number of lanczos vectors based on target number of singular/eigen values and vectors to compute .
train
false
2,370
def pathstrip(path, n): pathlist = [path] while (os.path.dirname(pathlist[0]) != ''): pathlist[0:1] = os.path.split(pathlist[0]) return '/'.join(pathlist[n:])
[ "def", "pathstrip", "(", "path", ",", "n", ")", ":", "pathlist", "=", "[", "path", "]", "while", "(", "os", ".", "path", ".", "dirname", "(", "pathlist", "[", "0", "]", ")", "!=", "''", ")", ":", "pathlist", "[", "0", ":", "1", "]", "=", "os"...
strip n leading components from the given path .
train
true
2,371
def sys_decode(thing): if isinstance(thing, bytes_str): return thing.decode(ENCODING) return thing
[ "def", "sys_decode", "(", "thing", ")", ":", "if", "isinstance", "(", "thing", ",", "bytes_str", ")", ":", "return", "thing", ".", "decode", "(", "ENCODING", ")", "return", "thing" ]
return unicode .
train
false
2,372
def compute_chunk_last_header(lines, numlines, meta, last_header=None): if (last_header is None): last_header = [None, None] line = lines[0] for (i, (linenum, header_key)) in enumerate([(line[1], u'left_headers'), (line[4], u'right_headers')]): headers = meta[header_key] if headers: header = headers[(-1)] ...
[ "def", "compute_chunk_last_header", "(", "lines", ",", "numlines", ",", "meta", ",", "last_header", "=", "None", ")", ":", "if", "(", "last_header", "is", "None", ")", ":", "last_header", "=", "[", "None", ",", "None", "]", "line", "=", "lines", "[", "...
computes information for the displayed function/class headers .
train
false
2,373
def dummy_1d(x, varname=None): if (varname is None): labels = [('level_%d' % i) for i in range((x.max() + 1))] return ((x[:, None] == np.arange((x.max() + 1))).astype(int), labels) else: grouplabels = np.unique(x) labels = [(varname + ('_%s' % str(i))) for i in grouplabels] return ((x[:, None] == grouplabel...
[ "def", "dummy_1d", "(", "x", ",", "varname", "=", "None", ")", ":", "if", "(", "varname", "is", "None", ")", ":", "labels", "=", "[", "(", "'level_%d'", "%", "i", ")", "for", "i", "in", "range", "(", "(", "x", ".", "max", "(", ")", "+", "1", ...
dummy variable for id integer groups paramters x : ndarray .
train
false
2,375
def certificate_status_for_student(student, course_id): from course_modes.models import CourseMode try: generated_certificate = GeneratedCertificate.objects.get(user=student, course_id=course_id) cert_status = {'status': generated_certificate.status, 'mode': generated_certificate.mode, 'uuid': generated_certifica...
[ "def", "certificate_status_for_student", "(", "student", ",", "course_id", ")", ":", "from", "course_modes", ".", "models", "import", "CourseMode", "try", ":", "generated_certificate", "=", "GeneratedCertificate", ".", "objects", ".", "get", "(", "user", "=", "stu...
this returns a dictionary with a key for status .
train
false
2,377
def read_sheets_titles(xml_source): root = fromstring(xml_source) titles_root = root.find(QName('http://schemas.openxmlformats.org/officeDocument/2006/extended-properties', 'TitlesOfParts').text) vector = titles_root.find(QName(NAMESPACES['vt'], 'vector').text) (parts, names) = get_number_of_parts(xml_source) size...
[ "def", "read_sheets_titles", "(", "xml_source", ")", ":", "root", "=", "fromstring", "(", "xml_source", ")", "titles_root", "=", "root", ".", "find", "(", "QName", "(", "'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties'", ",", "'TitlesOfParts'", ...
read titles for all sheets .
train
false
2,378
def CDLTRISTAR(barDs, count): return call_talib_with_ohlc(barDs, count, talib.CDLTRISTAR)
[ "def", "CDLTRISTAR", "(", "barDs", ",", "count", ")", ":", "return", "call_talib_with_ohlc", "(", "barDs", ",", "count", ",", "talib", ".", "CDLTRISTAR", ")" ]
tristar pattern .
train
false
2,381
def _fswalk_follow_symlinks(path): assert os.path.isdir(deunicodise(path)) walkdirs = set([path]) for (dirpath, dirnames, filenames) in _os_walk_unicode(path): real_dirpath = unicodise(os.path.realpath(deunicodise(dirpath))) for dirname in dirnames: current = os.path.join(dirpath, dirname) real_current = u...
[ "def", "_fswalk_follow_symlinks", "(", "path", ")", ":", "assert", "os", ".", "path", ".", "isdir", "(", "deunicodise", "(", "path", ")", ")", "walkdirs", "=", "set", "(", "[", "path", "]", ")", "for", "(", "dirpath", ",", "dirnames", ",", "filenames",...
walk filesystem .
train
false
2,383
def _migrate_collection_to_latest_schema(versioned_collection): collection_schema_version = versioned_collection['schema_version'] if (not (1 <= collection_schema_version <= feconf.CURRENT_COLLECTION_SCHEMA_VERSION)): raise Exception(('Sorry, we can only process v1-v%d collection schemas at present.' % feconf.CURRE...
[ "def", "_migrate_collection_to_latest_schema", "(", "versioned_collection", ")", ":", "collection_schema_version", "=", "versioned_collection", "[", "'schema_version'", "]", "if", "(", "not", "(", "1", "<=", "collection_schema_version", "<=", "feconf", ".", "CURRENT_COLLE...
holds the responsibility of performing a step-by-step .
train
false
2,385
def test_list_slice(): a = HyList([1, 2, 3, 4]) sl1 = a[1:] sl5 = a[5:] assert (type(sl1) == HyList) assert (sl1 == HyList([2, 3, 4])) assert (type(sl5) == HyList) assert (sl5 == HyList([]))
[ "def", "test_list_slice", "(", ")", ":", "a", "=", "HyList", "(", "[", "1", ",", "2", ",", "3", ",", "4", "]", ")", "sl1", "=", "a", "[", "1", ":", "]", "sl5", "=", "a", "[", "5", ":", "]", "assert", "(", "type", "(", "sl1", ")", "==", ...
check that slicing a hylist produces a hylist .
train
false
2,386
def extract_deps(fname, legal_deps): deps = {} for line in open(fname).readlines(): if (line[:8] != '#include'): continue inc = _re_include.match(line).group(1) if (inc in legal_deps.keys()): deps[inc] = legal_deps[inc] return deps
[ "def", "extract_deps", "(", "fname", ",", "legal_deps", ")", ":", "deps", "=", "{", "}", "for", "line", "in", "open", "(", "fname", ")", ".", "readlines", "(", ")", ":", "if", "(", "line", "[", ":", "8", "]", "!=", "'#include'", ")", ":", "contin...
extract the headers this file includes .
train
false
2,387
def generateOnlyInterface(list, int): for n in list: if int.providedBy(n): (yield n)
[ "def", "generateOnlyInterface", "(", "list", ",", "int", ")", ":", "for", "n", "in", "list", ":", "if", "int", ".", "providedBy", "(", "n", ")", ":", "(", "yield", "n", ")" ]
filters items in a list by class .
train
false
2,388
def full_path_split(path): (rest, tail) = os.path.split(path) if ((not rest) or (rest == os.path.sep)): return (tail,) return (full_path_split(rest) + (tail,))
[ "def", "full_path_split", "(", "path", ")", ":", "(", "rest", ",", "tail", ")", "=", "os", ".", "path", ".", "split", "(", "path", ")", "if", "(", "(", "not", "rest", ")", "or", "(", "rest", "==", "os", ".", "path", ".", "sep", ")", ")", ":",...
function to do a full split on a path .
train
false
2,389
@not_implemented_for('multigraph') def core_number(G): if (G.number_of_selfloops() > 0): msg = 'Input graph has self loops which is not permitted; Consider using G.remove_edges_from(G.selfloop_edges()).' raise NetworkXError(msg) degrees = dict(G.degree()) nodes = sorted(degrees, key=degrees.get) bin_boundaries ...
[ "@", "not_implemented_for", "(", "'multigraph'", ")", "def", "core_number", "(", "G", ")", ":", "if", "(", "G", ".", "number_of_selfloops", "(", ")", ">", "0", ")", ":", "msg", "=", "'Input graph has self loops which is not permitted; Consider using G.remove_edges_fro...
return the core number for each vertex .
train
false
2,390
@cli.command() def edit(): MARKER = '# Everything below is ignored\n' message = click.edit(('\n\n' + MARKER)) if (message is not None): msg = message.split(MARKER, 1)[0].rstrip('\n') if (not msg): click.echo('Empty message!') else: click.echo(('Message:\n' + msg)) else: click.echo('You did not enter a...
[ "@", "cli", ".", "command", "(", ")", "def", "edit", "(", ")", ":", "MARKER", "=", "'# Everything below is ignored\\n'", "message", "=", "click", ".", "edit", "(", "(", "'\\n\\n'", "+", "MARKER", ")", ")", "if", "(", "message", "is", "not", "None", ")"...
open filename in a text editor .
train
false
2,391
def list_schemes(package): resources = pkg_resources.resource_listdir(package.__name__, '.') resources = list(filter(is_ows, resources)) return sorted(resources)
[ "def", "list_schemes", "(", "package", ")", ":", "resources", "=", "pkg_resources", ".", "resource_listdir", "(", "package", ".", "__name__", ",", "'.'", ")", "resources", "=", "list", "(", "filter", "(", "is_ows", ",", "resources", ")", ")", "return", "so...
return a list of example workflows .
train
false
2,392
def get_image_properties_table(meta): (get_image_properties_table,) = from_migration_import('007_add_owner', ['get_image_properties_table']) image_properties = get_image_properties_table(meta) return image_properties
[ "def", "get_image_properties_table", "(", "meta", ")", ":", "(", "get_image_properties_table", ",", ")", "=", "from_migration_import", "(", "'007_add_owner'", ",", "[", "'get_image_properties_table'", "]", ")", "image_properties", "=", "get_image_properties_table", "(", ...
no changes to the image properties table from 002 .
train
false
2,393
def chhome(name, home, **kwargs): kwargs = salt.utils.clean_kwargs(**kwargs) persist = kwargs.pop('persist', False) if kwargs: salt.utils.invalid_kwargs(kwargs) if persist: log.info("Ignoring unsupported 'persist' argument to user.chhome") pre_info = info(name) if (not pre_info): raise CommandExecutionError...
[ "def", "chhome", "(", "name", ",", "home", ",", "**", "kwargs", ")", ":", "kwargs", "=", "salt", ".", "utils", ".", "clean_kwargs", "(", "**", "kwargs", ")", "persist", "=", "kwargs", ".", "pop", "(", "'persist'", ",", "False", ")", "if", "kwargs", ...
set a new home directory for an existing user name username to modify home new home directory to set persist : false set to true to prevent configuration files in the new home directory from being overwritten by the files from the skeleton directory .
train
true
2,394
def _update_configuration_context(context, configuration): config_key = configuration_helpers.get_value('domain_prefix') config = configuration.get('microsites', {}) if (config_key and config): context.update(config.get(config_key, {}))
[ "def", "_update_configuration_context", "(", "context", ",", "configuration", ")", ":", "config_key", "=", "configuration_helpers", ".", "get_value", "(", "'domain_prefix'", ")", "config", "=", "configuration", ".", "get", "(", "'microsites'", ",", "{", "}", ")", ...
site configuration will need to be able to override any hard coded content that was put into the context in the _update_certificate_context() call above .
train
false
2,395
def docstringLStrip(docstring): if (not docstring): return docstring docstring = string.replace(docstring, ' DCTB ', (' ' * 8)) lines = string.split(docstring, '\n') leading = 0 for l in xrange(1, len(lines)): line = lines[l] if string.strip(line): while 1: if (line[leading] == ' '): leading = (l...
[ "def", "docstringLStrip", "(", "docstring", ")", ":", "if", "(", "not", "docstring", ")", ":", "return", "docstring", "docstring", "=", "string", ".", "replace", "(", "docstring", ",", "' DCTB '", ",", "(", "' '", "*", "8", ")", ")", "lines", "=", "str...
gets rid of unsightly lefthand docstring whitespace residue .
train
false
2,396
def get_vpc_info(vpc): return {'id': vpc.id, 'cidr_block': vpc.cidr_block, 'dhcp_options_id': vpc.dhcp_options_id, 'region': vpc.region.name, 'state': vpc.state}
[ "def", "get_vpc_info", "(", "vpc", ")", ":", "return", "{", "'id'", ":", "vpc", ".", "id", ",", "'cidr_block'", ":", "vpc", ".", "cidr_block", ",", "'dhcp_options_id'", ":", "vpc", ".", "dhcp_options_id", ",", "'region'", ":", "vpc", ".", "region", ".", ...
retrieves vpc information from an instance id and returns it as a dictionary .
train
false
2,398
def copy_stack_trace(from_var, to_var): tr = [] if (type(from_var) is list): for v in from_var: tr += getattr(v.tag, 'trace', []) else: tr = getattr(from_var.tag, 'trace', []) if (tr and isinstance(tr[0], tuple)): tr = [tr] if (type(to_var) is list): for v in to_var: v.tag.trace = (getattr(v.tag, 'tr...
[ "def", "copy_stack_trace", "(", "from_var", ",", "to_var", ")", ":", "tr", "=", "[", "]", "if", "(", "type", "(", "from_var", ")", "is", "list", ")", ":", "for", "v", "in", "from_var", ":", "tr", "+=", "getattr", "(", "v", ".", "tag", ",", "'trac...
copies the stack trace from one or more tensor variables to one or more tensor variables .
train
false
2,401
def generate_x509_cert(user_id, project_id, bits=2048): subject = _user_cert_subject(user_id, project_id) with utils.tempdir() as tmpdir: keyfile = os.path.abspath(os.path.join(tmpdir, 'temp.key')) csrfile = os.path.abspath(os.path.join(tmpdir, 'temp.csr')) utils.execute('openssl', 'genrsa', '-out', keyfile, st...
[ "def", "generate_x509_cert", "(", "user_id", ",", "project_id", ",", "bits", "=", "2048", ")", ":", "subject", "=", "_user_cert_subject", "(", "user_id", ",", "project_id", ")", "with", "utils", ".", "tempdir", "(", ")", "as", "tmpdir", ":", "keyfile", "="...
generate and sign a cert for user in project .
train
false
2,402
def convert_to_prover9(input): if isinstance(input, list): result = [] for s in input: try: result.append(_convert_to_prover9(s.simplify())) except: print(('input %s cannot be converted to Prover9 input syntax' % input)) raise return result else: try: return _convert_to_prover9(input.simp...
[ "def", "convert_to_prover9", "(", "input", ")", ":", "if", "isinstance", "(", "input", ",", "list", ")", ":", "result", "=", "[", "]", "for", "s", "in", "input", ":", "try", ":", "result", ".", "append", "(", "_convert_to_prover9", "(", "s", ".", "si...
convert a logic .
train
false
2,403
def adagrad_optimizer(learning_rate, epsilon, n_win=10): def optimizer(loss, param): updates = OrderedDict() if (param is not list): param = list(param) for param_ in param: i = theano.shared(floatX(np.array(0))) i_int = i.astype('int64') value = param_.get_value(borrow=True) accu = theano.shared(...
[ "def", "adagrad_optimizer", "(", "learning_rate", ",", "epsilon", ",", "n_win", "=", "10", ")", ":", "def", "optimizer", "(", "loss", ",", "param", ")", ":", "updates", "=", "OrderedDict", "(", ")", "if", "(", "param", "is", "not", "list", ")", ":", ...
returns a function that returns parameter updates .
train
false
2,404
def unicode_obj(obj): if isinstance(obj, dict): return unicode_dict(obj) elif isinstance(obj, (list, tuple)): return unicode_list(obj) elif isinstance(obj, six.string_types): return unicode_string(obj) elif isinstance(obj, (int, float)): return obj elif (obj is None): return obj else: try: return t...
[ "def", "unicode_obj", "(", "obj", ")", ":", "if", "isinstance", "(", "obj", ",", "dict", ")", ":", "return", "unicode_dict", "(", "obj", ")", "elif", "isinstance", "(", "obj", ",", "(", "list", ",", "tuple", ")", ")", ":", "return", "unicode_list", "...
make sure keys and values of dict/list/tuple is unicode .
train
true
2,405
def get_text_from_s3(s3_connection, path): (bucket_name, key_name) = _from_path(path) bucket = s3_connection.get_bucket(bucket_name) k = boto.s3.Key(bucket) k.key = key_name txt = k.get_contents_as_string() return txt
[ "def", "get_text_from_s3", "(", "s3_connection", ",", "path", ")", ":", "(", "bucket_name", ",", "key_name", ")", "=", "_from_path", "(", "path", ")", "bucket", "=", "s3_connection", ".", "get_bucket", "(", "bucket_name", ")", "k", "=", "boto", ".", "s3", ...
read a file from s3 and return it as text .
train
false
2,406
def list_firewall_rules(profile=None): conn = _auth(profile) return conn.list_firewall_rules()
[ "def", "list_firewall_rules", "(", "profile", "=", "None", ")", ":", "conn", "=", "_auth", "(", "profile", ")", "return", "conn", ".", "list_firewall_rules", "(", ")" ]
fetches a list of all firewall rules for a tenant cli example: .
train
false
2,408
def swap32(value): value = long(value) return (((((value & 255L) << 24) | ((value & 65280L) << 8)) | ((value & 16711680L) >> 8)) | ((value & 4278190080L) >> 24))
[ "def", "swap32", "(", "value", ")", ":", "value", "=", "long", "(", "value", ")", "return", "(", "(", "(", "(", "(", "value", "&", "255", "L", ")", "<<", "24", ")", "|", "(", "(", "value", "&", "65280", "L", ")", "<<", "8", ")", ")", "|", ...
swap byte between big and little endian of a 32 bits integer .
train
false
2,409
def _get_existing_regions(): existing_regions = [] possible_files = os.listdir(os.path.expanduser('~')) for f in possible_files: something = re.search('\\.bees\\.(.*)', f) (existing_regions.append(something.group(1)) if something else 'no') return existing_regions
[ "def", "_get_existing_regions", "(", ")", ":", "existing_regions", "=", "[", "]", "possible_files", "=", "os", ".", "listdir", "(", "os", ".", "path", ".", "expanduser", "(", "'~'", ")", ")", "for", "f", "in", "possible_files", ":", "something", "=", "re...
return a list of zone name strings from looking at existing region ~/ .
train
false
2,411
def group_type_specs_get(context, group_type_id): return IMPL.group_type_specs_get(context, group_type_id)
[ "def", "group_type_specs_get", "(", "context", ",", "group_type_id", ")", ":", "return", "IMPL", ".", "group_type_specs_get", "(", "context", ",", "group_type_id", ")" ]
get all group specs for a group type .
train
false
2,412
def safe_as_int(val, atol=0.001): mod = (np.asarray(val) % 1) if (mod.ndim == 0): if (mod > 0.5): mod = (1 - mod) else: mod[(mod > 0.5)] = (1 - mod[(mod > 0.5)]) try: np.testing.assert_allclose(mod, 0, atol=atol) except AssertionError: raise ValueError('Integer argument required but received {0}, check ...
[ "def", "safe_as_int", "(", "val", ",", "atol", "=", "0.001", ")", ":", "mod", "=", "(", "np", ".", "asarray", "(", "val", ")", "%", "1", ")", "if", "(", "mod", ".", "ndim", "==", "0", ")", ":", "if", "(", "mod", ">", "0.5", ")", ":", "mod",...
attempt to safely cast values to integer format .
train
false
2,413
def generate_docs(root_dir, session): services_doc_path = os.path.join(root_dir, 'reference', 'services') if (not os.path.exists(services_doc_path)): os.makedirs(services_doc_path) for service_name in session.get_available_services(): docs = ServiceDocumenter(service_name, session).document_service() service_d...
[ "def", "generate_docs", "(", "root_dir", ",", "session", ")", ":", "services_doc_path", "=", "os", ".", "path", ".", "join", "(", "root_dir", ",", "'reference'", ",", "'services'", ")", "if", "(", "not", "os", ".", "path", ".", "exists", "(", "services_d...
generates the reference documentation for botocore this will go through every available aws service and output restructured text files documenting each service .
train
false
2,414
def commit_statuses(**kwargs): base = {'updated_at': datetimes(timezones=['UTC']), 'state': text(), 'context': text(average_size=2), 'target_url': text(average_size=2)} base.update(**kwargs) return fixed_dictionaries(base)
[ "def", "commit_statuses", "(", "**", "kwargs", ")", ":", "base", "=", "{", "'updated_at'", ":", "datetimes", "(", "timezones", "=", "[", "'UTC'", "]", ")", ",", "'state'", ":", "text", "(", ")", ",", "'context'", ":", "text", "(", "average_size", "=", ...
create a strategy for github commit status dicts .
train
false
2,415
def featured_map(request, site): map_obj = resolve_object(request, Map, {'featuredurl': site}, permission='base.view_resourcebase', permission_msg=_PERMISSION_MSG_VIEW) return map_view(request, str(map_obj.id))
[ "def", "featured_map", "(", "request", ",", "site", ")", ":", "map_obj", "=", "resolve_object", "(", "request", ",", "Map", ",", "{", "'featuredurl'", ":", "site", "}", ",", "permission", "=", "'base.view_resourcebase'", ",", "permission_msg", "=", "_PERMISSIO...
the view that returns the map composer opened to the map with the given official site url .
train
false
2,416
@deprecated(u'2.1') def pieces(seq, num=2): start = 0 while 1: item = seq[start:(start + num)] if (not len(item)): break (yield item) start += num
[ "@", "deprecated", "(", "u'2.1'", ")", "def", "pieces", "(", "seq", ",", "num", "=", "2", ")", ":", "start", "=", "0", "while", "1", ":", "item", "=", "seq", "[", "start", ":", "(", "start", "+", "num", ")", "]", "if", "(", "not", "len", "(",...
break up the *seq* into *num* tuples .
train
false
2,417
@default_selem def dilation(image, selem=None, out=None, shift_x=False, shift_y=False): selem = np.array(selem) selem = _shift_selem(selem, shift_x, shift_y) selem = _invert_selem(selem) if (out is None): out = np.empty_like(image) ndi.grey_dilation(image, footprint=selem, output=out) return out
[ "@", "default_selem", "def", "dilation", "(", "image", ",", "selem", "=", "None", ",", "out", "=", "None", ",", "shift_x", "=", "False", ",", "shift_y", "=", "False", ")", ":", "selem", "=", "np", ".", "array", "(", "selem", ")", "selem", "=", "_sh...
return greyscale morphological dilation of an image .
train
false
2,418
def add_modulo(image1, image2): image1.load() image2.load() return image1._new(image1.im.chop_add_modulo(image2.im))
[ "def", "add_modulo", "(", "image1", ",", "image2", ")", ":", "image1", ".", "load", "(", ")", "image2", ".", "load", "(", ")", "return", "image1", ".", "_new", "(", "image1", ".", "im", ".", "chop_add_modulo", "(", "image2", ".", "im", ")", ")" ]
add two images .
train
false
2,420
def insert_many(seq, where, val): seq = list(seq) result = [] for i in range((len(where) + len(seq))): if (i in where): result.append(val) else: result.append(seq.pop(0)) return tuple(result)
[ "def", "insert_many", "(", "seq", ",", "where", ",", "val", ")", ":", "seq", "=", "list", "(", "seq", ")", "result", "=", "[", "]", "for", "i", "in", "range", "(", "(", "len", "(", "where", ")", "+", "len", "(", "seq", ")", ")", ")", ":", "...
insert multiple documents .
train
false
2,421
@lru_cache() def get_git_branch(): branch = _shell_command(['/usr/bin/git', 'symbolic-ref', '-q', 'HEAD']).strip() if (not branch): return None return '/'.join(branch.split('/')[2:])
[ "@", "lru_cache", "(", ")", "def", "get_git_branch", "(", ")", ":", "branch", "=", "_shell_command", "(", "[", "'/usr/bin/git'", ",", "'symbolic-ref'", ",", "'-q'", ",", "'HEAD'", "]", ")", ".", "strip", "(", ")", "if", "(", "not", "branch", ")", ":", ...
returns the current git branch .
train
false
2,422
def addLoopToPointTable(loop, pointTable): for point in loop: pointTable[point] = None
[ "def", "addLoopToPointTable", "(", "loop", ",", "pointTable", ")", ":", "for", "point", "in", "loop", ":", "pointTable", "[", "point", "]", "=", "None" ]
add the points in the loop to the point table .
train
false