Skip to content

Commit

Permalink
Update configobj to 5.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiodsf committed Sep 27, 2024
1 parent 2d6874a commit d4f68c0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 80 deletions.
9 changes: 5 additions & 4 deletions sourcespec/configobj/LICENSE
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Copyright (c):
2003-2010, Michael Foord
2014, Eli Courtwright, Rob Dennis
2003-2010, Michael Foord, Nicola Larosa
2014-2023, Eli Courtwright, Rob Dennis
All rights reserved.
E-mails :
fuzzyman AT voidspace DOT org DOT uk
michael AT python DOT org
nico AT tekNico DOT net
eli AT courtwright DOT org
rdennis AT gmail DOT com

Expand All @@ -12,7 +13,7 @@ Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:


2014
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

Expand Down
59 changes: 27 additions & 32 deletions sourcespec/configobj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
# Python 2.7
from collections import Mapping

import six
from ._version import __version__

# imported lazily to avoid startup performance hit if it isn't used
Expand Down Expand Up @@ -201,7 +200,7 @@ class DuplicateError(ConfigObjError):

class ConfigspecError(ConfigObjError):
"""
An error occured whilst parsing a configspec.
An error occurred whilst parsing a configspec.
"""


Expand Down Expand Up @@ -507,11 +506,11 @@ def __getitem__(self, key):
"""Fetch the item and do string interpolation."""
val = dict.__getitem__(self, key)
if self.main.interpolation:
if isinstance(val, six.string_types):
if isinstance(val, (str, )):
return self._interpolate(key, val)
if isinstance(val, list):
def _check(entry):
if isinstance(entry, six.string_types):
if isinstance(entry, (str, )):
return self._interpolate(key, entry)
return entry
new = [_check(entry) for entry in val]
Expand All @@ -534,7 +533,7 @@ def __setitem__(self, key, value, unrepr=False):
``unrepr`` must be set when setting a value to a dictionary, without
creating a new sub-section.
"""
if not isinstance(key, six.string_types):
if not isinstance(key, (str, )):
raise ValueError('The key "%s" is not a string.' % key)

# add the comment
Expand Down Expand Up @@ -568,11 +567,11 @@ def __setitem__(self, key, value, unrepr=False):
if key not in self:
self.scalars.append(key)
if not self.main.stringify:
if isinstance(value, six.string_types):
if isinstance(value, (str, )):
pass
elif isinstance(value, (list, tuple)):
for entry in value:
if not isinstance(entry, six.string_types):
if not isinstance(entry, (str, )):
raise TypeError('Value is not a string "%s".' % entry)
else:
raise TypeError('Value is not a string "%s".' % value)
Expand Down Expand Up @@ -807,11 +806,11 @@ def walk(self, function, raise_errors=True,
Return a dictionary of the return values
If the function raises an exception, raise the errror
If the function raises an exception, raise the error
unless ``raise_errors=False``, in which case set the return value to
``False``.
Any unrecognised keyword arguments you pass to walk, will be pased on
Any unrecognised keyword arguments you pass to walk, will be passed on
to the function you pass in.
Note: if ``call_on_sections`` is ``True`` then - on encountering a
Expand Down Expand Up @@ -920,7 +919,7 @@ def as_bool(self, key):
return False
else:
try:
if not isinstance(val, six.string_types):
if not isinstance(val, (str, )):
# TODO: Why do we raise a KeyError here?
raise KeyError()
else:
Expand Down Expand Up @@ -1210,7 +1209,7 @@ def _load(self, infile, configspec):
except AttributeError:
pass

if isinstance(infile, six.string_types):
if isinstance(infile, (str, )):
self.filename = infile
if os.path.isfile(infile):
with open(infile, 'rb') as h:
Expand Down Expand Up @@ -1278,7 +1277,7 @@ def set_section(in_section, this_section):
break
break

assert all(isinstance(line, six.string_types) for line in content), repr(content)
assert all(isinstance(line, (str, )) for line in content), repr(content)
content = [line.rstrip('\r\n') for line in content]

self._parse(content)
Expand Down Expand Up @@ -1387,7 +1386,7 @@ def _handle_bom(self, infile):
else:
line = infile

if isinstance(line, six.text_type):
if isinstance(line, str):
# it's already decoded and there's no need to do anything
# else, just use the _decode utility method to handle
# listifying appropriately
Expand Down Expand Up @@ -1432,7 +1431,7 @@ def _handle_bom(self, infile):

# No encoding specified - so we need to check for UTF8/UTF16
for BOM, (encoding, final_encoding) in list(BOMS.items()):
if not isinstance(line, six.binary_type) or not line.startswith(BOM):
if not isinstance(line, bytes) or not line.startswith(BOM):
# didn't specify a BOM, or it's not a bytestring
continue
else:
Expand All @@ -1448,22 +1447,18 @@ def _handle_bom(self, infile):
else:
infile = newline
# UTF-8
if isinstance(infile, six.text_type):
if isinstance(infile, str):
return infile.splitlines(True)
elif isinstance(infile, six.binary_type):
elif isinstance(infile, bytes):
return infile.decode('utf-8').splitlines(True)
else:
return self._decode(infile, 'utf-8')
# UTF16 - have to decode
return self._decode(infile, encoding)


if six.PY2 and isinstance(line, str):
# don't actually do any decoding, since we're on python 2 and
# returning a bytestring is fine
return self._decode(infile, None)
# No BOM discovered and no encoding specified, default to UTF-8
if isinstance(infile, six.binary_type):
if isinstance(infile, bytes):
return infile.decode('utf-8').splitlines(True)
else:
return self._decode(infile, 'utf-8')
Expand All @@ -1475,18 +1470,18 @@ def _decode(self, infile, encoding):
if is a string, it also needs converting to a list.
"""
if isinstance(infile, six.binary_type):
if isinstance(infile, bytes):
# NOTE: Could raise a ``UnicodeDecodeError``
if encoding:
return infile.decode(encoding).splitlines(True)
else:
return infile.splitlines(True)
if isinstance(infile, six.string_types):
if isinstance(infile, (str, )):
return infile.splitlines(True)

