From 363695345d11c69b47c8d05f6a1826bc41ff6045 Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Wed, 21 Jul 2010 10:49:35 -0400 Subject: [PATCH] change tz_aware=False to be the default, so we're backwards compatible --- pymongo/bson.py | 4 ++-- pymongo/connection.py | 4 ++-- pymongo/helpers.py | 2 +- test/qcheck.py | 4 +--- test/test_bson.py | 12 ++++++------ test/test_connection.py | 4 ++-- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/pymongo/bson.py b/pymongo/bson.py index 2138b88a4..6ff86a375 100644 --- a/pymongo/bson.py +++ b/pymongo/bson.py @@ -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 diff --git a/pymongo/connection.py b/pymongo/connection.py index 99ab9f64b..c256dcb77 100644 --- a/pymongo/connection.py +++ b/pymongo/connection.py @@ -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) diff --git a/pymongo/helpers.py b/pymongo/helpers.py index 6e906c3d5..07669fe7e 100644 --- a/pymongo/helpers.py +++ b/pymongo/helpers.py @@ -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 diff --git a/test/qcheck.py b/test/qcheck.py index ec9302f26..6d45940e3 100644 --- a/test/qcheck.py +++ b/test/qcheck.py @@ -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): diff --git a/test/test_bson.py b/test/test_bson.py index 3e8acc0a8..1a6d9f27f 100644 --- a/test/test_bson.py +++ b/test/test_bson.py @@ -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: diff --git a/test/test_connection.py b/test/test_connection.py index 4a26a10b9..c33e7465c 100644 --- a/test/test_connection.py +++ b/test/test_connection.py @@ -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()