Skip to content

Commit 6b44014

Browse files
danigmtobixen
authored andcommitted
Drop python2 support
Python 2 went EOL on 1/1/2020 and we receive no more support from the Python Core Team after Python 2.7.18 even for known security issues. This removes the six package from dependencies.
1 parent db004b8 commit 6b44014

8 files changed

Lines changed: 31 additions & 96 deletions

File tree

caldav/davclient.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import re
55

66
import requests
7-
import six
87
from caldav.elements import cdav
98
from caldav.elements import dav
109
from caldav.elements import ical
@@ -22,10 +21,7 @@
2221
from caldav.requests import HTTPBearerAuth
2322
from lxml import etree
2423

25-
if six.PY3:
26-
from urllib.parse import unquote
27-
else:
28-
from urlparse import unquote
24+
from urllib.parse import unquote
2925

3026

3127
class DAVResponse:

caldav/elements/base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from caldav.lib.namespace import nsmap
44
from caldav.lib.python_utilities import to_unicode
55
from lxml import etree
6-
from six import PY3
76

87

98
class BaseElement(object):
@@ -30,9 +29,7 @@ def __str__(self):
3029
utf8 = etree.tostring(
3130
self.xmlelement(), encoding="utf-8", xml_declaration=True, pretty_print=True
3231
)
33-
if PY3:
34-
return str(utf8, "utf-8")
35-
return utf8
32+
return str(utf8, "utf-8")
3633

3734
def xmlelement(self):
3835
root = etree.Element(self.tag, nsmap=nsmap)

caldav/lib/python_utilities.py

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1-
from six import PY3
2-
from six import string_types
3-
4-
assert PY3 ## Still using python2? Write an issue on the github issue tracker, and I will consider to offer some limited python2-support for the 1.x-series of caldav - otherwise I will start cleaning away code for supporting python2 in the 1.1-release
5-
6-
7-
def isPython3():
8-
"""Deprecated. Use six.PY3"""
9-
return PY3
10-
11-
121
def to_wire(text):
132
if text is None:
143
return None
15-
if isinstance(text, string_types) and PY3:
4+
if isinstance(text, str):
165
text = bytes(text, "utf-8")
17-
elif not PY3:
18-
text = to_unicode(text).encode("utf-8")
196
text = text.replace(b"\n", b"\r\n")
207
text = text.replace(b"\r\r\n", b"\r\n")
218
return text
@@ -24,7 +11,7 @@ def to_wire(text):
2411
def to_local(text):
2512
if text is None:
2613
return None
27-
if not isinstance(text, string_types):
14+
if not isinstance(text, str):
2815
text = text.decode("utf-8")
2916
text = text.replace("\r\n", "\n")
3017
return text
@@ -35,28 +22,17 @@ def to_local(text):
3522

3623
def to_normal_str(text):
3724
"""
38-
A str object is a unicode on python3 and a byte string on python2.
39-
Make sure we return a normal string, no matter what version of
40-
python ...
25+
Make sure we return a normal string
4126
"""
4227
if text is None:
4328
return text
44-
if PY3 and not isinstance(text, str):
29+
if not isinstance(text, str):
4530
text = text.decode("utf-8")
46-
elif not PY3 and not isinstance(text, str):
47-
text = text.encode("utf-8")
4831
text = text.replace("\r\n", "\n")
4932
return text
5033

5134

5235
def to_unicode(text):
53-
if (
54-
text
55-
and isinstance(text, string_types)
56-
and not PY3
57-
and not isinstance(text, unicode)
58-
):
59-
return unicode(text, "utf-8")
60-
if PY3 and text and isinstance(text, bytes):
36+
if text and isinstance(text, bytes):
6137
return text.decode("utf-8")
6238
return text

