B
    EDb                 @   sZ   d dl Z d dlZd dlT d dlmZ d dlmZ d dlmZ dddZ	G d	d
 d
e
ZdS )    N)*)	LadonType)
attachment)PORTABLE_STRING_TYPESTc             C   sb   t tdtfi }t | }g }x>|D ]6}||s$|rFtt| |s$|dkrPq$||g7 }q$W |S )NZdummy__qualname__)dirtypeobjectcountinspectZismethodgetattr)clsZexclude_methodsZ
base_attrsZthis_cls_attrsresattr r   7G:\easytimepro\master/mysite/ladon\types\typemanager.pyget_userdef_class_attributes   s    
&r   c               @   s4   e Zd ZdZi Zdd Zdd Zdd Zdd	 Zd
S )TypeManageraR  
	This class is used by LadonServiceInfo to collect all types that a given
	service depends on. It also keeps track of the parse order so it is possible
	to create service type descriptors in the right order. This will prevent that
	an array of some type is not defined before the type itself.
	
		type_dict: holds all the parsed class-types that are derived from mysite.ladonType
		type_order: holds all parsed types in the correct parse order
		primitive_list: A list of all the primitive types a service depends on
	
	Primitive types are defined as all classes that don't inherit LadonType
	c             C   s(   i | _ g | _g | _d| _d| _d| _d S )NFr   )	type_dict
type_orderprimitive_list	has_listsZ	has_dictstype_parse_order)selfr   r   r   __init__%   s    zTypeManager.__init__c             C   s    | j |s|  j |g7  _ d S )N)r   r
   )r   Zprimr   r   r   add_primitive_type.   s    zTypeManager.add_primitive_typec          
   C   s  yt |t W n2 tk
rF } ztdt| W d d }~X Y nX |}|| jkrn|j|j	g d| j|< n
| j| S | j| }t
|}x|D ]}t||}d}i }	t|tkrt|dkr|d }d}d| _nt|tkry|d }
W n( tk
r   td|j	|f Y nX g }d	|krrt|d	 tkrNtd
|j	|f |d	 |	d	< |	d	 rr|td g7 }d|kr|d }t|tkr|g|	d< nFt|tkrg |	d< x.|D ]&}t|tkr|	d  |g7  < qW d|kr,||
g7 }t|d |krtd|j	|f |d |	d< d}d|kr|d }x`dD ]X}||krDt|| drDt|| rDd|	kri |	d< t|d | |	d |< qDW |
}n t|tkrtd|j	|f t |tr| | n| | |tkrd| _|r,| j|gs&|  j|gg7  _|g}||	d< |d  |||	fg7  < qW || jkrlt|| j|< | j|d< |  j|g7  _|  jd7  _|S )Nz"class not LadonType inherited - %s)modulename
attributesF   r   Tr   zKDictionary type definitions must contain the "type" key.
class: %s
attr: %sZnullablezODictionary type definition nullable must be a boolean value.
class: %s
attr: %sdocdefaultzCDefault value does not match the attribute type.
class: %s
attr: %sfilters)Zincoming_rawZincomingZoutgoingZoutgoing_raw__iter__zRclass attributes on LadonTypes must be defined as types, lists.
class: %s
attr: %sr   Zparse_order)r   getmror
   r   	ExceptionNeedToDefineParseTimeExceptionstrr   
__module____name__r   r   r   listlenr   dictAttributeErrorboolr   hasattranalyze_classr   r   temp_require_multipartr   global_type_dictcopyZdeepcopyr   )r   r   eZtype_keyZtype_containerZclass_attrsr   Zattr_valZ
array_attrZ
attr_propsZtemp_attr_valZok_default_typesZtemp_docZdoc_lineZhas_defaultr"   Zfilter_typer   r   r   r0   2   s    "












(



zTypeManager.analyze_classc             C   s  d| _ ttgt|rt|dkr,tdt|d tkrDtdt|d t	rh| 
|d  n | |d  |d tkrd| _ d| _| j|d gs|  j|d gg7  _nJt|tkrt|t	r| 
| n| | |tkrd| _ ntd| j S )NFr   z6Only one element is allowed when defining ladon arraysr   z=Only types are allowed as list-element when defining an arrayTz:Ladonized param definition must be a LadonType or iterable)r1   r*   tupler
   r   r+   r&   r   r$   r   r0   r   r   r   r   )r   Zparamr   r   r   analyze_param   s,    
zTypeManager.analyze_paramN)	r)   r(   r   __doc__r2   r   r   r0   r6   r   r   r   r   r      s   	Wr   )T)r   r3   Zmysite.ladon.exceptions.typesZmysite.ladon.types.ladontyper   Zmysite.ladon.types.attachmentr   Zmysite.ladon.compatr   r   r	   r   r   r   r   r   <module>   s   
