o
    ȷeg?                     @   sD   d Z ddlZddlmZ ddlmZ ddlmZ G dd deZ	dS )<       N)TooManyRecordsException)ResourceRecordSets)Statusc                   @   s   e Zd ZdZdd Zdd Zdd Z	d5d	d
Z		d6ddZ		d7ddZ	d5ddZ
d7ddZd7ddZd7ddZd8ddZd9ddZd9dd Zd9d!d"Zd7d#d$Zd7d%d&Zd7d'd(Zd:d)d*Zd:d+d,Zd:d-d.Zd/d0 Zd1d2 Zd3d4 ZdS );Zonez
    A Route53 Zone.

    :ivar route53connection: A :class:`boto.route53.connection.Route53Connection` connection
    :ivar id: The ID of the hosted zone
    c                 C   sD   || _ |D ]}|dkr|d dd| _q| | ||  qd S )NIdz/hostedzone/ )route53connectionreplaceid__setattr__lower)selfr	   	zone_dictkey r   H/var/www/ideatree/venv/lib/python3.10/site-packages/boto/route53/zone.py__init__(   s   zZone.__init__c                 C   s
   d| j  S )Nz	<Zone:%s>)namer   r   r   r   __repr__0   s   
zZone.__repr__c                 C   s   |  }|d d S )z
        Commit a set of changes and return the ChangeInfo portion of
        the response.

        :type changes: ResourceRecordSets
        :param changes: changes to be committed
         ChangeResourceRecordSetsResponse
ChangeInfo)commit)r   changesresponser   r   r   _commit3   s   zZone._commitr   c              	   C   s   d}d}	|dur%zt |d  |d }|d }W n   |d }	|d }Y |jd||||||	d}
t|tttfv rF|D ]}|
| q<dS |
| dS )aw  
        Add a CREATE change record to an existing ResourceRecordSets

        :type changes: ResourceRecordSets
        :param changes: change set to append to

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

        :type resource_type: str
        :param resource_type: The DNS record type

        :param value: Appropriate value for resource_type

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

        :type identifier: tuple
        :param identifier: A tuple for setting WRR or LBR attributes.  Valid
           forms are:

           * (str, int): WRR record [e.g. ('foo',10)]
           * (str, str): LBR record [e.g. ('foo','us-east-1')

        :type comment: str
        :param comment: A comment that will be stored with the change.
        N   r   CREATE)
identifierweightregion)int
add_changetypelisttupleset	add_value)r   r   resource_typer   valuettlr   commentr    r!   changerecordr   r   r   _new_record>   s&   
zZone._new_recordr   Nc              	   C   s8   t | j| j|}| ||||||| t| j| |S )z
        Add a new record to this Zone.  See _new_record for parameter
        documentation.  Returns a Status object.
        )r   r	   r   r/   r   r   )r   r)   r   r*   r+   r   r,   r   r   r   r   
add_recordo   s
   zZone.add_recordc              	   C   sZ   |pt }t|}t| j| j|}|d| | ||j|j|||| t	| j| 
|S )a
  
        Update an existing record in this Zone.  Returns a Status object.

        :type old_record: ResourceRecord
        :param old_record: A ResourceRecord (e.g. returned by find_records)

        See _new_record for additional parameter documentation.
        DELETE)default_ttlcopyr   r	   r   add_change_recordr/   r$   r   r   r   )r   
old_record	new_valuenew_ttlnew_identifierr,   r.   r   r   r   r   update_recordz   s   

zZone.update_recordc                 C   sX   t | j| j|}t|tttfv r|D ]}|d| qn|d| t| j| 	|S )a8  
        Delete one or more records from this Zone.  Returns a Status object.

        :param record: A ResourceRecord (e.g. returned by
           find_records) or list, tuple, or set of ResourceRecords.

        :type comment: str
        :param comment: A comment that will be stored with the change.
        r1   )
r   r	   r   r$   r%   r&   r'   r4   r   r   )r   r.   r,   r   rr   r   r   delete_record   s   
zZone.delete_recordc                 C   s6   |pt }| j|}| j|}| jd|||||dS )z
        Add a new CNAME record to this Zone.  See _new_record for
        parameter documentation.  Returns a Status object.
        CNAMEr)   r   r*   r+   r   r,   r2   r	   _make_qualifiedr0   r   r   r*   r+   r   r,   r   r   r   	add_cname   s   zZone.add_cnamec                 C   s*   |pt }| j|}| jd|||||dS )z
        Add a new A record to this Zone.  See _new_record for
        parameter documentation.  Returns a Status object.
        Ar=   r>   r@   r   r   r   add_a      z
