repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
greenbone/ospd | ospd/misc.py | valid_uuid | def valid_uuid(value):
""" Check if value is a valid UUID. """
try:
uuid.UUID(value, version=4)
return True
except (TypeError, ValueError, AttributeError):
return False | python | def valid_uuid(value):
""" Check if value is a valid UUID. """
try:
uuid.UUID(value, version=4)
return True
except (TypeError, ValueError, AttributeError):
return False | [
"def",
"valid_uuid",
"(",
"value",
")",
":",
"try",
":",
"uuid",
".",
"UUID",
"(",
"value",
",",
"version",
"=",
"4",
")",
"return",
"True",
"except",
"(",
"TypeError",
",",
"ValueError",
",",
"AttributeError",
")",
":",
"return",
"False"
] | Check if value is a valid UUID. | [
"Check",
"if",
"value",
"is",
"a",
"valid",
"UUID",
"."
] | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L762-L769 | train |
greenbone/ospd | ospd/misc.py | create_args_parser | def create_args_parser(description):
""" Create a command-line arguments parser for OSPD. """
parser = argparse.ArgumentParser(description=description)
def network_port(string):
""" Check if provided string is a valid network port. """
value = int(string)
if not 0 < value <= 65535... | python | def create_args_parser(description):
""" Create a command-line arguments parser for OSPD. """
parser = argparse.ArgumentParser(description=description)
def network_port(string):
""" Check if provided string is a valid network port. """
value = int(string)
if not 0 < value <= 65535... | [
"def",
"create_args_parser",
"(",
"description",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"description",
")",
"def",
"network_port",
"(",
"string",
")",
":",
"value",
"=",
"int",
"(",
"string",
")",
"if",
"not",
... | Create a command-line arguments parser for OSPD. | [
"Create",
"a",
"command",
"-",
"line",
"arguments",
"parser",
"for",
"OSPD",
"."
] | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L772-L846 | train |
greenbone/ospd | ospd/misc.py | go_to_background | def go_to_background():
""" Daemonize the running process. """
try:
if os.fork():
sys.exit()
except OSError as errmsg:
LOGGER.error('Fork failed: {0}'.format(errmsg))
sys.exit('Fork failed') | python | def go_to_background():
""" Daemonize the running process. """
try:
if os.fork():
sys.exit()
except OSError as errmsg:
LOGGER.error('Fork failed: {0}'.format(errmsg))
sys.exit('Fork failed') | [
"def",
"go_to_background",
"(",
")",
":",
"try",
":",
"if",
"os",
".",
"fork",
"(",
")",
":",
"sys",
".",
"exit",
"(",
")",
"except",
"OSError",
"as",
"errmsg",
":",
"LOGGER",
".",
"error",
"(",
"'Fork failed: {0}'",
".",
"format",
"(",
"errmsg",
")"... | Daemonize the running process. | [
"Daemonize",
"the",
"running",
"process",
"."
] | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L849-L856 | train |
greenbone/ospd | ospd/misc.py | get_common_args | def get_common_args(parser, args=None):
""" Return list of OSPD common command-line arguments from parser, after
validating provided values or setting default ones.
"""
options = parser.parse_args(args)
# TCP Port to listen on.
port = options.port
# Network address to bind listener to
... | python | def get_common_args(parser, args=None):
""" Return list of OSPD common command-line arguments from parser, after
validating provided values or setting default ones.
"""
options = parser.parse_args(args)
# TCP Port to listen on.
port = options.port
# Network address to bind listener to
... | [
"def",
"get_common_args",
"(",
"parser",
",",
"args",
"=",
"None",
")",
":",
"options",
"=",
"parser",
".",
"parse_args",
"(",
"args",
")",
"port",
"=",
"options",
".",
"port",
"address",
"=",
"options",
".",
"bind_address",
"unix_socket",
"=",
"options",
... | Return list of OSPD common command-line arguments from parser, after
validating provided values or setting default ones. | [
"Return",
"list",
"of",
"OSPD",
"common",
"command",
"-",
"line",
"arguments",
"from",
"parser",
"after",
"validating",
"provided",
"values",
"or",
"setting",
"default",
"ones",
"."
] | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L859-L899 | train |
greenbone/ospd | ospd/misc.py | print_version | def print_version(wrapper):
""" Prints the server version and license information."""
scanner_name = wrapper.get_scanner_name()
server_version = wrapper.get_server_version()
print("OSP Server for {0} version {1}".format(scanner_name, server_version))
protocol_version = wrapper.get_protocol_version(... | python | def print_version(wrapper):
""" Prints the server version and license information."""
scanner_name = wrapper.get_scanner_name()
server_version = wrapper.get_server_version()
print("OSP Server for {0} version {1}".format(scanner_name, server_version))
protocol_version = wrapper.get_protocol_version(... | [
"def",
"print_version",
"(",
"wrapper",
")",
":",
"scanner_name",
"=",
"wrapper",
".",
"get_scanner_name",
"(",
")",
"server_version",
"=",
"wrapper",
".",
"get_server_version",
"(",
")",
"print",
"(",
"\"OSP Server for {0} version {1}\"",
".",
"format",
"(",
"sca... | Prints the server version and license information. | [
"Prints",
"the",
"server",
"version",
"and",
"license",
"information",
"."
] | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L902-L917 | train |
greenbone/ospd | ospd/misc.py | main | def main(name, klass):
""" OSPD Main function. """
# Common args parser.
parser = create_args_parser(name)
# Common args
cargs = get_common_args(parser)
logging.getLogger().setLevel(cargs['log_level'])
wrapper = klass(certfile=cargs['certfile'], keyfile=cargs['keyfile'],
... | python | def main(name, klass):
""" OSPD Main function. """
# Common args parser.
parser = create_args_parser(name)
# Common args
cargs = get_common_args(parser)
logging.getLogger().setLevel(cargs['log_level'])
wrapper = klass(certfile=cargs['certfile'], keyfile=cargs['keyfile'],
... | [
"def",
"main",
"(",
"name",
",",
"klass",
")",
":",
"parser",
"=",
"create_args_parser",
"(",
"name",
")",
"cargs",
"=",
"get_common_args",
"(",
"parser",
")",
"logging",
".",
"getLogger",
"(",
")",
".",
"setLevel",
"(",
"cargs",
"[",
"'log_level'",
"]",... | OSPD Main function. | [
"OSPD",
"Main",
"function",
"."
] | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L920-L962 | train |
greenbone/ospd | ospd/misc.py | ScanCollection.add_result | def add_result(self, scan_id, result_type, host='', name='', value='',
port='', test_id='', severity='', qod=''):
""" Add a result to a scan in the table. """
assert scan_id
assert len(name) or len(value)
result = dict()
result['type'] = result_type
re... | python | def add_result(self, scan_id, result_type, host='', name='', value='',
port='', test_id='', severity='', qod=''):
""" Add a result to a scan in the table. """
assert scan_id
assert len(name) or len(value)
result = dict()
result['type'] = result_type
re... | [
"def",
"add_result",
"(",
"self",
",",
"scan_id",
",",
"result_type",
",",
"host",
"=",
"''",
",",
"name",
"=",
"''",
",",
"value",
"=",
"''",
",",
"port",
"=",
"''",
",",
"test_id",
"=",
"''",
",",
"severity",
"=",
"''",
",",
"qod",
"=",
"''",
... | Add a result to a scan in the table. | [
"Add",
"a",
"result",
"to",
"a",
"scan",
"in",
"the",
"table",
"."
] | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L87-L105 | train |
greenbone/ospd | ospd/misc.py | ScanCollection.get_hosts_unfinished | def get_hosts_unfinished(self, scan_id):
""" Get a list of finished hosts."""
unfinished_hosts = list()
for target in self.scans_table[scan_id]['finished_hosts']:
unfinished_hosts.extend(target_str_to_list(target))
for target in self.scans_table[scan_id]['finished_hosts']:
... | python | def get_hosts_unfinished(self, scan_id):
""" Get a list of finished hosts."""
unfinished_hosts = list()
for target in self.scans_table[scan_id]['finished_hosts']:
unfinished_hosts.extend(target_str_to_list(target))
for target in self.scans_table[scan_id]['finished_hosts']:
... | [
"def",
"get_hosts_unfinished",
"(",
"self",
",",
"scan_id",
")",
":",
"unfinished_hosts",
"=",
"list",
"(",
")",
"for",
"target",
"in",
"self",
".",
"scans_table",
"[",
"scan_id",
"]",
"[",
"'finished_hosts'",
"]",
":",
"unfinished_hosts",
".",
"extend",
"("... | Get a list of finished hosts. | [
"Get",
"a",
"list",
"of",
"finished",
"hosts",
"."
] | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L130-L140 | train |
greenbone/ospd | ospd/misc.py | ScanCollection.results_iterator | def results_iterator(self, scan_id, pop_res):
""" Returns an iterator over scan_id scan's results. If pop_res is True,
it removed the fetched results from the list.
"""
if pop_res:
result_aux = self.scans_table[scan_id]['results']
self.scans_table[scan_id]['result... | python | def results_iterator(self, scan_id, pop_res):
""" Returns an iterator over scan_id scan's results. If pop_res is True,
it removed the fetched results from the list.
"""
if pop_res:
result_aux = self.scans_table[scan_id]['results']
self.scans_table[scan_id]['result... | [
"def",
"results_iterator",
"(",
"self",
",",
"scan_id",
",",
"pop_res",
")",
":",
"if",
"pop_res",
":",
"result_aux",
"=",
"self",
".",
"scans_table",
"[",
"scan_id",
"]",
"[",
"'results'",
"]",
"self",
".",
"scans_table",
"[",
"scan_id",
"]",
"[",
"'res... | Returns an iterator over scan_id scan's results. If pop_res is True,
it removed the fetched results from the list. | [
"Returns",
"an",
"iterator",
"over",
"scan_id",
"scan",
"s",
"results",
".",
"If",
"pop_res",
"is",
"True",
"it",
"removed",
"the",
"fetched",
"results",
"from",
"the",
"list",
"."
] | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L142-L151 | train |
greenbone/ospd | ospd/misc.py | ScanCollection.del_results_for_stopped_hosts | def del_results_for_stopped_hosts(self, scan_id):
""" Remove results from the result table for those host
"""
unfinished_hosts = self.get_hosts_unfinished(scan_id)
for result in self.results_iterator(scan_id, False):
if result['host'] in unfinished_hosts:
self... | python | def del_results_for_stopped_hosts(self, scan_id):
""" Remove results from the result table for those host
"""
unfinished_hosts = self.get_hosts_unfinished(scan_id)
for result in self.results_iterator(scan_id, False):
if result['host'] in unfinished_hosts:
self... | [
"def",
"del_results_for_stopped_hosts",
"(",
"self",
",",
"scan_id",
")",
":",
"unfinished_hosts",
"=",
"self",
".",
"get_hosts_unfinished",
"(",
"scan_id",
")",
"for",
"result",
"in",
"self",
".",
"results_iterator",
"(",
"scan_id",
",",
"False",
")",
":",
"i... | Remove results from the result table for those host | [
"Remove",
"results",
"from",
"the",
"result",
"table",
"for",
"those",
"host"
] | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L162-L168 | train |
greenbone/ospd | ospd/misc.py | ScanCollection.create_scan | def create_scan(self, scan_id='', targets='', options=None, vts=''):
""" Creates a new scan with provided scan information. """
if self.data_manager is None:
self.data_manager = multiprocessing.Manager()
# Check if it is possible to resume task. To avoid to resume, the
# sc... | python | def create_scan(self, scan_id='', targets='', options=None, vts=''):
""" Creates a new scan with provided scan information. """
if self.data_manager is None:
self.data_manager = multiprocessing.Manager()
# Check if it is possible to resume task. To avoid to resume, the
# sc... | [
"def",
"create_scan",
"(",
"self",
",",
"scan_id",
"=",
"''",
",",
"targets",
"=",
"''",
",",
"options",
"=",
"None",
",",
"vts",
"=",
"''",
")",
":",
"if",
"self",
".",
"data_manager",
"is",
"None",
":",
"self",
".",
"data_manager",
"=",
"multiproce... | Creates a new scan with provided scan information. | [
"Creates",
"a",
"new",
"scan",
"with",
"provided",
"scan",
"information",
"."
] | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L191-L222 | train |
greenbone/ospd | ospd/misc.py | ScanCollection.set_option | def set_option(self, scan_id, name, value):
""" Set a scan_id scan's name option to value. """
self.scans_table[scan_id]['options'][name] = value | python | def set_option(self, scan_id, name, value):
""" Set a scan_id scan's name option to value. """
self.scans_table[scan_id]['options'][name] = value | [
"def",
"set_option",
"(",
"self",
",",
"scan_id",
",",
"name",
",",
"value",
")",
":",
"self",
".",
"scans_table",
"[",
"scan_id",
"]",
"[",
"'options'",
"]",
"[",
"name",
"]",
"=",
"value"
] | Set a scan_id scan's name option to value. | [
"Set",
"a",
"scan_id",
"scan",
"s",
"name",
"option",
"to",
"value",
"."
] | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L238-L241 | train |
greenbone/ospd | ospd/misc.py | ScanCollection.get_target_progress | def get_target_progress(self, scan_id, target):
""" Get a target's current progress value.
The value is calculated with the progress of each single host
in the target."""
total_hosts = len(target_str_to_list(target))
host_progresses = self.scans_table[scan_id]['target_progress']... | python | def get_target_progress(self, scan_id, target):
""" Get a target's current progress value.
The value is calculated with the progress of each single host
in the target."""
total_hosts = len(target_str_to_list(target))
host_progresses = self.scans_table[scan_id]['target_progress']... | [
"def",
"get_target_progress",
"(",
"self",
",",
"scan_id",
",",
"target",
")",
":",
"total_hosts",
"=",
"len",
"(",
"target_str_to_list",
"(",
"target",
")",
")",
"host_progresses",
"=",
"self",
".",
"scans_table",
"[",
"scan_id",
"]",
"[",
"'target_progress'"... | Get a target's current progress value.
The value is calculated with the progress of each single host
in the target. | [
"Get",
"a",
"target",
"s",
"current",
"progress",
"value",
".",
"The",
"value",
"is",
"calculated",
"with",
"the",
"progress",
"of",
"each",
"single",
"host",
"in",
"the",
"target",
"."
] | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L248-L260 | train |
greenbone/ospd | ospd/misc.py | ScanCollection.get_target_list | def get_target_list(self, scan_id):
""" Get a scan's target list. """
target_list = []
for target, _, _ in self.scans_table[scan_id]['targets']:
target_list.append(target)
return target_list | python | def get_target_list(self, scan_id):
""" Get a scan's target list. """
target_list = []
for target, _, _ in self.scans_table[scan_id]['targets']:
target_list.append(target)
return target_list | [
"def",
"get_target_list",
"(",
"self",
",",
"scan_id",
")",
":",
"target_list",
"=",
"[",
"]",
"for",
"target",
",",
"_",
",",
"_",
"in",
"self",
".",
"scans_table",
"[",
"scan_id",
"]",
"[",
"'targets'",
"]",
":",
"target_list",
".",
"append",
"(",
... | Get a scan's target list. | [
"Get",
"a",
"scan",
"s",
"target",
"list",
"."
] | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L272-L278 | train |
greenbone/ospd | ospd/misc.py | ScanCollection.get_ports | def get_ports(self, scan_id, target):
""" Get a scan's ports list. If a target is specified
it will return the corresponding port for it. If not,
it returns the port item of the first nested list in
the target's list.
"""
if target:
for item in self.scans_tabl... | python | def get_ports(self, scan_id, target):
""" Get a scan's ports list. If a target is specified
it will return the corresponding port for it. If not,
it returns the port item of the first nested list in
the target's list.
"""
if target:
for item in self.scans_tabl... | [
"def",
"get_ports",
"(",
"self",
",",
"scan_id",
",",
"target",
")",
":",
"if",
"target",
":",
"for",
"item",
"in",
"self",
".",
"scans_table",
"[",
"scan_id",
"]",
"[",
"'targets'",
"]",
":",
"if",
"target",
"==",
"item",
"[",
"0",
"]",
":",
"retu... | Get a scan's ports list. If a target is specified
it will return the corresponding port for it. If not,
it returns the port item of the first nested list in
the target's list. | [
"Get",
"a",
"scan",
"s",
"ports",
"list",
".",
"If",
"a",
"target",
"is",
"specified",
"it",
"will",
"return",
"the",
"corresponding",
"port",
"for",
"it",
".",
"If",
"not",
"it",
"returns",
"the",
"port",
"item",
"of",
"the",
"first",
"nested",
"list"... | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L280-L291 | train |
greenbone/ospd | ospd/misc.py | ScanCollection.get_credentials | def get_credentials(self, scan_id, target):
""" Get a scan's credential list. It return dictionary with
the corresponding credential for a given target.
"""
if target:
for item in self.scans_table[scan_id]['targets']:
if target == item[0]:
... | python | def get_credentials(self, scan_id, target):
""" Get a scan's credential list. It return dictionary with
the corresponding credential for a given target.
"""
if target:
for item in self.scans_table[scan_id]['targets']:
if target == item[0]:
... | [
"def",
"get_credentials",
"(",
"self",
",",
"scan_id",
",",
"target",
")",
":",
"if",
"target",
":",
"for",
"item",
"in",
"self",
".",
"scans_table",
"[",
"scan_id",
"]",
"[",
"'targets'",
"]",
":",
"if",
"target",
"==",
"item",
"[",
"0",
"]",
":",
... | Get a scan's credential list. It return dictionary with
the corresponding credential for a given target. | [
"Get",
"a",
"scan",
"s",
"credential",
"list",
".",
"It",
"return",
"dictionary",
"with",
"the",
"corresponding",
"credential",
"for",
"a",
"given",
"target",
"."
] | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L293-L300 | train |
greenbone/ospd | ospd/misc.py | ScanCollection.delete_scan | def delete_scan(self, scan_id):
""" Delete a scan if fully finished. """
if self.get_status(scan_id) == ScanStatus.RUNNING:
return False
self.scans_table.pop(scan_id)
if len(self.scans_table) == 0:
del self.data_manager
self.data_manager = None
... | python | def delete_scan(self, scan_id):
""" Delete a scan if fully finished. """
if self.get_status(scan_id) == ScanStatus.RUNNING:
return False
self.scans_table.pop(scan_id)
if len(self.scans_table) == 0:
del self.data_manager
self.data_manager = None
... | [
"def",
"delete_scan",
"(",
"self",
",",
"scan_id",
")",
":",
"if",
"self",
".",
"get_status",
"(",
"scan_id",
")",
"==",
"ScanStatus",
".",
"RUNNING",
":",
"return",
"False",
"self",
".",
"scans_table",
".",
"pop",
"(",
"scan_id",
")",
"if",
"len",
"("... | Delete a scan if fully finished. | [
"Delete",
"a",
"scan",
"if",
"fully",
"finished",
"."
] | cef773166b15a19c17764721d3fe404fa0e107bf | https://github.com/greenbone/ospd/blob/cef773166b15a19c17764721d3fe404fa0e107bf/ospd/misc.py#L312-L321 | train |
Grokzen/pykwalify | pykwalify/types.py | is_timestamp | def is_timestamp(obj):
"""
Yaml either have automatically converted it to a datetime object
or it is a string that will be validated later.
"""
return isinstance(obj, datetime.datetime) or is_string(obj) or is_int(obj) or is_float(obj) | python | def is_timestamp(obj):
"""
Yaml either have automatically converted it to a datetime object
or it is a string that will be validated later.
"""
return isinstance(obj, datetime.datetime) or is_string(obj) or is_int(obj) or is_float(obj) | [
"def",
"is_timestamp",
"(",
"obj",
")",
":",
"return",
"isinstance",
"(",
"obj",
",",
"datetime",
".",
"datetime",
")",
"or",
"is_string",
"(",
"obj",
")",
"or",
"is_int",
"(",
"obj",
")",
"or",
"is_float",
"(",
"obj",
")"
] | Yaml either have automatically converted it to a datetime object
or it is a string that will be validated later. | [
"Yaml",
"either",
"have",
"automatically",
"converted",
"it",
"to",
"a",
"datetime",
"object",
"or",
"it",
"is",
"a",
"string",
"that",
"will",
"be",
"validated",
"later",
"."
] | 02b7e21eafb97926f17b7c33e2ee7b3ea67c3ef7 | https://github.com/Grokzen/pykwalify/blob/02b7e21eafb97926f17b7c33e2ee7b3ea67c3ef7/pykwalify/types.py#L131-L136 | train |
Grokzen/pykwalify | pykwalify/__init__.py | init_logging | def init_logging(log_level):
"""
Init logging settings with default set to INFO
"""
log_level = log_level_to_string_map[min(log_level, 5)]
msg = "%(levelname)s - %(name)s:%(lineno)s - %(message)s" if log_level in os.environ else "%(levelname)s - %(message)s"
logging_conf = {
"version":... | python | def init_logging(log_level):
"""
Init logging settings with default set to INFO
"""
log_level = log_level_to_string_map[min(log_level, 5)]
msg = "%(levelname)s - %(name)s:%(lineno)s - %(message)s" if log_level in os.environ else "%(levelname)s - %(message)s"
logging_conf = {
"version":... | [
"def",
"init_logging",
"(",
"log_level",
")",
":",
"log_level",
"=",
"log_level_to_string_map",
"[",
"min",
"(",
"log_level",
",",
"5",
")",
"]",
"msg",
"=",
"\"%(levelname)s - %(name)s:%(lineno)s - %(message)s\"",
"if",
"log_level",
"in",
"os",
".",
"environ",
"e... | Init logging settings with default set to INFO | [
"Init",
"logging",
"settings",
"with",
"default",
"set",
"to",
"INFO"
] | 02b7e21eafb97926f17b7c33e2ee7b3ea67c3ef7 | https://github.com/Grokzen/pykwalify/blob/02b7e21eafb97926f17b7c33e2ee7b3ea67c3ef7/pykwalify/__init__.py#L25-L54 | train |
Grokzen/pykwalify | pykwalify/rule.py | Rule.keywords | def keywords(self):
"""
Returns a list of all keywords that this rule object has defined.
A keyword is considered defined if the value it returns != None.
"""
defined_keywords = [
('allowempty_map', 'allowempty_map'),
('assertion', 'assertion'),
... | python | def keywords(self):
"""
Returns a list of all keywords that this rule object has defined.
A keyword is considered defined if the value it returns != None.
"""
defined_keywords = [
('allowempty_map', 'allowempty_map'),
('assertion', 'assertion'),
... | [
"def",
"keywords",
"(",
"self",
")",
":",
"defined_keywords",
"=",
"[",
"(",
"'allowempty_map'",
",",
"'allowempty_map'",
")",
",",
"(",
"'assertion'",
",",
"'assertion'",
")",
",",
"(",
"'default'",
",",
"'default'",
")",
",",
"(",
"'class'",
",",
"'class... | Returns a list of all keywords that this rule object has defined.
A keyword is considered defined if the value it returns != None. | [
"Returns",
"a",
"list",
"of",
"all",
"keywords",
"that",
"this",
"rule",
"object",
"has",
"defined",
".",
"A",
"keyword",
"is",
"considered",
"defined",
"if",
"the",
"value",
"it",
"returns",
"!",
"=",
"None",
"."
] | 02b7e21eafb97926f17b7c33e2ee7b3ea67c3ef7 | https://github.com/Grokzen/pykwalify/blob/02b7e21eafb97926f17b7c33e2ee7b3ea67c3ef7/pykwalify/rule.py#L319-L364 | train |
Grokzen/pykwalify | pykwalify/core.py | Core._load_extensions | def _load_extensions(self):
"""
Load all extension files into the namespace pykwalify.ext
"""
log.debug(u"loading all extensions : %s", self.extensions)
self.loaded_extensions = []
for f in self.extensions:
if not os.path.isabs(f):
f = os.pat... | python | def _load_extensions(self):
"""
Load all extension files into the namespace pykwalify.ext
"""
log.debug(u"loading all extensions : %s", self.extensions)
self.loaded_extensions = []
for f in self.extensions:
if not os.path.isabs(f):
f = os.pat... | [
"def",
"_load_extensions",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"u\"loading all extensions : %s\"",
",",
"self",
".",
"extensions",
")",
"self",
".",
"loaded_extensions",
"=",
"[",
"]",
"for",
"f",
"in",
"self",
".",
"extensions",
":",
"if",
"n... | Load all extension files into the namespace pykwalify.ext | [
"Load",
"all",
"extension",
"files",
"into",
"the",
"namespace",
"pykwalify",
".",
"ext"
] | 02b7e21eafb97926f17b7c33e2ee7b3ea67c3ef7 | https://github.com/Grokzen/pykwalify/blob/02b7e21eafb97926f17b7c33e2ee7b3ea67c3ef7/pykwalify/core.py#L131-L149 | train |
Grokzen/pykwalify | pykwalify/core.py | Core._handle_func | def _handle_func(self, value, rule, path, done=None):
"""
Helper function that should check if func is specified for this rule and
then handle it for all cases in a generic way.
"""
func = rule.func
# func keyword is not defined so nothing to do
if not func:
... | python | def _handle_func(self, value, rule, path, done=None):
"""
Helper function that should check if func is specified for this rule and
then handle it for all cases in a generic way.
"""
func = rule.func
# func keyword is not defined so nothing to do
if not func:
... | [
"def",
"_handle_func",
"(",
"self",
",",
"value",
",",
"rule",
",",
"path",
",",
"done",
"=",
"None",
")",
":",
"func",
"=",
"rule",
".",
"func",
"if",
"not",
"func",
":",
"return",
"found_method",
"=",
"False",
"for",
"extension",
"in",
"self",
".",... | Helper function that should check if func is specified for this rule and
then handle it for all cases in a generic way. | [
"Helper",
"function",
"that",
"should",
"check",
"if",
"func",
"is",
"specified",
"for",
"this",
"rule",
"and",
"then",
"handle",
"it",
"for",
"all",
"cases",
"in",
"a",
"generic",
"way",
"."
] | 02b7e21eafb97926f17b7c33e2ee7b3ea67c3ef7 | https://github.com/Grokzen/pykwalify/blob/02b7e21eafb97926f17b7c33e2ee7b3ea67c3ef7/pykwalify/core.py#L241-L277 | train |
Grokzen/pykwalify | pykwalify/core.py | Core._validate_range | def _validate_range(self, max_, min_, max_ex, min_ex, value, path, prefix):
"""
Validate that value is within range values.
"""
if not isinstance(value, int) and not isinstance(value, float):
raise CoreError("Value must be a integer type")
log.debug(
u"Va... | python | def _validate_range(self, max_, min_, max_ex, min_ex, value, path, prefix):
"""
Validate that value is within range values.
"""
if not isinstance(value, int) and not isinstance(value, float):
raise CoreError("Value must be a integer type")
log.debug(
u"Va... | [
"def",
"_validate_range",
"(",
"self",
",",
"max_",
",",
"min_",
",",
"max_ex",
",",
"min_ex",
",",
"value",
",",
"path",
",",
"prefix",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"int",
")",
"and",
"not",
"isinstance",
"(",
"value",
","... | Validate that value is within range values. | [
"Validate",
"that",
"value",
"is",
"within",
"range",
"values",
"."
] | 02b7e21eafb97926f17b7c33e2ee7b3ea67c3ef7 | https://github.com/Grokzen/pykwalify/blob/02b7e21eafb97926f17b7c33e2ee7b3ea67c3ef7/pykwalify/core.py#L919-L966 | train |
Grokzen/pykwalify | pykwalify/cli.py | run | def run(cli_args):
"""
Split the functionality into 2 methods.
One for parsing the cli and one that runs the application.
"""
from .core import Core
c = Core(
source_file=cli_args["--data-file"],
schema_files=cli_args["--schema-file"],
extensions=cli_args['--extension']... | python | def run(cli_args):
"""
Split the functionality into 2 methods.
One for parsing the cli and one that runs the application.
"""
from .core import Core
c = Core(
source_file=cli_args["--data-file"],
schema_files=cli_args["--schema-file"],
extensions=cli_args['--extension']... | [
"def",
"run",
"(",
"cli_args",
")",
":",
"from",
".",
"core",
"import",
"Core",
"c",
"=",
"Core",
"(",
"source_file",
"=",
"cli_args",
"[",
"\"--data-file\"",
"]",
",",
"schema_files",
"=",
"cli_args",
"[",
"\"--schema-file\"",
"]",
",",
"extensions",
"=",... | Split the functionality into 2 methods.
One for parsing the cli and one that runs the application. | [
"Split",
"the",
"functionality",
"into",
"2",
"methods",
"."
] | 02b7e21eafb97926f17b7c33e2ee7b3ea67c3ef7 | https://github.com/Grokzen/pykwalify/blob/02b7e21eafb97926f17b7c33e2ee7b3ea67c3ef7/pykwalify/cli.py#L68-L86 | train |
daler/gffutils | gffutils/pybedtools_integration.py | to_bedtool | def to_bedtool(iterator):
"""
Convert any iterator into a pybedtools.BedTool object.
Note that the supplied iterator is not consumed by this function. To save
to a temp file or to a known location, use the `.saveas()` method of the
returned BedTool object.
"""
def gen():
for i in it... | python | def to_bedtool(iterator):
"""
Convert any iterator into a pybedtools.BedTool object.
Note that the supplied iterator is not consumed by this function. To save
to a temp file or to a known location, use the `.saveas()` method of the
returned BedTool object.
"""
def gen():
for i in it... | [
"def",
"to_bedtool",
"(",
"iterator",
")",
":",
"def",
"gen",
"(",
")",
":",
"for",
"i",
"in",
"iterator",
":",
"yield",
"helpers",
".",
"asinterval",
"(",
"i",
")",
"return",
"pybedtools",
".",
"BedTool",
"(",
"gen",
"(",
")",
")"
] | Convert any iterator into a pybedtools.BedTool object.
Note that the supplied iterator is not consumed by this function. To save
to a temp file or to a known location, use the `.saveas()` method of the
returned BedTool object. | [
"Convert",
"any",
"iterator",
"into",
"a",
"pybedtools",
".",
"BedTool",
"object",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/pybedtools_integration.py#L12-L23 | train |
daler/gffutils | gffutils/pybedtools_integration.py | tsses | def tsses(db, merge_overlapping=False, attrs=None, attrs_sep=":",
merge_kwargs=None, as_bed6=False, bedtools_227_or_later=True):
"""
Create 1-bp transcription start sites for all transcripts in the database
and return as a sorted pybedtools.BedTool object pointing to a temporary
file.
To ... | python | def tsses(db, merge_overlapping=False, attrs=None, attrs_sep=":",
merge_kwargs=None, as_bed6=False, bedtools_227_or_later=True):
"""
Create 1-bp transcription start sites for all transcripts in the database
and return as a sorted pybedtools.BedTool object pointing to a temporary
file.
To ... | [
"def",
"tsses",
"(",
"db",
",",
"merge_overlapping",
"=",
"False",
",",
"attrs",
"=",
"None",
",",
"attrs_sep",
"=",
"\":\"",
",",
"merge_kwargs",
"=",
"None",
",",
"as_bed6",
"=",
"False",
",",
"bedtools_227_or_later",
"=",
"True",
")",
":",
"_override",
... | Create 1-bp transcription start sites for all transcripts in the database
and return as a sorted pybedtools.BedTool object pointing to a temporary
file.
To save the file to a known location, use the `.moveto()` method on the
resulting `pybedtools.BedTool` object.
To extend regions upstream/downstr... | [
"Create",
"1",
"-",
"bp",
"transcription",
"start",
"sites",
"for",
"all",
"transcripts",
"in",
"the",
"database",
"and",
"return",
"as",
"a",
"sorted",
"pybedtools",
".",
"BedTool",
"object",
"pointing",
"to",
"a",
"temporary",
"file",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/pybedtools_integration.py#L26-L237 | train |
daler/gffutils | gffutils/gffwriter.py | GFFWriter.close | def close(self):
"""
Close the stream. Assumes stream has 'close' method.
"""
self.out_stream.close()
# If we're asked to write in place, substitute the named
# temporary file for the current file
if self.in_place:
shutil.move(self.temp_file.name, self... | python | def close(self):
"""
Close the stream. Assumes stream has 'close' method.
"""
self.out_stream.close()
# If we're asked to write in place, substitute the named
# temporary file for the current file
if self.in_place:
shutil.move(self.temp_file.name, self... | [
"def",
"close",
"(",
"self",
")",
":",
"self",
".",
"out_stream",
".",
"close",
"(",
")",
"if",
"self",
".",
"in_place",
":",
"shutil",
".",
"move",
"(",
"self",
".",
"temp_file",
".",
"name",
",",
"self",
".",
"out",
")"
] | Close the stream. Assumes stream has 'close' method. | [
"Close",
"the",
"stream",
".",
"Assumes",
"stream",
"has",
"close",
"method",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/gffwriter.py#L162-L170 | train |
daler/gffutils | gffutils/biopython_integration.py | to_seqfeature | def to_seqfeature(feature):
"""
Converts a gffutils.Feature object to a Bio.SeqFeature object.
The GFF fields `source`, `score`, `seqid`, and `frame` are stored as
qualifiers. GFF `attributes` are also stored as qualifiers.
Parameters
----------
feature : Feature object, or string
... | python | def to_seqfeature(feature):
"""
Converts a gffutils.Feature object to a Bio.SeqFeature object.
The GFF fields `source`, `score`, `seqid`, and `frame` are stored as
qualifiers. GFF `attributes` are also stored as qualifiers.
Parameters
----------
feature : Feature object, or string
... | [
"def",
"to_seqfeature",
"(",
"feature",
")",
":",
"if",
"isinstance",
"(",
"feature",
",",
"six",
".",
"string_types",
")",
":",
"feature",
"=",
"feature_from_line",
"(",
"feature",
")",
"qualifiers",
"=",
"{",
"'source'",
":",
"[",
"feature",
".",
"source... | Converts a gffutils.Feature object to a Bio.SeqFeature object.
The GFF fields `source`, `score`, `seqid`, and `frame` are stored as
qualifiers. GFF `attributes` are also stored as qualifiers.
Parameters
----------
feature : Feature object, or string
If string, assume it is a GFF or GTF-fo... | [
"Converts",
"a",
"gffutils",
".",
"Feature",
"object",
"to",
"a",
"Bio",
".",
"SeqFeature",
"object",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/biopython_integration.py#L21-L52 | train |
daler/gffutils | gffutils/biopython_integration.py | from_seqfeature | def from_seqfeature(s, **kwargs):
"""
Converts a Bio.SeqFeature object to a gffutils.Feature object.
The GFF fields `source`, `score`, `seqid`, and `frame` are assumed to be
stored as qualifiers. Any other qualifiers will be assumed to be GFF
attributes.
"""
source = s.qualifiers.get('sour... | python | def from_seqfeature(s, **kwargs):
"""
Converts a Bio.SeqFeature object to a gffutils.Feature object.
The GFF fields `source`, `score`, `seqid`, and `frame` are assumed to be
stored as qualifiers. Any other qualifiers will be assumed to be GFF
attributes.
"""
source = s.qualifiers.get('sour... | [
"def",
"from_seqfeature",
"(",
"s",
",",
"**",
"kwargs",
")",
":",
"source",
"=",
"s",
".",
"qualifiers",
".",
"get",
"(",
"'source'",
",",
"'.'",
")",
"[",
"0",
"]",
"score",
"=",
"s",
".",
"qualifiers",
".",
"get",
"(",
"'score'",
",",
"'.'",
"... | Converts a Bio.SeqFeature object to a gffutils.Feature object.
The GFF fields `source`, `score`, `seqid`, and `frame` are assumed to be
stored as qualifiers. Any other qualifiers will be assumed to be GFF
attributes. | [
"Converts",
"a",
"Bio",
".",
"SeqFeature",
"object",
"to",
"a",
"gffutils",
".",
"Feature",
"object",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/biopython_integration.py#L55-L81 | train |
daler/gffutils | gffutils/interface.py | FeatureDB.set_pragmas | def set_pragmas(self, pragmas):
"""
Set pragmas for the current database connection.
Parameters
----------
pragmas : dict
Dictionary of pragmas; see constants.default_pragmas for a template
and http://www.sqlite.org/pragma.html for a full list.
""... | python | def set_pragmas(self, pragmas):
"""
Set pragmas for the current database connection.
Parameters
----------
pragmas : dict
Dictionary of pragmas; see constants.default_pragmas for a template
and http://www.sqlite.org/pragma.html for a full list.
""... | [
"def",
"set_pragmas",
"(",
"self",
",",
"pragmas",
")",
":",
"self",
".",
"pragmas",
"=",
"pragmas",
"c",
"=",
"self",
".",
"conn",
".",
"cursor",
"(",
")",
"c",
".",
"executescript",
"(",
"';\\n'",
".",
"join",
"(",
"[",
"'PRAGMA %s=%s'",
"%",
"i",
... | Set pragmas for the current database connection.
Parameters
----------
pragmas : dict
Dictionary of pragmas; see constants.default_pragmas for a template
and http://www.sqlite.org/pragma.html for a full list. | [
"Set",
"pragmas",
"for",
"the",
"current",
"database",
"connection",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/interface.py#L163-L180 | train |
daler/gffutils | gffutils/interface.py | FeatureDB._feature_returner | def _feature_returner(self, **kwargs):
"""
Returns a feature, adding additional database-specific defaults
"""
kwargs.setdefault('dialect', self.dialect)
kwargs.setdefault('keep_order', self.keep_order)
kwargs.setdefault('sort_attribute_values', self.sort_attribute_values... | python | def _feature_returner(self, **kwargs):
"""
Returns a feature, adding additional database-specific defaults
"""
kwargs.setdefault('dialect', self.dialect)
kwargs.setdefault('keep_order', self.keep_order)
kwargs.setdefault('sort_attribute_values', self.sort_attribute_values... | [
"def",
"_feature_returner",
"(",
"self",
",",
"**",
"kwargs",
")",
":",
"kwargs",
".",
"setdefault",
"(",
"'dialect'",
",",
"self",
".",
"dialect",
")",
"kwargs",
".",
"setdefault",
"(",
"'keep_order'",
",",
"self",
".",
"keep_order",
")",
"kwargs",
".",
... | Returns a feature, adding additional database-specific defaults | [
"Returns",
"a",
"feature",
"adding",
"additional",
"database",
"-",
"specific",
"defaults"
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/interface.py#L182-L189 | train |
daler/gffutils | gffutils/interface.py | FeatureDB.schema | def schema(self):
"""
Returns the database schema as a string.
"""
c = self.conn.cursor()
c.execute(
'''
SELECT sql FROM sqlite_master
''')
results = []
for i, in c:
if i is not None:
results.append(i... | python | def schema(self):
"""
Returns the database schema as a string.
"""
c = self.conn.cursor()
c.execute(
'''
SELECT sql FROM sqlite_master
''')
results = []
for i, in c:
if i is not None:
results.append(i... | [
"def",
"schema",
"(",
"self",
")",
":",
"c",
"=",
"self",
".",
"conn",
".",
"cursor",
"(",
")",
"c",
".",
"execute",
"(",
")",
"results",
"=",
"[",
"]",
"for",
"i",
",",
"in",
"c",
":",
"if",
"i",
"is",
"not",
"None",
":",
"results",
".",
"... | Returns the database schema as a string. | [
"Returns",
"the",
"database",
"schema",
"as",
"a",
"string",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/interface.py#L199-L212 | train |
daler/gffutils | gffutils/interface.py | FeatureDB.featuretypes | def featuretypes(self):
"""
Iterate over feature types found in the database.
Returns
-------
A generator object that yields featuretypes (as strings)
"""
c = self.conn.cursor()
c.execute(
'''
SELECT DISTINCT featuretype from featu... | python | def featuretypes(self):
"""
Iterate over feature types found in the database.
Returns
-------
A generator object that yields featuretypes (as strings)
"""
c = self.conn.cursor()
c.execute(
'''
SELECT DISTINCT featuretype from featu... | [
"def",
"featuretypes",
"(",
"self",
")",
":",
"c",
"=",
"self",
".",
"conn",
".",
"cursor",
"(",
")",
"c",
".",
"execute",
"(",
")",
"for",
"i",
",",
"in",
"c",
":",
"yield",
"i"
] | Iterate over feature types found in the database.
Returns
-------
A generator object that yields featuretypes (as strings) | [
"Iterate",
"over",
"feature",
"types",
"found",
"in",
"the",
"database",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/interface.py#L339-L353 | train |
daler/gffutils | gffutils/interface.py | FeatureDB.execute | def execute(self, query):
"""
Execute arbitrary queries on the db.
.. seealso::
:class:`FeatureDB.schema` may be helpful when writing your own
queries.
Parameters
----------
query : str
Query to execute -- trailing ";" opti... | python | def execute(self, query):
"""
Execute arbitrary queries on the db.
.. seealso::
:class:`FeatureDB.schema` may be helpful when writing your own
queries.
Parameters
----------
query : str
Query to execute -- trailing ";" opti... | [
"def",
"execute",
"(",
"self",
",",
"query",
")",
":",
"c",
"=",
"self",
".",
"conn",
".",
"cursor",
"(",
")",
"return",
"c",
".",
"execute",
"(",
"query",
")"
] | Execute arbitrary queries on the db.
.. seealso::
:class:`FeatureDB.schema` may be helpful when writing your own
queries.
Parameters
----------
query : str
Query to execute -- trailing ";" optional.
Returns
-------
... | [
"Execute",
"arbitrary",
"queries",
"on",
"the",
"db",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/interface.py#L440-L461 | train |
daler/gffutils | gffutils/interface.py | FeatureDB.interfeatures | def interfeatures(self, features, new_featuretype=None,
merge_attributes=True, dialect=None,
attribute_func=None, update_attributes=None):
"""
Construct new features representing the space between features.
For example, if `features` is a list of exon... | python | def interfeatures(self, features, new_featuretype=None,
merge_attributes=True, dialect=None,
attribute_func=None, update_attributes=None):
"""
Construct new features representing the space between features.
For example, if `features` is a list of exon... | [
"def",
"interfeatures",
"(",
"self",
",",
"features",
",",
"new_featuretype",
"=",
"None",
",",
"merge_attributes",
"=",
"True",
",",
"dialect",
"=",
"None",
",",
"attribute_func",
"=",
"None",
",",
"update_attributes",
"=",
"None",
")",
":",
"for",
"i",
"... | Construct new features representing the space between features.
For example, if `features` is a list of exons, then this method will
return the introns. If `features` is a list of genes, then this method
will return the intergenic regions.
Providing N features will return N - 1 new fe... | [
"Construct",
"new",
"features",
"representing",
"the",
"space",
"between",
"features",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/interface.py#L650-L766 | train |
daler/gffutils | gffutils/interface.py | FeatureDB.update | def update(self, data, make_backup=True, **kwargs):
"""
Update database with features in `data`.
data : str, iterable, FeatureDB instance
If FeatureDB, all data will be used. If string, assume it's
a filename of a GFF or GTF file. Otherwise, assume it's an
i... | python | def update(self, data, make_backup=True, **kwargs):
"""
Update database with features in `data`.
data : str, iterable, FeatureDB instance
If FeatureDB, all data will be used. If string, assume it's
a filename of a GFF or GTF file. Otherwise, assume it's an
i... | [
"def",
"update",
"(",
"self",
",",
"data",
",",
"make_backup",
"=",
"True",
",",
"**",
"kwargs",
")",
":",
"from",
"gffutils",
"import",
"create",
"from",
"gffutils",
"import",
"iterators",
"if",
"make_backup",
":",
"if",
"isinstance",
"(",
"self",
".",
... | Update database with features in `data`.
data : str, iterable, FeatureDB instance
If FeatureDB, all data will be used. If string, assume it's
a filename of a GFF or GTF file. Otherwise, assume it's an
iterable of Feature objects. The classes in gffutils.iterators may
... | [
"Update",
"database",
"with",
"features",
"in",
"data",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/interface.py#L814-L871 | train |
daler/gffutils | gffutils/interface.py | FeatureDB.create_introns | def create_introns(self, exon_featuretype='exon',
grandparent_featuretype='gene', parent_featuretype=None,
new_featuretype='intron', merge_attributes=True):
"""
Create introns from existing annotations.
Parameters
----------
exon_fe... | python | def create_introns(self, exon_featuretype='exon',
grandparent_featuretype='gene', parent_featuretype=None,
new_featuretype='intron', merge_attributes=True):
"""
Create introns from existing annotations.
Parameters
----------
exon_fe... | [
"def",
"create_introns",
"(",
"self",
",",
"exon_featuretype",
"=",
"'exon'",
",",
"grandparent_featuretype",
"=",
"'gene'",
",",
"parent_featuretype",
"=",
"None",
",",
"new_featuretype",
"=",
"'intron'",
",",
"merge_attributes",
"=",
"True",
")",
":",
"if",
"(... | Create introns from existing annotations.
Parameters
----------
exon_featuretype : string
Feature type to use in order to infer introns. Typically `"exon"`.
grandparent_featuretype : string
If `grandparent_featuretype` is not None, then group exons by
... | [
"Create",
"introns",
"from",
"existing",
"annotations",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/interface.py#L945-L1017 | train |
daler/gffutils | gffutils/interface.py | FeatureDB.merge | def merge(self, features, ignore_strand=False):
"""
Merge overlapping features together.
Parameters
----------
features : iterator of Feature instances
ignore_strand : bool
If True, features on multiple strands will be merged, and the final
stra... | python | def merge(self, features, ignore_strand=False):
"""
Merge overlapping features together.
Parameters
----------
features : iterator of Feature instances
ignore_strand : bool
If True, features on multiple strands will be merged, and the final
stra... | [
"def",
"merge",
"(",
"self",
",",
"features",
",",
"ignore_strand",
"=",
"False",
")",
":",
"features",
"=",
"list",
"(",
"features",
")",
"if",
"len",
"(",
"features",
")",
"==",
"0",
":",
"raise",
"StopIteration",
"if",
"ignore_strand",
":",
"strand",
... | Merge overlapping features together.
Parameters
----------
features : iterator of Feature instances
ignore_strand : bool
If True, features on multiple strands will be merged, and the final
strand will be set to '.'. Otherwise, ValueError will be raised if
... | [
"Merge",
"overlapping",
"features",
"together",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/interface.py#L1019-L1112 | train |
daler/gffutils | gffutils/interface.py | FeatureDB.children_bp | def children_bp(self, feature, child_featuretype='exon', merge=False,
ignore_strand=False):
"""
Total bp of all children of a featuretype.
Useful for getting the exonic bp of an mRNA.
Parameters
----------
feature : str or Feature instance
... | python | def children_bp(self, feature, child_featuretype='exon', merge=False,
ignore_strand=False):
"""
Total bp of all children of a featuretype.
Useful for getting the exonic bp of an mRNA.
Parameters
----------
feature : str or Feature instance
... | [
"def",
"children_bp",
"(",
"self",
",",
"feature",
",",
"child_featuretype",
"=",
"'exon'",
",",
"merge",
"=",
"False",
",",
"ignore_strand",
"=",
"False",
")",
":",
"children",
"=",
"self",
".",
"children",
"(",
"feature",
",",
"featuretype",
"=",
"child_... | Total bp of all children of a featuretype.
Useful for getting the exonic bp of an mRNA.
Parameters
----------
feature : str or Feature instance
child_featuretype : str
Which featuretype to consider. For example, to get exonic bp of an
mRNA, use `child... | [
"Total",
"bp",
"of",
"all",
"children",
"of",
"a",
"featuretype",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/interface.py#L1114-L1152 | train |
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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/interface.py#L1154-L1299 | train |
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",
"=",
"data",
... | 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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/iterators.py#L229-L279 | train |
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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/inspect.py#L7-L105 | train |
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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/scripts/gffutils-flybase-convert.py#L25-L45 | train |
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"
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/feature.py#L356-L411 | train |
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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/feature.py#L182-L191 | train |
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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/feature.py#L293-L322 | train |
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",
")",
"seq",
"=",
... | 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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/feature.py#L324-L353 | train |
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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L25-L42 | train |
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",
")",
":",
"if",
"len",
"(",
"dialects",
")",
"==",
"0",
":",
"return",
"constants",
".",
"dialect",
"final_order",
"=",
"[",
"]",
"for",
"dialect",
"in",
"dialects",
":",
"for",
"o",
"in",
"dialect",
"[",
"'or... | 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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L45-L75 | train |
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"
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L242-L253 | train |
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"
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L256-L260 | train |
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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L263-L268 | train |
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"
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L271-L282 | train |
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"
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L285-L296 | train |
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",
")",
"for",
"k",
",",
"v",
"in",
"new_d",
".",
"items",
"(",
")",
":",
"if",
"not",
"... | Merges two attribute dictionaries into a single dictionary.
Parameters
----------
`attr1`, `attr2` : dict
Returns
-------
dict | [
"Merges",
"two",
"attribute",
"dictionaries",
"into",
"a",
"single",
"dictionary",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L307-L333 | train |
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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L336-L345 | train |
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",
"(",
")",
":",
"for",
"gene_recs",
"in",
"db",
".",
"iter_by_parent_childs",
"(",
")",
":",
"gene_id",
"=",
"gene_recs",
"[",
"0",
"]",
".",
"id... | 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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L348-L376 | train |
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",
")",
":",
"db",
"=",
"gffutils",
".",
"FeatureDB",
"(",
"gff_fname",
")",
"else"... | Sanitize a GFF file. | [
"Sanitize",
"a",
"GFF",
"file",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L379-L404 | train |
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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L415-L425 | train |
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",
")",
":",
"raise",
"ValueError",
"(",
"\"GFF %s does not exist.\"",
"%",
"(",
"gff_fname",
")",
")",
"candidate_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. | [
"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... | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/helpers.py#L475-L506 | train |
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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/parser.py#L76-L169 | train |
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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/create.py#L1025-L1312 | train |
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",
"isinstance",
"(",
"self",
".",
"id_spec",
",",
"six",
".",
"string_types",
")",
":",
"id_key",
"=",
"[",
"self",
".",
"id_spec",
"]",
"elif",
"hasattr",
"(",
"self",
".",
"id_spec",
",",
... | 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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/create.py#L153-L205 | train |
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",
")",
":",
"self",
".",
"_init_tables",
"(",
")",
"self",
".",
"_populate_from_lines",
"(",
"self",
".",
"iterator",
")",
"self",
".",
"_update_relations",
"(",
")",
"self",
".",
"_finalize",
"(",
")"
] | Calls various methods sequentially in order to fully build the
database. | [
"Calls",
"various",
"methods",
"sequentially",
"in",
"order",
"to",
"fully",
"build",
"the",
"database",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/create.py#L507-L517 | train |
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",
"."
] | 6f7f547cad898738a1bd0a999fd68ba68db2c524 | https://github.com/daler/gffutils/blob/6f7f547cad898738a1bd0a999fd68ba68db2c524/gffutils/create.py#L523-L530 | train |
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",
")",
":",
"if",
"len",
"(",
"args",
")",
"<",
"1",
":",
"return",
"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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/javascript.py#L45-L77 | train |
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",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'browser'",
")",
":",
"return",
"if",
"hasattr",
"(",
"self",
",",
"'_js_vars'",
")",
"and",
"self",
".",
"_js_vars",
":",
"EmptyPromise",
"(",
"lambda",
":",
"_ar... | 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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/javascript.py#L104-L135 | train |
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",
")",
":",
"script",
"=",
"u\" && \"",
".",
"join",
"(",
"[",
"u\"!(typeof {0} === 'undefined')\"",
".",
"format",
"(",
"var",
")",
"for",
"var",
"in",
"js_vars",
"]",
")",
"try",
":",
"return",
... | 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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/javascript.py#L138-L158 | train |
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",
")",
":",
"script",
"=",
"dedent",
"(",
"u",
")",
".",
"format",
"(",
"deps",
"=",
"json",
".",
"dumps",
"(",
"list",
"(",
"deps",
")",
")",
")",
"browser",
".",
"set_script_timeout",
"(... | 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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/javascript.py#L161-L212 | train |
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",
")",
":",
"try",
":",
"return_val",
"=",
"func",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"except",
"WebDriverException",
":",
"LOGGER",
".",... | 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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/page_object.py#L64-L90 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axs_ruleset.py#L36-L69 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axs_ruleset.py#L71-L103 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axs_ruleset.py#L134-L193 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/promise.py#L91-L106 | train |
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"
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/docs/code/round_3/pages.py#L43-L49 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axe_core_ruleset.py#L37-L101 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axe_core_ruleset.py#L156-L207 | train |
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",
")",
".",
"format",
"(",
"rules_js",
"=",
"rules_js",
",",
"custom_rules",
"=",
"config",
".",
"custom_rules",
",",
"context",
"="... | 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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/a11y/axe_core_ruleset.py#L227-L300 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L79-L104 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L107-L138 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L141-L189 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L192-L296 | train |
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"
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L309-L367 | train |
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",
")",
":",
"LOGGER",
".",
"info",
"(",
"u\"Using local browser: %s [Default is firefox]\"",
",",
"browser_name",
")",
"browser_class",
"=",
"BROWSERS",
".",
"get",
"(",
"browser_name",
")",
"headless",
"=",
"os",
".... | Returns class, kwargs, and args needed to instantiate the local browser. | [
"Returns",
"class",
"kwargs",
"and",
"args",
"needed",
"to",
"instantiate",
"the",
"local",
"browser",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L370-L437 | train |
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",
"=",
"[",
"]",
"envs",
"=",
"_required_envs",
"(",
"env_vars",
")",
"envs",
".",
"update",
"(",
"_optional_envs",
"(",
")",
")... | Returns class, kwargs, and args needed to instantiate the remote browser. | [
"Returns",
"class",
"kwargs",
"and",
"args",
"needed",
"to",
"instantiate",
"the",
"remote",
"browser",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L440-L474 | train |
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",
"=",
"{",
"}",
")",
":",
"proxy_dict",
"=",
"{",
"\"httpProxy\"",
":",
"proxy",
".",
"proxy",
",",
"\"proxyType\"",
":",
"'manual'",
",",
"}",
"if",
"browser_name",
"==",
"'f... | 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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L477-L503 | train |
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",
"}",
"missing",
"=",
"[",
"key",
"for",
"key",
",",
"val",
"in",
"list",
"(",
"en... | 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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L519-L544 | train |
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",
"'JOB_NAME'",
"in",
"envs",
"and",
... | 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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L547-L567 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/browser.py#L570-L611 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L81-L103 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L105-L126 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L128-L146 | train |
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 filter ... | 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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L148-L194 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L196-L203 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L205-L226 | train |
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",
")",
":",
"try",
":",
"return",
"[",
"six",
".",
"next",
"(",
"iter",
"(",
"xs",
")",
")",
"]",
"except",
"StopIteration",
":",
"return",
"[",
"]",
"return",
"self",
".",
"tra... | 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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L258-L280 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L356-L376 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L417-L427 | train |
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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L430-L440 | train |
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",
")",
":",
"elem",
".",
"clear",
"(",
")",
"elem",
".",
"send_keys",
"(",
"text",
")",
"self",
".",
"map",
"(",
"_fill",
",",
"u'fill({!r})'",
".",
"format",
"(",
"tex... | 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",
"."
] | cdd0d423419fc0c49d56a9226533aa1490b60afc | https://github.com/edx/bok-choy/blob/cdd0d423419fc0c49d56a9226533aa1490b60afc/bok_choy/query.py#L486-L507 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.