U
    W+d5                     @   sX   d dl Z d dlmZ d dlm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)json)AWSQueryConnection)
RegionInfo)JSONResponseError)
exceptionsc                       s4  e Zd ZdZdZdZdZeZe	j
e	je	je	je	je	jdZ fddZdd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd?d!d"Zd@d#d$ZdAd%d&Z dBd'd(Z!dCd)d*Z"d+d, Z#dDd-d.Z$dEd/d0Z%d1d2 Z&d3d4 Z'd5d6 Z(d7d8 Z)d9d: Z*d;d< Z+d=d> Z,  Z-S )FCloudSearchConnectionaj  
    Amazon CloudSearch Configuration Service
    You use the Amazon CloudSearch configuration service to create,
    configure, and manage search domains. Configuration service
    requests are submitted using the AWS Query protocol. AWS Query
    requests are HTTP or HTTPS requests submitted via HTTP GET or POST
    with a query parameter named Action.

    The endpoint for configuration service requests is region-
    specific: cloudsearch. region .amazonaws.com. For example,
    cloudsearch.us-east-1.amazonaws.com. For a current list of
    supported regions and endpoints, see `Regions and Endpoints`_.
    z
2013-01-01z	us-east-1z#cloudsearch.us-east-1.amazonaws.com)InvalidTypeExceptionLimitExceededExceptionInternalExceptionDisabledOperationExceptionResourceNotFoundExceptionBaseExceptionc                    sl   | dd }|s t| | j| j}d|ks4|d d kr>|j|d< | dd}|| _tt| jf | || _	d S )Nregionhostsign_requestF)
popr   DefaultRegionNameDefaultRegionEndpointZendpointr   superr   __init__r   )selfkwargsr   r   	__class__ </tmp/pip-unpacked-wheel-dlxw5sjy/boto/cloudsearch2/layer1.pyr   ;   s    
zCloudSearchConnection.__init__c                 C   s   dgS )Nzhmac-v4r   )r   r   r   r   _required_auth_capabilityJ   s    z/CloudSearchConnection._required_auth_capabilityc                 C   s   d|i}| j ddd|dS )a  
        Indexes the search suggestions.

        :type domain_name: string
        :param domain_name: A string that represents the name of a domain.
            Domain names are unique across the domains owned by an account
            within an AWS region. Domain names start with a letter or number
            and can contain the following characters: a-z (lowercase), 0-9, and
            - (hyphen).

        
DomainNameZBuildSuggestersPOST/actionverbpathparams_make_requestr   domain_namer$   r   r   r   build_suggestersM   s     z&CloudSearchConnection.build_suggestersc                 C   s   d|i}| j ddd|dS )a  
        Creates a new search domain. For more information, see
        `Creating a Search Domain`_ in the Amazon CloudSearch
        Developer Guide .

        :type domain_name: string
        :param domain_name: A name for the domain you are creating. Allowed
            characters are a-z (lower-case letters), 0-9, and hyphen (-).
            Domain names must start with a letter or number and be at least 3
            and no more than 28 characters long.

        r   ZCreateDomainr   r   r    r%   r'   r   r   r   create_domain_   s     z#CloudSearchConnection.create_domainc                 C   s(   d|i}|  |d| | jddd|dS )a  
        Configures an analysis scheme that can be applied to a `text`
        or `text-array` field to define language-specific text
        processing options. For more information, see `Configuring
        Analysis Schemes`_ in the Amazon CloudSearch Developer Guide .

        :type domain_name: string
        :param domain_name: A string that represents the name of a domain.
            Domain names are unique across the domains owned by an account
            within an AWS region. Domain names start with a letter or number
            and can contain the following characters: a-z (lowercase), 0-9, and
            - (hyphen).

        :type analysis_scheme: dict
        :param analysis_scheme: Configuration information for an analysis
            scheme. Each analysis scheme has a unique name and specifies the
            language of the text to be processed. The following options can be
            configured for an analysis scheme: `Synonyms`, `Stopwords`,
            `StemmingDictionary`, and `AlgorithmicStemming`.

        r   ZAnalysisSchemeZDefineAnalysisSchemer   r   r    build_complex_paramr&   )r   r(   Zanalysis_schemer$   r   r   r   define_analysis_schemer   s     z,CloudSearchConnection.define_analysis_schemec                 C   s(   d|i}|  |d| | jddd|dS )a  
        Configures an `Expression` for the search domain. Used to
        create new expressions and modify existing ones. If the
        expression exists, the new configuration replaces the old one.
        For more information, see `Configuring Expressions`_ in the
        Amazon CloudSearch Developer Guide .

        :type domain_name: string
        :param domain_name: A string that represents the name of a domain.
            Domain names are unique across the domains owned by an account
            within an AWS region. Domain names start with a letter or number
            and can contain the following characters: a-z (lowercase), 0-9, and
            - (hyphen).

        :type expression: dict
        :param expression: A named expression that can be evaluated at search
            time. Can be used to sort the search results, define other
            expressions, or return computed information in the search results.

        r   Z
