<commit_before># -*- coding: utf-8 -*-

"""This module contains pybooru object class."""

# urllib2 imports
from urllib import urlencode
from urllib2 import urlopen
from urllib2 import URLError
from urllib2 import HTTPError


# hashlib imports
import hashlib

# re imports
import re

try:
    # simplejson imports
    from simplejson import loads
except ImportError:
    try:
        # Python 2.6 and up
        from json import loads
    except ImportError:
        raise Exception("Pybooru requires the simplejson library to work")

# pyborru exceptions imports
from .exceptions import PybooruError
# pybooru resources imports
from .resources import API_BASE_URL
from .resources import SITE_LIST


class Pybooru(object):
    """Pybooru main class.

    To initialize Pybooru, you need to specify one of these two
    parameters: site_name or site_url. If you specify site_name, Pybooru checks
    whether there is in the list of default sites (You can get list of sites in
    the resources module).

    To specify a site that isn't in list of default sites, you need use site_url
    parameter.

    Some actions may require you to log in. always specify three parameters to
    log in: hash_string, username and password. Default sites has an associate
    hash string.

    Init Parameters:
        site_name (Type STR):
            The site name in SITE_LIST, default sites.

        site_url (Type STR):
            URL of based on Danbooru/Moebooru sites.

        hash_string (Type STR):
            String that is hashed (required to login).
            (See the API documentation of the site for more information).

        username (Type STR):
            Your username of the site
            (Required only for functions that modify the content).

        password (Type STR):
            Your user password in plain text
            (Required only for functions that modify the content).

    Attributes:
        site_name: Return site name.
        site_url: Return URL of based danbooru/Moebooru site.
        username: Return user name.
        password: Return password in plain text.
        hash_string: Return hash_string.
    """

    def __init__(self, site_name="", site_url="", hash_string="", username="",
                 password=""):

        # Attributes
        self.site_name = site_name.lower()
        self.site_url = site_url
        self.hash_string = hash_string
        self.username = username
        self.password = password

        # Validate site_name or site_url
        if (site_url is not "") or (site_name is not ""):
            if site_name is not "":
                self._site_name_validator(self.site_name)
            elif site_url is not "":
                self._url_validator(self.site_url)
        else:
            raise PybooruError("Unexpected empty strings,"
                               " specify parameter site_name or site_url.")

    def _site_name_validator(self, site_name):
        """Function that checks the site name and get the url.

        Parameters:
            site_name (Type STR):
                The name of a based Danbooru/Moebooru site. You can get list
                of sites in the resources module.
        """

        if site_name in SITE_LIST.keys():
            self.site_url = SITE_LIST[site_name]['url']
        else:
            raise PybooruError(
                "The site name is not valid, use the site_url parameter"
                )

    def _url_validator(self, url):
        """URL validator for site_url parameter of Pybooru.

        Parameters:
            url (Type STR):
                The URL to validate.
        """

        # Regular expression to URL validate
        regex = re.compile(
            r'^(?:http|https)://'  # Scheme only HTTP/HTTPS
            r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?| \
            [A-Z0-9-]{2,}(?<!-)\.?)|'  # Domain
            r'localhost|'  # localhost...
            r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|'  # or ipv4
            r'\[?[A-F0-9]*:[A-F0-9:]+\]?)'  # or ipv6
            r'(?::\d+)?'  # Port
            r'(?:/?|[/?]\S+)$', re.IGNORECASE)
<commit_msg>Adjust line<commit_after># -*- coding: utf-8 -*-

"""This module contains pybooru object class."""

# urllib2 imports
from urllib import urlencode
from urllib2 import urlopen
from urllib2 import URLError
from urllib2 import HTTPError


# hashlib imports
import hashlib

# re imports
import re

try:
    # simplejson imports
    from simplejson import loads
except ImportError:
    try:
        # Python 2.6 and up
        from json import loads
    except ImportError:
        raise Exception("Pybooru requires the simplejson library to work")

# pyborru exceptions imports
from .exceptions import PybooruError
# pybooru resources imports
from .resources import API_BASE_URL
from .resources import SITE_LIST


class Pybooru(object):
    """Pybooru main class.

    To initialize Pybooru, you need to specify one of these two
    parameters: site_name or site_url. If you specify site_name, Pybooru checks
    whether there is in the list of default sites (You can get list of sites in
    the resources module).

    To specify a site that isn't in list of default sites, you need use site_url
    parameter.

    Some actions may require you to log in. always specify three parameters to
    log in: hash_string, username and password. Default sites has an associate
    hash string.

    Init Parameters:
        site_name (Type STR):
            The site name in SITE_LIST, default sites.

        site_url (Type STR):
            URL of based on Danbooru/Moebooru sites.

        hash_string (Type STR):
            String that is hashed (required to login).
            (See the API documentation of the site for more information).

        username (Type STR):
            Your username of the site
            (Required only for functions that modify the content).

        password (Type STR):
            Your user password in plain text
            (Required only for functions that modify the content).

    Attributes:
        site_name: Return site name.
        site_url: Return URL of based danbooru/Moebooru site.
        username: Return user name.
        password: Return password in plain text.
        hash_string: Return hash_string.
    """

    def __init__(self, site_name="", site_url="", hash_string="", username="",
                 password=""):

        # Attributes
        self.site_name = site_name.lower()
        self.site_url = site_url
        self.hash_string = hash_string
        self.username = username
        self.password = password

        # Validate site_name or site_url
        if (site_url is not "") or (site_name is not ""):
            if site_name is not "":
                self._site_name_validator(self.site_name)
            elif site_url is not "":
                self._url_validator(self.site_url)
        else:
            raise PybooruError("Unexpected empty strings,"
                               " specify parameter site_name or site_url.")

    def _site_name_validator(self, site_name):
        """Function that checks the site name and get the url.

        Parameters:
            site_name (Type STR):
                The name of a based Danbooru/Moebooru site. You can get list
                of sites in the resources module.
        """

        if site_name in SITE_LIST.keys():
            self.site_url = SITE_LIST[site_name]['url']
        else:
            raise PybooruError(
                "The site name is not valid, use the site_url parameter")

    def _url_validator(self, url):
        """URL validator for site_url parameter of Pybooru.

        Parameters:
            url (Type STR):
                The URL to validate.
        """

        # Regular expression to URL validate
        regex = re.compile(
            r'^(?:http|https)://'  # Scheme only HTTP/HTTPS
            r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?| \
            [A-Z0-9-]{2,}(?<!-)\.?)|'  # Domain
            r'localhost|'  # localhost...
            r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|'  # or ipv4
            r'\[?[A-F0-9]*:[A-F0-9:]+\]?)'  # or ipv6
            r'(?::\d+)?'  # Port
            r'(?:/?|[/?]\S+)$', re.IGNORECASE)

{'fraction_non_alphanumeric': 0.09621660824368428, 'fraction_numerical': 0.008461259518916959, 'mean_word_length': 2.081564245810056, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2836646', 'n_tokens_mistral': 2442, 'n_tokens_neox': 2372, 'n_words': 829}