/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/cache_utf8.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
"""Some functions to enable caching the conversion between unicode to utf8"""
21
21
 
 
22
from __future__ import absolute_import
 
23
 
22
24
import codecs
23
25
 
24
26
_utf8_encode = codecs.utf_8_encode
25
27
_utf8_decode = codecs.utf_8_decode
26
 
 
27
 
 
28
28
def _utf8_decode_with_None(bytestring, _utf8_decode=_utf8_decode):
29
29
    """wrap _utf8_decode to support None->None for optional strings.
30
30
 
36
36
    else:
37
37
        return _utf8_decode(bytestring)[0]
38
38
 
39
 
 
40
39
# Map revisions from and to utf8 encoding
41
40
# Whenever we do an encode/decode operation, we save the result, so that
42
41
# we don't have to do it again.
109
108
    # real Unicode string. Unicode and plain strings of this type will have the
110
109
    # same hash, so we can just use it as the key in _uni_to_utf8, but we need
111
110
    # the return value to be different in _utf8_to_uni
112
 
    uni_str = ascii_str.decode('ascii')
113
 
    ascii_str = _uni_to_utf8.setdefault(uni_str, ascii_str)
114
 
    _utf8_to_uni.setdefault(ascii_str, uni_str)
 
111
    ascii_str = _uni_to_utf8.setdefault(ascii_str, ascii_str)
 
112
    _utf8_to_uni.setdefault(ascii_str, unicode(ascii_str))
115
113
    return ascii_str
116
114
 
117
115