Blame lang/python/src/callbacks.py

Packit Service 672cf4
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
Packit Service 672cf4
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
Packit Service 672cf4
#
Packit Service 672cf4
#    This library is free software; you can redistribute it and/or
Packit Service 672cf4
#    modify it under the terms of the GNU Lesser General Public
Packit Service 672cf4
#    License as published by the Free Software Foundation; either
Packit Service 672cf4
#    version 2.1 of the License, or (at your option) any later version.
Packit Service 672cf4
#
Packit Service 672cf4
#    This library is distributed in the hope that it will be useful,
Packit Service 672cf4
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 672cf4
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 672cf4
#    Lesser General Public License for more details.
Packit Service 672cf4
#
Packit Service 672cf4
#    You should have received a copy of the GNU Lesser General Public
Packit Service 672cf4
#    License along with this library; if not, write to the Free Software
Packit Service 672cf4
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
Packit Service 672cf4
Packit Service 672cf4
from __future__ import absolute_import, print_function, unicode_literals
Packit Service 672cf4
del absolute_import, print_function, unicode_literals
Packit Service 672cf4
Packit Service 6c01f9
from getpass import getpass
Packit Service 672cf4
Packit Service 672cf4
def passphrase_stdin(hint, desc, prev_bad, hook=None):
Packit Service 672cf4
    """This is a sample callback that will read a passphrase from
Packit Service 672cf4
    the terminal.  The hook here, if present, will be used to describe
Packit Service 672cf4
    why the passphrase is needed."""
Packit Service 672cf4
    why = ''
Packit Service 6c01f9
    if hook != None:
Packit Service 672cf4
        why = ' ' + hook
Packit Service 672cf4
    if prev_bad:
Packit Service 672cf4
        why += ' (again)'
Packit Service 672cf4
    print("Please supply %s' password%s:" % (hint, why))
Packit Service 672cf4
    return getpass()
Packit Service 672cf4
Packit Service 672cf4
def progress_stdout(what, type, current, total, hook=None):
Packit Service 6c01f9
    print("PROGRESS UPDATE: what = %s, type = %d, current = %d, total = %d" %\
Packit Service 672cf4
          (what, type, current, total))
Packit Service 672cf4
Packit Service 672cf4
def readcb_fh(count, hook):
Packit Service 672cf4
    """A callback for data.  hook should be a Python file-like object."""
Packit Service 672cf4
    if count:
Packit Service 672cf4
        # Should return '' on EOF
Packit Service 672cf4
        return hook.read(count)
Packit Service 672cf4
    else:
Packit Service 672cf4
        # Wants to rewind.
Packit Service 672cf4
        if not hasattr(hook, 'seek'):
Packit Service 672cf4
            return None
Packit Service 672cf4
        hook.seek(0, 0)
Packit Service 672cf4
        return None