Commit aa027588 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix save() and load() when 'filename' is a file object

parent 5cca53ce
......@@ -580,8 +580,10 @@ class Graph(object):
def load(self, filename, format="auto"):
"""Load graph from 'filename' (which can also be a file-like
object). The format is guessed from the file name, or can be specified
by 'format', which can be either 'xml' or 'dot'."""
filename = os.path.expanduser(filename)
by 'format', which can be either 'xml' or 'dot'. Alternatively, filename
can be file-like object."""
if type(filename) == str:
filename = os.path.expanduser(filename)
if format == 'auto' and isinstance(filename, str):
if filename.endswith(".xml") or filename.endswith(".xml.gz") or \
filename.endswith(".xml.bz2"):
......@@ -609,8 +611,10 @@ class Graph(object):
@_handle_exceptions
def save(self, filename, format="auto"):
"""Save graph to file. The format is guessed from the 'file' name, or
can be specified by 'format', which can be either 'xml' or 'dot'."""
filename = os.path.expanduser(filename)
can be specified by 'format', which can be either 'xml' or
'dot'. Alternatively, filename can be file-like object."""
if type(filename) == str:
filename = os.path.expanduser(filename)
if format == 'auto' and isinstance(filename, str):
if filename.endswith(".xml") or filename.endswith(".xml.gz") or \
filename.endswith(".xml.bz2"):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment