home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / pyshared / pyme / util.py < prev    next >
Encoding:
Python Source  |  2008-03-29  |  2.7 KB  |  73 lines

  1. # $Id: util.py,v 1.9 2008/03/29 22:50:11 belyi Exp $
  2. # Copyright (C) 2004,2008 Igor Belyi <belyi@users.sourceforge.net>
  3. # Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
  4. #
  5. #    This library is free software; you can redistribute it and/or
  6. #    modify it under the terms of the GNU Lesser General Public
  7. #    License as published by the Free Software Foundation; either
  8. #    version 2.1 of the License, or (at your option) any later version.
  9. #
  10. #    This library is distributed in the hope that it will be useful,
  11. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. #    Lesser General Public License for more details.
  14. #
  15. #    You should have received a copy of the GNU Lesser General Public
  16. #    License along with this library; if not, write to the Free Software
  17. #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  18.  
  19. import pygpgme
  20. from errors import errorcheck
  21.  
  22. def process_constants(starttext, dict):
  23.     """Called by the constant libraries to load up the appropriate constants
  24.     from the C library."""
  25.     index = len(starttext)
  26.     for identifier in dir(pygpgme):
  27.         if not identifier.startswith(starttext):
  28.             continue
  29.         name = identifier[index:]
  30.         dict[name] = getattr(pygpgme, identifier)
  31.         
  32. class GpgmeWrapper(object):
  33.     """Base class all Pyme wrappers for GPGME functionality.  Not to be
  34.     instantiated directly."""
  35.     def __repr__(self):
  36.         return '<instance of %s.%s with GPG object at %s>' % \
  37.                (__name__, self.__class__.__name__,
  38.                 self.wrapped)
  39.  
  40.     def __str__(self):
  41.         return repr(self)
  42.  
  43.     def __hash__(self):
  44.         return hash(repr(self.wrapped))
  45.  
  46.     def __eq__(self, other):
  47.         if other == None:
  48.             return False
  49.         else:
  50.             return repr(self.wrapped) == repr(other.wrapped)
  51.  
  52.     def _getctype(self):
  53.         raise NotImplementedException
  54.     
  55.     def __getattr__(self, name):
  56.         """On-the-fly function generation."""
  57.         if name[0] == '_' or self._getnameprepend() == None:
  58.             return None
  59.         name = self._getnameprepend() + name
  60.         if self._errorcheck(name):
  61.             def _funcwrap(*args, **kwargs):
  62.                 args = [self.wrapped] + list(args)
  63.                 return errorcheck(apply(getattr(pygpgme, name), args, kwargs),
  64.                                   "Invocation of " + name)
  65.         else:
  66.             def _funcwrap(*args, **kwargs):
  67.                 args = [self.wrapped] + list(args)
  68.                 return apply(getattr(pygpgme, name), args, kwargs)
  69.  
  70.         _funcwrap.__doc__ = getattr(getattr(pygpgme, name), "__doc__")
  71.         return _funcwrap
  72.  
  73.