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


Python xmlrpclib.loads方法代码示例

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


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

示例1: test_dump_encoding

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import loads [as 别名]
def test_dump_encoding(self):
        value = {test_support.u(r'key\u20ac\xa4'):
                 test_support.u(r'value\u20ac\xa4')}
        strg = xmlrpclib.dumps((value,), encoding='iso-8859-15')
        strg = "<?xml version='1.0' encoding='iso-8859-15'?>" + strg
        self.assertEqual(xmlrpclib.loads(strg)[0][0], value)

        strg = xmlrpclib.dumps((value,), encoding='iso-8859-15',
                               methodresponse=True)
        self.assertEqual(xmlrpclib.loads(strg)[0][0], value)

        methodname = test_support.u(r'method\u20ac\xa4')
        strg = xmlrpclib.dumps((value,), encoding='iso-8859-15',
                               methodname=methodname)
        self.assertEqual(xmlrpclib.loads(strg)[0][0], value)
        self.assertEqual(xmlrpclib.loads(strg)[1], methodname) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_xmlrpc.py

示例2: render

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import loads [as 别名]
def render(self, request):
        """ Overridden 'render' method which takes care of
        HTTP basic authorization """
        
        if self._auth:
            cleartext_token = self._user + ':' + self._password
            user = request.getUser()
            passwd = request.getPassword()
        
            if user=='' and passwd=='':
                request.setResponseCode(http.UNAUTHORIZED)
                return 'Authorization required!'
            else:
                token = user + ':' + passwd
                if token != cleartext_token:
                    request.setResponseCode(http.UNAUTHORIZED)
                    return 'Authorization Failed!'

        request.content.seek(0, 0)
        args, functionPath = xmlrpclib.loads(request.content.read())
        try:
            function = self._getFunction(functionPath)
        except Fault, f:
            self._cbRender(f, request) 
开发者ID:ActiveState,项目名称:code,代码行数:26,代码来源:recipe-526625.py

示例3: parseResponse

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import loads [as 别名]
def parseResponse(self, contents):
        if not self.deferred:
            return
        try:
            if self.useDateTime:
                response = xmlrpclib.loads(contents,
                    use_datetime=True)[0][0]
            else:
                # Maintain backwards compatibility with Python < 2.5
                response = xmlrpclib.loads(contents)[0][0]
        except:
            deferred, self.deferred = self.deferred, None
            deferred.errback(failure.Failure())
        else:
            deferred, self.deferred = self.deferred, None
            deferred.callback(response) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:18,代码来源:xmlrpc.py

示例4: _marshaled_dispatch

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import loads [as 别名]
def _marshaled_dispatch(self, data, dispatch_method = None, path = None):
        """Dispatches an XML-RPC method from marshalled (XML) data.

        XML-RPC methods are dispatched from the marshalled (XML) data
        using the _dispatch method and the result is returned as
        marshalled data. For backwards compatibility, a dispatch
        function can be provided as an argument (see comment in
        SimpleXMLRPCRequestHandler.do_POST) but overriding the
        existing method through subclassing is the preferred means
        of changing method dispatch behavior.
        """

        try:
            params, method = xmlrpclib.loads(data)

            # generate response
            if dispatch_method is not None:
                response = dispatch_method(method, params)
            else:
                response = self._dispatch(method, params)
            # wrap response in a singleton tuple
            response = (response,)
            response = xmlrpclib.dumps(response, methodresponse=1,
                                       allow_none=self.allow_none, encoding=self.encoding)
        except Fault, fault:
            response = xmlrpclib.dumps(fault, allow_none=self.allow_none,
                                       encoding=self.encoding) 
开发者ID:glmcdona,项目名称:meddle,代码行数:29,代码来源:SimpleXMLRPCServer.py

