view MoinMoin/script/xmlrpc/ @ 6133:a6283e189869 default tip

fixup: remove nonexisting passlib.utils._blowfish this was removed by the passlib 1.7.1 upgrade.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 01 Jun 2017 18:10:19 +0200
parents afc6264a134f
line wrap: on
line source

# -*- coding: iso-8859-1 -*-
    MoinMoin - page contents writer

    @copyright: 2007 MoinMoin:JohannesBerg
    @license: GNU GPL, see COPYING for details.

import xmlrpclib
import sys

from MoinMoin.script import MoinScript

class PluginScript(MoinScript):
This tool allows you to edit a page with xmlrpc. It is more of a commented
example than an actual script.

Detailed Instructions:
General syntax: moin xmlrpc write <targeturl> <username> <password> <pagename>

    To edit the page 'FrontPage' on '' using the username
    'JohnSmith' and the password 'MyPass', changing the page contents
    to 'This will be the new contents of the page!' use:
    moin xmlrpc write JohnSmith MyPass FrontPage
    This will be the new contents of the page!

Note: we automatically append ?action=xmlrpc2 to the target url given.


    def __init__(self, argv, def_values):
        MoinScript.__init__(self, argv, def_values)
        self.argv = argv

    # script entrypoint
    def mainloop(self):
        # grab parameters
        url = self.argv[0] + '?action=xmlrpc2'
        user = self.argv[1]
        passwd = self.argv[2]
        pagename = self.argv[3]

        # get auth token from server giving username/password
        s = xmlrpclib.ServerProxy(url)
        token = s.getAuthToken(user, passwd)

        if not token:
            print 'Invalid username/password'

        # Verify that the token is valid by using it
        # and checking that the result is 'SUCCESS'.
        # The token should be valid for 15 minutes.
        assert s.applyAuthToken(token) == 'SUCCESS'

            # read new page contents
            content =

            # build a multicall object that
            mcall = xmlrpclib.MultiCall(s)
            # first applies the token and
            # then edits the page
            mcall.putPage(pagename, content)

            # now execute the multicall
            results = mcall()

            # everything should have worked
            # instead of the asserts you can have anything else
            # but you should definitely access all the results
            # once so that faults are checked and raised
            assert results[0] == 'SUCCESS'
            assert results[1] is True

            # be nice to the server and clean up the token
            # regardless of what happened
            assert s.deleteAuthToken(token) == 'SUCCESS'