• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python internet.format_address函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pulsar.utils.internet.format_address函数的典型用法代码示例。如果您正苦于以下问题:Python format_address函数的具体用法?Python format_address怎么用?Python format_address使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了format_address函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: worker_info

 def worker_info(self, worker, info):
     info['sockets'] = sockets = []
     for server in worker.servers.get(self.name, ()):
         address = format_address(server.address)
         sockets.append({
             'address': format_address(server.address),
             'read_timeout': server.timeout,
             'concurrent_connections': server.concurrent_connections,
             'received_connections': server.received})
开发者ID:BazookaShao,项目名称:pulsar,代码行数:9,代码来源:__init__.py


示例2: create_endpoint

    def create_endpoint(self, **kw):
        '''create the server endpoint.

        :return: a :class:`~asyncio.Future` called back when the server is
            serving the socket.
        '''
        if hasattr(self, '_params'):
            address = self._params['address']
            sockets = self._params['sockets']
            del self._params
            try:
                transports = []
                if sockets:
                    for transport in sockets:
                        proto = self.create_protocol()
                        transports.append(transport(self._loop, proto))
                else:
                    loop = self._loop
                    transport, _ = yield from loop.create_datagram_endpoint(
                        self.protocol_factory, local_addr=address)
                    transports.append(transport)
                self._transports = transports
                self._started = self._loop.time()
                for transport in self._transports:
                    address = transport.get_extra_info('sockname')
                    self.logger.info('%s serving on %s', self._name,
                                     format_address(address))
                self.fire_event('start')
            except Exception as exc:
                self.logger.exception('Error while starting UDP server')
                self.fire_event('start', exc=exc)
                self.fire_event('stop')
开发者ID:cluo,项目名称:pulsar,代码行数:32,代码来源:protocols.py


示例3: create_endpoint

    async def create_endpoint(self, **kw):
        """create the server endpoint.

        :return: a :class:`~asyncio.Future` called back when the server is
            serving the socket.
        """
        if hasattr(self, "_params"):
            address = self._params["address"]
            sockets = self._params["sockets"]
            del self._params
            try:
                transports = []
                loop = self._loop
                if sockets:
                    for sock in sockets:
                        transport, _ = await loop.create_datagram_endpoint(self.create_protocol, sock=sock)
                        transports.append(transport)
                else:
                    transport, _ = await loop.create_datagram_endpoint(self.create_protocol, local_addr=address)
                    transports.append(transport)
                self._transports = transports
                self._started = loop.time()
                for transport in self._transports:
                    address = transport.get_extra_info("sockname")
                    self.logger.info("%s serving on %s", self._name, format_address(address))
                self.fire_event("start")
            except Exception as exc:
                self.logger.exception("Error while starting UDP server")
                self.fire_event("start", exc=exc)
                self.fire_event("stop")
开发者ID:quantmind,项目名称:pulsar,代码行数:30,代码来源:protocols.py


示例4: start_serving

    async def start_serving(self, backlog=100, sslcontext=None):
        """Start serving.

        :param backlog: Number of maximum connections
        :param sslcontext: optional SSLContext object.
        :return: a :class:`.Future` called back when the server is
            serving the socket.
        """
        assert not self._server
        if hasattr(self, "_params"):
            address = self._params["address"]
            sockets = self._params["sockets"]
            del self._params
            create_server = self._loop.create_server
            if sockets:
                server = None
                for sock in sockets:
                    srv = await create_server(self.create_protocol, sock=sock, backlog=backlog, ssl=sslcontext)
                    if server:
                        server.sockets.extend(srv.sockets)
                    else:
                        server = srv
            else:
                if isinstance(address, tuple):
                    server = await create_server(
                        self.create_protocol, host=address[0], port=address[1], backlog=backlog, ssl=sslcontext
                    )
                else:
                    raise NotImplementedError
            self._server = server
            self._started = self._loop.time()
            for sock in server.sockets:
                address = sock.getsockname()
                self.logger.info("%s serving on %s", self._name, format_address(address))
            self._loop.call_soon(self.fire_event, "start")
