Exemplo n.º 1
0
    def __call__(self, md):
        # In which language, if any?
        lang = get_value(self.lang, md)

        # Get the message!!
        ns = namespace(md)[0]
        md._push(InstanceDict(ns, md))
        message = render_blocks(self.section, md)
        md._pop(1)

        # Interpret the message as verbatim or not
        if not self.verbatim:
            message = " ".join([x.strip() for x in message.split()])

        # Search in a specific catalog
        if self.catalog is None:
            gettext = md.getitem("gettext", 0)
        else:
            gettext = md.getitem(self.catalog, 0).gettext

        translation = gettext(message, lang)

        # Variable substitution
        if self.data is not None:
            data = self.data.eval(md)
            translation = translation % data

        return translation
Exemplo n.º 2
0
    def __call__(self, md):
        ns = namespace(md)[0]
        md._push(InstanceDict(ns, md))
        message = render_blocks(self.section, md)
        md._pop(1)

        return message
Exemplo n.º 3
0
    def __call__(self, md):
        ns = namespace(md)[0]
        md._push(InstanceDict(ns, md))
        message = render_blocks(self.section, md)
        md._pop(1)

        return message
Exemplo n.º 4
0
    def __call__(self, md):
        # In which language, if any?
        lang = self.lang
        if lang is not None and type(lang) is not str:
            lang = lang.eval(md)

        # Get the message!!
        ns = namespace(md)[0]
        md._push(InstanceDict(ns, md))
        message = render_blocks(self.section, md)
        md._pop(1)

        # Interpret the message as verbatim or not
        if not self.verbatim:
            message = ' '.join([x.strip() for x in message.split()])

        # Search in a specific catalog
        if self.catalog is None:
            gettext = md.getitem('gettext', 0)
        else:
            gettext = md.getitem(self.catalog, 0).gettext

        translation = gettext(message, lang)

        # Variable substitution
        if self.data is not None:
            data = self.data.eval(md)
            translation = translation % data

        return translation
Exemplo n.º 5
0
    def render_try_except(self, md):
        result = ''

        # first we try to render the first block
        try:
            result = render_blocks(self.section, md)
        except DTReturn:
            raise
        except:
            # but an error occurs.. save the info.
            t, v = sys.exc_info()[:2]
            if type(t) == type(''):
                errname = t
            else:
                errname = t.__name__

            handler = self.find_handler(t)

            if handler is None:
                # we didn't find a handler, so reraise the error
                raise

            # found the handler block, now render it
            try:
                f = StringIO()
                traceback.print_exc(100, f)
                error_tb = f.getvalue()
                ns = namespace(md,
                               error_type=errname,
                               error_value=v,
                               error_tb=error_tb)[0]
                md._push(InstanceDict(ns, md))
                return render_blocks(handler, md)
            finally:
                md._pop(1)

        else:
            # No errors have occured, render the optional else block
            if (self.elseBlock is None):
                return result
            else:
                return result + render_blocks(self.elseBlock, md)
Exemplo n.º 6
0
    def render_try_except(self, md):
        result = ''

        # first we try to render the first block
        try:
            result = render_blocks(self.section, md)
        except DTReturn:
            raise
        except:
            # but an error occurs.. save the info.
            t,v = sys.exc_info()[:2]
            if type(t)==type(''):
                errname = t
            else:
                errname = t.__name__

            handler = self.find_handler(t)

            if handler is None:
                # we didn't find a handler, so reraise the error
                raise

            # found the handler block, now render it
            try:
                f=StringIO()
                traceback.print_exc(100,f)
                error_tb=f.getvalue()
                ns = namespace(md, error_type=errname, error_value=v,
                    error_tb=error_tb)[0]
                md._push(InstanceDict(ns,md))
                return render_blocks(handler, md)
            finally:
                md._pop(1)

        else:
            # No errors have occured, render the optional else block
            if (self.elseBlock is None):
                return result
            else:
                return result + render_blocks(self.elseBlock, md)