
    iEg                     *    d Z ddlZdZdZd Zd Zd Zy)z,Retrieve the proxy configuration from Gnome.    Nz1gsettings list-recursively org.gnome.system.proxyz Cannot parse gsettings value: %rc                     d}d}d}| }d|v r|j                  dd      \  }}d|v r.|j                  dd      \  }}d|v r|j                  dd      \  }}||||fS )zDParse the hostspec to get protocol, hostname, username and password.N://   @:)splitrsplit)hostspecprotocolusernamepasswordhostnames        9/usr/lib/python3/dist-packages/cinnamon/proxygsettings.pyparse_proxy_hostspecr   )   sz    HHHH%^^E15(
h%__S!4((?!)Q!7HhXx11    c                     t        || dz            \  }}}}|dk(  ry|| dz      }| dk(  r|d   r
|d   }|d   }d}||
d	||||fz  }nd
|||fz  }nd||fz  }||d|}|S )zLBuild and return the proxy URL for the given scheme, based on the gsettings.z.host Nz.porthttpzhttp.use-authenticationzhttp.authentication-userzhttp.authentication-passwordz%s:%s@%s:%dz%s@%s:%dz%s:%dr   )r   )scheme	gsettingsr   hostr   pwdport	proxy_urls           r   proxy_url_from_settingsr   9   s    $86GCS9T$U!HdHc rzVg%&DI&?@7867I?%#d4(@@I"htD%99IT{*	!)95	r   c                  V   t        j                  t        j                               j	                  d      } i }t        d      }| j                  d      D ]  }	 |j                  dd      \  }}}|j                  d      r|dd }nN|j                  d	      r|}n:|d
v r|dk(  }n0|j                         rt        |      }nt        t        |z         |}|dz   |z   |d }|||<    |d   }	|	dk(  ri }
|
S |	dk(  ri }
dD ]  }t        ||      }|||
|<    |
S i }
|
S # t        $ r Y w xY w)zParse the proxy settings as returned by the gsettings executable
       and return a dictionary with a proxy URL for each scheme .zutf-8zorg.gnome.system.proxy.
    'r   )[r   )truefalser#   .Nmodenonemanual)r   https)
subprocesscheck_outputGSETTINGS_CMDLINEr   decodelen
ValueError
startswithisdigitintprintCANNOT_PARSE_WARNINGr   )outputr   base_lenlinepathkeyvalueparsed_valuerelative_keyr&   settingsr   scheme_settingss                r   get_proxy_settingsr?   U   sq    $$%6%<%<%>?FFwOFI,-HT" /	#zz#q1D#u C  2;Lj) L''!VOL]]_u:L&./ Ls
S(()4".	,#/$ VDv~ O 
	' 	3F5fiHO*#2 	3 O O;  		s   D	D('D()__doc__r*   r,   r4   r   r   r?    r   r   <module>rB      s,   @ 3  H 9 2 8'r   