Ticket #4937: locale-independent-formatting.patch

File locale-independent-formatting.patch, 2.4 KB (added by facundobatista, 6 years ago)
  • twisted/conch/ls.py

    === modified file 'twisted/conch/ls.py'
     
    77
    88from time import time, strftime, localtime
    99
     10# locale-independent month names to use instead of strftime's
     11MONTH_NAMES = dict(zip(range(1, 13),
     12                   "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split()))
     13
    1014
    1115def lsLine(name, s):
    1216    mode = s.st_mode
     
    3943    if mode&stat.S_ISGID:
    4044        if perms[6] == 'x': perms[6] = 's'
    4145        else: perms[6] = 'S'
    42     l = perms.tostring()
    43     l += str(s.st_nlink).rjust(5) + ' '
     46
    4447    un = str(s.st_uid)
    45     l += un.ljust(9)
    4648    gr = str(s.st_gid)
    47     l += gr.ljust(9)
    4849    sz = str(s.st_size)
    49     l += sz.rjust(8)
    50     l += ' '
    5150    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)
    5256    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)
    5458    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)
    5864
    5965
    6066__all__ = ['lsLine']
  • twisted/mail/imap4.py

    === modified file 'twisted/mail/imap4.py'
     
    4949import twisted.cred.credentials
    5050
    5151
     52# locale-independent month names to use instead of strftime's
     53MONTH_NAMES = dict(zip(range(1, 13),
     54                   "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split()))
    5255
    5356class MessageSet(object):
    5457    """
     
    19041907            log.msg("%d:%r: unpareseable internaldate: %r" % (id, msg, idate))
    19051908            raise IMAP4Exception("Internal failure generating INTERNALDATE")
    19061909
    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]],)
    19081913        if ttup[9] is None:
    19091914            odate = odate + "+0000"
    19101915        else: