Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/pyexcel_io/writer.py : 37%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from pyexcel_io.plugins import NEW_WRITERS
4class Writer(object):
5 def __init__(self, file_type, library=None):
6 self.file_type = file_type
7 self.library = library
8 self.keyboards = None
9 # if you know which reader class to use, this attribute allows
10 # you to set reader class externally. Since there is no
11 # so call private field in Python, I am not going to create
12 # useless setter and getter functions like Java.
13 # in pyexcel, this attribute is mainly used for testing
14 self.writer_class = None
16 def open(self, file_name, **keywords):
17 if self.writer_class is None:
18 self.writer_class = NEW_WRITERS.get_a_plugin(
19 self.file_type, library=self.library, location="file"
20 )
21 self.writer = self.writer_class(file_name, self.file_type, **keywords)
23 def open_content(self, file_stream, **keywords):
24 if self.writer_class is None:
25 self.writer_class = NEW_WRITERS.get_a_plugin(
26 self.file_type, library=self.library, location="content"
27 )
28 self.writer = self.writer_class(
29 file_stream, self.file_type, **keywords
30 )
32 def open_stream(self, file_stream, **keywords):
33 if self.writer_class is None:
34 self.writer_class = NEW_WRITERS.get_a_plugin(
35 self.file_type, library=self.library, location="memory"
36 )
37 self.writer = self.writer_class(
38 file_stream, self.file_type, **keywords
39 )
41 def write(self, incoming_dict):
42 self.writer.write(incoming_dict)
44 def close(self):
45 self.writer.close()
47 def __enter__(self):
48 return self
50 def __exit__(self, a_type, value, traceback):
51 self.close()