U
    3d]                     @   sD   d dl Z d dlZ d dlmZ d dlmZ dd ZG dd deZdS )    N)AWSQueryConnection)
RegionInfoc                 C   s   | dkrdS dS )N)T   1truer   false )valr   r   ;/tmp/pip-unpacked-wheel-d7dsrkjd/boto/cloudsearch/layer1.pydo_bool    s    r   c                   @   s   e Zd ZdZejdddZejdddZd<ddZ	dd Z
d=ddZdd Zd>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d(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; ZdS )BLayer1z
2011-02-01ZBotoZcs_region_namez	us-east-1Zcs_region_endpointz#cloudsearch.us-east-1.amazonaws.comNTr   /c                 C   sL   |st | | j| j}|| _tj| | jj||||||||	|
|||||d d S )N)hostaws_access_key_idaws_secret_access_key	is_secureportproxy
proxy_port
proxy_user
proxy_passdebughttps_connection_factorypathsecurity_tokenvalidate_certsprofile_name)r   DefaultRegionNameDefaultRegionEndpointregionr   __init__Zendpoint)selfr   r   r   r   r   r   r   r   r   r   r   r   r   api_versionr   r   r   r   r   r
   r    +   s.    zLayer1.__init__c                 C   s   dgS )Nzhmac-v4r   )r!   r   r   r
   _required_auth_capabilityH   s    z Layer1._required_auth_capabilityGETc                 C   s   |s| }|  ||||}| }	tj|	 |jdkrtjj|rD|nddd}
tj|
|}|	|	 |
}|D ]}|
|}qn|s|d krd S g S t|tr|S tf |S n| |j|j|	d S )N   SetT)list_markerZpythonize_name)Zmake_requestreadbotologr   statusZjsonresponseElementZ
XmlHandlerparseget
isinstancelistdictResponseErrorreason)r!   doc_pathactionparamsr   parentverbr'   responsebodyehinnerpr   r   r
   get_responseK   s*    



zLayer1.get_responsec                 C   s   d}d|i}| j |d|ddS )a:  
        Create a new search domain.

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

        :raises: BaseException, InternalException, LimitExceededException
        )Zcreate_domain_responseZcreate_domain_resultdomain_status
DomainNameZCreateDomainPOSTr8   r?   r!   domain_namer4   r6   r   r   r
   create_domaind   s     zLayer1.create_domain Fc	                 C   s   d}	|||d}
|dkrF||
d< t ||
d< t ||
d< t ||
d< n:|dkrX||
d	< n(|d
kr||
d< t ||
d< t ||
d< | j|	d|
ddS )a  
        Defines an ``IndexField``, either replacing an existing
        definition or creating a new one.

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

        :type field_name: string
        :param field_name: The name of a field in the search index.

        :type field_type: string
        :param field_type: The type of field.  Valid values are
            uint | literal | text

        :type default: string or int
        :param default: The default value for the field.  If the
            field is of type ``uint`` this should be an integer value.
            Otherwise, it's a string.

        :type facet: bool
        :param facet: A boolean to indicate whether facets
            are enabled for this field or not.  Does not apply to
            fields of type ``uint``.

        :type results: bool
        :param results: A boolean to indicate whether values
            of this field can be returned in search results or
            used in ranking.  Does not apply to fields of type ``uint``.

        :type searchable: bool
        :param searchable: A boolean to indicate whether search
            is enabled for this field or not.  Applies only to fields
            of type ``literal``.

        :type source_attributes: list of dicts
        :param source_attributes: An optional list of dicts that
            provide information about attributes for this index field.
            A maximum of 20 source attributes can be configured for
            each index field.

            Each item in the list is a dict with the following keys:

            * data_copy - The value is a dict with the following keys:
                * default - Optional default value if the source attribute
                    is not specified in a document.
                * name - The name of the document source field to add
                    to this ``IndexField``.
            * data_function - Identifies the transformation to apply
                when copying data from a source attribute.
            * data_map - The value is a dict with the following keys:
                * cases - A dict that translates source field values
                    to custom values.
                * default - An optional default value to use if the
                    source attribute is not specified in a document.
                * name - the name of the document source field to add
                    to this ``IndexField``
            * data_trim_title - Trims common title words from a source
                document attribute when populating an ``IndexField``.
                This can be used to create an ``IndexField`` you can
                use for sorting.  The value is a dict with the following
                fields:
                * default - An optional default value.
                * language - an IETF RFC 4646 language code.
                * separator - The separator that follows the text to trim.
                * name - The name of the document source field to add.

        :raises: BaseException, InternalException, LimitExceededException,
            InvalidTypeException, ResourceNotFoundException
        )Zdefine_index_field_responseZdefine_index_field_resultindex_field)rA   zIndexField.IndexFieldNamezIndexField.IndexFieldTypeliteralz&IndexField.LiteralOptions.DefaultValuez&IndexField.LiteralOptions.FacetEnabledz'IndexField.LiteralOptions.ResultEnabledz'IndexField.LiteralOptions.SearchEnabledZuintz#IndexField.UIntOptions.DefaultValuetextz#IndexField.TextOptions.DefaultValuez#IndexField.TextOptions.FacetEnabledz$IndexField.TextOptions.ResultEnabledZDefineIndexFieldrB   rC   )r   r?   )r!   rF   
