[Checkins] SVN: DateTime/trunk/ First Python 3 support changes - test run and we get errors/failures
Hano Schlichting
cvs-admin at zope.org
Sat Feb 23 14:14:36 UTC 2013
Log message for revision 129709:
First Python 3 support changes - test run and we get errors/failures
Changed:
U DateTime/trunk/src/DateTime/DateTime.py
U DateTime/trunk/src/DateTime/__init__.py
U DateTime/trunk/src/DateTime/pytz.txt
U DateTime/trunk/src/DateTime/pytz_support.py
_U DateTime/trunk/src/DateTime/tests/
U DateTime/trunk/src/DateTime/tests/test_datetime.py
A DateTime/trunk/tox.ini
-=-
Modified: DateTime/trunk/src/DateTime/DateTime.py
===================================================================
--- DateTime/trunk/src/DateTime/DateTime.py 2013-02-23 13:48:21 UTC (rev 129708)
+++ DateTime/trunk/src/DateTime/DateTime.py 2013-02-23 14:14:35 UTC (rev 129709)
@@ -11,9 +11,9 @@
#
##############################################################################
-import copy_reg
import math
import re
+import sys
from time import altzone
from time import daylight
from time import gmtime
@@ -23,15 +23,22 @@
from time import tzname
from datetime import datetime
-from pytz_support import PytzCache
-from zope.interface import implements
+from zope.interface import implementer
-from interfaces import IDateTime
-from interfaces import DateTimeError
-from interfaces import SyntaxError
-from interfaces import DateError
-from interfaces import TimeError
+from .interfaces import IDateTime
+from .interfaces import DateTimeError
+from .interfaces import SyntaxError
+from .interfaces import DateError
+from .interfaces import TimeError
+from .pytz_support import PytzCache
+if sys.version_info > (3, ):
+ import copyreg as copy_reg
+ basestring = str
+ long = int
+else:
+ import copy_reg
+
default_datefmt = None
@@ -65,7 +72,7 @@
to_month = tm[yr % 4 == 0 and (yr % 100 != 0 or yr % 400 == 0)][mo]
EPOCH = ((to_year + to_month + dy +
(hr / 24.0 + mn / 1440.0 + sc / 86400.0)) * 86400)
-jd1901 = 2415385L
+jd1901 = 2415385
_TZINFO = PytzCache()
@@ -202,7 +209,7 @@
# Calculates the timezone-dependent second (integer part only)
# from the timezone-independent second.
fset = _tzoffset(tz, t)
- return fset + long(math.floor(t)) + long(EPOCH) - 86400L
+ return fset + long(math.floor(t)) + long(EPOCH) - 86400
def _calcDependentSecond2(yr, mo, dy, hr, mn, sc):
@@ -217,12 +224,12 @@
# Derive the timezone-independent second from the timezone
# dependent second.
fsetAtEpoch = _tzoffset(tz, 0.0)
- nearTime = x - fsetAtEpoch - long(EPOCH) + 86400L + ms
+ nearTime = x - fsetAtEpoch - long(EPOCH) + 86400 + ms
# nearTime is now within an hour of being correct.
# Recalculate t according to DST.
fset = long(_tzoffset(tz, nearTime))
d = (x - fset) / 86400.0 + (ms / 86400.0)
- t = x - fset - long(EPOCH) + 86400L + ms
+ t = x - fset - long(EPOCH) + 86400 + ms
micros = (x + 86400 - fset) * 1000000 + \
long(round(ms * 1000000.0)) - long(EPOCH * 1000000.0)
s = d - math.floor(d)
@@ -252,40 +259,40 @@
def _julianday(yr, mo, dy):
y, m, d = long(yr), long(mo), long(dy)
- if m > 12L:
- y = y + m / 12L
- m = m % 12L
- elif m < 1L:
+ if m > 12:
+ y = y + m / 12
+ m = m % 12
+ elif m < 1:
m = -m
- y = y - m / 12L - 1L
- m = 12L - m % 12L
- if y > 0L:
- yr_correct = 0L
+ y = y - m / 12 - 1
+ m = 12 - m % 12
+ if y > 0:
+ yr_correct = 0
else:
- yr_correct = 3L
- if m < 3L:
- y, m = y - 1L, m + 12L
- if y * 10000L + m * 100L + d > 15821014L:
- b = 2L - y / 100L + y / 400L
+ yr_correct = 3
+ if m < 3:
+ y, m = y - 1, m + 12
+ if y * 10000 + m * 100 + d > 15821014:
+ b = 2 - y / 100 + y / 400
else:
- b = 0L
- return ((1461L * y - yr_correct) / 4L +
- 306001L * (m + 1L) / 10000L + d + 1720994L + b)
+ b = 0
+ return ((1461 * y - yr_correct) / 4 +
+ 306001 * (m + 1) / 10000 + d + 1720994 + b)
def _calendarday(j):
j = long(j)
- if (j < 2299160L):
- b = j + 1525L
+ if (j < 2299160):
+ b = j + 1525
else:
- a = (4L * j - 7468861L) / 146097L
- b = j + 1526L + a - a / 4L
- c = (20L * b - 2442L) / 7305L
- d = 1461L * c / 4L
- e = 10000L * (b - d) / 306001L
- dy = int(b - d - 306001L * e / 10000L)
- mo = (e < 14L) and int(e - 1L) or int(e - 13L)
- yr = (mo > 2) and (c - 4716L) or (c - 4715L)
+ a = (4 * j - 7468861) / 146097
+ b = j + 1526 + a - a / 4
+ c = (20 * b - 2442) / 7305
+ d = 1461 * c / 4
+ e = 10000 * (b - d) / 306001
+ dy = int(b - d - 306001 * e / 10000)
+ mo = (e < 14) and int(e - 1) or int(e - 13)
+ yr = (mo > 2) and (c - 4716) or (c - 4715)
return (int(yr), int(mo), int(dy))
@@ -369,6 +376,7 @@
return self.dt.strftime(self.format)
+ at implementer(IDateTime)
class DateTime(object):
"""DateTime objects represent instants in time and provide
interfaces for controlling its representation without
@@ -412,8 +420,6 @@
and numeric operations return a new DateTime object rather than
modify the current object."""
- implements(IDateTime)
-
# For security machinery:
__roles__ = None
__allow_access_to_unprotected_subobjects__ = 1
@@ -838,7 +844,7 @@
tz = self._calcTimezoneName(x, ms)
s, d, t, microsecs = _calcIndependentSecondEtc(tz, x, ms)
- self._dayoffset = int((_julianday(yr, mo, dy) + 2L) % 7)
+ self._dayoffset = int((_julianday(yr, mo, dy) + 2) % 7)
# Round to nearest microsecond in platform-independent way. You
# cannot rely on C sprintf (Python '%') formatting to round
# consistently; doing it ourselves ensures that all but truly
@@ -875,7 +881,7 @@
if not _multipleZones:
return _localzone0
fsetAtEpoch = _tzoffset(_localzone0, 0.0)
- nearTime = x - fsetAtEpoch - long(EPOCH) + 86400L + ms
+ nearTime = x - fsetAtEpoch - long(EPOCH) + 86400 + ms
# nearTime is within an hour of being correct.
try:
ltm = safelocaltime(nearTime)
@@ -887,7 +893,7 @@
yr, mo, dy, hr, mn, sc = _calcYMDHMS(x, 0)
yr = ((yr - 1970) % 28) + 1970
x = _calcDependentSecond2(yr, mo, dy, hr, mn, sc)
- nearTime = x - fsetAtEpoch - long(EPOCH) + 86400L + ms
+ nearTime = x - fsetAtEpoch - long(EPOCH) + 86400 + ms
# nearTime might still be negative if we are east of Greenwich.
# But we can asume on 1969/12/31 were no timezone changes.
Modified: DateTime/trunk/src/DateTime/__init__.py
===================================================================
--- DateTime/trunk/src/DateTime/__init__.py 2013-02-23 13:48:21 UTC (rev 129708)
+++ DateTime/trunk/src/DateTime/__init__.py 2013-02-23 14:14:35 UTC (rev 129709)
@@ -10,5 +10,8 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
-from DateTime import DateTime
-from DateTime import Timezones
+
+from .DateTime import DateTime
+from .DateTime import Timezones
+
+__all__ = ('DateTime', 'Timezones')
Modified: DateTime/trunk/src/DateTime/pytz.txt
===================================================================
--- DateTime/trunk/src/DateTime/pytz.txt 2013-02-23 13:48:21 UTC (rev 129708)
+++ DateTime/trunk/src/DateTime/pytz.txt 2013-02-23 14:14:35 UTC (rev 129709)
@@ -144,7 +144,7 @@
>>> for name in cache._zlst:
... if not name.lower() in cache._zidx:
- ... print "Error %s not in _zidx" % name.lower()
+ ... print("Error %s not in _zidx" % name.lower())
The _zmap attribute maps the names in _zidx to official names in _zlst.
Modified: DateTime/trunk/src/DateTime/pytz_support.py
===================================================================
--- DateTime/trunk/src/DateTime/pytz_support.py 2013-02-23 13:48:21 UTC (rev 129708)
+++ DateTime/trunk/src/DateTime/pytz_support.py 2013-02-23 14:14:35 UTC (rev 129709)
@@ -11,12 +11,14 @@
#
##############################################################################
+from datetime import datetime, timedelta
+
import pytz
import pytz.reference
from pytz.tzinfo import StaticTzInfo, memorized_timedelta
-from datetime import datetime, timedelta
-from interfaces import DateTimeError
+from .interfaces import DateTimeError
+
EPOCH = datetime.utcfromtimestamp(0).replace(tzinfo=pytz.utc)
_numeric_timezone_data = {
Property changes on: DateTime/trunk/src/DateTime/tests
___________________________________________________________________
Modified: svn:ignore
- *so
*.pyc
build
+ *.pyc
*.pyo
__pycache__
Modified: DateTime/trunk/src/DateTime/tests/test_datetime.py
===================================================================
--- DateTime/trunk/src/DateTime/tests/test_datetime.py 2013-02-23 13:48:21 UTC (rev 129708)
+++ DateTime/trunk/src/DateTime/tests/test_datetime.py 2013-02-23 14:14:35 UTC (rev 129709)
@@ -12,21 +12,26 @@
#
##############################################################################
-import cPickle
+from datetime import date, datetime, tzinfo, timedelta
import math
import os
+import sys
import time
import unittest
+import pytz
+
from DateTime.DateTime import _findLocalTimeZoneName
from DateTime import DateTime
-from datetime import date, datetime, tzinfo, timedelta
-import pytz
+if sys.version_info > (3, ):
+ import pickle
+else:
+ import cPickle as pickle
+
try:
__file__
except NameError:
- import sys
f = sys.argv[0]
else:
f = __file__
@@ -212,22 +217,22 @@
def test_pickle(self):
dt = DateTime()
- data = cPickle.dumps(dt, 1)
- new = cPickle.loads(data)
+ data = pickle.dumps(dt, 1)
+ new = pickle.loads(data)
for key in DateTime.__slots__:
self.assertEqual(getattr(dt, key), getattr(new, key))
def test_pickle_with_tz(self):
dt = DateTime('2002/5/2 8:00am GMT+8')
- data = cPickle.dumps(dt, 1)
- new = cPickle.loads(data)
+ data = pickle.dumps(dt, 1)
+ new = pickle.loads(data)
for key in DateTime.__slots__:
self.assertEqual(getattr(dt, key), getattr(new, key))
def test_pickle_with_micros(self):
dt = DateTime('2002/5/2 8:00:14.123 GMT+8')
- data = cPickle.dumps(dt, 1)
- new = cPickle.loads(data)
+ data = pickle.dumps(dt, 1)
+ new = pickle.loads(data)
for key in DateTime.__slots__:
self.assertEqual(getattr(dt, key), getattr(new, key))
@@ -245,7 +250,7 @@
'\x1bM\xd2\x07U\x08_nearsecq\x1cG\x00\x00\x00\x00\x00\x00\x00'
'\x00U\x07_pmhourq\x1dK\x08U\n_dayoffsetq\x1eK\x04U\x04timeq'
'\x1fG?\xd5UUUV\x00\x00ub.')
- new = cPickle.loads(data)
+ new = pickle.loads(data)
for key in DateTime.__slots__:
self.assertEqual(getattr(dt, key), getattr(new, key))
@@ -262,7 +267,7 @@
'\x04_dayq\x19K\x02U\x05_yearq\x1aM\xd2\x07U\x08_nearsecq'
'\x1bG\x00\x00\x00\x00\x00\x00\x00\x00U\x07_pmhourq\x1cK\x08U'
'\n_dayoffsetq\x1dK\x04U\x04timeq\x1eG?\xd5UUUV\x00\x00ub.')
- new = cPickle.loads(data)
+ new = pickle.loads(data)
for key in DateTime.__slots__:
self.assertEqual(getattr(dt, key), getattr(new, key))
@@ -288,7 +293,7 @@
dsec = (dt.millis() - dt1.millis()) / 1000.0
ddays = math.floor((dsec / 86400.0) + 0.5)
- self.assertEqual(ddays, 3000000L, ddays)
+ self.assertEqual(ddays, 3000000, ddays)
def test_tzoffset(self):
# Test time-zone given as an offset
@@ -522,7 +527,7 @@
def test_calcTimezoneName(self):
from DateTime.interfaces import TimeError
- timezone_dependent_epoch = 2177452800L
+ timezone_dependent_epoch = 2177452800
try:
DateTime()._calcTimezoneName(timezone_dependent_epoch, 0)
except TimeError:
@@ -555,8 +560,10 @@
def testStrftimeUnicode(self):
dt = DateTime('2002-05-02T08:00:00+00:00')
- ok = dt.strftime('Le %d/%m/%Y a %Hh%M').replace('a', u'\xe0')
- self.assertEqual(dt.strftime(u'Le %d/%m/%Y \xe0 %Hh%M'), ok)
+ uchar = b'\xe0'.decode('latin1')
+ ok = dt.strftime('Le %d/%m/%Y a %Hh%M').replace('a', uchar)
+ ustr = b'Le %d/%m/%Y \xe0 %Hh%M'.decode('latin-1')
+ self.assertEqual(dt.strftime(ustr), ok)
def testTimezoneNaiveHandling(self):
# checks that we assign timezone naivity correctly
Added: DateTime/trunk/tox.ini
===================================================================
--- DateTime/trunk/tox.ini (rev 0)
+++ DateTime/trunk/tox.ini 2013-02-23 14:14:35 UTC (rev 129709)
@@ -0,0 +1,12 @@
+[tox]
+envlist =
+ py26,py27,py32,py33
+
+[testenv]
+commands =
+ python setup.py test -q
+# without explicit deps, setup.py test will download a bunch of eggs into $PWD
+# (and it seems I can't use zope.dottedname[testing] here, so forget DRY)
+deps =
+ zope.interface
+ pytz
More information about the checkins
mailing list