(self, binary=None, home=None, keyring=None, secring=None,
                 use_agent=False, default_preference_list=None,
                 ignore_homedir_permissions=False, verbose=False, options=None)
Create a ``GPGBase``.

        This class is used to set up properties for controlling the behaviour
        of configuring various options for GnuPG, such as setting GnuPG's
        **homedir** , and the paths to its **binary** and **keyring** .

        :const binary: (:obj:`str`) The full path to the GnuPG binary.

        :ivar homedir: (:class:`~gnupg._util.InheritableProperty`) The full
                       path to the current setting for the GnuPG
                       ``--homedir``.

        :ivar _generated_keys: (:class:`~gnupg._util.InheritableProperty`)
                               Controls setting the directory for storing any
                               keys which are generated with
                               :meth:`~gnupg.GPG.gen_key`.

        :ivar str keyring: The filename in **homedir** to use as the keyring
                           file for public keys.
        :ivar str secring: The filename in **homedir** to use as the keyring
                           file for secret keys.
Create a ``GPGBase``.
Create a GPGBase .
def __init__(self, binary=None, home=None, keyring=None, secring=None,
                 use_agent=False, default_preference_list=None,
                 ignore_homedir_permissions=False, verbose=False, options=None):
        """Create a ``GPGBase``.

        This class is used to set up properties for controlling the behaviour
        of configuring various options for GnuPG, such as setting GnuPG's
        **homedir** , and the paths to its **binary** and **keyring** .

        :const binary: (:obj:`str`) The full path to the GnuPG binary.

        :ivar homedir: (:class:`~gnupg._util.InheritableProperty`) The full
                       path to the current setting for the GnuPG
                       ``--homedir``.

        :ivar _generated_keys: (:class:`~gnupg._util.InheritableProperty`)
                               Controls setting the directory for storing any
                               keys which are generated with
                               :meth:`~gnupg.GPG.gen_key`.

        :ivar str keyring: The filename in **homedir** to use as the keyring
                           file for public keys.
        :ivar str secring: The filename in **homedir** to use as the keyring
                           file for secret keys.
        """
        self.ignore_homedir_permissions = ignore_homedir_permissions
        self.binary  = _util._find_binary(binary)
        self.homedir = os.path.expanduser(home) if home else _util._conf
        pub = _parsers._fix_unsafe(keyring) if keyring else 'pubring.gpg'
        sec = _parsers._fix_unsafe(secring) if secring else 'secring.gpg'
        self.keyring = os.path.join(self._homedir, pub)
        self.secring = os.path.join(self._homedir, sec)
        self.options = list(_parsers._sanitise_list(options)) if options else None

        #: The version string of our GnuPG binary
        self.binary_version = '0.0.0'
        self.verbose = False

        if default_preference_list:
            self._prefs = _check_preferences(default_preference_list, 'all')
        else:
            self._prefs  = 'SHA512 SHA384 SHA256 AES256 CAMELLIA256 TWOFISH'
            self._prefs += ' AES192 ZLIB ZIP Uncompressed'

        encoding = locale.getpreferredencoding()
        if encoding is None: # This happens on Jython!
            encoding = sys.stdin.encoding
        self._encoding = encoding.lower().replace('-', '_')
        self._filesystemencoding = encodings.normalize_encoding(
            sys.getfilesystemencoding().lower())

        # Issue #49: https://github.com/isislovecruft/python-gnupg/issues/49
        #
        # During `line = stream.readline()` in `_read_response()`, the Python
        # codecs module will choke on Unicode data, so we globally monkeypatch
        # the "strict" error handler to use the builtin `replace_errors`
        # handler:
        codecs.register_error('strict', codecs.replace_errors)

        self._keyserver = 'hkp://wwwkeys.pgp.net'
        self.__generated_keys = os.path.join(self.homedir, 'generated-keys')

        try:
            assert self.binary, "Could not find binary %s" % binary
            if _util._py3k:
                assert isinstance(verbose, (bool, str, int)), \
                    "'verbose' must be boolean, string, or 0 <= n <= 9"
            else:
                assert isinstance(verbose, (bool, str, int, unicode)), \
                    "'verbose' must be boolean, string, unicode, or 0 <= n <= 9"
            assert isinstance(use_agent, bool), "'use_agent' must be boolean"
            if self.options is not None:
                assert isinstance(self.options, list), "options not list"
        except (AssertionError, AttributeError) as ae:
            log.error("GPGBase.__init__(): %s" % str(ae))
            raise RuntimeError(str(ae))
        else:
            self._set_verbose(verbose)
            self.use_agent = use_agent

        if hasattr(self, '_agent_proc') \
                and getattr(self, '_remove_agent', None) is True:
            if hasattr(self, '__remove_path__'):
                self.__remove_path__('pinentry')

        # Assign our self.binary_version attribute:
        self._check_sane_and_get_gpg_version()
