~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Harald Meland
  • Date: 2005-10-06 22:55:44 UTC
  • mto: (1185.33.32 bzr.dev)
  • mto: This revision was merged to the branch mainline in revision 1509.
  • Revision ID: hmeland@twoflower.uio.no-20051006225544-bc7ef2300f20d9a3
Cleanup + better test of commit-msg control character escape code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
192
192
        else:
193
193
            self.timezone = int(timezone)
194
194
 
195
 
        assert isinstance(message, basestring), type(message)
 
195
        if isinstance(message, str):
 
196
            import bzrlib
 
197
            message = message.decode(bzrlib.user_encoding)
 
198
        assert isinstance(message, unicode), type(message)
196
199
        self.message = message
197
200
        self._escape_commit_message()
198
201
 
241
244
        # represented in well-formed XML; escape characters that
242
245
        # aren't listed in the XML specification
243
246
        # (http://www.w3.org/TR/REC-xml/#NT-Char).
244
 
        if isinstance(self.message, unicode):
245
 
            char_pattern = u'[^\x09\x0A\x0D\u0020-\uD7FF\uE000-\uFFFD]'
246
 
        else:
247
 
            # Use a regular 'str' as pattern to avoid having re.subn
248
 
            # return 'unicode' results.
249
 
            char_pattern = '[^\x09\x0A\x0D\x20-\xFF]'
250
247
        self.message, escape_count = re.subn(
251
 
            char_pattern,
 
248
            u'[^\x09\x0A\x0D\u0020-\uD7FF\uE000-\uFFFD]+',
252
249
            lambda match: match.group(0).encode('unicode_escape'),
253
250
            self.message)
254
251
        if escape_count: