~sschwarzer/ftputil

3e5e6187eff6fe2348665767bea739393d718585 — Stefan Schwarzer 9 years ago ebda8dd
Handle four-digit year in Microsoft directory format (ticket #67).
2 files changed, 28 insertions(+), 2 deletions(-)

M ftputil/ftp_stat.py
M test/test_ftp_stat.py
M ftputil/ftp_stat.py => ftputil/ftp_stat.py +4 -1
@@ 237,7 237,10 @@ class Parser(object):
        # send a mail (see ftputil.txt/html).
        try:
            month, day, year = [int(part) for part in date.split('-')]
            if year >= 70:
            if year >= 1000:
                # We have a four-digit year, so no need for heuristics.
                pass
            elif year >= 70:
                year = 1900 + year
            else:
                year = 2000 + year

M test/test_ftp_stat.py => test/test_ftp_stat.py +24 -1
@@ 33,6 33,9 @@ def stat_tuple_to_seconds(t):

class TestParsers(unittest.TestCase):

    #
    # Helper methods
    #
    def _test_valid_lines(self, parser_class, lines, expected_stat_results):
        parser = parser_class()
        for line, expected_stat_result in zip(lines, expected_stat_results):


@@ 67,6 70,9 @@ class TestParsers(unittest.TestCase):
        else:
            return now[0] - 1

    #
    # Unix parser
    #
    def test_valid_unix_lines(self):
        lines = [
          "drwxr-sr-x   2 45854    200           512 May  4  2000 "


@@ 127,7 133,10 @@ class TestParsers(unittest.TestCase):
        self._test_valid_lines(ftp_stat.UnixParser, lines,
                               expected_stat_results)

    def test_valid_ms_lines(self):
    #
    # Microsoft parser
    #
    def test_valid_ms_lines_two_digit_year(self):
        lines = [
          "07-27-01  11:16AM       <DIR>          Test",
          "10-23-95  03:25PM       <DIR>          WindowsXP",


@@ 149,6 158,20 @@ class TestParsers(unittest.TestCase):
          ]
        self._test_valid_lines(ftp_stat.MSParser, lines, expected_stat_results)

    def test_valid_ms_lines_four_digit_year(self):
        # See http://ftputil.sschwarzer.net/trac/ticket/67
        lines = [
          "10-19-2012  03:13PM       <DIR>          SYNCDEST",
          "10-19-2012  03:13PM       <DIR>          SYNCSOURCE"
          ]
        expected_stat_results = [
          [16640, None, None, None, None, None, None, None,
           (2012, 10, 19, 15, 13, 0), None, "SYNCDEST", None],
          [16640, None, None, None, None, None, None, None,
           (2012, 10, 19, 15, 13, 0), None, "SYNCSOURCE", None],
          ]
        self._test_valid_lines(ftp_stat.MSParser, lines, expected_stat_results)

    def test_invalid_ms_lines(self):
        lines = [
          "07-27-01  11:16AM                      Test",