Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions jproperties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"__"))
)


Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
),
Expand Down
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_encodingescape.py
Original file line number Diff line number Diff line change
@@ -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"])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_escape_parsing.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_line_continuation.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_setmeta.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_surrogate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from six import BytesIO
from io import BytesIO
from jproperties import Properties, ParseError


Expand Down