U
    W¨+dd   ã                   @   sÂ   d dl mZ G dd„ deƒZG dd„ deƒZG dd„ deƒZG dd	„ d	eƒZG d
d„ deƒZG dd„ deƒZG dd„ deƒZ	G dd„ deƒZ
G dd„ de
ƒZG dd„ de
ƒZG dd„ de
e	ƒZdS )é    )ÚSTRINGc                   @   s0   e Zd ZdZdZefdd„Zdd„ Zdd„ ZdS )	ÚBaseSchemaFieldz´
    An abstract class for defining schema fields.

    Contains most of the core functionality for the field. Subclasses must
    define an ``attr_type`` to pass to DynamoDB.
    Nc                 C   s   || _ || _dS )aN  
        Creates a Python schema field, to represent the data to pass to
        DynamoDB.

        Requires a ``name`` parameter, which should be a string name of the
        field.

        Optionally accepts a ``data_type`` parameter, which should be a
        constant from ``boto.dynamodb2.types``. (Default: ``STRING``)
        N©ÚnameÚ	data_type)Úselfr   r   © r   ú9/tmp/pip-unpacked-wheel-dlxw5sjy/boto/dynamodb2/fields.pyÚ__init__   s    zBaseSchemaField.__init__c                 C   s   | j | jdœS )zõ
        Returns the attribute definition structure DynamoDB expects.

        Example::

            >>> field.definition()
            {
                'AttributeName': 'username',
                'AttributeType': 'S',
            }

        ©ÚAttributeNameZAttributeTyper   ©r   r   r   r	   Ú
definition   s    þzBaseSchemaField.definitionc                 C   s   | j | jdœS )zà
        Returns the schema structure DynamoDB expects.

        Example::

            >>> field.schema()
            {
                'AttributeName': 'username',
                'KeyType': 'HASH',
            }

        )r   ZKeyType)r   Ú	attr_typer   r   r   r	   Úschema-   s    þzBaseSchemaField.schema)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r
   r   r   r   r   r   r	   r      s
   r   c                   @   s   e Zd ZdZdZdS )ÚHashKeyzÅ
    An field representing a hash key.

    Example::

        >>> from boto.dynamodb2.types import NUMBER
        >>> HashKey('username')
        >>> HashKey('date_joined', data_type=NUMBER)

    ÚHASHN©r   r   r   r   r   r   r   r   r	   r   @   s   
r   c                   @   s   e Zd ZdZdZdS )ÚRangeKeyzÆ
    An field representing a range key.

    Example::

        >>> from boto.dynamodb2.types import NUMBER
        >>> HashKey('username')
        >>> HashKey('date_joined', data_type=NUMBER)

    ÚRANGENr   r   r   r   r	   r   N   s   
r   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚBaseIndexFieldzº
    An abstract class for defining schema indexes.

    Contains most of the core functionality for the index. Subclasses must
    define a ``projection_type`` to pass to DynamoDB.
    c                 C   s   || _ || _d S ©N)r   Úparts)r   r   r   r   r   r	   r
   c   s    zBaseIndexField.__init__c                 C   s(   g }| j D ]}| |j|jdœ¡ q
|S )zõ
        Returns the attribute definition structure DynamoDB expects.

        Example::

            >>> index.definition()
            {
                'AttributeName': 'username',
                'AttributeType': 'S',
            }

        r   )r   Úappendr   r   )r   r   Úpartr   r   r	   r   g   s    
þ
zBaseIndexField.definitionc                 C   s2   g }| j D ]}| | ¡ ¡ q
| j|d| jidœS )aâ  
        Returns the schema structure DynamoDB expects.

        Example::

            >>> index.schema()
            {
                'IndexName': 'LastNameIndex',
                'KeySchema': [
                    {
                        'AttributeName': 'username',
                        'KeyType': 'HASH',
                    },
                ],
                'Projection': {
                    'ProjectionType': 'KEYS_ONLY',
                }
            }

        ZProjectionType)Z	IndexNameZ	KeySchemaÚ
Projection)r   r   r   r   Úprojection_type)r   Z
key_schemar   r   r   r	   r   ~   s    
 ÿýzBaseIndexField.schemaN)r   r   r   r   r
   r   r   r   r   r   r	   r   \   s   r   c                   @   s   e Zd ZdZdZdS )ÚAllIndexzà
    An index signifying all fields should be in the index.

    Example::

        >>> AllIndex('MostRecentlyJoined', parts=[
        ...     HashKey('username'),
        ...     RangeKey('date_joined')
        ... ])

    ÚALLN©r   r   r   r   r    r   r   r   r	   r!   ¡   s   r!   c                   @   s   e Zd ZdZdZdS )ÚKeysOnlyIndexzê
    An index signifying only key fields should be in the index.

    Example::

        >>> KeysOnlyIndex('MostRecentlyJoined', parts=[
        ...     HashKey('username'),
        ...     RangeKey('date_joined')
        ... ])

    Ú	KEYS_ONLYNr#   r   r   r   r	   r$   °   s   r$   c                       s0   e Zd ZdZdZ‡ fdd„Z‡ fdd„Z‡  ZS )ÚIncludeIndexzû
    An index signifying only certain fields should be in the index.

    Example::

        >>> IncludeIndex('GenderIndex', parts=[
        ...     HashKey('username'),
        ...     RangeKey('date_joined')
        ... ], includes=['gender'])

    ÚINCLUDEc                    s$   |  dg ¡| _tt| ƒj||Ž d S )NZincludes)ÚpopÚincludes_fieldsÚsuperr&   r
   )r   ÚargsÚkwargs©Ú	__class__r   r	   r
   Í   s    zIncludeIndex.__init__c                    s    t t| ƒ ¡ }| j|d d< |S )Nr   ZNonKeyAttributes)r*   r&   r   r)   ©r   Zschema_datar-   r   r	   r   Ñ   s    zIncludeIndex.schema)r   r   r   r   r    r
   r   Ú__classcell__r   r   r-   r	   r&   ¿   s   r&   c                       s6   e Zd ZdZdddœZ‡ fdd„Z‡ fdd„Z‡  ZS )ÚGlobalBaseIndexFieldzº
    An abstract class for defining global indexes.

    Contains most of the core functionality for the index. Subclasses must
    define a ``projection_type`` to pass to DynamoDB.
    é   )ÚreadÚwritec                    s0   |  dd ¡}|d k	r|| _tt| ƒj||Ž d S ©NÚ
throughput)r(   r6   r*   r1   r
   ©r   r+   r,   r6   r-   r   r	   r
   ã   s    zGlobalBaseIndexField.__init__c                    s4   t t| ƒ ¡ }t| jd ƒt| jd ƒdœ|d< |S )ax  
        Returns the schema structure DynamoDB expects.

        Example::

            >>> index.schema()
            {
                'IndexName': 'LastNameIndex',
                'KeySchema': [
                    {
                        'AttributeName': 'username',
                        'KeyType': 'HASH',
                    },
                ],
                'Projection': {
                    'ProjectionType': 'KEYS_ONLY',
                },
                'ProvisionedThroughput': {
                    'ReadCapacityUnits': 5,
                    'WriteCapacityUnits': 5
                }
            }

        r3   r4   )ZReadCapacityUnitsZWriteCapacityUnitsZProvisionedThroughput)r*   r1   r   Úintr6   r/   r-   r   r	   r   ë   s
    þ
zGlobalBaseIndexField.schema)r   r   r   r   r6   r
   r   r0   r   r   r-   r	   r1   ×   s   þr1   c                   @   s   e Zd ZdZdZdS )ÚGlobalAllIndexaE  
    An index signifying all fields should be in the index.

    Example::

        >>> GlobalAllIndex('MostRecentlyJoined', parts=[
        ...     HashKey('username'),
        ...     RangeKey('date_joined')
        ... ],
        ... throughput={
        ...     'read': 2,
        ...     'write': 1,
        ... })

    r"   Nr#   r   r   r   r	   r9     s   r9   c                   @   s   e Zd ZdZdZdS )ÚGlobalKeysOnlyIndexaO  
    An index signifying only key fields should be in the index.

    Example::

        >>> GlobalKeysOnlyIndex('MostRecentlyJoined', parts=[
        ...     HashKey('username'),
        ...     RangeKey('date_joined')
        ... ],
        ... throughput={
        ...     'read': 2,
        ...     'write': 1,
        ... })

    r%   Nr#   r   r   r   r	   r:     s   r:   c                   @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )ÚGlobalIncludeIndexal  
    An index signifying only certain fields should be in the index.

    Example::

        >>> GlobalIncludeIndex('GenderIndex', parts=[
        ...     HashKey('username'),
        ...     RangeKey('date_joined')
        ... ],
        ... includes=['gender'],
        ... throughput={
        ...     'read': 2,
        ...     'write': 1,
        ... })

    r'   c                 O   s@   |  dd ¡}tj| f|ž|Ž |r*||d< tj| f|ž|Ž d S r5   )r(   r&   r
   r1   r7   r   r   r	   r
   E  s
    zGlobalIncludeIndex.__init__c                 C   s   t  | ¡}| t | ¡¡ |S r   )r&   r   Úupdater1   r/   r   r   r	   r   L  s    
zGlobalIncludeIndex.schemaN)r   r   r   r   r    r
   r   r   r   r   r	   r;   2  s   r;   N)Zboto.dynamodb2.typesr   Úobjectr   r   r   r   r!   r$   r&   r1   r9   r:   r;   r   r   r   r	   Ú<module>   s   <E5