Skip to content
This repository was archived by the owner on Jun 1, 2022. It is now read-only.

Commit 71656ec

Browse files
committed
Reenabled set_charset/charset on Python 3
1 parent d2d5298 commit 71656ec

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

py_GeoIP.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,10 @@ static PyObject *GeoIP_range_by_ip_Py(PyObject * self, PyObject * args)
501501
return retval;
502502
}
503503

504-
#if PY_MAJOR_VERSION <= 2
505504
static PyObject *GeoIP_charset_Py(PyObject *self, PyObject *UNUSED(args))
506505
{
507506
GeoIP_GeoIPObject *GeoIP = (GeoIP_GeoIPObject *)self;
507+
508508
return Py_BuildValue("i", GeoIP_charset(GeoIP->gi));
509509
}
510510

@@ -515,10 +515,15 @@ static PyObject *GeoIP_set_charset_Py(PyObject * self, PyObject * args)
515515
if (!PyArg_ParseTuple(args, "i", &charset)) {
516516
return NULL;
517517
}
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
518525
return Py_BuildValue("i", GeoIP_set_charset(GeoIP->gi, charset));
519-
520526
}
521-
#endif
522527

523528
static PyObject *GeoIP_last_netmask_Py(PyObject * self, PyObject *UNUSED(args))
524529
{
@@ -609,12 +614,10 @@ static PyMethodDef GeoIP_GeoIP_methods[] = {
609614
"Lookup City Region By Name" },
610615
{ "range_by_ip", GeoIP_range_by_ip_Py, METH_VARARGS,
611616
"Lookup start and end IP's for a given IP" },
612-
#if PY_MAJOR_VERSION <= 2
613617
{ "charset", GeoIP_charset_Py, METH_NOARGS,
614618
"Return the current charset ( either GEOIP_CHARSET_ISO_8859_1 or GEOIP_CHARSET_UTF8 )" },
615619
{ "set_charset", GeoIP_set_charset_Py, METH_VARARGS,
616620
"Set the charset for city records" },
617-
#endif
618621
{ "last_netmask", GeoIP_last_netmask_Py, METH_NOARGS,
619622
"Return the netmask depth of the last lookup" },
620623
{ "country_code_by_name_v6", GeoIP_country_code_by_name_v6_Py, METH_VARARGS,

tests/test_errors.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
31
import GeoIP
42
from nose.tools import assert_equal
53

@@ -37,11 +35,6 @@ def test_errors():
3735

3836
assert_equal(gi.range_by_ip('1.1.1.1'), ('0.0.0.0', '12.87.117.255'))
3937

40-
if sys.version_info[0] == 2:
41-
assert_equal(gi.charset(), 0)
42-
43-
assert_equal(gi.set_charset(-1), 0)
44-
4538
assert_equal(gi.last_netmask(), 5)
4639

4740
assert_equal(gi.country_code_by_name_v6('1.1.1.1'), None)

0 commit comments

Comments
 (0)