Skip to content

Commit

Permalink
Merge pull request #121 from maxmind/greg/mcc-mnc
Browse files Browse the repository at this point in the history
Add MCC/MNC support
  • Loading branch information
horgh authored Nov 18, 2021
2 parents ee9dd7b + 7b15d13 commit ed175f6
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: "3.10"

- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
# We don't test on Windows currently as it appears mocket may not
# work there.
platform: [ubuntu-latest, macos-latest]
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [3.6, 3.7, 3.8, 3.9, "3.10"]

name: Python ${{ matrix.python-version }} on ${{ matrix.platform }}
runs-on: ${{ matrix.platform }}
Expand Down
12 changes: 12 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@

.. :changelog:
History
-------

4.5.0
++++++++++++++++++

* Support for mobile country code (MCC) and mobile network codes (MNC) was
added for the GeoIP2 ISP and Enterprise databases as well as the GeoIP2
City and Insights web services. ``mobile_country_code`` and
``mobile_network_code`` attributes were added to ``geoip2.model.ISP``
for the GeoIP2 ISP database and ``geoip2.record.Traits`` for the
Enterprise database and the GeoIP2 City and Insights web services.
We expect this data to be available by late January, 2022.

4.4.0 (2021-09-24)
++++++++++++++++++

Expand Down
42 changes: 31 additions & 11 deletions geoip2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ class AnonymousIP(SimpleModel):
The IP address used in the lookup.
:type: unicode
:type: str
.. attribute:: network
Expand Down Expand Up @@ -448,13 +448,13 @@ class ASN(SimpleModel):
The organization associated with the registered autonomous system number
for the IP address.
:type: unicode
:type: str
.. attribute:: ip_address
The IP address used in the lookup.
:type: unicode
:type: str
.. attribute:: network
Expand Down Expand Up @@ -495,13 +495,13 @@ class ConnectionType(SimpleModel):
Additional values may be added in the future.
:type: unicode
:type: str
.. attribute:: ip_address
The IP address used in the lookup.
:type: unicode
:type: str
.. attribute:: network
Expand All @@ -528,13 +528,13 @@ class Domain(SimpleModel):
The domain associated with the IP address.
:type: unicode
:type: str
.. attribute:: ip_address
The IP address used in the lookup.
:type: unicode
:type: str
.. attribute:: network
Expand Down Expand Up @@ -569,25 +569,41 @@ class ISP(ASN):
The organization associated with the registered autonomous system number
for the IP address.
:type: unicode
:type: str
.. attribute:: isp
The name of the ISP associated with the IP address.
:type: unicode
:type: str
.. attribute: mobile_country_code
The `mobile country code (MCC)
<https://en.wikipedia.org/wiki/Mobile_country_code>`_ associated with the
IP address and ISP.
:type: str
.. attribute: mobile_network_code
The `mobile network code (MNC)
<https://en.wikipedia.org/wiki/Mobile_country_code>`_ associated with the
IP address and ISP.
:type: str
.. attribute:: organization
The name of the organization associated with the IP address.
:type: unicode
:type: str
.. attribute:: ip_address
The IP address used in the lookup.
:type: unicode
:type: str
.. attribute:: network
Expand All @@ -599,10 +615,14 @@ class ISP(ASN):
"""

isp: Optional[str]
mobile_country_code: Optional[str]
mobile_network_code: Optional[str]
organization: Optional[str]

# pylint:disable=too-many-arguments
def __init__(self, raw: Dict[str, Union[str, int]]) -> None:
super().__init__(raw)
self.isp = cast(Optional[str], raw.get("isp"))
self.mobile_country_code = cast(Optional[str], raw.get("mobile_country_code"))
self.mobile_network_code = cast(Optional[str], raw.get("mobile_network_code"))
self.organization = cast(Optional[str], raw.get("organization"))
64 changes: 44 additions & 20 deletions geoip2/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class City(PlaceRecord):
The name of the city based on the locales list passed to the
constructor.
:type: unicode
:type: str
.. attribute:: names
Expand Down Expand Up @@ -117,7 +117,7 @@ class Continent(PlaceRecord):
A two character continent code like "NA" (North America)
or "OC" (Oceania).
:type: unicode
:type: str
.. attribute:: geoname_id
Expand All @@ -130,7 +130,7 @@ class Continent(PlaceRecord):
Returns the name of the continent based on the locales list passed to
the constructor.
:type: unicode
:type: str
.. attribute:: names
Expand Down Expand Up @@ -191,14 +191,14 @@ class Country(PlaceRecord):
<http://en.wikipedia.org/wiki/ISO_3166-1>`_ alpha code for the
country.
:type: unicode
:type: str
.. attribute:: name
The name of the country based on the locales list passed to the
constructor.
:type: unicode
:type: str
.. attribute:: names
Expand Down Expand Up @@ -266,14 +266,14 @@ class RepresentedCountry(Country):
The two-character `ISO 3166-1
<http://en.wikipedia.org/wiki/ISO_3166-1>`_ alpha code for the country.
:type: unicode
:type: str
.. attribute:: name
The name of the country based on the locales list passed to the
constructor.
:type: unicode
:type: str
.. attribute:: names
Expand All @@ -289,7 +289,7 @@ class RepresentedCountry(Country):
country. Currently we only return ``military`` but this could expand to
include other types in the future.
:type: unicode
:type: str
"""

Expand Down Expand Up @@ -376,7 +376,7 @@ class Location(Record):
Zone Database <http://www.iana.org/time-zones>`_, e.g.,
"America/New_York".
:type: unicode
:type: str
"""

Expand Down Expand Up @@ -443,7 +443,7 @@ class Postal(Record):
codes are not available for all countries. In some countries, this will
only contain part of the postal code.
:type: unicode
:type: str
.. attribute:: confidence
Expand Down Expand Up @@ -496,14 +496,14 @@ class Subdivision(PlaceRecord):
contain the subdivision portion of the `ISO 3166-2 code
<http://en.wikipedia.org/wiki/ISO_3166-2>`_.
:type: unicode
:type: str
.. attribute:: name
The name of the subdivision based on the locales list passed to the
constructor.
:type: unicode
:type: str
.. attribute:: names
Expand Down Expand Up @@ -598,7 +598,7 @@ class Traits(Record):
the IP address. This attribute is only available from the City and
Insights web service end points and the GeoIP2 Enterprise database.
:type: unicode
:type: str
.. attribute:: connection_type
Expand All @@ -613,7 +613,7 @@ class Traits(Record):
This attribute is only available in the GeoIP2 Enterprise database.
:type: unicode
:type: str
.. attribute:: domain
Expand All @@ -623,7 +623,7 @@ class Traits(Record):
from the City and Insights web service end points and the GeoIP2
Enterprise database.
:type: unicode
:type: str
.. attribute:: ip_address
Expand All @@ -633,7 +633,7 @@ class Traits(Record):
running on. If the system is behind a NAT, this may differ from the IP
address locally assigned to it.
:type: unicode
:type: str
.. attribute:: is_anonymous
Expand Down Expand Up @@ -713,7 +713,7 @@ class Traits(Record):
.. attribute:: is_tor_exit_node
This is true if the IP address is a Tor exit node. This attribute is
This is true if the IP address is a Tor exit node. This attribute is
only available from GeoIP2 Precision Insights.
:type: bool
Expand All @@ -724,7 +724,25 @@ class Traits(Record):
only available from the City and Insights web service end points and the
GeoIP2 Enterprise database.
:type: unicode
:type: str
.. attribute: mobile_country_code
The `mobile country code (MCC)
<https://en.wikipedia.org/wiki/Mobile_country_code>`_ associated with the
IP address and ISP. This attribute is available from the City and
Insights web services and the GeoIP2 Enterprise database.
:type: str
.. attribute: mobile_network_code
The `mobile network code (MNC)
<https://en.wikipedia.org/wiki/Mobile_country_code>`_ associated with the
IP address and ISP. This attribute is available from the City and
Insights web services and the GeoIP2 Enterprise database.
:type: str
.. attribute:: network
Expand All @@ -740,7 +758,7 @@ class Traits(Record):
attribute is only available from the City and Insights web service end
points and the GeoIP2 Enterprise database.
:type: unicode
:type: str
.. attribute:: static_ip_score
Expand Down Expand Up @@ -789,7 +807,7 @@ class Traits(Record):
This attribute is only available from the Insights end point and the
GeoIP2 Enterprise database.
:type: unicode
:type: str
"""

Expand All @@ -808,6 +826,8 @@ class Traits(Record):
is_tor_exit_node: bool
isp: Optional[str]
ip_address: Optional[str]
mobile_country_code: Optional[str]
mobile_network_code: Optional[str]
organization: Optional[str]
static_ip_score: Optional[float]
user_count: Optional[int]
Expand Down Expand Up @@ -838,6 +858,8 @@ def __init__(
static_ip_score: Optional[float] = None,
user_count: Optional[int] = None,
user_type: Optional[str] = None,
mobile_country_code: Optional[str] = None,
mobile_network_code: Optional[str] = None,
**_,
) -> None:
self.autonomous_system_number = autonomous_system_number
Expand All @@ -854,6 +876,8 @@ def __init__(
self.is_satellite_provider = is_satellite_provider
self.is_tor_exit_node = is_tor_exit_node
self.isp = isp
self.mobile_country_code = mobile_country_code
self.mobile_network_code = mobile_network_code
self.organization = organization
self.static_ip_score = static_ip_score
self.user_type = user_type
Expand Down
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ universal = 1
disable = duplicate-code

[tox:tox]
envlist = py36, py37, py38, py39, mypy
envlist = py36, py37, py38, py39, py310, mypy

[gh-actions]
python =
3.6: py36
3.7: py37
3.8: py38
3.9: py39, mypy
3.9: py39
"3.10": py310, mypy

[testenv]
deps =
Expand Down
Loading

0 comments on commit ed175f6

Please sign in to comment.