@@ -501,10 +501,10 @@ static PyObject *GeoIP_range_by_ip_Py(PyObject * self, PyObject * args)
501
501
return retval ;
502
502
}
503
503
504
- #if PY_MAJOR_VERSION <= 2
505
504
static PyObject * GeoIP_charset_Py (PyObject * self , PyObject * UNUSED (args ))
506
505
{
507
506
GeoIP_GeoIPObject * GeoIP = (GeoIP_GeoIPObject * )self ;
507
+
508
508
return Py_BuildValue ("i" , GeoIP_charset (GeoIP -> gi ));
509
509
}
510
510
@@ -515,10 +515,15 @@ static PyObject *GeoIP_set_charset_Py(PyObject * self, PyObject * args)
515
515
if (!PyArg_ParseTuple (args , "i" , & charset )) {
516
516
return NULL ;
517
517
}
518
+ #if PY_MAJOR_VERSION >= 3
519
+ if (charset != GEOIP_CHARSET_UTF8 ) {
520
+ PyErr_SetString (PyExc_ValueError ,
521
+ "Only UTF-8 is supported for Python 3+." );
522
+ return NULL ;
523
+ }
524
+ #endif
518
525
return Py_BuildValue ("i" , GeoIP_set_charset (GeoIP -> gi , charset ));
519
-
520
526
}
521
- #endif
522
527
523
528
static PyObject * GeoIP_last_netmask_Py (PyObject * self , PyObject * UNUSED (args ))
524
529
{
@@ -609,12 +614,10 @@ static PyMethodDef GeoIP_GeoIP_methods[] = {
609
614
"Lookup City Region By Name" },
610
615
{ "range_by_ip" , GeoIP_range_by_ip_Py , METH_VARARGS ,
611
616
"Lookup start and end IP's for a given IP" },
612
- #if PY_MAJOR_VERSION <= 2
613
617
{ "charset" , GeoIP_charset_Py , METH_NOARGS ,
614
618
"Return the current charset ( either GEOIP_CHARSET_ISO_8859_1 or GEOIP_CHARSET_UTF8 )" },
615
619
{ "set_charset" , GeoIP_set_charset_Py , METH_VARARGS ,
616
620
"Set the charset for city records" },
617
- #endif
618
621
{ "last_netmask" , GeoIP_last_netmask_Py , METH_NOARGS ,
619
622
"Return the netmask depth of the last lookup" },
620
623
{ "country_code_by_name_v6" , GeoIP_country_code_by_name_v6_Py , METH_VARARGS ,
0 commit comments