python3: fix inner iterator classes of csv_import
This commit is contained in:
parent
b551011ae3
commit
58cbf07bab
|
@ -28,6 +28,7 @@ from django.core.validators import RegexValidator
|
|||
from django.db import IntegrityError
|
||||
from django.db.transaction import atomic
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_bytes
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
@ -49,21 +50,32 @@ class UTF8Recoder(object):
|
|||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def next(self):
|
||||
return self.fd.next().encode('utf-8')
|
||||
def __next__(self):
|
||||
if six.PY2:
|
||||
return self.fd.next().encode('utf-8')
|
||||
else:
|
||||
return force_text(self.fd.__next__().encode('utf-8'))
|
||||
|
||||
next = __next__
|
||||
|
||||
|
||||
class UnicodeReader(object):
|
||||
def __init__(self, fd, dialect='excel', **kwargs):
|
||||
self.reader = csv.reader(UTF8Recoder(fd), dialect=dialect, **kwargs)
|
||||
|
||||
def next(self):
|
||||
row = self.reader.next()
|
||||
return [s.decode('utf-8') for s in row]
|
||||
def __next__(self):
|
||||
if six.PY2:
|
||||
row = self.reader.next()
|
||||
return [s.decode('utf-8') for s in row]
|
||||
else:
|
||||
row = self.reader.__next__()
|
||||
return [force_bytes(s).decode('utf-8') for s in row]
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
next = __next__
|
||||
|
||||
|
||||
class CsvImporter(object):
|
||||
rows = None
|
||||
|
|
Loading…
Reference in New Issue