Skip to content

Commit 58d449d

Browse files
committed
Merge pull request #32 from maxmind/greg/enterprise
Add support for GeoIP2 Enterprise
2 parents b35ed37 + 11952cb commit 58d449d

File tree

11 files changed

+211
-52
lines changed

11 files changed

+211
-52
lines changed

HISTORY.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ History
66
2.3.0 (201X-XX-XX)
77
++++++++++++++++++
88

9+
* Added support for the GeoIP2 Enterprise database.
910
* ``geoip2.database.Reader`` now supports being used in a ``with`` statement
1011
(PEP 343). (PR from Nguyễn Hồng Quân. GitHub #29)
1112

@@ -21,7 +22,6 @@ History
2122
<https://www.maxmind.com/en/geoip2-anonymous-ip-database>`_
2223
to determine whether an IP address is used by an anonymizing service.
2324

24-
2525
2.1.0 (2014-12-09)
2626
++++++++++++++++++
2727

@@ -80,7 +80,6 @@ History
8080
from this API.
8181
* Support was added for the GeoIP2 Connection Type, Domain, and ISP databases.
8282

83-
8483
0.5.1 (2014-03-28)
8584
++++++++++++++++++
8685

README.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,51 @@ Domain Database
217217
'128.101.101.101'
218218
>>> reader.close()
219219
220+
Enterprise Database
221+
^^^^^^^^^^^^^^^^^^^
222+
223+
.. code-block:: pycon
224+
225+
>>> import geoip2.database
226+
>>>
227+
>>> # This creates a Reader object. You should use the same object
228+
>>> # across multiple requests as creation of it is expensive.
229+
>>> with geoip2.database.Reader('/path/to/GeoIP2-Enterprise.mmdb') as reader:
230+
>>>
231+
>>> # Use the .enterprise method to do a lookup in the Enterprise database
232+
>>> response = reader.enterprise('128.101.101.101')
233+
>>>
234+
>>> response.country.confidence
235+
99
236+
>>> response.country.iso_code
237+
'US'
238+
>>> response.country.name
239+
'United States'
240+
>>> response.country.names['zh-CN']
241+
u'美国'
242+
>>>
243+
>>> response.subdivisions.most_specific.name
244+
'Minnesota'
245+
>>> response.subdivisions.most_specific.iso_code
246+
'MN'
247+
>>> response.subdivisions.most_specific.confidence
248+
77
249+
>>>
250+
>>> response.city.name
251+
'Minneapolis'
252+
>>> response.country.confidence
253+
11
254+
>>>
255+
>>> response.postal.code
256+
'55455'
257+
>>>
258+
>>> response.location.accuracy_radius
259+
50
260+
>>> response.location.latitude
261+
44.9733
262+
>>> response.location.longitude
263+
-93.2323
264+
220265
ISP Database
221266
^^^^^^^^^^^^
222267

docs/conf.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@
1212
# All configuration values have a default; values that are commented out
1313
# serve to show the default.
1414

15-
import sys, os
15+
import sys
16+
import os
1617

1718
# If extensions (or modules to document with autodoc) are in another directory,
1819
# add these directories to sys.path here. If the directory is relative to the
1920
# documentation root, use os.path.abspath to make it absolute, like shown here.
2021
sys.path.insert(0, os.path.abspath('..'))
2122
import geoip2
2223

23-
# -- General configuration -----------------------------------------------------
24+
# -- General configuration -----------------------------------------------
2425

2526
# If your documentation needs a minimal Sphinx version, state it here.
2627
#needs_sphinx = '1.0'
2728

2829
# Add any Sphinx extension module names here, as strings. They can be extensions
2930
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
30-
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.coverage']
31+
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest',
32+
'sphinx.ext.intersphinx', 'sphinx.ext.coverage']
3133

3234
# Add any paths that contain templates here, relative to this directory.
3335
templates_path = ['_templates']
@@ -43,7 +45,7 @@
4345

4446
# General information about the project.
4547
project = 'geoip2'
46-
copyright = '2014, MaxMind, Inc.'
48+
copyright = '2013-2016, MaxMind, Inc.'
4749

4850
# The version info for the project you're documenting, acts as replacement for
4951
# |version| and |release|, also used in various other places throughout the
@@ -89,7 +91,7 @@
8991
#modindex_common_prefix = []
9092

9193

92-
# -- Options for HTML output ---------------------------------------------------
94+
# -- Options for HTML output ---------------------------------------------
9395

9496
# The theme to use for HTML and HTML Help pages. See the documentation for
9597
# a list of builtin themes.
@@ -169,24 +171,24 @@
169171
htmlhelp_basename = 'geoip2doc'
170172

171173

172-
# -- Options for LaTeX output --------------------------------------------------
174+
# -- Options for LaTeX output --------------------------------------------
173175

174176
latex_elements = {
175-
# The paper size ('letterpaper' or 'a4paper').
176-
#'papersize': 'letterpaper',
177+
# The paper size ('letterpaper' or 'a4paper').
178+
#'papersize': 'letterpaper',
177179

178-
# The font size ('10pt', '11pt' or '12pt').
179-
#'pointsize': '10pt',
180+
# The font size ('10pt', '11pt' or '12pt').
181+
#'pointsize': '10pt',
180182

181-
# Additional stuff for the LaTeX preamble.
182-
#'preamble': '',
183+
# Additional stuff for the LaTeX preamble.
184+
#'preamble': '',
183185
}
184186

