<s> from __future__ import print_function <EOL> import re <EOL> import requests <EOL> from . import __title__ , __version__ , __email__ <EOL> AVAILABLE_PLUGINS = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> DEFAULT_PLUGIN = '<STR_LIT>' <EOL> error_messages = { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> } <EOL> class DnsUpdaterPlugin ( object ) : <EOL> """<STR_LIT>""" <EOL> auth_type = "<STR_LIT>" <EOL> def __init__ ( self , auth , hostname , options = None ) : <EOL> """<STR_LIT>""" <EOL> self . _auth = auth <EOL> self . _hostname = hostname <EOL> self . _options = { } if options is None else options <EOL> self . last_ddns_response = "<STR_LIT>" <EOL> @ property <EOL> def auth ( self ) : <EOL> return self . _auth <EOL> @ property <EOL> def hostname ( self ) : <EOL> return self . _hostname <EOL> def _get_base_url ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def update_dns ( self , new_ip ) : <EOL> """<STR_LIT>""" <EOL> headers = None <EOL> if self . auth_type == '<STR_LIT:T>' : <EOL> api_call_url = self . _get_base_url ( ) . format ( hostname = self . hostname , <EOL> token = self . auth . token , <EOL> ip = new_ip ) <EOL> else : <EOL> api_call_url = self . _get_base_url ( ) . format ( hostname = self . hostname , <EOL> ip = new_ip ) <EOL> headers = { <EOL> '<STR_LIT>' : "<STR_LIT>" % <EOL> self . auth . base64key . decode ( '<STR_LIT:utf-8>' ) , <EOL> '<STR_LIT>' : "<STR_LIT>" % ( __title__ , __version__ , __email__ ) <EOL> } <EOL> r = requests . get ( api_call_url , headers = headers ) <EOL> self . last_ddns_response = str ( r . text ) . strip ( ) <EOL> return r . status_code , r . text <EOL> @ property <EOL> def status_message ( self ) : <EOL> """<STR_LIT>""" <EOL> msg = None <EOL> if self . last_ddns_response in error_messages . keys ( ) : <EOL> msg = error_messages . get ( self . last_ddns_response ) <EOL> elif self . last_ddns_response == '<STR_LIT:OK>' : <EOL> msg = "<STR_LIT>" <EOL> elif '<STR_LIT>' in self . last_ddns_response or '<STR_LIT>' in self . last_ddns_response : <EOL> ip = re . search ( r'<STR_LIT>' , self . last_ddns_response ) . group ( ) <EOL> if '<STR_LIT>' in self . last_ddns_response : <EOL> msg = "<STR_LIT>" % ip <EOL> else : <EOL> msg = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" % ip <EOL> else : <EOL> msg = "<STR_LIT>" <EOL> return msg <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % ( type ( self ) . __name__ , self . hostname ) <EOL> class NoipDnsUpdater ( DnsUpdaterPlugin ) : <EOL> """<STR_LIT>""" <EOL> auth_type = "<STR_LIT:P>" <EOL> def _get_base_url ( self ) : <EOL> return "<STR_LIT>" "<STR_LIT>" <EOL> class DynDnsUpdater ( DnsUpdaterPlugin ) : <EOL> """<STR_LIT>""" <EOL> auth_type = "<STR_LIT:P>" <EOL> def _get_base_url ( self ) : <EOL> return "<STR_LIT>" "<STR_LIT>" <EOL> class DuckDnsUpdater ( DnsUpdaterPlugin ) : <EOL> """<STR_LIT>""" <EOL> auth_type = "<STR_LIT:T>" <EOL> @ property <EOL> def hostname ( self ) : <EOL> hostname = self . _hostname <EOL> found = re . search ( r'<STR_LIT>' , self . _hostname ) <EOL> if found : <EOL> hostname = found . group ( <NUM_LIT:1> ) <EOL> return hostname <EOL> def _get_base_url ( self ) : <EOL> return "<STR_LIT>" "<STR_LIT>" <EOL> class GenericDnsUpdater ( DnsUpdaterPlugin ) : <EOL> """<STR_LIT>""" <EOL> auth_type = "<STR_LIT:P>" <EOL> def _get_base_url ( self ) : <EOL> return "<STR_LIT>" "<STR_LIT>" . format ( url = self . _options [ '<STR_LIT:url>' ] ) </s>
