/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/errors.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
 
127
127
    def __str__(self):
128
128
        try:
129
 
            return self.__doc__ % self.__dict__
 
129
            # __str__() should always return a 'str' object
 
130
            # never a 'unicode' object.
 
131
            s = self.__doc__ % self.__dict__
 
132
            if isinstance(s, unicode):
 
133
                return s.encode('utf8')
 
134
            return s
130
135
        except (NameError, ValueError, KeyError), e:
131
136
            return 'Unprintable exception %s: %s' \
132
137
                % (self.__class__.__name__, str(e))
198
203
    # BzrCommandError, and non-UI code should not throw a subclass of
199
204
    # BzrCommandError.  ADHB 20051211
200
205
    def __init__(self, msg):
201
 
        self.msg = msg
 
206
        # Object.__str__() must return a real string
 
207
        # returning a Unicode string is a python error.
 
208
        if isinstance(msg, unicode):
 
209
            self.msg = msg.encode('utf8')
 
210
        else:
 
211
            self.msg = msg
202
212
 
203
213
    def __str__(self):
204
214
        return self.msg