summaryrefslogtreecommitdiff
path: root/reader.py
diff options
context:
space:
mode:
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