+
     g                         ^ RI t ^ RIt^ RIt^ RIt^ RIHtHtHt ^ RIH	t	 ^ RI
HtHtHtHtHt  ! R R] P                   R7      tR# )    N)AnyDictOptional)	urlencode)confighttpsystemutilversionc                      a  ] tR t^t o ^tRt]]P                  V 3R lR l4       4       t	RV 3R lR llt
R tRV 3R lR lltV 3R	 lR
 ltV 3R lR ltRtV tR# )UAServiceClientNc                    < V ^8  d   QhRS[ /# )   returnstr)format__classdict__s   "=/usr/lib/python3/dist-packages/uaclient/http/serviceclient.py__annotate__UAServiceClient.__annotate__   s      3     c                    R# )z@String in subclasses, the UAConfig attribute containing base urlN selfs   &r   cfg_url_base_attr!UAServiceClient.cfg_url_base_attr   s     	r   c                H   < V ^8  d   QhRS[ S[P                  ,          RR/# )r   cfgr   N)r   r   UAConfig)r   r   s   "r   r   r      s$      HV__5  r   c                Z    V'       g   \         P                  ! 4       V n        R # Wn        R # N)r   r!   r    )r   r    s   &&r   __init__UAServiceClient.__init__   s    (DHHr   c                V    R RP                  \        P                  ! 4       4      RRRR/# )z
user-agentzUA-Client/{}acceptapplication/jsoncontent-type)r   r   get_versionr   s   &r   headersUAServiceClient.headers   s1    .//0C0C0EF(.
 	
r   c                P   < V ^8  d   QhRS[ RS[S[,          RS[P                  /# )r   log_response_bodytimeoutr   )boolr   intr   HTTPResponse)r   r   s   "r   r   r   %   s5     &
 &
  &
 #&
 
		&
r   c           	        VP                  R 4      pV'       g   V P                  4       pVP                  R4      R8X  d>   V'       d6   \        P                  ! V\
        P                  R7      P                  R4      p\        P                  ! \        V P                  V P                  4      V4      pV P                  V4      p	V	'       d   V	# V'       dL   \        VP                  4       4       U
Uu/ uF  w  rVf   K  WbK  	  pp
pVR\!        V4      ,           ,          pVe   TMV P"                  p\$        P&                  ! VVVVVVR7      # u upp
i )/r)   r(   )clszutf-8?)urldatar+   methodr/   r.   )lstripr+   getjsondumpsr
   DatetimeAwareJSONEncoderencode	posixpathjoingetattrr    r   _get_fake_responsessorteditemsr   url_timeoutr   readurl)r   pathr8   r+   r9   query_paramsr.   r/   r7   fake_responsekvfiltered_paramstimeout_to_uses   &&&&&&&&      r   request_urlUAServiceClient.request_url%   s    {{3llnG;;~&*<<::d(E(EFMMD nnWTXXt/E/EFM005   "((:(:(<!=!=!=   3?333C$+$7T=M=M||"/
 	
s   1E>Ec                    < V ^8  d   QhRS[ /# )r   r7   r   )r   r   s   "r   r   r   M   s      3  3  3r   c                   V P                   e   V P                   P                  V. 4      # V P                  P                  P                  R4      pV'       g	   / V n         M\\        P
                  P                  V4      '       g	   / V n         M/\        P                  ! \        P                  ! V4      4      V n         V P                   P                  V. 4      # )a  Return a list of fake response dicts for a given URL.

serviceclient_url_responses in uaclient.conf should be a path
to a json file which contains a dictionary keyed by full URL path.
Each value will be a list of dicts representing each faked response
for the given URL.

    The response dict item will have a code: <HTTP_STATUS_CODE> and
       response: "some string of content".
    The JSON string below fakes the available_resources URL on the
    contract server:
    '{"https://contracts.canonical.com/v1/resources":                [{"code": 200, "response": {"key": "val1", "key2": "val2"}}]}'

:return: List of dicts for each faked response matching the url, or
   and empty list when no matching url found.
serviceclient_url_responses)_response_overlayr;   r    featuresosrH   existsr<   loadsr	   	load_file)r   r7   response_overlay_paths   && r   _get_response_overlay%UAServiceClient._get_response_overlayM   s    $ !!-))--c266 $ 1 1 5 5)!
 %%'D" 566%'D"%)ZZ  !67&D" %%))#r22r   c                J   < V ^8  d   QhRS[ RS[S[P                  ,          /# )r   r7   r   )r   r   r   r2   )r   r   s   "r   r   r   o   s&     
 
s 
x8I8I/J 
r   c           	        V P                  V4      pV'       g   R# \        V4      ^8X  d   V^ ,          pMVP                  ^ 4      p/ p. pVR,          p\        V\        4      '       d   TpM\        V\
        4      '       d   Tp\        P                  ! VR,          VP                  R/ 4      \        P                  ! VR,          RR7      VVR7      # )z7Return response if faked for this URL in uaclient.conf.Nresponsecoder+   T)	sort_keys)r`   r+   body	json_dict	json_list)r[   lenpop
isinstancedictlistr   r2   r;   r<   r=   )r   r7   	responsesr_   rc   rd   resps   &&     r   rC   #UAServiceClient._get_fake_responseso   s    ..s3	y>Q |H !}}Q'H		
#dD!!Id##I  &!LLB/HZ0DA
 	
r   )rT   r    r#   )NNNNTN)__name__
__module____qualname____firstlineno__rF   rT   propertyabcabstractmethodr   r$   r+   rO   r[   rC   __static_attributes____classdictcell__)r   s   @r   r   r      sa     K    
&
 &
P 3  3D
 
r   r   )	metaclass)rr   r<   rV   r@   typingr   r   r   urllib.parser   uaclientr   r   r	   r
   r   ABCMetar   r   r   r   <module>r{      s2    
  	  & & " 8 8
 
r   