• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python dtd.unquotefromdtd函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中translate.storage.dtd.unquotefromdtd函数的典型用法代码示例。如果您正苦于以下问题:Python unquotefromdtd函数的具体用法?Python unquotefromdtd怎么用?Python unquotefromdtd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了unquotefromdtd函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: convertmixedunit

 def convertmixedunit(self, labeldtd, accesskeydtd):
     labelpo = self.convertunit(labeldtd)
     accesskeypo = self.convertunit(accesskeydtd)
     if labelpo is None:
         return accesskeypo
     if accesskeypo is None:
         return labelpo
     thepo = po.pounit(encoding="UTF-8")
     thepo.addlocations(labelpo.getlocations())
     thepo.addlocations(accesskeypo.getlocations())
     thepo.msgidcomment = thepo._extract_msgidcomments() + labelpo._extract_msgidcomments()
     thepo.msgidcomment = thepo._extract_msgidcomments() + accesskeypo._extract_msgidcomments()
     thepo.addnote(labelpo.getnotes("developer"), "developer")
     thepo.addnote(accesskeypo.getnotes("developer"), "developer")
     thepo.addnote(labelpo.getnotes("translator"), "translator")
     thepo.addnote(accesskeypo.getnotes("translator"), "translator")
     # redo the strings from original dtd...
     label = dtd.unquotefromdtd(labeldtd.definition).decode('UTF-8')
     accesskey = dtd.unquotefromdtd(accesskeydtd.definition).decode('UTF-8')
     label = accesskeyfn.combine(label, accesskey)
     if label is None:
         return None
     thepo.source = label
     thepo.target = ""
     return thepo
开发者ID:AlexArgus,项目名称:affiliates-lib,代码行数:25,代码来源:dtd2po.py


示例2: applytranslation

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))
开发者ID:AlexArgus,项目名称:affiliates-lib,代码行数:32,代码来源:po2dtd.py


示例3: openDTD

def openDTD(file):
	f = open(file, "r")
	dtdobj = dtd.dtdfile(f)
	f.close()
	dtdentries = dtdobj.units
	d = OrderedDict()
	for i in dtdentries:
		if d.has_key(i.entity): print "Duplicate entry: %s" %i.entity
		else: d[i.entity] = dtd.unquotefromdtd(i.definition)
开发者ID:gialloporpora,项目名称:yellowpy,代码行数:9,代码来源:dtd2lang.py


示例4: test_invalid_quoting

 def test_invalid_quoting(self):
     """checks that invalid quoting doesn't work - quotes can't be reopened"""
     # TODO: we should rather raise an error
     dtdsource = '<!ENTITY test.me "bananas for sale""room">\n'
     assert dtd.unquotefromdtd(dtdsource[dtdsource.find('"'):]) == 'bananas for sale'
     dtdfile = self.dtdparse(dtdsource)
     assert len(dtdfile.units) == 1
     dtdunit = dtdfile.units[0]
     assert dtdunit.definition == '"bananas for sale"'
     assert dtdfile.serialize() == '<!ENTITY test.me "bananas for sale">\n'
开发者ID:Jobava,项目名称:translate-toolkit,代码行数:10,代码来源:test_dtd.py


示例5: test_accesskey_types

 def test_accesskey_types(self):
     """tests that we can detect the various styles of accesskey"""
     simplepo_template = '''#: simple.%s\n#: simple.%s\nmsgid "&File"\nmsgstr "F&aele"\n'''
     simpledtd_template = '''<!ENTITY simple.%s "File">\n<!ENTITY simple.%s "a">'''
     for label in ("label", "title"):
         for accesskey in ("accesskey", "accessKey", "akey"):
             simplepo = simplepo_template % (label, accesskey)
             simpledtd = simpledtd_template % (label, accesskey)
             dtdfile = self.merge2dtd(simpledtd, simplepo)
             dtdfile.makeindex()
             assert dtd.unquotefromdtd(dtdfile.index["simple.%s" % accesskey].definition) == "a"
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:11,代码来源:test_po2dtd.py