if encoding:
for i, line in enumerate(infile):
if isinstance(line, six.binary_type):
if isinstance(line, bytes):
# NOTE: The isinstance test here handles mixed lists of unicode/string
# NOTE: But the decode will break on any non-string values
# NOTE: Or could raise a ``UnicodeDecodeError``
Expand All @@ -1496,7 +1491,7 @@ def _decode(self, infile, encoding):

def _decode_element(self, line):
"""Decode element to unicode if necessary."""
if isinstance(line, six.binary_type) and self.default_encoding:
if isinstance(line, bytes) and self.default_encoding:
return line.decode(self.default_encoding)
else:
return line
Expand All @@ -1508,8 +1503,8 @@ def _str(self, value):
Used by ``stringify`` within validate, to turn non-string values
into strings.
"""
if not isinstance(value, six.string_types):
# intentially 'str' because it's just whatever the "normal"
if not isinstance(value, (str, )):
# intentionally 'str' because it's just whatever the "normal"
# string type is for the python version we're dealing with
return str(value)
else:
Expand Down Expand Up @@ -1706,7 +1701,7 @@ def _handle_error(self, text, ErrorClass, infile, cur_index):
Handle an error according to the error settings.
Either raise the error or store it.
The error will have occured at ``cur_index``
The error will have occurred at ``cur_index``
"""
line = infile[cur_index]
cur_index += 1
Expand Down Expand Up @@ -1761,9 +1756,9 @@ def _quote(self, value, multiline=True):
return self._quote(value[0], multiline=False) + ','
return ', '.join([self._quote(val, multiline=False)
for val in value])
if not isinstance(value, six.string_types):
if not isinstance(value, (str, )):
if self.stringify:
# intentially 'str' because it's just whatever the "normal"
# intentionally 'str' because it's just whatever the "normal"
# string type is for the python version we're dealing with
value = str(value)
else:
Expand Down Expand Up @@ -2081,7 +2076,7 @@ def write(self, outfile=None, section=None):
if not output.endswith(newline):
output += newline

if isinstance(output, six.binary_type):
if isinstance(output, bytes):
output_bytes = output
else:
output_bytes = output.encode(self.encoding or
Expand Down Expand Up @@ -2323,7 +2318,7 @@ def reload(self):
This method raises a ``ReloadError`` if the ConfigObj doesn't have
a filename attribute pointing to a file.
"""
if not isinstance(self.filename, six.string_types):
if not isinstance(self.filename, (str, )):
raise ReloadError()

filename = self.filename
Expand Down
Loading

0 comments on commit d4f68c0

Please sign in to comment.