Commits

Jason R. Coombs committed aa90cf0 Merge

Merged changes from default.

Comments (0)

Files changed (3)

openpack/basepack.py

 	content_type = None
 	rel_type = None
 
-	def __init__(self, package, name, content_type=None, rel_type=None, growth_hint=None, data=None):
+	def __init__(self, package, name, **kwargs):
+		#map(functools.partial(setattr, self), *kwargs.items())
+		for key, value in kwargs.items():
+			setattr(self, key, value)
 		self.name = name
 		self.package = package
-		if content_type is not None:
-			self.content_type = content_type
-		if rel_type is not None:
-			self.rel_type = rel_type
-		self.growth_hint = growth_hint
 		if not isinstance(self, Relationships):
 			self.relationships = Relationships(self.package, self)
-		if data is not None:
-			self.load(data)
 
 	@property
 	def base(self):
 		"""Return the raw bytes of the Part."""
 		data = self.data
 		if isinstance(data, ElementClass):
-			data = tostring(data)
+			data = tostring(data, encoding='utf-8', pretty_print=True)
 		if isinstance(data, unicode):
 			return data.encode('utf-8')
 		return data

openpack/zippack.py

 			if name == '/_rels/.rels':
 				continue
 			part = self[name]
-			content = part.dump()
-			if not content:
-				# silently ignore any content that doesn't actually
-				#  contain any content.
-				continue
-			zf.write_part(to_zip_name(name), content)
+			try:
+				zf.write_part(to_zip_name(name), part.dump())
+			except BaseException:
+				# silently ignore any part that fails to generate any
+				#  content.
+				pass
+
 
 	def _get_matching_segments(self, zf, name):
 		"""

test/test_basepack.py

 		p = Part(None, '/word/document.xml')
 		assert isinstance(p.relationships, Relationships)
 
+	def test_cant_dump_part_without_data(self):
+		part = Part(None, '/word/document.xml')
+		py.test.raises(BaseException, part.dump)
+
 class TestBasicPackage(object):
 	def test_create(self):
 		self.pack = Package()