diff options
| author | Claude Paroz <claude@2xlibre.net> | 2014-04-18 18:40:58 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2014-04-18 19:24:39 +0200 |
| commit | 13340df76984d019ff9d4612ed6f38507546aade (patch) | |
| tree | 588ab60da96e5d7a7037d90d33a56b347b1b95a2 | |
| parent | 8d7023dc714acc957fac7ef422ccee4d83429b09 (diff) | |
[1.7.x] Adapted fixture read mode to file type
Binary mode added in ed532a6a1e is not supported by ZipFile.
Refs #22399.
Backport of 275811a93 from master.
| -rw-r--r-- | django/core/management/commands/loaddata.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py index 9cc9324b35..8874a698ef 100644 --- a/django/core/management/commands/loaddata.py +++ b/django/core/management/commands/loaddata.py @@ -76,13 +76,14 @@ class Command(BaseCommand): self.models = set() self.serialization_formats = serializers.get_public_serializer_formats() + # Forcing binary mode may be revisited after dropping Python 2 support (see #22399) self.compression_formats = { - None: open, - 'gz': gzip.GzipFile, - 'zip': SingleZipReader + None: (open, 'rb'), + 'gz': (gzip.GzipFile, 'rb'), + 'zip': (SingleZipReader, 'r'), } if has_bz2: - self.compression_formats['bz2'] = bz2.BZ2File + self.compression_formats['bz2'] = (bz2.BZ2File, 'r') with connection.constraint_checks_disabled(): for fixture_label in fixture_labels: @@ -124,9 +125,8 @@ class Command(BaseCommand): """ 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)) - open_method = self.compression_formats[cmp_fmt] - # Forcing binary mode may be revisited after dropping Python 2 support (see #22399) - fixture = open_method(fixture_file, 'rb') + open_method, mode = self.compression_formats[cmp_fmt] + fixture = open_method(fixture_file, mode) try: self.fixture_count += 1 objects_in_fixture = 0 |
