def has_no_button(self, locator, **kwargs):

return self.has_no_selector("<STR_LIT>", locator, **kwargs)<EOL>

Checks if the page or current node has no button with the given text, value, or id.

Args:
    locator (str): The text, value, or id of a button to check for.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    bool: Whether it doesn't exist.


def has_checked_field(self, locator, **kwargs):

kwargs["<STR_LIT>"] = True<EOL>return self.has_selector("<STR_LIT>", locator, **kwargs)<EOL>

Checks if the page or current node has a radio button or checkbox with the given label,
value, or id, that is currently checked.

Args:
    locator (str): The label, name, or id of a checked field.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    bool: Whether it exists.


def has_no_checked_field(self, locator, **kwargs):

kwargs["<STR_LIT>"] = True<EOL>return self.has_no_selector("<STR_LIT>", locator, **kwargs)<EOL>

Checks if the page or current node has no radio button or checkbox with the given label,
value, or id that is currently checked.

Args:
    locator (str): The label, name, or id of a checked field.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    bool: Whether it doesn't exist.


return self.has_selector("<STR_LIT>", locator, **kwargs)<EOL>

Checks if the page or current node has a form field with the given label, name, or id.

For text fields and other textual fields, such as textareas and HTML5 email/url/etc. fields,
it's possible to specify a ``value`` argument to specify the text the field should contain::

    page.has_field("Name", value="Jonas")

Args:
    locator (str): The label, name, or id of a field to check for.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    bool: Whether it exists.


def has_no_field(self, locator, **kwargs):

Checks if the page or current node has no form field with the given label, name, or id. See
:meth:`has_field`.

Args:
    locator (str): The label, name, or id of a field to check for.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    bool: Whether it doesn't exist.


Checks if the page or current node has a link with the given text or id.

Args:
    locator (str): The text or id of a link to check for.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    bool: Whether it exists.


def has_no_link(self, locator, **kwargs):

Checks if the page or current node has no link with the given text or id.

Args:
    locator (str): The text or id of a link to check for.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    bool: Whether it doesn't exist.


def has_select(self, locator, **kwargs):

Checks if the page or current node has a select field with the given label, name, or id.

It can be specified which option should currently be selected::

    page.has_select("Language", selected="German")

For multiple select boxes, several options may be specified::

    page.has_select("Language", selected=["English", "German"])

It's also possible to check if the exact set of options exists for this select box::

    page.has_select("Language", options=["English", "German", "Spanish"])

You can also check for a partial set of options::

    page.has_select("Language", with_options=["English", "German"])

Args:
    locator (str): The label, name, or id of a select box.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    bool: Whether it exists.


def has_no_select(self, locator, **kwargs):

Checks if the page or current node has no select field with the given label, name, or id.
See :meth:`has_select`.

Args:
    locator (str): The label, name, or id of a select box.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    bool: Whether it doesn't exist.


Checks if the page or current node has a table with the given id or caption::

    page.has_table("People")

Args:
    locator (str): The id or caption of a table.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    bool: Whether it exists.


def has_no_table(self, locator, **kwargs):

Checks if the page or current node has no table with the given id or caption. See
:meth:`has_table`.

Args:
    locator (str): The id or caption of a table.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    bool: Whether it doesn't exist.


def has_unchecked_field(self, locator, **kwargs):

kwargs["<STR_LIT>"] = False<EOL>return self.has_selector("<STR_LIT>", locator, **kwargs)<EOL>

Checks if the page or current node has a radio button or checkbox with the given label,
value, or id, that is currently unchecked.

Args:
    locator (str): The label, name, or id of an unchecked field.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    bool: Whether it exists.


def has_no_unchecked_field(self, locator, **kwargs):

kwargs["<STR_LIT>"] = False<EOL>return self.has_no_selector("<STR_LIT>", locator, **kwargs)<EOL>

Checks if the page or current node has no radio button or checkbox with the given label,
value, or id, that is currently unchecked.

Args:
    locator (str): The label, name, or id of an unchecked field.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    bool: Whether it doesn't exist.


query = TextQuery(*args, **kwargs)<EOL>@self.synchronize(wait=query.wait)<EOL>def assert_text():<EOL><INDENT>count = query.resolve_for(self)<EOL>if not (matches_count(count, query.options) and<EOL>(count > <NUM_LIT:0> or expects_none(query.options))):<EOL><INDENT>raise ExpectationNotMet(query.failure_message)<EOL><DEDENT>return True<EOL><DEDENT>return assert_text()<EOL>

Asserts that the page or current node has the given text content, ignoring any HTML tags.

Args:
    *args: Variable length argument list for :class:`TextQuery`.
    **kwargs: Arbitrary keyword arguments for :class:`TextQuery`.

Returns:
    True

Raises:
    ExpectationNotMet: If the assertion hasn't succeeded during the wait time.


def assert_no_text(self, *args, **kwargs):

query = TextQuery(*args, **kwargs)<EOL>@self.synchronize(wait=query.wait)<EOL>def assert_no_text():<EOL><INDENT>count = query.resolve_for(self)<EOL>if matches_count(count, query.options) and (<EOL>count > <NUM_LIT:0> or expects_none(query.options)):<EOL><INDENT>raise ExpectationNotMet(query.negative_failure_message)<EOL><DEDENT>return True<EOL><DEDENT>return assert_no_text()<EOL>

Asserts that the page or current node doesn't have the given text content, ignoring any
HTML tags.

Args:
    *args: Variable length argument list for :class:`TextQuery`.
    **kwargs: Arbitrary keyword arguments for :class:`TextQuery`.

Returns:
    True

Raises:
    ExpectationNotMet: If the assertion hasn't succeeded during the wait time.


@predicate<EOL><INDENT>def has_text(self, *args, **kwargs):<DEDENT>

return self.assert_text(*args, **kwargs)<EOL>

Checks if the page or current node has the given text content, ignoring any HTML tags.

Whitespaces are normalized in both the node's text and the passed text parameter. Note that
whitespace isn't normalized in a passed regular expression as normalizing whitespace in a
regular expression isn't easy and doesn't seem to be worth it.

By default it will check if the text occurs at least once, but a different number can be
specified. ::

    page.has_text("lorem ipsum", between=range(2, 5))

Args:
    *args: Variable length argument list for :class:`TextQuery`.
    **kwargs: Arbitrary keyword arguments for :class:`TextQuery`.

Returns:
    bool: Whether it exists.


@predicate<EOL><INDENT>def has_no_text(self, *args, **kwargs):<DEDENT>

return self.assert_no_text(*args, **kwargs)<EOL>

Checks if the page or current node does not have the given text content, ignoring any HTML
tags and normalizing whitespace.

Args:
    *args: Variable length argument list for :class:`TextQuery`.
    **kwargs: Arbitrary keyword arguments for :class:`TextQuery`.

Returns:
    bool: Whether it doesn't exist.


return self._synchronized_resolve(SelectorQuery(*args, **kwargs))<EOL>

Find an :class:`Element` based on the given arguments. ``find`` will raise an error if the
element is not found.

``find`` takes the same options as :meth:`find_all`. ::

    page.find("#foo").find(".bar")
    page.find("xpath", "//div[contains(., 'bar')]")
    page.find("li", text="Quox").click_link("Delete")

Args:
    *args: Variable length argument list for :class:`SelectorQuery`.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    Element: The found element.

Raises:
    Ambiguous: If more than one element matching element is found.
    ElementNotFound: If the element can't be found before time expires.


return self._synchronized_resolve(AncestorQuery(*args, **kwargs))<EOL>

Find an :class:`Element` based on the given arguments that is also an ancestor of the
element called on. ``ancestor`` will raise an error if the element is not found.

``ancestor`` takes the same options as :meth:`find`. ::

    element.ancestor("#foo").find(".bar")
    element.ancestor("xpath", "//div[contains(., 'bar')]")
    element.ancestor("li", text="Quox").click_link("Delete")

Args:
    *args: Variable length argument list for :class:`AncestorQuery`.
    **kwargs: Arbitrary keyword arguments for :class:`AncestorQuery`.

Returns:
    Element: The found element.

Raises:
    Ambiguous: If more than one element matching element is found.
    ElementNotFound: If the element can't be found before time expires.


return self._synchronized_resolve(SiblingQuery(*args, **kwargs))<EOL>

Find an :class:`Element` based on the given arguments that is also a sibling of the
element called on. ``sibling`` will raise an error if the element is not found.

``sibling`` takes the same options as :meth:`find`. ::

    element.sibling("#foo").find(".bar")
    element.sibling("xpath", "//div[contains(., 'bar')]")
    element.sibling("li", text="Quox").click_link("Delete")

Args:
    *args: Variable length argument list for :class:`SiblingQuery`.
    **kwargs: Arbitrary keyword arguments for :class:`SiblingQuery`.

Returns:
    Element: The found element.

Raises:
    Ambiguous: If more than one element matching element is found.
    ElementNotFound: If the element can't be found before time expires.


def find_button(self, locator=None, **kwargs):

return self.find("<STR_LIT>", locator, **kwargs)<EOL>

Find a button on the page. This can be any ``<input>`` element of type submit, reset, image,
or button, or it can be a ``<button>`` element. All buttons can be found by their id, value,
or title. ``<button>`` elements can also be found by their text content, and image
``<input>`` elements by their alt attribute.

Args:
    locator (str, optional): The id, value, title, text content, alt of image.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    Element: The found element.


return self.find("<STR_LIT:id>", id, **kwargs)<EOL>

Find an element on the page, given its id.

Args:
    id (str): The id of the element.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    Element: The found element.


def find_field(self, locator=None, **kwargs):

Find a form field on the page. The field can be found by its name, id, or label text.

Args:
    locator (str, optional): Name, id, placeholder, or text of associated label element.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    Element: The found element.


def find_link(self, locator=None, **kwargs):

Find a link on the page. The link can be found by its id or text.

Args:
    locator (str, optional): ID, title, text, or alt of enclosed img element.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    Element: The found element.


query = SelectorQuery(*args, **kwargs)<EOL>@self.synchronize(wait=query.wait)<EOL>def find_all():<EOL><INDENT>result = query.resolve_for(self)<EOL>if not result.matches_count:<EOL><INDENT>raise ExpectationNotMet(result.failure_message)<EOL><DEDENT>return result<EOL><DEDENT>return find_all()<EOL>

Find all elements on the page matching the given selector and options.

Both XPath and CSS expressions are supported, but Capybara does not try to automatically
distinguish between them. The following statements are equivalent::

    page.find_all("css", "a#person_123")
    page.find_all("xpath", "//a[@id='person_123']")

If the type of selector is left out, Capybara uses :data:`capybara.default_selector`. It's
set to ``"css"`` by default. ::

    page.find_all("a#person_123")

    capybara.default_selector = "xpath"
    page.find_all("//a[@id='person_123']")

The set of found elements can further be restricted by specifying options. It's possible to
select elements by their text or visibility::

    page.find_all("a", text="Home")
    page.find_all("#menu li", visible=True)

By default if no elements are found, an empty list is returned; however, expectations can be
set on the number of elements to be found which will trigger Capybara's waiting behavior for
the expectations to match. The expectations can be set using::

    page.assert_selector("p#foo", count=4)
    page.assert_selector("p#foo", maximum=10)
    page.assert_selector("p#foo", minimum=1)
    page.assert_selector("p#foo", between=range(1, 11))

See :func:`capybara.result.Result.matches_count` for additional information about count
matching.

Args:
    *args: Variable length argument list for :class:`SelectorQuery`.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    Result: A collection of found elements.

Raises:
    ExpectationNotMet: The matched results did not meet the expected criteria.


if capybara.wait_on_first_by_default:<EOL><INDENT>kwargs.setdefault("<STR_LIT>", <NUM_LIT:1>)<EOL><DEDENT>try:<EOL><INDENT>result = self.find_all(*args, **kwargs)<EOL>return result[<NUM_LIT:0>] if len(result) > <NUM_LIT:0> else None<EOL><DEDENT>except ExpectationNotMet:<EOL><INDENT>return None<EOL><DEDENT>

Find the first element on the page matching the given selector and options, or None if no
element matches.

By default, no waiting behavior occurs. However, if ``capybara.wait_on_first_by_default``
is set to true, it will trigger Capybara's waiting behavior for a minimum of 1 matching
element to be found.

Args:
    *args: Variable length argument list for :class:`SelectorQuery`.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
    Element: The found element or None.


def attach_file(self, locator_or_path, path=None, **kwargs):

if path is None:<EOL><INDENT>locator, path = None, locator_or_path<EOL><DEDENT>else:<EOL><INDENT>locator = locator_or_path<EOL><DEDENT>if not os.path.isfile(path):<EOL><INDENT>raise FileNotFound("<STR_LIT>".format(path))<EOL><DEDENT>self.find("<STR_LIT>", locator, **kwargs).set(path)<EOL>

Find a file field on the page and attach a file given its path. The file field can be found
via its name, id, or label text. ::

    page.attach_file(locator, "/path/to/file.png")

Args:
    locator_or_path (str): Which field to attach the file to, or the path of the file that
        will be attached.
    path (str, optional): The path of the file that will be attached. Defaults to
        ``locator_or_path``.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Raises:
    FileNotFound: No file exists at the given path.


def check(self, locator=None, allow_label_click=None, **kwargs):

self._check_with_label(<EOL>"<STR_LIT>", True, locator=locator, allow_label_click=allow_label_click, **kwargs)<EOL>

Find a check box and mark it as checked. The check box can be found via name, id, or label
text. ::

    page.check("German")

Args:
    locator (str, optional): Which check box to check.
    allow_label_click (bool, optional): Attempt to click the label to toggle state if
        element is non-visible. Defaults to :data:`capybara.automatic_label_click`.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.


def choose(self, locator=None, allow_label_click=None, **kwargs):

Find a radio button and mark it as checked. The radio button can be found via name, id, or
label text. ::

    page.choose("Male")

Args:
    locator (str, optional): Which radio button to choose.
    allow_label_click (bool, optional): Attempt to click the label to toggle state if
        element is non-visible. Defaults to :data:`capybara.automatic_label_click`.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.


def click_button(self, locator=None, **kwargs):

return self.find("<STR_LIT>", locator, **kwargs).click()<EOL>

Finds a button on the page and clicks it. This can be any ``<input>`` element of type
submit, reset, image, or button, or it can be any ``<button>`` element. All buttons can be
found by their id, value, or title. ``<button>`` elements can also be found by their text
content, and image ``<input>`` elements by their alt attribute.

Args:
    locator (str, optional): Which button to find.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.


def click_link(self, locator=None, **kwargs):

Finds a link by id, text, or title and clicks it. Also looks at image alt text inside the
link.

Args:
    locator (str, optional): Text, id, title, or nested image's alt attribute.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.


def click_link_or_button(self, locator=None, **kwargs):

Finds a button or link by id, text or value and clicks it. Also looks at image alt text
inside the link.

Args:
    locator (str, optional): Text, id, or value of link or button.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.


def fill_in(self, locator=None, current_value=None, value=None, fill_options=None, **kwargs):

if current_value is not None:<EOL><INDENT>kwargs["<STR_LIT:value>"] = current_value<EOL><DEDENT>fill_options = fill_options or {}<EOL>self.find("<STR_LIT>", locator, **kwargs).set(value, **fill_options)<EOL>

Locate a text field or text area and fill it in with the given text. The field can be found
via its name, id, or label text. ::

    page.fill_in("Name", value="Bob")

Args:
    locator (str, optional): Which field to fill in.
    current_value (str, optional): The current value of the field.
    value (str, optional): The value to fill in. Defaults to None.
    fill_options (Dict, optional): Driver-specific options regarding how to fill fields.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.


def select(self, value=None, field=None, **kwargs):

if field:<EOL><INDENT>self.find("<STR_LIT>", field, **kwargs).find("<STR_LIT>", value, **kwargs).select_option()<EOL><DEDENT>else:<EOL><INDENT>self.find("<STR_LIT>", value, **kwargs).select_option()<EOL><DEDENT>

If the ``field`` argument is present, ``select`` finds a select box on the page and selects
a particular option from it. Otherwise it finds an option inside the current scope and
selects it. If the select box is a multiple select, ``select`` can be called multiple times
to select more than one option. The select box can be found via its name, id, or label text.
The option can be found by its text. ::

    page.select("March", field="Month")

Args:
    value (str, optional): Which option to select.
    field (str, optional): The id, name, or label of the select box.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.


def uncheck(self, locator=None, allow_label_click=None, **kwargs):

self._check_with_label(<EOL>"<STR_LIT>", False, locator=locator, allow_label_click=allow_label_click, **kwargs)<EOL>

Find a check box and uncheck it. The check box can be found via name, id, or label text. ::

    page.uncheck("German")

Args:
    locator (str, optional): Which check box to uncheck.
    allow_label_click (bool, optional): Attempt to click the label to toggle state if
        element is non-visible. Defaults to :data:`capybara.automatic_label_click`.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.


def unselect(self, value=None, field=None, **kwargs):

if field:<EOL><INDENT>self.find("<STR_LIT>", field, **kwargs).find("<STR_LIT>", value, **kwargs).unselect_option()<EOL><DEDENT>else:<EOL><INDENT>self.find("<STR_LIT>", value, **kwargs).unselect_option()<EOL><DEDENT>

Find a select box on the page and unselect a particular option from it. If the select box is
a multiple select, ``unselect`` can be called multiple times to unselect more than one
option. The select box can be found via its name, id, or label text. ::

    page.unselect("March", field="Month")

Args:
    value (str, optional): Which option to unselect.
    field (str, optional): The id, name, or label of the select box.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.


def _check_with_label(self, selector, checked, locator=None, allow_label_click=None, visible=None, wait=None,<EOL>**kwargs):

if allow_label_click is None:<EOL><INDENT>allow_label_click = capybara.automatic_label_click<EOL><DEDENT>@self.synchronize(wait=BaseQuery.normalize_wait(wait))<EOL>def check_with_label():<EOL><INDENT>element = None<EOL>try:<EOL><INDENT>element = self.find(selector, locator, visible=visible, **kwargs)<EOL>element.set(checked)<EOL><DEDENT>except Exception as e:<EOL><INDENT>if not allow_label_click or not self._should_catch_error(e):<EOL><INDENT>raise<EOL><DEDENT>try:<EOL><INDENT>if not element:<EOL><INDENT>element = self.find(selector, locator, visible="<STR_LIT:all>", **kwargs)<EOL><DEDENT>label = self.find("<STR_LIT:label>", field=element, visible=True)<EOL>if element.checked != checked:<EOL><INDENT>label.click()<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>raise e<EOL><DEDENT><DEDENT><DEDENT>check_with_label()<EOL>

Args:
    selector (str): The selector for the type of element that should be checked/unchecked.
    checked (bool): Whether the element should be checked.
    locator (str, optional): Which element to check.
    allow_label_click (bool, optional): Attempt to click the label to toggle state if
        element is non-visible. Defaults to :data:`capybara.automatic_label_click`.
    visible (bool | str, optional): The desired element visibility. Defaults to
        :data:`capybara.ignore_hidden_elements`.
    wait (int | float, optional): The number of seconds to wait to check the element.
        Defaults to :data:`capybara.default_max_wait_time`.
    **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.


def assert_title(self, title, **kwargs):

query = TitleQuery(title, **kwargs)<EOL>@self.synchronize(wait=query.wait)<EOL>def assert_title():<EOL><INDENT>if not query.resolves_for(self):<EOL><INDENT>raise ExpectationNotMet(query.failure_message)<EOL><DEDENT>return True<EOL><DEDENT>return assert_title()<EOL>

Asserts that the page has the given title.

Args:
    title (str | RegexObject): The string or regex that the title should match.
    **kwargs: Arbitrary keyword arguments for :class:`TitleQuery`.

Returns:
    True

Raises:
    ExpectationNotMet: If the assertion hasn't succeeded during the wait time.


def assert_no_title(self, title, **kwargs):

query = TitleQuery(title, **kwargs)<EOL>@self.synchronize(wait=query.wait)<EOL>def assert_no_title():<EOL><INDENT>if query.resolves_for(self):<EOL><INDENT>raise ExpectationNotMet(query.negative_failure_message)<EOL><DEDENT>return True<EOL><DEDENT>return assert_no_title()<EOL>

Asserts that the page doesn't have the given title.

Args:
    title (str | RegexObject): The string that the title should include.
    **kwargs: Arbitrary keyword arguments for :class:`TitleQuery`.

Returns:
    True

Raises:
    ExpectationNotMet: If the assertion hasn't succeeded during the wait time.


try:<EOL><INDENT>self.assert_title(title, **kwargs)<EOL>return True<EOL><DEDENT>except ExpectationNotMet:<EOL><INDENT>return False<EOL><DEDENT>

Checks if the page has the given title.

Args:
    title (str | RegexObject): The string or regex that the title should match.
    **kwargs: Arbitrary keyword arguments for :class:`TitleQuery`.

Returns:
    bool: Whether it matches.


def has_no_title(self, title, **kwargs):

try:<EOL><INDENT>self.assert_no_title(title, **kwargs)<EOL>return True<EOL><DEDENT>except ExpectationNotMet:<EOL><INDENT>return False<EOL><DEDENT>

Checks if the page doesn't have the given title.

Args:
    title (str | RegexObject): The string that the title should include.
    **kwargs: Arbitrary keyword arguments for :class:`TitleQuery`.

Returns:
    bool: Whether it doesn't match.


return self.base.native<EOL>

object: The native element from the driver.


return self.base.tag_name<EOL>


return self.base.visible<EOL>

bool: Whether or not the element is visible.


return self.base.style(styles)<EOL>

Retrieve the given CSS styles. ::

    element.style("color", "font-size")  # => Computed values of CSS "color" and "font-size" styles

Args:
    *styles (str): Names of the desired CSS properties.

Returns:
    Dict[str, str]: Dictionary of the CSS property names to computed values.


return self.base.value<EOL>


if capybara.ignore_hidden_elements or capybara.visible_text_only:<EOL><INDENT>return self.visible_text<EOL><DEDENT>else:<EOL><INDENT>return self.all_text<EOL><DEDENT>

Retrieve the text of the element. If :data:`capybara.ignore_hidden_elements` is ``True``,
which it is by default, then this will return only text which is visible. The exact
semantics of this may differ between drivers, but generally any text within elements with
``display: none`` is ignored.

Returns:
    str: The text of the element.


return self.base.all_text<EOL>


return self.base.visible_text<EOL>

str: Only the visible text of the element.


return self.base.checked<EOL>

bool: Whether or not the element is checked.


return self.base.selected<EOL>

bool: Whether or not the element is selected.


return self.base.disabled<EOL>

bool: Whether or not the element is disabled.


return self.base.readonly<EOL>

bool: Whether or not the element is readonly.


return self.base.multiple<EOL>

bool: Whether or not the element supports multiple results.


return self.base.path<EOL>

str: An XPath expression describing where on the page the element can be found.


return self.base[name]<EOL>

Retrieve the given attribute. ::

    element["title"]  # => HTML title attribute

Args:
    name (str): The attribute to retrieve.

Returns:
    str: The value of the attribute.


@synchronize<EOL><INDENT>def click(self, *keys, **offset):<DEDENT>

self.base.click(*keys, **offset)<EOL>

Click the element.

Both ``x`` and ``y`` must be specified if an offset is wanted. If not specified, the click
will occur at the middle of the element.

Args:
    keys (List[Keys], optional): Keys to be held down when clicking.
    offset (Dict[str, int], optional): X- and Y-coordinates to offset the click location
        from the toop left corner of the element.


@synchronize<EOL><INDENT>def double_click(self, *keys, **offset):<DEDENT>

self.base.double_click(*keys, **offset)<EOL>

Double-click the element.

Both ``x`` and ``y`` must be specified if an offset is wanted. If not specified, the click
will occur at the middle of the element.

Args:
    keys (List[Keys], optional): Keys to be held down when clicking.
    offset (Dict[str, int], optional): X- and Y-coordinates to offset the click location
        from the toop left corner of the element.


Drag the element to the given other element. ::

    source = page.find("#foo")
    target = page.find("#bar")
    source.drag_to(target)

Args:
    node (Element): The element to drag to.


Send keystrokes to the element.

Examples::

    from selenium.webdriver.common.keys import Keys

    element.send_keys("foo")                  # => value: "foo"
    element.send_keys("tet", Keys.LEFT, "s")  # => value: "test"

Args:
    *args: Variable length list of keys to send.


self.base.hover()<EOL>


@synchronize<EOL><INDENT>def right_click(self, *keys, **offset):<DEDENT>

self.base.right_click(*keys, **offset)<EOL>

Right-click the element.

Both ``x`` and ``y`` must be specified if an offset is wanted. If not specified, the click
will occur at the middle of the element.

Args:
    keys (List[Keys], optional): Keys to be held down when clicking.
    offset (Dict[str, int], optional): X- and Y-coordinates to offset the click location
        from the toop left corner of the element.


if self.disabled:<EOL><INDENT>warn("<STR_LIT>".format(self.value or self.text))<EOL><DEDENT>self.base.select_option()<EOL>

Select this node if it is an option element inside a select tag.


@synchronize<EOL><INDENT>def set(self, value, **options):<DEDENT>

self.base.set(value, **options)<EOL>

Set the value of the form element to the given value.

Args:
    value (bool | str): The new value.
    **options: Driver-specific options for how to set the value.


Unselect this node if it is an option element inside a multiple select tag.


if self.query.options["<STR_LIT:count>"] is not None:<EOL><INDENT>count_opt = int(self.query.options["<STR_LIT:count>"])<EOL>self._cache_at_least(count_opt + <NUM_LIT:1>)<EOL>return cmp(len(self._result_cache), count_opt)<EOL><DEDENT>if self.query.options["<STR_LIT>"] is not None:<EOL><INDENT>min_opt = int(self.query.options["<STR_LIT>"])<EOL>if not self._cache_at_least(min_opt):<EOL><INDENT>return -<NUM_LIT:1><EOL><DEDENT><DEDENT>if self.query.options["<STR_LIT>"] is not None:<EOL><INDENT>max_opt = int(self.query.options["<STR_LIT>"])<EOL>if self._cache_at_least(max_opt + <NUM_LIT:1>):<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>if self.query.options["<STR_LIT>"] is not None:<EOL><INDENT>between = self.query.options["<STR_LIT>"]<EOL>min_opt, max_opt = between[<NUM_LIT:0>], between[-<NUM_LIT:1>]<EOL>if not self._cache_at_least(min_opt):<EOL><INDENT>return -<NUM_LIT:1><EOL><DEDENT>if self._cache_at_least(max_opt + <NUM_LIT:1>):<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>return <NUM_LIT:0><EOL><DEDENT>return <NUM_LIT:0><EOL>

Returns how the result count compares to the query options.

The return value is negative if too few results were found, zero if enough were found, and
positive if too many were found.

Returns:
    int: -1, 0, or 1.


