B
    EDbe(                 @   sz   d dl T d dlmZ d dlZd dlZd dlZd dlmZmZ d dl	m
Z
mZ edejaG dd deZd d	lmZ dS )
    )*)get_type_infoN)
attachmentextract_attachment_reference)PORTABLE_BYTESPORTABLE_STRINGz
^cid:(.+)$c               @   s$   e Zd ZdZdddZdddZdS )		LadonTypea  LadonType must be specialized by all complex service types. It tells the Ladon
	framework that it should expect multiple primitives and/or lists to be defined as
	class attributes. Using LadonType it is possible to build nested types.

	LadonType specializations must define it's attributes as types (either primitive
	types, other LadonType specialization types, lists of primitive or lists of 
	LadonType specialization). This explains the Ladon framework what to expect. There
	are 5 primitive types:
		
		+------------+------------+
		| Python 2   | Python 3   |
		+============+============+
		| str        | bytes      |
		+------------+------------+
		| unicode    | str        |
		+------------+------------+
		| bool       | bool       |
		+------------+------------+
		| float      | float      |
		+------------+------------+
		| int        | int        |
		+------------+------------+
		| attachment | attachment |
		+------------+------------+
	Nc             C   s@  t |tkrt| j}x |d D ]\}}}t |tkrg }||kr|| d krbg ||< n2t || tkrt| |d|tt || f |t|d }	y|	rx|| D ]}
||d |
||dg7 }qW n|d tkrDx|| D ]T}
y|t|
||j	g7 }W q t
k
r< } zt| |t||W d d }~X Y qX qW n*x(|| D ]}
|||
|d g7 }qNW W nN t
k
r } z.t| |d|t|d t|
t|f |W d d }~X Y nX n8|d}d }d }|r|dr|d}|r|dr|d}||krt|}	|| }|d krH|d	d
krH|}n||	r^||||d}nf|tkryt|||j	}W n6 t
k
r } zt| |t||W d d }~X Y nX n|||||}n6|d}|d kr|d	d
krt| |d| |t| || q$W n.|r<tj| j }t| |dt |t|f d S )N
attributesz.Expected list type for attribute "%s" got "%s"r   )
prime_dicttcexport_dictzMType mismatch for subitem of attibute "%s", expected "%s" got "%s"
Details:%sfiltersZincoming_rawZincomingnullableTdefaultz1Missing prime_dict attribute is not nullable "%s"z9Dictionary expected for prime_dict got "%s" of value "%s")typedictr   	__class__listZListAttributeMismatchstrr   r   encoding	ExceptionZNonExistingAttachmentZfrom_unicode_stringZSubitemTypeMismatchgetZMandatoryAttributeMissingsetattrTypeManagerglobal_type_dictZLadonTypePrimerMismatch)selfr
   r   r   	type_dict	attr_name	attr_typepropsattr_valZ	type_infoitemer   
prefilterspostfiltersval r&   5G:\easytimepro\master/mysite/ladon\types\ladontype.py__init__&   s    


 





zLadonType.__init__c             C   s6  i }t j| j }x|d D ]\}}}t|tkryt| |}W n   wY nX t|tkstt| dt| |||kr~qg }	|	||< d}
|d t jkrd}
xz|D ]r}|
r|	|||g7 }	q|d tkrt|tkst	| dt| ||	|
|g7 }	q|	|||d g7 }	qW qyt| |}W n0   |ddkrP|d}ntd	Y nX |d
}d}d}|r|dr|d}|r|dr|d}|dkr|ddkr|||< ntd|| jf qt|tr<|d|kr<|d}|dkr2|ddkr2td|| jf |||< q|t jkry|||||< W n< tk
r } zt| d|t|f |W dd}~X Y nX q|tkrt|tkst	| dt| ||
|||< qy|||||||< W q tk
r, } zt| d|t|f |W dd}~X Y qX qW |S )z
		Convert LadonType to dict representation. Argument tc is a TypeConverter
		which holds information about string conversions and whether unsafe conversions
		are allowed or not.
		r	   zExpected list got: %sFr   Tz1Expected list of attachments got item of type: %sr   r   z=Non-optional attribute missing in LadonType while serializingr   NZoutgoingZoutgoing_rawz,Attribute "%s" (class: "%s") is not nullabler   zLAn exception was raised while processing LadonType attribute "%s"
Details:%szExpected attachment got %szBAn exception was raised while processing attribute "%s"
Details:%s)r   r   r   r   r   getattrZListExpected__dict__r   ZAttachmentExpectedZadd_attachmentZto_unicode_stringr   ZNeedToDefineParseTimeException
isinstancer   r   ZAttributeConversionExceptionr   )r   r   Zresponse_attachmentsZres_dictr   r   r   r   r    Z	attr_listZis_ladontype_itemsr%   r   r#   r$   r"   r&   r&   r'   r*      s    











zLadonType.__dict__)NNN)N)__name__
__module____qualname____doc__r(   r*   r&   r&   r&   r'   r      s   
jr   )r   )Zmysite.ladon.exceptions.typesZmysite.ladon.typesr   inspectsysreZmysite.ladon.types.attachmentr   r   Zmysite.ladon.compatr   r   compileIZrx_cidobjectr   Zmysite.ladon.types.typemanagerr   r&   r&   r&   r'   <module>   s    y