forked from openlp/openlp
Clean import strings of ASCII control chars (user's db had x07 chars)
This commit is contained in:
parent
398ac5afdf
commit
f02e886976
@ -77,6 +77,9 @@ class ZionWorxImport(SongImport):
|
||||
"""
|
||||
Receive a CSV file (from a ZionWorx database dump) to import.
|
||||
"""
|
||||
# Used to strip control chars (10=LF, 13=CR, 127=DEL)
|
||||
self.control_chars_map = dict.fromkeys(
|
||||
range(10) + [11, 12] + range(14,32) + [127])
|
||||
with open(self.importSource, 'rb') as songs_file:
|
||||
fieldnames = [u'SongNum', u'Title1', u'Title2', u'Lyrics',
|
||||
u'Writer', u'Copyright', u'Keywords', u'DefaultStyle']
|
||||
@ -131,9 +134,9 @@ class ZionWorxImport(SongImport):
|
||||
|
||||
def _decode(self, str):
|
||||
"""
|
||||
Decodes CSV input to unicode.
|
||||
|
||||
This encoding choice seems OK. ZionWorx has no option for setting the
|
||||
encoding for its songs, so we assume encoding is always the same.
|
||||
Decodes CSV input to unicode, stripping all control characters (except
|
||||
new lines).
|
||||
"""
|
||||
return unicode(str, u'cp1252')
|
||||
# This encoding choice seems OK. ZionWorx has no option for setting the
|
||||
# encoding for its songs, so we assume encoding is always the same.
|
||||
return unicode(str, u'cp1252').translate(self.control_chars_map)
|
||||
|
Loading…
Reference in New Issue
Block a user