Exemplo n.º 1
0
    def test_case1(self):
        """Test element content."""
        data = self.template % '<p>hello little world</p>'
        doc = XHTMLFile(string=data)

        messages = [unit[0] for unit in doc.get_units()]
        self.assertEqual(messages, [((TEXT, u'hello little world'),)])
Exemplo n.º 2
0
    def test_case2(self):
        """Test simple attribute."""
        data = self.template % '<img alt="The beach" src="beach.jpg" />'
        doc = XHTMLFile(string=data)

        messages = [unit[0] for unit in doc.get_units()]
        self.assertEqual(messages, [((TEXT, u'The beach'),)])
Exemplo n.º 3
0
    def test_case3(self):
        """Test complex attribute."""
        data = self.template % ('<input type="text" name="id" />\n'
                                '<input type="submit" value="Change" />')
        doc = XHTMLFile(string=data)

        messages = [unit[0] for unit in doc.get_units()]
        self.assertEqual(messages, [((TEXT, u'Change'),)])
Exemplo n.º 4
0
    def test_form(self):
        """Test complex attribute."""
        # The document
        doc = XHTMLFile(string=
            '<form xmlns="http://www.w3.org/1999/xhtml">\n'
            '  <input type="text" name="id" />\n'
            '  <input type="submit" value="Change" />\n'
            '</form>')

        messages = [unit[0] for unit in doc.get_units()]
        self.assertEqual(messages, [((TEXT, u'Change'),)])
Exemplo n.º 5
0
    def test_inline(self):
        doc = XHTMLFile(string=
            '<p xmlns="http://www.w3.org/1999/xhtml">'
            'Hi <b>everybody, </b><i>how are you ? </i>'
            '</p>')

        messages = [unit[0] for unit in doc.get_units()]
        expected = [((TEXT, u'Hi '), (START_FORMAT, 1),
                     (TEXT, u'everybody, '), (END_FORMAT, 1),
                     (START_FORMAT, 2), (TEXT, u'how are you ? '),
                     (END_FORMAT, 2))]
        self.assertEqual(messages, expected)
Exemplo n.º 6
0
    def test_case5(self):
        """Test translation of an element content"""
        po = POFile(string=
            'msgctxt "img[alt]"\n'
            'msgid "The beach"\n'
            'msgstr "La playa"')
        xhtml = XHTMLFile(string=
            self.template  % '<img alt="The beach" src="beach.jpg" />')

        html = xhtml.translate(po)
        xhtml = XHTMLFile(string=html)

        messages = [unit[0] for unit in xhtml.get_units()]
        self.assertEqual(messages, [((TEXT, u'La playa'),)])
Exemplo n.º 7
0
    def test_case4(self):
        """Test translation of an element content"""
        string = (
            'msgctxt "paragraph"\n'
            'msgid "hello world"\n'
            'msgstr "hola mundo"\n')
        p = POFile(string=string)

        string = self.template % '<p>hello world</p>'
        source = XHTMLFile(string=string)

        string = source.translate(p)
        xhtml = XHTMLFile(string=string)

        messages = [unit[0] for unit in xhtml.get_units()]
        self.assertEqual(messages, [((TEXT, u'hola mundo'),)])
Exemplo n.º 8
0
    def get_namespace(self, resource, context):
        source = resource.get_resource('/ui/wiki/help.txt')
        source = source.to_str()

        overrides = dict(resource.overrides)
        overrides['stylesheet'] = ''
        html = publish_string(source, writer_name='html',
                               settings_overrides=overrides)
        document = XHTMLFile(string=html)
        events = document.get_body().get_content_elements()

        # Now remove some magic to make the help work like a wiki page
        source = source.split('.. XXX SPLIT HERE')[0]

        return {
            'help_source': source,
            'help_html': events,
        }
