o
    ȷea9                     @   s8   g d Z ddlmZ G dd deZG dd deZdS ))AAAAATXTCNAMEMXPTRSRVSPF    )	ResultSetc                       st   e Zd ZdZdZdZd fdd	Zdd Z					dd
dZdd Z	dd Z
dd Z fddZ fddZ  ZS )ResourceRecordSetsz
    A list of resource records.

    :ivar hosted_zone_id: The ID of the hosted zone.
    :ivar comment: A comment that will be stored with the change.
    :ivar changes: A list of changes.
    a@  <?xml version="1.0" encoding="UTF-8"?>
    <ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
            <ChangeBatch>
                <Comment>%(comment)s</Comment>
                <Changes>%(changes)s</Changes>
            </ChangeBatch>
        </ChangeResourceRecordSetsRequest>zM<Change>
        <Action>%(action)s</Action>
        %(record)s
    </Change>Nc                    sD   || _ || _|| _g | _d | _d | _d | _tt| 	dt
fg d S )NResourceRecordSet)
connectionhosted_zone_idcommentchangesnext_record_namenext_record_typenext_record_identifiersuperr   __init__Record)selfr   r   r   	__class__ J/var/www/ideatree/venv/lib/python3.10/site-packages/boto/route53/record.pyr   4   s   zResourceRecordSets.__init__c                 C   s@   | j rddd | j D }n
ddd | D }d| j|f S )N,c                 S      g | ]}|  qS r   __repr__).0cr   r   r   
<listcomp>@       z/ResourceRecordSets.__repr__.<locals>.<listcomp>c                 S   r   r   r   )r    recordr   r   r   r"   B   r#   z<ResourceRecordSets:%s [%s])r   joinr   )r   record_listr   r   r   r   >   s   zResourceRecordSets.__repr__X  c                 C   s2   t ||||||||	|
||d}| j||g |S )a	  
        Add a change request to the set.

        :type action: str
        :param action: The action to perform ('CREATE'|'DELETE'|'UPSERT')

        :type name: str
        :param name: The name of the domain you want to perform the action on.

        :type type: str
        :param type: The DNS record type.  Valid values are:

            * A
            * AAAA
            * CNAME
            * MX
            * NS
            * PTR
            * SOA
            * SPF
            * SRV
            * TXT

        :type ttl: int
        :param ttl: The resource record cache time to live (TTL), in seconds.

        :type alias_hosted_zone_id: str
        :param alias_dns_name: *Alias resource record sets only* The value
            of the hosted zone ID, CanonicalHostedZoneNameId, for
            the LoadBalancer.

        :type alias_dns_name: str
        :param alias_hosted_zone_id: *Alias resource record sets only*
            Information about the domain to which you are redirecting traffic.

        :type identifier: str
        :param identifier: *Weighted and latency-based resource record sets
            only* An identifier that differentiates among multiple resource
            record sets that have the same combination of DNS name and type.

        :type weight: int
        :param weight: *Weighted resource record sets only* Among resource
            record sets that have the same combination of DNS name and type,
            a value that determines what portion of traffic for the current
            resource record set is routed to the associated location

        :type region: str
        :param region: *Latency-based resource record sets only* Among resource
            record sets that have the same combination of DNS name and type,
            a value that determines which region this should be associated with
            for the latency-based routing

        :type alias_evaluate_target_health: bool
        :param alias_evaluate_target_health: *Required for alias resource record
            sets* Indicates whether this Resource Record Set should respect the
            health status of any health checks associated with the ALIAS target
            record which it is linked to.

        :type health_check: str
        :param health_check: Health check to associate with this record

        :type failover: str
        :param failover: *Failover resource record sets only* Whether this is the
            primary or secondary resource record set.
        )alias_hosted_zone_idalias_dns_name
identifierweightregionalias_evaluate_target_healthhealth_checkfailover)r   r   append)r   actionnametypettlr(   r)   r*   r+   r,   r-   r.   r/   changer   r   r   
add_changeF   s   EzResourceRecordSets.add_changec                 C   s   | j ||g dS )z@Add an existing record to a change set with the specified actionN)r   r0   )r   r1   r5   r   r   r   add_change_record   s   z$ResourceRecordSets.add_change_recordc                 C   sJ   d}| j D ]}|d |d  d}|| j| 7 }q| j|d}| j| S )zcConvert this ResourceRecordSet into XML
        to be saved via the ChangeResourceRecordSetsRequest r	      )r1   r$   )r   r   )r   to_xml	ChangeXMLr   ChangeResourceRecordSetsBody)r   
changesXMLr5   changeParamsparamsr   r   r   r:      s   

zResourceRecordSets.to_xmlc                 C   s,   | j sddl}| | _ | j | j|  S )zCommit this changer	   N)r   botoconnect_route53change_rrsetsr   r:   )r   r@   r   r   r   commit   s   
zResourceRecordSets.commitc                    sJ   |dkr	|| _ dS |dkr|| _dS |dkr|| _dS tt| |||S )znOverwritten to also add the NextRecordName,
        NextRecordType and NextRecordIdentifier to the base objectNextRecordNameNextRecordTypeNextRecordIdentifierN)r   r   r   r   r   
endElementr   r2   valuer   r   r   r   rG      s   


