@@ -19,6 +19,7 @@ class GandiServerProxy(object):
1919 calling the API using Python attribute accessors instead of strings, and
2020 allows for the API key to be pre-loaded into all method calls.
2121 '''
22+
2223 def __init__ (self , api_key , proxy = None , chain = [], test = False ):
2324 self .api_key = api_key
2425 self .chain = chain
@@ -58,11 +59,8 @@ def __call__(self, *args):
5859def get_external_ip (attempts = 100 , threshold = 3 ):
5960 '''Return our current external IP address, or None if there was an error.'''
6061
61- # read the list of IP address providers, de-duping and normalizing them
62- providers = []
63- with open ('ip-providers.txt' ) as f :
64- providers = set (line .strip () for line in f )
65- providers = filter (lambda x : not not x , providers )
62+ # load the tuple of IP address providers
63+ providers = load_providers ()
6664
6765 # we want several different providers to agree on the address, otherwise we
6866 # need to keep trying to get agreement. this prevents picking up 'addresses'
@@ -119,8 +117,14 @@ def get_external_ip(attempts=100, threshold=3):
119117 # return None if no agreement could be reached
120118 return None
121119
120+ def load_providers ():
121+ '''Load the providers file as a de-duplicated and normalized tuple of URLs.'''
122+ with open ('providers.json' ) as f :
123+ providers = json .load (f )['providers' ]
124+ return tuple (set ([p .strip () for p in providers ]))
125+
122126def load_config ():
123- '''Load the config file from disk'''
127+ '''Load the config file from disk. '''
124128 with open ('config.json' ) as f :
125129 return json .load (f )
126130
0 commit comments