Update setup.py and README to mention Python 3.3.
[pyassuan.git] / bin / pinentry.py
index a9773f27cc96a578ce1c88fcaaa715b775f63e5f..2b4267347bd6e3b476cd10352282e09f696e9e97 100755 (executable)
@@ -1,20 +1,20 @@
 #!/usr/bin/env python3
 #
 #!/usr/bin/env python3
 #
-# Copyright (C) 2011 W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2012 W. Trevor King <wking@drexel.edu>
 #
 #
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
+# This file is part of pyassuan.
 #
 #
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
+# pyassuan is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
 #
 #
-# You should have received a copy of the GNU Lesser General Public
-# License along with this program.  If not, see
-# <http://www.gnu.org/licenses/>.
+# pyassuan is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# pyassuan.  If not, see <http://www.gnu.org/licenses/>.
 
 """Simple pinentry program for getting pins from a terminal.
 """
 
 """Simple pinentry program for getting pins from a terminal.
 """
@@ -178,7 +178,7 @@ class PinEntry (_server.AssuanServer):
             fd_path = _os_path.join(path, 'fd', '0')
             try:
                 link = _os.readlink(fd_path)
             fd_path = _os_path.join(path, 'fd', '0')
             try:
                 link = _os.readlink(fd_path)
-            except OSError, e:
+            except OSError as e:
                 self.logger.debug('not our process: {}'.format(e))
                 continue  # permission denied (not one of our processes)
             if link != tty_name:
                 self.logger.debug('not our process: {}'.format(e))
                 continue  # permission denied (not one of our processes)
             if link != tty_name:
@@ -216,9 +216,9 @@ class PinEntry (_server.AssuanServer):
 
     def _handle_GETINFO(self, arg):
         if arg == 'pid':
 
     def _handle_GETINFO(self, arg):
         if arg == 'pid':
-            yield _common.Response('D', str(_os.getpid()))
+            yield _common.Response('D', str(_os.getpid()).encode('ascii'))
         elif arg == 'version':
         elif arg == 'version':
-            yield _common.Response('D', __version__)
+            yield _common.Response('D', __version__.encode('ascii'))
         else:
             raise _error.AssuanError(message='Invalid parameter')
         yield _common.Response('OK')
         else:
             raise _error.AssuanError(message='Invalid parameter')
         yield _common.Response('OK')
@@ -256,7 +256,7 @@ class PinEntry (_server.AssuanServer):
 
         This indicator is updated as the passphrase is typed.  The
         clients needs to implement an inquiry named "QUALITY" which
 
         This indicator is updated as the passphrase is typed.  The
         clients needs to implement an inquiry named "QUALITY" which
-        gets passed the current passpharse (percent-plus escaped) and
+        gets passed the current passphrase (percent-plus escaped) and
         should send back a string with a single numerical vauelue
         between -100 and 100.  Negative values will be displayed in
         red.
         should send back a string with a single numerical vauelue
         between -100 and 100.  Negative values will be displayed in
         red.
@@ -273,17 +273,31 @@ class PinEntry (_server.AssuanServer):
             S: OK
 
         With STRING being a percent escaped string shown as the tooltip.
             S: OK
 
         With STRING being a percent escaped string shown as the tooltip.
+
+        Here is a real world example of these commands in use:
+
+            C: SETQUALITYBAR Quality%3a
+            S: OK
+            C: SETQUALITYBAR_TT The quality of the text entered above.%0aPlease ask your administrator for details about the criteria.
+            S: OK
         """
         """
-        raise NotImplementedError()
+        self.strings['qualitybar'] = arg
+        yield _common.Response('OK')
+
+    def _handle_SETQUALITYBAR_TT(self, arg):
+        self.strings['qualitybar_tooltip'] = arg
+        yield _common.Response('OK')
 
     def _handle_GETPIN(self, arg):
         try:
             self._connect()
             self._write(self.strings['description'])
 
     def _handle_GETPIN(self, arg):
         try:
             self._connect()
             self._write(self.strings['description'])
+            if 'qualitybar' in self.strings:
+                self._write(self.strings['qualitybar'])
             pin = self._prompt(self.strings['prompt'], add_colon=False)
         finally:
             self._disconnect()
             pin = self._prompt(self.strings['prompt'], add_colon=False)
         finally:
             self._disconnect()
-        yield _common.Response('D', pin)
+        yield _common.Response('D', pin.encode('ascii'))
         yield _common.Response('OK')
 
     def _handle_CONFIRM(self, arg):
         yield _common.Response('OK')
 
     def _handle_CONFIRM(self, arg):
@@ -339,7 +353,6 @@ if __name__ == '__main__':
                 logging.DEBUG, p.logger.level - 10*args.verbose))
 
     try:
                 logging.DEBUG, p.logger.level - 10*args.verbose))
 
     try:
-        p = PinEntry()
         p.run()
     except:
         p.logger.error(
         p.run()
     except:
         p.logger.error(