<s> """<STR_LIT>""" <EOL> __all__ = [ <EOL> '<STR_LIT>' <EOL> ] <EOL> try : <EOL> import simplejson as json <EOL> except ImportError : <EOL> import json <EOL> from libcloud . common . dnsimple import DNSimpleDNSConnection <EOL> from libcloud . dns . types import Provider , RecordType <EOL> from libcloud . dns . base import DNSDriver , Zone , Record <EOL> DEFAULT_ZONE_TTL = <NUM_LIT> <EOL> class DNSimpleDNSDriver ( DNSDriver ) : <EOL> type = Provider . DNSIMPLE <EOL> name = '<STR_LIT>' <EOL> website = '<STR_LIT>' <EOL> connectionCls = DNSimpleDNSConnection <EOL> RECORD_TYPE_MAP = { <EOL> RecordType . A : '<STR_LIT:A>' , <EOL> RecordType . AAAA : '<STR_LIT>' , <EOL> RecordType . ALIAS : '<STR_LIT>' , <EOL> RecordType . CNAME : '<STR_LIT>' , <EOL> RecordType . HINFO : '<STR_LIT>' , <EOL> RecordType . MX : '<STR_LIT>' , <EOL> RecordType . NAPTR : '<STR_LIT>' , <EOL> RecordType . NS : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> RecordType . SOA : '<STR_LIT>' , <EOL> RecordType . SPF : '<STR_LIT>' , <EOL> RecordType . SRV : '<STR_LIT>' , <EOL> RecordType . SSHFP : '<STR_LIT>' , <EOL> RecordType . TXT : '<STR_LIT>' , <EOL> RecordType . URL : '<STR_LIT>' <EOL> } <EOL> def list_zones ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . connection . request ( '<STR_LIT>' ) <EOL> zones = self . _to_zones ( response . object ) <EOL> return zones <EOL> def list_records ( self , zone ) : <EOL> """<STR_LIT>""" <EOL> response = self . connection . request ( '<STR_LIT>' % zone . id ) <EOL> records = self . _to_records ( response . object , zone ) <EOL> return records <EOL> def get_zone ( self , zone_id ) : <EOL> """<STR_LIT>""" <EOL> response = self . connection . request ( '<STR_LIT>' % zone_id ) <EOL> zone = self . _to_zone ( response . object ) <EOL> return zone <EOL> def get_record ( self , zone_id , record_id ) : <EOL> """<STR_LIT>""" <EOL> response = self . connection . request ( '<STR_LIT>' % <EOL> ( zone_id , record_id ) ) <EOL> record = self . _to_record ( response . object , zone_id = zone_id ) <EOL> return record <EOL> def create_zone ( self , domain , type = '<STR_LIT>' , ttl = None , extra = None ) : <EOL> """<STR_LIT>""" <EOL> r_json = { '<STR_LIT:name>' : domain } <EOL> if extra is not None : <EOL> r_json . update ( extra ) <EOL> r_data = json . dumps ( { '<STR_LIT>' : r_json } ) <EOL> response = self . connection . request ( <EOL> '<STR_LIT>' , method = '<STR_LIT:POST>' , data = r_data ) <EOL> zone = self . _to_zone ( response . object ) <EOL> return zone <EOL> def create_record ( self , name , zone , type , data , extra = None ) : <EOL> """<STR_LIT>""" <EOL> r_json = { '<STR_LIT:name>' : name , '<STR_LIT>' : type , '<STR_LIT:content>' : data } <EOL> if extra is not None : <EOL> r_json . update ( extra ) <EOL> r_data = json . dumps ( { '<STR_LIT>' : r_json } ) <EOL> response = self . connection . request ( '<STR_LIT>' % zone . id , <EOL> method = '<STR_LIT:POST>' , data = r_data ) <EOL> record = self . _to_record ( response . object , zone = zone ) <EOL> return record <EOL> def update_record ( self , record , name , type , data , extra = None ) : <EOL> """<STR_LIT>""" <EOL> zone = record . zone <EOL> r_json = { '<STR_LIT:name>' : name , '<STR_LIT:content>' : data } <EOL> if extra is not None : <EOL> r_json . update ( extra ) <EOL> r_data = json . dumps ( { '<STR_LIT>' : r_json } ) <EOL> response = self . connection . request ( '<STR_LIT>' % <EOL> ( zone . id , record . id ) , <EOL> method = '<STR_LIT>' , data = r_data ) <EOL> record = self . _to_record ( response . object , zone = zone ) <EOL> return record <EOL> def delete_zone ( self , zone ) : <EOL> """<STR_LIT>""" <EOL> self . connection . request ( '<STR_LIT>' % zone . id , method = '<STR_LIT>' ) <EOL> return True <EOL> def delete_record ( self , record ) : <EOL> """<STR_LIT>""" <EOL> zone_id = record . zone . id <EOL> self . connection . request ( '<STR_LIT>' % ( zone_id , <EOL> record . id ) , method = '<STR_LIT>' ) <EOL> return True <EOL> def _to_zones ( self , data ) : <EOL> zones = [ ] <EOL> for zone in data : <EOL> _zone = self . _to_zone ( zone ) <EOL> zones . append ( _zone ) <EOL> return zones <EOL> def _to_zone ( self , data ) : <EOL> domain = data . get ( '<STR_LIT>' ) <EOL> id = domain . get ( '<STR_LIT:id>' ) <EOL> name = domain . get ( '<STR_LIT:name>' ) <EOL> extra = { '<STR_LIT>' : domain . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : domain . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : domain . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : domain . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT:state>' : domain . get ( '<STR_LIT:state>' ) , <EOL> '<STR_LIT>' : domain . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : domain . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : domain . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : domain . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : domain . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : domain . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : domain . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : domain . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : domain . get ( '<STR_LIT>' ) } <EOL> type = '<STR_LIT>' <EOL> return Zone ( id = id , domain = name , type = type , ttl = DEFAULT_ZONE_TTL , <EOL> driver = self , extra = extra ) <EOL> def _to_records ( self , data , zone ) : <EOL> records = [ ] <EOL> for item in data : <EOL> record = self . _to_record ( item , zone = zone ) <EOL> records . append ( record ) <EOL> return records <EOL> def _to_record ( self , data , zone_id = None , zone = None ) : <EOL> if not zone : <EOL> zone = self . get_zone ( zone_id ) <EOL> record = data . get ( '<STR_LIT>' ) <EOL> id = record . get ( '<STR_LIT:id>' ) <EOL> name = record . get ( '<STR_LIT:name>' ) <EOL> type = record . get ( '<STR_LIT>' ) <EOL> data = record . get ( '<STR_LIT:content>' ) <EOL> extra = { '<STR_LIT>' : record . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : record . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : record . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : record . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : record . get ( '<STR_LIT>' ) } <EOL> return Record ( id = id , name = name , type = type , data = data , zone = zone , <EOL> driver = self , ttl = record . get ( '<STR_LIT>' , None ) , extra = extra ) </s>
