コード例 #1
0
    def VerifyChunkingDescriptions(self, fold_whitespace):
        p = tr_html.HtmlChunks()
        # Check capitals and explicit descriptions
        chunks = p.Parse(
            '<!-- desc=bingo! --><B>Hello!</B> how are you?<P>'
            '<I>I am fine.</I>', fold_whitespace)
        self.failUnlessEqual(chunks,
                             [(True, '<B>Hello!</B> how are you?', 'bingo!'),
                              (False, '<P>', ''),
                              (True, '<I>I am fine.</I>', '')])
        chunks = p.Parse(
            '<B><!-- desc=bingo! -->Hello!</B> how are you?<P>'
            '<I>I am fine.</I>', fold_whitespace)
        self.failUnlessEqual(chunks,
                             [(True, '<B>Hello!</B> how are you?', 'bingo!'),
                              (False, '<P>', ''),
                              (True, '<I>I am fine.</I>', '')])
        # Linebreaks get handled by the tclib message.
        chunks = p.Parse(
            '<B>Hello!</B> <!-- desc=bi\nngo\n! -->how are you?<P>'
            '<I>I am fine.</I>', fold_whitespace)
        self.failUnlessEqual(
            chunks, [(True, '<B>Hello!</B> how are you?', 'bi\nngo\n!'),
                     (False, '<P>', ''), (True, '<I>I am fine.</I>', '')])

        # In this case, because the explicit description appears after the first
        # translateable, it will actually apply to the second translateable.
        chunks = p.Parse(
            '<B>Hello!</B> how are you?<!-- desc=bingo! --><P>'
            '<I>I am fine.</I>', fold_whitespace)
        self.failUnlessEqual(chunks, [(True, '<B>Hello!</B> how are you?', ''),
                                      (False, '<P>', ''),
                                      (True, '<I>I am fine.</I>', 'bingo!')])
コード例 #2
0
  def VerifyChunkingBasic(self, fold_whitespace):
    p = tr_html.HtmlChunks()
    chunks = p.Parse('<p>Hello <b>dear</b> how <i>are</i>you?<p>Fine!',
                     fold_whitespace)
    self.failUnlessEqual(chunks, [
      (False, '<p>', ''), (True, 'Hello <b>dear</b> how <i>are</i>you?', ''),
      (False, '<p>', ''), (True, 'Fine!', '')])

    chunks = p.Parse('<p> Hello <b>dear</b> how <i>are</i>you? <p>Fine!',
                     fold_whitespace)
    self.failUnlessEqual(chunks, [
      (False, '<p> ', ''), (True, 'Hello <b>dear</b> how <i>are</i>you?', ''),
      (False, ' <p>', ''), (True, 'Fine!', '')])

    chunks = p.Parse('<p> Hello <b>dear how <i>are you? <p> Fine!',
                     fold_whitespace)
    self.failUnlessEqual(chunks, [
      (False, '<p> ', ''), (True, 'Hello <b>dear how <i>are you?', ''),
      (False, ' <p> ', ''), (True, 'Fine!', '')])

    # Ensure translateable sections that start with inline tags contain
    # the starting inline tag.
    chunks = p.Parse('<b>Hello!</b> how are you?<p><i>I am fine.</i>',
                     fold_whitespace)
    self.failUnlessEqual(chunks, [
      (True, '<b>Hello!</b> how are you?', ''), (False, '<p>', ''),
      (True, '<i>I am fine.</i>', '')])

    # Ensure translateable sections that end with inline tags contain
    # the ending inline tag.
    chunks = p.Parse("Hello! How are <b>you?</b><p><i>I'm fine!</i>",
                     fold_whitespace)
    self.failUnlessEqual(chunks, [
      (True, 'Hello! How are <b>you?</b>', ''), (False, '<p>', ''),
      (True, "<i>I'm fine!</i>", '')])
