(self, encoding=DEFAULT_OUTPUT_ENCODING,
                prettyPrint=False, indentLevel=0)
return s
Returns a string or Unicode representation of this tag and
        its contents. To get Unicode, pass None for encoding.

        NOTE: since Python's HTML parser consumes whitespace, this
        method is not certain to reproduce the whitespace present in
        the original string.
Returns a string or Unicode representation of this tag and
        its contents. To get Unicode, pass None for encoding.
Returns a string or Unicode representation of this tag and its contents . To get Unicode pass None for encoding .
def __str__(self, encoding=DEFAULT_OUTPUT_ENCODING,
                prettyPrint=False, indentLevel=0):
        """Returns a string or Unicode representation of this tag and
        its contents. To get Unicode, pass None for encoding.

        NOTE: since Python's HTML parser consumes whitespace, this
        method is not certain to reproduce the whitespace present in
        the original string."""

        encodedName = self.toEncoding(self.name, encoding)

        attrs = []
        if self.attrs:
            for key, val in self.attrs:
                fmt = '%s="%s"'
                if isinstance(val, basestring):
                    if self.containsSubstitutions and '%SOUP-ENCODING%' in val:
                        val = self.substituteEncoding(val, encoding)

                    # The attribute value either:
                    #
                    # * Contains no embedded double quotes or single quotes.
                    #   No problem: we enclose it in double quotes.
                    # * Contains embedded single quotes. No problem:
                    #   double quotes work here too.
                    # * Contains embedded double quotes. No problem:
                    #   we enclose it in single quotes.
                    # * Embeds both single _and_ double quotes. This
                    #   can't happen naturally, but it can happen if
                    #   you modify an attribute value after parsing
                    #   the document. Now we have a bit of a
                    #   problem. We solve it by enclosing the
                    #   attribute in single quotes, and escaping any
                    #   embedded single quotes to XML entities.
                    if '"' in val:
                        fmt = "%s='%s'"
                        if "'" in val:
                            # TODO: replace with apos when
                            # appropriate.
                            val = val.replace("'", "&squot;")

                    # Now we're okay w/r/t quotes. But the attribute
                    # value might also contain angle brackets, or
                    # ampersands that aren't part of entities. We need
                    # to escape those to XML entities too.
                    val = self.BARE_AMPERSAND_OR_BRACKET.sub(self._sub_entity, val)

                attrs.append(fmt % (self.toEncoding(key, encoding),
                                    self.toEncoding(val, encoding)))
        close = ''
        closeTag = ''
        if self.isSelfClosing:
            close = ' /'
        else:
            closeTag = '</%s>' % encodedName

        indentTag, indentContents = 0, 0
        if prettyPrint:
            indentTag = indentLevel
            space = (' ' * (indentTag-1))
            indentContents = indentTag + 1
        contents = self.renderContents(encoding, prettyPrint, indentContents)
        if self.hidden:
            s = contents
        else:
            s = []
            attributeString = ''
            if attrs:
                attributeString = ' ' + ' '.join(attrs)
            if prettyPrint:
                s.append(space)
            s.append('<%s%s%s>' % (encodedName, attributeString, close))
            if prettyPrint:
                s.append("\n")
            s.append(contents)
            if prettyPrint and contents and contents[-1] != "\n":
                s.append("\n")
            if prettyPrint and closeTag:
                s.append(space)
            s.append(closeTag)
            if prettyPrint and closeTag and self.nextSibling:
                s.append("\n")
            s = ''.join(s)
        return s
def __str__ ( self , encoding = DEFAULT_OUTPUT_ENCODING , prettyPrint = False , indentLevel = 0 ) : encodedName = self . toEncoding ( self . name , encoding ) attrs = [ ] if self . attrs : for key , val in self . attrs : fmt = '%s="%s"' if isinstance ( val , basestring ) : if self . containsSubstitutions and '%SOUP-ENCODING%' in val : val = self . substituteEncoding ( val , encoding ) # The attribute value either: # # * Contains no embedded double quotes or single quotes. #   No problem: we enclose it in double quotes. # * Contains embedded single quotes. No problem: #   double quotes work here too. # * Contains embedded double quotes. No problem: #   we enclose it in single quotes. # * Embeds both single _and_ double quotes. This #   can't happen naturally, but it can happen if #   you modify an attribute value after parsing #   the document. Now we have a bit of a #   problem. We solve it by enclosing the #   attribute in single quotes, and escaping any #   embedded single quotes to XML entities. if '"' in val : fmt = "%s='%s'" if "'" in val : # TODO: replace with apos when # appropriate. val = val . replace ( "'" , "&squot;" ) # Now we're okay w/r/t quotes. But the attribute # value might also contain angle brackets, or # ampersands that aren't part of entities. We need # to escape those to XML entities too. val = self . BARE_AMPERSAND_OR_BRACKET . sub ( self . _sub_entity , val ) attrs . append ( fmt % ( self . toEncoding ( key , encoding ) , self . toEncoding ( val , encoding ) ) ) close = '' closeTag = '' if self . isSelfClosing : close = ' /' else : closeTag = '</%s>' % encodedName indentTag , indentContents = 0 , 0 if prettyPrint : indentTag = indentLevel space = ( ' ' * ( indentTag - 1 ) ) indentContents = indentTag + 1 contents = self . renderContents ( encoding , prettyPrint , indentContents ) if self . hidden : s = contents else : s = [ ] attributeString = '' if attrs : attributeString = ' ' + ' ' . join ( attrs ) if prettyPrint : s . append ( space ) s . append ( '<%s%s%s>' % ( encodedName , attributeString , close ) ) if prettyPrint : s . append ( "\n" ) s . append ( contents ) if prettyPrint and contents and contents [ - 1 ] != "\n" : s . append ( "\n" ) if prettyPrint and closeTag : s . append ( space ) s . append ( closeTag ) if prettyPrint and closeTag and self . nextSibling : s . append ( "\n" ) s = '' . join ( s ) return s