This is a rather elegant trick from upstream to deal with the differences
between bytesarrays, strings, and unicode literals between Python2.x and
Py3k. However, it doesn't actually make a difference if we're running Py3k or
not to use the trick, since it dynamically calls the builtin type for the
native string in any Python version. It works like so:
>>> import sys
>>> data = '{}\n2 + 2 ≠ 5'.format(sys.version[:5])
>>> print(data)
3.3.2
2 + 2 ≠ 5
>>> type(data)
<class 'str'>
>>> type(data)()
''
>>> unicodedata = u'Mon corps et moi étions un, á cause de cette corde maudite.'
>>> type(unicodedata)
<class 'str'>
Also, in Python2.x:
>>> import sys
>>> data = '{}\n2 + 2 ≠ 5'.format(sys.version[:5])
>>> print data
2.7.5
2 + 2 ≠ 5
>>> type(data)
<type 'str'>
>>> type(data)()
''
>>> unicodedata = u'Mon corps et moi étions un, á cause de cette corde maudite.'
>>> type(unicodedata)
<type 'unicode'>
>>> type(unicodedata)()
u''
For some reason, in GnuPG>=2.x, a missing/corrupted trustdb is a fatal
error. This means that if the homedir was just changed, and any command which
utilizes keys is called (e.g. sign, encrypt, decrypt, etc.) GnuPG dies without
executing the command because we can't find a valid trustdb.
What's even more is that there is a new command in GnuPG>=2.x:
'--fix-trustdb'. You'd think it would, you know, *fix the trustdb*. Hah! Think
again! It prints out a series of shell commands (incorrect ones, at that, as
they don't respect the relevant env variables such as $GNUPGHOME) in a format
which is *not* exec'able (i.e. you can't do something similar to how
$ exec `ssh-agent`
is used). Software engineering, motherfuckers. #FML.
We should only add these methods (or rather, link them to their corresponding
functions in the gnupg._trust module) if using GnuPG>=2.x.
* ADD --export-ownertrust and --import-ownertrust functionality.
* ADD function gnupg._trust._create_trustdb().
* ADD function gnupg._trust.import_ownertrust().
* ADD function gnupg._trust.export_ownertrust().
* ADD function gnupg._trust.fix_trustdb().
* ADD function _util._deprefix() for stripping a given prefix from the
beginning of another string.
* ADD function _util._separate_keywork() for extracting the keyword from the
beginning of status-fd output.
* REMOVE excess EOL whitespace.
* CLEANUP method gnupg.GPGBase._read_response().
* CHANGE _find_binary() utility function to look for a gpg2 binary on the
users PATH if no binary is given and gpg is not found.
* FIXES an error where only gpg=>1.4.x was found.
* CHANGE unittest test_copy_data_bytesio() to actually check that the output
data matches the original message string given to io.BytesIO().
* REMOVE class test.test_gnupg.ResultStringIO, as it is now not used
anywhere.
* FIXES test_copy_data_bytesio() not actually testing what it was supposed
to.
* CHANGE unittest test_make_args_drop_protected_options() to discover the
path to the GnuPG binary; the discovered path SHOULD be the same as that
which was discovered upon class instantiation.
* FIXES failure in unittest test_make_args_drop_protected_options() which was
caused by the path to the GnuPG binary being hardcoded.
* ADD patches from Mikael Nordfeldth.
* FIXES#14 issues with strcmp in unittests looking for string literals when
Python3 expects byte strings.
* TODO: perhaps there should be a generalized function in
gnupg/test/test_gnupg.py which automatically translates Python2 strings to
b'' strings.
* CLOSES issue #14.
* ADD patch by Mikael Nordfeldth to file python3 syntax compatibility due to
the 'file' builtin being removed.
isinstance(foo, file) → hasattr(foo, 'read'), or,
file = _io._IOBase
* CLOSES issue #13.
https://github.com/isislovecruft/python-gnupg/pull/13
This patch sets the environment variable LANGUGE to 'en', meaning English translation is used for outputs. The string comparisons in test_gpg_binary_version_str failed otherwise when using a non-English locale. Another choice may be to set LANG=C to avoid locales all-in-all.
* CHANGE default key type to RSA for older GnuPG versions, since they seems
to not understand using a 'default' key type.
* UPDATE docstring for GPG.gen_key_input().
* ADD functions _util._match_version_string(), _util._is_gpg2(), and
_util._is_gpg1() for determining whether to set the default Key-Type to
'default' (for GnuPG v2.x) or to 'RSA' (for GnuPG v1.x).
* ADD class attribute GPG.binary_version, which stores the GnuPG executable's
version string, which should be in the form x.x.x, where 'x' is an integer.