summaryrefslogtreecommitdiff
path: root/reader.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2017-05-29 21:57:25 +0200
committerAnthon van der Neut <anthon@mnt.org>2017-05-29 21:57:25 +0200
commit6ba66a44af41d072f5ceddfcdf2c21611c2a7cd0 (patch)
tree1d6ce2221f7e08e831b9955b23c361d6dd84b124 /reader.py
parent37721c337037bda3136e964b1eb5972e2587b4a0 (diff)
downloadruamel.yaml-6ba66a44af41d072f5ceddfcdf2c21611c2a7cd0.tar.gz
preserve value type, support pathlib.Path as stream
Diffstat (limited to 'reader.py')
-rw-r--r--reader.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/reader.py b/reader.py
index 2ececae..4cc67b8 100644
--- a/reader.py
+++ b/reader.py
@@ -23,7 +23,7 @@ from __future__ import absolute_import
import codecs
import re
-from ruamel.yaml.error import YAMLError, FileMark, StringMark
+from ruamel.yaml.error import YAMLError, FileMark, StringMark, YAMLStreamError
from ruamel.yaml.compat import text_type, binary_type, PY3
if False: # MYPY
@@ -97,7 +97,12 @@ class Reader(object):
self.raw_buffer = stream
self.determine_encoding()
else:
- self.stream = stream
+ if not hasattr(stream, 'read') and hasattr(stream, 'open'):
+ self.stream = stream.open('r')
+ else:
+ if not hasattr(stream, 'read'):
+ raise YAMLStreamError('stream argument needs to have a read() method')
+ self.stream = stream
self.name = getattr(stream, 'name', "<file>")
self.eof = False
self.raw_buffer = None