
    [7#                         d dl Z d dlmZ d dlmZmZ d dlZd dlmZmZ  ej	        d          Z
d Zd Z G d d	          ZddZdS )    N)zip)VmomiSupporttypes)GetWsdlNameType	ObjDifferc                 B    | rt                               |           dS dS )z%Log a message if the condition is metN)__Log__debug)	conditionmessages     0/usr/lib/python3/dist-packages/pyVmomi/Differ.pyLogIfr      s,     mmG     c                 j   t          | t          j                  pt          | t          j                  pt          | t          j                  pt          | t
          j                  pt          | t          j                  pt          | t          j                  pt          | t
          j	                  p|t          | t          j
                  pbt          | t          j                  pHt          | t          j                  p.t          | t          j                  pt          | t                    S )z-See if the passed in type is a Primitive Type)
isinstancer   boolbyteshortsixinteger_typesdoublefloatstring_typesPropertyPathManagedMethoddatetimeURItype)objs    r   IsPrimitiveTyper!      s    c5:&& :*S%**E*E :ek"":&0c6G&H&H:el##:'1#u{'C'C: c&'': e())	:
 e)**: en%%: ei  : %/sD$9$9;r   c                   B    e Zd ZdZddZddZd Zd Zd Zdd	Z	d
 Z
