<commit_before>import logging
from urlparse import urlparse


import requests

from fakturo.core import exceptions, utils


LOG = logging.getLogger(__name__)


class BaseClient(object):
    def __init__(self, url=None):
        self.url = url
        self.requests = self.get_requests()

    def _ensure_url(self, args):
        parsed = urlparse(args['url'])
        if not parsed.scheme:
            args['url'] = self.url + parsed.path

    def get_requests(self, headers={}, args_hooks=[], pre_request_hooks=[]):
        if not 'Content-Type' in headers:
            headers['Content-Type'] = 'application/json'

        if not self._ensure_url in args_hooks:
            args_hooks.append(self._ensure_url)

        if utils.log_request not in pre_request_hooks:
            pre_request_hooks.insert(0, utils.log_request)

        session = requests.Session()
        session.hooks = dict(
            args=args_hooks,
            pre_request=pre_request_hooks)
        session.headers.update(headers)
        return session

    def wrap_api_call(self, function, *args, **kw):
        wrapper = kw.get('wrapper', None)
        # NOTE: If we're passed a wrapper function by the caller, pass the<commit_msg>Fix hooks<commit_after>import logging
from urlparse import urlparse


import requests

from fakturo.core import exceptions, utils


LOG = logging.getLogger(__name__)


class BaseClient(object):
    def __init__(self, url=None):
        self.url = url

        self.requests = self.get_requests()

    def _ensure_url(self, args):
        parsed = urlparse(args['url'])
        if not parsed.scheme:
            args['url'] = self.url + parsed.path

    def get_requests(self, headers={}, args_hooks=[], pre_request_hooks=[]):
        if not 'Content-Type' in headers:
            headers['Content-Type'] = 'application/json'

        args_hooks = args_hooks + [self._ensure_url]
        pre_request_hooks = pre_request_hooks + [utils.log_request]

        session = requests.Session()
        session.hooks = dict(
            args=args_hooks,
            pre_request=pre_request_hooks)
        session.headers.update(headers)
        return session

    def wrap_api_call(self, function, *args, **kw):
        wrapper = kw.get('wrapper', None)
        # NOTE: If we're passed a wrapper function by the caller, pass the
{'fraction_non_alphanumeric': 0.10257510729613734, 'fraction_numerical': 0.00042918454935622315, 'mean_word_length': 2.741573033707865, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1741487', 'n_tokens_mistral': 678, 'n_tokens_neox': 681, 'n_words': 171}