16 from io
import StringIO
19 from .robottypes
import is_bytes, is_pathlike, is_string
43 self.file, self.name, self.
_opened_opened = self.
_get_file_get_file(source, accept_text)
46 path = self.
_get_path_get_path(source, accept_text)
48 file = open(path,
'rb')
51 file = StringIO(source)
56 name = getattr(file,
'name',
'<in-memory file>')
57 return file, name, opened
68 if os.path.isabs(source)
or os.path.exists(source):
85 yield self.
_decode_decode(line, remove_bom=first_line)
88 def _decode(self, content, remove_bom=True):
90 content = content.decode(
'UTF-8')
91 if remove_bom
and content.startswith(
'\ufeff'):
94 content = content.replace(
'\r\n',
'\n')
98 mode = getattr(self.file,
'mode',
'')
99 encoding = getattr(self.file,
'encoding',
'ascii').lower()
100 return 'r' in mode
and encoding ==
'ascii'
Utility to ease reading different kind of files.
def _is_binary_file(self)
def _decode(self, content, remove_bom=True)
def __init__(self, source, accept_text=False)
def _get_path(self, source, accept_text)
def __exit__(self, *exc_info)
def _get_file(self, source, accept_text)