コード例 #3
0
 def VerifyChunkingReplaceables(self, fold_whitespace):
     # Check that replaceables within block tags (where attributes would go) are
     # handled correctly.
     p = tr_html.HtmlChunks()
     chunks = p.Parse(
         '<b>Hello!</b> how are you?<p [BINGO] [$~BONGO~$]>'
         '<i>I am fine.</i>', fold_whitespace)
     self.failUnlessEqual(chunks, [(True, '<b>Hello!</b> how are you?', ''),
                                   (False, '<p [BINGO] [$~BONGO~$]>', ''),
                                   (True, '<i>I am fine.</i>', '')])
コード例 #4
0
  def VerifyChunkingLineBreaks(self, fold_whitespace):
    # Check that the contents of preformatted tags preserve line breaks.
    p = tr_html.HtmlChunks()
    chunks = p.Parse('<textarea>Hello\nthere\nhow\nare\nyou?</textarea>',
                     fold_whitespace)
    self.failUnlessEqual(chunks, [(False, '<textarea>', ''),
      (True, 'Hello\nthere\nhow\nare\nyou?', ''), (False, '</textarea>', '')])

    # ...and that other tags' line breaks are converted to spaces
    chunks = p.Parse('<p>Hello\nthere\nhow\nare\nyou?</p>', fold_whitespace)
    self.failUnlessEqual(chunks, [(False, '<p>', ''),
      (True, 'Hello there how are you?', ''), (False, '</p>', '')])
コード例 #5
0
  def VerifyChunkingMessageNoBreak(self, fold_whitespace):
    p = tr_html.HtmlChunks()
    # Make sure that message-no-break comments work properly.
    chunks = p.Parse('Please <!-- message-no-break --> <br />don\'t break',
                     fold_whitespace)
    self.failUnlessEqual(chunks, [(True, 'Please <!-- message-no-break --> '
                         '<br />don\'t break', '')])

    chunks = p.Parse('Please <br /> break. <!-- message-no-break --> <br /> '
                     'But not this time.', fold_whitespace)
    self.failUnlessEqual(chunks, [(True, 'Please', ''),
                                  (False, ' <br /> ', ''),
                                  (True, 'break. <!-- message-no-break --> '
                                         '<br /> But not this time.', '')])
コード例 #6
0
  def testTranslateableAttributes(self):
    p = tr_html.HtmlChunks()

    # Check that the translateable attributes in <img>, <submit>, <button> and
    # <text> elements buttons are handled correctly.
    chunks = p.Parse('<img src=bingo.jpg alt="hello there">'
                     '<input type=submit value="hello">'
                     '<input type="button" value="hello">'
                     '<input type=\'text\' value=\'Howdie\'>')
    self.failUnless(chunks == [
      (False, '<img src=bingo.jpg alt="', ''), (True, 'hello there', ''),
      (False, '"><input type=submit value="', ''), (True, 'hello', ''),
      (False, '"><input type="button" value="', ''), (True, 'hello', ''),
      (False, '"><input type=\'text\' value=\'', ''), (True, 'Howdie', ''),
      (False, '\'>', '')])
コード例 #7
0
    def VerifyChunkingMessageBreak(self, fold_whitespace):
        p = tr_html.HtmlChunks()
        # Make sure that message-break comments work properly.
        chunks = p.Parse(
            'Break<!-- message-break --> apart '
            '<!--message-break-->messages', fold_whitespace)
        self.failUnlessEqual(chunks, [(True, 'Break', ''), (False, ' ', ''),
                                      (True, 'apart', ''), (False, ' ', ''),
                                      (True, 'messages', '')])

        # Make sure message-break comments work in an inline tag.
        chunks = p.Parse(
            '<a href=\'google.com\'><!-- message-break -->Google'
            '<!--message-break--></a>', fold_whitespace)
        self.failUnlessEqual(chunks, [(False, '<a href=\'google.com\'>', ''),
                                      (True, 'Google', ''),
                                      (False, '</a>', '')])
コード例 #8
0
  def testChunking(self):
    p = tr_html.HtmlChunks()
    chunks = p.Parse('<p>Hello <b>dear</b> how <i>are</i>you?<p>Fine!')
    self.failUnless(chunks == [
      (False, '<p>', ''), (True, 'Hello <b>dear</b> how <i>are</i>you?', ''),
      (False, '<p>', ''), (True, 'Fine!', '')])

    chunks = p.Parse('<p> Hello <b>dear</b> how <i>are</i>you? <p>Fine!')
    self.failUnless(chunks == [
      (False, '<p> ', ''), (True, 'Hello <b>dear</b> how <i>are</i>you?', ''),
      (False, ' <p>', ''), (True, 'Fine!', '')])

    chunks = p.Parse('<p> Hello <b>dear how <i>are you? <p> Fine!')
    self.failUnless(chunks == [
      (False, '<p> ', ''), (True, 'Hello <b>dear how <i>are you?', ''),
      (False, ' <p> ', ''), (True, 'Fine!', '')])

    # Ensure translateable sections that start with inline tags contain
    # the starting inline tag.
    chunks = p.Parse('<b>Hello!</b> how are you?<p><i>I am fine.</i>')
    self.failUnless(chunks == [
      (True, '<b>Hello!</b> how are you?', ''), (False, '<p>', ''),
      (True, '<i>I am fine.</i>', '')])

    # Ensure translateable sections that end with inline tags contain
    # the ending inline tag.
    chunks = p.Parse("Hello! How are <b>you?</b><p><i>I'm fine!</i>")
    self.failUnless(chunks == [
      (True, 'Hello! How are <b>you?</b>', ''), (False, '<p>', ''),
      (True, "<i>I'm fine!</i>", '')])

    # Check capitals and explicit descriptions
    chunks = p.Parse('<!-- desc=bingo! --><B>Hello!</B> how are you?<P><I>I am fine.</I>')
    self.failUnless(chunks == [
      (True, '<B>Hello!</B> how are you?', 'bingo!'), (False, '<P>', ''),
      (True, '<I>I am fine.</I>', '')])
    chunks = p.Parse('<B><!-- desc=bingo! -->Hello!</B> how are you?<P><I>I am fine.</I>')
    self.failUnless(chunks == [
      (True, '<B>Hello!</B> how are you?', 'bingo!'), (False, '<P>', ''),
      (True, '<I>I am fine.</I>', '')])
    # Linebreaks get changed to spaces just like any other HTML content
    chunks = p.Parse('<B>Hello!</B> <!-- desc=bi\nngo\n! -->how are you?<P><I>I am fine.</I>')
    self.failUnless(chunks == [
      (True, '<B>Hello!</B> how are you?', 'bi ngo !'), (False, '<P>', ''),
      (True, '<I>I am fine.</I>', '')])

    # In this case, because the explicit description appears after the first
    # translateable, it will actually apply to the second translateable.
    chunks = p.Parse('<B>Hello!</B> how are you?<!-- desc=bingo! --><P><I>I am fine.</I>')
    self.failUnless(chunks == [
      (True, '<B>Hello!</B> how are you?', ''), (False, '<P>', ''),
      (True, '<I>I am fine.</I>', 'bingo!')])

    # Check that replaceables within block tags (where attributes would go) are
    # handled correctly.
    chunks = p.Parse('<b>Hello!</b> how are you?<p [BINGO] [$~BONGO~$]>'
                     '<i>I am fine.</i>')
    self.failUnless(chunks == [
      (True, '<b>Hello!</b> how are you?', ''),
      (False, '<p [BINGO] [$~BONGO~$]>', ''),
      (True, '<i>I am fine.</i>', '')])

    # Check that the contents of preformatted tags preserve line breaks.
    chunks = p.Parse('<textarea>Hello\nthere\nhow\nare\nyou?</textarea>')
    self.failUnless(chunks == [(False, '<textarea>', ''),
      (True, 'Hello\nthere\nhow\nare\nyou?', ''), (False, '</textarea>', '')])

    # ...and that other tags' line breaks are converted to spaces
    chunks = p.Parse('<p>Hello\nthere\nhow\nare\nyou?</p>')
    self.failUnless(chunks == [(False, '<p>', ''),
      (True, 'Hello there how are you?', ''), (False, '</p>', '')])