当前位置: 首页>>代码示例>>Python>>正文


Python string.translate方法代码示例

本文整理汇总了Python中string.translate方法的典型用法代码示例。如果您正苦于以下问题:Python string.translate方法的具体用法?Python string.translate怎么用?Python string.translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在string的用法示例。


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

示例1: derot

# 需要导入模块: import string [as 别名]
# 或者: from string import translate [as 别名]
def derot(xset, hset, src):
    xset = eval(xset)
    hset = eval(hset)

    import string
    o = ''
    u = ''
    il = 0
    for first in hset:
        u += first
        o += xset[il]
        il += 1
    rot13 = string.maketrans(o, u)
    link = string.translate(src, rot13)
    xbmc.log('@#@DEROT-LINK: %s' % link, xbmc.LOGNOTICE)
    return link 
开发者ID:bugatsinho,项目名称:bugatsinho.github.io,代码行数:18,代码来源:sport365.py

示例2: dump_dirs

# 需要导入模块: import string [as 别名]
# 或者: from string import translate [as 别名]
def dump_dirs (self, msg):
        if DEBUG:
            from distutils.fancy_getopt import longopt_xlate
            print msg + ":"
            for opt in self.user_options:
                opt_name = opt[0]
                if opt_name[-1] == "=":
                    opt_name = opt_name[0:-1]
                if opt_name in self.negative_opt:
                    opt_name = string.translate(self.negative_opt[opt_name],
                                                longopt_xlate)
                    val = not getattr(self, opt_name)
                else:
                    opt_name = string.translate(opt_name, longopt_xlate)
                    val = getattr(self, opt_name)
                print "  %s: %s" % (opt_name, val) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:18,代码来源:install.py

示例3: do_simple_substitution

# 需要导入模块: import string [as 别名]
# 或者: from string import translate [as 别名]
def do_simple_substitution(ciphertext, pt_charset, ct_charset):
   '''
   Perform simple substitution based on character sets

   Simplifies the use of string.translate(). If, for instance, you wish to
   transform a ciphertext where 'e' is swapped with 't', you would call this
   function like so:

   do_simple_substitution('Simplt subeieueion ciphtrs art silly','et','te')
   
   ciphertext - A string to translate
   pt_charset - The character set of the plaintext, usually 'abcdefghijk...xyz'
   ct_charset - The character set of the ciphertext
   '''
   #translate ciphertext to plaintext using mapping
   return string.translate(ciphertext, string.maketrans(ct_charset, pt_charset))


# TODO: Implement chi square 
开发者ID:nccgroup,项目名称:featherduster,代码行数:21,代码来源:helpers.py

示例4: morse_decode

# 需要导入模块: import string [as 别名]
# 或者: from string import translate [as 别名]
def morse_decode(text, dot='.', dash='-', space=' '):
   '''
   Decodes a Morse encoded message. Optionally, you can provide an alternate
   single character for dot, dash, and space.

   Parameters:
   text - (string) A message to decode
   dot - (char) An alternate dot char
   dash - (char) An alternate dash char
   space - (char) A char to split the text on
   '''
   inverse_morse_table = map(lambda (x,y): (y,x), morse_table.items())
   dot_dash_trans = string.maketrans('.-', dot+dash)
   inverse_morse_table = [(string.translate(x,dot_dash_trans), y) for (x,y) in inverse_morse_table]
   inverse_morse_table = dict(inverse_morse_table)
   return ''.join([inverse_morse_table[char] for char in text.split(space) if char in inverse_morse_table.keys()]) 
开发者ID:nccgroup,项目名称:featherduster,代码行数:18,代码来源:classical.py

示例5: _normalize

# 需要导入模块: import string [as 别名]
# 或者: from string import translate [as 别名]
def _normalize(title, charset='utf-8'):
    '''Removes all accents and illegal chars for titles from the String'''
    if isinstance(title, unicode):
        title = string.translate(title, allchars, deletechars)
        try:
            title = title.encode("utf-8")
            title = normalize('NFKD', title).encode('ASCII', 'ignore')
        except UnicodeEncodeError:
            logger.error("Error de encoding")
    else:
        title = string.translate(title, allchars, deletechars)
        try:
            # iso-8859-1
            title = title.decode(charset).encode('utf-8')
            title = normalize('NFKD', unicode(title, 'utf-8'))
            title = title.encode('ASCII', 'ignore')
        except UnicodeEncodeError:
            logger.error("Error de encoding")
    return title

    # 
开发者ID:alfa-addon,项目名称:addon,代码行数:23,代码来源:subtitletools.py

示例6: b64sub

