@@ -520,6 +520,11 @@ def requires_subprocess():
520
520
"""Used for subprocess, os.spawn calls, fd inheritance"""
521
521
return unittest .skipUnless (has_subprocess_support , "requires subprocess support" )
522
522
523
+ # Does strftime() support glibc extension like '%4Y'?
524
+ try :
525
+ has_strftime_extensions = time .strftime ("%4Y" ) != "%4Y"
526
+ except ValueError :
527
+ has_strftime_extensions = False
523
528
524
529
# Define the URL of a dedicated HTTP server for the network tests.
525
530
# The URL must use clear-text HTTP: no redirection to encrypted HTTPS.
@@ -769,29 +774,29 @@ def check_sizeof(test, o, size):
769
774
770
775
@contextlib .contextmanager
771
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 :
772
789
try :
773
- import locale
774
- category = getattr (locale , catstr )
775
- orig_locale = locale .setlocale (category )
776
- except AttributeError :
777
- # if the test author gives us an invalid category string
778
- raise
790
+ locale .setlocale (category , loc )
791
+ break
779
792
except :
780
- # cannot retrieve original locale, so do nothing
781
- locale = orig_locale = None
782
- else :
783
- for loc in locales :
784
- try :
785
- locale .setlocale (category , loc )
786
- break
787
- except :
788
- pass
793
+ pass
789
794
790
- try :
791
- yield
792
- finally :
793
- if locale and orig_locale :
794
- locale .setlocale (category , orig_locale )
795
+ try :
796
+ yield
797
+ finally :
798
+ if locale and orig_locale :
799
+ locale .setlocale (category , orig_locale )
795
800
796
801
#=======================================================================
797
802
# Decorator for running a function in a specific timezone, correctly
0 commit comments