Skip to content

Commit 3408497

Browse files
committed
🤝 merge with master
2 parents ec62f38 + c21d36f commit 3408497

File tree

11 files changed

+170
-74
lines changed

11 files changed

+170
-74
lines changed

.travis.yml

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
sudo: false
32
dist: xenial
43
language: python
@@ -18,32 +17,40 @@ stages:
1817
- lint
1918

2019
.disable_global: &disable_global
20+
addons: false
21+
cache: false
22+
env: {}
23+
python: false
2124
before_install: false
22-
install: true
25+
install: false
2326
before_script: false
27+
script: false
2428
after_success: false
2529
after_failure: false
30+
before_deploy: false
31+
deploy: false
2632

2733
.lint: &lint
2834
<<: *disable_global
35+
git:
36+
submodules: false
2937
python: 3.6
3038
stage: lint
31-
install: pip install flake8
3239
script: make lint
3340

3441
jobs:
3542
include:
43+
- *moban
3644
- *lint
3745

3846
stage: test
3947

40-
script: make test
41-
4248
before_install:
4349
- if [[ -f min_requirements.txt && "$MINREQ" -eq 1 ]]; then
4450
mv min_requirements.txt requirements.txt ;
4551
fi
46-
- test ! -f rnd_requirements.txt || pip install --no-deps -r rnd_requirements.txt
52+
- test ! -f rnd_requirements.txt ||
53+
pip install --no-deps -r rnd_requirements.txt
4754
- test ! -f rnd_requirements.txt || pip install -r rnd_requirements.txt ;
4855
- pip install -r tests/requirements.txt
4956
script:

CHANGELOG.rst

+18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
Change log
22
================================================================================
33

4+
0.5.19 - 14.7.2019
5+
--------------------------------------------------------------------------------
6+
7+
updated
8+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9+
10+
#. `pyexcel#185 <https://github.com/pyexcel/pyexcel/issues/185>`_: handle stream
11+
conversion if file type(html) needs string content then bytes to handle
12+
13+
0.5.18 - 12.06.2019
14+
--------------------------------------------------------------------------------
15+
16+
updated
17+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
19+
#. `#69 <https://github.com/pyexcel/pyexcel-io/issues/69>`_: Force file
20+
type(force_file_type) on write
21+
422
0.5.17 - 04.04.2019
523
--------------------------------------------------------------------------------
624

changelog.yml

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
name: pyexcel-io
22
organisation: pyexcel
33
releases:
4+
- changes:
5+
- action: updated
6+
details:
7+
- '`pyexcel#185`: handle stream conversion if file type(html) needs string content then bytes to handle'
8+
version: 0.5.19
9+
date: 14.7.2019
10+
- changes:
11+
- action: updated
12+
details:
13+
- '`#69`: Force file type(force_file_type) on write'
14+
version: 0.5.18
15+
date: 12.06.2019
416
- changes:
517
- action: updated
618
details:

docs/source/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# The short X.Y version
2323
version = '0.6.0'
2424
# The full version, including alpha/beta/rc tags
25-
release = '0.5.17'
25+
release = '0.5.19'
2626

2727
# -- General configuration ---------------------------------------------------
2828

@@ -69,4 +69,4 @@
6969
# -- Options for intersphinx extension ---------------------------------------
7070

7171
# Example configuration for intersphinx: refer to the Python standard library.
72-
intersphinx_mapping = {'https://docs.python.org/': None}
72+
intersphinx_mapping = {'https://docs.python.org/': None}

lint.sh

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
pip install flake8
12
flake8 . --exclude=.moban.d,docs --builtins=unicode,xrange,long

pyexcel-io.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ name: pyexcel-io
44
nick_name: io
55
version: 0.6.0
66
current_version: 0.6.0
7+
release: 0.5.19
78
copyright_year: 2015-2019
8-
release: 0.5.17
9+
moban_command: false
910
dependencies:
1011
- ordereddict;python_version<"2.7"
1112
- lml>=0.0.4

pyexcel_io/book.py

+10
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ def create_sheet(self, sheet_name):
232232

233233
def _convert_content_to_stream(file_content, file_type):
234234
stream = manager.get_io(file_type)
235+
if not PY2:
236+
target_content_type = manager.get_io_type(file_type)
237+
needs_encode = (target_content_type == 'bytes' and
238+
not isinstance(file_content, bytes))
239+
needs_decode = (target_content_type == 'string' and
240+
isinstance(file_content, bytes))
241+
if needs_encode:
242+
file_content = file_content.encode('utf-8')
243+
elif needs_decode:
244+
file_content = file_content.decode('utf-8')
235245
stream.write(file_content)
236246
stream.seek(0)
237247
return stream

pyexcel_io/io.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
The io interface to file extensions
66
7-
:copyright: (c) 2014-2017 by Onni Software Ltd.
7+
:copyright: (c) 2014-2019 by Onni Software Ltd.
88
:license: New BSD License, see LICENSE for more details
99
"""
1010
import os
@@ -24,7 +24,7 @@ def iget_data(afile, file_type=None, **keywords):
2424
:param sheet_name: the name of the sheet to be loaded
2525
:param sheet_index: the index of the sheet to be loaded
2626
:param sheets: a list of sheet to be loaded
27-
:param file_type: used only when filename is not a physial file name
27+
:param file_type: used only when filename is not a physical file name
2828
:param force_file_type: used only when filename refers to a physical file
2929
and it is intended to open it as forced file type.
3030
:param streaming: toggles the type of returned data. The values of the
@@ -99,6 +99,8 @@ def save_data(afile, data, file_type=None, **keywords):
9999
:param filename: actual file name, a file stream or actual content
100100
:param data: a dictionary but an ordered dictionary is preferred
101101
:param file_type: used only when filename is not a physial file name
102+
:param force_file_type: used only when filename refers to a physical file
103+
and it is intended to open it as forced file type.
102104
:param library: explicitly name a library for use.
103105
e.g. library='pyexcel-ods'
104106
:param keywords: any other parameters that python csv module's
@@ -201,7 +203,8 @@ def load_data(
201203

202204

203205
def get_writer(
204-
file_name=None, file_stream=None, file_type=None, library=None, **keywords
206+
file_name=None, file_stream=None, file_type=None,
207+
library=None, force_file_type=None, **keywords
205208
):
206209
"""find a suitable writer"""
207210
inputs = [file_name, file_stream]
@@ -211,11 +214,15 @@ def get_writer(
211214
raise IOError(constants.MESSAGE_ERROR_02)
212215

213216
file_type_given = True
217+
214218
if file_type is None and file_name:
215-
try:
216-
file_type = file_name.split(".")[-1]
217-
except AttributeError:
218-
raise Exception("file_name should be a string type")
219+
if force_file_type:
220+
file_type = force_file_type
221+
else:
222+
try:
223+
file_type = file_name.split(".")[-1]
224+
except AttributeError:
225+
raise Exception("file_name should be a string type")
219226

220227
file_type_given = False
221228

0 commit comments

Comments
 (0)