#!/usr/bin/env python
# -*- coding: utf-8 -*-

import getpass
from .log import info, debug, CMDLineExit

try:
    import keyring
except ImportError:  # pragma: no cover
    keyring = None

PROMPT = 'prompt'
KEYRING = 'keyring'
TESTING = 'testing'
PASSWORD_PROVIDERS = [PROMPT, KEYRING, TESTING]


def prompt_get_password(username):
    """Return password for the given user"""
    return getpass.getpass("Password for {0}: ".format(username))


def keyring_get_password(username):

    if keyring is None:
        raise CMDLineExit("You requested to use the 'keyring' module "
                          "as password provider, but do not have this "
                          "installed.")

    keyring_impl = keyring.get_keyring()
    if keyring_impl.__class__.__name__ == 'PlaintextKeyring':
        raise CMDLineExit("Aborting: the 'keyring' module has selected the "
                          "insecure 'PlaintextKeyring'.")

    debug("Note: will use the backend: '{0}'".format(keyring_impl))
    password = keyring.get_password('afp', username)
    if not password:
        info("No password found in keychain, please enter it now to store it.")
        password = prompt_get_password(username)
        keyring.set_password('afp', username, password)
    return password


def get_password(password_provider, username):
    if password_provider == PROMPT:
        password = prompt_get_password(username)
    elif password_provider == KEYRING:
        password = keyring_get_password(username)
    elif password_provider == TESTING:
        password = 'PASSWORD'
    else:
        raise CMDLineExit("'{0}' is not a valid password provider.\n".
                          format(password_provider) +
                          "Valid options are: {0}".
                          format(str(PASSWORD_PROVIDERS)))

    return password

@@ -1,26 +1,4 @@
-#!/usr/bin/env python%0A
 # -*
@@ -16,16 +16,81 @@
 tf-8 -*-
+%0Afrom __future__ import print_function, absolute_import, division
 %0A%0Aimport
@@ -517,17 +517,16 @@
 rname):%0A
-%0A
     if k
@@ -1827,12 +1827,8 @@
 mat(
-str(
 PASS
@@ -1843,17 +1843,16 @@
 VIDERS))
-)
 %0A%0A    re

Remove unneeded shebang and str(), use more __future__