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 |
|---|---|---|---|---|---|---|---|---|---|---|
daler/gffutils | gffutils/interface.py | FeatureDB.bed12 | def bed12(self, feature, block_featuretype=['exon'],
thick_featuretype=['CDS'], thin_featuretype=None,
name_field='ID', color=None):
"""
Converts `feature` into a BED12 format.
GFF and GTF files do not necessarily define genes consistently, so this
method pro... | python | def bed12(self, feature, block_featuretype=['exon'],
thick_featuretype=['CDS'], thin_featuretype=None,
name_field='ID', color=None):
"""
Converts `feature` into a BED12 format.
GFF and GTF files do not necessarily define genes consistently, so this
method pro... | [
"def",
"bed12",
"(",
"self",
",",
"feature",
",",
"block_featuretype",
"=",
"[",
"'exon'",
"]",
",",
"thick_featuretype",
"=",
"[",
"'CDS'",
"]",
",",
"thin_featuretype",
"=",
"None",
",",
"name_field",
"=",
"'ID'",
",",
"color",
"=",
"None",
")",
":",
... | Converts `feature` into a BED12 format.
GFF and GTF files do not necessarily define genes consistently, so this
method provides flexiblity in specifying what to call a "transcript".
Parameters
----------
feature : str or Feature instance
In most cases, this feature ... | [
"Converts",
"feature",
"into",
"a",
"BED12",
"format",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/interface.py#L1154-L1299 |
daler/gffutils | gffutils/iterators.py | DataIterator | def DataIterator(data, checklines=10, transform=None,
force_dialect_check=False, from_string=False, **kwargs):
"""
Iterate over features, no matter how they are provided.
Parameters
----------
data : str, iterable of Feature objs, FeatureDB
`data` can be a string (filename,... | python | def DataIterator(data, checklines=10, transform=None,
force_dialect_check=False, from_string=False, **kwargs):
"""
Iterate over features, no matter how they are provided.
Parameters
----------
data : str, iterable of Feature objs, FeatureDB
`data` can be a string (filename,... | [
"def",
"DataIterator",
"(",
"data",
",",
"checklines",
"=",
"10",
",",
"transform",
"=",
"None",
",",
"force_dialect_check",
"=",
"False",
",",
"from_string",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"_kwargs",
"=",
"dict",
"(",
"data",
"=",
"d... | Iterate over features, no matter how they are provided.
Parameters
----------
data : str, iterable of Feature objs, FeatureDB
`data` can be a string (filename, URL, or contents of a file, if
from_string=True), any arbitrary iterable of features, or a FeatureDB
(in which case its all... | [
"Iterate",
"over",
"features",
"no",
"matter",
"how",
"they",
"are",
"provided",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/iterators.py#L229-L279 |
tisimst/pyDOE | pyDOE/doe_box_behnken.py | bbdesign | def bbdesign(n, center=None):
"""
Create a Box-Behnken design
Parameters
----------
n : int
The number of factors in the design
Optional
--------
center : int
The number of center points to include (default = 1).
Returns
-------
... | python | def bbdesign(n, center=None):
"""
Create a Box-Behnken design
Parameters
----------
n : int
The number of factors in the design
Optional
--------
center : int
The number of center points to include (default = 1).
Returns
-------
... | [
"def",
"bbdesign",
"(",
"n",
",",
"center",
"=",
"None",
")",
":",
"assert",
"n",
">=",
"3",
",",
"'Number of variables must be at least 3'",
"# First, compute a factorial DOE with 2 parameters\r",
"H_fact",
"=",
"ff2n",
"(",
"2",
")",
"# Now we populate the real DOE wi... | Create a Box-Behnken design
Parameters
----------
n : int
The number of factors in the design
Optional
--------
center : int
The number of center points to include (default = 1).
Returns
-------
mat : 2d-array
The design matrix
... | [
"Create",
"a",
"Box",
"-",
"Behnken",
"design",
"Parameters",
"----------",
"n",
":",
"int",
"The",
"number",
"of",
"factors",
"in",
"the",
"design",
"Optional",
"--------",
"center",
":",
"int",
"The",
"number",
"of",
"center",
"points",
"to",
"include",
... | train | https://github.com/tisimst/pyDOE/blob/436143702507a5c8ff87b361223eee8171d6a1d7/pyDOE/doe_box_behnken.py#L22-L91 |
daler/gffutils | gffutils/inspect.py | inspect | def inspect(data, look_for=['featuretype', 'chrom', 'attribute_keys',
'feature_count'], limit=None, verbose=True):
"""
Inspect a GFF or GTF data source.
This function is useful for figuring out the different featuretypes found
in a file (for potential removal before creating... | python | def inspect(data, look_for=['featuretype', 'chrom', 'attribute_keys',
'feature_count'], limit=None, verbose=True):
"""
Inspect a GFF or GTF data source.
This function is useful for figuring out the different featuretypes found
in a file (for potential removal before creating... | [
"def",
"inspect",
"(",
"data",
",",
"look_for",
"=",
"[",
"'featuretype'",
",",
"'chrom'",
",",
"'attribute_keys'",
",",
"'feature_count'",
"]",
",",
"limit",
"=",
"None",
",",
"verbose",
"=",
"True",
")",
":",
"results",
"=",
"{",
"}",
"obj_attrs",
"=",... | Inspect a GFF or GTF data source.
This function is useful for figuring out the different featuretypes found
in a file (for potential removal before creating a FeatureDB).
Returns a dictionary with a key for each item in `look_for` and
a corresponding value that is a dictionary of how many of each uniq... | [
"Inspect",
"a",
"GFF",
"or",
"GTF",
"data",
"source",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/inspect.py#L7-L105 |
tisimst/pyDOE | pyDOE/doe_factorial.py | fullfact | def fullfact(levels):
"""
Create a general full-factorial design
Parameters
----------
levels : array-like
An array of integers that indicate the number of levels of each input
design factor.
Returns
-------
mat : 2d-array
The design matrix ... | python | def fullfact(levels):
"""
Create a general full-factorial design
Parameters
----------
levels : array-like
An array of integers that indicate the number of levels of each input
design factor.
Returns
-------
mat : 2d-array
The design matrix ... | [
"def",
"fullfact",
"(",
"levels",
")",
":",
"n",
"=",
"len",
"(",
"levels",
")",
"# number of factors\r",
"nb_lines",
"=",
"np",
".",
"prod",
"(",
"levels",
")",
"# number of trial conditions\r",
"H",
"=",
"np",
".",
"zeros",
"(",
"(",
"nb_lines",
",",
"... | Create a general full-factorial design
Parameters
----------
levels : array-like
An array of integers that indicate the number of levels of each input
design factor.
Returns
-------
mat : 2d-array
The design matrix with coded levels 0 to k-1 for a k-l... | [
"Create",
"a",
"general",
"full",
"-",
"factorial",
"design",
"Parameters",
"----------",
"levels",
":",
"array",
"-",
"like",
"An",
"array",
"of",
"integers",
"that",
"indicate",
"the",
"number",
"of",
"levels",
"of",
"each",
"input",
"design",
"factor",
".... | train | https://github.com/tisimst/pyDOE/blob/436143702507a5c8ff87b361223eee8171d6a1d7/pyDOE/doe_factorial.py#L21-L82 |
tisimst/pyDOE | pyDOE/doe_factorial.py | fracfact | def fracfact(gen):
"""
Create a 2-level fractional-factorial design with a generator string.
Parameters
----------
gen : str
A string, consisting of lowercase, uppercase letters or operators "-"
and "+", indicating the factors of the experiment
Returns
--... | python | def fracfact(gen):
"""
Create a 2-level fractional-factorial design with a generator string.
Parameters
----------
gen : str
A string, consisting of lowercase, uppercase letters or operators "-"
and "+", indicating the factors of the experiment
Returns
--... | [
"def",
"fracfact",
"(",
"gen",
")",
":",
"# Recognize letters and combinations\r",
"A",
"=",
"[",
"item",
"for",
"item",
"in",
"re",
".",
"split",
"(",
"'\\-?\\s?\\+?'",
",",
"gen",
")",
"if",
"item",
"]",
"# remove empty strings\r",
"C",
"=",
"[",
"len",
... | Create a 2-level fractional-factorial design with a generator string.
Parameters
----------
gen : str
A string, consisting of lowercase, uppercase letters or operators "-"
and "+", indicating the factors of the experiment
Returns
-------
H : 2d-array
... | [
"Create",
"a",
"2",
"-",
"level",
"fractional",
"-",
"factorial",
"design",
"with",
"a",
"generator",
"string",
".",
"Parameters",
"----------",
"gen",
":",
"str",
"A",
"string",
"consisting",
"of",
"lowercase",
"uppercase",
"letters",
"or",
"operators",
"-",
... | train | https://github.com/tisimst/pyDOE/blob/436143702507a5c8ff87b361223eee8171d6a1d7/pyDOE/doe_factorial.py#L119-L231 |
tisimst/pyDOE | pyDOE/doe_lhs.py | lhs | def lhs(n, samples=None, criterion=None, iterations=None):
"""
Generate a latin-hypercube design
Parameters
----------
n : int
The number of factors to generate samples for
Optional
--------
samples : int
The number of samples to generate for each fa... | python | def lhs(n, samples=None, criterion=None, iterations=None):
"""
Generate a latin-hypercube design
Parameters
----------
n : int
The number of factors to generate samples for
Optional
--------
samples : int
The number of samples to generate for each fa... | [
"def",
"lhs",
"(",
"n",
",",
"samples",
"=",
"None",
",",
"criterion",
"=",
"None",
",",
"iterations",
"=",
"None",
")",
":",
"H",
"=",
"None",
"if",
"samples",
"is",
"None",
":",
"samples",
"=",
"n",
"if",
"criterion",
"is",
"not",
"None",
":",
... | Generate a latin-hypercube design
Parameters
----------
n : int
The number of factors to generate samples for
Optional
--------
samples : int
The number of samples to generate for each factor (Default: n)
criterion : str
Allowable values are "cen... | [
"Generate",
"a",
"latin",
"-",
"hypercube",
"design",
"Parameters",
"----------",
"n",
":",
"int",
"The",
"number",
"of",
"factors",
"to",
"generate",
"samples",
"for",
"Optional",
"--------",
"samples",
":",
"int",
"The",
"number",
"of",
"samples",
"to",
"g... | train | https://github.com/tisimst/pyDOE/blob/436143702507a5c8ff87b361223eee8171d6a1d7/pyDOE/doe_lhs.py#L21-L119 |
tisimst/pyDOE | pyDOE/doe_lhs.py | _pdist | def _pdist(x):
"""
Calculate the pair-wise point distances of a matrix
Parameters
----------
x : 2d-array
An m-by-n array of scalars, where there are m points in n dimensions.
Returns
-------
d : array
A 1-by-b array of scalars, where b = m*(m - 1)/2... | python | def _pdist(x):
"""
Calculate the pair-wise point distances of a matrix
Parameters
----------
x : 2d-array
An m-by-n array of scalars, where there are m points in n dimensions.
Returns
-------
d : array
A 1-by-b array of scalars, where b = m*(m - 1)/2... | [
"def",
"_pdist",
"(",
"x",
")",
":",
"x",
"=",
"np",
".",
"atleast_2d",
"(",
"x",
")",
"assert",
"len",
"(",
"x",
".",
"shape",
")",
"==",
"2",
",",
"'Input array must be 2d-dimensional'",
"m",
",",
"n",
"=",
"x",
".",
"shape",
"if",
"m",
"<",
"2... | Calculate the pair-wise point distances of a matrix
Parameters
----------
x : 2d-array
An m-by-n array of scalars, where there are m points in n dimensions.
Returns
-------
d : array
A 1-by-b array of scalars, where b = m*(m - 1)/2. This array contains
... | [
"Calculate",
"the",
"pair",
"-",
"wise",
"point",
"distances",
"of",
"a",
"matrix",
"Parameters",
"----------",
"x",
":",
"2d",
"-",
"array",
"An",
"m",
"-",
"by",
"-",
"n",
"array",
"of",
"scalars",
"where",
"there",
"are",
"m",
"points",
"in",
"n",
... | train | https://github.com/tisimst/pyDOE/blob/436143702507a5c8ff87b361223eee8171d6a1d7/pyDOE/doe_lhs.py#L200-L243 |
daler/gffutils | gffutils/scripts/gffutils-flybase-convert.py | clean_gff | def clean_gff(gff, cleaned, add_chr=False, chroms_to_ignore=None,
featuretypes_to_ignore=None):
"""
Cleans a GFF file by removing features on unwanted chromosomes and of
unwanted featuretypes. Optionally adds "chr" to chrom names.
"""
logger.info("Cleaning GFF")
chroms_to_ignore =... | python | def clean_gff(gff, cleaned, add_chr=False, chroms_to_ignore=None,
featuretypes_to_ignore=None):
"""
Cleans a GFF file by removing features on unwanted chromosomes and of
unwanted featuretypes. Optionally adds "chr" to chrom names.
"""
logger.info("Cleaning GFF")
chroms_to_ignore =... | [
"def",
"clean_gff",
"(",
"gff",
",",
"cleaned",
",",
"add_chr",
"=",
"False",
",",
"chroms_to_ignore",
"=",
"None",
",",
"featuretypes_to_ignore",
"=",
"None",
")",
":",
"logger",
".",
"info",
"(",
"\"Cleaning GFF\"",
")",
"chroms_to_ignore",
"=",
"chroms_to_i... | Cleans a GFF file by removing features on unwanted chromosomes and of
unwanted featuretypes. Optionally adds "chr" to chrom names. | [
"Cleans",
"a",
"GFF",
"file",
"by",
"removing",
"features",
"on",
"unwanted",
"chromosomes",
"and",
"of",
"unwanted",
"featuretypes",
".",
"Optionally",
"adds",
"chr",
"to",
"chrom",
"names",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/scripts/gffutils-flybase-convert.py#L25-L45 |
tisimst/pyDOE | pyDOE/doe_composite.py | ccdesign | def ccdesign(n, center=(4, 4), alpha='orthogonal', face='circumscribed'):
"""
Central composite design
Parameters
----------
n : int
The number of factors in the design.
Optional
--------
center : int array
A 1-by-2 array of integers, the number of c... | python | def ccdesign(n, center=(4, 4), alpha='orthogonal', face='circumscribed'):
"""
Central composite design
Parameters
----------
n : int
The number of factors in the design.
Optional
--------
center : int array
A 1-by-2 array of integers, the number of c... | [
"def",
"ccdesign",
"(",
"n",
",",
"center",
"=",
"(",
"4",
",",
"4",
")",
",",
"alpha",
"=",
"'orthogonal'",
",",
"face",
"=",
"'circumscribed'",
")",
":",
"# Check inputs\r",
"assert",
"isinstance",
"(",
"n",
",",
"int",
")",
"and",
"n",
">",
"1",
... | Central composite design
Parameters
----------
n : int
The number of factors in the design.
Optional
--------
center : int array
A 1-by-2 array of integers, the number of center points in each block
of the design. (Default: (4, 4)).
alpha : str
... | [
"Central",
"composite",
"design",
"Parameters",
"----------",
"n",
":",
"int",
"The",
"number",
"of",
"factors",
"in",
"the",
"design",
".",
"Optional",
"--------",
"center",
":",
"int",
"array",
"A",
"1",
"-",
"by",
"-",
"2",
"array",
"of",
"integers",
... | train | https://github.com/tisimst/pyDOE/blob/436143702507a5c8ff87b361223eee8171d6a1d7/pyDOE/doe_composite.py#L24-L160 |
daler/gffutils | gffutils/feature.py | feature_from_line | def feature_from_line(line, dialect=None, strict=True, keep_order=False):
"""
Given a line from a GFF file, return a Feature object
Parameters
----------
line : string
strict : bool
If True (default), assume `line` is a single, tab-delimited string that
has at least 9 fields.
... | python | def feature_from_line(line, dialect=None, strict=True, keep_order=False):
"""
Given a line from a GFF file, return a Feature object
Parameters
----------
line : string
strict : bool
If True (default), assume `line` is a single, tab-delimited string that
has at least 9 fields.
... | [
"def",
"feature_from_line",
"(",
"line",
",",
"dialect",
"=",
"None",
",",
"strict",
"=",
"True",
",",
"keep_order",
"=",
"False",
")",
":",
"if",
"not",
"strict",
":",
"lines",
"=",
"line",
".",
"splitlines",
"(",
"False",
")",
"_lines",
"=",
"[",
"... | Given a line from a GFF file, return a Feature object
Parameters
----------
line : string
strict : bool
If True (default), assume `line` is a single, tab-delimited string that
has at least 9 fields.
If False, then the input can have a more flexible format, useful for
c... | [
"Given",
"a",
"line",
"from",
"a",
"GFF",
"file",
"return",
"a",
"Feature",
"object"
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/feature.py#L356-L411 |
daler/gffutils | gffutils/feature.py | Feature.calc_bin | def calc_bin(self, _bin=None):
"""
Calculate the smallest UCSC genomic bin that will contain this feature.
"""
if _bin is None:
try:
_bin = bins.bins(self.start, self.end, one=True)
except TypeError:
_bin = None
return _bin | python | def calc_bin(self, _bin=None):
"""
Calculate the smallest UCSC genomic bin that will contain this feature.
"""
if _bin is None:
try:
_bin = bins.bins(self.start, self.end, one=True)
except TypeError:
_bin = None
return _bin | [
"def",
"calc_bin",
"(",
"self",
",",
"_bin",
"=",
"None",
")",
":",
"if",
"_bin",
"is",
"None",
":",
"try",
":",
"_bin",
"=",
"bins",
".",
"bins",
"(",
"self",
".",
"start",
",",
"self",
".",
"end",
",",
"one",
"=",
"True",
")",
"except",
"Type... | Calculate the smallest UCSC genomic bin that will contain this feature. | [
"Calculate",
"the",
"smallest",
"UCSC",
"genomic",
"bin",
"that",
"will",
"contain",
"this",
"feature",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/feature.py#L182-L191 |
daler/gffutils | gffutils/feature.py | Feature.astuple | def astuple(self, encoding=None):
"""
Return a tuple suitable for import into a database.
Attributes field and extra field jsonified into strings. The order of
fields is such that they can be supplied as arguments for the query
defined in :attr:`gffutils.constants._INSERT`.
... | python | def astuple(self, encoding=None):
"""
Return a tuple suitable for import into a database.
Attributes field and extra field jsonified into strings. The order of
fields is such that they can be supplied as arguments for the query
defined in :attr:`gffutils.constants._INSERT`.
... | [
"def",
"astuple",
"(",
"self",
",",
"encoding",
"=",
"None",
")",
":",
"if",
"not",
"encoding",
":",
"return",
"(",
"self",
".",
"id",
",",
"self",
".",
"seqid",
",",
"self",
".",
"source",
",",
"self",
".",
"featuretype",
",",
"self",
".",
"start"... | Return a tuple suitable for import into a database.
Attributes field and extra field jsonified into strings. The order of
fields is such that they can be supplied as arguments for the query
defined in :attr:`gffutils.constants._INSERT`.
If `encoding` is not None, then convert string fi... | [
"Return",
"a",
"tuple",
"suitable",
"for",
"import",
"into",
"a",
"database",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/feature.py#L293-L322 |
daler/gffutils | gffutils/feature.py | Feature.sequence | def sequence(self, fasta, use_strand=True):
"""
Retrieves the sequence of this feature as a string.
Uses the pyfaidx package.
Parameters
----------
fasta : str
If str, then it's a FASTA-format filename; otherwise assume it's
a pyfaidx.Fasta obje... | python | def sequence(self, fasta, use_strand=True):
"""
Retrieves the sequence of this feature as a string.
Uses the pyfaidx package.
Parameters
----------
fasta : str
If str, then it's a FASTA-format filename; otherwise assume it's
a pyfaidx.Fasta obje... | [
"def",
"sequence",
"(",
"self",
",",
"fasta",
",",
"use_strand",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"fasta",
",",
"six",
".",
"string_types",
")",
":",
"fasta",
"=",
"Fasta",
"(",
"fasta",
",",
"as_raw",
"=",
"False",
")",
"# recall GTF/GF... | Retrieves the sequence of this feature as a string.
Uses the pyfaidx package.
Parameters
----------
fasta : str
If str, then it's a FASTA-format filename; otherwise assume it's
a pyfaidx.Fasta object.
use_strand : bool
If True (default), th... | [
"Retrieves",
"the",
"sequence",
"of",
"this",
"feature",
"as",
"a",
"string",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/feature.py#L324-L353 |
daler/gffutils | gffutils/convert.py | to_bed12 | def to_bed12(f, db, child_type='exon', name_field='ID'):
"""
Given a top-level feature (e.g., transcript), construct a BED12 entry
Parameters
----------
f : Feature object or string
This is the top-level feature represented by one BED12 line. For
a canonical GFF or GTF, this will ge... | python | def to_bed12(f, db, child_type='exon', name_field='ID'):
"""
Given a top-level feature (e.g., transcript), construct a BED12 entry
Parameters
----------
f : Feature object or string
This is the top-level feature represented by one BED12 line. For
a canonical GFF or GTF, this will ge... | [
"def",
"to_bed12",
"(",
"f",
",",
"db",
",",
"child_type",
"=",
"'exon'",
",",
"name_field",
"=",
"'ID'",
")",
":",
"if",
"isinstance",
"(",
"f",
",",
"six",
".",
"string_types",
")",
":",
"f",
"=",
"db",
"[",
"f",
"]",
"children",
"=",
"list",
"... | Given a top-level feature (e.g., transcript), construct a BED12 entry
Parameters
----------
f : Feature object or string
This is the top-level feature represented by one BED12 line. For
a canonical GFF or GTF, this will generally be a transcript.
db : a FeatureDB object
This is ... | [
"Given",
"a",
"top",
"-",
"level",
"feature",
"(",
"e",
".",
"g",
".",
"transcript",
")",
"construct",
"a",
"BED12",
"entry",
"Parameters",
"----------",
"f",
":",
"Feature",
"object",
"or",
"string",
"This",
"is",
"the",
"top",
"-",
"level",
"feature",
... | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/convert.py#L7-L43 |
daler/gffutils | gffutils/helpers.py | infer_dialect | def infer_dialect(attributes):
"""
Infer the dialect based on the attributes.
Parameters
----------
attributes : str or iterable
A single attributes string from a GTF or GFF line, or an iterable of
such strings.
Returns
-------
Dictionary representing the inferred diale... | python | def infer_dialect(attributes):
"""
Infer the dialect based on the attributes.
Parameters
----------
attributes : str or iterable
A single attributes string from a GTF or GFF line, or an iterable of
such strings.
Returns
-------
Dictionary representing the inferred diale... | [
"def",
"infer_dialect",
"(",
"attributes",
")",
":",
"if",
"isinstance",
"(",
"attributes",
",",
"six",
".",
"string_types",
")",
":",
"attributes",
"=",
"[",
"attributes",
"]",
"dialects",
"=",
"[",
"parser",
".",
"_split_keyvals",
"(",
"i",
")",
"[",
"... | Infer the dialect based on the attributes.
Parameters
----------
attributes : str or iterable
A single attributes string from a GTF or GFF line, or an iterable of
such strings.
Returns
-------
Dictionary representing the inferred dialect | [
"Infer",
"the",
"dialect",
"based",
"on",
"the",
"attributes",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L25-L42 |
daler/gffutils | gffutils/helpers.py | _choose_dialect | def _choose_dialect(dialects):
"""
Given a list of dialects, choose the one to use as the "canonical" version.
If `dialects` is an empty list, then use the default GFF3 dialect
Parameters
----------
dialects : iterable
iterable of dialect dictionaries
Returns
-------
dict
... | python | def _choose_dialect(dialects):
"""
Given a list of dialects, choose the one to use as the "canonical" version.
If `dialects` is an empty list, then use the default GFF3 dialect
Parameters
----------
dialects : iterable
iterable of dialect dictionaries
Returns
-------
dict
... | [
"def",
"_choose_dialect",
"(",
"dialects",
")",
":",
"# NOTE: can use helpers.dialect_compare if you need to make this more",
"# complex....",
"# For now, this function favors the first dialect, and then appends the",
"# order of additional fields seen in the attributes of other lines giving",
"... | Given a list of dialects, choose the one to use as the "canonical" version.
If `dialects` is an empty list, then use the default GFF3 dialect
Parameters
----------
dialects : iterable
iterable of dialect dictionaries
Returns
-------
dict | [
"Given",
"a",
"list",
"of",
"dialects",
"choose",
"the",
"one",
"to",
"use",
"as",
"the",
"canonical",
"version",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L45-L75 |
daler/gffutils | gffutils/helpers.py | make_query | def make_query(args, other=None, limit=None, strand=None, featuretype=None,
extra=None, order_by=None, reverse=False,
completely_within=False):
"""
Multi-purpose, bare-bones ORM function.
This function composes queries given some commonly-used kwargs that can be
passed to ... | python | def make_query(args, other=None, limit=None, strand=None, featuretype=None,
extra=None, order_by=None, reverse=False,
completely_within=False):
"""
Multi-purpose, bare-bones ORM function.
This function composes queries given some commonly-used kwargs that can be
passed to ... | [
"def",
"make_query",
"(",
"args",
",",
"other",
"=",
"None",
",",
"limit",
"=",
"None",
",",
"strand",
"=",
"None",
",",
"featuretype",
"=",
"None",
",",
"extra",
"=",
"None",
",",
"order_by",
"=",
"None",
",",
"reverse",
"=",
"False",
",",
"complete... | Multi-purpose, bare-bones ORM function.
This function composes queries given some commonly-used kwargs that can be
passed to FeatureDB methods (like .parents(), .children(), .all_features(),
.features_of_type()). It handles, in one place, things like restricting to
featuretype, limiting to a genomic r... | [
"Multi",
"-",
"purpose",
"bare",
"-",
"bones",
"ORM",
"function",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L78-L239 |
daler/gffutils | gffutils/helpers.py | _bin_from_dict | def _bin_from_dict(d):
"""
Given a dictionary yielded by the parser, return the genomic "UCSC" bin
"""
try:
start = int(d['start'])
end = int(d['end'])
return bins.bins(start, end, one=True)
# e.g., if "."
except ValueError:
return None | python | def _bin_from_dict(d):
"""
Given a dictionary yielded by the parser, return the genomic "UCSC" bin
"""
try:
start = int(d['start'])
end = int(d['end'])
return bins.bins(start, end, one=True)
# e.g., if "."
except ValueError:
return None | [
"def",
"_bin_from_dict",
"(",
"d",
")",
":",
"try",
":",
"start",
"=",
"int",
"(",
"d",
"[",
"'start'",
"]",
")",
"end",
"=",
"int",
"(",
"d",
"[",
"'end'",
"]",
")",
"return",
"bins",
".",
"bins",
"(",
"start",
",",
"end",
",",
"one",
"=",
"... | Given a dictionary yielded by the parser, return the genomic "UCSC" bin | [
"Given",
"a",
"dictionary",
"yielded",
"by",
"the",
"parser",
"return",
"the",
"genomic",
"UCSC",
"bin"
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L242-L253 |
daler/gffutils | gffutils/helpers.py | _jsonify | def _jsonify(x):
"""Use most compact form of JSON"""
if isinstance(x, dict_class):
return json.dumps(x._d, separators=(',', ':'))
return json.dumps(x, separators=(',', ':')) | python | def _jsonify(x):
"""Use most compact form of JSON"""
if isinstance(x, dict_class):
return json.dumps(x._d, separators=(',', ':'))
return json.dumps(x, separators=(',', ':')) | [
"def",
"_jsonify",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"dict_class",
")",
":",
"return",
"json",
".",
"dumps",
"(",
"x",
".",
"_d",
",",
"separators",
"=",
"(",
"','",
",",
"':'",
")",
")",
"return",
"json",
".",
"dumps",
"(",
... | Use most compact form of JSON | [
"Use",
"most",
"compact",
"form",
"of",
"JSON"
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L256-L260 |
daler/gffutils | gffutils/helpers.py | _unjsonify | def _unjsonify(x, isattributes=False):
"""Convert JSON string to an ordered defaultdict."""
if isattributes:
obj = json.loads(x)
return dict_class(obj)
return json.loads(x) | python | def _unjsonify(x, isattributes=False):
"""Convert JSON string to an ordered defaultdict."""
if isattributes:
obj = json.loads(x)
return dict_class(obj)
return json.loads(x) | [
"def",
"_unjsonify",
"(",
"x",
",",
"isattributes",
"=",
"False",
")",
":",
"if",
"isattributes",
":",
"obj",
"=",
"json",
".",
"loads",
"(",
"x",
")",
"return",
"dict_class",
"(",
"obj",
")",
"return",
"json",
".",
"loads",
"(",
"x",
")"
] | Convert JSON string to an ordered defaultdict. | [
"Convert",
"JSON",
"string",
"to",
"an",
"ordered",
"defaultdict",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L263-L268 |
daler/gffutils | gffutils/helpers.py | _feature_to_fields | def _feature_to_fields(f, jsonify=True):
"""
Convert feature to tuple, for faster sqlite3 import
"""
x = []
for k in constants._keys:
v = getattr(f, k)
if jsonify and (k in ('attributes', 'extra')):
x.append(_jsonify(v))
else:
x.append(v)
return tu... | python | def _feature_to_fields(f, jsonify=True):
"""
Convert feature to tuple, for faster sqlite3 import
"""
x = []
for k in constants._keys:
v = getattr(f, k)
if jsonify and (k in ('attributes', 'extra')):
x.append(_jsonify(v))
else:
x.append(v)
return tu... | [
"def",
"_feature_to_fields",
"(",
"f",
",",
"jsonify",
"=",
"True",
")",
":",
"x",
"=",
"[",
"]",
"for",
"k",
"in",
"constants",
".",
"_keys",
":",
"v",
"=",
"getattr",
"(",
"f",
",",
"k",
")",
"if",
"jsonify",
"and",
"(",
"k",
"in",
"(",
"'att... | Convert feature to tuple, for faster sqlite3 import | [
"Convert",
"feature",
"to",
"tuple",
"for",
"faster",
"sqlite3",
"import"
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L271-L282 |
daler/gffutils | gffutils/helpers.py | _dict_to_fields | def _dict_to_fields(d, jsonify=True):
"""
Convert dict to tuple, for faster sqlite3 import
"""
x = []
for k in constants._keys:
v = d[k]
if jsonify and (k in ('attributes', 'extra')):
x.append(_jsonify(v))
else:
x.append(v)
return tuple(x) | python | def _dict_to_fields(d, jsonify=True):
"""
Convert dict to tuple, for faster sqlite3 import
"""
x = []
for k in constants._keys:
v = d[k]
if jsonify and (k in ('attributes', 'extra')):
x.append(_jsonify(v))
else:
x.append(v)
return tuple(x) | [
"def",
"_dict_to_fields",
"(",
"d",
",",
"jsonify",
"=",
"True",
")",
":",
"x",
"=",
"[",
"]",
"for",
"k",
"in",
"constants",
".",
"_keys",
":",
"v",
"=",
"d",
"[",
"k",
"]",
"if",
"jsonify",
"and",
"(",
"k",
"in",
"(",
"'attributes'",
",",
"'e... | Convert dict to tuple, for faster sqlite3 import | [
"Convert",
"dict",
"to",
"tuple",
"for",
"faster",
"sqlite3",
"import"
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L285-L296 |
daler/gffutils | gffutils/helpers.py | merge_attributes | def merge_attributes(attr1, attr2):
"""
Merges two attribute dictionaries into a single dictionary.
Parameters
----------
`attr1`, `attr2` : dict
Returns
-------
dict
"""
new_d = copy.deepcopy(attr1)
new_d.update(attr2)
#all of attr2 key : values just overwrote attr1,... | python | def merge_attributes(attr1, attr2):
"""
Merges two attribute dictionaries into a single dictionary.
Parameters
----------
`attr1`, `attr2` : dict
Returns
-------
dict
"""
new_d = copy.deepcopy(attr1)
new_d.update(attr2)
#all of attr2 key : values just overwrote attr1,... | [
"def",
"merge_attributes",
"(",
"attr1",
",",
"attr2",
")",
":",
"new_d",
"=",
"copy",
".",
"deepcopy",
"(",
"attr1",
")",
"new_d",
".",
"update",
"(",
"attr2",
")",
"#all of attr2 key : values just overwrote attr1, fix it",
"for",
"k",
",",
"v",
"in",
"new_d"... | Merges two attribute dictionaries into a single dictionary.
Parameters
----------
`attr1`, `attr2` : dict
Returns
-------
dict | [
"Merges",
"two",
"attribute",
"dictionaries",
"into",
"a",
"single",
"dictionary",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L307-L333 |
daler/gffutils | gffutils/helpers.py | dialect_compare | def dialect_compare(dialect1, dialect2):
"""
Compares two dialects.
"""
orig = set(dialect1.items())
new = set(dialect2.items())
return dict(
added=dict(list(new.difference(orig))),
removed=dict(list(orig.difference(new)))
) | python | def dialect_compare(dialect1, dialect2):
"""
Compares two dialects.
"""
orig = set(dialect1.items())
new = set(dialect2.items())
return dict(
added=dict(list(new.difference(orig))),
removed=dict(list(orig.difference(new)))
) | [
"def",
"dialect_compare",
"(",
"dialect1",
",",
"dialect2",
")",
":",
"orig",
"=",
"set",
"(",
"dialect1",
".",
"items",
"(",
")",
")",
"new",
"=",
"set",
"(",
"dialect2",
".",
"items",
"(",
")",
")",
"return",
"dict",
"(",
"added",
"=",
"dict",
"(... | Compares two dialects. | [
"Compares",
"two",
"dialects",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L336-L345 |
daler/gffutils | gffutils/helpers.py | sanitize_gff_db | def sanitize_gff_db(db, gid_field="gid"):
"""
Sanitize given GFF db. Returns a sanitized GFF db.
Sanitizing means:
- Ensuring that start < stop for all features
- Standardizing gene units by adding a 'gid' attribute
that makes the file grep-able
TODO: Do something with negative coordina... | python | def sanitize_gff_db(db, gid_field="gid"):
"""
Sanitize given GFF db. Returns a sanitized GFF db.
Sanitizing means:
- Ensuring that start < stop for all features
- Standardizing gene units by adding a 'gid' attribute
that makes the file grep-able
TODO: Do something with negative coordina... | [
"def",
"sanitize_gff_db",
"(",
"db",
",",
"gid_field",
"=",
"\"gid\"",
")",
":",
"def",
"sanitized_iterator",
"(",
")",
":",
"# Iterate through the database by each gene's records",
"for",
"gene_recs",
"in",
"db",
".",
"iter_by_parent_childs",
"(",
")",
":",
"# The ... | Sanitize given GFF db. Returns a sanitized GFF db.
Sanitizing means:
- Ensuring that start < stop for all features
- Standardizing gene units by adding a 'gid' attribute
that makes the file grep-able
TODO: Do something with negative coordinates? | [
"Sanitize",
"given",
"GFF",
"db",
".",
"Returns",
"a",
"sanitized",
"GFF",
"db",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L348-L376 |
daler/gffutils | gffutils/helpers.py | sanitize_gff_file | def sanitize_gff_file(gff_fname,
in_memory=True,
in_place=False):
"""
Sanitize a GFF file.
"""
db = None
if is_gff_db(gff_fname):
# It's a database filename, so load it
db = gffutils.FeatureDB(gff_fname)
else:
# Need to create a... | python | def sanitize_gff_file(gff_fname,
in_memory=True,
in_place=False):
"""
Sanitize a GFF file.
"""
db = None
if is_gff_db(gff_fname):
# It's a database filename, so load it
db = gffutils.FeatureDB(gff_fname)
else:
# Need to create a... | [
"def",
"sanitize_gff_file",
"(",
"gff_fname",
",",
"in_memory",
"=",
"True",
",",
"in_place",
"=",
"False",
")",
":",
"db",
"=",
"None",
"if",
"is_gff_db",
"(",
"gff_fname",
")",
":",
"# It's a database filename, so load it",
"db",
"=",
"gffutils",
".",
"Featu... | Sanitize a GFF file. | [
"Sanitize",
"a",
"GFF",
"file",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L379-L404 |
daler/gffutils | gffutils/helpers.py | is_gff_db | def is_gff_db(db_fname):
"""
Return True if the given filename is a GFF database.
For now, rely on .db extension.
"""
if not os.path.isfile(db_fname):
return False
if db_fname.endswith(".db"):
return True
return False | python | def is_gff_db(db_fname):
"""
Return True if the given filename is a GFF database.
For now, rely on .db extension.
"""
if not os.path.isfile(db_fname):
return False
if db_fname.endswith(".db"):
return True
return False | [
"def",
"is_gff_db",
"(",
"db_fname",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"db_fname",
")",
":",
"return",
"False",
"if",
"db_fname",
".",
"endswith",
"(",
"\".db\"",
")",
":",
"return",
"True",
"return",
"False"
] | Return True if the given filename is a GFF database.
For now, rely on .db extension. | [
"Return",
"True",
"if",
"the",
"given",
"filename",
"is",
"a",
"GFF",
"database",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L415-L425 |
daler/gffutils | gffutils/helpers.py | get_gff_db | def get_gff_db(gff_fname,
ext=".db"):
"""
Get db for GFF file. If the database has a .db file,
load that. Otherwise, create a named temporary file,
serialize the db to that, and return the loaded database.
"""
if not os.path.isfile(gff_fname):
# Not sure how we should deal... | python | def get_gff_db(gff_fname,
ext=".db"):
"""
Get db for GFF file. If the database has a .db file,
load that. Otherwise, create a named temporary file,
serialize the db to that, and return the loaded database.
"""
if not os.path.isfile(gff_fname):
# Not sure how we should deal... | [
"def",
"get_gff_db",
"(",
"gff_fname",
",",
"ext",
"=",
"\".db\"",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"gff_fname",
")",
":",
"# Not sure how we should deal with errors normally in",
"# gffutils -- Ryan?",
"raise",
"ValueError",
"(",
"\"G... | Get db for GFF file. If the database has a .db file,
load that. Otherwise, create a named temporary file,
serialize the db to that, and return the loaded database. | [
"Get",
"db",
"for",
"GFF",
"file",
".",
"If",
"the",
"database",
"has",
"a",
".",
"db",
"file",
"load",
"that",
".",
"Otherwise",
"create",
"a",
"named",
"temporary",
"file",
"serialize",
"the",
"db",
"to",
"that",
"and",
"return",
"the",
"loaded",
"da... | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L475-L506 |
daler/gffutils | gffutils/bins.py | bins | def bins(start, stop, fmt='gff', one=True):
"""
Uses the definition of a "genomic bin" described in Fig 7 of
http://genome.cshlp.org/content/12/6/996.abstract.
Parameters
----------
one : boolean
If `one=True` (default), then only return the smallest bin that
completely contains... | python | def bins(start, stop, fmt='gff', one=True):
"""
Uses the definition of a "genomic bin" described in Fig 7 of
http://genome.cshlp.org/content/12/6/996.abstract.
Parameters
----------
one : boolean
If `one=True` (default), then only return the smallest bin that
completely contains... | [
"def",
"bins",
"(",
"start",
",",
"stop",
",",
"fmt",
"=",
"'gff'",
",",
"one",
"=",
"True",
")",
":",
"# For very large coordinates, return 1 which is \"somewhere on the",
"# chromosome\".",
"if",
"start",
">=",
"MAX_CHROM_SIZE",
"or",
"stop",
">=",
"MAX_CHROM_SIZE... | Uses the definition of a "genomic bin" described in Fig 7 of
http://genome.cshlp.org/content/12/6/996.abstract.
Parameters
----------
one : boolean
If `one=True` (default), then only return the smallest bin that
completely contains these coordinates (useful for assigning a single
... | [
"Uses",
"the",
"definition",
"of",
"a",
"genomic",
"bin",
"described",
"in",
"Fig",
"7",
"of",
"http",
":",
"//",
"genome",
".",
"cshlp",
".",
"org",
"/",
"content",
"/",
"12",
"/",
"6",
"/",
"996",
".",
"abstract",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/bins.py#L58-L128 |
daler/gffutils | gffutils/bins.py | print_bin_sizes | def print_bin_sizes():
"""
Useful for debugging: how large is each bin, and what are the bin IDs?
"""
for i, offset in enumerate(OFFSETS):
binstart = offset
try:
binstop = OFFSETS[i + 1]
except IndexError:
binstop = binstart
bin_size = 2 ** (FIRST... | python | def print_bin_sizes():
"""
Useful for debugging: how large is each bin, and what are the bin IDs?
"""
for i, offset in enumerate(OFFSETS):
binstart = offset
try:
binstop = OFFSETS[i + 1]
except IndexError:
binstop = binstart
bin_size = 2 ** (FIRST... | [
"def",
"print_bin_sizes",
"(",
")",
":",
"for",
"i",
",",
"offset",
"in",
"enumerate",
"(",
"OFFSETS",
")",
":",
"binstart",
"=",
"offset",
"try",
":",
"binstop",
"=",
"OFFSETS",
"[",
"i",
"+",
"1",
"]",
"except",
"IndexError",
":",
"binstop",
"=",
"... | Useful for debugging: how large is each bin, and what are the bin IDs? | [
"Useful",
"for",
"debugging",
":",
"how",
"large",
"is",
"each",
"bin",
"and",
"what",
"are",
"the",
"bin",
"IDs?"
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/bins.py#L131-L155 |
daler/gffutils | gffutils/parser.py | _reconstruct | def _reconstruct(keyvals, dialect, keep_order=False,
sort_attribute_values=False):
"""
Reconstructs the original attributes string according to the dialect.
Parameters
==========
keyvals : dict
Attributes from a GFF/GTF feature
dialect : dict
Dialect containing... | python | def _reconstruct(keyvals, dialect, keep_order=False,
sort_attribute_values=False):
"""
Reconstructs the original attributes string according to the dialect.
Parameters
==========
keyvals : dict
Attributes from a GFF/GTF feature
dialect : dict
Dialect containing... | [
"def",
"_reconstruct",
"(",
"keyvals",
",",
"dialect",
",",
"keep_order",
"=",
"False",
",",
"sort_attribute_values",
"=",
"False",
")",
":",
"if",
"not",
"dialect",
":",
"raise",
"AttributeStringError",
"(",
")",
"if",
"not",
"keyvals",
":",
"return",
"\"\"... | Reconstructs the original attributes string according to the dialect.
Parameters
==========
keyvals : dict
Attributes from a GFF/GTF feature
dialect : dict
Dialect containing info on how to reconstruct a string version of the
attributes
keep_order : bool
If True, t... | [
"Reconstructs",
"the",
"original",
"attributes",
"string",
"according",
"to",
"the",
"dialect",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/parser.py#L76-L169 |
daler/gffutils | gffutils/parser.py | _split_keyvals | def _split_keyvals(keyval_str, dialect=None):
"""
Given the string attributes field of a GFF-like line, split it into an
attributes dictionary and a "dialect" dictionary which contains information
needed to reconstruct the original string.
Lots of logic here to handle all the corner cases.
If ... | python | def _split_keyvals(keyval_str, dialect=None):
"""
Given the string attributes field of a GFF-like line, split it into an
attributes dictionary and a "dialect" dictionary which contains information
needed to reconstruct the original string.
Lots of logic here to handle all the corner cases.
If ... | [
"def",
"_split_keyvals",
"(",
"keyval_str",
",",
"dialect",
"=",
"None",
")",
":",
"def",
"_unquote_quals",
"(",
"quals",
",",
"dialect",
")",
":",
"\"\"\"\n Handles the unquoting (decoding) of percent-encoded characters.\n\n See notes on encoding/decoding above.\n ... | Given the string attributes field of a GFF-like line, split it into an
attributes dictionary and a "dialect" dictionary which contains information
needed to reconstruct the original string.
Lots of logic here to handle all the corner cases.
If `dialect` is None, then do all the logic to infer a dialec... | [
"Given",
"the",
"string",
"attributes",
"field",
"of",
"a",
"GFF",
"-",
"like",
"line",
"split",
"it",
"into",
"an",
"attributes",
"dictionary",
"and",
"a",
"dialect",
"dictionary",
"which",
"contains",
"information",
"needed",
"to",
"reconstruct",
"the",
"ori... | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/parser.py#L175-L360 |
daler/gffutils | gffutils/create.py | create_db | def create_db(data, dbfn, id_spec=None, force=False, verbose=False,
checklines=10, merge_strategy='error', transform=None,
gtf_transcript_key='transcript_id', gtf_gene_key='gene_id',
gtf_subfeature='exon', force_gff=False,
force_dialect_check=False, from_string=Fa... | python | def create_db(data, dbfn, id_spec=None, force=False, verbose=False,
checklines=10, merge_strategy='error', transform=None,
gtf_transcript_key='transcript_id', gtf_gene_key='gene_id',
gtf_subfeature='exon', force_gff=False,
force_dialect_check=False, from_string=Fa... | [
"def",
"create_db",
"(",
"data",
",",
"dbfn",
",",
"id_spec",
"=",
"None",
",",
"force",
"=",
"False",
",",
"verbose",
"=",
"False",
",",
"checklines",
"=",
"10",
",",
"merge_strategy",
"=",
"'error'",
",",
"transform",
"=",
"None",
",",
"gtf_transcript_... | Create a database from a GFF or GTF file.
For more details on when and how to use the kwargs below, see the examples
in the online documentation (:ref:`examples`).
Parameters
----------
data : string or iterable
If a string (and `from_string` is False), then `data` is the path to
... | [
"Create",
"a",
"database",
"from",
"a",
"GFF",
"or",
"GTF",
"file",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/create.py#L1025-L1312 |
daler/gffutils | gffutils/create.py | _DBCreator._id_handler | def _id_handler(self, f):
"""
Given a Feature from self.iterator, figure out what the ID should be.
This uses `self.id_spec` identify the ID.
"""
# If id_spec is a string, convert to iterable for later
if isinstance(self.id_spec, six.string_types):
id_key = ... | python | def _id_handler(self, f):
"""
Given a Feature from self.iterator, figure out what the ID should be.
This uses `self.id_spec` identify the ID.
"""
# If id_spec is a string, convert to iterable for later
if isinstance(self.id_spec, six.string_types):
id_key = ... | [
"def",
"_id_handler",
"(",
"self",
",",
"f",
")",
":",
"# If id_spec is a string, convert to iterable for later",
"if",
"isinstance",
"(",
"self",
".",
"id_spec",
",",
"six",
".",
"string_types",
")",
":",
"id_key",
"=",
"[",
"self",
".",
"id_spec",
"]",
"elif... | Given a Feature from self.iterator, figure out what the ID should be.
This uses `self.id_spec` identify the ID. | [
"Given",
"a",
"Feature",
"from",
"self",
".",
"iterator",
"figure",
"out",
"what",
"the",
"ID",
"should",
"be",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/create.py#L153-L205 |
daler/gffutils | gffutils/create.py | _DBCreator._do_merge | def _do_merge(self, f, merge_strategy, add_duplicate=False):
"""
Different merge strategies upon name conflicts.
"error":
Raise error
"warning"
Log a warning
"merge":
Combine old and new attributes -- but only if everything else
... | python | def _do_merge(self, f, merge_strategy, add_duplicate=False):
"""
Different merge strategies upon name conflicts.
"error":
Raise error
"warning"
Log a warning
"merge":
Combine old and new attributes -- but only if everything else
... | [
"def",
"_do_merge",
"(",
"self",
",",
"f",
",",
"merge_strategy",
",",
"add_duplicate",
"=",
"False",
")",
":",
"if",
"merge_strategy",
"==",
"'error'",
":",
"raise",
"ValueError",
"(",
"\"Duplicate ID {0.id}\"",
".",
"format",
"(",
"f",
")",
")",
"if",
"m... | Different merge strategies upon name conflicts.
"error":
Raise error
"warning"
Log a warning
"merge":
Combine old and new attributes -- but only if everything else
matches; otherwise error. This can be slow, but is thorough.
"create_un... | [
"Different",
"merge",
"strategies",
"upon",
"name",
"conflicts",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/create.py#L213-L354 |
daler/gffutils | gffutils/create.py | _DBCreator._add_duplicate | def _add_duplicate(self, idspecid, newid):
"""
Adds a duplicate ID (as identified by id_spec) and its new ID to the
duplicates table so that they can be later searched for merging.
Parameters
----------
newid : str
The primary key used in the features table
... | python | def _add_duplicate(self, idspecid, newid):
"""
Adds a duplicate ID (as identified by id_spec) and its new ID to the
duplicates table so that they can be later searched for merging.
Parameters
----------
newid : str
The primary key used in the features table
... | [
"def",
"_add_duplicate",
"(",
"self",
",",
"idspecid",
",",
"newid",
")",
":",
"c",
"=",
"self",
".",
"conn",
".",
"cursor",
"(",
")",
"try",
":",
"c",
".",
"execute",
"(",
"'''\n INSERT INTO duplicates\n (idspecid, newid)\n ... | Adds a duplicate ID (as identified by id_spec) and its new ID to the
duplicates table so that they can be later searched for merging.
Parameters
----------
newid : str
The primary key used in the features table
idspecid : str
The ID identified by id_spec | [
"Adds",
"a",
"duplicate",
"ID",
"(",
"as",
"identified",
"by",
"id_spec",
")",
"and",
"its",
"new",
"ID",
"to",
"the",
"duplicates",
"table",
"so",
"that",
"they",
"can",
"be",
"later",
"searched",
"for",
"merging",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/create.py#L356-L388 |
daler/gffutils | gffutils/create.py | _DBCreator._candidate_merges | def _candidate_merges(self, f):
"""
Identifies those features that originally had the same ID as `f`
(according to the id_spec), but were modified because of duplicate
IDs.
"""
candidates = [self._get_feature(f.id)]
c = self.conn.cursor()
results = c.exec... | python | def _candidate_merges(self, f):
"""
Identifies those features that originally had the same ID as `f`
(according to the id_spec), but were modified because of duplicate
IDs.
"""
candidates = [self._get_feature(f.id)]
c = self.conn.cursor()
results = c.exec... | [
"def",
"_candidate_merges",
"(",
"self",
",",
"f",
")",
":",
"candidates",
"=",
"[",
"self",
".",
"_get_feature",
"(",
"f",
".",
"id",
")",
"]",
"c",
"=",
"self",
".",
"conn",
".",
"cursor",
"(",
")",
"results",
"=",
"c",
".",
"execute",
"(",
"co... | Identifies those features that originally had the same ID as `f`
(according to the id_spec), but were modified because of duplicate
IDs. | [
"Identifies",
"those",
"features",
"that",
"originally",
"had",
"the",
"same",
"ID",
"as",
"f",
"(",
"according",
"to",
"the",
"id_spec",
")",
"but",
"were",
"modified",
"because",
"of",
"duplicate",
"IDs",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/create.py#L390-L407 |
daler/gffutils | gffutils/create.py | _DBCreator._init_tables | def _init_tables(self):
"""
Table creation
"""
c = self.conn.cursor()
v = sqlite3.sqlite_version_info
self.set_pragmas(self.pragmas)
c.executescript(constants.SCHEMA)
self.conn.commit() | python | def _init_tables(self):
"""
Table creation
"""
c = self.conn.cursor()
v = sqlite3.sqlite_version_info
self.set_pragmas(self.pragmas)
c.executescript(constants.SCHEMA)
self.conn.commit() | [
"def",
"_init_tables",
"(",
"self",
")",
":",
"c",
"=",
"self",
".",
"conn",
".",
"cursor",
"(",
")",
"v",
"=",
"sqlite3",
".",
"sqlite_version_info",
"self",
".",
"set_pragmas",
"(",
"self",
".",
"pragmas",
")",
"c",
".",
"executescript",
"(",
"consta... | Table creation | [
"Table",
"creation"
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/create.py#L440-L448 |
daler/gffutils | gffutils/create.py | _DBCreator._finalize | def _finalize(self):
"""
Various last-minute stuff to perform after file has been parsed and
imported.
In general, if you'll be adding stuff to the meta table, do it here.
"""
c = self.conn.cursor()
directives = self.directives + self.iterator.directives
... | python | def _finalize(self):
"""
Various last-minute stuff to perform after file has been parsed and
imported.
In general, if you'll be adding stuff to the meta table, do it here.
"""
c = self.conn.cursor()
directives = self.directives + self.iterator.directives
... | [
"def",
"_finalize",
"(",
"self",
")",
":",
"c",
"=",
"self",
".",
"conn",
".",
"cursor",
"(",
")",
"directives",
"=",
"self",
".",
"directives",
"+",
"self",
".",
"iterator",
".",
"directives",
"c",
".",
"executemany",
"(",
"'''\n INSE... | Various last-minute stuff to perform after file has been parsed and
imported.
In general, if you'll be adding stuff to the meta table, do it here. | [
"Various",
"last",
"-",
"minute",
"stuff",
"to",
"perform",
"after",
"file",
"has",
"been",
"parsed",
"and",
"imported",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/create.py#L450-L505 |
daler/gffutils | gffutils/create.py | _DBCreator.create | def create(self):
"""
Calls various methods sequentially in order to fully build the
database.
"""
# Calls each of these methods in order. _populate_from_lines and
# _update_relations must be implemented in subclasses.
self._init_tables()
self._populate_f... | python | def create(self):
"""
Calls various methods sequentially in order to fully build the
database.
"""
# Calls each of these methods in order. _populate_from_lines and
# _update_relations must be implemented in subclasses.
self._init_tables()
self._populate_f... | [
"def",
"create",
"(",
"self",
")",
":",
"# Calls each of these methods in order. _populate_from_lines and",
"# _update_relations must be implemented in subclasses.",
"self",
".",
"_init_tables",
"(",
")",
"self",
".",
"_populate_from_lines",
"(",
"self",
".",
"iterator",
")"... | Calls various methods sequentially in order to fully build the
database. | [
"Calls",
"various",
"methods",
"sequentially",
"in",
"order",
"to",
"fully",
"build",
"the",
"database",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/create.py#L507-L517 |
daler/gffutils | gffutils/create.py | _DBCreator.execute | def execute(self, query):
"""
Execute a query directly on the database.
"""
c = self.conn.cursor()
result = c.execute(query)
for i in result:
yield i | python | def execute(self, query):
"""
Execute a query directly on the database.
"""
c = self.conn.cursor()
result = c.execute(query)
for i in result:
yield i | [
"def",
"execute",
"(",
"self",
",",
"query",
")",
":",
"c",
"=",
"self",
".",
"conn",
".",
"cursor",
"(",
")",
"result",
"=",
"c",
".",
"execute",
"(",
"query",
")",
"for",
"i",
"in",
"result",
":",
"yield",
"i"
] | Execute a query directly on the database. | [
"Execute",
"a",
"query",
"directly",
"on",
"the",
"database",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/create.py#L523-L530 |
daler/gffutils | gffutils/create.py | _DBCreator._replace | def _replace(self, feature, cursor):
"""
Insert a feature into the database.
"""
try:
cursor.execute(
constants._UPDATE,
list(feature.astuple()) + [feature.id])
except sqlite3.ProgrammingError:
cursor.execute(
... | python | def _replace(self, feature, cursor):
"""
Insert a feature into the database.
"""
try:
cursor.execute(
constants._UPDATE,
list(feature.astuple()) + [feature.id])
except sqlite3.ProgrammingError:
cursor.execute(
... | [
"def",
"_replace",
"(",
"self",
",",
"feature",
",",
"cursor",
")",
":",
"try",
":",
"cursor",
".",
"execute",
"(",
"constants",
".",
"_UPDATE",
",",
"list",
"(",
"feature",
".",
"astuple",
"(",
")",
")",
"+",
"[",
"feature",
".",
"id",
"]",
")",
... | Insert a feature into the database. | [
"Insert",
"a",
"feature",
"into",
"the",
"database",
"."
] | train | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/create.py#L542-L553 |
edx/bok-choy | bok_choy/javascript.py | wait_for_js | def wait_for_js(function):
"""
Method decorator that waits for JavaScript dependencies before executing `function`.
If the function is not a method, the decorator has no effect.
Args:
function (callable): Method to decorate.
Returns:
Decorated method
"""
@functools.wraps(f... | python | def wait_for_js(function):
"""
Method decorator that waits for JavaScript dependencies before executing `function`.
If the function is not a method, the decorator has no effect.
Args:
function (callable): Method to decorate.
Returns:
Decorated method
"""
@functools.wraps(f... | [
"def",
"wait_for_js",
"(",
"function",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"function",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# pylint: disable=missing-docstring",
"# If not a method, then just call the function",
"... | Method decorator that waits for JavaScript dependencies before executing `function`.
If the function is not a method, the decorator has no effect.
Args:
function (callable): Method to decorate.
Returns:
Decorated method | [
"Method",
"decorator",
"that",
"waits",
"for",
"JavaScript",
"dependencies",
"before",
"executing",
"function",
".",
"If",
"the",
"function",
"is",
"not",
"a",
"method",
"the",
"decorator",
"has",
"no",
"effect",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/javascript.py#L45-L77 |
edx/bok-choy | bok_choy/javascript.py | _decorator | def _decorator(store_name, store_values):
"""
Return a class decorator that:
1) Defines a new class method, `wait_for_js`
2) Defines a new class list variable, `store_name` and adds
`store_values` to the list.
"""
def decorator(clz): # pylint: disable=missing-docstring
# Add a... | python | def _decorator(store_name, store_values):
"""
Return a class decorator that:
1) Defines a new class method, `wait_for_js`
2) Defines a new class list variable, `store_name` and adds
`store_values` to the list.
"""
def decorator(clz): # pylint: disable=missing-docstring
# Add a... | [
"def",
"_decorator",
"(",
"store_name",
",",
"store_values",
")",
":",
"def",
"decorator",
"(",
"clz",
")",
":",
"# pylint: disable=missing-docstring",
"# Add a `wait_for_js` method to the class",
"if",
"not",
"hasattr",
"(",
"clz",
",",
"'wait_for_js'",
")",
":",
"... | Return a class decorator that:
1) Defines a new class method, `wait_for_js`
2) Defines a new class list variable, `store_name` and adds
`store_values` to the list. | [
"Return",
"a",
"class",
"decorator",
"that",
":"
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/javascript.py#L80-L101 |
edx/bok-choy | bok_choy/javascript.py | _wait_for_js | def _wait_for_js(self):
"""
Class method added by the decorators to allow
decorated classes to manually re-check JavaScript
dependencies.
Expect that `self` is a class that:
1) Has been decorated with either `js_defined` or `requirejs`
2) Has a `browser` property
If either (1) or (2) i... | python | def _wait_for_js(self):
"""
Class method added by the decorators to allow
decorated classes to manually re-check JavaScript
dependencies.
Expect that `self` is a class that:
1) Has been decorated with either `js_defined` or `requirejs`
2) Has a `browser` property
If either (1) or (2) i... | [
"def",
"_wait_for_js",
"(",
"self",
")",
":",
"# No Selenium browser available, so return without doing anything",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'browser'",
")",
":",
"return",
"# pylint: disable=protected-access",
"# Wait for JavaScript variables to be defined",
"... | Class method added by the decorators to allow
decorated classes to manually re-check JavaScript
dependencies.
Expect that `self` is a class that:
1) Has been decorated with either `js_defined` or `requirejs`
2) Has a `browser` property
If either (1) or (2) is not satisfied, then do nothing. | [
"Class",
"method",
"added",
"by",
"the",
"decorators",
"to",
"allow",
"decorated",
"classes",
"to",
"manually",
"re",
"-",
"check",
"JavaScript",
"dependencies",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/javascript.py#L104-L135 |
edx/bok-choy | bok_choy/javascript.py | _are_js_vars_defined | def _are_js_vars_defined(browser, js_vars):
"""
Return a boolean indicating whether all the JavaScript
variables `js_vars` are defined on the current page.
`browser` is a Selenium webdriver instance.
"""
# This script will evaluate to True iff all of
# the required vars are defined.
scr... | python | def _are_js_vars_defined(browser, js_vars):
"""
Return a boolean indicating whether all the JavaScript
variables `js_vars` are defined on the current page.
`browser` is a Selenium webdriver instance.
"""
# This script will evaluate to True iff all of
# the required vars are defined.
scr... | [
"def",
"_are_js_vars_defined",
"(",
"browser",
",",
"js_vars",
")",
":",
"# This script will evaluate to True iff all of",
"# the required vars are defined.",
"script",
"=",
"u\" && \"",
".",
"join",
"(",
"[",
"u\"!(typeof {0} === 'undefined')\"",
".",
"format",
"(",
"var",... | Return a boolean indicating whether all the JavaScript
variables `js_vars` are defined on the current page.
`browser` is a Selenium webdriver instance. | [
"Return",
"a",
"boolean",
"indicating",
"whether",
"all",
"the",
"JavaScript",
"variables",
"js_vars",
"are",
"defined",
"on",
"the",
"current",
"page",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/javascript.py#L138-L158 |
edx/bok-choy | bok_choy/javascript.py | _are_requirejs_deps_loaded | def _are_requirejs_deps_loaded(browser, deps):
"""
Return a boolean indicating whether all the RequireJS
dependencies `deps` have loaded on the current page.
`browser` is a WebDriver instance.
"""
# This is a little complicated
#
# We're going to use `execute_async_script` to give cont... | python | def _are_requirejs_deps_loaded(browser, deps):
"""
Return a boolean indicating whether all the RequireJS
dependencies `deps` have loaded on the current page.
`browser` is a WebDriver instance.
"""
# This is a little complicated
#
# We're going to use `execute_async_script` to give cont... | [
"def",
"_are_requirejs_deps_loaded",
"(",
"browser",
",",
"deps",
")",
":",
"# This is a little complicated",
"#",
"# We're going to use `execute_async_script` to give control to",
"# the browser. The browser indicates that it wants to return",
"# control to us by calling `callback`, which ... | Return a boolean indicating whether all the RequireJS
dependencies `deps` have loaded on the current page.
`browser` is a WebDriver instance. | [
"Return",
"a",
"boolean",
"indicating",
"whether",
"all",
"the",
"RequireJS",
"dependencies",
"deps",
"have",
"loaded",
"on",
"the",
"current",
"page",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/javascript.py#L161-L212 |
edx/bok-choy | bok_choy/page_object.py | no_selenium_errors | def no_selenium_errors(func):
"""
Decorator to create an `EmptyPromise` check function that is satisfied
only when `func` executes without a Selenium error.
This protects against many common test failures due to timing issues.
For example, accessing an element after it has been modified by JavaScri... | python | def no_selenium_errors(func):
"""
Decorator to create an `EmptyPromise` check function that is satisfied
only when `func` executes without a Selenium error.
This protects against many common test failures due to timing issues.
For example, accessing an element after it has been modified by JavaScri... | [
"def",
"no_selenium_errors",
"(",
"func",
")",
":",
"def",
"_inner",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# pylint: disable=missing-docstring",
"try",
":",
"return_val",
"=",
"func",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"excep... | Decorator to create an `EmptyPromise` check function that is satisfied
only when `func` executes without a Selenium error.
This protects against many common test failures due to timing issues.
For example, accessing an element after it has been modified by JavaScript
ordinarily results in a `StaleEleme... | [
"Decorator",
"to",
"create",
"an",
"EmptyPromise",
"check",
"function",
"that",
"is",
"satisfied",
"only",
"when",
"func",
"executes",
"without",
"a",
"Selenium",
"error",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/page_object.py#L64-L90 |
edx/bok-choy | bok_choy/page_object.py | pre_verify | def pre_verify(method):
"""
Decorator that calls self._verify_page() before executing the decorated method
Args:
method (callable): The method to decorate.
Returns:
Decorated method
"""
@wraps(method)
def wrapper(self, *args, **kwargs): # pylint: disable=missing-docstring
... | python | def pre_verify(method):
"""
Decorator that calls self._verify_page() before executing the decorated method
Args:
method (callable): The method to decorate.
Returns:
Decorated method
"""
@wraps(method)
def wrapper(self, *args, **kwargs): # pylint: disable=missing-docstring
... | [
"def",
"pre_verify",
"(",
"method",
")",
":",
"@",
"wraps",
"(",
"method",
")",
"def",
"wrapper",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# pylint: disable=missing-docstring",
"self",
".",
"_verify_page",
"(",
")",
"# pylint: dis... | Decorator that calls self._verify_page() before executing the decorated method
Args:
method (callable): The method to decorate.
Returns:
Decorated method | [
"Decorator",
"that",
"calls",
"self",
".",
"_verify_page",
"()",
"before",
"executing",
"the",
"decorated",
"method"
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/page_object.py#L110-L124 |
edx/bok-choy | bok_choy/a11y/axs_ruleset.py | AxsAuditConfig.set_rules | def set_rules(self, rules):
"""
Sets the rules to be run or ignored for the audit.
Args:
rules: a dictionary of the format `{"ignore": [], "apply": []}`.
See https://github.com/GoogleChrome/accessibility-developer-tools/tree/master/src/audits
Passing `{"apply": []... | python | def set_rules(self, rules):
"""
Sets the rules to be run or ignored for the audit.
Args:
rules: a dictionary of the format `{"ignore": [], "apply": []}`.
See https://github.com/GoogleChrome/accessibility-developer-tools/tree/master/src/audits
Passing `{"apply": []... | [
"def",
"set_rules",
"(",
"self",
",",
"rules",
")",
":",
"self",
".",
"rules_to_ignore",
"=",
"rules",
".",
"get",
"(",
"\"ignore\"",
",",
"[",
"]",
")",
"self",
".",
"rules_to_run",
"=",
"rules",
".",
"get",
"(",
"\"apply\"",
",",
"[",
"]",
")"
] | Sets the rules to be run or ignored for the audit.
Args:
rules: a dictionary of the format `{"ignore": [], "apply": []}`.
See https://github.com/GoogleChrome/accessibility-developer-tools/tree/master/src/audits
Passing `{"apply": []}` or `{}` means to check for all available rule... | [
"Sets",
"the",
"rules",
"to",
"be",
"run",
"or",
"ignored",
"for",
"the",
"audit",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axs_ruleset.py#L36-L69 |
edx/bok-choy | bok_choy/a11y/axs_ruleset.py | AxsAuditConfig.set_scope | def set_scope(self, include=None, exclude=None):
"""
Sets `scope`, the "start point" for the audit.
Args:
include: A list of css selectors specifying the elements that
contain the portion of the page that should be audited.
Defaults to auditing the e... | python | def set_scope(self, include=None, exclude=None):
"""
Sets `scope`, the "start point" for the audit.
Args:
include: A list of css selectors specifying the elements that
contain the portion of the page that should be audited.
Defaults to auditing the e... | [
"def",
"set_scope",
"(",
"self",
",",
"include",
"=",
"None",
",",
"exclude",
"=",
"None",
")",
":",
"if",
"include",
":",
"self",
".",
"scope",
"=",
"u\"document.querySelector(\\\"{}\\\")\"",
".",
"format",
"(",
"u', '",
".",
"join",
"(",
"include",
")",
... | Sets `scope`, the "start point" for the audit.
Args:
include: A list of css selectors specifying the elements that
contain the portion of the page that should be audited.
Defaults to auditing the entire document.
exclude: This arg is not implemented in t... | [
"Sets",
"scope",
"the",
"start",
"point",
"for",
"the",
"audit",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axs_ruleset.py#L71-L103 |
edx/bok-choy | bok_choy/a11y/axs_ruleset.py | AxsAudit._check_rules | def _check_rules(browser, rules_js, config):
"""
Check the page for violations of the configured rules. By default,
all rules in the ruleset will be checked.
Args:
browser: a browser instance.
rules_js: the ruleset JavaScript as a string.
config: an A... | python | def _check_rules(browser, rules_js, config):
"""
Check the page for violations of the configured rules. By default,
all rules in the ruleset will be checked.
Args:
browser: a browser instance.
rules_js: the ruleset JavaScript as a string.
config: an A... | [
"def",
"_check_rules",
"(",
"browser",
",",
"rules_js",
",",
"config",
")",
":",
"if",
"config",
".",
"rules_to_run",
"is",
"None",
":",
"msg",
"=",
"'No accessibility rules were specified to check.'",
"log",
".",
"warning",
"(",
"msg",
")",
"return",
"None",
... | Check the page for violations of the configured rules. By default,
all rules in the ruleset will be checked.
Args:
browser: a browser instance.
rules_js: the ruleset JavaScript as a string.
config: an AxsAuditConfig instance.
Returns:
A namedtupl... | [
"Check",
"the",
"page",
"for",
"violations",
"of",
"the",
"configured",
"rules",
".",
"By",
"default",
"all",
"rules",
"in",
"the",
"ruleset",
"will",
"be",
"checked",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axs_ruleset.py#L134-L193 |
edx/bok-choy | bok_choy/a11y/axs_ruleset.py | AxsAudit.get_errors | def get_errors(audit_results):
"""
Args:
audit_results: results of `AxsAudit.do_audit()`.
Returns: a list of errors.
"""
errors = []
if audit_results:
if audit_results.errors:
errors.extend(audit_results.errors)
return err... | python | def get_errors(audit_results):
"""
Args:
audit_results: results of `AxsAudit.do_audit()`.
Returns: a list of errors.
"""
errors = []
if audit_results:
if audit_results.errors:
errors.extend(audit_results.errors)
return err... | [
"def",
"get_errors",
"(",
"audit_results",
")",
":",
"errors",
"=",
"[",
"]",
"if",
"audit_results",
":",
"if",
"audit_results",
".",
"errors",
":",
"errors",
".",
"extend",
"(",
"audit_results",
".",
"errors",
")",
"return",
"errors"
] | Args:
audit_results: results of `AxsAudit.do_audit()`.
Returns: a list of errors. | [
"Args",
":"
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axs_ruleset.py#L196-L208 |
edx/bok-choy | bok_choy/a11y/axs_ruleset.py | AxsAudit.report_errors | def report_errors(audit, url):
"""
Args:
audit: results of `AxsAudit.do_audit()`.
url: the url of the page being audited.
Raises: `AccessibilityError`
"""
errors = AxsAudit.get_errors(audit)
if errors:
msg = u"URL '{}' has {} errors:\... | python | def report_errors(audit, url):
"""
Args:
audit: results of `AxsAudit.do_audit()`.
url: the url of the page being audited.
Raises: `AccessibilityError`
"""
errors = AxsAudit.get_errors(audit)
if errors:
msg = u"URL '{}' has {} errors:\... | [
"def",
"report_errors",
"(",
"audit",
",",
"url",
")",
":",
"errors",
"=",
"AxsAudit",
".",
"get_errors",
"(",
"audit",
")",
"if",
"errors",
":",
"msg",
"=",
"u\"URL '{}' has {} errors:\\n{}\"",
".",
"format",
"(",
"url",
",",
"len",
"(",
"errors",
")",
... | Args:
audit: results of `AxsAudit.do_audit()`.
url: the url of the page being audited.
Raises: `AccessibilityError` | [
"Args",
":"
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axs_ruleset.py#L211-L227 |
edx/bok-choy | bok_choy/promise.py | Promise.fulfill | def fulfill(self):
"""
Evaluate the promise and return the result.
Returns:
The result of the `Promise` (second return value from the `check_func`)
Raises:
BrokenPromise: the `Promise` was not satisfied within the time or attempt limits.
"""
is_... | python | def fulfill(self):
"""
Evaluate the promise and return the result.
Returns:
The result of the `Promise` (second return value from the `check_func`)
Raises:
BrokenPromise: the `Promise` was not satisfied within the time or attempt limits.
"""
is_... | [
"def",
"fulfill",
"(",
"self",
")",
":",
"is_fulfilled",
",",
"result",
"=",
"self",
".",
"_check_fulfilled",
"(",
")",
"if",
"is_fulfilled",
":",
"return",
"result",
"else",
":",
"raise",
"BrokenPromise",
"(",
"self",
")"
] | Evaluate the promise and return the result.
Returns:
The result of the `Promise` (second return value from the `check_func`)
Raises:
BrokenPromise: the `Promise` was not satisfied within the time or attempt limits. | [
"Evaluate",
"the",
"promise",
"and",
"return",
"the",
"result",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/promise.py#L91-L106 |
edx/bok-choy | bok_choy/promise.py | Promise._check_fulfilled | def _check_fulfilled(self):
"""
Return tuple `(is_fulfilled, result)` where
`is_fulfilled` is a boolean indicating whether the promise has been fulfilled
and `result` is the value to pass to the `with` block.
"""
is_fulfilled = False
result = None
start_ti... | python | def _check_fulfilled(self):
"""
Return tuple `(is_fulfilled, result)` where
`is_fulfilled` is a boolean indicating whether the promise has been fulfilled
and `result` is the value to pass to the `with` block.
"""
is_fulfilled = False
result = None
start_ti... | [
"def",
"_check_fulfilled",
"(",
"self",
")",
":",
"is_fulfilled",
"=",
"False",
"result",
"=",
"None",
"start_time",
"=",
"time",
".",
"time",
"(",
")",
"# Check whether the promise has been fulfilled until we run out of time or attempts",
"while",
"self",
".",
"_has_ti... | Return tuple `(is_fulfilled, result)` where
`is_fulfilled` is a boolean indicating whether the promise has been fulfilled
and `result` is the value to pass to the `with` block. | [
"Return",
"tuple",
"(",
"is_fulfilled",
"result",
")",
"where",
"is_fulfilled",
"is",
"a",
"boolean",
"indicating",
"whether",
"the",
"promise",
"has",
"been",
"fulfilled",
"and",
"result",
"is",
"the",
"value",
"to",
"pass",
"to",
"the",
"with",
"block",
".... | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/promise.py#L111-L136 |
edx/bok-choy | docs/code/round_3/pages.py | GitHubSearchPage.search | def search(self):
"""
Click on the Search button and wait for the
results page to be displayed
"""
self.q(css='button.btn').click()
GitHubSearchResultsPage(self.browser).wait_for_page() | python | def search(self):
"""
Click on the Search button and wait for the
results page to be displayed
"""
self.q(css='button.btn').click()
GitHubSearchResultsPage(self.browser).wait_for_page() | [
"def",
"search",
"(",
"self",
")",
":",
"self",
".",
"q",
"(",
"css",
"=",
"'button.btn'",
")",
".",
"click",
"(",
")",
"GitHubSearchResultsPage",
"(",
"self",
".",
"browser",
")",
".",
"wait_for_page",
"(",
")"
] | Click on the Search button and wait for the
results page to be displayed | [
"Click",
"on",
"the",
"Search",
"button",
"and",
"wait",
"for",
"the",
"results",
"page",
"to",
"be",
"displayed"
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/docs/code/round_3/pages.py#L43-L49 |
edx/bok-choy | bok_choy/a11y/axe_core_ruleset.py | AxeCoreAuditConfig.set_rules | def set_rules(self, rules):
"""
Set rules to ignore XOR limit to when checking for accessibility
errors on the page.
Args:
rules: a dictionary one of the following formats.
If you want to run all of the rules except for some::
{"ignore":... | python | def set_rules(self, rules):
"""
Set rules to ignore XOR limit to when checking for accessibility
errors on the page.
Args:
rules: a dictionary one of the following formats.
If you want to run all of the rules except for some::
{"ignore":... | [
"def",
"set_rules",
"(",
"self",
",",
"rules",
")",
":",
"options",
"=",
"{",
"}",
"if",
"rules",
":",
"if",
"rules",
".",
"get",
"(",
"\"ignore\"",
")",
":",
"options",
"[",
"\"rules\"",
"]",
"=",
"{",
"}",
"for",
"rule",
"in",
"rules",
".",
"ge... | Set rules to ignore XOR limit to when checking for accessibility
errors on the page.
Args:
rules: a dictionary one of the following formats.
If you want to run all of the rules except for some::
{"ignore": []}
If you want to run only a ... | [
"Set",
"rules",
"to",
"ignore",
"XOR",
"limit",
"to",
"when",
"checking",
"for",
"accessibility",
"errors",
"on",
"the",
"page",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axe_core_ruleset.py#L37-L101 |
edx/bok-choy | bok_choy/a11y/axe_core_ruleset.py | AxeCoreAuditConfig.set_scope | def set_scope(self, include=None, exclude=None):
"""
Sets `scope` (refered to as `context` in ruleset documentation), which
defines the elements on a page to include or exclude in the audit. If
neither `include` nor `exclude` are passed, the entire document will
be included.
... | python | def set_scope(self, include=None, exclude=None):
"""
Sets `scope` (refered to as `context` in ruleset documentation), which
defines the elements on a page to include or exclude in the audit. If
neither `include` nor `exclude` are passed, the entire document will
be included.
... | [
"def",
"set_scope",
"(",
"self",
",",
"include",
"=",
"None",
",",
"exclude",
"=",
"None",
")",
":",
"context",
"=",
"{",
"}",
"if",
"exclude",
":",
"context",
"[",
"\"exclude\"",
"]",
"=",
"[",
"[",
"selector",
"]",
"for",
"selector",
"in",
"exclude... | Sets `scope` (refered to as `context` in ruleset documentation), which
defines the elements on a page to include or exclude in the audit. If
neither `include` nor `exclude` are passed, the entire document will
be included.
Args:
include (optional): a list of css selectors f... | [
"Sets",
"scope",
"(",
"refered",
"to",
"as",
"context",
"in",
"ruleset",
"documentation",
")",
"which",
"defines",
"the",
"elements",
"on",
"a",
"page",
"to",
"include",
"or",
"exclude",
"in",
"the",
"audit",
".",
"If",
"neither",
"include",
"nor",
"exclud... | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axe_core_ruleset.py#L103-L154 |
edx/bok-choy | bok_choy/a11y/axe_core_ruleset.py | AxeCoreAuditConfig.customize_ruleset | def customize_ruleset(self, custom_ruleset_file=None):
"""
Updates the ruleset to include a set of custom rules. These rules will
be _added_ to the existing ruleset or replace the existing rule with
the same ID.
Args:
custom_ruleset_file (optional): The filepath to ... | python | def customize_ruleset(self, custom_ruleset_file=None):
"""
Updates the ruleset to include a set of custom rules. These rules will
be _added_ to the existing ruleset or replace the existing rule with
the same ID.
Args:
custom_ruleset_file (optional): The filepath to ... | [
"def",
"customize_ruleset",
"(",
"self",
",",
"custom_ruleset_file",
"=",
"None",
")",
":",
"custom_file",
"=",
"custom_ruleset_file",
"or",
"os",
".",
"environ",
".",
"get",
"(",
"\"BOKCHOY_A11Y_CUSTOM_RULES_FILE\"",
")",
"if",
"not",
"custom_file",
":",
"return"... | Updates the ruleset to include a set of custom rules. These rules will
be _added_ to the existing ruleset or replace the existing rule with
the same ID.
Args:
custom_ruleset_file (optional): The filepath to the custom rules.
Defaults to `None`. If `custom_ruleset_fi... | [
"Updates",
"the",
"ruleset",
"to",
"include",
"a",
"set",
"of",
"custom",
"rules",
".",
"These",
"rules",
"will",
"be",
"_added_",
"to",
"the",
"existing",
"ruleset",
"or",
"replace",
"the",
"existing",
"rule",
"with",
"the",
"same",
"ID",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axe_core_ruleset.py#L156-L207 |
edx/bok-choy | bok_choy/a11y/axe_core_ruleset.py | AxeCoreAudit._check_rules | def _check_rules(browser, rules_js, config):
"""
Run an accessibility audit on the page using the axe-core ruleset.
Args:
browser: a browser instance.
rules_js: the ruleset JavaScript as a string.
config: an AxsAuditConfig instance.
Returns:
... | python | def _check_rules(browser, rules_js, config):
"""
Run an accessibility audit on the page using the axe-core ruleset.
Args:
browser: a browser instance.
rules_js: the ruleset JavaScript as a string.
config: an AxsAuditConfig instance.
Returns:
... | [
"def",
"_check_rules",
"(",
"browser",
",",
"rules_js",
",",
"config",
")",
":",
"audit_run_script",
"=",
"dedent",
"(",
"u\"\"\"\n {rules_js}\n {custom_rules}\n axe.configure(customRules);\n var callback = function(err, results) {{\n ... | Run an accessibility audit on the page using the axe-core ruleset.
Args:
browser: a browser instance.
rules_js: the ruleset JavaScript as a string.
config: an AxsAuditConfig instance.
Returns:
A list of violations.
Related documentation:
... | [
"Run",
"an",
"accessibility",
"audit",
"on",
"the",
"page",
"using",
"the",
"axe",
"-",
"core",
"ruleset",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axe_core_ruleset.py#L227-L300 |
edx/bok-choy | bok_choy/a11y/axe_core_ruleset.py | AxeCoreAudit.get_errors | def get_errors(audit_results):
"""
Args:
audit_results: results of `AxeCoreAudit.do_audit()`.
Returns:
A dictionary with keys "errors" and "total".
"""
errors = {"errors": [], "total": 0}
if audit_results:
errors["errors"].extend(aud... | python | def get_errors(audit_results):
"""
Args:
audit_results: results of `AxeCoreAudit.do_audit()`.
Returns:
A dictionary with keys "errors" and "total".
"""
errors = {"errors": [], "total": 0}
if audit_results:
errors["errors"].extend(aud... | [
"def",
"get_errors",
"(",
"audit_results",
")",
":",
"errors",
"=",
"{",
"\"errors\"",
":",
"[",
"]",
",",
"\"total\"",
":",
"0",
"}",
"if",
"audit_results",
":",
"errors",
"[",
"\"errors\"",
"]",
".",
"extend",
"(",
"audit_results",
")",
"for",
"i",
"... | Args:
audit_results: results of `AxeCoreAudit.do_audit()`.
Returns:
A dictionary with keys "errors" and "total". | [
"Args",
":"
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axe_core_ruleset.py#L303-L319 |
edx/bok-choy | bok_choy/a11y/axe_core_ruleset.py | AxeCoreAudit.format_errors | def format_errors(errors):
"""
Args:
errors: results of `AxeCoreAudit.get_errors()`.
Returns: The errors as a formatted string.
"""
def _get_message(node):
"""
Get the message to display in the error output.
"""
messa... | python | def format_errors(errors):
"""
Args:
errors: results of `AxeCoreAudit.get_errors()`.
Returns: The errors as a formatted string.
"""
def _get_message(node):
"""
Get the message to display in the error output.
"""
messa... | [
"def",
"format_errors",
"(",
"errors",
")",
":",
"def",
"_get_message",
"(",
"node",
")",
":",
"\"\"\"\n Get the message to display in the error output.\n \"\"\"",
"messages",
"=",
"set",
"(",
")",
"try",
":",
"messages",
".",
"update",
"(",
"[",... | Args:
errors: results of `AxeCoreAudit.get_errors()`.
Returns: The errors as a formatted string. | [
"Args",
":"
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axe_core_ruleset.py#L322-L372 |
edx/bok-choy | bok_choy/a11y/axe_core_ruleset.py | AxeCoreAudit.report_errors | def report_errors(audit, url):
"""
Args:
audit: results of `AxeCoreAudit.do_audit()`.
url: the url of the page being audited.
Raises: `AccessibilityError`
"""
errors = AxeCoreAudit.get_errors(audit)
if errors["total"] > 0:
msg = u"URL... | python | def report_errors(audit, url):
"""
Args:
audit: results of `AxeCoreAudit.do_audit()`.
url: the url of the page being audited.
Raises: `AccessibilityError`
"""
errors = AxeCoreAudit.get_errors(audit)
if errors["total"] > 0:
msg = u"URL... | [
"def",
"report_errors",
"(",
"audit",
",",
"url",
")",
":",
"errors",
"=",
"AxeCoreAudit",
".",
"get_errors",
"(",
"audit",
")",
"if",
"errors",
"[",
"\"total\"",
"]",
">",
"0",
":",
"msg",
"=",
"u\"URL '{}' has {} errors:\\n\\n{}\"",
".",
"format",
"(",
"... | Args:
audit: results of `AxeCoreAudit.do_audit()`.
url: the url of the page being audited.
Raises: `AccessibilityError` | [
"Args",
":"
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axe_core_ruleset.py#L375-L391 |
edx/bok-choy | bok_choy/browser.py | save_source | def save_source(driver, name):
"""
Save the rendered HTML of the browser.
The location of the source can be configured
by the environment variable `SAVED_SOURCE_DIR`. If not set,
this defaults to the current working directory.
Args:
driver (selenium.webdriver): The Selenium-controlled... | python | def save_source(driver, name):
"""
Save the rendered HTML of the browser.
The location of the source can be configured
by the environment variable `SAVED_SOURCE_DIR`. If not set,
this defaults to the current working directory.
Args:
driver (selenium.webdriver): The Selenium-controlled... | [
"def",
"save_source",
"(",
"driver",
",",
"name",
")",
":",
"source",
"=",
"driver",
".",
"page_source",
"file_name",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"environ",
".",
"get",
"(",
"'SAVED_SOURCE_DIR'",
")",
",",
"'{name}.html'",
".",
... | Save the rendered HTML of the browser.
The location of the source can be configured
by the environment variable `SAVED_SOURCE_DIR`. If not set,
this defaults to the current working directory.
Args:
driver (selenium.webdriver): The Selenium-controlled browser.
name (str): A name to use... | [
"Save",
"the",
"rendered",
"HTML",
"of",
"the",
"browser",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L79-L104 |
edx/bok-choy | bok_choy/browser.py | save_screenshot | def save_screenshot(driver, name):
"""
Save a screenshot of the browser.
The location of the screenshot can be configured
by the environment variable `SCREENSHOT_DIR`. If not set,
this defaults to the current working directory.
Args:
driver (selenium.webdriver): The Selenium-controlle... | python | def save_screenshot(driver, name):
"""
Save a screenshot of the browser.
The location of the screenshot can be configured
by the environment variable `SCREENSHOT_DIR`. If not set,
this defaults to the current working directory.
Args:
driver (selenium.webdriver): The Selenium-controlle... | [
"def",
"save_screenshot",
"(",
"driver",
",",
"name",
")",
":",
"if",
"hasattr",
"(",
"driver",
",",
"'save_screenshot'",
")",
":",
"screenshot_dir",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'SCREENSHOT_DIR'",
")",
"if",
"not",
"screenshot_dir",
":",
"... | Save a screenshot of the browser.
The location of the screenshot can be configured
by the environment variable `SCREENSHOT_DIR`. If not set,
this defaults to the current working directory.
Args:
driver (selenium.webdriver): The Selenium-controlled browser.
name (str): A name for the s... | [
"Save",
"a",
"screenshot",
"of",
"the",
"browser",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L107-L138 |
edx/bok-choy | bok_choy/browser.py | save_driver_logs | def save_driver_logs(driver, prefix):
"""
Save the selenium driver logs.
The location of the driver log files can be configured
by the environment variable `SELENIUM_DRIVER_LOG_DIR`. If not set,
this defaults to the current working directory.
Args:
driver (selenium.webdriver): The Sel... | python | def save_driver_logs(driver, prefix):
"""
Save the selenium driver logs.
The location of the driver log files can be configured
by the environment variable `SELENIUM_DRIVER_LOG_DIR`. If not set,
this defaults to the current working directory.
Args:
driver (selenium.webdriver): The Sel... | [
"def",
"save_driver_logs",
"(",
"driver",
",",
"prefix",
")",
":",
"browser_name",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'SELENIUM_BROWSER'",
",",
"'firefox'",
")",
"log_dir",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'SELENIUM_DRIVER_LOG_DIR'",
")... | Save the selenium driver logs.
The location of the driver log files can be configured
by the environment variable `SELENIUM_DRIVER_LOG_DIR`. If not set,
this defaults to the current working directory.
Args:
driver (selenium.webdriver): The Selenium-controlled browser.
prefix (str): A ... | [
"Save",
"the",
"selenium",
"driver",
"logs",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L141-L189 |
edx/bok-choy | bok_choy/browser.py | browser | def browser(tags=None, proxy=None, other_caps=None):
"""
Interpret environment variables to configure Selenium.
Performs validation, logging, and sensible defaults.
There are three cases:
1. Local browsers: If the proper environment variables are not all set for the second case,
then we us... | python | def browser(tags=None, proxy=None, other_caps=None):
"""
Interpret environment variables to configure Selenium.
Performs validation, logging, and sensible defaults.
There are three cases:
1. Local browsers: If the proper environment variables are not all set for the second case,
then we us... | [
"def",
"browser",
"(",
"tags",
"=",
"None",
",",
"proxy",
"=",
"None",
",",
"other_caps",
"=",
"None",
")",
":",
"browser_name",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'SELENIUM_BROWSER'",
",",
"'firefox'",
")",
"def",
"browser_check_func",
"(",
")... | Interpret environment variables to configure Selenium.
Performs validation, logging, and sensible defaults.
There are three cases:
1. Local browsers: If the proper environment variables are not all set for the second case,
then we use a local browser.
* The environment variable `SELENIUM_... | [
"Interpret",
"environment",
"variables",
"to",
"configure",
"Selenium",
".",
"Performs",
"validation",
"logging",
"and",
"sensible",
"defaults",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L192-L296 |
edx/bok-choy | bok_choy/browser.py | _firefox_profile | def _firefox_profile():
"""Configure the Firefox profile, respecting FIREFOX_PROFILE_PATH if set"""
profile_dir = os.environ.get(FIREFOX_PROFILE_ENV_VAR)
if profile_dir:
LOGGER.info(u"Using firefox profile: %s", profile_dir)
try:
firefox_profile = webdriver.FirefoxProfile(profil... | python | def _firefox_profile():
"""Configure the Firefox profile, respecting FIREFOX_PROFILE_PATH if set"""
profile_dir = os.environ.get(FIREFOX_PROFILE_ENV_VAR)
if profile_dir:
LOGGER.info(u"Using firefox profile: %s", profile_dir)
try:
firefox_profile = webdriver.FirefoxProfile(profil... | [
"def",
"_firefox_profile",
"(",
")",
":",
"profile_dir",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"FIREFOX_PROFILE_ENV_VAR",
")",
"if",
"profile_dir",
":",
"LOGGER",
".",
"info",
"(",
"u\"Using firefox profile: %s\"",
",",
"profile_dir",
")",
"try",
":",
"f... | Configure the Firefox profile, respecting FIREFOX_PROFILE_PATH if set | [
"Configure",
"the",
"Firefox",
"profile",
"respecting",
"FIREFOX_PROFILE_PATH",
"if",
"set"
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L309-L367 |
edx/bok-choy | bok_choy/browser.py | _local_browser_class | def _local_browser_class(browser_name):
"""
Returns class, kwargs, and args needed to instantiate the local browser.
"""
# Log name of local browser
LOGGER.info(u"Using local browser: %s [Default is firefox]", browser_name)
# Get class of local browser based on name
browser_class = BROWSER... | python | def _local_browser_class(browser_name):
"""
Returns class, kwargs, and args needed to instantiate the local browser.
"""
# Log name of local browser
LOGGER.info(u"Using local browser: %s [Default is firefox]", browser_name)
# Get class of local browser based on name
browser_class = BROWSER... | [
"def",
"_local_browser_class",
"(",
"browser_name",
")",
":",
"# Log name of local browser",
"LOGGER",
".",
"info",
"(",
"u\"Using local browser: %s [Default is firefox]\"",
",",
"browser_name",
")",
"# Get class of local browser based on name",
"browser_class",
"=",
"BROWSERS",
... | Returns class, kwargs, and args needed to instantiate the local browser. | [
"Returns",
"class",
"kwargs",
"and",
"args",
"needed",
"to",
"instantiate",
"the",
"local",
"browser",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L370-L437 |
edx/bok-choy | bok_choy/browser.py | _remote_browser_class | def _remote_browser_class(env_vars, tags=None):
"""
Returns class, kwargs, and args needed to instantiate the remote browser.
"""
if tags is None:
tags = []
# Interpret the environment variables, raising an exception if they're
# invalid
envs = _required_envs(env_vars)
envs.upda... | python | def _remote_browser_class(env_vars, tags=None):
"""
Returns class, kwargs, and args needed to instantiate the remote browser.
"""
if tags is None:
tags = []
# Interpret the environment variables, raising an exception if they're
# invalid
envs = _required_envs(env_vars)
envs.upda... | [
"def",
"_remote_browser_class",
"(",
"env_vars",
",",
"tags",
"=",
"None",
")",
":",
"if",
"tags",
"is",
"None",
":",
"tags",
"=",
"[",
"]",
"# Interpret the environment variables, raising an exception if they're",
"# invalid",
"envs",
"=",
"_required_envs",
"(",
"e... | Returns class, kwargs, and args needed to instantiate the remote browser. | [
"Returns",
"class",
"kwargs",
"and",
"args",
"needed",
"to",
"instantiate",
"the",
"remote",
"browser",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L440-L474 |
edx/bok-choy | bok_choy/browser.py | _proxy_kwargs | def _proxy_kwargs(browser_name, proxy, browser_kwargs={}): # pylint: disable=dangerous-default-value
"""
Determines the kwargs needed to set up a proxy based on the
browser type.
Returns: a dictionary of arguments needed to pass when
instantiating the WebDriver instance.
"""
proxy_dic... | python | def _proxy_kwargs(browser_name, proxy, browser_kwargs={}): # pylint: disable=dangerous-default-value
"""
Determines the kwargs needed to set up a proxy based on the
browser type.
Returns: a dictionary of arguments needed to pass when
instantiating the WebDriver instance.
"""
proxy_dic... | [
"def",
"_proxy_kwargs",
"(",
"browser_name",
",",
"proxy",
",",
"browser_kwargs",
"=",
"{",
"}",
")",
":",
"# pylint: disable=dangerous-default-value",
"proxy_dict",
"=",
"{",
"\"httpProxy\"",
":",
"proxy",
".",
"proxy",
",",
"\"proxyType\"",
":",
"'manual'",
",",... | Determines the kwargs needed to set up a proxy based on the
browser type.
Returns: a dictionary of arguments needed to pass when
instantiating the WebDriver instance. | [
"Determines",
"the",
"kwargs",
"needed",
"to",
"set",
"up",
"a",
"proxy",
"based",
"on",
"the",
"browser",
"type",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L477-L503 |
edx/bok-choy | bok_choy/browser.py | _required_envs | def _required_envs(env_vars):
"""
Parse environment variables for required values,
raising a `BrowserConfig` error if they are not found.
Returns a `dict` of environment variables.
"""
envs = {
key: os.environ.get(key)
for key in env_vars
}
# Check for missing keys
... | python | def _required_envs(env_vars):
"""
Parse environment variables for required values,
raising a `BrowserConfig` error if they are not found.
Returns a `dict` of environment variables.
"""
envs = {
key: os.environ.get(key)
for key in env_vars
}
# Check for missing keys
... | [
"def",
"_required_envs",
"(",
"env_vars",
")",
":",
"envs",
"=",
"{",
"key",
":",
"os",
".",
"environ",
".",
"get",
"(",
"key",
")",
"for",
"key",
"in",
"env_vars",
"}",
"# Check for missing keys",
"missing",
"=",
"[",
"key",
"for",
"key",
",",
"val",
... | Parse environment variables for required values,
raising a `BrowserConfig` error if they are not found.
Returns a `dict` of environment variables. | [
"Parse",
"environment",
"variables",
"for",
"required",
"values",
"raising",
"a",
"BrowserConfig",
"error",
"if",
"they",
"are",
"not",
"found",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L519-L544 |
edx/bok-choy | bok_choy/browser.py | _optional_envs | def _optional_envs():
"""
Parse environment variables for optional values,
raising a `BrowserConfig` error if they are insufficiently specified.
Returns a `dict` of environment variables.
"""
envs = {
key: os.environ.get(key)
for key in OPTIONAL_ENV_VARS
if key in os.env... | python | def _optional_envs():
"""
Parse environment variables for optional values,
raising a `BrowserConfig` error if they are insufficiently specified.
Returns a `dict` of environment variables.
"""
envs = {
key: os.environ.get(key)
for key in OPTIONAL_ENV_VARS
if key in os.env... | [
"def",
"_optional_envs",
"(",
")",
":",
"envs",
"=",
"{",
"key",
":",
"os",
".",
"environ",
".",
"get",
"(",
"key",
")",
"for",
"key",
"in",
"OPTIONAL_ENV_VARS",
"if",
"key",
"in",
"os",
".",
"environ",
"}",
"# If we're using Jenkins, check that we have all ... | Parse environment variables for optional values,
raising a `BrowserConfig` error if they are insufficiently specified.
Returns a `dict` of environment variables. | [
"Parse",
"environment",
"variables",
"for",
"optional",
"values",
"raising",
"a",
"BrowserConfig",
"error",
"if",
"they",
"are",
"insufficiently",
"specified",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L547-L567 |
edx/bok-choy | bok_choy/browser.py | _capabilities_dict | def _capabilities_dict(envs, tags):
"""
Convert the dictionary of environment variables to
a dictionary of desired capabilities to send to the
Remote WebDriver.
`tags` is a list of string tags to apply to the SauceLabs job.
"""
capabilities = {
'browserName': envs['SELENIUM_BROWSER'... | python | def _capabilities_dict(envs, tags):
"""
Convert the dictionary of environment variables to
a dictionary of desired capabilities to send to the
Remote WebDriver.
`tags` is a list of string tags to apply to the SauceLabs job.
"""
capabilities = {
'browserName': envs['SELENIUM_BROWSER'... | [
"def",
"_capabilities_dict",
"(",
"envs",
",",
"tags",
")",
":",
"capabilities",
"=",
"{",
"'browserName'",
":",
"envs",
"[",
"'SELENIUM_BROWSER'",
"]",
",",
"'acceptInsecureCerts'",
":",
"bool",
"(",
"envs",
".",
"get",
"(",
"'SELENIUM_INSECURE_CERTS'",
",",
... | Convert the dictionary of environment variables to
a dictionary of desired capabilities to send to the
Remote WebDriver.
`tags` is a list of string tags to apply to the SauceLabs job. | [
"Convert",
"the",
"dictionary",
"of",
"environment",
"variables",
"to",
"a",
"dictionary",
"of",
"desired",
"capabilities",
"to",
"send",
"to",
"the",
"Remote",
"WebDriver",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L570-L611 |
edx/bok-choy | bok_choy/query.py | Query.replace | def replace(self, **kwargs):
"""
Return a copy of this `Query`, but with attributes specified
as keyword arguments replaced by the keyword values.
Keyword Args:
Attributes/values to replace in the copy.
Returns:
A copy of the query that has its attribut... | python | def replace(self, **kwargs):
"""
Return a copy of this `Query`, but with attributes specified
as keyword arguments replaced by the keyword values.
Keyword Args:
Attributes/values to replace in the copy.
Returns:
A copy of the query that has its attribut... | [
"def",
"replace",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"clone",
"=",
"copy",
"(",
"self",
")",
"clone",
".",
"transforms",
"=",
"list",
"(",
"clone",
".",
"transforms",
")",
"for",
"key",
",",
"value",
"in",
"kwargs",
".",
"items",
"(",
... | Return a copy of this `Query`, but with attributes specified
as keyword arguments replaced by the keyword values.
Keyword Args:
Attributes/values to replace in the copy.
Returns:
A copy of the query that has its attributes updated with the specified values.
Ra... | [
"Return",
"a",
"copy",
"of",
"this",
"Query",
"but",
"with",
"attributes",
"specified",
"as",
"keyword",
"arguments",
"replaced",
"by",
"the",
"keyword",
"values",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L81-L103 |
edx/bok-choy | bok_choy/query.py | Query.transform | def transform(self, transform, desc=None):
"""
Create a copy of this query, transformed by `transform`.
Args:
transform (callable): Callable that takes an iterable of values and
returns an iterable of transformed values.
Keyword Args:
desc (str):... | python | def transform(self, transform, desc=None):
"""
Create a copy of this query, transformed by `transform`.
Args:
transform (callable): Callable that takes an iterable of values and
returns an iterable of transformed values.
Keyword Args:
desc (str):... | [
"def",
"transform",
"(",
"self",
",",
"transform",
",",
"desc",
"=",
"None",
")",
":",
"if",
"desc",
"is",
"None",
":",
"desc",
"=",
"u'transform({})'",
".",
"format",
"(",
"getattr",
"(",
"transform",
",",
"'__name__'",
",",
"''",
")",
")",
"return",
... | Create a copy of this query, transformed by `transform`.
Args:
transform (callable): Callable that takes an iterable of values and
returns an iterable of transformed values.
Keyword Args:
desc (str): A description of the transform, to use in log messages.
... | [
"Create",
"a",
"copy",
"of",
"this",
"query",
"transformed",
"by",
"transform",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L105-L126 |
edx/bok-choy | bok_choy/query.py | Query.map | def map(self, map_fn, desc=None):
"""
Return a copy of this query, with the values mapped through `map_fn`.
Args:
map_fn (callable): A callable that takes a single argument and returns a new value.
Keyword Args:
desc (str): A description of the mapping transform... | python | def map(self, map_fn, desc=None):
"""
Return a copy of this query, with the values mapped through `map_fn`.
Args:
map_fn (callable): A callable that takes a single argument and returns a new value.
Keyword Args:
desc (str): A description of the mapping transform... | [
"def",
"map",
"(",
"self",
",",
"map_fn",
",",
"desc",
"=",
"None",
")",
":",
"if",
"desc",
"is",
"None",
":",
"desc",
"=",
"getattr",
"(",
"map_fn",
",",
"'__name__'",
",",
"''",
")",
"desc",
"=",
"u'map({})'",
".",
"format",
"(",
"desc",
")",
"... | Return a copy of this query, with the values mapped through `map_fn`.
Args:
map_fn (callable): A callable that takes a single argument and returns a new value.
Keyword Args:
desc (str): A description of the mapping transform, for use in log message.
Defaults to ... | [
"Return",
"a",
"copy",
"of",
"this",
"query",
"with",
"the",
"values",
"mapped",
"through",
"map_fn",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L128-L146 |
edx/bok-choy | bok_choy/query.py | Query.filter | def filter(self, filter_fn=None, desc=None, **kwargs):
"""
Return a copy of this query, with some values removed.
Example usages:
.. code:: python
# Returns a query that matches even numbers
q.filter(filter_fn=lambda x: x % 2)
# Returns a query tha... | python | def filter(self, filter_fn=None, desc=None, **kwargs):
"""
Return a copy of this query, with some values removed.
Example usages:
.. code:: python
# Returns a query that matches even numbers
q.filter(filter_fn=lambda x: x % 2)
# Returns a query tha... | [
"def",
"filter",
"(",
"self",
",",
"filter_fn",
"=",
"None",
",",
"desc",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"filter_fn",
"is",
"not",
"None",
"and",
"kwargs",
":",
"raise",
"TypeError",
"(",
"'Must supply either a filter_fn or attribute f... | Return a copy of this query, with some values removed.
Example usages:
.. code:: python
# Returns a query that matches even numbers
q.filter(filter_fn=lambda x: x % 2)
# Returns a query that matches elements with el.description == "foo"
q.filter(descri... | [
"Return",
"a",
"copy",
"of",
"this",
"query",
"with",
"some",
"values",
"removed",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L148-L194 |
edx/bok-choy | bok_choy/query.py | Query._execute | def _execute(self):
"""
Run the query, generating data from the `seed_fn` and performing transforms on the results.
"""
data = self.seed_fn()
for transform in self.transforms:
data = transform(data)
return list(data) | python | def _execute(self):
"""
Run the query, generating data from the `seed_fn` and performing transforms on the results.
"""
data = self.seed_fn()
for transform in self.transforms:
data = transform(data)
return list(data) | [
"def",
"_execute",
"(",
"self",
")",
":",
"data",
"=",
"self",
".",
"seed_fn",
"(",
")",
"for",
"transform",
"in",
"self",
".",
"transforms",
":",
"data",
"=",
"transform",
"(",
"data",
")",
"return",
"list",
"(",
"data",
")"
] | Run the query, generating data from the `seed_fn` and performing transforms on the results. | [
"Run",
"the",
"query",
"generating",
"data",
"from",
"the",
"seed_fn",
"and",
"performing",
"transforms",
"on",
"the",
"results",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L196-L203 |
edx/bok-choy | bok_choy/query.py | Query.execute | def execute(self, try_limit=5, try_interval=0.5, timeout=30):
"""
Execute this query, retrying based on the supplied parameters.
Keyword Args:
try_limit (int): The number of times to retry the query.
try_interval (float): The number of seconds to wait between each try (f... | python | def execute(self, try_limit=5, try_interval=0.5, timeout=30):
"""
Execute this query, retrying based on the supplied parameters.
Keyword Args:
try_limit (int): The number of times to retry the query.
try_interval (float): The number of seconds to wait between each try (f... | [
"def",
"execute",
"(",
"self",
",",
"try_limit",
"=",
"5",
",",
"try_interval",
"=",
"0.5",
",",
"timeout",
"=",
"30",
")",
":",
"return",
"Promise",
"(",
"no_error",
"(",
"self",
".",
"_execute",
")",
",",
"u\"Executing {!r}\"",
".",
"format",
"(",
"s... | Execute this query, retrying based on the supplied parameters.
Keyword Args:
try_limit (int): The number of times to retry the query.
try_interval (float): The number of seconds to wait between each try (float).
timeout (float): The maximum number of seconds to spend retryin... | [
"Execute",
"this",
"query",
"retrying",
"based",
"on",
"the",
"supplied",
"parameters",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L205-L226 |
edx/bok-choy | bok_choy/query.py | Query.first | def first(self):
"""
Return a Query that selects only the first element of this Query.
If no elements are available, returns a query with no results.
Example usage:
.. code:: python
>> q = Query(lambda: list(range(5)))
>> q.first.results
[0]... | python | def first(self):
"""
Return a Query that selects only the first element of this Query.
If no elements are available, returns a query with no results.
Example usage:
.. code:: python
>> q = Query(lambda: list(range(5)))
>> q.first.results
[0]... | [
"def",
"first",
"(",
"self",
")",
":",
"def",
"_transform",
"(",
"xs",
")",
":",
"# pylint: disable=missing-docstring, invalid-name",
"try",
":",
"return",
"[",
"six",
".",
"next",
"(",
"iter",
"(",
"xs",
")",
")",
"]",
"except",
"StopIteration",
":",
"ret... | Return a Query that selects only the first element of this Query.
If no elements are available, returns a query with no results.
Example usage:
.. code:: python
>> q = Query(lambda: list(range(5)))
>> q.first.results
[0]
Returns:
Query | [
"Return",
"a",
"Query",
"that",
"selects",
"only",
"the",
"first",
"element",
"of",
"this",
"Query",
".",
"If",
"no",
"elements",
"are",
"available",
"returns",
"a",
"query",
"with",
"no",
"results",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L258-L280 |
edx/bok-choy | bok_choy/query.py | Query.nth | def nth(self, index):
"""
Return a query that selects the element at `index` (starts from 0).
If no elements are available, returns a query with no results.
Example usage:
.. code:: python
>> q = Query(lambda: list(range(5)))
>> q.nth(2).results
... | python | def nth(self, index):
"""
Return a query that selects the element at `index` (starts from 0).
If no elements are available, returns a query with no results.
Example usage:
.. code:: python
>> q = Query(lambda: list(range(5)))
>> q.nth(2).results
... | [
"def",
"nth",
"(",
"self",
",",
"index",
")",
":",
"def",
"_transform",
"(",
"xs",
")",
":",
"# pylint: disable=missing-docstring, invalid-name",
"try",
":",
"return",
"[",
"next",
"(",
"islice",
"(",
"iter",
"(",
"xs",
")",
",",
"index",
",",
"None",
")... | Return a query that selects the element at `index` (starts from 0).
If no elements are available, returns a query with no results.
Example usage:
.. code:: python
>> q = Query(lambda: list(range(5)))
>> q.nth(2).results
[2]
Args:
index ... | [
"Return",
"a",
"query",
"that",
"selects",
"the",
"element",
"at",
"index",
"(",
"starts",
"from",
"0",
")",
".",
"If",
"no",
"elements",
"are",
"available",
"returns",
"a",
"query",
"with",
"no",
"results",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L282-L309 |
edx/bok-choy | bok_choy/query.py | BrowserQuery.attrs | def attrs(self, attribute_name):
"""
Retrieve HTML attribute values from the elements matched by the query.
Example usage:
.. code:: python
# Assume that the query matches html elements:
# <div class="foo"> and <div class="bar">
>> q.attrs('class')
... | python | def attrs(self, attribute_name):
"""
Retrieve HTML attribute values from the elements matched by the query.
Example usage:
.. code:: python
# Assume that the query matches html elements:
# <div class="foo"> and <div class="bar">
>> q.attrs('class')
... | [
"def",
"attrs",
"(",
"self",
",",
"attribute_name",
")",
":",
"desc",
"=",
"u'attrs({!r})'",
".",
"format",
"(",
"attribute_name",
")",
"return",
"self",
".",
"map",
"(",
"lambda",
"el",
":",
"el",
".",
"get_attribute",
"(",
"attribute_name",
")",
",",
"... | Retrieve HTML attribute values from the elements matched by the query.
Example usage:
.. code:: python
# Assume that the query matches html elements:
# <div class="foo"> and <div class="bar">
>> q.attrs('class')
['foo', 'bar']
Args:
... | [
"Retrieve",
"HTML",
"attribute",
"values",
"from",
"the",
"elements",
"matched",
"by",
"the",
"query",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L356-L376 |
edx/bok-choy | bok_choy/query.py | BrowserQuery.selected | def selected(self):
"""
Check whether all the matched elements are selected.
Returns:
bool
"""
query_results = self.map(lambda el: el.is_selected(), 'selected').results
if query_results:
return all(query_results)
return False | python | def selected(self):
"""
Check whether all the matched elements are selected.
Returns:
bool
"""
query_results = self.map(lambda el: el.is_selected(), 'selected').results
if query_results:
return all(query_results)
return False | [
"def",
"selected",
"(",
"self",
")",
":",
"query_results",
"=",
"self",
".",
"map",
"(",
"lambda",
"el",
":",
"el",
".",
"is_selected",
"(",
")",
",",
"'selected'",
")",
".",
"results",
"if",
"query_results",
":",
"return",
"all",
"(",
"query_results",
... | Check whether all the matched elements are selected.
Returns:
bool | [
"Check",
"whether",
"all",
"the",
"matched",
"elements",
"are",
"selected",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L417-L427 |
edx/bok-choy | bok_choy/query.py | BrowserQuery.visible | def visible(self):
"""
Check whether all matched elements are visible.
Returns:
bool
"""
query_results = self.map(lambda el: el.is_displayed(), 'visible').results
if query_results:
return all(query_results)
return False | python | def visible(self):
"""
Check whether all matched elements are visible.
Returns:
bool
"""
query_results = self.map(lambda el: el.is_displayed(), 'visible').results
if query_results:
return all(query_results)
return False | [
"def",
"visible",
"(",
"self",
")",
":",
"query_results",
"=",
"self",
".",
"map",
"(",
"lambda",
"el",
":",
"el",
".",
"is_displayed",
"(",
")",
",",
"'visible'",
")",
".",
"results",
"if",
"query_results",
":",
"return",
"all",
"(",
"query_results",
... | Check whether all matched elements are visible.
Returns:
bool | [
"Check",
"whether",
"all",
"matched",
"elements",
"are",
"visible",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L430-L440 |
edx/bok-choy | bok_choy/query.py | BrowserQuery.is_focused | def is_focused(self):
"""
Checks that *at least one* matched element is focused. More
specifically, it checks whether the element is document.activeElement.
If no matching element is focused, this returns `False`.
Returns:
bool
"""
active_el = self.br... | python | def is_focused(self):
"""
Checks that *at least one* matched element is focused. More
specifically, it checks whether the element is document.activeElement.
If no matching element is focused, this returns `False`.
Returns:
bool
"""
active_el = self.br... | [
"def",
"is_focused",
"(",
"self",
")",
":",
"active_el",
"=",
"self",
".",
"browser",
".",
"execute_script",
"(",
"\"return document.activeElement\"",
")",
"query_results",
"=",
"self",
".",
"map",
"(",
"lambda",
"el",
":",
"el",
"==",
"active_el",
",",
"'fo... | Checks that *at least one* matched element is focused. More
specifically, it checks whether the element is document.activeElement.
If no matching element is focused, this returns `False`.
Returns:
bool | [
"Checks",
"that",
"*",
"at",
"least",
"one",
"*",
"matched",
"element",
"is",
"focused",
".",
"More",
"specifically",
"it",
"checks",
"whether",
"the",
"element",
"is",
"document",
".",
"activeElement",
".",
"If",
"no",
"matching",
"element",
"is",
"focused"... | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L452-L466 |
edx/bok-choy | bok_choy/query.py | BrowserQuery.fill | def fill(self, text):
"""
Set the text value of each matched element to `text`.
Example usage:
.. code:: python
# Set the text of the first element matched by the query to "Foo"
q.first.fill('Foo')
Args:
text (str): The text used to fill th... | python | def fill(self, text):
"""
Set the text value of each matched element to `text`.
Example usage:
.. code:: python
# Set the text of the first element matched by the query to "Foo"
q.first.fill('Foo')
Args:
text (str): The text used to fill th... | [
"def",
"fill",
"(",
"self",
",",
"text",
")",
":",
"def",
"_fill",
"(",
"elem",
")",
":",
"# pylint: disable=missing-docstring",
"elem",
".",
"clear",
"(",
")",
"elem",
".",
"send_keys",
"(",
"text",
")",
"self",
".",
"map",
"(",
"_fill",
",",
"u'fill(... | Set the text value of each matched element to `text`.
Example usage:
.. code:: python
# Set the text of the first element matched by the query to "Foo"
q.first.fill('Foo')
Args:
text (str): The text used to fill the element (usually a text field or text ar... | [
"Set",
"the",
"text",
"value",
"of",
"each",
"matched",
"element",
"to",
"text",
"."
] | train | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L486-L507 |
metakermit/django-spa | spa/storage.py | PatchedManifestStaticFilesStorage.url_converter | def url_converter(self, *args, **kwargs):
"""
Return the custom URL converter for the given file name.
"""
upstream_converter = super(PatchedManifestStaticFilesStorage, self).url_converter(*args, **kwargs)
def converter(matchobj):
try:
upstream_conver... | python | def url_converter(self, *args, **kwargs):
"""
Return the custom URL converter for the given file name.
"""
upstream_converter = super(PatchedManifestStaticFilesStorage, self).url_converter(*args, **kwargs)
def converter(matchobj):
try:
upstream_conver... | [
"def",
"url_converter",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"upstream_converter",
"=",
"super",
"(",
"PatchedManifestStaticFilesStorage",
",",
"self",
")",
".",
"url_converter",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
... | Return the custom URL converter for the given file name. | [
"Return",
"the",
"custom",
"URL",
"converter",
"for",
"the",
"given",
"file",
"name",
"."
] | train | https://github.com/metakermit/django-spa/blob/dbdfa6d06c1077fade729db25b3b137d44299db6/spa/storage.py#L12-L27 |
TriOptima/tri.table | lib/tri/table/__init__.py | prepare_headers | def prepare_headers(table, bound_columns):
"""
:type bound_columns: list of BoundColumn
"""
if table.request is None:
return
for column in bound_columns:
if column.sortable:
params = table.request.GET.copy()
param_path = _with_path_prefix(table, 'order')
... | python | def prepare_headers(table, bound_columns):
"""
:type bound_columns: list of BoundColumn
"""
if table.request is None:
return
for column in bound_columns:
if column.sortable:
params = table.request.GET.copy()
param_path = _with_path_prefix(table, 'order')
... | [
"def",
"prepare_headers",
"(",
"table",
",",
"bound_columns",
")",
":",
"if",
"table",
".",
"request",
"is",
"None",
":",
"return",
"for",
"column",
"in",
"bound_columns",
":",
"if",
"column",
".",
"sortable",
":",
"params",
"=",
"table",
".",
"request",
... | :type bound_columns: list of BoundColumn | [
":",
"type",
"bound_columns",
":",
"list",
"of",
"BoundColumn"
] | train | https://github.com/TriOptima/tri.table/blob/fc38c02098a80a3fb336ac4cf502954d74e31484/lib/tri/table/__init__.py#L112-L138 |
TriOptima/tri.table | lib/tri/table/__init__.py | order_by_on_list | def order_by_on_list(objects, order_field, is_desc=False):
"""
Utility function to sort objects django-style even for non-query set collections
:param objects: list of objects to sort
:param order_field: field name, follows django conventions, so "foo__bar" means `foo.bar`, can be a callable.
:para... | python | def order_by_on_list(objects, order_field, is_desc=False):
"""
Utility function to sort objects django-style even for non-query set collections
:param objects: list of objects to sort
:param order_field: field name, follows django conventions, so "foo__bar" means `foo.bar`, can be a callable.
:para... | [
"def",
"order_by_on_list",
"(",
"objects",
",",
"order_field",
",",
"is_desc",
"=",
"False",
")",
":",
"if",
"callable",
"(",
"order_field",
")",
":",
"objects",
".",
"sort",
"(",
"key",
"=",
"order_field",
",",
"reverse",
"=",
"is_desc",
")",
"return",
... | Utility function to sort objects django-style even for non-query set collections
:param objects: list of objects to sort
:param order_field: field name, follows django conventions, so "foo__bar" means `foo.bar`, can be a callable.
:param is_desc: reverse the sorting
:return: | [
"Utility",
"function",
"to",
"sort",
"objects",
"django",
"-",
"style",
"even",
"for",
"non",
"-",
"query",
"set",
"collections"
] | train | https://github.com/TriOptima/tri.table/blob/fc38c02098a80a3fb336ac4cf502954d74e31484/lib/tri/table/__init__.py#L153-L172 |
TriOptima/tri.table | lib/tri/table/__init__.py | default_cell_formatter | def default_cell_formatter(table, column, row, value, **_):
"""
:type column: tri.table.Column
"""
formatter = _cell_formatters.get(type(value))
if formatter:
value = formatter(table=table, column=column, row=row, value=value)
if value is None:
return ''
return conditional_... | python | def default_cell_formatter(table, column, row, value, **_):
"""
:type column: tri.table.Column
"""
formatter = _cell_formatters.get(type(value))
if formatter:
value = formatter(table=table, column=column, row=row, value=value)
if value is None:
return ''
return conditional_... | [
"def",
"default_cell_formatter",
"(",
"table",
",",
"column",
",",
"row",
",",
"value",
",",
"*",
"*",
"_",
")",
":",
"formatter",
"=",
"_cell_formatters",
".",
"get",
"(",
"type",
"(",
"value",
")",
")",
"if",
"formatter",
":",
"value",
"=",
"formatte... | :type column: tri.table.Column | [
":",
"type",
"column",
":",
"tri",
".",
"table",
".",
"Column"
] | train | https://github.com/TriOptima/tri.table/blob/fc38c02098a80a3fb336ac4cf502954d74e31484/lib/tri/table/__init__.py#L207-L218 |
TriOptima/tri.table | lib/tri/table/__init__.py | django_pre_2_0_table_context | def django_pre_2_0_table_context(
request,
table,
links=None,
paginate_by=None,
page=None,
extra_context=None,
paginator=None,
show_hits=False,
hit_label='Items'):
"""
:type table: Table
"""
if extra_context is None: # pragma: no c... | python | def django_pre_2_0_table_context(
request,
table,
links=None,
paginate_by=None,
page=None,
extra_context=None,
paginator=None,
show_hits=False,
hit_label='Items'):
"""
:type table: Table
"""
if extra_context is None: # pragma: no c... | [
"def",
"django_pre_2_0_table_context",
"(",
"request",
",",
"table",
",",
"links",
"=",
"None",
",",
"paginate_by",
"=",
"None",
",",
"page",
"=",
"None",
",",
"extra_context",
"=",
"None",
",",
"paginator",
"=",
"None",
",",
"show_hits",
"=",
"False",
","... | :type table: Table | [
":",
"type",
"table",
":",
"Table"
] | train | https://github.com/TriOptima/tri.table/blob/fc38c02098a80a3fb336ac4cf502954d74e31484/lib/tri/table/__init__.py#L1450-L1521 |
TriOptima/tri.table | lib/tri/table/__init__.py | table_context | def table_context(request,
table,
links=None,
paginate_by=None,
page=None,
extra_context=None,
paginator=None,
show_hits=False,
hit_label='Items'):
"""
:type table: Tab... | python | def table_context(request,
table,
links=None,
paginate_by=None,
page=None,
extra_context=None,
paginator=None,
show_hits=False,
hit_label='Items'):
"""
:type table: Tab... | [
"def",
"table_context",
"(",
"request",
",",
"table",
",",
"links",
"=",
"None",
",",
"paginate_by",
"=",
"None",
",",
"page",
"=",
"None",
",",
"extra_context",
"=",
"None",
",",
"paginator",
"=",
"None",
",",
"show_hits",
"=",
"False",
",",
"hit_label"... | :type table: Table | [
":",
"type",
"table",
":",
"Table"
] | train | https://github.com/TriOptima/tri.table/blob/fc38c02098a80a3fb336ac4cf502954d74e31484/lib/tri/table/__init__.py#L1524-L1589 |
TriOptima/tri.table | lib/tri/table/__init__.py | render_table | def render_table(request,
table,
links=None,
context=None,
template='tri_table/list.html',
blank_on_empty=False,
paginate_by=40, # pragma: no mutate
page=None,
paginator=None,
... | python | def render_table(request,
table,
links=None,
context=None,
template='tri_table/list.html',
blank_on_empty=False,
paginate_by=40, # pragma: no mutate
page=None,
paginator=None,
... | [
"def",
"render_table",
"(",
"request",
",",
"table",
",",
"links",
"=",
"None",
",",
"context",
"=",
"None",
",",
"template",
"=",
"'tri_table/list.html'",
",",
"blank_on_empty",
"=",
"False",
",",
"paginate_by",
"=",
"40",
",",
"# pragma: no mutate",
"page",
... | Render a table. This automatically handles pagination, sorting, filtering and bulk operations.
:param request: the request object. This is set on the table object so that it is available for lambda expressions.
:param table: an instance of Table
:param links: a list of instances of Link
:param context:... | [
"Render",
"a",
"table",
".",
"This",
"automatically",
"handles",
"pagination",
"sorting",
"filtering",
"and",
"bulk",
"operations",
"."
] | train | https://github.com/TriOptima/tri.table/blob/fc38c02098a80a3fb336ac4cf502954d74e31484/lib/tri/table/__init__.py#L1595-L1671 |
TriOptima/tri.table | lib/tri/table/__init__.py | render_table_to_response | def render_table_to_response(*args, **kwargs):
"""
Shortcut for `HttpResponse(render_table(*args, **kwargs))`
"""
response = render_table(*args, **kwargs)
if isinstance(response, HttpResponse): # pragma: no cover
return response
return HttpResponse(response) | python | def render_table_to_response(*args, **kwargs):
"""
Shortcut for `HttpResponse(render_table(*args, **kwargs))`
"""
response = render_table(*args, **kwargs)
if isinstance(response, HttpResponse): # pragma: no cover
return response
return HttpResponse(response) | [
"def",
"render_table_to_response",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"response",
"=",
"render_table",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"if",
"isinstance",
"(",
"response",
",",
"HttpResponse",
")",
":",
"# pragma: no cover... | Shortcut for `HttpResponse(render_table(*args, **kwargs))` | [
"Shortcut",
"for",
"HttpResponse",
"(",
"render_table",
"(",
"*",
"args",
"**",
"kwargs",
"))"
] | train | https://github.com/TriOptima/tri.table/blob/fc38c02098a80a3fb336ac4cf502954d74e31484/lib/tri/table/__init__.py#L1674-L1681 |
infobloxopen/infoblox-client | infoblox_client/utils.py | generate_duid | def generate_duid(mac):
"""DUID is consisted of 10 hex numbers.
0x00 + mac with last 3 hex + mac with 6 hex
"""
valid = mac and isinstance(mac, six.string_types)
if not valid:
raise ValueError("Invalid argument was passed")
return "00:" + mac[9:] + ":" + mac | python | def generate_duid(mac):
"""DUID is consisted of 10 hex numbers.
0x00 + mac with last 3 hex + mac with 6 hex
"""
valid = mac and isinstance(mac, six.string_types)
if not valid:
raise ValueError("Invalid argument was passed")
return "00:" + mac[9:] + ":" + mac | [
"def",
"generate_duid",
"(",
"mac",
")",
":",
"valid",
"=",
"mac",
"and",
"isinstance",
"(",
"mac",
",",
"six",
".",
"string_types",
")",
"if",
"not",
"valid",
":",
"raise",
"ValueError",
"(",
"\"Invalid argument was passed\"",
")",
"return",
"\"00:\"",
"+",... | DUID is consisted of 10 hex numbers.
0x00 + mac with last 3 hex + mac with 6 hex | [
"DUID",
"is",
"consisted",
"of",
"10",
"hex",
"numbers",
"."
] | train | https://github.com/infobloxopen/infoblox-client/blob/edeec62db1935784c728731b2ae7cf0fcc9bf84d/infoblox_client/utils.py#L41-L49 |
infobloxopen/infoblox-client | infoblox_client/utils.py | try_value_to_bool | def try_value_to_bool(value, strict_mode=True):
"""Tries to convert value into boolean.
strict_mode is True:
- Only string representation of str(True) and str(False)
are converted into booleans;
- Otherwise unchanged incoming value is returned;
strict_mode is False:
- Anything that looks... | python | def try_value_to_bool(value, strict_mode=True):
"""Tries to convert value into boolean.
strict_mode is True:
- Only string representation of str(True) and str(False)
are converted into booleans;
- Otherwise unchanged incoming value is returned;
strict_mode is False:
- Anything that looks... | [
"def",
"try_value_to_bool",
"(",
"value",
",",
"strict_mode",
"=",
"True",
")",
":",
"if",
"strict_mode",
":",
"true_list",
"=",
"(",
"'True'",
",",
")",
"false_list",
"=",
"(",
"'False'",
",",
")",
"val",
"=",
"value",
"else",
":",
"true_list",
"=",
"... | Tries to convert value into boolean.
strict_mode is True:
- Only string representation of str(True) and str(False)
are converted into booleans;
- Otherwise unchanged incoming value is returned;
strict_mode is False:
- Anything that looks like True or False is converted into booleans.
Val... | [
"Tries",
"to",
"convert",
"value",
"into",
"boolean",
"."
] | train | https://github.com/infobloxopen/infoblox-client/blob/edeec62db1935784c728731b2ae7cf0fcc9bf84d/infoblox_client/utils.py#L85-L114 |
infobloxopen/infoblox-client | infoblox_client/object_manager.py | InfobloxObjectManager.create_network | def create_network(self, net_view_name, cidr, nameservers=None,
members=None, gateway_ip=None, dhcp_trel_ip=None,
network_extattrs=None):
"""Create NIOS Network and prepare DHCP options.
Some DHCP options are valid for IPv4 only, so just skip processing
... | python | def create_network(self, net_view_name, cidr, nameservers=None,
members=None, gateway_ip=None, dhcp_trel_ip=None,
network_extattrs=None):
"""Create NIOS Network and prepare DHCP options.
Some DHCP options are valid for IPv4 only, so just skip processing
... | [
"def",
"create_network",
"(",
"self",
",",
"net_view_name",
",",
"cidr",
",",
"nameservers",
"=",
"None",
",",
"members",
"=",
"None",
",",
"gateway_ip",
"=",
"None",
",",
"dhcp_trel_ip",
"=",
"None",
",",
"network_extattrs",
"=",
"None",
")",
":",
"ipv4",... | Create NIOS Network and prepare DHCP options.
Some DHCP options are valid for IPv4 only, so just skip processing
them for IPv6 case.
:param net_view_name: network view name
:param cidr: network to allocate, example '172.23.23.0/24'
:param nameservers: list of name servers hosts... | [
"Create",
"NIOS",
"Network",
"and",
"prepare",
"DHCP",
"options",
"."
] | train | https://github.com/infobloxopen/infoblox-client/blob/edeec62db1935784c728731b2ae7cf0fcc9bf84d/infoblox_client/object_manager.py#L58-L96 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.