wikicomserver.py :  » Network » Python-Wikipedia-Robot-Framework » pywikipedia » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » Python Wikipedia Robot Framework 
Python Wikipedia Robot Framework » pywikipedia » wikicomserver.py
#!/usr/bin/python
# -*- coding: utf-8  -*-
"""
This library allows the use of the pywikipediabot directly from COM-aware applications.

Calling this class from Visual Basic:
    set wiki = CreateObject("Mediawiki.Wiki")
    set site = wiki.getSite("en")
    print site.loggedin()
    set page = wiki.getPage(site, "User:Yurik/sandbox1")
    txt = page.get()
    print txt
    res = page.put("new text 1", "testing bot")
"""
#
# (C) Yuri Astrakhan, 2006
#
# Distributed under the terms of the MIT license.
#
__version__ = '$Id: wikicomserver.py 5846 2008-08-24 20:53:27Z siebrand $'


#
#
#   IMPORTANT!!!   Make sure this points to the pywikipedia installation directory
#
#
pywikipediaDir = "c:\\Projects\\Personal\\wiki\\pywikipedia"


import sys, os
from win32com.server.util import wrap,unwrap
import win32com.client

# Although we are able to register our Parent object for debugging,
# our Child object is not registered, so this won't work. To get
# the debugging behavior for our wrapped objects, we must do it ourself.
debugging = 1
if debugging:
    from win32com.server.dispatcher import DefaultDebugDispatcher
    useDispatcher = DefaultDebugDispatcher
else:
    useDispatcher = None

currDir = os.getcwdu()
os.chdir(pywikipediaDir)
import wikipedia

class Wiki:
    _reg_clsid_ = "{AEA5AC14-ED3D-42E9-AACF-871ED9D95346}"
    _reg_desc_ = "Mediawiki Wiki"
    _reg_progid_ = "Mediawiki.Wiki"
    _public_methods_ = ['getSite', 'getPage']
    _public_attrs_ = ['objectVer', 'objectName', 'argv', 'path']
    _readonly_attrs_ = _public_attrs_

    def __init__(self):
        os.chdir(pywikipediaDir)
        self.objectVer = __version__
        self.objectName = "Wiki"
        self.argv = sys.argv
        self.path = os.path.realpath( self.argv[0] )

    def getSite(self, code = None, fam = None, user = None):
        os.chdir(pywikipediaDir)
        site = wikipedia.getSite(code, fam, user)
        site.objectVer = wikipedia.__version__
        site.objectName = "WikiSite"
        site._public_methods_ = ['__cmp__', '__repr__', 'allmessages_address', 'allpages', 'allpages_address', 'ancientpages', 'ancientpages_address', 'broken_redirects_address', 'categories', 'categories_address', 'category_namespace', 'category_namespaces', 'category_on_one_line', 'checkCharset', 'cookies', 'deadendpages', 'deadendpages_address', 'delete_address', 'double_redirects_address', 'edit_address', 'encoding', 'encodings', 'export_address', 'family', 'forceLogin', 'getSite', 'getToken', 'getUrl', 'get_address', 'hostname', 'image_namespace', 'interwiki_putfirst', 'interwiki_putfirst_doubled', 'language', 'languages', 'linkto', 'loggedin', 'login_address', 'lonelypages', 'lonelypages_address', 'longpages', 'longpages_address', 'namespace', 'namespaces', 'newpages', 'newpages_address', 'purge_address', 'putToken', 'put_address', 'redirect', 'redirectRegex', 'references_address', 'shortpages', 'shortpages_address', 'sitename', 'template_namespace', 'uncategorizedcategories', 'uncategorizedcategories_address', 'uncategorizedpages', 'uncategorizedpages_address', 'unusedcategories', 'unusedcategories_address', 'upload_address', 'version', 'watchlist_address']
        site._public_attrs_ = ['objectVer', 'objectName']
        site._readonly_attrs_ = site._public_attrs_
        return wrap(site, useDispatcher=useDispatcher)

    def getPage(self, site, title):
        os.chdir(pywikipediaDir)
        siteObj = unwrap(site)
        page = WikiPage(siteObj, title)
        return wrap(page)

    def __del__(self):
        os.chdir(currDir)
        print "ChDir to original ", currDir

class WikiPage(wikipedia.Page):
    _reg_clsid_ = "{318CC152-D2A9-4C11-BA01-78B9B91DBDDE}"
    _reg_desc_ = "Mediawiki Wiki Page"
    _reg_progid_ = "Mediawiki.WikiPage"
    _public_methods_ = ['__cmp__', '__repr__', '__str__', 'aslink', 'autoFormat', 'canBeEdited', 'categories', 'contributingUsers', 'delete', 'encoding', 'exists', 'get', 'getEditPage', 'getRedirectTarget', 'getReferences', 'getVersionHistory', 'getVersionHistoryTable', 'imagelinks', 'interwiki', 'isAutoTitle', 'isCategory', 'isDisambig', 'isEmpty', 'isImage', 'isRedirectPage', 'isTalkPage', 'linkedPages', 'namespace', 'permalink', 'put', 'putPage', 'section', 'sectionFreeTitle', 'site', 'toggleTalkPage', 'templates', 'title', 'titleWithoutNamespace', 'urlname']
    _public_attrs_ = ['objectVer', 'objectName']
    _readonly_attrs_ = _public_attrs_

    def __init__(self, site, title):
        wikipedia.Page.__init__(self, site, title)
        self.objectVer = __version__
        self.objectName = "WikiPage"

if __name__=='__main__':
    import win32com.server.register
    try:
        win32com.server.register.UseCommandLine(Wiki)
    finally:
        wikipedia.stopme()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.