示例#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
示例#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
示例#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>"']
示例#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>"']
示例#5
0
文件: test_po.py 项目: onia/translate
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
示例#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
示例#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\\"."'
        ]
示例#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\\"."',
        ]
示例#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\\"."']
示例#10
0
文件: cpo.py 项目: flyeven/translate
def quoteforpo(text):
    return pypo.quoteforpo(text)