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


Python socket.errors方法代碼示例

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


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

示例1: is_unavailable_exception

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import errors [as 別名]
def is_unavailable_exception(e):
    '''Returns True if the given ProtocolError is the product of a server-side
       exception caused by the 'temporarily unavailable' response sometimes
       given by operations on non-blocking sockets.'''

    # sometimes we get a -1 error code and/or empty headers
    try:
        if e.errcode == -1 or e.headers is None:
            return True
        exc_mess = e.headers.get('X-exception')
    except AttributeError:
        # Ignore socket.errors here.
        exc_mess = str(e)

    if exc_mess and 'temporarily unavailable' in exc_mess.lower():
        return True

    return False 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:test_xmlrpc.py

示例2: test_multicall

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import errors [as 別名]
def test_multicall(self):
        try:
            p = xmlrpclib.ServerProxy(URL)
            multicall = xmlrpclib.MultiCall(p)
            multicall.add(2,3)
            multicall.pow(6,8)
            multicall.div(127,42)
            add_result, pow_result, div_result = multicall()
            self.assertEqual(add_result, 2+3)
            self.assertEqual(pow_result, 6**8)
            self.assertEqual(div_result, 127//42)
        except (xmlrpclib.ProtocolError, socket.error), e:
            # ignore failures due to non-blocking socket 'unavailable' errors
            if not is_unavailable_exception(e):
                # protocol error; provide additional information in test output
                self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:test_xmlrpc.py

示例3: test_non_existing_multicall

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import errors [as 別名]
def test_non_existing_multicall(self):
        try:
            p = xmlrpclib.ServerProxy(URL)
            multicall = xmlrpclib.MultiCall(p)
            multicall.this_is_not_exists()
            result = multicall()

            # result.results contains;
            # [{'faultCode': 1, 'faultString': '<type \'exceptions.Exception\'>:'
            #   'method "this_is_not_exists" is not supported'>}]

            self.assertEqual(result.results[0]['faultCode'], 1)
            self.assertEqual(result.results[0]['faultString'],
                '<type \'exceptions.Exception\'>:method "this_is_not_exists" '
                'is not supported')
        except (xmlrpclib.ProtocolError, socket.error), e:
            # ignore failures due to non-blocking socket 'unavailable' errors
            if not is_unavailable_exception(e):
                # protocol error; provide additional information in test output
                self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,代碼來源:test_xmlrpc.py

示例4: test_basic

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import errors [as 別名]
def test_basic(self):
        # check that flag is false by default
        flagval = SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header
        self.assertEqual(flagval, False)

        # enable traceback reporting
        SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True

        # test a call that shouldn't fail just as a smoke test
        try:
            p = xmlrpclib.ServerProxy(URL)
            self.assertEqual(p.pow(6,8), 6**8)
        except (xmlrpclib.ProtocolError, socket.error), e:
            # ignore failures due to non-blocking socket 'unavailable' errors
            if not is_unavailable_exception(e):
                # protocol error; provide additional information in test output
                self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:test_xmlrpc.py

示例5: test_fail_with_info

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import errors [as 別名]
def test_fail_with_info(self):
        # use the broken message class
        SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass

        # Check that errors in the server send back exception/traceback
        # info when flag is set
        SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True

        try:
            p = xmlrpclib.ServerProxy(URL)
            p.pow(6,8)
        except (xmlrpclib.ProtocolError, socket.error), e:
            # ignore failures due to non-blocking socket 'unavailable' errors
            if not is_unavailable_exception(e) and hasattr(e, "headers"):
                # We should get error info in the response
                expected_err = "invalid literal for int() with base 10: 'I am broken'"
                self.assertEqual(e.headers.get("x-exception"), expected_err)
                self.assertTrue(e.headers.get("x-traceback") is not None) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:test_xmlrpc.py

示例6: _download_byte_range

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import errors [as 別名]
def _download_byte_range(self, byte_range, retry_exceptions):
        # You can occasionally get socket.errors when downloading
        # chunks from Glacier, so each chunk can be retried up
        # to 5 times.
        for _ in range(5):
            try:
                response = self.get_output(byte_range)
                data = response.read()
                expected_tree_hash = response['TreeHash']
                return data, expected_tree_hash
            except retry_exceptions as e:
                continue
        else:
            raise DownloadArchiveError("There was an error downloading"
                                       "byte range %s: %s" % (byte_range,
                                                              e)) 
開發者ID:VirtueSecurity,項目名稱:aws-extender,代碼行數:18,代碼來源:job.py

示例7: test_simple1

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import errors [as 別名]
def test_simple1(self):
        try:
            p = xmlrpclib.ServerProxy(URL)
            self.assertEqual(p.pow(6,8), 6**8)
        except (xmlrpclib.ProtocolError, socket.error), e:
            # ignore failures due to non-blocking socket 'unavailable' errors
            if not is_unavailable_exception(e):
                # protocol error; provide additional information in test output
                self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_xmlrpc.py

示例8: test_nonascii

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import errors [as 別名]
def test_nonascii(self):
        start_string = test_support.u(r'P\N{LATIN SMALL LETTER Y WITH CIRCUMFLEX}t')
        end_string = test_support.u(r'h\N{LATIN SMALL LETTER O WITH HORN}n')

        try:
            p = xmlrpclib.ServerProxy(URL)
            self.assertEqual(p.add(start_string, end_string),
                             start_string + end_string)
        except (xmlrpclib.ProtocolError, socket.error) as e:
            # ignore failures due to non-blocking socket unavailable errors.
            if not is_unavailable_exception(e):
                # protocol error; provide additional information in test output
                self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:15,代碼來源:test_xmlrpc.py

示例9: test_client_encoding

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import errors [as 別名]
def test_client_encoding(self):
        start_string = unichr(0x20ac)
        end_string = unichr(0xa4)

        try:
            p = xmlrpclib.ServerProxy(URL, encoding='iso-8859-15')
            self.assertEqual(p.add(start_string, end_string),
                             start_string + end_string)
        except (xmlrpclib.ProtocolError, socket.error) as e:
            # ignore failures due to non-blocking socket unavailable errors.
            if not is_unavailable_exception(e):
                # protocol error; provide additional information in test output
                self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:15,代碼來源:test_xmlrpc.py

示例10: test_nonascii_methodname

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import errors [as 別名]
def test_nonascii_methodname(self):
        try:
            p = xmlrpclib.ServerProxy(URL, encoding='iso-8859-15')
            m = getattr(p, 't\xea\xa8t')
            self.assertEqual(m(42), 42)
        except (xmlrpclib.ProtocolError, socket.error) as e:
            # ignore failures due to non-blocking socket unavailable errors.
            if not is_unavailable_exception(e):
                # protocol error; provide additional information in test output
                self.fail("%s\n%s" % (e, getattr(e, "headers", "")))

    # [ch] The test 404 is causing lots of false alarms. 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:14,代碼來源:test_xmlrpc.py


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