dS )DifferzClass for comparing two ObjectsFTc                 "    || _         || _        d S )N)_looseMatch_ignoreArrayOrder)self
looseMatchignoreArrayOrders      r   __init__zDiffer.__init__-   s    #d/dr   c           
         ||k    rdS |r|s!t                               d           | j        S |}|}t          |t                    r|d         }t          |t                    r|d         }t          |          rYt          |          rJ|j        j        |j        j        k    r0||k    rdS |dk    s|dk    rt                               d           dS t          |          }t          |          }||k    r`t                               dt          t          |j                            dt          t          |j                                       dS t          |t                    r|                     |||          S t          |t          j                  r| r| p|o|o|j        |j        k    S t          |t          j                  r|rg|                                |                                k    }t#          | d	|                                d|                                           |S |                     ||          S t'          d
t          t          |j                            z             )zDiff any two ObjectsTz,DiffAnyObjects: One of the objects is unset.r   Nz*DiffAnyObjects: One of the objects in NoneFz#DiffAnyObjects: Types do not match  != z"DiffAnyObjects: Keys do not match Unknown type: )r
   r   r%   r   listr!   	__class____name__r   reprr   DiffArrayObjectsr   ManagedObject_moId
DataObjectGetKeyr   DiffDataObjects	TypeError)	r'   oldObjnewObj	isObjLinkoldObjInstancenewObjInstanceoldTypenewTypebMatchs	            r   DiffAnyObjectszDiffer.DiffAnyObjects1   s   	6		 !6 !	E	F	F	F 	 nn	FD	!	! $ )	FD	!	! $ ) &
!
! of&=&= &&*:*CCCf4nn$MMFGGG^$$g^$$g	G			+n6778888+n677888: 
; 
; 
; fd## O%%ffi@@	@ne&9:: O*F
 . 1-6 1-,
.ne&677 	O 
]]__7Ff**--////6==???4 5 5 5M$$VV44	4 )${6;K/L/L*M*MMNN	Nr   c                 6   t          |          t          |          k    r;t                              dt          |          t          |          fz             dS t          ||          D ]\  }}|rr|                                |                                k    rGt                              d|                                d|                                            dS y|                     ||          st                              d            dS dS )zDiff two DataObject arrays1DiffDoArrays: Array lengths do not match %d != %dFz DiffDoArrays: Keys do not match r,   z.DiffDoArrays: one of the elements do not matchT)lenr
   r   r   r6   r7   r'   r9   r:   isElementLinksijs         r   DiffDoArrayszDiffer.DiffDoArrays^   s   	VF	#	#	J6{{CKK() 
* 
* 
*ff%% 
 
$!Q 	
xxzzQXXZZ''}}}XXZZZZ- . . .ee (
 ''1-- }}BD D Dee Tr   c                 P   t          |          t          |          k    r;t                              dt          |          t          |          fz             dS t          ||          D ]9\  }}|                     |||          st                              d            dS :dS )z)Diff two arrays which contain Any objectsz3DiffAnyArrays: Array lengths do not match. %d != %dFz0DiffAnyArrays: One of the elements do not match.T)rD   r
   r   r   rA   rE   s         r   DiffAnyArrayszDiffer.DiffAnyArraysq   s    	VF	#	#	L6{{CKK() 
* 
* 
*ff%%  $!Q##Aq.99 
MMLMMM55
 Tr   c                    t          |          t          |          k    r;t                              dt          |          t          |          fz             dS d}| j        rE|rt	          |          pt	                      }|rt	          |          pt	                      }||k    }n t          ||          D ]\  }}||k    rd} n|st                              d           dS dS )zDiff two primitive arraysrC   FTz6DiffPrimitiveArrays: One of the elements do not match.)rD   r
   r   r&   	frozensetr   )r'   r9   r:   matcholdSetnewSetrG   rH   s           r   DiffPrimitiveArrayszDiffer.DiffPrimitiveArrays}   s   	VF	#	#	J6{{CKK() 
* 
* 
*e		 .Yv..=)++.Yv..=)++F"(( 
 
TQAvvuu   	D
F 
F 
FTr   c                     ||k    rdS |r|sdS t          |          t          |          k    r;t                              dt          |          t          |          fz             dS |d         }t          |          r|                     ||          S t          |t          j                  r|                     |||          S t          |t          j	                  r| 
                    |||          S t          d|j        z            )z>Method which deligates the diffing of arrays based on the typeTFz5DiffArrayObjects: Array lengths do not match %d != %dr   zUnknown type: %s)rD   r
   r   r!   rQ   r   r   r3   rK   r5   rI   r8   r/   )r'   r9   r:   rF   firstObjs        r   r2   zDiffer.DiffArrayObjects   s   	6		 6 	VF	#	#	N6{{CKK() 
* 
* 
*h		"	" @((88	8h 344 @""66>BB	Bh 011 @!!&&.AA	A+f.>>??	?r   c           	         ||k    rdS |r|st                               d           dS t          |          }t          |          }||k    r,t                               d|j        d|j                   dS |                                D ];}t          ||j                  }t          ||j                  }|                    |j                  j        }|s|sQ|j	        t          j        z  r| j        r|r|sq|r|s%t                               d|j        z              dS d}	t          |          r||k    }	nat          |t          j                  r+|                     |||j	        t          j        z            }	nt          |t          j                  r|j	        t          j        z  rf|                                |                                k    }	t+          |	 d|                                d|                                           n|                     |||j	        t          j        z            }	n^t          |t,                    r*|                     |||j	        t          j        z            }	nt1          dt3          |          z             |	s%t                               d	|j        z              dS =dS )
zDiff Data ObjectsTz+DiffDataObjects: One of the objects in NoneFz5DiffDataObjects: Types do not match for dataobjects. r,   z9DiffDataObjects: One of the objects has property %s unsetz"DiffDataObjects: Key match failed r-   z.DiffDataObjects: Objects differ in property %s)r
   r   r   	_wsdlName_GetPropertyListgetattrname_GetPropertyInfor   flagsr   
F_OPTIONALr%   r!   r   r   r3   rA   F_LINKr5   r6   r   r.   r2   r8   r1   )
r'   r9   r:   r>   r?   propoldPropnewProppropTyper@   s
             r   r7   zDiffer.DiffDataObjects   s   	6		 6 	D	E	E	EVgVg	G			!1!13
4 
4 
4 ))++ & &$649--649--++DI66; 	
 	

\44 

)0
8?
 
 
MMJ   55G$$ 
='FF%"566 
=(('4:$<% & &FF%"233 
=zL// )6==??:vZZ]]____fmmooo"7 8 8 8 8 ++GWdj '?( ) )vv$'' 
=**7GTZ$>% & &FF ,T(^^;<<< 
MMJ   55
 Tr   NFT)F)r0   
__module____qualname____doc__r*   rA   rI   rK   rQ   r2   r7    r   r   r#   r#   +   s        ((0 0 0 0+O +O +O +OZ  &
 
 
  .@ @ @ @*5 5 5 5 5r   r#   FTc                 P    t          ||          }|                    | |          S )zODiff any two objects. Objects can either be primitive type
      or DataObjects)r(   r)   )r#   rA   )obj1obj2r(   r)   differs        r   DiffAnysrj      s-     
?OPPP6


d
+
++r   ra   )r   	six.movesr   pyVmomir   r   loggingr   r   	getLoggerr
   r   r!   r#   rj   re   r   r   <module>ro      s   " 


       ' ' ' ' ' ' ' '  * * * * * * * *
'
K
(
(  
	; 	; 	;s s s s s s s sl, , , , , ,r   