
    _i                    :    d Z ddlmZ ddlZddlmZmZ 	 dddZdS )zAzure helpers.    )annotationsN)AnyOptional   resourcestr	client_idOptional[str]timeoutfloatreturndict[str, Any]c                ^   ddl m}m} d}|dz  }|d|  z  }|r|d| z  }ddd	} |||
          }	  |||          5 }|j        }	|                                                    d          }
d d d            n# 1 swxY w Y   n'# t          $ r}d|z  }t          |          d d }~ww xY w|	dk    rd}t          |          	 t          j	        |
          }n# t          $ r t          d          d w xY wdD ]/}|
                    |          sd}|||
fz  }t          |          0|S )Nr   )Requesturlopenz5http://169.254.169.254/metadata/identity/oauth2/tokenz?api-version=2018-02-01z
&resource=z&client_id=truezapplication/json)MetadataAccept)headers)r   utf8z'Failed to acquire IMDS access token: %s   z$Failed to acquire IMDS access token.z*Azure IMDS response must be in JSON format)access_token
expires_inz0Azure IMDS response must contain %s, but was %s.)urllib.requestr   r   statusreaddecode	Exception
ValueErrorjsonloadsget)r   r	   r   r   r   urlr   requestresponser   bodyemsgdatakeys                  9D:\Nbitz\venv\Lib\site-packages\pymongo/_azure_helpers.py_get_azure_responser,      s    0///////
AC$$C""""C )(Y(((!-?@@Ggc7+++G(WWg... 	2(_F==??))&11D	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2  ( ( (7!;oo4'( }}4ooQz$ Q Q QEFFDPQ . " "xx}} 	"DCd#CS//!	"
 KsG   B	 /A=1B	 =BB	 BB	 	
B-B((B-C C8)Nr   )r   r   r	   r
   r   r   r   r   )__doc__
__future__r   r    typingr   r   r,        r+   <module>r2      sj      " " " " " "                  FG# # # # # # #r1   