Example #1
0
def test_quotefordtd_unimplemented_cases():
    """Test unimplemented quoting DTD cases."""
    assert dtd.quotefordtd("Color & Light") == '"Color & Light"'
    assert dtd.quotefordtd("Color & █") == '"Color & █"'
    assert dtd.quotefordtd("Color&Light &red;") == '"Color&Light &red;"'
    assert dtd.quotefordtd("Color & Light; Yes") == '"Color & Light; Yes"'
    assert dtd.quotefordtd("Between <p> and </p>") == ('"Between &lt;p&gt; and'
                                                       ' &lt;/p&gt;"')
Example #2
0
def test_quotefordtd_unimplemented_cases():
    """Test unimplemented quoting DTD cases."""
    assert dtd.quotefordtd("Color & Light") == '"Color &amp; Light"'
    assert dtd.quotefordtd("Color & &block;") == '"Color &amp; &block;"'
    assert dtd.quotefordtd("Color&Light &red;") == '"Color&amp;Light &red;"'
    assert dtd.quotefordtd("Color & Light; Yes") == '"Color &amp; Light; Yes"'
    assert dtd.quotefordtd("Between <p> and </p>") == ('"Between &lt;p&gt; and'
                                                       ' &lt;/p&gt;"')
Example #3
0
def applytranslation(entity, dtdunit, inputunit, mixedentities):
    """applies the translation for entity in the po unit to the dtd unit"""
    # this converts the po-style string to a dtd-style string
    unquotedstr = inputunit.target
    # check there aren't missing entities...
    if len(unquotedstr.strip()) == 0:
        return
    # handle mixed entities
    for labelsuffix in dtd.labelsuffixes:
        if entity.endswith(labelsuffix):
            if entity in mixedentities:
                unquotedstr, akey = accesskey.extract(unquotedstr)
                break
    else:
        for akeytype in dtd.accesskeysuffixes:
            if entity.endswith(akeytype):
                if entity in mixedentities:
                    label, unquotedstr = accesskey.extract(unquotedstr)
                    if not unquotedstr:
                        warnings.warn("Could not find accesskey for %s" %
                                      entity)
                    else:
                        original = dtd.unquotefromdtd(dtdunit.definition)
                        # For the sake of diffs we keep the case of the
                        # accesskey the same if we know the translation didn't
                        # change. Casing matters in XUL.
                        if unquotedstr == dtdunit.source and original.lower(
                        ) == unquotedstr.lower():
                            if original.isupper():
                                unquotedstr = unquotedstr.upper()
                            elif original.islower():
                                unquotedstr = unquotedstr.lower()
    if len(unquotedstr) > 0:
        dtdunit.definition = dtd.quotefordtd(
            dtd.removeinvalidamps(entity, unquotedstr))
Example #4
0
 def convertstrings(self, inputunit, dtdunit):
     if inputunit.istranslated():
         unquoted = inputunit.target
     else:
         unquoted = inputunit.source
     dtdunit.definition = dtd.quotefordtd(
         dtd.removeinvalidamps(dtdunit.entity, unquoted))
Example #5
0
def applytranslation(entity, dtdunit, inputunit, mixedentities):
    """applies the translation for entity in the po unit to the dtd unit"""
    # this converts the po-style string to a dtd-style string
    unquotedstr = inputunit.target
    # check there aren't missing entities...
    if len(unquotedstr.strip()) == 0:
        return
    # handle mixed entities
    for labelsuffix in dtd.labelsuffixes:
        if entity.endswith(labelsuffix):
            if entity in mixedentities:
                unquotedstr, akey = accesskey.extract(unquotedstr)
                break
    else:
        for akeytype in dtd.accesskeysuffixes:
            if entity.endswith(akeytype):
                if entity in mixedentities:
                    label, unquotedstr = accesskey.extract(unquotedstr)
                    if not unquotedstr:
                        warnings.warn("Could not find accesskey for %s" % entity)
                    else:
                        original = dtd.unquotefromdtd(dtdunit.definition)
                        # For the sake of diffs we keep the case of the
                        # accesskey the same if we know the translation didn't
                        # change. Casing matters in XUL.
                        if unquotedstr == dtdunit.source and original.lower() == unquotedstr.lower():
                            if original.isupper():
                                unquotedstr = unquotedstr.upper()
                            elif original.islower():
                                unquotedstr = unquotedstr.lower()
    if len(unquotedstr) > 0:
        dtdunit.definition = dtd.quotefordtd(dtd.removeinvalidamps(entity, unquotedstr))
