output stringlengths 1 928k | instruction stringlengths 7 928k | system stringlengths 0 104k |
|---|---|---|
def is_present(self, locator, search_object=None):
"""
Determines whether an element is present on the page, retrying once if unable to locate
@type locator: webdriverwrapper.support.locator.Locator
@param locator: the locator or css string used to query... | Can you write a function in Python 3 where it
determines if an element is present on the page retrying once if unable to locate | You are a Python code generator, capable of creating scripts from specifications. |
def is_present_no_wait(self, locator):
"""
Determines whether an element is present on the page with no wait
@type locator: webdriverwrapper.support.locator.Locator
@param locator: the locator or css string used to query the element
"""
# first attempt to locate the el... | Can you create a Python 3 function that
determines whether an element is present on the page with no wait. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Base wait method that executes wait_function and returns True | Can you generate the documentation for the following Python 3 function
def wait_until(self, wait_function, failure_message=None, timeout=None):
timeout = timeout if timeout is not None else self.timeout
failure_message = failure_message if failure_message is not None else \
'Timeout waiting ... | As a python code expert, you are capable of creating scripts from specifications. |
Waits until an element is present | Can you tell what is the following Python 3 function doing
def wait_until_present(self, locator, timeout=None, failure_message='Timeout waiting for element to be present'):
timeout = timeout if timeout is not None else self.timeout
def wait():
'''
Wait function passed to executo... | As a Python code composer, you craft elegant and concise scripts. |
Wait until an element with the given locator is not present. | Here you have a function in Python 3, explain what it does
def wait_until_not_present(self, locator, timeout=None):
# TODO: rethink about neg case with is_present and waiting too long
timeout = timeout if timeout is not None else self.timeout
this = self # for passing WebDriverWrapperReference ... | As a Python code composer, you craft elegant and concise scripts. |
def wait_until_invisibility_of(self, locator, timeout=None):
"""
Waits for an element to be invisible
@type locator: webdriverwrapper.support.locator.Locator
@param locator: the locator or css string to search for the element
@type timeout: int
@param timeout: the max... | Write a Python 3 script to
wait until an element is invisible | As a Python code analyst, you investigate and solve complex coding mysteries |
def wait_until_clickable(self, locator, timeout=None):
"""
Waits for an element to be clickable
@type locator: webdriverwrapper.support.locator.Locator
@param locator: the locator or css string to search for the element
@type timeout: int
@param timeout: the maximum n... | Create a Python 3 function for
waiting for an element to be clickable | You are a Python code generator, capable of creating scripts from specifications. |
Waits until an element is found in the DOM and returns the element found
. | Given the following Python 3 function, write the documentation
def wait_until_stale(self, locator, timeout=None):
timeout = timeout if timeout is not None else self.timeout
def wait():
'''
Wait function passed to executor
'''
element = WebDriverWait(self.... | As a python code expert, you are capable of creating scripts from specifications. |
Waits until the title contains the partial_title | Make a summary of the following Python 3 code
def wait_until_title_contains(self, partial_title, timeout=None):
timeout = timeout if timeout is not None else self.timeout
def wait():
'''
Wait function passed to executor
'''
return WebDriverWait(self.drive... | You are a Python code architect, reviewing and designing scalable and efficient code |
Waits until the title is exactly the given one. | Can you generate a brief explanation for the following Python 3 code
def wait_until_title_is(self, title, timeout=None):
timeout = timeout if timeout is not None else self.timeout
def wait():
'''
Wait function passed to executor
'''
return WebDriverWait(s... | As a Python code analyst, you investigate and solve complex coding mysteries |
Waits until an alert is present in the element | Here you have a function in Python 3, explain what it does
def wait_until_alert_is_present(self, timeout=None):
timeout = timeout if timeout is not None else self.timeout
locator = None
def wait():
'''
Wait function passed to executor
'''
return W... | As a Python code analyst, you investigate and solve complex coding mysteries |
def wait_until_text_contains(self, locator, text, timeout=None):
"""
Waits for an element's text to contain <text>
@type locator: webdriverwrapper.support.locator.Locator
@param locator: locator used to find element
@type text: str
@param tex... | How would you implement a function in Python 3 that
waits for an element s text to contain text | As a Python code analyst, you investigate and solve complex coding mysteries |
def wait_until_text_is_not_empty(self, locator, timeout=None):
"""
Waits for an element's text to not be empty
@type locator: webdriverwrapper.support.locator.Locator
@param locator: locator used to find element
@type timeout: int
@param timeout... | Write a Python 3 function for
waiting for an element s text to not be empty | You are a Python code generator, capable of creating scripts from specifications. |
def wait_until_page_source_contains(self, text, timeout=None):
"""
Waits for the page source to contain <text>
@type text: str
@param text: the text to search for
@type timeout: int
@param timeout: the maximum number of seconds the... | How would you code a function in Python 3 to
wait until the page source contains the given text. | As a Python code analyst, you investigate and solve complex coding mysteries |
Waits until all jQuery AJAX requests are closed | Can you generate a brief explanation for the following Python 3 code
def wait_until_jquery_requests_are_closed(self, timeout=None):
timeout = timeout if timeout is not None else self.timeout
def wait():
'''
Wait function passed to executor
'''
WebDriverWa... | As a python code expert, you are capable of creating scripts from specifications. |
Execute a function and handle any exceptions raised by the action callbacks. | How would you explain what the following Python 3 function does
def execute_and_handle_webdriver_exceptions(self, function_to_execute, timeout=None, locator=None, failure_message=None):
logger = logging.getLogger(__name__)
try:
val = function_to_execute()
for cb in self.action_ca... | You are a Python code analyst, evaluating scripts for potential improvements. |
Injects a radio button into the page and waits for the user to click it. | Explain what the following Python 3 code does
def pause_and_wait_for_user(self, timeout=None, prompt_text='Click to resume (WebDriver is paused)'):
timeout = timeout if timeout is not None else self.user_wait_timeout
# Set the browser state paused
self.paused = True
def check_user_ready... | As a Python code composer, you craft elegant and concise scripts. |
Gets the console log of the browser | Can you generate a brief explanation for the following Python 3 code
def get_browser_log(self, levels=None):
logs = self.driver.get_log('browser')
self.browser_logs += logs
if levels is not None:
logs = [entry for entry in logs if entry.get(u'level') in levels]
return logs | You are a Python code architect, reviewing and designing scalable and efficient code |
def quit(self):
"""Close driver and kill all associated displays
"""
# Kill the driver
def _quit():
try:
self.driver.quit()
except Exception, err_driver:
os.kill(self.driver_pid, signal.SIGKILL)
raise
f... | Can you write a function in Python 3 where it
closes driver and kill all associated displays | As a python code expert, you are capable of creating scripts from specifications. |
def visit(self, url=''):
"""Visit the url, checking for rr errors in the response
@param url: URL
@return: Visit result
"""
result = super(CoyoteDriver, self).visit(url)
source = self.page_source()
return result | How would you code a function in Python 3 to
visit the url checking for rr errors in the response | As a python code expert, you are capable of creating scripts from specifications. |
Loads all attributes from source config into target config | Here you have a function in Python 3, explain what it does
def load_config_vars(target_config, source_config):
# Overwrite all attributes in config with new config
for attr in dir(source_config):
# skip all private class attrs
if attr.startswith('_'):
continue
val = getattr(s... | You are a Python code architect, reviewing and designing scalable and efficient code |
def _readall(self):
"""Read configs from all available configs. It will read files in the following order:
1.) Read all default settings:
These are located under: `<project_root>/config/*/default.cfg`
2.) Read the user's config settings:
This is locate... | Write a Python 3 function that can
read all available config files and return a dict of all the config files. | You are a Python code architect, reviewing and designing scalable and efficient code |
Runs a series of functions in parallel. | Given the following Python 3 function, write the documentation
def run_parallel(*functions):
def target(fn):
def wrapped(results_queue, error_queue, index):
result = None
try:
result = fn()
except Exception, e: # Swallow errors or else the process will ha... | You are a Python code architect, reviewing and designing scalable and efficient code |
def copy_and_update(dictionary, update):
"""Returns an updated copy of the dictionary without modifying the original"""
newdict = dictionary.copy()
newdict.update(update)
return newdict | How would you implement a function in Python 3 that
returns an updated copy of the dictionary without modifying the original | You are a Python code architect, reviewing and designing scalable and efficient code |
Retrieves the full path of the static directory | Here you have a function in Python 3, explain what it does
def get_static_directory():
directory = templates_dir = os.path.join(os.path.dirname(__file__), 'static')
return directory | You are a Python code analyst, evaluating scripts for potential improvements. |
def read_html_file(filename):
"""Reads the contents of an html file in the css directory
@return: Contents of the specified file
"""
with open(os.path.join(get_static_directory(), 'html/{filename}'.format(filename=filename))) as f:
contents = f.read()
return contents | Can you create a Python 3 function that
reads the contents of an html file in the css directory | You are a Python code generator, capable of creating scripts from specifications. |
Parses a valid selenium By and value from a locator ; returns as a named tuple with properties By and Value | Can you tell what is the following Python 3 function doing
def parse_locator(locator):
# handle backwards compatibility to support new Locator class
if isinstance(locator, loc.Locator):
locator = '{by}={locator}'.format(by=locator.by, locator=locator.locator)
locator_tuple = namedt... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Locate an element using a given locator | Here you have a function in Python 3, explain what it does
def find_by_locator(webdriver_or_element, locator, find_all_elements=False):
# handle backwards compatibility to support new Locator class
if isinstance(locator, loc.Locator):
locator = '{by}={locator}'.format(by=locator.by, locator=... | You are a Python code architect, reviewing and designing scalable and efficient code |
def spin_assert(self, assertion, failure_message='Failed Assertion', timeout=None):
"""
Asserts that assertion function passed to it will return True,
trying every 'step' seconds until 'timeout' seconds have passed.
"""
timeout = self.timeout if timeout is None else timeout
... | Create a Python 3 function to
spin a given assertion function until it returns True. | You are a Python code generator, capable of creating scripts from specifications. |
Assert the assertion and throw a WebDriverAssertionException | Given the following Python 3 function, write the documentation
def webdriver_assert(self, assertion, failure_message='Failed Assertion'):
try:
assert assertion() is True
except AssertionError:
raise WebDriverAssertionException.WebDriverAssertionException(self.driver_wrapper, fail... | As a Python code analyst, you investigate and solve complex coding mysteries |
def assert_true(self, value, failure_message='Expected value to be True, was: {}'):
"""
Asserts that a value is true
@type value: bool
@param value: value to test for True
"""
assertion = lambda: bool(value)
self.webdriver_assert(assertion, unicode(failure_m... | Implement a Python 3 function for
testing that a value is true for the current language. | You are a Python code generator, capable of creating scripts from specifications. |
Calls smart_assert but creates a closure that calls it with the expected and provided values with the == operator. | Can you generate the documentation for the following Python 3 function
def assert_equals(self, actual_val, expected_val, failure_message='Expected values to be equal: "{}" and "{}"'):
assertion = lambda: expected_val == actual_val
self.webdriver_assert(assertion, unicode(failure_message).format(actual_v... | You are a Python code generator, capable of creating scripts from specifications. |
def assert_numbers_almost_equal(self, actual_val, expected_val, allowed_delta=0.0001,
failure_message='Expected numbers to be within {} of each other: "{}" and "{}"'):
"""
Asserts that two numbers are within an allowed delta of each other
"""
assertion... | Create a Python 3 function to
test that two numbers are within an allowed delta of each other. | You are a Python code analyst, evaluating scripts for potential improvements. |
def assert_not_equal(self, actual_val, unexpected_val, failure_message='Expected values to differ: "{}" and "{}"'):
"""
Calls smart_assert, but creates its own assertion closure using
the expected and provided values with the '!=' operator
"""
assertion = lambda: unexpected_val !... | Write a Python 3 script for
calling smart_assert but creates a closure that does not compare the expected and provided values. | You are a Python code generator, capable of creating scripts from specifications. |
Calls smart_assert but creates a closure that calls it with the expected and provided values with the is operator. | Explain what the following Python 3 code does
def assert_is(self, actual_val, expected_type, failure_message='Expected type to be "{1}," but was "{0}"'):
assertion = lambda: expected_type is actual_val
self.webdriver_assert(assertion, unicode(failure_message).format(actual_val, expected_type)) | As a Python code translator, you convert algorithms and pseudocode into Python. |
def assert_is_not(self, actual_val, unexpected_type,
failure_message='Expected type not to be "{1}," but was "{0}"'):
"""
Calls smart_assert, but creates its own assertion closure using
the expected and provided values with the 'is not' operator
"""
assertio... | How would you code a function in Python 3 to
call smart_assert but creates a closure that calls it with the expected and provided values with the is not operator. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Calls smart_assert but creates a closure that calls smart_assert with the expected and provided values with the in operator | Can you tell what is the following Python 3 function doing
def assert_in(self, actual_collection_or_string, expected_value, failure_message='Expected "{1}" to be in "{0}"'):
assertion = lambda: expected_value in actual_collection_or_string
self.webdriver_assert(assertion, unicode(failure_message).format... | You are a Python code generator, capable of creating scripts from specifications. |
def assert_not_in(self, actual_collection_or_string, unexpected_value,
failure_message='Expected "{1}" not to be in "{0}"'):
"""
Calls smart_assert, but creates its own assertion closure using
the expected and provided values with the 'not in' operator
"""
a... | Implement a Python 3 function for
calling smart_assert but creates a closure that calls smart_assert with the expected and provided values with the not in operator | As a Python code translator, you convert algorithms and pseudocode into Python. |
def assert_page_source_contains(self, expected_value, failure_message='Expected page source to contain: "{}"'):
"""
Asserts that the page source contains the string passed in expected_value
"""
assertion = lambda: expected_value in self.driver_wrapper.page_source()
self.webdriver... | Implement a function in Python 3 to
test that the page source contains the string passed in expected_value | As a python code expert, you are capable of creating scripts from specifications. |
Assert that the union of two collections is not empty | Make a summary of the following Python 3 code
def assert_union(self, collection1, collection2,
failure_message='Expected overlap between collections: "{}" and "{}"'):
"""
Asserts that the union of two sets has at least one member (collections share at least one member)
"""
... | As a python code expert, you are capable of creating scripts from specifications. |
Assert that the union of two collections is empty | Can you generate the documentation for the following Python 3 function
def assert_no_union(self, collection1, collection2,
failure_message='Expected no overlap between collections: "{}" and "{}"'):
"""
Asserts that the union of two sets is empty (collections are unique)
"... | As a Python code composer, you craft elegant and concise scripts. |
Assert that a superset contains all elements of a subset of a set | Can you tell what is the following Python 3 function doing
def assert_subset(self, subset, superset, failure_message='Expected collection "{}" to be a subset of "{}'):
assertion = lambda: set(subset).issubset(set(superset))
failure_message = unicode(failure_message).format(superset, subset)
self... | As a python code expert, you are capable of creating scripts from specifications. |
Clears the field represented by this element and returns itself. | Here you have a function in Python 3, explain what it does
def clear(self):
def clear_element():
"""
Wrapper to clear element
"""
return self.element.clear()
self.execute_and_handle_webelement_exceptions(clear_element, 'clear')
return self | As a Python code analyst, you investigate and solve complex coding mysteries |
Deletes content in the input field by repeatedly typing HOME then DELETE. | Here you have a function in Python 3, explain what it does
def delete_content(self, max_chars=100):
def delete_content_element():
chars_deleted = 0
while len(self.get_attribute('value')) > 0 and chars_deleted < max_chars:
self.click()
self.send_keys(Keys.H... | As a python code expert, you are capable of creating scripts from specifications. |
def click(self, force_click=False):
"""
Clicks the element
@type force_click: bool
@param force_click: force a click on the element using javascript, skipping webdriver
@rtype: WebElementWrapper
@return: Returns itself
"""
js_exec... | Implement a function in Python 3 to
click the element using javascript | As a python code expert, you are capable of creating scripts from specifications. |
Gets the value of the element with the specified name. | Given the following Python 3 function, write the documentation
def get_value(self):
def get_element_value():
if self.tag_name() == 'input':
return self.get_attribute('value')
elif self.tag_name() == 'select':
selected_options = self.element.all_selected_op... | As a python code expert, you are capable of creating scripts from specifications. |
Retrieves specified attribute from WebElement
| Make a summary of the following Python 3 code
def get_attribute(self, name):
def get_attribute_element():
"""
Wrapper to retrieve element
"""
return self.element.get_attribute(name)
return self.execute_and_handle_webelement_exceptions(get_attribute_element... | As a Python code composer, you craft elegant and concise scripts. |
Tests if the element is on the screen. | How would you explain what the following Python 3 function does
def is_on_screen(self):
width = self.get_width()
height = self.get_height()
loc = self.location()
el_x_left = loc['x']
el_x_right = el_x_left + width
el_y_top = loc['y']
el_y_bottom = el_y_top + heigh... | As a Python code translator, you convert algorithms and pseudocode into Python. |
def send_special_keys(self, value):
"""
Send special keys such as <enter> or <delete>
@rtype: WebElementWrapper
@return: Self
"""
def send_keys_element():
"""
Wrapper to send keys
"""
return self.element.send_keys(va... | Write a Python 3 function that can
send special keys such as enter delete or delete. | You are a Python code architect, reviewing and designing scalable and efficient code |
def set(self, val, force_set=False):
"""
Sets an input with a specified value; if force_set=True, will set through javascript if webdriver fails
NOTE: if val is None, this function will interpret this to be an empty string
@type val: str
@param val: string to se... | Create a Python 3 function for
setting an input with a specified value. | You are a Python code analyst, evaluating scripts for potential improvements. |
Submit a webe element and return the self. | Given the following Python 3 function, write the documentation
def submit(self):
def submit_element():
"""
Wrapper to submit element
"""
return self.element.submit()
self.execute_and_handle_webelement_exceptions(submit_element, 'send keys')
return ... | As a Python code composer, you craft elegant and concise scripts. |
Gets the value of a CSS property for the element | Can you generate a brief explanation for the following Python 3 code
def value_of_css_property(self, property_name):
def value_of_css_property_element():
"""
Wrapper to get css property
"""
return self.element.value_of_css_property(property_name)
return se... | As a python code expert, you are capable of creating scripts from specifications. |
def has_class(self, classname):
"""Test if an element has a specific classname
@type classname: str
@param classname: Classname to test for; cannot contain spaces
@rtype: bool
@return: True if classname exists; false otherwise
"""
def element_has_class():
... | Can you create a Python 3 function that
tests if an element has a specific classname ; cannot contain spaces | As a Python code composer, you craft elegant and concise scripts. |
Get the parent of the element | Can you tell what is the following Python 3 function doing
def parent(self):
def parent_element():
"""
Wrapper to retrieve parent element
"""
return WebElementWrapper(self.driver_wrapper, self.locator, self.element.parent)
return self.execute_and_handle_we... | You are a Python code generator, capable of creating scripts from specifications. |
Get the parent of the element | Can you tell what is the following Python 3 function doing
def parent_element(self):
def parent_element():
"""
Wrapper to get parent element
"""
parent = self.driver_wrapper.execute_script('return arguments[0].parentNode;', self.element)
wrapped_parent... | You are a Python code analyst, evaluating scripts for potential improvements. |
Get the text of the element | Explain what the following Python 3 code does
def text(self, force_get=False):
def text_element():
"""
Wrapper to get text of element
"""
return self.element.text
def force_text_element():
"""Get text by javascript"""
return self.d... | You are a Python code analyst, evaluating scripts for potential improvements. |
Highlights the elements in the element using javascript | Can you generate a brief explanation for the following Python 3 code
def highlight(self):
js_executor = self.driver_wrapper.js_executor
def highlight_element():
"""
Wrapper to highlight elements
"""
location = self.element.location
size = self.... | You are a Python code analyst, evaluating scripts for potential improvements. |
Sets the attribute of the element to a specified value | Can you generate the documentation for the following Python 3 function
def set_attribute(self, name, value):
js_executor = self.driver_wrapper.js_executor
def set_attribute_element():
"""
Wrapper to set attribute
"""
js_executor.execute_template('setAttrib... | As a Python code composer, you craft elegant and concise scripts. |
def select_option(self, value=None, text=None, index=None):
"""
Selects an option by value, text, or index. You must name the parameter
@type value: str
@param value: the value of the option
@type text: str
@param text: the option's visible text
@type... | Can you write a function in Python 3 where it
selects an option by value text or index. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Private method used by select methods. | Can you generate a brief explanation for the following Python 3 code
def set_select(self, select_or_deselect = 'select', value=None, text=None, index=None):
# TODO: raise exception if element is not select element
if select_or_deselect is 'select':
if value is not None:
Sele... | As a Python code composer, you craft elegant and concise scripts. |
Wrapper to check a checkbox | Can you generate the documentation for the following Python 3 function
def checkbox_check(self, force_check=False):
if not self.get_attribute('checked'):
self.click(force_click=force_check) | You are a Python code analyst, evaluating scripts for potential improvements. |
Wrapper to uncheck a checkbox | Given the following Python 3 function, write the documentation
def checkbox_uncheck(self, force_check=False):
if self.get_attribute('checked'):
self.click(force_click=force_check) | You are a Python code analyst, evaluating scripts for potential improvements. |
def find(self, locator, find_all=False, search_object=None, exclude_invisible=None, *args, **kwargs):
"""
Find wrapper, invokes webDriverWrapper find with the current element as the search object
@type locator: webdriverwrapper.support.locator.Locator
@param locator: lo... | Create a Python 3 function for
finding wrapper invokes webDriverWrapper. find with the current element as the search object | As a Python code composer, you craft elegant and concise scripts. |
def find_once(self, locator):
"""
Find wrapper to run a single find
@type locator: webdriverwrapper.support.locator.Locator
@param locator: locator used in search
@type find_all: bool
@param find_all: should I find all elements, or just on... | Write a Python 3 script to
find a single element in the page | As a python code expert, you are capable of creating scripts from specifications. |
Find wrapper finds all elements with the given locator | Can you generate a brief explanation for the following Python 3 code
def find_all(self, locator):
return self.driver_wrapper.find(locator, True, self.element) | As a Python code translator, you convert algorithms and pseudocode into Python. |
def is_present(self, locator):
"""
Tests to see if an element is present
@type locator: webdriverwrapper.support.locator.Locator
@param locator: locator used in search
@rtype: bool
@return: True if present, False if not pr... | Can you create a Python 3 function that
tests to see if an element is present in the page | You are a Python code architect, reviewing and designing scalable and efficient code |
Waits until the element is stale in the DOM | Explain what the following Python 3 code does
def wait_until_stale(self, timeout=None):
timeout = timeout if timeout is not None else self.driver_wrapper.timeout
def wait():
"""
Wrapper to wait for element to be stale
"""
WebDriverWait(self.driver, timeou... | As a python code expert, you are capable of creating scripts from specifications. |
def execute_and_handle_webelement_exceptions(self, function_to_execute, name_of_action):
"""
Private method to be called by other methods to handle common WebDriverExceptions or throw
a custom exception
@type function_to_execute: types.FunctionType
@param function_to_execut... | Write a Python 3 script to
execute a function and handles any common WebDriverExceptions or throw an exception. | As a python code expert, you are capable of creating scripts from specifications. |
Makes a request using requests. Session. | Given the following Python 3 function, write the documentation
def request(self, uri, method=GET, headers=None, cookies=None, params=None, data=None, post_files=None,**kwargs):
coyote_args = {
'headers': headers,
'cookies': cookies,
'params': params,
'files': pos... | As a Python code composer, you craft elegant and concise scripts. |
Saves the last response to a file | Explain what the following Python 3 code does
def save_last_response_to_file(self, filename):
response = self.get_last_response()
return self.save_response_to_file(response, filename) | As a Python code composer, you craft elegant and concise scripts. |
def save_response_to_file(self, response, filename):
"""Saves the body of the last response to a file
@param filename: Filename to save to
@return: Returns False if there is an OS error, True if successful
"""
try:
last_response = self.get_last_response()
... | How would you implement a function in Python 3 that
saves the body of the last response to a file | As a Python code translator, you convert algorithms and pseudocode into Python. |
Validates that the url can be opened and responds with an allowed response code. | Can you tell what is the following Python 3 function doing
def validate_url(url, allowed_response_codes=None):
allowed_response_codes = [200] if allowed_response_codes is None else allowed_response_codes
# link calls a js function, do not try to open
if str(url).startswith('javascript:'):
return Tr... | As a Python code analyst, you investigate and solve complex coding mysteries |
def validate_urls(urls, allowed_response_codes=None):
"""Validates that a list of urls can be opened and each responds with an allowed response code
urls -- the list of urls to ping
allowed_response_codes -- a list of response codes that the validator will ignore
"""
for url in urls:
valid... | Create a Python 3 function to
validate that a list of urls can be opened and each responds with an allowed response code | As a Python code composer, you craft elegant and concise scripts. |
def build_follow_url(host=None, **params):
"""
Build a URL for the /follow page
"""
# template = '?{params}'
config = ExampleConfig()
template = '/follow?{params}'
if not host:
host = config.get('example_web_hostname')
return ExampleUrlBuild... | How would you code a function in Python 3 to
build a URL for the follow page. | You are a Python code generator, capable of creating scripts from specifications. |
def encode_collection(collection, encoding='utf-8'):
"""Encodes all the string keys and values in a collection with specified encoding"""
if isinstance(collection, dict):
return dict((encode_collection(key), encode_collection(value)) for key, value in collection.iteritems())
elif isinstance(collect... | Can you create a Python 3 function that
encodes all the string keys and values in a collection with specified encoding | You are a Python code architect, reviewing and designing scalable and efficient code |
def get_delimited_string_from_list(_list, delimiter=', ', wrap_values_with_char=None, wrap_strings_with_char=None):
"""Given a list, returns a string representation of that list with specified delimiter and optional string chars
_list -- the list or tuple to stringify
delimiter -- the the character to sepe... | How would you code a function in Python 3 to
give a list returns a string representation of that list with specified delimiter and optional string chars | As a Python code analyst, you investigate and solve complex coding mysteries |
Execute a script in the browser | Make a summary of the following Python 3 code
def execute_script(self, string, args=None):
result = None
try:
result = self.driver_wrapper.driver.execute_script(string, args)
return result
except WebDriverException:
if result is not None:
mess... | As a Python code analyst, you investigate and solve complex coding mysteries |
Execute a script from a template | Can you generate the documentation for the following Python 3 function
def execute_template(self, template_name, variables, args=None):
js_text = self.build_js_from_template(template_name, variables)
try:
self.execute_script(js_text, args)
except WebDriverException:
retur... | As a python code expert, you are capable of creating scripts from specifications. |
def execute_template_and_return_result(self, template_name, variables, args=None):
"""
Execute script from a template and return result
@type template_name: str
@value template_name: Script template to implement
@type variables: dict
@value variables: D... | Write a Python 3 script to
execute a script from a template and return the result | As a Python code composer, you craft elegant and concise scripts. |
def build_js_from_template(self, template_file, variables):
"""
Build a JS script from a template and args
@type template_file: str
@param template_file: Script template to implement; can be the name of a built-in script or full filepath to
a js file... | Implement a function in Python 3 to
build a javascript script from a template and args. | As a python code expert, you are capable of creating scripts from specifications. |
def build(template='/', host=None, scheme=None, port=None, **template_vars):
"""Builds a url with a string template and template variables; relative path if host is None, abs otherwise:
template format: "/staticendpoint/{dynamic_endpoint}?{params}"
"""
# TODO: refactor to build_absol... | Can you implement a function in Python 3 that
builds a url with a string template and template variables ; absolute path if host is None abs otherwise. | As a Python code analyst, you investigate and solve complex coding mysteries |
def poll(function, step=0.5, timeout=3, ignore_exceptions=(), exception_message='', message_builder=None,
args=(), kwargs=None, ontimeout=()):
"""Calls the function until bool(return value) is truthy
@param step: Wait time between each function call
@param timeout: Max amount of time that will ela... | Implement a function in Python 3 to
call the function until bool ( return value ) is truthy. | You are a Python code architect, reviewing and designing scalable and efficient code |
def build(self, **variables):
"""Formats the locator with specified parameters"""
return Locator(self.by, self.locator.format(**variables), self.description) | Write a Python 3 script to
format the locator with specified parameters | As a Python code composer, you craft elegant and concise scripts. |
def random_words_string(count=1, maxchars=None, sep=''):
"""Gets a
"""
nouns = sep.join([random_word() for x in xrange(0, count)])
if maxchars is not None and nouns > maxchars:
nouns = nouns[0:maxchars-1]
return nouns | How would you code a function in Python 3 to
get a random words string | You are a Python code generator, capable of creating scripts from specifications. |
def is_subdomain(domain, reference):
"""Tests if a hostname is a subdomain of a reference hostname
e.g. www.domain.com is subdomain of reference
@param domain: Domain to test if it is a subdomain
@param reference: Reference "parent" domain
"""
index_of_reference = domain.find(reference)
if ... | Write a Python 3 function that can
test if a hostname is a subdomain of a reference hostname e. g. www. domain. com is subdomain of reference hostname | You are a Python code analyst, evaluating scripts for potential improvements. |
def dump_requestdriver_cookies_into_webdriver(requestdriver, webdriverwrapper, handle_sub_domain=True):
"""Adds all cookies in the RequestDriver session to Webdriver
@type requestdriver: RequestDriver
@param requestdriver: RequestDriver with cookies
@type webdriverwrapper: WebDriverWrapper
@param w... | Can you implement a function in Python 3 that
dumps all cookies in the requestdriver session into the WebdriverWrapper. | As a python code expert, you are capable of creating scripts from specifications. |
Adds all cookies in the Webdriver session to the requestdriver. | Make a summary of the following Python 3 code
def dump_webdriver_cookies_into_requestdriver(requestdriver, webdriverwrapper):
for cookie in webdriverwrapper.get_cookies():
# Wedbriver uses "expiry"; requests uses "expires", adjust for this
expires = cookie.pop('expiry', {'expiry': None})
co... | You are a Python code generator, capable of creating scripts from specifications. |
def get_firefox_binary():
"""Gets the firefox binary
@rtype: FirefoxBinary
"""
browser_config = BrowserConfig()
constants_config = ConstantsConfig()
log_dir = os.path.join(constants_config.get('logs_dir'), 'firefox')
create_directory(log_dir)
log_path = os.path.join(log_dir, '{}_{}.log... | Implement a Python 3 function for
getting the firefox binary | You are a Python code architect, reviewing and designing scalable and efficient code |
def _log_fail_callback(driver, *args, **kwargs):
"""Raises an assertion error if the page has severe console errors
@param driver: ShapewaysDriver
@return: None
"""
try:
logs = driver.get_browser_log(levels=[BROWSER_LOG_LEVEL_SEVERE])
failure_message = 'There were severe console er... | Can you create a Python 3 function that
raises an assertion error if the page has severe console errors | As a Python code translator, you convert algorithms and pseudocode into Python. |
Clones the object and updates the args
| Here you have a function in Python 3, explain what it does
def clone_and_update(self, **kwargs):
cloned = self.clone()
cloned.update(**kwargs)
return cloned | As a Python code analyst, you investigate and solve complex coding mysteries |
Render the body of the message to a string. | Can you generate the documentation for the following Python 3 function
def message(self):
template_name = self.template_name() if \
callable(self.template_name) \
else self.template_name
return loader.render_to_string(
template_name, self.get_context(), request=self.r... | As a Python code composer, you craft elegant and concise scripts. |
def subject(self):
"""
Render the subject of the message to a string.
"""
template_name = self.subject_template_name() if \
callable(self.subject_template_name) \
else self.subject_template_name
subject = loader.render_to_string(
template_name... | Can you write a function in Python 3 where it
renders the subject of the message to a string. | You are a Python code analyst, evaluating scripts for potential improvements. |
def get_context(self):
"""
Return the context used to render the templates for the email
subject and body.
By default, this context includes:
* All of the validated values in the form, as variables of the
same names as their fields.
* The current ``Site`` obj... | Implement a Python 3 function for
returning the context used to render the templates for the email. | You are a Python code architect, reviewing and designing scalable and efficient code |
Generates the various parts of the message and return them in a dictionary suitable for passing directly as keyword arguments to django. core. mail. send_mail. | How would you explain what the following Python 3 function does
def get_message_dict(self):
if not self.is_valid():
raise ValueError(
"Message cannot be sent from invalid contact form"
)
message_dict = {}
for message_part in ('from_email', 'message',
... | You are a Python code architect, reviewing and designing scalable and efficient code |
Initialises the Shopify session with the Shopify App s API credentials. | Can you generate a brief explanation for the following Python 3 code
def initialise_shopify_session():
if not settings.SHOPIFY_APP_API_KEY or not settings.SHOPIFY_APP_API_SECRET:
raise ImproperlyConfigured("SHOPIFY_APP_API_KEY and SHOPIFY_APP_API_SECRET must be set in settings")
shopify.Session.setup(ap... | As a Python code analyst, you investigate and solve complex coding mysteries |
Creates and saves a ShopUser with the given domain and password. | Given the following Python 3 function, write the documentation
def create_user(self, myshopify_domain, password=None):
if not myshopify_domain:
raise ValueError('ShopUsers must have a myshopify domain')
user = self.model(myshopify_domain=myshopify_domain)
# Never want to be able to... | You are a Python code architect, reviewing and designing scalable and efficient code |
Merge a dictionary of query parameters into the given URL. | Explain what the following Python 3 code does
def add_query_parameters_to_url(url, query_parameters):
# Parse the given URL into parts.
url_parts = urllib.parse.urlparse(url)
# Parse existing parameters and add new parameters.
qs_args = urllib.parse.parse_qs(url_parts[4])
qs_args.update(query_param... | As a Python code analyst, you investigate and solve complex coding mysteries |
def bind(self, event_name, callback, *args, **kwargs):
"""Bind an event to a callback
:param event_name: The name of the event to bind to.
:type event_name: str
:param callback: The callback to notify of this event.
"""
self.event_callbacks[event_name].append((callback,... | Can you create a Python 3 function that
binds an event to a callback | As a Python code translator, you convert algorithms and pseudocode into Python. |
Send an event to the Pusher server. | Can you generate the documentation for the following Python 3 function
def send_event(self, event_name, data, channel_name=None):
event = {'event': event_name, 'data': data}
if channel_name:
event['channel'] = channel_name
self.logger.info("Connection: Sending event - %s" % event)
... | As a Python code composer, you craft elegant and concise scripts. |
Trigger an event on this channel. Only available for private or presence channels. | Make a summary of the following Python 3 code
def trigger(self, event_name, data):
if self.connection:
if event_name.startswith("client-"):
if self.name.startswith("private-") or self.name.startswith("presence-"):
self.connection.send_event(event_name, data, chann... | As a Python code composer, you craft elegant and concise scripts. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.