~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to common.py

  • Committer: John Arbash Meinel
  • Date: 2005-07-16 16:22:04 UTC
  • mto: (1185.82.1 bzr-w-changeset) (0.5.98)
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: john@arbash-meinel.com-20050716162204-ca86975b99b2742e
Handling international characters, added more test cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
    >>> encode(u'abcdefg')
115
115
    'abcdefg'
116
116
    >>> encode(u'a b\\tc\\nd\\\\e')
117
 
    'a b\\\\tc\\\\nd\\\\e'
 
117
    'a b\\tc\\nd\\\\e'
118
118
    >>> encode('a b\\tc\\nd\\e')
119
 
    'a b\\\\tc\\\\nd\\\\e'
 
119
    'a b\\tc\\nd\\\\e'
120
120
    >>> encode(u'\\u1234\\u0020')
121
 
    '\\\\u1234 '
 
121
    '\\xe1\\x88\\xb4 '
122
122
    >>> encode('abcdefg')
123
123
    'abcdefg'
124
124
    >>> encode(u'')
126
126
    >>> encode('')
127
127
    ''
128
128
    """
129
 
    return s.encode('unicode_escape')
 
129
    return s.encode('utf-8')
130
130
 
131
131
def decode(s):
132
132
    """Undo the encode operation, returning a unicode string.
133
133
 
134
134
    >>> decode('abcdefg')
135
135
    u'abcdefg'
136
 
    >>> decode('a b\\\\tc\\\\nd\\\\e')
 
136
    >>> decode('a b\\tc\\nd\\\\e')
137
137
    u'a b\\tc\\nd\\\\e'
138
 
    >>> decode('\\\\u1234\\\\u0020')
 
138
    >>> decode('\\xe1\\x88\\xb4 ')
139
139
    u'\\u1234 '
140
140
    >>> for s in ('test', 'strings'):
141
141
    ...   if decode(encode(s)) != s:
142
142
    ...     print 'Failed: %r' % s # There should be no failures
143
143
 
144
144
    """
145
 
    return s.decode('unicode_escape')
 
145
    return s.decode('utf-8')
146
146
 
147
147
def format_highres_date(t, offset=0):
148
148
    """Format a date, such that it includes higher precision in the