Python string 模块,translate() 实例源码

我们从Python开源项目中,提取了以下49个代码示例,用于说明如何使用string.translate()

项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
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)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
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)
项目:IntroPython2016    作者:UWPCE-PythonCert    | 项目源码 | 文件源码
def strip_punctuation(text):
    """
    strips the punctuation from a bunch of text
    """
    # build a translation table for string.translate:
    # there are other ways to do this:

    # create a translation table to replace all punctuation with spaces
    #    -- then split() will remove the extra spaces
    punctuation = string.punctuation
    punctuation = punctuation.replace("'", "")  # keep apostropies
    punctuation = punctuation.replace("-", "")  # keep hyphenated words
    # building a translation table
    table = {}
    for c in punctuation:
        table[ord(c)] = ' '
    # remove punctuation with the translation table
    text = text.translate(table)
    # remove "--" -- can't do multiple characters with translate
    text = text.replace("--", " ")

    return text
项目:featherduster    作者:nccgroup    | 项目源码 | 文件源码
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
项目:featherduster    作者:nccgroup    | 项目源码 | 文件源码
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()])
项目:oil    作者:oilshell    | 项目源码 | 文件源码
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)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
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)
项目:OKUSON    作者:frankluebeck    | 项目源码 | 文件源码
def BibTeXString(d):
  res = ['@'+d['bibtype']+ '{ ' + d['id'] + ',']
  inner = []
  fill = '                         '
  for n in StandardBibTeXOrder:
    if d.has_key(n):
      if len(NormalizedWhitespace(d[n])) > 0:
        if n in ['author','editor']:
          inner.append('  '+n+' = '+fill[0:16-len(n)]+'{'+normedNamesString(d[n])+'}')
        else:
          inner.append('  '+n+' = '+fill[0:16-len(n)]+'{'+d[n]+'}')
  for n in d.keys():
    if not n in StandardBibTeXOrder and not n in ['bibtype', 'id']:
      inner.append('  '+n+' = '+fill[0:16-len(n)]+'{'+d[n]+'}')
  res.append(string.join(inner, ',\n'))
  res.append("}\n")
  return string.join(res, "\n")

# (re)translate a Bib entry into a string for a BibXML file
项目:pelisalacarta-ce    作者:pelisalacarta-ce    | 项目源码 | 文件源码
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

    #
项目:plugin.video.streamondemand-pureita    作者:orione7    | 项目源码 | 文件源码
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.info("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.info("Error de encoding")
    return title

    #
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
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)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
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)
项目:empyrion-python-api    作者:huhlig    | 项目源码 | 文件源码
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)
项目:Scriptology    作者:JohnTroony    | 项目源码 | 文件源码
def get_pattern(stuff):
    first = "abcdefghijklmnopqrstuvwxyz0123456789"
    next = "bcdefghijklmnopqrstuvwxyz0123456789a"
    table = string.maketrans(first, next)

    textString.append("".join(number))

    for run in range(stuff - 1):
        if number[2] == '9':
            nextNumber = string.translate(number[1], table)
            number[1] = nextNumber

        if number[1] == '9' and number[2] == '9':
            nextNumber = string.translate(number[0], table)
            number[0] = nextNumber

        nextNumber = string.translate(number[2], table)
        number[2] = nextNumber
        textString.append("".join(number))

    return textString
项目:Genum    作者:la0rg    | 项目源码 | 文件源码
def set(self, key, val, coded_val,
            LegalChars=_LegalChars,
            idmap=_idmap, translate=string.translate):
        # First we verify that the key isn't a reserved word
        # Second we make sure it only contains legal characters
        if key.lower() in self._reserved:
            raise CookieError("Attempt to set a reserved key: %s" % key)
        if "" != translate(key, idmap, LegalChars):
            raise CookieError("Illegal key value: %s" % key)

        # It's a good key, so save it.
        self.key = key
        self.value = val
        self.coded_value = coded_val

    # end set
项目:addon    作者:alfa-addon    | 项目源码 | 文件源码
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

    #
项目:pyomo    作者:Pyomo    | 项目源码 | 文件源码
def __init__(self, preserve, translate, other):
        """
        Arguments::
           preserve: a string of characters to preserve
           translate: a dict or key/value list of characters to translate
           other: the character to return for all characters not in
                  preserve or translate
        """
        self.table = dict(
            (k if isinstance(k, int) else ord(k), v)
            for k,v in six.iteritems(dict(translate)) )
        for c in preserve:
            _c = ord(c)
            if _c in self.table and self.table[_c] != c:
                raise RuntimeError("Duplicate character '%s' appears in both "
                                   "translate table and preserve list" % (c,))
            self.table[_c] = c
        self.other = other
项目:CTF-chal-code    作者:zwhubuntu    | 项目源码 | 文件源码
def foo():
    s='vbkq{ukCkS_vrduztucCVQXVuvzuckrvtZDUBTGYSkvcktv}'
    '''
    '''
    a=string.lowercase
    b=""
    for i in xrange(len(a)):
        if i%2==0:
            if i<19:
                b+=a[i+7]
            else:
                b+=a[i-19]
        else:
            if i>=7:
                b+=a[i-7]
            else:
                b+=a[i+19]

    table=string.maketrans(a,b)
    print string.translate(s,table)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def get_attr_name (self, long_option):
        """Translate long option name 'long_option' to the form it
        has as an attribute of some object: ie., translate hyphens
        to underscores."""
        return string.translate(long_option, longopt_xlate)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def translate_longopt(opt):
    """Convert a long option name to a valid Python identifier by
    changing "-" to "_".
    """
    return string.translate(opt, longopt_xlate)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
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
项目:shadowsocksR-b    作者:hao35954514    | 项目源码 | 文件源码
def update(self, data):
        if self._op:
            return translate(data, self._encrypt_table)
        else:
            return translate(data, self._decrypt_table)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def get_attr_name (self, long_option):
        """Translate long option name 'long_option' to the form it
        has as an attribute of some object: ie., translate hyphens
        to underscores."""
        return string.translate(long_option, longopt_xlate)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def translate_longopt(opt):
    """Convert a long option name to a valid Python identifier by
    changing "-" to "_".
    """
    return string.translate(opt, longopt_xlate)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
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
项目:shadowsocksr    作者:shadowsocksr-backup    | 项目源码 | 文件源码
def update(self, data):
        if self._op:
            return translate(data, self._encrypt_table)
        else:
            return translate(data, self._decrypt_table)
项目:ShadowSocks    作者:immqy    | 项目源码 | 文件源码
def update(self, data):
        if self._op:
            return translate(data, self._encrypt_table)
        else:
            return translate(data, self._decrypt_table)
项目:ghostlines-robofont    作者:ghostlines    | 项目源码 | 文件源码
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
项目:ghostlines-robofont    作者:ghostlines    | 项目源码 | 文件源码
def set(self, key, val, coded_val,
            LegalChars=_LegalChars,
            idmap=_idmap, translate=string.translate):
        # First we verify that the key isn't a reserved word
        # Second we make sure it only contains legal characters
        if key.lower() in self._reserved:
            raise CookieError("Attempt to set a reserved key: %s" % key)
        if "" != translate(key, idmap, LegalChars):
            raise CookieError("Illegal key value: %s" % key)

        # It's a good key, so save it.
        self.key                 = key
        self.value               = val
        self.coded_value         = coded_val
    # end set
