B
    è?F[d   ã               @   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   ú4lib/python3.7/site-packages/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',
            }

        )ÚAttributeNameÚAttributeType)r   r   )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_type)r   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)

    Z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)

    ÚRANGEN)r   r   r   r   r   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 }x"| j D ]}| |j|jdœ¡ qW |S )zõ
        Returns the attribute definition structure DynamoDB expects.

        Example::

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

        )r
   r   )r   Úappendr   r   )r   r   Úpartr   r   r   r   g   s    zBaseIndexField.definitionc             C   s6   g }x| j D ]}| | ¡ ¡ qW | 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_ONLYN)r   r   r   r   r   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   Úschema_data)r'   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"   r.   r$   r*   r	   )r   r%   r&   r.   )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
                }
            }

        r,   r-   )ZReadCapacityUnitsZWriteCapacityUnitsZProvisionedThroughput)r$   r*   r   Úintr.   )r   r(   )r'   r   r   r   ë   s    zGlobalBaseIndexField.schema)r   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 )Ú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   N)r   r   r   r   r   r   r   r   r   r0     s   r0   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   N)r   r   r   r   r   r   r   r   r   r1     s   r1   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 )Nr.   )r"   r    r	   r*   )r   r%   r&   r.   r   r   r   r	   E  s
    zGlobalIncludeIndex.__init__c             C   s   t  | ¡}| t | ¡¡ |S )N)r    r   Úupdater*   )r   r(   r   r   r   r   L  s    
zGlobalIncludeIndex.schemaN)r   r   r   r   r   r	   r   r   r   r   r   r2   2  s   r2   N)Zboto.dynamodb2.typesr   Úobjectr   r   r   r   r   r   r    r*   r0   r1   r2   r   r   r   r   Ú<module>   s   <E5