示例5: test_dump_load

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import loads [as 别名]
def test_dump_load(self):
        self.assertEqual(alist,
                         xmlrpclib.loads(xmlrpclib.dumps((alist,)))[0][0]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_xmlrpc.py

示例6: test_dump_bare_datetime

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import loads [as 别名]
def test_dump_bare_datetime(self):
        # This checks that an unwrapped datetime.date object can be handled
        # by the marshalling code.  This can't be done via test_dump_load()
        # since with use_datetime set to 1 the unmarshaller would create
        # datetime objects for the 'datetime[123]' keys as well
        dt = datetime.datetime(2005, 02, 10, 11, 41, 23)
        s = xmlrpclib.dumps((dt,))
        (newdt,), m = xmlrpclib.loads(s, use_datetime=1)
        self.assertEqual(newdt, dt)
        self.assertEqual(m, None)

        (newdt,), m = xmlrpclib.loads(s, use_datetime=0)
        self.assertEqual(newdt, xmlrpclib.DateTime('20050210T11:41:23')) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_xmlrpc.py

示例7: test_datetime_before_1900

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import loads [as 别名]
def test_datetime_before_1900(self):
        # same as before but with a date before 1900
        dt = datetime.datetime(1, 02, 10, 11, 41, 23)
        s = xmlrpclib.dumps((dt,))
        (newdt,), m = xmlrpclib.loads(s, use_datetime=1)
        self.assertEqual(newdt, dt)
        self.assertEqual(m, None)

        (newdt,), m = xmlrpclib.loads(s, use_datetime=0)
        self.assertEqual(newdt, xmlrpclib.DateTime('00010210T11:41:23')) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_xmlrpc.py

示例8: test_bug_1164912

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import loads [as 别名]
def test_bug_1164912 (self):
        d = xmlrpclib.DateTime()
        ((new_d,), dummy) = xmlrpclib.loads(xmlrpclib.dumps((d,),
                                            methodresponse=True))
        self.assertIsInstance(new_d.value, str)

        # Check that the output of dumps() is still an 8-bit string
        s = xmlrpclib.dumps((new_d,), methodresponse=True)
        self.assertIsInstance(s, str) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_xmlrpc.py

示例9: test_dump_none

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import loads [as 别名]
def test_dump_none(self):
        value = alist + [None]
        arg1 = (alist + [None],)
        strg = xmlrpclib.dumps(arg1, allow_none=True)
        self.assertEqual(value,
                         xmlrpclib.loads(strg)[0][0])
        self.assertRaises(TypeError, xmlrpclib.dumps, (arg1,)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_xmlrpc.py

示例10: test_default_encoding_issues

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import loads [as 别名]
def test_default_encoding_issues(self):
        # SF bug #1115989: wrong decoding in '_stringify'
        utf8 = """<?xml version='1.0' encoding='iso-8859-1'?>
                  <params>
                    <param><value>
                      <string>abc \x95</string>
                      </value></param>
                    <param><value>
                      <struct>
                        <member>
                          <name>def \x96</name>
                          <value><string>ghi \x97</string></value>
                          </member>
                        </struct>
                      </value></param>
                  </params>
                  """

        # sys.setdefaultencoding() normally doesn't exist after site.py is
        # loaded.  Import a temporary fresh copy to get access to it
        # but then restore the original copy to avoid messing with
        # other potentially modified sys module attributes
        old_encoding = sys.getdefaultencoding()
        with test_support.CleanImport('sys'):
            import sys as temp_sys
            temp_sys.setdefaultencoding("iso-8859-1")
            try:
                (s, d), m = xmlrpclib.loads(utf8)
            finally:
                temp_sys.setdefaultencoding(old_encoding)

        items = d.items()
        if test_support.have_unicode:
            self.assertEqual(s, u"abc \x95")
            self.assertIsInstance(s, unicode)
            self.assertEqual(items, [(u"def \x96", u"ghi \x97")])
            self.assertIsInstance(items[0][0], unicode)
            self.assertIsInstance(items[0][1], unicode)
        else:
            self.assertEqual(s, "abc \xc2\x95")
            self.assertEqual(items, [("def \xc2\x96", "ghi \xc2\x97")]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:43,代码来源:test_xmlrpc.py

示例11: test_loads_unsupported

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import loads [as 别名]
def test_loads_unsupported(self):
        ResponseError = xmlrpclib.ResponseError
        data = '<params><param><value><spam/></value></param></params>'
        self.assertRaises(ResponseError, xmlrpclib.loads, data)
        data = ('<params><param><value><array>'
                '<value><spam/></value>'
                '</array></value></param></params>')
        self.assertRaises(ResponseError, xmlrpclib.loads, data)
        data = ('<params><param><value><struct>'
                '<member><name>a</name><value><spam/></value></member>'
                '<member><name>b</name><value><spam/></value></member>'
                '</struct></value></param></params>')
        self.assertRaises(ResponseError, xmlrpclib.loads, data) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_xmlrpc.py

示例12: test_dump_fault

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import loads [as 别名]
def test_dump_fault(self):
        f = xmlrpclib.Fault(42, 'Test Fault')
        s = xmlrpclib.dumps((f,))
        (newf,), m = xmlrpclib.loads(s)
        self.assertEqual(newf, {'faultCode': 42, 'faultString': 'Test Fault'})
        self.assertEqual(m, None)

        s = xmlrpclib.Marshaller().dumps(f)
        self.assertRaises(xmlrpclib.Fault, xmlrpclib.loads, s) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_xmlrpc.py

示例13: __init__

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import loads [as 别名]
def __init__(self, conn, dumps, loads):
        self._conn = conn
        self._dumps = dumps
        self._loads = loads
        for attr in ('fileno', 'close', 'poll', 'recv_bytes', 'send_bytes'):
            obj = getattr(conn, attr)
            setattr(self, attr, obj) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:connection.py

示例14: _xml_loads

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import loads [as 别名]
def _xml_loads(s):
    (obj,), method = xmlrpclib.loads(s)
    return obj 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:connection.py

示例15: test_default_encoding_issues

# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import loads [as 别名]
def test_default_encoding_issues(self):
        # SF bug #1115989: wrong decoding in '_stringify'
        utf8 = """<?xml version='1.0' encoding='iso-8859-1'?>
                  <params>
                    <param><value>
                      <string>abc \x95</string>
                      </value></param>
                    <param><value>
                      <struct>
                        <member>
                          <name>def \x96</name>
                          <value><string>ghi \x97</string></value>
                          </member>
                        </struct>
                      </value></param>
                  </params>
                  """

        # sys.setdefaultencoding() normally doesn't exist after site.py is
        # loaded.  Import a temporary fresh copy to get access to it
        # but then restore the original copy to avoid messing with
        # other potentially modified sys module attributes
        old_encoding = sys.getdefaultencoding()
        with test_support.CleanImport('sys'):
            import sys as temp_sys
            temp_sys.setdefaultencoding("iso-8859-1")
            try:
                (s, d), m = xmlrpclib.loads(utf8)
            finally:
                temp_sys.setdefaultencoding(old_encoding)

        items = d.items()
        if have_unicode:
            self.assertEqual(s, u"abc \x95")
            self.assertIsInstance(s, unicode)
            self.assertEqual(items, [(u"def \x96", u"ghi \x97")])
            self.assertIsInstance(items[0][0], unicode)
            self.assertIsInstance(items[0][1], unicode)
        else:
            self.assertEqual(s, "abc \xc2\x95")
            self.assertEqual(items, [("def \xc2\x96", "ghi \xc2\x97")]) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:43,代码来源:test_xmlrpc.py


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