Skip to content

Commit cb3f567

Browse files
committed
Handling files whose content looks like a dict.
1 parent 7fc68ab commit cb3f567

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

bitbucket/repository.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# -*- coding: utf-8 -*-
2+
import json
23
from tempfile import NamedTemporaryFile
34
from zipfile import ZipFile
45

6+
from pprint import pprint
7+
58

69
URLS = {
710
'CREATE_REPO': 'repositories/',
@@ -139,12 +142,15 @@ def archive(self, repo_slug=None, owner=None, format='zip', prefix=''):
139142
if self.bitbucket.repo_tree:
140143
with NamedTemporaryFile(delete=False) as archive:
141144
with ZipFile(archive, 'w') as zip_archive:
142-
for name, file in self.bitbucket.repo_tree.items():
145+
for name, f in self.bitbucket.repo_tree.items():
143146
with NamedTemporaryFile(delete=False) as temp_file:
147+
if isinstance(f, dict):
148+
f = json.dumps(f)
149+
144150
try:
145-
temp_file.write(file.encode('utf-8'))
151+
temp_file.write(f.encode('utf-8'))
146152
except UnicodeDecodeError:
147-
temp_file.write(file)
153+
temp_file.write(f)
148154
zip_archive.write(temp_file.name, prefix + name)
149155
return (True, archive.name)
150156
return (False, 'Could not archive your project.')

0 commit comments

Comments
 (0)