Zone.add_ac                 C   s*   |pt }| j|}| jd|||||dS )z
        Add a new MX record to this Zone.  See _new_record for
        parameter documentation.  Returns a Status object.
        MXr=   r>   )r   r   recordsr+   r   r,   r   r   r   add_mx   rD   zZone.add_mxr   Fc           
         s,  | j |}| j j| j||d}g }|D ]}|j|kr&|j|kr&|| q dd durDzt d   d W n    d Y durR fdd|D }dur` fdd|D }|st||krd||f }	|	d7 }	|	d		d
d |D 7 }	t
|	t|dkr|S t|dkr|d S dS )a  
        Search this Zone for records that match given parameters.
        Returns None if no results, a ResourceRecord if one result, or
        a ResourceRecordSets if more than one result.

        :type name: str
        :param name: The name of the records should match this parameter

        :type type: str
        :param type: The type of the records should match this parameter

        :type desired: int
        :param desired: The number of desired results.  If the number of
           matching records in the Zone exceeds the value of this parameter,
           throw TooManyRecordsException

        :type all: Boolean
        :param all: If true return all records that match name, type, and
          identifier parameters

        :type identifier: Tuple
        :param identifier: A tuple specifying WRR or LBR attributes.  Valid
           forms are:

           * (str, int): WRR record [e.g. ('foo',10)]
           * (str, str): LBR record [e.g. ('foo','us-east-1')

        )r   r$   Nr   c                    (   g | ]}|j kr|j d  kr|qS r   )r    r   .0r:   )r   r    r   r   
<listcomp>       z%Zone.find_records.<locals>.<listcomp>c                    rH   rI   )r!   r   rJ   )r   r!   r   r   rL     rM   zSearch: name %s type %sz
Found: z, c                 S   s"   g | ]}d |j |j| f qS )z%s %s %s)r   r$   to_printrJ   r   r   r   rL     s    r   )r	   r?   get_all_rrsetsr   r   r$   appendr"   lenjoinr   )
r   r   r$   desiredallr   returnedresultsr:   messager   )r   r!   r    r   find_records   sB   

zZone.find_recordsc                 C      | j |d|dS )z
        Search this Zone for CNAME records that match name.

        Returns a ResourceRecord.

        If there is more than one match return all as a
        ResourceRecordSets if all is True, otherwise throws
        TooManyRecordsException.
        r<   rT   rX   r   r   rT   r   r   r   	get_cname     
zZone.get_cnamec                 C   rY   )z
        Search this Zone for A records that match name.

        Returns a ResourceRecord.

        If there is more than one match return all as a
        ResourceRecordSets if all is True, otherwise throws
        TooManyRecordsException.
        rB   rZ   r[   r\   r   r   r   get_a  r^   z
Zone.get_ac                 C   rY   )z
        Search this Zone for MX records that match name.

        Returns a ResourceRecord.

        If there is more than one match return all as a
        ResourceRecordSets if all is True, otherwise throws
        TooManyRecordsException.
        rE   rZ   r[   r\   r   r   r   get_mx*  r^   zZone.get_mxc                 C   @   | j |}| j |}| |}|p|j}| j|||||dS )z
        Update the given CNAME record in this Zone to a new value, ttl,
        and identifier.  Returns a Status object.

        Will throw TooManyRecordsException is name, value does not match
        a single record.
        r6   r7   r8   r,   )r	   r?   r]   r+   r9   r   r   r*   r+   r   r,   r5   r   r   r   update_cname6     

zZone.update_cnamec                 C   s4   | j |}| |}|p|j}| j|||||dS )z
        Update the given A record in this Zone to a new value, ttl,
        and identifier.  Returns a Status object.

        Will throw TooManyRecordsException is name, value does not match
        a single record.
        rb   )r	   r?   r_   r+   r9   rc   r   r   r   update_aH  s   

zZone.update_ac                 C   ra   )z
        Update the given MX record in this Zone to a new value, ttl,
        and identifier.  Returns a Status object.

        Will throw TooManyRecordsException is name, value does not match
        a single record.
        rb   )r	   r?   r`   r+   r9   rc   r   r   r   	update_mxY  re   zZone.update_mxc                 C   (   | j |}| j|d||d}| |S )z
        Delete a CNAME record matching name and identifier from
        this Zone.  Returns a Status object.

        If there is more than one match delete all matching records if
        all is True, otherwise throws TooManyRecordsException.
        r<   r   rT   r	   r?   rX   r;   r   r   r   rT   r.   r   r   r   delete_cnamek  
   

zZone.delete_cnamec                 C   rh   )z
        Delete an A record matching name and identifier from this
        Zone.  Returns a Status object.

        If there is more than one match delete all matching records if
        all is True, otherwise throws TooManyRecordsException.
        rB   ri   rj   rk   r   r   r   delete_ax  rm   zZone.delete_ac                 C   rh   )z
        Delete an MX record matching name and identifier from this
        Zone.  Returns a Status object.

        If there is more than one match delete all matching records if
        all is True, otherwise throws TooManyRecordsException.
        rE   ri   rj   rk   r   r   r   	delete_mx  rm   zZone.delete_mxc                 C   s   | j | jS )zS
        Return a ResourceRecordsSets for all of the records in this zone.
        )r	   rO   r   r   r   r   r   get_records  s   zZone.get_recordsc                 C   s   | j | j dS )z>
        Request that this zone be deleted by Amazon.
        N)r	   delete_hosted_zoner   r   r   r   r   delete  s   zZone.deletec                 C   s    |  | jd}|dur|j}|S )z+ Get the list of nameservers for this zone.NSN)rX   r   resource_records)r   nsr   r   r   get_nameservers  s   zZone.get_nameservers)r   )r   Nr   )NNr   )r   FN)F)NF)__name__
__module____qualname____doc__r   r   r   r/   r0   r9   r;   rA   rC   rG   rX   r]   r_   r`   rd   rf   rg   rl   rn   ro   rp   rr   rv   r   r   r   r   r   !   s<    
1







I







r   )
r2   r3   boto.exceptionr   boto.route53.recordr   boto.route53.statusr   objectr   r   r   r   r   <module>   s   