parent
4363db90c0
commit
017f143a5f
@ -64,11 +64,13 @@ def compact_text(text, elidelength=None):
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
def read_file(filename):
|
def read_file(filename, binary=False):
|
||||||
"""Get the contents of a file contained with qutebrowser.
|
"""Get the contents of a file contained with qutebrowser.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
filename: The filename to open as string.
|
filename: The filename to open as string.
|
||||||
|
binary: Whether to return a binary string.
|
||||||
|
If False, the data is UTF-8-decoded.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
The file contents as string.
|
The file contents as string.
|
||||||
@ -76,11 +78,17 @@ def read_file(filename):
|
|||||||
if hasattr(sys, 'frozen'):
|
if hasattr(sys, 'frozen'):
|
||||||
# cx_Freeze doesn't support pkg_resources :(
|
# cx_Freeze doesn't support pkg_resources :(
|
||||||
fn = os.path.join(os.path.dirname(sys.executable), filename)
|
fn = os.path.join(os.path.dirname(sys.executable), filename)
|
||||||
with open(fn, 'r', encoding='utf-8') as f:
|
if binary:
|
||||||
return f.read()
|
with open(fn, 'rb') as f:
|
||||||
|
return f.read()
|
||||||
|
else:
|
||||||
|
with open(fn, 'r', encoding='utf-8') as f:
|
||||||
|
return f.read()
|
||||||
else:
|
else:
|
||||||
data = pkg_resources.resource_string(qutebrowser.__name__, filename)
|
data = pkg_resources.resource_string(qutebrowser.__name__, filename)
|
||||||
return data.decode('UTF-8')
|
if not binary:
|
||||||
|
data = data.decode('UTF-8')
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
def actute_warning():
|
def actute_warning():
|
||||||
|
Loading…
Reference in New Issue
Block a user