+
    hk  c                   s\    ^ RI t ^ RIt^RIHt ^RIHt R t ! R R4      t ! R R4      t	R# )	    N)log)xmlutilc                 sd   T p\         P                  ! R RV 4      p \         P                  ! RRV 4      p \         P                  ! RRV 4      p \         P                  ! RRV 4      p \         P                  ! RR	V 4      p \        P                  ! W4      pV'       d   \        P
                  ! R
V4       V # )z	arch=".*"zarch="i686"zdomain type=".*"zdomain type="test"zmachine type=".*" z>exe<z>hvm<z>linux<z>xen<z!virtinst test sanitizing diff
:%s)resubr   diffr   Zdebug)xmlZorigr   s   &  '/usr/share/virt-manager/virtinst/uri.pysanitize_xml_for_test_definer	      s    D
&&mS
1C
&&#%93
?C
&&$b#
.C
&&'3
'C
&&GS
)C<<"D		6=J    c                   s0   a  ] tR t^t o RtR tR tRtV tR# )URIz2
Parse an arbitrary URI into its individual parts
c                s   Wn         V P                  V4      pV^ ,          V n        \        \        P
                  P                  VR,          4      w  V n        V n        V n	        V n
        V n        RV n        RV P                  9   d*   V P                  P                  R^4      w  V n        V n        RV n        RV n        V P                  P!                  R4      '       d   RV P                  9   dz   RV P                  9   d*   V P                  P                  R^4      w  V n        V n        RP#                  V P                  R,          P%                  R^4      4      V n        R	V n        M:RV P                  9   d*   V P                  P%                  R^4      w  V n        V n        \'        \(        P*                  ! R
V P                  4      4      V n        R# )r    :   NNr   Z+FZ[Z]z]::Tz	^[0-9.]+$N)uri_splitschemeZmapurllibZparseZunquoteusernamehostnamepathqueryfragment	transportZrsplitportis_ipv6
startswithZjoinsplitZboolr   Zmatchhost_is_ipv4_string)selfr   Z	split_uris   && r   __init__ZURI.__init__"   sT   KK$	lORLL  )B-P
Lty$*dm $++*.++*<*<S!*D'DK	==##C((SDMM-At}}$+/==+?+?Q+G(tyGGDMM"$5$;$;C$CDDMDLDMM!'+}}':':3'B$DM49#'dmm(L#M r
   c                s   R
R lpR;p;p;p;rgVP                  R4      pV^ 8  d   VRV P                  4       W^,           R rVR,          R8X  d4   V! V^4      w  rQVP                  R4      p	V	^ 8  d   V^ V	 pWY^,           R pRV9   d   VP                  R^4      w  rR	V9   d   VP                  R	^4      w  rW4WQWg3# )r    c                 sn    R  F  pV P                  W!4      pV^ 8  g   K   M	  \        V 4      pWV WR 3# )z/?#N)findlen)ZurlZstartZcZdelims   &&  r   splitnetlocZURI._split.<locals>.splitnetloc@   sC    *A: 
 CU#S[00r
   r   r   N:Ni   Nz//Z@Z#Z?r    )r   Zlowerr   )
r   r   r!   r   r   Znetlocr   r   ZiZoffsets
   &&        r   r   Z
URI._split?   s    	1 9;:::F:UHHSMq5bq'--/31uw<C2w$)#q1S)A:%a/H#QJL1Fcz #		#q 1cz YYsA.
e==r
   )r   r   r   r   r   r   r   r   r   r   r   N)	__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes____classdictcell__Z__classdict__   @r   r   r      s     N:> >r
   r   c                   sJ   a  ] tR t^Zt o RtRt]R 4       tR tR t	R t
RtV tR# )	MagicURIa  
Handle magic virtinst URIs we use for the test suite and UI testing.
This allows a special URI to override various features like capabilities
XML, reported connection and libvirt versions, that enable testing
different code paths.

A magic URI has 3 parts:

    1) Magic prefix __virtinst_test__
    2) Actual openable URI, usually a test:/// URI
    3) Comma separated options

The available options are:

    * 'predictable': Generate predictable UUIDs, MAC addresses, and
        temporary file names.
    * 'fakeuri': The URI to advertise as the actual connection URI
    * 'connver=%d': Override the connection (hv) version
    * 'libver=%d': Override the libvirt version
    * 'caps=%s': Points to a file with capabilities XML, that will
                 be returned in conn.getCapabilities. Ex.
                 files in test/capabilities-xml/
    * 'domcaps=%s': Points to a file with domain capabilities XML, that
                    will be returned in conn.getDomainCapabilities

