Skip to content

Commit 16d4f32

Browse files
committed
Merge pull request #57 from DiffSK/master
release 5.0.5
2 parents 6ae299f + df25945 commit 16d4f32

File tree

7 files changed

+36
-27
lines changed

7 files changed

+36
-27
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configobj [![Build Status](https://travis-ci.org/DiffSK/configobj.png?branch=master)](https://travis-ci.org/DiffSK/configobj)[![Downloads](https://pypip.in/d/configobj/badge.png)](https://crate.io/packages/configobj)[![PyPI version](https://badge.fury.io/py/configobj.png)](http://badge.fury.io/py/configobj)[![Coverage Status](https://coveralls.io/repos/DiffSK/configobj/badge.png?branch=master)](https://coveralls.io/r/DiffSK/configobj?branch=master)
1+
configobj [![Build Status](https://travis-ci.org/DiffSK/configobj.svg?branch=master)](https://travis-ci.org/DiffSK/configobj)[![Downloads](https://pypip.in/d/configobj/badge.png)](https://crate.io/packages/configobj)[![PyPI version](https://badge.fury.io/py/configobj.png)](http://badge.fury.io/py/configobj)[![Coverage Status](https://coveralls.io/repos/DiffSK/configobj/badge.png?branch=master)](https://coveralls.io/r/DiffSK/configobj?branch=master)
22
=========
33

44
Python 3+ compatible port of the [configobj](https://pypi.python.org/pypi/configobj/) library.
@@ -9,7 +9,7 @@ Found at [readthedocs](http://configobj.readthedocs.org/)
99

1010
Status
1111
=========
12-
This project has is now maintained by [Eli Courtwright](https://github.com/EliAndrewC) and [Rob Dennis](https://github.com/robdennis) with the blessing of original creator [Michael Foord](http://www.voidspace.org.uk/) and the most recent release is version *5.0.4* (view [changelog](http://configobj.readthedocs.org/en/latest/configobj.html#version-5-0-4)).
12+
This project is now maintained by [Eli Courtwright](https://github.com/EliAndrewC) and [Rob Dennis](https://github.com/robdennis) with the blessing of original creator [Michael Foord](http://www.voidspace.org.uk/).
1313

1414
For long time ConfigObj users, the biggest change is in the officially supported python versions:
1515
- 2.6

_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '5.0.4'
1+
__version__ = '5.0.5'

configobj.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,21 +2107,25 @@ def write(self, outfile=None, section=None):
21072107
# Windows specific hack to avoid writing '\r\r\n'
21082108
newline = '\n'
21092109
output = self._a_to_u(newline).join(out)
2110-
if self.encoding:
2111-
output = output.encode(self.encoding)
2112-
if self.BOM and ((self.encoding is None) or match_utf8(self.encoding)):
2113-
# Add the UTF8 BOM
2114-
output = BOM_UTF8 + output
2115-
21162110
if not output.endswith(newline):
21172111
output += newline
2112+
2113+
if isinstance(output, six.binary_type):
2114+
output_bytes = output
2115+
else:
2116+
output_bytes = output.encode(self.encoding or
2117+
self.default_encoding or
2118+
'ascii')
2119+
2120+
if self.BOM and ((self.encoding is None) or match_utf8(self.encoding)):
2121+
# Add the UTF8 BOM
2122+
output_bytes = BOM_UTF8 + output_bytes
2123+
21182124
if outfile is not None:
2119-
outfile.write(output)
2125+
outfile.write(output_bytes)
21202126
else:
21212127
with open(self.filename, 'wb') as h:
2122-
h.write(output.encode(self.encoding or
2123-
self.default_encoding or
2124-
'ascii'))
2128+
h.write(output_bytes)
21252129

21262130
def validate(self, validator, preserve_errors=False, copy=False,
21272131
section=None):

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
# built documents.
5151
#
5252
# The full version, including alpha/beta/rc tags.
53-
release = '5.0.4'
53+
release = '5.0.5'
5454
# The short X.Y version.
5555
version = '.'.join(release.split('.')[:2])
5656

docs/configobj.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
----------------------------------------
99

1010
:Authors: Michael Foord, Nicola Larosa, Rob Dennis, Eli Courtwright
11-
:Version: ConfigObj 5.0.4
11+
:Version: ConfigObj 5.0.5
1212
:Date: 2014/02/08
1313
:PyPI Entry: `ConfigObj on PyPI <http://pypi.python.org/pypi/configobj/>`_
1414
:Homepage: `Github Page`_
@@ -64,7 +64,7 @@ For support and bug reports please use the ConfigObj `Github Page`_.
6464
Downloading
6565
===========
6666

67-
The current version is **5.0.4**, dated 11th April 2014. ConfigObj 5 is
67+
The current version is **5.0.5**, dated 25th April 2014. ConfigObj 5 is
6868
stable and mature. We still expect to pick up a few bugs along the way though, particularly with respect to Python 3 compatibility [#]_.
6969

7070
We recommend downloading and installing using pip:
@@ -2383,6 +2383,10 @@ CHANGELOG
23832383
This is an abbreviated changelog showing the major releases up to version 4.
23842384
From version 4 it lists all releases and changes.
23852385

2386+
2014/04/11 - Version 5.0.4
2387+
--------------------------
2388+
* BUGFIX: error in writing out config files to disk with non-ascii characters
2389+
23862390
2014/04/11 - Version 5.0.4
23872391
--------------------------
23882392
* BUGFIX: correcting that the code path fixed in 5.0.3 didn't cover reading in

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
* The order of keys/sections is preserved
5252
* Powerful ``unrepr`` mode for storing/retrieving Python data-types
5353
54+
| Release 5.0.5 corrects a unicode-bug that still existed in writing files
5455
| Release 5.0.4 corrects a unicode-bug that still existed in reading files after
5556
| fixing lists of string in 5.0.3
5657
| Release 5.0.3 corrects errors related to the incorrectly handling unicode

tests/test_configobj.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@ def test_that_encoding_using_list_of_strings(self):
216216
else:
217217
assert isinstance(c['test'], str)
218218

219-
#TODO: this can be made more explicit if we switch to unicode_literals
220-
assert c['test'] == b'\xf0\x9f\x90\x9c'.decode('utf8')
219+
assert c['test'] == '\U0001f41c'
221220

222221
#issue #44
223222
def test_encoding_in_subsections(self, ant_cfg, cfg_contents):
@@ -226,7 +225,7 @@ def test_encoding_in_subsections(self, ant_cfg, cfg_contents):
226225

227226
assert isinstance(cfg['tags']['bug']['translated'], six.text_type)
228227

229-
#issue #44
228+
#issue #44 and #55
230229
def test_encoding_in_config_files(self, request, ant_cfg):
231230
# the cfg_contents fixture is doing this too, but be explicit
232231
with NamedTemporaryFile(delete=False, mode='wb') as cfg_file:
@@ -235,6 +234,7 @@ def test_encoding_in_config_files(self, request, ant_cfg):
235234

236235
cfg = ConfigObj(cfg_file.name, encoding='utf-8')
237236
assert isinstance(cfg['tags']['bug']['translated'], six.text_type)
237+
cfg.write()
238238

239239
@pytest.fixture
240240
def testconfig1():
@@ -515,7 +515,7 @@ def test_unicode_handling():
515515
uc = ConfigObj(u)
516516
assert uc.newlines == '\r\n'
517517
uc.newlines = '\r'
518-
file_like = six.StringIO()
518+
file_like = six.BytesIO()
519519
uc.write(file_like)
520520
file_like.seek(0)
521521
uc2 = ConfigObj(file_like)
@@ -811,7 +811,7 @@ def reloadable_cfg_content(self):
811811
return content
812812

813813
def test_handle_no_filename(self):
814-
for bad_args in ([six.StringIO()], [], [[]]):
814+
for bad_args in ([six.BytesIO()], [], [[]]):
815815
cfg = ConfigObj(*bad_args)
816816
with pytest.raises(ReloadError) as excinfo:
817817
cfg.reload()
@@ -1264,23 +1264,23 @@ class TestEdgeCasesWhenWritingOut(object):
12641264
def test_newline_terminated(self, empty_cfg):
12651265
empty_cfg.newlines = '\n'
12661266
empty_cfg['a'] = 'b'
1267-
collector = six.StringIO()
1267+
collector = six.BytesIO()
12681268
empty_cfg.write(collector)
1269-
assert collector.getvalue() == 'a = b\n'
1269+
assert collector.getvalue() == b'a = b\n'
12701270

12711271
def test_hash_escaping(self, empty_cfg):
12721272
empty_cfg.newlines = '\n'
12731273
empty_cfg['#a'] = 'b # something'
1274-
collector = six.StringIO()
1274+
collector = six.BytesIO()
12751275
empty_cfg.write(collector)
1276-
assert collector.getvalue() == '"#a" = "b # something"\n'
1276+
assert collector.getvalue() == b'"#a" = "b # something"\n'
12771277

12781278
empty_cfg = ConfigObj()
12791279
empty_cfg.newlines = '\n'
12801280
empty_cfg['a'] = 'b # something', 'c # something'
1281-
collector = six.StringIO()
1281+
collector = six.BytesIO()
12821282
empty_cfg.write(collector)
1283-
assert collector.getvalue() == 'a = "b # something", "c # something"\n'
1283+
assert collector.getvalue() == b'a = "b # something", "c # something"\n'
12841284

12851285
def test_detecting_line_endings_from_existing_files(self):
12861286
for expected_line_ending in ('\r\n', '\n'):

0 commit comments

Comments
 (0)