callback.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #============================================================================
  2. # This file is part of Pwman3.
  3. #
  4. # Pwman3 is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License, version 2
  6. # as published by the Free Software Foundation;
  7. #
  8. # Pwman3 is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with Pwman3; if not, write to the Free Software
  15. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. #============================================================================
  17. # Copyright (C) 2012 Oz Nahum <nahumoz@gmail.com>
  18. #============================================================================
  19. #============================================================================
  20. # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
  21. #============================================================================
  22. """
  23. Callback interface
  24. To be used when UI needs to be back to get info from user.
  25. """
  26. import getpass
  27. # this class is just a base class no real method to test
  28. class Callback(object): # pragma: no cover
  29. """Callback interface. Callback classes must implement this."""
  30. def getinput(self, question):
  31. """Return text"""
  32. pass
  33. def getsecret(self, question):
  34. """Return key"""
  35. pass
  36. def error(self, error):
  37. """Present error to user"""
  38. pass
  39. def warning(self, warning):
  40. """Present warning to user"""
  41. pass
  42. def notice(self, warning):
  43. """Present notice to user"""
  44. pass
  45. class CLICallback(Callback): # pragma: no cover
  46. def getinput(self, question):
  47. return raw_input(question)
  48. def getsecret(self, question):
  49. return getpass.getpass(question + ":")
  50. def getnewsecret(self, question):
  51. return getpass.getpass(question + ":")