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
51,716
def RemoveNativelySupportedComponents(filters, orders, exists): (filters, orders) = Normalize(filters, orders, exists) for f in filters: if (f.op() in EXISTS_OPERATORS): return (filters, orders) has_key_desc_order = False if (orders and (orders[(-1)].property() == datastore_types.KEY_SPECIAL_PROPERTY)): if (...
[ "def", "RemoveNativelySupportedComponents", "(", "filters", ",", "orders", ",", "exists", ")", ":", "(", "filters", ",", "orders", ")", "=", "Normalize", "(", "filters", ",", "orders", ",", "exists", ")", "for", "f", "in", "filters", ":", "if", "(", "f",...
removes query components that are natively supported by the datastore .
train
false
51,718
def test_no_truncate_crval_p17(): w = wcs.WCS(naxis=2) w.wcs.crval = [50.123456789012344, 50.123456789012344] w.wcs.cdelt = [0.001, 0.001] w.wcs.ctype = [u'RA---TAN', u'DEC--TAN'] w.wcs.set() header = w.to_header() assert (header[u'CRVAL1'] != w.wcs.crval[0]) assert (header[u'CRVAL2'] != w.wcs.crval[1]) header...
[ "def", "test_no_truncate_crval_p17", "(", ")", ":", "w", "=", "wcs", ".", "WCS", "(", "naxis", "=", "2", ")", "w", ".", "wcs", ".", "crval", "=", "[", "50.123456789012344", ",", "50.123456789012344", "]", "w", ".", "wcs", ".", "cdelt", "=", "[", "0.0...
regression test for URL .
train
false
51,719
def registry(database_name=None): if (database_name is None): import threading database_name = threading.currentThread().dbname return modules.registry.Registry(database_name)
[ "def", "registry", "(", "database_name", "=", "None", ")", ":", "if", "(", "database_name", "is", "None", ")", ":", "import", "threading", "database_name", "=", "threading", ".", "currentThread", "(", ")", ".", "dbname", "return", "modules", ".", "registry",...
return the model registry for the given database .
train
false
51,722
def _parse_modes(mode_string, unary_modes=''): if ((not mode_string) or (not (mode_string[0] in '+-'))): return [] modes = [] parts = mode_string.split() (mode_part, args) = (parts[0], parts[1:]) for ch in mode_part: if (ch in '+-'): sign = ch continue arg = (args.pop(0) if ((ch in unary_modes) and arg...
[ "def", "_parse_modes", "(", "mode_string", ",", "unary_modes", "=", "''", ")", ":", "if", "(", "(", "not", "mode_string", ")", "or", "(", "not", "(", "mode_string", "[", "0", "]", "in", "'+-'", ")", ")", ")", ":", "return", "[", "]", "modes", "=", ...
parse the mode_string and return a list of triples .
train
true
51,724
def assure_volume(fnc): @wraps(fnc) def _wrapped(self, volume, *args, **kwargs): if (not isinstance(volume, CloudBlockStorageVolume)): volume = self._manager.get(volume) return fnc(self, volume, *args, **kwargs) return _wrapped
[ "def", "assure_volume", "(", "fnc", ")", ":", "@", "wraps", "(", "fnc", ")", "def", "_wrapped", "(", "self", ",", "volume", ",", "*", "args", ",", "**", "kwargs", ")", ":", "if", "(", "not", "isinstance", "(", "volume", ",", "CloudBlockStorageVolume", ...
converts a volumeid passed as the volume to a cloudblockstoragevolume object .
train
true
51,725
def _find_credentials(host): user_names = [__pillar__['proxy'].get('username', 'root')] passwords = __pillar__['proxy']['passwords'] for user in user_names: for password in passwords: try: ret = salt.modules.vsphere.system_info(host=host, username=user, password=password) except SaltSystemExit: conti...
[ "def", "_find_credentials", "(", "host", ")", ":", "user_names", "=", "[", "__pillar__", "[", "'proxy'", "]", ".", "get", "(", "'username'", ",", "'root'", ")", "]", "passwords", "=", "__pillar__", "[", "'proxy'", "]", "[", "'passwords'", "]", "for", "us...
cycle through all the possible credentials and return the first one that works .
train
true
51,726
def polarity(s, **kwargs): return sentiment(s, **kwargs)[0]
[ "def", "polarity", "(", "s", ",", "**", "kwargs", ")", ":", "return", "sentiment", "(", "s", ",", "**", "kwargs", ")", "[", "0", "]" ]
returns the sentence polarity between -1 .
train
false
51,729
def zero_crossings(data): zx = np.zeros(len(data)) zx[np.where(((data[:(-1)] * data[1:]) < 0))] = 1 return zx
[ "def", "zero_crossings", "(", "data", ")", ":", "zx", "=", "np", ".", "zeros", "(", "len", "(", "data", ")", ")", "zx", "[", "np", ".", "where", "(", "(", "(", "data", "[", ":", "(", "-", "1", ")", "]", "*", "data", "[", "1", ":", "]", ")...
return a vector of length n-1 of zero-crossings within vector data .
train
false
51,730
def enum_cfg_repos(config): repositories = util.getRepositoryDir(config) for section in config.sections(): l = section.split(None, 1) type_ = l.pop(0) if (type_ != 'repo'): continue if (not l): continue (name,) = l if (not os.path.exists(os.path.join(repositories, name))): subpath = ('%s.git' % n...
[ "def", "enum_cfg_repos", "(", "config", ")", ":", "repositories", "=", "util", ".", "getRepositoryDir", "(", "config", ")", "for", "section", "in", "config", ".", "sections", "(", ")", ":", "l", "=", "section", ".", "split", "(", "None", ",", "1", ")",...
enumerates all repositories that have repo sections in the config .
train
false
51,731
def dnsdomain_list(context): return IMPL.dnsdomain_list(context)
[ "def", "dnsdomain_list", "(", "context", ")", ":", "return", "IMPL", ".", "dnsdomain_list", "(", "context", ")" ]
get a list of all zones in our database .
train
false
51,734
def test_finder_priority_file_over_page(data): req = InstallRequirement.from_line('gmpy==1.15', None) finder = PackageFinder([data.find_links], ['http://pypi.python.org/simple'], session=PipSession()) all_versions = finder.find_all_candidates(req.name) assert (all_versions[0].location.scheme == 'file') assert all(...
[ "def", "test_finder_priority_file_over_page", "(", "data", ")", ":", "req", "=", "InstallRequirement", ".", "from_line", "(", "'gmpy==1.15'", ",", "None", ")", "finder", "=", "PackageFinder", "(", "[", "data", ".", "find_links", "]", ",", "[", "'http://pypi.pyth...
test packagefinder prefers file links over equivalent page links .
train
false
51,736
def infer_subscript(self, context=None): value = next(self.value.infer(context)) if (value is YES): (yield YES) return index = next(self.slice.infer(context)) if (index is YES): (yield YES) return if isinstance(index, nodes.Const): try: assigned = value.getitem(index.value, context) except Attribute...
[ "def", "infer_subscript", "(", "self", ",", "context", "=", "None", ")", ":", "value", "=", "next", "(", "self", ".", "value", ".", "infer", "(", "context", ")", ")", "if", "(", "value", "is", "YES", ")", ":", "(", "yield", "YES", ")", "return", ...
infer simple subscription such as [1 .
train
false
51,737
def test_suite(): return DocTestSuite()
[ "def", "test_suite", "(", ")", ":", "return", "DocTestSuite", "(", ")" ]
for the z3 test runner .
train
false
51,738
def values_eq_approx_high_tol(a, b): assert (a.ndim == 4) atol = None if ((a.shape[(-1)] * a.shape[(-2)]) > 100): atol = 3e-05 return CudaNdarrayType.values_eq_approx(a, b, atol=atol)
[ "def", "values_eq_approx_high_tol", "(", "a", ",", "b", ")", ":", "assert", "(", "a", ".", "ndim", "==", "4", ")", "atol", "=", "None", "if", "(", "(", "a", ".", "shape", "[", "(", "-", "1", ")", "]", "*", "a", ".", "shape", "[", "(", "-", ...
this fct is needed to dont have debugmode raise useless error due to ronding error .
train
false
51,740
def get_network(context, net_id, fields=None): session = context.session return session.query(BrocadeNetwork).filter_by(id=net_id).first()
[ "def", "get_network", "(", "context", ",", "net_id", ",", "fields", "=", "None", ")", ":", "session", "=", "context", ".", "session", "return", "session", ".", "query", "(", "BrocadeNetwork", ")", ".", "filter_by", "(", "id", "=", "net_id", ")", ".", "...
get brocade specific network .
train
false
51,742
def maybe_drop_privileges(uid=None, gid=None): if (sys.platform == u'win32'): return if os.geteuid(): if (not os.getuid()): raise SecurityError(u'contact support') uid = (uid and parse_uid(uid)) gid = (gid and parse_gid(gid)) if uid: _setuid(uid, gid) else: (gid and setgid(gid)) if (uid and (not os.ge...
[ "def", "maybe_drop_privileges", "(", "uid", "=", "None", ",", "gid", "=", "None", ")", ":", "if", "(", "sys", ".", "platform", "==", "u'win32'", ")", ":", "return", "if", "os", ".", "geteuid", "(", ")", ":", "if", "(", "not", "os", ".", "getuid", ...
change process privileges to new user/group .
train
false
51,743
def test_adapthist_alpha(): img = skimage.img_as_float(data.astronaut()) alpha = np.ones((img.shape[0], img.shape[1]), dtype=float) img = np.dstack((img, alpha)) with expected_warnings(['precision loss']): adapted = exposure.equalize_adapthist(img) assert (adapted.shape != img.shape) img = img[:, :, :3] full_s...
[ "def", "test_adapthist_alpha", "(", ")", ":", "img", "=", "skimage", ".", "img_as_float", "(", "data", ".", "astronaut", "(", ")", ")", "alpha", "=", "np", ".", "ones", "(", "(", "img", ".", "shape", "[", "0", "]", ",", "img", ".", "shape", "[", ...
test an rgba color image .
train
false
51,744
def _encode_emr_api_params(x): if isinstance(x, dict): result = {} for (key, value) in x.items(): if ((key == 'Properties') and isinstance(value, dict)): value = [{'Key': k, 'Value': v} for (k, v) in sorted(value.items())] unpacked_value = _encode_emr_api_params(value) if isinstance(unpacked_value, di...
[ "def", "_encode_emr_api_params", "(", "x", ")", ":", "if", "isinstance", "(", "x", ",", "dict", ")", ":", "result", "=", "{", "}", "for", "(", "key", ",", "value", ")", "in", "x", ".", "items", "(", ")", ":", "if", "(", "(", "key", "==", "'Prop...
recursively unpack parameters to the emr api .
train
false
51,748
@gen.engine def ListAllCommonPrefixes(store, delimiter, callback, prefix=None, marker=None): prefixes = set() keys = [] while True: (new_prefixes, new_keys) = (yield gen.Task(store.ListCommonPrefixes, delimiter, prefix=prefix, marker=marker, maxkeys=1000)) prefixes = prefixes.union(set(new_prefixes)) keys.exte...
[ "@", "gen", ".", "engine", "def", "ListAllCommonPrefixes", "(", "store", ",", "delimiter", ",", "callback", ",", "prefix", "=", "None", ",", "marker", "=", "None", ")", ":", "prefixes", "=", "set", "(", ")", "keys", "=", "[", "]", "while", "True", ":...
list all common prefixes .
train
false
51,749
def __get_request_cpu_usage(): warnings.warn('get_request_cpu_usage may not always return correct values', DeprecationWarning, stacklevel=2) if apiproxy: return apiproxy.GetRequestCpuUsage() return 0
[ "def", "__get_request_cpu_usage", "(", ")", ":", "warnings", ".", "warn", "(", "'get_request_cpu_usage may not always return correct values'", ",", "DeprecationWarning", ",", "stacklevel", "=", "2", ")", "if", "apiproxy", ":", "return", "apiproxy", ".", "GetRequestCpuUs...
get the amount of cpu used so far for the current request .
train
false
51,750
def _natsort_key(item, case_sensitivity=False): item = str(item) try: chunks = re.split('(\\d+(?:\\.\\d+)?)', item) except TypeError: chunks = re.split('(\\d+(?:\\.\\d+)?)', item[0]) for ii in range(len(chunks)): if (chunks[ii] and (chunks[ii][0] in '0123456789')): if ('.' in chunks[ii]): numtype = flo...
[ "def", "_natsort_key", "(", "item", ",", "case_sensitivity", "=", "False", ")", ":", "item", "=", "str", "(", "item", ")", "try", ":", "chunks", "=", "re", ".", "split", "(", "'(\\\\d+(?:\\\\.\\\\d+)?)'", ",", "item", ")", "except", "TypeError", ":", "ch...
provides normalized version of item for sorting with digits .
train
false
51,751
def check_output_inside_dir(command, dirpath): with inside_dir(dirpath): return subprocess.check_output(shlex.split(command))
[ "def", "check_output_inside_dir", "(", "command", ",", "dirpath", ")", ":", "with", "inside_dir", "(", "dirpath", ")", ":", "return", "subprocess", ".", "check_output", "(", "shlex", ".", "split", "(", "command", ")", ")" ]
run a command from inside a given directory .
train
false
51,752
def rolling_window(array, length): orig_shape = array.shape if (not orig_shape): raise IndexError("Can't restride a scalar.") elif (orig_shape[0] <= length): raise IndexError("Can't restride array of shape {shape} with a window length of {len}".format(shape=orig_shape, len=length)) num_windows = ((orig_shape[0]...
[ "def", "rolling_window", "(", "array", ",", "length", ")", ":", "orig_shape", "=", "array", ".", "shape", "if", "(", "not", "orig_shape", ")", ":", "raise", "IndexError", "(", "\"Can't restride a scalar.\"", ")", "elif", "(", "orig_shape", "[", "0", "]", "...
restride an array of shape into an array of shape where each slice at index i along the first axis is equivalent to result[i] = array[length * i:length * ] parameters array : np .
train
true
51,754
def test_apiview_invalid_method(rf): view = UserAPIView.as_view() request = create_api_request(rf, 'post') response = view(request) assert (response.status_code == 405) request = create_api_request(rf, 'patch') response = view(request) assert (response.status_code == 405)
[ "def", "test_apiview_invalid_method", "(", "rf", ")", ":", "view", "=", "UserAPIView", ".", "as_view", "(", ")", "request", "=", "create_api_request", "(", "rf", ",", "'post'", ")", "response", "=", "view", "(", "request", ")", "assert", "(", "response", "...
tests for invalid methods .
train
false
51,755
def max_drawdown(networth): hwm = [0] eq_idx = networth.index drawdown = pd.Series(index=eq_idx) duration = pd.Series(index=eq_idx) for t in range(1, len(eq_idx)): cur_hwm = max(hwm[(t - 1)], networth[t]) hwm.append(cur_hwm) drawdown[t] = (hwm[t] - networth[t]) duration[t] = (0 if (drawdown[t] <= 0) else (...
[ "def", "max_drawdown", "(", "networth", ")", ":", "hwm", "=", "[", "0", "]", "eq_idx", "=", "networth", ".", "index", "drawdown", "=", "pd", ".", "Series", "(", "index", "=", "eq_idx", ")", "duration", "=", "pd", ".", "Series", "(", "index", "=", "...
networth: 历史净值 .
train
false
51,756
@require_POST @login_required @permitted def follow_commentable(request, course_id, commentable_id): user = cc.User.from_django_user(request.user) commentable = cc.Commentable.find(commentable_id) user.follow(commentable) return JsonResponse({})
[ "@", "require_POST", "@", "login_required", "@", "permitted", "def", "follow_commentable", "(", "request", ",", "course_id", ",", "commentable_id", ")", ":", "user", "=", "cc", ".", "User", ".", "from_django_user", "(", "request", ".", "user", ")", "commentabl...
given a course_id and commentable id .
train
false
51,757
@ship.command('move') @click.argument('ship') @click.argument('x', type=float) @click.argument('y', type=float) @click.option('--speed', metavar='KN', default=10, help='Speed in knots.') def ship_move(ship, x, y, speed): click.echo(('Moving ship %s to %s,%s with speed %s' % (ship, x, y, speed)))
[ "@", "ship", ".", "command", "(", "'move'", ")", "@", "click", ".", "argument", "(", "'ship'", ")", "@", "click", ".", "argument", "(", "'x'", ",", "type", "=", "float", ")", "@", "click", ".", "argument", "(", "'y'", ",", "type", "=", "float", "...
moves ship to the new location x .
train
false
51,758
def preDeployFile(file): pass
[ "def", "preDeployFile", "(", "file", ")", ":", "pass" ]
called prior to deploying a single built file .
train
false
51,759
def detect_console_encoding(): import locale global _initial_defencoding encoding = None try: encoding = (sys.stdout.encoding or sys.stdin.encoding) except AttributeError: pass if ((not encoding) or ('ascii' in encoding.lower())): try: encoding = locale.getpreferredencoding() except Exception: pass ...
[ "def", "detect_console_encoding", "(", ")", ":", "import", "locale", "global", "_initial_defencoding", "encoding", "=", "None", "try", ":", "encoding", "=", "(", "sys", ".", "stdout", ".", "encoding", "or", "sys", ".", "stdin", ".", "encoding", ")", "except"...
try to find the most capable encoding supported by the console .
train
true
51,761
def get_order_dir(field, default='ASC'): dirn = ORDER_DIR[default] if (field[0] == '-'): return (field[1:], dirn[1]) return (field, dirn[0])
[ "def", "get_order_dir", "(", "field", ",", "default", "=", "'ASC'", ")", ":", "dirn", "=", "ORDER_DIR", "[", "default", "]", "if", "(", "field", "[", "0", "]", "==", "'-'", ")", ":", "return", "(", "field", "[", "1", ":", "]", ",", "dirn", "[", ...
returns the field name and direction for an order specification .
train
false
51,762
def make_bar_data(asset_info, calendar): assert (PSEUDO_EPOCH.value < calendar.normalize().min().value <= asset_info['start_date'].min().value), ("calendar.min(): %s\nasset_info['start_date'].min(): %s" % (calendar.min(), asset_info['start_date'].min())) assert (asset_info['start_date'] < asset_info['end_date']).all(...
[ "def", "make_bar_data", "(", "asset_info", ",", "calendar", ")", ":", "assert", "(", "PSEUDO_EPOCH", ".", "value", "<", "calendar", ".", "normalize", "(", ")", ".", "min", "(", ")", ".", "value", "<=", "asset_info", "[", "'start_date'", "]", ".", "min", ...
for a given asset/date/column combination .
train
true
51,763
def test_rus_sk_estimator(): check_estimator(RandomUnderSampler)
[ "def", "test_rus_sk_estimator", "(", ")", ":", "check_estimator", "(", "RandomUnderSampler", ")" ]
test the sklearn estimator compatibility .
train
false
51,764
def update(context, id, name, description, is_public=None): if (id is None): msg = _('id cannot be None') raise exception.InvalidGroupType(reason=msg) elevated = (context if context.is_admin else context.elevated()) try: type_updated = db.group_type_update(elevated, id, dict(name=name, description=description,...
[ "def", "update", "(", "context", ",", "id", ",", "name", ",", "description", ",", "is_public", "=", "None", ")", ":", "if", "(", "id", "is", "None", ")", ":", "msg", "=", "_", "(", "'id cannot be None'", ")", "raise", "exception", ".", "InvalidGroupTyp...
update a key with a value in the minion datastore cli example: .
train
false
51,765
def init_gpg(): gpg = gnupg.GPG(homedir=config.GPG_KEY_DIR) for keyfile in ('test_journalist_key.pub', 'test_journalist_key.sec'): gpg.import_keys(open(keyfile).read()) return gpg
[ "def", "init_gpg", "(", ")", ":", "gpg", "=", "gnupg", ".", "GPG", "(", "homedir", "=", "config", ".", "GPG_KEY_DIR", ")", "for", "keyfile", "in", "(", "'test_journalist_key.pub'", ",", "'test_journalist_key.sec'", ")", ":", "gpg", ".", "import_keys", "(", ...
initialize the gpg keyring and import the journalist key for testing .
train
false
51,767
def get_deps(dsk): dependencies = {k: get_dependencies(dsk, task=v) for (k, v) in dsk.items()} dependents = reverse_dict(dependencies) return (dependencies, dependents)
[ "def", "get_deps", "(", "dsk", ")", ":", "dependencies", "=", "{", "k", ":", "get_dependencies", "(", "dsk", ",", "task", "=", "v", ")", "for", "(", "k", ",", "v", ")", "in", "dsk", ".", "items", "(", ")", "}", "dependents", "=", "reverse_dict", ...
get dependencies and dependents from dask dask graph .
train
false
51,769
def ComputeSplitPenalties(tree): _TreePenaltyAssigner().Visit(tree)
[ "def", "ComputeSplitPenalties", "(", "tree", ")", ":", "_TreePenaltyAssigner", "(", ")", ".", "Visit", "(", "tree", ")" ]
compute split penalties on tokens in the given parse tree .
train
false
51,770
def _read_dicts(fn_list, keyatom): dict_list = [] datalabel_list = [] for fn in fn_list: peaklist = Peaklist(fn) dict = peaklist.residue_dict(keyatom) dict_list.append(dict) datalabel_list.append(peaklist.datalabels) return [dict_list, datalabel_list]
[ "def", "_read_dicts", "(", "fn_list", ",", "keyatom", ")", ":", "dict_list", "=", "[", "]", "datalabel_list", "=", "[", "]", "for", "fn", "in", "fn_list", ":", "peaklist", "=", "Peaklist", "(", "fn", ")", "dict", "=", "peaklist", ".", "residue_dict", "...
read multiple files into a list of residue dictionaries .
train
false
51,771
def fresnels_zeros(nt): if ((floor(nt) != nt) or (nt <= 0) or (not isscalar(nt))): raise ValueError('Argument must be positive scalar integer.') return specfun.fcszo(2, nt)
[ "def", "fresnels_zeros", "(", "nt", ")", ":", "if", "(", "(", "floor", "(", "nt", ")", "!=", "nt", ")", "or", "(", "nt", "<=", "0", ")", "or", "(", "not", "isscalar", "(", "nt", ")", ")", ")", ":", "raise", "ValueError", "(", "'Argument must be p...
compute nt complex zeros of sine fresnel integral s(z) .
train
false
51,772
def consolidate_metadata(info_mi, info): try: raw = info[u'xmp_metadata'].rstrip() if (not raw): return info_mi xmp_mi = metadata_from_xmp_packet(raw) except Exception: import traceback traceback.print_exc() return info_mi (info_title, info_authors, info_tags) = ((info_mi.title or _(u'Unknown')), list...
[ "def", "consolidate_metadata", "(", "info_mi", ",", "info", ")", ":", "try", ":", "raw", "=", "info", "[", "u'xmp_metadata'", "]", ".", "rstrip", "(", ")", "if", "(", "not", "raw", ")", ":", "return", "info_mi", "xmp_mi", "=", "metadata_from_xmp_packet", ...
when both the pdf info dict and xmp metadata are present .
train
false
51,774
def test_step_schedule(backend_default): step_config = [1, 4, 5] change = [0.1, 0.3, 0.4] sch = StepSchedule(step_config=step_config, change=change) target_lr = [1.0, 0.1, 0.1, 0.1, 0.3, 0.4, 0.4, 0.4, 0.4] for (e, lr) in enumerate(target_lr): assert np.allclose(lr, sch.get_learning_rate(learning_rate=1.0, epoch...
[ "def", "test_step_schedule", "(", "backend_default", ")", ":", "step_config", "=", "[", "1", ",", "4", ",", "5", "]", "change", "=", "[", "0.1", ",", "0.3", ",", "0.4", "]", "sch", "=", "StepSchedule", "(", "step_config", "=", "step_config", ",", "chan...
test the stepschedule class .
train
false
51,775
def _queue_management_worker(executor_reference, processes, pending_work_items, work_ids_queue, call_queue, result_queue): executor = None def shutting_down(): return (_shutdown or (executor is None) or executor._shutdown_thread) def shutdown_worker(): nb_children_alive = sum((p.is_alive() for p in processes.val...
[ "def", "_queue_management_worker", "(", "executor_reference", ",", "processes", ",", "pending_work_items", ",", "work_ids_queue", ",", "call_queue", ",", "result_queue", ")", ":", "executor", "=", "None", "def", "shutting_down", "(", ")", ":", "return", "(", "_shu...
manages the communication between this process and the worker processes .
train
false
51,776
def get_build_version(): prefix = 'MSC v.' i = string.find(sys.version, prefix) if (i == (-1)): return 6 i = (i + len(prefix)) (s, rest) = sys.version[i:].split(' ', 1) majorVersion = (int(s[:(-2)]) - 6) minorVersion = (int(s[2:3]) / 10.0) if (majorVersion == 6): minorVersion = 0 if (majorVersion >= 6): ...
[ "def", "get_build_version", "(", ")", ":", "prefix", "=", "'MSC v.'", "i", "=", "string", ".", "find", "(", "sys", ".", "version", ",", "prefix", ")", "if", "(", "i", "==", "(", "-", "1", ")", ")", ":", "return", "6", "i", "=", "(", "i", "+", ...
return the version of msvc that was used to build python .
train
false
51,777
def upgrade_center(): try: current = pkg_resources.get_distribution('rainbowstream').version url = 'https://raw.githubusercontent.com/DTVD/rainbowstream/master/setup.py' readme = requests.get(url).text latest = readme.split("version = '")[1].split("'")[0] g['using_latest'] = (current == latest) if (not g['...
[ "def", "upgrade_center", "(", ")", ":", "try", ":", "current", "=", "pkg_resources", ".", "get_distribution", "(", "'rainbowstream'", ")", ".", "version", "url", "=", "'https://raw.githubusercontent.com/DTVD/rainbowstream/master/setup.py'", "readme", "=", "requests", "....
check latest and notify to upgrade .
train
false
51,779
@frappe.whitelist(allow_guest=True) def get_product_info(item_code): if (not is_cart_enabled()): return {} qty = 0 cart_quotation = _get_cart_quotation() template_item_code = frappe.db.get_value(u'Item', item_code, u'variant_of') in_stock = get_qty_in_stock(item_code, template_item_code) price = get_price(item_...
[ "@", "frappe", ".", "whitelist", "(", "allow_guest", "=", "True", ")", "def", "get_product_info", "(", "item_code", ")", ":", "if", "(", "not", "is_cart_enabled", "(", ")", ")", ":", "return", "{", "}", "qty", "=", "0", "cart_quotation", "=", "_get_cart_...
get product price / stock info .
train
false
51,780
def getDiagonalSwitchedTetragridByPolar(diagonals, unitPolar): diagonalSwitchedTetragrid = getIdentityTetragrid() for diagonal in diagonals: diagonalSwitchedTetragrid[diagonal][diagonal] = unitPolar.real diagonalSwitchedTetragrid[diagonals[0]][diagonals[1]] = (- unitPolar.imag) diagonalSwitchedTetragrid[diagonals...
[ "def", "getDiagonalSwitchedTetragridByPolar", "(", "diagonals", ",", "unitPolar", ")", ":", "diagonalSwitchedTetragrid", "=", "getIdentityTetragrid", "(", ")", "for", "diagonal", "in", "diagonals", ":", "diagonalSwitchedTetragrid", "[", "diagonal", "]", "[", "diagonal",...
get the diagonals and switched matrix by unitpolar .
train
false
51,781
def _nftables_cmd(): return 'nft'
[ "def", "_nftables_cmd", "(", ")", ":", "return", "'nft'" ]
return correct command .
train
false
51,782
def traverse_pre_order(start_node, get_children, filter_func=None): return _traverse_generic(start_node, get_parents=None, get_children=get_children, filter_func=filter_func)
[ "def", "traverse_pre_order", "(", "start_node", ",", "get_children", ",", "filter_func", "=", "None", ")", ":", "return", "_traverse_generic", "(", "start_node", ",", "get_parents", "=", "None", ",", "get_children", "=", "get_children", ",", "filter_func", "=", ...
generator for yielding nodes of a tree in a pre-order sort .
train
false
51,784
def parse_proxy(proxy_str): proxy_dict = {} if (proxy_str is None): return if (u'@' in proxy_str): (user_pass, host_port) = proxy_str.split(u'@') else: (user_pass, host_port) = (u'', proxy_str) if (u':' in host_port): (host, port) = host_port.split(u':') (proxy_dict[u'proxy_host'], proxy_dict[u'proxy_por...
[ "def", "parse_proxy", "(", "proxy_str", ")", ":", "proxy_dict", "=", "{", "}", "if", "(", "proxy_str", "is", "None", ")", ":", "return", "if", "(", "u'@'", "in", "proxy_str", ")", ":", "(", "user_pass", ",", "host_port", ")", "=", "proxy_str", ".", "...
parses proxy address user:pass@host:port into a dict suitable for httplib2 .
train
false
51,785
def check_ucd(ucd, check_controlled_vocabulary=False, has_colon=False): if (ucd is None): return True try: parse_ucd(ucd, check_controlled_vocabulary=check_controlled_vocabulary, has_colon=has_colon) except ValueError: return False return True
[ "def", "check_ucd", "(", "ucd", ",", "check_controlled_vocabulary", "=", "False", ",", "has_colon", "=", "False", ")", ":", "if", "(", "ucd", "is", "None", ")", ":", "return", "True", "try", ":", "parse_ucd", "(", "ucd", ",", "check_controlled_vocabulary", ...
returns false if *ucd* is not a valid unified content descriptor_ .
train
false
51,786
def _represent_yaml_str(self, node): return self.represent_scalar(node)
[ "def", "_represent_yaml_str", "(", "self", ",", "node", ")", ":", "return", "self", ".", "represent_scalar", "(", "node", ")" ]
represent for yaml .
train
false
51,787
def human_readable_filesize(b): thresh = 1024.0 if (b < thresh): return '{0:.1f} B'.format(b) units = ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] u = 0 b /= thresh while (b >= thresh): b /= thresh u += 1 return '{0:.1f} {1:s}'.format(round(b, 1), units[u])
[ "def", "human_readable_filesize", "(", "b", ")", ":", "thresh", "=", "1024.0", "if", "(", "b", "<", "thresh", ")", ":", "return", "'{0:.1f} B'", ".", "format", "(", "b", ")", "units", "=", "[", "'KiB'", ",", "'MiB'", ",", "'GiB'", ",", "'TiB'", ",", ...
returns filesize in a human readable format .
train
false
51,788
def wait_until_appeared(browser, css_selector, timeout=10, frequency=1.0): wait_until_condition(browser, condition=(lambda x: x.driver.find_element_by_css_selector(css_selector).is_displayed()), timeout=timeout, frequency=frequency)
[ "def", "wait_until_appeared", "(", "browser", ",", "css_selector", ",", "timeout", "=", "10", ",", "frequency", "=", "1.0", ")", ":", "wait_until_condition", "(", "browser", ",", "condition", "=", "(", "lambda", "x", ":", "x", ".", "driver", ".", "find_ele...
wait until the element has appeared .
train
false
51,791
def num_repr(num): if (num <= 9999): return str(num) def digit_count(x): ' Return number of digits. ' return int((math.floor(math.log10(x)) + 1)) digits = digit_count(num) sig = (3 if ((digits % 3) == 0) else 2) rounded = int(round(num, int((sig - digits)))) digits = digit_count(rounded) suffix = '_kmBTqXY...
[ "def", "num_repr", "(", "num", ")", ":", "if", "(", "num", "<=", "9999", ")", ":", "return", "str", "(", "num", ")", "def", "digit_count", "(", "x", ")", ":", "return", "int", "(", "(", "math", ".", "floor", "(", "math", ".", "log10", "(", "x",...
return up to four digit string representation of a number .
train
false
51,793
def Timer(*args, **kwargs): return _Timer(*args, **kwargs)
[ "def", "Timer", "(", "*", "args", ",", "**", "kwargs", ")", ":", "return", "_Timer", "(", "*", "args", ",", "**", "kwargs", ")" ]
factory function to create a timer object .
train
false
51,794
def handleargs(arglist): try: if (len(arglist) == 1): return (0, int(arglist[0]), 1) elif (len(arglist) == 2): return (int(arglist[0]), int(arglist[1]), 1) elif (len(arglist) == 3): if (arglist[2] == 0): raise ValueError('step argument must not be zero') return tuple((int(x) for x in arglist)) ...
[ "def", "handleargs", "(", "arglist", ")", ":", "try", ":", "if", "(", "len", "(", "arglist", ")", "==", "1", ")", ":", "return", "(", "0", ",", "int", "(", "arglist", "[", "0", "]", ")", ",", "1", ")", "elif", "(", "len", "(", "arglist", ")",...
take list of arguments and extract/create proper start .
train
false
51,795
def to_tree(expr, names=None): if isinstance(expr, slice): return {u'op': u'slice', u'args': [to_tree(arg, names=names) for arg in [expr.start, expr.stop, expr.step]]} if (names and (expr in names)): return names[expr] if isinstance(expr, tuple): return [to_tree(arg, names=names) for arg in expr] if isinstanc...
[ "def", "to_tree", "(", "expr", ",", "names", "=", "None", ")", ":", "if", "isinstance", "(", "expr", ",", "slice", ")", ":", "return", "{", "u'op'", ":", "u'slice'", ",", "u'args'", ":", "[", "to_tree", "(", "arg", ",", "names", "=", "names", ")", ...
represent blaze expression with core data structures transform a blaze expression into a form using only strings .
train
false
51,796
def write_hyperlinks(worksheet): if (not worksheet.hyperlinks): return tag = Element('hyperlinks') for cell in worksheet.hyperlinks: link = cell.hyperlink link.ref = cell.coordinate rel = Relationship(type='hyperlink', targetMode='External', target=link.target) worksheet._rels.append(rel) link.id = 'rId{...
[ "def", "write_hyperlinks", "(", "worksheet", ")", ":", "if", "(", "not", "worksheet", ".", "hyperlinks", ")", ":", "return", "tag", "=", "Element", "(", "'hyperlinks'", ")", "for", "cell", "in", "worksheet", ".", "hyperlinks", ":", "link", "=", "cell", "...
write worksheet hyperlinks to xml .
train
false
51,797
def _decode_value(stored_value, flags, do_unpickle): assert isinstance(stored_value, str) assert isinstance(flags, (int, long)) type_number = (flags & FLAG_TYPE_MASK) value = stored_value if (type_number == TYPE_STR): return value elif (type_number == TYPE_UNICODE): return value.decode('utf-8') elif (type_nu...
[ "def", "_decode_value", "(", "stored_value", ",", "flags", ",", "do_unpickle", ")", ":", "assert", "isinstance", "(", "stored_value", ",", "str", ")", "assert", "isinstance", "(", "flags", ",", "(", "int", ",", "long", ")", ")", "type_number", "=", "(", ...
utility function for decoding values retrieved from memcache .
train
false
51,798
def color_print(msg): clrmsg = ((clrgreen + msg) + clrnull) print clrmsg
[ "def", "color_print", "(", "msg", ")", ":", "clrmsg", "=", "(", "(", "clrgreen", "+", "msg", ")", "+", "clrnull", ")", "print", "clrmsg" ]
add color to this print output .
train
false
51,799
def relpath(path, start='.'): if ((sys.version_info < (2, 7)) and ('posix' in sys.builtin_module_names)): if (not path): raise ValueError('no path specified') start_list = [x for x in os.path.abspath(start).split(os.path.sep) if x] path_list = [x for x in os.path.abspath(path).split(os.path.sep) if x] i = l...
[ "def", "relpath", "(", "path", ",", "start", "=", "'.'", ")", ":", "if", "(", "(", "sys", ".", "version_info", "<", "(", "2", ",", "7", ")", ")", "and", "(", "'posix'", "in", "sys", ".", "builtin_module_names", ")", ")", ":", "if", "(", "not", ...
work around python bug #5117 .
train
false
51,801
def _TestFakeAuthViewfinderUser(action, tester, user_dict, device_dict=None, user_cookie=None): if ('email' in user_dict): ident_dict = {'key': ('Email:%s' % user_dict['email']), 'authority': 'FakeViewfinder'} else: ident_dict = {'key': ('Phone:%s' % user_dict['phone']), 'authority': 'FakeViewfinder'} response =...
[ "def", "_TestFakeAuthViewfinderUser", "(", "action", ",", "tester", ",", "user_dict", ",", "device_dict", "=", "None", ",", "user_cookie", "=", "None", ")", ":", "if", "(", "'email'", "in", "user_dict", ")", ":", "ident_dict", "=", "{", "'key'", ":", "(", ...
called by the servicetester in order to test login/fakeviewfinder and register/fakeviewfinder service endpoints .
train
false
51,802
def hypermedia_out(): request = cherrypy.serving.request request._hypermedia_inner_handler = request.handler request.handler = hypermedia_handler
[ "def", "hypermedia_out", "(", ")", ":", "request", "=", "cherrypy", ".", "serving", ".", "request", "request", ".", "_hypermedia_inner_handler", "=", "request", ".", "handler", "request", ".", "handler", "=", "hypermedia_handler" ]
determine the best handler for the requested content type wrap the normal handler and transform the output from that handler into the requested content type .
train
true
51,803
def write_mesh(fname, vertices, faces, normals, texcoords, name='', format='obj', overwrite=False, reshape_faces=True): if (op.isfile(fname) and (not overwrite)): raise IOError(('file "%s" exists, use overwrite=True' % fname)) if (format not in 'obj'): raise ValueError('Only "obj" format writing currently support...
[ "def", "write_mesh", "(", "fname", ",", "vertices", ",", "faces", ",", "normals", ",", "texcoords", ",", "name", "=", "''", ",", "format", "=", "'obj'", ",", "overwrite", "=", "False", ",", "reshape_faces", "=", "True", ")", ":", "if", "(", "op", "."...
write mesh data to file .
train
true
51,805
def ghd(ref, hyp, ins_cost=2.0, del_cost=2.0, shift_cost_coeff=1.0, boundary='1'): ref_idx = [i for (i, val) in enumerate(ref) if (val == boundary)] hyp_idx = [i for (i, val) in enumerate(hyp) if (val == boundary)] nref_bound = len(ref_idx) nhyp_bound = len(hyp_idx) if ((nref_bound == 0) and (nhyp_bound == 0)): ...
[ "def", "ghd", "(", "ref", ",", "hyp", ",", "ins_cost", "=", "2.0", ",", "del_cost", "=", "2.0", ",", "shift_cost_coeff", "=", "1.0", ",", "boundary", "=", "'1'", ")", ":", "ref_idx", "=", "[", "i", "for", "(", "i", ",", "val", ")", "in", "enumera...
compute the generalized hamming distance for a reference and a hypothetical segmentation .
train
false
51,807
def parse_comma_separated(tokens): tokens = [token for token in tokens if (token.type != u'S')] if (not tokens): return [] if (((len(tokens) % 2) == 1) and all((((token.type == u'DELIM') and (token.value == u',')) for token in tokens[1::2]))): return tokens[::2]
[ "def", "parse_comma_separated", "(", "tokens", ")", ":", "tokens", "=", "[", "token", "for", "token", "in", "tokens", "if", "(", "token", ".", "type", "!=", "u'S'", ")", "]", "if", "(", "not", "tokens", ")", ":", "return", "[", "]", "if", "(", "(",...
parse a list of tokens as arguments made of a single token each .
train
false
51,808
def pyext_coms(platform): if (platform == 'win32'): pyext_cccom = '$PYEXTCC /Fo$TARGET /c $PYEXTCCSHARED $PYEXTCFLAGS $PYEXTCCFLAGS $_CCCOMCOM $_PYEXTCPPINCFLAGS $SOURCES' pyext_cxxcom = '$PYEXTCXX /Fo$TARGET /c $PYEXTCSHARED $PYEXTCXXFLAGS $PYEXTCCFLAGS $_CCCOMCOM $_PYEXTCPPINCFLAGS $SOURCES' pyext_linkcom = '$...
[ "def", "pyext_coms", "(", "platform", ")", ":", "if", "(", "platform", "==", "'win32'", ")", ":", "pyext_cccom", "=", "'$PYEXTCC /Fo$TARGET /c $PYEXTCCSHARED $PYEXTCFLAGS $PYEXTCCFLAGS $_CCCOMCOM $_PYEXTCPPINCFLAGS $SOURCES'", "pyext_cxxcom", "=", "'$PYEXTCXX /Fo$TARGET /c $PYEXT...
return pyextcccom .
train
false
51,809
def _iface_hdlr(iface_node): return True
[ "def", "_iface_hdlr", "(", "iface_node", ")", ":", "return", "True" ]
a handler function used by interfaces to handle suspicious interface nodes .
train
false
51,810
def find_cmd(cmd): path = py3compat.which(cmd) if (path is None): raise FindCmdError(('command could not be found: %s' % cmd)) return path
[ "def", "find_cmd", "(", "cmd", ")", ":", "path", "=", "py3compat", ".", "which", "(", "cmd", ")", "if", "(", "path", "is", "None", ")", ":", "raise", "FindCmdError", "(", "(", "'command could not be found: %s'", "%", "cmd", ")", ")", "return", "path" ]
find absolute path to executable cmd in a cross platform manner .
train
false
51,811
def parse_repl_hex_escape(source, expected_len, type): digits = [] for i in range(expected_len): ch = source.get() if (ch not in HEX_DIGITS): raise error(('incomplete escape \\%s%s' % (type, ''.join(digits))), source.string, source.pos) digits.append(ch) return int(''.join(digits), 16)
[ "def", "parse_repl_hex_escape", "(", "source", ",", "expected_len", ",", "type", ")", ":", "digits", "=", "[", "]", "for", "i", "in", "range", "(", "expected_len", ")", ":", "ch", "=", "source", ".", "get", "(", ")", "if", "(", "ch", "not", "in", "...
parses a hex escape sequence in a replacement string .
train
false
51,814
def hrm_experience_controller(): if (current.session.s3.hrm.mode is not None): current.session.error = current.T('Access denied') redirect(URL(f='index')) def prep(r): if (r.method in ('create', 'update')): field = current.s3db.hrm_experience.person_id person_id = current.request.get_vars.get('~.person_id...
[ "def", "hrm_experience_controller", "(", ")", ":", "if", "(", "current", ".", "session", ".", "s3", ".", "hrm", ".", "mode", "is", "not", "None", ")", ":", "current", ".", "session", ".", "error", "=", "current", ".", "T", "(", "'Access denied'", ")", ...
experience controller .
train
false
51,816
def make_istatechange_tests(klass, kwargs1, kwargs2): def instance(kwargs): if isinstance(kwargs, dict): return klass(**kwargs) return klass(**kwargs()) class Tests(make_comparison_tests(klass, kwargs1, kwargs2), ): def test_interface(self): '\n The class implements ``IStateChange``.\n ...
[ "def", "make_istatechange_tests", "(", "klass", ",", "kwargs1", ",", "kwargs2", ")", ":", "def", "instance", "(", "kwargs", ")", ":", "if", "isinstance", "(", "kwargs", ",", "dict", ")", ":", "return", "klass", "(", "**", "kwargs", ")", "return", "klass"...
create tests to verify a class provides istatechange .
train
false
51,818
@pytest.fixture def forum_locked(category, default_settings): forum = Forum(title='Test Forum', category_id=category.id) forum.locked = True forum.save() return forum
[ "@", "pytest", ".", "fixture", "def", "forum_locked", "(", "category", ",", "default_settings", ")", ":", "forum", "=", "Forum", "(", "title", "=", "'Test Forum'", ",", "category_id", "=", "category", ".", "id", ")", "forum", ".", "locked", "=", "True", ...
a single locked forum in a category .
train
false
51,819
def get_course_chapters(course_key): if (course_key is None): return try: course_obj = CourseStructure.objects.get(course_id=course_key) except CourseStructure.DoesNotExist: return course_struct = course_obj.structure try: return course_struct['blocks'][course_struct['root']].get('children', []) except Ke...
[ "def", "get_course_chapters", "(", "course_key", ")", ":", "if", "(", "course_key", "is", "None", ")", ":", "return", "try", ":", "course_obj", "=", "CourseStructure", ".", "objects", ".", "get", "(", "course_id", "=", "course_key", ")", "except", "CourseStr...
extracts the chapters from a course structure .
train
false
51,820
def _list_samples(meter, project=None, resource=None, source=None, user=None): q_ts = _get_query_timestamps(flask.request.args) f = storage.SampleFilter(user=user, project=project, source=source, meter=meter, resource=resource, start=q_ts['start_timestamp'], end=q_ts['end_timestamp'], metaquery=_get_metaquery(flask.r...
[ "def", "_list_samples", "(", "meter", ",", "project", "=", "None", ",", "resource", "=", "None", ",", "source", "=", "None", ",", "user", "=", "None", ")", ":", "q_ts", "=", "_get_query_timestamps", "(", "flask", ".", "request", ".", "args", ")", "f", ...
return a list of raw samples .
train
false
51,821
def icreate_animations(figure, filename=None, sharing='public', auto_open=False): url = create_animations(figure, filename, sharing, auto_open) if isinstance(figure, dict): layout = figure.get('layout', {}) else: layout = {} embed_options = dict() embed_options['width'] = layout.get('width', '100%') embed_opt...
[ "def", "icreate_animations", "(", "figure", ",", "filename", "=", "None", ",", "sharing", "=", "'public'", ",", "auto_open", "=", "False", ")", ":", "url", "=", "create_animations", "(", "figure", ",", "filename", ",", "sharing", ",", "auto_open", ")", "if...
create a unique url for this animated plot in plotly and open in ipython .
train
false
51,822
def locationUpdatingRequest(): a = TpPd(pd=5) b = MessageType(mesType=8) c = LocationUpdatingTypeAndCiphKeySeqNr() e = LocalAreaId() f = MobileStationClassmark1() g = MobileId() packet = (((((a / b) / c) / e) / f) / g) return packet
[ "def", "locationUpdatingRequest", "(", ")", ":", "a", "=", "TpPd", "(", "pd", "=", "5", ")", "b", "=", "MessageType", "(", "mesType", "=", "8", ")", "c", "=", "LocationUpdatingTypeAndCiphKeySeqNr", "(", ")", "e", "=", "LocalAreaId", "(", ")", "f", "=",...
location updating request section 9 .
train
true
51,823
def post_save_layer(instance, sender, **kwargs): ModelDescription.objects.filter(name=instance.name).update(layer=instance)
[ "def", "post_save_layer", "(", "instance", ",", "sender", ",", "**", "kwargs", ")", ":", "ModelDescription", ".", "objects", ".", "filter", "(", "name", "=", "instance", ".", "name", ")", ".", "update", "(", "layer", "=", "instance", ")" ]
assign layer instance to the dynamic model .
train
false
51,824
def is_undefined(obj): from jinja2.runtime import Undefined return isinstance(obj, Undefined)
[ "def", "is_undefined", "(", "obj", ")", ":", "from", "jinja2", ".", "runtime", "import", "Undefined", "return", "isinstance", "(", "obj", ",", "Undefined", ")" ]
check if the object passed is undefined .
train
false
51,825
def POSform(variables, minterms, dontcares=None): variables = [sympify(v) for v in variables] if (minterms == []): return false minterms = [list(i) for i in minterms] dontcares = [list(i) for i in (dontcares or [])] for d in dontcares: if (d in minterms): raise ValueError(('%s in minterms is also in dontcar...
[ "def", "POSform", "(", "variables", ",", "minterms", ",", "dontcares", "=", "None", ")", ":", "variables", "=", "[", "sympify", "(", "v", ")", "for", "v", "in", "variables", "]", "if", "(", "minterms", "==", "[", "]", ")", ":", "return", "false", "...
the posform function uses simplified_pairs and a redundant-group eliminating algorithm to convert the list of all input combinations that generate 1 into the smallest product of sums form .
train
false
51,826
def test_log_sum_exp_1(): rng = np.random.RandomState([2015, 2, 9]) x = (1.0 + (rng.randn(5) / 10.0)) naive = np.log(np.exp(x).sum()) x = sharedX(x) stable = log_sum_exp(x).eval() assert np.allclose(naive, stable)
[ "def", "test_log_sum_exp_1", "(", ")", ":", "rng", "=", "np", ".", "random", ".", "RandomState", "(", "[", "2015", ",", "2", ",", "9", "]", ")", "x", "=", "(", "1.0", "+", "(", "rng", ".", "randn", "(", "5", ")", "/", "10.0", ")", ")", "naive...
tests that the stable log sum exp matches the naive one for values near 1 .
train
false
51,828
def GetClientURNFromPath(path): try: return ClientURN(path.split('/')[1]) except (type_info.TypeValueError, IndexError): return None
[ "def", "GetClientURNFromPath", "(", "path", ")", ":", "try", ":", "return", "ClientURN", "(", "path", ".", "split", "(", "'/'", ")", "[", "1", "]", ")", "except", "(", "type_info", ".", "TypeValueError", ",", "IndexError", ")", ":", "return", "None" ]
extracts the client id from the path .
train
false
51,831
def _count_contributors_in_range(querysets, users, date_range): (start, end) = date_range retained_users = set() for (queryset, fields) in querysets: for field in fields: filters = {('%s__in' % field): users, 'created__gte': start, 'created__lt': end} retained_users |= set((getattr(o, field) for o in queryse...
[ "def", "_count_contributors_in_range", "(", "querysets", ",", "users", ",", "date_range", ")", ":", "(", "start", ",", "end", ")", "=", "date_range", "retained_users", "=", "set", "(", ")", "for", "(", "queryset", ",", "fields", ")", "in", "querysets", ":"...
of the group users .
train
false
51,832
def getNewRepository(): return ExportRepository()
[ "def", "getNewRepository", "(", ")", ":", "return", "ExportRepository", "(", ")" ]
get the repository constructor .
train
false
51,833
def get_evennia_version(): import evennia return evennia.__version__
[ "def", "get_evennia_version", "(", ")", ":", "import", "evennia", "return", "evennia", ".", "__version__" ]
helper method for getting the current evennia version .
train
false
51,834
def get_parallels(bezier2, width): (c1x, c1y) = bezier2[0] (cmx, cmy) = bezier2[1] (c2x, c2y) = bezier2[2] (cos_t1, sin_t1) = get_cos_sin(c1x, c1y, cmx, cmy) (cos_t2, sin_t2) = get_cos_sin(cmx, cmy, c2x, c2y) (c1x_left, c1y_left, c1x_right, c1y_right) = get_normal_points(c1x, c1y, cos_t1, sin_t1, width) (c2x_lef...
[ "def", "get_parallels", "(", "bezier2", ",", "width", ")", ":", "(", "c1x", ",", "c1y", ")", "=", "bezier2", "[", "0", "]", "(", "cmx", ",", "cmy", ")", "=", "bezier2", "[", "1", "]", "(", "c2x", ",", "c2y", ")", "=", "bezier2", "[", "2", "]"...
given the quadraitc bezier control points *bezier2* .
train
false
51,836
def _scalar_to_format(value): for type_ in (int, float, complex): try: value = type_(value) break except ValueError: continue numpy_dtype_str = np.min_scalar_type(value).str numpy_dtype_str = numpy_dtype_str[1:] try: fits_format = NUMPY2FITS[numpy_dtype_str] return FITSUPCONVERTERS.get(fits_format,...
[ "def", "_scalar_to_format", "(", "value", ")", ":", "for", "type_", "in", "(", "int", ",", "float", ",", "complex", ")", ":", "try", ":", "value", "=", "type_", "(", "value", ")", "break", "except", "ValueError", ":", "continue", "numpy_dtype_str", "=", ...
given a scalar value or string .
train
false
51,837
def simple_python_completion(): python_completion = [] python_completion += builtin_module_names python_completion += tuple(dir(__builtins__)) python_completion += [module_name[1] for module_name in iter_modules()] try: python_completion += tuple(__builtins__.__dict__.keys()) except: pass python_completion =...
[ "def", "simple_python_completion", "(", ")", ":", "python_completion", "=", "[", "]", "python_completion", "+=", "builtin_module_names", "python_completion", "+=", "tuple", "(", "dir", "(", "__builtins__", ")", ")", "python_completion", "+=", "[", "module_name", "["...
return tuple of strings containing python words for simple completion .
train
false
51,839
def extend_element(element, base): u' Recursion is needed if the extension base itself extends another element.' if isinstance(base, dict): for (i, kk) in enumerate(base): if isinstance(base, Struct): element.insert(kk, base[kk], i) if (isinstance(base, Struct) and base.namespaces and kk): element.n...
[ "def", "extend_element", "(", "element", ",", "base", ")", ":", "if", "isinstance", "(", "base", ",", "dict", ")", ":", "for", "(", "i", ",", "kk", ")", "in", "enumerate", "(", "base", ")", ":", "if", "isinstance", "(", "base", ",", "Struct", ")", ...
recursively extend the elemnet if it has an extension base .
train
false
51,841
def dmp_zz_wang_non_divisors(E, cs, ct, K): result = [(cs * ct)] for q in E: q = abs(q) for r in reversed(result): while (r != 1): r = K.gcd(r, q) q = (q // r) if K.is_one(q): return None result.append(q) return result[1:]
[ "def", "dmp_zz_wang_non_divisors", "(", "E", ",", "cs", ",", "ct", ",", "K", ")", ":", "result", "=", "[", "(", "cs", "*", "ct", ")", "]", "for", "q", "in", "E", ":", "q", "=", "abs", "(", "q", ")", "for", "r", "in", "reversed", "(", "result"...
wang/eez: compute a set of valid divisors .
train
false
51,842
def invalid_marker(text): try: evaluate_marker(text) except SyntaxError as e: e.filename = None e.lineno = None return e return False
[ "def", "invalid_marker", "(", "text", ")", ":", "try", ":", "evaluate_marker", "(", "text", ")", "except", "SyntaxError", "as", "e", ":", "e", ".", "filename", "=", "None", "e", ".", "lineno", "=", "None", "return", "e", "return", "False" ]
validate text as a pep 508 environment marker; return an exception if invalid or false otherwise .
train
true
51,843
def parse_qsd(data, name='query string', exception=PluginError, schema=None, **params): value = dict(parse_qsl(data, **params)) if schema: value = schema.validate(value, name=name, exception=exception) return value
[ "def", "parse_qsd", "(", "data", ",", "name", "=", "'query string'", ",", "exception", "=", "PluginError", ",", "schema", "=", "None", ",", "**", "params", ")", ":", "value", "=", "dict", "(", "parse_qsl", "(", "data", ",", "**", "params", ")", ")", ...
parses a query string into a dict .
train
true
51,844
def _check_plural_is_ambiguous(plural_arg): if _STRING_RE.match(plural_arg): return False fn_match = _FUNCTION_RE.match(plural_arg) if (fn_match and (fn_match.group(1) in _functions)): return False return True
[ "def", "_check_plural_is_ambiguous", "(", "plural_arg", ")", ":", "if", "_STRING_RE", ".", "match", "(", "plural_arg", ")", ":", "return", "False", "fn_match", "=", "_FUNCTION_RE", ".", "match", "(", "plural_arg", ")", "if", "(", "fn_match", "and", "(", "fn_...
check to see if a string is ambiguously named .
train
false
51,845
def Print(file): finder = _getfinder() fss = Carbon.File.FSSpec(file) return finder._print(fss)
[ "def", "Print", "(", "file", ")", ":", "finder", "=", "_getfinder", "(", ")", "fss", "=", "Carbon", ".", "File", ".", "FSSpec", "(", "file", ")", "return", "finder", ".", "_print", "(", "fss", ")" ]
print a file thru the finder .
train
false
51,846
def is_writeable(path, check_parent=False): if (os.access(path, os.F_OK) and os.access(path, os.W_OK)): return True if (os.access(path, os.F_OK) and (not os.access(path, os.W_OK))): return False if (check_parent is False): return False parent_dir = os.path.dirname(path) if (not os.access(parent_dir, os.F_OK)...
[ "def", "is_writeable", "(", "path", ",", "check_parent", "=", "False", ")", ":", "if", "(", "os", ".", "access", "(", "path", ",", "os", ".", "F_OK", ")", "and", "os", ".", "access", "(", "path", ",", "os", ".", "W_OK", ")", ")", ":", "return", ...
check if a given path is writeable by the current user .
train
true
51,847
def _get_id_token_user(token, audiences, allowed_client_ids, time_now, cache): try: parsed_token = _verify_signed_jwt_with_certs(token, time_now, cache) except _AppIdentityError as e: logging.warning('id_token verification failed: %s', e) return None except: logging.warning('id_token verification failed.') ...
[ "def", "_get_id_token_user", "(", "token", ",", "audiences", ",", "allowed_client_ids", ",", "time_now", ",", "cache", ")", ":", "try", ":", "parsed_token", "=", "_verify_signed_jwt_with_certs", "(", "token", ",", "time_now", ",", "cache", ")", "except", "_AppId...
get a user for the given id token .
train
false
51,850
def decodeHostPort(line): abcdef = re.sub('[^0-9, ]', '', line) parsed = [int(p.strip()) for p in abcdef.split(',')] for x in parsed: if ((x < 0) or (x > 255)): raise ValueError('Out of range', line, x) (a, b, c, d, e, f) = parsed host = ('%s.%s.%s.%s' % (a, b, c, d)) port = ((int(e) << 8) + int(f)) return ...
[ "def", "decodeHostPort", "(", "line", ")", ":", "abcdef", "=", "re", ".", "sub", "(", "'[^0-9, ]'", ",", "''", ",", "line", ")", "parsed", "=", "[", "int", "(", "p", ".", "strip", "(", ")", ")", "for", "p", "in", "abcdef", ".", "split", "(", "'...
decode an ftp response specifying a host and port .
train
false
51,852
def _download(quidditch, retries=5): passed = False clean = True comment = '' while (not passed): log.debug('Downloading. tries left: {0}'.format(str(retries))) passed = quidditch.Download() log.debug('Done downloading: {0}'.format(str(passed))) if isinstance(passed, Exception): clean = False comment ...
[ "def", "_download", "(", "quidditch", ",", "retries", "=", "5", ")", ":", "passed", "=", "False", "clean", "=", "True", "comment", "=", "''", "while", "(", "not", "passed", ")", ":", "log", ".", "debug", "(", "'Downloading. tries left: {0}'", ".", "forma...
another wrapper method .
train
false
51,853
def parse_netntlm(authenticate_header, authorization_header, headers, ack, seq): if (authenticate_header != None): chal_header = authenticate_header.group() parse_netntlm_chal(headers, chal_header, ack) elif (authorization_header != None): resp_header = authorization_header.group() msg = parse_netntlm_resp_ms...
[ "def", "parse_netntlm", "(", "authenticate_header", ",", "authorization_header", ",", "headers", ",", "ack", ",", "seq", ")", ":", "if", "(", "authenticate_header", "!=", "None", ")", ":", "chal_header", "=", "authenticate_header", ".", "group", "(", ")", "par...
parse ntlm hashes out .
train
false
51,854
def test_copy_function_doc_to_method_doc(): def f1(object, a, b, c): 'Docstring for f1\n\n Parameters\n ----------\n object : object\n Some object. This description also has\n\n blank lines in it.\n a : int\n Parameter a\n b : int\n Param...
[ "def", "test_copy_function_doc_to_method_doc", "(", ")", ":", "def", "f1", "(", "object", ",", "a", ",", "b", ",", "c", ")", ":", "pass", "def", "f2", "(", "object", ")", ":", "pass", "def", "f3", "(", "object", ")", ":", "pass", "def", "f4", "(", ...
test decorator for re-using function docstring as method docstrings .
train
false
51,855
def decouple(prefix): dynamic.decouple(prefix) from calibre.gui2.widgets import history history.decouple(prefix)
[ "def", "decouple", "(", "prefix", ")", ":", "dynamic", ".", "decouple", "(", "prefix", ")", "from", "calibre", ".", "gui2", ".", "widgets", "import", "history", "history", ".", "decouple", "(", "prefix", ")" ]
ensure that config files used by utility code are not the same as those used by the main calibre gui .
train
false