Changeset 1933:e84ebbbace3b


Ignore:
Timestamp:
Apr 11, 2020, 9:57:10 PM (16 months ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Make check/rounding part of `set_time_shift`

Before, `__assert_valid_time_shift` and, after the assertion,
`__rounded_time_shift`, were called only from `synchronize_times`.
However, it makes sense to call the former two methods for any
call of `set_time_shift`, including calls by users.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ftputil/host.py

    r1931 r1933  
    308308    # Time shift adjustment between client (i. e. us) and server
    309309    #
    310     def set_time_shift(self, time_shift):
    311         """
    312         Set the time shift value (i. e. the time difference between
    313         client and server, where the client time is in UTC) for this
    314         `FTPHost` object. By (my) definition, the time shift value is
    315         positive if the local time of the server is greater than the
    316         local time of the client (for the same physical time), i. e.
    317 
    318             time_shift =def= t_server - t_client_utc
    319         <=> t_server = t_client_utc + time_shift
    320         <=> t_client_utc = t_server - time_shift
    321 
    322         The time shift is measured in seconds.
    323         """
    324         old_time_shift = self.time_shift()
    325         if time_shift != old_time_shift:
    326             # If the time shift changed, all entries in the cache will have
    327             # wrong times with respect to the updated time shift, therefore
    328             # clear the cache.
    329             self.stat_cache.clear()
    330             self._time_shift = time_shift
    331 
    332     def time_shift(self):
    333         """
    334         Return the time shift between FTP server and client. See the
    335         docstring of `set_time_shift` for more on this value.
    336         """
    337         return self._time_shift
    338 
    339310    @staticmethod
    340311    def __rounded_time_shift(time_shift):
     
    381352                "from 15-minute units".format(time_shift, int(maximum_deviation))
    382353            )
     354
     355    def set_time_shift(self, time_shift):
     356        """
     357        Set the time shift value (i. e. the time difference between
     358        client and server, where the client time is in UTC) for this
     359        `FTPHost` object. By (my) definition, the time shift value is
     360        positive if the local time of the server is greater than the
     361        local time of the client (for the same physical time), i. e.
     362
     363            time_shift =def= t_server - t_client_utc
     364        <=> t_server = t_client_utc + time_shift
     365        <=> t_client_utc = t_server - time_shift
     366
     367        The time shift is measured in seconds.
     368        """
     369        self.__assert_valid_time_shift(time_shift)
     370        old_time_shift = self.time_shift()
     371        if time_shift != old_time_shift:
     372            # If the time shift changed, all entries in the cache will have
     373            # wrong times with respect to the updated time shift, therefore
     374            # clear the cache.
     375            self.stat_cache.clear()
     376            self._time_shift = self.__rounded_time_shift(time_shift)
     377
     378    def time_shift(self):
     379        """
     380        Return the time shift between FTP server and client. See the
     381        docstring of `set_time_shift` for more on this value.
     382        """
     383        return self._time_shift
    383384
    384385    def synchronize_times(self):
     
    446447            server_datetime = server_datetime.replace(year=server_datetime.year + 1)
    447448            time_shift = server_datetime.timestamp() - now
    448         # Do some sanity checks.
    449         self.__assert_valid_time_shift(time_shift)
    450         # If tests passed, store the time difference as time shift value.
    451         self.set_time_shift(self.__rounded_time_shift(time_shift))
     449        self.set_time_shift(time_shift)
    452450
    453451    #
Note: See TracChangeset for help on using the changeset viewer.