Commit a4e1e8a3 authored by Chris McDonough's avatar Chris McDonough

Remove magical cast to int. Raise a ValueError explicitly when we

notice that the date is a long.
parent 60d04a03
......@@ -11,7 +11,7 @@
#
##############################################################################
"""$Id: DateRangeIndex.py,v 1.8 2003/11/02 11:57:58 chrism Exp $
"""$Id: DateRangeIndex.py,v 1.9 2003/11/04 14:53:28 chrism Exp $
"""
import os
......@@ -405,16 +405,11 @@ class DateRangeIndex(UnIndex):
value = dt_obj.millis() / 1000 / 60 # flatten to minutes
if isinstance( value, DateTime ):
value = value.millis() / 1000 / 60 # flatten to minutes
# XXX 2038K bug:
# we might still be dealing with a long.
# we're using IOBTrees with dates as keys and we
# cant convert long to int if its > sys.maxint.
# BTrees code blows up if we try to ask it for a long key,
# so we punt here. In a future version, we should either
# come up with a LOBTree or use OOBTrees to store datum.
if value > sys.maxint:
value = sys.maxint
return int( value )
result = int( value )
if isinstance(result, long): # this won't work
raise ValueError( '%s is not within the range of dates allowed'
'by a DateRangeIndex' % value)
return result
InitializeClass( DateRangeIndex )
......
......@@ -13,6 +13,7 @@
import Zope
import unittest
import sys
from Products.PluginIndexes.DateRangeIndex.DateRangeIndex import DateRangeIndex
......@@ -111,6 +112,13 @@ class DRI_Tests( unittest.TestCase ):
for result, match in map( None, results, matches ):
assert work.getEntryForObject( result ) == match.datum()
def test_longdates( self ):
self.assertRaises(ValueError, self._badlong )
def _badlong(self):
work = DateRangeIndex ('work', 'start', 'stop' )
bad = Dummy( 'bad', sys.maxint + 1, sys.maxint + 1 )
work.index_object( 0, bad )
def test_suite():
suite = unittest.TestSuite()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment