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


Python _socket.getservbyname方法代碼示例

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


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

示例1: test_getservbyname

# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import getservbyname [as 別名]
def test_getservbyname(self):
        self.assertEqual(_socket.getservbyname("http"), 80) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:4,代碼來源:test__socket.py

示例2: _lookup_port

# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import getservbyname [as 別名]
def _lookup_port(self, port, socktype):
        socktypes = []
        if isinstance(port, string_types):
            try:
                port = int(port)
            except ValueError:
                try:
                    if socktype == 0:
                        origport = port
                        try:
                            port = getservbyname(port, 'tcp')
                            socktypes.append(SOCK_STREAM)
                        except error:
                            port = getservbyname(port, 'udp')
                            socktypes.append(SOCK_DGRAM)
                        else:
                            try:
                                if port == getservbyname(origport, 'udp'):
                                    socktypes.append(SOCK_DGRAM)
                            except error:
                                pass
                    elif socktype == SOCK_STREAM:
                        port = getservbyname(port, 'tcp')
                    elif socktype == SOCK_DGRAM:
                        port = getservbyname(port, 'udp')
                    else:
                        raise gaierror(EAI_SERVICE, 'Servname not supported for ai_socktype')
                except error as ex:
                    if 'not found' in str(ex):
                        raise gaierror(EAI_SERVICE, 'Servname not supported for ai_socktype')
                    else:
                        raise gaierror(str(ex))
                except UnicodeEncodeError:
                    raise error('Int or String expected')
        elif port is None:
            port = 0
        elif isinstance(port, integer_types):
            pass
        else:
            raise error('Int or String expected', port, type(port))
        port = int(port % 65536)
        if not socktypes and socktype:
            socktypes.append(socktype)
        return port, socktypes 
開發者ID:leancloud,項目名稱:satori,代碼行數:46,代碼來源:resolver_ares.py

示例3: _lookup_port

# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import getservbyname [as 別名]
def _lookup_port(self, port, socktype):
        # pylint:disable=too-many-branches
        socktypes = []
        if isinstance(port, string_types):
            try:
                port = int(port)
            except ValueError:
                try:
                    if socktype == 0:
                        origport = port
                        try:
                            port = getservbyname(port, 'tcp')
                            socktypes.append(SOCK_STREAM)
                        except error:
                            port = getservbyname(port, 'udp')
                            socktypes.append(SOCK_DGRAM)
                        else:
                            try:
                                if port == getservbyname(origport, 'udp'):
                                    socktypes.append(SOCK_DGRAM)
                            except error:
                                pass
                    elif socktype == SOCK_STREAM:
                        port = getservbyname(port, 'tcp')
                    elif socktype == SOCK_DGRAM:
                        port = getservbyname(port, 'udp')
                    else:
                        raise gaierror(EAI_SERVICE, 'Servname not supported for ai_socktype')
                except error as ex:
                    if 'not found' in str(ex):
                        raise gaierror(EAI_SERVICE, 'Servname not supported for ai_socktype')
                    else:
                        raise gaierror(str(ex))
                except UnicodeEncodeError:
                    raise error('Int or String expected')
        elif port is None:
            port = 0
        elif isinstance(port, integer_types):
            pass
        else:
            raise error('Int or String expected', port, type(port))
        port = int(port % 65536)
        if not socktypes and socktype:
            socktypes.append(socktype)
        return port, socktypes 
開發者ID:priyankark,項目名稱:PhonePi_SampleServer,代碼行數:47,代碼來源:resolver_ares.py


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