o
    iz                     @   sx   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 G dd deZG d	d
 d
eZG dd deZdS )z^Metaclass utilities for
:attr:`spyne.model.complex.ComplexModelBase.Attributes.declare_order`
    N)wraps)chain)warn)odictc                   @      e Zd ZdZdS )ClassNotFoundExceptionz9Raise when class declaration is not found in frame stack.N__name__
__module____qualname____doc__ r   r   O/var/www/html/LicenciasMIG/venv/lib/python3.10/site-packages/spyne/util/meta.pyr   "       r   c                   @   r   )AttributeNotFoundExceptionz7Raise when attribute is not found in class declaration.Nr   r   r   r   r   r   &   r   r   c                   @   s   e Zd ZdZdd ZdS )Prepareablea%  Implement __prepare__ for Python 2.

    This class is used in Python 2 and Python 3 to support `six.add_metaclass`
    decorator that populates attributes of resulting class from plain unordered
    attributes dict of decorated class.

    Based on https://gist.github.com/DasIch/5562625
    c              	      sr   z|d  W n t y   t| ||| Y S w  fdd}z
t ||d< W n   td Y t| |||S )N__new__c                    s  t || gD ]}t|dr|jjdvr nq| |||S z| j W n ty2   | ||| Y S w t|tr?| |||S t	 }d   d u rst
t|jj}|D ]}t|rc|j|krc|  nqS|jrk|j}ntd d u sI jf fdd	t| fddd}| ||}	|D ]\}
}||	|
< q| |||	}t }|d usJ d	 ||j|jksJ d
||j|j|S )N
Attributes)Nrandomz)Can't find class declaration in any framec                    sJ   z| | W S  ty$   | drY dS d|  j}|d7 }t|w )N_r   z)Can't find {0} in {1} class declaration. zWHINT: use spyne.util.odict.odict for class attributes if you populate them dynamically.)index
ValueError
startswithformatco_namer   )attribute_name_namesmsg)class_declarationr   r   	get_index_   s   
zEPrepareable.__new__.<locals>.preparing_constructor.<locals>.get_indexc                    s    | d S )Nr   r   )item)r   r   r   <lambda>r   s    zDPrepareable.__new__.<locals>.preparing_constructor.<locals>.<lambda>)keyz7Module is not found for class_declaration {0}, name {1}z1Found wrong class declaration of {0}: {1} != {2}.)r   hasattrr   declare_order__prepare__AttributeError
isinstancer   sys	_getframelistreversedf_code	co_constsinspectiscoder   f_backr   co_namessorteditems	getmoduler   r	   r
   )clsnamebases
attributesccurrent_frameliteralsliteralby_appearance	namespacer"   valuenew_clsfound_moduleconstructor)r   r   r   preparing_constructor:   s^   





z2Prepareable.__new__.<locals>.preparing_constructorzKWrapping class initializer failed. This is normal when running under Nuitka)KeyErrortyper   r   r   )r5   r6   r7   r8   rD   r   rB   r   r   4   s   K
zPrepareable.__new__N)r	   r
   r   r   r   r   r   r   r   r   *   s    	r   )r   r(   r.   	functoolsr   	itertoolsr   warningsr   spyne.util.odictr   	Exceptionr   r   rF   r   r   r   r   r   <module>   s   