From 17d270a7b46c4456dbdd666f0f334f16126ee51f Mon Sep 17 00:00:00 2001 From: rahogata Date: Tue, 11 Nov 2025 00:01:59 +0530 Subject: [PATCH] remove six module. --- jproperties.py | 36 ++++++++++++++++----------------- pyproject.toml | 5 +---- tests/test_encodingescape.py | 2 +- tests/test_escape_parsing.py | 2 +- tests/test_line_continuation.py | 2 +- tests/test_setmeta.py | 2 +- tests/test_surrogate.py | 2 +- 7 files changed, 24 insertions(+), 27 deletions(-) diff --git a/jproperties.py b/jproperties.py index e657f48..c8419f8 100644 --- a/jproperties.py +++ b/jproperties.py @@ -38,10 +38,10 @@ import struct import sys import time +import io from collections import namedtuple -import six -from six.moves.collections_abc import MutableMapping +from collections.abc import MutableMapping # This represents a combination of a value and metadata for a property key. @@ -58,8 +58,8 @@ def _is_runtime_meta(key): Handles both unicode and byte metadata keys. """ return ( - (isinstance(key, six.text_type) and key.startswith(u"__")) or - (isinstance(key, six.binary_type) and key.startswith(b"__")) + (isinstance(key, str) and key.startswith(u"__")) or + (isinstance(key, bytes) and key.startswith(b"__")) ) @@ -99,11 +99,11 @@ def replace(match): return u'\\u{0:04x}\\u{1:04x}'.format(s1, s2) # Just to be sure: If we get passed a str object, then try to decode it as UTF-8. - if isinstance(unicode_obj, six.binary_type): + if isinstance(unicode_obj, bytes): unicode_obj = unicode_obj.decode('utf-8') return re.sub( - six.text_type(r'[^ -~]'), + str(r'[^ -~]'), replace, unicode_obj ) @@ -141,13 +141,13 @@ def _escape_str(raw_str, only_leading_spaces=False, escape_non_printing=False, l :return: The escaped string. """ # We NEED an unicode object. It's worth a try. - if isinstance(raw_str, six.binary_type): + if isinstance(raw_str, bytes): # consider bringing in chardet... raw_str = raw_str.decode("utf-8") - elif not isinstance(raw_str, six.text_type): + elif not isinstance(raw_str, str): # Last resort: Convert unknown object to a unicode string. # This works nicely for integers etc. - raw_str = six.text_type(raw_str) + raw_str = str(raw_str) # Do simple whitespace substitutions. trans_dict = { @@ -267,7 +267,7 @@ def __len__(self): return len(self._properties) def __getitem__(self, item): - if not isinstance(item, six.string_types): + if not isinstance(item, str): raise TypeError("Property keys must be of type str or unicode") if item not in self._properties: @@ -279,14 +279,14 @@ def __getitem__(self, item): ) def __setitem__(self, key, value): - if not isinstance(key, six.string_types): + if not isinstance(key, str): raise TypeError("Property keys must be of type str or unicode") metadata = None if isinstance(value, tuple): value, metadata = value - if not isinstance(value, six.string_types): + if not isinstance(value, str): raise TypeError("Property values must be of type str or unicode") if metadata is not None and not isinstance(metadata, dict): @@ -297,7 +297,7 @@ def __setitem__(self, key, value): self._metadata[key] = metadata def __delitem__(self, key): - if not isinstance(key, six.string_types): + if not isinstance(key, str): raise TypeError("Property keys must be of type str or unicode") if key not in self._properties: @@ -800,12 +800,12 @@ def load(self, source_data, encoding="iso-8859-1", metadoc=False): """ self.reset(metadoc) - if isinstance(source_data, six.binary_type): + if isinstance(source_data, bytes): # Byte string. Need to decode. - self._source_file = six.StringIO(source_data.decode(encoding)) - elif isinstance(source_data, six.text_type): + self._source_file = io.StringIO(source_data.decode(encoding)) + elif isinstance(source_data, str): # No need to decode. - self._source_file = six.StringIO(source_data) + self._source_file = io.StringIO(source_data) elif encoding is not None: # We treat source_data as a file-like object and wrap it with a StreamReader # for the requested encoding so that we don't need to str.decode() the data manually. @@ -1010,7 +1010,7 @@ def main(): try: p.store( - sys.stdout.buffer if six.PY3 else sys.stdout, + sys.stdout.buffer, u"File generated by %s (escapes in values: %s)" % ( prog_name, process_escapes_in_values ), diff --git a/pyproject.toml b/pyproject.toml index fab68f3..47a37cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,10 +31,7 @@ classifiers = [ "Topic :: Software Development" ] -dependencies = [ - # TODO: Drop dependency since we only support Python 3 nowadays. - "six ~= 1.13" -] +dependencies = [] requires-python = ">= 3.8" dynamic = ["version"] diff --git a/tests/test_encodingescape.py b/tests/test_encodingescape.py index 2482e58..e288ab5 100644 --- a/tests/test_encodingescape.py +++ b/tests/test_encodingescape.py @@ -1,7 +1,7 @@ # vim: fileencoding=utf-8 import pytest -from six import BytesIO +from io import BytesIO from jproperties import Properties @pytest.mark.parametrize("out_encoding", ["ascii", "iso-8859-1"]) diff --git a/tests/test_escape_parsing.py b/tests/test_escape_parsing.py index e9cccce..b2063d5 100644 --- a/tests/test_escape_parsing.py +++ b/tests/test_escape_parsing.py @@ -1,7 +1,7 @@ # vim: fileencoding=utf-8 from jproperties import Properties -from six import BytesIO +from io import BytesIO def test_simple_escape_parsing(): diff --git a/tests/test_line_continuation.py b/tests/test_line_continuation.py index 244c58a..4c7baed 100644 --- a/tests/test_line_continuation.py +++ b/tests/test_line_continuation.py @@ -1,7 +1,7 @@ # vim: fileencoding=utf-8 from jproperties import Properties -from six import BytesIO +from io import BytesIO def test_line_continuation_allowed(): diff --git a/tests/test_setmeta.py b/tests/test_setmeta.py index eecde83..6104257 100644 --- a/tests/test_setmeta.py +++ b/tests/test_setmeta.py @@ -1,7 +1,7 @@ # vim: fileencoding=utf-8 from jproperties import Properties -from six import BytesIO +from io import BytesIO def test_setmeta_bytes(): p = Properties() diff --git a/tests/test_surrogate.py b/tests/test_surrogate.py index db4950c..ac365fe 100644 --- a/tests/test_surrogate.py +++ b/tests/test_surrogate.py @@ -1,5 +1,5 @@ import pytest -from six import BytesIO +from io import BytesIO from jproperties import Properties, ParseError