How to use the yarl.URL function in yarl

To help you get started, we’ve selected a few yarl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aio-libs / yarl / tests / test_url.py View on Github external
def test_compressed_ipv6():
    url = URL("http://[1DEC:0:0:0::1]")
    assert url.raw_host == "1dec::1"
    assert url.host == url.raw_host
github aio-libs / yarl / tests / test_url_update_netloc.py View on Github external
def test_from_str_with_host_ipv6():
    url = URL("http://host:80")
    url = url.with_host("::1")
    assert url.raw_host == "::1"
github aio-libs / aiohttp / tests / test_http_parser.py View on Github external
def test_http_request_parser_non_utf8(parser) -> None:
    text = 'GET /path HTTP/1.1\r\nx-test:тест\r\n\r\n'.encode('cp1251')
    msg = parser.feed_data(text)[0][0][0]

    assert msg.method == 'GET'
    assert msg.path == '/path'
    assert msg.version == (1, 1)
    assert msg.headers == CIMultiDict([('X-TEST', 'тест'.encode('cp1251')
                                        .decode('utf8', 'surrogateescape'))])
    assert msg.raw_headers == ((b'x-test', 'тест'.encode('cp1251')),)
    assert not msg.should_close
    assert msg.compression is None
    assert not msg.upgrade
    assert not msg.chunked
    assert msg.url == URL('/path')
github aio-libs / yarl / tests / test_url_parsing.py View on Github external
def test_no_host(self):
        with pytest.raises(ValueError):
            URL("//:80")
github aio-libs / yarl / tests / test_url.py View on Github external
def test_with_name_double_dot():
    with pytest.raises(ValueError):
        URL("http://example.com").with_name("..")
github fabaff / python-mystrom / pymystrom / switch.py View on Github external
async def get_state(self) -> None:
        """Get the details from the switch/plug."""
        url = URL(self.uri).join(URL("report"))
        response = await request(self, uri=url)
        self._consumption = response["power"]
        self._state = response["relay"]
        try:
            self._temperature = response["temperature"]
        except KeyError:
            self._temperature = None

        url = URL(self.uri).join(URL("info.json"))
        response = await request(self, uri=url)
        self._firmware = response["version"]
        self._mac = response["mac"]
github pengutronix / aiohttp-json-rpc / aiohttp_json_rpc / client.py View on Github external
def __init__(self, logger=default_logger, url=None, cookies=None,
                 loop=None):

        self._pending = {}
        self._msg_id = 0
        self._logger = logger
        self._handler = {}
        self._methods = {}
        self._autoconnect_url = URL(url) if url is not None else url
        self._autoconnect_cookies = cookies
        self._loop = loop or asyncio.get_event_loop()

        self._id = JsonRpcClient._client_id
        JsonRpcClient._client_id += 1
github rtfol / aiohttp-sse-client / aiohttp_sse_client / client.py View on Github external
**kwargs):
        """Construct EventSource instance.

        :param url: specifies the URL to which to connect
        :param option: specifies the settings, if any,
            in the form of an Dict[str, Any]. Current only one key supported
            - with_credentials: bool, specifies CORS mode to `Use Credentials`
        :param reconnection_time: wait time before try to reconnect in case
            connection broken
        :param session: specifies a aiohttp.ClientSession, if not, create
            a default ClientSession
        :param on_open: event handler for open event
        :param on_message: event handler for message event
        :param on_error: event handler for error event
        """
        self._url = URL(url)
        if option is not None:
            self._with_credentials = option.get('with_credentials', False)
        else:
            self._with_credentials = False
        self._ready_state = READY_STATE_CONNECTING

        if session is not None:
            self._session = session
            self._need_close_session = False
        else:
            self._session = ClientSession()
            self._need_close_session = True

        self._on_open = on_open
        self._on_message = on_message
        self._on_error = on_error
github mushorg / snare / snare / cloner.py View on Github external
def add_scheme(url):
        if url[-1] == '/':
            url = url.strip('/')
        if yarl.URL(url).scheme:
            new_url = yarl.URL(url)
            err_url = yarl.URL(url + '/status_404')
        else:
            new_url = yarl.URL('http://' + url)
            err_url = yarl.URL('http://' + url + '/status_404')
        return new_url, err_url
github clamor-py / anysocks / anysocks / client.py View on Github external
def _url_to_host(url, ssl_context):
    url = URL(url)
    if url.scheme not in ('ws', 'wss'):
        raise ValueError('WebSocket URL scheme must be "ws:" or "wss:"')

    if ssl_context is None:
        ssl_context = url.scheme == 'wss'
    elif url.scheme == 'ws':
        raise ValueError('SSL context must be None for "ws:" URL scheme')

    return url.host, url.port, url.path_qs, ssl_context