~abompard/mailman/import21

« back to all changes in this revision

Viewing changes to src/mailman/utilities/importer.py

  • Committer: Aurélien Bompard
  • Date: 2013-10-03 16:37:04 UTC
  • Revision ID: aurelien@bompard.org-20131003163704-d9p7wz110x91p25f
More unicode fixes in the import script

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
    elif value == 3:
104
104
        return Action.discard
105
105
 
 
106
 
 
107
def unicode_to_string(value):
 
108
    return str(value) if value is not None else None
 
109
 
106
110
 
107
111
# Attributes in Mailman 2 which have a different type in Mailman 3.
108
112
TYPES = dict(
124
128
    forward_unrecognized_bounces_to=UnrecognizedBounceDisposition,
125
129
    default_member_action=member_action_mapping,
126
130
    default_nonmember_action=nonmember_action_mapping,
 
131
    moderator_password=unicode_to_string,
127
132
    )
128
133
 
129
134
 
177
182
        # strings).
178
183
        if hasattr(mlist, key):
179
184
            if isinstance(value, str):
180
 
                value = unicode(value, 'ascii')
 
185
                for encoding in ("ascii", "utf-8"):
 
186
                    try:
 
187
                        value = unicode(value, encoding)
 
188
                    except UnicodeDecodeError, e:
 
189
                        continue
 
190
                    else:
 
191
                        break
 
192
                if isinstance(value, str): # we did our best
 
193
                    value = unicode(value, 'ascii', 'replace')
181
194
            # Some types require conversion.
182
195
            converter = TYPES.get(key)
183
196
            if converter is not None: