Пример #1
0
    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,
        )
Пример #2
0
 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)
Пример #3
0
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"
Пример #4
0
 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)
Пример #5
0
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"
Пример #6
0
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
Пример #7
0
def test_with_password_ipv6():
    url = URL("http://*****:*****@[::1]:8080/")
    assert str(url.with_password(None)) == "http://john@[::1]:8080/"
Пример #8
0
def test_with_password():
    url = URL("http://[email protected]")
    assert str(url.with_password("pass")) == "http://*****:*****@example.com"
Пример #9
0
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]"
Пример #10
0
def test_with_password():
    url = URL('http://[email protected]')
    assert str(url.with_password('pass')) == 'http://*****:*****@example.com'
Пример #11
0
def test_with_password_and_empty_user():
    url = URL('http://example.com')
    with pytest.raises(ValueError):
        assert str(url.with_password('pass'))
Пример #12
0
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))
Пример #13
0
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]"
Пример #14
0
def test_with_password_invalid_type():
    url = URL("http://example.com:123")
    with pytest.raises(TypeError):
        url.with_password(123)
Пример #15
0
def test_with_password_None():
    url = URL("http://*****:*****@example.com")
    assert str(url.with_password(None)) == "http://[email protected]"
Пример #16
0
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 == "п:а"
Пример #17
0
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 == "пароль"
Пример #18
0
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 == 'пароль'
Пример #19
0
def test_with_password_invalid_type():
    url = URL('http://example.com:123')
    with pytest.raises(TypeError):
        url.with_password(123)
Пример #20
0
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]'
Пример #21
0
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 == 'пароль'
Пример #22
0
def test_with_password_None():
    url = URL('http://*****:*****@example.com')
    assert str(url.with_password(None)) == 'http://[email protected]'
Пример #23
0
def censor_url(url: URL):
    if url.password is not None:
        return url.with_password("******")
    return url
Пример #24
0
def test_with_password_and_empty_user():
    url = URL('http://example.com')
    with pytest.raises(ValueError):
        assert str(url.with_password('pass'))
Пример #25
0
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 == "п:а"
Пример #26
0
    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
Пример #27
0
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 == 'п:а'