Skip to content

Fix two bugs encountered #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions dokuwiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from xmlrpclib import ServerProxy, Binary, Fault
from urllib import urlencode

from base64 import b64decode, b64encode

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

def utc2local(date):
Expand Down Expand Up @@ -97,7 +99,7 @@ def __init__(self, dokuwiki):
self._dokuwiki = dokuwiki

def list(self, namespace='/', **options):
return self._dokuwiki.send('dokuwiki.getPagelist', namespace, **options)
return self._dokuwiki.send('dokuwiki.getPagelist', namespace, options)

def changes(self, timestamp):
return self._dokuwiki.send('wiki.getRecentChanges', timestamp)
Expand All @@ -112,12 +114,15 @@ def info(self, pagename, version=''):
return (self._dokuwiki.send('wiki.getPageInfoVersion', pagename, version)
if version else self._dokuwiki.send('wiki.getPageInfo', pagename))

def get(self, pagename, version=''):
return (self._dokuwiki.send('wiki.getPageVersion', pagename, version))
def get(self, pagename, version=None):
if version is None:
return self._dokuwiki.send('wiki.getPage', pagename)

return self._dokuwiki.send('wiki.getPageVersion', pagename, version)

def append(self, pagename, content, **options):
return self._dokuwiki.send(
'dokuwiki.appendPage', pagename, content, **options)
'dokuwiki.appendPage', pagename, content, options)

def html(self, pagename, version=''):
return (self._dokuwiki.send('wiki.getPageHTMLVersion', pagename, version)
Expand All @@ -126,7 +131,7 @@ def html(self, pagename, version=''):
def set(self, pagename, content, **options):
try:
return self._dokuwiki.send(
'wiki.putPage', pagename, content, **options)
'wiki.putPage', pagename, content, options)
except ExpatError as err:
# Sometime the first line of the XML response is blank which raise
# the 'ExpatError' exception although the change has been done. This
Expand Down Expand Up @@ -167,10 +172,15 @@ def changes(self, timestamp):
return self._dokuwiki.send('wiki.getRecentMediaChanges', timestamp)

def list(self, namespace='/', **options):
return self._dokuwiki.send('wiki.getAttachments', namespace, **options)
return self._dokuwiki.send('wiki.getAttachments', namespace, options)

def get(self, media, dirpath, filename='', overwrite=False):
def get(self, media, dirpath=None, filename='', overwrite=False):
import os
data = self._dokuwiki.send('wiki.getAttachment', media)
data = b64decode(data)
if dirpath is None:
return data

if not filename:
filename = media.replace('/', ':').split(':')[-1]
if not os.path.exists(dirpath):
Expand All @@ -179,7 +189,7 @@ def get(self, media, dirpath, filename='', overwrite=False):
if os.path.exists(filepath) and not overwrite:
raise FileExistsError("[Errno 17] File exists: '%s'" % filepath)
with open(filepath, 'wb') as fhandler:
fhandler.write(self._dokuwiki.send('wiki.getAttachment', media).data)
fhandler.write(data)

def info(self, media):
return self._dokuwiki.send('wiki.getAttachmentInfo', media)
Expand All @@ -189,6 +199,10 @@ def add(self, media, filepath, overwrite=True):
self._dokuwiki.send('wiki.putAttachment',
media, Binary(fhandler.read()), ow=overwrite)

def set(self, media, _bytes, overwrite=True):
self._dokuwiki.send('wiki.putAttachment', media,
b64encode(_bytes), ow=overwrite)

def delete(self, media):
return self._dokuwiki.send('wiki.deleteAttachment', media)

Expand Down