Search is not available for this dataset
text stringlengths 75 104k |
|---|
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 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_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_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_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_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 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 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 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 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 __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 __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 __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 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_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 __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 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 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 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_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 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 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 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 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 __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 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 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 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 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 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 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 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 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_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 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 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 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 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 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 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 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 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 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(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 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 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 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 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 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 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 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 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 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 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 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 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 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_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 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 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 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 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 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 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 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 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 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 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 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 _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 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_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_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 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 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_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_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_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_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_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_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_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_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_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_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 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 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 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 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 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 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 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 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 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_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_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 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 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 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 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)... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.