當前位置: 首頁>>代碼示例>>Python>>正文


Python yarl.URL屬性代碼示例

本文整理匯總了Python中yarl.URL屬性的典型用法代碼示例。如果您正苦於以下問題:Python yarl.URL屬性的具體用法?Python yarl.URL怎麽用?Python yarl.URL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在yarl的用法示例。


在下文中一共展示了yarl.URL屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_watcher_info

# 需要導入模塊: import yarl [as 別名]
# 或者: from yarl import URL [as 別名]
def get_watcher_info(request: web.Request, agent_id: str) -> dict:
    '''
    Get watcher information.

    :return addr: address of agent watcher (eg: http://127.0.0.1:6009)
    :return token: agent watcher token ("insecure" if not set in config server)
    '''
    token = request.app['config']['watcher']['token']
    if token is None:
        token = 'insecure'
    agent_ip = await request.app['registry'].config_server.get(f'nodes/agents/{agent_id}/ip')
    watcher_port = await request.app['registry'].config_server.get(
        f'nodes/agents/{agent_id}/watcher_port')
    if watcher_port is None:
        watcher_port = 6009
    # TODO: watcher scheme is assumed to be http
    addr = yarl.URL(f'http://{agent_ip}:{watcher_port}')
    return {
        'addr': addr,
        'token': token,
    } 
開發者ID:lablup,項目名稱:backend.ai-manager,代碼行數:23,代碼來源:resource.py

示例2: test_connect_proxy_ip

# 需要導入模塊: import yarl [as 別名]
# 或者: from yarl import URL [as 別名]
def test_connect_proxy_ip(loop):
    tr, proto = mock.Mock(name='transport'), mock.Mock(name='protocol')

    with mock.patch('aiosocks.connector.create_connection',
                    make_mocked_coro((tr, proto))):
        loop.getaddrinfo = make_mocked_coro(
             [[0, 0, 0, 0, ['127.0.0.1', 1080]]])

        req = ProxyClientRequest(
            'GET', URL('http://python.org'), loop=loop,
            proxy=URL('socks5://proxy.org'))
        connector = ProxyConnector(loop=loop)
        conn = await connector.connect(req, [], ClientTimeout())

    assert loop.getaddrinfo.called
    assert conn.protocol is proto

    conn.close() 
開發者ID:nibrag,項目名稱:aiosocks,代碼行數:20,代碼來源:test_connector.py

示例3: test_connect_proxy_domain

# 需要導入模塊: import yarl [as 別名]
# 或者: from yarl import URL [as 別名]
def test_connect_proxy_domain():
    tr, proto = mock.Mock(name='transport'), mock.Mock(name='protocol')

    with mock.patch('aiosocks.connector.create_connection',
                    make_mocked_coro((tr, proto))):
        loop_mock = mock.Mock()

        req = ProxyClientRequest(
            'GET', URL('http://python.org'),  loop=loop_mock,
            proxy=URL('socks5://proxy.example'))
        connector = ProxyConnector(loop=loop_mock)

        connector._resolve_host = make_mocked_coro([mock.MagicMock()])
        conn = await connector.connect(req, [], ClientTimeout())

    assert connector._resolve_host.call_count == 1
    assert conn.protocol is proto

    conn.close() 
開發者ID:nibrag,項目名稱:aiosocks,代碼行數:21,代碼來源:test_connector.py

示例4: test_connect_remote_resolve

# 需要導入模塊: import yarl [as 別名]
# 或者: from yarl import URL [as 別名]
def test_connect_remote_resolve(loop):
    tr, proto = mock.Mock(name='transport'), mock.Mock(name='protocol')

    with mock.patch('aiosocks.connector.create_connection',
                    make_mocked_coro((tr, proto))):
        req = ProxyClientRequest(
            'GET', URL('http://python.org'), loop=loop,
            proxy=URL('socks5://127.0.0.1'))
        connector = ProxyConnector(loop=loop, remote_resolve=True)
        connector._resolve_host = make_mocked_coro([mock.MagicMock()])
        conn = await connector.connect(req, [], ClientTimeout())

    assert connector._resolve_host.call_count == 1
    assert conn.protocol is proto

    conn.close() 
開發者ID:nibrag,項目名稱:aiosocks,代碼行數:18,代碼來源:test_connector.py

示例5: test_connect_locale_resolve

# 需要導入模塊: import yarl [as 別名]
# 或者: from yarl import URL [as 別名]
def test_connect_locale_resolve(loop):
    tr, proto = mock.Mock(name='transport'), mock.Mock(name='protocol')

    with mock.patch('aiosocks.connector.create_connection',
                    make_mocked_coro((tr, proto))):
        req = ProxyClientRequest(
            'GET', URL('http://python.org'), loop=loop,
            proxy=URL('socks5://proxy.example'))
        connector = ProxyConnector(loop=loop, remote_resolve=False)
        connector._resolve_host = make_mocked_coro([mock.MagicMock()])
        conn = await connector.connect(req, [], ClientTimeout())

    assert connector._resolve_host.call_count == 2
    assert conn.protocol is proto

    conn.close() 
