<commit_before>from __future__ import print_function

from six.moves import urllib
from .browser import Browser
from .utils import LinkNotFoundError
from .form import Form
import sys
import re
import bs4


class StatefulBrowser(Browser):
    """An extension of :class:`Browser` that stores the browser's state
    and provides many convenient functions for interacting with HTML elements.
    It is the primary tool in MechanicalSoup for interfacing with websites.
    """

    def __init__(self, session=None, soup_config=None, requests_adapters=None,
                 *args, **kwargs):
        """Build a StatefulBrowser.

        :param session: Attach a pre-existing requests Session instead of
            constructing a new one.
        :param soup_config: Configuration passed to MechanicalSoup to affect
            the way HTML is parsed.
        :param requests_adapters: Configuration passed to requests, to affect
            the way HTTP requests are performed.
        :param raise_on_404: If True, raise :class:`LinkNotFoundError`
            when visiting a page triggers a 404 Not Found error.
        :param user_agent: Set the user agent header to this value.

        All arguments are forwarded to :func:`Browser.__init__`.

        Examples ::

            browser = mechanicalsoup.StatefulBrowser(
                soup_config={'features': 'lxml'},  # Use the lxml HTML parser
                raise_on_404=True,
                user_agent='MyBot/0.1: mysite.example.com/bot_info',
            )
            browser.open(url)
            # ...
            browser.close()

        Once not used anymore, the browser must be closed
        using :func:`~Browser.close`.
        """
        super(StatefulBrowser, self).__init__(
            session, soup_config, requests_adapters, *args, **kwargs)
        self.__debug = False
        self.__verbose = 0
        self.__current_page = None
        self.__current_url = None
        self.__current_form = None

    def set_debug(self, debug):
        """Set the debug mode (off by default).

        Set to True to enable debug mode. When active, some actions
        will launch a browser on the current page on failure to let
        you inspect the page content.
        """<commit_msg>stateful_browser.py: simplify __init__ interface<commit_after>from __future__ import print_function

from six.moves import urllib
from .browser import Browser
from .utils import LinkNotFoundError
from .form import Form
import sys
import re
import bs4


class StatefulBrowser(Browser):
    """An extension of :class:`Browser` that stores the browser's state
    and provides many convenient functions for interacting with HTML elements.
    It is the primary tool in MechanicalSoup for interfacing with websites.
    """

    def __init__(self, *args, **kwargs):
        """Build a StatefulBrowser.

        :param session: Attach a pre-existing requests Session instead of
            constructing a new one.
        :param soup_config: Configuration passed to MechanicalSoup to affect
            the way HTML is parsed.
        :param requests_adapters: Configuration passed to requests, to affect
            the way HTTP requests are performed.
        :param raise_on_404: If True, raise :class:`LinkNotFoundError`
            when visiting a page triggers a 404 Not Found error.
        :param user_agent: Set the user agent header to this value.

        All arguments are forwarded to :func:`Browser.__init__`.

        Examples ::

            browser = mechanicalsoup.StatefulBrowser(
                soup_config={'features': 'lxml'},  # Use the lxml HTML parser
                raise_on_404=True,
                user_agent='MyBot/0.1: mysite.example.com/bot_info',
            )
            browser.open(url)
            # ...
            browser.close()

        Once not used anymore, the browser must be closed
        using :func:`~Browser.close`.
        """
        super(StatefulBrowser, self).__init__(*args, **kwargs)
        self.__debug = False
        self.__verbose = 0
        self.__current_page = None
        self.__current_url = None
        self.__current_form = None

    def set_debug(self, debug):
        """Set the debug mode (off by default).

        Set to True to enable debug mode. When active, some actions
        will launch a browser on the current page on failure to let
        you inspect the page content.
        """
{'fraction_non_alphanumeric': 0.06939421338155516, 'fraction_numerical': 0.005877034358047016, 'mean_word_length': 2.3908045977011496, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6940603', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1083, 'n_words': 438}