Exemplo n.º 1
0
    def check_disallowedElements(self, dom, filename):
        def m(node, self=self):
            return not self.allowedTags(node.tagName)

        for element in domhelpers.findElements(dom, m):
            self._reportError(filename, element,
                              'unrecommended tag %s' % element.tagName)
Exemplo n.º 2
0
def getHeaders(document):
    """
    Return all H2 and H3 nodes in the given document.

    @type document: A DOM Node or Document

    @rtype: C{list}
    """
    return domhelpers.findElements(document, lambda n, m=re.compile("h[23]$").match: m(n.nodeName))
Exemplo n.º 3
0
 def check_disallowedClasses(self, dom, filename):
     def matcher(element, self=self):
         if not element.hasAttribute('class'):
             return 0
         checker = self.allowedClasses.get(element.tagName, lambda x:0)
         return not checker(element.getAttribute('class'))
     for element in domhelpers.findElements(dom, matcher):
         self._reportError(filename, element,
                           'unknown class %s' %element.getAttribute('class'))
Exemplo n.º 4
0
 def check_disallowedClasses(self, dom, filename):
     def matcher(element, self=self):
         if not element.hasAttribute('class'):
             return 0
         checker = self.allowedClasses.get(element.tagName, lambda x:0)
         return not checker(element.getAttribute('class'))
     for element in domhelpers.findElements(dom, matcher):
         self._reportError(filename, element,
                           'unknown class %s' %element.getAttribute('class'))
Exemplo n.º 5
0
def lowerDocument(href, d, nodeLevel):
    newNode = microdom.parse(open(os.path.join(d, href)))
    newNode = domhelpers.findNodesNamed(newNode, 'body')[0]
    headers = domhelpers.findElements(newNode,
              lambda x: len(x.tagName)==2 and x.tagName[0]=='h' and
                        x.tagName[1] in '123456')
    for header in headers:
        header.tagName = 'h'+str(int(header.tagName[1])+nodeLevel)
    return newNode
Exemplo n.º 6
0
def getHeaders(document):
    """
    Return all H2 and H3 nodes in the given document.

    @type document: A DOM Node or Document

    @rtype: C{list}
    """
    return domhelpers.findElements(
        document, lambda n, m=re.compile('h[23]$').match: m(n.nodeName))
Exemplo n.º 7
0
    def setUp(self, request, node, data):
        # node = widgets.Widget.generateDOM(self,request,node)
        lmn = lmx(node)
        if not node.hasAttribute('action'):
            lmn['action'] = (request.prepath + request.postpath)[-1]
        if not node.hasAttribute("method"):
            lmn['method'] = 'post'
        lmn['enctype'] = 'multipart/form-data'
        self.errorNodes = errorNodes = {}  # name: nodes which trap errors
        self.inputNodes = inputNodes = {}
        for errorNode in domhelpers.findElementsWithAttribute(
                node, 'errorFor'):
            errorNodes[errorNode.getAttribute('errorFor')] = errorNode
        argz = {}
        # list to figure out which nodes are in the template already and which aren't
        hasSubmit = 0
        argList = self.model.fmethod.getArgs()
        for arg in argList:
            if isinstance(arg, formmethod.Submit):
                hasSubmit = 1
            argz[arg.name] = arg
        inNodes = domhelpers.findElements(
            node, lambda n: n.tagName.lower() in
            ('textarea', 'select', 'input', 'div'))
        for inNode in inNodes:
            t = inNode.getAttribute("type")
            if t and t.lower() == "submit":
                hasSubmit = 1
            if not inNode.hasAttribute("name"):
                continue
            nName = inNode.getAttribute("name")
            if argz.has_key(nName):
                #send an empty content shell - we just want the node
                inputNodes[nName] = self.convergeInput(request, lmx(),
                                                       argz[nName], inNode)
                inNode.parentNode.replaceChild(inputNodes[nName], inNode)
                del argz[nName]
            # TODO:
            # * some arg types should only have a single node (text, string, etc)
            # * some should have multiple nodes (choice, checkgroup)
            # * some have a bunch of ancillary nodes that are possible values (menu, radiogroup)
            # these should all be taken into account when walking through the template
        if argz:
            shell = self.createShell(request, node, data)
            # create inputs, in the same order they were passed to us:
            for remArg in [arg for arg in argList if argz.has_key(arg.name)]:
                inputNode, errorNode = self.createInput(request, shell, remArg)
                errorNodes[remArg.name] = errorNode
                inputNodes[remArg.name] = inputNode

        if not hasSubmit:
            lmn.input(type="submit")
