# Path: lacli/cmdutil.py
# def command(**types):
#     """ Decorator to parse command options with docopt and
#         validate the types.
#     """
#     def decorate(func):
#         @wraps(func)
#         def wrap(self, line):
#             kwargs = {}
#             try:
#                 opts = docopt(func.__doc__, shlex.split(line))
#                 for opt, val in opts.iteritems():
#                     kw = opt.strip('<>')
#                     if val and kw in types:
#                         if types[kw] == unicode:
#                             kwargs[kw] = get_unicode(val)
#                         else:
#                             kwargs[kw] = types[kw](val)
#             except ValueError as e:
#                 print "error: invalid value:", e
#                 print func.__doc__
#                 return
#             except DocoptExit as e:
#                 print e
#                 return
#             try:
#                 func(self, **kwargs)
#             except CacheInitException as e:
#                 getLogger().debug("Cache not initialized", exc_info=True)
#                 print "Could not initialize cache"
#                 return
#         return wrap
#     return decorate
# 
# Path: lacli/command.py
# class LaCertsCommand(LaBaseCommand):
# class LaCapsuleCommand(LaBaseCommand):
# class LaArchiveCommand(LaBaseCommand):
# class LaFetchCommand(LaBaseCommand):
#     def makecmd(self, options):
#     def do_list(self):
#     def do_delete(self, cert_id=None, srm=None):
#         def _countdown():
#     def do_export(self, cert_id=None):
#     def do_print(self, cert_id=None):
#     def do_import(self, filename=None):
#     def makecmd(self, options):
#     def do_list(self):
#     def do_archives(self, capsule=None):
#     def __init__(self, *args, **kwargs):
#     def setopt(self, options):
#     def makecmd(self, options):
#     def do_upload(self, index=1, capsule=None):
#     def _poll_status_async(self, link):
#     def _poll_status(self, link):
#     def upload_async(self, docs, fname, progq, state):
#     def upload(self, docs, fname, progq, state):
#     def do_create(self, directory=None, title="my archive", description=None):
#             def mycb(path, rel):
#     def do_list(self):
#     def do_status(self, index=1):
#     def do_extract(self, path=None, dest=None, cert_id=None, cert_file=None):
#                 def extract(cert, archive, dest=dest):
#                     def _print(f):
#     def complete_put(self, text, line, begidx, endidx):  # pragma: no cover
#     def do_reset(self, index):
#     def do_delete(self, index=None, srm=None):
#     def makecmd(self, options):
#     def do_fetch(self, archiveid, key=None):
# 
# Path: lacli/log.py
# def getLogger(logger='lacli'):
#     return lacore.log.getLogger(logger)
# 
# Path: lacli/exceptions.py
# class ApiNoSessionError(BaseAppException):
#     msg = "no session credentials provided."


from lacli.cmdutil import command
from lacore.async import block
from lacli.command import LaBaseCommand
from lacli.log import getLogger
from lacli.exceptions import ApiNoSessionError
from lacore.exceptions import (ApiAuthException, ApiErrorException,
                               ApiUnavailableException)
from twisted.internet import defer
from re import match, IGNORECASE
from getpass import getpass
                        self.registry.save_session(
                            self.username, self.password)
        except Exception:
            getLogger().debug("auth failure", exc_info=True)
            print "authentication failed"

    def login_batch(self, username, password):
        block(self.login_async)(username, password)

    @defer.inlineCallbacks
    def login_async(self, username, password):
        self.username = username
        self.password = password
        session = self.registry.new_session()
        try:
            account = yield session.async_account
            self.email = account['email']
            self.session = session
            getLogger().debug("logged in {}".format(self.email))
        except ApiErrorException:
            raise
        except ApiUnavailableException:
            raise
        except ApiNoSessionError:
            raise
        except Exception as e:
            self.username = self.password = None
            getLogger().debug("auth failure", exc_info=True)
            raise ApiAuthException(username=username, exc=e)


