# Path: pgp/commands/gpg/exceptions.py
# class FatalException(Exception):
# 
#     def __init__(self, exit_code):
#         self.exit_code
# 
# Path: pgp/commands/gpg/message_.py
# class MessageCommand(object):
# 
#     def __init__(self, io_helper, message_filename, set_filesize,
#                  escape_from_lines, for_your_eyes_only):
#         self.io_helper = io_helper
#         if for_your_eyes_only:
#             message_filename = u'_CONSOLE'
#         self.message_filename = message_filename
#         # TODO: set_filesize
#         self.set_filesize = set_filesize
#         self.escape_from_lines = escape_from_lines
# 
#     def file_to_literal_message(self, filename, binary=True, encoding=None):
#         timestamp = self.io_helper.get_timestamp(filename)
#         if filename is None:
#             file_ = self.io_helper.open_stdin()
#         else:
#             file_ = self.io_helper.open_file(filename)
#         if self.message_filename:
#             filename = self.message_filename
#         if binary:
#             msg = message.BinaryMessage(file_.read(), filename, timestamp)
#         else:
#             data = file_.read()
#             if encoding:
#                 data = data.decode(encoding)
#             else:
#                 encoding = chardet.detect(data).get('encoding', 'utf8')
#                 data = data.decode()
# 
#             if self.escape_from_lines:
#                 data = re.sub(r'^From ', u'- From ', data)
#             msg = message.TextMessage(data, filename, timestamp)
#         return msg
# 
#     def run(self, filename=None):
#         msg = self.file_to_literal_message(filename)
#         msg = self.process_message(msg)
#         msg = self.postprocess_message(msg)
#         self.output(msg, filename)
# 
#     def output(self, message, filename):
#         output_filename = self.formatter.make_output_filename(filename)
#         self.io_helper.write_output(
#             self.formatter.format_message(message),
#             output_filename=output_filename
#             )


from pgp.commands.gpg.exceptions import FatalException
from pgp.commands.gpg.message_ import MessageCommand
            self, filename, binary=binary)
        msg = msg.compress(self.algorithm_helper.get_compression_algorithm(),
                           self.algorithm_helper.get_compression_level())
        return msg

    def pubkey_encrypt_message(self, msg):
        session_key = None
        use_mdc = True
        # Choose an algorithm supported by all our recipients
        preferred_ciphers = \
            self.algorithm_helper.get_preferred_ciphers_for_encryption()
        recipient_public_keys = \
            self.recipient_helper.get_recipient_public_keys()
        hidden_recipient_public_keys = \
            self.recipient_helper.get_hidden_recipient_public_keys()
        if self.throw_keys:
            # All recipients are hidden
            hidden_recipient_public_keys += recipient_public_keys
            recipient_public_keys = []

        all_keys = recipient_public_keys + hidden_recipient_public_keys
        for cipher in preferred_ciphers:
            acceptable = True
            for key in all_keys:
                if cipher not in key.preferred_symmetric_algorithms:
                    acceptable = False
                    break
            if acceptable:
                break
        if not acceptable:

# Path: pgp/commands/gpg/exceptions.py
# class FatalException(Exception):
# 
#     def __init__(self, exit_code):
#         self.exit_code
# 
# Path: pgp/commands/gpg/message_.py
# class MessageCommand(object):
# 
#     def __init__(self, io_helper, message_filename, set_filesize,
#                  escape_from_lines, for_your_eyes_only):
#         self.io_helper = io_helper
#         if for_your_eyes_only:
#             message_filename = u'_CONSOLE'
#         self.message_filename = message_filename
#         # TODO: set_filesize
#         self.set_filesize = set_filesize
#         self.escape_from_lines = escape_from_lines
# 
#     def file_to_literal_message(self, filename, binary=True, encoding=None):
#         timestamp = self.io_helper.get_timestamp(filename)
#         if filename is None:
#             file_ = self.io_helper.open_stdin()
#         else:
#             file_ = self.io_helper.open_file(filename)
#         if self.message_filename:
#             filename = self.message_filename
#         if binary:
#             msg = message.BinaryMessage(file_.read(), filename, timestamp)
#         else:
#             data = file_.read()
#             if encoding:
#                 data = data.decode(encoding)
#             else:
#                 encoding = chardet.detect(data).get('encoding', 'utf8')
#                 data = data.decode()
# 
#             if self.escape_from_lines:
#                 data = re.sub(r'^From ', u'- From ', data)
#             msg = message.TextMessage(data, filename, timestamp)
#         return msg
# 
#     def run(self, filename=None):
#         msg = self.file_to_literal_message(filename)
#         msg = self.process_message(msg)
#         msg = self.postprocess_message(msg)
#         self.output(msg, filename)
# 
#     def output(self, message, filename):
#         output_filename = self.formatter.make_output_filename(filename)
#         self.io_helper.write_output(
#             self.formatter.format_message(message),
#             output_filename=output_filename
#             )


# Path: pgp/commands/gpg/encrypt.py
from pgp.commands.gpg.exceptions import FatalException
from pgp.commands.gpg.message_ import MessageCommand

            self, filename, binary=binary)
        msg = msg.compress(self.algorithm_helper.get_compression_algorithm(),
                           self.algorithm_helper.get_compression_level())
        return msg

    def pubkey_encrypt_message(self, msg):
        session_key = None
        use_mdc = True
        # Choose an algorithm supported by all our recipients
        preferred_ciphers = \
            self.algorithm_helper.get_preferred_ciphers_for_encryption()
        recipient_public_keys = \
            self.recipient_helper.get_recipient_public_keys()
        hidden_recipient_public_keys = \
            self.recipient_helper.get_hidden_recipient_public_keys()
        if self.throw_keys:
            # All recipients are hidden
            hidden_recipient_public_keys += recipient_public_keys
            recipient_public_keys = []

        all_keys = recipient_public_keys + hidden_recipient_public_keys
        for cipher in preferred_ciphers:
            acceptable = True
            for key in all_keys:
                if cipher not in key.preferred_symmetric_algorithms:
                    acceptable = False
                    break
            if acceptable:
                break
        if not acceptable:

            raise FatalException(