<commit_before>import json

import requests
from bs4 import BeautifulSoup
from cachecontrol import CacheControlAdapter
from cachecontrol.heuristics import ExpiresAfter
from urllib3.util.retry import Retry

from pynga.default_config import USER_AGENT

NGA_JSON_SHIFT = len('window.script_muti_get_var_store=')


class Session(object):
    def __init__(self, authentication=None, max_retries=5, timeout=5):
        self.authentication = authentication
        self._build_session(max_retries)
        self.timeout = timeout

    def _build_session(self, max_retries):
        from requests.adapters import HTTPAdapter

        if not isinstance(max_retries, int):
            raise ValueError(f'int expected, found {type(max_retries)}.')
        elif max_retries < 1:
            raise ValueError('max_retries should be greater or equal to 1.')

        session = requests.Session()

        # mount retries adapter
        session.mount('http://', HTTPAdapter(max_retries=Retry(
            total=max_retries, method_whitelist=frozenset(['GET', 'POST'])
        )))

        # mount cache adapter
        session.mount('http://', CacheControlAdapter(heuristic=ExpiresAfter(hours=1)))

        # update authentication
        if isinstance(self.authentication, dict):
            if 'uid' in self.authentication and 'cid' in self.authentication:
                session.headers.update({
                    'Cookie': (
                        f'ngaPassportUid={self.authentication["uid"]};'
                        f'ngaPassportCid={self.authentication["cid"]};'
                    )
                })
            if 'username' in self.authentication and 'password' in self.authentication:<commit_msg>fix retry adapter not working<commit_after>import json

import requests
from bs4 import BeautifulSoup
from cachecontrol import CacheControlAdapter
from cachecontrol.heuristics import ExpiresAfter
from urllib3.util.retry import Retry

from pynga.default_config import USER_AGENT

NGA_JSON_SHIFT = len('window.script_muti_get_var_store=')


class Session(object):
    def __init__(self, authentication=None, max_retries=5, timeout=5):
        self.authentication = authentication
        self._build_session(max_retries)
        self.timeout = timeout

    def _build_session(self, max_retries):
        if not isinstance(max_retries, int):
            raise ValueError(f'int expected, found {type(max_retries)}.')
        elif max_retries < 1:
            raise ValueError('max_retries should be greater or equal to 1.')

        session = requests.Session()

        # mount cache adapter with retries
        session.mount(
            'http://',
            CacheControlAdapter(
                max_retries=Retry(
                    total=max_retries, method_whitelist=frozenset(['GET', 'POST'])
                ),
                heuristic=ExpiresAfter(hours=1)
            )
        )

        # update authentication
        if isinstance(self.authentication, dict):
            if 'uid' in self.authentication and 'cid' in self.authentication:
                session.headers.update({
                    'Cookie': (
                        f'ngaPassportUid={self.authentication["uid"]};'
                        f'ngaPassportCid={self.authentication["cid"]};'
                    )
                })
            if 'username' in self.authentication and 'password' in self.authentication:
{'fraction_non_alphanumeric': 0.0900794818957904, 'fraction_numerical': 0.004121283485428319, 'mean_word_length': 2.48870636550308, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1727329', 'n_tokens_mistral': 937, 'n_tokens_neox': 907, 'n_words': 211}