code-search-net-python-permissive / code_search_net_python_permissive.sample.jsonl
PiotrSty's picture
CodeSearchNet Python permissive-only
c032c6d verified
Raw History Blame Contribute Delete
20.9 kB
{"added": "2026-12-05", "author": "ihgazni2/elist", "created": "2019", "id": "424773fc2889176b60ed7c4d", "license": "MIT", "source": "code_search_net", "text": "regex = re.compile(\"^[a-z]+$\")\n pl = ['b1c3d','xab15cxx','1x','y2']\n regex_in(pl,regex)\n \n regex = re.compile(\"^[0-9a-z]+$\")\n pl = ['b1c3d','xab15cxx','1x','y2']\n regex_in(pl,regex)\n\ndef regex_in(pl,regex):\n '''\n regex = re.compile(\"^[a-z]+$\")\n pl = ['b1c3d','xab15cxx','1x','y2']\n regex_in(pl,regex)\n \n regex = re.compile(\"^[0-9a-z]+$\")\n pl = ['b1c3d','xab15cxx','1x','y2']\n regex_in(pl,regex)\n \n '''\n def cond_func(ele,regex):\n m = regex.search(ele)\n if(m == None):\n return(False)\n else:\n return(True)\n cond = some(pl,cond_func,regex)['cond']\n return(cond)", "token_count": 220}
{"added": "2026-12-05", "author": "pallets/werkzeug", "created": "2019", "id": "116a93e88ecabeca456f59ef", "license": "BSD-3-Clause", "source": "code_search_net", "text": "Replace special characters \"&\", \"<\", \">\" and (\") to HTML-safe sequences.\n\n There is a special handling for `None` which escapes to an empty string.\n\n .. versionchanged:: 0.9\n `quote` is now implicitly on.\n\n :param s: the string to escape.\n :param quote: ignored.\n\ndef escape(s):\n \"\"\"Replace special characters \"&\", \"<\", \">\" and (\") to HTML-safe sequences.\n\n There is a special handling for `None` which escapes to an empty string.\n\n .. versionchanged:: 0.9\n `quote` is now implicitly on.\n\n :param s: the string to escape.\n :param quote: ignored.\n \"\"\"\n if s is None:\n return \"\"\n elif hasattr(s, \"__html__\"):\n return text_type(s.__html__())\n\n if not isinstance(s, string_types):\n s = text_type(s)\n\n return (\n s.replace(\"&\", \"&amp;\")\n .replace(\"<\", \"&lt;\")\n .replace(\">\", \"&gt;\")\n .replace('\"', \"&quot;\")\n )", "token_count": 226}
{"added": "2026-12-05", "author": "ncolony/ncolony", "created": "2019", "id": "1b27b40bab9109854ff07c29", "license": "MIT", "source": "code_search_net", "text": "Run a process, return a deferred that fires when it is done\n\n :params args: Process arguments\n :params timeout: Time before terminating process\n :params grace: Time before killing process after terminating it\n :params reactor: IReactorProcess and IReactorTime\n :returns: deferred that fires with success when the process ends,\n or fails if there was a problem spawning/terminating\n the process\n\ndef runProcess(args, timeout, grace, reactor):\n \"\"\"Run a process, return a deferred that fires when it is done\n\n :params args: Process arguments\n :params timeout: Time before terminating process\n :params grace: Time before killing process after terminating it\n :params reactor: IReactorProcess and IReactorTime\n :returns: deferred that fires with success when the process ends,\n or fails if there was a problem spawning/terminating\n the process\n \"\"\"\n deferred = defer.Deferred()\n protocol = ProcessProtocol(deferred)\n process = reactor.spawnProcess(protocol, args[0], args, env=os.environ)\n\n def _logEnded(err):\n err.trap(tierror.ProcessDone, tierror.ProcessTerminated)\n print(err.value)\n deferred.addErrback(_logEnded)\n\n def _cancelTermination(dummy):\n for termination in terminations:\n if termination.active():\n termination.cancel()\n deferred.addCallback(_cancelTermination)\n terminations = []\n terminations.append(reactor.callLater(timeout, process.signalProcess,\n \"TERM\"))\n terminations.append(reactor.callLater(timeout+grace,\n process.signalProcess, \"KILL\"))\n return deferred", "token_count": 350}
{"added": "2026-12-05", "author": "coded-by-hand/mass", "created": "2019", "id": "e87a8fad10cafc30aa63ac68", "license": "BSD-2-Clause", "source": "code_search_net", "text": "does the dirty work of actually getting the rsponse object using urllib2\n and its HTTP auth builtins.\n\ndef get_response(self, url, username=None, password=None):\n \"\"\"\n does the dirty work of actually getting the rsponse object using urllib2\n and its HTTP auth builtins.\n \"\"\"\n scheme, netloc, path, query, frag = urlparse.urlsplit(url)\n req = self.get_request(url)\n\n stored_username, stored_password = self.passman.find_user_password(None, netloc)\n # see if we have a password stored\n if stored_username is None:\n if username is None and self.prompting:\n username = urllib.quote(raw_input('User for %s: ' % netloc))\n password = urllib.quote(getpass.getpass('Password: '))\n if username and password:\n self.passman.add_password(None, netloc, username, password)\n stored_username, stored_password = self.passman.find_user_password(None, netloc)\n authhandler = urllib2.HTTPBasicAuthHandler(self.passman)\n opener = urllib2.build_opener(authhandler)\n # FIXME: should catch a 401 and offer to let the user reenter credentials\n return opener.open(req)", "token_count": 254}
{"added": "2026-12-05", "author": "google/grr", "created": "2019", "id": "1e287bcddd8e978ecc4eb55d", "license": "Apache-2.0", "source": "code_search_net", "text": "Creates a ClientFullInfo object from a database response.\n\ndef _ResponseToClientsFullInfo(self, response):\n \"\"\"Creates a ClientFullInfo object from a database response.\"\"\"\n c_full_info = None\n prev_cid = None\n for row in response:\n (cid, fs, crt, ping, clk, ip, foreman, first, last_client_ts,\n last_crash_ts, last_startup_ts, client_obj, client_startup_obj,\n last_startup_obj, label_owner, label_name) = row\n\n if cid != prev_cid:\n if c_full_info:\n yield db_utils.IntToClientID(prev_cid), c_full_info\n\n metadata = rdf_objects.ClientMetadata(\n certificate=crt,\n fleetspeak_enabled=fs,\n first_seen=mysql_utils.TimestampToRDFDatetime(first),\n ping=mysql_utils.TimestampToRDFDatetime(ping),\n clock=mysql_utils.TimestampToRDFDatetime(clk),\n ip=mysql_utils.StringToRDFProto(rdf_client_network.NetworkAddress,\n ip),\n last_foreman_time=mysql_utils.TimestampToRDFDatetime(foreman),\n startup_info_timestamp=mysql_utils.TimestampToRDFDatetime(\n last_startup_ts),\n last_crash_timestamp=mysql_utils.TimestampToRDFDatetime(\n last_crash_ts))\n\n if client_obj is not None:\n l_snapshot = rdf_objects.ClientSnapshot.FromSerializedString(\n client_obj)\n l_snapshot.timestamp = mysql_utils.TimestampToRDFDatetime(\n last_client_ts)\n l_snapshot.startup_info = rdf_client.StartupInfo.FromSerializedString(\n client_startup_obj)\n l_snapshot.startup_info.timestamp = l_snapshot.timestamp\n else:\n l_snapshot = rdf_objects.ClientSnapshot(\n client_id=db_utils.IntToClientID(cid))\n\n if last_startup_obj is not None:\n startup_info = rdf_client.StartupInfo.FromSerializedString(\n last_startup_obj)\n startup_info.timestamp = mysql_utils.TimestampToRDFDatetime(\n last_startup_ts)\n else:\n startup_info = None\n\n prev_cid = cid\n c_full_info = rdf_objects.ClientFullInfo(\n metadata=metadata,\n labels=[],\n last_snapshot=l_snapshot,\n last_startup_info=startup_info)\n\n if label_owner and label_name:\n c_full_info.labels.append(\n rdf_objects.ClientLabel(name=label_name, owner=label_owner))\n\n if c_full_info:\n yield db_utils.IntToClientID(prev_cid), c_full_info", "token_count": 501}
{"added": "2026-12-05", "author": "timkpaine/pyEX", "created": "2019", "id": "f7a6b947d8a50eb9de060992", "license": "Apache-2.0", "source": "code_search_net", "text": "Stock split history\n\n https://iexcloud.io/docs/api/#splits\n Updated at 9am UTC every day\n\n Args:\n symbol (string); Ticker to request\n token (string); Access token\n version (string); API version\n\n Returns:\n DataFrame: result\n\ndef splitsDF(symbol, timeframe='ytd', token='', version=''):\n '''Stock split history\n\n https://iexcloud.io/docs/api/#splits\n Updated at 9am UTC every day\n\n Args:\n symbol (string); Ticker to request\n token (string); Access token\n version (string); API version\n\n Returns:\n DataFrame: result\n '''\n s = splits(symbol, timeframe, token, version)\n df = _splitsToDF(s)\n return df", "token_count": 171}
{"added": "2026-12-05", "author": "astropy/photutils", "created": "2019", "id": "57d98f64e94a5dd1f6e53cb2", "license": "BSD-3-Clause", "source": "code_search_net", "text": "Retrieve uncertainties on fitted parameters from the fitter\n object.\n\n Parameters\n ----------\n star_group_size : int\n Number of stars in the given group.\n\n Returns\n -------\n unc_tab : `~astropy.table.Table`\n Table which contains uncertainties on the fitted parameters.\n The uncertainties are reported as one standard deviation.\n\ndef _get_uncertainties(self, star_group_size):\n \"\"\"\n Retrieve uncertainties on fitted parameters from the fitter\n object.\n\n Parameters\n ----------\n star_group_size : int\n Number of stars in the given group.\n\n Returns\n -------\n unc_tab : `~astropy.table.Table`\n Table which contains uncertainties on the fitted parameters.\n The uncertainties are reported as one standard deviation.\n \"\"\"\n\n unc_tab = Table()\n for param_name in self.psf_model.param_names:\n if not self.psf_model.fixed[param_name]:\n unc_tab.add_column(Column(name=param_name + \"_unc\",\n data=np.empty(star_group_size)))\n\n if 'param_cov' in self.fitter.fit_info.keys():\n if self.fitter.fit_info['param_cov'] is not None:\n k = 0\n n_fit_params = len(unc_tab.colnames)\n for i in range(star_group_size):\n unc_tab[i] = np.sqrt(np.diag(\n self.fitter.fit_info['param_cov'])\n )[k: k + n_fit_params]\n k = k + n_fit_params\n return unc_tab", "token_count": 310}
{"added": "2026-12-05", "author": "xapple/fasta", "created": "2019", "id": "28a265462c31aecb9165e52c", "license": "MIT", "source": "code_search_net", "text": "This functions starts with self because it's \n meant as an extension to the FASTA class.\n\ndef parse_primers(self, primers=None, mismatches=0, revcompl=False):\n \"\"\"This functions starts with self because it's \n meant as an extension to the FASTA class.\"\"\"\n # Default primers #\n if primers is None: primers = self.primers\n # Case straight #\n if not revcompl:\n fwd_regex = regex.compile(\"(%s){s<=%i}\" % (primers.fwd_pattern, mismatches))\n rev_regex = regex.compile(\"(%s){s<=%i}\" % (primers.rev_pattern, mismatches))\n generator = (ReadWithPrimers(r, fwd_regex, rev_regex) for r in self.parse())\n # Case revcompl #\n if revcompl:\n fwd_regex = regex.compile(\"(%s){s<=%i}\" % (primers.fwd_pattern, mismatches))\n rev_regex = regex.compile(\"(%s){s<=%i}\" % (primers.rev_pattern_revcompl, mismatches))\n generator = (ReadWithPrimersRevCompl(r, fwd_regex, rev_regex) for r in self.parse())\n # Return #\n return GenWithLength(generator, len(self))", "token_count": 271}
{"added": "2026-12-05", "author": "tanghaibao/jcvi", "created": "2019", "id": "91903dbaa82fbb224e0da737", "license": "BSD-2-Clause", "source": "code_search_net", "text": "%prog uniq gffile cdsfasta\n\n Remove overlapping gene models. Similar to formats.gff.uniq(), overlapping\n 'piles' are processed, one by one.\n\n Here, we use a different algorithm, that retains the best non-overlapping\n subset witin each pile, rather than single best model. Scoring function is\n also different, rather than based on score or span, we optimize for the\n subset that show the best combined score. Score is defined by:\n\n score = (1 - AED) * length\n\ndef uniq(args):\n \"\"\"\n %prog uniq gffile cdsfasta\n\n Remove overlapping gene models. Similar to formats.gff.uniq(), overlapping\n 'piles' are processed, one by one.\n\n Here, we use a different algorithm, that retains the best non-overlapping\n subset witin each pile, rather than single best model. Scoring function is\n also different, rather than based on score or span, we optimize for the\n subset that show the best combined score. Score is defined by:\n\n score = (1 - AED) * length\n \"\"\"\n\n p = OptionParser(uniq.__doc__)\n p.set_outfile()\n opts, args = p.parse_args(args)\n\n if len(args) != 2:\n sys.exit(not p.print_help())\n\n gffile, cdsfasta = args\n gff = Gff(gffile)\n sizes = Sizes(cdsfasta).mapping\n gene_register = {}\n for g in gff:\n if g.type != \"mRNA\":\n continue\n aed = float(g.attributes[\"_AED\"][0])\n gene_register[g.parent] = (1 - aed) * sizes[g.accn]\n\n allgenes = import_feats(gffile)\n g = get_piles(allgenes)\n\n bestids = set()\n for group in g:\n ranges = [to_range(x, score=gene_register[x.accn], id=x.accn) \\\n for x in group]\n selected_chain, score = range_chain(ranges)\n bestids |= set(x.id for x in selected_chain)\n\n removed = set(x.accn for x in allgenes) - bestids\n fw = open(\"removed.ids\", \"w\")\n print(\"\\n\".join(sorted(removed)), file=fw)\n fw.close()\n populate_children(opts.outfile, bestids, gffile, \"gene\")", "token_count": 514}
{"added": "2026-12-05", "author": "SheffieldML/GPyOpt", "created": "2019", "id": "5da901eed6fd7d6c5a9a7da1", "license": "BSD-3-Clause", "source": "code_search_net", "text": "Computes the expected change in mean and variance at the representer \n points (cf. Section 2.4 in the paper). \n \n \n :param x: candidate for which to compute the expected change in the GP\n :type x: np.array(1, input_dim)\n \n :return: innovation of mean (without samples) and variance at the representer points\n :rtype: (np.array(num_repr_points, 1), np.array(num_repr_points, num_repr_points))\n\ndef _innovations(self, x):\n \"\"\"\n Computes the expected change in mean and variance at the representer \n points (cf. Section 2.4 in the paper). \n \n \n :param x: candidate for which to compute the expected change in the GP\n :type x: np.array(1, input_dim)\n \n :return: innovation of mean (without samples) and variance at the representer points\n :rtype: (np.array(num_repr_points, 1), np.array(num_repr_points, num_repr_points))\n \n \"\"\"\n \n \n '''\n The notation differs from the paper. The representer points\n play the role of x*, the test input x is X. The Omega term is applied\n in the calling function _compute_acq. Another difference is that we\n ignore the noise as in the original Matlab implementation:\n https://github.com/ProbabilisticNumerics/entropy-search/blob/master/matlab/GP_innovation_local.m\n '''\n \n # Get the standard deviation at x without noise\n _, stdev_x = self.model.predict(x, with_noise=False)\n\n # Compute the variance between the test point x and the representer points\n sigma_x_rep = self.model.get_covariance_between_points(self.repr_points, x)\n dm_rep = sigma_x_rep / stdev_x\n\n # Compute the deterministic innovation for the variance\n dv_rep = -dm_rep.dot(dm_rep.T)\n return dm_rep, dv_rep", "token_count": 415}
{"added": "2026-12-05", "author": "adobe-apiplatform/umapi-client.py", "created": "2019", "id": "45775534c49974d20b495221", "license": "MIT", "source": "code_search_net", "text": "Return the connection status, both locally and remotely.\n\n The local connection status is a dictionary that gives:\n * the count of multiple queries sent to the server.\n * the count of single queries sent to the server.\n * the count of actions sent to the server.\n * the count of actions executed successfully by the server.\n * the count of actions queued to go to the server.\n\n The remote connection status includes whether the server is live,\n as well as data about version and build. The server data is\n cached, unless the remote flag is specified.\n\n :param remote: whether to query the server for its latest status\n :return: tuple of status dicts: (local, server).\n\ndef status(self, remote=False):\n \"\"\"\n Return the connection status, both locally and remotely.\n\n The local connection status is a dictionary that gives:\n * the count of multiple queries sent to the server.\n * the count of single queries sent to the server.\n * the count of actions sent to the server.\n * the count of actions executed successfully by the server.\n * the count of actions queued to go to the server.\n\n The remote connection status includes whether the server is live,\n as well as data about version and build. The server data is\n cached, unless the remote flag is specified.\n\n :param remote: whether to query the server for its latest status\n :return: tuple of status dicts: (local, server).\n \"\"\"\n if remote:\n components = urlparse.urlparse(self.endpoint)\n try:\n result = self.session.get(components[0] + \"://\" + components[1] + \"/status\", timeout=self.timeout)\n except Exception as e:\n if self.logger: self.logger.debug(\"Failed to connect to server for status: %s\", e)\n result = None\n if result and result.status_code == 200:\n self.server_status = result.json()\n self.server_status[\"endpoint\"] = self.endpoint\n elif result:\n if self.logger: self.logger.debug(\"Server status response not understandable: Status: %d, Body: %s\",\n result.status_code, result.text)\n self.server_status = {\"endpoint\": self.endpoint,\n \"status\": (\"Unexpected HTTP status \" + str(result.status_code) + \" at: \" +\n strftime(\"%d %b %Y %H:%M:%S +0000\", gmtime()))}\n else:\n self.server_status = {\"endpoint\": self.endpoint,\n \"status\": \"Unreachable at: \" + strftime(\"%d %b %Y %H:%M:%S +0000\", gmtime())}\n return self.local_status, self.server_status", "token_count": 559}
{"added": "2026-12-05", "author": "MacHu-GWU/uszipcode-project", "created": "2019", "id": "d78065a9f69915dff5ed3180", "license": "MIT", "source": "code_search_net", "text": "Execute a query, yield result proxy.\n\n :param query: :class:`sqlalchemy.orm.Query`,\n has to be created from ``session.query(Object)``\n\n :return: :class:`sqlalchemy.engine.result.ResultProxy`\n\ndef execute_query_return_result_proxy(query):\n \"\"\"\n Execute a query, yield result proxy.\n\n :param query: :class:`sqlalchemy.orm.Query`,\n has to be created from ``session.query(Object)``\n\n :return: :class:`sqlalchemy.engine.result.ResultProxy`\n \"\"\"\n context = query._compile_context()\n context.statement.use_labels = False\n if query._autoflush and not query._populate_existing:\n query.session._autoflush()\n\n conn = query._get_bind_args(\n context,\n query._connection_from_session,\n close_with_result=True)\n\n return conn.execute(context.statement, query._params)", "token_count": 185}