Skip to content

Commit

Permalink
feat: drop six usage
Browse files Browse the repository at this point in the history
  • Loading branch information
gforcada committed Apr 23, 2023
1 parent d3b1b0b commit da5bcb7
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 32 deletions.
6 changes: 1 addition & 5 deletions plone/rfc822/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@
from zope.schema import getFieldsInOrder

import logging
import six


logger = logging.getLogger("plone.rfc822")


def safe_native_string(value, encoding="utf8"):
"""Try to convert value into a native string"""
if six.PY2:
if isinstance(value, str):
return value.encode(encoding)
elif isinstance(value, bytes):
if isinstance(value, bytes):
return value.decode(encoding)
if not isinstance(value, str):
raise ValueError("Cannot convert %r into a native string" % value)
Expand Down
18 changes: 4 additions & 14 deletions plone/rfc822/fields.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ This interface is implemented by a the following class::
>>> from decimal import Decimal
>>> from zope.interface import implementer
>>> import datetime
>>> import six
>>> @implementer(ITestContent)
... class TestContent(object):
... _text = u"text\xd8"
Expand All @@ -80,7 +79,7 @@ This interface is implemented by a the following class::
... _id = u'some.id'
... _dottedName = 'dotted.name'
... _bool = True
... _int = long(-10) if six.PY2 else -10
... _int = -10
... _float = 0.3
... _decimal = Decimal("5.0")
... _choice1 = u"two"
Expand Down Expand Up @@ -295,10 +294,7 @@ An URI is in Python 2 based on unicode text, in Python 3 on bytes.
'http://plone.org'
>>> marshaler.getContentType() is None
True
>>> if six.PY2:
... expected = None # its IBytes based
... else:
... expected = 'utf-8'
>>> expected = 'utf-8'
>>> marshaler.getCharset('utf-8') == expected
True
>>> marshaler.ascii
Expand All @@ -316,10 +312,7 @@ Id
'some.id'
>>> marshaler.getContentType() is None
True
>>> if six.PY2:
... expected = None # its IBytes based
... else:
... expected = 'utf-8'
>>> expected = 'utf-8'
>>> marshaler.getCharset('utf-8') == expected
True
>>> marshaler.ascii
Expand All @@ -337,10 +330,7 @@ DottedName
'dotted.name'
>>> marshaler.getContentType() is None
True
>>> if six.PY2:
... expected = None # its IBytes based
... else:
... expected = 'utf-8'
>>> expected = 'utf-8'
>>> marshaler.getCharset('utf-8') == expected
True
>>> marshaler.ascii
Expand Down
3 changes: 1 addition & 2 deletions plone/rfc822/message.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ annotations, which we will use later in this test::

::

>>> from six import StringIO
>>> from io import StringIO
>>> from zope.configuration import xmlconfig
>>> xmlconfig.xmlconfig(StringIO(configuration))

Expand Down Expand Up @@ -621,7 +621,6 @@ Technical both is fine.

::

>>> import six
>>> content.description = "Test content\nwith newline difference"
>>> msg = constructMessageFromSchema(content, ITestContent)
>>> effective_output = msg.as_string()
Expand Down
11 changes: 0 additions & 11 deletions plone/rfc822/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from plone.testing.zca import UNIT_TESTING

import doctest
import re
import six
import unittest


Expand All @@ -22,14 +20,6 @@
)


class Py23DocChecker(doctest.OutputChecker):
def check_output(self, want, got, optionflags):
if six.PY2:
got = re.sub("u'(.*?)'", "'\\1'", got)
got = re.sub("b'(.*?)'", "'\\1'", got)
return doctest.OutputChecker.check_output(self, want, got, optionflags)


class TestUtils(unittest.TestCase):
def test_safe_native_string(self):
self.assertIsInstance(safe_native_string(b""), str)
Expand All @@ -45,7 +35,6 @@ def test_suite():
doctest.DocFileSuite(
docfile,
optionflags=optionflags,
checker=Py23DocChecker(),
),
layer=UNIT_TESTING,
)
Expand Down

0 comments on commit da5bcb7

Please sign in to comment.