Python locale.LC_ALL Examples
The following are 30
code examples of locale.LC_ALL().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
locale
, or try the search function
.
Example #1
Source File: test_cftp.py From learn_python3_spider with MIT License | 6 votes |
def test_localeIndependent(self): """ The month name in the date is locale independent. """ # A point about three months in the past. then = self.now - (60 * 60 * 24 * 31 * 3) stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0)) # Fake that we're in a language where August is not Aug (e.g.: Spanish) currentLocale = locale.getlocale() locale.setlocale(locale.LC_ALL, "es_AR.UTF8") self.addCleanup(locale.setlocale, locale.LC_ALL, currentLocale) self.assertEqual( self._lsInTimezone('America/New_York', stat), '!--------- 0 0 0 0 Aug 28 17:33 foo') self.assertEqual( self._lsInTimezone('Pacific/Auckland', stat), '!--------- 0 0 0 0 Aug 29 09:33 foo') # If alternate locale is not available, the previous test will be # skipped, please install this locale for it to run
Example #2
Source File: kodiutils.py From plugin.video.vrt.nu with GNU General Public License v3.0 | 6 votes |
def set_locale(): """Load the proper locale for date strings, only once""" if hasattr(set_locale, 'cached'): return getattr(set_locale, 'cached') from locale import Error, LC_ALL, setlocale locale_lang = get_global_setting('locale.language').split('.')[-1] locale_lang = locale_lang[:-2] + locale_lang[-2:].upper() # NOTE: setlocale() only works if the platform supports the Kodi configured locale try: setlocale(LC_ALL, locale_lang) except (Error, ValueError) as exc: if locale_lang != 'en_GB': log(3, "Your system does not support locale '{locale}': {error}", locale=locale_lang, error=exc) set_locale.cached = False return False set_locale.cached = True return True
Example #3
Source File: generic.py From quantipy with MIT License | 6 votes |
def __init__(self, savFileName, ioUtf8=False, ioLocale=None): """Constructor. Note that interface locale and encoding can only be set once""" locale.setlocale(locale.LC_ALL, "") self.savFileName = savFileName self.libc = cdll.LoadLibrary(ctypes.util.find_library("c")) self.spssio = self.loadLibrary() self.wholeCaseIn = self.spssio.spssWholeCaseIn self.wholeCaseOut = self.spssio.spssWholeCaseOut self.encoding_and_locale_set = False if not self.encoding_and_locale_set: self.encoding_and_locale_set = True self.ioLocale = ioLocale self.ioUtf8 = ioUtf8
Example #4
Source File: main.py From aurman with MIT License | 6 votes |
def main(): from locale import setlocale, LC_ALL setlocale(LC_ALL, '') # initialize locales because python doesn't try: # auto completion if len(argv) >= 2 and argv[1] == "--auto_complete": possible_completions() sys.exit(0) # normal call process(argv[1:]) except (KeyboardInterrupt, PermissionError): sys.exit(1) except SystemExit as e: sys.exit(e) except: logging.error("", exc_info=True) sys.exit(1)
Example #5
Source File: test_cftp.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_localeIndependent(self): """ The month name in the date is locale independent. """ # A point about three months in the past. then = self.now - (60 * 60 * 24 * 31 * 3) stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0)) # Fake that we're in a language where August is not Aug (e.g.: Spanish) currentLocale = locale.getlocale() locale.setlocale(locale.LC_ALL, "es_AR.UTF8") self.addCleanup(locale.setlocale, locale.LC_ALL, currentLocale) self.assertEqual( self._lsInTimezone('America/New_York', stat), '!--------- 0 0 0 0 Aug 28 17:33 foo') self.assertEqual( self._lsInTimezone('Pacific/Auckland', stat), '!--------- 0 0 0 0 Aug 29 09:33 foo') # If alternate locale is not available, the previous test will be # skipped, please install this locale for it to run
Example #6
Source File: test_time.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def setUp(self): self.oldloc = locale.setlocale(locale.LC_ALL)
Example #7
Source File: test_time.py From ironpython3 with Apache License 2.0 | 5 votes |
def tearDown(self): locale.setlocale(locale.LC_ALL, self.oldloc)
Example #8
Source File: test_time.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_bug_3061(self): try: tmp = locale.setlocale(locale.LC_ALL, "fr_FR") except locale.Error: self.skipTest('could not set locale.LC_ALL to fr_FR') # This should not cause an exception time.strftime("%B", (2009,2,1,0,0,0,0,0,0))
Example #9
Source File: test_locale.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_setlocale_category(self): locale.setlocale(locale.LC_ALL) locale.setlocale(locale.LC_TIME) locale.setlocale(locale.LC_CTYPE) locale.setlocale(locale.LC_COLLATE) locale.setlocale(locale.LC_MONETARY) locale.setlocale(locale.LC_NUMERIC) # crasher from bug #7419 self.assertRaises(locale.Error, locale.setlocale, 12345)
Example #10
Source File: test_locale.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_invalid_locale_format_in_localetuple(self): with self.assertRaises(TypeError): locale.setlocale(locale.LC_ALL, b'fi_FI')
Example #11
Source File: annotation.py From TFSegmentation with Apache License 2.0 | 5 votes |
def updateDate( self ): try: locale.setlocale( locale.LC_ALL , 'en_US' ) except locale.Error: locale.setlocale( locale.LC_ALL , 'us_us' ) except: pass self.date = datetime.datetime.now().strftime("%d-%b-%Y %H:%M:%S") # Mark the object as deleted
Example #12
Source File: utility.py From maltelligence with GNU General Public License v3.0 | 5 votes |
def convertNumber(data): locale.setlocale( locale.LC_ALL, 'en_US.UTF-8') num = locale.atoi(data) if is_number(num): return num else: msg = '[*] %s is not a number' % (data) logging.error(msg) return 0
Example #13
Source File: annotation.py From Detectron-PYTORCH with Apache License 2.0 | 5 votes |
def updateDate( self ): try: locale.setlocale( locale.LC_ALL , 'en_US' ) except locale.Error: locale.setlocale( locale.LC_ALL , 'us_us' ) except: pass self.date = datetime.datetime.now().strftime("%d-%b-%Y %H:%M:%S") # Mark the object as deleted
Example #14
Source File: process_cityscapes.py From Efficient-Segmentation-Networks with MIT License | 5 votes |
def updateDate( self ): try: locale.setlocale( locale.LC_ALL , 'en_US.utf8' ) except locale.Error: locale.setlocale( locale.LC_ALL , 'en_US' ) except locale.Error: locale.setlocale( locale.LC_ALL , 'us_us.utf8' ) except locale.Error: locale.setlocale( locale.LC_ALL , 'us_us' ) except: pass self.date = datetime.datetime.now().strftime("%d-%b-%Y %H:%M:%S") # Mark the object as deleted
Example #15
Source File: testing.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def set_locale(new_locale, lc_var=locale.LC_ALL): """Context manager for temporarily setting a locale. Parameters ---------- new_locale : str or tuple A string of the form <language_country>.<encoding>. For example to set the current locale to US English with a UTF8 encoding, you would pass "en_US.UTF-8". Notes ----- This is useful when you want to run a particular block of code under a particular locale, without globally setting the locale. This probably isn't thread-safe. """ current_locale = locale.getlocale() try: locale.setlocale(lc_var, new_locale) try: normalized_locale = locale.getlocale() except ValueError: yield new_locale else: if _all_not_none(*normalized_locale): yield '.'.join(normalized_locale) else: yield new_locale finally: locale.setlocale(lc_var, current_locale)
Example #16
Source File: test_cli.py From yamllint with GNU General Public License v3.0 | 5 votes |
def test_run_non_ascii_file(self): path = os.path.join(self.wd, 'non-ascii', 'éçäγλνπ¥', 'utf-8') # Make sure the default localization conditions on this "system" # support UTF-8 encoding. loc = locale.getlocale() try: locale.setlocale(locale.LC_ALL, 'C.UTF-8') except locale.Error: locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') self.addCleanup(locale.setlocale, locale.LC_ALL, loc) with RunContext(self) as ctx: cli.run(('-f', 'parsable', path)) self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', ''))
Example #17
Source File: testing.py From vnpy_crypto with MIT License | 5 votes |
def set_locale(new_locale, lc_var=locale.LC_ALL): """Context manager for temporarily setting a locale. Parameters ---------- new_locale : str or tuple A string of the form <language_country>.<encoding>. For example to set the current locale to US English with a UTF8 encoding, you would pass "en_US.UTF-8". Notes ----- This is useful when you want to run a particular block of code under a particular locale, without globally setting the locale. This probably isn't thread-safe. """ current_locale = locale.getlocale() try: locale.setlocale(lc_var, new_locale) try: normalized_locale = locale.getlocale() except ValueError: yield new_locale else: if com._all_not_none(*normalized_locale): yield '.'.join(normalized_locale) else: yield new_locale finally: locale.setlocale(lc_var, current_locale)
Example #18
Source File: test_time.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def tearDown(self): locale.setlocale(locale.LC_ALL, self.oldloc)
Example #19
Source File: test_time.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_bug_3061(self): try: tmp = locale.setlocale(locale.LC_ALL, "fr_FR") except locale.Error: self.skipTest('could not set locale.LC_ALL to fr_FR') # This should not cause an exception time.strftime("%B", (2009,2,1,0,0,0,0,0,0))
Example #20
Source File: test_locale.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_setlocale_category(self): locale.setlocale(locale.LC_ALL) locale.setlocale(locale.LC_TIME) locale.setlocale(locale.LC_CTYPE) locale.setlocale(locale.LC_COLLATE) locale.setlocale(locale.LC_MONETARY) locale.setlocale(locale.LC_NUMERIC) # crasher from bug #7419 self.assertRaises(locale.Error, locale.setlocale, 12345)
Example #21
Source File: test_locale.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_invalid_locale_format_in_localetuple(self): with self.assertRaises(TypeError): locale.setlocale(locale.LC_ALL, b'fi_FI')
Example #22
Source File: floattestsuite.py From pypylon with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_TheFrenchWay(self): """[ GenApiTest@FloatTestSuite_TestTheFrenchWay.xml|gxml <SwissKnife Name="Value"> <Formula>1.234</Formula> </SwissKnife> <Float Name="FloatValue"> <Value>1.234</Value> </Float> """ OldLocale = setlocale(LC_ALL, None) print("Original Locale = " + OldLocale + "\n") if (not setlocale(LC_ALL, "French")): if (not setlocale(LC_ALL, "fr_FR.UTF-8")): setlocale(LC_ALL, "fr_FR") print("French locale = " + setlocale(LC_ALL, None) + "\n") Camera = CNodeMapRef() Camera._LoadXMLFromFile("GenApiTest", "FloatTestSuite_TestTheFrenchWay") value = Camera.GetNode("Value") value.GetValue() self.assertAlmostEqual(1.234, value.GetValue(), self.FLOAT64_EPSILON) setlocale(LC_ALL, OldLocale) print("Restored locale = " + setlocale(LC_ALL, None) + "\n")
Example #23
Source File: testing.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def set_locale(new_locale, lc_var=locale.LC_ALL): """Context manager for temporarily setting a locale. Parameters ---------- new_locale : str or tuple A string of the form <language_country>.<encoding>. For example to set the current locale to US English with a UTF8 encoding, you would pass "en_US.UTF-8". Notes ----- This is useful when you want to run a particular block of code under a particular locale, without globally setting the locale. This probably isn't thread-safe. """ current_locale = locale.getlocale() try: locale.setlocale(lc_var, new_locale) try: normalized_locale = locale.getlocale() except ValueError: yield new_locale else: if _all_not_none(*normalized_locale): yield '.'.join(normalized_locale) else: yield new_locale finally: locale.setlocale(lc_var, current_locale)
Example #24
Source File: test_time.py From android_universal with MIT License | 5 votes |
def setUp(self): self.oldloc = locale.setlocale(locale.LC_ALL)
Example #25
Source File: test_time.py From android_universal with MIT License | 5 votes |
def tearDown(self): locale.setlocale(locale.LC_ALL, self.oldloc)
Example #26
Source File: test_time.py From android_universal with MIT License | 5 votes |
def test_bug_3061(self): try: tmp = locale.setlocale(locale.LC_ALL, "fr_FR") except locale.Error: self.skipTest('could not set locale.LC_ALL to fr_FR') # This should not cause an exception time.strftime("%B", (2009,2,1,0,0,0,0,0,0))
Example #27
Source File: annotation.py From fcn8s_tensorflow with GNU General Public License v3.0 | 5 votes |
def updateDate( self ): try: locale.setlocale( locale.LC_ALL , 'en_US' ) except locale.Error: locale.setlocale( locale.LC_ALL , 'us_us' ) except: pass self.date = datetime.datetime.now().strftime("%d-%b-%Y %H:%M:%S") # Mark the object as deleted
Example #28
Source File: annotation.py From openseg.pytorch with MIT License | 5 votes |
def updateDate( self ): try: locale.setlocale( locale.LC_ALL , 'en_US' ) except locale.Error: locale.setlocale( locale.LC_ALL , 'us_us' ) except: pass self.date = datetime.datetime.now().strftime("%d-%b-%Y %H:%M:%S") # Mark the object as deleted
Example #29
Source File: testing.py From Computable with MIT License | 5 votes |
def set_locale(new_locale, lc_var=locale.LC_ALL): """Context manager for temporarily setting a locale. Parameters ---------- new_locale : str or tuple A string of the form <language_country>.<encoding>. For example to set the current locale to US English with a UTF8 encoding, you would pass "en_US.UTF-8". Notes ----- This is useful when you want to run a particular block of code under a particular locale, without globally setting the locale. This probably isn't thread-safe. """ current_locale = locale.getlocale() try: locale.setlocale(lc_var, new_locale) try: normalized_locale = locale.getlocale() except ValueError: yield new_locale else: if all(lc is not None for lc in normalized_locale): yield '.'.join(normalized_locale) else: yield new_locale finally: locale.setlocale(lc_var, current_locale)
Example #30
Source File: test_imap.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def test_fetchInternalDateLocaleIndependent(self): """ The month name in the date is locale independent. """ # Fake that we're in a language where December is not Dec currentLocale = locale.setlocale(locale.LC_ALL, None) locale.setlocale(locale.LC_ALL, "es_AR.UTF8") self.addCleanup(locale.setlocale, locale.LC_ALL, currentLocale) return self.testFetchInternalDate(1) # if alternate locale is not available, the previous test will be skipped, # please install this locale for it to run. Avoid using locale.getlocale to # learn the current locale; its values don't round-trip well on all # platforms. Fortunately setlocale returns a value which does round-trip # well.