field_nameZ
field_typedefaultZfacetresultZ
searchableZsource_attributesr4   r6   r   r   r
   define_index_fieldz   s(    N
 zLayer1.define_index_fieldc                 C   s"   d}|||d}| j |d|ddS )a  
        Defines a RankExpression, either replacing an existing
        definition or creating a new one.

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

        :type rank_name: string
        :param rank_name: The name of an expression computed for ranking
            while processing a search request.

        :type rank_expression: string
        :param rank_expression: The expression to evaluate for ranking
            or thresholding while processing a search request. The
            RankExpression syntax is based on JavaScript expressions
            and supports:

            * Integer, floating point, hex and octal literals
            * Shortcut evaluation of logical operators such that an
                expression a || b evaluates to the value a if a is
                true without evaluting b at all
            * JavaScript order of precedence for operators
            * Arithmetic operators: + - * / %
            * Boolean operators (including the ternary operator)
            * Bitwise operators
            * Comparison operators
            * Common mathematic functions: abs ceil erf exp floor
                lgamma ln log2 log10 max min sqrt pow
            * Trigonometric library functions: acosh acos asinh asin
                atanh atan cosh cos sinh sin tanh tan
            * Random generation of a number between 0 and 1: rand
            * Current time in epoch: time
            * The min max functions that operate on a variable argument list

            Intermediate results are calculated as double precision
            floating point values. The final return value of a
            RankExpression is automatically converted from floating
            point to a 32-bit unsigned integer by rounding to the
            nearest integer, with a natural floor of 0 and a ceiling
            of max(uint32_t), 4294967295. Mathematical errors such as
            dividing by 0 will fail during evaluation and return a
            value of 0.

            The source data for a RankExpression can be the name of an
            IndexField of type uint, another RankExpression or the
            reserved name text_relevance. The text_relevance source is
            defined to return an integer from 0 to 1000 (inclusive) to
            indicate how relevant a document is to the search request,
            taking into account repetition of search terms in the
            document and proximity of search terms to each other in
            each matching IndexField in the document.

            For more information about using rank expressions to
            customize ranking, see the Amazon CloudSearch Developer
            Guide.

        :raises: BaseException, InternalException, LimitExceededException,
            InvalidTypeException, ResourceNotFoundException
        )Zdefine_rank_expression_responseZdefine_rank_expression_resultrank_expression)rA   zRankExpression.RankExpressionzRankExpression.RankNameZDefineRankExpressionrB   rC   rD   )r!   rF   	rank_namerP   r4   r6   r   r   r
   define_rank_expression   s    B zLayer1.define_rank_expressionc                 C   s   d}d|i}| j |d|ddS )a  
        Delete a search domain.

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

        :raises: BaseException, InternalException
        )Zdelete_domain_responseZdelete_domain_resultr@   rA   ZDeleteDomainrB   rC   rD   rE   r   r   r
   delete_domain(  s     zLayer1.delete_domainc                 C   s    d}||d}| j |d|ddS )a6  
        Deletes an existing ``IndexField`` from the search domain.

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

        :type field_name: string
        :param field_name: A string that represents the name of
            an index field. Field names must begin with a letter and
            can contain the following characters: a-z (lowercase),
            0-9, and _ (underscore). Uppercase letters and hyphens are
            not allowed. The names "body", "docid", and
            "text_relevance" are reserved and cannot be specified as
            field or rank expression names.

        :raises: BaseException, InternalException, ResourceNotFoundException
        )Zdelete_index_field_responseZdelete_index_field_resultrI   )rA   ZIndexFieldNameZDeleteIndexFieldrB   rC   rD   )r!   rF   rL   r4   r6   r   r   r
   delete_index_field>  s     zLayer1.delete_index_fieldc                 C   s    d}||d}| j |d|ddS )a  
        Deletes an existing ``RankExpression`` from the search domain.

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

        :type rank_name: string
        :param rank_name: Name of the ``RankExpression`` to delete.

        :raises: BaseException, InternalException, ResourceNotFoundException
        )Zdelete_rank_expression_responseZdelete_rank_expression_resultrP   )rA   ZRankNameZDeleteRankExpressionrB   rC   rD   )r!   rF   rQ   r4   r6   r   r   r
   delete_rank_expression^  s    
 zLayer1.delete_rank_expressionc                 C   s   d}d|i}| j |d|ddS )a  
        Describes options defining the default search field used by
        indexing for the search domain.

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

        :raises: BaseException, InternalException, ResourceNotFoundException
        )Z&describe_default_search_field_responseZ$describe_default_search_field_resultdefault_search_fieldrA   ZDescribeDefaultSearchFieldrB   rC   rD   rE   r   r   r
   describe_default_search_fieldw  s     z$Layer1.describe_default_search_fieldc                 C   s@   d}i }|r,t |dD ]\}}||d| < q| j|d|dddS )a  
        Describes the domains (optionally limited to one or more
        domains by name) owned by this account.

        :type domain_names: list
        :param domain_names: Limits the response to the specified domains.

        :raises: BaseException, InternalException
        )Zdescribe_domains_responseZdescribe_domains_resultZdomain_status_listr   zDomainNames.member.%dZDescribeDomainsrB   ZDomainStatusListr8   r'   	enumerater?   )r!   Zdomain_namesr4   r6   irF   r   r   r
   describe_domains  s    
 zLayer1.describe_domainsc                 C   sD   d}d|i}|r0t |dD ]\}}||d| < q| j|d|dddS )	a  
        Describes index fields in the search domain, optionally
        limited to a single ``IndexField``.

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

        :type field_names: list
        :param field_names: Limits the response to the specified fields.

        :raises: BaseException, InternalException, ResourceNotFoundException
        )Zdescribe_index_fields_responseZdescribe_index_fields_resultZindex_fieldsrA   r   zFieldNames.member.%dZDescribeIndexFieldsrB   ZIndexFieldsrX   rY   )r!   rF   field_namesr4   r6   r[   rL   r   r   r
   describe_index_fields  s     zLayer1.describe_index_fieldsc                 C   sD   d}d|i}|r0t |dD ]\}}||d| < q| j|d|dddS )	a  
        Describes RankExpressions in the search domain, optionally
        limited to a single expression.

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

        :type rank_names: list
        :param rank_names: Limit response to the specified rank names.

        :raises: BaseException, InternalException, ResourceNotFoundException
        )Z"describe_rank_expressions_responseZ describe_rank_expressions_resultZrank_expressionsrA   r   zRankNames.member.%dZDescribeRankExpressionsrB   ZRankExpressionsrX   rY   )r!   rF   Z
rank_namesr4   r6   r[   rQ   r   r   r
   describe_rank_expressions  s     z Layer1.describe_rank_expressionsc                 C   s   d}d|i}| j |d|ddS )a  
        Describes the resource-based policies controlling access to
        the services in this search domain.

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

        :raises: BaseException, InternalException, ResourceNotFoundException
        )Z)describe_service_access_policies_responseZ'describe_service_access_policies_resultaccess_policiesrA   ZDescribeServiceAccessPoliciesrB   rC   rD   rE   r   r   r
    describe_service_access_policies  s     z'Layer1.describe_service_access_policiesc                 C   s   d}d|i}| j |d|ddS )ad  
        Describes stemming options used by indexing for the search domain.

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

        :raises: BaseException, InternalException, ResourceNotFoundException
        )Z"describe_stemming_options_responseZ describe_stemming_options_resultstemsrA   ZDescribeStemmingOptionsrB   rC   rD   rE   r   r   r
   describe_stemming_options  s     z Layer1.describe_stemming_optionsc                 C   s   d}d|i}| j |d|ddS )ad  
        Describes stopword options used by indexing for the search domain.

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

        :raises: BaseException, InternalException, ResourceNotFoundException
        )Z"describe_stopword_options_responseZ describe_stopword_options_result	stopwordsrA   ZDescribeStopwordOptionsrB   rC   rD   rE   r   r   r
   describe_stopword_options  s     z Layer1.describe_stopword_optionsc                 C   s   d}d|i}| j |d|ddS )ac  
        Describes synonym options used by indexing for the search domain.

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

        :raises: BaseException, InternalException, ResourceNotFoundException
        )Z!describe_synonym_options_responseZdescribe_synonym_options_resultsynonymsrA   ZDescribeSynonymOptionsrB   rC   rD   rE   r   r   r
   describe_synonym_options"  s     zLayer1.describe_synonym_optionsc                 C   s    d}d|i}| j |d|dddS )aL  
        Tells the search domain to start scanning its documents using
        the latest text processing options and ``IndexFields``.  This
        operation must be invoked to make visible in searches any
        options whose <a>OptionStatus</a> has ``OptionState`` of
        ``RequiresIndexDocuments``.

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

        :raises: BaseException, InternalException, ResourceNotFoundException
        )Zindex_documents_responseZindex_documents_resultr]   rA   ZIndexDocumentsrB   Z
FieldNamesrX   rD   rE   r   r   r
   index_documents8  s    
 zLayer1.index_documentsc                 C   s    d}||d}| j |d|ddS )a  
        Updates options defining the default search field used by
        indexing for the search domain.

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

        :type default_search_field: string
        :param default_search_field: The IndexField to use for search
            requests issued with the q parameter. The default is an
            empty string, which automatically searches all text
            fields.

        :raises: BaseException, InternalException, InvalidTypeException,
            ResourceNotFoundException
        )Z$update_default_search_field_responseZ"update_default_search_field_resultrV   )rA   ZDefaultSearchFieldZUpdateDefaultSearchFieldrB   rC   rD   )r!   rF   rV   r4   r6   r   r   r
   update_default_search_fieldR  s     z"Layer1.update_default_search_fieldc                 C   s    d}||d}| j |d|ddS )a  
        Updates the policies controlling access to the services in
        this search domain.

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

        :type access_policies: string
        :param access_policies: An IAM access policy as described in
            The Access Policy Language in Using AWS Identity and
            Access Management. The maximum size of an access policy
            document is 100KB.

        :raises: BaseException, InternalException, LimitExceededException,
            ResourceNotFoundException, InvalidTypeException
        )Z'update_service_access_policies_responseZ%update_service_access_policies_resultr`   )ZAccessPoliciesrA   ZUpdateServiceAccessPoliciesrB   rC   rD   )r!   rF   r`   r4   r6   r   r   r
   update_service_access_policiesq  s     z%Layer1.update_service_access_policiesc                 C   s    d}||d}| j |d|ddS )a  
        Updates stemming options used by indexing for the search domain.

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

        :type stems: string
        :param stems: Maps terms to their stems.  The JSON object
            has a single key called "stems" whose value is a
            dict mapping terms to their stems. The maximum size
            of a stemming document is 500KB.
            Example: {"stems":{"people": "person", "walking":"walk"}}

        :raises: BaseException, InternalException, InvalidTypeException,
            LimitExceededException, ResourceNotFoundException
        )Z update_stemming_options_responseZupdate_stemming_options_resultrb   )rA   ZStemsZUpdateStemmingOptionsrB   rC   rD   )r!   rF   rb   r4   r6   r   r   r
   update_stemming_options  s     zLayer1.update_stemming_optionsc                 C   s    d}||d}| j |d|ddS )a  
        Updates stopword options used by indexing for the search domain.

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

        :type stopwords: string
        :param stopwords: Lists stopwords in a JSON object. The object has a
            single key called "stopwords" whose value is an array of strings.
            The maximum size of a stopwords document is 10KB. Example:
            {"stopwords": ["a", "an", "the", "of"]}

        :raises: BaseException, InternalException, InvalidTypeException,
            LimitExceededException, ResourceNotFoundException
        )Z update_stopword_options_responseZupdate_stopword_options_resultrd   )rA   Z	StopwordsZUpdateStopwordOptionsrB   rC   rD   )r!   rF   rd   r4   r6   r   r   r
   update_stopword_options  s     zLayer1.update_stopword_optionsc                 C   s    d}||d}| j |d|ddS )aB  
        Updates synonym options used by indexing for the search domain.

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

        :type synonyms: string
        :param synonyms: Maps terms to their synonyms.  The JSON object
            has a single key "synonyms" whose value is a dict mapping terms
            to their synonyms. Each synonym is a simple string or an
            array of strings. The maximum size of a stopwords document
            is 100KB. Example:
            {"synonyms": {"cat": ["feline", "kitten"], "puppy": "dog"}}

        :raises: BaseException, InternalException, InvalidTypeException,
            LimitExceededException, ResourceNotFoundException
        )Zupdate_synonym_options_responseZupdate_synonym_options_resultrf   )rA   ZSynonymsZUpdateSynonymOptionsrB   rC   rD   )r!   rF   rf   r4   r6   r   r   r
   update_synonym_options  s     zLayer1.update_synonym_options)NNTNNNNNNr   NNr   NNTN)r   Nr$   N)rH   FFFN)N)N)N) __name__
__module____qualname__Z
APIVersionr)   configr.   r   r   r    r#   r?   rG   rO   rR   rS   rT   rU   rW   r\   r^   r_   ra   rc   re   rg   rh   ri   rj   rk   rl   rm   r   r   r   r
   r   $   sj   
                         
      
        
cK 


r   )r)   Zboto.jsonresponseZboto.connectionr   Zboto.regioninfor   r   r   r   r   r   r
   <module>   s
   