mirror of https://github.com/django/django.git
Made GeoIP2.__del__() close all databases.
This commit is contained in:
parent
79099a7ba4
commit
0f83133a35
|
@ -132,8 +132,10 @@ class GeoIP2:
|
|||
|
||||
def __del__(self):
|
||||
# Cleanup any GeoIP file handles lying around.
|
||||
if self._reader:
|
||||
self._reader.close()
|
||||
if self._city:
|
||||
self._city.close()
|
||||
if self._country:
|
||||
self._country.close()
|
||||
|
||||
def __repr__(self):
|
||||
meta = self._reader.metadata()
|
||||
|
|
|
@ -152,6 +152,16 @@ class GeoIPTest(SimpleTestCase):
|
|||
self.assertEqual("Lawrence", d["city"])
|
||||
self.assertEqual("KS", d["region"])
|
||||
|
||||
def test_del(self):
|
||||
g = GeoIP2()
|
||||
city = g._city
|
||||
country = g._country
|
||||
self.assertIs(city._db_reader.closed, False)
|
||||
self.assertIs(country._db_reader.closed, False)
|
||||
del g
|
||||
self.assertIs(city._db_reader.closed, True)
|
||||
self.assertIs(country._db_reader.closed, True)
|
||||
|
||||
def test_repr(self):
|
||||
path = settings.GEOIP_PATH
|
||||
g = GeoIP2(path=path)
|
||||
|
|
Loading…
Reference in New Issue