def __init__ ( self , binary = None , home = None , keyring = None , secring = None , use_agent = False , default_preference_list = None , ignore_homedir_permissions = False , verbose = False , options = None ) : self . ignore_homedir_permissions = ignore_homedir_permissions self . binary = _util . _find_binary ( binary ) self . homedir = os . path . expanduser ( home ) if home else _util . _conf pub = _parsers . _fix_unsafe ( keyring ) if keyring else 'pubring.gpg' sec = _parsers . _fix_unsafe ( secring ) if secring else 'secring.gpg' self . keyring = os . path . join ( self . _homedir , pub ) self . secring = os . path . join ( self . _homedir , sec ) self . options = list ( _parsers . _sanitise_list ( options ) ) if options else None #: The version string of our GnuPG binary self . binary_version = '0.0.0' self . verbose = False if default_preference_list : self . _prefs = _check_preferences ( default_preference_list , 'all' ) else : self . _prefs = 'SHA512 SHA384 SHA256 AES256 CAMELLIA256 TWOFISH' self . _prefs += ' AES192 ZLIB ZIP Uncompressed' encoding = locale . getpreferredencoding ( ) if encoding is None : # This happens on Jython! encoding = sys . stdin . encoding self . _encoding = encoding . lower ( ) . replace ( '-' , '_' ) self . _filesystemencoding = encodings . normalize_encoding ( sys . getfilesystemencoding ( ) . lower ( ) ) # Issue #49: https://github.com/isislovecruft/python-gnupg/issues/49 # # During `line = stream.readline()` in `_read_response()`, the Python # codecs module will choke on Unicode data, so we globally monkeypatch # the "strict" error handler to use the builtin `replace_errors` # handler: codecs . register_error ( 'strict' , codecs . replace_errors ) self . _keyserver = 'hkp://wwwkeys.pgp.net' self . __generated_keys = os . path . join ( self . homedir , 'generated-keys' ) try : assert self . binary , "Could not find binary %s" % binary if _util . _py3k : assert isinstance ( verbose , ( bool , str , int ) ) , "'verbose' must be boolean, string, or 0 <= n <= 9" else : assert isinstance ( verbose , ( bool , str , int , unicode ) ) , "'verbose' must be boolean, string, unicode, or 0 <= n <= 9" assert isinstance ( use_agent , bool ) , "'use_agent' must be boolean" if self . options is not None : assert isinstance ( self . options , list ) , "options not list" except ( AssertionError , AttributeError ) as ae : log . error ( "GPGBase.__init__(): %s" % str ( ae ) ) raise RuntimeError ( str ( ae ) ) else : self . _set_verbose ( verbose ) self . use_agent = use_agent if hasattr ( self , '_agent_proc' ) and getattr ( self , '_remove_agent' , None ) is True : if hasattr ( self , '__remove_path__' ) : self . __remove_path__ ( 'pinentry' ) # Assign our self.binary_version attribute: self . _check_sane_and_get_gpg_version ( )