Skip to content

Commit 584f5f4

Browse files
committed
upstreaming the fix from v0.3.3
2 parents 9e9ed77 + 47ab508 commit 584f5f4

File tree

8 files changed

+61
-18
lines changed

8 files changed

+61
-18
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ language: python
33
notifications:
44
email: false
55
python:
6+
- pypy
67
- 3.6
78
- 3.5
89
- 3.4
910
- 3.3
1011
- 2.7
1112
- 2.6
12-
- pypy
1313
matrix:
1414
include:
1515
- python: 2.7

CHANGELOG.rst

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,29 @@ Change log
77
Updated
88
********************************************************************************
99

10-
#. `#15 <https://github.com/pyexcel/pyexcel-xlsx/issues/15>`_, close file
11-
handle
10+
#. `#15 <https://github.com/pyexcel/pyexcel-xlsx/issues/15>`_, close file handle
1211
#. pyexcel-io plugin interface now updated to use
1312
`lml <https://github.com/chfw/lml>`_.
1413

14+
0.3.3 - 30/05/2017
15+
--------------------------------------------------------------------------------
16+
17+
Updated
18+
********************************************************************************
19+
20+
#. `#18 <https://github.com/pyexcel/pyexcel-xls/issues/18>`_, pass on
21+
encoding_override and others to xlrd.
22+
23+
0.3.2 - 18.05.2017
24+
--------------------------------------------------------------------------------
25+
26+
Updated
27+
********************************************************************************
28+
29+
#. `#16 <https://github.com/pyexcel/pyexcel-xls/issues/16>`_, allow mmap to
30+
be passed as file content
31+
32+
1533
0.3.1 - 16.01.2017
1634
--------------------------------------------------------------------------------
1735

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
]
1313

1414
intersphinx_mapping = {
15-
'pyexcel': ('http://pyexcel.readthedocs.org/en/latest/', None)
15+
'pyexcel': ('http://pyexcel.readthedocs.org/en/latest/', None),
1616
}
1717
spelling_word_list_filename = 'spelling_wordlist.txt'
1818
templates_path = ['_templates']
@@ -21,7 +21,7 @@
2121

2222
project = u'pyexcel-xls'
2323
copyright = u'2015-2017 Onni Software Ltd.'
24-
version = '0.3.1'
24+
version = '0.3.3'
2525
release = '0.4.0'
2626
exclude_patterns = []
2727
pygments_style = 'sphinx'

pyexcel_xls.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ overrides: "pyexcel.yaml"
22
name: "pyexcel-xls"
33
nick_name: xls
44
version: 0.4.0
5-
release: 0.3.1
5+
release: 0.3.3
66
file_type: xls
77
dependencies:
88
- pyexcel-io>=0.3.0

pyexcel_xls/xlsr.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
from collections import OrderedDict
2323

2424

25+
XLS_KEYWORDS = [
26+
'filename', 'logfile', 'verbosity', 'use_mmap',
27+
'file_contents', 'encoding_override', 'formatting_info',
28+
'on_demand', 'ragged_rows'
29+
]
30+
31+
2532
class XLSheet(SheetReader):
2633
"""
2734
xls, xlsx, xlsm sheet reader
@@ -118,30 +125,34 @@ def read_sheet(self, native_sheet):
118125
return {sheet.name: sheet.to_array()}
119126

120127
def _get_book(self, on_demand=False):
128+
xlrd_params = self._extract_xlrd_params()
129+
xlrd_params['on_demand'] = on_demand
130+
121131
if self._file_name:
122-
xls_book = xlrd.open_workbook(self._file_name, on_demand=on_demand)
132+
xlrd_params['filename'] = self._file_name
123133
elif self._file_stream:
124134
self._file_stream.seek(0)
125135
file_content = self._file_stream.read()
126-
xls_book = xlrd.open_workbook(
127-
None,
128-
file_contents=file_content,
129-
on_demand=on_demand
130-
)
136+
xlrd_params['file_contents'] = file_content
131137
elif self._file_content is not None:
132-
xls_book = xlrd.open_workbook(
133-
None,
134-
file_contents=self._file_content,
135-
on_demand=on_demand
136-
)
138+
xlrd_params['file_contents'] = self._file_content
137139
else:
138140
raise IOError("No valid file name or file content found.")
141+
xls_book = xlrd.open_workbook(**xlrd_params)
139142
return xls_book
140143

141144
def _get_params(self):
142145
self.skip_hidden_sheets = self._keywords.get(
143146
'skip_hidden_sheets', True)
144147

148+
def _extract_xlrd_params(self):
149+
params = {}
150+
if self._keywords is not None:
151+
for key in list(self._keywords.keys()):
152+
if key in XLS_KEYWORDS:
153+
params[key] = self._keywords.pop(key)
154+
return params
155+
145156

146157
def is_integer_ok_for_xl_float(value):
147158
"""check if a float value had zero value in digits"""

tests/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
nose
2+
mock;python_version<"3"
23
codecov
34
coverage
45
flake8

tests/test_bug_fixes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from _compact import OrderedDict
1111
from nose.tools import eq_, raises
1212
import datetime
13+
from mock import patch
1314

1415

1516
def test_pyexcel_issue_5():
@@ -68,5 +69,17 @@ def test_issue_16_file_stream_has_no_getvalue():
6869
pe.get_sheet(file_stream=f, file_type='xls')
6970

7071

72+
@patch('xlrd.open_workbook')
73+
def test_issue_18_encoding_override_isnt_passed(fake_open):
74+
fake_open.return_value = None
75+
test_encoding = 'utf-32'
76+
from pyexcel_xls.xlsr import XLSBook
77+
book = XLSBook()
78+
book.open('fake_file.xls', encoding_override=test_encoding)
79+
book._get_book()
80+
keywords = fake_open.call_args[1]
81+
assert keywords['encoding_override'] == test_encoding
82+
83+
7184
def get_fixture(file_name):
7285
return os.path.join("tests", "fixtures", file_name)

tests/test_writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ def test_write_book(self):
1919
reader = Reader()
2020
reader.open(self.testfile)
2121
content = reader.read_all()
22-
reader.close()
2322
for key in content.keys():
2423
content[key] = list(content[key])
2524
assert content == self.content
25+
reader.close()
2626

2727
def tearDown(self):
2828
if os.path.exists(self.testfile):

0 commit comments

Comments
 (0)