mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[1.6.x] Fixed #21996 -- Used proper encoding for GeoIP content
Thanks Florent Messa for the report.
Backport of fb1e3435a4 from master.
			
			
This commit is contained in:
		| @@ -22,6 +22,7 @@ class GeoIPRecord(Structure): | ||||
|                 ('continent_code', c_char_p), | ||||
|                 ] | ||||
| geoip_char_fields = [name for name, ctype in GeoIPRecord._fields_ if ctype is c_char_p] | ||||
| GEOIP_DEFAULT_ENCODING = 'iso-8859-1' | ||||
| geoip_encodings = { 0: 'iso-8859-1', | ||||
|                     1: 'utf8', | ||||
|                     } | ||||
| @@ -92,7 +93,7 @@ def check_string(result, func, cargs): | ||||
|         free(result) | ||||
|     else: | ||||
|         s = '' | ||||
|     return s.decode() | ||||
|     return s.decode(GEOIP_DEFAULT_ENCODING) | ||||
|  | ||||
| GeoIP_database_info = lgeoip.GeoIP_database_info | ||||
| GeoIP_database_info.restype = geoip_char_p | ||||
| @@ -102,7 +103,7 @@ GeoIP_database_info.errcheck = check_string | ||||
| def string_output(func): | ||||
|     def _err_check(result, func, cargs): | ||||
|         if result: | ||||
|             return result.decode() | ||||
|             return result.decode(GEOIP_DEFAULT_ENCODING) | ||||
|         return result | ||||
|     func.restype = c_char_p | ||||
|     func.errcheck = _err_check | ||||
|   | ||||
| @@ -118,3 +118,5 @@ class GeoIPTest(unittest.TestCase): | ||||
|         g = GeoIP() | ||||
|         d = g.city("www.osnabrueck.de") | ||||
|         self.assertEqual('Osnabrück', d['city']) | ||||
|         d = g.country('200.7.49.81') | ||||
|         self.assertEqual('Curaçao', d['country_name']) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user