Example #1
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",
        "\\n",
        "\\t",
        "\\r",
        '\\"',
        "\r\n",
        "\\r\\n",
        "\\",
    ]
    for special in specials:
        quoted_special = pypo.quoteforpo(special)
        unquoted_special = pypo.unquotefrompo(quoted_special)
        print("special: %r\nquoted: %r\nunquoted: %r\n" %
              (special, quoted_special, unquoted_special))
        assert special == unquoted_special
Example #2
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",
        "\\n",
        "\\t",
        "\\r",
        '\\"',
        "\r\n",
        "\\r\\n",
        "\\",
    ]
    for special in specials:
        quoted_special = pypo.quoteforpo(special)
        unquoted_special = pypo.unquotefrompo(quoted_special)
        print("special: %r\nquoted: %r\nunquoted: %r\n" % (special, quoted_special, unquoted_special))
        assert special == unquoted_special
Example #3
0
 def test_quoteforpo(self):
     """Special escaping routine to manage newlines and linewrap in PO"""
     # Simple case
     assert pypo.quoteforpo("Some test") == ['"Some test"']
     # Newline handling
     assert pypo.quoteforpo("One\nTwo\n") == ['""', '"One\\n"', '"Two\\n"']
     # First line wrapping
     assert pypo.quoteforpo("A very long sentence. A very long sentence. A very long sentence. A ver") == [
         '"A very long sentence. A very long sentence. A very long sentence. A ver"']
     assert pypo.quoteforpo("A very long sentence. A very long sentence. A very long sentence. A very") == [
         '""',
         '"A very long sentence. A very long sentence. A very long sentence. A very"']
     # Long line with a newline
     assert pypo.quoteforpo("A very long sentence. A very long sentence. A very long sentence. A very lon\n") == [
         '""', '"A very long sentence. A very long sentence. A very long sentence. A very "', '"lon\\n"']
     assert pypo.quoteforpo("A very long sentence. A very long sentence. A very long sentence. A very 123\n") == [
         '""', '"A very long sentence. A very long sentence. A very long sentence. A very "', '"123\\n"']
     # Special 77 char failure.
     assert pypo.quoteforpo("Ukuba uyayiqonda into eyenzekayo, \nungaxelela i-&brandShortName; ukuba iqalise ukuthemba ufaniso lwale sayithi. \n<b>Nokuba uyayithemba isayithi, le mposiso isenokuthetha ukuba   kukho umntu \nobhucabhuca ukudibanisa kwakho.</b>") == [
         '""',
         '"Ukuba uyayiqonda into eyenzekayo, \\n"',
         '"ungaxelela i-&brandShortName; ukuba iqalise ukuthemba ufaniso lwale sayithi. "',
         '"\\n"',
         '"<b>Nokuba uyayithemba isayithi, le mposiso isenokuthetha ukuba   kukho umntu "',
         '"\\n"',
         '"obhucabhuca ukudibanisa kwakho.</b>"']
Example #4
0
 def test_quoteforpo(self):
     """Special escaping routine to manage newlines and linewrap in PO"""
     # Simple case
     assert pypo.quoteforpo("Some test") == ['"Some test"']
     # Newline handling
     assert pypo.quoteforpo("One\nTwo\n") == ['""', '"One\\n"', '"Two\\n"']
     # First line wrapping
     assert pypo.quoteforpo("A very long sentence. A very long sentence. A very long sentence. A ver") == \
                          ['"A very long sentence. A very long sentence. A very long sentence. A ver"']
     assert pypo.quoteforpo("A very long sentence. A very long sentence. A very long sentence. A very") == \
                           ['""',
                            '"A very long sentence. A very long sentence. A very long sentence. A very"']
     # Long line with a newline
     assert pypo.quoteforpo("A very long sentence. A very long sentence. A very long sentence. A very lon\n") == \
                          ['""', '"A very long sentence. A very long sentence. A very long sentence. A very "', '"lon\\n"']
     assert pypo.quoteforpo("A very long sentence. A very long sentence. A very long sentence. A very 123\n") == \
                          ['""', '"A very long sentence. A very long sentence. A very long sentence. A very "', '"123\\n"']
     # Special 77 char failure.
     assert pypo.quoteforpo("Ukuba uyayiqonda into eyenzekayo, \nungaxelela i-&brandShortName; ukuba iqalise ukuthemba ufaniso lwale sayithi. \n<b>Nokuba uyayithemba isayithi, le mposiso isenokuthetha ukuba   kukho umntu \nobhucabhuca ukudibanisa kwakho.</b>") == \
                          ['""',
                           '"Ukuba uyayiqonda into eyenzekayo, \\n"',
                           '"ungaxelela i-&brandShortName; ukuba iqalise ukuthemba ufaniso lwale sayithi. "',
                           '"\\n"',
                           '"<b>Nokuba uyayithemba isayithi, le mposiso isenokuthetha ukuba   kukho umntu "',
                           '"\\n"',
                           '"obhucabhuca ukudibanisa kwakho.</b>"']
Example #5
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',
                '\\n', '\\t', '\\r', '\\"', '\r\n', '\\r\\n', '\\']
    for special in specials:
        quoted_special = pypo.quoteforpo(special)
        unquoted_special = pypo.unquotefrompo(quoted_special)
        print("special: %r\nquoted: %r\nunquoted: %r\n" % (special, quoted_special, unquoted_special))
        assert special == unquoted_special
Example #6
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', 
                '\\n', '\\t', '\\r', '\\"', '\r\n', '\\r\\n', '\\']
    for special in specials:
        quoted_special = pypo.quoteforpo(special)
        unquoted_special = pypo.unquotefrompo(quoted_special)
        print "special: %r\nquoted: %r\nunquoted: %r\n" % (special, quoted_special, unquoted_special)
        assert special == unquoted_special
Example #7
0
    def test_quoteforpo_escaped_quotes(self):
        """Ensure that we don't break \" in two when wrapping

        See :issue:`3140`
        """
        assert pypo.quoteforpo(
            '''You can get a copy of your Recovery Key by going to &syncBrand.shortName.label; Options on your other device, and selecting  "My Recovery Key" under "Manage Account".'''
        ) == [
            u'""', u'"You can get a copy of your Recovery Key by going to "',
            u'"&syncBrand.shortName.label; Options on your other device, and selecting  \\""',
            u'"My Recovery Key\\" under \\"Manage Account\\"."'
        ]
Example #8
0
    def test_quoteforpo_escaped_quotes():
        """Ensure that we don't break \" in two when wrapping

        See :issue:`3140`
        """
        assert pypo.quoteforpo(
            """You can get a copy of an recovery key by going to "My Recovery Key" under "Manage Account"."""
        ) == [
            '""',
            '"You can get a copy of an recovery key by going to \\"My Recovery Key\\" under "',
            '"\\"Manage Account\\"."',
        ]
Example #9
0
    def test_quoteforpo_escaped_quotes(self):
        """Ensure that we don't break \" in two when wrapping

        See :issue:`3140`
        """
        assert pypo.quoteforpo('''You can get a copy of your Recovery Key by going to &syncBrand.shortName.label; Options on your other device, and selecting  "My Recovery Key" under "Manage Account".''') == [u'""', u'"You can get a copy of your Recovery Key by going to "', u'"&syncBrand.shortName.label; Options on your other device, and selecting  \\""', u'"My Recovery Key\\" under \\"Manage Account\\"."']
Example #10
0
def quoteforpo(text):
    return pypo.quoteforpo(text)