~jri-openerp/enapps-csv-import-tool/misc_small_fixes

« back to all changes in this revision

Viewing changes to ea_import/ea_import_chain.py

  • Committer: jri at openerp
  • Date: 2012-05-16 12:37:45 UTC
  • mfrom: (2.5.1 charset_fix)
  • Revision ID: jri@openerp.com-20120516123745-o8oq5pe3c3thzauq
Merged charset_fix branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
        'link_ids': fields.one2many('ea_import.chain.link', 'chain_id', 'Chain Links', ),
35
35
        'result_ids': fields.one2many('ea_import.chain.result', 'chain_id', 'Import Results', ),
36
36
        'separator': fields.selection([
37
 
            (",", '<,> - Coma'),
 
37
            (",", '<,> - Comma'),
38
38
            (";", '<;> - Semicolon'),
39
39
            ("\t", '<TAB> - Tab'),
40
40
            (" ", '<SPACE> - Space'),
41
 
        ], 'Separator',),
 
41
        ], 'Separator', required=True),
42
42
        'delimiter': fields.selection([
43
43
            ("'", '<\'> - Single quotation mark'),
44
44
            ('"', '<"> - Double quotation mark'),
45
45
            (None, 'None'),
46
 
        ], 'Delimiter',),
 
46
        ], 'Delimiter', required=True),
 
47
        'charset': fields.selection([
 
48
            ('us-ascii', 'US-ASCII'),
 
49
            ('utf-7', 'Unicode (UTF-7)'),
 
50
            ('utf-8', 'Unicode (UTF-8)'),
 
51
            ('utf-16', 'Unicode (UTF-16)'),
 
52
            ('windows-1250', 'Central European (Windows)'),
 
53
            ('iso-8859-1', 'Western European (ISO)'),
 
54
            ('iso-8859-15', 'Latin 9 (ISO)'),
 
55
        ], 'Encoding', required=True)
47
56
        }
48
57
 
49
58
    _defaults = {
50
59
        'separator': ",",
 
60
        'charset': 'utf-8',
51
61
        'delimiter': None,
52
62
    }
53
63
 
85
95
            input_file = StringIO(base64.b64decode(chain.input_file))
86
96
            for string_record in input_file:
87
97
                line = []
88
 
                for field_string in string_record.split(chain.separator):
 
98
                for field_string in string_record.decode(chain.charset).split(chain.separator):
89
99
                    delimiter = chain.delimiter and chain.delimiter + "\n\r" or "\n\r"
90
100
                    line.append(field_string.strip(delimiter))
91
101
                result.append(line)