@@ -774,29 +774,29 @@ def check_sizeof(test, o, size):
774
774
775
775
@contextlib .contextmanager
776
776
def run_with_locale (catstr , * locales ):
777
+ try :
778
+ import locale
779
+ category = getattr (locale , catstr )
780
+ orig_locale = locale .setlocale (category )
781
+ except AttributeError :
782
+ # if the test author gives us an invalid category string
783
+ raise
784
+ except :
785
+ # cannot retrieve original locale, so do nothing
786
+ locale = orig_locale = None
787
+ else :
788
+ for loc in locales :
777
789
try :
778
- import locale
779
- category = getattr (locale , catstr )
780
- orig_locale = locale .setlocale (category )
781
- except AttributeError :
782
- # if the test author gives us an invalid category string
783
- raise
790
+ locale .setlocale (category , loc )
791
+ break
784
792
except :
785
- # cannot retrieve original locale, so do nothing
786
- locale = orig_locale = None
787
- else :
788
- for loc in locales :
789
- try :
790
- locale .setlocale (category , loc )
791
- break
792
- except :
793
- pass
793
+ pass
794
794
795
- try :
796
- yield
797
- finally :
798
- if locale and orig_locale :
799
- locale .setlocale (category , orig_locale )
795
+ try :
796
+ yield
797
+ finally :
798
+ if locale and orig_locale :
799
+ locale .setlocale (category , orig_locale )
800
800
801
801
#=======================================================================
802
802
# Decorator for running a function in a specific timezone, correctly
0 commit comments