repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
wiredrive/wtframework | wtframework/wtf/assets.py | AssetManager.get_asset_path | def get_asset_path(self, filename):
"""
Get the full system path of a given asset if it exists. Otherwise it throws
an error.
Args:
filename (str) - File name of a file in /assets folder to fetch the path for.
Returns:
str - path to the target file.
... | python | def get_asset_path(self, filename):
"""
Get the full system path of a given asset if it exists. Otherwise it throws
an error.
Args:
filename (str) - File name of a file in /assets folder to fetch the path for.
Returns:
str - path to the target file.
... | [
"def",
"get_asset_path",
"(",
"self",
",",
"filename",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"_asset_path",
",",
"filename",
")",
")",
":",
"return",
"os",
".",
"path",
".",
"join",... | Get the full system path of a given asset if it exists. Otherwise it throws
an error.
Args:
filename (str) - File name of a file in /assets folder to fetch the path for.
Returns:
str - path to the target file.
Raises:
AssetNotFoundError - if asset... | [
"Get",
"the",
"full",
"system",
"path",
"of",
"a",
"given",
"asset",
"if",
"it",
"exists",
".",
"Otherwise",
"it",
"throws",
"an",
"error",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/assets.py#L47-L70 |
wiredrive/wtframework | wtframework/wtf/web/webdriver.py | WebDriverFactory.create_webdriver | def create_webdriver(self, testname=None):
'''
Creates an instance of Selenium webdriver based on config settings.
This should only be called by a shutdown hook. Do not call directly within
a test.
Kwargs:
testname: Optional test name to pass, t... | python | def create_webdriver(self, testname=None):
'''
Creates an instance of Selenium webdriver based on config settings.
This should only be called by a shutdown hook. Do not call directly within
a test.
Kwargs:
testname: Optional test name to pass, t... | [
"def",
"create_webdriver",
"(",
"self",
",",
"testname",
"=",
"None",
")",
":",
"try",
":",
"driver_type",
"=",
"self",
".",
"_config_reader",
".",
"get",
"(",
"self",
".",
"DRIVER_TYPE_CONFIG",
")",
"except",
":",
"driver_type",
"=",
"self",
".",
"DRIVER_... | Creates an instance of Selenium webdriver based on config settings.
This should only be called by a shutdown hook. Do not call directly within
a test.
Kwargs:
testname: Optional test name to pass, this gets appended to the test name
sent ... | [
"Creates",
"an",
"instance",
"of",
"Selenium",
"webdriver",
"based",
"on",
"config",
"settings",
".",
"This",
"should",
"only",
"be",
"called",
"by",
"a",
"shutdown",
"hook",
".",
"Do",
"not",
"call",
"directly",
"within",
"a",
"test",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webdriver.py#L116-L161 |
wiredrive/wtframework | wtframework/wtf/web/webdriver.py | WebDriverFactory.__create_driver_from_browser_config | def __create_driver_from_browser_config(self):
'''
Reads the config value for browser type.
'''
try:
browser_type = self._config_reader.get(
WebDriverFactory.BROWSER_TYPE_CONFIG)
except KeyError:
_wtflog("%s missing is missing from config f... | python | def __create_driver_from_browser_config(self):
'''
Reads the config value for browser type.
'''
try:
browser_type = self._config_reader.get(
WebDriverFactory.BROWSER_TYPE_CONFIG)
except KeyError:
_wtflog("%s missing is missing from config f... | [
"def",
"__create_driver_from_browser_config",
"(",
"self",
")",
":",
"try",
":",
"browser_type",
"=",
"self",
".",
"_config_reader",
".",
"get",
"(",
"WebDriverFactory",
".",
"BROWSER_TYPE_CONFIG",
")",
"except",
"KeyError",
":",
"_wtflog",
"(",
"\"%s missing is mis... | Reads the config value for browser type. | [
"Reads",
"the",
"config",
"value",
"for",
"browser",
"type",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webdriver.py#L163-L195 |
wiredrive/wtframework | wtframework/wtf/web/webdriver.py | WebDriverFactory.__create_safari_driver | def __create_safari_driver(self):
'''
Creates an instance of Safari webdriver.
'''
# Check for selenium jar env file needed for safari driver.
if not os.getenv(self.__SELENIUM_SERVER_JAR_ENV):
# If not set, check if we have a config setting for it.
try:
... | python | def __create_safari_driver(self):
'''
Creates an instance of Safari webdriver.
'''
# Check for selenium jar env file needed for safari driver.
if not os.getenv(self.__SELENIUM_SERVER_JAR_ENV):
# If not set, check if we have a config setting for it.
try:
... | [
"def",
"__create_safari_driver",
"(",
"self",
")",
":",
"# Check for selenium jar env file needed for safari driver.",
"if",
"not",
"os",
".",
"getenv",
"(",
"self",
".",
"__SELENIUM_SERVER_JAR_ENV",
")",
":",
"# If not set, check if we have a config setting for it.",
"try",
... | Creates an instance of Safari webdriver. | [
"Creates",
"an",
"instance",
"of",
"Safari",
"webdriver",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webdriver.py#L198-L214 |
wiredrive/wtframework | wtframework/wtf/web/webdriver.py | WebDriverFactory.__create_phantom_js_driver | def __create_phantom_js_driver(self):
'''
Creates an instance of PhantomJS driver.
'''
try:
return webdriver.PhantomJS(executable_path=self._config_reader.get(self.PHANTOMEJS_EXEC_PATH),
service_args=['--ignore-ssl-errors=true'])
... | python | def __create_phantom_js_driver(self):
'''
Creates an instance of PhantomJS driver.
'''
try:
return webdriver.PhantomJS(executable_path=self._config_reader.get(self.PHANTOMEJS_EXEC_PATH),
service_args=['--ignore-ssl-errors=true'])
... | [
"def",
"__create_phantom_js_driver",
"(",
"self",
")",
":",
"try",
":",
"return",
"webdriver",
".",
"PhantomJS",
"(",
"executable_path",
"=",
"self",
".",
"_config_reader",
".",
"get",
"(",
"self",
".",
"PHANTOMEJS_EXEC_PATH",
")",
",",
"service_args",
"=",
"[... | Creates an instance of PhantomJS driver. | [
"Creates",
"an",
"instance",
"of",
"PhantomJS",
"driver",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webdriver.py#L216-L224 |
wiredrive/wtframework | wtframework/wtf/web/webdriver.py | WebDriverFactory.__create_remote_webdriver_from_config | def __create_remote_webdriver_from_config(self, testname=None):
'''
Reads the config value for browser type.
'''
desired_capabilities = self._generate_desired_capabilities(testname)
remote_url = self._config_reader.get(
WebDriverFactory.REMOTE_URL_CONFIG)
... | python | def __create_remote_webdriver_from_config(self, testname=None):
'''
Reads the config value for browser type.
'''
desired_capabilities = self._generate_desired_capabilities(testname)
remote_url = self._config_reader.get(
WebDriverFactory.REMOTE_URL_CONFIG)
... | [
"def",
"__create_remote_webdriver_from_config",
"(",
"self",
",",
"testname",
"=",
"None",
")",
":",
"desired_capabilities",
"=",
"self",
".",
"_generate_desired_capabilities",
"(",
"testname",
")",
"remote_url",
"=",
"self",
".",
"_config_reader",
".",
"get",
"(",
... | Reads the config value for browser type. | [
"Reads",
"the",
"config",
"value",
"for",
"browser",
"type",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webdriver.py#L226-L261 |
wiredrive/wtframework | wtframework/wtf/web/webdriver.py | WebDriverManager.clean_up_webdrivers | def clean_up_webdrivers(self):
'''
Clean up webdrivers created during execution.
'''
# Quit webdrivers.
_wtflog.info("WebdriverManager: Cleaning up webdrivers")
try:
if self.__use_shutdown_hook:
for key in self.__registered_drivers.keys():
... | python | def clean_up_webdrivers(self):
'''
Clean up webdrivers created during execution.
'''
# Quit webdrivers.
_wtflog.info("WebdriverManager: Cleaning up webdrivers")
try:
if self.__use_shutdown_hook:
for key in self.__registered_drivers.keys():
... | [
"def",
"clean_up_webdrivers",
"(",
"self",
")",
":",
"# Quit webdrivers.",
"_wtflog",
".",
"info",
"(",
"\"WebdriverManager: Cleaning up webdrivers\"",
")",
"try",
":",
"if",
"self",
".",
"__use_shutdown_hook",
":",
"for",
"key",
"in",
"self",
".",
"__registered_dri... | Clean up webdrivers created during execution. | [
"Clean",
"up",
"webdrivers",
"created",
"during",
"execution",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webdriver.py#L402-L419 |
wiredrive/wtframework | wtframework/wtf/web/webdriver.py | WebDriverManager.close_driver | def close_driver(self):
"""
Close current running instance of Webdriver.
Usage::
driver = WTF_WEBDRIVER_MANAGER.new_driver()
driver.get("http://the-internet.herokuapp.com")
WTF_WEBDRIVER_MANAGER.close_driver()
"""
channel = self.__get_channel... | python | def close_driver(self):
"""
Close current running instance of Webdriver.
Usage::
driver = WTF_WEBDRIVER_MANAGER.new_driver()
driver.get("http://the-internet.herokuapp.com")
WTF_WEBDRIVER_MANAGER.close_driver()
"""
channel = self.__get_channel... | [
"def",
"close_driver",
"(",
"self",
")",
":",
"channel",
"=",
"self",
".",
"__get_channel",
"(",
")",
"driver",
"=",
"self",
".",
"__get_driver_for_channel",
"(",
"channel",
")",
"if",
"self",
".",
"__config",
".",
"get",
"(",
"self",
".",
"REUSE_BROWSER",... | Close current running instance of Webdriver.
Usage::
driver = WTF_WEBDRIVER_MANAGER.new_driver()
driver.get("http://the-internet.herokuapp.com")
WTF_WEBDRIVER_MANAGER.close_driver() | [
"Close",
"current",
"running",
"instance",
"of",
"Webdriver",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webdriver.py#L421-L453 |
wiredrive/wtframework | wtframework/wtf/web/webdriver.py | WebDriverManager.get_driver | def get_driver(self):
'''
Get an already running instance of Webdriver. If there is none, it will create one.
Returns:
Webdriver - Selenium Webdriver instance.
Usage::
driver = WTF_WEBDRIVER_MANAGER.new_driver()
driver.get("http://the-internet.herok... | python | def get_driver(self):
'''
Get an already running instance of Webdriver. If there is none, it will create one.
Returns:
Webdriver - Selenium Webdriver instance.
Usage::
driver = WTF_WEBDRIVER_MANAGER.new_driver()
driver.get("http://the-internet.herok... | [
"def",
"get_driver",
"(",
"self",
")",
":",
"driver",
"=",
"self",
".",
"__get_driver_for_channel",
"(",
"self",
".",
"__get_channel",
"(",
")",
")",
"if",
"driver",
"is",
"None",
":",
"driver",
"=",
"self",
".",
"new_driver",
"(",
")",
"return",
"driver... | Get an already running instance of Webdriver. If there is none, it will create one.
Returns:
Webdriver - Selenium Webdriver instance.
Usage::
driver = WTF_WEBDRIVER_MANAGER.new_driver()
driver.get("http://the-internet.herokuapp.com")
same_driver = WTF_W... | [
"Get",
"an",
"already",
"running",
"instance",
"of",
"Webdriver",
".",
"If",
"there",
"is",
"none",
"it",
"will",
"create",
"one",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webdriver.py#L455-L473 |
wiredrive/wtframework | wtframework/wtf/web/webdriver.py | WebDriverManager.new_driver | def new_driver(self, testname=None):
'''
Used at a start of a test to get a new instance of WebDriver. If the
'resuebrowser' setting is true, it will use a recycled WebDriver instance
with delete_all_cookies() called.
Kwargs:
testname (str) - Optional test name to ... | python | def new_driver(self, testname=None):
'''
Used at a start of a test to get a new instance of WebDriver. If the
'resuebrowser' setting is true, it will use a recycled WebDriver instance
with delete_all_cookies() called.
Kwargs:
testname (str) - Optional test name to ... | [
"def",
"new_driver",
"(",
"self",
",",
"testname",
"=",
"None",
")",
":",
"channel",
"=",
"self",
".",
"__get_channel",
"(",
")",
"# Get reference for the current driver.",
"driver",
"=",
"self",
".",
"__get_driver_for_channel",
"(",
"channel",
")",
"if",
"self"... | Used at a start of a test to get a new instance of WebDriver. If the
'resuebrowser' setting is true, it will use a recycled WebDriver instance
with delete_all_cookies() called.
Kwargs:
testname (str) - Optional test name to pass to Selenium Grid. Helpful for
... | [
"Used",
"at",
"a",
"start",
"of",
"a",
"test",
"to",
"get",
"a",
"new",
"instance",
"of",
"WebDriver",
".",
"If",
"the",
"resuebrowser",
"setting",
"is",
"true",
"it",
"will",
"use",
"a",
"recycled",
"WebDriver",
"instance",
"with",
"delete_all_cookies",
"... | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webdriver.py#L488-L552 |
wiredrive/wtframework | wtframework/wtf/web/webdriver.py | WebDriverManager.__register_driver | def __register_driver(self, channel, webdriver):
"Register webdriver to a channel."
# Add to list of webdrivers to cleanup.
if not self.__registered_drivers.has_key(channel):
self.__registered_drivers[channel] = [] # set to new empty array
self.__registered_drivers[channel... | python | def __register_driver(self, channel, webdriver):
"Register webdriver to a channel."
# Add to list of webdrivers to cleanup.
if not self.__registered_drivers.has_key(channel):
self.__registered_drivers[channel] = [] # set to new empty array
self.__registered_drivers[channel... | [
"def",
"__register_driver",
"(",
"self",
",",
"channel",
",",
"webdriver",
")",
":",
"# Add to list of webdrivers to cleanup.",
"if",
"not",
"self",
".",
"__registered_drivers",
".",
"has_key",
"(",
"channel",
")",
":",
"self",
".",
"__registered_drivers",
"[",
"c... | Register webdriver to a channel. | [
"Register",
"webdriver",
"to",
"a",
"channel",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webdriver.py#L555-L565 |
wiredrive/wtframework | wtframework/wtf/web/webdriver.py | WebDriverManager.__unregister_driver | def __unregister_driver(self, channel):
"Unregister webdriver"
driver = self.__get_driver_for_channel(channel)
if self.__registered_drivers.has_key(channel) \
and driver in self.__registered_drivers[channel]:
self.__registered_drivers[channel].remove(driver)
... | python | def __unregister_driver(self, channel):
"Unregister webdriver"
driver = self.__get_driver_for_channel(channel)
if self.__registered_drivers.has_key(channel) \
and driver in self.__registered_drivers[channel]:
self.__registered_drivers[channel].remove(driver)
... | [
"def",
"__unregister_driver",
"(",
"self",
",",
"channel",
")",
":",
"driver",
"=",
"self",
".",
"__get_driver_for_channel",
"(",
"channel",
")",
"if",
"self",
".",
"__registered_drivers",
".",
"has_key",
"(",
"channel",
")",
"and",
"driver",
"in",
"self",
"... | Unregister webdriver | [
"Unregister",
"webdriver"
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webdriver.py#L567-L576 |
wiredrive/wtframework | wtframework/wtf/web/webdriver.py | WebDriverManager.__get_channel | def __get_channel(self):
"Get the channel to register webdriver to."
if self.__config.get(WebDriverManager.ENABLE_THREADING_SUPPORT, False):
channel = current_thread().ident
else:
channel = 0
return channel | python | def __get_channel(self):
"Get the channel to register webdriver to."
if self.__config.get(WebDriverManager.ENABLE_THREADING_SUPPORT, False):
channel = current_thread().ident
else:
channel = 0
return channel | [
"def",
"__get_channel",
"(",
"self",
")",
":",
"if",
"self",
".",
"__config",
".",
"get",
"(",
"WebDriverManager",
".",
"ENABLE_THREADING_SUPPORT",
",",
"False",
")",
":",
"channel",
"=",
"current_thread",
"(",
")",
".",
"ident",
"else",
":",
"channel",
"=... | Get the channel to register webdriver to. | [
"Get",
"the",
"channel",
"to",
"register",
"webdriver",
"to",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webdriver.py#L585-L592 |
wiredrive/wtframework | wtframework/wtf/web/capture.py | WebScreenShotUtil.take_screenshot | def take_screenshot(webdriver, file_name):
"""
Captures a screenshot.
Args:
webdriver (WebDriver) - Selenium webdriver.
file_name (str) - File name to save screenshot as.
"""
folder_location = os.path.join(ProjectUtils.get_project_root(),
... | python | def take_screenshot(webdriver, file_name):
"""
Captures a screenshot.
Args:
webdriver (WebDriver) - Selenium webdriver.
file_name (str) - File name to save screenshot as.
"""
folder_location = os.path.join(ProjectUtils.get_project_root(),
... | [
"def",
"take_screenshot",
"(",
"webdriver",
",",
"file_name",
")",
":",
"folder_location",
"=",
"os",
".",
"path",
".",
"join",
"(",
"ProjectUtils",
".",
"get_project_root",
"(",
")",
",",
"WebScreenShotUtil",
".",
"SCREEN_SHOT_LOCATION",
")",
"WebScreenShotUtil",... | Captures a screenshot.
Args:
webdriver (WebDriver) - Selenium webdriver.
file_name (str) - File name to save screenshot as. | [
"Captures",
"a",
"screenshot",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/capture.py#L34-L47 |
wiredrive/wtframework | wtframework/wtf/web/capture.py | WebScreenShotUtil.take_reference_screenshot | def take_reference_screenshot(webdriver, file_name):
"""
Captures a screenshot as a reference screenshot.
Args:
webdriver (WebDriver) - Selenium webdriver.
file_name (str) - File name to save screenshot as.
"""
folder_location = os.path.join(ProjectUtils.... | python | def take_reference_screenshot(webdriver, file_name):
"""
Captures a screenshot as a reference screenshot.
Args:
webdriver (WebDriver) - Selenium webdriver.
file_name (str) - File name to save screenshot as.
"""
folder_location = os.path.join(ProjectUtils.... | [
"def",
"take_reference_screenshot",
"(",
"webdriver",
",",
"file_name",
")",
":",
"folder_location",
"=",
"os",
".",
"path",
".",
"join",
"(",
"ProjectUtils",
".",
"get_project_root",
"(",
")",
",",
"WebScreenShotUtil",
".",
"REFERENCE_SCREEN_SHOT_LOCATION",
")",
... | Captures a screenshot as a reference screenshot.
Args:
webdriver (WebDriver) - Selenium webdriver.
file_name (str) - File name to save screenshot as. | [
"Captures",
"a",
"screenshot",
"as",
"a",
"reference",
"screenshot",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/capture.py#L50-L62 |
wiredrive/wtframework | wtframework/wtf/web/capture.py | WebScreenShotUtil.__capture_screenshot | def __capture_screenshot(webdriver, folder_location, file_name):
"Capture a screenshot"
# Check folder location exists.
if not os.path.exists(folder_location):
os.makedirs(folder_location)
file_location = os.path.join(folder_location, file_name)
if isinstance(webdri... | python | def __capture_screenshot(webdriver, folder_location, file_name):
"Capture a screenshot"
# Check folder location exists.
if not os.path.exists(folder_location):
os.makedirs(folder_location)
file_location = os.path.join(folder_location, file_name)
if isinstance(webdri... | [
"def",
"__capture_screenshot",
"(",
"webdriver",
",",
"folder_location",
",",
"file_name",
")",
":",
"# Check folder location exists.",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"folder_location",
")",
":",
"os",
".",
"makedirs",
"(",
"folder_location",
... | Capture a screenshot | [
"Capture",
"a",
"screenshot"
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/capture.py#L65-L83 |
wiredrive/wtframework | wtframework/wtf/utils/project_utils.py | ProjectUtils.get_project_root | def get_project_root(cls):
'''
Return path of the project directory. Use this method for getting paths relative to the project.
However, for data, it's recommended you use WTF_DATA_MANAGER and for assets it's recommended
to use WTF_ASSET_MANAGER, which are already singleton instances t... | python | def get_project_root(cls):
'''
Return path of the project directory. Use this method for getting paths relative to the project.
However, for data, it's recommended you use WTF_DATA_MANAGER and for assets it's recommended
to use WTF_ASSET_MANAGER, which are already singleton instances t... | [
"def",
"get_project_root",
"(",
"cls",
")",
":",
"if",
"(",
"cls",
".",
"__root_folder__",
"!=",
"None",
")",
":",
"return",
"cls",
".",
"__root_folder__",
"# Check for enviornment variable override.",
"try",
":",
"cls",
".",
"__root_folder__",
"=",
"os",
".",
... | Return path of the project directory. Use this method for getting paths relative to the project.
However, for data, it's recommended you use WTF_DATA_MANAGER and for assets it's recommended
to use WTF_ASSET_MANAGER, which are already singleton instances that manger the /data, and /assets
fold... | [
"Return",
"path",
"of",
"the",
"project",
"directory",
".",
"Use",
"this",
"method",
"for",
"getting",
"paths",
"relative",
"to",
"the",
"project",
".",
"However",
"for",
"data",
"it",
"s",
"recommended",
"you",
"use",
"WTF_DATA_MANAGER",
"and",
"for",
"asse... | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/utils/project_utils.py#L38-L75 |
wiredrive/wtframework | wtframework/wtf/utils/wait_utils.py | do_until | def do_until(lambda_expr, timeout=WTF_TIMEOUT_MANAGER.NORMAL, sleep=0.5, message=None):
'''
A retry wrapper that'll keep performing the action until it succeeds.
(main differnce between do_until and wait_until is do_until will keep trying
until a value is returned, while wait until will wait until the ... | python | def do_until(lambda_expr, timeout=WTF_TIMEOUT_MANAGER.NORMAL, sleep=0.5, message=None):
'''
A retry wrapper that'll keep performing the action until it succeeds.
(main differnce between do_until and wait_until is do_until will keep trying
until a value is returned, while wait until will wait until the ... | [
"def",
"do_until",
"(",
"lambda_expr",
",",
"timeout",
"=",
"WTF_TIMEOUT_MANAGER",
".",
"NORMAL",
",",
"sleep",
"=",
"0.5",
",",
"message",
"=",
"None",
")",
":",
"__check_condition_parameter_is_function",
"(",
"lambda_expr",
")",
"end_time",
"=",
"datetime",
".... | A retry wrapper that'll keep performing the action until it succeeds.
(main differnce between do_until and wait_until is do_until will keep trying
until a value is returned, while wait until will wait until the function
evaluates True.)
Args:
lambda_expr (lambda) : Expression to evaluate.
... | [
"A",
"retry",
"wrapper",
"that",
"ll",
"keep",
"performing",
"the",
"action",
"until",
"it",
"succeeds",
".",
"(",
"main",
"differnce",
"between",
"do_until",
"and",
"wait_until",
"is",
"do_until",
"will",
"keep",
"trying",
"until",
"a",
"value",
"is",
"retu... | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/utils/wait_utils.py#L39-L88 |
wiredrive/wtframework | wtframework/wtf/utils/wait_utils.py | wait_and_ignore | def wait_and_ignore(condition, timeout=WTF_TIMEOUT_MANAGER.NORMAL, sleep=0.5):
'''
Waits wrapper that'll wait for the condition to become true, but will
not error if the condition isn't met.
Args:
condition (lambda) - Lambda expression to wait for to evaluate to True.
Kwargs:
time... | python | def wait_and_ignore(condition, timeout=WTF_TIMEOUT_MANAGER.NORMAL, sleep=0.5):
'''
Waits wrapper that'll wait for the condition to become true, but will
not error if the condition isn't met.
Args:
condition (lambda) - Lambda expression to wait for to evaluate to True.
Kwargs:
time... | [
"def",
"wait_and_ignore",
"(",
"condition",
",",
"timeout",
"=",
"WTF_TIMEOUT_MANAGER",
".",
"NORMAL",
",",
"sleep",
"=",
"0.5",
")",
":",
"try",
":",
"return",
"wait_until",
"(",
"condition",
",",
"timeout",
",",
"sleep",
")",
"except",
":",
"pass"
] | Waits wrapper that'll wait for the condition to become true, but will
not error if the condition isn't met.
Args:
condition (lambda) - Lambda expression to wait for to evaluate to True.
Kwargs:
timeout (number) : Maximum number of seconds to wait.
sleep (number) : Sleep time to wa... | [
"Waits",
"wrapper",
"that",
"ll",
"wait",
"for",
"the",
"condition",
"to",
"become",
"true",
"but",
"will",
"not",
"error",
"if",
"the",
"condition",
"isn",
"t",
"met",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/utils/wait_utils.py#L91-L123 |
wiredrive/wtframework | wtframework/wtf/utils/wait_utils.py | wait_until | def wait_until(condition, timeout=WTF_TIMEOUT_MANAGER.NORMAL, sleep=0.5, pass_exceptions=False, message=None):
'''
Waits wrapper that'll wait for the condition to become true.
(main differnce between do_until and wait_until is do_until will keep trying
until a value is returned, while wait until will w... | python | def wait_until(condition, timeout=WTF_TIMEOUT_MANAGER.NORMAL, sleep=0.5, pass_exceptions=False, message=None):
'''
Waits wrapper that'll wait for the condition to become true.
(main differnce between do_until and wait_until is do_until will keep trying
until a value is returned, while wait until will w... | [
"def",
"wait_until",
"(",
"condition",
",",
"timeout",
"=",
"WTF_TIMEOUT_MANAGER",
".",
"NORMAL",
",",
"sleep",
"=",
"0.5",
",",
"pass_exceptions",
"=",
"False",
",",
"message",
"=",
"None",
")",
":",
"__check_condition_parameter_is_function",
"(",
"condition",
... | Waits wrapper that'll wait for the condition to become true.
(main differnce between do_until and wait_until is do_until will keep trying
until a value is returned, while wait until will wait until the function
evaluates True.)
Args:
condition (lambda) - Lambda expression to wait for to evalu... | [
"Waits",
"wrapper",
"that",
"ll",
"wait",
"for",
"the",
"condition",
"to",
"become",
"true",
".",
"(",
"main",
"differnce",
"between",
"do_until",
"and",
"wait_until",
"is",
"do_until",
"will",
"keep",
"trying",
"until",
"a",
"value",
"is",
"returned",
"whil... | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/utils/wait_utils.py#L125-L187 |
wiredrive/wtframework | wtframework/wtf/email.py | IMapEmailAccountObject.check_email_exists_by_subject | def check_email_exists_by_subject(self, subject, match_recipient=None):
"""
Searches for Email by Subject. Returns True or False.
Args:
subject (str): Subject to search for.
Kwargs:
match_recipient (str) : Recipient to match exactly. (don't care if not specifie... | python | def check_email_exists_by_subject(self, subject, match_recipient=None):
"""
Searches for Email by Subject. Returns True or False.
Args:
subject (str): Subject to search for.
Kwargs:
match_recipient (str) : Recipient to match exactly. (don't care if not specifie... | [
"def",
"check_email_exists_by_subject",
"(",
"self",
",",
"subject",
",",
"match_recipient",
"=",
"None",
")",
":",
"# Select inbox to fetch the latest mail on server.",
"self",
".",
"_mail",
".",
"select",
"(",
"\"inbox\"",
")",
"try",
":",
"matches",
"=",
"self",
... | Searches for Email by Subject. Returns True or False.
Args:
subject (str): Subject to search for.
Kwargs:
match_recipient (str) : Recipient to match exactly. (don't care if not specified)
Returns:
True - email found, False - email not found | [
"Searches",
"for",
"Email",
"by",
"Subject",
".",
"Returns",
"True",
"or",
"False",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/email.py#L65-L89 |
wiredrive/wtframework | wtframework/wtf/email.py | IMapEmailAccountObject.find_emails_by_subject | def find_emails_by_subject(self, subject, limit=50, match_recipient=None):
"""
Searches for Email by Subject. Returns email's imap message IDs
as a list if matching subjects is found.
Args:
subject (str) - Subject to search for.
Kwargs:
limit (int) - L... | python | def find_emails_by_subject(self, subject, limit=50, match_recipient=None):
"""
Searches for Email by Subject. Returns email's imap message IDs
as a list if matching subjects is found.
Args:
subject (str) - Subject to search for.
Kwargs:
limit (int) - L... | [
"def",
"find_emails_by_subject",
"(",
"self",
",",
"subject",
",",
"limit",
"=",
"50",
",",
"match_recipient",
"=",
"None",
")",
":",
"# Select inbox to fetch the latest mail on server.",
"self",
".",
"_mail",
".",
"select",
"(",
"\"inbox\"",
")",
"matching_uids",
... | Searches for Email by Subject. Returns email's imap message IDs
as a list if matching subjects is found.
Args:
subject (str) - Subject to search for.
Kwargs:
limit (int) - Limit search to X number of matches, default 50
match_recipient (str) - Recipient to... | [
"Searches",
"for",
"Email",
"by",
"Subject",
".",
"Returns",
"email",
"s",
"imap",
"message",
"IDs",
"as",
"a",
"list",
"if",
"matching",
"subjects",
"is",
"found",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/email.py#L91-L113 |
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",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/email.py#L115-L137 |
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",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/email.py#L139-L188 |
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"
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/email.py#L190-L219 |
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",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/config.py#L82-L124 |
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"
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/_devtools_/page_object_tools.py#L139-L177 |
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",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/data/data_management.py#L65-L94 |
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",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/data/data_management.py#L133-L152 |
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",
... | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webelement.py#L33-L70 |
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",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webelement.py#L89-L114 |
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",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/web/webelement.py#L117-L131 |
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",
"..."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/utils/data_utils.py#L28-L51 |
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",
"."
] | train | https://github.com/wiredrive/wtframework/blob/ef7f86c4d4cf7fb17745fd627b3cc4a41f4c0216/wtframework/wtf/utils/data_utils.py#L65-L74 |
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",
"()",
"."
] | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L87-L99 |
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",
"."
] | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L320-L342 |
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",
"."
] | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L357-L367 |
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",
"."
] | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L370-L383 |
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",
"."
] | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L385-L398 |
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... | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L404-L422 |
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",
"."
] | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L424-L436 |
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",
"."
] | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L438-L445 |
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",
"."
] | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L447-L532 |
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",
"."
] | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L559-L584 |
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",
... | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L592-L601 |
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",
"."
] | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L722-L732 |
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",
"."
] | train | https://github.com/chrisspen/weka/blob/c86fc4b8eef1afd56f89ec28283bdf9e2fdc453b/weka/arff.py#L746-L750 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L249-L295 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L307-L344 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L346-L385 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L387-L428 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L430-L457 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L459-L485 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L487-L514 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L516-L542 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L544-L580 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L582-L612 |
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",
"*",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L614-L655 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L657-L688 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L690-L716 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L718-L745 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L747-L770 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L772-L795 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L797-L820 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L822-L845 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L847-L867 |
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",
")",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L869-L912 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L914-L935 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L937-L956 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L958-L990 |
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"
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L992-L1020 |
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"
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1022-L1047 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1049-L1067 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1069-L1087 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1123-L1147 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1150-L1174 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1177-L1202 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1205-L1229 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1232-L1256 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1259-L1283 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1286-L1314 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1317-L1341 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1344-L1370 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1373-L1401 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1404-L1424 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1707-L1744 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1867-L1885 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1895-L1912 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L1914-L1937 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L2089-L2127 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L2129-L2160 |
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",
"."
] | train | https://github.com/xav/Grapefruit/blob/b3d88375be727a3a1ec5839fbc462e0e8e0836e4/grapefruit.py#L2162-L2183 |
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",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L19-L71 |
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",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L74-L94 |
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",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L97-L139 |
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",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L142-L190 |
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",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L193-L201 |
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",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L204-L211 |
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",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L214-L257 |
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",
"."
] | train | https://github.com/huntrar/scrape/blob/bf877f6da5df3ed0f2bea60a95acf7df63c88002/scrape/scrape.py#L260-L272 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.