Robot Framework Integrated Development Environment (RIDE)
robotio.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 import io
17 
18 from .platform import PY3
19 
20 
21 def file_writer(path=None, encoding='UTF-8', newline=None):
22  if path:
23  f = io.open(path, 'w', encoding=encoding, newline=newline)
24  else:
25  f = io.StringIO(newline=newline)
26  if PY3:
27  return f
28  # These streams require written text to be Unicode. We don't want to add
29  # `u` prefix to all our strings in Python 2, and cannot really use
30  # `unicode_literals` either because many other Python 2 APIs accept only
31  # byte strings.
32  write = f.write
33  f.write = lambda text: write(unicode(text))
34  return f
35 
36 
37 def binary_file_writer(path=None):
38  if path:
39  return io.open(path, 'wb')
40  f = io.BytesIO()
41  getvalue = f.getvalue
42  f.getvalue = lambda encoding='UTF-8': getvalue().decode(encoding)
43  return f
def write(msg, level='INFO', html=False)
Writes the message to the log file using the given level.
Definition: logger.py:86
unicode
Exceptions and return codes used internally.
Definition: errors.py:24
def file_writer(path=None, encoding='UTF-8', newline=None)
Definition: robotio.py:21
def binary_file_writer(path=None)
Definition: robotio.py:37