def test_proxies_from_env_http_with_auth(mocker): url = URL('http://*****:*****@aiohttp.io/path') mocker.patch.dict(os.environ, {'http_proxy': str(url)}) ret = helpers.proxies_from_env() assert ret.keys() == {'http'} assert ret['http'].proxy == url.with_user(None) proxy_auth = ret['http'].proxy_auth assert proxy_auth.login == 'user' assert proxy_auth.password == 'pass' assert proxy_auth.encoding == 'latin1'
def test_with_user_None_when_password_present(): url = URL("http://*****:*****@example.com") assert str(url.with_user(None)) == "http://example.com"
def test_with_user_None(): url = URL("http://[email protected]") assert str(url.with_user(None)) == "http://example.com"
def test_with_user_non_ascii(): url = URL("http://example.com") url2 = url.with_user("вася") assert url2.raw_user == "%D0%B2%D0%B0%D1%81%D1%8F" assert url2.user == "вася"
def strip_auth_from_url(url: URL) -> Tuple[URL, Optional[BasicAuth]]: auth = BasicAuth.from_url(url) if auth is None: return url, None else: return url.with_user(None), auth
def test_with_user_non_ascii(): url = URL('http://example.com') url2 = url.with_user('вася') assert url2.raw_user == '%D0%B2%D0%B0%D1%81%D1%8F' assert url2.user == 'вася'
def test_with_user(): url = URL('http://example.com') assert str(url.with_user('john')) == 'http://[email protected]'
def test_with_user_invalid_type(): url = URL("http://example.com:123") with pytest.raises(TypeError): url.with_user(123)
def test_with_user(): url = URL("http://example.com") assert str(url.with_user("john")) == "http://[email protected]"
async def _async_fetch_image(self, url: str) -> tuple[bytes | None, str | None]: """Retrieve an image.""" content, content_type = (None, None) websession = async_get_clientsession(self.hass) with suppress(asyncio.TimeoutError), async_timeout.timeout(10): response = await websession.get(url) if response.status == HTTPStatus.OK: content = await response.read() if content_type := response.headers.get(CONTENT_TYPE): content_type = content_type.split(";")[0] if content is None: url_parts = URL(url) if url_parts.user is not None: url_parts = url_parts.with_user("xxxx") if url_parts.password is not None: url_parts = url_parts.with_password("xxxxxxxx") url = str(url_parts) _LOGGER.warning("Error retrieving proxied image from %s", url) return content, content_type def get_browse_image_url( self, media_content_type: str, media_content_id: str, media_image_id: str | None = None, ) -> str: """Generate an url for a media browser image.""" url_path = (f"/api/media_player_proxy/{self.entity_id}/browse_media"
def test_with_user_ipv6(): url = URL("http://*****:*****@[::1]:8080/") assert str(url.with_user(None)) == "http://[::1]:8080/"