def __init__(self, url='http://127.0.0.1:7474/', auth=None, transport=Transport, request_timeout=..., *, loop=None): if loop is None: loop = asyncio.get_event_loop() self.loop = loop url = URL(url) if url.user and url.password: auth = url.user, url.password url = url.with_user(None) # TODO: not sure is it needed url = url.with_password(None) self.transport = transport( url=url, auth=auth, request_timeout=request_timeout, loop=self.loop, )
def _mask_url(url: URL) -> str: if url.password: url = url.with_password('***') for key, val in url.query.items(): if RE_SECRET_WORDS.match(key): url = url.update_query({key: '***'}) return str(url)
def test_with_password_non_ascii(): url = URL("http://[email protected]") url2 = url.with_password("пароль") assert url2.raw_password == "%D0%BF%D0%B0%D1%80%D0%BE%D0%BB%D1%8C" assert url2.password == "пароль" assert url2.raw_authority == "john:%D0%BF%D0%B0%D1%80%D0%BE%D0%BB%D1%[email protected]" assert url2.authority == "john:пароль@example.com:80"
async def async_added_to_hass(self): """Run when entity about to be added to hass.""" uri_no_auth = await self.device.async_get_stream_uri(self.profile) url = URL(uri_no_auth) url = url.with_user(self.device.username) url = url.with_password(self.device.password) self._stream_uri = str(url)
def test_with_password_percent_encoded(): url = URL("http://[email protected]") url2 = url.with_password("%cf%80") assert url2.raw_password == "%25cf%2580" assert url2.password == "%cf%80" assert url2.raw_authority == "john:%25cf%[email protected]" assert url2.authority == "john:%cf%[email protected]:80"
def localcheckout(args, workspaceDir): gitArray = ['git', 'clone', '--depth', '1'] locationUserIndex = utils.indexof('-locationuser', args) locationPasswordIndex = utils.indexof('-locationpassword', args) locationPathIndex = utils.indexof('-locationpath', args) locationBranchIndex = utils.indexof('-locationbranch', args) locationPortIndex = utils.indexof('-locationport', args) locationUrlIndex = utils.indexof('-locationurl', args) port = args[locationPortIndex + 1] if locationPortIndex != None else None user = args[locationUserIndex + 1] if locationUserIndex != None else None password = args[locationPasswordIndex + 1] if locationPasswordIndex != None else None if locationUrlIndex == None: print("Unknown location URL, use -locationurl") exit(1) else: url = URL(args[locationUrlIndex + 1]) if user != None: url = url.with_user(user) else: url = url.with_user("git") if password != None: url = url.with_password(password) if port != None: url = url.with_port(port) if locationPathIndex == None: args.append("-locationpath") path = f"{workspaceDir}/" args.append(path) else: path = args[locationPathIndex + 1] = f"{workspaceDir}/" if locationBranchIndex == None: print("Unknown branch, use -locationbranch") exit(1) else: gitArray.append('--branch') gitArray.append(os.path.basename(args[locationBranchIndex + 1])) gitArray.append(str(url)) gitArray.append(path) cloneResult = subprocess.run(gitArray) if cloneResult.returncode != 0: print(f"Clone failed.") exit(cloneResult.returncode) return args
def test_with_password_ipv6(): url = URL("http://*****:*****@[::1]:8080/") assert str(url.with_password(None)) == "http://john@[::1]:8080/"
def test_with_password(): url = URL("http://[email protected]") assert str(url.with_password("pass")) == "http://*****:*****@example.com"
def test_with_password_and_empty_user(): url = URL("http://example.com") url2 = url.with_password("pass") assert url2.password == "pass" assert url2.user is None assert str(url2) == "http://:[email protected]"
def test_with_password(): url = URL('http://[email protected]') assert str(url.with_password('pass')) == 'http://*****:*****@example.com'
def test_with_password_and_empty_user(): url = URL('http://example.com') with pytest.raises(ValueError): assert str(url.with_password('pass'))
def secure_connect_string(connect_string: str) -> str: connect_url = URL(connect_string) secure_password = None if connect_url.password: secure_password = hide_password(connect_url.password) return str(connect_url.with_password(secure_password))
def test_with_password_and_empty_user(): url = URL("http://example.com") url2 = url.with_password("pass") assert url2.password == "pass" assert url2.user is None assert str(url2) == "http://:[email protected]"
def test_with_password_invalid_type(): url = URL("http://example.com:123") with pytest.raises(TypeError): url.with_password(123)
def test_with_password_None(): url = URL("http://*****:*****@example.com") assert str(url.with_password(None)) == "http://[email protected]"
def test_with_password_non_ascii_with_colon(): url = URL("http://[email protected]") url2 = url.with_password("п:а") assert url2.raw_password == "%D0%BF%3A%D0%B0" assert url2.password == "п:а"
def test_with_password_non_ascii(): url = URL("http://[email protected]") url2 = url.with_password("пароль") assert url2.raw_password == "%D0%BF%D0%B0%D1%80%D0%BE%D0%BB%D1%8C" assert url2.password == "пароль"
def test_with_password_non_ascii(): url = URL('http://[email protected]') url2 = url.with_password('пароль') assert url2.raw_password == '%D0%BF%D0%B0%D1%80%D0%BE%D0%BB%D1%8C' assert url2.password == 'пароль'
def test_with_password_invalid_type(): url = URL('http://example.com:123') with pytest.raises(TypeError): url.with_password(123)
def test_with_password_and_empty_user(): url = URL('http://example.com') url2 = url.with_password('pass') assert url2.password == 'pass' assert url2.user is None assert str(url2) == 'http://:[email protected]'
def test_with_password_non_ascii(): url = URL('http://[email protected]') url2 = url.with_password('пароль') assert url2.raw_password == '%D0%BF%D0%B0%D1%80%D0%BE%D0%BB%D1%8C' assert url2.password == 'пароль'
def test_with_password_None(): url = URL('http://*****:*****@example.com') assert str(url.with_password(None)) == 'http://[email protected]'
def censor_url(url: URL): if url.password is not None: return url.with_password("******") return url
def test_with_password_and_empty_user(): url = URL('http://example.com') with pytest.raises(ValueError): assert str(url.with_password('pass'))
def test_with_password_non_ascii_with_colon(): url = URL("http://[email protected]") url2 = url.with_password("п:а") assert url2.raw_password == "%D0%BF%3A%D0%B0" assert url2.password == "п:а"
if isinstance(payload, BrowseMedia): payload = payload.as_dict() else: _LOGGER.warning("Browse Media should use new BrowseMedia class") connection.send_result(msg["id"], payload) async def async_fetch_image(logger: logging.Logger, hass: HomeAssistant, url: str) -> tuple[bytes | None, str | None]: """Retrieve an image.""" content, content_type = (None, None) websession = async_get_clientsession(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 test_with_password_non_ascii_with_colon(): url = URL('http://[email protected]') url2 = url.with_password('п:а') assert url2.raw_password == '%D0%BF%3A%D0%B0' assert url2.password == 'п:а'