repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
akfullfo/taskforce | taskforce/httpd.py | BaseServer.register_get | def register_get(self, regex, callback):
"""
Register a regex for processing HTTP GET
requests. If the callback is None, any
existing registration is removed.
"""
if callback is None: # pragma: no cover
... | python | def register_get(self, regex, callback):
"""
Register a regex for processing HTTP GET
requests. If the callback is None, any
existing registration is removed.
"""
if callback is None: # pragma: no cover
... | [
"def",
"register_get",
"(",
"self",
",",
"regex",
",",
"callback",
")",
":",
"if",
"callback",
"is",
"None",
":",
"# pragma: no cover",
"if",
"regex",
"in",
"self",
".",
"get_registrations",
":",
"del",
"self",
".",
"get_registrations",
"[",
"regex",
"]",
... | Register a regex for processing HTTP GET
requests. If the callback is None, any
existing registration is removed. | [
"Register",
"a",
"regex",
"for",
"processing",
"HTTP",
"GET",
"requests",
".",
"If",
"the",
"callback",
"is",
"None",
"any",
"existing",
"registration",
"is",
"removed",
"."
] | train | https://github.com/akfullfo/taskforce/blob/bc6dd744bd33546447d085dbd18a350532220193/taskforce/httpd.py#L206-L216 |
akfullfo/taskforce | taskforce/httpd.py | BaseServer.register_post | def register_post(self, regex, callback):
"""
Register a regex for processing HTTP POST
requests. If the callback is None, any
existing registration is removed.
The callback will be called as:
callback(path, postmap)
"""
if callback is None: ... | python | def register_post(self, regex, callback):
"""
Register a regex for processing HTTP POST
requests. If the callback is None, any
existing registration is removed.
The callback will be called as:
callback(path, postmap)
"""
if callback is None: ... | [
"def",
"register_post",
"(",
"self",
",",
"regex",
",",
"callback",
")",
":",
"if",
"callback",
"is",
"None",
":",
"# pragma: no cover",
"if",
"regex",
"in",
"self",
".",
"post_registrations",
":",
"del",
"self",
".",
"post_registrations",
"[",
"regex",
"]",... | Register a regex for processing HTTP POST
requests. If the callback is None, any
existing registration is removed.
The callback will be called as:
callback(path, postmap) | [
"Register",
"a",
"regex",
"for",
"processing",
"HTTP",
"POST",
"requests",
".",
"If",
"the",
"callback",
"is",
"None",
"any",
"existing",
"registration",
"is",
"removed",
"."
] | train | https://github.com/akfullfo/taskforce/blob/bc6dd744bd33546447d085dbd18a350532220193/taskforce/httpd.py#L218-L232 |
akfullfo/taskforce | taskforce/httpd.py | BaseServer.serve_get | def serve_get(self, path, **params):
"""
Find a GET callback for the given HTTP path, call it and return the
results. The callback is called with two arguments, the path used to
match it, and params which include the BaseHTTPRequestHandler instance.
The callback must return a t... | python | def serve_get(self, path, **params):
"""
Find a GET callback for the given HTTP path, call it and return the
results. The callback is called with two arguments, the path used to
match it, and params which include the BaseHTTPRequestHandler instance.
The callback must return a t... | [
"def",
"serve_get",
"(",
"self",
",",
"path",
",",
"*",
"*",
"params",
")",
":",
"if",
"path",
"is",
"None",
":",
"return",
"None",
"matched",
"=",
"self",
".",
"_match_path",
"(",
"path",
",",
"self",
".",
"get_registrations",
")",
"if",
"matched",
... | Find a GET callback for the given HTTP path, call it and return the
results. The callback is called with two arguments, the path used to
match it, and params which include the BaseHTTPRequestHandler instance.
The callback must return a tuple:
(code, content, content_type)
... | [
"Find",
"a",
"GET",
"callback",
"for",
"the",
"given",
"HTTP",
"path",
"call",
"it",
"and",
"return",
"the",
"results",
".",
"The",
"callback",
"is",
"called",
"with",
"two",
"arguments",
"the",
"path",
"used",
"to",
"match",
"it",
"and",
"params",
"whic... | train | https://github.com/akfullfo/taskforce/blob/bc6dd744bd33546447d085dbd18a350532220193/taskforce/httpd.py#L246-L268 |
akfullfo/taskforce | taskforce/httpd.py | BaseServer.serve_post | def serve_post(self, path, postmap, **params):
"""
Find a POST callback for the given HTTP path, call it and return
the results. The callback is called with the path used to match
it, a dict of vars from the POST body and params which include the
BaseHTTPRequestHandler instance.... | python | def serve_post(self, path, postmap, **params):
"""
Find a POST callback for the given HTTP path, call it and return
the results. The callback is called with the path used to match
it, a dict of vars from the POST body and params which include the
BaseHTTPRequestHandler instance.... | [
"def",
"serve_post",
"(",
"self",
",",
"path",
",",
"postmap",
",",
"*",
"*",
"params",
")",
":",
"matched",
"=",
"self",
".",
"_match_path",
"(",
"path",
",",
"self",
".",
"post_registrations",
")",
"if",
"matched",
"is",
"None",
":",
"# pragma: no cove... | Find a POST callback for the given HTTP path, call it and return
the results. The callback is called with the path used to match
it, a dict of vars from the POST body and params which include the
BaseHTTPRequestHandler instance.
The callback must return a tuple:
(code, con... | [
"Find",
"a",
"POST",
"callback",
"for",
"the",
"given",
"HTTP",
"path",
"call",
"it",
"and",
"return",
"the",
"results",
".",
"The",
"callback",
"is",
"called",
"with",
"the",
"path",
"used",
"to",
"match",
"it",
"a",
"dict",
"of",
"vars",
"from",
"the... | train | https://github.com/akfullfo/taskforce/blob/bc6dd744bd33546447d085dbd18a350532220193/taskforce/httpd.py#L270-L291 |
Sulverus/pydht | pydht/driver.py | get | def get(**kwargs):
"""
Safe sensor wrapper
"""
sensor = None
tick = 0
driver = DHTReader(**kwargs)
while not sensor and tick < TIME_LIMIT:
try:
sensor = driver.receive_data()
except DHTException:
tick += 1
return sensor | python | def get(**kwargs):
"""
Safe sensor wrapper
"""
sensor = None
tick = 0
driver = DHTReader(**kwargs)
while not sensor and tick < TIME_LIMIT:
try:
sensor = driver.receive_data()
except DHTException:
tick += 1
return sensor | [
"def",
"get",
"(",
"*",
"*",
"kwargs",
")",
":",
"sensor",
"=",
"None",
"tick",
"=",
"0",
"driver",
"=",
"DHTReader",
"(",
"*",
"*",
"kwargs",
")",
"while",
"not",
"sensor",
"and",
"tick",
"<",
"TIME_LIMIT",
":",
"try",
":",
"sensor",
"=",
"driver"... | Safe sensor wrapper | [
"Safe",
"sensor",
"wrapper"
] | train | https://github.com/Sulverus/pydht/blob/b83e864378bcfde026ea769daf0564f2737a2b36/pydht/driver.py#L12-L24 |
20c/munge | munge/config.py | parse_url | def parse_url(url, extra_schemes={}):
"""
parse a munge url
type:URL
URL.type
examples:
file.yaml
yaml:file.txt
http://example.com/file.yaml
yaml:http://example.com/file.txt
mysql://user:password@localhost/database/table
django:///home/user/project/... | python | def parse_url(url, extra_schemes={}):
"""
parse a munge url
type:URL
URL.type
examples:
file.yaml
yaml:file.txt
http://example.com/file.yaml
yaml:http://example.com/file.txt
mysql://user:password@localhost/database/table
django:///home/user/project/... | [
"def",
"parse_url",
"(",
"url",
",",
"extra_schemes",
"=",
"{",
"}",
")",
":",
"if",
"not",
"url",
":",
"raise",
"ValueError",
"(",
"'url cannot be empty'",
")",
"cls",
"=",
"None",
"res",
"=",
"urlsplit",
"(",
"url",
")",
"# check config first",
"if",
"... | parse a munge url
type:URL
URL.type
examples:
file.yaml
yaml:file.txt
http://example.com/file.yaml
yaml:http://example.com/file.txt
mysql://user:password@localhost/database/table
django:///home/user/project/settings_dir.settings/app_name/model | [
"parse",
"a",
"munge",
"url"
] | train | https://github.com/20c/munge/blob/e20fef8c24e48d4b0a5c387820fbb2b7bebb0af0/munge/config.py#L211-L259 |
20c/munge | munge/config.py | Config.get_nested | def get_nested(self, *args):
"""
get a nested value, returns None if path does not exist
"""
data = self.data
for key in args:
if key not in data:
return None
data = data[key]
return data | python | def get_nested(self, *args):
"""
get a nested value, returns None if path does not exist
"""
data = self.data
for key in args:
if key not in data:
return None
data = data[key]
return data | [
"def",
"get_nested",
"(",
"self",
",",
"*",
"args",
")",
":",
"data",
"=",
"self",
".",
"data",
"for",
"key",
"in",
"args",
":",
"if",
"key",
"not",
"in",
"data",
":",
"return",
"None",
"data",
"=",
"data",
"[",
"key",
"]",
"return",
"data"
] | get a nested value, returns None if path does not exist | [
"get",
"a",
"nested",
"value",
"returns",
"None",
"if",
"path",
"does",
"not",
"exist"
] | train | https://github.com/20c/munge/blob/e20fef8c24e48d4b0a5c387820fbb2b7bebb0af0/munge/config.py#L84-L93 |
20c/munge | munge/config.py | Config.read | def read(self, config_dir=None, config_name=None, clear=False):
"""
read config from config_dir
if config_dir is None, clear to default config
clear will clear to default before reading new file
"""
# TODO should probably allow config_dir to be a list as well
# get name ... | python | def read(self, config_dir=None, config_name=None, clear=False):
"""
read config from config_dir
if config_dir is None, clear to default config
clear will clear to default before reading new file
"""
# TODO should probably allow config_dir to be a list as well
# get name ... | [
"def",
"read",
"(",
"self",
",",
"config_dir",
"=",
"None",
",",
"config_name",
"=",
"None",
",",
"clear",
"=",
"False",
")",
":",
"# TODO should probably allow config_dir to be a list as well",
"# get name of config directory",
"if",
"not",
"config_dir",
":",
"config... | read config from config_dir
if config_dir is None, clear to default config
clear will clear to default before reading new file | [
"read",
"config",
"from",
"config_dir",
"if",
"config_dir",
"is",
"None",
"clear",
"to",
"default",
"config",
"clear",
"will",
"clear",
"to",
"default",
"before",
"reading",
"new",
"file"
] | train | https://github.com/20c/munge/blob/e20fef8c24e48d4b0a5c387820fbb2b7bebb0af0/munge/config.py#L111-L145 |
20c/munge | munge/config.py | Config.try_read | def try_read(self, config_dir=None, **kwargs):
"""
try reading without throwing an error
config_dir may be a list of directories to try in order, if so it
will return after the first successful read
other args will be passed direction to read()
"""
if isinstance(c... | python | def try_read(self, config_dir=None, **kwargs):
"""
try reading without throwing an error
config_dir may be a list of directories to try in order, if so it
will return after the first successful read
other args will be passed direction to read()
"""
if isinstance(c... | [
"def",
"try_read",
"(",
"self",
",",
"config_dir",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"config_dir",
",",
"basestring",
")",
":",
"config_dir",
"=",
"(",
"config_dir",
",",
")",
"for",
"cdir",
"in",
"config_dir",
":... | try reading without throwing an error
config_dir may be a list of directories to try in order, if so it
will return after the first successful read
other args will be passed direction to read() | [
"try",
"reading",
"without",
"throwing",
"an",
"error",
"config_dir",
"may",
"be",
"a",
"list",
"of",
"directories",
"to",
"try",
"in",
"order",
"if",
"so",
"it",
"will",
"return",
"after",
"the",
"first",
"successful",
"read",
"other",
"args",
"will",
"be... | train | https://github.com/20c/munge/blob/e20fef8c24e48d4b0a5c387820fbb2b7bebb0af0/munge/config.py#L147-L163 |
20c/munge | munge/config.py | Config.write | def write(self, config_dir=None, config_name=None, codec=None):
"""
writes config to config_dir using config_name
"""
# get name of config directory
if not config_dir:
config_dir = self._meta_config_dir
if not config_dir:
raise IOError("con... | python | def write(self, config_dir=None, config_name=None, codec=None):
"""
writes config to config_dir using config_name
"""
# get name of config directory
if not config_dir:
config_dir = self._meta_config_dir
if not config_dir:
raise IOError("con... | [
"def",
"write",
"(",
"self",
",",
"config_dir",
"=",
"None",
",",
"config_name",
"=",
"None",
",",
"codec",
"=",
"None",
")",
":",
"# get name of config directory",
"if",
"not",
"config_dir",
":",
"config_dir",
"=",
"self",
".",
"_meta_config_dir",
"if",
"no... | writes config to config_dir using config_name | [
"writes",
"config",
"to",
"config_dir",
"using",
"config_name"
] | train | https://github.com/20c/munge/blob/e20fef8c24e48d4b0a5c387820fbb2b7bebb0af0/munge/config.py#L165-L190 |
brosner/django-gunicorn | django_gunicorn/management/commands/runserver.py | Command.get_handler | def get_handler(self, *args, **options):
"""
Returns the default WSGI handler for the runner.
"""
handler = get_internal_wsgi_application()
from django.contrib.staticfiles.handlers import StaticFilesHandler
return StaticFilesHandler(handler) | python | def get_handler(self, *args, **options):
"""
Returns the default WSGI handler for the runner.
"""
handler = get_internal_wsgi_application()
from django.contrib.staticfiles.handlers import StaticFilesHandler
return StaticFilesHandler(handler) | [
"def",
"get_handler",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"options",
")",
":",
"handler",
"=",
"get_internal_wsgi_application",
"(",
")",
"from",
"django",
".",
"contrib",
".",
"staticfiles",
".",
"handlers",
"import",
"StaticFilesHandler",
"return",... | Returns the default WSGI handler for the runner. | [
"Returns",
"the",
"default",
"WSGI",
"handler",
"for",
"the",
"runner",
"."
] | train | https://github.com/brosner/django-gunicorn/blob/2284688c9c3f867cbb7f87d851c9d904df7e2189/django_gunicorn/management/commands/runserver.py#L29-L35 |
abbot/m2ext | m2ext/SSL.py | Context.validate_certificate | def validate_certificate(self, cert):
"""
Validate a certificate using this SSL Context
"""
store_ctx = X509.X509_Store_Context(_m2ext.x509_store_ctx_new(), _pyfree=1)
_m2ext.x509_store_ctx_init(store_ctx.ctx,
self.get_cert_store().store,
... | python | def validate_certificate(self, cert):
"""
Validate a certificate using this SSL Context
"""
store_ctx = X509.X509_Store_Context(_m2ext.x509_store_ctx_new(), _pyfree=1)
_m2ext.x509_store_ctx_init(store_ctx.ctx,
self.get_cert_store().store,
... | [
"def",
"validate_certificate",
"(",
"self",
",",
"cert",
")",
":",
"store_ctx",
"=",
"X509",
".",
"X509_Store_Context",
"(",
"_m2ext",
".",
"x509_store_ctx_new",
"(",
")",
",",
"_pyfree",
"=",
"1",
")",
"_m2ext",
".",
"x509_store_ctx_init",
"(",
"store_ctx",
... | Validate a certificate using this SSL Context | [
"Validate",
"a",
"certificate",
"using",
"this",
"SSL",
"Context"
] | train | https://github.com/abbot/m2ext/blob/f56394240240fcda0b2abc14d69916d357c1c36e/m2ext/SSL.py#L5-L16 |
PMBio/limix-backup | limix/mtSet/iset.py | fit_iSet | def fit_iSet(Y, U_R=None, S_R=None, covs=None, Xr=None, n_perms=0, Ie=None,
strat=False, verbose=True):
"""
Args:
Y: [N, P] phenotype matrix
S_R: N vector of eigenvalues of R
U_R: [N, N] eigenvector matrix of R
covs: [N, K] matrix for K c... | python | def fit_iSet(Y, U_R=None, S_R=None, covs=None, Xr=None, n_perms=0, Ie=None,
strat=False, verbose=True):
"""
Args:
Y: [N, P] phenotype matrix
S_R: N vector of eigenvalues of R
U_R: [N, N] eigenvector matrix of R
covs: [N, K] matrix for K c... | [
"def",
"fit_iSet",
"(",
"Y",
",",
"U_R",
"=",
"None",
",",
"S_R",
"=",
"None",
",",
"covs",
"=",
"None",
",",
"Xr",
"=",
"None",
",",
"n_perms",
"=",
"0",
",",
"Ie",
"=",
"None",
",",
"strat",
"=",
"False",
",",
"verbose",
"=",
"True",
")",
"... | Args:
Y: [N, P] phenotype matrix
S_R: N vector of eigenvalues of R
U_R: [N, N] eigenvector matrix of R
covs: [N, K] matrix for K covariates
Xr: [N, S] genotype data of the set component
n_perms: number of permutations to consider
... | [
"Args",
":",
"Y",
":",
"[",
"N",
"P",
"]",
"phenotype",
"matrix",
"S_R",
":",
"N",
"vector",
"of",
"eigenvalues",
"of",
"R",
"U_R",
":",
"[",
"N",
"N",
"]",
"eigenvector",
"matrix",
"of",
"R",
"covs",
":",
"[",
"N",
"K",
"]",
"matrix",
"for",
"... | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/mtSet/iset.py#L13-L102 |
inveniosoftware-contrib/invenio-classifier | invenio_classifier/extractor.py | is_pdf | def is_pdf(document):
"""Check if a document is a PDF file and return True if is is."""
if not executable_exists('pdftotext'):
current_app.logger.warning(
"GNU file was not found on the system. "
"Switching to a weak file extension test."
)
if document.lower().end... | python | def is_pdf(document):
"""Check if a document is a PDF file and return True if is is."""
if not executable_exists('pdftotext'):
current_app.logger.warning(
"GNU file was not found on the system. "
"Switching to a weak file extension test."
)
if document.lower().end... | [
"def",
"is_pdf",
"(",
"document",
")",
":",
"if",
"not",
"executable_exists",
"(",
"'pdftotext'",
")",
":",
"current_app",
".",
"logger",
".",
"warning",
"(",
"\"GNU file was not found on the system. \"",
"\"Switching to a weak file extension test.\"",
")",
"if",
"docum... | Check if a document is a PDF file and return True if is is. | [
"Check",
"if",
"a",
"document",
"is",
"a",
"PDF",
"file",
"and",
"return",
"True",
"if",
"is",
"is",
"."
] | train | https://github.com/inveniosoftware-contrib/invenio-classifier/blob/3c758cf34dca6bf0548e7da5de34e5f72e3b255e/invenio_classifier/extractor.py#L41-L68 |
inveniosoftware-contrib/invenio-classifier | invenio_classifier/extractor.py | text_lines_from_local_file | def text_lines_from_local_file(document, remote=False):
"""Return the fulltext of the local file.
@param document: fullpath to the file that should be read
@param remote: boolean, if True does not count lines
@return: list of lines if st was read or an empty list
"""
try:
if is_pdf(doc... | python | def text_lines_from_local_file(document, remote=False):
"""Return the fulltext of the local file.
@param document: fullpath to the file that should be read
@param remote: boolean, if True does not count lines
@return: list of lines if st was read or an empty list
"""
try:
if is_pdf(doc... | [
"def",
"text_lines_from_local_file",
"(",
"document",
",",
"remote",
"=",
"False",
")",
":",
"try",
":",
"if",
"is_pdf",
"(",
"document",
")",
":",
"if",
"not",
"executable_exists",
"(",
"\"pdftotext\"",
")",
":",
"current_app",
".",
"logger",
".",
"error",
... | Return the fulltext of the local file.
@param document: fullpath to the file that should be read
@param remote: boolean, if True does not count lines
@return: list of lines if st was read or an empty list | [
"Return",
"the",
"fulltext",
"of",
"the",
"local",
"file",
"."
] | train | https://github.com/inveniosoftware-contrib/invenio-classifier/blob/3c758cf34dca6bf0548e7da5de34e5f72e3b255e/invenio_classifier/extractor.py#L71-L107 |
inveniosoftware-contrib/invenio-classifier | invenio_classifier/extractor.py | executable_exists | def executable_exists(executable):
"""Test if an executable is available on the system."""
for directory in os.getenv("PATH").split(":"):
if os.path.exists(os.path.join(directory, executable)):
return True
return False | python | def executable_exists(executable):
"""Test if an executable is available on the system."""
for directory in os.getenv("PATH").split(":"):
if os.path.exists(os.path.join(directory, executable)):
return True
return False | [
"def",
"executable_exists",
"(",
"executable",
")",
":",
"for",
"directory",
"in",
"os",
".",
"getenv",
"(",
"\"PATH\"",
")",
".",
"split",
"(",
"\":\"",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"os",
".",
"path",
".",
"join",
"(",
"d... | Test if an executable is available on the system. | [
"Test",
"if",
"an",
"executable",
"is",
"available",
"on",
"the",
"system",
"."
] | train | https://github.com/inveniosoftware-contrib/invenio-classifier/blob/3c758cf34dca6bf0548e7da5de34e5f72e3b255e/invenio_classifier/extractor.py#L110-L115 |
inveniosoftware-contrib/invenio-classifier | invenio_classifier/extractor.py | get_plaintext_document_body | def get_plaintext_document_body(fpath, keep_layout=False):
"""Given a file-path to a full-text, return a list of unicode strings.
Each string is a line of the fulltext.
In the case of a plain-text document, this simply means reading the
contents in from the file. In the case of a PDF/PostScript however... | python | def get_plaintext_document_body(fpath, keep_layout=False):
"""Given a file-path to a full-text, return a list of unicode strings.
Each string is a line of the fulltext.
In the case of a plain-text document, this simply means reading the
contents in from the file. In the case of a PDF/PostScript however... | [
"def",
"get_plaintext_document_body",
"(",
"fpath",
",",
"keep_layout",
"=",
"False",
")",
":",
"textbody",
"=",
"[",
"]",
"status",
"=",
"0",
"if",
"os",
".",
"access",
"(",
"fpath",
",",
"os",
".",
"F_OK",
"|",
"os",
".",
"R_OK",
")",
":",
"# filep... | Given a file-path to a full-text, return a list of unicode strings.
Each string is a line of the fulltext.
In the case of a plain-text document, this simply means reading the
contents in from the file. In the case of a PDF/PostScript however,
this means converting the document to plaintext.
:param... | [
"Given",
"a",
"file",
"-",
"path",
"to",
"a",
"full",
"-",
"text",
"return",
"a",
"list",
"of",
"unicode",
"strings",
"."
] | train | https://github.com/inveniosoftware-contrib/invenio-classifier/blob/3c758cf34dca6bf0548e7da5de34e5f72e3b255e/invenio_classifier/extractor.py#L118-L159 |
inveniosoftware-contrib/invenio-classifier | invenio_classifier/extractor.py | convert_PDF_to_plaintext | def convert_PDF_to_plaintext(fpath, keep_layout=False):
"""Convert PDF to txt using pdftotext.
Take the path to a PDF file and run pdftotext for this file, capturing
the output.
:param fpath: (string) path to the PDF file
:return: (list) of unicode strings (contents of the PDF file translated
... | python | def convert_PDF_to_plaintext(fpath, keep_layout=False):
"""Convert PDF to txt using pdftotext.
Take the path to a PDF file and run pdftotext for this file, capturing
the output.
:param fpath: (string) path to the PDF file
:return: (list) of unicode strings (contents of the PDF file translated
... | [
"def",
"convert_PDF_to_plaintext",
"(",
"fpath",
",",
"keep_layout",
"=",
"False",
")",
":",
"if",
"keep_layout",
":",
"layout_option",
"=",
"\"-layout\"",
"else",
":",
"layout_option",
"=",
"\"-raw\"",
"status",
"=",
"0",
"doclines",
"=",
"[",
"]",
"# Pattern... | Convert PDF to txt using pdftotext.
Take the path to a PDF file and run pdftotext for this file, capturing
the output.
:param fpath: (string) path to the PDF file
:return: (list) of unicode strings (contents of the PDF file translated
into plaintext; each string is a line in the document.) | [
"Convert",
"PDF",
"to",
"txt",
"using",
"pdftotext",
"."
] | train | https://github.com/inveniosoftware-contrib/invenio-classifier/blob/3c758cf34dca6bf0548e7da5de34e5f72e3b255e/invenio_classifier/extractor.py#L162-L215 |
inveniosoftware-contrib/invenio-classifier | invenio_classifier/extractor.py | pdftotext_conversion_is_bad | def pdftotext_conversion_is_bad(txtlines):
"""Check if conversion after pdftotext is bad.
Sometimes pdftotext performs a bad conversion which consists of many
spaces and garbage characters.
This method takes a list of strings obtained from a pdftotext conversion
and examines them to see if they ar... | python | def pdftotext_conversion_is_bad(txtlines):
"""Check if conversion after pdftotext is bad.
Sometimes pdftotext performs a bad conversion which consists of many
spaces and garbage characters.
This method takes a list of strings obtained from a pdftotext conversion
and examines them to see if they ar... | [
"def",
"pdftotext_conversion_is_bad",
"(",
"txtlines",
")",
":",
"# Numbers of 'words' and 'whitespaces' found in document:",
"numWords",
"=",
"numSpaces",
"=",
"0",
"# whitespace character pattern:",
"p_space",
"=",
"re",
".",
"compile",
"(",
"unicode",
"(",
"r'(\\s)'",
... | Check if conversion after pdftotext is bad.
Sometimes pdftotext performs a bad conversion which consists of many
spaces and garbage characters.
This method takes a list of strings obtained from a pdftotext conversion
and examines them to see if they are likely to be the result of a bad
conversion.... | [
"Check",
"if",
"conversion",
"after",
"pdftotext",
"is",
"bad",
"."
] | train | https://github.com/inveniosoftware-contrib/invenio-classifier/blob/3c758cf34dca6bf0548e7da5de34e5f72e3b255e/invenio_classifier/extractor.py#L218-L245 |
PMBio/limix-backup | limix/mtSet/core/read_utils.py | readBimFile | def readBimFile(basefilename):
"""
Helper fuinction that reads bim files
"""
# read bim file
bim_fn = basefilename+'.bim'
rv = SP.loadtxt(bim_fn,delimiter='\t',usecols = (0,3),dtype=int)
return rv | python | def readBimFile(basefilename):
"""
Helper fuinction that reads bim files
"""
# read bim file
bim_fn = basefilename+'.bim'
rv = SP.loadtxt(bim_fn,delimiter='\t',usecols = (0,3),dtype=int)
return rv | [
"def",
"readBimFile",
"(",
"basefilename",
")",
":",
"# read bim file",
"bim_fn",
"=",
"basefilename",
"+",
"'.bim'",
"rv",
"=",
"SP",
".",
"loadtxt",
"(",
"bim_fn",
",",
"delimiter",
"=",
"'\\t'",
",",
"usecols",
"=",
"(",
"0",
",",
"3",
")",
",",
"dt... | Helper fuinction that reads bim files | [
"Helper",
"fuinction",
"that",
"reads",
"bim",
"files"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/mtSet/core/read_utils.py#L4-L11 |
PMBio/limix-backup | limix/mtSet/core/read_utils.py | readCovarianceMatrixFile | def readCovarianceMatrixFile(cfile,readCov=True,readEig=True):
""""
reading in similarity matrix
cfile File containing the covariance matrix. The corresponding ID file must be specified in cfile.id)
"""
covFile = cfile+'.cov'
evalFile = cfile+'.cov.eval'
evecFile = cfile+'.cov.evec'
... | python | def readCovarianceMatrixFile(cfile,readCov=True,readEig=True):
""""
reading in similarity matrix
cfile File containing the covariance matrix. The corresponding ID file must be specified in cfile.id)
"""
covFile = cfile+'.cov'
evalFile = cfile+'.cov.eval'
evecFile = cfile+'.cov.evec'
... | [
"def",
"readCovarianceMatrixFile",
"(",
"cfile",
",",
"readCov",
"=",
"True",
",",
"readEig",
"=",
"True",
")",
":",
"covFile",
"=",
"cfile",
"+",
"'.cov'",
"evalFile",
"=",
"cfile",
"+",
"'.cov.eval'",
"evecFile",
"=",
"cfile",
"+",
"'.cov.evec'",
"RV",
"... | reading in similarity matrix
cfile File containing the covariance matrix. The corresponding ID file must be specified in cfile.id) | [
"reading",
"in",
"similarity",
"matrix"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/mtSet/core/read_utils.py#L13-L33 |
PMBio/limix-backup | limix/mtSet/core/read_utils.py | readCovariatesFile | def readCovariatesFile(fFile):
""""
reading in covariate file
cfile file containing the fixed effects as NxP matrix
(N=number of samples, P=number of covariates)
"""
assert os.path.exists(fFile), '%s is missing.'%fFile
F = SP.loadtxt(fFile)
if F.ndim==1: F=F[:,SP.newaxis]
... | python | def readCovariatesFile(fFile):
""""
reading in covariate file
cfile file containing the fixed effects as NxP matrix
(N=number of samples, P=number of covariates)
"""
assert os.path.exists(fFile), '%s is missing.'%fFile
F = SP.loadtxt(fFile)
if F.ndim==1: F=F[:,SP.newaxis]
... | [
"def",
"readCovariatesFile",
"(",
"fFile",
")",
":",
"assert",
"os",
".",
"path",
".",
"exists",
"(",
"fFile",
")",
",",
"'%s is missing.'",
"%",
"fFile",
"F",
"=",
"SP",
".",
"loadtxt",
"(",
"fFile",
")",
"if",
"F",
".",
"ndim",
"==",
"1",
":",
"F... | reading in covariate file
cfile file containing the fixed effects as NxP matrix
(N=number of samples, P=number of covariates) | [
"reading",
"in",
"covariate",
"file"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/mtSet/core/read_utils.py#L36-L46 |
PMBio/limix-backup | limix/mtSet/core/read_utils.py | readPhenoFile | def readPhenoFile(pfile,idx=None):
""""
reading in phenotype file
pfile root of the file containing the phenotypes as NxP matrix
(N=number of samples, P=number of traits)
"""
usecols = None
if idx!=None:
""" different traits are comma-seperated """
usecols = [int(... | python | def readPhenoFile(pfile,idx=None):
""""
reading in phenotype file
pfile root of the file containing the phenotypes as NxP matrix
(N=number of samples, P=number of traits)
"""
usecols = None
if idx!=None:
""" different traits are comma-seperated """
usecols = [int(... | [
"def",
"readPhenoFile",
"(",
"pfile",
",",
"idx",
"=",
"None",
")",
":",
"usecols",
"=",
"None",
"if",
"idx",
"!=",
"None",
":",
"\"\"\" different traits are comma-seperated \"\"\"",
"usecols",
"=",
"[",
"int",
"(",
"x",
")",
"for",
"x",
"in",
"idx",
".",
... | reading in phenotype file
pfile root of the file containing the phenotypes as NxP matrix
(N=number of samples, P=number of traits) | [
"reading",
"in",
"phenotype",
"file"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/mtSet/core/read_utils.py#L49-L68 |
PMBio/limix-backup | limix/mtSet/core/read_utils.py | readNullModelFile | def readNullModelFile(nfile):
""""
reading file with null model info
nfile File containing null model info
"""
params0_file = nfile+'.p0'
nll0_file = nfile+'.nll0'
assert os.path.exists(params0_file), '%s is missing.'%params0_file
assert os.path.exists(nll0_file), '%s is missing.'%nl... | python | def readNullModelFile(nfile):
""""
reading file with null model info
nfile File containing null model info
"""
params0_file = nfile+'.p0'
nll0_file = nfile+'.nll0'
assert os.path.exists(params0_file), '%s is missing.'%params0_file
assert os.path.exists(nll0_file), '%s is missing.'%nl... | [
"def",
"readNullModelFile",
"(",
"nfile",
")",
":",
"params0_file",
"=",
"nfile",
"+",
"'.p0'",
"nll0_file",
"=",
"nfile",
"+",
"'.nll0'",
"assert",
"os",
".",
"path",
".",
"exists",
"(",
"params0_file",
")",
",",
"'%s is missing.'",
"%",
"params0_file",
"as... | reading file with null model info
nfile File containing null model info | [
"reading",
"file",
"with",
"null",
"model",
"info"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/mtSet/core/read_utils.py#L70-L90 |
PMBio/limix-backup | limix/mtSet/core/read_utils.py | readWindowsFile | def readWindowsFile(wfile):
""""
reading file with windows
wfile File containing window info
"""
window_file = wfile+'.wnd'
assert os.path.exists(window_file), '%s is missing.'%window_file
rv = SP.loadtxt(window_file)
return rv | python | def readWindowsFile(wfile):
""""
reading file with windows
wfile File containing window info
"""
window_file = wfile+'.wnd'
assert os.path.exists(window_file), '%s is missing.'%window_file
rv = SP.loadtxt(window_file)
return rv | [
"def",
"readWindowsFile",
"(",
"wfile",
")",
":",
"window_file",
"=",
"wfile",
"+",
"'.wnd'",
"assert",
"os",
".",
"path",
".",
"exists",
"(",
"window_file",
")",
",",
"'%s is missing.'",
"%",
"window_file",
"rv",
"=",
"SP",
".",
"loadtxt",
"(",
"window_fi... | reading file with windows
wfile File containing window info | [
"reading",
"file",
"with",
"windows"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/mtSet/core/read_utils.py#L92-L101 |
goshuirc/irc | girc/formatting.py | extract_irc_colours | def extract_irc_colours(msg):
"""Extract the IRC colours from the start of the string.
Extracts the colours from the start, and returns the colour code in our
format, and then the rest of the message.
"""
# first colour
fore, msg = _extract_irc_colour_code(msg)
if not fore:
return ... | python | def extract_irc_colours(msg):
"""Extract the IRC colours from the start of the string.
Extracts the colours from the start, and returns the colour code in our
format, and then the rest of the message.
"""
# first colour
fore, msg = _extract_irc_colour_code(msg)
if not fore:
return ... | [
"def",
"extract_irc_colours",
"(",
"msg",
")",
":",
"# first colour",
"fore",
",",
"msg",
"=",
"_extract_irc_colour_code",
"(",
"msg",
")",
"if",
"not",
"fore",
":",
"return",
"'[]'",
",",
"msg",
"if",
"not",
"len",
"(",
"msg",
")",
"or",
"msg",
"[",
"... | Extract the IRC colours from the start of the string.
Extracts the colours from the start, and returns the colour code in our
format, and then the rest of the message. | [
"Extract",
"the",
"IRC",
"colours",
"from",
"the",
"start",
"of",
"the",
"string",
"."
] | train | https://github.com/goshuirc/irc/blob/d6a5e3e04d337566c009b087f108cd76f9e122cc/girc/formatting.py#L59-L81 |
goshuirc/irc | girc/formatting.py | extract_girc_colours | def extract_girc_colours(msg, fill_last):
"""Extract the girc-formatted colours from the start of the string.
Extracts the colours from the start, and returns the colour code in IRC
format, and then the rest of the message.
If `fill_last`, last number must be zero-padded.
"""
if not len(msg):
... | python | def extract_girc_colours(msg, fill_last):
"""Extract the girc-formatted colours from the start of the string.
Extracts the colours from the start, and returns the colour code in IRC
format, and then the rest of the message.
If `fill_last`, last number must be zero-padded.
"""
if not len(msg):
... | [
"def",
"extract_girc_colours",
"(",
"msg",
",",
"fill_last",
")",
":",
"if",
"not",
"len",
"(",
"msg",
")",
":",
"return",
"''",
",",
"''",
"if",
"']'",
"not",
"in",
"msg",
"or",
"not",
"msg",
".",
"startswith",
"(",
"'['",
")",
":",
"return",
"''"... | Extract the girc-formatted colours from the start of the string.
Extracts the colours from the start, and returns the colour code in IRC
format, and then the rest of the message.
If `fill_last`, last number must be zero-padded. | [
"Extract",
"the",
"girc",
"-",
"formatted",
"colours",
"from",
"the",
"start",
"of",
"the",
"string",
"."
] | train | https://github.com/goshuirc/irc/blob/d6a5e3e04d337566c009b087f108cd76f9e122cc/girc/formatting.py#L84-L114 |
goshuirc/irc | girc/formatting.py | escape | def escape(msg):
"""Takes a raw IRC message and returns a girc-escaped message."""
msg = msg.replace(escape_character, 'girc-escaped-character')
for escape_key, irc_char in format_dict.items():
msg = msg.replace(irc_char, escape_character + escape_key)
# convert colour codes
new_msg = ''
... | python | def escape(msg):
"""Takes a raw IRC message and returns a girc-escaped message."""
msg = msg.replace(escape_character, 'girc-escaped-character')
for escape_key, irc_char in format_dict.items():
msg = msg.replace(irc_char, escape_character + escape_key)
# convert colour codes
new_msg = ''
... | [
"def",
"escape",
"(",
"msg",
")",
":",
"msg",
"=",
"msg",
".",
"replace",
"(",
"escape_character",
",",
"'girc-escaped-character'",
")",
"for",
"escape_key",
",",
"irc_char",
"in",
"format_dict",
".",
"items",
"(",
")",
":",
"msg",
"=",
"msg",
".",
"repl... | Takes a raw IRC message and returns a girc-escaped message. | [
"Takes",
"a",
"raw",
"IRC",
"message",
"and",
"returns",
"a",
"girc",
"-",
"escaped",
"message",
"."
] | train | https://github.com/goshuirc/irc/blob/d6a5e3e04d337566c009b087f108cd76f9e122cc/girc/formatting.py#L117-L141 |
goshuirc/irc | girc/formatting.py | _get_from_format_dict | def _get_from_format_dict(format_dict, key):
"""Return a value from our format dict."""
if isinstance(format_dict[key], str):
return format_dict[key]
elif isinstance(format_dict[key], (list, tuple)):
fn_list = list(format_dict[key])
function = fn_list.pop(0)
if len(fn_list):... | python | def _get_from_format_dict(format_dict, key):
"""Return a value from our format dict."""
if isinstance(format_dict[key], str):
return format_dict[key]
elif isinstance(format_dict[key], (list, tuple)):
fn_list = list(format_dict[key])
function = fn_list.pop(0)
if len(fn_list):... | [
"def",
"_get_from_format_dict",
"(",
"format_dict",
",",
"key",
")",
":",
"if",
"isinstance",
"(",
"format_dict",
"[",
"key",
"]",
",",
"str",
")",
":",
"return",
"format_dict",
"[",
"key",
"]",
"elif",
"isinstance",
"(",
"format_dict",
"[",
"key",
"]",
... | Return a value from our format dict. | [
"Return",
"a",
"value",
"from",
"our",
"format",
"dict",
"."
] | train | https://github.com/goshuirc/irc/blob/d6a5e3e04d337566c009b087f108cd76f9e122cc/girc/formatting.py#L144-L162 |
goshuirc/irc | girc/formatting.py | unescape | def unescape(msg, extra_format_dict={}):
"""Takes a girc-escaped message and returns a raw IRC message"""
new_msg = ''
extra_format_dict.update(format_dict)
while len(msg):
char = msg[0]
msg = msg[1:]
if char == escape_character:
escape_key = msg[0]
msg ... | python | def unescape(msg, extra_format_dict={}):
"""Takes a girc-escaped message and returns a raw IRC message"""
new_msg = ''
extra_format_dict.update(format_dict)
while len(msg):
char = msg[0]
msg = msg[1:]
if char == escape_character:
escape_key = msg[0]
msg ... | [
"def",
"unescape",
"(",
"msg",
",",
"extra_format_dict",
"=",
"{",
"}",
")",
":",
"new_msg",
"=",
"''",
"extra_format_dict",
".",
"update",
"(",
"format_dict",
")",
"while",
"len",
"(",
"msg",
")",
":",
"char",
"=",
"msg",
"[",
"0",
"]",
"msg",
"=",
... | Takes a girc-escaped message and returns a raw IRC message | [
"Takes",
"a",
"girc",
"-",
"escaped",
"message",
"and",
"returns",
"a",
"raw",
"IRC",
"message"
] | train | https://github.com/goshuirc/irc/blob/d6a5e3e04d337566c009b087f108cd76f9e122cc/girc/formatting.py#L165-L207 |
goshuirc/irc | girc/formatting.py | remove_formatting_codes | def remove_formatting_codes(line, irc=False):
"""Remove girc control codes from the given line."""
if irc:
line = escape(line)
new_line = ''
while len(line) > 0:
try:
if line[0] == '$':
line = line[1:]
if line[0] == '$':
ne... | python | def remove_formatting_codes(line, irc=False):
"""Remove girc control codes from the given line."""
if irc:
line = escape(line)
new_line = ''
while len(line) > 0:
try:
if line[0] == '$':
line = line[1:]
if line[0] == '$':
ne... | [
"def",
"remove_formatting_codes",
"(",
"line",
",",
"irc",
"=",
"False",
")",
":",
"if",
"irc",
":",
"line",
"=",
"escape",
"(",
"line",
")",
"new_line",
"=",
"''",
"while",
"len",
"(",
"line",
")",
">",
"0",
":",
"try",
":",
"if",
"line",
"[",
"... | Remove girc control codes from the given line. | [
"Remove",
"girc",
"control",
"codes",
"from",
"the",
"given",
"line",
"."
] | train | https://github.com/goshuirc/irc/blob/d6a5e3e04d337566c009b087f108cd76f9e122cc/girc/formatting.py#L210-L264 |
PMBio/limix-backup | limix/mtSet/core/simulator.py | CSimulator.getRegion | def getRegion(self,size=3e4,min_nSNPs=1,chrom_i=None,pos_min=None,pos_max=None):
"""
Sample a region from the piece of genotype X, chrom, pos
minSNPnum: minimum number of SNPs contained in the region
Ichrom: restrict X to chromosome Ichrom before taking the region
cis: b... | python | def getRegion(self,size=3e4,min_nSNPs=1,chrom_i=None,pos_min=None,pos_max=None):
"""
Sample a region from the piece of genotype X, chrom, pos
minSNPnum: minimum number of SNPs contained in the region
Ichrom: restrict X to chromosome Ichrom before taking the region
cis: b... | [
"def",
"getRegion",
"(",
"self",
",",
"size",
"=",
"3e4",
",",
"min_nSNPs",
"=",
"1",
",",
"chrom_i",
"=",
"None",
",",
"pos_min",
"=",
"None",
",",
"pos_max",
"=",
"None",
")",
":",
"if",
"(",
"self",
".",
"chrom",
"is",
"None",
")",
"or",
"(",
... | Sample a region from the piece of genotype X, chrom, pos
minSNPnum: minimum number of SNPs contained in the region
Ichrom: restrict X to chromosome Ichrom before taking the region
cis: bool vector that marks the sorted region
region: vector that contains chrom and init and fina... | [
"Sample",
"a",
"region",
"from",
"the",
"piece",
"of",
"genotype",
"X",
"chrom",
"pos",
"minSNPnum",
":",
"minimum",
"number",
"of",
"SNPs",
"contained",
"in",
"the",
"region",
"Ichrom",
":",
"restrict",
"X",
"to",
"chromosome",
"Ichrom",
"before",
"taking",... | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/mtSet/core/simulator.py#L48-L106 |
PMBio/limix-backup | limix/mtSet/core/simulator.py | CSimulator.genRegionTerm | def genRegionTerm(self,X,vTot=0.1,pCausal=0.10,nCausal=None,pCommon=1.,nCommon=None,plot=False,distribution='biNormal'):
"""
Generate population structure term
Population structure is simulated by background SNPs
beta_pdf: pdf used to generate the regression weights
... | python | def genRegionTerm(self,X,vTot=0.1,pCausal=0.10,nCausal=None,pCommon=1.,nCommon=None,plot=False,distribution='biNormal'):
"""
Generate population structure term
Population structure is simulated by background SNPs
beta_pdf: pdf used to generate the regression weights
... | [
"def",
"genRegionTerm",
"(",
"self",
",",
"X",
",",
"vTot",
"=",
"0.1",
",",
"pCausal",
"=",
"0.10",
",",
"nCausal",
"=",
"None",
",",
"pCommon",
"=",
"1.",
",",
"nCommon",
"=",
"None",
",",
"plot",
"=",
"False",
",",
"distribution",
"=",
"'biNormal'... | Generate population structure term
Population structure is simulated by background SNPs
beta_pdf: pdf used to generate the regression weights
for now either Normal or fixed
variance: variance of the term
percCausal: percentage of causal SNPs
... | [
"Generate",
"population",
"structure",
"term",
"Population",
"structure",
"is",
"simulated",
"by",
"background",
"SNPs"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/mtSet/core/simulator.py#L109-L171 |
PMBio/limix-backup | limix/mtSet/core/simulator.py | CSimulator._genBgTerm_fromSNPs | def _genBgTerm_fromSNPs(self,vTot=0.5,vCommon=0.1,pCausal=0.5,plot=False):
""" generate """
if self.X is None:
print('Reading in all SNPs. This is slow.')
rv = plink_reader.readBED(self.bfile,useMAFencoding=True)
X = rv['snps']
else:
X = self.X... | python | def _genBgTerm_fromSNPs(self,vTot=0.5,vCommon=0.1,pCausal=0.5,plot=False):
""" generate """
if self.X is None:
print('Reading in all SNPs. This is slow.')
rv = plink_reader.readBED(self.bfile,useMAFencoding=True)
X = rv['snps']
else:
X = self.X... | [
"def",
"_genBgTerm_fromSNPs",
"(",
"self",
",",
"vTot",
"=",
"0.5",
",",
"vCommon",
"=",
"0.1",
",",
"pCausal",
"=",
"0.5",
",",
"plot",
"=",
"False",
")",
":",
"if",
"self",
".",
"X",
"is",
"None",
":",
"print",
"(",
"'Reading in all SNPs. This is slow.... | generate | [
"generate"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/mtSet/core/simulator.py#L174-L212 |
PMBio/limix-backup | limix/mtSet/core/simulator.py | CSimulator._genBgTerm_fromXX | def _genBgTerm_fromXX(self,vTot,vCommon,XX,a=None,c=None):
"""
generate background term from SNPs
Args:
vTot: variance of Yc+Yi
vCommon: variance of Yc
XX: kinship matrix
a: common scales, it can be set for debugging purposes
c: indipe... | python | def _genBgTerm_fromXX(self,vTot,vCommon,XX,a=None,c=None):
"""
generate background term from SNPs
Args:
vTot: variance of Yc+Yi
vCommon: variance of Yc
XX: kinship matrix
a: common scales, it can be set for debugging purposes
c: indipe... | [
"def",
"_genBgTerm_fromXX",
"(",
"self",
",",
"vTot",
",",
"vCommon",
",",
"XX",
",",
"a",
"=",
"None",
",",
"c",
"=",
"None",
")",
":",
"vSpecific",
"=",
"vTot",
"-",
"vCommon",
"SP",
".",
"random",
".",
"seed",
"(",
"0",
")",
"if",
"c",
"==",
... | generate background term from SNPs
Args:
vTot: variance of Yc+Yi
vCommon: variance of Yc
XX: kinship matrix
a: common scales, it can be set for debugging purposes
c: indipendent scales, it can be set for debugging purposes | [
"generate",
"background",
"term",
"from",
"SNPs"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/mtSet/core/simulator.py#L214-L244 |
PMBio/limix-backup | limix/mtSet/core/simulator.py | CSimulator.genBgTerm | def genBgTerm(self,vTot=0.5,vCommon=0.1,pCausal=0.5,XX=None,use_XX=False,a=None,c=None,plot=False):
""" generate """
if use_XX:
if XX is None: XX = self.XX
assert XX is not None, 'Simulator: set XX!'
Yc,Yi = self._genBgTerm_fromXX(vTot,vCommon,XX,a=a,c=c)
el... | python | def genBgTerm(self,vTot=0.5,vCommon=0.1,pCausal=0.5,XX=None,use_XX=False,a=None,c=None,plot=False):
""" generate """
if use_XX:
if XX is None: XX = self.XX
assert XX is not None, 'Simulator: set XX!'
Yc,Yi = self._genBgTerm_fromXX(vTot,vCommon,XX,a=a,c=c)
el... | [
"def",
"genBgTerm",
"(",
"self",
",",
"vTot",
"=",
"0.5",
",",
"vCommon",
"=",
"0.1",
",",
"pCausal",
"=",
"0.5",
",",
"XX",
"=",
"None",
",",
"use_XX",
"=",
"False",
",",
"a",
"=",
"None",
",",
"c",
"=",
"None",
",",
"plot",
"=",
"False",
")",... | generate | [
"generate"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/mtSet/core/simulator.py#L247-L255 |
PMBio/limix-backup | limix/mtSet/core/simulator.py | CSimulator.genHidden | def genHidden(self,nHidden=10,vTot=0.5,vCommon=0.1):
""" generate """
vSpecific = vTot-vCommon
# generate hidden
X = self.genWeights(self.N,nHidden)
# common effect
H = self.genWeights(nHidden,self.P)
Bc = SP.dot(H,self.genTraitEffect())
Yc = SP.dot(X... | python | def genHidden(self,nHidden=10,vTot=0.5,vCommon=0.1):
""" generate """
vSpecific = vTot-vCommon
# generate hidden
X = self.genWeights(self.N,nHidden)
# common effect
H = self.genWeights(nHidden,self.P)
Bc = SP.dot(H,self.genTraitEffect())
Yc = SP.dot(X... | [
"def",
"genHidden",
"(",
"self",
",",
"nHidden",
"=",
"10",
",",
"vTot",
"=",
"0.5",
",",
"vCommon",
"=",
"0.1",
")",
":",
"vSpecific",
"=",
"vTot",
"-",
"vCommon",
"# generate hidden",
"X",
"=",
"self",
".",
"genWeights",
"(",
"self",
".",
"N",
",",... | generate | [
"generate"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/mtSet/core/simulator.py#L257-L276 |
praekelt/django-moderator | moderator/models.py | realtime_comment_classifier | def realtime_comment_classifier(sender, instance, created, **kwargs):
"""
Classifies a comment after it has been created.
This behaviour is configurable by the REALTIME_CLASSIFICATION MODERATOR,
default behaviour is to classify(True).
"""
# Only classify if newly created.
if created:
... | python | def realtime_comment_classifier(sender, instance, created, **kwargs):
"""
Classifies a comment after it has been created.
This behaviour is configurable by the REALTIME_CLASSIFICATION MODERATOR,
default behaviour is to classify(True).
"""
# Only classify if newly created.
if created:
... | [
"def",
"realtime_comment_classifier",
"(",
"sender",
",",
"instance",
",",
"created",
",",
"*",
"*",
"kwargs",
")",
":",
"# Only classify if newly created.",
"if",
"created",
":",
"moderator_settings",
"=",
"getattr",
"(",
"settings",
",",
"'MODERATOR'",
",",
"Non... | Classifies a comment after it has been created.
This behaviour is configurable by the REALTIME_CLASSIFICATION MODERATOR,
default behaviour is to classify(True). | [
"Classifies",
"a",
"comment",
"after",
"it",
"has",
"been",
"created",
"."
] | train | https://github.com/praekelt/django-moderator/blob/72f1d5259128ff5a1a0341d4a573bfd561ba4665/moderator/models.py#L171-L189 |
quantmind/pulsar-odm | benchmark/bench.py | run_benchmark | def run_benchmark(monitor):
'''Run the benchmarks
'''
url = urlparse(monitor.cfg.test_url)
name = slugify(url.path) or 'home'
name = '%s_%d.csv' % (name, monitor.cfg.workers)
monitor.logger.info('WRITING RESULTS ON "%s"', name)
total = REQUESTS//monitor.cfg.workers
with open(name, 'w') ... | python | def run_benchmark(monitor):
'''Run the benchmarks
'''
url = urlparse(monitor.cfg.test_url)
name = slugify(url.path) or 'home'
name = '%s_%d.csv' % (name, monitor.cfg.workers)
monitor.logger.info('WRITING RESULTS ON "%s"', name)
total = REQUESTS//monitor.cfg.workers
with open(name, 'w') ... | [
"def",
"run_benchmark",
"(",
"monitor",
")",
":",
"url",
"=",
"urlparse",
"(",
"monitor",
".",
"cfg",
".",
"test_url",
")",
"name",
"=",
"slugify",
"(",
"url",
".",
"path",
")",
"or",
"'home'",
"name",
"=",
"'%s_%d.csv'",
"%",
"(",
"name",
",",
"moni... | Run the benchmarks | [
"Run",
"the",
"benchmarks"
] | train | https://github.com/quantmind/pulsar-odm/blob/5955c20beca0a89270c2b390335838deb7d5915e/benchmark/bench.py#L99-L143 |
quantmind/pulsar-odm | benchmark/bench.py | Bench.filldb | def filldb(self):
'''Fill database
'''
from app import World, Fortune, odm, MAXINT
mapper = odm.Mapper(self.cfg.postgresql)
mapper.register(World)
mapper.register(Fortune)
mapper.table_create()
with mapper.begin() as session:
query = session.... | python | def filldb(self):
'''Fill database
'''
from app import World, Fortune, odm, MAXINT
mapper = odm.Mapper(self.cfg.postgresql)
mapper.register(World)
mapper.register(Fortune)
mapper.table_create()
with mapper.begin() as session:
query = session.... | [
"def",
"filldb",
"(",
"self",
")",
":",
"from",
"app",
"import",
"World",
",",
"Fortune",
",",
"odm",
",",
"MAXINT",
"mapper",
"=",
"odm",
".",
"Mapper",
"(",
"self",
".",
"cfg",
".",
"postgresql",
")",
"mapper",
".",
"register",
"(",
"World",
")",
... | Fill database | [
"Fill",
"database"
] | train | https://github.com/quantmind/pulsar-odm/blob/5955c20beca0a89270c2b390335838deb7d5915e/benchmark/bench.py#L163-L185 |
KelSolaar/Foundations | foundations/walkers.py | files_walker | def files_walker(directory, filters_in=None, filters_out=None, flags=0):
"""
Defines a generator used to walk files using given filters.
Usage::
>>> for file in files_walker("./foundations/tests/tests_foundations/resources/standard/level_0"):
... print(file)
...
./found... | python | def files_walker(directory, filters_in=None, filters_out=None, flags=0):
"""
Defines a generator used to walk files using given filters.
Usage::
>>> for file in files_walker("./foundations/tests/tests_foundations/resources/standard/level_0"):
... print(file)
...
./found... | [
"def",
"files_walker",
"(",
"directory",
",",
"filters_in",
"=",
"None",
",",
"filters_out",
"=",
"None",
",",
"flags",
"=",
"0",
")",
":",
"if",
"filters_in",
":",
"LOGGER",
".",
"debug",
"(",
"\"> Current filters in: '{0}'.\"",
".",
"format",
"(",
"filters... | Defines a generator used to walk files using given filters.
Usage::
>>> for file in files_walker("./foundations/tests/tests_foundations/resources/standard/level_0"):
... print(file)
...
./foundations/tests/tests_foundations/resources/standard/level_0/level_1/level_2/standard.sI... | [
"Defines",
"a",
"generator",
"used",
"to",
"walk",
"files",
"using",
"given",
"filters",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/walkers.py#L36-L82 |
KelSolaar/Foundations | foundations/walkers.py | depth_walker | def depth_walker(directory, maximum_depth=1):
"""
Defines a generator used to walk into directories using given maximum depth.
Usage::
>>> for item in depth_walker("./foundations/tests/tests_foundations/resources/standard/level_0"):
... print(item)
...
(u'./foundations/... | python | def depth_walker(directory, maximum_depth=1):
"""
Defines a generator used to walk into directories using given maximum depth.
Usage::
>>> for item in depth_walker("./foundations/tests/tests_foundations/resources/standard/level_0"):
... print(item)
...
(u'./foundations/... | [
"def",
"depth_walker",
"(",
"directory",
",",
"maximum_depth",
"=",
"1",
")",
":",
"separator",
"=",
"os",
".",
"path",
".",
"sep",
"base_depth",
"=",
"directory",
".",
"count",
"(",
"separator",
")",
"for",
"parent_directory",
",",
"directories",
",",
"fi... | Defines a generator used to walk into directories using given maximum depth.
Usage::
>>> for item in depth_walker("./foundations/tests/tests_foundations/resources/standard/level_0"):
... print(item)
...
(u'./foundations/tests/tests_foundations/resources/standard/level_0', [u'le... | [
"Defines",
"a",
"generator",
"used",
"to",
"walk",
"into",
"directories",
"using",
"given",
"maximum",
"depth",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/walkers.py#L85-L117 |
KelSolaar/Foundations | foundations/walkers.py | dictionaries_walker | def dictionaries_walker(dictionary, path=()):
"""
Defines a generator used to walk into nested dictionaries.
Usage::
>>> nested_dictionary = {"Level 1A":{"Level 2A": { "Level 3A" : "Higher Level"}}, "Level 1B" : "Lower level"}
>>> dictionaries_walker(nested_dictionary)
<generator o... | python | def dictionaries_walker(dictionary, path=()):
"""
Defines a generator used to walk into nested dictionaries.
Usage::
>>> nested_dictionary = {"Level 1A":{"Level 2A": { "Level 3A" : "Higher Level"}}, "Level 1B" : "Lower level"}
>>> dictionaries_walker(nested_dictionary)
<generator o... | [
"def",
"dictionaries_walker",
"(",
"dictionary",
",",
"path",
"=",
"(",
")",
")",
":",
"for",
"key",
"in",
"dictionary",
":",
"if",
"not",
"isinstance",
"(",
"dictionary",
"[",
"key",
"]",
",",
"dict",
")",
":",
"yield",
"path",
",",
"key",
",",
"dic... | Defines a generator used to walk into nested dictionaries.
Usage::
>>> nested_dictionary = {"Level 1A":{"Level 2A": { "Level 3A" : "Higher Level"}}, "Level 1B" : "Lower level"}
>>> dictionaries_walker(nested_dictionary)
<generator object dictionaries_walker at 0x10131a320>
>>> for ... | [
"Defines",
"a",
"generator",
"used",
"to",
"walk",
"into",
"nested",
"dictionaries",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/walkers.py#L120-L150 |
KelSolaar/Foundations | foundations/walkers.py | nodes_walker | def nodes_walker(node, ascendants=False):
"""
Defines a generator used to walk into Nodes hierarchy.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode("MyNodeC", node_a)
>>> node_d ... | python | def nodes_walker(node, ascendants=False):
"""
Defines a generator used to walk into Nodes hierarchy.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode("MyNodeC", node_a)
>>> node_d ... | [
"def",
"nodes_walker",
"(",
"node",
",",
"ascendants",
"=",
"False",
")",
":",
"attribute",
"=",
"\"children\"",
"if",
"not",
"ascendants",
"else",
"\"parent\"",
"if",
"not",
"hasattr",
"(",
"node",
",",
"attribute",
")",
":",
"return",
"elements",
"=",
"g... | Defines a generator used to walk into Nodes hierarchy.
Usage::
>>> node_a = AbstractCompositeNode("MyNodeA")
>>> node_b = AbstractCompositeNode("MyNodeB", node_a)
>>> node_c = AbstractCompositeNode("MyNodeC", node_a)
>>> node_d = AbstractCompositeNode("MyNodeD", node_b)
>>>... | [
"Defines",
"a",
"generator",
"used",
"to",
"walk",
"into",
"Nodes",
"hierarchy",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/walkers.py#L153-L202 |
PMBio/limix-backup | limix/core/old/gp/gp_base.py | GP.setY | def setY(self,Y):
"""
set pheno
"""
if Y.ndim==1: Y = Y[:,SP.newaxis]
self.n,self.t = Y.shape
self.Y = Y
self.Y_has_changed = True | python | def setY(self,Y):
"""
set pheno
"""
if Y.ndim==1: Y = Y[:,SP.newaxis]
self.n,self.t = Y.shape
self.Y = Y
self.Y_has_changed = True | [
"def",
"setY",
"(",
"self",
",",
"Y",
")",
":",
"if",
"Y",
".",
"ndim",
"==",
"1",
":",
"Y",
"=",
"Y",
"[",
":",
",",
"SP",
".",
"newaxis",
"]",
"self",
".",
"n",
",",
"self",
".",
"t",
"=",
"Y",
".",
"shape",
"self",
".",
"Y",
"=",
"Y"... | set pheno | [
"set",
"pheno"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/core/old/gp/gp_base.py#L25-L32 |
PMBio/limix-backup | limix/core/old/gp/gp_base.py | GP.LML | def LML(self,params=None):
"""
evalutes the log marginal likelihood for the given hyperparameters
hyperparams
"""
if params is not None:
self.setParams(params)
KV = self._update_cache()
alpha = KV['alpha']
L = KV['L']
lml_quad = 0.5 ... | python | def LML(self,params=None):
"""
evalutes the log marginal likelihood for the given hyperparameters
hyperparams
"""
if params is not None:
self.setParams(params)
KV = self._update_cache()
alpha = KV['alpha']
L = KV['L']
lml_quad = 0.5 ... | [
"def",
"LML",
"(",
"self",
",",
"params",
"=",
"None",
")",
":",
"if",
"params",
"is",
"not",
"None",
":",
"self",
".",
"setParams",
"(",
"params",
")",
"KV",
"=",
"self",
".",
"_update_cache",
"(",
")",
"alpha",
"=",
"KV",
"[",
"'alpha'",
"]",
"... | evalutes the log marginal likelihood for the given hyperparameters
hyperparams | [
"evalutes",
"the",
"log",
"marginal",
"likelihood",
"for",
"the",
"given",
"hyperparameters"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/core/old/gp/gp_base.py#L46-L63 |
PMBio/limix-backup | limix/core/old/gp/gp_base.py | GP.LMLgrad | def LMLgrad(self,params=None):
"""
evaluates the gradient of the log marginal likelihood for the given hyperparameters
"""
if params is not None:
self.setParams(params)
KV = self._update_cache()
W = KV['W']
LMLgrad = SP.zeros(self.covar.n_params)
... | python | def LMLgrad(self,params=None):
"""
evaluates the gradient of the log marginal likelihood for the given hyperparameters
"""
if params is not None:
self.setParams(params)
KV = self._update_cache()
W = KV['W']
LMLgrad = SP.zeros(self.covar.n_params)
... | [
"def",
"LMLgrad",
"(",
"self",
",",
"params",
"=",
"None",
")",
":",
"if",
"params",
"is",
"not",
"None",
":",
"self",
".",
"setParams",
"(",
"params",
")",
"KV",
"=",
"self",
".",
"_update_cache",
"(",
")",
"W",
"=",
"KV",
"[",
"'W'",
"]",
"LMLg... | evaluates the gradient of the log marginal likelihood for the given hyperparameters | [
"evaluates",
"the",
"gradient",
"of",
"the",
"log",
"marginal",
"likelihood",
"for",
"the",
"given",
"hyperparameters"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/core/old/gp/gp_base.py#L66-L78 |
PMBio/limix-backup | limix/core/old/gp/gp_base.py | GP.predict | def predict(self,Xstar):
"""
predict on Xstar
"""
KV = self._update_cache()
self.covar.setXstar(Xstar)
Kstar = self.covar.Kcross()
Ystar = SP.dot(Kstar,KV['alpha'])
return Ystar | python | def predict(self,Xstar):
"""
predict on Xstar
"""
KV = self._update_cache()
self.covar.setXstar(Xstar)
Kstar = self.covar.Kcross()
Ystar = SP.dot(Kstar,KV['alpha'])
return Ystar | [
"def",
"predict",
"(",
"self",
",",
"Xstar",
")",
":",
"KV",
"=",
"self",
".",
"_update_cache",
"(",
")",
"self",
".",
"covar",
".",
"setXstar",
"(",
"Xstar",
")",
"Kstar",
"=",
"self",
".",
"covar",
".",
"Kcross",
"(",
")",
"Ystar",
"=",
"SP",
"... | predict on Xstar | [
"predict",
"on",
"Xstar"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/core/old/gp/gp_base.py#L81-L89 |
PMBio/limix-backup | limix/core/old/gp/gp_base.py | GP._update_cache | def _update_cache(self):
"""
INPUT:
hyperparams: dictionary
OUTPUT: dictionary with the fields
K: kernel
Kinv: inverse of the kernel
L: chol(K)
alpha: solve(K,y)
W: D*Kinv * alpha*alpha^T
"""
cov_params_have_changed = ... | python | def _update_cache(self):
"""
INPUT:
hyperparams: dictionary
OUTPUT: dictionary with the fields
K: kernel
Kinv: inverse of the kernel
L: chol(K)
alpha: solve(K,y)
W: D*Kinv * alpha*alpha^T
"""
cov_params_have_changed = ... | [
"def",
"_update_cache",
"(",
"self",
")",
":",
"cov_params_have_changed",
"=",
"self",
".",
"covar",
".",
"params_have_changed",
"if",
"cov_params_have_changed",
"or",
"self",
".",
"Y_has_changed",
":",
"K",
"=",
"self",
".",
"covar",
".",
"K",
"(",
")",
"L"... | INPUT:
hyperparams: dictionary
OUTPUT: dictionary with the fields
K: kernel
Kinv: inverse of the kernel
L: chol(K)
alpha: solve(K,y)
W: D*Kinv * alpha*alpha^T | [
"INPUT",
":",
"hyperparams",
":",
"dictionary",
"OUTPUT",
":",
"dictionary",
"with",
"the",
"fields",
"K",
":",
"kernel",
"Kinv",
":",
"inverse",
"of",
"the",
"kernel",
"L",
":",
"chol",
"(",
"K",
")",
"alpha",
":",
"solve",
"(",
"K",
"y",
")",
"W",
... | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/core/old/gp/gp_base.py#L91-L117 |
PMBio/limix-backup | limix/core/old/gp/gp_base.py | GP.checkGradient | def checkGradient(self,h=1e-6,verbose=True):
""" utility function to check the gradient of the gp """
grad_an = self.LMLgrad()
grad_num = {}
params0 = self.params.copy()
for key in list(self.params.keys()):
paramsL = params0.copy()
paramsR = params0.copy()... | python | def checkGradient(self,h=1e-6,verbose=True):
""" utility function to check the gradient of the gp """
grad_an = self.LMLgrad()
grad_num = {}
params0 = self.params.copy()
for key in list(self.params.keys()):
paramsL = params0.copy()
paramsR = params0.copy()... | [
"def",
"checkGradient",
"(",
"self",
",",
"h",
"=",
"1e-6",
",",
"verbose",
"=",
"True",
")",
":",
"grad_an",
"=",
"self",
".",
"LMLgrad",
"(",
")",
"grad_num",
"=",
"{",
"}",
"params0",
"=",
"self",
".",
"params",
".",
"copy",
"(",
")",
"for",
"... | utility function to check the gradient of the gp | [
"utility",
"function",
"to",
"check",
"the",
"gradient",
"of",
"the",
"gp"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/core/old/gp/gp_base.py#L120-L142 |
fitnr/twitter_bot_utils | twitter_bot_utils/confighelper.py | configure | def configure(screen_name=None, config_file=None, app=None, **kwargs):
"""
Set up a config dictionary using a bots.yaml config file and optional keyword args.
Args:
screen_name (str): screen_name of user to search for in config file
config_file (str): Path to read for the config file
... | python | def configure(screen_name=None, config_file=None, app=None, **kwargs):
"""
Set up a config dictionary using a bots.yaml config file and optional keyword args.
Args:
screen_name (str): screen_name of user to search for in config file
config_file (str): Path to read for the config file
... | [
"def",
"configure",
"(",
"screen_name",
"=",
"None",
",",
"config_file",
"=",
"None",
",",
"app",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"# Use passed config file, or look for it in the default path.",
"# Super-optionally, accept a different place to look for the f... | Set up a config dictionary using a bots.yaml config file and optional keyword args.
Args:
screen_name (str): screen_name of user to search for in config file
config_file (str): Path to read for the config file
app (str): Name of the app to look for in the config file. Defaults to the one se... | [
"Set",
"up",
"a",
"config",
"dictionary",
"using",
"a",
"bots",
".",
"yaml",
"config",
"file",
"and",
"optional",
"keyword",
"args",
"."
] | train | https://github.com/fitnr/twitter_bot_utils/blob/21f35afa5048cd3efa54db8cb87d405f69a78a62/twitter_bot_utils/confighelper.py#L43-L80 |
fitnr/twitter_bot_utils | twitter_bot_utils/confighelper.py | parse | def parse(file_path):
'''Parse a YAML or JSON file.'''
_, ext = path.splitext(file_path)
if ext in ('.yaml', '.yml'):
func = yaml.load
elif ext == '.json':
func = json.load
else:
raise ValueError("Unrecognized config file type %s" % ext)
with open(file_path, 'r') as ... | python | def parse(file_path):
'''Parse a YAML or JSON file.'''
_, ext = path.splitext(file_path)
if ext in ('.yaml', '.yml'):
func = yaml.load
elif ext == '.json':
func = json.load
else:
raise ValueError("Unrecognized config file type %s" % ext)
with open(file_path, 'r') as ... | [
"def",
"parse",
"(",
"file_path",
")",
":",
"_",
",",
"ext",
"=",
"path",
".",
"splitext",
"(",
"file_path",
")",
"if",
"ext",
"in",
"(",
"'.yaml'",
",",
"'.yml'",
")",
":",
"func",
"=",
"yaml",
".",
"load",
"elif",
"ext",
"==",
"'.json'",
":",
"... | Parse a YAML or JSON file. | [
"Parse",
"a",
"YAML",
"or",
"JSON",
"file",
"."
] | train | https://github.com/fitnr/twitter_bot_utils/blob/21f35afa5048cd3efa54db8cb87d405f69a78a62/twitter_bot_utils/confighelper.py#L83-L98 |
fitnr/twitter_bot_utils | twitter_bot_utils/confighelper.py | find_file | def find_file(config_file=None, default_directories=None, default_bases=None):
'''Search for a config file in a list of files.'''
if config_file:
if path.exists(path.expanduser(config_file)):
return config_file
else:
raise FileNotFoundError('Config file not found: {}'.fo... | python | def find_file(config_file=None, default_directories=None, default_bases=None):
'''Search for a config file in a list of files.'''
if config_file:
if path.exists(path.expanduser(config_file)):
return config_file
else:
raise FileNotFoundError('Config file not found: {}'.fo... | [
"def",
"find_file",
"(",
"config_file",
"=",
"None",
",",
"default_directories",
"=",
"None",
",",
"default_bases",
"=",
"None",
")",
":",
"if",
"config_file",
":",
"if",
"path",
".",
"exists",
"(",
"path",
".",
"expanduser",
"(",
"config_file",
")",
")",
... | Search for a config file in a list of files. | [
"Search",
"for",
"a",
"config",
"file",
"in",
"a",
"list",
"of",
"files",
"."
] | train | https://github.com/fitnr/twitter_bot_utils/blob/21f35afa5048cd3efa54db8cb87d405f69a78a62/twitter_bot_utils/confighelper.py#L101-L120 |
fitnr/twitter_bot_utils | twitter_bot_utils/confighelper.py | setup_auth | def setup_auth(**keys):
'''Set up Tweepy authentication using passed args or config file settings.'''
auth = tweepy.OAuthHandler(consumer_key=keys['consumer_key'], consumer_secret=keys['consumer_secret'])
auth.set_access_token(
key=keys.get('token', keys.get('key', keys.get('oauth_token'))),
... | python | def setup_auth(**keys):
'''Set up Tweepy authentication using passed args or config file settings.'''
auth = tweepy.OAuthHandler(consumer_key=keys['consumer_key'], consumer_secret=keys['consumer_secret'])
auth.set_access_token(
key=keys.get('token', keys.get('key', keys.get('oauth_token'))),
... | [
"def",
"setup_auth",
"(",
"*",
"*",
"keys",
")",
":",
"auth",
"=",
"tweepy",
".",
"OAuthHandler",
"(",
"consumer_key",
"=",
"keys",
"[",
"'consumer_key'",
"]",
",",
"consumer_secret",
"=",
"keys",
"[",
"'consumer_secret'",
"]",
")",
"auth",
".",
"set_acces... | Set up Tweepy authentication using passed args or config file settings. | [
"Set",
"up",
"Tweepy",
"authentication",
"using",
"passed",
"args",
"or",
"config",
"file",
"settings",
"."
] | train | https://github.com/fitnr/twitter_bot_utils/blob/21f35afa5048cd3efa54db8cb87d405f69a78a62/twitter_bot_utils/confighelper.py#L123-L130 |
ssato/python-anytemplate | anytemplate/engine.py | list_engines_by_priority | def list_engines_by_priority(engines=None):
"""
Return a list of engines supported sorted by each priority.
"""
if engines is None:
engines = ENGINES
return sorted(engines, key=operator.methodcaller("priority")) | python | def list_engines_by_priority(engines=None):
"""
Return a list of engines supported sorted by each priority.
"""
if engines is None:
engines = ENGINES
return sorted(engines, key=operator.methodcaller("priority")) | [
"def",
"list_engines_by_priority",
"(",
"engines",
"=",
"None",
")",
":",
"if",
"engines",
"is",
"None",
":",
"engines",
"=",
"ENGINES",
"return",
"sorted",
"(",
"engines",
",",
"key",
"=",
"operator",
".",
"methodcaller",
"(",
"\"priority\"",
")",
")"
] | Return a list of engines supported sorted by each priority. | [
"Return",
"a",
"list",
"of",
"engines",
"supported",
"sorted",
"by",
"each",
"priority",
"."
] | train | https://github.com/ssato/python-anytemplate/blob/3e56baa914bd47f044083b20e33100f836443596/anytemplate/engine.py#L50-L57 |
ssato/python-anytemplate | anytemplate/engine.py | find_by_filename | def find_by_filename(filename=None, engines=None):
"""
Find a list of template engine classes to render template `filename`.
:param filename: Template file name (may be a absolute/relative path)
:param engines: Template engines
:return: A list of engines support given template file
"""
if ... | python | def find_by_filename(filename=None, engines=None):
"""
Find a list of template engine classes to render template `filename`.
:param filename: Template file name (may be a absolute/relative path)
:param engines: Template engines
:return: A list of engines support given template file
"""
if ... | [
"def",
"find_by_filename",
"(",
"filename",
"=",
"None",
",",
"engines",
"=",
"None",
")",
":",
"if",
"engines",
"is",
"None",
":",
"engines",
"=",
"ENGINES",
"if",
"filename",
"is",
"None",
":",
"return",
"list_engines_by_priority",
"(",
"engines",
")",
"... | Find a list of template engine classes to render template `filename`.
:param filename: Template file name (may be a absolute/relative path)
:param engines: Template engines
:return: A list of engines support given template file | [
"Find",
"a",
"list",
"of",
"template",
"engine",
"classes",
"to",
"render",
"template",
"filename",
"."
] | train | https://github.com/ssato/python-anytemplate/blob/3e56baa914bd47f044083b20e33100f836443596/anytemplate/engine.py#L60-L76 |
ssato/python-anytemplate | anytemplate/engine.py | find_by_name | def find_by_name(name, engines=None):
"""
Find a template engine class specified by its name `name`.
:param name: Template name
:param engines: Template engines
:return: A template engine or None if no any template engine of given name
were found.
"""
if engines is None:
en... | python | def find_by_name(name, engines=None):
"""
Find a template engine class specified by its name `name`.
:param name: Template name
:param engines: Template engines
:return: A template engine or None if no any template engine of given name
were found.
"""
if engines is None:
en... | [
"def",
"find_by_name",
"(",
"name",
",",
"engines",
"=",
"None",
")",
":",
"if",
"engines",
"is",
"None",
":",
"engines",
"=",
"ENGINES",
"for",
"egn",
"in",
"engines",
":",
"if",
"egn",
".",
"name",
"(",
")",
"==",
"name",
":",
"return",
"egn",
"r... | Find a template engine class specified by its name `name`.
:param name: Template name
:param engines: Template engines
:return: A template engine or None if no any template engine of given name
were found. | [
"Find",
"a",
"template",
"engine",
"class",
"specified",
"by",
"its",
"name",
"name",
"."
] | train | https://github.com/ssato/python-anytemplate/blob/3e56baa914bd47f044083b20e33100f836443596/anytemplate/engine.py#L79-L96 |
fitnr/twitter_bot_utils | twitter_bot_utils/api.py | API.update_status | def update_status(self, *pargs, **kwargs):
"""
Wrapper for tweepy.api.update_status with a 10s wait when twitter is over capacity
"""
try:
return super(API, self).update_status(*pargs, **kwargs)
except tweepy.TweepError as e:
if getattr(e, 'api_code', Non... | python | def update_status(self, *pargs, **kwargs):
"""
Wrapper for tweepy.api.update_status with a 10s wait when twitter is over capacity
"""
try:
return super(API, self).update_status(*pargs, **kwargs)
except tweepy.TweepError as e:
if getattr(e, 'api_code', Non... | [
"def",
"update_status",
"(",
"self",
",",
"*",
"pargs",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"return",
"super",
"(",
"API",
",",
"self",
")",
".",
"update_status",
"(",
"*",
"pargs",
",",
"*",
"*",
"kwargs",
")",
"except",
"tweepy",
".",
... | Wrapper for tweepy.api.update_status with a 10s wait when twitter is over capacity | [
"Wrapper",
"for",
"tweepy",
".",
"api",
".",
"update_status",
"with",
"a",
"10s",
"wait",
"when",
"twitter",
"is",
"over",
"capacity"
] | train | https://github.com/fitnr/twitter_bot_utils/blob/21f35afa5048cd3efa54db8cb87d405f69a78a62/twitter_bot_utils/api.py#L180-L192 |
fitnr/twitter_bot_utils | twitter_bot_utils/api.py | API.media_upload | def media_upload(self, filename, *args, **kwargs):
""" :reference: https://dev.twitter.com/rest/reference/post/media/upload
:reference https://dev.twitter.com/rest/reference/post/media/upload-chunked
:allowed_param:
"""
f = kwargs.pop('file', None)
mime, _ = mime... | python | def media_upload(self, filename, *args, **kwargs):
""" :reference: https://dev.twitter.com/rest/reference/post/media/upload
:reference https://dev.twitter.com/rest/reference/post/media/upload-chunked
:allowed_param:
"""
f = kwargs.pop('file', None)
mime, _ = mime... | [
"def",
"media_upload",
"(",
"self",
",",
"filename",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"f",
"=",
"kwargs",
".",
"pop",
"(",
"'file'",
",",
"None",
")",
"mime",
",",
"_",
"=",
"mimetypes",
".",
"guess_type",
"(",
"filename",
")",
... | :reference: https://dev.twitter.com/rest/reference/post/media/upload
:reference https://dev.twitter.com/rest/reference/post/media/upload-chunked
:allowed_param: | [
":",
"reference",
":",
"https",
":",
"//",
"dev",
".",
"twitter",
".",
"com",
"/",
"rest",
"/",
"reference",
"/",
"post",
"/",
"media",
"/",
"upload",
":",
"reference",
"https",
":",
"//",
"dev",
".",
"twitter",
".",
"com",
"/",
"rest",
"/",
"refer... | train | https://github.com/fitnr/twitter_bot_utils/blob/21f35afa5048cd3efa54db8cb87d405f69a78a62/twitter_bot_utils/api.py#L195-L212 |
fitnr/twitter_bot_utils | twitter_bot_utils/api.py | API.upload_chunked | def upload_chunked(self, filename, *args, **kwargs):
""" :reference https://dev.twitter.com/rest/reference/post/media/upload-chunked
:allowed_param:
"""
f = kwargs.pop('file', None)
# Media category is dependant on whether media is attached to a tweet
# or to a direc... | python | def upload_chunked(self, filename, *args, **kwargs):
""" :reference https://dev.twitter.com/rest/reference/post/media/upload-chunked
:allowed_param:
"""
f = kwargs.pop('file', None)
# Media category is dependant on whether media is attached to a tweet
# or to a direc... | [
"def",
"upload_chunked",
"(",
"self",
",",
"filename",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"f",
"=",
"kwargs",
".",
"pop",
"(",
"'file'",
",",
"None",
")",
"# Media category is dependant on whether media is attached to a tweet",
"# or to a direct ... | :reference https://dev.twitter.com/rest/reference/post/media/upload-chunked
:allowed_param: | [
":",
"reference",
"https",
":",
"//",
"dev",
".",
"twitter",
".",
"com",
"/",
"rest",
"/",
"reference",
"/",
"post",
"/",
"media",
"/",
"upload",
"-",
"chunked",
":",
"allowed_param",
":"
] | train | https://github.com/fitnr/twitter_bot_utils/blob/21f35afa5048cd3efa54db8cb87d405f69a78a62/twitter_bot_utils/api.py#L232-L294 |
fitnr/twitter_bot_utils | twitter_bot_utils/api.py | API._get_media_category | def _get_media_category(is_direct_message, file_type):
""" :reference: https://developer.twitter.com/en/docs/direct-messages/message-attachments/guides/attaching-media
:allowed_param:
"""
if is_direct_message:
prefix = 'dm'
else:
prefix = 'tweet'
... | python | def _get_media_category(is_direct_message, file_type):
""" :reference: https://developer.twitter.com/en/docs/direct-messages/message-attachments/guides/attaching-media
:allowed_param:
"""
if is_direct_message:
prefix = 'dm'
else:
prefix = 'tweet'
... | [
"def",
"_get_media_category",
"(",
"is_direct_message",
",",
"file_type",
")",
":",
"if",
"is_direct_message",
":",
"prefix",
"=",
"'dm'",
"else",
":",
"prefix",
"=",
"'tweet'",
"if",
"file_type",
"in",
"IMAGE_MIMETYPES",
":",
"if",
"file_type",
"==",
"'image/gi... | :reference: https://developer.twitter.com/en/docs/direct-messages/message-attachments/guides/attaching-media
:allowed_param: | [
":",
"reference",
":",
"https",
":",
"//",
"developer",
".",
"twitter",
".",
"com",
"/",
"en",
"/",
"docs",
"/",
"direct",
"-",
"messages",
"/",
"message",
"-",
"attachments",
"/",
"guides",
"/",
"attaching",
"-",
"media",
":",
"allowed_param",
":"
] | train | https://github.com/fitnr/twitter_bot_utils/blob/21f35afa5048cd3efa54db8cb87d405f69a78a62/twitter_bot_utils/api.py#L382-L397 |
20c/munge | munge/base.py | CodecBase.open | def open(self, url, mode='r', stdio=True):
"""
opens a URL, no scheme is assumed to be a file
no path will use stdin or stdout depending on mode, unless stdio is False
"""
# doesn't need to use config, because the object is already created
res = urlsplit(url)
if ... | python | def open(self, url, mode='r', stdio=True):
"""
opens a URL, no scheme is assumed to be a file
no path will use stdin or stdout depending on mode, unless stdio is False
"""
# doesn't need to use config, because the object is already created
res = urlsplit(url)
if ... | [
"def",
"open",
"(",
"self",
",",
"url",
",",
"mode",
"=",
"'r'",
",",
"stdio",
"=",
"True",
")",
":",
"# doesn't need to use config, because the object is already created",
"res",
"=",
"urlsplit",
"(",
"url",
")",
"if",
"not",
"res",
".",
"scheme",
":",
"if"... | opens a URL, no scheme is assumed to be a file
no path will use stdin or stdout depending on mode, unless stdio is False | [
"opens",
"a",
"URL",
"no",
"scheme",
"is",
"assumed",
"to",
"be",
"a",
"file",
"no",
"path",
"will",
"use",
"stdin",
"or",
"stdout",
"depending",
"on",
"mode",
"unless",
"stdio",
"is",
"False"
] | train | https://github.com/20c/munge/blob/e20fef8c24e48d4b0a5c387820fbb2b7bebb0af0/munge/base.py#L47-L72 |
20c/munge | munge/base.py | CodecBase.loadu | def loadu(self, url, **kwargs):
"""
opens url and passes to load()
kwargs are passed to both open and load
"""
return self.load(self.open(url, **kwargs), **kwargs) | python | def loadu(self, url, **kwargs):
"""
opens url and passes to load()
kwargs are passed to both open and load
"""
return self.load(self.open(url, **kwargs), **kwargs) | [
"def",
"loadu",
"(",
"self",
",",
"url",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"load",
"(",
"self",
".",
"open",
"(",
"url",
",",
"*",
"*",
"kwargs",
")",
",",
"*",
"*",
"kwargs",
")"
] | opens url and passes to load()
kwargs are passed to both open and load | [
"opens",
"url",
"and",
"passes",
"to",
"load",
"()",
"kwargs",
"are",
"passed",
"to",
"both",
"open",
"and",
"load"
] | train | https://github.com/20c/munge/blob/e20fef8c24e48d4b0a5c387820fbb2b7bebb0af0/munge/base.py#L74-L79 |
20c/munge | munge/base.py | CodecBase.dumpu | def dumpu(self, data, url, **kwargs):
"""
opens url and passes to load()
kwargs are passed to both open and dump
"""
return self.dump(data, self.open(url, 'w', **kwargs), **kwargs) | python | def dumpu(self, data, url, **kwargs):
"""
opens url and passes to load()
kwargs are passed to both open and dump
"""
return self.dump(data, self.open(url, 'w', **kwargs), **kwargs) | [
"def",
"dumpu",
"(",
"self",
",",
"data",
",",
"url",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"dump",
"(",
"data",
",",
"self",
".",
"open",
"(",
"url",
",",
"'w'",
",",
"*",
"*",
"kwargs",
")",
",",
"*",
"*",
"kwargs",
")"
... | opens url and passes to load()
kwargs are passed to both open and dump | [
"opens",
"url",
"and",
"passes",
"to",
"load",
"()",
"kwargs",
"are",
"passed",
"to",
"both",
"open",
"and",
"dump"
] | train | https://github.com/20c/munge/blob/e20fef8c24e48d4b0a5c387820fbb2b7bebb0af0/munge/base.py#L81-L86 |
inveniosoftware-contrib/invenio-classifier | invenio_classifier/find.py | find_end_of_reference_section | def find_end_of_reference_section(docbody,
ref_start_line,
ref_line_marker,
ref_line_marker_ptn):
"""Find end of reference section.
Given that the start of a document's reference section has already been
r... | python | def find_end_of_reference_section(docbody,
ref_start_line,
ref_line_marker,
ref_line_marker_ptn):
"""Find end of reference section.
Given that the start of a document's reference section has already been
r... | [
"def",
"find_end_of_reference_section",
"(",
"docbody",
",",
"ref_start_line",
",",
"ref_line_marker",
",",
"ref_line_marker_ptn",
")",
":",
"section_ended",
"=",
"False",
"x",
"=",
"ref_start_line",
"if",
"type",
"(",
"x",
")",
"is",
"not",
"int",
"or",
"x",
... | Find end of reference section.
Given that the start of a document's reference section has already been
recognised, this function is tasked with finding the line-number in the
document of the last line of the reference section.
@param docbody: (list) of strings - the entire plain-text document body.
... | [
"Find",
"end",
"of",
"reference",
"section",
"."
] | train | https://github.com/inveniosoftware-contrib/invenio-classifier/blob/3c758cf34dca6bf0548e7da5de34e5f72e3b255e/invenio_classifier/find.py#L361-L473 |
inveniosoftware-contrib/invenio-classifier | invenio_classifier/find.py | get_reference_section_beginning | def get_reference_section_beginning(fulltext):
"""Get start of reference section."""
sect_start = {
'start_line': None,
'end_line': None,
'title_string': None,
'marker_pattern': None,
'marker': None,
'how_found_start': None,
}
# Find start of refs section... | python | def get_reference_section_beginning(fulltext):
"""Get start of reference section."""
sect_start = {
'start_line': None,
'end_line': None,
'title_string': None,
'marker_pattern': None,
'marker': None,
'how_found_start': None,
}
# Find start of refs section... | [
"def",
"get_reference_section_beginning",
"(",
"fulltext",
")",
":",
"sect_start",
"=",
"{",
"'start_line'",
":",
"None",
",",
"'end_line'",
":",
"None",
",",
"'title_string'",
":",
"None",
",",
"'marker_pattern'",
":",
"None",
",",
"'marker'",
":",
"None",
",... | Get start of reference section. | [
"Get",
"start",
"of",
"reference",
"section",
"."
] | train | https://github.com/inveniosoftware-contrib/invenio-classifier/blob/3c758cf34dca6bf0548e7da5de34e5f72e3b255e/invenio_classifier/find.py#L476-L518 |
splitkeycoffee/pyhottop | pyhottop/cli/config.py | main | def main():
"""Run the core."""
parser = ArgumentParser()
subs = parser.add_subparsers(dest='cmd')
setup_parser = subs.add_parser('test')
setup_parser.add_argument('--interface', default=None,
help='Manually pass in the USB connection.')
args = parser.parse_args()
... | python | def main():
"""Run the core."""
parser = ArgumentParser()
subs = parser.add_subparsers(dest='cmd')
setup_parser = subs.add_parser('test')
setup_parser.add_argument('--interface', default=None,
help='Manually pass in the USB connection.')
args = parser.parse_args()
... | [
"def",
"main",
"(",
")",
":",
"parser",
"=",
"ArgumentParser",
"(",
")",
"subs",
"=",
"parser",
".",
"add_subparsers",
"(",
"dest",
"=",
"'cmd'",
")",
"setup_parser",
"=",
"subs",
".",
"add_parser",
"(",
"'test'",
")",
"setup_parser",
".",
"add_argument",
... | Run the core. | [
"Run",
"the",
"core",
"."
] | train | https://github.com/splitkeycoffee/pyhottop/blob/2986bbb2d848f7e41fa3ece5ebb1b33c8882219c/pyhottop/cli/config.py#L23-L42 |
KelSolaar/Foundations | foundations/library.py | Library.path | def path(self, value):
"""
Setter for **self.__path** attribute.
:param value: Attribute value.
:type value: unicode
"""
if value is not None:
assert type(value) is unicode, "'{0}' attribute: '{1}' type is not 'unicode'!".format(
"path", valu... | python | def path(self, value):
"""
Setter for **self.__path** attribute.
:param value: Attribute value.
:type value: unicode
"""
if value is not None:
assert type(value) is unicode, "'{0}' attribute: '{1}' type is not 'unicode'!".format(
"path", valu... | [
"def",
"path",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"not",
"None",
":",
"assert",
"type",
"(",
"value",
")",
"is",
"unicode",
",",
"\"'{0}' attribute: '{1}' type is not 'unicode'!\"",
".",
"format",
"(",
"\"path\"",
",",
"value",
")",
... | Setter for **self.__path** attribute.
:param value: Attribute value.
:type value: unicode | [
"Setter",
"for",
"**",
"self",
".",
"__path",
"**",
"attribute",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/library.py#L240-L252 |
KelSolaar/Foundations | foundations/library.py | Library.functions | def functions(self, value):
"""
Setter for **self.__functions** attribute.
:param value: Attribute value.
:type value: tuple
"""
if value is not None:
assert type(value) is tuple, "'{0}' attribute: '{1}' type is not 'tuple'!".format("functions", value)
... | python | def functions(self, value):
"""
Setter for **self.__functions** attribute.
:param value: Attribute value.
:type value: tuple
"""
if value is not None:
assert type(value) is tuple, "'{0}' attribute: '{1}' type is not 'tuple'!".format("functions", value)
... | [
"def",
"functions",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"not",
"None",
":",
"assert",
"type",
"(",
"value",
")",
"is",
"tuple",
",",
"\"'{0}' attribute: '{1}' type is not 'tuple'!\"",
".",
"format",
"(",
"\"functions\"",
",",
"value",
"... | Setter for **self.__functions** attribute.
:param value: Attribute value.
:type value: tuple | [
"Setter",
"for",
"**",
"self",
".",
"__functions",
"**",
"attribute",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/library.py#L277-L290 |
KelSolaar/Foundations | foundations/library.py | Library.bind_function | def bind_function(self, function):
"""
Binds given function to a class object attribute.
Usage::
>>> import ctypes
>>> path = "FreeImage.dll"
>>> function = LibraryHook(name="FreeImage_GetVersion", arguments_types=None, return_value=ctypes.c_char_p)
... | python | def bind_function(self, function):
"""
Binds given function to a class object attribute.
Usage::
>>> import ctypes
>>> path = "FreeImage.dll"
>>> function = LibraryHook(name="FreeImage_GetVersion", arguments_types=None, return_value=ctypes.c_char_p)
... | [
"def",
"bind_function",
"(",
"self",
",",
"function",
")",
":",
"LOGGER",
".",
"debug",
"(",
"\"> Binding '{0}' library '{1}' function.\"",
".",
"format",
"(",
"self",
".",
"__class__",
".",
"__name__",
",",
"function",
".",
"name",
")",
")",
"function_object",
... | Binds given function to a class object attribute.
Usage::
>>> import ctypes
>>> path = "FreeImage.dll"
>>> function = LibraryHook(name="FreeImage_GetVersion", arguments_types=None, return_value=ctypes.c_char_p)
>>> library = Library(path, bind_library=False)
... | [
"Binds",
"given",
"function",
"to",
"a",
"class",
"object",
"attribute",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/library.py#L335-L364 |
KelSolaar/Foundations | foundations/library.py | Library.bind_library | def bind_library(self):
"""
Binds the Library using functions registered in the **self.__functions** attribute.
Usage::
>>> import ctypes
>>> path = "FreeImage.dll"
>>> functions = (LibraryHook(name="FreeImage_GetVersion", arguments_types=None, return_value=... | python | def bind_library(self):
"""
Binds the Library using functions registered in the **self.__functions** attribute.
Usage::
>>> import ctypes
>>> path = "FreeImage.dll"
>>> functions = (LibraryHook(name="FreeImage_GetVersion", arguments_types=None, return_value=... | [
"def",
"bind_library",
"(",
"self",
")",
":",
"if",
"self",
".",
"__functions",
":",
"for",
"function",
"in",
"self",
".",
"__functions",
":",
"self",
".",
"bind_function",
"(",
"function",
")",
"return",
"True"
] | Binds the Library using functions registered in the **self.__functions** attribute.
Usage::
>>> import ctypes
>>> path = "FreeImage.dll"
>>> functions = (LibraryHook(name="FreeImage_GetVersion", arguments_types=None, return_value=ctypes.c_char_p),)
>>> library =... | [
"Binds",
"the",
"Library",
"using",
"functions",
"registered",
"in",
"the",
"**",
"self",
".",
"__functions",
"**",
"attribute",
"."
] | train | https://github.com/KelSolaar/Foundations/blob/5c141330faf09dad70a12bc321f4c564917d0a91/foundations/library.py#L366-L388 |
PMBio/limix-backup | limix/deprecated/archive/data_deprecated.py | estCumPos | def estCumPos(pos,chrom,offset = 20000000):
'''
compute the cumulative position of each variant given the position and the chromosome
Also return the starting cumulativeposition of each chromosome
Args:
pos: scipy.array of basepair positions (on the chromosome)
chrom: scipy.... | python | def estCumPos(pos,chrom,offset = 20000000):
'''
compute the cumulative position of each variant given the position and the chromosome
Also return the starting cumulativeposition of each chromosome
Args:
pos: scipy.array of basepair positions (on the chromosome)
chrom: scipy.... | [
"def",
"estCumPos",
"(",
"pos",
",",
"chrom",
",",
"offset",
"=",
"20000000",
")",
":",
"chromvals",
"=",
"SP",
".",
"unique",
"(",
"chrom",
")",
"#SP.unique is always sorted",
"chrom_pos",
"=",
"SP",
".",
"zeros_like",
"(",
"chromvals",
")",
"#get the start... | compute the cumulative position of each variant given the position and the chromosome
Also return the starting cumulativeposition of each chromosome
Args:
pos: scipy.array of basepair positions (on the chromosome)
chrom: scipy.array of chromosomes
offset: offset between ... | [
"compute",
"the",
"cumulative",
"position",
"of",
"each",
"variant",
"given",
"the",
"position",
"and",
"the",
"chromosome",
"Also",
"return",
"the",
"starting",
"cumulativeposition",
"of",
"each",
"chromosome"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/deprecated/archive/data_deprecated.py#L13-L37 |
PMBio/limix-backup | limix/deprecated/archive/data_deprecated.py | _imputeMissing | def _imputeMissing(X, center=True, unit=True, betaNotUnitVariance=False, betaA=1.0, betaB=1.0):
'''
fill in missing values in the SNP matrix by the mean value
optionally center the data and unit-variance it
Args:
X: scipy.array of SNP values. If dtype=='int8' the missin... | python | def _imputeMissing(X, center=True, unit=True, betaNotUnitVariance=False, betaA=1.0, betaB=1.0):
'''
fill in missing values in the SNP matrix by the mean value
optionally center the data and unit-variance it
Args:
X: scipy.array of SNP values. If dtype=='int8' the missin... | [
"def",
"_imputeMissing",
"(",
"X",
",",
"center",
"=",
"True",
",",
"unit",
"=",
"True",
",",
"betaNotUnitVariance",
"=",
"False",
",",
"betaA",
"=",
"1.0",
",",
"betaB",
"=",
"1.0",
")",
":",
"typeX",
"=",
"X",
".",
"dtype",
"if",
"typeX",
"!=",
"... | fill in missing values in the SNP matrix by the mean value
optionally center the data and unit-variance it
Args:
X: scipy.array of SNP values. If dtype=='int8' the missing values are -9,
otherwise the missing values are scipy.nan
center: Boolean indicat... | [
"fill",
"in",
"missing",
"values",
"in",
"the",
"SNP",
"matrix",
"by",
"the",
"mean",
"value",
"optionally",
"center",
"the",
"data",
"and",
"unit",
"-",
"variance",
"it"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/deprecated/archive/data_deprecated.py#L40-L107 |
PMBio/limix-backup | limix/deprecated/archive/data_deprecated.py | QTLData.load | def load(self,cache_genotype=False,cache_phenotype=True):
"""load data file
Args:
cache_genotype: load genotypes fully into memory (default: False)
cache_phenotype: load phentopyes fully intro memry (default: True)
"""
self.f = h5py.File(se... | python | def load(self,cache_genotype=False,cache_phenotype=True):
"""load data file
Args:
cache_genotype: load genotypes fully into memory (default: False)
cache_phenotype: load phentopyes fully intro memry (default: True)
"""
self.f = h5py.File(se... | [
"def",
"load",
"(",
"self",
",",
"cache_genotype",
"=",
"False",
",",
"cache_phenotype",
"=",
"True",
")",
":",
"self",
".",
"f",
"=",
"h5py",
".",
"File",
"(",
"self",
".",
"file_name",
",",
"'r'",
")",
"self",
".",
"pheno",
"=",
"self",
".",
"f",... | load data file
Args:
cache_genotype: load genotypes fully into memory (default: False)
cache_phenotype: load phentopyes fully intro memry (default: True) | [
"load",
"data",
"file",
"Args",
":",
"cache_genotype",
":",
"load",
"genotypes",
"fully",
"into",
"memory",
"(",
"default",
":",
"False",
")",
"cache_phenotype",
":",
"load",
"phentopyes",
"fully",
"intro",
"memry",
"(",
"default",
":",
"True",
")"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/deprecated/archive/data_deprecated.py#L115-L166 |
PMBio/limix-backup | limix/deprecated/archive/data_deprecated.py | QTLData.getGenoIndex | def getGenoIndex(self,pos0=None,pos1=None,chrom=None,pos_cum0=None,pos_cum1=None):
"""computes 0-based genotype index from position of cumulative position.
Positions can be given in one out of two ways:
- position (pos0-pos1 on chrom)
- cumulative position (pos_cum0-pos_cum1)
I... | python | def getGenoIndex(self,pos0=None,pos1=None,chrom=None,pos_cum0=None,pos_cum1=None):
"""computes 0-based genotype index from position of cumulative position.
Positions can be given in one out of two ways:
- position (pos0-pos1 on chrom)
- cumulative position (pos_cum0-pos_cum1)
I... | [
"def",
"getGenoIndex",
"(",
"self",
",",
"pos0",
"=",
"None",
",",
"pos1",
"=",
"None",
",",
"chrom",
"=",
"None",
",",
"pos_cum0",
"=",
"None",
",",
"pos_cum1",
"=",
"None",
")",
":",
"if",
"(",
"pos0",
"is",
"not",
"None",
")",
"&",
"(",
"pos1"... | computes 0-based genotype index from position of cumulative position.
Positions can be given in one out of two ways:
- position (pos0-pos1 on chrom)
- cumulative position (pos_cum0-pos_cum1)
If all these are None (default), then all genotypes are returned
Args:
pos... | [
"computes",
"0",
"-",
"based",
"genotype",
"index",
"from",
"position",
"of",
"cumulative",
"position",
".",
"Positions",
"can",
"be",
"given",
"in",
"one",
"out",
"of",
"two",
"ways",
":",
"-",
"position",
"(",
"pos0",
"-",
"pos1",
"on",
"chrom",
")",
... | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/deprecated/archive/data_deprecated.py#L168-L202 |
PMBio/limix-backup | limix/deprecated/archive/data_deprecated.py | QTLData.getGenotypes | def getGenotypes(self,i0=None,i1=None,pos0=None,pos1=None,chrom=None,center=True,unit=True,pos_cum0=None,pos_cum1=None,impute_missing=True):
"""load genotypes.
Optionally the indices for loading subgroups the genotypes for all people
can be given in one out of three ways:
- 0-based ind... | python | def getGenotypes(self,i0=None,i1=None,pos0=None,pos1=None,chrom=None,center=True,unit=True,pos_cum0=None,pos_cum1=None,impute_missing=True):
"""load genotypes.
Optionally the indices for loading subgroups the genotypes for all people
can be given in one out of three ways:
- 0-based ind... | [
"def",
"getGenotypes",
"(",
"self",
",",
"i0",
"=",
"None",
",",
"i1",
"=",
"None",
",",
"pos0",
"=",
"None",
",",
"pos1",
"=",
"None",
",",
"chrom",
"=",
"None",
",",
"center",
"=",
"True",
",",
"unit",
"=",
"True",
",",
"pos_cum0",
"=",
"None",... | load genotypes.
Optionally the indices for loading subgroups the genotypes for all people
can be given in one out of three ways:
- 0-based indexing (i0-i1)
- position (pos0-pos1 on chrom)
- cumulative position (pos_cum0-pos_cum1)
If all these are None (default), then al... | [
"load",
"genotypes",
".",
"Optionally",
"the",
"indices",
"for",
"loading",
"subgroups",
"the",
"genotypes",
"for",
"all",
"people",
"can",
"be",
"given",
"in",
"one",
"out",
"of",
"three",
"ways",
":",
"-",
"0",
"-",
"based",
"indexing",
"(",
"i0",
"-",... | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/deprecated/archive/data_deprecated.py#L204-L236 |
PMBio/limix-backup | limix/deprecated/archive/data_deprecated.py | QTLData.getCovariance | def getCovariance(self,normalize=True,i0=None,i1=None,pos0=None,pos1=None,chrom=None,center=True,unit=True,pos_cum0=None,pos_cum1=None,blocksize=None,X=None,**kw_args):
"""calculate the empirical genotype covariance in a region"""
if X is not None:
K=X.dot(X.T)
Nsnp=X.shape[1]
... | python | def getCovariance(self,normalize=True,i0=None,i1=None,pos0=None,pos1=None,chrom=None,center=True,unit=True,pos_cum0=None,pos_cum1=None,blocksize=None,X=None,**kw_args):
"""calculate the empirical genotype covariance in a region"""
if X is not None:
K=X.dot(X.T)
Nsnp=X.shape[1]
... | [
"def",
"getCovariance",
"(",
"self",
",",
"normalize",
"=",
"True",
",",
"i0",
"=",
"None",
",",
"i1",
"=",
"None",
",",
"pos0",
"=",
"None",
",",
"pos1",
"=",
"None",
",",
"chrom",
"=",
"None",
",",
"center",
"=",
"True",
",",
"unit",
"=",
"True... | calculate the empirical genotype covariance in a region | [
"calculate",
"the",
"empirical",
"genotype",
"covariance",
"in",
"a",
"region"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/deprecated/archive/data_deprecated.py#L238-L269 |
PMBio/limix-backup | limix/deprecated/archive/data_deprecated.py | QTLData.getGenoID | def getGenoID(self,i0=None,i1=None,pos0=None,pos1=None,chrom=None,pos_cum0=None,pos_cum1=None):
"""get genotype IDs.
Optionally the indices for loading subgroups the genotype IDs for all people
can be given in one out of three ways:
- 0-based indexing (i0-i1)
- position (pos0-p... | python | def getGenoID(self,i0=None,i1=None,pos0=None,pos1=None,chrom=None,pos_cum0=None,pos_cum1=None):
"""get genotype IDs.
Optionally the indices for loading subgroups the genotype IDs for all people
can be given in one out of three ways:
- 0-based indexing (i0-i1)
- position (pos0-p... | [
"def",
"getGenoID",
"(",
"self",
",",
"i0",
"=",
"None",
",",
"i1",
"=",
"None",
",",
"pos0",
"=",
"None",
",",
"pos1",
"=",
"None",
",",
"chrom",
"=",
"None",
",",
"pos_cum0",
"=",
"None",
",",
"pos_cum1",
"=",
"None",
")",
":",
"#position based m... | get genotype IDs.
Optionally the indices for loading subgroups the genotype IDs for all people
can be given in one out of three ways:
- 0-based indexing (i0-i1)
- position (pos0-pos1 on chrom)
- cumulative position (pos_cum0-pos_cum1)
If all these are None (default), th... | [
"get",
"genotype",
"IDs",
".",
"Optionally",
"the",
"indices",
"for",
"loading",
"subgroups",
"the",
"genotype",
"IDs",
"for",
"all",
"people",
"can",
"be",
"given",
"in",
"one",
"out",
"of",
"three",
"ways",
":",
"-",
"0",
"-",
"based",
"indexing",
"(",... | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/deprecated/archive/data_deprecated.py#L271-L305 |
PMBio/limix-backup | limix/deprecated/archive/data_deprecated.py | QTLData.getPhenotypes | def getPhenotypes(self,i0=None,i1=None,phenotype_IDs=None,geneIDs=None,environments=None,center=True,impute=True,intersection=False):
"""load Phenotypes
Args:
i0: phenotype indices to load (start individual index)
i1: phenotype indices to load (st... | python | def getPhenotypes(self,i0=None,i1=None,phenotype_IDs=None,geneIDs=None,environments=None,center=True,impute=True,intersection=False):
"""load Phenotypes
Args:
i0: phenotype indices to load (start individual index)
i1: phenotype indices to load (st... | [
"def",
"getPhenotypes",
"(",
"self",
",",
"i0",
"=",
"None",
",",
"i1",
"=",
"None",
",",
"phenotype_IDs",
"=",
"None",
",",
"geneIDs",
"=",
"None",
",",
"environments",
"=",
"None",
",",
"center",
"=",
"True",
",",
"impute",
"=",
"True",
",",
"inter... | load Phenotypes
Args:
i0: phenotype indices to load (start individual index)
i1: phenotype indices to load (stop individual index)
phenotype_IDs: names of phenotypes to load
geneIDs: names of genes to load
envir... | [
"load",
"Phenotypes",
"Args",
":",
"i0",
":",
"phenotype",
"indices",
"to",
"load",
"(",
"start",
"individual",
"index",
")",
"i1",
":",
"phenotype",
"indices",
"to",
"load",
"(",
"stop",
"individual",
"index",
")",
"phenotype_IDs",
":",
"names",
"of",
"ph... | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/deprecated/archive/data_deprecated.py#L307-L359 |
PMBio/limix-backup | limix/deprecated/archive/data_deprecated.py | QTLData.getIcis_geno | def getIcis_geno(self,geneID,cis_window=50E3):
""" if eqtl==True it returns a bool vec for cis """
assert self.eqtl == True, 'Only for eqtl data'
index = self.geneID==geneID
[_chrom,_gene_start,_gene_end] = self.gene_pos[index][0,:]
Icis = (self.genoChrom==_chrom)*(self.genoPos>=... | python | def getIcis_geno(self,geneID,cis_window=50E3):
""" if eqtl==True it returns a bool vec for cis """
assert self.eqtl == True, 'Only for eqtl data'
index = self.geneID==geneID
[_chrom,_gene_start,_gene_end] = self.gene_pos[index][0,:]
Icis = (self.genoChrom==_chrom)*(self.genoPos>=... | [
"def",
"getIcis_geno",
"(",
"self",
",",
"geneID",
",",
"cis_window",
"=",
"50E3",
")",
":",
"assert",
"self",
".",
"eqtl",
"==",
"True",
",",
"'Only for eqtl data'",
"index",
"=",
"self",
".",
"geneID",
"==",
"geneID",
"[",
"_chrom",
",",
"_gene_start",
... | if eqtl==True it returns a bool vec for cis | [
"if",
"eqtl",
"==",
"True",
"it",
"returns",
"a",
"bool",
"vec",
"for",
"cis"
] | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/deprecated/archive/data_deprecated.py#L372-L378 |
PMBio/limix-backup | limix/deprecated/archive/data_deprecated.py | QTLData.subSample | def subSample(self,Irow=None,Icol_geno=None,Icol_pheno=None):
"""sample a particular set of individuals (Irow) or phenotypes (Icol_pheno) or genotypes (Icol_geno)
Args:
Irow: indices for a set of individuals
Icol_pheno: indices for a set of phenotypes
... | python | def subSample(self,Irow=None,Icol_geno=None,Icol_pheno=None):
"""sample a particular set of individuals (Irow) or phenotypes (Icol_pheno) or genotypes (Icol_geno)
Args:
Irow: indices for a set of individuals
Icol_pheno: indices for a set of phenotypes
... | [
"def",
"subSample",
"(",
"self",
",",
"Irow",
"=",
"None",
",",
"Icol_geno",
"=",
"None",
",",
"Icol_pheno",
"=",
"None",
")",
":",
"C",
"=",
"copy",
".",
"copy",
"(",
"self",
")",
"if",
"Irow",
"is",
"not",
"None",
":",
"C",
".",
"genoM",
"=",
... | sample a particular set of individuals (Irow) or phenotypes (Icol_pheno) or genotypes (Icol_geno)
Args:
Irow: indices for a set of individuals
Icol_pheno: indices for a set of phenotypes
Icol_geno: indices for a set of SNPs
Returns... | [
"sample",
"a",
"particular",
"set",
"of",
"individuals",
"(",
"Irow",
")",
"or",
"phenotypes",
"(",
"Icol_pheno",
")",
"or",
"genotypes",
"(",
"Icol_geno",
")",
"Args",
":",
"Irow",
":",
"indices",
"for",
"a",
"set",
"of",
"individuals",
"Icol_pheno",
":",... | train | https://github.com/PMBio/limix-backup/blob/1e201fdb5c694d0d5506f207f3de65d8ef66146c/limix/deprecated/archive/data_deprecated.py#L380-L415 |
TissueMAPS/TmClient | src/python/tmclient/auth.py | load_credentials_from_file | def load_credentials_from_file(username):
'''Loads password for `username` from a file.
The file must be called ``.tm_pass`` and stored in
the home directory. It must provide a YAML mapping where
keys are usernames and values the corresponding passwords.
Parameters
----------
username: str... | python | def load_credentials_from_file(username):
'''Loads password for `username` from a file.
The file must be called ``.tm_pass`` and stored in
the home directory. It must provide a YAML mapping where
keys are usernames and values the corresponding passwords.
Parameters
----------
username: str... | [
"def",
"load_credentials_from_file",
"(",
"username",
")",
":",
"filename",
"=",
"os",
".",
"path",
".",
"expandvars",
"(",
"os",
".",
"path",
".",
"join",
"(",
"'$HOME'",
",",
"'.tm_pass'",
")",
")",
"try",
":",
"with",
"open",
"(",
"filename",
")",
"... | Loads password for `username` from a file.
The file must be called ``.tm_pass`` and stored in
the home directory. It must provide a YAML mapping where
keys are usernames and values the corresponding passwords.
Parameters
----------
username: str
name of the TissueMAPS user
Returns... | [
"Loads",
"password",
"for",
"username",
"from",
"a",
"file",
"."
] | train | https://github.com/TissueMAPS/TmClient/blob/6fb40622af19142cb5169a64b8c2965993a25ab1/src/python/tmclient/auth.py#L23-L69 |
TissueMAPS/TmClient | src/python/tmclient/auth.py | prompt_for_credentials | def prompt_for_credentials(username):
'''Prompt `username` for password.
Parameters
----------
username: str
name of the TissueMAPS user
Returns
-------
str
password for the given user
'''
message = 'Enter password for user "{0}": '.format(username)
password = ... | python | def prompt_for_credentials(username):
'''Prompt `username` for password.
Parameters
----------
username: str
name of the TissueMAPS user
Returns
-------
str
password for the given user
'''
message = 'Enter password for user "{0}": '.format(username)
password = ... | [
"def",
"prompt_for_credentials",
"(",
"username",
")",
":",
"message",
"=",
"'Enter password for user \"{0}\": '",
".",
"format",
"(",
"username",
")",
"password",
"=",
"getpass",
".",
"getpass",
"(",
"message",
")",
"if",
"not",
"password",
":",
"raise",
"Value... | Prompt `username` for password.
Parameters
----------
username: str
name of the TissueMAPS user
Returns
-------
str
password for the given user | [
"Prompt",
"username",
"for",
"password",
"."
] | train | https://github.com/TissueMAPS/TmClient/blob/6fb40622af19142cb5169a64b8c2965993a25ab1/src/python/tmclient/auth.py#L72-L92 |
jf-parent/brome | brome/core/configurator.py | generate_brome_config | def generate_brome_config():
"""Generate a brome config with default value
Returns:
config (dict)
"""
config = {}
for key in iter(default_config):
for inner_key, value in iter(default_config[key].items()):
if key not in config:
config[key] = {}
... | python | def generate_brome_config():
"""Generate a brome config with default value
Returns:
config (dict)
"""
config = {}
for key in iter(default_config):
for inner_key, value in iter(default_config[key].items()):
if key not in config:
config[key] = {}
... | [
"def",
"generate_brome_config",
"(",
")",
":",
"config",
"=",
"{",
"}",
"for",
"key",
"in",
"iter",
"(",
"default_config",
")",
":",
"for",
"inner_key",
",",
"value",
"in",
"iter",
"(",
"default_config",
"[",
"key",
"]",
".",
"items",
"(",
")",
")",
... | Generate a brome config with default value
Returns:
config (dict) | [
"Generate",
"a",
"brome",
"config",
"with",
"default",
"value"
] | train | https://github.com/jf-parent/brome/blob/784f45d96b83b703dd2181cb59ca8ea777c2510e/brome/core/configurator.py#L1-L16 |
jf-parent/brome | brome/core/configurator.py | parse_brome_config_from_browser_config | def parse_brome_config_from_browser_config(browser_config):
"""Parse the browser config and look for brome specific config
Args:
browser_config (dict)
"""
config = {}
brome_keys = [key for key in browser_config if key.find(':') != -1]
for brome_key in brome_keys:
section, opt... | python | def parse_brome_config_from_browser_config(browser_config):
"""Parse the browser config and look for brome specific config
Args:
browser_config (dict)
"""
config = {}
brome_keys = [key for key in browser_config if key.find(':') != -1]
for brome_key in brome_keys:
section, opt... | [
"def",
"parse_brome_config_from_browser_config",
"(",
"browser_config",
")",
":",
"config",
"=",
"{",
"}",
"brome_keys",
"=",
"[",
"key",
"for",
"key",
"in",
"browser_config",
"if",
"key",
".",
"find",
"(",
"':'",
")",
"!=",
"-",
"1",
"]",
"for",
"brome_ke... | Parse the browser config and look for brome specific config
Args:
browser_config (dict) | [
"Parse",
"the",
"browser",
"config",
"and",
"look",
"for",
"brome",
"specific",
"config"
] | train | https://github.com/jf-parent/brome/blob/784f45d96b83b703dd2181cb59ca8ea777c2510e/brome/core/configurator.py#L36-L56 |
dfiel/greenwavereality | greenwavereality/greenwavereality.py | grab_xml | def grab_xml(host, token=None):
"""Grab XML data from Gateway, returned as a dict."""
urllib3.disable_warnings()
if token:
scheme = "https"
if not token:
scheme = "http"
token = "1234567890"
url = (
scheme + '://' + host + '/gwr/gop.php?cmd=GWRBatch&data=<gwrcmds>... | python | def grab_xml(host, token=None):
"""Grab XML data from Gateway, returned as a dict."""
urllib3.disable_warnings()
if token:
scheme = "https"
if not token:
scheme = "http"
token = "1234567890"
url = (
scheme + '://' + host + '/gwr/gop.php?cmd=GWRBatch&data=<gwrcmds>... | [
"def",
"grab_xml",
"(",
"host",
",",
"token",
"=",
"None",
")",
":",
"urllib3",
".",
"disable_warnings",
"(",
")",
"if",
"token",
":",
"scheme",
"=",
"\"https\"",
"if",
"not",
"token",
":",
"scheme",
"=",
"\"http\"",
"token",
"=",
"\"1234567890\"",
"url"... | Grab XML data from Gateway, returned as a dict. | [
"Grab",
"XML",
"data",
"from",
"Gateway",
"returned",
"as",
"a",
"dict",
"."
] | train | https://github.com/dfiel/greenwavereality/blob/cb2c0328385eb7afda910cc483266086432fb708/greenwavereality/greenwavereality.py#L6-L19 |
dfiel/greenwavereality | greenwavereality/greenwavereality.py | set_brightness | def set_brightness(host, did, value, token=None):
"""Set brightness of a bulb or fixture."""
urllib3.disable_warnings()
if token:
scheme = "https"
if not token:
scheme = "http"
token = "1234567890"
url = (
scheme + '://' + host + '/gwr/gop.php?cmd=DeviceSendComman... | python | def set_brightness(host, did, value, token=None):
"""Set brightness of a bulb or fixture."""
urllib3.disable_warnings()
if token:
scheme = "https"
if not token:
scheme = "http"
token = "1234567890"
url = (
scheme + '://' + host + '/gwr/gop.php?cmd=DeviceSendComman... | [
"def",
"set_brightness",
"(",
"host",
",",
"did",
",",
"value",
",",
"token",
"=",
"None",
")",
":",
"urllib3",
".",
"disable_warnings",
"(",
")",
"if",
"token",
":",
"scheme",
"=",
"\"https\"",
"if",
"not",
"token",
":",
"scheme",
"=",
"\"http\"",
"to... | Set brightness of a bulb or fixture. | [
"Set",
"brightness",
"of",
"a",
"bulb",
"or",
"fixture",
"."
] | train | https://github.com/dfiel/greenwavereality/blob/cb2c0328385eb7afda910cc483266086432fb708/greenwavereality/greenwavereality.py#L22-L37 |
dfiel/greenwavereality | greenwavereality/greenwavereality.py | turn_on | def turn_on(host, did, token=None):
"""Turn on bulb or fixture"""
urllib3.disable_warnings()
if token:
scheme = "https"
if not token:
scheme = "http"
token = "1234567890"
url = (
scheme + '://' + host + '/gwr/gop.php?cmd=DeviceSendCommand&data=<gip><version>1</ver... | python | def turn_on(host, did, token=None):
"""Turn on bulb or fixture"""
urllib3.disable_warnings()
if token:
scheme = "https"
if not token:
scheme = "http"
token = "1234567890"
url = (
scheme + '://' + host + '/gwr/gop.php?cmd=DeviceSendCommand&data=<gip><version>1</ver... | [
"def",
"turn_on",
"(",
"host",
",",
"did",
",",
"token",
"=",
"None",
")",
":",
"urllib3",
".",
"disable_warnings",
"(",
")",
"if",
"token",
":",
"scheme",
"=",
"\"https\"",
"if",
"not",
"token",
":",
"scheme",
"=",
"\"http\"",
"token",
"=",
"\"1234567... | Turn on bulb or fixture | [
"Turn",
"on",
"bulb",
"or",
"fixture"
] | train | https://github.com/dfiel/greenwavereality/blob/cb2c0328385eb7afda910cc483266086432fb708/greenwavereality/greenwavereality.py#L49-L63 |
dfiel/greenwavereality | greenwavereality/greenwavereality.py | grab_token | def grab_token(host, email, password):
"""Grab token from gateway. Press sync button before running."""
urllib3.disable_warnings()
url = ('https://' + host + '/gwr/gop.php?cmd=GWRLogin&data=<gip><version>1</version><email>' + str(email) + '</email><password>' + str(password) + '</password></gip>&fmt=xml')
... | python | def grab_token(host, email, password):
"""Grab token from gateway. Press sync button before running."""
urllib3.disable_warnings()
url = ('https://' + host + '/gwr/gop.php?cmd=GWRLogin&data=<gip><version>1</version><email>' + str(email) + '</email><password>' + str(password) + '</password></gip>&fmt=xml')
... | [
"def",
"grab_token",
"(",
"host",
",",
"email",
",",
"password",
")",
":",
"urllib3",
".",
"disable_warnings",
"(",
")",
"url",
"=",
"(",
"'https://'",
"+",
"host",
"+",
"'/gwr/gop.php?cmd=GWRLogin&data=<gip><version>1</version><email>'",
"+",
"str",
"(",
"email",... | Grab token from gateway. Press sync button before running. | [
"Grab",
"token",
"from",
"gateway",
".",
"Press",
"sync",
"button",
"before",
"running",
"."
] | train | https://github.com/dfiel/greenwavereality/blob/cb2c0328385eb7afda910cc483266086432fb708/greenwavereality/greenwavereality.py#L88-L97 |
dfiel/greenwavereality | greenwavereality/greenwavereality.py | grab_bulbs | def grab_bulbs(host, token=None):
"""Grab XML, then add all bulbs to a dict. Removes room functionality"""
xml = grab_xml(host, token)
bulbs = {}
for room in xml:
for device in room['device']:
bulbs[int(device['did'])] = device
return bulbs | python | def grab_bulbs(host, token=None):
"""Grab XML, then add all bulbs to a dict. Removes room functionality"""
xml = grab_xml(host, token)
bulbs = {}
for room in xml:
for device in room['device']:
bulbs[int(device['did'])] = device
return bulbs | [
"def",
"grab_bulbs",
"(",
"host",
",",
"token",
"=",
"None",
")",
":",
"xml",
"=",
"grab_xml",
"(",
"host",
",",
"token",
")",
"bulbs",
"=",
"{",
"}",
"for",
"room",
"in",
"xml",
":",
"for",
"device",
"in",
"room",
"[",
"'device'",
"]",
":",
"bul... | Grab XML, then add all bulbs to a dict. Removes room functionality | [
"Grab",
"XML",
"then",
"add",
"all",
"bulbs",
"to",
"a",
"dict",
".",
"Removes",
"room",
"functionality"
] | train | https://github.com/dfiel/greenwavereality/blob/cb2c0328385eb7afda910cc483266086432fb708/greenwavereality/greenwavereality.py#L99-L106 |
akfullfo/taskforce | taskforce/http.py | Client.getmap | def getmap(self, path, query=None):
"""
Performs a GET request where the response content type is required to be
"application/json" and the content is a JSON-encoded data structure.
The decoded structure is returned.
"""
code, data, ctype = self.get(path, query)
if ct... | python | def getmap(self, path, query=None):
"""
Performs a GET request where the response content type is required to be
"application/json" and the content is a JSON-encoded data structure.
The decoded structure is returned.
"""
code, data, ctype = self.get(path, query)
if ct... | [
"def",
"getmap",
"(",
"self",
",",
"path",
",",
"query",
"=",
"None",
")",
":",
"code",
",",
"data",
",",
"ctype",
"=",
"self",
".",
"get",
"(",
"path",
",",
"query",
")",
"if",
"ctype",
"!=",
"'application/json'",
":",
"self",
".",
"log",
".",
"... | Performs a GET request where the response content type is required to be
"application/json" and the content is a JSON-encoded data structure.
The decoded structure is returned. | [
"Performs",
"a",
"GET",
"request",
"where",
"the",
"response",
"content",
"type",
"is",
"required",
"to",
"be",
"application",
"/",
"json",
"and",
"the",
"content",
"is",
"a",
"JSON",
"-",
"encoded",
"data",
"structure",
".",
"The",
"decoded",
"structure",
... | train | https://github.com/akfullfo/taskforce/blob/bc6dd744bd33546447d085dbd18a350532220193/taskforce/http.py#L220-L235 |
akfullfo/taskforce | taskforce/http.py | Client.post | def post(self, path, valuemap=None, query=None):
"""
Performs a POST request. "valuemap" is a dict sent as "application/x-www-form-urlencoded".
"query" is as for get(). Return is same as get().
"""
self.lastpath = path
if query is not None:
self.lastpath += '?' ... | python | def post(self, path, valuemap=None, query=None):
"""
Performs a POST request. "valuemap" is a dict sent as "application/x-www-form-urlencoded".
"query" is as for get(). Return is same as get().
"""
self.lastpath = path
if query is not None:
self.lastpath += '?' ... | [
"def",
"post",
"(",
"self",
",",
"path",
",",
"valuemap",
"=",
"None",
",",
"query",
"=",
"None",
")",
":",
"self",
".",
"lastpath",
"=",
"path",
"if",
"query",
"is",
"not",
"None",
":",
"self",
".",
"lastpath",
"+=",
"'?'",
"+",
"urlencode",
"(",
... | Performs a POST request. "valuemap" is a dict sent as "application/x-www-form-urlencoded".
"query" is as for get(). Return is same as get(). | [
"Performs",
"a",
"POST",
"request",
".",
"valuemap",
"is",
"a",
"dict",
"sent",
"as",
"application",
"/",
"x",
"-",
"www",
"-",
"form",
"-",
"urlencoded",
".",
"query",
"is",
"as",
"for",
"get",
"()",
".",
"Return",
"is",
"same",
"as",
"get",
"()",
... | train | https://github.com/akfullfo/taskforce/blob/bc6dd744bd33546447d085dbd18a350532220193/taskforce/http.py#L237-L257 |
akfullfo/taskforce | taskforce/http.py | Client.postmap | def postmap(self, path, valuemap=None, query=None):
"""
Performs a POST request as per post() but the response content type
is required to be "application/json" and is processed as with getmap().
"""
code, data, ctype = self.post(path, valuemap, query)
if ctype != 'applicatio... | python | def postmap(self, path, valuemap=None, query=None):
"""
Performs a POST request as per post() but the response content type
is required to be "application/json" and is processed as with getmap().
"""
code, data, ctype = self.post(path, valuemap, query)
if ctype != 'applicatio... | [
"def",
"postmap",
"(",
"self",
",",
"path",
",",
"valuemap",
"=",
"None",
",",
"query",
"=",
"None",
")",
":",
"code",
",",
"data",
",",
"ctype",
"=",
"self",
".",
"post",
"(",
"path",
",",
"valuemap",
",",
"query",
")",
"if",
"ctype",
"!=",
"'ap... | Performs a POST request as per post() but the response content type
is required to be "application/json" and is processed as with getmap(). | [
"Performs",
"a",
"POST",
"request",
"as",
"per",
"post",
"()",
"but",
"the",
"response",
"content",
"type",
"is",
"required",
"to",
"be",
"application",
"/",
"json",
"and",
"is",
"processed",
"as",
"with",
"getmap",
"()",
"."
] | train | https://github.com/akfullfo/taskforce/blob/bc6dd744bd33546447d085dbd18a350532220193/taskforce/http.py#L259-L273 |
akfullfo/taskforce | taskforce/http.py | Client.request | def request(self, method, url, *args):
"""
Pass-thru method to make this class behave a little like HTTPConnection
"""
return self.http.request(method, url, *args) | python | def request(self, method, url, *args):
"""
Pass-thru method to make this class behave a little like HTTPConnection
"""
return self.http.request(method, url, *args) | [
"def",
"request",
"(",
"self",
",",
"method",
",",
"url",
",",
"*",
"args",
")",
":",
"return",
"self",
".",
"http",
".",
"request",
"(",
"method",
",",
"url",
",",
"*",
"args",
")"
] | Pass-thru method to make this class behave a little like HTTPConnection | [
"Pass",
"-",
"thru",
"method",
"to",
"make",
"this",
"class",
"behave",
"a",
"little",
"like",
"HTTPConnection"
] | train | https://github.com/akfullfo/taskforce/blob/bc6dd744bd33546447d085dbd18a350532220193/taskforce/http.py#L275-L279 |
akfullfo/taskforce | taskforce/http.py | Client.getresponse | def getresponse(self):
"""
Pass-thru method to make this class behave a little like HTTPConnection
"""
resp = self.http.getresponse()
self.log.info("resp is %s", str(resp))
if resp.status < 400:
return resp
else:
errtext = resp.read()
... | python | def getresponse(self):
"""
Pass-thru method to make this class behave a little like HTTPConnection
"""
resp = self.http.getresponse()
self.log.info("resp is %s", str(resp))
if resp.status < 400:
return resp
else:
errtext = resp.read()
... | [
"def",
"getresponse",
"(",
"self",
")",
":",
"resp",
"=",
"self",
".",
"http",
".",
"getresponse",
"(",
")",
"self",
".",
"log",
".",
"info",
"(",
"\"resp is %s\"",
",",
"str",
"(",
"resp",
")",
")",
"if",
"resp",
".",
"status",
"<",
"400",
":",
... | Pass-thru method to make this class behave a little like HTTPConnection | [
"Pass",
"-",
"thru",
"method",
"to",
"make",
"this",
"class",
"behave",
"a",
"little",
"like",
"HTTPConnection"
] | train | https://github.com/akfullfo/taskforce/blob/bc6dd744bd33546447d085dbd18a350532220193/taskforce/http.py#L281-L292 |
theonion/djes | djes/models.py | IndexableManager.client | def client(self):
"""Get an elasticsearch client
"""
if not hasattr(self, "_client"):
self._client = connections.get_connection("default")
return self._client | python | def client(self):
"""Get an elasticsearch client
"""
if not hasattr(self, "_client"):
self._client = connections.get_connection("default")
return self._client | [
"def",
"client",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"\"_client\"",
")",
":",
"self",
".",
"_client",
"=",
"connections",
".",
"get_connection",
"(",
"\"default\"",
")",
"return",
"self",
".",
"_client"
] | Get an elasticsearch client | [
"Get",
"an",
"elasticsearch",
"client"
] | train | https://github.com/theonion/djes/blob/8f7347382c74172e82e959e3dfbc12b18fbb523f/djes/models.py#L16-L21 |
theonion/djes | djes/models.py | IndexableManager.mapping | def mapping(self):
"""Get a mapping class for this model
This method will return a Mapping class for your model, generating it using settings from a
`Mapping` class on your model (if one exists). The generated class is cached on the manager.
"""
if not hasattr(self, "_mapping"):... | python | def mapping(self):
"""Get a mapping class for this model
This method will return a Mapping class for your model, generating it using settings from a
`Mapping` class on your model (if one exists). The generated class is cached on the manager.
"""
if not hasattr(self, "_mapping"):... | [
"def",
"mapping",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"\"_mapping\"",
")",
":",
"if",
"hasattr",
"(",
"self",
".",
"model",
",",
"\"Mapping\"",
")",
":",
"mapping_klass",
"=",
"type",
"(",
"\"Mapping\"",
",",
"(",
"DjangoMa... | Get a mapping class for this model
This method will return a Mapping class for your model, generating it using settings from a
`Mapping` class on your model (if one exists). The generated class is cached on the manager. | [
"Get",
"a",
"mapping",
"class",
"for",
"this",
"model"
] | train | https://github.com/theonion/djes/blob/8f7347382c74172e82e959e3dfbc12b18fbb523f/djes/models.py#L24-L38 |
theonion/djes | djes/models.py | IndexableManager.from_es | def from_es(self, hit):
"""Returns a Django model instance, using a document from Elasticsearch"""
doc = hit.copy()
klass = shallow_class_factory(self.model)
# We can pass in the entire source, except when we have a non-indexable many-to-many
for field in self.model._meta.get_fi... | python | def from_es(self, hit):
"""Returns a Django model instance, using a document from Elasticsearch"""
doc = hit.copy()
klass = shallow_class_factory(self.model)
# We can pass in the entire source, except when we have a non-indexable many-to-many
for field in self.model._meta.get_fi... | [
"def",
"from_es",
"(",
"self",
",",
"hit",
")",
":",
"doc",
"=",
"hit",
".",
"copy",
"(",
")",
"klass",
"=",
"shallow_class_factory",
"(",
"self",
".",
"model",
")",
"# We can pass in the entire source, except when we have a non-indexable many-to-many",
"for",
"fiel... | Returns a Django model instance, using a document from Elasticsearch | [
"Returns",
"a",
"Django",
"model",
"instance",
"using",
"a",
"document",
"from",
"Elasticsearch"
] | train | https://github.com/theonion/djes/blob/8f7347382c74172e82e959e3dfbc12b18fbb523f/djes/models.py#L40-L72 |
theonion/djes | djes/models.py | IndexableManager.get | def get(self, **kwargs):
"""Get a object from Elasticsearch by id
"""
# get the doc id
id = None
if "id" in kwargs:
id = kwargs["id"]
del kwargs["id"]
elif "pk" in kwargs:
id = kwargs["pk"]
del kwargs["pk"]
else:
... | python | def get(self, **kwargs):
"""Get a object from Elasticsearch by id
"""
# get the doc id
id = None
if "id" in kwargs:
id = kwargs["id"]
del kwargs["id"]
elif "pk" in kwargs:
id = kwargs["pk"]
del kwargs["pk"]
else:
... | [
"def",
"get",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"# get the doc id",
"id",
"=",
"None",
"if",
"\"id\"",
"in",
"kwargs",
":",
"id",
"=",
"kwargs",
"[",
"\"id\"",
"]",
"del",
"kwargs",
"[",
"\"id\"",
"]",
"elif",
"\"pk\"",
"in",
"kwargs",
... | Get a object from Elasticsearch by id | [
"Get",
"a",
"object",
"from",
"Elasticsearch",
"by",
"id"
] | train | https://github.com/theonion/djes/blob/8f7347382c74172e82e959e3dfbc12b18fbb523f/djes/models.py#L74-L101 |
theonion/djes | djes/models.py | IndexableManager.refresh | def refresh(self):
"""Force a refresh of the Elasticsearch index
"""
self.client.indices.refresh(index=self.model.search_objects.mapping.index) | python | def refresh(self):
"""Force a refresh of the Elasticsearch index
"""
self.client.indices.refresh(index=self.model.search_objects.mapping.index) | [
"def",
"refresh",
"(",
"self",
")",
":",
"self",
".",
"client",
".",
"indices",
".",
"refresh",
"(",
"index",
"=",
"self",
".",
"model",
".",
"search_objects",
".",
"mapping",
".",
"index",
")"
] | Force a refresh of the Elasticsearch index | [
"Force",
"a",
"refresh",
"of",
"the",
"Elasticsearch",
"index"
] | train | https://github.com/theonion/djes/blob/8f7347382c74172e82e959e3dfbc12b18fbb523f/djes/models.py#L124-L127 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.