<commit_before># Python Version: 3.x
import datetime
import getpass
import http.cookies
import sys
import time
from typing import *

import requests

import onlinejudge
import onlinejudge._implementation.logging as log
import onlinejudge._implementation.utils as utils

if TYPE_CHECKING:
    import argparse


def login_with_password(service: onlinejudge.type.Service, *, username: Optional[str], password: Optional[str], session: requests.Session) -> None:
    def get_credentials() -> Tuple[str, str]:
        nonlocal username, password
        if username is None:
            username = input('Username: ')
        if password is None:
            password = getpass.getpass()
        return username, password

    service.login(get_credentials=get_credentials, session=session)


# a wrapper class, because selenium.common.exceptions.* is not always imported
class WebDriverException(Exception):
    pass


def login_with_browser(service: onlinejudge.type.Service, *, session: requests.Session) -> None:
    try:
        import selenium.webdriver
    except ImportError:
        raise

    try:
        profile = selenium.webdriver.FirefoxProfile()
        profile.set_preference("general.useragent.override", session.headers['User-Agent'])
        driver = selenium.webdriver.Firefox(firefox_profile=profile)
    except selenium.common.exceptions.WebDriverException as e:
        raise WebDriverException(e)

    # get cookies via Selenium
    url = service.get_url_of_login_page()
    log.info('open with WebDriver: %s', url)
    driver.get(url)
    cookies = []  # type: List[Dict[str, str]]
    try:
        while driver.current_url:
            cookies = driver.get_cookies()
            time.sleep(0.1)
    except selenium.common.exceptions.NoSuchWindowException:
        pass  # the window is closed

    # set cookies to the requests.Session
    log.info('copy cookies from WebDriver')
    for c in cookies:
        log.status('set cookie: %s', c['name'])
        morsel = http.cookies.Morsel()  # type: http.cookies.Morsel
        morsel.set(c['name'], c['value'], c['value'])
        morsel.update({key: value for key, value in c.items() if morsel.isReservedKey(key)})
        if not morsel['expires']:
            expires = datetime.datetime.now(datetime.timezone.utc).astimezone() + datetime.timedelta(days=180)
            morsel.update({'expires': expires.strftime('%a, %d-%b-%Y %H:%M:%S GMT')})  # RFC2109 format
        cookie = requests.cookies.morsel_to_cookie(morsel)
        session.cookies.set_cookie(cookie)  # type: ignore


def is_logged_in_with_message(service: onlinejudge.type.Service, *, session: requests.Session) -> bool:
    if service.is_logged_in(session=session):
        log.info('You have already signed in.')
        return True<commit_msg>#514: fix a problem of WebDriver on Windows<commit_after># Python Version: 3.x
import datetime
import getpass
import http.cookies
import sys
import time
from typing import *

import requests

import onlinejudge
import onlinejudge._implementation.logging as log
import onlinejudge._implementation.utils as utils

if TYPE_CHECKING:
    import argparse


def login_with_password(service: onlinejudge.type.Service, *, username: Optional[str], password: Optional[str], session: requests.Session) -> None:
    def get_credentials() -> Tuple[str, str]:
        nonlocal username, password
        if username is None:
            username = input('Username: ')
        if password is None:
            password = get<PASSWORD>()
        return username, password

    service.login(get_credentials=get_credentials, session=session)


# a wrapper class, because selenium.common.exceptions.* is not always imported
class WebDriverException(Exception):
    pass


def login_with_browser(service: onlinejudge.type.Service, *, session: requests.Session) -> None:
    try:
        import selenium.webdriver
    except ImportError:
        raise

    try:
        profile = selenium.webdriver.FirefoxProfile()
        profile.set_preference("general.useragent.override", session.headers['User-Agent'])
        driver = selenium.webdriver.Firefox(firefox_profile=profile)
    except selenium.common.exceptions.WebDriverException as e:
        raise WebDriverException(e)

    # get cookies via Selenium
    url = service.get_url_of_login_page()
    log.info('open with WebDriver: %s', url)
    driver.get(url)
    cookies = []  # type: List[Dict[str, str]]
    try:
        while driver.current_url:
            cookies = driver.get_cookies()
            time.sleep(0.1)
    except selenium.common.exceptions.WebDriverException:
        pass  # the window is closed

    # set cookies to the requests.Session
    log.info('copy cookies from WebDriver')
    for c in cookies:
        log.status('set cookie: %s', c['name'])
        morsel = http.cookies.Morsel()  # type: http.cookies.Morsel
        morsel.set(c['name'], c['value'], c['value'])
        morsel.update({key: value for key, value in c.items() if morsel.isReservedKey(key)})
        if not morsel['expires']:
            expires = datetime.datetime.now(datetime.timezone.utc).astimezone() + datetime.timedelta(days=180)
            morsel.update({'expires': expires.strftime('%a, %d-%b-%Y %H:%M:%S GMT')})  # RFC2109 format
        cookie = requests.cookies.morsel_to_cookie(morsel)
        session.cookies.set_cookie(cookie)  # type: ignore


def is_logged_in_with_message(service: onlinejudge.type.Service, *, session: requests.Session) -> bool:
    if service.is_logged_in(session=session):
        log.info('You have already signed in.')
        return True
{'fraction_non_alphanumeric': 0.10817092794564634, 'fraction_numerical': 0.004112283211156803, 'mean_word_length': 3.3600935307872173, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4143058', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1624, 'n_words': 404}