Esempio n. 1
0
    def __plain_render(self, data):
        """
        Take a non-list, non-dict Python object and produce XML.
        
        A simple conversion to string is performed.
        
        @param data:    A Python object
        @type  data:    object
        
        @return:        XML representation of the object.
        @rtype:         string

        """
        if type(data) is str  or  type(data) is unicode:
            if data.startswith("http://") or data.startswith("https://")  or data.startswith("/"):
                data = Url(data)
        if data is None:
            out = "---"
        elif type(data) is Url:
            out = str(data)
        elif type(data) is bool:
            out = bool_view(data)
        else:
            if type(data) is not unicode:
                data_str = str(data)
            else:
                data_str = data
            out = data_str
        if not out.endswith("\n"):
            out += "\n"
        return self.__indent_level * self.__indent_spaces + out
Esempio n. 2
0
    def __plain_render(self, data):
        """
        Take a non-list, non-dict Python object and produce HTML.
        
        A simple conversion to string is performed.
        
        @param data:    A Python object
        @type  data:    object
        
        @return:        HTML representation of the object.
        @rtype:         string

        """
        if type(data) is unicode or type(data) is str:
            # WSGI wants str(), but some unicode characters can cause exceptions.
            # I'm sure there are better ways to do this, but that works for now.
            # When we use Jython then we can get unprintable characters even
            # in str (while later string operations may fail, which is totally
            # odd...)
            data = ''.join([(str(x) if x in string.printable else "")
                            for x in data])
        # Note that when we use Jython we still have unicode (the conversion to str
        # doesn't seem to work). That's why in the following line we have to test
        # for str() as well as unicode(). The return in unicode is not a problem
        # for the Java server.
        if type(data) is str or type(data) is unicode:
            if data.startswith("http://") or data.startswith(
                    "https://") or data.startswith("/"):
                data = Url(data)
        if data is None:
            out = "---"
        elif type(data) is Url:
            out = data.as_html()
        elif type(data) is bool:
            out = bool_view(data)
        else:
            if type(data) is not unicode:
                data_str = str(data)
            else:
                data_str = data
            if type(data) is not str and type(data) is not unicode and type(
                    data) in [int, float]:
                # Output as number
                out = data_str
            else:
                #out = '<i>%s</i>' % data_str.replace("\n", "<br/>")
                #out = '<span class="string">%s</span>' % data_str
                # This is HTML rendering, so we want to give even normal text to preserve
                # some of its formatting. A simple way to do that is to replace double \n
                # with a single <br>. Triple \n is replaced with two <br> tags, resulting
                # in the rendering of an empty line.
                # This simple strategy allows us to preserve paragraph breaks and formatting
                # without markup, which would be a nuisance in a plain text representation.
                data_str = data_str.replace("\n\n\n", "<br/><br/>")
                out = '<span class="string">%s</span>' % data_str.replace(
                    "\n\n", "<br/>")
        return out
Esempio n. 3
0
    def __plain_render(self, data):
        """
        Take a non-list, non-dict Python object and produce HTML.
        
        A simple conversion to string is performed.
        
        @param data:    A Python object
        @type  data:    object
        
        @return:        HTML representation of the object.
        @rtype:         string

        """
        if type(data) is unicode  or  type(data) is str:
            # WSGI wants str(), but some unicode characters can cause exceptions.
            # I'm sure there are better ways to do this, but that works for now.
            # When we use Jython then we can get unprintable characters even
            # in str (while later string operations may fail, which is totally
            # odd...)
            data = ''.join([ (str(x) if x in string.printable else "") for x in data ])
        # Note that when we use Jython we still have unicode (the conversion to str
        # doesn't seem to work). That's why in the following line we have to test
        # for str() as well as unicode(). The return in unicode is not a problem
        # for the Java server.
        if type(data) is str  or  type(data) is unicode:
            if data.startswith("http://") or data.startswith("https://")  or data.startswith("/"):
                data = Url(data)
        if data is None:
            out = "---"
        elif type(data) is Url:
            out = data.as_html()
        elif type(data) is bool:
            out = bool_view(data)
        else:
            if type(data) is not unicode:
                data_str = str(data)
            else:
                data_str = data
            if type(data) is not str  and  type(data) is not unicode  and  type(data) in [ int, float ]:
                # Output as number
                out = data_str
            else:
                #out = '<i>%s</i>' % data_str.replace("\n", "<br/>")
                #out = '<span class="string">%s</span>' % data_str
                # This is HTML rendering, so we want to give even normal text to preserve
                # some of its formatting. A simple way to do that is to replace double \n
                # with a single <br>. Triple \n is replaced with two <br> tags, resulting
                # in the rendering of an empty line.
                # This simple strategy allows us to preserve paragraph breaks and formatting
                # without markup, which would be a nuisance in a plain text representation.
                data_str = data_str.replace("\n\n\n", "<br/><br/>")
                out = '<span class="string">%s</span>' % data_str.replace("\n\n", "<br/>")
        return out