Example #1
0
    def flatten(self, expander, variables, res):
        name = []
        evaluate.flatten(self[0], expander, variables, name)
        name = u"".join(name).strip()
        parameters = u''

        for parm in self[2:]:
            tmp = []
            evaluate.flatten(parm, expander, variables, tmp)
            evaluate._insert_implicit_newlines(tmp)
            tmp = u"".join(tmp)
            if "=" in tmp:
                key, value = tmp.split("=", 1)
                parameters += " %s=%s" % (key, quoteattr(value))

        tmpres = []
        tmpres.append("<%s%s>" % (name, parameters))

        if len(self) > 1:
            tmp = []
            evaluate.flatten(self[1], expander, variables, tmp)
            evaluate._insert_implicit_newlines(tmp)
            tmp = u"".join(tmp)
            tmpres.append(tmp)

        tmpres.append("</%s>" % (name,))
        tmpres = u"".join(tmpres)
        tmpres = expander.uniquifier.replace_tags(tmpres)
        res.append(tmpres)
Example #2
0
    def flatten(self, expander, variables, res):
        v1 = []
        flatten(self[0], expander, variables, v1)
        v1 = u"".join(v1).strip()

        v2 = []
        if len(self) > 1:
            flatten(self[1], expander, variables, v2)
        v2 = u"".join(v2).strip()

        from mwlib.templ.magics import maybe_numeric_compare

        res.append(maybe_newline)
        tmp = []

        if maybe_numeric_compare(v1, v2):
            if len(self) > 2:
                flatten(self[2], expander, variables, tmp)
        else:
            if len(self) > 3:
                flatten(self[3], expander, variables, tmp)

        _insert_implicit_newlines(tmp)
        res.append(u"".join(tmp).strip())
        res.append(dummy_mark)
Example #3
0
    def flatten(self, expander, variables, res):
        name = []
        evaluate.flatten(self[0], expander, variables, name)
        name = u"".join(name).strip()
        parameters = u''

        for parm in self[2:]:
            tmp = []
            evaluate.flatten(parm, expander, variables, tmp)
            evaluate._insert_implicit_newlines(tmp)
            tmp = u"".join(tmp)
            if "=" in tmp:
                key, value = tmp.split("=", 1)
                parameters += " %s=%s" % (key, quoteattr(value))

        tmpres = []
        tmpres.append("<%s%s>" % (name, parameters))

        if len(self) > 1:
            tmp = []
            evaluate.flatten(self[1], expander, variables, tmp)
            evaluate._insert_implicit_newlines(tmp)
            tmp = u"".join(tmp)
            tmpres.append(tmp)

        tmpres.append("</%s>" % (name, ))
        tmpres = u"".join(tmpres)
        tmpres = expander.uniquifier.replace_tags(tmpres)
        res.append(tmpres)
Example #4
0
    def flatten(self, expander, variables, res):
        v1 = []
        flatten(self[0], expander, variables, v1)
        v1 = u"".join(v1).strip()

        v2 = []
        if len(self) > 1:
            flatten(self[1], expander, variables, v2)
        v2 = u"".join(v2).strip()

        from mwlib.templ.magics import maybe_numeric_compare

        res.append(maybe_newline)
        tmp = []

        if maybe_numeric_compare(v1, v2):
            if len(self) > 2:
                flatten(self[2], expander, variables, tmp)
        else:
            if len(self) > 3:
                flatten(self[3], expander, variables, tmp)

        _insert_implicit_newlines(tmp)
        res.append(u"".join(tmp).strip())
        res.append(dummy_mark)
