Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1089803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:16:42+00:00 2026-05-16T23:16:42+00:00

I’m writing a class that interfaces to a MoinMoin wiki via xmlrpc (simplified code

  • 0

I’m writing a class that interfaces to a MoinMoin wiki via xmlrpc (simplified code follows):

class MoinMoin(object):
    token = None

    def __init__(self, url, username=None, password=None):
        self.wiki  = xmlrpclib.ServerProxy(url + '/?action=xmlrpc2')
        if username and password:
            self.token = self.wiki.getAuthToken(username, password)
    # some sample methods:
    def searchPages(self, regexp):
    def getPage(self, page):
    def putPage(self, page):

now each of my methods needs to call the relevant xmlrpc method alone if there isn’t authentication involved, or to wrap it in a multicall if there’s auth. Example:

def getPage(self, page):
    if not self.token:
        result = self.wiki.getPage(page)
    else:
        mc = xmlrpclib.MultiCall(self.wiki) # build an XML-RPC multicall
        mc.applyAuthToken(self.token)       # call 1
        mc.getPage(page)                    # call 2
        result = mc()[-1]                  # run both, keep result of the latter
    return result

is there any nicer way to do it other than repeating that stuff for each and every method?

Since I have to call arbitrary methods, wrap them with stuff, then call the identically named method on another class, select relevant results and give them back, I suspect the solution would involve meta-classes or similar esoteric (for me) stuff. I should probably look at xmlrpclib sources and see how it’s done, then maybe subclass their MultiCall to add my stuff…

But maybe I’m missing something easier. The best I’ve come out with is something like:

def _getMultiCall(self):
    mc = xmlrpclib.MultiCall(self.wiki)
    if self.token:
        mc.applyAuthToken(self.token)
    return mc
def fooMethod(self, x):
    mc = self._getMultiCall()
    mc.fooMethod(x)
    return mc()[-1]

but it still repeats the same three lines of code for each and every method I need to implement, just changing the called method name. Any better?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:16:42+00:00Added an answer on May 16, 2026 at 11:16 pm

    Python function are objects so they can be passed quite easily to other function.

    def HandleAuthAndReturnResult(self, method, arg):
        mc = xmlrpclib.MultiCall(self.wiki)
        if self.token:
            mc.applyAuthToken(self.token)
        method(mc, arg)
        return mc()[-1]
    def fooMethod(self, x):
        HandleAuthAndReturnResult(xmlrpclib.MultiCall.fooMethod, x)
    

    There may be other way but I think it should work. Of course, the arg part needs to be aligned with what is needed for the method but all your methods take one argument.

    Edit: I didn’t understand that MultiCall was a proxy object. Even if the real method call ultimately is the one in your ServerProxy, you should not pass this method object in case MultiCall ever overrides(define) it. In this case, you could use the getattribute method with the method name you want to call and then call the returned function object. Take care to handle the AttributeError exception.

    Methods would now look like:

    def HandleAuthAndReturnResult(self, methodName, arg):
        mc = xmlrpclib.MultiCall(self.wiki)
        if self.token:
            mc.applyAuthToken(self.token)
    
        try:
            methodToCall = getattr(mc, methodName)
        except AttributeError:
            return None
    
        methodToCall(arg)
        return mc()[-1]
    
    def fooMethod(self, x):
        HandleAuthAndReturnResult('fooMethod', x)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.