Changeset 10027


Ignore:
Timestamp:
15 Mar 2013, 00:58:05 (12 years ago)
Author:
uli
Message:

Support unicode-aware CSV ops. New buildout run required (new dependency package).

Location:
main/waeup.kofa/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/setup.py

    r9999 r10027  
    2424    'reportlab',
    2525    'PIL',
     26    'unicodecsv',
    2627    'zope.app.authentication', # BBB: During switch to grok 1.1
    2728    'zope.app.file',
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py

    r9931 r10027  
    1818""" Viewing components for Kofa objects.
    1919"""
    20 import csv
     20# XXX: All csv ops should move to a dedicated module soon
     21import unicodecsv as csv
    2122import grok
    2223import os
     
    10441045            # XXX: temporary solution to prevent users from
    10451046            # uploading non-ascii files.
    1046             for element in filecontent:
    1047                 try:
    1048                     if ord(element) > 128:
    1049                       self.flash(_(
    1050                           "Only ASCII files are allowed. "
    1051                           "Your file contains non-ASCII characters."))
    1052                       logger.info('%s - non-ascii file uploaded: %s' %
    1053                           (ob_class, target))
    1054                       return
    1055                 except TypeError:
    1056                     self.flash(_(
    1057                         "Only ASCII files are allowed. "
    1058                         "Your file contains non-ASCII characters."))
    1059                     logger.info('%s - non-ascii file uploaded: %s' %
    1060                         (ob_class, target))
    1061                     return
     1047            #for element in filecontent:
     1048            #    try:
     1049            #        if ord(element) > 128:
     1050            #          self.flash(_(
     1051            #              "Only ASCII files are allowed. "
     1052            #              "Your file contains non-ASCII characters."))
     1053            #          logger.info('%s - non-ascii file uploaded: %s' %
     1054            #              (ob_class, target))
     1055            #          return
     1056            #    except TypeError:
     1057            #        self.flash(_(
     1058            #            "Only ASCII files are allowed. "
     1059            #            "Your file contains non-ASCII characters."))
     1060            #        logger.info('%s - non-ascii file uploaded: %s' %
     1061            #            (ob_class, target))
     1062            #        return
    10621063
    10631064            open(target, 'wb').write(filecontent)
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py

    r9823 r10027  
    2222"""
    2323import grok
    24 import csv
    2524import datetime
    2625import os
     
    2827import tempfile
    2928import time
     29import unicodecsv
    3030import zc.async.interfaces
    3131from cStringIO import StringIO
     
    142142        """
    143143        result = dict()
    144         reader = csv.reader(open(path, 'rb'))
     144        reader = unicodecsv.reader(open(path, 'rb'))
    145145        raw_header = reader.next()
    146146        for num, field in enumerate(headerfields):
     
    279279        self.checkHeaders(headerfields, mode)
    280280        mapping = self.getMapping(path, headerfields, mode)
    281         reader = csv.DictReader(open(path, 'rb'))
     281        reader = unicodecsv.DictReader(open(path, 'rb'))
    282282
    283283        temp_dir = tempfile.mkdtemp()
     
    288288        failed_headers = mapping.values()
    289289        failed_headers.append('--ERRORS--')
    290         failed_writer = csv.DictWriter(open(failed_path, 'wb'),
    291                                        failed_headers)
     290        failed_writer = unicodecsv.DictWriter(open(failed_path, 'wb'),
     291                                              failed_headers)
    292292        os.chmod(failed_path, 0664)
    293293        failed_writer.writerow(dict([(x,x) for x in failed_headers]))
     
    295295        finished_path = os.path.join(temp_dir, "%s.finished%s" % (base, ext))
    296296        finished_headers = mapping.values()
    297         finished_writer = csv.DictWriter(open(finished_path, 'wb'),
    298                                          finished_headers)
     297        finished_writer = unicodecsv.DictWriter(open(finished_path, 'wb'),
     298                                                finished_headers)
    299299        os.chmod(finished_path, 0664)
    300300        finished_writer.writerow(dict([(x,x) for x in finished_headers]))
     
    398398        """
    399399        outfile = StringIO()
    400         writer = csv.DictWriter(outfile, self.available_fields)
     400        writer = unicodecsv.DictWriter(outfile, self.available_fields)
    401401        writer.writerow(
    402402            dict(zip(self.available_fields, self.available_fields))) # header
     
    455455        else:
    456456            outfile = open(filepath, 'wb')
    457         writer = csv.DictWriter(outfile, self.fields)
     457        writer = unicodecsv.DictWriter(outfile, self.fields)
    458458        writer.writerow(dict(zip(self.fields, self.fields))) # header
    459459        return writer, outfile
Note: See TracChangeset for help on using the changeset viewer.