Commit 6edc9d97 by William Tisäter

Make internal cache class private

parent 06509cce
...@@ -51,18 +51,10 @@ MEMORY_CACHE = const.MEMORY_CACHE ...@@ -51,18 +51,10 @@ MEMORY_CACHE = const.MEMORY_CACHE
ENCODING = const.ENCODING ENCODING = const.ENCODING
class GeoIPError(Exception): class _GeoIPMetaclass(type):
pass
class GeoIPMetaclass(type):
def __new__(cls, *args, **kwargs): def __new__(cls, *args, **kwargs):
""" """ Singleton method to gets an instance without reparsing
Singleton method to gets an instance without reparsing the db. Unique the database, the filename is being used as cache key.
instances are instantiated based on the filename of the db. Flags are
ignored for this, i.e. if you initialize one with STANDARD
flag (default) and then try later to initialize with MEMORY_CACHE, it
will still return the STANDARD one.
""" """
if not hasattr(cls, '_instances'): if not hasattr(cls, '_instances'):
cls._instances = {} cls._instances = {}
...@@ -78,10 +70,14 @@ class GeoIPMetaclass(type): ...@@ -78,10 +70,14 @@ class GeoIPMetaclass(type):
return cls._instances[filename] return cls._instances[filename]
GeoIPBase = GeoIPMetaclass('GeoIPBase', (object,), {}) _GeoIPBase = _GeoIPMetaclass('GeoIPBase', (object,), {})
class GeoIPError(Exception):
pass
class GeoIP(GeoIPBase): class GeoIP(_GeoIPBase):
def __init__(self, filename, flags=0): def __init__(self, filename, flags=0):
""" """
Initialize the class. Initialize the class.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment