Skip to content

Commit

Permalink
[1.7.x] Adapted fixture read mode to file type
Browse files Browse the repository at this point in the history
Binary mode added in ed532a6 is not supported by ZipFile.
Refs #22399.
Backport of 275811a from master.
  • Loading branch information
claudep committed Apr 18, 2014
1 parent 8d7023d commit 13340df
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions django/core/management/commands/loaddata.py
Expand Up @@ -76,13 +76,14 @@ def loaddata(self, fixture_labels):
self.models = set() self.models = set()


self.serialization_formats = serializers.get_public_serializer_formats() self.serialization_formats = serializers.get_public_serializer_formats()
# Forcing binary mode may be revisited after dropping Python 2 support (see #22399)
self.compression_formats = { self.compression_formats = {
None: open, None: (open, 'rb'),
'gz': gzip.GzipFile, 'gz': (gzip.GzipFile, 'rb'),
'zip': SingleZipReader 'zip': (SingleZipReader, 'r'),
} }
if has_bz2: if has_bz2:
self.compression_formats['bz2'] = bz2.BZ2File self.compression_formats['bz2'] = (bz2.BZ2File, 'r')


with connection.constraint_checks_disabled(): with connection.constraint_checks_disabled():
for fixture_label in fixture_labels: for fixture_label in fixture_labels:
Expand Down Expand Up @@ -124,9 +125,8 @@ def load_label(self, fixture_label):
""" """
for fixture_file, fixture_dir, fixture_name in self.find_fixtures(fixture_label): for fixture_file, fixture_dir, fixture_name in self.find_fixtures(fixture_label):
_, ser_fmt, cmp_fmt = self.parse_name(os.path.basename(fixture_file)) _, ser_fmt, cmp_fmt = self.parse_name(os.path.basename(fixture_file))
open_method = self.compression_formats[cmp_fmt] open_method, mode = self.compression_formats[cmp_fmt]
# Forcing binary mode may be revisited after dropping Python 2 support (see #22399) fixture = open_method(fixture_file, mode)
fixture = open_method(fixture_file, 'rb')
try: try:
self.fixture_count += 1 self.fixture_count += 1
objects_in_fixture = 0 objects_in_fixture = 0
Expand Down

0 comments on commit 13340df

Please sign in to comment.