# Path: lacli/cmdutil.py
# def command(**types):
#     """ Decorator to parse command options with docopt and
#         validate the types.
#     """
#     def decorate(func):
#         @wraps(func)
#         def wrap(self, line):
#             kwargs = {}
#             try:
#                 opts = docopt(func.__doc__, shlex.split(line))
#                 for opt, val in opts.iteritems():
#                     kw = opt.strip('<>')
#                     if val and kw in types:
#                         if types[kw] == unicode:
#                             kwargs[kw] = get_unicode(val)
#                         else:
#                             kwargs[kw] = types[kw](val)
#             except ValueError as e:
#                 print "error: invalid value:", e
#                 print func.__doc__
#                 return
#             except DocoptExit as e:
#                 print e
#                 return
#             try:
#                 func(self, **kwargs)
#             except CacheInitException as e:
#                 getLogger().debug("Cache not initialized", exc_info=True)
#                 print "Could not initialize cache"
#                 return
#         return wrap
#     return decorate
# 
# Path: lacli/command.py
# class LaCertsCommand(LaBaseCommand):
# class LaCapsuleCommand(LaBaseCommand):
# class LaArchiveCommand(LaBaseCommand):
# class LaFetchCommand(LaBaseCommand):
#     def makecmd(self, options):
#     def do_list(self):
#     def do_delete(self, cert_id=None, srm=None):
#         def _countdown():
#     def do_export(self, cert_id=None):
#     def do_print(self, cert_id=None):
#     def do_import(self, filename=None):
#     def makecmd(self, options):
#     def do_list(self):
#     def do_archives(self, capsule=None):
#     def __init__(self, *args, **kwargs):
#     def setopt(self, options):
#     def makecmd(self, options):
#     def do_upload(self, index=1, capsule=None):
#     def _poll_status_async(self, link):
#     def _poll_status(self, link):
#     def upload_async(self, docs, fname, progq, state):
#     def upload(self, docs, fname, progq, state):
#     def do_create(self, directory=None, title="my archive", description=None):
#             def mycb(path, rel):
#     def do_list(self):
#     def do_status(self, index=1):
#     def do_extract(self, path=None, dest=None, cert_id=None, cert_file=None):
#                 def extract(cert, archive, dest=dest):
#                     def _print(f):
#     def complete_put(self, text, line, begidx, endidx):  # pragma: no cover
#     def do_reset(self, index):
#     def do_delete(self, index=None, srm=None):
#     def makecmd(self, options):
#     def do_fetch(self, archiveid, key=None):
# 
# Path: lacli/log.py
# def getLogger(logger='lacli'):
#     return lacore.log.getLogger(logger)
# 
# Path: lacli/exceptions.py
# class ApiNoSessionError(BaseAppException):
#     msg = "no session credentials provided."


# Path: lacli/login.py
from lacli.cmdutil import command
from lacore.async import block
from lacli.command import LaBaseCommand
from lacli.log import getLogger
from lacli.exceptions import ApiNoSessionError
from lacore.exceptions import (ApiAuthException, ApiErrorException,
                               ApiUnavailableException)
from twisted.internet import defer
from re import match, IGNORECASE
from getpass import getpass

                        self.registry.save_session(
                            self.username, self.password)
        except Exception:
            getLogger().debug("auth failure", exc_info=True)
            print "authentication failed"

    def login_batch(self, username, password):
        block(self.login_async)(username, password)

    @defer.inlineCallbacks
    def login_async(self, username, password):
        self.username = username
        self.password = password
        session = self.registry.new_session()
        try:
            account = yield session.async_account
            self.email = account['email']
            self.session = session
            getLogger().debug("logged in {}".format(self.email))
        except ApiErrorException:
            raise
        except ApiUnavailableException:
            raise
        except ApiNoSessionError:
            raise
        except Exception as e:
            self.username = self.password = None
            getLogger().debug("auth failure", exc_info=True)
            raise ApiAuthException(username=username, exc=e)


    @command()