Exemplo n.º 8
0
    def setUp(self, request, node, data):
        # node = widgets.Widget.generateDOM(self,request,node)
        lmn = lmx(node)
        if not node.hasAttribute('action'):
            lmn['action'] = (request.prepath+request.postpath)[-1]
        if not node.hasAttribute("method"):
            lmn['method'] = 'post'
        lmn['enctype'] = 'multipart/form-data'
        self.errorNodes = errorNodes = {}                     # name: nodes which trap errors
        self.inputNodes = inputNodes = {}
        for errorNode in domhelpers.findElementsWithAttribute(node, 'errorFor'):
            errorNodes[errorNode.getAttribute('errorFor')] = errorNode
        argz={}
        # list to figure out which nodes are in the template already and which aren't
        hasSubmit = 0
        argList = self.model.fmethod.getArgs()
        for arg in argList:
            if isinstance(arg, formmethod.Submit):
                hasSubmit = 1
            argz[arg.name] = arg
        inNodes = domhelpers.findElements(
            node,
            lambda n: n.tagName.lower() in ('textarea', 'select', 'input',
                                            'div'))
        for inNode in inNodes:
            t = inNode.getAttribute("type")
            if t and t.lower() == "submit":
                hasSubmit = 1
            if not inNode.hasAttribute("name"):
                continue
            nName = inNode.getAttribute("name")
            if argz.has_key(nName):
                #send an empty content shell - we just want the node
                inputNodes[nName] = self.convergeInput(request, lmx(),
                                                       argz[nName], inNode)
                inNode.parentNode.replaceChild(inputNodes[nName], inNode)
                del argz[nName]
            # TODO:
            # * some arg types should only have a single node (text, string, etc)
            # * some should have multiple nodes (choice, checkgroup)
            # * some have a bunch of ancillary nodes that are possible values (menu, radiogroup)
            # these should all be taken into account when walking through the template
        if argz:
            shell = self.createShell(request, node, data)
            # create inputs, in the same order they were passed to us:
            for remArg in [arg for arg in argList if argz.has_key(arg.name)]:
                inputNode, errorNode = self.createInput(request, shell, remArg)
                errorNodes[remArg.name] = errorNode
                inputNodes[remArg.name] = inputNode

        if not hasSubmit:
            lmn.input(type="submit")
Exemplo n.º 9
0
def fontifyPython(document):
    """
    Syntax color any node in the given document which contains a Python source
    listing.

    @type document: A DOM Node or Document
    @param document: The input document which contains all of the content to be
    presented.

    @return: C{None}
    """
    def matcher(node):
        return (node.nodeName == 'pre' and node.hasAttribute('class') and
                node.getAttribute('class') == 'python')
    for node in domhelpers.findElements(document, matcher):
        fontifyPythonNode(node)
Exemplo n.º 10
0
def fontifyPython(document):
    """
    Syntax color any node in the given document which contains a Python source
    listing.

    @type document: A DOM Node or Document
    @param document: The input document which contains all of the content to be
    presented.

    @return: C{None}
    """
    def matcher(node):
        return (node.nodeName == 'pre' and node.hasAttribute('class') and
                node.getAttribute('class') == 'python')
    for node in domhelpers.findElements(document, matcher):
        fontifyPythonNode(node)
Exemplo n.º 11
0
 def setUp(self, request, node, data):
     lmn = lmx(node)
     if not node.hasAttribute('action'):
         lmn['action'] = (request.prepath+request.postpath)[-1]
     if not node.hasAttribute("method"):
         lmn['method'] = 'post'
     lmn['enctype'] = 'multipart/form-data'
     self.errorNodes = errorNodes = {}                     # name: nodes which trap errors
     self.inputNodes = inputNodes = {}
     for errorNode in domhelpers.findElementsWithAttribute(node, 'errorFor'):
         errorNodes[errorNode.getAttribute('errorFor')] = errorNode
     argz={}
     hasSubmit = 0
     argList = self.model.fmethod.getArgs()
     for arg in argList:
         if isinstance(arg, formmethod.Submit):
             hasSubmit = 1
         argz[arg.name] = arg
     inNodes = domhelpers.findElements(
         node,
         lambda n: n.tagName.lower() in ('textarea', 'select', 'input',
                                         'div'))
     for inNode in inNodes:
         t = inNode.getAttribute("type")
         if t and t.lower() == "submit":
             hasSubmit = 1
         if not inNode.hasAttribute("name"):
             continue
         nName = inNode.getAttribute("name")
         if argz.has_key(nName):
             inputNodes[nName] = self.convergeInput(request, lmx(),
                                                    argz[nName], inNode)
             inNode.parentNode.replaceChild(inputNodes[nName], inNode)
             del argz[nName]
     if argz:
         shell = self.createShell(request, node, data)
         for remArg in [arg for arg in argList if argz.has_key(arg.name)]:
             inputNode, errorNode = self.createInput(request, shell, remArg)
             errorNodes[remArg.name] = errorNode
             inputNodes[remArg.name] = inputNode
     if not hasSubmit:
         lmn.input(type="submit")
Exemplo n.º 12
0
 def check_disallowedElements(self, dom, filename):
     def m(node, self=self):
         return not self.allowedTags(node.tagName)
     for element in domhelpers.findElements(dom, m):
         self._reportError(filename, element,
                            'unrecommended tag %s' % element.tagName)
Exemplo n.º 13
0
def fontifyPython(document):
    def matcher(node):
        return (node.nodeName == 'pre' and node.hasAttribute('class') and
                node.getAttribute('class') == 'python')
    for node in domhelpers.findElements(document, matcher):
        fontifyPythonNode(node)
Exemplo n.º 14
0
def getHeaders(document):
    return domhelpers.findElements(document, 
                           lambda n,m=re.compile('h[23]$').match:m(n.nodeName))