U
    æÛŸjÍ  ã                   @   sn   d dl mZmZmZmZmZ d dlmZ d dl	m
Z
 d dlmZ ddlmZ er\ddlmZ G dd	„ d	ƒZd
S )é    )ÚTYPE_CHECKINGÚAnyÚListÚOptionalÚUnion)Úmodels)ÚEmptyManager)Úcached_propertyé   )Úapi_settings)ÚTokenc                   @   sø  e Zd ZdZdZeejƒZeej	ƒZ
dddœdd„Zedœd	d
„Zeeeef dœdd„ƒZeeeef dœdd„ƒZeedœdd„ƒZeedœdd„ƒZeedœdd„ƒZeedœdd„Zeedœdd„Zedœdd„Zddœdd„Zddœdd„Zedd œd!d"„Zedd œd#d$„Zeejdœd%d&„ƒZ eej	dœd'd(„ƒZ!d@e"e e#d)œd*d+„Z$dAe"e e#d)œd,d-„Z%dBee"e ed.œd/d0„Z&dCe'e e"e ed1œd2d3„Z(eed4œd5d6„Z)eedœd7d8„ƒZ*eedœd9d:„ƒZ+edœd;d<„Z,ee"e- d=œd>d?„Z.dS )DÚ	TokenUseraÒ  
    A dummy user class modeled after django.contrib.auth.models.AnonymousUser.
    Used in conjunction with the `JWTStatelessUserAuthentication` backend to
    implement single sign-on functionality across services which share the same
    secret key.  `JWTStatelessUserAuthentication` will return an instance of this
    class instead of a `User` model instance.  Instances of this class act as
    stateless user objects which are backed by validated tokens.
    Tr   N)ÚtokenÚreturnc                 C   s
   || _ d S ©N)r   )Úselfr   © r   úC/tmp/pip-unpacked-wheel-rl9al_jx/rest_framework_simplejwt/models.pyÚ__init__   s    zTokenUser.__init__)r   c                 C   s   d| j › �S )Nz
TokenUser ©Úid©r   r   r   r   Ú__str__!   s    zTokenUser.__str__c                 C   s   | j tj S r   )r   r   ZUSER_ID_CLAIMr   r   r   r   r   $   s    zTokenUser.idc                 C   s   | j S r   r   r   r   r   r   Úpk(   s    zTokenUser.pkc                 C   s   | j  dd¡S )NÚusernameÚ ©r   Úgetr   r   r   r   r   ,   s    zTokenUser.usernamec                 C   s   | j  dd¡S )NÚis_staffFr   r   r   r   r   r   0   s    zTokenUser.is_staffc                 C   s   | j  dd¡S )NÚis_superuserFr   r   r   r   r   r   4   s    zTokenUser.is_superuser)Úotherr   c                 C   s   t |tƒstS | j|jkS r   )Ú
isinstancer   ÚNotImplementedr   ©r   r    r   r   r   Ú__eq__8   s    
zTokenUser.__eq__c                 C   s   |   |¡ S r   )r$   r#   r   r   r   Ú__ne__=   s    zTokenUser.__ne__c                 C   s
   t | jƒS r   )Úhashr   r   r   r   r   Ú__hash__@   s    zTokenUser.__hash__c                 C   s   t dƒ‚d S ©Nz%Token users have no DB representation©ÚNotImplementedErrorr   r   r   r   ÚsaveC   s    zTokenUser.savec                 C   s   t dƒ‚d S r(   r)   r   r   r   r   ÚdeleteF   s    zTokenUser.delete)Úraw_passwordr   c                 C   s   t dƒ‚d S r(   r)   ©r   r-   r   r   r   Úset_passwordI   s    zTokenUser.set_passwordc                 C   s   t dƒ‚d S r(   r)   r.   r   r   r   Úcheck_passwordL   s    zTokenUser.check_passwordc                 C   s   | j S r   )Ú_groupsr   r   r   r   ÚgroupsO   s    zTokenUser.groupsc                 C   s   | j S r   )Ú_user_permissionsr   r   r   r   Úuser_permissionsS   s    zTokenUser.user_permissions)Úobjr   c                 C   s   t ƒ S r   ©Úset©r   r5   r   r   r   Úget_group_permissionsW   s    zTokenUser.get_group_permissionsc                 C   s   t ƒ S r   r6   r8   r   r   r   Úget_all_permissionsZ   s    zTokenUser.get_all_permissions)Úpermr5   r   c                 C   s   dS ©NFr   )r   r;   r5   r   r   r   Úhas_perm]   s    zTokenUser.has_perm)Ú	perm_listr5   r   c                 C   s   dS r<   r   )r   r>   r5   r   r   r   Ú	has_perms`   s    zTokenUser.has_perms)Úmoduler   c                 C   s   dS r<   r   )r   r@   r   r   r   Úhas_module_permsc   s    zTokenUser.has_module_permsc                 C   s   dS r<   r   r   r   r   r   Úis_anonymousf   s    zTokenUser.is_anonymousc                 C   s   dS )NTr   r   r   r   r   Úis_authenticatedj   s    zTokenUser.is_authenticatedc                 C   s   | j S r   )r   r   r   r   r   Úget_usernamen   s    zTokenUser.get_username)Úattrr   c                 C   s   | j  |d¡S )zVThis acts as a backup attribute getter for custom claims defined in Token serializers.Nr   )r   rE   r   r   r   Ú__getattr__q   s    zTokenUser.__getattr__)N)N)N)N)/Ú__name__Ú
__module__Ú__qualname__Ú__doc__Z	is_activer   Úauth_modelsÚGroupr1   Z
Permissionr3   r   Ústrr   r	   r   Úintr   r   r   Úboolr   r   Úobjectr$   r%   r'   r+   r,   r/   r0   Úpropertyr2   r4   r   r7   r9   r:   r=   r   r?   rA   rB   rC   rD   r   rF   r   r   r   r   r      sL   

r   N)Útypingr   r   r   r   r   Zdjango.contrib.authr   rK   Zdjango.db.models.managerr   Zdjango.utils.functionalr	   Úsettingsr   Útokensr   r   r   r   r   r   Ú<module>   s   