diff options
| author | Barry Warsaw | 2015-03-25 22:32:56 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2015-03-25 22:32:56 -0400 |
| commit | 56c852bff0aa8c92aff92be5888fc6e4d50b5704 (patch) | |
| tree | d6ec02624c4d540b98d80503abca0e2511e559c8 /src/mailman/commands/cli_import.py | |
| parent | 187bd00e812bb7db44b7aedc5cf0040090724922 (diff) | |
| parent | a75be4230498933792e6ed02504ab4ab3e600f90 (diff) | |
| download | mailman-56c852bff0aa8c92aff92be5888fc6e4d50b5704.tar.gz mailman-56c852bff0aa8c92aff92be5888fc6e4d50b5704.tar.zst mailman-56c852bff0aa8c92aff92be5888fc6e4d50b5704.zip | |
Diffstat (limited to 'src/mailman/commands/cli_import.py')
| -rw-r--r-- | src/mailman/commands/cli_import.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/mailman/commands/cli_import.py b/src/mailman/commands/cli_import.py index 30aeb7894..344d5baee 100644 --- a/src/mailman/commands/cli_import.py +++ b/src/mailman/commands/cli_import.py @@ -25,6 +25,7 @@ __all__ = [ import sys import pickle +from contextlib import ExitStack, contextmanager from mailman.core.i18n import _ from mailman.database.transaction import transactional from mailman.interfaces.command import ICLISubCommand @@ -35,6 +36,25 @@ from zope.interface import implementer +# A fake Bouncer class from Mailman 2.1, we don't use it but there are +# instances in the .pck files. +class Bouncer: + class _BounceInfo: + pass + + +@contextmanager +def hacked_sys_modules(): + assert 'Mailman.Bouncer' not in sys.modules + sys.modules['Mailman.Bouncer'] = Bouncer + try: + yield + finally: + del sys.modules['Mailman.Bouncer'] + + + + @implementer(ICLISubCommand) class Import21: """Import Mailman 2.1 list data.""" @@ -74,10 +94,13 @@ class Import21: assert len(args.pickle_file) == 1, ( 'Unexpected positional arguments: %s' % args.pickle_file) filename = args.pickle_file[0] - with open(filename, 'rb') as fp: + with ExitStack() as resources: + fp = resources.enter_context(open(filename, 'rb')) + resources.enter_context(hacked_sys_modules()) while True: try: - config_dict = pickle.load(fp) + config_dict = pickle.load( + fp, encoding='utf-8', errors='ignore') except EOFError: break except pickle.UnpicklingError: |
