From 0abc7e17cdc66ae587a8bcb0f77f899eaf3698e1 Mon Sep 17 00:00:00 2001 From: Labrys Date: Mon, 6 Jun 2016 12:16:22 -0400 Subject: [PATCH] Update configobj to v5.0.6: Dependencies * six 1.10.0 --- libs/configobj/_version.py | 2 +- libs/configobj/configobj.py | 54 ++++++++++++++++++++----------------- libs/configobj/validate.py | 2 +- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/libs/configobj/_version.py b/libs/configobj/_version.py index 742c20e4..6d013711 100644 --- a/libs/configobj/_version.py +++ b/libs/configobj/_version.py @@ -1 +1 @@ -__version__ = '5.0.4' \ No newline at end of file +__version__ = '5.0.6' \ No newline at end of file diff --git a/libs/configobj/configobj.py b/libs/configobj/configobj.py index 76ff78f1..ba886e86 100644 --- a/libs/configobj/configobj.py +++ b/libs/configobj/configobj.py @@ -19,9 +19,10 @@ import sys from codecs import BOM_UTF8, BOM_UTF16, BOM_UTF16_BE, BOM_UTF16_LE -# imported lazily to avoid startup performance hit if it isn't used import six +from _version import __version__ +# imported lazily to avoid startup performance hit if it isn't used compiler = None # A dictionary mapping BOM to @@ -1580,7 +1581,7 @@ class ConfigObj(Section): self.indent_type = indent cur_depth = sect_open.count('[') if cur_depth != sect_close.count(']'): - self._handle_error("Cannot compute the section depth at line %s.", + self._handle_error("Cannot compute the section depth", NestingError, infile, cur_index) continue @@ -1590,7 +1591,7 @@ class ConfigObj(Section): parent = self._match_depth(this_section, cur_depth).parent except SyntaxError: - self._handle_error("Cannot compute nesting level at line %s.", + self._handle_error("Cannot compute nesting level", NestingError, infile, cur_index) continue elif cur_depth == this_section.depth: @@ -1600,12 +1601,13 @@ class ConfigObj(Section): # the new section is a child the current section parent = this_section else: - self._handle_error("Section too nested at line %s.", + self._handle_error("Section too nested", NestingError, infile, cur_index) + continue sect_name = self._unquote(sect_name) if sect_name in parent: - self._handle_error('Duplicate section name at line %s.', + self._handle_error('Duplicate section name', DuplicateError, infile, cur_index) continue @@ -1625,7 +1627,7 @@ class ConfigObj(Section): mat = self._keyword.match(line) if mat is None: self._handle_error( - 'Invalid line ({0!r}) (matched as neither section nor keyword) at line "%s".'.format(line), + 'Invalid line ({0!r}) (matched as neither section nor keyword)'.format(line), ParseError, infile, cur_index) else: # is a keyword value @@ -1640,7 +1642,7 @@ class ConfigObj(Section): value, infile, cur_index, maxline) except SyntaxError: self._handle_error( - 'Parse error in multiline value at line %s.', + 'Parse error in multiline value', ParseError, infile, cur_index) continue else: @@ -1650,9 +1652,9 @@ class ConfigObj(Section): value = unrepr(value) except Exception as e: if type(e) == UnknownType: - msg = 'Unknown name or type in value at line %s.' + msg = 'Unknown name or type in value' else: - msg = 'Parse error from unrepr-ing multiline value at line %s.' + msg = 'Parse error from unrepr-ing multiline value' self._handle_error(msg, UnreprError, infile, cur_index) continue @@ -1663,9 +1665,9 @@ class ConfigObj(Section): value = unrepr(value) except Exception as e: if isinstance(e, UnknownType): - msg = 'Unknown name or type in value at line %s.' + msg = 'Unknown name or type in value' else: - msg = 'Parse error from unrepr-ing value at line %s.' + msg = 'Parse error from unrepr-ing value' self._handle_error(msg, UnreprError, infile, cur_index) continue @@ -1675,14 +1677,14 @@ class ConfigObj(Section): (value, comment) = self._handle_value(value) except SyntaxError: self._handle_error( - 'Parse error in value at line %s.', + 'Parse error in value', ParseError, infile, cur_index) continue # key = self._unquote(key) if key in this_section: self._handle_error( - 'Duplicate keyword name at line %s.', + 'Duplicate keyword name', DuplicateError, infile, cur_index) continue # add the key. @@ -1733,7 +1735,7 @@ class ConfigObj(Section): """ line = infile[cur_index] cur_index += 1 - message = text % cur_index + message = '{0} at line {1}.'.format(text, cur_index) error = ErrorClass(message, cur_index, line) if self.raise_errors: # raise the error - parsing stops here @@ -2106,21 +2108,25 @@ class ConfigObj(Section): # Windows specific hack to avoid writing '\r\r\n' newline = '\n' output = self._a_to_u(newline).join(out) - if self.encoding: - output = output.encode(self.encoding) - if self.BOM and ((self.encoding is None) or match_utf8(self.encoding)): - # Add the UTF8 BOM - output = BOM_UTF8 + output - if not output.endswith(newline): output += newline + + if isinstance(output, six.binary_type): + output_bytes = output + else: + output_bytes = output.encode(self.encoding or + self.default_encoding or + 'ascii') + + if self.BOM and ((self.encoding is None) or match_utf8(self.encoding)): + # Add the UTF8 BOM + output_bytes = BOM_UTF8 + output_bytes + if outfile is not None: - outfile.write(output) + outfile.write(output_bytes) else: with open(self.filename, 'wb') as h: - h.write(output.encode(self.encoding or - self.default_encoding or - 'ascii')) + h.write(output_bytes) def validate(self, validator, preserve_errors=False, copy=False, section=None): diff --git a/libs/configobj/validate.py b/libs/configobj/validate.py index 11ab2ef3..b7a964c4 100644 --- a/libs/configobj/validate.py +++ b/libs/configobj/validate.py @@ -538,7 +538,7 @@ class Validator(object): ConfigObj, an alternative to ConfigParser which supports lists and can validate a config file using a config schema. For more details on using Validator with ConfigObj see: - http://www.voidspace.org.uk/python/configobj.html + https://configobj.readthedocs.org/en/latest/configobj.html """ # this regex does the initial parsing of the checks