mirror of
https://github.com/django/django.git
synced 2025-08-21 01:09:13 +00:00
Made GeoIP2.__del__() close all databases.
This commit is contained in:
parent
79099a7ba4
commit
0f83133a35
@ -132,8 +132,10 @@ class GeoIP2:
|
|||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
# Cleanup any GeoIP file handles lying around.
|
# Cleanup any GeoIP file handles lying around.
|
||||||
if self._reader:
|
if self._city:
|
||||||
self._reader.close()
|
self._city.close()
|
||||||
|
if self._country:
|
||||||
|
self._country.close()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
meta = self._reader.metadata()
|
meta = self._reader.metadata()
|
||||||
|
@ -152,6 +152,16 @@ class GeoIPTest(SimpleTestCase):
|
|||||||
self.assertEqual("Lawrence", d["city"])
|
self.assertEqual("Lawrence", d["city"])
|
||||||
self.assertEqual("KS", d["region"])
|
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):
|
def test_repr(self):
|
||||||
path = settings.GEOIP_PATH
|
path = settings.GEOIP_PATH
|
||||||
g = GeoIP2(path=path)
|
g = GeoIP2(path=path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user