项目:ghostlines-robofont    作者:ghostlines    | 项目源码 | 文件源码
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
项目:ghostlines-robofont    作者:ghostlines    | 项目源码 | 文件源码
def set(self, key, val, coded_val,
            LegalChars=_LegalChars,
            idmap=_idmap, translate=string.translate):
        # First we verify that the key isn't a reserved word
        # Second we make sure it only contains legal characters
        if key.lower() in self._reserved:
            raise CookieError("Attempt to set a reserved key: %s" % key)
        if "" != translate(key, idmap, LegalChars):
            raise CookieError("Illegal key value: %s" % key)

        # It's a good key, so save it.
        self.key                 = key
        self.value               = val
        self.coded_value         = coded_val
    # end set
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def update(self, data):
        if self._op:
            return translate(data, self._encrypt_table)
        else:
            return translate(data, self._decrypt_table)
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
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
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def set(self, key, val, coded_val,
            LegalChars=_LegalChars,
            idmap=_idmap, translate=string.translate):
        # First we verify that the key isn't a reserved word
        # Second we make sure it only contains legal characters
        if key.lower() in self._reserved:
            raise CookieError("Attempt to set a reserved key: %s" % key)
        if "" != translate(key, idmap, LegalChars):
            raise CookieError("Illegal key value: %s" % key)

        # It's a good key, so save it.
        self.key                 = key
        self.value               = val
        self.coded_value         = coded_val
    # end set
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def update(self, data):
        if self._op:
            return translate(data, self._encrypt_table)
        else:
            return translate(data, self._decrypt_table)
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
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
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def set(self, key, val, coded_val,
            LegalChars=_LegalChars,
            idmap=_idmap, translate=string.translate):
        # First we verify that the key isn't a reserved word
        # Second we make sure it only contains legal characters
        if key.lower() in self._reserved:
            raise CookieError("Attempt to set a reserved key: %s" % key)
        if "" != translate(key, idmap, LegalChars):
            raise CookieError("Illegal key value: %s" % key)

        # It's a good key, so save it.
        self.key                 = key
        self.value               = val
        self.coded_value         = coded_val
    # end set
项目:ssrr    作者:do21    | 项目源码 | 文件源码
def update(self, data):
        if self._op:
            return translate(data, self._encrypt_table)
        else:
            return translate(data, self._decrypt_table)
项目:shadowsocksr    作者:ShadowsocksR-Live    | 项目源码 | 文件源码
def update(self, data):
        if self._op:
            return translate(data, self._encrypt_table)
        else:
            return translate(data, self._decrypt_table)
项目:featherduster    作者:nccgroup    | 项目源码 | 文件源码
def output_mask(text, charset):
   '''
   Output masking - mask all characters besides those in the provided character
   set with dots.

   Parameters:
   (string) text - output to mask
   (string) charset - string containing acceptable characters
   '''
   all_chars = output_chars = map(chr,range(256))
   charset = set(charset)
   for charnum in range(256):
      if all_chars[charnum] not in charset:
         output_chars[charnum] = '.'
   return string.translate(text,''.join(output_chars))
项目:featherduster    作者:nccgroup    | 项目源码 | 文件源码
def morse_encode(text, dot='.', dash='-', space=' '):
   '''
   Encodes text into Morse code.
   '''
   dot_dash_trans = string.maketrans('.-', dot+dash)
   translated_morse_table = map(lambda (x,y): (x, string.translate(y, dot_dash_trans)), morse_table.items())
   translated_morse_table = dict(translated_morse_table)
   output = []
   for char in text.lower():
      if char in string.lowercase + string.digits:
         output.append(translated_morse_table[char])
   return space.join(output)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def get_attr_name (self, long_option):
        """Translate long option name 'long_option' to the form it
        has as an attribute of some object: ie., translate hyphens
        to underscores."""
        return string.translate(long_option, longopt_xlate)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def translate_longopt(opt):
    """Convert a long option name to a valid Python identifier by
    changing "-" to "_".
    """
    return string.translate(opt, longopt_xlate)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
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
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def get_attr_name (self, long_option):
        """Translate long option name 'long_option' to the form it
        has as an attribute of some object: ie., translate hyphens
        to underscores."""
        return string.translate(long_option, longopt_xlate)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def translate_longopt(opt):
    """Convert a long option name to a valid Python identifier by
    changing "-" to "_".
    """
    return string.translate(opt, longopt_xlate)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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
项目:PyS60-Projects    作者:gauravssnl    | 项目源码 | 文件源码
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