Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-07 Thread Guido van Rossum
I think I've said all I can say in this thread; I'm sure you will come up with a satisfactory solution. -- --Guido van Rossum (python.org/~guido) ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-06 Thread Victor Stinner
Le mercredi 05 janvier 2011 à 23:48 -0500, Alexander Belopolsky a écrit : I would be happy with just if accept2dyear: if 69 = y = 99: y += 1900 elif 0 = y = 68: y += 2000 # call system function with tm_year = y - 1900 Perfect. That's what I

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-06 Thread Victor Stinner
Le jeudi 06 janvier 2011 à 00:10 -0500, Alexander Belopolsky a écrit : If calling specific system functions such as strftime with tm_year 0 is deemed unsafe, we can move the check to where the system function is called. What do you mean by unsafe? Does it crash? On my Linux box, strftime(%Y)

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-06 Thread R. David Murray
On Thu, 06 Jan 2011 12:55:24 +0100, Victor Stinner victor.stin...@haypocalc.com wrote: Le jeudi 06 janvier 2011 à 00:10 -0500, Alexander Belopolsky a écrit : If calling specific system functions such as strftime with tm_year 0 is deemed unsafe, we can move the check to where the system

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-06 Thread Victor Stinner
Le jeudi 06 janvier 2011 à 10:47 -0500, R. David Murray a écrit : On Thu, 06 Jan 2011 12:55:24 +0100, Victor Stinner victor.stin...@haypocalc.com wrote: Le jeudi 06 janvier 2011 à 00:10 -0500, Alexander Belopolsky a écrit : If calling specific system functions such as strftime with tm_year

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-06 Thread Eric Smith
On 01/06/2011 11:08 AM, Victor Stinner wrote: Le jeudi 06 janvier 2011 à 10:47 -0500, R. David Murray a écrit : On Thu, 06 Jan 2011 12:55:24 +0100, Victor Stinnervictor.stin...@haypocalc.com wrote: Le jeudi 06 janvier 2011 à 00:10 -0500, Alexander Belopolsky a écrit : If calling specific

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-06 Thread Alexander Belopolsky
On Thu, Jan 6, 2011 at 6:47 AM, Victor Stinner victor.stin...@haypocalc.com wrote: Le mercredi 05 janvier 2011 à 23:48 -0500, Alexander Belopolsky a écrit : I would be happy with just    if accept2dyear:        if 69 = y = 99:            y += 1900        elif 0 = y = 68:            y +=

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-06 Thread Stephen J. Turnbull
R. David Murray writes: I believe that we have had several cases where Windows crashed when out-of-range values were passed to the CRT that other platforms accepted. XEmacs had crashes due to strftime on Windows native with VC++. Never went so far as to BSOD, but a couple of users lost

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-05 Thread Alexander Belopolsky
On Mon, Jan 3, 2011 at 7:47 PM, Guido van Rossum gu...@python.org wrote: Given the rule garbage in - garbage out, I'd do the most useful thing, which would be to produce a longer output string (and update the docs). This would match the behavior of e.g. '%04d' % y when y . If that means

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-05 Thread Antoine Pitrou
On Wed, 5 Jan 2011 12:33:55 -0500 Alexander Belopolsky alexander.belopol...@gmail.com wrote: On Mon, Jan 3, 2011 at 7:47 PM, Guido van Rossum gu...@python.org wrote: Given the rule garbage in - garbage out, I'd do the most useful thing, which would be to produce a longer output string (and

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-05 Thread Alexander Belopolsky
On Wed, Jan 5, 2011 at 12:48 PM, Antoine Pitrou solip...@pitrou.net wrote: .. Couldn't we deprecate and remove time.accept2dyear? It has been there for backward compatibility since Python 1.5.2. It will be useful for another 50 years or so. (POSIX 2-digit years cover 1969 - 2068.) In any

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-05 Thread Guido van Rossum
On Wed, Jan 5, 2011 at 10:12 AM, Alexander Belopolsky alexander.belopol...@gmail.com wrote: On Wed, Jan 5, 2011 at 12:48 PM, Antoine Pitrou solip...@pitrou.net wrote: .. Couldn't we deprecate and remove time.accept2dyear? It has been there for backward compatibility since Python 1.5.2. It

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-05 Thread Alexander Belopolsky
On Wed, Jan 5, 2011 at 2:19 PM, Guido van Rossum gu...@python.org wrote: .. extending accepted range is a borderline case IMO. I like accepting all years = 1 when accept2dyear is False. Why = 1? Shouldn't it be = 1900 - maxint? Also, what is your take on always accepting [1000 - 1899]?

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-05 Thread Guido van Rossum
On Wed, Jan 5, 2011 at 12:58 PM, Alexander Belopolsky alexander.belopol...@gmail.com wrote: On Wed, Jan 5, 2011 at 2:19 PM, Guido van Rossum gu...@python.org wrote: .. extending accepted range is a borderline case IMO. I like accepting all years = 1 when accept2dyear is False. Why = 1?

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-05 Thread Glyph Lefkowitz
On Jan 5, 2011, at 4:33 PM, Guido van Rossum wrote: Shouldn't the logic be to take the current year into account? By the time 2070 comes around, I'd expect 70 to refer to 2070, not to 1970. In fact, I'd expect it to refer to 2070 long before 2070 comes around. All of which makes me think

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-05 Thread Alexander Belopolsky
On Wed, Jan 5, 2011 at 4:33 PM, Guido van Rossum gu...@python.org wrote: .. Why = 1? Because that's what the datetime module accepts. What the datetime module accepts is irrelevant here. Note that functions affected by accept2dyear are: time.mktime(), time.asctime(), time.strftime() and

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-05 Thread Guido van Rossum
On Wed, Jan 5, 2011 at 2:55 PM, Alexander Belopolsky alexander.belopol...@gmail.com wrote: On Wed, Jan 5, 2011 at 4:33 PM, Guido van Rossum gu...@python.org wrote: .. Why = 1? Because that's what the datetime module accepts. What the datetime module accepts is irrelevant here. Not

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-05 Thread Alexander Belopolsky
On Wed, Jan 5, 2011 at 6:12 PM, Guido van Rossum gu...@python.org wrote: .. If they both impose some arbitrary limits, it would be easier for users to remember the limits if they were the same for both modules. Unfortunately, that is not possible on 32-bit systems where range supported by say

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-05 Thread Guido van Rossum
I'm sorry, but at this point I'm totally confused about what you're asking or proposing. You keep referring to various implementation details and behaviors. Maybe if you summarized how the latest implementation (say python 3.2) works and what you propose to change that would be quicker than this

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-05 Thread Alexander Belopolsky
On Wed, Jan 5, 2011 at 9:18 PM, Guido van Rossum gu...@python.org wrote: I'm sorry, but at this point I'm totally confused about what you're asking or proposing. You keep referring to various implementation details and behaviors. Maybe if you summarized how the latest implementation (say

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-05 Thread Guido van Rossum
On Wed, Jan 5, 2011 at 6:46 PM, Alexander Belopolsky alexander.belopol...@gmail.com wrote: On Wed, Jan 5, 2011 at 9:18 PM, Guido van Rossum gu...@python.org wrote: I'm sorry, but at this point I'm totally confused about what you're asking or proposing. You keep referring to various

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-05 Thread Alexander Belopolsky
On Wed, Jan 5, 2011 at 10:50 PM, Guido van Rossum gu...@python.org wrote: .. I propose to change that to if y 1000:    if accept2dyear:        if 69 = y = 99:            y += 1900        elif 0 = y = 68:            y += 2000        else:            raise ValueError(year out of range) #

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-05 Thread Alexander Belopolsky
On Wed, Jan 5, 2011 at 10:50 PM, Guido van Rossum gu...@python.org wrote: .. But what guarantees do we have that the system functions accept negative values for tm_year on all relevant platforms? Also note that the subject of this thread is limited to time.asctime and time.ctime. The other

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-04 Thread Alexander Belopolsky
On Mon, Jan 3, 2011 at 7:47 PM, Guido van Rossum gu...@python.org wrote: Given the rule garbage in - garbage out, I'd do the most useful thing, which would be to produce a longer output string (and update the docs). I did not know that GIGO was a design rule, but after thinking about it some

[Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-03 Thread Alexander Belopolsky
There are several reports of bugs caused by the fact that the behavior of C functions asctime and ctime is undefined when they are asked to format time for more than 4-digit years: http://bugs.python.org/issue8013 http://bugs.python.org/issue6608 (closed) http://bugs.python.org/issue10563

Re: [Python-Dev] Checking input range in time.asctime and time.ctime

2011-01-03 Thread Guido van Rossum
Given the rule garbage in - garbage out, I'd do the most useful thing, which would be to produce a longer output string (and update the docs). This would match the behavior of e.g. '%04d' % y when y . If that means the platform libc asctime/ctime can't be used, too bad. --Guido On Mon, Jan