def test_roundtrip_quoting():
    specials = ['Fish & chips', 'five < six', 'six > five',
                'Use &nbsp;', 'Use &amp;nbsp;' 
                'A "solution"', "skop 'n bal", '"""', "'''",
                '\n', '\t', '\r',
                'Escape at end \\',
                '\\n', '\\t', '\\r', '\\"', '\r\n', '\\r\\n', '\\']
    for special in specials:
        quoted_special = dtd.quotefordtd(special)
        unquoted_special = dtd.unquotefromdtd(quoted_special)
        print "special: %r\nquoted: %r\nunquoted: %r\n" % (special, quoted_special, unquoted_special)
        assert special == unquoted_special
Example #7
0
def test_roundtrip_quoting():
    specials = [
        'Fish & chips', 'five < six', 'six > five', 'Use &nbsp;',
        'Use &amp;nbsp;'
        'A "solution"', "skop 'n bal", '"""', "'''", '\n', '\t', '\r',
        'Escape at end \\', '\\n', '\\t', '\\r', '\\"', '\r\n', '\\r\\n', '\\'
    ]
    for special in specials:
        quoted_special = dtd.quotefordtd(special)
        unquoted_special = dtd.unquotefromdtd(quoted_special)
        print "special: %r\nquoted: %r\nunquoted: %r\n" % (
            special, quoted_special, unquoted_special)
        assert special == unquoted_special
Example #8
0
def test_roundtrip_quoting():
    specials = [
        "Fish & chips",
        "five < six",
        "six > five",
        "Use &nbsp;",
        'Use &amp;nbsp;A "solution"',
        "skop 'n bal",
        '"""',
        "'''",
        "\n",
        "\t",
        "\r",
        "Escape at end \\",
        "",
        "\\n",
        "\\t",
        "\\r",
        '\\"',
        "\r\n",
        "\\r\\n",
        "\\",
        "Completed %S",
        "&blockAttackSites;",
        "&#x00A0;",
        "&intro-point2-a;",
        "&basePBMenu.label;",
        # "Don't buy",
        # "Don't \"buy\"",
        'A "thing"',
        '<a href="http',
    ]
    for special in specials:
        quoted_special = dtd.quotefordtd(special)
        unquoted_special = dtd.unquotefromdtd(quoted_special)
        print(
            "special: %r\nquoted: %r\nunquoted: %r\n"
            % (special, quoted_special, unquoted_special)
        )
        assert special == unquoted_special
Example #9
0
def test_roundtrip_quoting():
    specials = [
        'Fish & chips',
        'five < six',
        'six > five',
        'Use &nbsp;',
        'Use &amp;nbsp;A "solution"',
        "skop 'n bal",
        '"""',
        "'''",
        '\n',
        '\t',
        '\r',
        'Escape at end \\',
        '',
        '\\n',
        '\\t',
        '\\r',
        '\\"',
        '\r\n',
        '\\r\\n',
        '\\',
        "Completed %S",
        "&blockAttackSites;",
        "&#x00A0;",
        "&intro-point2-a;",
        "&basePBMenu.label;",
        #"Don't buy",
        #"Don't \"buy\"",
        "A \"thing\"",
        "<a href=\"http"
    ]
    for special in specials:
        quoted_special = dtd.quotefordtd(special)
        unquoted_special = dtd.unquotefromdtd(quoted_special)
        print("special: %r\nquoted: %r\nunquoted: %r\n" % (special,
                                                           quoted_special,
                                                           unquoted_special))
        assert special == unquoted_special
Example #10
0
def test_roundtrip_quoting():
    specials = [
        'Fish & chips',
        'five < six',
        'six > five',
        'Use &nbsp;',
        'Use &amp;nbsp;A "solution"',
        "skop 'n bal",
        '"""',
        "'''",
        '\n',
        '\t',
        '\r',
        'Escape at end \\',
        '',
        '\\n',
        '\\t',
        '\\r',
        '\\"',
        '\r\n',
        '\\r\\n',
        '\\',
        "Completed %S",
        "&blockAttackSites;",
        "&#x00A0;",
        "&intro-point2-a;",
        "&basePBMenu.label;",
        #"Don't buy",
        #"Don't \"buy\"",
        "A \"thing\"",
        "<a href=\"http"
    ]
    for special in specials:
        quoted_special = dtd.quotefordtd(special)
        unquoted_special = dtd.unquotefromdtd(quoted_special)
        print("special: %r\nquoted: %r\nunquoted: %r\n" % (special,
                                                           quoted_special,
                                                           unquoted_special))
        assert special == unquoted_special
