diff --git a/gnupg/gnupg.py b/gnupg/gnupg.py index d3e2c87..7730169 100644 --- a/gnupg/gnupg.py +++ b/gnupg/gnupg.py @@ -786,9 +786,38 @@ class GPG(object): # ENCRYPTION # def encrypt_file(self, file, recipients, sign=None, - always_trust=False, passphrase=None, - armor=True, output=None, symmetric=False): - """Encrypt the message read from the file-like object :param:file .""" + always_trust=False, passphrase=None, + armor=True, output=None, symmetric=False): + """Encrypt the message read from ``file``. + + :type file: file or :class:BytesIO + :param file: The file or bytestream to encrypt. + :type recipients: str or list or tuple + :param recipients: The recipients to encrypt to. Recipients may be + specified by UID or keyID/fingerprint. + :param str sign: The keyID to use for signing, i.e. + "gpg --sign --default-key A3ADB67A2CDB8B35 ..." + :param bool always_trust: If True, ignore trust warnings on recipient + keys. If False, display trust warnings. + (default: False) + :param bool passphrase: If True, use the stored passphrase for our + secret key. + + :param bool armor: If True, ascii armor the encrypted output; if False, + the encrypted output will be in binary + format. (default: True) + + :param str output: The output file to write to. If not specified, the + encrypted output is returned, and thus should be + stored as an object in Python. For example: + + >>> gpg = gnupg.GPG(gpghome='./tmp_test') + + """ + if output: # write the output to a file with the specified name + if os.path.exists(output): + os.remove(output) # to avoid overwrite confirmation message + args.append('--output "%s"' % output) args = ['--encrypt'] if symmetric: args = ['--symmetric']