开发者ID:quantmind,项目名称:pulsar,代码行数:35,代码来源:protocols.py


示例5: test_start_serving_ipv6

 def test_start_serving_ipv6(self):
     loop = get_event_loop()
     sockets = yield loop.start_serving(Protocol,'::1', 0)
     self.assertEqual(len(sockets), 1)
     sock = sockets[0]
     self.assertEqual(sock.family, socket.AF_INET6)
     address = sock.getsockname()
     faddress = format_address(address)
     self.assertEqual(faddress, '[::1]:%s' % address[1])
     loop.stop_serving(sock)
     self.assertTrue(is_socket_closed(sock))
开发者ID:elimisteve,项目名称:pulsar,代码行数:11,代码来源:eventloop.py


示例6: info

 def info(self):
     sockets = []
     up = int(self._loop.time() - self._started) if self._started else 0
     server = {"uptime_in_seconds": up, "sockets": sockets, "max_requests": self._max_requests}
     clients = {"requests_processed": self._requests_processed}
     if self._transports:
         for transport in self._transports:
             sock = transport.get_extra_info("socket")
             if sock:
                 sockets.append({"address": format_address(sock.getsockname())})
     return {"server": server, "clients": clients}
开发者ID:quantmind,项目名称:pulsar,代码行数:11,代码来源:protocols.py


示例7: info

 def info(self):
     sockets = []
     up = int(self._loop.time() - self._started) if self._started else 0
     server = {'uptime_in_seconds': up,
               'sockets': sockets,
               'max_requests': self._max_requests}
     clients = {'requests_processed': self._requests_processed}
     if self._transports:
         for transport in self._transports:
             sockets.append({
                 'address': format_address(transport._sock.getsockname())})
     return {'server': server,
             'clients': clients}
开发者ID:wilddom,项目名称:pulsar,代码行数:13,代码来源:protocols.py


示例8: info

 def info(self):
     sockets = []
     up = int(self._loop.time() - self._started) if self._started else 0
     server = {
         "pulsar_version": pulsar.__version__,
         "python_version": sys.version,
         "uptime_in_seconds": up,
         "sockets": sockets,
         "max_requests": self._max_requests,
     }
     clients = {"requests_processed": self._requests_processed}
     if self._transports:
         for transport in self._transports:
             sockets.append({"address": format_address(transport._sock.getsockname())})
     return {"server": server, "clients": clients}
开发者ID:Danzeer,项目名称:pulsar,代码行数:15,代码来源:protocols.py


示例9: start_serving

    def start_serving(self, backlog=100, sslcontext=None):
        '''Start serving.

        :param backlog: Number of maximum connections
        :param sslcontext: optional SSLContext object.
        :return: a :class:`.Future` called back when the server is
            serving the socket.'''
        assert not self._server
        if hasattr(self, '_params'):
            address = self._params['address']
            sockets = self._params['sockets']
            del self._params
            create_server = self._loop.create_server
            try:
                if sockets:
                    server = None
                    for sock in sockets:
                        srv = yield from create_server(self.create_protocol,
                                                       sock=sock,
                                                       backlog=backlog,
                                                       ssl=sslcontext)
                        if server:
                            server.sockets.extend(srv.sockets)
                        else:
                            server = srv
                else:
                    if isinstance(address, tuple):
                        server = yield from create_server(self.create_protocol,
                                                          host=address[0],
                                                          port=address[1],
                                                          backlog=backlog,
                                                          ssl=sslcontext)
                    else:
                        raise NotImplementedError
                self._server = server
                self._started = self._loop.time()
                for sock in server.sockets:
                    address = sock.getsockname()
                    self.logger.info('%s serving on %s', self._name,
                                     format_address(address))
                self.fire_event('start')
            except Exception as exc:
                self.fire_event('start', exc=exc)