return self.compare_count == <NUM_LIT:0><EOL>

bool: Whether the result count matches the query options.


message = failure_message(self.query.description, self.query.options)<EOL>if len(self) > <NUM_LIT:0>:<EOL><INDENT>message += "<STR_LIT>".format(<EOL>count=len(self),<EOL>matches=declension("<STR_LIT>", "<STR_LIT>", len(self)),<EOL>results="<STR_LIT:U+002CU+0020>".join([desc(node.text) for node in self]))<EOL><DEDENT>else:<EOL><INDENT>message += "<STR_LIT>"<EOL><DEDENT>if self._rest:<EOL><INDENT>elements = "<STR_LIT:U+002CU+0020>".join([desc(element.text) for element in self._rest])<EOL>message += ("<STR_LIT>"<EOL>"<STR_LIT>".format(elements))<EOL><DEDENT>return message<EOL>

str: A message describing the query failure.


try:<EOL><INDENT>while len(self._result_cache) < size:<EOL><INDENT>self._result_cache.append(next(self._result_iter))<EOL><DEDENT>return True<EOL><DEDENT>except StopIteration:<EOL><INDENT>return False<EOL><DEDENT>

Attempts to fill the result cache with at least the given number of results.

Returns:
    bool: Whether the cache contains at least the given size.


return value.decode("<STR_LIT:utf-8>") if isbytes(value) else value<EOL>


return value.encode("<STR_LIT:utf-8>") if isstring(value) else value<EOL>


s = socket()<EOL>s.bind(("<STR_LIT>", <NUM_LIT:0>))<EOL>return s.getsockname()[<NUM_LIT:1>]<EOL>


from lxml import etree<EOL>parts = [node.text]<EOL>for child in node.getchildren():<EOL><INDENT>parts.append(etree.tostring(child, encoding="<STR_LIT:utf-8>"))<EOL>parts.append(child.tail)<EOL><DEDENT>return "<STR_LIT>".join(filter(None, parts))<EOL>

Returns the inner content of a given XML node, including tags.

Args:
    node (lxml.etree.Element): The node whose inner content is desired.

Returns:
    str: The inner content of the node.


from lxml import etree<EOL>parts = [node.text]<EOL>for child in node.getchildren():<EOL><INDENT>parts.append(etree.tostring(child, encoding="<STR_LIT:utf-8>", method="<STR_LIT:text>"))<EOL>parts.append(child.tail)<EOL><DEDENT>return "<STR_LIT>".join(map(decode_bytes, filter(None, parts)))<EOL>

Returns the inner text of a given XML node, excluding tags.

Args:
    node: (lxml.etree.Element): The node whose inner text is desired.

Returns:
    str: The inner text of the node.


return isinstance(value, bytes_)<EOL>

bool: Whether the given value is a sequence of bytes.


return hasattr(possible_regex, "<STR_LIT>") and callable(possible_regex.search)<EOL>

Returns whether the given object is (probably) a regular expression object.

Args:
    possible_regex (object): An object which may or may not be a regular expression.

Returns:
    bool: Whether the given object is (probably) a regular expression object.


return isinstance(value, str_)<EOL>

bool: Whether the given value is a string.


uri = urlparse(url)<EOL>query = uri.query or "<STR_LIT>"<EOL>pairs = parse_qsl(query)<EOL>decoded_pairs = [(unquote(key), value) for key, value in pairs]<EOL>encoded_pairs = [(quote(key), value) for key, value in decoded_pairs]<EOL>normalized_query = urlencode(encoded_pairs)<EOL>return ParseResult(<EOL>scheme=uri.scheme,<EOL>netloc=uri.netloc,<EOL>path=uri.path,<EOL>params=uri.params,<EOL>query=normalized_query,<EOL>fragment=uri.fragment).geturl()<EOL>

Returns the given URL with all query keys properly escaped.

Args:
    url (str): The URL to normalize.

Returns:
    str: The normalized URL.


def fget(self):<EOL><INDENT>def inner(value):<EOL><INDENT>fset(self, value)<EOL><DEDENT>def outer(value=None):<EOL><INDENT>if value:<EOL><INDENT>inner(value)<EOL><DEDENT>else:<EOL><INDENT>return inner<EOL><DEDENT><DEDENT>return outer<EOL><DEDENT>fdoc = fset.__doc__<EOL>return property(fget, fset, None, fdoc)<EOL>

Define a write-only property that, in addition to the given setter function, also
provides a setter decorator defined as the property's getter function.

This allows one to set the property either through traditional assignment, as a
method argument, or through decoration::

    class Widget(object):
        @setter_decorator
        def handler(self, value):
            self._handler = value

    widget = Widget()

    # Method 1: Traditional assignment
    widget.handler = lambda input: process(input)

    # Method 2: Assignment via method argument
    widget.handler(lambda input: process(input))

    # Method 3: Assignment via decoration
    @widget.handler
    def handler(input):
        return process(input)

    # Method 3b: Assignment via decoration with extraneous parens
    @widget.handler()
    def handler(input):
        return process(input)


return self._value<EOL>


def get_browser(browser_name, capabilities=None, **options):

if browser_name == "<STR_LIT>":<EOL><INDENT>return webdriver.Chrome(desired_capabilities=capabilities, **options)<EOL><DEDENT>if browser_name == "<STR_LIT>":<EOL><INDENT>return webdriver.Edge(capabilities=capabilities, **options)<EOL><DEDENT>if browser_name in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>return webdriver.Firefox(capabilities=capabilities, **options)<EOL><DEDENT>if browser_name in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>return webdriver.Ie(capabilities=capabilities, **options)<EOL><DEDENT>if browser_name == "<STR_LIT>":<EOL><INDENT>return webdriver.PhantomJS(desired_capabilities=capabilities, **options)<EOL><DEDENT>if browser_name == "<STR_LIT>":<EOL><INDENT>return webdriver.Remote(desired_capabilities=capabilities, **options)<EOL><DEDENT>if browser_name == "<STR_LIT>":<EOL><INDENT>return webdriver.Safari(desired_capabilities=capabilities, **options)<EOL><DEDENT>raise ValueError("<STR_LIT>".format(repr(browser_name)))<EOL>

Returns an instance of the given browser with the given capabilities.

Args:
    browser_name (str): The name of the desired browser.
    capabilities (Dict[str, str | bool], optional): The desired capabilities of the browser.
        Defaults to None.
    options: Arbitrary keyword arguments for the browser-specific subclass of
        :class:`webdriver.Remote`.

Returns:
    WebDriver: An instance of the desired browser.


return capybara.drivers[self.mode](self.app)<EOL>

driver.Base: The driver for the current session.


return Document(self, self.driver)<EOL>

Document: The document for the current page.


scope = self._scopes[-<NUM_LIT:1>]<EOL>if scope in [None, "<STR_LIT>"]:<EOL><INDENT>scope = self.document<EOL><DEDENT>return scope<EOL>

node.Base: The current node relative to which all interaction will be scoped.


return self.driver.html<EOL>

str: A snapshot of the DOM of the current document, as it looks right now.


if not self.current_url:<EOL><INDENT>return<EOL><DEDENT>path = urlparse(self.current_url).path<EOL>return path if path else None<EOL>

str: Path of the current page, without any domain information.


if not self.current_url:<EOL><INDENT>return<EOL><DEDENT>result = urlparse(self.current_url)<EOL>scheme, netloc = result.scheme, result.netloc<EOL>host = netloc.split("<STR_LIT::>")[<NUM_LIT:0>] if netloc else None<EOL>return "<STR_LIT>".format(scheme, host) if host else None<EOL>


return self.driver.current_url<EOL>

str: Fully qualified URL of the current page.


self.raise_server_error()<EOL>visit_uri = urlparse(visit_uri)<EOL>if capybara.app_host:<EOL><INDENT>uri_base = urlparse(capybara.app_host)<EOL><DEDENT>elif self.server:<EOL><INDENT>uri_base = urlparse("<STR_LIT>".format(self.server.host, self.server.port))<EOL><DEDENT>else:<EOL><INDENT>uri_base = None<EOL><DEDENT>visit_uri = ParseResult(<EOL>scheme=visit_uri.scheme or (uri_base.scheme if uri_base else "<STR_LIT>"),<EOL>netloc=visit_uri.netloc or (uri_base.netloc if uri_base else "<STR_LIT>"),<EOL>path=visit_uri.path,<EOL>params=visit_uri.params,<EOL>query=visit_uri.query,<EOL>fragment=visit_uri.fragment)<EOL>self.driver.visit(visit_uri.geturl())<EOL>

Navigate to the given URL. The URL can either be a relative URL or an absolute URL. The
behavior of either depends on the driver. ::

    session.visit("/foo")
    session.visit("http://google.com")

For drivers which can run against an external application, such as the Selenium driver,
giving an absolute URL will navigate to that page. This allows testing applications running
on remote servers. For these drivers, setting :data:`capybara.app_host` will make the
remote server the default. For example::

    capybara.app_host = "http://google.com"
    session.visit("/")  # visits the Google homepage

Args:
    visit_uri (str): The URL to navigate to.


self.raise_server_error()<EOL>self.driver.refresh()<EOL>


Move back a single entry in the browser's history.


Move forward a single entry in the browser's history.


@contextmanager<EOL><INDENT>def scope(self, *args, **kwargs):<DEDENT>

new_scope = args[<NUM_LIT:0>] if isinstance(args[<NUM_LIT:0>], Base) else self.find(*args, **kwargs)<EOL>self._scopes.append(new_scope)<EOL>try:<EOL><INDENT>yield<EOL><DEDENT>finally:<EOL><INDENT>self._scopes.pop()<EOL><DEDENT>

Executes the wrapped code within the context of a node. ``scope`` takes the same options
as :meth:`find`. For the duration of the context, any command to Capybara will be handled
as though it were scoped to the given element. ::

    with scope("xpath", "//div[@id='delivery-address']"):
        fill_in("Street", value="12 Main Street")

Just as with :meth:`find`, if multiple elements match the selector given to ``scope``, an
error will be raised, and just as with :meth:`find`, this behavior can be controlled
through the ``match`` and ``exact`` options.

It is possible to omit the first argument, in that case, the selector is assumed to be of
the type set in :data:`capybara.default_selector`. ::

    with scope("div#delivery-address"):
        fill_in("Street", value="12 Main Street")

Note that a lot of uses of ``scope`` can be replaced more succinctly with chaining::

    find("div#delivery-address").fill_in("Street", value="12 Main Street")

Args:
    *args: Variable length argument list for the call to :meth:`find`.
    **kwargs: Arbitrary keywords arguments for the call to :meth:`find`.


with self.scope("<STR_LIT>", locator):<EOL><INDENT>yield<EOL><DEDENT>

Execute the wrapped code within a specific fieldset given the id or legend of that
fieldset.

Args:
    locator (str): The id or legend of the fieldset.


Execute the wrapped code within a specific table given the id or caption of that table.

Args:
    locator (str): The id or caption of the table.


@contextmanager<EOL><INDENT>def frame(self, locator=None, *args, **kwargs):<DEDENT>

self.switch_to_frame(self._find_frame(locator, *args, **kwargs))<EOL>try:<EOL><INDENT>yield<EOL><DEDENT>finally:<EOL><INDENT>self.switch_to_frame("<STR_LIT>")<EOL><DEDENT>

Execute the wrapped code within the given iframe using the given frame or frame name/id.
May not be supported by all drivers.

Args:
    locator (str | Element, optional): The name/id of the frame or the frame's element.
        Defaults to the only frame in the document.


return Window(self, self.driver.current_window_handle)<EOL>


return [Window(self, window_handle) for window_handle in self.driver.window_handles]<EOL>

Get all opened windows. The order of the windows in the returned list is not defined. The
driver may sort windows by their creation time but it's not required.

Returns:
    List[Window]: A list of all windows.


return self.window_opened_by(lambda: self.driver.open_new_window())<EOL>

Open new window. The current window doesn't change as a result of this call. It should be
switched explicitly.

Returns:
    Window: The window that has been opened.


