예제 #1
0
def get_credentials(create=False):
    """
        We use this to ask the user for his credentials in case we have no
        valid token.
        If create is true, the user is asked twice for the password,
        to make sure, that no typing error occurred. This is done three times
        after that a PasswordsDontMatchException is thrown.
    """
    email = raw_input('Email   : ')
    password = None
    for i in range(3):
        #noinspection PyArgumentEqualDefault
        password = recode_input(getpass('Password: '******'Password (again): '))
            if password != password2:
                print messages['PasswordsDontMatch']
                if i == 2:
                    #noinspection PyExceptionInherit
                    raise PasswordsDontMatchException()
            else:
                break
        else:
            break
    return email, password
예제 #2
0
파일: auth.py 프로젝트: parnas/cctrl
def get_password(create=False):
    password = None
    for i in range(3):
        password = recode_input(getpass('Password: '******'Password (again): '))
            if password != password2:
                print messages['PasswordsDontMatch']
                if i == 2:
                    raise PasswordsDontMatchException()
            else:
                break
        else:
            break

    return password
예제 #3
0
파일: auth.py 프로젝트: denito36/cctrl
def get_password(create=False):
    password = None
    for i in range(3):
        password = recode_input(getpass('Password: '******'Password (again): '))
            if password != password2:
                print >> sys.stderr, messages['PasswordsDontMatch']
                if i == 2:
                    raise PasswordsDontMatchException()
            else:
                break
        else:
            break

    return password
예제 #4
0
def if_file_get_content(value):
    """
        if value is the path to a local file, read the content and return it
        otherwise just return value
    """
    file_path = path.abspath(value)
    if path.isfile(file_path):
        try:
            f = open(file_path, 'rU')
        except IOError:
            pass
        else:
            content = f.read()
            f.close()
            return content

    if sys.platform == 'win32':
        # in windows, sys.argv is encoded in windows-1252
        return value.decode('windows-1252').encode('UTF-8')
    else:
        # all others use the same encoding for stdin and argv
        return recode_input(value)
예제 #5
0
def if_file_get_content(value):
    """
        if value is the path to a local file, read the content and return it
        otherwise just return value
    """
    file_path = path.abspath(value)
    if path.isfile(file_path):
        try:
            f = open(file_path, 'rU')
        except IOError:
            pass
        else:
            content = f.read()
            f.close()
            return content

    if sys.platform == 'win32':
        # in windows, sys.argv is encoded in windows-1252
        return value.decode('windows-1252').encode('UTF-8')
    else:
        # all others use the same encoding for stdin and argv
        return recode_input(value)