forked from pool/python-anymarkup-core
187 lines
6.8 KiB
Diff
187 lines
6.8 KiB
Diff
|
|
From 1d0c5673c15116625c02316b2605648b92cf18a4 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Daniel Garcia Moreno <daniel.garcia@suse.com>
|
||
|
|
Date: Thu, 20 Oct 2022 08:45:53 +0200
|
||
|
|
Subject: [PATCH] Drop python2 support
|
||
|
|
|
||
|
|
Python2 is very old and not maintained anymore, this patch removes the
|
||
|
|
python-six dependency and drop python2 support.
|
||
|
|
---
|
||
|
|
anymarkup_core/__init__.py | 36 +++++++++++++-----------------------
|
||
|
|
requirements.txt | 1 -
|
||
|
|
setup.py | 7 +++----
|
||
|
|
test/test_parse.py | 5 ++---
|
||
|
|
test/test_serialize.py | 3 +--
|
||
|
|
5 files changed, 19 insertions(+), 33 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/anymarkup_core/__init__.py b/anymarkup_core/__init__.py
|
||
|
|
index 91f4133..21ccc78 100644
|
||
|
|
--- a/anymarkup_core/__init__.py
|
||
|
|
+++ b/anymarkup_core/__init__.py
|
||
|
|
@@ -7,7 +7,6 @@ import os
|
||
|
|
import re
|
||
|
|
import traceback
|
||
|
|
|
||
|
|
-import six
|
||
|
|
try:
|
||
|
|
import configobj
|
||
|
|
except ImportError:
|
||
|
|
@@ -95,7 +94,7 @@ def parse(inp, format=None, encoding='utf-8', force_types=True, interpolate=True
|
||
|
|
if hasattr(inp, 'read'):
|
||
|
|
proper_inp = inp.read()
|
||
|
|
# if proper_inp is unicode, encode it
|
||
|
|
- if isinstance(proper_inp, six.text_type):
|
||
|
|
+ if isinstance(proper_inp, str):
|
||
|
|
proper_inp = proper_inp.encode(encoding)
|
||
|
|
|
||
|
|
# try to guess markup type
|
||
|
|
@@ -105,7 +104,7 @@ def parse(inp, format=None, encoding='utf-8', force_types=True, interpolate=True
|
||
|
|
fmt = _get_format(format, fname, proper_inp)
|
||
|
|
|
||
|
|
# make it look like file-like bytes-yielding object
|
||
|
|
- proper_inp = six.BytesIO(proper_inp)
|
||
|
|
+ proper_inp = io.BytesIO(proper_inp)
|
||
|
|
|
||
|
|
try:
|
||
|
|
res = _do_parse(proper_inp, fmt, encoding, force_types, interpolate)
|
||
|
|
@@ -232,22 +231,17 @@ def _do_parse(inp, fmt, encoding, force_types, interpolate):
|
||
|
|
cfg = configobj.ConfigObj(inp, encoding=encoding, interpolation=interpolate)
|
||
|
|
res = cfg.dict()
|
||
|
|
elif fmt == 'json':
|
||
|
|
- if six.PY3:
|
||
|
|
- # python 3 json only reads from unicode objects
|
||
|
|
- inp = io.TextIOWrapper(inp, encoding=encoding)
|
||
|
|
- res = json.load(inp)
|
||
|
|
- else:
|
||
|
|
- res = json.load(inp, encoding=encoding)
|
||
|
|
+ # python 3 json only reads from unicode objects
|
||
|
|
+ inp = io.TextIOWrapper(inp, encoding=encoding)
|
||
|
|
+ res = json.load(inp)
|
||
|
|
elif fmt == 'json5':
|
||
|
|
- if six.PY3:
|
||
|
|
- inp = io.TextIOWrapper(inp, encoding=encoding)
|
||
|
|
+ inp = io.TextIOWrapper(inp, encoding=encoding)
|
||
|
|
res = json5.load(inp, encoding=encoding)
|
||
|
|
elif fmt == 'toml':
|
||
|
|
if not _is_utf8(encoding):
|
||
|
|
raise AnyMarkupError('toml is always utf-8 encoded according to specification')
|
||
|
|
- if six.PY3:
|
||
|
|
- # python 3 toml prefers unicode objects
|
||
|
|
- inp = io.TextIOWrapper(inp, encoding=encoding)
|
||
|
|
+ # python 3 toml prefers unicode objects
|
||
|
|
+ inp = io.TextIOWrapper(inp, encoding=encoding)
|
||
|
|
res = toml.load(inp)
|
||
|
|
elif fmt == 'xml':
|
||
|
|
res = xmltodict.parse(inp, encoding=encoding)
|
||
|
|
@@ -336,9 +330,9 @@ def _ensure_proper_types(struct, encoding, force_types):
|
||
|
|
res = []
|
||
|
|
for i in struct:
|
||
|
|
res.append(_ensure_proper_types(i, encoding, force_types))
|
||
|
|
- elif isinstance(struct, six.binary_type):
|
||
|
|
+ elif isinstance(struct, bytes):
|
||
|
|
res = struct.decode(encoding)
|
||
|
|
- elif isinstance(struct, (six.text_type, type(None), type(True), six.integer_types, float)):
|
||
|
|
+ elif isinstance(struct, (str, type(None), type(True), int, float)):
|
||
|
|
res = struct
|
||
|
|
elif isinstance(struct, datetime.datetime):
|
||
|
|
# toml can parse datetime natively
|
||
|
|
@@ -347,11 +341,11 @@ def _ensure_proper_types(struct, encoding, force_types):
|
||
|
|
raise AnyMarkupError('internal error - unexpected type {0} in parsed markup'.
|
||
|
|
format(type(struct)))
|
||
|
|
|
||
|
|
- if force_types and isinstance(res, six.text_type):
|
||
|
|
+ if force_types and isinstance(res, str):
|
||
|
|
res = _recognize_basic_types(res)
|
||
|
|
elif not (force_types or
|
||
|
|
- isinstance(res, (dict, collections.OrderedDict, list, six.text_type))):
|
||
|
|
- res = six.text_type(res)
|
||
|
|
+ isinstance(res, (dict, collections.OrderedDict, list, str))):
|
||
|
|
+ res = str(res)
|
||
|
|
|
||
|
|
return res
|
||
|
|
|
||
|
|
@@ -361,8 +355,6 @@ def _recognize_basic_types(s):
|
||
|
|
to a proper type and return it.
|
||
|
|
"""
|
||
|
|
tps = [int, float]
|
||
|
|
- if not six.PY3: # compat for older versions of six that don't have PY2
|
||
|
|
- tps.append(long)
|
||
|
|
for tp in tps:
|
||
|
|
try:
|
||
|
|
return tp(s)
|
||
|
|
@@ -498,5 +490,3 @@ if yaml is not None:
|
||
|
|
yaml.SafeLoader.add_constructor(u'tag:yaml.org,2002:omap', construct_ordereddict)
|
||
|
|
yaml.SafeDumper.add_representer(collections.OrderedDict, represent_ordereddict)
|
||
|
|
yaml.SafeDumper.add_representer(str, represent_str)
|
||
|
|
- if six.PY2:
|
||
|
|
- yaml.SafeDumper.add_representer(unicode, represent_str)
|
||
|
|
diff --git a/requirements.txt b/requirements.txt
|
||
|
|
index ffe2fce..e69de29 100644
|
||
|
|
--- a/requirements.txt
|
||
|
|
+++ b/requirements.txt
|
||
|
|
@@ -1 +0,0 @@
|
||
|
|
-six
|
||
|
|
diff --git a/setup.py b/setup.py
|
||
|
|
index e5b0be2..5391427 100644
|
||
|
|
--- a/setup.py
|
||
|
|
+++ b/setup.py
|
||
|
|
@@ -21,9 +21,8 @@ setup(
|
||
|
|
'License :: OSI Approved :: BSD License',
|
||
|
|
'Operating System :: POSIX :: Linux',
|
||
|
|
'Programming Language :: Python',
|
||
|
|
- 'Programming Language :: Python :: 2.7',
|
||
|
|
- 'Programming Language :: Python :: 3.3',
|
||
|
|
- 'Programming Language :: Python :: 3.4',
|
||
|
|
- 'Programming Language :: Python :: 3.5',
|
||
|
|
+ 'Programming Language :: Python :: 3.8',
|
||
|
|
+ 'Programming Language :: Python :: 3.9',
|
||
|
|
+ 'Programming Language :: Python :: 3.10',
|
||
|
|
]
|
||
|
|
)
|
||
|
|
diff --git a/test/test_parse.py b/test/test_parse.py
|
||
|
|
index 3c0bf86..cddd872 100644
|
||
|
|
--- a/test/test_parse.py
|
||
|
|
+++ b/test/test_parse.py
|
||
|
|
@@ -4,7 +4,6 @@ import io
|
||
|
|
import os
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
-import six
|
||
|
|
import toml
|
||
|
|
|
||
|
|
from anymarkup_core import *
|
||
|
|
@@ -23,8 +22,8 @@ class TestParse(object):
|
||
|
|
elif isinstance(struct, list):
|
||
|
|
for i in struct:
|
||
|
|
self.assert_unicode(i)
|
||
|
|
- elif isinstance(struct, (six.string_types, type(None), type(True), \
|
||
|
|
- six.integer_types, float, datetime)):
|
||
|
|
+ elif isinstance(struct, (str, type(None), type(True), \
|
||
|
|
+ int, float, datetime)):
|
||
|
|
pass
|
||
|
|
else:
|
||
|
|
raise AssertionError('Unexpected type {0} in parsed structure'.format(type(struct)))
|
||
|
|
diff --git a/test/test_serialize.py b/test/test_serialize.py
|
||
|
|
index 8191561..9ffbeab 100644
|
||
|
|
--- a/test/test_serialize.py
|
||
|
|
+++ b/test/test_serialize.py
|
||
|
|
@@ -3,7 +3,6 @@ import io
|
||
|
|
import os
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
-import six
|
||
|
|
|
||
|
|
from anymarkup_core import *
|
||
|
|
|
||
|
|
@@ -21,7 +20,7 @@ class TestSerialize(object):
|
||
|
|
fixtures = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||
|
|
|
||
|
|
def _read_decode(self, file):
|
||
|
|
- if isinstance(file, six.string_types):
|
||
|
|
+ if isinstance(file, str):
|
||
|
|
file = open(file, 'rb')
|
||
|
|
else:
|
||
|
|
file.seek(0)
|
||
|
|
--
|
||
|
|
2.38.0
|
||
|
|
|