Blame lang/python/src/__init__.py

Packit d7e8d0
# Copyright (C) 2016 g10 Code GmbH
Packit d7e8d0
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
Packit d7e8d0
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
Packit d7e8d0
#
Packit d7e8d0
# This library is free software; you can redistribute it and/or
Packit d7e8d0
# modify it under the terms of the GNU Lesser General Public
Packit d7e8d0
# License as published by the Free Software Foundation; either
Packit d7e8d0
# version 2.1 of the License, or (at your option) any later version.
Packit d7e8d0
#
Packit d7e8d0
# This library is distributed in the hope that it will be useful,
Packit d7e8d0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit d7e8d0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit d7e8d0
# Lesser General Public License for more details.
Packit d7e8d0
#
Packit d7e8d0
# You should have received a copy of the GNU Lesser General Public
Packit d7e8d0
# License along with this library; if not, write to the Free Software
Packit d7e8d0
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
Packit d7e8d0
Packit d7e8d0
"""gpg: GnuPG Interface for Python (GPGME bindings)
Packit d7e8d0
Packit d7e8d0
Welcome to gpg, the GnuPG Interface for Python.
Packit d7e8d0
Packit d7e8d0
The latest release of this package may be obtained from
Packit d7e8d0
https://www.gnupg.org
Packit d7e8d0
Packit d7e8d0
FEATURES
Packit d7e8d0
--------
Packit d7e8d0
Packit d7e8d0
 * Feature-rich, full implementation of the GPGME library.  Supports
Packit d7e8d0
   all GPGME features.  Callback functions may be written in pure
Packit d7e8d0
   Python.  Exceptions raised in callbacks are properly propagated.
Packit d7e8d0
Packit d7e8d0
 * Ability to sign, encrypt, decrypt, and verify data.
Packit d7e8d0
Packit d7e8d0
 * Ability to list keys, export and import keys, and manage the keyring.
Packit d7e8d0
Packit d7e8d0
 * Fully object-oriented with convenient classes and modules.
Packit d7e8d0
Packit d7e8d0
QUICK EXAMPLE
Packit d7e8d0
-------------
Packit d7e8d0
Packit d7e8d0
    >>> import gpg
Packit d7e8d0
    >>> with gpg.Context() as c:
Packit d7e8d0
    >>> with gpg.Context() as c:
Packit d7e8d0
    ...     cipher, _, _ = c.encrypt("Hello world :)".encode(),
Packit d7e8d0
    ...                              passphrase="abc")
Packit d7e8d0
    ...     c.decrypt(cipher, passphrase="abc")
Packit d7e8d0
    ...
Packit d7e8d0
    (b'Hello world :)',
Packit d7e8d0
     <gpg.results.DecryptResult object at 0x7f5ab8121080>,
Packit d7e8d0
     <gpg.results.VerifyResult object at 0x7f5ab81219b0>)
Packit d7e8d0
Packit d7e8d0
GENERAL OVERVIEW
Packit d7e8d0
----------------
Packit d7e8d0
Packit d7e8d0
For those of you familiar with GPGME, you will be right at home here.
Packit d7e8d0
Packit d7e8d0
The python gpg module is, for the most part, a direct interface to the C GPGME
Packit d7e8d0
library.  However, it is re-packaged in a more Pythonic way --
Packit d7e8d0
object-oriented with classes and modules.  Take a look at the classes
Packit d7e8d0
defined here -- they correspond directly to certain object types in GPGME
Packit d7e8d0
for C.  For instance, the following C code:
Packit d7e8d0
Packit d7e8d0
gpgme_ctx_t context;
Packit d7e8d0
gpgme_new(&context);
Packit d7e8d0
...
Packit d7e8d0
gpgme_op_encrypt(context, recp, 1, plain, cipher);
Packit d7e8d0
Packit d7e8d0
Translates into the following Python code:
Packit d7e8d0
Packit d7e8d0
context = core.Context()
Packit d7e8d0
...
Packit d7e8d0
context.op_encrypt(recp, 1, plain, cipher)
Packit d7e8d0
Packit d7e8d0
The Python module automatically does error-checking and raises Python
Packit d7e8d0
exception gpg.errors.GPGMEError when GPGME signals an error. getcode()
Packit d7e8d0
and getsource() of this exception return code and source of the error.
Packit d7e8d0
Packit d7e8d0
IMPORTANT NOTE
Packit d7e8d0
--------------
Packit d7e8d0
This documentation only covers a small subset of available GPGME functions and
Packit d7e8d0
methods.  Please consult the documentation for the C library
Packit d7e8d0
for comprehensive coverage.
Packit d7e8d0
Packit d7e8d0
This library uses Python's reflection to automatically detect the methods
Packit d7e8d0
that are available for each class, and as such, most of those methods
Packit d7e8d0
do not appear explicitly anywhere. You can use dir() python built-in command
Packit d7e8d0
on an object to see what methods and fields it has but their meaning can
Packit d7e8d0
be found only in GPGME documentation.
Packit d7e8d0
Packit d7e8d0
FOR MORE INFORMATION
Packit d7e8d0
--------------------
Packit d7e8d0
GnuPG homepage: https://www.gnupg.org/
Packit d7e8d0
GPGME documentation: https://www.gnupg.org/documentation/manuals/gpgme/
Packit d7e8d0
Packit d7e8d0
"""
Packit d7e8d0
Packit d7e8d0
from __future__ import absolute_import, print_function, unicode_literals
Packit d7e8d0
del absolute_import, print_function, unicode_literals
Packit d7e8d0
Packit d7e8d0
from . import core
Packit d7e8d0
from . import errors
Packit d7e8d0
from . import constants
Packit d7e8d0
from . import util
Packit d7e8d0
from . import callbacks
Packit d7e8d0
from . import version
Packit d7e8d0
from .core import Context
Packit d7e8d0
from .core import Data
Packit d7e8d0
Packit d7e8d0
# Interface hygiene.
Packit d7e8d0
Packit d7e8d0
# Drop the low-level gpgme that creeps in for some reason.
Packit d7e8d0
gpgme = None
Packit d7e8d0
del gpgme
Packit d7e8d0
Packit d7e8d0
# This is a white-list of symbols.  Any other will alert pyflakes.
Packit d7e8d0
_ = [Context, Data, core, errors, constants, util, callbacks, version]
Packit d7e8d0
del _
Packit d7e8d0
Packit d7e8d0
__all__ = ["Context", "Data",
Packit d7e8d0
           "core", "errors", "constants", "util", "callbacks", "version"]