Skip to content
Snippets Groups Projects
Commit 97ac3f3b authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

added optional argument to `File.get_value`

parent 895ce34f
No related branches found
No related tags found
No related merge requests found
# v2.16.2
* added optional argument to `File.get_value`
__version__ = '2.16.2a1'
__version__ = '2.16.2a2'
......@@ -76,14 +76,19 @@ class FileObject:
def __hash__(self) -> int:
return hash(self.path)
def get_value(self) -> bytes:
def get_value(self, encoding: tp.Optional[str] = None) -> tp.Union[str, bytes]:
"""
Read in the entire file into memory
:param encoding: optional encoding to apply. If None given, bytes will be returned
:return: file contents
"""
with open(self.path, 'rb') as f_in:
return f_in.read()
data = f_in.read()
if encoding:
return data.decode(encoding)
else:
return data
def open(self, mode: str):
"""
......
......@@ -26,6 +26,7 @@ class TestSchema(unittest.TestCase):
fo = s({'key': "test"})['key']
self.assertEqual(str(fo), 'test')
self.assertEqual(fo.get_value(), b'test')
self.assertEqual(fo.get_value('utf-8'), 'test')
def test_caster(self):
ps = Caster(Environment)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment