Skip to content

Commit 6278276

Browse files
committed
fix pep8 warnings and update documentation
1 parent dac7326 commit 6278276

File tree

1 file changed

+78
-52
lines changed

1 file changed

+78
-52
lines changed

pyexcel_webio/__init__.py

Lines changed: 78 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,20 @@ class ExcelInput(object):
4040
def load_single_sheet(self, sheet_name=None, **keywords):
4141
"""Abstract method
4242
43-
:param form_field_name: the file field name in the html form for file upload
44-
:param sheet_name: For an excel book, there could be multiple sheets. If it is left
45-
unspecified, the sheet at index 0 is loaded. For 'csv', 'tsv' file,
46-
*sheet_name* should be None anyway.
43+
:param sheet_name: For an excel book, there could be multiple
44+
sheets. If it is left unspecified, the
45+
sheet at index 0 is loaded. For 'csv', 'tsv'
46+
file, *sheet_name* should be None anyway.
4747
:param keywords: additional key words
4848
:returns: A sheet object
4949
"""
5050
raise NotImplementedError("Please implement this function")
5151

5252
def load_book(self, **keywords):
5353
"""Abstract method
54-
55-
:param form_field_name: the file field name in the html form for file upload
54+
55+
:param form_field_name: the file field name in the html
56+
form for file upload
5657
:param keywords: additional key words
5758
:returns: A instance of :class:`Book`
5859
"""
@@ -61,24 +62,24 @@ def load_book(self, **keywords):
6162
def get_sheet(self, sheet_name=None, **keywords):
6263
"""
6364
Get a :class:`Sheet` instance from the file
64-
65-
:param form_field_name: the file field name in the html form for file upload
66-
:param sheet_name: For an excel book, there could be multiple sheets. If it is left
67-
unspecified, the sheet at index 0 is loaded. For 'csv', 'tsv' file,
68-
*sheet_name* should be None anyway.
65+
66+
:param sheet_name: For an excel book, there could be multiple
67+
sheets. If it is left unspecified, the
68+
sheet at index 0 is loaded. For 'csv',
69+
'tsv' file, *sheet_name* should be None anyway.
6970
:param keywords: additional key words
7071
:returns: A sheet object
7172
"""
7273
return self.load_single_sheet(sheet_name=sheet_name, **keywords)
73-
74+
7475
def get_array(self, sheet_name=None, **keywords):
7576
"""
7677
Get a list of lists from the file
77-
78-
:param form_field_name: the file field name in the html form for file upload
79-
:param sheet_name: For an excel book, there could be multiple sheets. If it is left
80-
unspecified, the sheet at index 0 is loaded. For 'csv', 'tsv' file,
81-
*sheet_name* should be None anyway.
78+
79+
:param sheet_name: For an excel book, there could be multiple
80+
sheets. If it is left unspecified, the
81+
sheet at index 0 is loaded. For 'csv',
82+
'tsv' file, *sheet_name* should be None anyway.
8283
:param keywords: additional key words
8384
:returns: A list of lists
8485
"""
@@ -90,31 +91,37 @@ def get_array(self, sheet_name=None, **keywords):
9091

9192
def get_dict(self, sheet_name=None, name_columns_by_row=0, **keywords):
9293
"""Get a dictionary from the file
93-
94-
:param form_field_name: the file field name in the html form for file upload
95-
:param sheet_name: For an excel book, there could be multiple sheets. If it is left
96-
unspecified, the sheet at index 0 is loaded. For 'csv', 'tsv' file,
97-
*sheet_name* should be None anyway.
94+
95+
:param sheet_name: For an excel book, there could be multiple
96+
sheets. If it is left unspecified, the
97+
sheet at index 0 is loaded. For 'csv',
98+
'tsv' file, *sheet_name* should be None anyway.
9899
:param keywords: additional key words
99100
:returns: A dictionary
100101
"""
101-
sheet = self.load_single_sheet(sheet_name=sheet_name, name_columns_by_row=name_columns_by_row, **keywords)
102+
sheet = self.load_single_sheet(
103+
sheet_name=sheet_name,
104+
name_columns_by_row=name_columns_by_row,
105+
**keywords)
102106
if sheet:
103107
return sheet.to_dict()
104108
else:
105109
return None
106110

107111
def get_records(self, sheet_name=None, name_columns_by_row=0, **keywords):
108112
"""Get a list of records from the file
109-
110-
:param form_field_name: the file field name in the html form for file upload
111-
:param sheet_name: For an excel book, there could be multiple sheets. If it is left
112-
unspecified, the sheet at index 0 is loaded. For 'csv', 'tsv' file,
113-
*sheet_name* should be None anyway.
113+
114+
:param sheet_name: For an excel book, there could be multiple
115+
sheets. If it is left unspecified, the
116+
sheet at index 0 is loaded. For 'csv',
117+
'tsv' file, *sheet_name* should be None anyway.
114118
:param keywords: additional key words
115119
:returns: A list of records
116120
"""
117-
sheet = self.load_single_sheet(sheet_name=sheet_name, name_columns_by_row=name_columns_by_row, **keywords)
121+
sheet = self.load_single_sheet(
122+
sheet_name=sheet_name,
123+
name_columns_by_row=name_columns_by_row,
124+
**keywords)
118125
if sheet:
119126
return sheet.to_records()
120127
else:
@@ -142,7 +149,6 @@ def save_to_database(
142149
def get_book(self, **keywords):
143150
"""Get a instance of :class:`Book` from the file
144151
145-
:param form_field_name: the file field name in the html form for file upload
146152
:param keywords: additional key words
147153
:returns: A instance of :class:`Book`
148154
"""
@@ -151,7 +157,6 @@ def get_book(self, **keywords):
151157
def get_book_dict(self, **keywords):
152158
"""Get a dictionary of two dimensional array from the file
153159
154-
:param form_field_name: the file field name in the html form for file upload
155160
:param keywords: additional key words
156161
:returns: A dictionary of two dimensional arrays
157162
"""
@@ -161,10 +166,11 @@ def get_book_dict(self, **keywords):
161166
else:
162167
return None
163168

164-
def save_book_to_database(self,
165-
session=None, tables=None,
166-
initializers=None, mapdicts=None, auto_commit=True,
167-
**keywords):
169+
def save_book_to_database(
170+
self,
171+
session=None, tables=None,
172+
initializers=None, mapdicts=None, auto_commit=True,
173+
**keywords):
168174
book = self.load_book(**keywords)
169175
if book:
170176
book.save_to_database(session,
@@ -174,7 +180,6 @@ def save_book_to_database(self,
174180
auto_commit=auto_commit)
175181

176182

177-
178183
class ExcelInputInMultiDict(ExcelInput):
179184
""" A generic interface for an upload excel file appearing in a dictionary
180185
"""
@@ -193,7 +198,7 @@ def load_single_sheet(self, field_name=None, sheet_name=None, **keywords):
193198

194199
def load_book(self, field_name=None, **keywords):
195200
file_type, file_handle = self.get_file_tuple(field_name)
196-
if file_type is not None and file_handle is not None:
201+
if file_type is not None and file_handle is not None:
197202
return pe.get_book(file_type=file_type,
198203
file_content=file_handle.read(),
199204
**keywords)
@@ -209,11 +214,13 @@ def dummy_func(content, content_type=None, status=200):
209214

210215

211216
def make_response(pyexcel_instance, file_type, status=200, **keywords):
212-
"""Make a http response from a pyexcel instance of :class:`~pyexcel.Sheet` or :class:`~pyexcel.Book`
217+
"""
218+
Make a http response from a pyexcel instance of
219+
:class:`~pyexcel.Sheet` or :class:`~pyexcel.Book`
213220
214221
:param pyexcel_instance: pyexcel.Sheet or pyexcel.Book
215222
:param file_type: one of the following strings:
216-
223+
217224
* 'csv'
218225
* 'tsv'
219226
* 'csvz'
@@ -222,41 +229,60 @@ def make_response(pyexcel_instance, file_type, status=200, **keywords):
222229
* 'xlsx'
223230
* 'xlsm'
224231
* 'ods'
225-
232+
226233
:param status: unless a different status is to be returned.
227234
"""
228235
io = pe.get_io(file_type)
229236
pyexcel_instance.save_to_memory(file_type, io, **keywords)
230237
io.seek(0)
231-
return ExcelResponse(io.read(), content_type=FILE_TYPE_MIME_TABLE[file_type], status=status)
238+
return ExcelResponse(io.read(),
239+
content_type=FILE_TYPE_MIME_TABLE[file_type],
240+
status=status)
232241

233242

234-
def make_response_from_array(array, file_type, status=200, **keywords):
235-
return make_response(pe.Sheet(array), file_type, status, **keywords)
243+
def make_response_from_array(array,
244+
file_type, status=200,
245+
**keywords):
246+
return make_response(pe.Sheet(array),
247+
file_type, status, **keywords)
236248

237-
238-
def make_response_from_dict(adict, file_type, status=200, **keywords):
239-
return make_response(pe.load_from_dict(adict), file_type, status, **keywords)
240249

250+
def make_response_from_dict(adict,
251+
file_type, status=200,
252+
**keywords):
253+
return make_response(pe.load_from_dict(adict),
254+
file_type, status, **keywords)
241255

242-
def make_response_from_records(records, file_type, status=200, **keywords):
243-
return make_response(pe.load_from_records(records), file_type, status, **keywords)
244256

257+
def make_response_from_records(records,
258+
file_type, status=200,
259+
**keywords):
260+
return make_response(pe.load_from_records(records),
261+
file_type, status, **keywords)
245262

246-
def make_response_from_book_dict(adict, file_type, status=200, **keywords):
263+
264+
def make_response_from_book_dict(adict,
265+
file_type, status=200,
266+
**keywords):
247267
return make_response(pe.Book(adict), file_type, status, **keywords)
248268

249269

250-
def make_response_from_query_sets(query_sets, column_names, file_type, status=200, **keywords):
270+
def make_response_from_query_sets(query_sets, column_names,
271+
file_type, status=200,
272+
**keywords):
251273
sheet = pe.get_sheet(query_sets=query_sets, column_names=column_names)
252274
return make_response(sheet, file_type, status, **keywords)
253275

254276

255-
def make_response_from_a_table(session, table, file_type, status=200, **keywords):
277+
def make_response_from_a_table(session, table,
278+
file_type, status=200,
279+
**keywords):
256280
sheet = pe.get_sheet(session=session, table=table, **keywords)
257281
return make_response(sheet, file_type, status, **keywords)
258282

259283

260-
def make_response_from_tables(session, tables, file_type, status=200, **keywords):
284+
def make_response_from_tables(session, tables,
285+
file_type, status=200,
286+
**keywords):
261287
book = pe.get_book(session=session, tables=tables, **keywords)
262288
return make_response(book, file_type, status, **keywords)

0 commit comments

Comments
 (0)