Ejemplo n.º 1
0
 def ToPrettyMultilineString( self ):
     
     pretty_strings = []
     
     for ( name, attrs, index ) in self._tag_rules:
         
         s = ''
         
         if index is None:
             
             s += 'get every'
             
         else:
             
             num = index + 1
             
             s += 'get the ' + HydrusData.ConvertIntToPrettyOrdinalString( num )
             
         
         s += ' <' + name + '> tag'
         
         if len( attrs ) > 0:
             
             s += ' with attributes ' + ', '.join( key + '=' + value for ( key, value ) in attrs.items() )
             
         
         pretty_strings.append( s )
         
     
     if self._content_rule is None:
         
         pretty_strings.append( 'get the text content of those tags' )
         
     else:
         
         pretty_strings.append( 'get the ' + self._content_rule + ' attribute of those tags' )
         
     
     pretty_strings.extend( self._string_converter.GetTransformationStrings() )
     
     separator = os.linesep + 'and then '
     
     pretty_multiline_string = separator.join( pretty_strings )
     
     return pretty_multiline_string
Ejemplo n.º 2
0
    def ToPrettyMultilineString(self):

        pretty_strings = []

        for (name, attrs, index) in self._tag_rules:

            s = ''

            if index is None:

                s += 'get every'

            else:

                num = index + 1

                s += 'get the ' + HydrusData.ConvertIntToPrettyOrdinalString(
                    num)

            s += ' <' + name + '> tag'

            if len(attrs) > 0:

                s += ' with attributes ' + ', '.join(
                    key + '=' + value for (key, value) in attrs.items())

            pretty_strings.append(s)

        if self._content_rule is None:

            pretty_strings.append('get the text content of those tags')

        else:

            pretty_strings.append('get the ' + self._content_rule +
                                  ' attribute of those tags')

        cull_munge_strings = []

        (cull_front, cull_back, prepend, append) = self._culling_and_adding

        if cull_front > 0:

            cull_munge_strings.append(
                'the first ' +
                HydrusData.ConvertIntToPrettyString(cull_front) +
                ' characters')

        elif cull_front < 0:

            cull_munge_strings.append(
                'all but the last ' +
                HydrusData.ConvertIntToPrettyString(abs(cull_front)) +
                ' characters')

        if cull_back > 0:

            cull_munge_strings.append(
                'the last ' + HydrusData.ConvertIntToPrettyString(cull_back) +
                ' characters')

        elif cull_back < 0:

            cull_munge_strings.append(
                'all but the first ' +
                HydrusData.ConvertIntToPrettyString(abs(cull_back)) +
                ' characters')

        if len(cull_munge_strings) > 0:

            pretty_strings.append('remove ' + ' and '.join(cull_munge_strings))

        add_munge_strings = []

        if prepend != '':

            add_munge_strings.append('prepend "' + prepend + '"')

        if append != '':

            add_munge_strings.append('append "' + append + '"')

        if len(add_munge_strings) > 0:

            pretty_strings.append(' and '.join(add_munge_strings))

        separator = os.linesep + 'and then '

        pretty_multiline_string = separator.join(pretty_strings)

        return pretty_multiline_string