mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 08:01:09 +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))
|
||||
|
||||
|
||||
def download_text(src):
|
||||
def download_text(src, mode='r'):
|
||||
""" return the text content of a downloaded file
|
||||
|
||||
src: str
|
||||
Source to copy from (file path or url)
|
||||
mode: str
|
||||
Mode to use with open()
|
||||
|
||||
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:
|
||||
dst = os.path.join(d, 'dst')
|
||||
download(src, dst)
|
||||
with open(dst) as f:
|
||||
with open(dst, mode=mode) as f:
|
||||
return f.read()
|
||||
|
Loading…
x
Reference in New Issue
Block a user