@@ -149,7 +149,7 @@ static PyObject * GeoIP_org_by_name_Py(PyObject *self, PyObject *args) {
149
149
return Py_BuildValue ("s" , retval );
150
150
}
151
151
152
- void GeoIP_SetItemString (PyObject * dict , const char * name , char * value ) {
152
+ void GeoIP_SetItemString (PyObject * dict , const char * name , const char * value ) {
153
153
PyObject * nameObj ;
154
154
PyObject * valueObj ;
155
155
nameObj = Py_BuildValue ("s" ,name );
@@ -201,6 +201,10 @@ static PyObject * GeoIP_populate_dict(GeoIPRecord *gir) {
201
201
GeoIP_SetItemFloat (retval ,"longitude" ,gir -> longitude );
202
202
GeoIP_SetItemInt (retval ,"dma_code" ,gir -> dma_code );
203
203
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 ));
204
208
GeoIPRecord_delete (gir );
205
209
return retval ;
206
210
}
@@ -274,9 +278,15 @@ static PyMethodDef GeoIP_Object_methods[] = {
274
278
static PyObject *
275
279
GeoIP_GetAttr (PyObject * self , char * attrname )
276
280
{
281
+ GeoIP_GeoIPObject * GeoIP = (GeoIP_GeoIPObject * )self ;
277
282
if (strcmp (attrname , "GEOIP_STANDARD" ) == 0 ) {
278
283
return Py_BuildValue ("i" , 0 );
279
- }
284
+ } else if (strcmp (attrname , "database_info" ) == 0 ) {
285
+ return Py_BuildValue ("z" , GeoIP_database_info (GeoIP -> gi ));
286
+ } else if (strcmp (attrname , "database_edition" ) == 0 ) {
287
+ return Py_BuildValue ("z" , GeoIPDBDescription [
288
+ GeoIP_database_edition (GeoIP -> gi )]);
289
+ }
280
290
return Py_FindMethod (GeoIP_Object_methods , self , attrname );
281
291
}
282
292
@@ -307,7 +317,10 @@ static PyMethodDef GeoIP_Class_methods[] = {
307
317
DL_EXPORT (void )
308
318
initGeoIP (void )
309
319
{
310
- PyObject * m , * d , * tmp ;
320
+ PyObject * m , * d , * tmp , * ccode , * cname , * ccont , * name ;
321
+ int i ;
322
+ const int total_ccodes = sizeof (GeoIP_country_code ) /
323
+ sizeof (GeoIP_country_code [0 ]);
311
324
GeoIP_GeoIPType .ob_type = & PyType_Type ;
312
325
313
326
m = Py_InitModule ("GeoIP" , GeoIP_Class_methods );
@@ -316,33 +329,44 @@ initGeoIP(void)
316
329
PyGeoIPError = PyErr_NewException ("py_geoip.error" , NULL , NULL );
317
330
PyDict_SetItemString (d , "error" , PyGeoIPError );
318
331
319
- int total_ccodes = 253 ;
320
-
321
- PyObject * ccode = PyTuple_New (total_ccodes );
322
- PyObject * cname = PyDict_New ();
323
- PyObject * ccont = PyDict_New ();
324
- PyObject * s ;
332
+ ccode = PyTuple_New (total_ccodes );
333
+ cname = PyDict_New ();
334
+ ccont = PyDict_New ();
325
335
326
- int i = 0 ;
327
- for (; i < total_ccodes ; i ++ )
336
+ for (i = 0 ; i < total_ccodes ; i ++ )
328
337
{
329
- s = PyString_FromString (GeoIP_country_code [i ]);
330
- PyTuple_SET_ITEM (ccode , i , s );
331
- Py_INCREF (s );
332
- PyDict_SetItem (cname , s , PyString_FromString (GeoIP_country_name [i ]));
333
- Py_INCREF (s );
334
- PyDict_SetItem (ccont , s , PyString_FromString (GeoIP_country_continent [i ]));
335
- };
338
+ name = PyString_FromString (GeoIP_country_code [i ]);
339
+ PyTuple_SET_ITEM (ccode , i , name );
340
+
341
+ tmp = PyString_FromString (GeoIP_country_name [i ]);
342
+ PyDict_SetItem (cname , name , tmp );
343
+ Py_DECREF (tmp );
344
+
345
+ tmp = PyString_FromString (GeoIP_country_continent [i ]);
346
+ PyDict_SetItem (ccont , name , tmp );
347
+ Py_DECREF (tmp );
348
+ }
336
349
337
350
PyDict_SetItemString (d , "country_codes" , ccode );
351
+ Py_DECREF (ccode );
338
352
PyDict_SetItemString (d , "country_names" , cname );
353
+ Py_DECREF (cname );
339
354
PyDict_SetItemString (d , "country_continents" , ccont );
355
+ Py_DECREF (ccont );
340
356
341
- tmp = PyInt_FromLong (0 );
357
+ tmp = PyInt_FromLong (GEOIP_STANDARD );
342
358
PyDict_SetItemString (d , "GEOIP_STANDARD" , tmp );
343
359
Py_DECREF (tmp );
344
360
345
- tmp = PyInt_FromLong (1 );
361
+ tmp = PyInt_FromLong (GEOIP_MEMORY_CACHE );
346
362
PyDict_SetItemString (d , "GEOIP_MEMORY_CACHE" , tmp );
347
363
Py_DECREF (tmp );
364
+
365
+ tmp = PyInt_FromLong (GEOIP_CHECK_CACHE );
366
+ PyDict_SetItemString (d , "GEOIP_CHECK_CACHE" , tmp );
367
+ Py_DECREF (tmp );
368
+
369
+ tmp = PyInt_FromLong (GEOIP_INDEX_CACHE );
370
+ PyDict_SetItemString (d , "GEOIP_INDEX_CACHE" , tmp );
371
+ Py_DECREF (tmp );
348
372
}
0 commit comments