示例6: test_roundtrip_quoting

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
开发者ID:AndreasEisele,项目名称:wikitrans-pootle,代码行数:12,代码来源:test_dtd.py


示例7: convertstrings

 def convertstrings(self, thedtd, thepo):
     # extract the string, get rid of quoting
     unquoted = dtd.unquotefromdtd(thedtd.definition).replace("\r", "")
     # escape backslashes... but not if they're for a newline
     # unquoted = unquoted.replace("\\", "\\\\").replace("\\\\n", "\\n")
     # now split the string into lines and quote them
     lines = unquoted.split('\n')
     while lines and not lines[0].strip():
         del lines[0]
     while lines and not lines[-1].strip():
         del lines[-1]
     # quotes have been escaped already by escapeforpo, so just add the start and end quotes
     if len(lines) > 1:
         thepo.source = "\n".join([lines[0].rstrip() + ' '] + \
                 [line.strip() + ' ' for line in lines[1:-1]] + \
                 [lines[-1].lstrip()])
     elif lines:
         thepo.source = lines[0]
     else:
         thepo.source = ""
     thepo.target = ""
开发者ID:AlexArgus,项目名称:affiliates-lib,代码行数:21,代码来源:dtd2po.py


示例8: test_roundtrip_quoting

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
开发者ID:Jobava,项目名称:translate-toolkit,代码行数:39,代码来源:test_dtd.py


示例9: test_accesskeycase

 def test_accesskeycase(self):
     """tests that access keys come out with the same case as the original, regardless"""
     simplepo_template = '''#: simple.label\n#: simple.accesskey\nmsgid "%s"\nmsgstr "%s"\n'''
     simpledtd_template = '''<!ENTITY simple.label "Simple %s">\n<!ENTITY simple.accesskey "%s">'''
     possibilities = [
             #(en label, en akey, en po, af po, af label, expected af akey)
             ("Sis", "S", "&Sis", "&Sies", "Sies", "S"),
             ("Sis", "s", "Si&s", "&Sies", "Sies", "S"),
             ("Sis", "S", "&Sis", "Sie&s", "Sies", "s"),
             ("Sis", "s", "Si&s", "Sie&s", "Sies", "s"),
             # untranslated strings should have the casing of the source
             ("Sis", "S", "&Sis", "", "Sis", "S"),
             ("Sis", "s", "Si&s", "", "Sis", "s"),
             ("Suck", "S", "&Suck", "", "Suck", "S"),
             ("Suck", "s", "&Suck", "", "Suck", "s"),
             ]
     for (en_label, en_akey, po_source, po_target, target_label, target_akey) in possibilities:
         simplepo = simplepo_template % (po_source, po_target)
         simpledtd = simpledtd_template % (en_label, en_akey)
         dtdfile = self.merge2dtd(simpledtd, simplepo)
         dtdfile.makeindex()
         accel = dtd.unquotefromdtd(dtdfile.index["simple.accesskey"].definition)
         assert accel == target_akey
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:23,代码来源:test_po2dtd.py


示例10: test_unquotefromdtd_unimplemented_cases

def test_unquotefromdtd_unimplemented_cases():
    """Test unimplemented unquoting DTD cases."""
    assert dtd.unquotefromdtd('"&lt;p&gt; and &lt;/p&gt;"') == "<p> and </p>"
开发者ID:Jobava,项目名称:translate-toolkit,代码行数:3,代码来源:test_dtd.py


示例11: test_unquotefromdtd

