Skip to content

Commit c7b9300

Browse files
committed
update
1 parent 78ddd51 commit c7b9300

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

bin/show_qfiles

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ from __future__ import print_function
3636
import sys
3737
import argparse
3838
from pickle import load
39+
import pickle
3940

4041
import paths
4142
from Mailman.i18n import C_
@@ -63,16 +64,28 @@ def main():
6364
for filename in args.qfiles:
6465
if not args.quiet:
6566
print(('====================>', filename))
66-
fp = open(filename)
6767
if filename.endswith(".pck"):
68-
msg = load(fp)
69-
data = load(fp)
70-
if data.get('_parsemsg'):
71-
sys.stdout.write(msg)
72-
else:
73-
sys.stdout.write(msg.as_string())
68+
try:
69+
with open(filename, 'rb') as fp:
70+
try:
71+
# Try UTF-8 first for newer files
72+
msg = load(fp, fix_imports=True, encoding='utf-8')
73+
data = load(fp, fix_imports=True, encoding='utf-8')
74+
except (UnicodeDecodeError, pickle.UnpicklingError):
75+
# Fall back to latin1 for older files
76+
fp.seek(0)
77+
msg = load(fp, fix_imports=True, encoding='latin1')
78+
data = load(fp, fix_imports=True, encoding='latin1')
79+
if data.get('_parsemsg'):
80+
sys.stdout.write(msg)
81+
else:
82+
sys.stdout.write(msg.as_string())
83+
except Exception as e:
84+
print('Error reading pickle file %s: %s' % (filename, str(e)), file=sys.stderr)
85+
sys.exit(1)
7486
else:
75-
sys.stdout.write(fp.read())
87+
with open(filename) as fp:
88+
sys.stdout.write(fp.read())
7689

7790

7891
if __name__ == '__main__':

0 commit comments

Comments
 (0)