@@ -470,14 +470,17 @@ def get_locales(prefix=None, normalize=True,
470
470
471
471
@contextmanager
472
472
def set_locale (new_locale , lc_var = locale .LC_ALL ):
473
- """Context manager for temporarily setting a locale.
473
+ """
474
+ Context manager for temporarily setting a locale.
474
475
475
476
Parameters
476
477
----------
477
478
new_locale : str or tuple
478
479
A string of the form <language_country>.<encoding>. For example to set
479
480
the current locale to US English with a UTF8 encoding, you would pass
480
481
"en_US.UTF-8".
482
+ lc_var : int, default `locale.LC_ALL`
483
+ The category of the locale being set.
481
484
482
485
Notes
483
486
-----
@@ -503,21 +506,23 @@ def set_locale(new_locale, lc_var=locale.LC_ALL):
503
506
locale .setlocale (lc_var , current_locale )
504
507
505
508
506
- def _can_set_locale (lc ):
507
- """Check to see if we can set a locale without throwing an exception .
509
+ def can_set_locale (lc , lc_var = locale . LC_ALL ):
510
+ """Check to see if we can set a locale without throwing an Exception .
508
511
509
512
Parameters
510
513
----------
511
514
lc : str
512
515
The locale to attempt to set.
516
+ lc_var : int, default `locale.LC_ALL`
517
+ The category of the locale being set.
513
518
514
519
Returns
515
520
-------
516
- isvalid : bool
521
+ is_valid : bool
517
522
Whether the passed locale can be set
518
523
"""
519
524
try :
520
- with set_locale (lc ):
525
+ with set_locale (lc , lc_var = lc_var ):
521
526
pass
522
527
except locale .Error : # horrible name for a Exception subclass
523
528
return False
@@ -546,7 +551,7 @@ def _valid_locales(locales, normalize):
546
551
else :
547
552
normalizer = lambda x : x .strip ()
548
553
549
- return list (filter (_can_set_locale , map (normalizer , locales )))
554
+ return list (filter (can_set_locale , map (normalizer , locales )))
550
555
551
556
# -----------------------------------------------------------------------------
552
557
# Stdout / stderr decorators
0 commit comments