Ticket #4937: locale-independent-formatting-with-tests.patch
| File locale-independent-formatting-with-tests.patch, 5.4 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) + ' ' 46 44 47 un = str(s.st_uid) 45 l += un.ljust(9)46 48 gr = str(s.st_gid) 47 l += gr.ljust(9)48 49 sz = str(s.st_size) 49 l += sz.rjust(8)50 l += ' '51 50 sixmo = 60 * 60 * 24 * 7 * 26 51 l = [perms.tostring(), str(s.st_nlink).rjust(5), ' ', 52 un.ljust(9), gr.ljust(9), sz.rjust(8), ' '] 53 54 # need to specify the month manually, as strftime depends on locale 55 ttup = localtime(s.st_mtime) 52 56 if s.st_mtime + sixmo < time(): # last edited more than 6mo ago 53 l += strftime("%b %d %Y ", localtime(s.st_mtime))57 strtime = strftime("%%s %d %Y ", ttup) 54 58 else: 55 l += strftime("%b %d %H:%M ", localtime(s.st_mtime)) 56 l += name 57 return l 59 strtime = strftime("%%s %d %H:%M ", ttup) 60 l.append(strtime % (MONTH_NAMES[ttup[1]],)) 61 62 l.append(name) 63 return ''.join(l) 58 64 59 65 60 66 __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 12 13 from twisted.conch.test.test_ssh import Crypto, pyasn1 14 from twisted.python import runtime 13 15 14 16 _reason = None 15 17 if Crypto and pyasn1: … … 142 144 '!--------- 0 0 0 0 Aug 29 09:33 foo') 143 145 144 146 147 def test_localeIndependent(self): 148 """ 149 The month name in the date should be locale independent. 150 """ 151 # A point about three months in the past. 152 then = self.now - (60 * 60 * 24 * 31 * 3) 153 stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0)) 154 155 # Fake that we're in a language where August is not Aug (e.g.: Spanish) 156 current_locale = locale.getlocale() 157 locale.setlocale(locale.LC_ALL, "es_AR.UTF8") 158 self.addCleanup(locale.setlocale, locale.LC_ALL, current_locale) 159 160 self.assertEqual( 161 self._lsInTimezone('America/New_York', stat), 162 '!--------- 0 0 0 0 Aug 28 17:33 foo') 163 self.assertEqual( 164 self._lsInTimezone('Pacific/Auckland', stat), 165 '!--------- 0 0 0 0 Aug 29 09:33 foo') 166 167 if runtime.platform.isWindows(): 168 test_localeIndependent.skip = "No es_AR.UTF8 locale in Windows." 169 170 145 171 def test_newSingleDigitDayOfMonth(self): 146 172 """ 147 173 A file with a high-resolution timestamp which falls on a day of the -
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 … … 29 30 from twisted.trial import unittest 30 31 from twisted.python import util 31 32 from twisted.python import failure 33 from twisted.python import runtime 32 34 33 35 from twisted import cred 34 36 import twisted.cred.error … … 3461 3463 def testFetchInternalDateUID(self): 3462 3464 return self.testFetchInternalDate(1) 3463 3465 3466 def testFetchInternalDateLocaleIndependent(self): 3467 """ 3468 The month name in the date should be locale independent. 3469 """ 3470 # Fake that we're in a language where December is not Dec 3471 current_locale = locale.getlocale() 3472 locale.setlocale(locale.LC_ALL, "es_AR.UTF8") 3473 self.addCleanup(locale.setlocale, locale.LC_ALL, current_locale) 3474 return self.testFetchInternalDate(1) 3475 3476 if runtime.platform.isWindows(): 3477 testFetchInternalDateLocaleIndependent.skip = """ 3478 No es_AR.UTF8 locale in Windows. 3479 """ 3480 3464 3481 def testFetchEnvelope(self, uid=0): 3465 3482 self.function = self.client.fetchEnvelope 3466 3483 self.messages = '15'
