Skip to content

Commit f1e3d7e

Browse files
author
borisz
committed
Update test_city.py and test_region.py ( Boris Zenter )
Add region_name to GeoIPRegion ( Boris Zentner )
1 parent 5cf0ad7 commit f1e3d7e

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Update test_city.py and test_region.py ( Boris Zentner )
2+
* Add region_name to GeoIPRegion ( Boris Zentner )
13
* Add database_info and database_edition attributes to GeoIP object
24
(James Henstridge)
35
* Add region_name and time_zone keys to GeoIPRecord wrapper (James

py_GeoIP.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,14 @@ void GeoIP_SetItemInt(PyObject *dict, const char * name, int value) {
181181

182182
static PyObject * GeoIP_region_populate_dict(GeoIPRegion * gir) {
183183
PyObject * retval;
184+
const char * region_name = NULL;
184185
retval = PyDict_New();
185186
GeoIP_SetItemString(retval,"country_code",gir->country_code);
186187
GeoIP_SetItemString(retval,"region",gir->region);
188+
if ( gir->country_code[0] ) {
189+
region_name = GeoIP_region_name_by_code(gir->country_code, gir->region);
190+
}
191+
GeoIP_SetItemString(retval,"region_name",region_name);
187192
GeoIPRegion_delete(gir);
188193
return retval;
189194
}
@@ -201,10 +206,10 @@ static PyObject * GeoIP_populate_dict(GeoIPRecord *gir) {
201206
GeoIP_SetItemFloat(retval,"longitude",gir->longitude);
202207
GeoIP_SetItemInt(retval,"dma_code",gir->dma_code);
203208
GeoIP_SetItemInt(retval,"area_code",gir->area_code);
204-
GeoIP_SetItemString(retval, "region_name",
205-
GeoIP_region_name_by_code(gir->country_code, gir->region));
206-
GeoIP_SetItemString(retval, "time_zone",
207-
GeoIP_time_zone_by_country_and_region(gir->country_code, gir->region));
209+
GeoIP_SetItemString(retval, "region_name",
210+
GeoIP_region_name_by_code(gir->country_code, gir->region));
211+
GeoIP_SetItemString(retval, "time_zone",
212+
GeoIP_time_zone_by_country_and_region(gir->country_code, gir->region));
208213
GeoIPRecord_delete(gir);
209214
return retval;
210215
}

test_city.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
print gir['country_code']
1212
print gir['country_code3']
1313
print gir['country_name']
14-
print gir['region']
1514
print gir['city']
15+
print gir['region']
16+
print gir['region_name']
1617
print gir['postal_code']
1718
print gir['latitude']
1819
print gir['longitude']
1920
print gir['dma_code']
2021
print gir['area_code']
22+
print gir['time_zone']

test_region.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
gir = gi.region_by_name("www.google.com")
88
if gir != None:
99
print gir['country_code']
10-
print gir['region']
1110

11+
print gir['region']
12+
print gir['region_name']
1213
gir = gi.region_by_addr("24.24.24.24")
1314
if gir != None:
1415
print gir['country_code']
1516
print gir['region']
17+
print gir['region_name']
18+

0 commit comments

Comments
 (0)