diff options
author | Frank Vanderham <twelve.eighty@gmail.com> | 2018-04-23 20:48:12 -0600 |
---|---|---|
committer | Jelle van der Waa <jelle@vdwaa.nl> | 2019-01-21 21:19:58 +0100 |
commit | 6cbf136e0bc8ed5698ce205f771e2f36e6bbd609 (patch) | |
tree | a0ff634bd1007b76d1cdab6f428826198fc834d1 /main | |
parent | 7bc2457012b3722a937aba315286ec56a40fda0f (diff) | |
download | archweb-6cbf136e0bc8ed5698ce205f771e2f36e6bbd609.tar.gz archweb-6cbf136e0bc8ed5698ce205f771e2f36e6bbd609.zip |
Fix Python 2 vs. Python 3 Unicode string issues
* Fixed issue with string concatenation that fails under Python 3
* Fixed issue with concatenating strings with potentially mixed
encoding. All strings are now first converted to UTF-8 and then
concatenated.
Diffstat (limited to 'main')
-rw-r--r-- | main/management/commands/donor_import.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/main/management/commands/donor_import.py b/main/management/commands/donor_import.py index 895b316c..b8bdbf54 100644 --- a/main/management/commands/donor_import.py +++ b/main/management/commands/donor_import.py @@ -43,10 +43,10 @@ class Command(BaseCommand): def decode_subject(self, subject): subject = decode_header(subject) - default_charset = 'ASCII' + default_charset = 'utf-8' # Convert the list of tuples containing the decoded string and encoding to - # the same encoding. - return u''.join([unicode(s[0], s[1] or default_charset) for s in subject]) + # UTF-8 + return u''.join([s[0].encode(default_charset, 'replace').decode(default_charset, 'replace') for s in subject]) def parse_subject(self, subject): @@ -67,7 +67,7 @@ class Command(BaseCommand): return u'' # Strip any numbers, they could be a bank account number - name = filter(lambda x: not x.isdigit(), name) + name = u''.join([l for l in name if not l.isdigit()]) # Normalize all capitalized names. (JOHN DOE) name = u' '.join(l.capitalize() for l in name.split(u' ')) |