mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-07-27 14:51:29 +00:00
Add mode param to download_text() to allow using custom modes like 'rb'
This commit is contained in:
parent
128eca1a5b
commit
ff66707a4c
@ -334,18 +334,20 @@ def download(src, dst, size=0):
|
|||||||
size / 1024.0 / 1024))
|
size / 1024.0 / 1024))
|
||||||
|
|
||||||
|
|
||||||
def download_text(src):
|
def download_text(src, mode='r'):
|
||||||
""" return the text content of a downloaded file
|
""" return the text content of a downloaded file
|
||||||
|
|
||||||
src: str
|
src: str
|
||||||
Source to copy from (file path or url)
|
Source to copy from (file path or url)
|
||||||
|
mode: str
|
||||||
|
Mode to use with open()
|
||||||
|
|
||||||
Raises the same exceptions as download()
|
Raises the same exceptions as download()
|
||||||
|
|
||||||
Returns text content of downloaded file
|
Returns text (or binary, if mode includes 'b') content of downloaded file
|
||||||
"""
|
"""
|
||||||
with tempfile.TemporaryDirectory() as d:
|
with tempfile.TemporaryDirectory() as d:
|
||||||
dst = os.path.join(d, 'dst')
|
dst = os.path.join(d, 'dst')
|
||||||
download(src, dst)
|
download(src, dst)
|
||||||
with open(dst) as f:
|
with open(dst, mode=mode) as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user