3
3
"""This python module aims to manage
4
4
`DokuWiki <https://www.dokuwiki.org/dokuwiki>`_ wikis by using the
5
5
provided `XML-RPC API <https://www.dokuwiki.org/devel:xmlrpc>`_. It is
6
- compatible with python2.7 and python3+.
6
+ compatible with python3+.
7
7
8
8
Installation
9
9
------------
15
15
Otherwise sources are in `github <https://github.com/fmenabe/python-dokuwiki>`_
16
16
"""
17
17
18
- import re
19
- import sys
20
18
import base64
19
+ import re
21
20
import weakref
22
- from xml .parsers .expat import ExpatError
23
-
24
- PY_VERSION = sys .version_info [0 ]
25
- if PY_VERSION == 3 :
26
- from xmlrpc .client import ServerProxy , Binary , Fault , Transport , SafeTransport , ProtocolError
27
- from urllib .parse import quote
28
- else :
29
- from xmlrpclib import ServerProxy , Binary , Fault , Transport , SafeTransport , ProtocolError
30
- from urllib import quote
31
-
32
21
from datetime import datetime , timedelta
22
+ from urllib .parse import quote
23
+ from xml .parsers .expat import ExpatError
24
+ from xmlrpc .client import ServerProxy , Binary , Fault , Transport , SafeTransport , ProtocolError
33
25
34
26
ERR = 'XML or text declaration not at start of entity: line 2, column 0'
35
27
36
28
_URL_RE = re .compile (r'(?P<proto>https?)://(?P<host>[^/]*)(?P<uri>/.*)?' )
37
29
38
30
def date (date ):
39
- """DokuWiki returns dates of `xmlrpclib`/` xmlrpc.client` ``DateTime``
31
+ """DokuWiki returns dates of `xmlrpc.client` ``DateTime``
40
32
type and the format changes between DokuWiki versions ... This function
41
33
convert *date* to a `datetime` object.
42
34
"""
@@ -49,10 +41,7 @@ def utc2local(date):
49
41
"""DokuWiki returns date with a +0000 timezone. This function convert *date*
50
42
to the local time.
51
43
"""
52
- date_offset = (datetime .now () - datetime .utcnow ())
53
- # Python < 2.7 don't have the 'total_seconds' method so calculate it by hand!
54
- date_offset = (date_offset .microseconds +
55
- (date_offset .seconds + date_offset .days * 24 * 3600 ) * 1e6 ) / 1e6
44
+ date_offset = (datetime .now () - datetime .utcnow ()).total_seconds ()
56
45
date_offset = int (round (date_offset / 60 / 60 ))
57
46
return date + timedelta (hours = date_offset )
58
47
@@ -88,38 +77,13 @@ def parse_response(self, response):
88
77
finally :
89
78
return _TransportClass_ .parse_response (self , response )
90
79
91
- class CookiesTransport2 (_TransportClass_ ):
92
- """A Python2 xmlrpclib.Transport subclass that retains cookies."""
93
- def __init__ (self ):
94
- _TransportClass_ .__init__ (self )
95
- self ._cookies = dict ()
96
-
97
- def send_request (self , connection , handler , request_body ):
98
- _TransportClass_ .send_request (self , connection , handler , request_body )
99
- # set cookie below handler
100
- if self ._cookies :
101
- cookies = map (lambda x : x [0 ] + '=' + x [1 ], self ._cookies .items ())
102
- connection .putheader ("Cookie" , "; " .join (cookies ))
103
-
104
- def parse_response (self , response ):
105
- """parse and store cookie"""
106
- try :
107
- for header in response .getheader ("set-cookie" ).split (", " ):
108
- # filter 'expire' information
109
- if not header .startswith ("D" ):
110
- continue
111
- cookie = header .split (";" , 1 )[0 ]
112
- cookieKey , cookieValue = cookie .split ("=" , 1 )
113
- self ._cookies [cookieKey ] = cookieValue
114
- finally :
115
- return _TransportClass_ .parse_response (self , response )
80
+ return CookiesTransport ()
116
81
117
- return CookiesTransport2 () if PY_VERSION == 2 else CookiesTransport ()
118
82
119
- class DokuWiki ( object ) :
83
+ class DokuWiki :
120
84
"""Initialize a connection to a DokuWiki wiki. ``url``, ``user`` and
121
85
``password`` are respectively the URL, the login and the password for
122
- connecting to the wiki. ``kwargs`` are `xmlrpclib`/` xmlrpc.client`
86
+ connecting to the wiki. ``kwargs`` are `xmlrpc.client`
123
87
**ServerProxy** parameters.
124
88
125
89
The exception `DokuWikiError` is raised if the authentication
@@ -256,7 +220,7 @@ def del_acl(self, scope, user):
256
220
return self .send ('plugin.acl.delAcl' , scope , user )
257
221
258
222
259
- class _Pages ( object ) :
223
+ class _Pages :
260
224
"""This object regroup methods for managing pages of a DokuWiki. This object
261
225
is accessible from the ``pages`` property of an `DokuWiki` instance::
262
226
@@ -383,7 +347,7 @@ def backlinks(self, page):
383
347
return self ._dokuwiki .send ('wiki.getBackLinks' , page )
384
348
385
349
386
- class _Medias ( object ) :
350
+ class _Medias :
387
351
"""This object regroup methods for managing medias of a DokuWiki. This
388
352
object is accessible from the ``medias`` property of an `DokuWiki`
389
353
instance::
@@ -464,7 +428,7 @@ def delete(self, media):
464
428
return self ._dokuwiki .send ('wiki.deleteAttachment' , media )
465
429
466
430
467
- class _Structs ( object ) :
431
+ class _Structs :
468
432
def __init__ (self , dokuwiki ):
469
433
"""Get the structured data of a given page."""
470
434
self ._dokuwiki = dokuwiki
@@ -487,7 +451,7 @@ def get_aggregation_data(self, schemas, columns, data_filter=[], sort=''):
487
451
'plugin.struct.getAggregationData' , schemas , columns , data_filter , sort )
488
452
489
453
490
- class Dataentry ( object ) :
454
+ class Dataentry :
491
455
"""Object that manage `data entries <https://www.dokuwiki.org/plugin:data>`_."""
492
456
493
457
@staticmethod
0 commit comments