Example #5
0
    def flatten(self, expander, variables, res):
        if self.unresolved is None:
            self._init()

        res.append(maybe_newline)
        val = []
        flatten(self[0], expander, variables, val)
        val = u"".join(val).strip()

        num_val = maybe_numeric(val)

        t1 = self.fast.get(val, self.sentinel)
        t2 = self.fast.get(num_val, self.sentinel)

        pos, retval = min(t1, t2)

        if pos is None:
            pos = len(self.unresolved)+1

        for k, v in self.unresolved[:pos]:
            tmp = []
            flatten(k, expander, variables, tmp)
            tmp = u"".join(tmp).strip()
            if tmp == val:
                retval = v
                break
            if num_val is not None and maybe_numeric(tmp) == num_val:
                retval = v
                break

        if retval is None:
            for a in expander.aliasmap.get_aliases("default") or ["#default"]:
                retval = self.fast.get(a)
                if retval is not None:
                    retval = retval[1]
                    break
            retval = retval or u""

        tmp = []
        flatten(retval, expander, variables, tmp)
        _insert_implicit_newlines(tmp)
        tmp = u"".join(tmp).strip()
        res.append(tmp)
        res.append(dummy_mark)
Example #6
0
    def flatten(self, expander, variables, res):
        if self.unresolved is None:
            self._init()

        res.append(maybe_newline)
        val = []
        flatten(self[0], expander, variables, val)
        val = u"".join(val).strip()

        num_val = maybe_numeric(val)

        t1 = self.fast.get(val, self.sentinel)
        t2 = self.fast.get(num_val, self.sentinel)

        pos, retval = min(t1, t2)

        if pos is None:
            pos = len(self.unresolved) + 1

        for k, v in self.unresolved[:pos]:
            tmp = []
            flatten(k, expander, variables, tmp)
            tmp = u"".join(tmp).strip()
            if tmp == val:
                retval = v
                break
            if num_val is not None and maybe_numeric(tmp) == num_val:
                retval = v
                break

        if retval is None:
            for a in expander.aliasmap.get_aliases("default") or ["#default"]:
                retval = self.fast.get(a)
                if retval is not None:
                    retval = retval[1]
                    break
            retval = retval or u""

        tmp = []
        flatten(retval, expander, variables, tmp)
        _insert_implicit_newlines(tmp)
        tmp = u"".join(tmp).strip()
        res.append(tmp)
        res.append(dummy_mark)
Example #7
0
    def flatten(self, expander, variables, res):
        cond = []
        flatten(self[0], expander, variables, cond)
        cond = u"".join(cond).strip()

        # template blacklisting results in 0xebad
        # see http://code.pediapress.com/wiki/ticket/700#comment:1
        cond = cond.strip(unichr(0xebad))

        res.append(maybe_newline)
        tmp = []
        if cond:
            if len(self) > 1:
                flatten(self[1], expander, variables, tmp)
        else:
            if len(self) > 2:
                flatten(self[2], expander, variables, tmp)
        _insert_implicit_newlines(tmp)
        res.append(u"".join(tmp).strip())
        res.append(dummy_mark)
Example #8
0
    def flatten(self, expander, variables, res):
        cond = []
        flatten(self[0], expander, variables, cond)
        cond = u"".join(cond).strip()

        # template blacklisting results in 0xebad
        # see http://code.pediapress.com/wiki/ticket/700#comment:1
        cond = cond.strip(unichr(0xebad))

        res.append(maybe_newline)
        tmp = []
        if cond:
            if len(self) > 1:
                flatten(self[1], expander, variables, tmp)
        else:
            if len(self) > 2:
                flatten(self[2], expander, variables, tmp)
        _insert_implicit_newlines(tmp)
        res.append(u"".join(tmp).strip())
        res.append(dummy_mark)
Example #9
0
    def _handle_marks(self, m, res):
        i = 0

        while i < len(m):
            logger.debug(repr(m[i]))
            if isinstance(m[i], marks.mark_start):
                a = self.get_action(eval(m[i].msg))
                if a == EXPAND:
                    res.append(m[i])
                    i += 1
                elif a == REMOVE:
                    i += self._remove(m[i:], res)
                else: #KEEP
                    i += self._keep(m[i:], res)
            elif not isinstance(m[i], mark_argument):
                res.append(m[i])
                i += 1
            else:
                i += 1

        evaluate._insert_implicit_newlines(res)