'Initialize the GeoIP object. No parameters are required to use default
settings. Keyword arguments may be passed in to customize the locations
of the GeoIP datasets.
* path: Base directory to where GeoIP data is located or the full path
to where the city or country data files (*.mmdb) are located.
Assumes that both the city and country data sets are located in
this directory; overrides the GEOIP_PATH setting.
* cache: The cache settings when opening up the GeoIP datasets. May be
an integer in (0, 1, 2, 4, 8) corresponding to the MODE_AUTO,
MODE_MMAP_EXT, MODE_MMAP, MODE_FILE, and MODE_MEMORY,
`GeoIPOptions` C API settings,  respectively. Defaults to 0,
meaning MODE_AUTO.
* country: The name of the GeoIP country data file. Defaults to
\'GeoLite2-Country.mmdb\'; overrides the GEOIP_COUNTRY setting.
* city: The name of the GeoIP city data file. Defaults to
\'GeoLite2-City.mmdb\'; overrides the GEOIP_CITY setting.'

def __init__(self, path=None, cache=0, country=None, city=None):

    if (cache in self.cache_options):
        self._cache = cache
    else:
        raise GeoIP2Exception(('Invalid    GeoIP    caching    option:    %s' % cache))
    if (not path):
        path = GEOIP_SETTINGS['GEOIP_PATH']
        if (not path):
            raise GeoIP2Exception('GeoIP    path    must    be    provided    via    parameter    or    the    GEOIP_PATH    setting.')
    if (not isinstance(path, str)):
        raise TypeError(('Invalid    path    type:    %s' % type(path).__name__))
    if os.path.isdir(path):
        country_db = os.path.join(path, (country or GEOIP_SETTINGS['GEOIP_COUNTRY']))
        if os.path.isfile(country_db):
            self._country = geoip2.database.Reader(country_db, mode=cache)
            self._country_file = country_db
        city_db = os.path.join(path, (city or GEOIP_SETTINGS['GEOIP_CITY']))
        if os.path.isfile(city_db):
            self._city = geoip2.database.Reader(city_db, mode=cache)
            self._city_file = city_db
    elif os.path.isfile(path):
        reader = geoip2.database.Reader(path, mode=cache)
        db_type = reader.metadata().database_type
        if db_type.endswith('City'):
            self._city = reader
            self._city_file = path
        elif db_type.endswith('Country'):
            self._country = reader
            self._country_file = path
        else:
            raise GeoIP2Exception(('Unable    to    recognize    database    edition:    %s' % db_type))
    else:
        raise GeoIP2Exception('GeoIP    path    must    be    a    valid    file    or    directory.')
