当前位置: 首页>>代码示例>>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;未经允许,请勿转载。