Пример #1
0
def getXML(wikitext):
    db = DummyDB()
    r = parseString(title="test", raw=wikitext, wikidb=db)
    print "before preprocess"
    show(sys.stdout, r)
    preprocess(r)
    print "after preprocess"
    show(sys.stdout, r)
    dbw = DocBookWriter()
    dbw.dbwriteArticle(r)
    return dbw.asstring()
Пример #2
0
    def _servXML(self, args, query, dialect="mwxml"):
        if not len(args):
            self._doc(error="require articlename")
            return
        unknown = [k for k in query if k not in ("debug", "imageresolver")]
        if unknown:
            return self._doc(error="unknown option %r" % unknown)
        title = args.pop()
        base_url = "http://%s/" % ("/".join(args) or default_baseurl)
        debug = bool(query.setdefault("debug", [default_debug])[0])

        language = "en" # FIXME
        namespace="en.wikipedia.org" # FIXME

        print "_servXML", title, base_url, debug

        db = mwapidb.WikiDB(base_url)
        db.print_template = None # deactivate print template lookups
        tree = db.getParsedArticle(title, revision=None)

        if dialect == "mwxhtml":
            xhtmlwriter.preprocess(tree)
            dbw = xhtmlwriter.MWXHTMLWriter(imagesrcresolver=imagesrcresolver,
                                            debug=False)
        elif dialect == "mwxml":
            advtree.buildAdvancedTree(tree) # this should be optional
            dbw = xhtmlwriter.MWXMLWriter() # 1:1 XML from parse tree
        elif dialect == "dbxml":
            from mwlib import docbookwriter
            docbookwriter.preprocess(tree)
            dbw = docbookwriter.DocBookWriter(imagesrcresolver=imagesrcresolver,
                                            debug=debug) 
        else:
            raise Exception, "unkonwn export"


        dbw.writeBook(tree)
        if debug:
            dbw.writeparsetree(tree)

        response = dbw.asstring()
        
        self.send_response(200)
        self.send_header("Content-type", "text/xml")
        self.send_header("Content-length", str(len(response)))
        self.end_headers()
        self.wfile.write(response)
        
        # shut down the connection
        self.wfile.flush()