Skip to content

Commit ec6bb41

Browse files
committed
pylinting
1 parent 9cb462e commit ec6bb41

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

pyexcel_io/base.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
:license: New BSD License, see LICENSE for more details
99
"""
1010
import datetime
11-
from abc import ABCMeta, abstractmethod, abstractproperty
11+
from abc import ABCMeta, abstractmethod
1212
from ._compact import PY2, is_generator, OrderedDict, isstream
13-
from ._compact import StringIO, BytesIO
13+
from ._compact import StringIO, BytesIO, is_string
1414
from .constants import (
1515
DEFAULT_SHEET_NAME,
1616
MESSAGE_ERROR_03,
@@ -126,10 +126,10 @@ def write_array(self, table):
126126
rows = len(table)
127127
if rows < 1:
128128
return
129-
columns = max(map(len, table))
129+
columns = max([len(row) for row in table])
130130
self.set_size((rows, columns))
131-
for r in table:
132-
self.write_row(r)
131+
for row in table:
132+
self.write_row(row)
133133

134134
def close(self):
135135
"""
@@ -143,10 +143,10 @@ def from_query_sets(column_names, query_sets):
143143
Convert query sets into an array
144144
"""
145145
yield column_names
146-
for o in query_sets:
146+
for row in query_sets:
147147
new_array = []
148148
for column in column_names:
149-
value = getattr(o, column)
149+
value = getattr(row, column)
150150
if isinstance(value, (datetime.date, datetime.time)):
151151
value = value.isoformat()
152152
new_array.append(value)
@@ -158,9 +158,9 @@ def is_empty_array(array):
158158
Check if an array is an array of '' or not
159159
"""
160160
if PY2:
161-
return len(filter(lambda x: x != '', array)) == 0
161+
return len(filter(lambda element: element != '', array)) == 0
162162
else:
163-
return len(list(filter(lambda x: x != '', array))) == 0
163+
return len(list(filter(lambda element: element != '', array))) == 0
164164

165165

166166
def swap_empty_string_for_none(array):
@@ -187,11 +187,11 @@ def get_io(file_type):
187187
return None
188188

189189

190-
def validate_io(file_type, io):
190+
def validate_io(file_type, stream):
191191
if file_type in TEXT_STREAM_TYPES:
192-
return isinstance(io, StringIO)
192+
return isinstance(stream, StringIO)
193193
elif file_type in BINARY_STREAM_TYPES:
194-
return isinstance(io, BytesIO)
194+
return isinstance(stream, BytesIO)
195195
else:
196196
return False
197197

@@ -218,14 +218,14 @@ def open_stream(self, file_stream, **keywords):
218218

219219
def open_content(self, file_content, **keywords):
220220
io = get_io(self.file_type)
221-
if not PY2:
221+
if PY2:
222+
io.write(file_content)
223+
else:
222224
if (isinstance(io, StringIO) and isinstance(file_content, bytes)):
223225
content = file_content.decode('utf-8')
224226
else:
225227
content = file_content
226228
io.write(content)
227-
else:
228-
io.write(file_content)
229229
io.seek(0)
230230
self.open_stream(io, **keywords)
231231

@@ -276,7 +276,7 @@ def open_stream(self, file_stream, **keywords):
276276
self.native_book = self.load_from_stream(file_stream)
277277

278278
def read_sheet_by_name(self, sheet_name):
279-
named_contents = list(filter(lambda nc: nc.name == sheet_name, self.native_book))
279+
named_contents = list(filter(lambda nc: nc.name == sheet_name, self.native_book))
280280
if len(named_contents) == 1:
281281
return {named_contents[0].name: self.read_sheet(named_contents[0])}
282282
else:
@@ -305,7 +305,7 @@ def read_sheet(self, native_sheet):
305305
pass
306306

307307
@abstractmethod
308-
def load_from_memory(self, file_content):
308+
def load_from_stream(self, file_content):
309309
"""Load content from memory
310310
311311
:params stream file_content: the actual file content in memory
@@ -372,6 +372,10 @@ def write(self, incoming_dict):
372372
sheet_writer.write_array(incoming_dict[sheet_name])
373373
sheet_writer.close()
374374

375+
@abstractmethod
376+
def create_sheet(self, sheet_name):
377+
pass
378+
375379
def close(self):
376380
pass
377381

@@ -391,8 +395,6 @@ def close(self):
391395
}
392396

393397

394-
from ._compact import is_string
395-
396398

397399
def resolve_missing_extensions(extension, available_list):
398400
handler = available_list.get(extension)
@@ -419,10 +421,7 @@ def add_factory(file_type, reader_class):
419421
def create_reader(file_type):
420422
if file_type in ReaderFactory.factories:
421423
reader_class = ReaderFactory.factories[file_type]
422-
if file_type in [FILE_FORMAT_CSV, FILE_FORMAT_TSV, FILE_FORMAT_CSVZ, FILE_FORMAT_TSVZ, DB_DJANGO, DB_SQL, FILE_FORMAT_XLS]:
423-
return reader_class()
424-
else:
425-
return Reader(file_type, reader_class)
424+
return reader_class()
426425
else:
427426
resolve_missing_extensions(file_type, AVAILABLE_READERS)
428427

@@ -437,9 +436,6 @@ def add_factory(file_type, writer_class):
437436
def create_writer(file_type):
438437
if file_type in WriterFactory.factories:
439438
writer_class = WriterFactory.factories[file_type]
440-
if file_type in [FILE_FORMAT_CSV, FILE_FORMAT_TSVZ, FILE_FORMAT_CSVZ, DB_DJANGO, DB_SQL, FILE_FORMAT_XLS]:
441-
return writer_class()
442-
else:
443-
return Writer(file_type, writer_class)
439+
return writer_class()
444440
else:
445441
resolve_missing_extensions(file_type, AVAILABLE_WRITERS)

0 commit comments

Comments
 (0)