diff options
author | Anthon van der Neut <anthon@mnt.org> | 2017-05-29 21:57:25 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2017-05-29 21:57:25 +0200 |
commit | 6ba66a44af41d072f5ceddfcdf2c21611c2a7cd0 (patch) | |
tree | 1d6ce2221f7e08e831b9955b23c361d6dd84b124 /reader.py | |
parent | 37721c337037bda3136e964b1eb5972e2587b4a0 (diff) | |
download | ruamel.yaml-6ba66a44af41d072f5ceddfcdf2c21611c2a7cd0.tar.gz |
preserve value type, support pathlib.Path as stream
Diffstat (limited to 'reader.py')
-rw-r--r-- | reader.py | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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 |