示例#1
0
def search_and_skin(sourcepath, prefix):

    # local variables for <exec/>
    locals = {"shavianise": shavianise.shavianise}

    for d in os.walk(sourcepath):
        for f in d[2]:
            if ".." in f:
                print "Ignoring ", f
                continue

            target = (prefix + "/" + f).replace(".ss.xml", ".html").replace("_", "/").replace("//", "_")
            if not f.endswith(".ss.xml"):
                f = d[0] + "/" + f
                open(target, "wb").write(open(f, "rb").read())
                continue

            dom1 = parse(d[0] + "/" + f)
            content = ""
            title = dom1.documentElement.getAttribute("title")
            crumb = dom1.documentElement.getAttribute("crumb")
            if crumb == None:
                crumb = title
            crumb = [crumb]
            for c in dom1.documentElement.childNodes:
                if c.nodeType == c.TEXT_NODE:
                    continue
                if c.nodeName == "text":
                    translate = c.getAttribute("only")
                    i = inner_html(c, translate, locals)
                    t = title
                    alphabet = c.getAttribute("a")
                    if not translate and alphabet == "shaw":
                        t = shavianise.shavianise(t)
                    if c.getAttribute("notitle"):
                        content += '<div style="clear:all" lang="en-%s">\n%s\n</div>' % (alphabet, i[0])
                        if translate:
                            content += '<div style="clear:all" lang="en-shaw">\n%s\n</div>' % (i[1])
                    else:
                        content += '<div lang="en-%s">\n<h1>%s</h1>\n%s\n</div>' % (alphabet, t, i[0])
                        if translate:
                            content += '<div lang="en-shaw">\n<h1>%s</h1>\n%s\n</div>' % (
                                shavianise.shavianise(t),
                                i[1],
                            )
                elif c.nodeName == "crumb":
                    crumb.insert(0, inner_html(c, False, locals)[0])

            skin(content, title=title, target=target, crumb=crumb)
            dom1.unlink()
示例#2
0
def inner_html(e, translate=False, locals={}):
    r = ""
    t = ""
    for c in e.childNodes:
        if c.nodeType == c.TEXT_NODE:
            r += c.data
            t += shavianise.shavianise(c.data)
        elif c.nodeType == c.ELEMENT_NODE and c.nodeName == "e":
            shaw = c.getAttribute("shaw")
            latn = c.getAttribute("latn")
            if not shaw:
                shaw = latn
            elif shaw[0] <= "z":
                shaw = shavianise.unascii(shaw)
            r += latn
            t += shaw
        elif c.nodeType == c.ELEMENT_NODE and c.nodeName == "just":
            alphabet = c.getAttribute("a")
            if alphabet == "shaw":
                t += inner_html(c, translate, locals)[1]
            elif alphabet == "latn":
                r += inner_html(c, translate, locals)[0]
        elif c.nodeType == c.ELEMENT_NODE and c.nodeName == "exec":
            saved = sys.stdout
            sys.stdout = StringIO.StringIO()
            exec (inner_html(c, 0, locals)[0], locals)
            b = sys.stdout.getvalue()
            sys.stdout.close()
            sys.stdout = saved

            r += b
            t += ""

        elif c.nodeType == c.ELEMENT_NODE:
            a = ""
            for attr in c._attrs.keys():
                a += ' %s="%s"' % (attr, c._attrs[attr].value)
            inner = inner_html(c, translate, locals)

            if inner:
                r += "<%s%s>%s</%s>" % (c.nodeName, a, inner[0], c.nodeName)
                t += "<%s%s>%s</%s>" % (c.nodeName, a, inner[1], c.nodeName)
            else:
                r += "<%s%s/>" % (c.nodeName, a)
                t += "<%s%s/>" % (c.nodeName, a)
    return (r, t)
示例#3
0
def inner_html(e, translate=False, locals={}):
    r = ''
    t = ''
    for c in e.childNodes:
        if c.nodeType == c.TEXT_NODE:
            r += c.data
            t += shavianise.shavianise(c.data)
        elif c.nodeType == c.ELEMENT_NODE and c.nodeName=='e':
            shaw = c.getAttribute('shaw')
            latn = c.getAttribute('latn')
            if not shaw:
                shaw = latn
            elif shaw[0]<='z':
                shaw = shavianise.unascii(shaw)
            r += latn
            t += shaw
        elif c.nodeType == c.ELEMENT_NODE and c.nodeName=='just':
            alphabet = c.getAttribute('a')
            if alphabet == 'shaw':
                t += inner_html(c, translate, locals)[1]
            elif alphabet == 'latn':
                r += inner_html(c, translate, locals)[0]
        elif c.nodeType == c.ELEMENT_NODE and c.nodeName=='exec':
            saved = sys.stdout
            sys.stdout = StringIO.StringIO()
            exec(inner_html(c, 0, locals)[0], locals)
            b = sys.stdout.getvalue()
            sys.stdout.close()
            sys.stdout = saved

            r += b
            t += ''

        elif c.nodeType == c.ELEMENT_NODE:
            a = ''
            for attr in c._attrs.keys():
                a += ' %s="%s"' % (attr, c._attrs[attr].value)
            inner = inner_html(c, translate, locals)

            if inner:
                r += '<%s%s>%s</%s>' % (c.nodeName, a, inner[0], c.nodeName)
                t += '<%s%s>%s</%s>' % (c.nodeName, a, inner[1], c.nodeName)
            else:
                r += '<%s%s/>' % (c.nodeName, a)
                t += '<%s%s/>' % (c.nodeName, a)
    return (r, t)
示例#4
0
def search_and_skin(sourcepath, prefix):

    # local variables for <exec/>
    locals = {'shavianise': shavianise.shavianise}

    for d in os.walk(sourcepath):
        for f in d[2]:
            if '..' in f:
                print 'Ignoring ',f
                continue

            target = (prefix+'/'+f).replace('.ss.xml', '.html').replace('_','/').replace('//','_')
            if not f.endswith('.ss.xml'):
                f = d[0]+'/'+f
                open(target, 'wb').write(open(f,'rb').read())
                continue

            dom1 = parse(d[0]+'/'+f)
            content = ''
            title = dom1.documentElement.getAttribute('title')
            crumb = dom1.documentElement.getAttribute('crumb')
            if crumb==None:
                crumb = title
            crumb = [crumb]
            for c in dom1.documentElement.childNodes:
                    if c.nodeType == c.TEXT_NODE: continue
                    if c.nodeName == 'text':
                        translate = c.getAttribute('only')
                        i = inner_html(c, translate, locals)
                        t = title
                        alphabet = c.getAttribute('a')
                        if not translate and alphabet=='shaw':
                            t = shavianise.shavianise(t)
                        if c.getAttribute('notitle'):
                            content += '<div style="clear:all" lang="en-%s">\n%s\n</div>' % (alphabet, i[0])
                            if translate:
                                content += '<div style="clear:all" lang="en-shaw">\n%s\n</div>' % (i[1])
                        else:
                            content += '<div lang="en-%s">\n<h1>%s</h1>\n%s\n</div>' % (alphabet, t, i[0])
                            if translate:
                                content += '<div lang="en-shaw">\n<h1>%s</h1>\n%s\n</div>' % (shavianise.shavianise(t), i[1])
                    elif c.nodeName == 'crumb':
                        crumb.insert(0, inner_html(c, False, locals)[0])

            skin(content, title=title, target=target, crumb=crumb)
            dom1.unlink()