U
    8ÄT_´  ã                   @   sz   d dl Z d dlZd dlmZ d dlmZ d dlmZ G dd„ dƒZG dd„ de 	e¡ƒZ
G d	d
„ d
ƒZG dd„ de
ƒZdS )é    N)Úimport_module)Úrouter)ÚQuerySetc                       s´   e Zd ZdZdZdZ‡ fdd„Z‡ fdd„Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zedd„ ƒZed$dd„ƒZdd„ Zdd„ Zd%dd„Zedd„ ƒZdd„ Zdd„ Zd d!„ Zd"d#„ Z‡  ZS )&ÚBaseManagerr   Fc                    s   t ƒ  | ¡}||f|_|S ©N)ÚsuperÚ__new__Ú_constructor_args)ÚclsÚargsÚkwargsÚobj©Ú	__class__© ú</tmp/pip-unpacked-wheel-dv63caxw/django/db/models/manager.pyr      s    
zBaseManager.__new__c                    s.   t ƒ  ¡  |  ¡  d | _d | _d | _i | _d S r   )r   Ú__init__Ú_set_creation_counterÚmodelÚnameÚ_dbÚ_hints©Úselfr   r   r   r      s    
zBaseManager.__init__c                 C   s   d| j jj| jf S )z,Return "app_label.model_label.manager_name".ú%s.%s)r   Ú_metaÚlabelr   r   r   r   r   Ú__str__"   s    zBaseManager.__str__c                 O   s   | S r   r   )r
   r   r   r   r   r   Ú__class_getitem__&   s    zBaseManager.__class_getitem__c                 C   s‚   | j }t| ddƒr,ddd|j|jf ddfS | j}| jj}t|ƒ}t||ƒs\td||f ƒ‚dd||f d| jd | jd fS dS )	z½
        Return a 5-tuple of the form (as_manager (True), manager_class,
        queryset_class, args, kwargs).

        Raise a ValueError if the manager is dynamically generated.
        Z_built_with_as_managerFTNr   z…Could not find manager %s in %s.
Please note that you need to inherit from managers you dynamically generated with 'from_queryset()'.r   é   )	Ú_queryset_classÚgetattrÚ
__module__Ú__name__r   r   ÚhasattrÚ
ValueErrorr	   )r   Zqs_classÚmodule_namer   Úmoduler   r   r   Údeconstruct)   s.    û
ýÿ
ûzBaseManager.deconstructc                 K   s   g S r   r   )r   r   r   r   r   ÚcheckN   s    zBaseManager.checkc                 C   sh   dd„ }i }t j|t jd�D ]F\}}t| |ƒr0qt|dd ƒ}|s|d krT| d¡rTq|||ƒ||< q|S )Nc                    s    ‡ fdd„}|j |_ |j|_|S )Nc                    s   t |  ¡ ˆ ƒ||ŽS r   )r!   Úget_queryset)r   r   r   ©r   r   r   Úmanager_methodT   s    zPBaseManager._get_queryset_methods.<locals>.create_method.<locals>.manager_method)r#   Ú__doc__)r   Úmethodr,   r   r+   r   Úcreate_methodS   s    z8BaseManager._get_queryset_methods.<locals>.create_method)Ú	predicateÚqueryset_onlyÚ_)ÚinspectÚ
getmembersÚ
isfunctionr$   r!   Ú
startswith)r
   Úqueryset_classr/   Znew_methodsr   r.   r1   r   r   r   Ú_get_queryset_methodsQ   s    
z!BaseManager._get_queryset_methodsNc                 C   s4   |d krd| j |j f }t|| fd|i|  |¡–ƒS )Nz%sFrom%sr    )r#   Útyper8   )r
   r7   Ú
class_namer   r   r   Úfrom_querysetg   s     ÿþzBaseManager.from_querysetc                 C   s2   | j p|| _ || _t||t| ƒƒ |j | ¡ d S r   )r   r   ÚsetattrÚManagerDescriptorr   Zadd_manager)r   r   r   r   r   r   Úcontribute_to_classp   s    zBaseManager.contribute_to_classc                 C   s   t j| _t  jd7  _dS )zn
        Set the creation counter value for this instance and increment the
        class-level copy.
        r   N)r   Úcreation_counterr   r   r   r   r   x   s    z!BaseManager._set_creation_counterc                 C   s&   t   | ¡}|p| j|_|p| j|_|S r   )Úcopyr   r   )r   ÚusingÚhintsr   r   r   r   Ú
db_manager€   s    
zBaseManager.db_managerc                 C   s   | j ptj| jf| jŽS r   )r   r   Zdb_for_readr   r   r   r   r   r   Údb†   s    zBaseManager.dbc                 C   s   | j | j| j| jd�S )z…
        Return a new QuerySet object. Subclasses can override this method to
        customize the behavior of the Manager.
        )r   rA   rB   )r    r   r   r   r   r   r   r   r*   Ž   s    zBaseManager.get_querysetc                 C   s   |   ¡ S r   )r*   r   r   r   r   Úall•   s    zBaseManager.allc                 C   s   t || jƒo| j|jkS r   )Ú
isinstancer   r	   )r   Úotherr   r   r   Ú__eq__ž   s    
þzBaseManager.__eq__c                 C   s   t | ƒS r   )Úidr   r   r   r   Ú__hash__¤   s    zBaseManager.__hash__)N)NN)r#   r"   Ú__qualname__r?   Zauto_createdZuse_in_migrationsr   r   r   r   r(   r)   Úclassmethodr8   r;   r>   r   rC   ÚpropertyrD   r*   rE   rH   rJ   Ú__classcell__r   r   r   r   r   	   s,   %


	r   c                   @   s   e Zd ZdS )ÚManagerN)r#   r"   rK   r   r   r   r   rO   ¨   s   rO   c                   @   s   e Zd Zdd„ Zddd„ZdS )r=   c                 C   s
   || _ d S r   )Úmanager)r   rP   r   r   r   r   ®   s    zManagerDescriptor.__init__Nc                 C   sf   |d k	rt d|j ƒ‚|jjr0t d|jjf ƒ‚|jjrVt d|jj|jj|jjf ƒ‚|jj| jj	 S )Nz)Manager isn't accessible via %s instancesz'Manager isn't available; %s is abstractz:Manager isn't available; '%s.%s' has been swapped for '%s')
ÚAttributeErrorr#   r   ZabstractZobject_nameZswappedZ	app_labelZmanagers_maprP   r   )r   Úinstancer
   r   r   r   Ú__get__±   s    ÿýÿzManagerDescriptor.__get__)N)r#   r"   rK   r   rS   r   r   r   r   r=   ¬   s   r=   c                       s(   e Zd Z‡ fdd„Z‡ fdd„Z‡  ZS )ÚEmptyManagerc                    s   t ƒ  ¡  || _d S r   )r   r   r   )r   r   r   r   r   r   Ç   s    
zEmptyManager.__init__c                    s   t ƒ  ¡  ¡ S r   )r   r*   Únoner   r   r   r   r*   Ë   s    zEmptyManager.get_queryset)r#   r"   rK   r   r*   rN   r   r   r   r   rT   Æ   s   rT   )r@   r3   Ú	importlibr   Z	django.dbr   Zdjango.db.models.queryr   r   r;   rO   r=   rT   r   r   r   r   Ú<module>   s     