From 1587504ffae762377381e42c05ecde3f267ae3cc Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Wed, 1 Nov 2023 15:53:39 +0100 Subject: [PATCH] python2 removal --- README.rst | 2 +- dokuwiki.py | 64 ++++++++++++----------------------------------------- setup.py | 1 - 3 files changed, 15 insertions(+), 52 deletions(-) diff --git a/README.rst b/README.rst index 077947f..440ad1a 100644 --- a/README.rst +++ b/README.rst @@ -24,7 +24,7 @@ python-dokuwiki This python module aims to manage `DokuWiki `_ wikis by using the provided `XML-RPC API `_. -This module is compatible with python2.7 and python3+. +This module is compatible with python3+. API is described `here `_. diff --git a/dokuwiki.py b/dokuwiki.py index ffea216..f021564 100644 --- a/dokuwiki.py +++ b/dokuwiki.py @@ -3,7 +3,7 @@ """This python module aims to manage `DokuWiki `_ wikis by using the provided `XML-RPC API `_. It is -compatible with python2.7 and python3+. +compatible with python3+. Installation ------------ @@ -15,28 +15,20 @@ Otherwise sources are in `github `_ """ -import re -import sys import base64 +import re import weakref -from xml.parsers.expat import ExpatError - -PY_VERSION = sys.version_info[0] -if PY_VERSION == 3: - from xmlrpc.client import ServerProxy, Binary, Fault, Transport, SafeTransport, ProtocolError - from urllib.parse import quote -else: - from xmlrpclib import ServerProxy, Binary, Fault, Transport, SafeTransport, ProtocolError - from urllib import quote - from datetime import datetime, timedelta +from urllib.parse import quote +from xml.parsers.expat import ExpatError +from xmlrpc.client import ServerProxy, Binary, Fault, Transport, SafeTransport, ProtocolError ERR = 'XML or text declaration not at start of entity: line 2, column 0' _URL_RE = re.compile(r'(?Phttps?)://(?P[^/]*)(?P/.*)?') def date(date): - """DokuWiki returns dates of `xmlrpclib`/`xmlrpc.client` ``DateTime`` + """DokuWiki returns dates of `xmlrpc.client` ``DateTime`` type and the format changes between DokuWiki versions ... This function convert *date* to a `datetime` object. """ @@ -49,10 +41,7 @@ def utc2local(date): """DokuWiki returns date with a +0000 timezone. This function convert *date* to the local time. """ - date_offset = (datetime.now() - datetime.utcnow()) - # Python < 2.7 don't have the 'total_seconds' method so calculate it by hand! - date_offset = (date_offset.microseconds + - (date_offset.seconds + date_offset.days * 24 * 3600) * 1e6) / 1e6 + date_offset = (datetime.now() - datetime.utcnow()).total_seconds() date_offset = int(round(date_offset / 60 / 60)) return date + timedelta(hours=date_offset) @@ -88,38 +77,13 @@ def parse_response(self, response): finally: return _TransportClass_.parse_response(self, response) - class CookiesTransport2(_TransportClass_): - """A Python2 xmlrpclib.Transport subclass that retains cookies.""" - def __init__(self): - _TransportClass_.__init__(self) - self._cookies = dict() - - def send_request(self, connection, handler, request_body): - _TransportClass_.send_request(self, connection, handler, request_body) - # set cookie below handler - if self._cookies: - cookies = map(lambda x: x[0] + '=' + x[1], self._cookies.items()) - connection.putheader("Cookie", "; ".join(cookies)) - - def parse_response(self, response): - """parse and store cookie""" - try: - for header in response.getheader("set-cookie").split(", "): - # filter 'expire' information - if not header.startswith("D"): - continue - cookie = header.split(";", 1)[0] - cookieKey, cookieValue = cookie.split("=", 1) - self._cookies[cookieKey] = cookieValue - finally: - return _TransportClass_.parse_response(self, response) + return CookiesTransport() - return CookiesTransport2() if PY_VERSION == 2 else CookiesTransport() -class DokuWiki(object): +class DokuWiki: """Initialize a connection to a DokuWiki wiki. ``url``, ``user`` and ``password`` are respectively the URL, the login and the password for - connecting to the wiki. ``kwargs`` are `xmlrpclib`/`xmlrpc.client` + connecting to the wiki. ``kwargs`` are `xmlrpc.client` **ServerProxy** parameters. The exception `DokuWikiError` is raised if the authentication @@ -256,7 +220,7 @@ def del_acl(self, scope, user): return self.send('plugin.acl.delAcl', scope, user) -class _Pages(object): +class _Pages: """This object regroup methods for managing pages of a DokuWiki. This object is accessible from the ``pages`` property of an `DokuWiki` instance:: @@ -383,7 +347,7 @@ def backlinks(self, page): return self._dokuwiki.send('wiki.getBackLinks', page) -class _Medias(object): +class _Medias: """This object regroup methods for managing medias of a DokuWiki. This object is accessible from the ``medias`` property of an `DokuWiki` instance:: @@ -464,7 +428,7 @@ def delete(self, media): return self._dokuwiki.send('wiki.deleteAttachment', media) -class _Structs(object): +class _Structs: def __init__(self, dokuwiki): """Get the structured data of a given page.""" self._dokuwiki = dokuwiki @@ -487,7 +451,7 @@ def get_aggregation_data(self, schemas, columns, data_filter=[], sort=''): 'plugin.struct.getAggregationData', schemas, columns, data_filter, sort) -class Dataentry(object): +class Dataentry: """Object that manage `data entries `_.""" @staticmethod diff --git a/setup.py b/setup.py index 1a5a65b..2cb0b3d 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,6 @@ classifiers=[ 'Development Status :: 5 - Production/Stable', 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License',