当前位置: 首页>>代码示例>>Python>>正文


Python xmlrpclib.ProtocolError方法代码示例

本文整理汇总了Python中xmlrpclib.ProtocolError方法的典型用法代码示例。如果您正苦于以下问题:Python xmlrpclib.ProtocolError方法的具体用法?Python xmlrpclib.ProtocolError怎么用?Python xmlrpclib.ProtocolError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xmlrpclib的用法示例。


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

示例1: is_unavailable_exception

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ProtocolError [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 xmlrpclib [as 别名]
# 或者: from xmlrpclib import ProtocolError [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 xmlrpclib [as 别名]
# 或者: from xmlrpclib import ProtocolError [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 xmlrpclib [as 别名]
# 或者: from xmlrpclib import ProtocolError [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 xmlrpclib [as 别名]
# 或者: from xmlrpclib import ProtocolError [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: terminate

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ProtocolError [as 别名]
def terminate(self):

        if self.server is None:
            # Nothing to do
            return

        try:
            response = self.server.LogOut(self.token)
        except xmlrpclib.ProtocolError:
            raise ProviderNotAvailable
        except xmlrpclib.ResponseNotReady:
            logger.warning('ResponseNotReady exception thrown on logout.')
            return

        if response['status'] != '200 OK':
            raise ProviderError('Logout failed with status %r' % response['status']) 
开发者ID:caronc,项目名称:nzb-subliminal,代码行数:18,代码来源:opensubtitles.py

示例7: download_subtitle

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ProtocolError [as 别名]
def download_subtitle(self, subtitle):

        if self.server is None:
            # Nothing to do
            raise ProviderError('Provider not initialized.')

        try:
            response = self.server.DownloadSubtitles(self.token, [subtitle.id])
            logger.debug('Download URL: %s {token=%s, subid:%s}' % (
                self.server_url,
                self.token, subtitle.id,
            ))
        except xmlrpclib.ProtocolError:
            raise ProviderNotAvailable
        if response['status'] != '200 OK':
            raise ProviderError(
                'Download failed with status %s' % str(response['status']))
        if not response['data']:
            raise ProviderError('Nothing to download')
        subtitle_bytes = zlib.decompress(base64.b64decode(response['data'][0]['data']), 47)
        subtitle_text = subtitle_bytes.decode(
            detect(subtitle_bytes, subtitle.language.alpha2)['encoding'], 'replace')
        if not is_valid_subtitle(subtitle_text):
            raise InvalidSubtitle
        return subtitle_text 
开发者ID:caronc,项目名称:nzb-subliminal,代码行数:27,代码来源:opensubtitles.py

示例8: request

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ProtocolError [as 别名]
def request(self, host, handler, request_body, verbose):
        """
        Make an xmlrpc request.
        """
        client = self.session or requests
        headers = {'User-Agent': self.user_agent,
                   'Content-Type': 'text/xml',
                   }
        url = self._build_url(host, handler)
        try:
            resp = client.post(url, data=request_body, headers=headers, timeout=self.timeout)
        except ValueError:
            raise
        except Exception:
            raise # something went wrong
        else:
            try:
                resp.raise_for_status()
            except requests.RequestException as e:
                raise xmlrpc.ProtocolError(url, resp.status_code,
                    str(e), resp.headers)
            else:
                return self.parse_response(resp) 
开发者ID:ip-tools,项目名称:patzilla,代码行数:25,代码来源:requests_xmlrpclib.py

示例9: bitcoind_get_transactions_from_block

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ProtocolError [as 别名]
def bitcoind_get_transactions_from_block(self, block, addresses):
    logging.info(addresses)
    transaction_ids = block['tx']

    transactions_per_address = {}
    for addr in addresses:
      transactions_per_address[addr] = []

    for tx in transaction_ids:
      try:
        raw_transaction = self.get_raw_transaction(tx)
      except ProtocolError:
        continue
      transaction = self.decode_raw_transaction(raw_transaction)
      for vout in transaction['vout']:
        if not 'addresses' in vout['scriptPubKey']:
          continue
        addresses_in_vout = set(vout['scriptPubKey']['addresses'])
        for addr in addresses:
          if addr in addresses_in_vout:
            transactions_per_address[addr].append(transaction)

    logging.info(transactions_per_address)
    return transactions_per_address 
开发者ID:orisi,项目名称:orisi,代码行数:26,代码来源:bitcoinclient.py

示例10: _run_and_ignore_connection_lost

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ProtocolError [as 别名]
def _run_and_ignore_connection_lost(self):
        try:
            yield
        except RuntimeError as r:  # disconnection from remotelibrary
            if 'Connection to remote server broken:' in r.args[0]:
                logger.info('Connection died as expected')
                return
            raise
        except HandlerExecutionFailed as e:  # disconnection from xmlrpc wrapped in robot keyword
            if any(elem in e.args[0] for elem in ('Connection to remote server broken:', 'ProtocolError')):
                logger.info('Connection died as expected')
                return
            raise
        except ProtocolError as r:  # disconnection from xmlrpc in jython on some platforms
            logger.info('Connection died as expected')
            return 
开发者ID:robotframework,项目名称:remoteswinglibrary,代码行数:18,代码来源:RemoteSwingLibrary.py

示例11: _request

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import ProtocolError [as 别名]
def _request(self, host, handler, request_body, verbose=0):
        # issue XML-RPC request
        h = self.cache.get_connection()
        try:
            self._set_connection_params(h)
            h.add_data(request_body)
            response = pycurllib.urlopen(h, close=False)
        except:
            # connection may no longer be valid
            self.cache.destroy_connection(h)
            raise
        self.cache.put_connection(h)
        if response.code != 200:
            raise xmlrpclib.ProtocolError(
                host + handler,
                response.code, response.msg,
                'N/A',
            )
        self.verbose = verbose
        return self._parse_response(response) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:22,代码来源:xmlrpclib2.py


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