ExpressionZDefineExpressionr   r   r    r+   )r   r(   Z
expressionr$   r   r   r   define_expression   s     z'CloudSearchConnection.define_expressionc                 C   s(   d|i}|  |d| | jddd|dS )ao  
        Configures an `IndexField` for the search domain. Used to
        create new fields and modify existing ones. You must specify
        the name of the domain you are configuring and an index field
        configuration. The index field configuration specifies a
        unique name, the index field type, and the options you want to
        configure for the field. The options you can specify depend on
        the `IndexFieldType`. If the field exists, the new
        configuration replaces the old one. For more information, see
        `Configuring Index Fields`_ in the Amazon CloudSearch
        Developer Guide .

        :type domain_name: string
        :param domain_name: A string that represents the name of a domain.
            Domain names are unique across the domains owned by an account
            within an AWS region. Domain names start with a letter or number
            and can contain the following characters: a-z (lowercase), 0-9, and
            - (hyphen).

        :type index_field: dict
        :param index_field: The index field and field options you want to
            configure.

        r   Z
IndexFieldZDefineIndexFieldr   r   r    r+   )r   r(   Zindex_fieldr$   r   r   r   define_index_field   s     z(CloudSearchConnection.define_index_fieldc                 C   s(   d|i}|  |d| | jddd|dS )az  
        Configures a suggester for a domain. A suggester enables you
        to display possible matches before users finish typing their
        queries. When you configure a suggester, you must specify the
        name of the text field you want to search for possible matches
        and a unique name for the suggester. For more information, see
        `Getting Search Suggestions`_ in the Amazon CloudSearch
        Developer Guide .

        :type domain_name: string
        :param domain_name: A string that represents the name of a domain.
            Domain names are unique across the domains owned by an account
            within an AWS region. Domain names start with a letter or number
            and can contain the following characters: a-z (lowercase), 0-9, and
            - (hyphen).

        :type suggester: dict
        :param suggester: Configuration information for a search suggester.
            Each suggester has a unique name and specifies the text field you
            want to use for suggestions. The following options can be
            configured for a suggester: `FuzzyMatching`, `SortExpression`.

        r   Z	SuggesterZDefineSuggesterr   r   r    r+   )r   r(   Z	suggesterr$   r   r   r   define_suggester   s     z&CloudSearchConnection.define_suggesterc                 C   s   ||d}| j ddd|dS )a  
        Deletes an analysis scheme. For more information, see
        `Configuring Analysis Schemes`_ in the Amazon CloudSearch
        Developer Guide .

        :type domain_name: string
        :param domain_name: A string that represents the name of a domain.
            Domain names are unique across the domains owned by an account
            within an AWS region. Domain names start with a letter or number
            and can contain the following characters: a-z (lowercase), 0-9, and
            - (hyphen).

        :type analysis_scheme_name: string
        :param analysis_scheme_name: The name of the analysis scheme you want
            to delete.

        )r   ZAnalysisSchemeNameZDeleteAnalysisSchemer   r   r    r%   )r   r(   Zanalysis_scheme_namer$   r   r   r   delete_analysis_scheme   s     z,CloudSearchConnection.delete_analysis_schemec                 C   s   d|i}| j ddd|dS )a  
        Permanently deletes a search domain and all of its data. Once
        a domain has been deleted, it cannot be recovered. For more
        information, see `Deleting a Search Domain`_ in the Amazon
        CloudSearch Developer Guide .

        :type domain_name: string
        :param domain_name: The name of the domain you want to permanently
            delete.

        r   ZDeleteDomainr   r   r    r%   r'   r   r   r   delete_domain	  s     z#CloudSearchConnection.delete_domainc                 C   s   ||d}| j ddd|dS )a  
        Removes an `Expression` from the search domain. For more
        information, see `Configuring Expressions`_ in the Amazon
        CloudSearch Developer Guide .

        :type domain_name: string
        :param domain_name: A string that represents the name of a domain.
            Domain names are unique across the domains owned by an account
            within an AWS region. Domain names start with a letter or number
            and can contain the following characters: a-z (lowercase), 0-9, and
            - (hyphen).

        :type expression_name: string
        :param expression_name: The name of the `Expression` to delete.

        )r   ZExpressionNameZDeleteExpressionr   r   r    r%   )r   r(   Zexpression_namer$   r   r   r   delete_expression  s     z'CloudSearchConnection.delete_expressionc                 C   s   ||d}| j ddd|dS )a  
        Removes an `IndexField` from the search domain. For more
        information, see `Configuring Index Fields`_ in the Amazon
        CloudSearch Developer Guide .

        :type domain_name: string
        :param domain_name: A string that represents the name of a domain.
            Domain names are unique across the domains owned by an account
            within an AWS region. Domain names start with a letter or number
            and can contain the following characters: a-z (lowercase), 0-9, and
            - (hyphen).

        :type index_field_name: string
        :param index_field_name: The name of the index field your want to
            remove from the domain's indexing options.

        )r   ZIndexFieldNameZDeleteIndexFieldr   r   r    r%   )r   r(   Zindex_field_namer$   r   r   r   delete_index_field5  s     z(CloudSearchConnection.delete_index_fieldc                 C   s   ||d}| j ddd|dS )a  
        Deletes a suggester. For more information, see `Getting Search
        Suggestions`_ in the Amazon CloudSearch Developer Guide .

        :type domain_name: string
        :param domain_name: A string that represents the name of a domain.
            Domain names are unique across the domains owned by an account
            within an AWS region. Domain names start with a letter or number
            and can contain the following characters: a-z (lowercase), 0-9, and
            - (hyphen).

        :type suggester_name: string
        :param suggester_name: Specifies the name of the suggester you want to
            delete.

        )r   ZSuggesterNameZDeleteSuggesterr   r   r    r%   )r   r(   Zsuggester_namer$   r   r   r   delete_suggesterP  s     z&CloudSearchConnection.delete_suggesterNc                 C   sH   d|i}|dk	r|  ||d |dk	r6t| |d< | jddd|dS )	a  
        Gets the analysis schemes configured for a domain. An analysis
        scheme defines language-specific text processing options for a
        `text` field. Can be limited to specific analysis schemes by
        name. By default, shows all analysis schemes and includes any
        pending changes to the configuration. Set the `Deployed`
        option to `True` to show the active configuration and exclude
        pending changes. For more information, see `Configuring
        Analysis Schemes`_ in the Amazon CloudSearch Developer Guide .

        :type domain_name: string
        :param domain_name: The name of the domain you want to describe.

        :type analysis_scheme_names: list
        :param analysis_scheme_names: The analysis schemes you want to
            describe.

        :type deployed: boolean
        :param deployed: Whether to display the deployed configuration (
            `True`) or include any pending changes ( `False`). Defaults to
            `False`.

        r   NzAnalysisSchemeNames.memberDeployedZDescribeAnalysisSchemesr   r   r    build_list_paramsstrlowerr&   )r   r(   Zanalysis_scheme_namesdeployedr$   r   r   r   describe_analysis_schemesj  s      z/CloudSearchConnection.describe_analysis_schemesc                 C   s2   d|i}|dk	r t | |d< | jddd|dS )a  
        Gets the availability options configured for a domain. By
        default, shows the configuration with any pending changes. Set
        the `Deployed` option to `True` to show the active
        configuration and exclude pending changes. For more
        information, see `Configuring Availability Options`_ in the
        Amazon CloudSearch Developer Guide .

        :type domain_name: string
        :param domain_name: The name of the domain you want to describe.

        :type deployed: boolean
        :param deployed: Whether to display the deployed configuration (
            `True`) or include any pending changes ( `False`). Defaults to
            `False`.

        r   Nr6   ZDescribeAvailabilityOptionsr   r   r    r9   r:   r&   r   r(   r;   r$   r   r   r   describe_availability_options  s     z3CloudSearchConnection.describe_availability_optionsc                 C   s,   i }|dk	r|  ||d | jddd|dS )az  
        Gets information about the search domains owned by this
        account. Can be limited to specific domains. Shows all domains
        by default. To get the number of searchable documents in a
        domain, use the console or submit a `matchall` request to your
        domain's search endpoint:
        `q=matchall&q.parser=structured&size=0`. For more information,
        see `Getting Information about a Search Domain`_ in the Amazon
        CloudSearch Developer Guide .

        :type domain_names: list
        :param domain_names: The names of the domains you want to include in
            the response.

        NzDomainNames.memberZDescribeDomainsr   r   r    )r8   r&   )r   Zdomain_namesr$   r   r   r   describe_domains  s     z&CloudSearchConnection.describe_domainsc                 C   sH   d|i}|dk	r|  ||d |dk	r6t| |d< | jddd|dS )	a  
        Gets the expressions configured for the search domain. Can be
        limited to specific expressions by name. By default, shows all
        expressions and includes any pending changes to the
        configuration. Set the `Deployed` option to `True` to show the
        active configuration and exclude pending changes. For more
        information, see `Configuring Expressions`_ in the Amazon
        CloudSearch Developer Guide .

        :type domain_name: string
        :param domain_name: The name of the domain you want to describe.

        :type expression_names: list
        :param expression_names: Limits the `DescribeExpressions` response to
            the specified expressions. If not specified, all expressions are
            shown.

        :type deployed: boolean
        :param deployed: Whether to display the deployed configuration (
            `True`) or include any pending changes ( `False`). Defaults to
            `False`.

        r   NzExpressionNames.memberr6   ZDescribeExpressionsr   r   r    r7   )r   r(   Zexpression_namesr;   r$   r   r   r   describe_expressions  s      z*CloudSearchConnection.describe_expressionsc                 C   sH   d|i}|dk	r|  ||d |dk	r6t| |d< | jddd|dS )	a  
        Gets information about the index fields configured for the
        search domain. Can be limited to specific fields by name. By
        default, shows all fields and includes any pending changes to
        the configuration. Set the `Deployed` option to `True` to show
        the active configuration and exclude pending changes. For more
        information, see `Getting Domain Information`_ in the Amazon
        CloudSearch Developer Guide .

        :type domain_name: string
        :param domain_name: The name of the domain you want to describe.

        :type field_names: list
        :param field_names: A list of the index fields you want to describe. If
            not specified, information is returned for all configured index
            fields.

        :type deployed: boolean
        :param deployed: Whether to display the deployed configuration (
            `True`) or include any pending changes ( `False`). Defaults to
            `False`.

        r   NzFieldNames.memberr6   ZDescribeIndexFieldsr   r   r    r7   )r   r(   field_namesr;   r$   r   r   r   describe_index_fields  s      z+CloudSearchConnection.describe_index_fieldsc                 C   s   d|i}| j ddd|dS )a  
        Gets the scaling parameters configured for a domain. A
        domain's scaling parameters specify the desired search
        instance type and replication count. For more information, see
        `Configuring Scaling Options`_ in the Amazon CloudSearch
        Developer Guide .

        :type domain_name: string
        :param domain_name: A string that represents the name of a domain.
            Domain names are unique across the domains owned by an account
            within an AWS region. Domain names start with a letter or number
            and can contain the following characters: a-z (lowercase), 0-9, and
            - (hyphen).

        r   ZDescribeScalingParametersr   r   r    r%   r'   r   r   r   describe_scaling_parameters  s     z1CloudSearchConnection.describe_scaling_parametersc                 C   s2   d|i}|dk	r t | |d< | jddd|dS )a  
        Gets information about the access policies that control access
        to the domain's document and search endpoints. By default,
        shows the configuration with any pending changes. Set the
        `Deployed` option to `True` to show the active configuration
        and exclude pending changes. For more information, see
        `Configuring Access for a Search Domain`_ in the Amazon
        CloudSearch Developer Guide .

        :type domain_name: string
        :param domain_name: The name of the domain you want to describe.

        :type deployed: boolean
        :param deployed: Whether to display the deployed configuration (
            `True`) or include any pending changes ( `False`). Defaults to
            `False`.

        r   Nr6   ZDescribeServiceAccessPoliciesr   r   r    r=   r>   r   r   r    describe_service_access_policies'  s     z6CloudSearchConnection.describe_service_access_policiesc                 C   sH   d|i}|dk	r|  ||d |dk	r6t| |d< | jddd|dS )	a  
        Gets the suggesters configured for a domain. A suggester
        enables you to display possible matches before users finish
        typing their queries. Can be limited to specific suggesters by
        name. By default, shows all suggesters and includes any
        pending changes to the configuration. Set the `Deployed`
        option to `True` to show the active configuration and exclude
        pending changes. For more information, see `Getting Search
        Suggestions`_ in the Amazon CloudSearch Developer Guide .

        :type domain_name: string
        :param domain_name: The name of the domain you want to describe.

        :type suggester_names: list
        :param suggester_names: The suggesters you want to describe.

        :type deployed: boolean
        :param deployed: Whether to display the deployed configuration (
            `True`) or include any pending changes ( `False`). Defaults to
            `False`.

        r   NzSuggesterNames.memberr6   ZDescribeSuggestersr   r   r    r7   )r   r(   Zsuggester_namesr;   r$   r   r   r   describe_suggestersC  s      z)CloudSearchConnection.describe_suggestersc                 C   s   d|i}| j ddd|dS )aV  
        Tells the search domain to start indexing its documents using
        the latest indexing options. This operation must be invoked to
        activate options whose OptionStatus is
        `RequiresIndexDocuments`.

        :type domain_name: string
        :param domain_name: A string that represents the name of a domain.
            Domain names are unique across the domains owned by an account
            within an AWS region. Domain names start with a letter or number
            and can contain the following characters: a-z (lowercase), 0-9, and
            - (hyphen).

        r   ZIndexDocumentsr   r   r    r%   r'   r   r   r   index_documentsh  s     z%CloudSearchConnection.index_documentsc                 C   s   i }| j ddd|dS )z?
        Lists all search domains owned by an account.
        ZListDomainNamesr   r   r    r%   )r   r$   r   r   r   list_domain_names}  s     z'CloudSearchConnection.list_domain_namesc                 C   s   ||d}| j ddd|dS )a  
        Configures the availability options for a domain. Enabling the
        Multi-AZ option expands an Amazon CloudSearch domain to an
        additional Availability Zone in the same Region to increase
        fault tolerance in the event of a service disruption. Changes
        to the Multi-AZ option can take about half an hour to become
        active. For more information, see `Configuring Availability
        Options`_ in the Amazon CloudSearch Developer Guide .

        :type domain_name: string
        :param domain_name: A string that represents the name of a domain.
            Domain names are unique across the domains owned by an account
            within an AWS region. Domain names start with a letter or number
            and can contain the following characters: a-z (lowercase), 0-9, and
            - (hyphen).

        :type multi_az: boolean
        :param multi_az: You expand an existing search domain to a second
            Availability Zone by setting the Multi-AZ option to true.
            Similarly, you can turn off the Multi-AZ option to downgrade the
            domain to a single Availability Zone by setting the Multi-AZ option
            to `False`.

        )r   ZMultiAZZUpdateAvailabilityOptionsr   r   r    r%   )r   r(   Zmulti_azr$   r   r   r   update_availability_options  s    
 z1CloudSearchConnection.update_availability_optionsc                 C   s(   d|i}|  |d| | jddd|dS )a`  
        Configures scaling parameters for a domain. A domain's scaling
        parameters specify the desired search instance type and
        replication count. Amazon CloudSearch will still automatically
        scale your domain based on the volume of data and traffic, but
        not below the desired instance type and replication count. If
        the Multi-AZ option is enabled, these values control the
        resources used per Availability Zone. For more information,
        see `Configuring Scaling Options`_ in the Amazon CloudSearch
        Developer Guide .

        :type domain_name: string
        :param domain_name: A string that represents the name of a domain.
            Domain names are unique across the domains owned by an account
            within an AWS region. Domain names start with a letter or number
            and can contain the following characters: a-z (lowercase), 0-9, and
            - (hyphen).

        :type scaling_parameters: dict
        :param scaling_parameters: The desired instance type and desired number
            of replicas of each index partition.

        r   ZScalingParametersZUpdateScalingParametersr   r   r    r+   )r   r(   Zscaling_parametersr$   r   r   r   update_scaling_parameters  s     z/CloudSearchConnection.update_scaling_parametersc                 C   s   ||d}| j ddd|dS )a  
        Configures the access rules that control access to the
        domain's document and search endpoints. For more information,
        see ` Configuring Access for an Amazon CloudSearch Domain`_.

        :type domain_name: string
        :param domain_name: A string that represents the name of a domain.
            Domain names are unique across the domains owned by an account
            within an AWS region. Domain names start with a letter or number
            and can contain the following characters: a-z (lowercase), 0-9, and
            - (hyphen).

        :type access_policies: string
        :param access_policies: The access rules you want to configure. These
            rules replace any existing rules.

        )r   ZAccessPoliciesZUpdateServiceAccessPoliciesr   r   r    r%   )r   r(   Zaccess_policiesr$   r   r   r   update_service_access_policies  s     z4CloudSearchConnection.update_service_access_policiesc                 C   s~   |  D ]p\}}t|trD|  D ]\}}| ||d | | q"qt|trh|rVdpXd|d||f < q||d||f < qdS )a  Serialize a structure.

        For example::

            param_type = 'structure'
            label = 'IndexField'
            value = {'IndexFieldName': 'a', 'IntOptions': {'DefaultValue': 5}}

        would result in the params dict being updated with these params::

            IndexField.IndexFieldName = a
            IndexField.IntOptions.DefaultValue = 5

        :type params: dict
        :param params: The params dict.  The complex list params
            will be added to this dict.

        :type label: str
        :param label: String label for param key

        :type value: any
        :param value: The value to serialize
        .truefalsez%s.%sN)items
isinstancedictr,   bool)r   r$   labelvaluekvZk2Zv2r   r   r   r,     s    

z)CloudSearchConnection.build_complex_paramc           
      C   s   d|d< | j |dd|d}| d}tj| |jdkrHt|S t|}|	di 	d	d }| j
	|| j}	|	|j|j|d
d S )NZJSONZContentTyper   r   r    zutf-8   ErrorZCode)body)Zmake_requestreaddecodebotologdebugstatusr   loadsget_faultsResponseErrorreason)
r   r!   r"   r#   r$   responserY   Z	json_bodyZ
fault_nameZexception_classr   r   r   r&     s     



z#CloudSearchConnection._make_request)NN)N)N)NN)NN)N)NN).__name__
__module____qualname____doc__Z
APIVersionr   r   r   rc   r   r   r	   r
   r   r   r   rb   r   r   r)   r*   r-   r.   r/   r0   r1   r2   r3   r4   r5   r<   r?   r@   rA   rC   rD   rE   rF   rG   rH   rI   rJ   rK   r,   r&   __classcell__r   r   r   r   r      s`   	!    
&

  
&  
&
  
%
 !r   )r\   Zboto.compatr   Zboto.connectionr   Zboto.regioninfor   Zboto.exceptionr   Zboto.cloudsearch2r   r   r   r   r   r   <module>   s   