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 <p> and' ' </p>"')
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 convertstrings(self, inputunit, dtdunit): if inputunit.istranslated(): unquoted = inputunit.target else: unquoted = inputunit.source dtdunit.definition = dtd.quotefordtd( dtd.removeinvalidamps(dtdunit.entity, unquoted))
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 ', 'Use &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
def test_roundtrip_quoting(): specials = [ 'Fish & chips', 'five < six', 'six > five', 'Use ', 'Use &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
def test_roundtrip_quoting(): specials = [ "Fish & chips", "five < six", "six > five", "Use ", 'Use &nbsp;A "solution"', "skop 'n bal", '"""', "'''", "\n", "\t", "\r", "Escape at end \\", "", "\\n", "\\t", "\\r", '\\"', "\r\n", "\\r\\n", "\\", "Completed %S", "&blockAttackSites;", " ", "&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
def test_roundtrip_quoting(): specials = [ 'Fish & chips', 'five < six', 'six > five', 'Use ', 'Use &nbsp;A "solution"', "skop 'n bal", '"""', "'''", '\n', '\t', '\r', 'Escape at end \\', '', '\\n', '\\t', '\\r', '\\"', '\r\n', '\\r\\n', '\\', "Completed %S", "&blockAttackSites;", " ", "&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
def convertstrings(self, inputunit, dtdunit): if inputunit.istranslated(): unquoted = inputunit.target else: unquoted = inputunit.source dtdunit.definition = dtd.quotefordtd(dtd.removeinvalidamps(dtdunit.entity, unquoted))
def test_quotefordtd(): """Test quoting DTD definitions""" assert dtd.quotefordtd('') == '""' assert dtd.quotefordtd("") == '""' assert dtd.quotefordtd("Completed %S") == '"Completed %S"' assert dtd.quotefordtd("&blockAttackSites;") == '"&blockAttackSites;"' assert dtd.quotefordtd(" ") == '" "' assert dtd.quotefordtd("&intro-point2-a;") == '"&intro-point2-a;"' assert dtd.quotefordtd("&basePBMenu.label;") == '"&basePBMenu.label;"' # The ' character isn't escaped as ' since the " char isn't present. assert dtd.quotefordtd("Don't buy") == '"Don\'t buy"' # The ' character is escaped as ' because the " character is present. assert dtd.quotefordtd("Don't \"buy\"") == '"Don't "buy""' assert dtd.quotefordtd("A \"thing\"") == '"A "thing""' # The " character is not escaped when it indicates an attribute value. assert dtd.quotefordtd("<a href=\"http") == "'<a href=\"http'" # & 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"'
def test_quotefordtd_unimplemented_cases(): """Test unimplemented quoting DTD cases.""" assert dtd.quotefordtd("Between <p> and </p>") == ('"Between <p> and' ' </p>"')
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
def test_quotefordtd(): """Test quoting DTD definitions""" assert dtd.quotefordtd("") == '""' assert dtd.quotefordtd("") == '""' assert dtd.quotefordtd("Completed %S") == '"Completed %S"' assert dtd.quotefordtd("&blockAttackSites;") == '"&blockAttackSites;"' assert dtd.quotefordtd(" ") == '" "' assert dtd.quotefordtd("&intro-point2-a;") == '"&intro-point2-a;"' assert dtd.quotefordtd("&basePBMenu.label;") == '"&basePBMenu.label;"' # The ' character isn't escaped as ' since the " char isn't present. assert dtd.quotefordtd("Don't buy") == '"Don\'t buy"' # The ' character is escaped as ' because the " character is present. assert dtd.quotefordtd('Don\'t "buy"') == '"Don't "buy""' assert dtd.quotefordtd('A "thing"') == '"A "thing""' # The " character is not escaped when it indicates an attribute value. assert dtd.quotefordtd('<a href="http') == "'<a href=\"http'" # & 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"'