mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-24 22:58:50 +01:00
Merge remote-tracking branch 'karsten/geoip2regcountry'
This commit is contained in:
commit
613b0a3bc5
1 changed files with 13 additions and 0 deletions
|
@ -339,11 +339,24 @@ def parse_mm_file(s):
|
||||||
def format_datum(datum):
|
def format_datum(datum):
|
||||||
"""Given a Datum at a leaf of the tree, return the string that we should
|
"""Given a Datum at a leaf of the tree, return the string that we should
|
||||||
write as its value.
|
write as its value.
|
||||||
|
|
||||||
|
We first try country->iso_code which is the two-character ISO 3166-1
|
||||||
|
country code of the country where MaxMind believes the end user is
|
||||||
|
located. If there's no such key, we try registered_country->iso_code
|
||||||
|
which is the country in which the ISP has registered the IP address.
|
||||||
|
Without falling back to registered_country, we'd leave out all ranges
|
||||||
|
that MaxMind thinks belong to anonymous proxies, because those ranges
|
||||||
|
don't contain country but only registered_country. In short: let's
|
||||||
|
fill all A1 entries with what ARIN et. al think.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return bytesToStr(datum.map['country'].map['iso_code'].data)
|
return bytesToStr(datum.map['country'].map['iso_code'].data)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
return bytesToStr(datum.map['registered_country'].map['iso_code'].data)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
||||||
IPV4_PREFIX = "0"*96
|
IPV4_PREFIX = "0"*96
|
||||||
|
|
Loading…
Add table
Reference in a new issue