开发者ID:cluo,项目名称:pulsar,代码行数:43,代码来源:protocols.py


示例10: _got_sockets

 def _got_sockets(self, sockets):
     self._sock = sockets[0]
     self.logger.info('%s serving on %s', self._name,
                      format_address(self.address))
     return self
开发者ID:etataurov,项目名称:pulsar,代码行数:5,代码来源:stream.py


示例11: test_format_address

 def test_format_address(self):
     self.assertRaises(ValueError, format_address, (1,))
     self.assertRaises(ValueError, format_address, (1, 2, 3))
     self.assertRaises(ValueError, format_address, (1, 2, 3, 4, 5))
     self.assertEqual(format_address(1), '1')
开发者ID:Danzeer,项目名称:pulsar,代码行数:5,代码来源:test_internet.py


示例12: wsgi_environ

def wsgi_environ(stream, address, client_address, headers,
                 server_software=None, https=False, extra=None):
    protocol = stream.protocol()
    parser = stream.parser
    request_headers = stream.headers
    raw_uri = parser.get_url()
    request_uri = urlparse(raw_uri)
    #
    # http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.2
    # If Request-URI is an absoluteURI, the host is part of the Request-URI.
    # Any Host header field value in the request MUST be ignored
    if request_uri.scheme:
        url_scheme = request_uri.scheme
        host = request_uri.netloc
    else:
        url_scheme = 'https' if https else 'http'
        host = None
    #
    environ = {"wsgi.input": stream,
               "wsgi.errors": sys.stderr,
               "wsgi.version": (1, 0),
               "wsgi.run_once": False,
               "wsgi.multithread": False,
               "wsgi.multiprocess": False,
               "SERVER_SOFTWARE": server_software or pulsar.SERVER_SOFTWARE,
               "REQUEST_METHOD": native_str(parser.get_method()),
               "QUERY_STRING": parser.get_query_string(),
               "RAW_URI": raw_uri,
               "SERVER_PROTOCOL": protocol,
               "CONTENT_TYPE": ''}
    forward = client_address
    script_name = os.environ.get("SCRIPT_NAME", "")
    for header, value in request_headers:
        header = header.lower()
        if header in HOP_HEADERS:
            headers[header] = value
        if header == 'x-forwarded-for':
            forward = value
        elif header == "x-forwarded-protocol" and value == "ssl":
            url_scheme = "https"
        elif header == "x-forwarded-ssl" and value == "on":
            url_scheme = "https"
        elif header == "host" and not host:
            host = value
        elif header == "script_name":
            script_name = value
        elif header == "content-type":
            environ['CONTENT_TYPE'] = value
            continue
        elif header == "content-length":
            environ['CONTENT_LENGTH'] = value
            continue
        key = 'HTTP_' + header.upper().replace('-', '_')
        environ[key] = value
    environ['wsgi.url_scheme'] = url_scheme
    if url_scheme == 'https':
        environ['HTTPS'] = 'on'
    if is_string(forward):
        # we only took the last one
        # http://en.wikipedia.org/wiki/X-Forwarded-For
        if forward.find(",") >= 0:
            forward = forward.rsplit(",", 1)[1].strip()
        remote = forward.split(":")
        if len(remote) < 2:
            remote.append('80')
    else:
        remote = forward
    environ['REMOTE_ADDR'] = remote[0]
    environ['REMOTE_PORT'] = str(remote[1])
    if not host and protocol == 'HTTP/1.0':
        host = format_address(address)
    if host:
        host = host_and_port_default(url_scheme, host)
        environ['SERVER_NAME'] = socket.getfqdn(host[0])
        environ['SERVER_PORT'] = host[1]
    path_info = parser.get_path()
    if path_info is not None:
        if script_name:
            path_info = path_info.split(script_name, 1)[1]
        environ['PATH_INFO'] = unquote(path_info)
    environ['SCRIPT_NAME'] = script_name
    if extra:
        environ.update(extra)
    return environ
