# Path: lacli/log.py
# def getLogger(logger='lacli'):
#     return lacore.log.getLogger(logger)


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

    def init_prefs(self):
        prefs = self.prefs['api']
        if prefs.get('url') is None:
            prefs['url'] = API_URL
        if not prefs['user']:
            prefs['user'] = self._saved_session[0]
            prefs['pass'] = self._saved_session[1]
        return prefs

    def new_session(self, prefs=None):
        if not prefs:
            prefs = self.init_prefs()
        return self.prefs['api']['factory'](prefs)

    def netarsee(self):
        ours = os.path.join(self.cache.home, ".netrc")
        users = os.path.expanduser('~/.netrc')
        if not os.path.exists(ours) and os.path.exists(users):
            return users
        return ours

    @cached_property
    def _saved_session(self):
        hostname = urlparse(self.prefs['api']['url']).hostname
        try:
            for host, creds in netrc(self.netarsee()).hosts.iteritems():
                if host == hostname:
                    return (creds[0], creds[2])
        except:

# Path: lacli/log.py
# def getLogger(logger='lacli'):
#     return lacore.log.getLogger(logger)


# Path: lacli/registry.py
import os
from urlparse import urlparse
from netrc import netrc
from lacli.log import getLogger
from lacore.decorators import cached_property


    def init_prefs(self):
        prefs = self.prefs['api']
        if prefs.get('url') is None:
            prefs['url'] = API_URL
        if not prefs['user']:
            prefs['user'] = self._saved_session[0]
            prefs['pass'] = self._saved_session[1]
        return prefs

    def new_session(self, prefs=None):
        if not prefs:
            prefs = self.init_prefs()
        return self.prefs['api']['factory'](prefs)

    def netarsee(self):
        ours = os.path.join(self.cache.home, ".netrc")
        users = os.path.expanduser('~/.netrc')
        if not os.path.exists(ours) and os.path.exists(users):
            return users
        return ours

    @cached_property
    def _saved_session(self):
        hostname = urlparse(self.prefs['api']['url']).hostname
        try:
            for host, creds in netrc(self.netarsee()).hosts.iteritems():
                if host == hostname:
                    return (creds[0], creds[2])
        except:

            getLogger().debug("Couldn't read from netrc", exc_info=True)