Skip to content

Commit a1f56b6

Browse files
committed
Correct a bug when retrieving/uploading medias.
base64 encoding/decoding was manually done instead of using xmlrpclib/xmlrpc.client Binary object. For compatibilty, b64encode/b64decode parameters have beed added to the respectives methods.
1 parent fc55e58 commit a1f56b6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

dokuwiki.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import re
1919
import sys
20+
import base64
2021
import weakref
2122
from xml.parsers.expat import ExpatError
2223
if sys.version_info[0] == 3:
@@ -27,7 +28,6 @@
2728
from urllib import urlencode
2829

2930
from datetime import datetime, timedelta
30-
from base64 import b64decode, b64encode
3131

3232
ERR = 'XML or text declaration not at start of entity: line 2, column 0'
3333

@@ -325,7 +325,7 @@ def changes(self, timestamp):
325325
"""
326326
return self._dokuwiki.send('wiki.getRecentMediaChanges', timestamp)
327327

328-
def get(self, media, dirpath=None, filename=None, overwrite=False):
328+
def get(self, media, dirpath=None, filename=None, overwrite=False, b64decode=False):
329329
"""Returns the binary data of *media* or save it to a file. If *dirpath*
330330
is not set the binary data is returned, otherwise the data is saved
331331
to a file. By default, the filename is the name of the media but it can
@@ -334,7 +334,7 @@ def get(self, media, dirpath=None, filename=None, overwrite=False):
334334
"""
335335
import os
336336
data = self._dokuwiki.send('wiki.getAttachment', media)
337-
data = b64decode(data)
337+
data = base64.b64decode(data) if b64decode else data.data
338338
if dirpath is None:
339339
return data
340340

@@ -361,12 +361,12 @@ def add(self, media, filepath, overwrite=True):
361361
self._dokuwiki.send('wiki.putAttachment', media,
362362
Binary(fhandler.read()), ow=overwrite)
363363

364-
def set(self, media, _bytes, overwrite=True):
364+
def set(self, media, _bytes, overwrite=True, b64encode=False):
365365
"""Set *media* from *_bytes*. *overwrite* parameter specify if the media
366366
must be overwrite if it exists remotely.
367367
"""
368-
self._dokuwiki.send('wiki.putAttachment', media,
369-
b64encode(_bytes), ow=overwrite)
368+
data = base64.b64encode(_bytes) if b64encode else Binary(_bytes)
369+
self._dokuwiki.send('wiki.putAttachment', media, data, ow=overwrite)
370370

371371
def delete(self, media):
372372
"""Delete *media*."""

0 commit comments

Comments
 (0)