Ticket #4937: locale-independent-formatting-with-tests2.patch
| File locale-independent-formatting-with-tests2.patch, 6.1 KB (added by facundobatista, 2 years ago) |
|---|
-
twisted/conch/ls.py
=== modified file 'twisted/conch/ls.py'
7 7 8 8 from time import time, strftime, localtime 9 9 10 # locale-independent month names to use instead of strftime's 11 MONTH_NAMES = dict(zip(range(1, 13), 12 "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split())) 13 10 14 11 15 def lsLine(name, s): 12 16 mode = s.st_mode … … 39 43 if mode&stat.S_ISGID: 40 44 if perms[6] == 'x': perms[6] = 's' 41 45 else: perms[6] = 'S' 42 l = perms.tostring() 43 l += str(s.st_nlink).rjust(5) + ' ' 44 un = str(s.st_uid) 45 l += un.ljust(9) 46 gr = str(s.st_gid) 47 l += gr.ljust(9) 48 sz = str(s.st_size) 49 l += sz.rjust(8) 50 l += ' ' 51 sixmo = 60 * 60 * 24 * 7 * 26 52 if s.st_mtime + sixmo < time(): # last edited more than 6mo ago 53 l += strftime("%b %d %Y ", localtime(s.st_mtime)) 46 47 lsresult = [ 48 perms.tostring(), 49 str(s.st_nlink).rjust(5), 50 ' ', 51 str(s.st_uid).ljust(9), 52 str(s.st_gid).ljust(9), 53 str(s.st_size).rjust(8), 54 ' ', 55 ] 56 57 # need to specify the month manually, as strftime depends on locale 58 ttup = localtime(s.st_mtime) 59 sixmonths = 60 * 60 * 24 * 7 * 26 60 if s.st_mtime + sixmonths < time(): # last edited more than 6mo ago 61 strtime = strftime("%%s %d %Y ", ttup) 54 62 else: 55 l += strftime("%b %d %H:%M ", localtime(s.st_mtime)) 56 l += name 57 return l 63 strtime = strftime("%%s %d %H:%M ", ttup) 64 lsresult.append(strtime % (MONTH_NAMES[ttup[1]],)) 65 66 lsresult.append(name) 67 return ''.join(lsresult) 58 68 59 69 60 70 __all__ = ['lsLine'] -
twisted/conch/test/test_cftp.py
=== modified file 'twisted/conch/test/test_cftp.py'
6 6 Tests for L{twisted.conch.scripts.cftp}. 7 7 """ 8 8 9 import locale 9 10 import time, sys, os, operator, getpass, struct 10 11 from StringIO import StringIO 11 12 … … 142 143 '!--------- 0 0 0 0 Aug 29 09:33 foo') 143 144 144 145 146 def test_localeIndependent(self): 147 """ 148 The month name in the date should be locale independent. 149 """ 150 # A point about three months in the past. 151 then = self.now - (60 * 60 * 24 * 31 * 3) 152 stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0)) 153 154 # Fake that we're in a language where August is not Aug (e.g.: Spanish) 155 current_locale = locale.getlocale() 156 locale.setlocale(locale.LC_ALL, "es_AR.UTF8") 157 self.addCleanup(locale.setlocale, locale.LC_ALL, current_locale) 158 159 self.assertEqual( 160 self._lsInTimezone('America/New_York', stat), 161 '!--------- 0 0 0 0 Aug 28 17:33 foo') 162 self.assertEqual( 163 self._lsInTimezone('Pacific/Auckland', stat), 164 '!--------- 0 0 0 0 Aug 29 09:33 foo') 165 166 # if alternate locale is not available, the previous test will be 167 # skipped, please install this locale for it to run 168 current_locale = locale.getlocale() 169 try: 170 locale.setlocale(locale.LC_ALL, "es_AR.UTF8") 171 except locale.Error: 172 test_localeIndependent.skip = "The es_AR.UTF8 locale is not installed." 173 finally: 174 locale.setlocale(locale.LC_ALL, current_locale) 175 145 176 def test_newSingleDigitDayOfMonth(self): 146 177 """ 147 178 A file with a high-resolution timestamp which falls on a day of the … … 161 192 '!--------- 0 0 0 0 Sep 02 09:33 foo') 162 193 163 194 164 165 195 class StdioClientTests(TestCase): 166 196 """ 167 197 Tests for L{cftp.StdioClient}. -
twisted/mail/imap4.py
=== modified file 'twisted/mail/imap4.py'
49 49 import twisted.cred.credentials 50 50 51 51 52 # locale-independent month names to use instead of strftime's 53 MONTH_NAMES = dict(zip(range(1, 13), 54 "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split())) 52 55 53 56 class MessageSet(object): 54 57 """ … … 1904 1907 log.msg("%d:%r: unpareseable internaldate: %r" % (id, msg, idate)) 1905 1908 raise IMAP4Exception("Internal failure generating INTERNALDATE") 1906 1909 1907 odate = time.strftime("%d-%b-%Y %H:%M:%S ", ttup[:9]) 1910 # need to specify the month manually, as strftime depends on locale 1911 strdate = time.strftime("%d-%%s-%Y %H:%M:%S ", ttup[:9]) 1912 odate = strdate % (MONTH_NAMES[ttup[1]],) 1908 1913 if ttup[9] is None: 1909 1914 odate = odate + "+0000" 1910 1915 else: -
twisted/mail/test/test_imap.py
=== modified file 'twisted/mail/test/test_imap.py'
12 12 except ImportError: 13 13 from StringIO import StringIO 14 14 15 import codecs 16 import locale 15 17 import os 16 18 import types 17 import codecs18 19 19 20 from zope.interface import implements 20 21 … … 3461 3462 def testFetchInternalDateUID(self): 3462 3463 return self.testFetchInternalDate(1) 3463 3464 3465 def testFetchInternalDateLocaleIndependent(self): 3466 """ 3467 The month name in the date should be locale independent. 3468 """ 3469 # Fake that we're in a language where December is not Dec 3470 current_locale = locale.getlocale() 3471 locale.setlocale(locale.LC_ALL, "es_AR.UTF8") 3472 self.addCleanup(locale.setlocale, locale.LC_ALL, current_locale) 3473 return self.testFetchInternalDate(1) 3474 3475 # if alternate locale is not available, the previous test will be 3476 # skipped, please install this locale for it to run 3477 current_locale = locale.getlocale() 3478 try: 3479 locale.setlocale(locale.LC_ALL, "es_AR.UTF8") 3480 except locale.Error: 3481 testFetchInternalDateLocaleIndependent.skip = ("The es_AR.UTF8 locale " 3482 "is not installed.") 3483 finally: 3484 locale.setlocale(locale.LC_ALL, current_locale) 3485 3464 3486 def testFetchEnvelope(self, uid=0): 3465 3487 self.function = self.client.fetchEnvelope 3466 3488 self.messages = '15'
