change tz_aware=False to be the default, so we're backwards compatible

This commit is contained in:
Mike Dirolf 2010-07-21 10:49:35 -04:00
parent a8bb1038e6
commit 363695345d
6 changed files with 14 additions and 16 deletions

View File

@ -53,7 +53,7 @@ except ImportError:
RE_TYPE = type(re.compile(""))
def _get_int(data, as_class=None, tz_aware=True, unsigned=False):
def _get_int(data, as_class=None, tz_aware=False, unsigned=False):
format = unsigned and "I" or "i"
try:
value = struct.unpack("<%s" % format, data[:4])[0]
@ -440,7 +440,7 @@ class BSON(str):
"""
return cls(_dict_to_bson(dct, check_keys))
def to_dict(self, as_class=dict, tz_aware=True):
def to_dict(self, as_class=dict, tz_aware=False):
"""Convert this BSON data to a mapping type.
The default type to use is :class:`dict`. This can be replaced

View File

@ -103,7 +103,7 @@ class Connection(object): # TODO support auth for pooling
def __init__(self, host=None, port=None, pool_size=None,
auto_start_request=None, timeout=None, slave_okay=False,
network_timeout=None, document_class=dict, tz_aware=True,
network_timeout=None, document_class=dict, tz_aware=False,
_connect=True):
"""Create a new connection to a single MongoDB instance at *host:port*.
@ -143,7 +143,7 @@ class Connection(object): # TODO support auth for pooling
for socket operations - default is no timeout
- `document_class` (optional): default class to use for
documents returned from queries on this connection
- `tz_aware` (optional): if ``True`` (default),
- `tz_aware` (optional): if ``True``,
:class:`~datetime.datetime` instances returned as values
in a document by this :class:`Connection` will be timezone
aware (otherwise they will be naive)

View File

@ -71,7 +71,7 @@ def _index_document(index_list):
return index
def _unpack_response(response, cursor_id=None, as_class=dict, tz_aware=True):
def _unpack_response(response, cursor_id=None, as_class=dict, tz_aware=False):
"""Unpack a response from the database.
Check the response for errors and unpack, returning a dictionary

View File

@ -23,7 +23,6 @@ from pymongo.binary import Binary
from pymongo.objectid import ObjectId
from pymongo.dbref import DBRef
from pymongo.son import SON
from pymongo.tz_util import utc
gen_target = 100
reduction_attempts = 10
@ -100,8 +99,7 @@ def gen_datetime():
random.randint(0, 23),
random.randint(0, 59),
random.randint(0, 59),
random.randint(0, 999) * 1000,
utc)
random.randint(0, 999) * 1000)
def gen_dict(gen_key, gen_value, gen_length):

View File

@ -166,7 +166,7 @@ class TestBSON(unittest.TestCase):
helper({"a binary": Binary("test", 128)})
helper({"a binary": Binary("test", 254)})
helper({"another binary": Binary("test")})
helper(SON([(u'test dst', datetime.datetime(1993, 4, 4, 2, tzinfo=utc))]))
helper(SON([(u'test dst', datetime.datetime(1993, 4, 4, 2))]))
helper({"big float": float(10000000000)})
helper({"ref": DBRef("coll", 5)})
helper({"ref": DBRef("coll", 5, foo="bar", bar=4)})
@ -186,7 +186,7 @@ class TestBSON(unittest.TestCase):
aware = datetime.datetime(1993, 4, 4, 2, tzinfo=FixedOffset(555, "SomeZone"))
as_utc = (aware - aware.utcoffset()).replace(tzinfo=utc)
self.assertEqual(datetime.datetime(1993, 4, 3, 16, 45, tzinfo=utc), as_utc)
after = BSON.from_dict({"date": aware}).to_dict()["date"]
after = BSON.from_dict({"date": aware}).to_dict(tz_aware=True)["date"]
self.assertEqual(utc, after.tzinfo)
self.assertEqual(as_utc, after)
@ -194,13 +194,13 @@ class TestBSON(unittest.TestCase):
aware = datetime.datetime(1993, 4, 4, 2, tzinfo=FixedOffset(555, "SomeZone"))
naive_utc = (aware - aware.utcoffset()).replace(tzinfo=None)
self.assertEqual(datetime.datetime(1993, 4, 3, 16, 45), naive_utc)
after = BSON.from_dict({"date": aware}).to_dict(tz_aware=False)["date"]
after = BSON.from_dict({"date": aware}).to_dict()["date"]
self.assertEqual(None, after.tzinfo)
self.assertEqual(naive_utc, after)
def test_dst(self):
d = {"x": datetime.datetime(1993, 4, 4, 2)}
self.assertEqual(d, BSON.from_dict(d).to_dict(tz_aware=False))
self.assertEqual(d, BSON.from_dict(d).to_dict())
def test_bad_encode(self):
self.assertRaises(InvalidStringData, BSON.from_dict,
@ -280,8 +280,8 @@ class TestBSON(unittest.TestCase):
("_id", "b")])))
def test_dates(self):
doc = {"early": datetime.datetime(1686, 5, 5, tzinfo=utc),
"late": datetime.datetime(2086, 5, 5, tzinfo=utc)}
doc = {"early": datetime.datetime(1686, 5, 5),
"late": datetime.datetime(2086, 5, 5)}
try:
self.assertEqual(doc, BSON.from_dict(doc).to_dict())
except ValueError:

View File

@ -421,8 +421,8 @@ class TestConnection(unittest.TestCase):
no_timeout.pymongo_test, 0.1)
def test_tz_aware(self):
aware = Connection(self.host, self.port)
naive = Connection(self.host, self.port, tz_aware=False)
aware = Connection(self.host, self.port, tz_aware=True)
naive = Connection(self.host, self.port)
aware.pymongo_test.drop_collection("test")
now = datetime.datetime.utcnow()