See tests/utils.py for example URLs
Z__virtinst_test__c                s@    V P                  \        P                  4      # N)r   r,   VIRTINST_URI_MAGIC_PREFIX)r      &r   uri_is_magicZMagicURI.uri_is_magicy   s    ~~h@@AAr
   c                s*  a ^RI Hp VP                  V P                  R4      pVP	                  R^4      pV^ ,          V n        \        T! \        V4      ^8  ;'       d    V^,          ;'       g    R4      4      oV3R lpV! R4      V n        SP                  RR4      V n
        SP                  RR4      V n        SP                  R	R4      V n        SP                  R
R4      V n        V P                  '       d   \        V P                  4      V n        MV P                  '       d   RV n        SP                  RR4      V n        V P                  '       d   \        V P                  4      V n        RV n        S'       d   RS,          V n        R# R# )r   )parse_optstr_tuplesr   Z,c                 s6   < V S9   pSP                  V R 4       V# r-   )pop)Zfieldretoptss   & r   pop_boolZ#MagicURI.__init__.<locals>.pop_bool   s    4-CHHUD!Jr
   predictablefakeuriNZcapsZdomcapsZconnverl    d(	 ZlibverzMagicURI has unhandled opts=%s)Zclir1   Zreplacer.   r   open_uriZdictr    r6   r2   r7   capsfiledomcapsfileconn_versionZintlibvirt_version_err)r   r   r1   r3   r5   r4   s   &&   @r   r   ZMagicURI.__init__}   s@    	-kk$88"=iiQA'C1(?(?Q(E(E2FG	
 $M2xx	40.88It4 HHY5 #D$5$5 6D\\\ +D#xx$7#&t';';#<D 	84?DI r
   c                sT    V P                   '       d   \        V P                   4      hR # r-   )r=   ZRuntimeError)r   r/   r   validateZMagicURI.validate   s    999tyy)) r
   c                s  aaaaa	 V P                   '       d/   \        V P                   4      P                  4       oV3R lVn        R oRoV P                  '       d$   \        V P                  4      P                  4       oRVV3R llpW!n        V P                  '       d3   VP                  oVP                  o	V3R lpV	3R lpW1n        WAn        R# R# )z
After the connection is open, we need to stub out various functions
depending on what magic bits the user specified in the URI
c                  s   < S # r-    )capsxmls   r   Z<lambda>Z3MagicURI.overwrite_conn_functions.<locals>.<lambda>   s    7r
   c                 s`    ^ RI pVP                  RV RRR.pVP                  V 4      pW#n        Vh)r    N)libvirtZVIR_ERR_NO_SUPPORTZlibvirtErrorerr)ZmsgrA   rB   Zexcs   &   r   _raise_nosupport_errorZAMagicURI.overwrite_conn_functions.<locals>._raise_nosupport_error   s7    --tS$dKC&&s+CGIr
   Nc                 s   < T pTpTpTpS'       d,   SpV'       d    \         P                  ! R RV,          V4      pV# S! R4       R# )zarch>.+</archzarch>%s</archz+virtinst test driver fake domcaps nosupportN)r   r   )	ZemulatorZarchZmachineZvirttypeflagsZignorer3   rC   
domcapsxmls	   &&&&&  r   fake_domcapsZ7MagicURI.overwrite_conn_functions.<locals>.fake_domcaps   sI    FFFF &&/D2H#NC

 ##PQr
   c                 s*   < \        V 4      p S! W4      # r-   r	   )r   rD   
origcreates   &&r   	newcreateZ4MagicURI.overwrite_conn_functions.<locals>.newcreate   s    237!#--r
   c                 s*   < \        V 4      p S! V 4      # r-   rG   )r   
origdefines   &r   	newdefineZ4MagicURI.overwrite_conn_functions.<locals>.newdefine   s    237!#&r
   r"   )	r9   ZopenZreadZgetCapabilitiesr:   ZgetDomainCapabilitiesr7   Z	createXMLZ	defineXML)
r   ZconnrF   rI   rK   rC   r@   rE   rH   rJ   s
   &&   @@@@@r   overwrite_conn_functionsZ!MagicURI.overwrite_conn_functions   s     ===4==)..0G#2D 	 
d../446J	R 	R" &2"<<<JJ.' 'N&N r
   )r=   r9   r;   r:   r7   r<   r8   r6   N)r#   r$   r%   r&   r'   r.   Zstaticmethodr0   r   r>   rL   r(   r)   r*   r+   r   r,   r,   Z   s<     8 !4B B @L*9' 9'r
   r,   )
r   Zurllib.parser   Zloggerr   r   r   r	   r   r,   r?   r
   r   <module>rM      s/    
   :> :>zF' F'r
   