Commit 09088718 authored by Lars Kruse's avatar Lars Kruse

fixed a minor bug when opening file-like objects (instead of using filenames)

additionally mention a corner-case regarding urllib2.urlopen.read()
see: https://sourceforge.net/tracker/index.php?func=detail&aid=3476811&group_id=237831&atid=1104176
parent 30dc5651
...@@ -61,7 +61,8 @@ def ImportModel(filename, use_kdtree=True, callback=None, **kwargs): ...@@ -61,7 +61,8 @@ def ImportModel(filename, use_kdtree=True, callback=None, **kwargs):
normal_conflict_warning_seen = False normal_conflict_warning_seen = False
if hasattr(filename, "read"): if hasattr(filename, "read"):
f = filename # make sure that the input stream can seek and has ".len"
f = StringIO.StringIO(filename.read())
# useful for later error messages # useful for later error messages
filename = "input stream" filename = "input stream"
else: else:
...@@ -70,6 +71,9 @@ def ImportModel(filename, use_kdtree=True, callback=None, **kwargs): ...@@ -70,6 +71,9 @@ def ImportModel(filename, use_kdtree=True, callback=None, **kwargs):
# urllib.urlopen objects do not support "seek" - so we need to read # urllib.urlopen objects do not support "seek" - so we need to read
# the whole file at once. This is ugly - anyone with a better idea? # the whole file at once. This is ugly - anyone with a better idea?
f = StringIO.StringIO(url_file.read()) f = StringIO.StringIO(url_file.read())
# TODO: the above ".read" may be incomplete - this is ugly
# see http://patrakov.blogspot.com/2011/03/case-of-non-raised-exception.html
# and http://stackoverflow.com/questions/1824069/urllib2-not-retrieving-entire-http-response
url_file.close() url_file.close()
except IOError, err_msg: except IOError, err_msg:
log.error("STLImporter: Failed to read file (%s): %s" \ log.error("STLImporter: Failed to read file (%s): %s" \
......
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