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
41,458
def _incremental_fit_estimator(estimator, X, y, classes, train, test, train_sizes, scorer, verbose): (train_scores, test_scores) = ([], []) partitions = zip(train_sizes, np.split(train, train_sizes)[:(-1)]) for (n_train_samples, partial_train) in partitions: train_subset = train[:n_train_samples] (X_train, y_tra...
[ "def", "_incremental_fit_estimator", "(", "estimator", ",", "X", ",", "y", ",", "classes", ",", "train", ",", "test", ",", "train_sizes", ",", "scorer", ",", "verbose", ")", ":", "(", "train_scores", ",", "test_scores", ")", "=", "(", "[", "]", ",", "[...
train estimator on training subsets incrementally and compute scores .
train
false
41,459
def get_english_lang(): try: return Language.objects.get_default().id except (Language.DoesNotExist, OperationalError): return 65535
[ "def", "get_english_lang", "(", ")", ":", "try", ":", "return", "Language", ".", "objects", ".", "get_default", "(", ")", ".", "id", "except", "(", "Language", ".", "DoesNotExist", ",", "OperationalError", ")", ":", "return", "65535" ]
returns object id for english language .
train
false
41,460
def _read_config(conf_file=None): if (conf_file is None): paths = ('/etc/supervisor/supervisord.conf', '/etc/supervisord.conf') for path in paths: if os.path.exists(path): conf_file = path break if (conf_file is None): raise CommandExecutionError('No suitable config file found') config = configparse...
[ "def", "_read_config", "(", "conf_file", "=", "None", ")", ":", "if", "(", "conf_file", "is", "None", ")", ":", "paths", "=", "(", "'/etc/supervisor/supervisord.conf'", ",", "'/etc/supervisord.conf'", ")", "for", "path", "in", "paths", ":", "if", "os", ".", ...
reads the config file using configparser .
train
true
41,461
@require_context @pick_context_manager_writer def instance_info_cache_delete(context, instance_uuid): model_query(context, models.InstanceInfoCache).filter_by(instance_uuid=instance_uuid).soft_delete()
[ "@", "require_context", "@", "pick_context_manager_writer", "def", "instance_info_cache_delete", "(", "context", ",", "instance_uuid", ")", ":", "model_query", "(", "context", ",", "models", ".", "InstanceInfoCache", ")", ".", "filter_by", "(", "instance_uuid", "=", ...
deletes an existing instance_info_cache record .
train
false
41,462
def getTransformedVector3(tetragrid, vector3): if getIsIdentityTetragridOrNone(tetragrid): return vector3.copy() return getTransformedVector3Blindly(tetragrid, vector3)
[ "def", "getTransformedVector3", "(", "tetragrid", ",", "vector3", ")", ":", "if", "getIsIdentityTetragridOrNone", "(", "tetragrid", ")", ":", "return", "vector3", ".", "copy", "(", ")", "return", "getTransformedVector3Blindly", "(", "tetragrid", ",", "vector3", ")...
get the vector3 multiplied by a matrix .
train
false
41,463
def test_password_strength(password, user_inputs=None): result = zxcvbn.password_strength(password, user_inputs) result[u'feedback'] = get_feedback(result[u'score'], result[u'match_sequence']) return result
[ "def", "test_password_strength", "(", "password", ",", "user_inputs", "=", "None", ")", ":", "result", "=", "zxcvbn", ".", "password_strength", "(", "password", ",", "user_inputs", ")", "result", "[", "u'feedback'", "]", "=", "get_feedback", "(", "result", "["...
wrapper around zxcvbn .
train
false
41,464
def sigmaclip(a, low=4.0, high=4.0): c = np.asarray(a).ravel() delta = 1 while delta: c_std = c.std() c_mean = c.mean() size = c.size critlower = (c_mean - (c_std * low)) critupper = (c_mean + (c_std * high)) c = c[((c > critlower) & (c < critupper))] delta = (size - c.size) return SigmaclipResult(c, ...
[ "def", "sigmaclip", "(", "a", ",", "low", "=", "4.0", ",", "high", "=", "4.0", ")", ":", "c", "=", "np", ".", "asarray", "(", "a", ")", ".", "ravel", "(", ")", "delta", "=", "1", "while", "delta", ":", "c_std", "=", "c", ".", "std", "(", ")...
iterative sigma-clipping of array elements .
train
false
41,466
def output(): return s3_rest_controller()
[ "def", "output", "(", ")", ":", "return", "s3_rest_controller", "(", ")" ]
dont display data .
train
false
41,468
def _setHTTPReferer(): if conf.referer: debugMsg = 'setting the HTTP Referer header' logger.debug(debugMsg) conf.httpHeaders[HTTP_HEADER.REFERER] = conf.referer
[ "def", "_setHTTPReferer", "(", ")", ":", "if", "conf", ".", "referer", ":", "debugMsg", "=", "'setting the HTTP Referer header'", "logger", ".", "debug", "(", "debugMsg", ")", "conf", ".", "httpHeaders", "[", "HTTP_HEADER", ".", "REFERER", "]", "=", "conf", ...
set the http referer .
train
false
41,469
def register_class(class_): manager = manager_of_class(class_) if (manager is None): manager = _instrumentation_factory.create_manager_for_cls(class_) return manager
[ "def", "register_class", "(", "class_", ")", ":", "manager", "=", "manager_of_class", "(", "class_", ")", "if", "(", "manager", "is", "None", ")", ":", "manager", "=", "_instrumentation_factory", ".", "create_manager_for_cls", "(", "class_", ")", "return", "ma...
register class instrumentation .
train
false
41,470
def iterload_objects(import_paths): return map(load_object, import_paths)
[ "def", "iterload_objects", "(", "import_paths", ")", ":", "return", "map", "(", "load_object", ",", "import_paths", ")" ]
load a list of objects .
train
false
41,471
def corr_equi(k_vars, rho): corr = np.empty((k_vars, k_vars)) corr.fill(rho) corr[np.diag_indices_from(corr)] = 1 return corr
[ "def", "corr_equi", "(", "k_vars", ",", "rho", ")", ":", "corr", "=", "np", ".", "empty", "(", "(", "k_vars", ",", "k_vars", ")", ")", "corr", ".", "fill", "(", "rho", ")", "corr", "[", "np", ".", "diag_indices_from", "(", "corr", ")", "]", "=", ...
create equicorrelated correlation matrix with rho on off diagonal parameters k_vars : int number of variables .
train
false
41,472
def drop_unique_constraint(migrate_engine, table_name, uc_name, *columns, **col_name_col_instance): if (migrate_engine.name in ['mysql', 'postgresql']): meta = MetaData() meta.bind = migrate_engine t = Table(table_name, meta, autoload=True) uc = UniqueConstraint(table=t, name=uc_name, *columns) uc.drop() el...
[ "def", "drop_unique_constraint", "(", "migrate_engine", ",", "table_name", ",", "uc_name", ",", "*", "columns", ",", "**", "col_name_col_instance", ")", ":", "if", "(", "migrate_engine", ".", "name", "in", "[", "'mysql'", ",", "'postgresql'", "]", ")", ":", ...
this method drops uc from table and works for mysql .
train
false
41,473
def make_compensator(info, from_, to, exclude_comp_chs=False): if (from_ == to): return None if (from_ != 0): C1 = _make_compensator(info, from_) comp_from_0 = linalg.inv((np.eye(info['nchan']) - C1)) if (to != 0): C2 = _make_compensator(info, to) comp_0_to = (np.eye(info['nchan']) - C2) if (from_ != 0): ...
[ "def", "make_compensator", "(", "info", ",", "from_", ",", "to", ",", "exclude_comp_chs", "=", "False", ")", ":", "if", "(", "from_", "==", "to", ")", ":", "return", "None", "if", "(", "from_", "!=", "0", ")", ":", "C1", "=", "_make_compensator", "("...
return compensation matrix eg .
train
false
41,475
def get_work_dim(*args, **kargs): raise _stub_error
[ "def", "get_work_dim", "(", "*", "args", ",", "**", "kargs", ")", ":", "raise", "_stub_error" ]
opencl get_work_dim() .
train
false
41,476
def sub_pre(e): reps = [a for a in e.atoms(Add) if a.could_extract_minus_sign()] reps.sort(key=default_sort_key) e = e.xreplace(dict(((a, Mul._from_args([S.NegativeOne, (- a)])) for a in reps))) if isinstance(e, Basic): negs = {} for a in sorted(e.atoms(Add), key=default_sort_key): if ((a in reps) or a.could...
[ "def", "sub_pre", "(", "e", ")", ":", "reps", "=", "[", "a", "for", "a", "in", "e", ".", "atoms", "(", "Add", ")", "if", "a", ".", "could_extract_minus_sign", "(", ")", "]", "reps", ".", "sort", "(", "key", "=", "default_sort_key", ")", "e", "=",...
replace y - x with - if -1 can be extracted from y - x .
train
false
41,477
def get_all_access_keys(user_name, marker=None, max_items=None, region=None, key=None, keyid=None, profile=None): conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile) try: return conn.get_all_access_keys(user_name, marker, max_items) except boto.exception.BotoServerError as e: log.debug(e) lo...
[ "def", "get_all_access_keys", "(", "user_name", ",", "marker", "=", "None", ",", "max_items", "=", "None", ",", "region", "=", "None", ",", "key", "=", "None", ",", "keyid", "=", "None", ",", "profile", "=", "None", ")", ":", "conn", "=", "_get_conn", ...
get all access keys from a user .
train
true
41,478
def react(main, argv=(), _reactor=None): if (_reactor is None): from twisted.internet import reactor as _reactor finished = main(_reactor, *argv) codes = [0] stopping = [] _reactor.addSystemEventTrigger('before', 'shutdown', stopping.append, True) def stop(result, stopReactor): if stopReactor: try: _re...
[ "def", "react", "(", "main", ",", "argv", "=", "(", ")", ",", "_reactor", "=", "None", ")", ":", "if", "(", "_reactor", "is", "None", ")", ":", "from", "twisted", ".", "internet", "import", "reactor", "as", "_reactor", "finished", "=", "main", "(", ...
call c{main} and run the reactor until the l{deferred} it returns fires .
train
false
41,479
def noHint(str): return re.sub('(^.*?)( ?\\(.+?\\))?$', '\\1', str)
[ "def", "noHint", "(", "str", ")", ":", "return", "re", ".", "sub", "(", "'(^.*?)( ?\\\\(.+?\\\\))?$'", ",", "'\\\\1'", ",", "str", ")" ]
remove translation hint from end of string .
train
false
41,480
def theme_data(): field = s3db.gis_layer_theme_id() field.requires = IS_EMPTY_OR(field.requires) output = s3_rest_controller(csv_extra_fields=[dict(label='Layer', field=field)]) return output
[ "def", "theme_data", "(", ")", ":", "field", "=", "s3db", ".", "gis_layer_theme_id", "(", ")", "field", ".", "requires", "=", "IS_EMPTY_OR", "(", "field", ".", "requires", ")", "output", "=", "s3_rest_controller", "(", "csv_extra_fields", "=", "[", "dict", ...
restful crud controller .
train
false
41,482
def recursive_set_rng_kwarg(expr, rng=None): if (rng is None): rng = np.random.RandomState() lrng = as_apply(rng) for node in dfs(expr): if (node.name in implicit_stochastic_symbols): for (ii, (name, arg)) in enumerate(list(node.named_args)): if (name == 'rng'): node.named_args[ii] = ('rng', lrng) ...
[ "def", "recursive_set_rng_kwarg", "(", "expr", ",", "rng", "=", "None", ")", ":", "if", "(", "rng", "is", "None", ")", ":", "rng", "=", "np", ".", "random", ".", "RandomState", "(", ")", "lrng", "=", "as_apply", "(", "rng", ")", "for", "node", "in"...
make all of the stochastic nodes in expr use the rng uniform -> uniform .
train
false
41,483
def getSpacedPortionDirections(interpolationDictionary): portionDirections = [] for interpolationDictionaryValue in interpolationDictionary.values(): portionDirections += interpolationDictionaryValue.portionDirections portionDirections.sort(comparePortionDirection) if (len(portionDirections) < 1): return [] sp...
[ "def", "getSpacedPortionDirections", "(", "interpolationDictionary", ")", ":", "portionDirections", "=", "[", "]", "for", "interpolationDictionaryValue", "in", "interpolationDictionary", ".", "values", "(", ")", ":", "portionDirections", "+=", "interpolationDictionaryValue"...
get sorted portion directions .
train
false
41,484
def get_url_field(): from django.forms import URLField field = URLField() try: field = URLField(verify_exists=False) except TypeError as e: pass return field
[ "def", "get_url_field", "(", ")", ":", "from", "django", ".", "forms", "import", "URLField", "field", "=", "URLField", "(", ")", "try", ":", "field", "=", "URLField", "(", "verify_exists", "=", "False", ")", "except", "TypeError", "as", "e", ":", "pass",...
this should be compatible with both django 1 .
train
false
41,485
def list_to_local(acs, attrlist, allow_unknown_attributes=False): if (not acs): acs = [AttributeConverter()] acsd = {'': acs} else: acsd = dict([(a.name_format, a) for a in acs]) ava = {} for attr in attrlist: try: _func = acsd[attr.name_format].ava_from except KeyError: if ((attr.name_format == NAM...
[ "def", "list_to_local", "(", "acs", ",", "attrlist", ",", "allow_unknown_attributes", "=", "False", ")", ":", "if", "(", "not", "acs", ")", ":", "acs", "=", "[", "AttributeConverter", "(", ")", "]", "acsd", "=", "{", "''", ":", "acs", "}", "else", ":...
replaces the attribute names in a attribute value assertion with the equivalent name from a local name format .
train
true
41,486
def get_default_support_url(request=None, force_is_admin=False): siteconfig = SiteConfiguration.objects.get_current() if siteconfig.get(u'send_support_usage_stats'): support_data = serialize_support_data(request, force_is_admin) else: support_data = u'' return (settings.DEFAULT_SUPPORT_URL % {u'support_data': s...
[ "def", "get_default_support_url", "(", "request", "=", "None", ",", "force_is_admin", "=", "False", ")", ":", "siteconfig", "=", "SiteConfiguration", ".", "objects", ".", "get_current", "(", ")", "if", "siteconfig", ".", "get", "(", "u'send_support_usage_stats'", ...
return the url for the default review board support page .
train
false
41,487
def parse_request_data(request): try: data = json.loads((request.body or '{}')) except ValueError: raise ValueError(_('The record is not in the correct format. Please add a valid username or email address.')) return data
[ "def", "parse_request_data", "(", "request", ")", ":", "try", ":", "data", "=", "json", ".", "loads", "(", "(", "request", ".", "body", "or", "'{}'", ")", ")", "except", "ValueError", ":", "raise", "ValueError", "(", "_", "(", "'The record is not in the co...
parse and return request data .
train
false
41,488
def _extract_files_to_lint(file_diffs): if (not file_diffs): return [] lint_files = [f.name for f in file_diffs if (f.status.upper() in 'ACMRT')] return lint_files
[ "def", "_extract_files_to_lint", "(", "file_diffs", ")", ":", "if", "(", "not", "file_diffs", ")", ":", "return", "[", "]", "lint_files", "=", "[", "f", ".", "name", "for", "f", "in", "file_diffs", "if", "(", "f", ".", "status", ".", "upper", "(", ")...
grab only files out of a list of filediffs that have a acmrt status .
train
false
41,490
def test_future_altaz(): from ...utils.exceptions import AstropyWarning from ..builtin_frames import utils if hasattr(utils, u'__warningregistry__'): utils.__warningregistry__.clear() with catch_warnings() as found_warnings: location = EarthLocation(lat=(0 * u.deg), lon=(0 * u.deg)) t = Time(u'J2161') SkyCo...
[ "def", "test_future_altaz", "(", ")", ":", "from", "...", "utils", ".", "exceptions", "import", "AstropyWarning", "from", ".", ".", "builtin_frames", "import", "utils", "if", "hasattr", "(", "utils", ",", "u'__warningregistry__'", ")", ":", "utils", ".", "__wa...
while this does test the full stack .
train
false
41,492
def readmailcapfile(fp): caps = {} while 1: line = fp.readline() if (not line): break if ((line[0] == '#') or (line.strip() == '')): continue nextline = line while (nextline[(-2):] == '\\\n'): nextline = fp.readline() if (not nextline): nextline = '\n' line = (line[:(-2)] + nextline) (k...
[ "def", "readmailcapfile", "(", "fp", ")", ":", "caps", "=", "{", "}", "while", "1", ":", "line", "=", "fp", ".", "readline", "(", ")", "if", "(", "not", "line", ")", ":", "break", "if", "(", "(", "line", "[", "0", "]", "==", "'#'", ")", "or",...
read a mailcap file and return a dictionary keyed by mime type .
train
false
41,493
@transaction.non_atomic_requests @require_POST @ensure_csrf_cookie @cache_control(no_cache=True, no_store=True, must_revalidate=True) @require_level('staff') def problem_grade_report(request, course_id): course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id) try: lms.djangoapps.instructor_task.api.s...
[ "@", "transaction", ".", "non_atomic_requests", "@", "require_POST", "@", "ensure_csrf_cookie", "@", "cache_control", "(", "no_cache", "=", "True", ",", "no_store", "=", "True", ",", "must_revalidate", "=", "True", ")", "@", "require_level", "(", "'staff'", ")",...
request a csv showing students grades for all problems in the course .
train
false
41,494
def synchronized(lock=None): if (lock is None): lock = threading.Lock() def wrapper(function): def new_function(*args, **kwargs): lock.acquire() try: return function(*args, **kwargs) finally: lock.release() return new_function return wrapper
[ "def", "synchronized", "(", "lock", "=", "None", ")", ":", "if", "(", "lock", "is", "None", ")", ":", "lock", "=", "threading", ".", "Lock", "(", ")", "def", "wrapper", "(", "function", ")", ":", "def", "new_function", "(", "*", "args", ",", "**", ...
this wrapper will serialize access to func to a single thread .
train
false
41,495
def CreateUserSecret(user): secret = base64.b32encode(os.urandom(_SECRET_BYTES)) secrets.PutSecret(_SecretName(user), secret) DisplayUserSecret(user)
[ "def", "CreateUserSecret", "(", "user", ")", ":", "secret", "=", "base64", ".", "b32encode", "(", "os", ".", "urandom", "(", "_SECRET_BYTES", ")", ")", "secrets", ".", "PutSecret", "(", "_SecretName", "(", "user", ")", ",", "secret", ")", "DisplayUserSecre...
generates a random user secret and stores it to the secrets database .
train
false
41,496
def LoadSingleQueue(queue_info, open_fn=None): builder = yaml_object.ObjectBuilder(QueueInfoExternal) handler = yaml_builder.BuilderHandler(builder) listener = yaml_listener.EventListener(handler) listener.Parse(queue_info) queue_info = handler.GetResults() if (len(queue_info) < 1): raise MalformedQueueConfigur...
[ "def", "LoadSingleQueue", "(", "queue_info", ",", "open_fn", "=", "None", ")", ":", "builder", "=", "yaml_object", ".", "ObjectBuilder", "(", "QueueInfoExternal", ")", "handler", "=", "yaml_builder", ".", "BuilderHandler", "(", "builder", ")", "listener", "=", ...
load a queue .
train
false
41,497
def get_source_index(): try: exists = STORAGE.index_exists('source') except OSError: create_index() exists = False if (not exists): create_source_index() index = STORAGE.open_index('source') if ('location' not in index.schema): index.add_field('location', TEXT()) if ('pk' not in index.schema): index.a...
[ "def", "get_source_index", "(", ")", ":", "try", ":", "exists", "=", "STORAGE", ".", "index_exists", "(", "'source'", ")", "except", "OSError", ":", "create_index", "(", ")", "exists", "=", "False", "if", "(", "not", "exists", ")", ":", "create_source_inde...
returns source index object .
train
false
41,498
def _keys_match(attribute): def key_match_invariant(pmap): if (pmap is None): return (True, '') for (key, value) in pmap.items(): if (key != getattr(value, attribute)): return (False, '{} is not correct key for {}'.format(key, value)) return (True, '') return key_match_invariant
[ "def", "_keys_match", "(", "attribute", ")", ":", "def", "key_match_invariant", "(", "pmap", ")", ":", "if", "(", "pmap", "is", "None", ")", ":", "return", "(", "True", ",", "''", ")", "for", "(", "key", ",", "value", ")", "in", "pmap", ".", "items...
create an invariant for a field holding a pmap .
train
false
41,499
def GetRequestCpuUsage(): return _apphosting_runtime___python__apiproxy.get_request_cpu_usage()
[ "def", "GetRequestCpuUsage", "(", ")", ":", "return", "_apphosting_runtime___python__apiproxy", ".", "get_request_cpu_usage", "(", ")" ]
returns the number of megacycles used so far by this request .
train
false
41,500
def _to_const(cf): if isinstance(cf, string_types): if (cf not in _str_to_frame): raise ValueError(('Unknown cf %s' % cf)) cf = _str_to_frame[cf] elif (not isinstance(cf, (int, np.integer))): raise TypeError(('cf must be str or int, not %s' % type(cf))) return int(cf)
[ "def", "_to_const", "(", "cf", ")", ":", "if", "isinstance", "(", "cf", ",", "string_types", ")", ":", "if", "(", "cf", "not", "in", "_str_to_frame", ")", ":", "raise", "ValueError", "(", "(", "'Unknown cf %s'", "%", "cf", ")", ")", "cf", "=", "_str_...
convert string or int coord frame into int .
train
false
41,501
def at_server_cold_start(): pass
[ "def", "at_server_cold_start", "(", ")", ":", "pass" ]
this is called only when the server starts "cold" .
train
false
41,502
def getConnectError(e): if isinstance(e, Exception): args = e.args else: args = e try: (number, string) = args except ValueError: return ConnectError(string=e) if (hasattr(socket, 'gaierror') and isinstance(e, socket.gaierror)): klass = UnknownHostError else: klass = errnoMapping.get(number, ConnectEr...
[ "def", "getConnectError", "(", "e", ")", ":", "if", "isinstance", "(", "e", ",", "Exception", ")", ":", "args", "=", "e", ".", "args", "else", ":", "args", "=", "e", "try", ":", "(", "number", ",", "string", ")", "=", "args", "except", "ValueError"...
given a socket exception .
train
false
41,503
def safe_rmpath(path): try: st = os.stat(path) if stat.S_ISDIR(st.st_mode): os.rmdir(path) else: os.remove(path) except OSError as err: if (err.errno != errno.ENOENT): raise
[ "def", "safe_rmpath", "(", "path", ")", ":", "try", ":", "st", "=", "os", ".", "stat", "(", "path", ")", "if", "stat", ".", "S_ISDIR", "(", "st", ".", "st_mode", ")", ":", "os", ".", "rmdir", "(", "path", ")", "else", ":", "os", ".", "remove", ...
convenience function for removing temporary test files or dirs .
train
false
41,504
def promotions(request): promotions = get_request_promotions(request) context = {'url_path': request.path} split_by_position(promotions, context) return context
[ "def", "promotions", "(", "request", ")", ":", "promotions", "=", "get_request_promotions", "(", "request", ")", "context", "=", "{", "'url_path'", ":", "request", ".", "path", "}", "split_by_position", "(", "promotions", ",", "context", ")", "return", "contex...
for adding bindings for banners and pods to the template context .
train
false
41,505
def proxy_functions(proxy): if proxy: return {'proxy_functions': proxy['rest_sample.fns']()}
[ "def", "proxy_functions", "(", "proxy", ")", ":", "if", "proxy", ":", "return", "{", "'proxy_functions'", ":", "proxy", "[", "'rest_sample.fns'", "]", "(", ")", "}" ]
the loader will execute functions with one argument and pass a reference to the proxymodules lazyloader object .
train
false
41,506
def change_PROCESS_AUTOMATICALLY(process_automatically): process_automatically = checkbox_to_value(process_automatically) if (sickbeard.PROCESS_AUTOMATICALLY == process_automatically): return sickbeard.PROCESS_AUTOMATICALLY = process_automatically if sickbeard.PROCESS_AUTOMATICALLY: if (not sickbeard.autoPostPr...
[ "def", "change_PROCESS_AUTOMATICALLY", "(", "process_automatically", ")", ":", "process_automatically", "=", "checkbox_to_value", "(", "process_automatically", ")", "if", "(", "sickbeard", ".", "PROCESS_AUTOMATICALLY", "==", "process_automatically", ")", ":", "return", "s...
enable/disable postprocessor thread todo: make this return true/false on success/failure .
train
false
41,507
def get_city_code(request): if ('X-AppEngine-City' in request.headers): return request.headers['X-AppEngine-City'] return None
[ "def", "get_city_code", "(", "request", ")", ":", "if", "(", "'X-AppEngine-City'", "in", "request", ".", "headers", ")", ":", "return", "request", ".", "headers", "[", "'X-AppEngine-City'", "]", "return", "None" ]
city code based on iso 3166-1 .
train
false
41,508
def get_file_name(blob_key): if (not blob_key): raise files.InvalidArgumentError('Empty blob key') if (not isinstance(blob_key, (blobstore.BlobKey, basestring))): raise files.InvalidArgumentError('Expected string or blobstore.BlobKey') return ('%s%s' % (_BLOBSTORE_DIRECTORY, blob_key))
[ "def", "get_file_name", "(", "blob_key", ")", ":", "if", "(", "not", "blob_key", ")", ":", "raise", "files", ".", "InvalidArgumentError", "(", "'Empty blob key'", ")", "if", "(", "not", "isinstance", "(", "blob_key", ",", "(", "blobstore", ".", "BlobKey", ...
get a filename to read from the blob .
train
false
41,509
def multivariateNormalPdf(z, x, sigma): assert ((len(z.shape) == 1) and (len(x.shape) == 1) and (len(x) == len(z)) and (sigma.shape == (len(x), len(z)))) tmp = ((-0.5) * dot(dot((z - x), inv(sigma)), (z - x))) res = (((1.0 / power((2.0 * pi), (len(z) / 2.0))) * (1.0 / sqrt(det(sigma)))) * exp(tmp)) return res
[ "def", "multivariateNormalPdf", "(", "z", ",", "x", ",", "sigma", ")", ":", "assert", "(", "(", "len", "(", "z", ".", "shape", ")", "==", "1", ")", "and", "(", "len", "(", "x", ".", "shape", ")", "==", "1", ")", "and", "(", "len", "(", "x", ...
the pdf of a multivariate normal distribution .
train
false
41,510
def pivot(self, index=None, columns=None, values=None): if (values is None): cols = ([columns] if (index is None) else [index, columns]) append = (index is None) indexed = self.set_index(cols, append=append) return indexed.unstack(columns) else: if (index is None): index = self.index else: index = s...
[ "def", "pivot", "(", "self", ",", "index", "=", "None", ",", "columns", "=", "None", ",", "values", "=", "None", ")", ":", "if", "(", "values", "is", "None", ")", ":", "cols", "=", "(", "[", "columns", "]", "if", "(", "index", "is", "None", ")"...
see dataframe .
train
false
41,511
def convert_ReferenceProperty(model, prop, kwargs): kwargs['reference_class'] = prop.reference_class kwargs.setdefault('allow_blank', (not prop.required)) return ReferencePropertyField(**kwargs)
[ "def", "convert_ReferenceProperty", "(", "model", ",", "prop", ",", "kwargs", ")", ":", "kwargs", "[", "'reference_class'", "]", "=", "prop", ".", "reference_class", "kwargs", ".", "setdefault", "(", "'allow_blank'", ",", "(", "not", "prop", ".", "required", ...
returns a form field for a db .
train
false
41,512
@intercept_errors(UserAPIInternalError, ignore_errors=[UserAPIRequestError]) def update_user_preferences(requesting_user, update, user=None): if ((not user) or isinstance(user, basestring)): user = _get_authorized_user(requesting_user, user) else: _check_authorized(requesting_user, user.username) errors = {} se...
[ "@", "intercept_errors", "(", "UserAPIInternalError", ",", "ignore_errors", "=", "[", "UserAPIRequestError", "]", ")", "def", "update_user_preferences", "(", "requesting_user", ",", "update", ",", "user", "=", "None", ")", ":", "if", "(", "(", "not", "user", "...
update the user preferences for the given user .
train
false
41,513
def with_text(no_text=False, text=False, utext=False): values = [] if no_text: values.append(0) if text: values.append(1) if utext: values.append(2) def set_value(function): try: function.TEXT.add(values) except AttributeError: function.TEXT = set(values) return function return set_value
[ "def", "with_text", "(", "no_text", "=", "False", ",", "text", "=", "False", ",", "utext", "=", "False", ")", ":", "values", "=", "[", "]", "if", "no_text", ":", "values", ".", "append", "(", "0", ")", "if", "text", ":", "values", ".", "append", ...
decorator for benchmarks that use text .
train
false
41,514
def _GetValidMain(module): if (not hasattr(module, 'main')): return None main = module.main if (not hasattr(main, '__call__')): return None defaults = main.__defaults__ if defaults: default_argcount = len(defaults) else: default_argcount = 0 if ((main.__code__.co_argcount - default_argcount) == 0): ret...
[ "def", "_GetValidMain", "(", "module", ")", ":", "if", "(", "not", "hasattr", "(", "module", ",", "'main'", ")", ")", ":", "return", "None", "main", "=", "module", ".", "main", "if", "(", "not", "hasattr", "(", "main", ",", "'__call__'", ")", ")", ...
returns a main function in module if it exists and is valid or none .
train
false
41,515
def _apps(): def _in_exclusions(module_name): settings_exclusions = getattr(settings, 'RAPIDSMS_HANDLERS_EXCLUDE_APPS', []) return ((module_name == 'rapidsms.contrib.handlers') or module_name.startswith('django.contrib.') or (module_name in settings_exclusions)) return [module_name for module_name in settings.INS...
[ "def", "_apps", "(", ")", ":", "def", "_in_exclusions", "(", "module_name", ")", ":", "settings_exclusions", "=", "getattr", "(", "settings", ",", "'RAPIDSMS_HANDLERS_EXCLUDE_APPS'", ",", "[", "]", ")", "return", "(", "(", "module_name", "==", "'rapidsms.contrib...
return a list of the apps which may contain handlers .
train
false
41,516
@require_context @pick_context_manager_reader def flavor_get(context, id): result = _flavor_get_query(context).filter_by(id=id).first() if (not result): raise exception.FlavorNotFound(flavor_id=id) return _dict_with_extra_specs(result)
[ "@", "require_context", "@", "pick_context_manager_reader", "def", "flavor_get", "(", "context", ",", "id", ")", ":", "result", "=", "_flavor_get_query", "(", "context", ")", ".", "filter_by", "(", "id", "=", "id", ")", ".", "first", "(", ")", "if", "(", ...
returns a dict describing specific flavor .
train
false
41,517
def get_best_encoding(stream): rv = (getattr(stream, 'encoding', None) or sys.getdefaultencoding()) if is_ascii_encoding(rv): return 'utf-8' return rv
[ "def", "get_best_encoding", "(", "stream", ")", ":", "rv", "=", "(", "getattr", "(", "stream", ",", "'encoding'", ",", "None", ")", "or", "sys", ".", "getdefaultencoding", "(", ")", ")", "if", "is_ascii_encoding", "(", "rv", ")", ":", "return", "'utf-8'"...
returns the default stream encoding if not found .
train
true
41,518
def init_siteconfig(app, created_models, verbosity, db=None, **kwargs): try: site = Site.objects.get_current() except Site.DoesNotExist: from django.contrib.sites.management import create_default_site create_default_site(app, created_models, verbosity, db=db) site = Site.objects.get_current() (siteconfig, is...
[ "def", "init_siteconfig", "(", "app", ",", "created_models", ",", "verbosity", ",", "db", "=", "None", ",", "**", "kwargs", ")", ":", "try", ":", "site", "=", "Site", ".", "objects", ".", "get_current", "(", ")", "except", "Site", ".", "DoesNotExist", ...
initialize the site configuration .
train
false
41,520
def pull_external(ctx, filename): hashed_filename = hash_func(filename) rel_path = path.join('webassets-external', ('%s_%s' % (hashed_filename, path.basename(filename)))) full_path = path.join(ctx.directory, rel_path) if path.isfile(full_path): gs = (lambda p: os.stat(p).st_mtime) if (gs(full_path) > gs(filenam...
[ "def", "pull_external", "(", "ctx", ",", "filename", ")", ":", "hashed_filename", "=", "hash_func", "(", "filename", ")", "rel_path", "=", "path", ".", "join", "(", "'webassets-external'", ",", "(", "'%s_%s'", "%", "(", "hashed_filename", ",", "path", ".", ...
helper which will pull filename into :attr:environment .
train
false
41,521
def retry_request(n_retries=5, **kwargs): exc = resp = None for n_try in range(n_retries): try: exc = None resp = requests.request(**kwargs) if (resp.status_code < 500): return resp except requests.RequestException as exc: pass time.sleep(((2 ** (n_try + 1)) * 0.5)) if exc: raise exc if resp...
[ "def", "retry_request", "(", "n_retries", "=", "5", ",", "**", "kwargs", ")", ":", "exc", "=", "resp", "=", "None", "for", "n_try", "in", "range", "(", "n_retries", ")", ":", "try", ":", "exc", "=", "None", "resp", "=", "requests", ".", "request", ...
retry a requests request with exponential backoff up to n_retries times .
train
false
41,524
@release.command() def publish(): version = get_version(1) with chdir(BASE): subprocess.check_call(['git', 'push']) subprocess.check_call(['git', 'push', '--tags']) path = os.path.join(BASE, 'dist', 'beets-{}.tar.gz'.format(version)) subprocess.check_call(['twine', 'upload', path])
[ "@", "release", ".", "command", "(", ")", "def", "publish", "(", ")", ":", "version", "=", "get_version", "(", "1", ")", "with", "chdir", "(", "BASE", ")", ":", "subprocess", ".", "check_call", "(", "[", "'git'", ",", "'push'", "]", ")", "subprocess"...
publish message to an mqtt topic .
train
false
41,525
def test_url_utf8(): out = u'<a href="%(url)s" rel="nofollow">%(url)s</a>' tests = (('http://\xc3\xa9x\xc3\xa1mpl\xc3\xa9.com/', (out % {'url': u'http://\xe9x\xe1mpl\xe9.com/'})), ('http://\xc3\xa9x\xc3\xa1mpl\xc3\xa9.com/\xc3\xad\xc3\xa0\xc3\xb1\xc3\xa1/', (out % {'url': u'http://\xe9x\xe1mpl\xe9.com/\xed\xe0\xf1\xe...
[ "def", "test_url_utf8", "(", ")", ":", "out", "=", "u'<a href=\"%(url)s\" rel=\"nofollow\">%(url)s</a>'", "tests", "=", "(", "(", "'http://\\xc3\\xa9x\\xc3\\xa1mpl\\xc3\\xa9.com/'", ",", "(", "out", "%", "{", "'url'", ":", "u'http://\\xe9x\\xe1mpl\\xe9.com/'", "}", ")", ...
allow utf8 characters in urls themselves .
train
false
41,526
def orthogonal_procrustes(A, B, check_finite=True): if check_finite: A = np.asarray_chkfinite(A) B = np.asarray_chkfinite(B) else: A = np.asanyarray(A) B = np.asanyarray(B) if (A.ndim != 2): raise ValueError(('expected ndim to be 2, but observed %s' % A.ndim)) if (A.shape != B.shape): raise ValueError((...
[ "def", "orthogonal_procrustes", "(", "A", ",", "B", ",", "check_finite", "=", "True", ")", ":", "if", "check_finite", ":", "A", "=", "np", ".", "asarray_chkfinite", "(", "A", ")", "B", "=", "np", ".", "asarray_chkfinite", "(", "B", ")", "else", ":", ...
compute the matrix solution of the orthogonal procrustes problem .
train
false
41,527
def clearcache(): global cache cache = {}
[ "def", "clearcache", "(", ")", ":", "global", "cache", "cache", "=", "{", "}" ]
clear the cache entirely .
train
false
41,528
def _get_persistent_modules(): mods = set() with salt.utils.fopen(_LOADER_CONF, 'r') as loader_conf: for line in loader_conf: line = line.strip() mod_name = _get_module_name(line) if mod_name: mods.add(mod_name) return mods
[ "def", "_get_persistent_modules", "(", ")", ":", "mods", "=", "set", "(", ")", "with", "salt", ".", "utils", ".", "fopen", "(", "_LOADER_CONF", ",", "'r'", ")", "as", "loader_conf", ":", "for", "line", "in", "loader_conf", ":", "line", "=", "line", "."...
returns a list of modules in loader .
train
true
41,529
def build_tables(): print(u'Building lexer and parser tables.') sys.path.insert(0, os.path.dirname(__file__)) from xonsh.parser import Parser Parser(lexer_table=u'lexer_table', yacc_table=u'parser_table', outputdir=u'xonsh', yacc_debug=True) sys.path.pop(0)
[ "def", "build_tables", "(", ")", ":", "print", "(", "u'Building lexer and parser tables.'", ")", "sys", ".", "path", ".", "insert", "(", "0", ",", "os", ".", "path", ".", "dirname", "(", "__file__", ")", ")", "from", "xonsh", ".", "parser", "import", "Pa...
build the lexer/parser modules .
train
false
41,531
@handle_response_format @treeio_login_required def stream_checkmail(request, stream_id, response_format='html'): user = request.user.profile stream = get_object_or_404(MessageStream, pk=stream_id) if (not user.has_permission(stream)): return user_denied(request, message="You don't have access to this Stream", resp...
[ "@", "handle_response_format", "@", "treeio_login_required", "def", "stream_checkmail", "(", "request", ",", "stream_id", ",", "response_format", "=", "'html'", ")", ":", "user", "=", "request", ".", "user", ".", "profile", "stream", "=", "get_object_or_404", "(",...
stream check mail .
train
false
41,532
def get_schema_view(title=None, url=None, urlconf=None, renderer_classes=None): generator = SchemaGenerator(title=title, url=url, urlconf=urlconf) if (renderer_classes is None): if (renderers.BrowsableAPIRenderer in api_settings.DEFAULT_RENDERER_CLASSES): rclasses = [renderers.CoreJSONRenderer, renderers.Browsab...
[ "def", "get_schema_view", "(", "title", "=", "None", ",", "url", "=", "None", ",", "urlconf", "=", "None", ",", "renderer_classes", "=", "None", ")", ":", "generator", "=", "SchemaGenerator", "(", "title", "=", "title", ",", "url", "=", "url", ",", "ur...
return a schema view .
train
false
41,533
def test_disk_store_alt_name_relpath(): with TestConfig(DISK_TEST_CONFIG) as (directory, object_store): empty_dataset = MockDataset(1) directory.write('', 'files1/000/dataset_1.dat') directory.write('foo', 'foo.txt') try: assert (object_store.get_data(empty_dataset, extra_dir='dataset_1_files', alt_name='.....
[ "def", "test_disk_store_alt_name_relpath", "(", ")", ":", "with", "TestConfig", "(", "DISK_TEST_CONFIG", ")", "as", "(", "directory", ",", "object_store", ")", ":", "empty_dataset", "=", "MockDataset", "(", "1", ")", "directory", ".", "write", "(", "''", ",", ...
test that alt_name cannot be used to access arbitrary paths using a relative path .
train
false
41,536
def get_NSString(string): return CFSTR(string).autorelease()
[ "def", "get_NSString", "(", "string", ")", ":", "return", "CFSTR", "(", "string", ")", ".", "autorelease", "(", ")" ]
autoreleased version of cfstr .
train
false
41,538
def get_project_stats(project): return [{u'language': force_text(tup[0]), u'code': tup[0].code, u'total': tup[2], u'translated': tup[1], u'translated_percent': translation_percent(tup[1], tup[2]), u'total_words': tup[4], u'translated_words': tup[3], u'words_percent': translation_percent(tup[3], tup[4])} for tup in get...
[ "def", "get_project_stats", "(", "project", ")", ":", "return", "[", "{", "u'language'", ":", "force_text", "(", "tup", "[", "0", "]", ")", ",", "u'code'", ":", "tup", "[", "0", "]", ".", "code", ",", "u'total'", ":", "tup", "[", "2", "]", ",", "...
returns stats for project .
train
false
41,539
def import_files(lib, paths, query): for path in paths: if (not os.path.exists(syspath(normpath(path)))): raise ui.UserError(u'no such file or directory: {0}'.format(displayable_path(path))) if (config['import']['quiet'] and config['import']['timid']): raise ui.UserError(u"can't be both quiet and timid") if (...
[ "def", "import_files", "(", "lib", ",", "paths", ",", "query", ")", ":", "for", "path", "in", "paths", ":", "if", "(", "not", "os", ".", "path", ".", "exists", "(", "syspath", "(", "normpath", "(", "path", ")", ")", ")", ")", ":", "raise", "ui", ...
import the files in the given list of paths or matching the query .
train
false
41,540
@decorator def needs_sqlite(f, self, *a, **kw): if ((sqlite3 is None) or (not self.enabled)): return [] else: return f(self, *a, **kw)
[ "@", "decorator", "def", "needs_sqlite", "(", "f", ",", "self", ",", "*", "a", ",", "**", "kw", ")", ":", "if", "(", "(", "sqlite3", "is", "None", ")", "or", "(", "not", "self", ".", "enabled", ")", ")", ":", "return", "[", "]", "else", ":", ...
decorator: return an empty list in the absence of sqlite .
train
false
41,541
def month_by_name(name, lang=u'en'): month_names = MONTH_NAMES.get(lang, MONTH_NAMES[u'en']) try: return (month_names.index(name) + 1) except ValueError: return None
[ "def", "month_by_name", "(", "name", ",", "lang", "=", "u'en'", ")", ":", "month_names", "=", "MONTH_NAMES", ".", "get", "(", "lang", ",", "MONTH_NAMES", "[", "u'en'", "]", ")", "try", ":", "return", "(", "month_names", ".", "index", "(", "name", ")", ...
return the number of a month by english name .
train
false
41,543
def assert_equal_mod_whitespace(first, second, msg=None): nose.tools.assert_equal(compact_whitespace(first), compact_whitespace(second), msg)
[ "def", "assert_equal_mod_whitespace", "(", "first", ",", "second", ",", "msg", "=", "None", ")", ":", "nose", ".", "tools", ".", "assert_equal", "(", "compact_whitespace", "(", "first", ")", ",", "compact_whitespace", "(", "second", ")", ",", "msg", ")" ]
asserts that two strings are equal .
train
false
41,546
def get_site(): return (c.site.analytics_name if c.site else '')
[ "def", "get_site", "(", ")", ":", "return", "(", "c", ".", "site", ".", "analytics_name", "if", "c", ".", "site", "else", "''", ")" ]
return the name of the current "site" .
train
false
41,547
def get_minibatch(doc_iter, size, pos_class=positive_class): data = [(u'{title}\n\n{body}'.format(**doc), (pos_class in doc['topics'])) for doc in itertools.islice(doc_iter, size) if doc['topics']] if (not len(data)): return (np.asarray([], dtype=int), np.asarray([], dtype=int)) (X_text, y) = zip(*data) return (X...
[ "def", "get_minibatch", "(", "doc_iter", ",", "size", ",", "pos_class", "=", "positive_class", ")", ":", "data", "=", "[", "(", "u'{title}\\n\\n{body}'", ".", "format", "(", "**", "doc", ")", ",", "(", "pos_class", "in", "doc", "[", "'topics'", "]", ")",...
extract a minibatch of examples .
train
false
41,548
def getLatestVersionInfo(): try: page = urllib.request.urlopen(versionURL) except urllib.error.URLError: return (-1) latest = {} for line in page.readlines(): if (line.find(':') == (-1)): return (-1) (key, keyInfo) = line.split(':') latest[key] = keyInfo.replace('\n', '').replace('\r', '') return late...
[ "def", "getLatestVersionInfo", "(", ")", ":", "try", ":", "page", "=", "urllib", ".", "request", ".", "urlopen", "(", "versionURL", ")", "except", "urllib", ".", "error", ".", "URLError", ":", "return", "(", "-", "1", ")", "latest", "=", "{", "}", "f...
fetch info about the latest availiable version .
train
false
41,549
def make_event(): res = event() return (res, res.make_caller())
[ "def", "make_event", "(", ")", ":", "res", "=", "event", "(", ")", "return", "(", "res", ",", "res", ".", "make_caller", "(", ")", ")" ]
creates an event object tuple .
train
false
41,551
def validate_ok_for_replace(replacement): validate_is_mapping('replacement', replacement) if (replacement and (not isinstance(replacement, RawBSONDocument))): first = next(iter(replacement)) if first.startswith('$'): raise ValueError('replacement can not include $ operators')
[ "def", "validate_ok_for_replace", "(", "replacement", ")", ":", "validate_is_mapping", "(", "'replacement'", ",", "replacement", ")", "if", "(", "replacement", "and", "(", "not", "isinstance", "(", "replacement", ",", "RawBSONDocument", ")", ")", ")", ":", "firs...
validate a replacement document .
train
true
41,552
def versioned_bucket_lister(bucket, prefix='', delimiter='', marker='', generation_marker='', headers=None): more_results = True k = None while more_results: rs = bucket.get_all_versions(prefix=prefix, marker=marker, generation_marker=generation_marker, delimiter=delimiter, headers=headers, max_keys=999) for k i...
[ "def", "versioned_bucket_lister", "(", "bucket", ",", "prefix", "=", "''", ",", "delimiter", "=", "''", ",", "marker", "=", "''", ",", "generation_marker", "=", "''", ",", "headers", "=", "None", ")", ":", "more_results", "=", "True", "k", "=", "None", ...
a generator function for listing versioned objects .
train
false
41,553
def get_redirect(): return_to = request.params.get('return_to') hash_given = request.params.get('hash', '') if (not (return_to and hash_given)): return None hash_expected = get_message_hash(return_to) if (hash_given == hash_expected): return return_to.encode('utf-8') return None
[ "def", "get_redirect", "(", ")", ":", "return_to", "=", "request", ".", "params", ".", "get", "(", "'return_to'", ")", "hash_given", "=", "request", ".", "params", ".", "get", "(", "'hash'", ",", "''", ")", "if", "(", "not", "(", "return_to", "and", ...
checks the return_to value against the hash .
train
false
41,554
def _read_overrides(overrides_file): if (not overrides_file): return {} overrides_lines = [line for line in overrides_file.readlines() if (not line.startswith('#'))] overrides_pairs = zip(overrides_lines[0::3], overrides_lines[1::3]) _assert_is_all_blank_lines(overrides_lines[2::3], overrides_file) return dict(o...
[ "def", "_read_overrides", "(", "overrides_file", ")", ":", "if", "(", "not", "overrides_file", ")", ":", "return", "{", "}", "overrides_lines", "=", "[", "line", "for", "line", "in", "overrides_file", ".", "readlines", "(", ")", "if", "(", "not", "line", ...
read pattern overrides from overrides_file .
train
false
41,556
def is_possible_number(numobj): return (is_possible_number_with_reason(numobj) == ValidationResult.IS_POSSIBLE)
[ "def", "is_possible_number", "(", "numobj", ")", ":", "return", "(", "is_possible_number_with_reason", "(", "numobj", ")", "==", "ValidationResult", ".", "IS_POSSIBLE", ")" ]
convenience wrapper around is_possible_number_with_reason .
train
false
41,557
def push_status_message(message, kind='warning', dismissible=True, trust=True, jumbotron=False): try: statuses = session.data.get('status') except RuntimeError as e: exception_message = getattr(e, 'message', None) if (exception_message == 'working outside of request context'): if (kind == 'error'): from ...
[ "def", "push_status_message", "(", "message", ",", "kind", "=", "'warning'", ",", "dismissible", "=", "True", ",", "trust", "=", "True", ",", "jumbotron", "=", "False", ")", ":", "try", ":", "statuses", "=", "session", ".", "data", ".", "get", "(", "'s...
push a status message that will be displayed as a banner on the next page loaded by the user .
train
false
41,559
def migRing(populations, k, selection, replacement=None, migarray=None): nbr_demes = len(populations) if (migarray is None): migarray = (range(1, nbr_demes) + [0]) immigrants = [[] for i in xrange(nbr_demes)] emigrants = [[] for i in xrange(nbr_demes)] for from_deme in xrange(nbr_demes): emigrants[from_deme].e...
[ "def", "migRing", "(", "populations", ",", "k", ",", "selection", ",", "replacement", "=", "None", ",", "migarray", "=", "None", ")", ":", "nbr_demes", "=", "len", "(", "populations", ")", "if", "(", "migarray", "is", "None", ")", ":", "migarray", "=",...
perform a ring migration between the *populations* .
train
false
41,560
def denoise_tv_chambolle(im, weight=0.1, eps=0.0002, n_iter_max=200, multichannel=False): im_type = im.dtype if (not (im_type.kind == 'f')): im = img_as_float(im) if multichannel: out = np.zeros_like(im) for c in range(im.shape[(-1)]): out[..., c] = _denoise_tv_chambolle_nd(im[..., c], weight, eps, n_iter_m...
[ "def", "denoise_tv_chambolle", "(", "im", ",", "weight", "=", "0.1", ",", "eps", "=", "0.0002", ",", "n_iter_max", "=", "200", ",", "multichannel", "=", "False", ")", ":", "im_type", "=", "im", ".", "dtype", "if", "(", "not", "(", "im_type", ".", "ki...
perform total-variation denoising on n-dimensional images .
train
false
41,561
def _get_featurestate(name): featurestate = _featurestate_cache.get(name, None) if (featurestate is None): featurestate = FeatureState(name, _world) _featurestate_cache[name] = featurestate return featurestate
[ "def", "_get_featurestate", "(", "name", ")", ":", "featurestate", "=", "_featurestate_cache", ".", "get", "(", "name", ",", "None", ")", "if", "(", "featurestate", "is", "None", ")", ":", "featurestate", "=", "FeatureState", "(", "name", ",", "_world", ")...
get a featurestate object for this feature .
train
false
41,562
def sorted_proposals(proposals, scopepref=None, typepref=None): sorter = _ProposalSorter(proposals, scopepref, typepref) return sorter.get_sorted_proposal_list()
[ "def", "sorted_proposals", "(", "proposals", ",", "scopepref", "=", "None", ",", "typepref", "=", "None", ")", ":", "sorter", "=", "_ProposalSorter", "(", "proposals", ",", "scopepref", ",", "typepref", ")", "return", "sorter", ".", "get_sorted_proposal_list", ...
sort a list of proposals return a sorted list of the given codeassistproposals .
train
true
41,563
def displayhosts(recordsgen, out=sys.stdout, **kargs): for record in recordsgen: displayhost(record, out=out, **kargs) if os.isatty(out.fileno()): raw_input() else: out.write('\n')
[ "def", "displayhosts", "(", "recordsgen", ",", "out", "=", "sys", ".", "stdout", ",", "**", "kargs", ")", ":", "for", "record", "in", "recordsgen", ":", "displayhost", "(", "record", ",", "out", "=", "out", ",", "**", "kargs", ")", "if", "os", ".", ...
displays the nmap scan results generated by recordsgen .
train
false
41,564
def _extract_possible_number(number): match = _VALID_START_CHAR_PATTERN.search(number) if match: number = number[match.start():] trailing_chars_match = _UNWANTED_END_CHAR_PATTERN.search(number) if trailing_chars_match: number = number[:trailing_chars_match.start()] second_number_match = _SECOND_NUMBER_STAR...
[ "def", "_extract_possible_number", "(", "number", ")", ":", "match", "=", "_VALID_START_CHAR_PATTERN", ".", "search", "(", "number", ")", "if", "match", ":", "number", "=", "number", "[", "match", ".", "start", "(", ")", ":", "]", "trailing_chars_match", "="...
attempt to extract a possible number from the string passed in .
train
true
41,566
def set_user_agent(http, user_agent): request_orig = http.request def new_request(uri, method='GET', body=None, headers=None, redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None): 'Modify the request headers to add the user-agent.' if (headers is None): headers = {} if ('user-agent' in headers)...
[ "def", "set_user_agent", "(", "http", ",", "user_agent", ")", ":", "request_orig", "=", "http", ".", "request", "def", "new_request", "(", "uri", ",", "method", "=", "'GET'", ",", "body", "=", "None", ",", "headers", "=", "None", ",", "redirections", "="...
set the user-agent on every request .
train
false
41,567
def select_url_from_video_api(html): c = json.loads(html) video_dic = {} for i in c['mp4']: video_dic[i['code']] = i['http'] quality_preference_list = ['sdvd', 'hd', 'dvd', 'sd'] url = [video_dic[quality] for quality in quality_preference_list if (quality in video_dic)][0] html = get_html(url) c = json.loads(h...
[ "def", "select_url_from_video_api", "(", "html", ")", ":", "c", "=", "json", ".", "loads", "(", "html", ")", "video_dic", "=", "{", "}", "for", "i", "in", "c", "[", "'mp4'", "]", ":", "video_dic", "[", "i", "[", "'code'", "]", "]", "=", "i", "[",...
str->str choose the best one .
train
false
41,568
def retry_all_jobs(): history_db = sabnzbd.connect_db() return NzbQueue.do.retry_all_jobs(history_db)
[ "def", "retry_all_jobs", "(", ")", ":", "history_db", "=", "sabnzbd", ".", "connect_db", "(", ")", "return", "NzbQueue", ".", "do", ".", "retry_all_jobs", "(", "history_db", ")" ]
re enter all failed jobs in the download queue .
train
false
41,569
def listfy(data): if isinstance(data, basestring): data = data.split(',') elif (not isinstance(data, list)): data = [data] return data
[ "def", "listfy", "(", "data", ")", ":", "if", "isinstance", "(", "data", ",", "basestring", ")", ":", "data", "=", "data", ".", "split", "(", "','", ")", "elif", "(", "not", "isinstance", "(", "data", ",", "list", ")", ")", ":", "data", "=", "[",...
check and convert data to list .
train
false
41,570
def Opt(re): result = Alt(re, Empty) result.str = ('Opt(%s)' % re) return result
[ "def", "Opt", "(", "re", ")", ":", "result", "=", "Alt", "(", "re", ",", "Empty", ")", "result", ".", "str", "=", "(", "'Opt(%s)'", "%", "re", ")", "return", "result" ]
opt is an re which matches either |re| or the empty string .
train
false
41,571
def _valid_str(value): return (isinstance(value, six.string_types) and (len(value) > 0))
[ "def", "_valid_str", "(", "value", ")", ":", "return", "(", "isinstance", "(", "value", ",", "six", ".", "string_types", ")", "and", "(", "len", "(", "value", ")", ">", "0", ")", ")" ]
valid str? .
train
false
41,572
def _parse_build(encoded_data, pointer=0, spec=None, spec_params=None): (info, new_pointer) = _parse(encoded_data, len(encoded_data), pointer) return (_build(spec=spec, spec_params=spec_params, *info), new_pointer)
[ "def", "_parse_build", "(", "encoded_data", ",", "pointer", "=", "0", ",", "spec", "=", "None", ",", "spec_params", "=", "None", ")", ":", "(", "info", ",", "new_pointer", ")", "=", "_parse", "(", "encoded_data", ",", "len", "(", "encoded_data", ")", "...
parses a byte string generically .
train
false
41,573
def select_node(nodes): if nodes: return random.choice(nodes) else: raise EmptyClusterError('Cluster contains no nodes.')
[ "def", "select_node", "(", "nodes", ")", ":", "if", "nodes", ":", "return", "random", ".", "choice", "(", "nodes", ")", "else", ":", "raise", "EmptyClusterError", "(", "'Cluster contains no nodes.'", ")" ]
select a node from a list of nodes .
train
false
41,574
def pportInPaperOut(): if (port.DlPortReadPortUchar(statusRegAdrs) & 32): return 1 else: return 0
[ "def", "pportInPaperOut", "(", ")", ":", "if", "(", "port", ".", "DlPortReadPortUchar", "(", "statusRegAdrs", ")", "&", "32", ")", ":", "return", "1", "else", ":", "return", "0" ]
input from paper out pin .
train
false
41,575
def set_startup_disk(path): if (path not in list_startup_disks()): msg = 'Invalid value passed for path.\nMust be a valid startup disk as found in system.list_startup_disks.\nPassed: {0}'.format(path) raise SaltInvocationError(msg) cmd = 'systemsetup -setstartupdisk {0}'.format(path) salt.utils.mac_utils.execute...
[ "def", "set_startup_disk", "(", "path", ")", ":", "if", "(", "path", "not", "in", "list_startup_disks", "(", ")", ")", ":", "msg", "=", "'Invalid value passed for path.\\nMust be a valid startup disk as found in system.list_startup_disks.\\nPassed: {0}'", ".", "format", "("...
set the current startup disk to the indicated path .
train
false
41,577
def get_texpath(): def _get_texpath(): try: texpath = get_setting(sublime.platform(), {}).get('texpath') except AttributeError: exc_info = sys.exc_info try: reload(sys.modules[get_texpath.__module__]) texpath = get_setting(sublime.platform(), {}).get('texpath') except: reraise(*exc_info) ...
[ "def", "get_texpath", "(", ")", ":", "def", "_get_texpath", "(", ")", ":", "try", ":", "texpath", "=", "get_setting", "(", "sublime", ".", "platform", "(", ")", ",", "{", "}", ")", ".", "get", "(", "'texpath'", ")", "except", "AttributeError", ":", "...
returns the texpath setting with any environment variables expanded .
train
false
41,580
@receiver(post_save, sender=CourseCreator) def post_save_callback(sender, **kwargs): instance = kwargs['instance'] if (instance.state != instance.orig_state): granted_state_change = ((instance.state == CourseCreator.GRANTED) or (instance.orig_state == CourseCreator.GRANTED)) if granted_state_change: assert has...
[ "@", "receiver", "(", "post_save", ",", "sender", "=", "CourseCreator", ")", "def", "post_save_callback", "(", "sender", ",", "**", "kwargs", ")", ":", "instance", "=", "kwargs", "[", "'instance'", "]", "if", "(", "instance", ".", "state", "!=", "instance"...
event changes to user preferences .
train
false