o
    È·eí"  ã                   @   s$   G d d„ de ƒZG dd„ deƒZdS )c                   @   s@   e Zd ZdZ			ddd„Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚCORSRuleaŸ  
    CORS rule for a bucket.

    :ivar id: A unique identifier for the rule.  The ID value can be
        up to 255 characters long.  The IDs help you find a rule in
        the configuration.

    :ivar allowed_methods: An HTTP method that you want to allow the
        origin to execute.  Each CORSRule must identify at least one
        origin and one method. Valid values are:
        GET|PUT|HEAD|POST|DELETE

    :ivar allowed_origin: An origin that you want to allow cross-domain
        requests from. This can contain at most one * wild character.
        Each CORSRule must identify at least one origin and one method.
        The origin value can include at most one '*' wild character.
        For example, "http://*.example.com". You can also specify
        only * as the origin value allowing all origins cross-domain access.

    :ivar allowed_header: Specifies which headers are allowed in a
        pre-flight OPTIONS request via the
        Access-Control-Request-Headers header. Each header name
        specified in the Access-Control-Request-Headers header must
        have a corresponding entry in the rule. Amazon S3 will send
        only the allowed headers in a response that were requested.
        This can contain at most one * wild character.

    :ivar max_age_seconds: The time in seconds that your browser is to
        cache the preflight response for the specified resource.

    :ivar expose_header: One or more headers in the response that you
        want customers to be able to access from their applications
        (for example, from a JavaScript XMLHttpRequest object).  You
        add one ExposeHeader element in the rule for each header.
        Nc                 C   sX   |d u rg }|| _ |d u rg }|| _|| _|d u rg }|| _|| _|d u r'g }|| _d S ©N)Úallowed_methodÚallowed_originÚidÚallowed_headerÚmax_age_secondsÚexpose_header)Úselfr   r   r   r   r   r   © r
   úC/var/www/ideatree/venv/lib/python3.10/site-packages/boto/s3/cors.pyÚ__init__>   s   
zCORSRule.__init__c                 C   s
   d| j  S )Nz
<Rule: %s>)r   )r	   r
   r
   r   Ú__repr__P   s   
zCORSRule.__repr__c                 C   s   d S r   r
   )r	   ÚnameÚattrsÚ
connectionr
   r
   r   ÚstartElementS   s   zCORSRule.startElementc                 C   s˜   |dkr	|| _ d S |dkr| j |¡ d S |dkr!| j |¡ d S |dkr-| j |¡ d S |dkr8t|ƒ| _d S |dkrD| j |¡ d S t| ||ƒ d S )NÚIDÚAllowedMethodÚAllowedOriginÚAllowedHeaderÚMaxAgeSecondsÚExposeHeader)	r   r   Úappendr   r   Úintr   r   Úsetattr©r	   r   Úvaluer   r
   r
   r   Ú
endElementV   s   
zCORSRule.endElementc                 C   s˜   d}| j D ]}|d| 7 }q| jD ]}|d| 7 }q| jD ]}|d| 7 }q| jD ]}|d| 7 }q)| jr<|d| j 7 }| jrF|d| j 7 }|d7 }|S )	Nz
<CORSRule>z!<AllowedMethod>%s</AllowedMethod>z!<AllowedOrigin>%s</AllowedOrigin>z!<AllowedHeader>%s</AllowedHeader>z<ExposeHeader>%s</ExposeHeader>z!<MaxAgeSeconds>%d</MaxAgeSeconds>z<ID>%s</ID>z</CORSRule>)r   r   r   r   r   r   )r	   Úsr   r   r   r   r
   r
   r   Úto_xmlf   s   



zCORSRule.to_xml)NNNNNN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r
   r
   r
   r   r      s    $
þr   c                   @   s6   e Zd ZdZdd„ Zdd„ Zdd„ Z		dd	d
„ZdS )ÚCORSConfigurationzI
    A container for the rules associated with a CORS configuration.
    c                 C   s    |dkrt ƒ }|  |¡ |S d S )Nr   )r   r   )r	   r   r   r   Úruler
   r
   r   r   }   s
   
zCORSConfiguration.startElementc                 C   s   t | ||ƒ d S r   )r   r   r
   r
   r   r   „   s   zCORSConfiguration.endElementc                 C   s&   d}| D ]}||  ¡ 7 }q|d7 }|S )zv
        Returns a string containing the XML version of the Lifecycle
        configuration as defined by S3.
        z<CORSConfiguration>z</CORSConfiguration>)r   )r	   r   r%   r
   r
   r   r   ‡   s
   zCORSConfiguration.to_xmlNc                 C   sŒ   t |ttfƒs
|g}t |ttfƒs|g}t |ttfƒs%|du r"g }n|g}t |ttfƒs6|du r3g }n|g}t||||||ƒ}|  |¡ dS )aÒ  
        Add a rule to this CORS configuration.  This only adds
        the rule to the local copy.  To install the new rule(s) on
        the bucket, you need to pass this CORS config object
        to the set_cors method of the Bucket object.

        :type allowed_methods: list of str
        :param allowed_methods: An HTTP method that you want to allow the
            origin to execute.  Each CORSRule must identify at least one
            origin and one method. Valid values are:
            GET|PUT|HEAD|POST|DELETE

        :type allowed_origin: list of str
        :param allowed_origin: An origin that you want to allow cross-domain
            requests from. This can contain at most one * wild character.
            Each CORSRule must identify at least one origin and one method.
            The origin value can include at most one '*' wild character.
            For example, "http://*.example.com". You can also specify
            only * as the origin value allowing all origins
            cross-domain access.

        :type id: str
        :param id: A unique identifier for the rule.  The ID value can be
            up to 255 characters long.  The IDs help you find a rule in
            the configuration.

        :type allowed_header: list of str
        :param allowed_header: Specifies which headers are allowed in a
            pre-flight OPTIONS request via the
            Access-Control-Request-Headers header. Each header name
            specified in the Access-Control-Request-Headers header must
            have a corresponding entry in the rule. Amazon S3 will send
            only the allowed headers in a response that were requested.
            This can contain at most one * wild character.

        :type max_age_seconds: int
        :param max_age_seconds: The time in seconds that your browser is to
            cache the preflight response for the specified resource.

        :type expose_header: list of str
        :param expose_header: One or more headers in the response that you
            want customers to be able to access from their applications
            (for example, from a JavaScript XMLHttpRequest object).  You
            add one ExposeHeader element in the rule for each header.
        N)Ú
isinstanceÚlistÚtupler   r   )r	   r   r   r   r   r   r   r%   r
   r
   r   Úadd_rule’   s    0
ÿzCORSConfiguration.add_rule)NNNN)r    r!   r"   r#   r   r   r   r)   r
   r
   r
   r   r$   x   s    þr$   N)Úobjectr   r'   r$   r
   r
   r
   r   Ú<module>   s   _