开发者ID:Ghost-script,项目名称:dyno-chat,代码行数:84,代码来源:server.py


示例13: __repr__

 def __repr__(self):
     return '%s %s' % (self.__class__.__name__,
                       format_address(self.address))
开发者ID:etataurov,项目名称:pulsar,代码行数:3,代码来源:protocols.py


示例14: wsgi_environ

def wsgi_environ(
    stream, parser, request_headers, address, client_address, headers, server_software=None, https=False, extra=None
):
    """Build the WSGI Environment dictionary

    :param stream: a wsgi stream object
    :param parser: pulsar HTTP parser
    :param request_headers: headers of request
    :param address: server address
    :param client_address: client address
    :param headers: container for response headers
    """
    protocol = http_protocol(parser)
    raw_uri = parser.get_url()
    request_uri = urlparse(raw_uri)
    #
    # http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.2
    # If Request-URI is an absoluteURI, the host is part of the Request-URI.
    # Any Host header field value in the request MUST be ignored
    if request_uri.scheme:
        url_scheme = request_uri.scheme
        host = request_uri.netloc
    else:
        url_scheme = "https" if https else "http"
        host = None
    #
    environ = {
        "wsgi.input": stream,
        "wsgi.errors": sys.stderr,
        "wsgi.version": (1, 0),
        "wsgi.run_once": False,
        "wsgi.multithread": False,
        "wsgi.multiprocess": False,
        "SERVER_SOFTWARE": server_software or pulsar.SERVER_SOFTWARE,
        "REQUEST_METHOD": native_str(parser.get_method()),
        "QUERY_STRING": parser.get_query_string(),
        "RAW_URI": raw_uri,
        "SERVER_PROTOCOL": protocol,
        "CONTENT_TYPE": "",
    }
    forward = client_address
    script_name = os.environ.get("SCRIPT_NAME", "")
    for header, value in request_headers:
        header = header.lower()
        if header in HOP_HEADERS:
            headers[header] = value
        if header == "x-forwarded-for":
            forward = value
        elif header == "x-forwarded-protocol" and value == "ssl":
            url_scheme = "https"
        elif header == "x-forwarded-ssl" and value == "on":
            url_scheme = "https"
        elif header == "host" and not host:
            host = value
        elif header == "script_name":
            script_name = value
        elif header == "content-type":
            environ["CONTENT_TYPE"] = value
            continue
        elif header == "content-length":
            environ["CONTENT_LENGTH"] = value
            continue
        key = "HTTP_" + header.upper().replace("-", "_")
        environ[key] = value
    environ["wsgi.url_scheme"] = url_scheme
    if url_scheme == "https":
        environ["HTTPS"] = "on"
    if isinstance(forward, str):
        # we only took the last one
        # http://en.wikipedia.org/wiki/X-Forwarded-For
        if forward.find(",") >= 0:
            forward = forward.rsplit(",", 1)[1].strip()
        remote = forward.split(":")
        if len(remote) < 2:
            remote.append("80")
    else:
        remote = forward
    environ["REMOTE_ADDR"] = remote[0]
    environ["REMOTE_PORT"] = str(remote[1])
    if not host and protocol == "HTTP/1.0":
        host = format_address(address)
    if host:
        h = host_and_port_default(url_scheme, host)
        environ["SERVER_NAME"] = socket.getfqdn(h[0]) if h[0] else "0.0.0.0"
        environ["SERVER_PORT"] = h[1]
    path_info = request_uri.path
    if path_info is not None:
        if script_name:
            path_info = path_info.split(script_name, 1)[1]
        environ["PATH_INFO"] = unquote(path_info)
    environ["SCRIPT_NAME"] = script_name
    if extra:
        environ.update(extra)
    return environ
开发者ID:luffyhwl,项目名称:pulsar,代码行数:94,代码来源:server.py



注:本文中的pulsar.utils.internet.format_address函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pep.iteritems函数代码示例发布时间:2022-05-25
下一篇:
Python httpurl.SimpleCookie类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap