<commit_before>import os

from urlparse import urlparse
from netrc import netrc
from lacli.log import getLogger
from lacli.decorators import cached_property


class LaRegistry(object):
    cache = None
    prefs = None
    session = None

    def __init__(self, cache, prefs):
        self.cache = cache
        self.prefs = prefs
        self.session = self.prefs['api']['factory'](prefs)

    def new_session(self, prefs=None):
        if not prefs:
            prefs = self.prefs['api']
        if not prefs['user']:
            prefs['user'] = self._saved_session[0]
            prefs['pass'] = self._saved_session[1]
        return self.prefs['api']['factory'](prefs)

    @cached_property
    def _saved_session(self):
        hostname = urlparse(self.session.url).hostname
        try:
            for host, creds in netrc().hosts.iteritems():
                if host == hostname:
                    return (creds[0], creds[2])
        except:
            getLogger().debug("Couldn't read from netrc", exc_info=True)
            return (None, None)

    def save_session(self, *args):
        self._saved_session = tuple(args)
        with open(os.path.expanduser("~/.netrc"), 'a') as f:
            f.write("machine {} login {} password {}\n".format(
                urlparse(self.session.url).hostname,
                self._saved_session[0],
                self._saved_session[1]))
<commit_msg>_saved_session property should always return a tuple<commit_after>import os

from urlparse import urlparse
from netrc import netrc
from lacli.log import getLogger
from lacli.decorators import cached_property


class LaRegistry(object):
    cache = None
    prefs = None
    session = None

    def __init__(self, cache, prefs):
        self.cache = cache
        self.prefs = prefs
        self.session = self.prefs['api']['factory'](prefs)

    def new_session(self, prefs=None):
        if not prefs:
            prefs = self.prefs['api']
        if not prefs['user']:
            prefs['user'] = self._saved_session[0]
            prefs['pass'] = self._saved_session[1]
        return self.prefs['api']['factory'](prefs)

    @cached_property
    def _saved_session(self):
        hostname = urlparse(self.session.url).hostname
        try:
            for host, creds in netrc().hosts.iteritems():
                if host == hostname:
                    return (creds[0], creds[2])
        except:
            getLogger().debug("Couldn't read from netrc", exc_info=True)
        return (None, None)

    def save_session(self, *args):
        self._saved_session = tuple(args)
        with open(os.path.expanduser("~/.netrc"), 'a') as f:
            f.write("machine {} login {} password {}\n".format(
                urlparse(self.session.url).hostname,
                self._saved_session[0],
                self._saved_session[1]))

{'fraction_non_alphanumeric': 0.12082894274675096, 'fraction_numerical': 0.004214963119072708, 'mean_word_length': 2.269804822043628, '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': '870031', 'n_tokens_mistral': 858, 'n_tokens_neox': 837, 'n_words': 198}