File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -649,7 +649,8 @@ class StrAnonymizer(str):
649
649
650
650
def __new__ (cls , data , method , salt ):
651
651
method = method .lower ()
652
- if method not in hashlib .algorithms_guaranteed :
652
+ if method not in (hashlib .algorithms if six .PY2 else
653
+ hashlib .algorithms_guaranteed ):
653
654
raise ValueError ('Unsupported hashing method: %r' % method )
654
655
s = str .__new__ (cls , data or '' )
655
656
s .method = method
Original file line number Diff line number Diff line change @@ -3565,6 +3565,22 @@ def test_str_anonymizer(self):
3565
3565
self .assertRaises (ValueError , utils .StrAnonymizer ,
3566
3566
'Swift is great!' , 'sha257' , '' )
3567
3567
3568
+ def test_str_anonymizer_python_maddness (self ):
3569
+ with mock .patch ('swift.common.utils.hashlib' ) as mocklib :
3570
+ if six .PY2 :
3571
+ # python <2.7.9 doesn't have this algorithms_guaranteed, but
3572
+ # our if block short-circuts before we explode
3573
+ mocklib .algorithms = hashlib .algorithms
3574
+ mocklib .algorithms_guaranteed .sideEffect = AttributeError ()
3575
+ else :
3576
+ # python 3 doesn't have this algorithms but our if block
3577
+ # short-circuts before we explode
3578
+ mocklib .algorithms .sideEffect .sideEffect = AttributeError ()
3579
+ mocklib .algorithms_guaranteed = hashlib .algorithms_guaranteed
3580
+ utils .StrAnonymizer ('Swift is great!' , 'sha1' , '' )
3581
+ self .assertRaises (ValueError , utils .StrAnonymizer ,
3582
+ 'Swift is great!' , 'sha257' , '' )
3583
+
3568
3584
def test_str_format_time (self ):
3569
3585
dt = utils .StrFormatTime (10000.123456789 )
3570
3586
self .assertEqual (str (dt ), '10000.123456789' )
You can’t perform that action at this time.
0 commit comments