Changeset 1568:9f7123eafbab


Ignore:
Timestamp:
Oct 4, 2014, 1:41:10 PM (7 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Reverted Philippe's changes to `stat.py`.

Using the same exception handling code three times is a bit much. :)

Also, the approach doesn't handle "real" errors properly, like a
month value 13. That said, the previous code by me doesn't handle
this either as it turned out. For example, my Linux system "wraps"
invalid values, so the month 13 in year y becomes the month 1 in
year y+1.

TODO: Use approach outlined in ticket #83:
http://ftputil.sschwarzer.net/trac/ticket/83#comment:17
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ftputil/stat.py

    r1567 r1568  
    188188            # `year_or_time` is really a year.
    189189            year, hour, minute = int(year_or_time), 0, 0
    190             try:
    191                 st_mtime = time.mktime( (year, month, day,
    192                                          hour, minute, 0, 0, 0, -1) )
    193             except (OverflowError, ValueError):
    194                 # use the epoch and a year precision if mktime fails
    195                 st_mtime = 0.0
    196                 st_mtime_precision = 365 * 12 * 24 * 60 * 60
     190            st_mtime = time.mktime( (year, month, day,
     191                                     hour, minute, 0, 0, 0, -1) )
    197192            # Precise up to a day.
    198193            st_mtime_precision = 24 * 60 * 60
     
    203198            # Try the current year
    204199            year = time.localtime()[0]
    205             try:
    206                 st_mtime = time.mktime( (year, month, day,
    207                                          hour, minute, 0, 0, 0, -1) )
    208             except (OverflowError, ValueError):
    209                 # use the epoch and a year precision if mktime fails
    210                 st_mtime = 0.0
    211                 st_mtime_precision = 365 * 12 * 24 * 60 * 60
     200            st_mtime = time.mktime( (year, month, day,
     201                                     hour, minute, 0, 0, 0, -1) )
    212202            # Times are precise up to a minute.
    213203            st_mtime_precision = 60
     
    226216            if st_mtime > time.time() + time_shift + st_mtime_precision:
    227217                # If it's in the future, use previous year.
    228                 try:
    229                     st_mtime = time.mktime( (year-1, month, day,
    230                                              hour, minute, 0, 0, 0, -1) )
    231                 except (OverflowError, ValueError):
    232                 # use the epoch and a year precision if mktime fails
    233                     st_mtime = 0.0
    234                     st_mtime_precision = 365 * 12 * 24 * 60 * 60
     218                st_mtime = time.mktime( (year-1, month, day,
     219                                         hour, minute, 0, 0, 0, -1) )
    235220        if with_precision:
    236221            return st_mtime, st_mtime_precision
Note: See TracChangeset for help on using the changeset viewer.