99import maxminddb
1010# pylint: disable=unused-import
1111from maxminddb import (MODE_AUTO , MODE_MMAP , MODE_MMAP_EXT , MODE_FILE ,
12- MODE_MEMORY )
12+ MODE_MEMORY , MODE_FD )
1313
1414import geoip2
1515import geoip2 .models
@@ -23,9 +23,9 @@ class Reader(object):
2323 IP addresses can be looked up using the ``country`` and ``city`` methods.
2424
2525 The basic API for this class is the same for every database. First, you
26- create a reader object, specifying a file name. You then call the method
27- corresponding to the specific database, passing it the IP address you want
28- to look up.
26+ create a reader object, specifying a file name or file descriptor.
27+ You then call the method corresponding to the specific database, passing
28+ it the IP address you want to look up.
2929
3030 If the request succeeds, the method call will return a model class for the
3131 method you called. This model in turn contains multiple record classes,
@@ -40,10 +40,12 @@ class Reader(object):
4040
4141"""
4242
43- def __init__ (self , filename , locales = None , mode = MODE_AUTO ):
43+ def __init__ (self , fileish , locales = None , mode = MODE_AUTO ):
4444 """Create GeoIP2 Reader.
4545
46- :param filename: The path to the GeoIP2 database.
46+ :param fileish: The string path to the GeoIP2 database, or an existing
47+ file descriptor pointing to the database. Note that this latter
48+ usage is only valid when mode is MODE_FD.
4749 :param locales: This is list of locale codes. This argument will be
4850 passed on to record classes to use when their name properties are
4951 called. The default value is ['en'].
@@ -73,13 +75,15 @@ def __init__(self, filename, locales=None, mode=MODE_AUTO):
7375 * MODE_MMAP - read from memory map. Pure Python.
7476 * MODE_FILE - read database as standard file. Pure Python.
7577 * MODE_MEMORY - load database into memory. Pure Python.
78+ * MODE_FD - the param passed via fileish is a file descriptor, not a
79+ path. This mode implies MODE_MEMORY. Pure Python.
7680 * MODE_AUTO - try MODE_MMAP_EXT, MODE_MMAP, MODE_FILE in that order.
7781 Default.
7882
7983 """
8084 if locales is None :
8185 locales = ['en' ]
82- self ._db_reader = maxminddb .open_database (filename , mode )
86+ self ._db_reader = maxminddb .open_database (fileish , mode )
8387 self ._locales = locales
8488
8589 def __enter__ (self ):
0 commit comments