save() now requires filename

pull/63/head
Andy Port 2018-08-21 21:27:29 -07:00
parent 0955278f73
commit 4bc146fd62
1 changed files with 4 additions and 12 deletions

View File

@ -210,8 +210,7 @@ class Document:
self.root = self.tree.getroot() self.root = self.tree.getroot()
def flatten_all_paths(self, def flatten_all_paths(self, group_filter=lambda x: True,
group_filter=lambda x: True,
path_filter=lambda x: True, path_filter=lambda x: True,
path_conversions=CONVERSIONS): path_conversions=CONVERSIONS):
"""Forward the tree of this document into the more general """Forward the tree of this document into the more general
@ -219,12 +218,8 @@ class Document:
return flatten_all_paths(self.tree.getroot(), group_filter, return flatten_all_paths(self.tree.getroot(), group_filter,
path_filter, path_conversions) path_filter, path_conversions)
def flatten_group(self, def flatten_group(self, group, recursive=True, group_filter=lambda x: True,
group, path_filter=lambda x: True, path_conversions=CONVERSIONS):
recursive=True,
group_filter=lambda x: True,
path_filter=lambda x: True,
path_conversions=CONVERSIONS):
if all(isinstance(s, str) for s in group): if all(isinstance(s, str) for s in group):
# If we're given a list of strings, assume it represents a # If we're given a list of strings, assume it represents a
# nested sequence # nested sequence
@ -342,10 +337,7 @@ class Document:
return SubElement(parent, '{{{0}}}g'.format( return SubElement(parent, '{{{0}}}g'.format(
SVG_NAMESPACE['svg']), group_attribs) SVG_NAMESPACE['svg']), group_attribs)
def save(self, filename=None): def save(self, filename):
if filename is None:
filename = self.original_filename
with open(filename, 'w') as output_svg: with open(filename, 'w') as output_svg:
output_svg.write(etree.tostring(self.tree.getroot())) output_svg.write(etree.tostring(self.tree.getroot()))