Example #11
0
 def convertstrings(self, inputunit, dtdunit):
     if inputunit.istranslated():
         unquoted = inputunit.target
     else:
         unquoted = inputunit.source
     dtdunit.definition = dtd.quotefordtd(dtd.removeinvalidamps(dtdunit.entity, unquoted))
Example #12
0
def test_quotefordtd():
    """Test quoting DTD definitions"""
    assert dtd.quotefordtd('') == '""'
    assert dtd.quotefordtd("") == '""'
    assert dtd.quotefordtd("Completed %S") == '"Completed &#037;S"'
    assert dtd.quotefordtd("&blockAttackSites;") == '"&blockAttackSites;"'
    assert dtd.quotefordtd("&#x00A0;") == '"&#x00A0;"'
    assert dtd.quotefordtd("&intro-point2-a;") == '"&intro-point2-a;"'
    assert dtd.quotefordtd("&basePBMenu.label;") == '"&basePBMenu.label;"'
    # The ' character isn't escaped as &apos; since the " char isn't present.
    assert dtd.quotefordtd("Don't buy") == '"Don\'t buy"'
    # The ' character is escaped as &apos; because the " character is present.
    assert dtd.quotefordtd("Don't \"buy\"") == '"Don&apos;t &quot;buy&quot;"'
    assert dtd.quotefordtd("A \"thing\"") == '"A &quot;thing&quot;"'
    # The " character is not escaped when it indicates an attribute value.
    assert dtd.quotefordtd("<a href=\"http") == "'<a href=\"http'"
    # &amp;
    assert dtd.quotefordtd("Color & Light") == '"Color &amp; Light"'
    assert dtd.quotefordtd("Color & &block;") == '"Color &amp; &block;"'
    assert dtd.quotefordtd("Color&Light &red;") == '"Color&amp;Light &red;"'
    assert dtd.quotefordtd("Color & Light; Yes") == '"Color &amp; Light; Yes"'
Example #13
0
def test_quotefordtd_unimplemented_cases():
    """Test unimplemented quoting DTD cases."""
    assert dtd.quotefordtd("Between <p> and </p>") == ('"Between &lt;p&gt; and'
                                                       ' &lt;/p&gt;"')
Example #14
0
 def tester(raw_original, dtd_ready_result):
     #print dtd.quotefordtd(raw_original)
     assert dtd.quotefordtd(raw_original) == dtd_ready_result
     #print dtd.unquotefromdtd(dtd_ready_result)
     assert dtd.unquotefromdtd(dtd_ready_result) == raw_original
Example #15
0
def test_quotefordtd():
    """Test quoting DTD definitions"""
    assert dtd.quotefordtd("") == '""'
    assert dtd.quotefordtd("") == '""'
    assert dtd.quotefordtd("Completed %S") == '"Completed &#037;S"'
    assert dtd.quotefordtd("&blockAttackSites;") == '"&blockAttackSites;"'
    assert dtd.quotefordtd("&#x00A0;") == '"&#x00A0;"'
    assert dtd.quotefordtd("&intro-point2-a;") == '"&intro-point2-a;"'
    assert dtd.quotefordtd("&basePBMenu.label;") == '"&basePBMenu.label;"'
    # The ' character isn't escaped as &apos; since the " char isn't present.
    assert dtd.quotefordtd("Don't buy") == '"Don\'t buy"'
    # The ' character is escaped as &apos; because the " character is present.
    assert dtd.quotefordtd('Don\'t "buy"') == '"Don&apos;t &quot;buy&quot;"'
    assert dtd.quotefordtd('A "thing"') == '"A &quot;thing&quot;"'
    # The " character is not escaped when it indicates an attribute value.
    assert dtd.quotefordtd('<a href="http') == "'<a href=\"http'"
    # &amp;
    assert dtd.quotefordtd("Color & Light") == '"Color &amp; Light"'
    assert dtd.quotefordtd("Color & &block;") == '"Color &amp; &block;"'
    assert dtd.quotefordtd("Color&Light &red;") == '"Color&amp;Light &red;"'
    assert dtd.quotefordtd("Color & Light; Yes") == '"Color &amp; Light; Yes"'
Example #16
0
def test_quotefordtd_unimplemented_cases():
    """Test unimplemented quoting DTD cases."""
    assert dtd.quotefordtd("Between <p> and </p>") == ('"Between &lt;p&gt; and'
                                                       ' &lt;/p&gt;"')
Example #17
0
 def tester(raw_original, dtd_ready_result):
     #print dtd.quotefordtd(raw_original)
     assert dtd.quotefordtd(raw_original) == dtd_ready_result
     #print dtd.unquotefromdtd(dtd_ready_result)
     assert dtd.unquotefromdtd(dtd_ready_result) == raw_original