File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -46,10 +46,16 @@ def _remove_error_label(self, label):
46
46
"""Remove the given label from this error."""
47
47
self ._error_labels .remove (label )
48
48
49
- def __str__ (self ):
50
- if sys .version_info [0 ] == 2 and isinstance (self ._message , unicode ):
51
- return self ._message .encode ('utf-8' , errors = 'replace' )
52
- return str (self ._message )
49
+ if sys .version_info [0 ] == 2 :
50
+ def __str__ (self ):
51
+ if isinstance (self ._message , unicode ):
52
+ return self ._message .encode ('utf-8' , errors = 'replace' )
53
+ return str (self ._message )
54
+
55
+ def __unicode__ (self ):
56
+ if isinstance (self ._message , unicode ):
57
+ return self ._message
58
+ return unicode (self ._message , 'utf-8' , errors = 'replace' )
53
59
54
60
55
61
class ProtocolError (PyMongoError ):
Original file line number Diff line number Diff line change @@ -1335,6 +1335,12 @@ def test_write_error_unicode(self):
1335
1335
self .assertIn ('E11000 duplicate key error' ,
1336
1336
str (ctx .exception ))
1337
1337
1338
+ if sys .version_info [0 ] == 2 :
1339
+ # Test unicode(error) conversion.
1340
+ self .assertIn ('E11000 duplicate key error' ,
1341
+ unicode (ctx .exception ))
1342
+
1343
+
1338
1344
def test_wtimeout (self ):
1339
1345
# Ensure setting wtimeout doesn't disable write concern altogether.
1340
1346
# See SERVER-12596.
You can’t perform that action at this time.
0 commit comments