<commit_before>from urlparse import urljoin, urlparse
from latvm.tvm import BaseTvm
from lacli.log import getLogger
from lacli.decorators import cached_property, with_api_response
from netrc import netrc

import json


API_URL = 'http://stage.longaccess.com/api/v1/'


class RequestsFactory():

    def __init__(self, prefs):
        self.prefs = prefs
        if self.prefs['user'] is None:
            self.read_netrc(self.prefs['url'])

    def new_session(self):
        import requests
        session = requests.Session()
        session.auth = (self.prefs['user'], self.prefs['pass'])
        return session

    def read_netrc(self, url):
        hostname = urlparse(url).hostname
        for host, creds in netrc().hosts.iteritems():
            if host == hostname:
                self.prefs['user'] = creds[0]
                self.prefs['pass'] = creds[2]

<commit_msg>check for key before using<commit_after>from urlparse import urljoin, urlparse
from latvm.tvm import BaseTvm
from lacli.log import getLogger
from lacli.decorators import cached_property, with_api_response
from netrc import netrc

import json


API_URL = 'http://stage.longaccess.com/api/v1/'


class RequestsFactory():

    def __init__(self, prefs):
        self.prefs = prefs
        if 'user' in self.prefs and self.prefs['user'] is None:
            self.read_netrc(self.prefs['url'])

    def new_session(self):
        import requests
        session = requests.Session()
        session.auth = (self.prefs['user'], self.prefs['pass'])
        return session

    def read_netrc(self, url):
        hostname = urlparse(url).hostname
        for host, creds in netrc().hosts.iteritems():
            if host == hostname:
                self.prefs['user'] = creds[0]
                self.prefs['pass'] = creds[2]


{'fraction_non_alphanumeric': 0.11166666666666666, 'fraction_numerical': 0.0033333333333333335, 'mean_word_length': 2.705761316872428, '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': '1141456', 'n_tokens_mistral': 564, 'n_tokens_neox': 548, 'n_words': 140}