Commits

Martin Matusiak committed 6fcd3a9 Merge

Merged in numerodix/pypy/py3.3-fixes2 (pull request #271)

remove time.accept2dyear (removed in python 3.3)

  • Participants
  • Parent commits 0c8f0c1, df851de
  • Branches py3.3

Comments (0)

Files changed (3)

pypy/module/rctime/__init__.py

         from pypy.module.rctime import interp_time
 
         interp_time._init_timezone(space)
-        interp_time._init_accept2dyear(space)
-

pypy/module/rctime/interp_time.py

 c_strftime = external('strftime', [rffi.CCHARP, rffi.SIZE_T, rffi.CCHARP, TM_P],
                       rffi.SIZE_T)
 
-def _init_accept2dyear(space):
-    if os.environ.get("PYTHONY2K"):
-        accept2dyear = 0
-    else:
-        accept2dyear = 1
-    _set_module_object(space, "accept2dyear", space.wrap(accept2dyear))
-
 def _init_timezone(space):
     timezone = daylight = altzone = 0
     tzname = ["", ""]
             glob_buf.c_tm_zone = lltype.nullptr(rffi.CCHARP.TO)
             rffi.setintfield(glob_buf, 'c_tm_gmtoff', 0)
 
-    if y < 1000:
-        w_accept2dyear = _get_module_object(space, "accept2dyear")
-        accept2dyear = space.is_true(w_accept2dyear)
-
-        if accept2dyear:
-            if 69 <= y <= 99:
-                y += 1900
-            elif 0 <= y <= 68:
-                y += 2000
-            else:
-                raise OperationError(space.w_ValueError,
-                                     space.wrap("year out of range"))
-            space.warn(space.wrap("Century info guessed for a 2-digit year."),
-                       space.w_DeprecationWarning)
-
     # tm_wday does not need checking of its upper-bound since taking "%
     #  7" in _gettmarg() automatically restricts the range.
     if rffi.getintfield(glob_buf, 'c_tm_wday') < -1:

pypy/module/rctime/test/test_rctime.py

 
     def test_attributes(self):
         import time as rctime
-        assert isinstance(rctime.accept2dyear, int)
         assert isinstance(rctime.altzone, int)
         assert isinstance(rctime.daylight, int)
         assert isinstance(rctime.timezone, int)
         res = rctime.mktime(rctime.localtime())
         assert isinstance(res, float)
 
+        # year cannot be -1
         ltime = rctime.localtime()
-        rctime.accept2dyear == 0
         ltime = list(ltime)
         ltime[0] = -1
-        raises(ValueError, rctime.mktime, tuple(ltime))
-        rctime.accept2dyear == 1
+        raises(OverflowError, rctime.mktime, tuple(ltime))
 
-        ltime = list(ltime)
-        ltime[0] = 67
-        ltime = tuple(ltime)
-        if os.name != "nt" and sys.maxsize < 1<<32:   # time_t may be 64bit
-            raises(OverflowError, rctime.mktime, ltime)
-
+        # year cannot be 100
         ltime = list(ltime)
         ltime[0] = 100
-        raises(ValueError, rctime.mktime, tuple(ltime))
+        raises(OverflowError, rctime.mktime, tuple(ltime))
 
         t = rctime.time()
         assert int(rctime.mktime(rctime.localtime(t))) == int(t)
         assert asc[-len(str(bigyear)):] == str(bigyear)
         raises(OverflowError, rctime.asctime, (bigyear + 1,) + (0,)*8)
 
-    def test_accept2dyear_access(self):
-        import time as rctime
-
-        accept2dyear = rctime.accept2dyear
-        del rctime.accept2dyear
-        try:
-            # with year >= 1900 this shouldn't need to access accept2dyear
-            assert rctime.asctime((2000,) + (0,) * 8).split()[-1] == '2000'
-        finally:
-            rctime.accept2dyear = accept2dyear
-
-    def test_accept2dyear_bad(self):
-        import time as rctime
-        class X:
-            def __bool__(self):
-                raise RuntimeError('boo')
-        orig, rctime.accept2dyear = rctime.accept2dyear, X()
-        try:
-            raises(RuntimeError, rctime.asctime, (200,)  + (0,) * 8)
-        finally:
-            rctime.accept2dyear = orig
-
     def test_struct_time(self):
         import time as rctime
         raises(TypeError, rctime.struct_time)
         raises(TypeError, rctime.strftime, ())
         raises(TypeError, rctime.strftime, (1,))
         raises(TypeError, rctime.strftime, range(8))
-        exp = '2000 01 01 00 00 00 1 001'
+        exp = '0 01 01 00 00 00 1 001'
         assert rctime.strftime("%Y %m %d %H %M %S %w %j", (0,)*9) == exp
 
         # Guard against invalid/non-supported format string
         else:
             assert rctime.strftime('%f') == '%f'
 
+    def test_strftime_y2k(self):
+        '''Port of cpython's datetimetester.test_strftime_y2k.'''
+        import time as rctime
+
+        ltime = list(rctime.gmtime())
+        for y in (1, 49, 70, 99, 100, 999, 1000, 1970):
+            ltime[0] = y
+
+            def fmt(template):
+                return rctime.strftime(template, tuple(ltime))
+
+            if fmt('%Y') != '%04d' % y:
+                # Year 42 returns '42', not padded
+                assert fmt("%Y") == '%d' % y
+                # '0042' is obtained anyway
+                assert fmt("%4Y") == '%04d' % y
+
     def test_strftime_ext(self):
         import time as rctime
 
         # of the time tuple.
 
         # check year
-        if rctime.accept2dyear:
-            raises(ValueError, rctime.strftime, '', (-1, 1, 1, 0, 0, 0, 0, 1, -1))
-            raises(ValueError, rctime.strftime, '', (100, 1, 1, 0, 0, 0, 0, 1, -1))
         rctime.strftime('', (1899, 1, 1, 0, 0, 0, 0, 1, -1))
         rctime.strftime('', (0, 1, 1, 0, 0, 0, 0, 1, -1))