Commit af04f7ff by Like Ma

Add region name to GeoIP record by country code and region code.

parent 90170a4c
......@@ -39,6 +39,7 @@ from StringIO import StringIO
from . import const
from .util import ip2long
from .timezone import time_zone_by_country_and_region
from .regionname import region_name_by_country_and_region_code
import six
......@@ -340,7 +341,8 @@ class GeoIP(GeoIPBase):
char = ord(record_buf[record_buf_pos+str_length])
if str_length > 0:
record['region_name'] = record_buf[record_buf_pos:record_buf_pos+str_length]
record['region'] = record_buf[record_buf_pos:record_buf_pos+str_length]
record['region_name'] = region_name_by_country_and_region_code(record['country_code'], record['region']) if 'country_code' in record else ''
record_buf_pos += str_length + 1
str_length = 0
......@@ -410,7 +412,7 @@ class GeoIP(GeoIPBase):
if 'country_code' in record:
record['time_zone'] = time_zone_by_country_and_region(
record['country_code'], record.get('region_name')) or ''
record['country_code'], record.get('region')) or ''
else:
record['time_zone'] = ''
......@@ -536,7 +538,7 @@ class GeoIP(GeoIPBase):
@type addr: str
@return: dict with country_code, country_code3, country_name,
region, city, postal_code, latitude, longitude,
dma_code, metro_code, area_code, region_name, time_zone
dma_code, metro_code, area_code, region, region_name, time_zone
@rtype: dict
"""
try:
......@@ -561,7 +563,7 @@ class GeoIP(GeoIPBase):
@type hostname: str
@return: dict with country_code, country_code3, country_name,
region, city, postal_code, latitude, longitude,
dma_code, metro_code, area_code, region_name, time_zone
dma_code, metro_code, area_code, region, region_name, time_zone
@rtype: dict
"""
addr = socket.gethostbyname(hostname)
......@@ -576,7 +578,7 @@ class GeoIP(GeoIPBase):
@param addr: IP address
@type addr: str
@return: dict containing country_code, region,
and region_name
region and region_name
@rtype: dict
"""
try:
......@@ -602,7 +604,7 @@ class GeoIP(GeoIPBase):
@param hostname: host name
@type hostname: str
@return: dict containing country_code, region,
and region_name
region and region_name
@rtype: dict
"""
addr = socket.gethostbyname(hostname)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment