repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
wiredrive/wtframework | wtframework/wtf/email.py | IMapEmailAccountObject.get_email_message | def get_email_message(self, message_uid, message_type="text/plain"):
"""
Fetch contents of email.
Args:
message_uid (int): IMAP Message UID number.
Kwargs:
message_type: Can be 'text' or 'html'
"""
self._mail.select("inbox")
result = sel... | python | def get_email_message(self, message_uid, message_type="text/plain"):
"""
Fetch contents of email.
Args:
message_uid (int): IMAP Message UID number.
Kwargs:
message_type: Can be 'text' or 'html'
"""
self._mail.select("inbox")
result = sel... | [
"def",
"get_email_message",
"(",
"self",
",",
"message_uid",
",",
"message_type",
"=",
"\"text/plain\"",
")",
":",
"self",
".",
"_mail",
".",
"select",
"(",
"\"inbox\"",
")",
"result",
"=",
"self",
".",
"_mail",
".",
"uid",
"(",
"'fetch'",
",",
"message_ui... | Fetch contents of email.
Args:
message_uid (int): IMAP Message UID number.
Kwargs:
message_type: Can be 'text' or 'html' | [
"Fetch",
"contents",
"of",
"email",
"."
] | ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216 | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/email.py#L115-L137 | train |
wiredrive/wtframework | wtframework/wtf/email.py | IMapEmailAccountObject.raw_search | def raw_search(self, *args, **kwargs):
"""
Find the a set of emails matching each regular expression passed in against the (RFC822) content.
Args:
*args: list of regular expressions.
Kwargs:
limit (int) - Limit to how many of the most resent emails to search thr... | python | def raw_search(self, *args, **kwargs):
"""
Find the a set of emails matching each regular expression passed in against the (RFC822) content.
Args:
*args: list of regular expressions.
Kwargs:
limit (int) - Limit to how many of the most resent emails to search thr... | [
"def",
"raw_search",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"limit",
"=",
"50",
"try",
":",
"limit",
"=",
"kwargs",
"[",
"'limit'",
"]",
"except",
"KeyError",
":",
"pass",
"# Get first X messages.",
"self",
".",
"_mail",
".",... | Find the a set of emails matching each regular expression passed in against the (RFC822) content.
Args:
*args: list of regular expressions.
Kwargs:
limit (int) - Limit to how many of the most resent emails to search through.
date (datetime) - If specified, it will f... | [
"Find",
"the",
"a",
"set",
"of",
"emails",
"matching",
"each",
"regular",
"expression",
"passed",
"in",
"against",
"the",
"(",
"RFC822",
")",
"content",
"."
] | ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216 | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/email.py#L139-L188 | train |
wiredrive/wtframework | wtframework/wtf/email.py | IMapEmailAccountObject.__search_email_by_subject | def __search_email_by_subject(self, subject, match_recipient):
"Get a list of message numbers"
if match_recipient is None:
_, data = self._mail.uid('search',
None,
'(HEADER SUBJECT "{subject}")'
... | python | def __search_email_by_subject(self, subject, match_recipient):
"Get a list of message numbers"
if match_recipient is None:
_, data = self._mail.uid('search',
None,
'(HEADER SUBJECT "{subject}")'
... | [
"def",
"__search_email_by_subject",
"(",
"self",
",",
"subject",
",",
"match_recipient",
")",
":",
"if",
"match_recipient",
"is",
"None",
":",
"_",
",",
"data",
"=",
"self",
".",
"_mail",
".",
"uid",
"(",
"'search'",
",",
"None",
",",
"'(HEADER SUBJECT \"{su... | Get a list of message numbers | [
"Get",
"a",
"list",
"of",
"message",
"numbers"
] | ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216 | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/email.py#L190-L219 | train |
wiredrive/wtframework | wtframework/wtf/config.py | ConfigReader.get | def get(self, key, default_value=__NoDefaultSpecified__):
'''
Gets the value from the yaml config based on the key.
No type casting is performed, any type casting should be
performed by the caller.
Args:
key (str) - Config setting key.
Kwargs:
... | python | def get(self, key, default_value=__NoDefaultSpecified__):
'''
Gets the value from the yaml config based on the key.
No type casting is performed, any type casting should be
performed by the caller.
Args:
key (str) - Config setting key.
Kwargs:
... | [
"def",
"get",
"(",
"self",
",",
"key",
",",
"default_value",
"=",
"__NoDefaultSpecified__",
")",
":",
"# First attempt to get the var from OS enviornment.",
"os_env_string",
"=",
"ConfigReader",
".",
"ENV_PREFIX",
"+",
"key",
"os_env_string",
"=",
"os_env_string",
".",
... | Gets the value from the yaml config based on the key.
No type casting is performed, any type casting should be
performed by the caller.
Args:
key (str) - Config setting key.
Kwargs:
default_value - Default value to return if config is not specified.
R... | [
"Gets",
"the",
"value",
"from",
"the",
"yaml",
"config",
"based",
"on",
"the",
"key",
"."
] | ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216 | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/config.py#L82-L124 | train |
wiredrive/wtframework | wtframework/wtf/_devtools_/page_object_tools.py | generate_page_object | def generate_page_object(page_name, url):
"Generate page object from URL"
# Attempt to extract partial URL for verification.
url_with_path = u('^.*//[^/]+([^?]+)?|$')
try:
match = re.match(url_with_path, url)
partial_url = match.group(1)
print("Using partial URL for location ver... | python | def generate_page_object(page_name, url):
"Generate page object from URL"
# Attempt to extract partial URL for verification.
url_with_path = u('^.*//[^/]+([^?]+)?|$')
try:
match = re.match(url_with_path, url)
partial_url = match.group(1)
print("Using partial URL for location ver... | [
"def",
"generate_page_object",
"(",
"page_name",
",",
"url",
")",
":",
"# Attempt to extract partial URL for verification.",
"url_with_path",
"=",
"u",
"(",
"'^.*//[^/]+([^?]+)?|$'",
")",
"try",
":",
"match",
"=",
"re",
".",
"match",
"(",
"url_with_path",
",",
"url"... | Generate page object from URL | [
"Generate",
"page",
"object",
"from",
"URL"
] | ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216 | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/_devtools_/page_object_tools.py#L139-L177 | train |
wiredrive/wtframework | wtframework/wtf/data/data_management.py | DataManager.get_data_path | def get_data_path(self, filename, env_prefix=None):
"""
Get data path.
Args:
filename (string) : Name of file inside of /data folder to retrieve.
Kwargs:
env_prefix (string) : Name of subfolder, ex: 'qa' will find files in /data/qa
Returns:
... | python | def get_data_path(self, filename, env_prefix=None):
"""
Get data path.
Args:
filename (string) : Name of file inside of /data folder to retrieve.
Kwargs:
env_prefix (string) : Name of subfolder, ex: 'qa' will find files in /data/qa
Returns:
... | [
"def",
"get_data_path",
"(",
"self",
",",
"filename",
",",
"env_prefix",
"=",
"None",
")",
":",
"if",
"env_prefix",
"==",
"None",
":",
"target_file",
"=",
"filename",
"else",
":",
"target_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"env_prefix",
","... | Get data path.
Args:
filename (string) : Name of file inside of /data folder to retrieve.
Kwargs:
env_prefix (string) : Name of subfolder, ex: 'qa' will find files in /data/qa
Returns:
String - path to file.
Usage::
open(WTF_DATA_MANAG... | [
"Get",
"data",
"path",
"."
] | ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216 | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/data/data_management.py#L65-L94 | train |
wiredrive/wtframework | wtframework/wtf/data/data_management.py | CsvReader.next | def next(self):
"""
Gets next entry as a dictionary.
Returns:
object - Object key/value pair representing a row.
{key1: value1, key2: value2, ...}
"""
try:
entry = {}
row = self._csv_reader.next()
for i in range(0, le... | python | def next(self):
"""
Gets next entry as a dictionary.
Returns:
object - Object key/value pair representing a row.
{key1: value1, key2: value2, ...}
"""
try:
entry = {}
row = self._csv_reader.next()
for i in range(0, le... | [
"def",
"next",
"(",
"self",
")",
":",
"try",
":",
"entry",
"=",
"{",
"}",
"row",
"=",
"self",
".",
"_csv_reader",
".",
"next",
"(",
")",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"row",
")",
")",
":",
"entry",
"[",
"self",
".",
... | Gets next entry as a dictionary.
Returns:
object - Object key/value pair representing a row.
{key1: value1, key2: value2, ...} | [
"Gets",
"next",
"entry",
"as",
"a",
"dictionary",
"."
] | ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216 | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/data/data_management.py#L133-L152 | train |
wiredrive/wtframework | wtframework/wtf/web/webelement.py | WebElementSelector.find_element_by_selectors | def find_element_by_selectors(webdriver, *selectors):
"""
Utility method makes it easier to find an element using multiple selectors. This is
useful for problematic elements what might works with one browser, but fail in another.
(Like different page elements being served up for differe... | python | def find_element_by_selectors(webdriver, *selectors):
"""
Utility method makes it easier to find an element using multiple selectors. This is
useful for problematic elements what might works with one browser, but fail in another.
(Like different page elements being served up for differe... | [
"def",
"find_element_by_selectors",
"(",
"webdriver",
",",
"*",
"selectors",
")",
":",
"# perform initial check to verify selectors are valid by statements.",
"for",
"selector",
"in",
"selectors",
":",
"(",
"by_method",
",",
"value",
")",
"=",
"selector",
"if",
"not",
... | Utility method makes it easier to find an element using multiple selectors. This is
useful for problematic elements what might works with one browser, but fail in another.
(Like different page elements being served up for different browsers)
Args:
selectors - var arg if N number of... | [
"Utility",
"method",
"makes",
"it",
"easier",
"to",
"find",
"an",
"element",
"using",
"multiple",
"selectors",
".",
"This",
"is",
"useful",
"for",
"problematic",
"elements",
"what",
"might",
"works",
"with",
"one",
"browser",
"but",
"fail",
"in",
"another",
... | ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216 | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webelement.py#L33-L70 | train |
wiredrive/wtframework | wtframework/wtf/web/webelement.py | WebElementUtils.wait_until_element_not_visible | def wait_until_element_not_visible(webdriver, locator_lambda_expression,
timeout=WTF_TIMEOUT_MANAGER.NORMAL, sleep=0.5):
"""
Wait for a WebElement to disappear.
Args:
webdriver (Webdriver) - Selenium Webdriver
locator (lambda) - Loc... | python | def wait_until_element_not_visible(webdriver, locator_lambda_expression,
timeout=WTF_TIMEOUT_MANAGER.NORMAL, sleep=0.5):
"""
Wait for a WebElement to disappear.
Args:
webdriver (Webdriver) - Selenium Webdriver
locator (lambda) - Loc... | [
"def",
"wait_until_element_not_visible",
"(",
"webdriver",
",",
"locator_lambda_expression",
",",
"timeout",
"=",
"WTF_TIMEOUT_MANAGER",
".",
"NORMAL",
",",
"sleep",
"=",
"0.5",
")",
":",
"# Wait for loading progress indicator to go away.",
"try",
":",
"stoptime",
"=",
... | Wait for a WebElement to disappear.
Args:
webdriver (Webdriver) - Selenium Webdriver
locator (lambda) - Locator lambda expression.
Kwargs:
timeout (number) - timeout period
sleep (number) - sleep period between intervals. | [
"Wait",
"for",
"a",
"WebElement",
"to",
"disappear",
"."
] | ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216 | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webelement.py#L89-L114 | train |
wiredrive/wtframework | wtframework/wtf/web/webelement.py | WebElementUtils.is_image_loaded | def is_image_loaded(webdriver, webelement):
'''
Check if an image (in an image tag) is loaded.
Note: This call will not work against background images. Only Images in <img> tags.
Args:
webelement (WebElement) - WebDriver web element to validate.
'''
script ... | python | def is_image_loaded(webdriver, webelement):
'''
Check if an image (in an image tag) is loaded.
Note: This call will not work against background images. Only Images in <img> tags.
Args:
webelement (WebElement) - WebDriver web element to validate.
'''
script ... | [
"def",
"is_image_loaded",
"(",
"webdriver",
",",
"webelement",
")",
":",
"script",
"=",
"(",
"u",
"(",
"\"return arguments[0].complete && type of arguments[0].naturalWidth != \\\"undefined\\\" \"",
")",
"+",
"u",
"(",
"\"&& arguments[0].naturalWidth > 0\"",
")",
")",
"try",... | Check if an image (in an image tag) is loaded.
Note: This call will not work against background images. Only Images in <img> tags.
Args:
webelement (WebElement) - WebDriver web element to validate. | [
"Check",
"if",
"an",
"image",
"(",
"in",
"an",
"image",
"tag",
")",
"is",
"loaded",
".",
"Note",
":",
"This",
"call",
"will",
"not",
"work",
"against",
"background",
"images",
".",
"Only",
"Images",
"in",
"<img",
">",
"tags",
"."
] | ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216 | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webelement.py#L117-L131 | train |
wiredrive/wtframework | wtframework/wtf/utils/data_utils.py | generate_timestamped_string | def generate_timestamped_string(subject="test", number_of_random_chars=4):
"""
Generate time-stamped string. Format as follows...
`2013-01-31_14:12:23_SubjectString_a3Zg`
Kwargs:
subject (str): String to use as subject.
number_of_random_chars (int) : Number of random characters to app... | python | def generate_timestamped_string(subject="test", number_of_random_chars=4):
"""
Generate time-stamped string. Format as follows...
`2013-01-31_14:12:23_SubjectString_a3Zg`
Kwargs:
subject (str): String to use as subject.
number_of_random_chars (int) : Number of random characters to app... | [
"def",
"generate_timestamped_string",
"(",
"subject",
"=",
"\"test\"",
",",
"number_of_random_chars",
"=",
"4",
")",
":",
"random_str",
"=",
"generate_random_string",
"(",
"number_of_random_chars",
")",
"timestamp",
"=",
"generate_timestamp",
"(",
")",
"return",
"u\"{... | Generate time-stamped string. Format as follows...
`2013-01-31_14:12:23_SubjectString_a3Zg`
Kwargs:
subject (str): String to use as subject.
number_of_random_chars (int) : Number of random characters to append.
This method is helpful for creating unique names with timestamps in them so ... | [
"Generate",
"time",
"-",
"stamped",
"string",
".",
"Format",
"as",
"follows",
"..."
] | ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216 | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/utils/data_utils.py#L28-L51 | train |
wiredrive/wtframework | wtframework/wtf/utils/data_utils.py | generate_random_string | def generate_random_string(number_of_random_chars=8, character_set=string.ascii_letters):
"""
Generate a series of random characters.
Kwargs:
number_of_random_chars (int) : Number of characters long
character_set (str): Specify a character set. Default is ASCII
"""
return u('').joi... | python | def generate_random_string(number_of_random_chars=8, character_set=string.ascii_letters):
"""
Generate a series of random characters.
Kwargs:
number_of_random_chars (int) : Number of characters long
character_set (str): Specify a character set. Default is ASCII
"""
return u('').joi... | [
"def",
"generate_random_string",
"(",
"number_of_random_chars",
"=",
"8",
",",
"character_set",
"=",
"string",
".",
"ascii_letters",
")",
":",
"return",
"u",
"(",
"''",
")",
".",
"join",
"(",
"random",
".",
"choice",
"(",
"character_set",
")",
"for",
"_",
... | Generate a series of random characters.
Kwargs:
number_of_random_chars (int) : Number of characters long
character_set (str): Specify a character set. Default is ASCII | [
"Generate",
"a",
"series",
"of",
"random",
"characters",
"."
] | ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216 | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/utils/data_utils.py#L65-L74 | train |
chrisspen/weka | weka/arff.py | convert_weka_to_py_date_pattern | def convert_weka_to_py_date_pattern(p):
"""
Converts the date format pattern used by Weka to the date format pattern used by Python's datetime.strftime().
"""
# https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior
# https://www.cs.waikato.ac.nz/ml/weka/arff.html
p = p.repla... | python | def convert_weka_to_py_date_pattern(p):
"""
Converts the date format pattern used by Weka to the date format pattern used by Python's datetime.strftime().
"""
# https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior
# https://www.cs.waikato.ac.nz/ml/weka/arff.html
p = p.repla... | [
"def",
"convert_weka_to_py_date_pattern",
"(",
"p",
")",
":",
"# https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior",
"# https://www.cs.waikato.ac.nz/ml/weka/arff.html",
"p",
"=",
"p",
".",
"replace",
"(",
"'yyyy'",
",",
"r'%Y'",
")",
"p",
"=",
"p",
... | Converts the date format pattern used by Weka to the date format pattern used by Python's datetime.strftime(). | [
"Converts",
"the",
"date",
"format",
"pattern",
"used",
"by",
"Weka",
"to",
"the",
"date",
"format",
"pattern",
"used",
"by",
"Python",
"s",
"datetime",
".",
"strftime",
"()",
"."
] | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L87-L99 | train |
chrisspen/weka | weka/arff.py | ArffFile.get_attribute_value | def get_attribute_value(self, name, index):
"""
Returns the value associated with the given value index
of the attribute with the given name.
This is only applicable for nominal and string types.
"""
if index == MISSING:
return
elif self.attri... | python | def get_attribute_value(self, name, index):
"""
Returns the value associated with the given value index
of the attribute with the given name.
This is only applicable for nominal and string types.
"""
if index == MISSING:
return
elif self.attri... | [
"def",
"get_attribute_value",
"(",
"self",
",",
"name",
",",
"index",
")",
":",
"if",
"index",
"==",
"MISSING",
":",
"return",
"elif",
"self",
".",
"attribute_types",
"[",
"name",
"]",
"in",
"NUMERIC_TYPES",
":",
"at",
"=",
"self",
".",
"attribute_types",
... | Returns the value associated with the given value index
of the attribute with the given name.
This is only applicable for nominal and string types. | [
"Returns",
"the",
"value",
"associated",
"with",
"the",
"given",
"value",
"index",
"of",
"the",
"attribute",
"with",
"the",
"given",
"name",
".",
"This",
"is",
"only",
"applicable",
"for",
"nominal",
"and",
"string",
"types",
"."
] | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L320-L342 | train |
chrisspen/weka | weka/arff.py | ArffFile.load | def load(cls, filename, schema_only=False):
"""
Load an ARFF File from a file.
"""
o = open(filename)
s = o.read()
a = cls.parse(s, schema_only=schema_only)
if not schema_only:
a._filename = filename
o.close()
return a | python | def load(cls, filename, schema_only=False):
"""
Load an ARFF File from a file.
"""
o = open(filename)
s = o.read()
a = cls.parse(s, schema_only=schema_only)
if not schema_only:
a._filename = filename
o.close()
return a | [
"def",
"load",
"(",
"cls",
",",
"filename",
",",
"schema_only",
"=",
"False",
")",
":",
"o",
"=",
"open",
"(",
"filename",
")",
"s",
"=",
"o",
".",
"read",
"(",
")",
"a",
"=",
"cls",
".",
"parse",
"(",
"s",
",",
"schema_only",
"=",
"schema_only",... | Load an ARFF File from a file. | [
"Load",
"an",
"ARFF",
"File",
"from",
"a",
"file",
"."
] | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L357-L367 | train |
chrisspen/weka | weka/arff.py | ArffFile.parse | def parse(cls, s, schema_only=False):
"""
Parse an ARFF File already loaded into a string.
"""
a = cls()
a.state = 'comment'
a.lineno = 1
for l in s.splitlines():
a.parseline(l)
a.lineno += 1
if schema_only and a.state == 'data'... | python | def parse(cls, s, schema_only=False):
"""
Parse an ARFF File already loaded into a string.
"""
a = cls()
a.state = 'comment'
a.lineno = 1
for l in s.splitlines():
a.parseline(l)
a.lineno += 1
if schema_only and a.state == 'data'... | [
"def",
"parse",
"(",
"cls",
",",
"s",
",",
"schema_only",
"=",
"False",
")",
":",
"a",
"=",
"cls",
"(",
")",
"a",
".",
"state",
"=",
"'comment'",
"a",
".",
"lineno",
"=",
"1",
"for",
"l",
"in",
"s",
".",
"splitlines",
"(",
")",
":",
"a",
".",... | Parse an ARFF File already loaded into a string. | [
"Parse",
"an",
"ARFF",
"File",
"already",
"loaded",
"into",
"a",
"string",
"."
] | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L370-L383 | train |
chrisspen/weka | weka/arff.py | ArffFile.copy | def copy(self, schema_only=False):
"""
Creates a deepcopy of the instance.
If schema_only is True, the data will be excluded from the copy.
"""
o = type(self)()
o.relation = self.relation
o.attributes = list(self.attributes)
o.attribute_types = self.attrib... | python | def copy(self, schema_only=False):
"""
Creates a deepcopy of the instance.
If schema_only is True, the data will be excluded from the copy.
"""
o = type(self)()
o.relation = self.relation
o.attributes = list(self.attributes)
o.attribute_types = self.attrib... | [
"def",
"copy",
"(",
"self",
",",
"schema_only",
"=",
"False",
")",
":",
"o",
"=",
"type",
"(",
"self",
")",
"(",
")",
"o",
".",
"relation",
"=",
"self",
".",
"relation",
"o",
".",
"attributes",
"=",
"list",
"(",
"self",
".",
"attributes",
")",
"o... | Creates a deepcopy of the instance.
If schema_only is True, the data will be excluded from the copy. | [
"Creates",
"a",
"deepcopy",
"of",
"the",
"instance",
".",
"If",
"schema_only",
"is",
"True",
"the",
"data",
"will",
"be",
"excluded",
"from",
"the",
"copy",
"."
] | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L385-L398 | train |
chrisspen/weka | weka/arff.py | ArffFile.open_stream | def open_stream(self, class_attr_name=None, fn=None):
"""
Save an arff structure to a file, leaving the file object
open for writing of new data samples.
This prevents you from directly accessing the data via Python,
but when generating a huge file, this prevents all your data
... | python | def open_stream(self, class_attr_name=None, fn=None):
"""
Save an arff structure to a file, leaving the file object
open for writing of new data samples.
This prevents you from directly accessing the data via Python,
but when generating a huge file, this prevents all your data
... | [
"def",
"open_stream",
"(",
"self",
",",
"class_attr_name",
"=",
"None",
",",
"fn",
"=",
"None",
")",
":",
"if",
"fn",
":",
"self",
".",
"fout_fn",
"=",
"fn",
"else",
":",
"fd",
",",
"self",
".",
"fout_fn",
"=",
"tempfile",
".",
"mkstemp",
"(",
")",... | Save an arff structure to a file, leaving the file object
open for writing of new data samples.
This prevents you from directly accessing the data via Python,
but when generating a huge file, this prevents all your data
from being stored in memory. | [
"Save",
"an",
"arff",
"structure",
"to",
"a",
"file",
"leaving",
"the",
"file",
"object",
"open",
"for",
"writing",
"of",
"new",
"data",
"samples",
".",
"This",
"prevents",
"you",
"from",
"directly",
"accessing",
"the",
"data",
"via",
"Python",
"but",
"whe... | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L404-L422 | train |
chrisspen/weka | weka/arff.py | ArffFile.close_stream | def close_stream(self):
"""
Terminates an open stream and returns the filename
of the file containing the streamed data.
"""
if self.fout:
fout = self.fout
fout_fn = self.fout_fn
self.fout.flush()
self.fout.close()
self.... | python | def close_stream(self):
"""
Terminates an open stream and returns the filename
of the file containing the streamed data.
"""
if self.fout:
fout = self.fout
fout_fn = self.fout_fn
self.fout.flush()
self.fout.close()
self.... | [
"def",
"close_stream",
"(",
"self",
")",
":",
"if",
"self",
".",
"fout",
":",
"fout",
"=",
"self",
".",
"fout",
"fout_fn",
"=",
"self",
".",
"fout_fn",
"self",
".",
"fout",
".",
"flush",
"(",
")",
"self",
".",
"fout",
".",
"close",
"(",
")",
"sel... | Terminates an open stream and returns the filename
of the file containing the streamed data. | [
"Terminates",
"an",
"open",
"stream",
"and",
"returns",
"the",
"filename",
"of",
"the",
"file",
"containing",
"the",
"streamed",
"data",
"."
] | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L424-L436 | train |
chrisspen/weka | weka/arff.py | ArffFile.save | def save(self, filename=None):
"""
Save an arff structure to a file.
"""
filename = filename or self._filename
o = open(filename, 'w')
o.write(self.write())
o.close() | python | def save(self, filename=None):
"""
Save an arff structure to a file.
"""
filename = filename or self._filename
o = open(filename, 'w')
o.write(self.write())
o.close() | [
"def",
"save",
"(",
"self",
",",
"filename",
"=",
"None",
")",
":",
"filename",
"=",
"filename",
"or",
"self",
".",
"_filename",
"o",
"=",
"open",
"(",
"filename",
",",
"'w'",
")",
"o",
".",
"write",
"(",
"self",
".",
"write",
"(",
")",
")",
"o",... | Save an arff structure to a file. | [
"Save",
"an",
"arff",
"structure",
"to",
"a",
"file",
"."
] | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L438-L445 | train |
chrisspen/weka | weka/arff.py | ArffFile.write_line | def write_line(self, d, fmt=SPARSE):
"""
Converts a single data line to a string.
"""
def smart_quote(s):
if isinstance(s, basestring) and ' ' in s and s[0] != '"':
s = '"%s"' % s
return s
if fmt == DENSE:
#TOD... | python | def write_line(self, d, fmt=SPARSE):
"""
Converts a single data line to a string.
"""
def smart_quote(s):
if isinstance(s, basestring) and ' ' in s and s[0] != '"':
s = '"%s"' % s
return s
if fmt == DENSE:
#TOD... | [
"def",
"write_line",
"(",
"self",
",",
"d",
",",
"fmt",
"=",
"SPARSE",
")",
":",
"def",
"smart_quote",
"(",
"s",
")",
":",
"if",
"isinstance",
"(",
"s",
",",
"basestring",
")",
"and",
"' '",
"in",
"s",
"and",
"s",
"[",
"0",
"]",
"!=",
"'\"'",
"... | Converts a single data line to a string. | [
"Converts",
"a",
"single",
"data",
"line",
"to",
"a",
"string",
"."
] | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L447-L532 | train |
chrisspen/weka | weka/arff.py | ArffFile.write | def write(self,
fout=None,
fmt=SPARSE,
schema_only=False,
data_only=False):
"""
Write an arff structure to a string.
"""
assert not (schema_only and data_only), 'Make up your mind.'
assert fmt in FORMATS, 'Invalid format "%s". Should be one of: %s'... | python | def write(self,
fout=None,
fmt=SPARSE,
schema_only=False,
data_only=False):
"""
Write an arff structure to a string.
"""
assert not (schema_only and data_only), 'Make up your mind.'
assert fmt in FORMATS, 'Invalid format "%s". Should be one of: %s'... | [
"def",
"write",
"(",
"self",
",",
"fout",
"=",
"None",
",",
"fmt",
"=",
"SPARSE",
",",
"schema_only",
"=",
"False",
",",
"data_only",
"=",
"False",
")",
":",
"assert",
"not",
"(",
"schema_only",
"and",
"data_only",
")",
",",
"'Make up your mind.'",
"asse... | Write an arff structure to a string. | [
"Write",
"an",
"arff",
"structure",
"to",
"a",
"string",
"."
] | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L559-L584 | train |
chrisspen/weka | weka/arff.py | ArffFile.define_attribute | def define_attribute(self, name, atype, data=None):
"""
Define a new attribute. atype has to be one of 'integer', 'real', 'numeric', 'string', 'date' or 'nominal'.
For nominal attributes, pass the possible values as data.
For date attributes, pass the format as data.
"""
... | python | def define_attribute(self, name, atype, data=None):
"""
Define a new attribute. atype has to be one of 'integer', 'real', 'numeric', 'string', 'date' or 'nominal'.
For nominal attributes, pass the possible values as data.
For date attributes, pass the format as data.
"""
... | [
"def",
"define_attribute",
"(",
"self",
",",
"name",
",",
"atype",
",",
"data",
"=",
"None",
")",
":",
"self",
".",
"attributes",
".",
"append",
"(",
"name",
")",
"assert",
"atype",
"in",
"TYPES",
",",
"\"Unknown type '%s'. Must be one of: %s\"",
"%",
"(",
... | Define a new attribute. atype has to be one of 'integer', 'real', 'numeric', 'string', 'date' or 'nominal'.
For nominal attributes, pass the possible values as data.
For date attributes, pass the format as data. | [
"Define",
"a",
"new",
"attribute",
".",
"atype",
"has",
"to",
"be",
"one",
"of",
"integer",
"real",
"numeric",
"string",
"date",
"or",
"nominal",
".",
"For",
"nominal",
"attributes",
"pass",
"the",
"possible",
"values",
"as",
"data",
".",
"For",
"date",
... | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L592-L601 | train |
chrisspen/weka | weka/arff.py | ArffFile.dump | def dump(self):
"""Print an overview of the ARFF file."""
print("Relation " + self.relation)
print(" With attributes")
for n in self.attributes:
if self.attribute_types[n] != TYPE_NOMINAL:
print(" %s of type %s" % (n, self.attribute_types[n]))
... | python | def dump(self):
"""Print an overview of the ARFF file."""
print("Relation " + self.relation)
print(" With attributes")
for n in self.attributes:
if self.attribute_types[n] != TYPE_NOMINAL:
print(" %s of type %s" % (n, self.attribute_types[n]))
... | [
"def",
"dump",
"(",
"self",
")",
":",
"print",
"(",
"\"Relation \"",
"+",
"self",
".",
"relation",
")",
"print",
"(",
"\" With attributes\"",
")",
"for",
"n",
"in",
"self",
".",
"attributes",
":",
"if",
"self",
".",
"attribute_types",
"[",
"n",
"]",
"... | Print an overview of the ARFF file. | [
"Print",
"an",
"overview",
"of",
"the",
"ARFF",
"file",
"."
] | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L722-L732 | train |
chrisspen/weka | weka/arff.py | ArffFile.alphabetize_attributes | def alphabetize_attributes(self):
"""
Orders attributes names alphabetically, except for the class attribute, which is kept last.
"""
self.attributes.sort(key=lambda name: (name == self.class_attr_name, name)) | python | def alphabetize_attributes(self):
"""
Orders attributes names alphabetically, except for the class attribute, which is kept last.
"""
self.attributes.sort(key=lambda name: (name == self.class_attr_name, name)) | [
"def",
"alphabetize_attributes",
"(",
"self",
")",
":",
"self",
".",
"attributes",
".",
"sort",
"(",
"key",
"=",
"lambda",
"name",
":",
"(",
"name",
"==",
"self",
".",
"class_attr_name",
",",
"name",
")",
")"
] | Orders attributes names alphabetically, except for the class attribute, which is kept last. | [
"Orders",
"attributes",
"names",
"alphabetically",
"except",
"for",
"the",
"class",
"attribute",
"which",
"is",
"kept",
"last",
"."
] | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L746-L750 | train |
xav/Grapefruit | grapefruit.py | rgb_to_hsl | def rgb_to_hsl(r, g=None, b=None):
"""Convert the color from RGB coordinates to HSL.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (h, s, l) tuple in the range:
h[0...360],... | python | def rgb_to_hsl(r, g=None, b=None):
"""Convert the color from RGB coordinates to HSL.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (h, s, l) tuple in the range:
h[0...360],... | [
"def",
"rgb_to_hsl",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"minVal",
"=",
"min",
"(",
"r",
",",
"g",
... | Convert the color from RGB coordinates to HSL.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (h, s, l) tuple in the range:
h[0...360],
s[0...1],
l[0...1]
>>> rgb_t... | [
"Convert",
"the",
"color",
"from",
"RGB",
"coordinates",
"to",
"HSL",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L249-L295 | train |
xav/Grapefruit | grapefruit.py | hsl_to_rgb | def hsl_to_rgb(h, s=None, l=None):
"""Convert the color from HSL coordinates to RGB.
Parameters:
:h:
The Hue component value [0...1]
:s:
The Saturation component value [0...1]
:l:
The Lightness component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r... | python | def hsl_to_rgb(h, s=None, l=None):
"""Convert the color from HSL coordinates to RGB.
Parameters:
:h:
The Hue component value [0...1]
:s:
The Saturation component value [0...1]
:l:
The Lightness component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r... | [
"def",
"hsl_to_rgb",
"(",
"h",
",",
"s",
"=",
"None",
",",
"l",
"=",
"None",
")",
":",
"if",
"type",
"(",
"h",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"h",
",",
"s",
",",
"l",
"=",
"h",
"if",
"s",
"==",
"0",
":",
"return",
"(",
... | Convert the color from HSL coordinates to RGB.
Parameters:
:h:
The Hue component value [0...1]
:s:
The Saturation component value [0...1]
:l:
The Lightness component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
>... | [
"Convert",
"the",
"color",
"from",
"HSL",
"coordinates",
"to",
"RGB",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L307-L344 | train |
xav/Grapefruit | grapefruit.py | rgb_to_hsv | def rgb_to_hsv(r, g=None, b=None):
"""Convert the color from RGB coordinates to HSV.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (h, s, v) tuple in the range:
h[0...360],... | python | def rgb_to_hsv(r, g=None, b=None):
"""Convert the color from RGB coordinates to HSV.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (h, s, v) tuple in the range:
h[0...360],... | [
"def",
"rgb_to_hsv",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"v",
"=",
"float",
"(",
"max",
"(",
"r",
"... | Convert the color from RGB coordinates to HSV.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (h, s, v) tuple in the range:
h[0...360],
s[0...1],
v[0...1]
>>> rgb_t... | [
"Convert",
"the",
"color",
"from",
"RGB",
"coordinates",
"to",
"HSV",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L346-L385 | train |
xav/Grapefruit | grapefruit.py | hsv_to_rgb | def hsv_to_rgb(h, s=None, v=None):
"""Convert the color from RGB coordinates to HSV.
Parameters:
:h:
The Hus component value [0...1]
:s:
The Saturation component value [0...1]
:v:
The Value component [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
... | python | def hsv_to_rgb(h, s=None, v=None):
"""Convert the color from RGB coordinates to HSV.
Parameters:
:h:
The Hus component value [0...1]
:s:
The Saturation component value [0...1]
:v:
The Value component [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
... | [
"def",
"hsv_to_rgb",
"(",
"h",
",",
"s",
"=",
"None",
",",
"v",
"=",
"None",
")",
":",
"if",
"type",
"(",
"h",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"h",
",",
"s",
",",
"v",
"=",
"h",
"if",
"s",
"==",
"0",
":",
"return",
"(",
... | Convert the color from RGB coordinates to HSV.
Parameters:
:h:
The Hus component value [0...1]
:s:
The Saturation component value [0...1]
:v:
The Value component [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
>>> hsv_to_... | [
"Convert",
"the",
"color",
"from",
"RGB",
"coordinates",
"to",
"HSV",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L387-L428 | train |
xav/Grapefruit | grapefruit.py | rgb_to_yiq | def rgb_to_yiq(r, g=None, b=None):
"""Convert the color from RGB to YIQ.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (y, i, q) tuple in the range:
y[0...1],
i[0...1],... | python | def rgb_to_yiq(r, g=None, b=None):
"""Convert the color from RGB to YIQ.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (y, i, q) tuple in the range:
y[0...1],
i[0...1],... | [
"def",
"rgb_to_yiq",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"y",
"=",
"(",
"r",
"*",
"0.29895808",
")",
... | Convert the color from RGB to YIQ.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (y, i, q) tuple in the range:
y[0...1],
i[0...1],
q[0...1]
>>> '(%g, %g, %g)' % rg... | [
"Convert",
"the",
"color",
"from",
"RGB",
"to",
"YIQ",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L430-L457 | train |
xav/Grapefruit | grapefruit.py | yiq_to_rgb | def yiq_to_rgb(y, i=None, q=None):
"""Convert the color from YIQ coordinates to RGB.
Parameters:
:y:
Tte Y component value [0...1]
:i:
The I component value [0...1]
:q:
The Q component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...... | python | def yiq_to_rgb(y, i=None, q=None):
"""Convert the color from YIQ coordinates to RGB.
Parameters:
:y:
Tte Y component value [0...1]
:i:
The I component value [0...1]
:q:
The Q component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...... | [
"def",
"yiq_to_rgb",
"(",
"y",
",",
"i",
"=",
"None",
",",
"q",
"=",
"None",
")",
":",
"if",
"type",
"(",
"y",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"y",
",",
"i",
",",
"q",
"=",
"y",
"r",
"=",
"y",
"+",
"(",
"i",
"*",
"0.9562... | Convert the color from YIQ coordinates to RGB.
Parameters:
:y:
Tte Y component value [0...1]
:i:
The I component value [0...1]
:q:
The Q component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
>>> '({}, {}, {})'.f... | [
"Convert",
"the",
"color",
"from",
"YIQ",
"coordinates",
"to",
"RGB",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L459-L485 | train |
xav/Grapefruit | grapefruit.py | rgb_to_yuv | def rgb_to_yuv(r, g=None, b=None):
"""Convert the color from RGB coordinates to YUV.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (y, u, v) tuple in the range:
y[0...1],
... | python | def rgb_to_yuv(r, g=None, b=None):
"""Convert the color from RGB coordinates to YUV.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (y, u, v) tuple in the range:
y[0...1],
... | [
"def",
"rgb_to_yuv",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"y",
"=",
"(",
"r",
"*",
"0.29900",
")",
"... | Convert the color from RGB coordinates to YUV.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (y, u, v) tuple in the range:
y[0...1],
u[-0.436...0.436],
v[-0.615...0.6... | [
"Convert",
"the",
"color",
"from",
"RGB",
"coordinates",
"to",
"YUV",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L487-L514 | train |
xav/Grapefruit | grapefruit.py | yuv_to_rgb | def yuv_to_rgb(y, u=None, v=None):
"""Convert the color from YUV coordinates to RGB.
Parameters:
:y:
The Y component value [0...1]
:u:
The U component value [-0.436...0.436]
:v:
The V component value [-0.615...0.615]
Returns:
The color as an (r, g, b) tuple in the range:
r[... | python | def yuv_to_rgb(y, u=None, v=None):
"""Convert the color from YUV coordinates to RGB.
Parameters:
:y:
The Y component value [0...1]
:u:
The U component value [-0.436...0.436]
:v:
The V component value [-0.615...0.615]
Returns:
The color as an (r, g, b) tuple in the range:
r[... | [
"def",
"yuv_to_rgb",
"(",
"y",
",",
"u",
"=",
"None",
",",
"v",
"=",
"None",
")",
":",
"if",
"type",
"(",
"y",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"y",
",",
"u",
",",
"v",
"=",
"y",
"r",
"=",
"y",
"+",
"(",
"v",
"*",
"1.1398... | Convert the color from YUV coordinates to RGB.
Parameters:
:y:
The Y component value [0...1]
:u:
The U component value [-0.436...0.436]
:v:
The V component value [-0.615...0.615]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
>>... | [
"Convert",
"the",
"color",
"from",
"YUV",
"coordinates",
"to",
"RGB",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L516-L542 | train |
xav/Grapefruit | grapefruit.py | rgb_to_xyz | def rgb_to_xyz(r, g=None, b=None):
"""Convert the color from sRGB to CIE XYZ.
The methods assumes that the RGB coordinates are given in the sRGB
colorspace (D65).
.. note::
Compensation for the sRGB gamma correction is applied before converting.
Parameters:
:r:
The Red component value [0...... | python | def rgb_to_xyz(r, g=None, b=None):
"""Convert the color from sRGB to CIE XYZ.
The methods assumes that the RGB coordinates are given in the sRGB
colorspace (D65).
.. note::
Compensation for the sRGB gamma correction is applied before converting.
Parameters:
:r:
The Red component value [0...... | [
"def",
"rgb_to_xyz",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"r",
",",
"g",
",",
"b",
"=",
"[",
"(",
... | Convert the color from sRGB to CIE XYZ.
The methods assumes that the RGB coordinates are given in the sRGB
colorspace (D65).
.. note::
Compensation for the sRGB gamma correction is applied before converting.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component val... | [
"Convert",
"the",
"color",
"from",
"sRGB",
"to",
"CIE",
"XYZ",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L544-L580 | train |
xav/Grapefruit | grapefruit.py | xyz_to_rgb | def xyz_to_rgb(x, y=None, z=None):
"""Convert the color from CIE XYZ coordinates to sRGB.
.. note::
Compensation for sRGB gamma correction is applied before converting.
Parameters:
:x:
The X component value [0...1]
:y:
The Y component value [0...1]
:z:
The Z component value [... | python | def xyz_to_rgb(x, y=None, z=None):
"""Convert the color from CIE XYZ coordinates to sRGB.
.. note::
Compensation for sRGB gamma correction is applied before converting.
Parameters:
:x:
The X component value [0...1]
:y:
The Y component value [0...1]
:z:
The Z component value [... | [
"def",
"xyz_to_rgb",
"(",
"x",
",",
"y",
"=",
"None",
",",
"z",
"=",
"None",
")",
":",
"if",
"type",
"(",
"x",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"x",
",",
"y",
",",
"z",
"=",
"x",
"r",
"=",
"(",
"x",
"*",
"3.2406255",
")",
... | Convert the color from CIE XYZ coordinates to sRGB.
.. note::
Compensation for sRGB gamma correction is applied before converting.
Parameters:
:x:
The X component value [0...1]
:y:
The Y component value [0...1]
:z:
The Z component value [0...1]
Returns:
The color as an (... | [
"Convert",
"the",
"color",
"from",
"CIE",
"XYZ",
"coordinates",
"to",
"sRGB",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L582-L612 | train |
xav/Grapefruit | grapefruit.py | xyz_to_lab | def xyz_to_lab(x, y=None, z=None, wref=_DEFAULT_WREF):
"""Convert the color from CIE XYZ to CIE L*a*b*.
Parameters:
:x:
The X component value [0...1]
:y:
The Y component value [0...1]
:z:
The Z component value [0...1]
:wref:
The whitepoint reference, default is 2° D65.
Re... | python | def xyz_to_lab(x, y=None, z=None, wref=_DEFAULT_WREF):
"""Convert the color from CIE XYZ to CIE L*a*b*.
Parameters:
:x:
The X component value [0...1]
:y:
The Y component value [0...1]
:z:
The Z component value [0...1]
:wref:
The whitepoint reference, default is 2° D65.
Re... | [
"def",
"xyz_to_lab",
"(",
"x",
",",
"y",
"=",
"None",
",",
"z",
"=",
"None",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"if",
"type",
"(",
"x",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"x",
",",
"y",
",",
"z",
"=",
"x",
"# White poin... | Convert the color from CIE XYZ to CIE L*a*b*.
Parameters:
:x:
The X component value [0...1]
:y:
The Y component value [0...1]
:z:
The Z component value [0...1]
:wref:
The whitepoint reference, default is 2° D65.
Returns:
The color as an (L, a, b) tuple in the range:
... | [
"Convert",
"the",
"color",
"from",
"CIE",
"XYZ",
"to",
"CIE",
"L",
"*",
"a",
"*",
"b",
"*",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L614-L655 | train |
xav/Grapefruit | grapefruit.py | lab_to_xyz | def lab_to_xyz(l, a=None, b=None, wref=_DEFAULT_WREF):
"""Convert the color from CIE L*a*b* to CIE 1931 XYZ.
Parameters:
:l:
The L component [0...100]
:a:
The a component [-1...1]
:b:
The a component [-1...1]
:wref:
The whitepoint reference, default is 2° D65.
Returns:
... | python | def lab_to_xyz(l, a=None, b=None, wref=_DEFAULT_WREF):
"""Convert the color from CIE L*a*b* to CIE 1931 XYZ.
Parameters:
:l:
The L component [0...100]
:a:
The a component [-1...1]
:b:
The a component [-1...1]
:wref:
The whitepoint reference, default is 2° D65.
Returns:
... | [
"def",
"lab_to_xyz",
"(",
"l",
",",
"a",
"=",
"None",
",",
"b",
"=",
"None",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"if",
"type",
"(",
"l",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"l",
",",
"a",
",",
"b",
"=",
"l",
"y",
"=",
... | Convert the color from CIE L*a*b* to CIE 1931 XYZ.
Parameters:
:l:
The L component [0...100]
:a:
The a component [-1...1]
:b:
The a component [-1...1]
:wref:
The whitepoint reference, default is 2° D65.
Returns:
The color as an (x, y, z) tuple in the range:
x[0...q]... | [
"Convert",
"the",
"color",
"from",
"CIE",
"L",
"*",
"a",
"*",
"b",
"*",
"to",
"CIE",
"1931",
"XYZ",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L657-L688 | train |
xav/Grapefruit | grapefruit.py | cmyk_to_cmy | def cmyk_to_cmy(c, m=None, y=None, k=None):
"""Convert the color from CMYK coordinates to CMY.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:k:
The Black component value [0...1]
Returns:
... | python | def cmyk_to_cmy(c, m=None, y=None, k=None):
"""Convert the color from CMYK coordinates to CMY.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:k:
The Black component value [0...1]
Returns:
... | [
"def",
"cmyk_to_cmy",
"(",
"c",
",",
"m",
"=",
"None",
",",
"y",
"=",
"None",
",",
"k",
"=",
"None",
")",
":",
"if",
"type",
"(",
"c",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"c",
",",
"m",
",",
"y",
",",
"k",
"=",
"c",
"mk",
"=... | Convert the color from CMYK coordinates to CMY.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:k:
The Black component value [0...1]
Returns:
The color as an (c, m, y) tuple in the range:
... | [
"Convert",
"the",
"color",
"from",
"CMYK",
"coordinates",
"to",
"CMY",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L690-L716 | train |
xav/Grapefruit | grapefruit.py | cmy_to_cmyk | def cmy_to_cmyk(c, m=None, y=None):
"""Convert the color from CMY coordinates to CMYK.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
Returns:
The color as an (c, m, y, k) tuple in the range:
c... | python | def cmy_to_cmyk(c, m=None, y=None):
"""Convert the color from CMY coordinates to CMYK.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
Returns:
The color as an (c, m, y, k) tuple in the range:
c... | [
"def",
"cmy_to_cmyk",
"(",
"c",
",",
"m",
"=",
"None",
",",
"y",
"=",
"None",
")",
":",
"if",
"type",
"(",
"c",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"c",
",",
"m",
",",
"y",
"=",
"c",
"k",
"=",
"min",
"(",
"c",
",",
"m",
",",... | Convert the color from CMY coordinates to CMYK.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
Returns:
The color as an (c, m, y, k) tuple in the range:
c[0...1],
m[0...1],
y[0...1],
... | [
"Convert",
"the",
"color",
"from",
"CMY",
"coordinates",
"to",
"CMYK",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L718-L745 | train |
xav/Grapefruit | grapefruit.py | rgb_to_cmy | def rgb_to_cmy(r, g=None, b=None):
"""Convert the color from RGB coordinates to CMY.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (c, m, y) tuple in the range:
c[0...1],
... | python | def rgb_to_cmy(r, g=None, b=None):
"""Convert the color from RGB coordinates to CMY.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (c, m, y) tuple in the range:
c[0...1],
... | [
"def",
"rgb_to_cmy",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"return",
"(",
"1",
"-",
"r",
",",
"1",
"-... | Convert the color from RGB coordinates to CMY.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (c, m, y) tuple in the range:
c[0...1],
m[0...1],
y[0...1]
>>> rgb_to_... | [
"Convert",
"the",
"color",
"from",
"RGB",
"coordinates",
"to",
"CMY",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L747-L770 | train |
xav/Grapefruit | grapefruit.py | cmy_to_rgb | def cmy_to_rgb(c, m=None, y=None):
"""Convert the color from CMY coordinates to RGB.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...... | python | def cmy_to_rgb(c, m=None, y=None):
"""Convert the color from CMY coordinates to RGB.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...... | [
"def",
"cmy_to_rgb",
"(",
"c",
",",
"m",
"=",
"None",
",",
"y",
"=",
"None",
")",
":",
"if",
"type",
"(",
"c",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"c",
",",
"m",
",",
"y",
"=",
"c",
"return",
"(",
"1",
"-",
"c",
",",
"1",
"-... | Convert the color from CMY coordinates to RGB.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
>>> cm... | [
"Convert",
"the",
"color",
"from",
"CMY",
"coordinates",
"to",
"RGB",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L772-L795 | train |
xav/Grapefruit | grapefruit.py | rgb_to_ints | def rgb_to_ints(r, g=None, b=None):
"""Convert the color in the standard [0...1] range to ints in the [0..255] range.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (r, g, b) tu... | python | def rgb_to_ints(r, g=None, b=None):
"""Convert the color in the standard [0...1] range to ints in the [0..255] range.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (r, g, b) tu... | [
"def",
"rgb_to_ints",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"return",
"tuple",
"(",
"int",
"(",
"round",
... | Convert the color in the standard [0...1] range to ints in the [0..255] range.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...255],
g[0... | [
"Convert",
"the",
"color",
"in",
"the",
"standard",
"[",
"0",
"...",
"1",
"]",
"range",
"to",
"ints",
"in",
"the",
"[",
"0",
"..",
"255",
"]",
"range",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L797-L820 | train |
xav/Grapefruit | grapefruit.py | ints_to_rgb | def ints_to_rgb(r, g=None, b=None):
"""Convert ints in the [0...255] range to the standard [0...1] range.
Parameters:
:r:
The Red component value [0...255]
:g:
The Green component value [0...255]
:b:
The Blue component value [0...255]
Returns:
The color as an (r, g, b) tuple in... | python | def ints_to_rgb(r, g=None, b=None):
"""Convert ints in the [0...255] range to the standard [0...1] range.
Parameters:
:r:
The Red component value [0...255]
:g:
The Green component value [0...255]
:b:
The Blue component value [0...255]
Returns:
The color as an (r, g, b) tuple in... | [
"def",
"ints_to_rgb",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"return",
"tuple",
"(",
"float",
"(",
"v",
... | Convert ints in the [0...255] range to the standard [0...1] range.
Parameters:
:r:
The Red component value [0...255]
:g:
The Green component value [0...255]
:b:
The Blue component value [0...255]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
... | [
"Convert",
"ints",
"in",
"the",
"[",
"0",
"...",
"255",
"]",
"range",
"to",
"the",
"standard",
"[",
"0",
"...",
"1",
"]",
"range",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L822-L845 | train |
xav/Grapefruit | grapefruit.py | rgb_to_html | def rgb_to_html(r, g=None, b=None):
"""Convert the color from (r, g, b) to #RRGGBB.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
A CSS string representation of this color (#RRGGBB).
>>> rg... | python | def rgb_to_html(r, g=None, b=None):
"""Convert the color from (r, g, b) to #RRGGBB.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
A CSS string representation of this color (#RRGGBB).
>>> rg... | [
"def",
"rgb_to_html",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"return",
"'#%02x%02x%02x'",
"%",
"tuple",
"(",... | Convert the color from (r, g, b) to #RRGGBB.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
A CSS string representation of this color (#RRGGBB).
>>> rgb_to_html(1, 0.5, 0)
'#ff8000' | [
"Convert",
"the",
"color",
"from",
"(",
"r",
"g",
"b",
")",
"to",
"#RRGGBB",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L847-L867 | train |
xav/Grapefruit | grapefruit.py | html_to_rgb | def html_to_rgb(html):
"""Convert the HTML color to (r, g, b).
Parameters:
:html:
the HTML definition of the color (#RRGGBB or #RGB or a color name).
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
Throws:
:ValueError:
If html is neither... | python | def html_to_rgb(html):
"""Convert the HTML color to (r, g, b).
Parameters:
:html:
the HTML definition of the color (#RRGGBB or #RGB or a color name).
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
Throws:
:ValueError:
If html is neither... | [
"def",
"html_to_rgb",
"(",
"html",
")",
":",
"html",
"=",
"html",
".",
"strip",
"(",
")",
".",
"lower",
"(",
")",
"if",
"html",
"[",
"0",
"]",
"==",
"'#'",
":",
"html",
"=",
"html",
"[",
"1",
":",
"]",
"elif",
"html",
"in",
"NAMED_COLOR",
":",
... | Convert the HTML color to (r, g, b).
Parameters:
:html:
the HTML definition of the color (#RRGGBB or #RGB or a color name).
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
Throws:
:ValueError:
If html is neither a known color name or a hex... | [
"Convert",
"the",
"HTML",
"color",
"to",
"(",
"r",
"g",
"b",
")",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L869-L912 | train |
xav/Grapefruit | grapefruit.py | rgb_to_pil | def rgb_to_pil(r, g=None, b=None):
"""Convert the color from RGB to a PIL-compatible integer.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
A PIL compatible integer (0xBBGGRR).
>>> '0x%06x'... | python | def rgb_to_pil(r, g=None, b=None):
"""Convert the color from RGB to a PIL-compatible integer.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
A PIL compatible integer (0xBBGGRR).
>>> '0x%06x'... | [
"def",
"rgb_to_pil",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"r",
",",
"g",
",",
"b",
"=",
"[",
"min",
... | Convert the color from RGB to a PIL-compatible integer.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
A PIL compatible integer (0xBBGGRR).
>>> '0x%06x' % rgb_to_pil(1, 0.5, 0)
'0x0080ff' | [
"Convert",
"the",
"color",
"from",
"RGB",
"to",
"a",
"PIL",
"-",
"compatible",
"integer",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L914-L935 | train |
xav/Grapefruit | grapefruit.py | pil_to_rgb | def pil_to_rgb(pil):
"""Convert the color from a PIL-compatible integer to RGB.
Parameters:
pil: a PIL compatible color representation (0xBBGGRR)
Returns:
The color as an (r, g, b) tuple in the range:
the range:
r: [0...1]
g: [0...1]
b: [0...1]
>>> '(%g, %g, %g)' % pil_to_rgb(0x0080ff)... | python | def pil_to_rgb(pil):
"""Convert the color from a PIL-compatible integer to RGB.
Parameters:
pil: a PIL compatible color representation (0xBBGGRR)
Returns:
The color as an (r, g, b) tuple in the range:
the range:
r: [0...1]
g: [0...1]
b: [0...1]
>>> '(%g, %g, %g)' % pil_to_rgb(0x0080ff)... | [
"def",
"pil_to_rgb",
"(",
"pil",
")",
":",
"r",
"=",
"0xff",
"&",
"pil",
"g",
"=",
"0xff",
"&",
"(",
"pil",
">>",
"8",
")",
"b",
"=",
"0xff",
"&",
"(",
"pil",
">>",
"16",
")",
"return",
"tuple",
"(",
"(",
"v",
"/",
"255.0",
"for",
"v",
"in"... | Convert the color from a PIL-compatible integer to RGB.
Parameters:
pil: a PIL compatible color representation (0xBBGGRR)
Returns:
The color as an (r, g, b) tuple in the range:
the range:
r: [0...1]
g: [0...1]
b: [0...1]
>>> '(%g, %g, %g)' % pil_to_rgb(0x0080ff)
'(1, 0.501961, 0)' | [
"Convert",
"the",
"color",
"from",
"a",
"PIL",
"-",
"compatible",
"integer",
"to",
"RGB",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L937-L956 | train |
xav/Grapefruit | grapefruit.py | _websafe_component | def _websafe_component(c, alt=False):
"""Convert a color component to its web safe equivalent.
Parameters:
:c:
The component value [0...1]
:alt:
If True, return the alternative value instead of the nearest one.
Returns:
The web safe equivalent of the component value.
"""
# This suck... | python | def _websafe_component(c, alt=False):
"""Convert a color component to its web safe equivalent.
Parameters:
:c:
The component value [0...1]
:alt:
If True, return the alternative value instead of the nearest one.
Returns:
The web safe equivalent of the component value.
"""
# This suck... | [
"def",
"_websafe_component",
"(",
"c",
",",
"alt",
"=",
"False",
")",
":",
"# This sucks, but floating point between 0 and 1 is quite fuzzy...",
"# So we just change the scale a while to make the equality tests",
"# work, otherwise it gets wrong at some decimal far to the right.",
"sc",
... | Convert a color component to its web safe equivalent.
Parameters:
:c:
The component value [0...1]
:alt:
If True, return the alternative value instead of the nearest one.
Returns:
The web safe equivalent of the component value. | [
"Convert",
"a",
"color",
"component",
"to",
"its",
"web",
"safe",
"equivalent",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L958-L990 | train |
xav/Grapefruit | grapefruit.py | rgb_to_websafe | def rgb_to_websafe(r, g=None, b=None, alt=False):
"""Convert the color from RGB to 'web safe' RGB
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
:alt:
If True, use the alternative color instead of th... | python | def rgb_to_websafe(r, g=None, b=None, alt=False):
"""Convert the color from RGB to 'web safe' RGB
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
:alt:
If True, use the alternative color instead of th... | [
"def",
"rgb_to_websafe",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
",",
"alt",
"=",
"False",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"websafeComponent"... | Convert the color from RGB to 'web safe' RGB
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
:alt:
If True, use the alternative color instead of the nearest one.
Can be used for dithering.
Retu... | [
"Convert",
"the",
"color",
"from",
"RGB",
"to",
"web",
"safe",
"RGB"
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L992-L1020 | train |
xav/Grapefruit | grapefruit.py | rgb_to_greyscale | def rgb_to_greyscale(r, g=None, b=None):
"""Convert the color from RGB to its greyscale equivalent
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
... | python | def rgb_to_greyscale(r, g=None, b=None):
"""Convert the color from RGB to its greyscale equivalent
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
... | [
"def",
"rgb_to_greyscale",
"(",
"r",
",",
"g",
"=",
"None",
",",
"b",
"=",
"None",
")",
":",
"if",
"type",
"(",
"r",
")",
"in",
"[",
"list",
",",
"tuple",
"]",
":",
"r",
",",
"g",
",",
"b",
"=",
"r",
"v",
"=",
"(",
"r",
"+",
"g",
"+",
"... | Convert the color from RGB to its greyscale equivalent
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
the range:
r[0...1],
g[0...1],
... | [
"Convert",
"the",
"color",
"from",
"RGB",
"to",
"its",
"greyscale",
"equivalent"
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1022-L1047 | train |
xav/Grapefruit | grapefruit.py | rgb_to_ryb | def rgb_to_ryb(hue):
"""Maps a hue on the RGB color wheel to Itten's RYB wheel.
Parameters:
:hue:
The hue on the RGB color wheel [0...360]
Returns:
An approximation of the corresponding hue on Itten's RYB wheel.
>>> rgb_to_ryb(15)
26.0
"""
d = hue % 15
i = int(hue / 15)
x0 = _RybWhee... | python | def rgb_to_ryb(hue):
"""Maps a hue on the RGB color wheel to Itten's RYB wheel.
Parameters:
:hue:
The hue on the RGB color wheel [0...360]
Returns:
An approximation of the corresponding hue on Itten's RYB wheel.
>>> rgb_to_ryb(15)
26.0
"""
d = hue % 15
i = int(hue / 15)
x0 = _RybWhee... | [
"def",
"rgb_to_ryb",
"(",
"hue",
")",
":",
"d",
"=",
"hue",
"%",
"15",
"i",
"=",
"int",
"(",
"hue",
"/",
"15",
")",
"x0",
"=",
"_RybWheel",
"[",
"i",
"]",
"x1",
"=",
"_RybWheel",
"[",
"i",
"+",
"1",
"]",
"return",
"x0",
"+",
"(",
"x1",
"-",... | Maps a hue on the RGB color wheel to Itten's RYB wheel.
Parameters:
:hue:
The hue on the RGB color wheel [0...360]
Returns:
An approximation of the corresponding hue on Itten's RYB wheel.
>>> rgb_to_ryb(15)
26.0 | [
"Maps",
"a",
"hue",
"on",
"the",
"RGB",
"color",
"wheel",
"to",
"Itten",
"s",
"RYB",
"wheel",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1049-L1067 | train |
xav/Grapefruit | grapefruit.py | ryb_to_rgb | def ryb_to_rgb(hue):
"""Maps a hue on Itten's RYB color wheel to the standard RGB wheel.
Parameters:
:hue:
The hue on Itten's RYB color wheel [0...360]
Returns:
An approximation of the corresponding hue on the standard RGB wheel.
>>> ryb_to_rgb(15)
8.0
"""
d = hue % 15
i = int(hue / 15... | python | def ryb_to_rgb(hue):
"""Maps a hue on Itten's RYB color wheel to the standard RGB wheel.
Parameters:
:hue:
The hue on Itten's RYB color wheel [0...360]
Returns:
An approximation of the corresponding hue on the standard RGB wheel.
>>> ryb_to_rgb(15)
8.0
"""
d = hue % 15
i = int(hue / 15... | [
"def",
"ryb_to_rgb",
"(",
"hue",
")",
":",
"d",
"=",
"hue",
"%",
"15",
"i",
"=",
"int",
"(",
"hue",
"/",
"15",
")",
"x0",
"=",
"_RgbWheel",
"[",
"i",
"]",
"x1",
"=",
"_RgbWheel",
"[",
"i",
"+",
"1",
"]",
"return",
"x0",
"+",
"(",
"x1",
"-",... | Maps a hue on Itten's RYB color wheel to the standard RGB wheel.
Parameters:
:hue:
The hue on Itten's RYB color wheel [0...360]
Returns:
An approximation of the corresponding hue on the standard RGB wheel.
>>> ryb_to_rgb(15)
8.0 | [
"Maps",
"a",
"hue",
"on",
"Itten",
"s",
"RYB",
"color",
"wheel",
"to",
"the",
"standard",
"RGB",
"wheel",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1069-L1087 | train |
xav/Grapefruit | grapefruit.py | Color.from_rgb | def from_rgb(r, g, b, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed RGB values.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
:alpha:
The color t... | python | def from_rgb(r, g, b, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed RGB values.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
:alpha:
The color t... | [
"def",
"from_rgb",
"(",
"r",
",",
"g",
",",
"b",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"(",
"r",
",",
"g",
",",
"b",
")",
",",
"'rgb'",
",",
"alpha",
",",
"wref",
")"
] | Create a new instance based on the specifed RGB values.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
T... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"RGB",
"values",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1123-L1147 | train |
xav/Grapefruit | grapefruit.py | Color.from_hsl | def from_hsl(h, s, l, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed HSL values.
Parameters:
:h:
The Hue component value [0...1]
:s:
The Saturation component value [0...1]
:l:
The Lightness component value [0...1]
:alpha:
T... | python | def from_hsl(h, s, l, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed HSL values.
Parameters:
:h:
The Hue component value [0...1]
:s:
The Saturation component value [0...1]
:l:
The Lightness component value [0...1]
:alpha:
T... | [
"def",
"from_hsl",
"(",
"h",
",",
"s",
",",
"l",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"(",
"h",
",",
"s",
",",
"l",
")",
",",
"'hsl'",
",",
"alpha",
",",
"wref",
")"
] | Create a new instance based on the specifed HSL values.
Parameters:
:h:
The Hue component value [0...1]
:s:
The Saturation component value [0...1]
:l:
The Lightness component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"HSL",
"values",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1150-L1174 | train |
xav/Grapefruit | grapefruit.py | Color.from_hsv | def from_hsv(h, s, v, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed HSV values.
Parameters:
:h:
The Hus component value [0...1]
:s:
The Saturation component value [0...1]
:v:
The Value component [0...1]
:alpha:
The color t... | python | def from_hsv(h, s, v, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed HSV values.
Parameters:
:h:
The Hus component value [0...1]
:s:
The Saturation component value [0...1]
:v:
The Value component [0...1]
:alpha:
The color t... | [
"def",
"from_hsv",
"(",
"h",
",",
"s",
",",
"v",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"h2",
",",
"s",
",",
"l",
"=",
"rgb_to_hsl",
"(",
"*",
"hsv_to_rgb",
"(",
"h",
",",
"s",
",",
"v",
")",
")",
"return",
"Co... | Create a new instance based on the specifed HSV values.
Parameters:
:h:
The Hus component value [0...1]
:s:
The Saturation component value [0...1]
:v:
The Value component [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
T... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"HSV",
"values",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1177-L1202 | train |
xav/Grapefruit | grapefruit.py | Color.from_yiq | def from_yiq(y, i, q, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed YIQ values.
Parameters:
:y:
The Y component value [0...1]
:i:
The I component value [0...1]
:q:
The Q component value [0...1]
:alpha:
The color transparen... | python | def from_yiq(y, i, q, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed YIQ values.
Parameters:
:y:
The Y component value [0...1]
:i:
The I component value [0...1]
:q:
The Q component value [0...1]
:alpha:
The color transparen... | [
"def",
"from_yiq",
"(",
"y",
",",
"i",
",",
"q",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"yiq_to_rgb",
"(",
"y",
",",
"i",
",",
"q",
")",
",",
"'rgb'",
",",
"alpha",
",",
"wref",
")"
] | Create a new instance based on the specifed YIQ values.
Parameters:
:y:
The Y component value [0...1]
:i:
The I component value [0...1]
:q:
The Q component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
The whitep... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"YIQ",
"values",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1205-L1229 | train |
xav/Grapefruit | grapefruit.py | Color.from_yuv | def from_yuv(y, u, v, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed YUV values.
Parameters:
:y:
The Y component value [0...1]
:u:
The U component value [-0.436...0.436]
:v:
The V component value [-0.615...0.615]
:alpha:
Th... | python | def from_yuv(y, u, v, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed YUV values.
Parameters:
:y:
The Y component value [0...1]
:u:
The U component value [-0.436...0.436]
:v:
The V component value [-0.615...0.615]
:alpha:
Th... | [
"def",
"from_yuv",
"(",
"y",
",",
"u",
",",
"v",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"yuv_to_rgb",
"(",
"y",
",",
"u",
",",
"v",
")",
",",
"'rgb'",
",",
"alpha",
",",
"wref",
")"
] | Create a new instance based on the specifed YUV values.
Parameters:
:y:
The Y component value [0...1]
:u:
The U component value [-0.436...0.436]
:v:
The V component value [-0.615...0.615]
:alpha:
The color transparency [0...1], default is opaque
:wref:
... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"YUV",
"values",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1232-L1256 | train |
xav/Grapefruit | grapefruit.py | Color.from_xyz | def from_xyz(x, y, z, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed CIE-XYZ values.
Parameters:
:x:
The Red component value [0...1]
:y:
The Green component value [0...1]
:z:
The Blue component value [0...1]
:alpha:
The col... | python | def from_xyz(x, y, z, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed CIE-XYZ values.
Parameters:
:x:
The Red component value [0...1]
:y:
The Green component value [0...1]
:z:
The Blue component value [0...1]
:alpha:
The col... | [
"def",
"from_xyz",
"(",
"x",
",",
"y",
",",
"z",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"xyz_to_rgb",
"(",
"x",
",",
"y",
",",
"z",
")",
",",
"'rgb'",
",",
"alpha",
",",
"wref",
")"
] | Create a new instance based on the specifed CIE-XYZ values.
Parameters:
:x:
The Red component value [0...1]
:y:
The Green component value [0...1]
:z:
The Blue component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"CIE",
"-",
"XYZ",
"values",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1259-L1283 | train |
xav/Grapefruit | grapefruit.py | Color.from_lab | def from_lab(l, a, b, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed CIE-LAB values.
Parameters:
:l:
The L component [0...100]
:a:
The a component [-1...1]
:b:
The a component [-1...1]
:alpha:
The color transparency [0...1]... | python | def from_lab(l, a, b, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed CIE-LAB values.
Parameters:
:l:
The L component [0...100]
:a:
The a component [-1...1]
:b:
The a component [-1...1]
:alpha:
The color transparency [0...1]... | [
"def",
"from_lab",
"(",
"l",
",",
"a",
",",
"b",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"xyz_to_rgb",
"(",
"*",
"lab_to_xyz",
"(",
"l",
",",
"a",
",",
"b",
",",
"wref",
")",
")",
",",
"'rg... | Create a new instance based on the specifed CIE-LAB values.
Parameters:
:l:
The L component [0...100]
:a:
The a component [-1...1]
:b:
The a component [-1...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
The whitepoint refer... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"CIE",
"-",
"LAB",
"values",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1286-L1314 | train |
xav/Grapefruit | grapefruit.py | Color.from_cmy | def from_cmy(c, m, y, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed CMY values.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:alpha:
The co... | python | def from_cmy(c, m, y, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed CMY values.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:alpha:
The co... | [
"def",
"from_cmy",
"(",
"c",
",",
"m",
",",
"y",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"cmy_to_rgb",
"(",
"c",
",",
"m",
",",
"y",
")",
",",
"'rgb'",
",",
"alpha",
",",
"wref",
")"
] | Create a new instance based on the specifed CMY values.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"CMY",
"values",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1317-L1341 | train |
xav/Grapefruit | grapefruit.py | Color.from_cmyk | def from_cmyk(c, m, y, k, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed CMYK values.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:k:
The B... | python | def from_cmyk(c, m, y, k, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed CMYK values.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:k:
The B... | [
"def",
"from_cmyk",
"(",
"c",
",",
"m",
",",
"y",
",",
"k",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"cmy_to_rgb",
"(",
"*",
"cmyk_to_cmy",
"(",
"c",
",",
"m",
",",
"y",
",",
"k",
")",
")",
... | Create a new instance based on the specifed CMYK values.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:k:
The Black component value [0...1]
:alpha:
The color tran... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"CMYK",
"values",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1344-L1370 | train |
xav/Grapefruit | grapefruit.py | Color.from_html | def from_html(html, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed HTML color definition.
Parameters:
:html:
The HTML definition of the color (#RRGGBB or #RGB or a color name).
:alpha:
The color transparency [0...1], default is opaque.
:wref:
... | python | def from_html(html, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed HTML color definition.
Parameters:
:html:
The HTML definition of the color (#RRGGBB or #RGB or a color name).
:alpha:
The color transparency [0...1], default is opaque.
:wref:
... | [
"def",
"from_html",
"(",
"html",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"html_to_rgb",
"(",
"html",
")",
",",
"'rgb'",
",",
"alpha",
",",
"wref",
")"
] | Create a new instance based on the specifed HTML color definition.
Parameters:
:html:
The HTML definition of the color (#RRGGBB or #RGB or a color name).
:alpha:
The color transparency [0...1], default is opaque.
:wref:
The whitepoint reference, default is 2° D65.
Ret... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"HTML",
"color",
"definition",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1373-L1401 | train |
xav/Grapefruit | grapefruit.py | Color.from_pil | def from_pil(pil, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed PIL color.
Parameters:
:pil:
A PIL compatible color representation (0xBBGGRR)
:alpha:
The color transparency [0...1], default is opaque
:wref:
The whitepoint reference, def... | python | def from_pil(pil, alpha=1.0, wref=_DEFAULT_WREF):
"""Create a new instance based on the specifed PIL color.
Parameters:
:pil:
A PIL compatible color representation (0xBBGGRR)
:alpha:
The color transparency [0...1], default is opaque
:wref:
The whitepoint reference, def... | [
"def",
"from_pil",
"(",
"pil",
",",
"alpha",
"=",
"1.0",
",",
"wref",
"=",
"_DEFAULT_WREF",
")",
":",
"return",
"Color",
"(",
"pil_to_rgb",
"(",
"pil",
")",
",",
"'rgb'",
",",
"alpha",
",",
"wref",
")"
] | Create a new instance based on the specifed PIL color.
Parameters:
:pil:
A PIL compatible color representation (0xBBGGRR)
:alpha:
The color transparency [0...1], default is opaque
:wref:
The whitepoint reference, default is 2° D65.
Returns:
A grapefruit.Color in... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"the",
"specifed",
"PIL",
"color",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1404-L1424 | train |
xav/Grapefruit | grapefruit.py | Color.with_white_ref | def with_white_ref(self, wref, labAsRef=False):
"""Create a new instance based on this one with a new white reference.
Parameters:
:wref:
The whitepoint reference.
:labAsRef:
If True, the L*a*b* values of the current instance are used as reference
for the new color; otherwis... | python | def with_white_ref(self, wref, labAsRef=False):
"""Create a new instance based on this one with a new white reference.
Parameters:
:wref:
The whitepoint reference.
:labAsRef:
If True, the L*a*b* values of the current instance are used as reference
for the new color; otherwis... | [
"def",
"with_white_ref",
"(",
"self",
",",
"wref",
",",
"labAsRef",
"=",
"False",
")",
":",
"if",
"labAsRef",
":",
"l",
",",
"a",
",",
"b",
"=",
"self",
".",
"lab",
"return",
"Color",
".",
"from_lab",
"(",
"l",
",",
"a",
",",
"b",
",",
"self",
... | Create a new instance based on this one with a new white reference.
Parameters:
:wref:
The whitepoint reference.
:labAsRef:
If True, the L*a*b* values of the current instance are used as reference
for the new color; otherwise, the RGB values are used as reference.
Returns:
... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"this",
"one",
"with",
"a",
"new",
"white",
"reference",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1707-L1744 | train |
xav/Grapefruit | grapefruit.py | Color.desaturate | def desaturate(self, level):
"""Create a new instance based on this one but less saturated.
Parameters:
:level:
The amount by which the color should be desaturated to produce
the new one [0...1].
Returns:
A grapefruit.Color instance.
>>> Color.from_hsl(30, 0.5, 0.5).desatu... | python | def desaturate(self, level):
"""Create a new instance based on this one but less saturated.
Parameters:
:level:
The amount by which the color should be desaturated to produce
the new one [0...1].
Returns:
A grapefruit.Color instance.
>>> Color.from_hsl(30, 0.5, 0.5).desatu... | [
"def",
"desaturate",
"(",
"self",
",",
"level",
")",
":",
"h",
",",
"s",
",",
"l",
"=",
"self",
".",
"__hsl",
"return",
"Color",
"(",
"(",
"h",
",",
"max",
"(",
"s",
"-",
"level",
",",
"0",
")",
",",
"l",
")",
",",
"'hsl'",
",",
"self",
"."... | Create a new instance based on this one but less saturated.
Parameters:
:level:
The amount by which the color should be desaturated to produce
the new one [0...1].
Returns:
A grapefruit.Color instance.
>>> Color.from_hsl(30, 0.5, 0.5).desaturate(0.25)
Color(0.625, 0.5, 0.3... | [
"Create",
"a",
"new",
"instance",
"based",
"on",
"this",
"one",
"but",
"less",
"saturated",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1867-L1885 | train |
xav/Grapefruit | grapefruit.py | Color.websafe_dither | def websafe_dither(self):
"""Return the two websafe colors nearest to this one.
Returns:
A tuple of two grapefruit.Color instances which are the two
web safe colors closest this one.
>>> c = Color.from_rgb(1.0, 0.45, 0.0)
>>> c1, c2 = c.websafe_dither()
>>> c1
Color(1.0, 0.4, 0.0, ... | python | def websafe_dither(self):
"""Return the two websafe colors nearest to this one.
Returns:
A tuple of two grapefruit.Color instances which are the two
web safe colors closest this one.
>>> c = Color.from_rgb(1.0, 0.45, 0.0)
>>> c1, c2 = c.websafe_dither()
>>> c1
Color(1.0, 0.4, 0.0, ... | [
"def",
"websafe_dither",
"(",
"self",
")",
":",
"return",
"(",
"Color",
"(",
"rgb_to_websafe",
"(",
"*",
"self",
".",
"__rgb",
")",
",",
"'rgb'",
",",
"self",
".",
"__a",
",",
"self",
".",
"__wref",
")",
",",
"Color",
"(",
"rgb_to_websafe",
"(",
"alt... | Return the two websafe colors nearest to this one.
Returns:
A tuple of two grapefruit.Color instances which are the two
web safe colors closest this one.
>>> c = Color.from_rgb(1.0, 0.45, 0.0)
>>> c1, c2 = c.websafe_dither()
>>> c1
Color(1.0, 0.4, 0.0, 1.0)
>>> c2
Color(1.0, 0.... | [
"Return",
"the",
"two",
"websafe",
"colors",
"nearest",
"to",
"this",
"one",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1895-L1912 | train |
xav/Grapefruit | grapefruit.py | Color.complementary_color | def complementary_color(self, mode='ryb'):
"""Create a new instance which is the complementary color of this one.
Parameters:
:mode:
Select which color wheel to use for the generation (ryb/rgb).
Returns:
A grapefruit.Color instance.
>>> Color.from_hsl(30, 1, 0.5).complementary_co... | python | def complementary_color(self, mode='ryb'):
"""Create a new instance which is the complementary color of this one.
Parameters:
:mode:
Select which color wheel to use for the generation (ryb/rgb).
Returns:
A grapefruit.Color instance.
>>> Color.from_hsl(30, 1, 0.5).complementary_co... | [
"def",
"complementary_color",
"(",
"self",
",",
"mode",
"=",
"'ryb'",
")",
":",
"h",
",",
"s",
",",
"l",
"=",
"self",
".",
"__hsl",
"if",
"mode",
"==",
"'ryb'",
":",
"h",
"=",
"rgb_to_ryb",
"(",
"h",
")",
"h",
"=",
"(",
"h",
"+",
"180",
")",
... | Create a new instance which is the complementary color of this one.
Parameters:
:mode:
Select which color wheel to use for the generation (ryb/rgb).
Returns:
A grapefruit.Color instance.
>>> Color.from_hsl(30, 1, 0.5).complementary_color(mode='rgb')
Color(0.0, 0.5, 1.0, 1.0)
... | [
"Create",
"a",
"new",
"instance",
"which",
"is",
"the",
"complementary",
"color",
"of",
"this",
"one",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1914-L1937 | train |
xav/Grapefruit | grapefruit.py | Color.make_analogous_scheme | def make_analogous_scheme(self, angle=30, mode='ryb'):
"""Return two colors analogous to this one.
Args:
:angle:
The angle between the hues of the created colors and this one.
:mode:
Select which color wheel to use for the generation (ryb/rgb).
Returns:
A tuple of grapefr... | python | def make_analogous_scheme(self, angle=30, mode='ryb'):
"""Return two colors analogous to this one.
Args:
:angle:
The angle between the hues of the created colors and this one.
:mode:
Select which color wheel to use for the generation (ryb/rgb).
Returns:
A tuple of grapefr... | [
"def",
"make_analogous_scheme",
"(",
"self",
",",
"angle",
"=",
"30",
",",
"mode",
"=",
"'ryb'",
")",
":",
"h",
",",
"s",
",",
"l",
"=",
"self",
".",
"__hsl",
"if",
"mode",
"==",
"'ryb'",
":",
"h",
"=",
"rgb_to_ryb",
"(",
"h",
")",
"h",
"+=",
"... | Return two colors analogous to this one.
Args:
:angle:
The angle between the hues of the created colors and this one.
:mode:
Select which color wheel to use for the generation (ryb/rgb).
Returns:
A tuple of grapefruit.Colors analogous to this one.
>>> c1 = Color.from_hsl... | [
"Return",
"two",
"colors",
"analogous",
"to",
"this",
"one",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L2089-L2127 | train |
xav/Grapefruit | grapefruit.py | Color.alpha_blend | def alpha_blend(self, other):
"""Alpha-blend this color on the other one.
Args:
:other:
The grapefruit.Color to alpha-blend with this one.
Returns:
A grapefruit.Color instance which is the result of alpha-blending
this color on the other one.
>>> c1 = Color.from_rgb(1, 0.5, ... | python | def alpha_blend(self, other):
"""Alpha-blend this color on the other one.
Args:
:other:
The grapefruit.Color to alpha-blend with this one.
Returns:
A grapefruit.Color instance which is the result of alpha-blending
this color on the other one.
>>> c1 = Color.from_rgb(1, 0.5, ... | [
"def",
"alpha_blend",
"(",
"self",
",",
"other",
")",
":",
"# get final alpha channel",
"fa",
"=",
"self",
".",
"__a",
"+",
"other",
".",
"__a",
"-",
"(",
"self",
".",
"__a",
"*",
"other",
".",
"__a",
")",
"# get percentage of source alpha compared to final al... | Alpha-blend this color on the other one.
Args:
:other:
The grapefruit.Color to alpha-blend with this one.
Returns:
A grapefruit.Color instance which is the result of alpha-blending
this color on the other one.
>>> c1 = Color.from_rgb(1, 0.5, 0, 0.2)
>>> c2 = Color.from_rgb(1... | [
"Alpha",
"-",
"blend",
"this",
"color",
"on",
"the",
"other",
"one",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L2129-L2160 | train |
xav/Grapefruit | grapefruit.py | Color.blend | def blend(self, other, percent=0.5):
"""blend this color with the other one.
Args:
:other:
the grapefruit.Color to blend with this one.
Returns:
A grapefruit.Color instance which is the result of blending
this color on the other one.
>>> c1 = Color.from_rgb(1, 0.5, 0, 0.2)
... | python | def blend(self, other, percent=0.5):
"""blend this color with the other one.
Args:
:other:
the grapefruit.Color to blend with this one.
Returns:
A grapefruit.Color instance which is the result of blending
this color on the other one.
>>> c1 = Color.from_rgb(1, 0.5, 0, 0.2)
... | [
"def",
"blend",
"(",
"self",
",",
"other",
",",
"percent",
"=",
"0.5",
")",
":",
"dest",
"=",
"1.0",
"-",
"percent",
"rgb",
"=",
"tuple",
"(",
"(",
"(",
"u",
"*",
"percent",
")",
"+",
"(",
"v",
"*",
"dest",
")",
"for",
"u",
",",
"v",
"in",
... | blend this color with the other one.
Args:
:other:
the grapefruit.Color to blend with this one.
Returns:
A grapefruit.Color instance which is the result of blending
this color on the other one.
>>> c1 = Color.from_rgb(1, 0.5, 0, 0.2)
>>> c2 = Color.from_rgb(1, 1, 1, 0.6)
... | [
"blend",
"this",
"color",
"with",
"the",
"other",
"one",
"."
] | b3d88375be727a3a1ec5839fbc462e0e8e0836e4 | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L2162-L2183 | train |
huntrar/scrape | scrape/scrape.py | get_parser | def get_parser():
"""Parse command-line arguments."""
parser = ArgumentParser(description='a command-line web scraping tool')
parser.add_argument('query', metavar='QUERY', type=str, nargs='*',
help='URLs/files to scrape')
parser.add_argument('-a', '--attributes', type=str, nargs=... | python | def get_parser():
"""Parse command-line arguments."""
parser = ArgumentParser(description='a command-line web scraping tool')
parser.add_argument('query', metavar='QUERY', type=str, nargs='*',
help='URLs/files to scrape')
parser.add_argument('-a', '--attributes', type=str, nargs=... | [
"def",
"get_parser",
"(",
")",
":",
"parser",
"=",
"ArgumentParser",
"(",
"description",
"=",
"'a command-line web scraping tool'",
")",
"parser",
".",
"add_argument",
"(",
"'query'",
",",
"metavar",
"=",
"'QUERY'",
",",
"type",
"=",
"str",
",",
"nargs",
"=",
... | Parse command-line arguments. | [
"Parse",
"command",
"-",
"line",
"arguments",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L19-L71 | train |
huntrar/scrape | scrape/scrape.py | write_files | def write_files(args, infilenames, outfilename):
"""Write scraped or local file(s) in desired format.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- name of output file (str)
Remove PART(#).html files afte... | python | def write_files(args, infilenames, outfilename):
"""Write scraped or local file(s) in desired format.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- name of output file (str)
Remove PART(#).html files afte... | [
"def",
"write_files",
"(",
"args",
",",
"infilenames",
",",
"outfilename",
")",
":",
"write_actions",
"=",
"{",
"'print'",
":",
"utils",
".",
"print_text",
",",
"'pdf'",
":",
"utils",
".",
"write_pdf_files",
",",
"'csv'",
":",
"utils",
".",
"write_csv_files"... | Write scraped or local file(s) in desired format.
Keyword arguments:
args -- program arguments (dict)
infilenames -- names of user-inputted and/or downloaded files (list)
outfilename -- name of output file (str)
Remove PART(#).html files after conversion unless otherwise specified. | [
"Write",
"scraped",
"or",
"local",
"file",
"(",
"s",
")",
"in",
"desired",
"format",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L74-L94 | train |
huntrar/scrape | scrape/scrape.py | write_single_file | def write_single_file(args, base_dir, crawler):
"""Write to a single output file and/or subdirectory."""
if args['urls'] and args['html']:
# Create a directory to save PART.html files in
domain = utils.get_domain(args['urls'][0])
if not args['quiet']:
print('Storing html file... | python | def write_single_file(args, base_dir, crawler):
"""Write to a single output file and/or subdirectory."""
if args['urls'] and args['html']:
# Create a directory to save PART.html files in
domain = utils.get_domain(args['urls'][0])
if not args['quiet']:
print('Storing html file... | [
"def",
"write_single_file",
"(",
"args",
",",
"base_dir",
",",
"crawler",
")",
":",
"if",
"args",
"[",
"'urls'",
"]",
"and",
"args",
"[",
"'html'",
"]",
":",
"# Create a directory to save PART.html files in",
"domain",
"=",
"utils",
".",
"get_domain",
"(",
"ar... | Write to a single output file and/or subdirectory. | [
"Write",
"to",
"a",
"single",
"output",
"file",
"and",
"/",
"or",
"subdirectory",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L97-L139 | train |
huntrar/scrape | scrape/scrape.py | write_multiple_files | def write_multiple_files(args, base_dir, crawler):
"""Write to multiple output files and/or subdirectories."""
for i, query in enumerate(args['query']):
if query in args['files']:
# Write files
if args['out'] and i < len(args['out']):
outfilename = args['out'][i]
... | python | def write_multiple_files(args, base_dir, crawler):
"""Write to multiple output files and/or subdirectories."""
for i, query in enumerate(args['query']):
if query in args['files']:
# Write files
if args['out'] and i < len(args['out']):
outfilename = args['out'][i]
... | [
"def",
"write_multiple_files",
"(",
"args",
",",
"base_dir",
",",
"crawler",
")",
":",
"for",
"i",
",",
"query",
"in",
"enumerate",
"(",
"args",
"[",
"'query'",
"]",
")",
":",
"if",
"query",
"in",
"args",
"[",
"'files'",
"]",
":",
"# Write files",
"if"... | Write to multiple output files and/or subdirectories. | [
"Write",
"to",
"multiple",
"output",
"files",
"and",
"/",
"or",
"subdirectories",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L142-L190 | train |
huntrar/scrape | scrape/scrape.py | split_input | def split_input(args):
"""Split query input into local files and URLs."""
args['files'] = []
args['urls'] = []
for arg in args['query']:
if os.path.isfile(arg):
args['files'].append(arg)
else:
args['urls'].append(arg.strip('/')) | python | def split_input(args):
"""Split query input into local files and URLs."""
args['files'] = []
args['urls'] = []
for arg in args['query']:
if os.path.isfile(arg):
args['files'].append(arg)
else:
args['urls'].append(arg.strip('/')) | [
"def",
"split_input",
"(",
"args",
")",
":",
"args",
"[",
"'files'",
"]",
"=",
"[",
"]",
"args",
"[",
"'urls'",
"]",
"=",
"[",
"]",
"for",
"arg",
"in",
"args",
"[",
"'query'",
"]",
":",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"arg",
")",
... | Split query input into local files and URLs. | [
"Split",
"query",
"input",
"into",
"local",
"files",
"and",
"URLs",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L193-L201 | train |
huntrar/scrape | scrape/scrape.py | detect_output_type | def detect_output_type(args):
"""Detect whether to save to a single or multiple files."""
if not args['single'] and not args['multiple']:
# Save to multiple files if multiple files/URLs entered
if len(args['query']) > 1 or len(args['out']) > 1:
args['multiple'] = True
else:
... | python | def detect_output_type(args):
"""Detect whether to save to a single or multiple files."""
if not args['single'] and not args['multiple']:
# Save to multiple files if multiple files/URLs entered
if len(args['query']) > 1 or len(args['out']) > 1:
args['multiple'] = True
else:
... | [
"def",
"detect_output_type",
"(",
"args",
")",
":",
"if",
"not",
"args",
"[",
"'single'",
"]",
"and",
"not",
"args",
"[",
"'multiple'",
"]",
":",
"# Save to multiple files if multiple files/URLs entered",
"if",
"len",
"(",
"args",
"[",
"'query'",
"]",
")",
">"... | Detect whether to save to a single or multiple files. | [
"Detect",
"whether",
"to",
"save",
"to",
"a",
"single",
"or",
"multiple",
"files",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L204-L211 | train |
huntrar/scrape | scrape/scrape.py | scrape | def scrape(args):
"""Scrape webpage content."""
try:
base_dir = os.getcwd()
if args['out'] is None:
args['out'] = []
# Detect whether to save to a single or multiple files
detect_output_type(args)
# Split query input into local files and URLs
split_i... | python | def scrape(args):
"""Scrape webpage content."""
try:
base_dir = os.getcwd()
if args['out'] is None:
args['out'] = []
# Detect whether to save to a single or multiple files
detect_output_type(args)
# Split query input into local files and URLs
split_i... | [
"def",
"scrape",
"(",
"args",
")",
":",
"try",
":",
"base_dir",
"=",
"os",
".",
"getcwd",
"(",
")",
"if",
"args",
"[",
"'out'",
"]",
"is",
"None",
":",
"args",
"[",
"'out'",
"]",
"=",
"[",
"]",
"# Detect whether to save to a single or multiple files",
"d... | Scrape webpage content. | [
"Scrape",
"webpage",
"content",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L214-L257 | train |
huntrar/scrape | scrape/scrape.py | prompt_filetype | def prompt_filetype(args):
"""Prompt user for filetype if none specified."""
valid_types = ('print', 'text', 'csv', 'pdf', 'html')
if not any(args[x] for x in valid_types):
try:
filetype = input('Print or save output as ({0}): '
.format(', '.join(valid_types)... | python | def prompt_filetype(args):
"""Prompt user for filetype if none specified."""
valid_types = ('print', 'text', 'csv', 'pdf', 'html')
if not any(args[x] for x in valid_types):
try:
filetype = input('Print or save output as ({0}): '
.format(', '.join(valid_types)... | [
"def",
"prompt_filetype",
"(",
"args",
")",
":",
"valid_types",
"=",
"(",
"'print'",
",",
"'text'",
",",
"'csv'",
",",
"'pdf'",
",",
"'html'",
")",
"if",
"not",
"any",
"(",
"args",
"[",
"x",
"]",
"for",
"x",
"in",
"valid_types",
")",
":",
"try",
":... | Prompt user for filetype if none specified. | [
"Prompt",
"user",
"for",
"filetype",
"if",
"none",
"specified",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L260-L272 | train |
huntrar/scrape | scrape/scrape.py | prompt_save_images | def prompt_save_images(args):
"""Prompt user to save images when crawling (for pdf and HTML formats)."""
if args['images'] or args['no_images']:
return
if (args['pdf'] or args['html']) and (args['crawl'] or args['crawl_all']):
save_msg = ('Choosing to save images will greatly slow the'
... | python | def prompt_save_images(args):
"""Prompt user to save images when crawling (for pdf and HTML formats)."""
if args['images'] or args['no_images']:
return
if (args['pdf'] or args['html']) and (args['crawl'] or args['crawl_all']):
save_msg = ('Choosing to save images will greatly slow the'
... | [
"def",
"prompt_save_images",
"(",
"args",
")",
":",
"if",
"args",
"[",
"'images'",
"]",
"or",
"args",
"[",
"'no_images'",
"]",
":",
"return",
"if",
"(",
"args",
"[",
"'pdf'",
"]",
"or",
"args",
"[",
"'html'",
"]",
")",
"and",
"(",
"args",
"[",
"'cr... | Prompt user to save images when crawling (for pdf and HTML formats). | [
"Prompt",
"user",
"to",
"save",
"images",
"when",
"crawling",
"(",
"for",
"pdf",
"and",
"HTML",
"formats",
")",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L275-L289 | train |
huntrar/scrape | scrape/scrape.py | command_line_runner | def command_line_runner():
"""Handle command-line interaction."""
parser = get_parser()
args = vars(parser.parse_args())
if args['version']:
print(__version__)
return
if args['clear_cache']:
utils.clear_cache()
print('Cleared {0}.'.format(utils.CACHE_DIR))
ret... | python | def command_line_runner():
"""Handle command-line interaction."""
parser = get_parser()
args = vars(parser.parse_args())
if args['version']:
print(__version__)
return
if args['clear_cache']:
utils.clear_cache()
print('Cleared {0}.'.format(utils.CACHE_DIR))
ret... | [
"def",
"command_line_runner",
"(",
")",
":",
"parser",
"=",
"get_parser",
"(",
")",
"args",
"=",
"vars",
"(",
"parser",
".",
"parse_args",
"(",
")",
")",
"if",
"args",
"[",
"'version'",
"]",
":",
"print",
"(",
"__version__",
")",
"return",
"if",
"args"... | Handle command-line interaction. | [
"Handle",
"command",
"-",
"line",
"interaction",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L292-L322 | train |
chrisspen/weka | weka/classifiers.py | Classifier.load_raw | def load_raw(cls, model_fn, schema, *args, **kwargs):
"""
Loads a trained classifier from the raw Weka model format.
Must specify the model schema and classifier name, since
these aren't currently deduced from the model format.
"""
c = cls(*args, **kwargs)
c.schem... | python | def load_raw(cls, model_fn, schema, *args, **kwargs):
"""
Loads a trained classifier from the raw Weka model format.
Must specify the model schema and classifier name, since
these aren't currently deduced from the model format.
"""
c = cls(*args, **kwargs)
c.schem... | [
"def",
"load_raw",
"(",
"cls",
",",
"model_fn",
",",
"schema",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"c",
"=",
"cls",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"c",
".",
"schema",
"=",
"schema",
".",
"copy",
"(",
"schema_on... | Loads a trained classifier from the raw Weka model format.
Must specify the model schema and classifier name, since
these aren't currently deduced from the model format. | [
"Loads",
"a",
"trained",
"classifier",
"from",
"the",
"raw",
"Weka",
"model",
"format",
".",
"Must",
"specify",
"the",
"model",
"schema",
"and",
"classifier",
"name",
"since",
"these",
"aren",
"t",
"currently",
"deduced",
"from",
"the",
"model",
"format",
".... | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/classifiers.py#L270-L279 | train |
chrisspen/weka | weka/classifiers.py | Classifier.train | def train(self, training_data, testing_data=None, verbose=False):
"""
Updates the classifier with new data.
"""
model_fn = None
training_fn = None
clean_training = False
testing_fn = None
clean_testing = False
try:
# Valida... | python | def train(self, training_data, testing_data=None, verbose=False):
"""
Updates the classifier with new data.
"""
model_fn = None
training_fn = None
clean_training = False
testing_fn = None
clean_testing = False
try:
# Valida... | [
"def",
"train",
"(",
"self",
",",
"training_data",
",",
"testing_data",
"=",
"None",
",",
"verbose",
"=",
"False",
")",
":",
"model_fn",
"=",
"None",
"training_fn",
"=",
"None",
"clean_training",
"=",
"False",
"testing_fn",
"=",
"None",
"clean_testing",
"=",... | Updates the classifier with new data. | [
"Updates",
"the",
"classifier",
"with",
"new",
"data",
"."
] | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/classifiers.py#L312-L417 | train |
chrisspen/weka | weka/classifiers.py | Classifier.predict | def predict(self, query_data, verbose=False, distribution=False, cleanup=True):
"""
Iterates over the predicted values and probability (if supported).
Each iteration yields a tuple of the form (prediction, probability).
If the file is a test file (i.e. contains no query variable... | python | def predict(self, query_data, verbose=False, distribution=False, cleanup=True):
"""
Iterates over the predicted values and probability (if supported).
Each iteration yields a tuple of the form (prediction, probability).
If the file is a test file (i.e. contains no query variable... | [
"def",
"predict",
"(",
"self",
",",
"query_data",
",",
"verbose",
"=",
"False",
",",
"distribution",
"=",
"False",
",",
"cleanup",
"=",
"True",
")",
":",
"model_fn",
"=",
"None",
"query_fn",
"=",
"None",
"clean_query",
"=",
"False",
"stdout",
"=",
"None"... | Iterates over the predicted values and probability (if supported).
Each iteration yields a tuple of the form (prediction, probability).
If the file is a test file (i.e. contains no query variables),
then the tuple will be of the form (prediction, actual).
See http://wek... | [
"Iterates",
"over",
"the",
"predicted",
"values",
"and",
"probability",
"(",
"if",
"supported",
")",
".",
"Each",
"iteration",
"yields",
"a",
"tuple",
"of",
"the",
"form",
"(",
"prediction",
"probability",
")",
".",
"If",
"the",
"file",
"is",
"a",
"test",
... | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/classifiers.py#L419-L592 | train |
chrisspen/weka | weka/classifiers.py | EnsembleClassifier.get_training_coverage | def get_training_coverage(self):
"""
Returns a ratio of classifiers that were able to be trained successfully.
"""
total = len(self.training_results)
i = sum(1 for data in self.training_results.values() if not isinstance(data, basestring))
return i/float(total) | python | def get_training_coverage(self):
"""
Returns a ratio of classifiers that were able to be trained successfully.
"""
total = len(self.training_results)
i = sum(1 for data in self.training_results.values() if not isinstance(data, basestring))
return i/float(total) | [
"def",
"get_training_coverage",
"(",
"self",
")",
":",
"total",
"=",
"len",
"(",
"self",
".",
"training_results",
")",
"i",
"=",
"sum",
"(",
"1",
"for",
"data",
"in",
"self",
".",
"training_results",
".",
"values",
"(",
")",
"if",
"not",
"isinstance",
... | Returns a ratio of classifiers that were able to be trained successfully. | [
"Returns",
"a",
"ratio",
"of",
"classifiers",
"that",
"were",
"able",
"to",
"be",
"trained",
"successfully",
"."
] | c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/classifiers.py#L640-L646 | train |
huntrar/scrape | scrape/crawler.py | Crawler.get_new_links | def get_new_links(self, url, resp):
"""Get new links from a URL and filter them."""
links_on_page = resp.xpath('//a/@href')
links = [utils.clean_url(u, url) for u in links_on_page]
# Remove non-links through filtering by protocol
links = [x for x in links if utils.check_protocol... | python | def get_new_links(self, url, resp):
"""Get new links from a URL and filter them."""
links_on_page = resp.xpath('//a/@href')
links = [utils.clean_url(u, url) for u in links_on_page]
# Remove non-links through filtering by protocol
links = [x for x in links if utils.check_protocol... | [
"def",
"get_new_links",
"(",
"self",
",",
"url",
",",
"resp",
")",
":",
"links_on_page",
"=",
"resp",
".",
"xpath",
"(",
"'//a/@href'",
")",
"links",
"=",
"[",
"utils",
".",
"clean_url",
"(",
"u",
",",
"url",
")",
"for",
"u",
"in",
"links_on_page",
"... | Get new links from a URL and filter them. | [
"Get",
"new",
"links",
"from",
"a",
"URL",
"and",
"filter",
"them",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/crawler.py#L20-L36 | train |
huntrar/scrape | scrape/crawler.py | Crawler.page_crawled | def page_crawled(self, page_resp):
"""Check if page has been crawled by hashing its text content.
Add new pages to the page cache.
Return whether page was found in cache.
"""
page_text = utils.parse_text(page_resp)
page_hash = utils.hash_text(''.join(page_text))
... | python | def page_crawled(self, page_resp):
"""Check if page has been crawled by hashing its text content.
Add new pages to the page cache.
Return whether page was found in cache.
"""
page_text = utils.parse_text(page_resp)
page_hash = utils.hash_text(''.join(page_text))
... | [
"def",
"page_crawled",
"(",
"self",
",",
"page_resp",
")",
":",
"page_text",
"=",
"utils",
".",
"parse_text",
"(",
"page_resp",
")",
"page_hash",
"=",
"utils",
".",
"hash_text",
"(",
"''",
".",
"join",
"(",
"page_text",
")",
")",
"if",
"page_hash",
"not"... | Check if page has been crawled by hashing its text content.
Add new pages to the page cache.
Return whether page was found in cache. | [
"Check",
"if",
"page",
"has",
"been",
"crawled",
"by",
"hashing",
"its",
"text",
"content",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/crawler.py#L42-L53 | train |
huntrar/scrape | scrape/crawler.py | Crawler.crawl_links | def crawl_links(self, seed_url=None):
"""Find new links given a seed URL and follow them breadth-first.
Save page responses as PART.html files.
Return the PART.html filenames created during crawling.
"""
if seed_url is not None:
self.seed_url = seed_url
if s... | python | def crawl_links(self, seed_url=None):
"""Find new links given a seed URL and follow them breadth-first.
Save page responses as PART.html files.
Return the PART.html filenames created during crawling.
"""
if seed_url is not None:
self.seed_url = seed_url
if s... | [
"def",
"crawl_links",
"(",
"self",
",",
"seed_url",
"=",
"None",
")",
":",
"if",
"seed_url",
"is",
"not",
"None",
":",
"self",
".",
"seed_url",
"=",
"seed_url",
"if",
"self",
".",
"seed_url",
"is",
"None",
":",
"sys",
".",
"stderr",
".",
"write",
"("... | Find new links given a seed URL and follow them breadth-first.
Save page responses as PART.html files.
Return the PART.html filenames created during crawling. | [
"Find",
"new",
"links",
"given",
"a",
"seed",
"URL",
"and",
"follow",
"them",
"breadth",
"-",
"first",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/crawler.py#L55-L105 | train |
huntrar/scrape | scrape/utils.py | get_proxies | def get_proxies():
"""Get available proxies to use with requests library."""
proxies = getproxies()
filtered_proxies = {}
for key, value in proxies.items():
if key.startswith('http://'):
if not value.startswith('http://'):
filtered_proxies[key] = 'http://{0}'.format(v... | python | def get_proxies():
"""Get available proxies to use with requests library."""
proxies = getproxies()
filtered_proxies = {}
for key, value in proxies.items():
if key.startswith('http://'):
if not value.startswith('http://'):
filtered_proxies[key] = 'http://{0}'.format(v... | [
"def",
"get_proxies",
"(",
")",
":",
"proxies",
"=",
"getproxies",
"(",
")",
"filtered_proxies",
"=",
"{",
"}",
"for",
"key",
",",
"value",
"in",
"proxies",
".",
"items",
"(",
")",
":",
"if",
"key",
".",
"startswith",
"(",
"'http://'",
")",
":",
"if"... | Get available proxies to use with requests library. | [
"Get",
"available",
"proxies",
"to",
"use",
"with",
"requests",
"library",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L63-L73 | train |
huntrar/scrape | scrape/utils.py | get_resp | def get_resp(url):
"""Get webpage response as an lxml.html.HtmlElement object."""
try:
headers = {'User-Agent': random.choice(USER_AGENTS)}
try:
request = requests.get(url, headers=headers, proxies=get_proxies())
except MissingSchema:
url = add_protocol(url)
... | python | def get_resp(url):
"""Get webpage response as an lxml.html.HtmlElement object."""
try:
headers = {'User-Agent': random.choice(USER_AGENTS)}
try:
request = requests.get(url, headers=headers, proxies=get_proxies())
except MissingSchema:
url = add_protocol(url)
... | [
"def",
"get_resp",
"(",
"url",
")",
":",
"try",
":",
"headers",
"=",
"{",
"'User-Agent'",
":",
"random",
".",
"choice",
"(",
"USER_AGENTS",
")",
"}",
"try",
":",
"request",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"headers",
"=",
"headers",
",",... | Get webpage response as an lxml.html.HtmlElement object. | [
"Get",
"webpage",
"response",
"as",
"an",
"lxml",
".",
"html",
".",
"HtmlElement",
"object",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L76-L88 | train |
huntrar/scrape | scrape/utils.py | enable_cache | def enable_cache():
"""Enable requests library cache."""
try:
import requests_cache
except ImportError as err:
sys.stderr.write('Failed to enable cache: {0}\n'.format(str(err)))
return
if not os.path.exists(CACHE_DIR):
os.makedirs(CACHE_DIR)
requests_cache.install_cac... | python | def enable_cache():
"""Enable requests library cache."""
try:
import requests_cache
except ImportError as err:
sys.stderr.write('Failed to enable cache: {0}\n'.format(str(err)))
return
if not os.path.exists(CACHE_DIR):
os.makedirs(CACHE_DIR)
requests_cache.install_cac... | [
"def",
"enable_cache",
"(",
")",
":",
"try",
":",
"import",
"requests_cache",
"except",
"ImportError",
"as",
"err",
":",
"sys",
".",
"stderr",
".",
"write",
"(",
"'Failed to enable cache: {0}\\n'",
".",
"format",
"(",
"str",
"(",
"err",
")",
")",
")",
"ret... | Enable requests library cache. | [
"Enable",
"requests",
"library",
"cache",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L106-L115 | train |
huntrar/scrape | scrape/utils.py | hash_text | def hash_text(text):
"""Return MD5 hash of a string."""
md5 = hashlib.md5()
md5.update(text)
return md5.hexdigest() | python | def hash_text(text):
"""Return MD5 hash of a string."""
md5 = hashlib.md5()
md5.update(text)
return md5.hexdigest() | [
"def",
"hash_text",
"(",
"text",
")",
":",
"md5",
"=",
"hashlib",
".",
"md5",
"(",
")",
"md5",
".",
"update",
"(",
"text",
")",
"return",
"md5",
".",
"hexdigest",
"(",
")"
] | Return MD5 hash of a string. | [
"Return",
"MD5",
"hash",
"of",
"a",
"string",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L127-L131 | train |
huntrar/scrape | scrape/utils.py | cache_page | def cache_page(page_cache, page_hash, cache_size):
"""Add a page to the page cache."""
page_cache.append(page_hash)
if len(page_cache) > cache_size:
page_cache.pop(0) | python | def cache_page(page_cache, page_hash, cache_size):
"""Add a page to the page cache."""
page_cache.append(page_hash)
if len(page_cache) > cache_size:
page_cache.pop(0) | [
"def",
"cache_page",
"(",
"page_cache",
",",
"page_hash",
",",
"cache_size",
")",
":",
"page_cache",
".",
"append",
"(",
"page_hash",
")",
"if",
"len",
"(",
"page_cache",
")",
">",
"cache_size",
":",
"page_cache",
".",
"pop",
"(",
"0",
")"
] | Add a page to the page cache. | [
"Add",
"a",
"page",
"to",
"the",
"page",
"cache",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L134-L138 | train |
huntrar/scrape | scrape/utils.py | re_filter | def re_filter(text, regexps):
"""Filter text using regular expressions."""
if not regexps:
return text
matched_text = []
compiled_regexps = [re.compile(x) for x in regexps]
for line in text:
if line in matched_text:
continue
for regexp in compiled_regexps:
... | python | def re_filter(text, regexps):
"""Filter text using regular expressions."""
if not regexps:
return text
matched_text = []
compiled_regexps = [re.compile(x) for x in regexps]
for line in text:
if line in matched_text:
continue
for regexp in compiled_regexps:
... | [
"def",
"re_filter",
"(",
"text",
",",
"regexps",
")",
":",
"if",
"not",
"regexps",
":",
"return",
"text",
"matched_text",
"=",
"[",
"]",
"compiled_regexps",
"=",
"[",
"re",
".",
"compile",
"(",
"x",
")",
"for",
"x",
"in",
"regexps",
"]",
"for",
"line... | Filter text using regular expressions. | [
"Filter",
"text",
"using",
"regular",
"expressions",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L144-L160 | train |
huntrar/scrape | scrape/utils.py | remove_whitespace | def remove_whitespace(text):
"""Remove unnecessary whitespace while keeping logical structure.
Keyword arguments:
text -- text to remove whitespace from (list)
Retain paragraph structure but remove other whitespace,
such as between words on a line and at the start and end of the text.
"""
... | python | def remove_whitespace(text):
"""Remove unnecessary whitespace while keeping logical structure.
Keyword arguments:
text -- text to remove whitespace from (list)
Retain paragraph structure but remove other whitespace,
such as between words on a line and at the start and end of the text.
"""
... | [
"def",
"remove_whitespace",
"(",
"text",
")",
":",
"clean_text",
"=",
"[",
"]",
"curr_line",
"=",
"''",
"# Remove any newlines that follow two lines of whitespace consecutively",
"# Also remove whitespace at start and end of text",
"while",
"text",
":",
"if",
"not",
"curr_lin... | Remove unnecessary whitespace while keeping logical structure.
Keyword arguments:
text -- text to remove whitespace from (list)
Retain paragraph structure but remove other whitespace,
such as between words on a line and at the start and end of the text. | [
"Remove",
"unnecessary",
"whitespace",
"while",
"keeping",
"logical",
"structure",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L163-L211 | train |
huntrar/scrape | scrape/utils.py | parse_text | def parse_text(infile, xpath=None, filter_words=None, attributes=None):
"""Filter text using XPath, regex keywords, and tag attributes.
Keyword arguments:
infile -- HTML or text content to parse (list)
xpath -- an XPath expression (str)
filter_words -- regex keywords (list)
attributes -- HTML t... | python | def parse_text(infile, xpath=None, filter_words=None, attributes=None):
"""Filter text using XPath, regex keywords, and tag attributes.
Keyword arguments:
infile -- HTML or text content to parse (list)
xpath -- an XPath expression (str)
filter_words -- regex keywords (list)
attributes -- HTML t... | [
"def",
"parse_text",
"(",
"infile",
",",
"xpath",
"=",
"None",
",",
"filter_words",
"=",
"None",
",",
"attributes",
"=",
"None",
")",
":",
"infiles",
"=",
"[",
"]",
"text",
"=",
"[",
"]",
"if",
"xpath",
"is",
"not",
"None",
":",
"infile",
"=",
"par... | Filter text using XPath, regex keywords, and tag attributes.
Keyword arguments:
infile -- HTML or text content to parse (list)
xpath -- an XPath expression (str)
filter_words -- regex keywords (list)
attributes -- HTML tag attributes (list)
Return a list of strings of text. | [
"Filter",
"text",
"using",
"XPath",
"regex",
"keywords",
"and",
"tag",
"attributes",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L214-L261 | train |
huntrar/scrape | scrape/utils.py | get_parsed_text | def get_parsed_text(args, infilename):
"""Parse and return text content of infiles.
Keyword arguments:
args -- program arguments (dict)
infilenames -- name of user-inputted and/or downloaded file (str)
Return a list of strings of text.
"""
parsed_text = []
if infilename.endswith('.html... | python | def get_parsed_text(args, infilename):
"""Parse and return text content of infiles.
Keyword arguments:
args -- program arguments (dict)
infilenames -- name of user-inputted and/or downloaded file (str)
Return a list of strings of text.
"""
parsed_text = []
if infilename.endswith('.html... | [
"def",
"get_parsed_text",
"(",
"args",
",",
"infilename",
")",
":",
"parsed_text",
"=",
"[",
"]",
"if",
"infilename",
".",
"endswith",
"(",
"'.html'",
")",
":",
"# Convert HTML to lxml object for content parsing",
"html",
"=",
"lh",
".",
"fromstring",
"(",
"read... | Parse and return text content of infiles.
Keyword arguments:
args -- program arguments (dict)
infilenames -- name of user-inputted and/or downloaded file (str)
Return a list of strings of text. | [
"Parse",
"and",
"return",
"text",
"content",
"of",
"infiles",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L264-L291 | train |
huntrar/scrape | scrape/utils.py | parse_html | def parse_html(infile, xpath):
"""Filter HTML using XPath."""
if not isinstance(infile, lh.HtmlElement):
infile = lh.fromstring(infile)
infile = infile.xpath(xpath)
if not infile:
raise ValueError('XPath {0} returned no results.'.format(xpath))
return infile | python | def parse_html(infile, xpath):
"""Filter HTML using XPath."""
if not isinstance(infile, lh.HtmlElement):
infile = lh.fromstring(infile)
infile = infile.xpath(xpath)
if not infile:
raise ValueError('XPath {0} returned no results.'.format(xpath))
return infile | [
"def",
"parse_html",
"(",
"infile",
",",
"xpath",
")",
":",
"if",
"not",
"isinstance",
"(",
"infile",
",",
"lh",
".",
"HtmlElement",
")",
":",
"infile",
"=",
"lh",
".",
"fromstring",
"(",
"infile",
")",
"infile",
"=",
"infile",
".",
"xpath",
"(",
"xp... | Filter HTML using XPath. | [
"Filter",
"HTML",
"using",
"XPath",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L309-L316 | train |
huntrar/scrape | scrape/utils.py | clean_url | def clean_url(url, base_url=None):
"""Add base netloc and path to internal URLs and remove www, fragments."""
parsed_url = urlparse(url)
fragment = '{url.fragment}'.format(url=parsed_url)
if fragment:
url = url.split(fragment)[0]
# Identify internal URLs and fix their format
netloc = '... | python | def clean_url(url, base_url=None):
"""Add base netloc and path to internal URLs and remove www, fragments."""
parsed_url = urlparse(url)
fragment = '{url.fragment}'.format(url=parsed_url)
if fragment:
url = url.split(fragment)[0]
# Identify internal URLs and fix their format
netloc = '... | [
"def",
"clean_url",
"(",
"url",
",",
"base_url",
"=",
"None",
")",
":",
"parsed_url",
"=",
"urlparse",
"(",
"url",
")",
"fragment",
"=",
"'{url.fragment}'",
".",
"format",
"(",
"url",
"=",
"parsed_url",
")",
"if",
"fragment",
":",
"url",
"=",
"url",
".... | Add base netloc and path to internal URLs and remove www, fragments. | [
"Add",
"base",
"netloc",
"and",
"path",
"to",
"internal",
"URLs",
"and",
"remove",
"www",
"fragments",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L348-L366 | train |
huntrar/scrape | scrape/utils.py | add_url_suffix | def add_url_suffix(url):
"""Add .com suffix to URL if none found."""
url = url.rstrip('/')
if not has_suffix(url):
return '{0}.com'.format(url)
return url | python | def add_url_suffix(url):
"""Add .com suffix to URL if none found."""
url = url.rstrip('/')
if not has_suffix(url):
return '{0}.com'.format(url)
return url | [
"def",
"add_url_suffix",
"(",
"url",
")",
":",
"url",
"=",
"url",
".",
"rstrip",
"(",
"'/'",
")",
"if",
"not",
"has_suffix",
"(",
"url",
")",
":",
"return",
"'{0}.com'",
".",
"format",
"(",
"url",
")",
"return",
"url"
] | Add .com suffix to URL if none found. | [
"Add",
".",
"com",
"suffix",
"to",
"URL",
"if",
"none",
"found",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L374-L379 | train |
huntrar/scrape | scrape/utils.py | get_outfilename | def get_outfilename(url, domain=None):
"""Construct the output filename from domain and end of path."""
if domain is None:
domain = get_domain(url)
path = '{url.path}'.format(url=urlparse(url))
if '.' in path:
tail_url = path.split('.')[-2]
else:
tail_url = path
if tail... | python | def get_outfilename(url, domain=None):
"""Construct the output filename from domain and end of path."""
if domain is None:
domain = get_domain(url)
path = '{url.path}'.format(url=urlparse(url))
if '.' in path:
tail_url = path.split('.')[-2]
else:
tail_url = path
if tail... | [
"def",
"get_outfilename",
"(",
"url",
",",
"domain",
"=",
"None",
")",
":",
"if",
"domain",
"is",
"None",
":",
"domain",
"=",
"get_domain",
"(",
"url",
")",
"path",
"=",
"'{url.path}'",
".",
"format",
"(",
"url",
"=",
"urlparse",
"(",
"url",
")",
")"... | Construct the output filename from domain and end of path. | [
"Construct",
"the",
"output",
"filename",
"from",
"domain",
"and",
"end",
"of",
"path",
"."
] | bf877f6da5df3ed0f2bea60a95acf7df63c88002 | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/utils.py#L385-L426 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.