def test_unquotefromdtd():
    """Test unquoting DTD definitions"""
    # %
    assert dtd.unquotefromdtd('"Completed &#037;S"') == "Completed %S"
    assert dtd.unquotefromdtd('"Completed &#37;S"') == "Completed %S"
    assert dtd.unquotefromdtd('"Completed &#x25;S"') == "Completed %S"
    # &entity;
    assert dtd.unquotefromdtd('"Color&light &block;"') == "Color&light &block;"
    assert dtd.unquotefromdtd('"Color & Light; Red"') == "Color & Light; Red"
    assert dtd.unquotefromdtd('"&blockAttackSites;"') == "&blockAttackSites;"
    assert dtd.unquotefromdtd('"&intro-point2-a;"') == "&intro-point2-a;"
    assert dtd.unquotefromdtd('"&basePBMenu.label"') == "&basePBMenu.label"
    # &amp;
    assert dtd.unquotefromdtd('"Color &amp; Light"') == "Color & Light"
    assert dtd.unquotefromdtd('"Color &amp; &block;"') == "Color & &block;"
    # nbsp
    assert dtd.unquotefromdtd('"&#x00A0;"') == "&#x00A0;"
    # '
    assert dtd.unquotefromdtd("'Don&apos;t buy'") == "Don't buy"
    # "
    assert dtd.unquotefromdtd("'Don&apos;t &quot;buy&quot;'") == 'Don\'t "buy"'
    assert dtd.unquotefromdtd('"A &quot;thing&quot;"') == "A \"thing\""
    assert dtd.unquotefromdtd('"A &#x0022;thing&#x0022;"') == "A \"thing\""
    assert dtd.unquotefromdtd("'<a href=\"http'") == "<a href=\"http"
    # other chars
    assert dtd.unquotefromdtd('"&#187;"') == u"»"
开发者ID:Jobava,项目名称:translate-toolkit,代码行数:26,代码来源:test_dtd.py


示例12: test_unquotefromdtd_unimplemented_cases

def test_unquotefromdtd_unimplemented_cases():
    """Test unimplemented unquoting DTD cases."""
    assert dtd.unquotefromdtd('"Color &amp; Light"') == "Color & Light"
    assert dtd.unquotefromdtd('"Color &amp; &block;"') == "Color & &block;"
    assert dtd.unquotefromdtd('"&lt;p&gt; and &lt;/p&gt;"') == "<p> and </p>"
开发者ID:anderson916,项目名称:translate,代码行数:5,代码来源:test_dtd.py


示例13: test_unquotefromdtd

def test_unquotefromdtd():
    """Test unquoting DTD definitions"""
    assert dtd.unquotefromdtd('"Completed &#037;S"') == "Completed %S"
    assert dtd.unquotefromdtd('"Completed &#37;S"') == "Completed %S"
    assert dtd.unquotefromdtd('"Completed &#x25;S"') == "Completed %S"
    assert dtd.unquotefromdtd('"Color&light &block;"') == "Color&light &block;"
    assert dtd.unquotefromdtd('"Color & Light; Red"') == "Color & Light; Red"
    assert dtd.unquotefromdtd('"&blockAttackSites;"') == "&blockAttackSites;"
    assert dtd.unquotefromdtd('"&#x00A0;"') == "&#x00A0;"
    assert dtd.unquotefromdtd('"&intro-point2-a;"') == "&intro-point2-a;"
    assert dtd.unquotefromdtd('"&basePBMenu.label"') == "&basePBMenu.label"
    assert dtd.unquotefromdtd("'Don&apos;t buy'") == "Don't buy"
    assert dtd.unquotefromdtd("'Don&apos;t &quot;buy&quot;'") == 'Don\'t "buy"'
    assert dtd.unquotefromdtd('"A &quot;thing&quot;"') == "A \"thing\""
    assert dtd.unquotefromdtd("'<a href=\"http'") == "<a href=\"http"
开发者ID:chhitz,项目名称:translate,代码行数:15,代码来源:test_dtd.py


示例14: tester

 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
开发者ID:AshishNamdev,项目名称:verbatim,代码行数:5,代码来源:test_dtd.py



注:本文中的translate.storage.dtd.unquotefromdtd函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python factory.getclass函数代码示例发布时间:2022-05-27
下一篇:
Python dtd.dtdfile函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap