Changeset 1907:ec1e0f95c44d


Ignore:
Timestamp:
Jan 3, 2020, 6:26:33 PM (2 weeks ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
histedit_source:
f8930c8a2e2fcc4ab6c032768e5b3db78ece0752,2d51f19678d05fd8bc7d6011cdd5f67fa00031cd
Message:
Remove `Parser._mktime`

We no longer use the `time` module for the parsers but the `datetime`
module. Instead of `_mktime`, use `_datetime`.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ftputil/stat.py

    r1906 r1907  
    1 # Copyright (C) 2002-2019, Stefan Schwarzer <sschwarzer@sschwarzer.net>
     1# Copyright (C) 2002-2020, Stefan Schwarzer <sschwarzer@sschwarzer.net>
    22# and ftputil contributors (see `doc/contributors.txt`)
    33# See the file LICENSE for licensing terms.
     
    1111import re
    1212import stat
    13 import time
    1413
    1514import ftputil.error
     
    204203                "non-integer {} value {!r}".format(int_description, int_string)
    205204            )
    206 
    207     # pylint: disable=no-self-use
    208     def _mktime(self, mktime_tuple):
    209         """
    210         Return a float value like `time.mktime` does, but ...
    211 
    212         - Raise a `ParserError` if parts of `mktime_tuple` are
    213           invalid (say, a day is 32).
    214 
    215         - If the resulting float value would be smaller than 0.0
    216           (indicating a time before the "epoch") return a sentinel
    217           value of 0.0. Do this also if the native `mktime`
    218           implementation would raise an `OverflowError`.
    219         """
    220         datetime_tuple = mktime_tuple[:6]
    221         try:
    222             # Only for sanity checks, we're not interested in the
    223             # return value.
    224             datetime.datetime(*datetime_tuple)
    225         # For example, day == 32. Not all implementations of `mktime`
    226         # catch this kind of error.
    227         except ValueError:
    228             invalid_datetime = "%04d-%02d-%02d %02d:%02d:%02d" % datetime_tuple
    229             raise ftputil.error.ParserError(
    230                 "invalid datetime {0!r}".format(invalid_datetime)
    231             )
    232         try:
    233             time_float = time.mktime(mktime_tuple)
    234         except (OverflowError, ValueError):
    235             # Sentinel for times before the epoch, see ticket #83.
    236             time_float = 0.0
    237         # Don't allow float values smaller than 0.0 because, according
    238         # to https://docs.python.org/3/library/time.html#module-time ,
    239         # these might be undefined for some platforms.
    240         return max(0.0, time_float)
    241205
    242206    @staticmethod
     
    572536        st_atime = None
    573537        # st_mtime
    574         st_mtime, st_mtime_precision = self.parse_ms_time(date, time_, time_shift, with_precision=True)
     538        st_mtime, st_mtime_precision = self.parse_ms_time(
     539            date, time_, time_shift, with_precision=True
     540        )
    575541        # st_ctime
    576542        st_ctime = None
Note: See TracChangeset for help on using the changeset viewer.