# Path: lib/robot/writer/filewriters.py
# def FileWriter(context):
#     """Creates and returns a FileWriter object.
# 
#     :param context: Type of returned FileWriter is determined based on
#         `context.format`. `context` is also passed to created writer.
#     :type context: :py:class:`WritingContext`
#     """
#     if context.format == context.html_format:
#         return HtmlFileWriter(context)
#     if context.format == context.tsv_format:
#         return TsvFileWriter(context)
#     if context.pipe_separated:
#         return PipeSeparatedTxtWriter(context)
#     return SpaceSeparatedTxtWriter(context)


import os
from robot.errors import DataError
from .filewriters import FileWriter
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

from __future__ import with_statement




class DataFileWriter(object):
    """Object to write parsed test data file objects back to disk."""

    def __init__(self, **options):
        """
        :param `**options`: A :class:`.WritingContext` is created based
            on these.
        """
        self._options = options

    def write(self, datafile):
        """Writes given `datafile` using `**options`.

        :param datafile: The parsed test data object to be written
        :type datafile: :py:class:`~robot.parsing.model.TestCaseFile`,
            :py:class:`~robot.parsing.model.ResourceFile`,
            :py:class:`~robot.parsing.model.TestDataDirectory`
        """
        with WritingContext(datafile, **self._options) as ctx:

# Path: lib/robot/writer/filewriters.py
# def FileWriter(context):
#     """Creates and returns a FileWriter object.
# 
#     :param context: Type of returned FileWriter is determined based on
#         `context.format`. `context` is also passed to created writer.
#     :type context: :py:class:`WritingContext`
#     """
#     if context.format == context.html_format:
#         return HtmlFileWriter(context)
#     if context.format == context.tsv_format:
#         return TsvFileWriter(context)
#     if context.pipe_separated:
#         return PipeSeparatedTxtWriter(context)
#     return SpaceSeparatedTxtWriter(context)


# Path: lib/robot/writer/datafilewriter.py
import os
from robot.errors import DataError
from .filewriters import FileWriter

#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

from __future__ import with_statement




class DataFileWriter(object):
    """Object to write parsed test data file objects back to disk."""

    def __init__(self, **options):
        """
        :param `**options`: A :class:`.WritingContext` is created based
            on these.
        """
        self._options = options

    def write(self, datafile):
        """Writes given `datafile` using `**options`.

        :param datafile: The parsed test data object to be written
        :type datafile: :py:class:`~robot.parsing.model.TestCaseFile`,
            :py:class:`~robot.parsing.model.ResourceFile`,
            :py:class:`~robot.parsing.model.TestDataDirectory`
        """
        with WritingContext(datafile, **self._options) as ctx:

            FileWriter(ctx).write(datafile)