# 需要导入模块: import string [as 别名]
# 或者: from string import translate [as 别名]
def b64sub(s, key):
    """
    "Encryption" method that base64 encodes a given string, 
    then does a randomized alphabetic letter substitution.
    """
    enc_tbl = string.maketrans(string.ascii_letters, key)
    return string.translate(base64.b64encode(s), enc_tbl) 
开发者ID:HarmJ0y,项目名称:Arya,代码行数:9,代码来源:arya.py

示例7: update

# 需要导入模块: import string [as 别名]
# 或者: from string import translate [as 别名]
def update(self, data):
        if self._op:
            return translate(data, self._encrypt_table)
        else:
            return translate(data, self._decrypt_table) 
开发者ID:ntfreedom,项目名称:neverendshadowsocks,代码行数:7,代码来源:table.py

示例8: test_bad_str_translate_call_string_literal

# 需要导入模块: import string [as 别名]
# 或者: from string import translate [as 别名]
def test_bad_str_translate_call_string_literal(self):
        node = astroid.extract_node(
            """
         foobar.translate(None, 'abc123') #@
         """
        )
        message = testutils.Message(
            "deprecated-str-translate-call", node=node, confidence=INFERENCE_FAILURE
        )
        with self.assertAddsMessages(message):
            self.checker.visit_call(node) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:13,代码来源:unittest_checker_python3.py

示例9: test_bad_str_translate_call_variable

# 需要导入模块: import string [as 别名]
# 或者: from string import translate [as 别名]
def test_bad_str_translate_call_variable(self):
        node = astroid.extract_node(
            """
         def raz(foobar):
           foobar.translate(None, 'hello') #@
         """
        )
        message = testutils.Message(
            "deprecated-str-translate-call", node=node, confidence=INFERENCE_FAILURE
        )
        with self.assertAddsMessages(message):
            self.checker.visit_call(node) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:14,代码来源:unittest_checker_python3.py

示例10: test_bad_str_translate_call_infer_str

# 需要导入模块: import string [as 别名]
# 或者: from string import translate [as 别名]
def test_bad_str_translate_call_infer_str(self):
        node = astroid.extract_node(
            """
         foobar = "hello world"
         foobar.translate(None, foobar) #@
         """
        )
        message = testutils.Message(
            "deprecated-str-translate-call", node=node, confidence=INFERENCE
        )
        with self.assertAddsMessages(message):
            self.checker.visit_call(node) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:14,代码来源:unittest_checker_python3.py

示例11: test_ok_str_translate_call_integer

# 需要导入模块: import string [as 别名]
# 或者: from string import translate [as 别名]
def test_ok_str_translate_call_integer(self):
        node = astroid.extract_node(
            """
         foobar.translate(None, 33) #@
         """
        )
        with self.assertNoMessages():
            self.checker.visit_call(node) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:10,代码来源:unittest_checker_python3.py

示例12: test_ok_str_translate_call_keyword

# 需要导入模块: import string [as 别名]
# 或者: from string import translate [as 别名]
def test_ok_str_translate_call_keyword(self):
        node = astroid.extract_node(
            """
         foobar.translate(None, 'foobar', raz=33) #@
         """
        )
        with self.assertNoMessages():
            self.checker.visit_call(node) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:10,代码来源:unittest_checker_python3.py

示例13: test_six_ifexp_conditional

# 需要导入模块: import string [as 别名]
# 或者: from string import translate [as 别名]
def test_six_ifexp_conditional(self):
        code = """
        from __future__ import absolute_import
        import six
        import string
        string.translate if six.PY2 else None
        """
        module = astroid.parse(code)
        with self.assertNoMessages():
            self.walk(module) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:12,代码来源:unittest_checker_python3.py

示例14: test_ok_str_translate_call_not_str

# 需要导入模块: import string [as 别名]
# 或者: from string import translate [as 别名]
def test_ok_str_translate_call_not_str(self):
        node = astroid.extract_node(
            """
         foobar = {}
         foobar.translate(None, 'foobar') #@
         """
        )
        with self.assertNoMessages():
            self.checker.visit_call(node) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:11,代码来源:unittest_checker_python3.py

示例15: _quote

# 需要导入模块: import string [as 别名]
# 或者: from string import translate [as 别名]
def _quote(str, LegalChars=_LegalChars,
           idmap=_idmap, translate=string.translate):
    #
    # If the string does not need to be double-quoted,
    # then just return the string.  Otherwise, surround
    # the string in doublequotes and precede quote (with a \)
    # special characters.
    #
    if "" == translate(str, idmap, LegalChars):
        return str
    else:
        return '"' + _nulljoin( map(_Translator.get, str, str) ) + '"'
# end _quote 
开发者ID:glmcdona,项目名称:meddle,代码行数:15,代码来源:Cookie.py


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