U
    ÓZj	  ã                   @   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
   úd/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/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   