caldav/lib/url.py

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,15 @@
22
# -*- encoding: utf-8 -*-
33
from caldav.lib.python_utilities import to_normal_str
44
from caldav.lib.python_utilities import to_unicode
5-
from six import PY3
6-
7-
if PY3:
8-
from urllib.parse import (
9-
ParseResult,
10-
SplitResult,
11-
urlparse,
12-
unquote,
13-
quote,
14-
urlunparse,
15-
)
16-
else:
17-
from urlparse import ParseResult, SplitResult
18-
from urlparse import urlparse, urlunparse
19-
from urllib import unquote, quote
20-
21-
22-
def uc2utf8(input):
23-
# argh! this feels wrong, but seems to be needed.
24-
if not PY3 and type(input) == unicode:
25-
return input.encode("utf-8")
26-
else:
27-
return input
5+
6+
from urllib.parse import (
7+
ParseResult,
8+
SplitResult,
9+
urlparse,
10+
unquote,
11+
quote,
12+
urlunparse,
13+
)
2814

2915

3016
class URL:
@@ -195,12 +181,12 @@ def join(self, path):
195181
raise ValueError("%s can't be joined with %s" % (self, path))
196182

197183
if path.path[0] == "/":
198-
ret_path = uc2utf8(path.path)
184+
ret_path = path.path
199185
else:
200186
sep = "/"
201187
if self.path.endswith("/"):
202188
sep = ""
203-
ret_path = "%s%s%s" % (self.path, sep, uc2utf8(path.path))
189+
ret_path = "%s%s%s" % (self.path, sep, path.path)
204190
return URL(
205191
ParseResult(
206192
self.scheme or path.scheme,

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
"vobject",
8484
"lxml",
8585
"requests",
86-
"six",
8786
"icalendar",
8887
"recurring-ical-events>=2.0.0",
8988
]

tests/proxy.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,11 @@
2828

2929
from caldav.lib.python_utilities import to_local
3030
from caldav.lib.python_utilities import to_wire
31-
from six import PY3
32-
33-
if PY3:
34-
from urllib import parse
35-
from urllib.parse import urlparse, urlunparse
36-
from http.server import BaseHTTPRequestHandler, HTTPServer
37-
from socketserver import ThreadingMixIn
38-
else:
39-
from urlparse import urlparse as parse
40-
from urlparse import urlparse, urlunparse
41-
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
42-
from SocketServer import ThreadingMixIn
31+
32+
from urllib import parse
33+
from urllib.parse import urlparse, urlunparse
34+
from http.server import BaseHTTPRequestHandler, HTTPServer
35+
from socketserver import ThreadingMixIn
4336

4437
__version__ = "0.3.1"
4538

tests/test_caldav.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
from caldav.objects import Principal
4242
from caldav.objects import Todo
4343
from requests.packages import urllib3
44-
from six import PY3
4544

4645
from . import compatibility_issues
4746
from .conf import caldav_servers
@@ -70,10 +69,7 @@
7069
import radicale.server
7170
import socket
7271

73-
if PY3:
74-
from urllib.parse import urlparse
75-
else:
76-
from urlparse import urlparse
72+
from urllib.parse import urlparse
7773

7874
log = logging.getLogger("caldav")
7975

tests/test_caldav_unit.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,10 @@
3535
from caldav.objects import Journal
3636
from caldav.objects import Principal
3737
from caldav.objects import Todo
38-
from six import PY3
3938

4039

41-
if PY3:
42-
from urllib.parse import urlparse
43-
from unittest import mock
44-
else:
45-
from urlparse import urlparse
46-
import mock
40+
from urllib.parse import urlparse
41+
from unittest import mock
4742

4843
## Some example icalendar data partly copied from test_caldav.py
4944
ev1 = """BEGIN:VCALENDAR
@@ -263,14 +258,11 @@ def testRequestNonAscii(self, mocked):
263258
assert response.status == 200
264259
assert response.tree is None
265260

266-
if PY3:
267-
response = client.put(
268-
"/foo/møøh/bar".encode("utf-8"),
269-
"bringebærsyltetøy 北京 пиво".encode("utf-8"),
270-
{},
271-
)
272-
else:
273-
response = client.put(u"/foo/møøh/bar", "bringebærsyltetøy 北京 пиво", {}) # fmt: skip
261+
response = client.put(
262+
"/foo/møøh/bar".encode("utf-8"),
263+
"bringebærsyltetøy 北京 пиво".encode("utf-8"),
264+
{},
265+
)
274266
assert response.status == 200
275267
assert response.tree is None
276268

0 commit comments

Comments
 (0)