if path:
url += "/" + escape_path(path)
- if to_file:
- outf = open(to_file, "wb")
- close_outf = True
- else:
- outf = stdout
- close_outf = False
-
resp = do_http("GET", url)
if resp.status in (200, 201,):
+ if to_file:
+ outf = open(to_file, "wb")
+ else:
+ outf = stdout
while True:
data = resp.read(4096)
if not data:
break
outf.write(data)
+ if to_file:
+ outf.close()
rc = 0
else:
print >>stderr, "Error, got %s %s" % (resp.status, resp.reason)
print >>stderr, resp.read()
rc = 1
- if close_outf:
- outf.close()
-
return rc