185187
# Grouping the document tree into LaTeX files. List of tuples
186188
# (source start file, target name, title, author, documentclass [howto/manual]).
187189
latex_documents = [
188-
('index', 'geoip2.tex', 'geoip2 Documentation',
189-
'Gregory Oschwald', 'manual'),
190+
('index', 'geoip2.tex', 'geoip2 Documentation',
191+
'Gregory Oschwald', 'manual'),
190192
]
191193

192194
# The name of an image file (relative to this directory) to place at the top of
@@ -210,7 +212,7 @@
210212
#latex_domain_indices = True
211213

212214

213-
# -- Options for manual page output --------------------------------------------
215+
# -- Options for manual page output --------------------------------------
214216

215217
# One entry per manual page. List of tuples
216218
# (source start file, name, description, authors, manual section).
@@ -223,15 +225,15 @@
223225
#man_show_urls = False
224226

225227

226-
# -- Options for Texinfo output ------------------------------------------------
228+
# -- Options for Texinfo output ------------------------------------------
227229

228230
# Grouping the document tree into Texinfo files. List of tuples
229231
# (source start file, target name, title, author,
230232
# dir menu entry, description, category)
231233
texinfo_documents = [
232-
('index', 'geoip2', 'geoip2 Documentation',
233-
'Gregory Oschwald', 'geoip2', 'One line description of project.',
234-
'Miscellaneous'),
234+
('index', 'geoip2', 'geoip2 Documentation',
235+
'Gregory Oschwald', 'geoip2', 'One line description of project.',
236+
'Miscellaneous'),
235237
]
236238

237239
# Documents to append as an appendix to all manuals.

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ Indices and tables
3838
* :ref:`modindex`
3939
* :ref:`search`
4040

41-
:copyright: (c) 2014 by MaxMind, Inc.
41+
:copyright: (c) 2013-2016 by MaxMind, Inc.
4242
:license: Apache License, Version 2.0
4343

geoip2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
__version__ = '2.2.0'
55
__author__ = 'Gregory Oschwald'
66
__license__ = 'Apache License, Version 2.0'
7-
__copyright__ = 'Copyright 2014 Maxmind, Inc.'
7+
__copyright__ = 'Copyright (c) 2013-2016 Maxmind, Inc.'

geoip2/database.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ def domain(self, ip_address):
142142
return self._flat_model_for(geoip2.models.Domain, 'GeoIP2-Domain',
143143
ip_address)
144144

145+
def enterprise(self, ip_address):
146+
"""Get the Enterprise object for the IP address
147+
148+
:param ip_address: IPv4 or IPv6 address as a string.
149+
150+
:returns: :py:class:`geoip2.models.Enterprise` object
151+
152+
"""
153+
return self._model_for(geoip2.models.Enterprise, 'Enterprise',
154+
ip_address)
155+
145156
def isp(self, ip_address):
146157
"""Get the ISP object for the IP address
147158

geoip2/models.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,70 @@ class Insights(City):
237237
"""
238238

239239

240+
class Enterprise(City):
241+
"""Model for the GeoIP2 Enterprise database
242+
243+
.. attribute:: city
244+
245+
City object for the requested IP address.
246+
247+
:type: :py:class:`geoip2.records.City`
248+
249+
.. attribute:: continent
250+
251+
Continent object for the requested IP address.
252+
253+
:type: :py:class:`geoip2.records.Continent`
254+
255+
.. attribute:: country
256+
257+
Country object for the requested IP address. This record represents the
258+
country where MaxMind believes the IP is located.
259+
260+
:type: :py:class:`geoip2.records.Country`
261+
262+
.. attribute:: location
263+
264+
Location object for the requested IP address.
265+
266+
.. attribute:: maxmind
267+
268+
Information related to your MaxMind account.
269+
270+
:type: :py:class:`geoip2.records.MaxMind`
271+
272+
.. attribute:: registered_country
273+
274+
The registered country object for the requested IP address. This record
275+
represents the country where the ISP has registered a given IP block in
276+
and may differ from the user's country.
277+
278+
:type: :py:class:`geoip2.records.Country`
279+
280+
.. attribute:: represented_country
281+
282+
Object for the country represented by the users of the IP address
283+
when that country is different than the country in ``country``. For
284+
instance, the country represented by an overseas military base.
285+
286+
:type: :py:class:`geoip2.records.RepresentedCountry`
287+
288+
.. attribute:: subdivisions
289+
290+
Object (tuple) representing the subdivisions of the country to which
291+
the location of the requested IP address belongs.
292+
293+
:type: :py:class:`geoip2.records.Subdivisions`
294+
295+
.. attribute:: traits
296+
297+
Object with the traits of the requested IP address.
298+
299+
:type: :py:class:`geoip2.records.Traits`
300+
301+
"""
302+
303+
240304
class SimpleModel(SimpleEquality):
241305
"""Provides basic methods for non-location models"""
242306

0 commit comments

Comments
 (0)