Exemplo n.º 9
0
    def test_random(self):
        """Test element content."""
        # The document
        doc = XHTMLFile(string=
            '<body xmlns="http://www.w3.org/1999/xhtml">\n'
            '  <p>this <em>word</em> is nice</p>\n'
            '  <a href="/"><img src="logo.png" /></a>\n'
            '  <p><em>hello world</em></p><br/>'
            '  bye <em>J. David Ibanez Palomar</em>\n'
            '</body>')

        messages = [unit[0] for unit in doc.get_units()]
        expected = [((TEXT, u'this '), (START_FORMAT, 1), (TEXT, u'word'),
                     (END_FORMAT, 1), (TEXT, u' is nice')),
                    ((TEXT, u'hello world'),), ((TEXT, u'bye '),
                     (START_FORMAT, 6), (TEXT, u'J. David Ibanez Palomar'),
                     (END_FORMAT, 6))]

        self.assertEqual(messages, expected)
Exemplo n.º 10
0
    def test_paragraph(self):
        """Test formatted paragraph"""
        doc = XHTMLFile(string=
            '<p xmlns="http://www.w3.org/1999/xhtml">\n'
            'The Mozilla project maintains <em>choice</em> and\n'
            '<em>innovation</em> on the Internet. Developing the\n'
            'acclaimed, <em>open source</em>, <b>Mozilla 1.6</b>.\n'
            '</p>')

        messages = [unit[0] for unit in doc.get_units()]
        expected = [((TEXT, u'The Mozilla project maintains '),
                     (START_FORMAT, 1), (TEXT, u'choice'), (END_FORMAT, 1),
                     (TEXT, u' and '), (START_FORMAT, 2),
                     (TEXT, u'innovation'), (END_FORMAT, 2),
                     (TEXT, u' on the Internet.')),
                    ((TEXT, u'Developing the acclaimed, '),
                     (START_FORMAT, 3), (TEXT, u'open source'),
                     (END_FORMAT, 3), (TEXT, u', '), (START_FORMAT, 4),
                     (TEXT, u'Mozilla 1.6'), (END_FORMAT, 4), (TEXT, u'.'))]
        self.assertEqual(messages, expected)
Exemplo n.º 11
0
    def test_table(self):
        doc = XHTMLFile(string=
            '<table xmlns="http://www.w3.org/1999/xhtml">\n'
            '  <tr>\n'
            '    <th>Title</th>\n'
            '    <th>Size</th>\n'
            '  </tr>\n'
            '  <tr>\n'
            '    <td>The good, the bad and the ugly</td>\n'
            '    <td>looong</td>\n'
            '  </tr>\n'
            '  <tr>\n'
            '    <td>Love story</td>\n'
            '    <td>even longer</td>\n'
            '  </tr>\n'
            '</table>')

        messages = [unit[0] for unit in doc.get_units()]
        expected = [((TEXT, u'Title'),), ((TEXT, u'Size'),),
                    ((TEXT, u'The good, the bad and the ugly'),),
                    ((TEXT, u'looong'),), ((TEXT, u'Love story'),),
                    ((TEXT, u'even longer'),)]

        self.assertEqual(messages, expected)
Exemplo n.º 12
0
 def filter(path, mimetype, body):
     # HTML
     if mimetype == 'text/html':
         source = XHTMLFile(string=body)
         target = XHTMLFile()
         elem = get_element(source.events, 'div', **{'class': 'body'})
         if not elem:
             print 'E', path
             return None
         elements = elem.get_content_elements()
         elements = rewrite_uris(elements, rewrite)
         elements = list(elements)
         target.set_body(elements)
         return target.to_str()
     # Skip
     elif mimetype in skip:
         return None
     # Keep
     elif mimetype in keep:
         return body
     # Unknown
     else:
         print 'X', path, mimetype
         return body
Exemplo n.º 13
0
 def filter(path, mimetype, body):
     # HTML
     if mimetype == "text/html":
         source = XHTMLFile(string=body)
         target = XHTMLFile()
         elem = get_element(source.events, "div", **{"class": "body"})
         if not elem:
             print "E", path
             return None
         elements = elem.get_content_elements()
         elements = rewrite_uris(elements, rewrite)
         elements = list(elements)
         target.set_body(elements)
         return target.to_str()
     # Skip
     elif mimetype in skip:
         return None
     # Keep
     elif mimetype in keep:
         return body
     # Unknown
     else:
         print "X", path, mimetype
         return body