U
    cc	                     @   sB   d dl Z d dlmZ e jr&d dlmZ dd Zdd Zdd	 ZdS )
    N)PersistenceException)RequestEnvelopec                 C   s4   z| j jjj}|W S  tk
r.   tdY nX dS )a`  Retrieve user id from request envelope, to use as partition key.

    :param request_envelope: Request Envelope passed during skill
        invocation
    :type request_envelope: ask_sdk_model.RequestEnvelope
    :return: User Id retrieved from request envelope
    :rtype: str
    :raises: :py:class:`ask_sdk_core.exceptions.PersistenceException`
    zFCouldn't retrieve user id from request envelope, for partition key useN)contextsystemuseruser_idAttributeErrorr   )request_enveloper    r
   E/tmp/pip-unpacked-wheel-vzs5_2lw/ask_sdk_dynamodb/partition_keygen.pyuser_id_partition_keygen   s
    r   c                 C   s4   z| j jjj}|W S  tk
r.   tdY nX dS )ad  Retrieve device id from request envelope, to use as partition key.

    :param request_envelope: Request Envelope passed during skill
        invocation
    :type request_envelope: ask_sdk_model.RequestEnvelope
    :return: Device Id retrieved from request envelope
    :rtype: str
    :raises: :py:class:`ask_sdk_core.exceptions.PersistenceException`
    zHCouldn't retrieve device id from request envelope, for partition key useN)r   r   Zdevice	device_idr   r   )r	   r   r
   r
   r   device_id_partition_keygen-   s
    r   c                 C   sV   z| j jjj}W n@ tk
rP   zt| d}W n tk
rJ   tdY nX Y nX |S )a_  Retrieve person id from request envelope, to use as object key.

    This method retrieves the `person id` specific to a voice profile from
    the request envelope if it exists, to be used as an object key. If it
    doesn't exist, then the `user id` is returned instead.

    :param request_envelope: Request Envelope passed during skill
        invocation
    :type request_envelope: ask_sdk_model.RequestEnvelope
    :return: person Id retrieved from request envelope if exists, else
        fall back on User Id
    :rtype: str
    :raises: :py:class:`ask_sdk_core.exceptions.PersistenceException`
    )r	   zSCouldn't retrieve person id or user id from request envelope, for partition key use)r   r   Zperson	person_idr   r   r   )r	   r   r
   r
   r   person_id_partition_keygen@   s    
r   )	typingZask_sdk_core.exceptionsr   TYPE_CHECKINGZask_sdk_modelr   r   r   r   r
   r
   r
   r   <module>   s   