Beispiel #1
0
 def __init__(self, replyTo, dispatcher, uri, doSkin):
     self._replyTo = replyTo
     self._dispatcher = dispatcher
     self._uri = uri
     self._doSkin = doSkin
     self._headTag = ET.Element('head')
     self._bodyTag = ET.Element('body')
Beispiel #2
0
    def handleGET(self,req):
        """
        Parse and dispatch a single GET request.
        Expects to receive a WebRequest object.
        """
        assert req.getRequestType() == "GET"

        self.landingPage.incrementQuickStat("Pages Served")
        
        uri = req.getURI()
        args = req.dictFromGET()
        
        callable,returnsResponse,autoSkin = self.uriToHandler.get(uri, [self.invalidURI,False,False])

        if callable != self.invalidURI:
            self.notify.info("%s - %s - %s - 200" % (req.getSourceAddress(), uri, args))
        
        if returnsResponse:
            result = apply(callable,(),args)
            if autoSkin:
                self._headTag = ET.Element('head')
                self._bodyTag = ET.Element('body')
                req.respond(self.landingPage.skin(result,uri, headTag=self._headTag, bodyTag=self._bodyTag))
                del self._bodyTag
                del self._headTag
            else:
                req.respond(result)
        else:
            args["replyTo"] = SkinningReplyTo(req, self, uri, autoSkin)
            apply(callable,(),args)
    def __init__(self, title):
        root = ET.Element('HTML')
        ET.ElementTree.__init__(self, root)

        head = ET.SubElement(root, 'HEAD')
        titleTag = ET.SubElement(head, 'TITLE')
        titleTag.text = title

        body = ET.SubElement(root, 'BODY')
Beispiel #4
0
def addBodyHeaderAndContent(bodyTag, titleString, menuTags):
    SE = ET.SubElement
    bodyTag.append(ET.Comment('HEADER'))
    header = SE(bodyTag, 'div', id='header')
    h2 = SE(header, 'h2')
    h2.text = titleString
    navContainer = SE(header, 'div', id='navcontainer')
    navList = SE(navContainer, 'ul', id='navlist')
    for menuTag in menuTags:
        navList.append(menuTag)
    bodyTag.append(ET.Comment('CONTENT'))
    contents = SE(bodyTag, 'div', id='contents')
    center = SE(contents, 'center')
    # for ease of removal of center tag closer
    center.append(ET.Comment(''))
Beispiel #5
0
    def getHeader(self, activeTab="Main", headTag=None, bodyTag=None):
        if headTag is None:
            headTag = ET.Element('head')
        if bodyTag is None:
            bodyTag = ET.Element('body')

        # make sure each component has elements to make formatting consistent
        headTag.append(ET.Comment(''))
        bodyTag.append(ET.Comment(''))

        fileStr = StringIO()
        ET.ElementTree(headTag).write(fileStr, encoding='utf-8')
        headTagStr = unicodeUtf8(fileStr.getvalue())
        # remove the tag closer
        # </head>
        headTagStr = headTagStr[:headTagStr.rindex('<')]

        # fill in the prefab body tag content
        titleStr = LandingPageHTML.title
        landing = ET.Element('body')
        LandingPageHTML.addBodyHeaderAndContent(landing, titleStr,
                                                self.getMenuTags(activeTab))

        fileStr = StringIO()
        ET.ElementTree(landing).write(fileStr, encoding='utf-8')
        landingStr = unicodeUtf8(fileStr.getvalue())
        # remove <body>
        landingStr = landingStr[landingStr.index('>') + 1:]
        # remove tag closers
        for i in xrange(3):
            # </body>
            # contents </div>
            # </center>
            landingStr = landingStr[:landingStr.rindex('<')]

        fileStr = StringIO()
        ET.ElementTree(bodyTag).write(fileStr, encoding='utf-8')
        bodyTagStr = unicodeUtf8(fileStr.getvalue())
        # extract <body>
        bodyStr = bodyTagStr[bodyTagStr.index('>') + 1:]
        bodyTagStr = bodyTagStr[:bodyTagStr.index('>') + 1]

        bodyStr = bodyTagStr + '\n' + landingStr + '\n' + bodyStr

        s = self.headerTemplate % {
            'titlestring': titleStr,
            'headTag': headTagStr,
            'bodyTag': bodyStr,
        }
        return s
Beispiel #6
0
def getTabTags(menu,activeTab):
    tabList = menu.keys()
    if "Main" in tabList:
        tabList.remove("Main")
    if "Services" in tabList:
        tabList.remove("Services")
        
    tabList.sort()
    
    if "Main" in menu.keys():
        tabList.insert(0, "Main")
    if "Services" in menu.keys():
        tabList.insert(1, "Services")

    tabNum = 0

    tags = []

    for tab in tabList:
        if tabNum == 0:
            if tab == activeTab:
                li = ET.Element('li', id='active')
                li.set('class', 'first')
                a = ET.SubElement(li, 'a', href=menu[tab], id='current')
                a.text = tab
                tags.append(li)
            else:
                li = ET.Element('li')
                li.set('class', 'first')
                a = ET.SubElement(li, 'a', href=menu[tab])
                a.text = tab
                tags.append(li)
        else:
            if tab == activeTab:
                li = ET.Element('li', id='active')
                a = ET.SubElement(li, 'a', href=menu[tab], id='current')
                a.text = tab
                tags.append(li)
            else:
                li = ET.Element('li')
                a = ET.SubElement(li, 'a', href=menu[tab])
                a.text = tab
                tags.append(li)
        tabNum += 1

    return tags
Beispiel #7
0
 def load(self, filename):
     doc = ElementTree.parse(filename)
     assert doc.getroot().get
Beispiel #8
0
	def load(self, filename):
		doc = ElementTree.parse(filename)
		assert doc.getroot().get