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

"""
gspread.httpsession
~~~~~~~~~~~~~~~~~~~

This module contains a class for working with http sessions.

"""

from requests import requests
try:
    from urllib import urlencode
except ImportError:
    from urllib.parse import urlencode

try:
    unicode
except NameError:
    basestring = unicode = str


from .exceptions import RequestError


class HTTPSession(object):

    """Handles HTTP activity while keeping headers persisting across requests.

       :param headers: A dict with initial headers.
    """

    def __init__(self, headers=None):
        self.headers = headers or {}
        self.requests_session = requests.Session()

    def request(self, method, url, data=None, params=None, headers=None, files=None, json=None):
        if data and isinstance(data, bytes):
            data = data.decode()

        if data and not isinstance(data, basestring):
            data = urlencode(data)

        if data is not None:
            data = data.encode('utf8')

        # If we have data and Content-Type is not set, set it...
        if data and not headers.get('Content-Type', None):
            headers['Content-Type'] = 'application/x-www-form-urlencoded'

        request_headers = self.headers.copy()

        if headers:
            for k, v in headers.items():
                if v is None:
                    del request_headers[k]
                else:
                    request_headers[k] = v

        try:
            func = getattr(self.requests_session, method.lower())
        except AttributeError:
            raise RequestError("HTTP method '{}' is not supported".format(method))

        response = func(url, data=data, params=params, headers=request_headers, files=files, json=json)

        if response.status_code > 399:
            raise RequestError(response.status_code, "{0}: {1}".format(
                response.status_code, response.content))
        return response

    def get(self, url, params=None, **kwargs):
        return self.request('GET', url, params=params, **kwargs)

    def delete(self, url, params=None, **kwargs):
        return self.request('DELETE', url, params=params, **kwargs)

    def post(self, url, data=None, params=None, files=None, headers={}, json=None):
        return self.request('POST', url, params=params, data=data, headers=headers, files=files, json=json)

    def put(self, url, data=None, params=None,  **kwargs):
        return self.request('PUT', url, params=params, data=data, **kwargs)

    def add_header(self, name, value):
        self.headers[name] = value
<commit_msg>Try use . instead requeust<commit_after># -*- coding: utf-8 -*-

"""
gspread.httpsession
~~~~~~~~~~~~~~~~~~~

This module contains a class for working with http sessions.

"""

from . import requests
try:
    from urllib import urlencode
except ImportError:
    from urllib.parse import urlencode

try:
    unicode
except NameError:
    basestring = unicode = str


from .exceptions import RequestError


class HTTPSession(object):

    """Handles HTTP activity while keeping headers persisting across requests.

       :param headers: A dict with initial headers.
    """

    def __init__(self, headers=None):
        self.headers = headers or {}
        self.requests_session = requests.Session()

    def request(self, method, url, data=None, params=None, headers=None, files=None, json=None):
        if data and isinstance(data, bytes):
            data = data.decode()

        if data and not isinstance(data, basestring):
            data = urlencode(data)

        if data is not None:
            data = data.encode('utf8')

        # If we have data and Content-Type is not set, set it...
        if data and not headers.get('Content-Type', None):
            headers['Content-Type'] = 'application/x-www-form-urlencoded'

        request_headers = self.headers.copy()

        if headers:
            for k, v in headers.items():
                if v is None:
                    del request_headers[k]
                else:
                    request_headers[k] = v

        try:
            func = getattr(self.requests_session, method.lower())
        except AttributeError:
            raise RequestError("HTTP method '{}' is not supported".format(method))

        response = func(url, data=data, params=params, headers=request_headers, files=files, json=json)

        if response.status_code > 399:
            raise RequestError(response.status_code, "{0}: {1}".format(
                response.status_code, response.content))
        return response

    def get(self, url, params=None, **kwargs):
        return self.request('GET', url, params=params, **kwargs)

    def delete(self, url, params=None, **kwargs):
        return self.request('DELETE', url, params=params, **kwargs)

    def post(self, url, data=None, params=None, files=None, headers={}, json=None):
        return self.request('POST', url, params=params, data=data, headers=headers, files=files, json=json)

    def put(self, url, data=None, params=None,  **kwargs):
        return self.request('PUT', url, params=params, data=data, **kwargs)

    def add_header(self, name, value):
        self.headers[name] = value

{'fraction_non_alphanumeric': 0.12087490406753645, 'fraction_numerical': 0.002686108979278588, 'mean_word_length': 2.6737138830162084, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4764137', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1412, 'n_words': 438}