zResourceRecordSets.endElementc                 #   sj    t t|  }| j}|r3|D ]}|V  q| jr*d| _| jj| j| j| j| j	d}nd}|| _|sdS dS )z,Override the next function to support pagingF)r2   r3   r*   N)
r   r   __iter__is_truncatedr   get_all_rrsetsr   r   r   r   )r   results	truncatedobjr   r   r   rJ      s   zResourceRecordSets.__iter__)NNN)	r'   NNNNNNNN)__name__
__module____qualname____doc__r<   r;   r   r   r6   r7   r:   rC   rG   rJ   __classcell__r   r   r   r   r      s     

N
r   c                   @   s   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
Z				dddZdd Zdd Z	dddZdd Zdd Zdd Zdd ZdS ) r   zAn individual ResourceRecordSetz!<HealthCheckId>%s</HealthCheckId>z<ResourceRecordSet>
        <Name>%(name)s</Name>
        <Type>%(type)s</Type>
        %(weight)s
        %(body)s
        %(health_check)s
    </ResourceRecordSet>z_
        <SetIdentifier>%(identifier)s</SetIdentifier>
        <Weight>%(weight)s</Weight>
    z_
        <SetIdentifier>%(identifier)s</SetIdentifier>
        <Region>%(region)s</Region>
    ze
        <SetIdentifier>%(identifier)s</SetIdentifier>
        <Failover>%(failover)s</Failover>
    zh
        <TTL>%(ttl)s</TTL>
        <ResourceRecords>
            %(records)s
        </ResourceRecords>z@<ResourceRecord>
        <Value>%s</Value>
    </ResourceRecord>z<AliasTarget>
        <HostedZoneId>%(hosted_zone_id)s</HostedZoneId>
        <DNSName>%(dns_name)s</DNSName>
        %(eval_target_health)s
    </AliasTarget>z/<EvaluateTargetHealth>%s</EvaluateTargetHealth>Nr'   c                 C   sX   || _ || _|| _|d u rg }|| _|| _|| _|| _|| _|	| _|
| _	|| _
|| _d S N)r2   r3   r4   resource_recordsr(   r)   r*   r+   r,   r-   r.   r/   )r   r2   r3   r4   rV   r(   r)   r*   r+   r,   r-   r.   r/   r   r   r   r      s   
zRecord.__init__c                 C   s   d| j | j|  f S )Nz<Record:%s:%s:%s>)r2   r3   to_print)r   r   r   r   r     s   zRecord.__repr__c                 C   s   | j | dS )zAdd a resource record valueN)rV   r0   )r   rI   r   r   r   	add_value  s   zRecord.add_valueFc                 C   s   || _ || _|| _dS )z&Make this an alias resource record setN)r(   r)   r-   )r   r(   r)   r-   r   r   r   	set_alias  s   
zRecord.set_aliasc                 C   s8  | j dur(| jdur(| jdur| j| jrdnd }nd}| j| j | j|d }nd}| jD ]	}|| j| 7 }q-| j| j|d }d}| j	durW| j
durW| j| j	| j
d }n)| j	durl| jdurl| j| j	| jd }n| j	dur| jdur| j| j	| jd	 }d}| jdur| j| j }| j| j|||d
}| j| S )z(Spit this resource record set out as XMLNtruefalser8   )r   dns_nameeval_target_health)r4   records)r*   r+   )r*   r,   )r*   r/   )r2   r3   r+   bodyr.   )r(   r)   r-   EvaluateTargetHealth	AliasBodyrV   ResourceRecordBodyResourceRecordsBodyr4   r*   r+   WRRBodyr,   RRRBodyr/   FailoverBodyr.   HealthCheckBodyr2   r3   XMLBody)r   r]   r_   r^   rr+   r.   r?   r   r   r   r:     sL   






zRecord.to_xmlc                 C   s   d}| j d ur#| jd ur#d| j  d | j }| jd ur"|d| j 7 }nd| j}| jd ur?| jd ur?|d| j| jf 7 }|S | jd urU| jd urU|d| j| jf 7 }|S | jd uri| jd uri|d| j| jf 7 }|S )	Nr8   zALIAS  z (EvalTarget %s)r   z (WRR id=%s, w=%s)z (LBR id=%s, region=%s)z (FAILOVER id=%s, failover=%s))	r(   r)   r-   r%   rV   r*   r+   r,   r/   )r   rrr   r   r   rW   G  s    
zRecord.to_printc                 C   s   |dkr	|| _ d S |dkr|| _d S |dkr|| _d S |dkr'| j| d S |dkr0|| _d S |dkr9|| _d S |dkrB|| _d S |dkrO| d	k| _	d S |d
krX|| _
d S |dkra|| _d S |dkrj|| _d S |dkrs|| _d S d S )NNameTypeTTLValueHostedZoneIdDNSNameSetIdentifierr`   rZ   WeightRegionFailoverHealthCheckId)r2   r3   r4   rV   r0   r(   r)   r*   lowerr-   r+   r,   r/   r.   rH   r   r   r   rG   [  s2   









zRecord.endElementc                 C   s   d S rU   r   )r   r2   attrsr   r   r   r   startElementu  s   zRecord.startElement)NNr'   NNNNNNNNN)F)rP   rQ   rR   rS   rg   rh   rd   re   rf   rc   rb   ra   r`   r   r   rX   rY   r:   rW   rG   ry   r   r   r   r   r      s0    

1r   N)RECORD_TYPESboto.resultsetr
   r   objectr   r   r   r   r   <module>   s
    *