開發者ID:nibrag,項目名稱:aiosocks,代碼行數:18,代碼來源:test_connector.py

示例6: test_proxy_connect_http

# 需要導入模塊: import yarl [as 別名]
# 或者: from yarl import URL [as 別名]
def test_proxy_connect_http(loop):
    tr, proto = mock.Mock(name='transport'), mock.Mock(name='protocol')
    loop_mock = mock.Mock()
    loop_mock.getaddrinfo = make_mocked_coro([
        [0, 0, 0, 0, ['127.0.0.1', 1080]]])
    loop_mock.create_connection = make_mocked_coro((tr, proto))
    loop_mock.create_task.return_value = asyncio.Task(
        make_mocked_coro([
            {'host': 'host', 'port': 80, 'family': 1,
             'hostname': 'hostname', 'flags': 11, 'proto': 'proto'}])())

    req = ProxyClientRequest(
        'GET', URL('http://python.org'), loop=loop,
        proxy=URL('http://127.0.0.1'))
    connector = ProxyConnector(loop=loop_mock)

    await connector.connect(req, [], ClientTimeout()) 
開發者ID:nibrag,項目名稱:aiosocks,代碼行數:19,代碼來源:test_connector.py

示例7: registerEmptyUri

# 需要導入模塊: import yarl [as 別名]
# 或者: from yarl import URL [as 別名]
def registerEmptyUri(self, uri, status):
        def cb():
            fut = asyncio.Future(loop=self._loop)
            resp = ClientResponse(
                'GET',
                yarl.URL('foo'),
                writer=Mock(),
                timer=TimerNoop(),
                continue100=None,
                request_info=Mock(),
                traces=[],
                loop=self._loop,
                session=Mock()
                )
            resp.status = status

            # setting this as aiohttp 3.5.4 is now checking if this value is not None
            # see aiohttp/client_reqrep.py:934
            resp.reason = http.client.responses[status]

            fut.set_result(resp)
            return fut
        self._callbacks[uri].append(cb) 
開發者ID:madedotcom,項目名稱:atomicpuppy,代碼行數:25,代碼來源:fakehttp.py

示例8: test_url

# 需要導入模塊: import yarl [as 別名]
# 或者: from yarl import URL [as 別名]
def test_url(dispatcher: TreeUrlDispatcher):
    location = dispatcher['root']
    assert 'path' in location.get_info()
    route = location._routes['GET']
    route.set_info(x=1)
    assert route.get_info().get('x') == 1

    location = dispatcher['pet']
    assert location.url(parts={'id': 1}) == '/api/1/pet/1'
    assert location.url_for(id=1) == URL('/api/1/pet/1')
    assert repr(location)

    route = location._routes['GET']
    assert route.url(parts={'id': 1}) == '/api/1/pet/1'
    assert route.url_for(id=1) == URL('/api/1/pet/1')
    assert repr(route)
    assert route.name
    assert 'formatter' in route.get_info()

    assert dispatcher.tree_resource.url_for() == URL('/')
    assert dispatcher.tree_resource.url(query={'q': 1}) == '/?q=1'
    assert repr(dispatcher.tree_resource)
    assert dispatcher.tree_resource.get_info() is not None 
開發者ID:aamalev,項目名稱:aiohttp_apiset,代碼行數:25,代碼來源:test_dispatcher.py

示例9: fromRequestWillBeSent

# 需要導入模塊: import yarl [as 別名]
# 或者: from yarl import URL [as 別名]
def fromRequestWillBeSent (self, req):
        """ Set request data from Chrome Network.requestWillBeSent event """
        r = req['request']

        self.id = req['requestId']
        self.url = URL (r['url'])
        self.resourceType = req.get ('type')
        self._time = ReferenceTimestamp (req['timestamp'], req['wallTime'])

        assert self.request is None, req
        self.request = Request ()
        self.request.initiator = req['initiator']
        self.request.headers = CIMultiDict (self._unfoldHeaders (r['headers']))
        self.request.hasPostData = r.get ('hasPostData', False)
        self.request.method = r['method']
        self.request.timestamp = self._time (req['timestamp'])
        if self.request.hasPostData:
            postData = r.get ('postData')
            if postData is not None:
                self.request.body = UnicodeBody (postData) 
開發者ID:PromyLOPh,項目名稱:crocoite,代碼行數:22,代碼來源:browser.py

示例10: _responseReceived

# 需要導入模塊: import yarl [as 別名]
# 或者: from yarl import URL [as 別名]
def _responseReceived (self, **kwargs):
        self.logger.debug ('responseReceived',
                uuid='ecd67e69-401a-41cb-b4ec-eeb1f1ec6abb', args=kwargs)

        reqId = kwargs['requestId']
        item = self.requests.get (reqId)
        if item is None:
            return

        resp = kwargs['response']
        url = URL (resp['url'])
        logger = self.logger.bind (reqId=reqId, respUrl=url)
        if item.url != url:
            logger.error ('url mismatch', uuid='7385f45f-0b06-4cbc-81f9-67bcd72ee7d0', respUrl=url)
        if url.scheme in self.allowedSchemes:
            item.fromResponseReceived (kwargs)
        else:
            logger.warning ('scheme forbidden', uuid='2ea6e5d7-dd3b-4881-b9de-156c1751c666') 
開發者ID:PromyLOPh,項目名稱:crocoite,代碼行數:20,代碼來源:browser.py

示例11: run

# 需要導入模塊: import yarl [as 別名]
# 或者: from yarl import URL [as 別名]
def run(self):
        # XXX: do this once only
        fd = pkg_resources.resource_stream ('crocoite', 'data/click.yaml')
        config = list (yaml.safe_load_all (fd))

        l = nodes.definition_list ()
        for site in config:
            urls = set ()
            v = nodes.definition ()
            vl = nodes.bullet_list ()
            v += vl
            for s in site['selector']:
                i = nodes.list_item ()
                i += nodes.paragraph (text=s['description'])
                vl += i
                urls.update (map (lambda x: URL(x).with_path ('/'), s.get ('urls', [])))

            item = nodes.definition_list_item ()
            term = ', '.join (map (lambda x: x.host, urls)) if urls else site['match']
            k = nodes.term (text=term)
            item += k

            item += v
            l += item
        return [l] 
開發者ID:PromyLOPh,項目名稱:crocoite,代碼行數:27,代碼來源:clicklist.py

示例12: setup_static_root_files

# 需要導入模塊: import yarl [as 別名]
# 或者: from yarl import URL [as 別名]
def setup_static_root_files(self, directory: str, ui_base: str) -> None:
        files = {
            "asset-manifest.json": "application/json",
            "manifest.json": "application/json",
            "favicon.png": "image/png",
        }
        for file, mime in files.items():
            with open(f"{directory}/{file}", "rb") as stream:
                data = stream.read()
            self.app.router.add_get(f"{ui_base}/{file}", lambda _: web.Response(body=data,
                                                                                content_type=mime))

        # also set up a resource path for the public url path prefix config
        # cut the prefix path from public_url
        public_url = self.config["server.public_url"]
        base_path = self.config["server.base_path"]
        public_url_path = ""
        if public_url:
            public_url_path = URL(public_url).path.rstrip("/")

        # assemble with base_path
        api_path = f"{public_url_path}{base_path}"

        path_prefix_response_body = json.dumps({"api_path": api_path.rstrip("/")})
        self.app.router.add_get(f"{ui_base}/paths.json", lambda _: web.Response(body=path_prefix_response_body,
                                                                                content_type="application/json")) 
開發者ID:maubot,項目名稱:maubot,代碼行數:28,代碼來源:server.py

示例13: __init__

# 需要導入模塊: import yarl [as 別名]
# 或者: from yarl import URL [as 別名]
def __init__(self, client: 'MaubotMatrixClient', loop: AbstractEventLoop, http: ClientSession,
                 instance_id: str, log: Logger, config: Optional['BaseProxyConfig'],
                 database: Optional[Engine], webapp: Optional['PluginWebApp'],
                 webapp_url: Optional[str]) -> None:
        self.client = client
        self.loop = loop
        self.http = http
        self.id = instance_id
        self.log = log
        self.config = config
        self.database = database
        self.webapp = webapp
        self.webapp_url = URL(webapp_url) if webapp_url else None
        self._handlers_at_startup = [] 
開發者ID:maubot,項目名稱:maubot,代碼行數:16,代碼來源:plugin_base.py

示例14: get_docker_registries

# 需要導入模塊: import yarl [as 別名]
# 或者: from yarl import URL [as 別名]
def get_docker_registries(request) -> web.Response:
    '''
    Returns the list of all registered docker registries.
    '''
    log.info('ETCD.GET_DOCKER_REGISTRIES ()')
    etcd = request.app['registry'].config_server.etcd
    _registries = await get_known_registries(etcd)
    # ``yarl.URL`` is not JSON-serializable, so we need to represent it as string.
    known_registries: Mapping[str, str] = {k: v.human_repr() for k, v in _registries.items()}
    return web.json_response(known_registries, status=200) 
開發者ID:lablup,項目名稱:backend.ai-manager,代碼行數:12,代碼來源:etcd.py

示例15: test_not_verbose

# 需要導入模塊: import yarl [as 別名]
# 或者: from yarl import URL [as 別名]
def test_not_verbose(self, loop, console, results):
        async with self._get_session(loop, console, verbose=1) as session:
            req = ClientRequest("GET", URL("http://example.com"))
            await session.send_event("sending_request", request=req)

            response = Response(body="")
            request = Request()
            await session.send_event(
                "response_received", response=response, request=request
            )

        res = await serialize(console)
        self.assertEqual(res, "") 
開發者ID:loads,項目名稱:molotov,代碼行數:15,代碼來源:test_session.py


注:本文中的yarl.URL屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。