if isinstance(frame, Element):<EOL><INDENT>self.driver.switch_to_frame(frame)<EOL>self._scopes.append("<STR_LIT>")<EOL><DEDENT>elif frame == "<STR_LIT>":<EOL><INDENT>if self._scopes[-<NUM_LIT:1>] != "<STR_LIT>":<EOL><INDENT>raise ScopeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>self._scopes.pop()<EOL>self.driver.switch_to_frame("<STR_LIT>")<EOL><DEDENT>elif frame == "<STR_LIT>":<EOL><INDENT>if "<STR_LIT>" in self._scopes:<EOL><INDENT>idx = self._scopes.index("<STR_LIT>")<EOL>if any([scope not in ["<STR_LIT>", None] for scope in self._scopes[idx:]]):<EOL><INDENT>raise ScopeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>self._scopes = self._scopes[:idx]<EOL>self.driver.switch_to_frame("<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>

Switch to the given frame.

If you use this method you are responsible for making sure you switch back to the parent
frame when done in the frame changed to. :meth:`frame` is preferred over this method and
should be used when possible. May not be supported by all drivers.

Args:
    frame (Element | str): The iframe/frame element to switch to.


def switch_to_window(self, window, wait=None):

if len(self._scopes) > <NUM_LIT:1>:<EOL><INDENT>raise ScopeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if isinstance(window, Window):<EOL><INDENT>self.driver.switch_to_window(window.handle)<EOL>return window<EOL><DEDENT>else:<EOL><INDENT>@self.document.synchronize(errors=(WindowError,), wait=wait)<EOL>def switch_and_get_matching_window():<EOL><INDENT>original_window_handle = self.driver.current_window_handle<EOL>try:<EOL><INDENT>for handle in self.driver.window_handles:<EOL><INDENT>self.driver.switch_to_window(handle)<EOL>result = window()<EOL>if result:<EOL><INDENT>return Window(self, handle)<EOL><DEDENT><DEDENT><DEDENT>except Exception:<EOL><INDENT>self.driver.switch_to_window(original_window_handle)<EOL>raise<EOL><DEDENT>self.driver.switch_to_window(original_window_handle)<EOL>raise WindowError("<STR_LIT>")<EOL><DEDENT>return switch_and_get_matching_window()<EOL><DEDENT>

If ``window`` is a lambda, it switches to the first window for which ``window`` returns a
value other than False or None. If a window that matches can't be found, the window will be
switched back and :exc:`WindowError` will be raised.

Args:
    window (Window | lambda): The window that should be switched to, or a filtering lambda.
    wait (int | float, optional): The number of seconds to wait to find the window.

Returns:
    Window: The new current window.

Raises:
    ScopeError: If this method is invoked inside :meth:`scope, :meth:`frame`, or
        :meth:`window`.
    WindowError: If no window matches the given lambda.


original = self.current_window<EOL>if window != original:<EOL><INDENT>self.switch_to_window(window)<EOL><DEDENT>self._scopes.append(None)<EOL>try:<EOL><INDENT>yield<EOL><DEDENT>finally:<EOL><INDENT>self._scopes.pop()<EOL>if original != window:<EOL><INDENT>self.switch_to_window(original)<EOL><DEDENT><DEDENT>

This method does the following:

1. Switches to the given window (it can be located by window instance/lambda/string).
2. Executes the given block (within window located at previous step).
3. Switches back (this step will be invoked even if exception happens at second step).

Args:
    window (Window | lambda): The desired :class:`Window`, or a lambda that will be run in
        the context of each open window and returns ``True`` for the desired window.


def window_opened_by(self, trigger_func, wait=None):

old_handles = set(self.driver.window_handles)<EOL>trigger_func()<EOL>@self.document.synchronize(wait=wait, errors=(WindowError,))<EOL>def get_new_window():<EOL><INDENT>opened_handles = set(self.driver.window_handles) - old_handles<EOL>if len(opened_handles) != <NUM_LIT:1>:<EOL><INDENT>raise WindowError("<STR_LIT>"<EOL>"<STR_LIT>".format(len(opened_handles)))<EOL><DEDENT>return Window(self, list(opened_handles)[<NUM_LIT:0>])<EOL><DEDENT>return get_new_window()<EOL>

Get the window that has been opened by the passed lambda. It will wait for it to be opened
(in the same way as other Capybara methods wait). It's better to use this method than
``windows[-1]`` `as order of windows isn't defined in some drivers`__.

__ https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html#h_note_10

Args:
    trigger_func (func): The function that should trigger the opening of a new window.
    wait (int | float, optional): Maximum wait time. Defaults to
        :data:`capybara.default_max_wait_time`.

Returns:
    Window: The window that has been opened within the lambda.

Raises:
    WindowError: If lambda passed to window hasn't opened window or opened more than one
        window.


def execute_script(self, script, *args):

args = [arg.base if isinstance(arg, Base) else arg for arg in args]<EOL>self.driver.execute_script(script, *args)<EOL>

Execute the given script, not returning a result. This is useful for scripts that return
complex objects, such as jQuery statements. ``execute_script`` should be used over
:meth:`evaluate_script` whenever possible.

Args:
    script (str): A string of JavaScript to execute.
    *args: Variable length argument list to pass to the executed JavaScript string.


def evaluate_script(self, script, *args):

args = [arg.base if isinstance(arg, Base) else arg for arg in args]<EOL>result = self.driver.evaluate_script(script, *args)<EOL>return self._wrap_element_script_result(result)<EOL>

Evaluate the given JavaScript and return the result. Be careful when using this with
scripts that return complex objects, such as jQuery statements. :meth:`execute_script`
might be a better alternative.

Args:
    script (str): A string of JavaScript to evaluate.
    *args: Variable length argument list to pass to the executed JavaScript string.

Returns:
    object: The result of the evaluated JavaScript (may be driver specific).


def evaluate_async_script(self, script, *args):

args = [arg.base if isinstance(arg, Base) else arg for arg in args]<EOL>result = self.driver.evaluate_async_script(script, *args)<EOL>return self._wrap_element_script_result(result)<EOL>

Evaluate the given JavaScript and obtain the result from a callback function which will be
passed as the last argument to the script.

Args:
    script (str): A string of JavaScript to evaluate.
    *args: Variable length argument list to pass to the executed JavaScript string.

Returns:
    object: The result of the evaluated JavaScript (may be driver specific).


@contextmanager<EOL><INDENT>def accept_alert(self, text=None, wait=None):<DEDENT>

wait = wait or capybara.default_max_wait_time<EOL>with self.driver.accept_modal("<STR_LIT>", text=text, wait=wait):<EOL><INDENT>yield<EOL><DEDENT>

Execute the wrapped code, accepting an alert.

Args:
    text (str | RegexObject, optional): Text to match against the text in the modal.
    wait (int | float, optional): Maximum time to wait for the modal to appear after
        executing the wrapped code.

Raises:
    ModalNotFound: If a modal dialog hasn't been found.


@contextmanager<EOL><INDENT>def accept_confirm(self, text=None, wait=None):<DEDENT>

with self.driver.accept_modal("<STR_LIT>", text=text, wait=wait):<EOL><INDENT>yield<EOL><DEDENT>

Execute the wrapped code, accepting a confirm.

Args:
    text (str | RegexObject, optional): Text to match against the text in the modal.
    wait (int | float, optional): Maximum time to wait for the modal to appear after
        executing the wrapped code.

Raises:
    ModalNotFound: If a modal dialog hasn't been found.


@contextmanager<EOL><INDENT>def dismiss_confirm(self, text=None, wait=None):<DEDENT>

with self.driver.dismiss_modal("<STR_LIT>", text=text, wait=wait):<EOL><INDENT>yield<EOL><DEDENT>

Execute the wrapped code, dismissing a confirm.

Args:
    text (str | RegexObject, optional): Text to match against the text in the modal.
    wait (int | float, optional): Maximum time to wait for the modal to appear after
        executing the wrapped code.

Raises:
    ModalNotFound: If a modal dialog hasn't been found.


@contextmanager<EOL><INDENT>def accept_prompt(self, text=None, response=None, wait=None):<DEDENT>

with self.driver.accept_modal("<STR_LIT>", text=text, response=response, wait=wait):<EOL><INDENT>yield<EOL><DEDENT>

Execute the wrapped code, accepting a prompt, optionally responding to the prompt.

Args:
    text (str | RegexObject, optional): Text to match against the text in the modal.
    response (str, optional): Response to provide to the prompt.
    wait (int | float, optional): Maximum time to wait for the modal to appear after
        executing the wrapped code.

Raises:
    ModalNotFound: If a modal dialog hasn't been found.


@contextmanager<EOL><INDENT>def dismiss_prompt(self, text=None, wait=None):<DEDENT>

Execute the wrapped code, dismissing a prompt.

Args:
    text (str | RegexObject, optional): Text to match against the text in the modal.
    wait (int | float, optional): Maximum time to wait for the modal to appear after
        executing the wrapped code.

Raises:
    ModalNotFound: If a modal dialog hasn't been found.


path = _prepare_path(path, "<STR_LIT:html>")<EOL>with open(path, "<STR_LIT:wb>") as f:<EOL><INDENT>f.write(encode_string(self.body))<EOL><DEDENT>return path<EOL>

Save a snapshot of the page.

If invoked without arguments, it will save a file to :data:`capybara.save_path` and the
file will be given a randomly generated filename. If invoked with a relative path, the path
will be relative to :data:`capybara.save_path`.

Args:
    path (str, optional): The path to where it should be saved.

Returns:
    str: The path to which the file was saved.


def save_screenshot(self, path=None, **kwargs):

path = _prepare_path(path, "<STR_LIT>")<EOL>self.driver.save_screenshot(path, **kwargs)<EOL>return path<EOL>

Save a screenshot of the page.

If invoked without arguments, it will save a file to :data:`capybara.save_path` and the
file will be given a randomly generated filename. If invoked with a relative path, the path
will be relative to :data:`capybara.save_path`.

Args:
    path (str, optional): The path to where it should be saved.
    **kwargs: Arbitrary keywords arguments for the driver.

Returns:
    str: The path to which the file was saved.


self.driver.reset()<EOL>if self.server:<EOL><INDENT>self.server.wait_for_pending_requests()<EOL><DEDENT>self.raise_server_error()<EOL>

Reset the session (i.e., remove cookies and navigate to a blank page).

This method does not:
* accept modal dialogs if they are present (the Selenium driver does, but others may not),
* clear the browser cache/HTML 5 local storage/IndexedDB/Web SQL database/etc., or
* modify the state of the driver/underlying browser in any other way

as doing so would result in performance downsides and it's not needed to do everything
from the list above for most apps.

If you want to do anything from the list above on a general basis you can write a test
teardown method.


if self.server and self.server.error:<EOL><INDENT>try:<EOL><INDENT>if capybara.raise_server_errors:<EOL><INDENT>raise self.server.error<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>self.server.reset_error()<EOL><DEDENT><DEDENT>


def make_zone_file(json_zone_file_input, origin=None, ttl=None, template=None):

if template is None:<EOL><INDENT>template = DEFAULT_TEMPLATE[:]<EOL><DEDENT>json_zone_file = copy.deepcopy(json_zone_file_input)<EOL>if origin is not None:<EOL><INDENT>json_zone_file['<STR_LIT>'] = origin <EOL><DEDENT>if ttl is not None:<EOL><INDENT>json_zone_file['<STR_LIT>'] = ttl<EOL><DEDENT>soa_records = [json_zone_file.get('<STR_LIT>')] if json_zone_file.get('<STR_LIT>') else None<EOL>zone_file = template<EOL>zone_file = process_origin(json_zone_file.get('<STR_LIT>', None), zone_file)<EOL>zone_file = process_ttl(json_zone_file.get('<STR_LIT>', None), zone_file)<EOL>zone_file = process_soa(soa_records, zone_file)<EOL>zone_file = process_ns(json_zone_file.get('<STR_LIT>', None), zone_file)<EOL>zone_file = process_a(json_zone_file.get('<STR_LIT:a>', None), zone_file)<EOL>zone_file = process_aaaa(json_zone_file.get('<STR_LIT>', None), zone_file)<EOL>zone_file = process_cname(json_zone_file.get('<STR_LIT>', None), zone_file)<EOL>zone_file = process_alias(json_zone_file.get('<STR_LIT>', None), zone_file)<EOL>zone_file = process_mx(json_zone_file.get('<STR_LIT>', None), zone_file)<EOL>zone_file = process_ptr(json_zone_file.get('<STR_LIT>', None), zone_file)<EOL>zone_file = process_txt(json_zone_file.get('<STR_LIT>', None), zone_file)<EOL>zone_file = process_srv(json_zone_file.get('<STR_LIT>', None), zone_file)<EOL>zone_file = process_spf(json_zone_file.get('<STR_LIT>', None), zone_file)<EOL>zone_file = process_uri(json_zone_file.get('<STR_LIT>', None), zone_file)<EOL>zone_file = "<STR_LIT:\n>".join(<EOL>filter(<EOL>lambda l: len(l.strip()) > <NUM_LIT:0>, [tl.strip() for tl in zone_file.split("<STR_LIT:\n>")]<EOL>)<EOL>) + "<STR_LIT:\n>"<EOL>return zone_file<EOL>

Generate the DNS zonefile, given a json-encoded description of the
zone file (@json_zone_file) and the template to fill in (@template)

json_zone_file = {
    "$origin": origin server,
    "$ttl":    default time-to-live,
    "soa":     [ soa records ],
    "ns":      [ ns records ],
    "a":       [ a records ],
    "aaaa":    [ aaaa records ]
    "cname":   [ cname records ]
    "alias":   [ alias records ]
    "mx":      [ mx records ]
    "ptr":     [ ptr records ]
    "txt":     [ txt records ]
    "srv":     [ srv records ]
    "spf":     [ spf records ]
    "uri":     [ uri records ]
}


def make_rr_subparser(subparsers, rec_type, args_and_types):

sp = subparsers.add_parser(rec_type)<EOL>sp.add_argument("<STR_LIT:name>", type=str)<EOL>sp.add_argument("<STR_LIT>", type=int, nargs='<STR_LIT:?>')<EOL>sp.add_argument(rec_type, type=str)<EOL>for my_spec in args_and_types:<EOL><INDENT>(argname, argtype) = my_spec[:<NUM_LIT:2>]<EOL>if len(my_spec) > <NUM_LIT:2>:<EOL><INDENT>nargs = my_spec[<NUM_LIT:2>]<EOL>sp.add_argument(argname, type=argtype, nargs=nargs)<EOL><DEDENT>else:<EOL><INDENT>sp.add_argument(argname, type=argtype)<EOL><DEDENT><DEDENT>return sp<EOL>

Make a subparser for a given type of DNS record


line_parser = ZonefileLineParser()<EOL>subparsers = line_parser.add_subparsers()<EOL>sp = subparsers.add_parser("<STR_LIT>")<EOL>sp.add_argument("<STR_LIT>", type=str)<EOL>sp = subparsers.add_parser("<STR_LIT>")<EOL>sp.add_argument("<STR_LIT>", type=int)<EOL>args_and_types = [<EOL>("<STR_LIT>", str), ("<STR_LIT>", str), ("<STR_LIT>", int), ("<STR_LIT>", int),<EOL>("<STR_LIT>", int), ("<STR_LIT>", int), ("<STR_LIT>", int)<EOL>]<EOL>make_rr_subparser(subparsers, "<STR_LIT>", args_and_types)<EOL>make_rr_subparser(subparsers, "<STR_LIT>", [("<STR_LIT:host>", str)])<EOL>make_rr_subparser(subparsers, "<STR_LIT:A>", [("<STR_LIT>", str)])<EOL>make_rr_subparser(subparsers, "<STR_LIT>", [("<STR_LIT>", str)])<EOL>make_rr_subparser(subparsers, "<STR_LIT>", [("<STR_LIT>", str)])<EOL>make_rr_subparser(subparsers, "<STR_LIT>", [("<STR_LIT:host>", str)])<EOL>make_rr_subparser(subparsers, "<STR_LIT>", [("<STR_LIT>", str), ("<STR_LIT:host>", str)])<EOL>make_txt_subparser(subparsers)<EOL>make_rr_subparser(subparsers, "<STR_LIT>", [("<STR_LIT:host>", str)])<EOL>make_rr_subparser(subparsers, "<STR_LIT>", [("<STR_LIT>", int), ("<STR_LIT>", int), ("<STR_LIT:port>", int), ("<STR_LIT:target>", str)])<EOL>make_rr_subparser(subparsers, "<STR_LIT>", [("<STR_LIT:data>", str)])<EOL>make_rr_subparser(subparsers, "<STR_LIT>", [("<STR_LIT>", int), ("<STR_LIT>", int), ("<STR_LIT:target>", str)])<EOL>return line_parser<EOL>

Make an ArgumentParser that accepts DNS RRs


ret = []<EOL>escape = False<EOL>quote = False<EOL>tokbuf = "<STR_LIT>"<EOL>ll = list(line)<EOL>while len(ll) > <NUM_LIT:0>:<EOL><INDENT>c = ll.pop(<NUM_LIT:0>)<EOL>if c.isspace():<EOL><INDENT>if not quote and not escape:<EOL><INDENT>if len(tokbuf) > <NUM_LIT:0>:<EOL><INDENT>ret.append(tokbuf)<EOL><DEDENT>tokbuf = "<STR_LIT>"<EOL><DEDENT>elif quote:<EOL><INDENT>tokbuf += c<EOL><DEDENT>elif escape:<EOL><INDENT>tokbuf += c<EOL>escape = False<EOL><DEDENT>else:<EOL><INDENT>tokbuf = "<STR_LIT>"<EOL><DEDENT>continue<EOL><DEDENT>if c == '<STR_LIT:\\>':<EOL><INDENT>escape = True<EOL>continue<EOL><DEDENT>elif c == '<STR_LIT:">':<EOL><INDENT>if not escape:<EOL><INDENT>if quote:<EOL><INDENT>ret.append(tokbuf)<EOL>tokbuf = "<STR_LIT>"<EOL>quote = False<EOL>continue<EOL><DEDENT>else:<EOL><INDENT>quote = True<EOL>continue<EOL><DEDENT><DEDENT><DEDENT>elif c == '<STR_LIT:;>':<EOL><INDENT>if not escape:<EOL><INDENT>ret.append(tokbuf)<EOL>tokbuf = "<STR_LIT>"<EOL>break<EOL><DEDENT><DEDENT>tokbuf += c<EOL>escape = False<EOL><DEDENT>if len(tokbuf.strip("<STR_LIT:U+0020>").strip("<STR_LIT:\n>")) > <NUM_LIT:0>:<EOL><INDENT>ret.append(tokbuf)<EOL><DEDENT>return ret<EOL>

Tokenize a line:
* split tokens on whitespace
* treat quoted strings as a single token
* drop comments
* handle escaped spaces and comment delimiters


ret = []<EOL>for tok in tokens:<EOL><INDENT>if "<STR_LIT:U+0020>" in tok:<EOL><INDENT>tok = '<STR_LIT>' % tok<EOL><DEDENT>if "<STR_LIT:;>" in tok:<EOL><INDENT>tok = tok.replace("<STR_LIT:;>", "<STR_LIT>")<EOL><DEDENT>ret.append(tok)<EOL><DEDENT>return "<STR_LIT:U+0020>".join(ret)<EOL>

Serialize tokens:
* quote whitespace-containing tokens
* escape semicolons


ret = []<EOL>lines = text.split("<STR_LIT:\n>")<EOL>for line in lines:<EOL><INDENT>if len(line) == <NUM_LIT:0>:<EOL><INDENT>continue <EOL><DEDENT>line = serialize(tokenize_line(line))<EOL>ret.append(line)<EOL><DEDENT>return "<STR_LIT:\n>".join(ret)<EOL>


lines = text.split("<STR_LIT:\n>")<EOL>tokens = []<EOL>for l in lines:<EOL><INDENT>if len(l) == <NUM_LIT:0>:<EOL><INDENT>continue <EOL><DEDENT>l = l.replace("<STR_LIT:\t>", "<STR_LIT:U+0020>")<EOL>tokens += filter(lambda x: len(x) > <NUM_LIT:0>, l.split("<STR_LIT:U+0020>")) + ['<STR_LIT>']<EOL><DEDENT>capturing = False<EOL>captured = []<EOL>flattened = []<EOL>while len(tokens) > <NUM_LIT:0>:<EOL><INDENT>tok = tokens.pop(<NUM_LIT:0>)<EOL>if not capturing and len(tok) == <NUM_LIT:0>:<EOL><INDENT>if len(captured) > <NUM_LIT:0>:<EOL><INDENT>flattened.append("<STR_LIT:U+0020>".join(captured))<EOL>captured = []<EOL><DEDENT>continue <EOL><DEDENT>if tok.startswith("<STR_LIT:(>"):<EOL><INDENT>tok = tok.lstrip("<STR_LIT:(>")<EOL>capturing = True<EOL><DEDENT>if capturing and tok.endswith("<STR_LIT:)>"):<EOL><INDENT>tok = tok.rstrip("<STR_LIT:)>")<EOL>capturing = False <EOL><DEDENT>captured.append(tok)<EOL><DEDENT>return "<STR_LIT:\n>".join(flattened)<EOL>

Flatten the text:
* make sure each record is on one line.
* remove parenthesis


<EOL>lines = text.split("<STR_LIT:\n>")<EOL>ret = []<EOL>for line in lines:<EOL><INDENT>tokens = tokenize_line(line)<EOL>tokens_upper = [t.upper() for t in tokens]<EOL>if "<STR_LIT>" in tokens_upper:<EOL><INDENT>tokens.remove("<STR_LIT>")<EOL><DEDENT>elif "<STR_LIT>" in tokens_upper:<EOL><INDENT>tokens.remove("<STR_LIT>")<EOL><DEDENT>elif "<STR_LIT>" in tokens_upper:<EOL><INDENT>tokens.remove("<STR_LIT>")<EOL><DEDENT>elif "<STR_LIT>" in tokens_upper:<EOL><INDENT>tokens.remove("<STR_LIT>")<EOL><DEDENT>ret.append(serialize(tokens))<EOL><DEDENT>return "<STR_LIT:\n>".join(ret)<EOL>

Remove the CLASS from each DNS record, if present.
The only class that gets used today (for all intents
and purposes) is 'IN'.


global SUPPORTED_RECORDS<EOL>lines = text.split("<STR_LIT:\n>")<EOL>ret = []<EOL>for line in lines:<EOL><INDENT>tokens = tokenize_line(line)<EOL>if len(tokens) == <NUM_LIT:0>:<EOL><INDENT>continue<EOL><DEDENT>if tokens[<NUM_LIT:0>] in SUPPORTED_RECORDS and not tokens[<NUM_LIT:0>].startswith("<STR_LIT:$>"):<EOL><INDENT>tokens = ['<STR_LIT:@>'] + tokens <EOL><DEDENT>ret.append(serialize(tokens))<EOL><DEDENT>return "<STR_LIT:\n>".join(ret)<EOL>

Go through each line of the text and ensure that
a name is defined.  Use '@' if there is none.


def parse_line(parser, record_token, parsed_records):

global SUPPORTED_RECORDS<EOL>line = "<STR_LIT:U+0020>".join(record_token)<EOL>if len(record_token) >= <NUM_LIT:2> and record_token[<NUM_LIT:1>] in SUPPORTED_RECORDS:<EOL><INDENT>record_token = [record_token[<NUM_LIT:1>]] + record_token<EOL><DEDENT>elif len(record_token) >= <NUM_LIT:3> and record_token[<NUM_LIT:2>] in SUPPORTED_RECORDS:<EOL><INDENT>record_token = [record_token[<NUM_LIT:2>]] + record_token<EOL>if record_token[<NUM_LIT:0>] == "<STR_LIT>":<EOL><INDENT>record_token = record_token[:<NUM_LIT:2>] + ["<STR_LIT>"] + record_token[<NUM_LIT:2>:]<EOL><DEDENT><DEDENT>try:<EOL><INDENT>rr, unmatched = parser.parse_known_args(record_token)<EOL>assert len(unmatched) == <NUM_LIT:0>, "<STR_LIT>" % unmatched<EOL><DEDENT>except (SystemExit, AssertionError, InvalidLineException):<EOL><INDENT>raise InvalidLineException(line)<EOL><DEDENT>record_dict = rr.__dict__<EOL>if record_token[<NUM_LIT:0>] == "<STR_LIT>" and len(record_dict['<STR_LIT>']) == <NUM_LIT:1>:<EOL><INDENT>record_dict['<STR_LIT>'] = record_dict['<STR_LIT>'][<NUM_LIT:0>]<EOL><DEDENT>record_type = None<EOL>for key in record_dict.keys():<EOL><INDENT>if key in SUPPORTED_RECORDS and (key.startswith("<STR_LIT:$>") or record_dict[key] == key):<EOL><INDENT>record_type = key<EOL>if record_dict[key] == key:<EOL><INDENT>del record_dict[key]<EOL><DEDENT>break<EOL><DEDENT><DEDENT>assert record_type is not None, "<STR_LIT>" % rr<EOL>for field in record_dict.keys():<EOL><INDENT>if record_dict[field] is None:<EOL><INDENT>del record_dict[field]<EOL><DEDENT><DEDENT>current_origin = record_dict.get('<STR_LIT>', parsed_records.get('<STR_LIT>', None))<EOL>if record_type == '<STR_LIT>':<EOL><INDENT>record_dict['<STR_LIT>'] = record_dict['<STR_LIT:name>'] + '<STR_LIT:.>' + current_origin<EOL><DEDENT>if len(record_dict) > <NUM_LIT:0>:<EOL><INDENT>if record_type.startswith("<STR_LIT:$>"):<EOL><INDENT>record_dict_key = record_type.lower()<EOL>parsed_records[record_dict_key] = record_dict[record_type]<EOL><DEDENT>else:<EOL><INDENT>record_dict_key = record_type.lower()<EOL>parsed_records[record_dict_key].append(record_dict)<EOL><DEDENT><DEDENT>return parsed_records<EOL>

Given the parser, capitalized list of a line's tokens, and the current set of records
parsed so far, parse it into a dictionary.

Return the new set of parsed records.
Raise an exception on error.


json_zone_file = defaultdict(list)<EOL>record_lines = text.split("<STR_LIT:\n>")<EOL>parser = make_parser()<EOL>for record_line in record_lines:<EOL><INDENT>record_token = tokenize_line(record_line)<EOL>try:<EOL><INDENT>json_zone_file = parse_line(parser, record_token, json_zone_file)<EOL><DEDENT>except InvalidLineException:<EOL><INDENT>if ignore_invalid:<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT>return json_zone_file<EOL>

Parse a zonefile into a dict.
@text must be flattened--each record must be on one line.
Also, all comments must be removed.


text = remove_comments(text)<EOL>text = flatten(text)<EOL>text = remove_class(text)<EOL>text = add_default_name(text)<EOL>json_zone_file = parse_lines(text, ignore_invalid=ignore_invalid)<EOL>return json_zone_file<EOL>


raise InvalidLineException(message)<EOL>


record = "<STR_LIT>"<EOL>if data is not None:<EOL><INDENT>record += "<STR_LIT>" % data<EOL><DEDENT>return template.replace("<STR_LIT>", record)<EOL>

Replace {$origin} in template with a serialized $ORIGIN record


Replace {$ttl} in template with a serialized $TTL record


record = template[:]<EOL>if data is not None:<EOL><INDENT>assert len(data) == <NUM_LIT:1>, "<STR_LIT>"<EOL>data = data[<NUM_LIT:0>]<EOL>soadat = []<EOL>domain_fields = ['<STR_LIT>', '<STR_LIT>']<EOL>param_fields = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>for f in domain_fields + param_fields:<EOL><INDENT>assert f in data.keys(), "<STR_LIT>" % (f, data)<EOL><DEDENT>data_name = str(data.get('<STR_LIT:name>', '<STR_LIT:@>'))<EOL>soadat.append(data_name)<EOL>if data.get('<STR_LIT>') is not None:<EOL><INDENT>soadat.append( str(data['<STR_LIT>']) )<EOL><DEDENT>soadat.append("<STR_LIT>")<EOL>soadat.append("<STR_LIT>")<EOL>for key in domain_fields:<EOL><INDENT>value = str(data[key])<EOL>soadat.append(value)<EOL><DEDENT>soadat.append("<STR_LIT:(>")<EOL>for key in param_fields:<EOL><INDENT>value = str(data[key])<EOL>soadat.append(value)<EOL><DEDENT>soadat.append("<STR_LIT:)>")<EOL>soa_txt = "<STR_LIT:U+0020>".join(soadat)<EOL>record = record.replace("<STR_LIT>", soa_txt)<EOL><DEDENT>else:<EOL><INDENT>record = record.replace("<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>return record<EOL>

Replace {SOA} in template with a set of serialized SOA records


if data is None:<EOL><INDENT>return None <EOL><DEDENT>data_dup = copy.deepcopy(data)<EOL>for i in xrange(<NUM_LIT:0>, len(data_dup)):<EOL><INDENT>data_dup[i][field] = '<STR_LIT>' % data_dup[i][field]<EOL>data_dup[i][field] = data_dup[i][field].replace("<STR_LIT:;>", "<STR_LIT>")<EOL><DEDENT>return data_dup<EOL>

Quote a field in a list of DNS records.
Return the new data records.


def process_rr(data, record_type, record_keys, field, template):

if data is None:<EOL><INDENT>return template.replace(field, "<STR_LIT>")<EOL><DEDENT>if type(record_keys) == list:<EOL><INDENT>pass<EOL><DEDENT>elif type(record_keys) == str:<EOL><INDENT>record_keys = [record_keys]<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>assert type(data) == list, "<STR_LIT>"<EOL>record = "<STR_LIT>"<EOL>for i in xrange(<NUM_LIT:0>, len(data)):<EOL><INDENT>for record_key in record_keys:<EOL><INDENT>assert record_key in data[i].keys(), "<STR_LIT>" % record_key<EOL><DEDENT>record_data = []<EOL>record_data.append( str(data[i].get('<STR_LIT:name>', '<STR_LIT:@>')) )<EOL>if data[i].get('<STR_LIT>') is not None:<EOL><INDENT>record_data.append( str(data[i]['<STR_LIT>']) )<EOL><DEDENT>record_data.append(record_type)<EOL>record_data += [str(data[i][record_key]) for record_key in record_keys]<EOL>record += "<STR_LIT:U+0020>".join(record_data) + "<STR_LIT:\n>"<EOL><DEDENT>return template.replace(field, record)<EOL>

Meta method:
Replace $field in template with the serialized $record_type records,
using @record_key from each datum.


return process_rr(data, "<STR_LIT>", "<STR_LIT:host>", "<STR_LIT>", template)<EOL>

Replace {ns} in template with the serialized NS records


return process_rr(data, "<STR_LIT:A>", "<STR_LIT>", "<STR_LIT>", template)<EOL>

Replace {a} in template with the serialized A records


return process_rr(data, "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", template)<EOL>

Replace {aaaa} in template with the serialized A records


Replace {cname} in template with the serialized CNAME records


Replace {alias} in template with the serialized ALIAS records


return process_rr(data, "<STR_LIT>", ["<STR_LIT>", "<STR_LIT:host>"], "<STR_LIT>", template)<EOL>

Replace {mx} in template with the serialized MX records


Replace {ptr} in template with the serialized PTR records


if data is None:<EOL><INDENT>to_process = None<EOL><DEDENT>else:<EOL><INDENT>to_process = copy.deepcopy(data)<EOL>for datum in to_process:<EOL><INDENT>if isinstance(datum["<STR_LIT>"], list):<EOL><INDENT>datum["<STR_LIT>"] = "<STR_LIT:U+0020>".join(['<STR_LIT>' % entry.replace("<STR_LIT:;>", "<STR_LIT>")<EOL>for entry in datum["<STR_LIT>"]])<EOL><DEDENT>else:<EOL><INDENT>datum["<STR_LIT>"] = '<STR_LIT>' % datum["<STR_LIT>"].replace("<STR_LIT:;>", "<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT>return process_rr(to_process, "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", template)<EOL>

Replace {txt} in template with the serialized TXT records


return process_rr(data, "<STR_LIT>", ["<STR_LIT>", "<STR_LIT>", "<STR_LIT:port>", "<STR_LIT:target>"], "<STR_LIT>", template)<EOL>

Replace {srv} in template with the serialized SRV records


return process_rr(data, "<STR_LIT>", "<STR_LIT:data>", "<STR_LIT>", template)<EOL>

Replace {spf} in template with the serialized SPF records


<EOL>data_dup = quote_field(data, "<STR_LIT:target>")<EOL>return process_rr(data_dup, "<STR_LIT>", ["<STR_LIT>", "<STR_LIT>", "<STR_LIT:target>"], "<STR_LIT>", template)<EOL>

Replace {uri} in templtae with the serialized URI records


UnusualModel = apps.get_model("<STR_LIT>", "<STR_LIT>")<EOL>UnusualModel.objects.all().delete()<EOL>

Brutally deleting all entries for this model...


Resource = apps.get_model("<STR_LIT>", "<STR_LIT>")<EOL>Resource.objects.all().delete()<EOL>TypeResource = apps.get_model("<STR_LIT>", "<STR_LIT>")<EOL>TypeResource.objects.all().delete()<EOL>


bits = token.contents.split('<STR_LIT:U+0020>')<EOL>if len(bits) <= <NUM_LIT:1>:<EOL><INDENT>raise template.TemplateSyntaxError("<STR_LIT>" % bits[<NUM_LIT:0>])<EOL><DEDENT>if token.contents[<NUM_LIT>] == '<STR_LIT:">':<EOL><INDENT>end_quote = token.contents.index('<STR_LIT:">', <NUM_LIT>) + <NUM_LIT:1><EOL>args = [template.Variable(token.contents[<NUM_LIT>:end_quote])]<EOL>kwargs_start = end_quote<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>next_space = token.contents.index('<STR_LIT:U+0020>', <NUM_LIT>)<EOL>kwargs_start = next_space + <NUM_LIT:1><EOL><DEDENT>except ValueError:<EOL><INDENT>next_space = None<EOL>kwargs_start = None<EOL><DEDENT>args = [template.Variable(token.contents[<NUM_LIT>:next_space])]<EOL><DEDENT>kwargs = {}<EOL>kwargs_list = token.contents[kwargs_start:].split('<STR_LIT:U+002C>')<EOL>for kwargs_item in kwargs_list:<EOL><INDENT>if '<STR_LIT:=>' in kwargs_item:<EOL><INDENT>k, v = kwargs_item.split('<STR_LIT:=>', <NUM_LIT:1>)<EOL>k = k.strip()<EOL>kwargs[k] = template.Variable(v)<EOL><DEDENT><DEDENT>return args, kwargs<EOL>

Parse uniformly args and kwargs from a templatetag

Usage::

  For parsing a template like this:

  {% footag my_contents,height=10,zoom=20 as myvar %}

  You simply do this:

  @register.tag
  def footag(parser, token):
      args, kwargs = parse_args_kwargs(parser, token)


def prepare_context(self, args, kwargs, context):

return context<EOL>

Hook for overriding in subclasses.

Note that "args" and "kwargs" parameters are already resolved with context


nodelist = parser.parse(('<STR_LIT>',))<EOL>class EvalNode(template.Node):<EOL><INDENT>def render(self, context):<EOL><INDENT>return template.Template(nodelist.render(context)).render(template.Context(context))<EOL><DEDENT><DEDENT>parser.delete_first_token()<EOL>return EvalNode()<EOL>


@classmethod<EOL><INDENT>def get_config(self, request, **kwargs):<DEDENT>

config = kwargs<EOL>config_from_settings = deepcopy(inplace_settings.DEFAULT_INPLACE_EDIT_OPTIONS)<EOL>config_one_by_one = inplace_settings.DEFAULT_INPLACE_EDIT_OPTIONS_ONE_BY_ONE<EOL>if not config_one_by_one:<EOL><INDENT>if not config and config_from_settings:<EOL><INDENT>config = config_from_settings<EOL><DEDENT><DEDENT>else:<EOL><INDENT>config = dict(config_from_settings, **config)<EOL><DEDENT>return config<EOL>

Get the arguments given to the template tag element and complete these
with the ones from the settings.py if necessary.


edit_empty_value = self.config.get('<STR_LIT>', False)<EOL>if edit_empty_value:<EOL><INDENT>return edit_empty_value<EOL><DEDENT>else:<EOL><INDENT>return unicode(inplace_settings.INPLACEEDIT_EDIT_EMPTY_VALUE)<EOL><DEDENT>

Get the text to display when the field is empty.


obj_dict = obj.__dict__<EOL>obj_dict_result = obj_dict.copy()<EOL>for key, value in obj_dict.items():<EOL><INDENT>if key.endswith('<STR_LIT>'):<EOL><INDENT>key2 = key.replace('<STR_LIT>', '<STR_LIT>')<EOL>try:<EOL><INDENT>field, model, direct, m2m = obj._meta.get_field_by_name(key2)<EOL>if isinstance(field, ForeignKey):<EOL><INDENT>obj_dict_result[key2] = obj_dict_result[key]<EOL>del obj_dict_result[key]<EOL><DEDENT><DEDENT>except FieldDoesNotExist:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>manytomany_list = obj._meta.many_to_many<EOL>for manytomany in manytomany_list:<EOL><INDENT>pks = [obj_rel.pk for obj_rel in manytomany.value_from_object(obj).select_related()]<EOL>if pks:<EOL><INDENT>obj_dict_result[manytomany.name] = pks<EOL><DEDENT><DEDENT>return obj_dict_result<EOL>

Edit to get the dict even when the object is a GenericRelatedObjectManager.
Added the try except.


return getattr(settings, '<STR_LIT>', get_static_url() + "<STR_LIT>")<EOL>

Return the ADMIN_MEDIA_PREFIX if it is in the settings.py else get
the static url from the previous function and add /admin/.


def to_raw_text_markupless(text, keep_whitespace=False, normalize_ascii=True):

return sent_tokenize(<EOL>remove_dates(_remove_urls(text)),<EOL>keep_whitespace,<EOL>normalize_ascii<EOL>)<EOL>

A generator to convert raw text segments, without xml to a
list of words without any markup.
Additionally dates are replaced by `7777` for normalization.

Arguments
---------
    text: str, input text to tokenize, strip of markup.
    keep_whitespace : bool, should the output retain the
        whitespace of the input (so that char offsets in the
        output correspond to those in the input).

Returns
-------
    generator<list<list<str>>>, a generator for sentences, with
        within each sentence a list of the words separated.


def to_raw_text(text, keep_whitespace=False, normalize_ascii=True):

out = text<EOL>out = _remove_urls(text)<EOL>out = _remove_mvar(out)<EOL>out = _remove_squiggly_bracket(out)<EOL>out = _remove_table(out)<EOL>out = _remove_brackets(out)<EOL>out = remove_remaining_double_brackets(out)<EOL>out = remove_markup(out)<EOL>out = remove_wikipedia_link.sub(anchor_replacer, out)<EOL>out = remove_bullets_nbsps.sub(empty_space, out)<EOL>out = remove_dates(out)<EOL>out = remove_math_sections(out)<EOL>out = remove_html(out)<EOL>out = sent_tokenize(out, keep_whitespace, normalize_ascii)<EOL>return out<EOL>

A generator to convert raw text segments, with xml, and other
non-textual content to a list of words without any markup.
Additionally dates are replaced by `7777` for normalization.

Arguments
---------
   text: str, input text to tokenize, strip of markup.
   keep_whitespace : bool, should the output retain the
      whitespace of the input (so that char offsets in the
      output correspond to those in the input).

Returns
-------
    generator<list<list<str>>>, a generator for sentences, with
        within each sentence a list of the words separated.


def to_raw_text_pairings(text, keep_whitespace=False, normalize_ascii=True):

out = text<EOL>out = _remove_mvar(out)<EOL>out = _remove_squiggly_bracket(out)<EOL>out = _remove_table(out)<EOL>out = remove_markup(out)<EOL>out = remove_wikipedia_link.sub(anchor_replacer, out)<EOL>out = remove_bullets_nbsps.sub(empty_space, out)<EOL>out = remove_math_sections(out)<EOL>out = remove_html(out)<EOL>for sentence in sent_tokenize(out, keep_whitespace, normalize_ascii):<EOL><INDENT>yield sentence<EOL><DEDENT>

A generator to convert raw text segments, with xml, and other
non-textual content to a list of words without any markup.
Additionally dates are replaced by `7777` for normalization,
along with wikipedia anchors kept.

Arguments
---------
   text: str, input text to tokenize, strip of markup.
   keep_whitespace : bool, should the output retain the
      whitespace of the input (so that char offsets in the
      output correspond to those in the input).

Returns
-------
    generator<list<list<str>>>, a generator for sentences, with
        within each sentence a list of the words separated.


tokenized = group_quoted_tokens(tokens)<EOL>words = []<EOL>sentences = []<EOL>for i in range(len(tokenized)):<EOL><INDENT>end_sentence = False<EOL>if isinstance(tokenized[i], list):<EOL><INDENT>if len(words) == <NUM_LIT:0>:<EOL><INDENT>if is_end_symbol(tokenized[i][-<NUM_LIT:2>].rstrip()):<EOL><INDENT>end_sentence = True<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if (tokenized[i][<NUM_LIT:0>][<NUM_LIT:0>] == '<STR_LIT:">' and<EOL>is_end_symbol(tokenized[i][-<NUM_LIT:2>].rstrip()) and<EOL>not tokenized[i][<NUM_LIT:1>][<NUM_LIT:0>].isupper()):<EOL><INDENT>end_sentence = True<EOL><DEDENT><DEDENT>words.extend(tokenized[i])<EOL><DEDENT>else:<EOL><INDENT>stripped_tokenized = tokenized[i].rstrip()<EOL>if is_end_symbol(stripped_tokenized):<EOL><INDENT>words.append(tokenized[i])<EOL>not_last_word = i + <NUM_LIT:1> != len(tokenized)<EOL>next_word_lowercase = (<EOL>not_last_word and<EOL>tokenized[i+<NUM_LIT:1>][<NUM_LIT:0>].islower()<EOL>)<EOL>next_word_continue_punct = (<EOL>not_last_word and<EOL>tokenized[i+<NUM_LIT:1>][<NUM_LIT:0>] in CONTINUE_PUNCT_SYMBOLS<EOL>)<EOL>end_sentence = not (<EOL>not_last_word and<EOL>(<EOL>next_word_lowercase or<EOL>next_word_continue_punct<EOL>)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>words.append(tokenized[i])<EOL><DEDENT><DEDENT>if end_sentence:<EOL><INDENT>sentences.append(words)<EOL>words = []<EOL><DEDENT><DEDENT>if len(words) > <NUM_LIT:0>:<EOL><INDENT>sentences.append(words)<EOL><DEDENT>if len(sentences) > <NUM_LIT:0> and sentences[-<NUM_LIT:1>][-<NUM_LIT:1>]:<EOL><INDENT>alpha_word_piece = word_with_alpha_and_period.match(sentences[-<NUM_LIT:1>][-<NUM_LIT:1>])<EOL>if alpha_word_piece:<EOL><INDENT>sentences[-<NUM_LIT:1>][-<NUM_LIT:1>] = alpha_word_piece.group(<NUM_LIT:1>)<EOL>sentences[-<NUM_LIT:1>].append(alpha_word_piece.group(<NUM_LIT:2>))<EOL><DEDENT><DEDENT>return sentences<EOL>

Subdivide an input list of strings (tokens)
into multiple lists according to detected
sentence boundaries.

```
detect_sentence_boundaries(
    ["Cat ", "sat ", "mat", ". ", "Cat ", "'s ", "named ", "Cool", "."]
)
#=> [
    ["Cat ", "sat ", "mat", ". "],
    ["Cat ", "'s ", "named ", "Cool", "."]
]
```

Arguments:
----------

    tokens : list<str>

Returns:
--------
    list<list<str>> : original list subdivided into multiple
        lists according to (detected) sentence boundaries.


return [[w.rstrip() for w in sent] for sent in sentences]<EOL>

Clear out spaces and newlines
from the list of list of strings.

Arguments:
----------
    sentences : list<list<str>>

Returns:
--------
    list<list<str>> : same strings as input,
        without spaces or newlines.


def sent_tokenize(text, keep_whitespace=False, normalize_ascii=True):

sentences = detect_sentence_boundaries(<EOL>tokenize(<EOL>text,<EOL>normalize_ascii<EOL>)<EOL>)<EOL>if not keep_whitespace:<EOL><INDENT>sentences = remove_whitespace(sentences)<EOL><DEDENT>return sentences<EOL>

Perform sentence + word tokenization on the input text
using regular expressions and english/french specific
rules.

Arguments:
----------
    text : str, input string to tokenize
    keep_whitespace : bool, whether to strip out spaces
        and newlines.
    normalize_ascii : bool, perform some replacements
        on rare characters so that they become
        easier to process in a ascii pipeline
        (canonicalize dashes, replace œ -> oe, etc..)
Returns:
--------
    list<list<str>> : sentences with their content held
        in a list of strings for each token.


word_matches = list(re.finditer(word_with_period, text))<EOL>total_words = len(word_matches)<EOL>for i, match in enumerate(word_matches):<EOL><INDENT>match_start = match.start()<EOL>match_end = match.end()<EOL>for char_pos in range(match_start, match_end):<EOL><INDENT>if split_locations[char_pos] == SHOULD_SPLIT and match_end - char_pos > <NUM_LIT:1>:<EOL><INDENT>match_start = char_pos<EOL><DEDENT><DEDENT>word = text[match_start:match_end]<EOL>if not word.endswith('<STR_LIT:.>'):<EOL><INDENT>if (not word[<NUM_LIT:0>].isdigit() and<EOL>split_locations[match_start] == UNDECIDED):<EOL><INDENT>split_locations[match_start] = SHOULD_SPLIT<EOL><DEDENT>continue<EOL><DEDENT>period_pos = match_end - <NUM_LIT:1><EOL>word_is_in_abbr = word[:-<NUM_LIT:1>].lower() in ABBR<EOL>is_abbr_like = (<EOL>word_is_in_abbr or<EOL>one_letter_long_or_repeating.match(word[:-<NUM_LIT:1>]) is not None<EOL>)<EOL>is_digit = False if is_abbr_like else word[:-<NUM_LIT:1>].isdigit()<EOL>is_last_word = i == (total_words - <NUM_LIT:1>)<EOL>is_ending = is_last_word and (match_end == len(text) or text[match_end:].isspace())<EOL>is_not_ending = not is_ending<EOL>abbreviation_and_not_end = (<EOL>len(word) > <NUM_LIT:1> and<EOL>is_abbr_like and<EOL>is_not_ending<EOL>)<EOL>if abbreviation_and_not_end and (<EOL>(not is_last_word and word_matches[i+<NUM_LIT:1>].group(<NUM_LIT:0>)[<NUM_LIT:0>].islower()) or<EOL>(not is_last_word and word_matches[i+<NUM_LIT:1>].group(<NUM_LIT:0>) in PUNCT_SYMBOLS) or<EOL>word[<NUM_LIT:0>].isupper() or<EOL>word_is_in_abbr or<EOL>len(word) == <NUM_LIT:2>):<EOL><INDENT>if split_locations[period_pos] == SHOULD_SPLIT and period_pos + <NUM_LIT:1> < len(split_locations):<EOL><INDENT>split_locations[period_pos + <NUM_LIT:1>] = SHOULD_SPLIT<EOL><DEDENT>split_locations[period_pos] = SHOULD_NOT_SPLIT<EOL><DEDENT>elif (is_digit and<EOL>len(word[:-<NUM_LIT:1>]) <= <NUM_LIT:2> and<EOL>not is_last_word and<EOL>word_matches[i+<NUM_LIT:1>].group(<NUM_LIT:0>).lower() in MONTHS):<EOL><INDENT>if split_locations[period_pos] == SHOULD_SPLIT and period_pos + <NUM_LIT:1> < len(split_locations):<EOL><INDENT>split_locations[period_pos + <NUM_LIT:1>] = SHOULD_SPLIT<EOL><DEDENT>split_locations[period_pos] = SHOULD_NOT_SPLIT<EOL><DEDENT>elif split_locations[period_pos] == UNDECIDED:<EOL><INDENT>split_locations[period_pos] = SHOULD_SPLIT<EOL><DEDENT><DEDENT>

Annotate locations in a string that contain
periods as being true periods or periods
that are a part of shorthand (and thus should
not be treated as punctuation marks).

Arguments:
----------
    text : str
    split_locations : list<int>, same length as text.


start = <NUM_LIT:0><EOL>for pos, decision in enumerate(locations):<EOL><INDENT>if decision == SHOULD_SPLIT:<EOL><INDENT>if start != pos:<EOL><INDENT>yield text[start:pos]<EOL><DEDENT>start = pos<EOL><DEDENT><DEDENT>if start != len(text):<EOL><INDENT>yield text[start:]<EOL><DEDENT>

Use an integer list to split the string
contained in `text`.

Arguments:
----------
    text : str, same length as locations.
    locations : list<int>, contains values
        'SHOULD_SPLIT', 'UNDECIDED', and
        'SHOULD_NOT_SPLIT'. Will create
        strings between each 'SHOULD_SPLIT'
        locations.
Returns:
--------
    Generator<str> : the substrings of text
        corresponding to the slices given
        in locations.


def mark_regex(regex, text, split_locations):

for match in regex.finditer(text):<EOL><INDENT>end_match = match.end()<EOL>if end_match < len(split_locations):<EOL><INDENT>split_locations[end_match] = SHOULD_SPLIT<EOL><DEDENT><DEDENT>

Regex that adds a 'SHOULD_SPLIT' marker at the end
location of each matching group of the given regex.

Arguments
---------
    regex : re.Expression
    text : str, same length as split_locations
    split_locations : list<int>, split decisions.


def mark_begin_end_regex(regex, text, split_locations):

for match in regex.finditer(text):<EOL><INDENT>end_match = match.end()<EOL>begin_match = match.start()<EOL>for i in range(begin_match+<NUM_LIT:1>, end_match):<EOL><INDENT>split_locations[i] = SHOULD_NOT_SPLIT<EOL><DEDENT>if end_match < len(split_locations):<EOL><INDENT>if split_locations[end_match] == UNDECIDED:<EOL><INDENT>split_locations[end_match] = SHOULD_SPLIT<EOL><DEDENT><DEDENT>if split_locations[begin_match] == UNDECIDED:<EOL><INDENT>split_locations[begin_match] = SHOULD_SPLIT<EOL><DEDENT><DEDENT>

Regex that adds a 'SHOULD_SPLIT' marker at the end
location of each matching group of the given regex,
and adds a 'SHOULD_SPLIT' at the beginning of the
matching group. Each character within the matching
group will be marked as 'SHOULD_NOT_SPLIT'.

Arguments
---------
    regex : re.Expression
    text : str, same length as split_locations
    split_locations : list<int>, split decisions.


<EOL>if no_punctuation.match(text):<EOL><INDENT>return [text]<EOL><DEDENT>if normalize_ascii:<EOL><INDENT>text = text.replace(u"<STR_LIT>", "<STR_LIT>").replace(u"<STR_LIT>", "<STR_LIT>")<EOL>text = repeated_dash_converter.sub("<STR_LIT:->", text)<EOL><DEDENT>split_locations = [UNDECIDED] * len(text)<EOL>regexes = (<EOL>pure_whitespace,<EOL>left_quote_shifter,<EOL>left_quote_converter,<EOL>left_single_quote_converter,<EOL>remaining_quote_converter,<EOL>english_nots,<EOL>english_contractions,<EOL>english_specific_appendages,<EOL>french_appendages<EOL>)<EOL>for regex in regexes:<EOL><INDENT>mark_regex(regex, text, split_locations)<EOL><DEDENT>begin_end_regexes = (<EOL>multi_single_quote_finder,<EOL>right_single_quote_converter,<EOL>simple_dash_finder if normalize_ascii else advanced_dash_finder,<EOL>numerical_expression,<EOL>url_file_finder,<EOL>shifted_ellipses,<EOL>shifted_standard_punctuation<EOL>)<EOL>for regex in begin_end_regexes:<EOL><INDENT>mark_begin_end_regex(regex, text, split_locations)<EOL><DEDENT>protect_shorthand(text, split_locations)<EOL>if normalize_ascii:<EOL><INDENT>text = dash_converter.sub("<STR_LIT:->", text)<EOL><DEDENT>return list(split_with_locations(text, split_locations))<EOL>

Convert a single string into a list of substrings
split along punctuation and word boundaries. Keep
whitespace intact by always attaching it to the
previous token.

Arguments:
----------
    text : str
    normalize_ascii : bool, perform some replacements
        on non-ascii characters to canonicalize the
        string (defaults to True).

Returns:
--------
    list<str>, list of substring tokens.


def wrapper(*args, **kargs):<EOL><INDENT>callStr = "<STR_LIT>" % (func.__name__, "<STR_LIT:U+002CU+0020>".join([repr(p) for p in args] + ["<STR_LIT>" % (k, repr(v)) for (k, v) in list(kargs.items())]))<EOL>debug("<STR_LIT>", callStr)<EOL>ret = func(*args, **kargs)<EOL>debug("<STR_LIT>", callStr, repr(ret))<EOL>return ret<EOL><DEDENT>return wrapper<EOL>


func.__lock__ = threading.Lock()<EOL>def synced_func(*args, **kargs):<EOL><INDENT>with func.__lock__:<EOL><INDENT>return func(*args, **kargs)<EOL><DEDENT><DEDENT>return synced_func<EOL>


Clear previous progress message, if any.


<EOL>if not (sys.stdout.isatty() and sys.stderr.isatty()):<EOL><INDENT>return<EOL><DEDENT>text = (msg % args)<EOL>if progress.prev_message:<EOL><INDENT>sys.stderr.write('<STR_LIT:U+0020>' * len(progress.prev_message) + '<STR_LIT:\r>')<EOL><DEDENT>sys.stderr.write(text + '<STR_LIT:\r>')<EOL>progress.prev_message = text<EOL>

Show current progress message to stderr.
       This function will remember the previous message so that next time,
       it will clear the previous message before showing next one.


clear_progress()<EOL>text = (msg % args)<EOL>sys.stdout.write(text + '<STR_LIT:\n>')<EOL>


def fail(message, exc_info=None, status=<NUM_LIT:1>, stacktrace=False):

text = message<EOL>if exc_info:<EOL><INDENT>text += str(exc_info)<EOL><DEDENT>error(text)<EOL>if stacktrace:<EOL><INDENT>error(traceback.format_exc())<EOL><DEDENT>clean_tempfiles()<EOL>if __name__ == '<STR_LIT:__main__>':<EOL><INDENT>sys.exit(status)<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError(status)<EOL><DEDENT>

Utility function to handle runtime failures gracefully.
       Show concise information if possible, then terminate program.


fn = '<STR_LIT>' % (target, '<STR_LIT>'.join(random.Random().sample("<STR_LIT>", <NUM_LIT:15>)))<EOL>TEMP_FILES.add(fn)<EOL>return fn<EOL>

Get a temp filename for atomic download.


if target:<EOL><INDENT>os.rename(tempfile, target)<EOL><DEDENT>else:<EOL><INDENT>os.unlink(tempfile)<EOL><DEDENT>if target in TEMP_FILES:<EOL><INDENT>TEMP_FILES.remove(tempfile)<EOL><DEDENT>


for fn in TEMP_FILES:<EOL><INDENT>if os.path.exists(fn):<EOL><INDENT>os.unlink(fn)<EOL><DEDENT><DEDENT>


return self.log.debug, self.log.info, self.log.warn, self.log.error<EOL>

Return a list of the logger methods: (debug, info, warn, error)


try:<EOL><INDENT>self.proto, self.bucket, self.path = S3URL.S3URL_PATTERN.match(uri).groups()<EOL>self.proto = '<STR_LIT>' <EOL><DEDENT>except:<EOL><INDENT>raise InvalidArgument('<STR_LIT>' % uri)<EOL><DEDENT>


return S3URL.combine(self.proto, self.bucket, self.path)<EOL>


pi = self.path.split(PATH_SEP)<EOL>fi = []<EOL>for p in pi:<EOL><INDENT>if '<STR_LIT:*>' in p or '<STR_LIT:?>' in p:<EOL><INDENT>break<EOL><DEDENT>fi.append(p)<EOL><DEDENT>return PATH_SEP.join(fi)<EOL>

Get the fixed part of the path without wildcard


@staticmethod<EOL><INDENT>def combine(proto, bucket, path):<DEDENT>

return '<STR_LIT>' % (proto, bucket, path)<EOL>

Combine each component and general a S3 url string, no path normalization
           here. The path should not start with slash.


return S3URL.S3URL_PATTERN.match(uri) != None<EOL>


def __init__(self, opt, aws_access_key_id=None, aws_secret_access_key=None):

self.opt = opt<EOL>if (aws_access_key_id is not None) and (aws_secret_access_key is not None):<EOL><INDENT>self.client = self.boto3.client('<STR_LIT>',<EOL>aws_access_key_id=aws_access_key_id,<EOL>aws_secret_access_key=aws_secret_access_key,<EOL>endpoint_url=opt.endpoint_url)<EOL><DEDENT>else:<EOL><INDENT>self.client = self.boto3.client('<STR_LIT>', endpoint_url=opt.endpoint_url)<EOL><DEDENT>self.legal_params = {}<EOL>for method in BotoClient.ALLOWED_CLIENT_METHODS:<EOL><INDENT>self.legal_params[method] = self.get_legal_params(method)<EOL><DEDENT>

Initialize boto3 API bridge class. Calculate and cache all legal parameters
           for each method we are going to call.


if method in BotoClient.ALLOWED_CLIENT_METHODS:<EOL><INDENT>def wrapped_method(*args, **kargs):<EOL><INDENT>merged_kargs = self.merge_opt_params(method, kargs)<EOL>callStr = "<STR_LIT>" % ("<STR_LIT>" + method, "<STR_LIT:U+002CU+0020>".join([repr(p) for p in args] + ["<STR_LIT>" % (k, repr(v)) for (k, v) in list(kargs.items())]))<EOL>debug("<STR_LIT>", callStr)<EOL>ret = getattr(self.client, method)(*args, **merged_kargs)<EOL>debug("<STR_LIT>", callStr, repr(ret))<EOL>return ret<EOL><DEDENT>return wrapped_method<EOL><DEDENT>return super(BotoClient, self).__getattribute__(method)<EOL>

Intercept boto3 API call to inject our extra options.


if method not in self.client.meta.method_to_api_mapping:<EOL><INDENT>return []<EOL><DEDENT>api = self.client.meta.method_to_api_mapping[method]<EOL>shape = self.client.meta.service_model.operation_model(api).input_shape<EOL>if shape is None:<EOL><INDENT>return []<EOL><DEDENT>return shape.members.keys()<EOL>

Given a API name, list all legal parameters using boto3 service model.


def merge_opt_params(self, method, kargs):

for key in self.legal_params[method]:<EOL><INDENT>if not hasattr(self.opt, key) or getattr(self.opt, key) is None:<EOL><INDENT>continue<EOL><DEDENT>if key in kargs and type(kargs[key]) == dict:<EOL><INDENT>assert(type(getattr(self.opt, key)) == dict)<EOL>for k, v in getattr(self.opt, key).iteritems():<EOL><INDENT>kargs[key][k] = v<EOL><DEDENT><DEDENT>else:<EOL><INDENT>kargs[key] = getattr(self.opt, key)<EOL><DEDENT><DEDENT>return kargs<EOL>

Combine existing parameters with extra options supplied from command line
           options. Carefully merge special type of parameter if needed.


for param, param_type, param_doc in BotoClient.EXTRA_CLIENT_PARAMS:<EOL><INDENT>parser.add_option('<STR_LIT>' + param, help=param_doc, type=param_type, dest=param)<EOL><DEDENT>

Add the whole list of API parameters into optparse.


self.client = None<EOL>


Override original join() with a timeout and handle keyboard interrupt.


if exc_info:<EOL><INDENT>self.exc_info = exc_info<EOL><DEDENT>try:<EOL><INDENT>while self.get_nowait():<EOL><INDENT>self.task_done()<EOL><DEDENT><DEDENT>except Queue.Empty:<EOL><INDENT>pass<EOL><DEDENT>

Terminate all threads by deleting the queue and forcing the child threads
           to quit.


self.opt = opt<EOL>self.tasks = TaskQueue()<EOL>self.processed_tasks = <NUM_LIT:0><EOL>self.thread_class = thread_class<EOL>self.workers = []<EOL>for i in range(opt.num_threads):<EOL><INDENT>self.workers.append(thread_class(self))<EOL><DEDENT>

Constructor of ThreadPool.
           Create workers and pool will automatically inherit all methods from
           thread_class by redirecting calls through __getattribute__().


return self<EOL>


def __exit__(self, exc_type, exc_value, traceback):

self.join()<EOL>return isinstance(exc_value, TypeError)<EOL>

Utility function for with statement, wait for completion


try:<EOL><INDENT>attr = super(ThreadPool, self).__getattribute__(name)<EOL><DEDENT>except AttributeError as e:<EOL><INDENT>if name in self.thread_class.__dict__:<EOL><INDENT>def deferred_task(*args, **kargs):<EOL><INDENT>self.add_task(name, *args, **kargs)<EOL><DEDENT>attr = deferred_task<EOL><DEDENT>else:<EOL><INDENT>raise AttributeError('<STR_LIT>' % name)<EOL><DEDENT><DEDENT>return attr<EOL>

Special attribute accessor to add tasks into task queue.
           Here if we found a function not in ThreadPool, we will try
           to see if we have a function in the utility class. If so, we
           add the function call into task queue.


def add_task(self, func_name, *args, **kargs):

self.tasks.put((func_name, <NUM_LIT:0>, args, kargs))<EOL>

Utility function to add a single task into task queue


self.tasks.join()<EOL>for worker in self.workers:<EOL><INDENT>self.tasks.put(None)<EOL><DEDENT>for worker in self.workers:<EOL><INDENT>worker.join()<EOL>worker.s3 = None<EOL><DEDENT>

Utility function to wait all tasks to complete


self.processed_tasks += <NUM_LIT:1><EOL>qsize = self.tasks.qsize()<EOL>if qsize > <NUM_LIT:0>:<EOL><INDENT>progress('<STR_LIT>', self.processed_tasks, qsize, len(self.workers))<EOL><DEDENT>else:<EOL><INDENT>progress('<STR_LIT>', self.processed_tasks, len(self.workers))<EOL><DEDENT>

Increase the processed task counter and show progress message


env = os.environ<EOL>if S3_ACCESS_KEY_NAME in env and S3_SECRET_KEY_NAME in env:<EOL><INDENT>keys = (env[S3_ACCESS_KEY_NAME], env[S3_SECRET_KEY_NAME])<EOL>debug("<STR_LIT>")<EOL>return keys<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>

Retrieve S3 access keys from the environment, or None if not present.


if opt.access_key != None and opt.secret_key != None:<EOL><INDENT>keys = (opt.access_key, opt.secret_key)<EOL>debug("<STR_LIT>")<EOL>return keys<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>

Retrieve S3 access keys from the command line, or None if not present.


try:<EOL><INDENT>if opt.s3cfg != None:<EOL><INDENT>s3cfg_path = "<STR_LIT:%s>" % opt.s3cfg<EOL><DEDENT>else:<EOL><INDENT>s3cfg_path = "<STR_LIT>" % os.environ["<STR_LIT>"]<EOL><DEDENT>if not os.path.exists(s3cfg_path):<EOL><INDENT>return None<EOL><DEDENT>config = ConfigParser.ConfigParser()<EOL>config.read(s3cfg_path)<EOL>keys = config.get("<STR_LIT:default>", "<STR_LIT>"), config.get("<STR_LIT:default>", "<STR_LIT>")<EOL>debug("<STR_LIT>", s3cfg_path)<EOL>return keys<EOL><DEDENT>except Exception as e:<EOL><INDENT>info("<STR_LIT>", s3cfg_path, e)<EOL>return None<EOL><DEDENT>

Retrieve S3 access key settings from s3cmd's config file, if present; otherwise return None.


S3Handler.S3_KEYS = S3Handler.s3_keys_from_cmdline(opt) or S3Handler.s3_keys_from_env()or S3Handler.s3_keys_from_s3cfg(opt)<EOL>

Initialize s3 access keys from environment variable or s3cfg config file.


self.s3 = None<EOL>self.opt = opt<EOL>self.connect()<EOL>


self.s3 = None<EOL>


try:<EOL><INDENT>if S3Handler.S3_KEYS:<EOL><INDENT>self.s3 = BotoClient(self.opt, S3Handler.S3_KEYS[<NUM_LIT:0>], S3Handler.S3_KEYS[<NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>self.s3 = BotoClient(self.opt)<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>raise RetryFailure('<STR_LIT>' % e)<EOL><DEDENT>


result = []<EOL>for bucket in self.s3.list_buckets().get('<STR_LIT>') or []:<EOL><INDENT>result.append({<EOL>'<STR_LIT:name>': S3URL.combine('<STR_LIT>', bucket['<STR_LIT:Name>'], '<STR_LIT>'),<EOL>'<STR_LIT>': True,<EOL>'<STR_LIT:size>': <NUM_LIT:0>,<EOL>'<STR_LIT>': bucket['<STR_LIT>']<EOL>})<EOL><DEDENT>return result<EOL>


@log_calls<EOL><INDENT>def s3walk(self, basedir, show_dir=None):<DEDENT>

<EOL>if not show_dir:<EOL><INDENT>show_dir = self.opt.show_dir<EOL><DEDENT>if basedir[-<NUM_LIT:1>] == PATH_SEP:<EOL><INDENT>basedir = basedir[<NUM_LIT:0>:-<NUM_LIT:1>]<EOL><DEDENT>s3url = S3URL(basedir)<EOL>result = []<EOL>pool = ThreadPool(ThreadUtil, self.opt)<EOL>pool.s3walk(s3url, s3url.get_fixed_path(), s3url.path, result)<EOL>pool.join()<EOL>if not show_dir and len(result) == <NUM_LIT:1> and result[<NUM_LIT:0>]['<STR_LIT>']:<EOL><INDENT>path = result[<NUM_LIT:0>]['<STR_LIT:name>']<EOL>s3url = S3URL(path)<EOL>result = []<EOL>pool = ThreadPool(ThreadUtil, self.opt)<EOL>pool.s3walk(s3url, s3url.get_fixed_path(), s3url.path, result)<EOL>pool.join()<EOL><DEDENT>def compare(x, y):<EOL><INDENT>'''<STR_LIT>'''<EOL>result = -cmp(x['<STR_LIT>'], y['<STR_LIT>'])<EOL>if result != <NUM_LIT:0>:<EOL><INDENT>return result<EOL><DEDENT>return cmp(x['<STR_LIT:name>'], y['<STR_LIT:name>'])<EOL><DEDENT>return sorted(result, key=cmp_to_key(compare))<EOL>

Walk through a S3 directory. This function initiate a walk with a basedir.
           It also supports multiple wildcards.


result = []<EOL>for root, dirs, files in os.walk(basedir):<EOL><INDENT>for f in files:<EOL><INDENT>result.append(os.path.join(root, f))<EOL><DEDENT><DEDENT>return result<EOL>

Walk through local directories from root basedir


if path[-<NUM_LIT:1>] == PATH_SEP:<EOL><INDENT>path = path[<NUM_LIT:0>:-<NUM_LIT:1>]<EOL><DEDENT>return os.path.basename(path)<EOL>

Unix style basename.
           This fuction will return 'bar' for '/foo/bar/' instead of empty string.
           It is used to normalize the input trailing slash.


result = []<EOL>if not isinstance(source, list):<EOL><INDENT>source = [source]<EOL><DEDENT>for src in source:<EOL><INDENT>tmp = self.opt.recursive<EOL>self.opt.recursive = False<EOL>result += [f['<STR_LIT:name>'] for f in self.s3walk(src, True)]<EOL>self.opt.recursive = tmp<EOL><DEDENT>if (len(result) == <NUM_LIT:0>) and (not self.opt.ignore_empty_source):<EOL><INDENT>fail("<STR_LIT>")<EOL><DEDENT>return result<EOL>

Expand the wildcards for an S3 path. This emulates the shall expansion
           for wildcards if the input is local path.