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

Python tostring.tostring函数代码示例

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

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



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

示例1: testConvertStruct

 def testConvertStruct(self):
     params = [{"foo": "bar", "baz": False}]
     params_xml = py2xml(*params)
     expected_xml = self.parse_xml("""
         <params xmlns="jabber:iq:rpc">
             <param>
                 <value>
                     <struct>
                         <member>
                             <name>foo</name>
                             <value><string>bar</string></value>
                         </member>
                         <member>
                             <name>baz</name>
                             <value><boolean>0</boolean></value>
                         </member>
                     </struct>
                 </value>
             </param>
         </params>
     """)
     self.assertTrue(self.compare(expected_xml, params_xml),
                     "Struct to XML conversion\nExpected: %s\nGot: %s" % (
                         tostring(expected_xml), tostring(params_xml)))
     self.assertEqual(params, xml2py(expected_xml),
                      "XML to struct conversion")
开发者ID:PADGETS-EU,项目名称:padgets-repo,代码行数:26,代码来源:test_stanza_xep_0009.py


示例2: recv_feature

    def recv_feature(self, data, method='mask', use_values=True, timeout=1):
        """
        """
        if method is None and hasattr(self, 'match_method'):
            method = getattr(self, 'match_method')

        if self.xmpp.socket.is_live:
            # we are working with a live connection, so we should
            # verify what has been received instead of simulating
            # receiving data.
            recv_data = self.xmpp.socket.next_recv(timeout)
            xml = self.parse_xml(data)
            recv_xml = self.parse_xml(recv_data)
            if recv_data is None:
                self.fail("No stanza was received.")
            if method == 'exact':
                self.failUnless(self.compare(xml, recv_xml),
                    "Features do not match.\nDesired:\n%s\nReceived:\n%s" % (
                        tostring(xml), tostring(recv_xml)))
            elif method == 'mask':
                matcher = MatchXMLMask(xml)
                self.failUnless(matcher.match(recv_xml),
                    "Stanza did not match using %s method:\n" % method + \
                    "Criteria:\n%s\n" % tostring(xml) + \
                    "Stanza:\n%s" % tostring(recv_xml))
            else:
                raise ValueError("Uknown matching method: %s" % method)
        else:
            # place the data in the dummy socket receiving queue.
            data = str(data)
            self.xmpp.socket.recv_data(data)
开发者ID:philipmarivoet,项目名称:SleekXMPP,代码行数:31,代码来源:sleektest.py


示例3: testConvertArray

 def testConvertArray(self):
     params = [[1,2,3], ('a', 'b', 'c')]
     params_xml = py2xml(*params)
     expected_xml = self.parse_xml("""
         <params xmlns="jabber:iq:rpc">
             <param>
                 <value>
                     <array>
                         <data>
                             <value><i4>1</i4></value>
                             <value><i4>2</i4></value>
                             <value><i4>3</i4></value>
                         </data>
                     </array>
                 </value>
             </param>
             <param>
                 <value>
                     <array>
                         <data>
                             <value><string>a</string></value>
                             <value><string>b</string></value>
                             <value><string>c</string></value>
                         </data>
                     </array>
                 </value>
             </param>
         </params>
     """)
     self.assertTrue(self.compare(expected_xml, params_xml),
                     "Array to XML conversion\nExpected: %s\nGot: %s" % (
                         tostring(expected_xml), tostring(params_xml)))
     self.assertEqual(list(map(list, params)), xml2py(expected_xml),
                      "XML to array conversion")
开发者ID:PADGETS-EU,项目名称:padgets-repo,代码行数:34,代码来源:test_stanza_xep_0009.py


示例4: testConvertBase64

 def testConvertBase64(self):
     params = [rpcbase64(base64.b64encode(b"Hello, world!"))]
     params_xml = py2xml(*params)
     expected_xml = self.parse_xml("""
         <params xmlns="jabber:iq:rpc">
             <param>
                 <value>
                     <base64>SGVsbG8sIHdvcmxkIQ==</base64>
                 </value>
             </param>
         </params>
     """)
     alternate_xml = self.parse_xml("""
         <params xmlns="jabber:iq:rpc">
             <param>
                 <value>
                     <Base64>SGVsbG8sIHdvcmxkIQ==</Base64>
                 </value>
             </param>
         </params>
     """)
     self.assertTrue(self.compare(expected_xml, params_xml),
                     "Base64 to XML conversion\nExpected: %s\nGot: %s" % (
                         tostring(expected_xml), tostring(params_xml)))
     self.assertEqual(list(map(lambda x: x.decode(), params)),
                      list(map(lambda x: x.decode(), xml2py(expected_xml))),
                      "XML to base64 conversion")
     self.assertEqual(list(map(lambda x: x.decode(), params)),
                      list(map(lambda x: x.decode(), xml2py(alternate_xml))),
                      "Alternate XML to base64 conversion")
开发者ID:PADGETS-EU,项目名称:padgets-repo,代码行数:30,代码来源:test_stanza_xep_0009.py


示例5: send_feature

 def send_feature(self, data, use_values=True, timeout=1):
     """
     """
     sent_data = self.xmpp.socket.next_sent(timeout)
     if sent_data is None:
         return False
     xml = self.parse_xml(data)
     sent_xml = self.parse_xml(sent_data)
     self.failUnless(self.compare(xml, sent_xml),
         "Features do not match.\nDesired:\n%s\nSent:\n%s" % (
             tostring(xml), tostring(sent_xml)))
开发者ID:EnerNOC,项目名称:smallfoot-sleekxmpp,代码行数:11,代码来源:sleektest.py


示例6: __init__

    def __init__(self, xmpp_msg):
        self.title = re.sub('([\n\r]+)', '. ', xmpp_msg['body'])
        self.pubdate = datetime.utcnow()
        self.project_id = None
        self.story_id = None
        self.categories = []
        self.text = None
        self.tags = None
        self.status = None
        self.color = None
        self.creator = None
        self.creator_mail = None
        self.content = None
        self.content_plain = None

        source = tostring(xmpp_msg['html']['body'])
        self._load_project_and_story(source)
        self.link = 'https://agilezen.com' \
            + '/project/' + str(self.project_id) \
            + '/story/' + str(self.story_id)
        self.guid = self.link + '#' + xmpp_msg['id']
        match = re.search(CAUSER_RE, source, re.UNICODE)
        if match:
            self.causer = match.group(1)
        self._load_additional_data()
开发者ID:alienhard,项目名称:notify,代码行数:25,代码来源:message.py


示例7: testConvertNil

 def testConvertNil(self):
     params = [None]
     params_xml = py2xml(*params)
     expected_xml = self.parse_xml("""
         <params xmlns="jabber:iq:rpc">
             <param>
                 <value>
                     <nil />
                 </value>
             </param>
         </params>
     """)
     self.assertTrue(self.compare(expected_xml, params_xml),
                     "Nil to XML conversion\nExpected: %s\nGot: %s" % (
                         tostring(expected_xml), tostring(params_xml)))
     self.assertEqual(params, xml2py(expected_xml),
                      "XML to nil conversion")
开发者ID:PADGETS-EU,项目名称:padgets-repo,代码行数:17,代码来源:test_stanza_xep_0009.py


示例8: testConvertDouble

 def testConvertDouble(self):
     params = [3.14159265]
     params_xml = py2xml(*params)
     expected_xml = self.parse_xml("""
         <params xmlns="jabber:iq:rpc">
             <param>
                 <value>
                     <double>3.14159265</double>
                 </value>
             </param>
         </params>
     """)
     self.assertTrue(self.compare(expected_xml, params_xml),
                     "Double to XML conversion\nExpected: %s\nGot: %s" % (
                         tostring(expected_xml), tostring(params_xml)))
     self.assertEqual(params, xml2py(expected_xml),
                      "XML to double conversion")
开发者ID:PADGETS-EU,项目名称:padgets-repo,代码行数:17,代码来源:test_stanza_xep_0009.py


示例9: testConvertString

 def testConvertString(self):
     params = ["'This' & \"That\""]
     params_xml = py2xml(*params)
     expected_xml = self.parse_xml("""
         <params xmlns="jabber:iq:rpc">
             <param>
                 <value>
                     <string>&apos;This&apos; &amp; &quot;That&quot;</string>
                 </value>
             </param>
         </params>
     """)
     self.assertTrue(self.compare(expected_xml, params_xml),
                     "String to XML conversion\nExpected: %s\nGot: %s" % (
                         tostring(expected_xml), tostring(params_xml)))
     self.assertEqual(params, xml2py(expected_xml),
                     "XML to string conversion")
开发者ID:PADGETS-EU,项目名称:padgets-repo,代码行数:17,代码来源:test_stanza_xep_0009.py


示例10: testConvertUnicodeString

 def testConvertUnicodeString(self):
     params = ["おはよう"]
     params_xml = py2xml(*params)
     expected_xml = self.parse_xml("""
         <params xmlns="jabber:iq:rpc">
             <param>
                 <value>
                     <string>おはよう</string>
                 </value>
             </param>
         </params>
     """)
     self.assertTrue(self.compare(expected_xml, params_xml),
                     "String to XML conversion\nExpected: %s\nGot: %s" % (
                         tostring(expected_xml), tostring(params_xml)))
     self.assertEqual(params, xml2py(expected_xml),
                     "XML to string conversion")
开发者ID:2M1R,项目名称:SleekXMPP,代码行数:17,代码来源:test_stanza_xep_0009.py


示例11: testConvertDateTime

 def testConvertDateTime(self):
     params = [rpctime("20111220T01:50:00")]
     params_xml = py2xml(*params)
     expected_xml = self.parse_xml("""
         <params xmlns="jabber:iq:rpc">
             <param>
                 <value>
                     <dateTime.iso8601>20111220T01:50:00</dateTime.iso8601>
                 </value>
             </param>
         </params>
     """)
     self.assertTrue(self.compare(expected_xml, params_xml),
                     "DateTime to XML conversion\nExpected: %s\nGot: %s" % (
                         tostring(expected_xml), tostring(params_xml)))
     self.assertEqual(list(map(lambda x: x.iso8601(), params)),
                      list(map(lambda x: x.iso8601(), xml2py(expected_xml))),
                      None)
开发者ID:PADGETS-EU,项目名称:padgets-repo,代码行数:18,代码来源:test_stanza_xep_0009.py


示例12: recv_feature

 def recv_feature(self, data, use_values=True, timeout=1):
     """
     """
     if self.xmpp.socket.is_live:
         # we are working with a live connection, so we should
         # verify what has been received instead of simulating
         # receiving data.
         recv_data = self.xmpp.socket.next_recv(timeout)
         if recv_data is None:
             return False
         xml = self.parse_xml(data)
         recv_xml = self.parse_xml(recv_data)
         self.failUnless(self.compare(xml, recv_xml),
             "Features do not match.\nDesired:\n%s\nReceived:\n%s" % (
                 tostring(xml), tostring(recv_xml)))
     else:
         # place the data in the dummy socket receiving queue.
         data = str(data)
         self.xmpp.socket.recv_data(data)
开发者ID:EnerNOC,项目名称:smallfoot-sleekxmpp,代码行数:19,代码来源:sleektest.py


示例13: __str__

    def __str__(self, top_level_ns=True):
        """
        Return a string serialization of the underlying XML object.

        Arguments:
            top_level_ns -- Display the top-most namespace.
                            Defaults to True.
        """
        stanza_ns = '' if top_level_ns else self.namespace
        return tostring(self.xml, xmlns='', stanza_ns=stanza_ns)
开发者ID:macdiesel,项目名称:SleekXMPP,代码行数:10,代码来源:stanzabase.py


示例14: send_feature

 def send_feature(self, data, method='mask', use_values=True, timeout=1):
     """
     """
     sent_data = self.xmpp.socket.next_sent(timeout)
     xml = self.parse_xml(data)
     sent_xml = self.parse_xml(sent_data)
     if sent_data is None:
         self.fail("No stanza was sent.")
     if method == 'exact':
         self.failUnless(self.compare(xml, sent_xml),
             "Features do not match.\nDesired:\n%s\nReceived:\n%s" % (
                 tostring(xml), tostring(sent_xml)))
     elif method == 'mask':
         matcher = MatchXMLMask(xml)
         self.failUnless(matcher.match(sent_xml),
             "Stanza did not match using %s method:\n" % method + \
             "Criteria:\n%s\n" % tostring(xml) + \
             "Stanza:\n%s" % tostring(sent_xml))
     else:
         raise ValueError("Uknown matching method: %s" % method)
开发者ID:philipmarivoet,项目名称:SleekXMPP,代码行数:20,代码来源:sleektest.py


示例15: __str__

    def __str__(self, top_level_ns=False):
        """Serialize the stanza's XML to a string.

        :param bool top_level_ns: Display the top-most namespace.
                                  Defaults to ``False``.
        """
        stanza_ns = '' if top_level_ns else self.namespace
        return tostring(self.xml, xmlns='',
                        stanza_ns=stanza_ns,
                        stream=self.stream,
                        top_level=not top_level_ns)
开发者ID:Lujeni,项目名称:old-projects,代码行数:11,代码来源:stanzabase.py


示例16: tryTostring

 def tryTostring(self, original='', expected=None, message='', **kwargs):
     """
     Compare the result of calling tostring against an
     expected result.
     """
     if not expected:
         expected=original
     if isinstance(original, str):
         xml = ET.fromstring(original)
     else:
         xml=original
     result = tostring(xml, **kwargs)
     self.failUnless(result == expected, "%s: %s" % (message, result))
开发者ID:AmiZya,项目名称:emesene,代码行数:13,代码来源:test_tostring.py


示例17: testConvertBoolean

 def testConvertBoolean(self):
     params = [True, False]
     params_xml = py2xml(*params)
     expected_xml = self.parse_xml("""
         <params xmlns="jabber:iq:rpc">
             <param>
                 <value>
                     <boolean>1</boolean>
                 </value>
             </param>
             <param>
                 <value>
                     <boolean>0</boolean>
                 </value>
             </param>
         </params>
     """)
     self.assertTrue(self.compare(expected_xml, params_xml),
                     "Boolean to XML conversion\nExpected: %s\nGot: %s" % (
                         tostring(expected_xml), tostring(params_xml)))
     self.assertEqual(params, xml2py(expected_xml),
                      "XML to boolean conversion")
开发者ID:PADGETS-EU,项目名称:padgets-repo,代码行数:22,代码来源:test_stanza_xep_0009.py


示例18: testConvertInteger

 def testConvertInteger(self):
     params = [32767, -32768]
     params_xml = py2xml(*params)
     expected_xml = self.parse_xml("""
         <params xmlns="jabber:iq:rpc">
             <param>
                 <value>
                     <i4>32767</i4>
                 </value>
             </param>
             <param>
                 <value>
                     <i4>-32768</i4>
                 </value>
             </param>
         </params>
     """)
     alternate_xml = self.parse_xml("""
         <params xmlns="jabber:iq:rpc">
             <param>
                 <value>
                     <int>32767</int>
                 </value>
             </param>
             <param>
                 <value>
                     <int>-32768</int>
                 </value>
             </param>
         </params>
     """)
     self.assertTrue(self.compare(expected_xml, params_xml),
                     "Integer to XML conversion\nExpected: %s\nGot: %s" % (
                         tostring(expected_xml), tostring(params_xml)))
     self.assertEqual(params, xml2py(expected_xml),
                      "XML to boolean conversion")
     self.assertEqual(params, xml2py(alternate_xml),
                      "Alternate XML to boolean conversion")
开发者ID:PADGETS-EU,项目名称:padgets-repo,代码行数:38,代码来源:test_stanza_xep_0009.py


示例19: rsync

    def rsync(self, project, files=None):
        """ Starts a rsync transaction, rsync and stop the
        transaction.

        Raises a BaboonException if there's a problem.
        """

        # Verify if the connection is established. Otherwise, wait...
        if not self.connected.is_set():
            self.connected.wait()

        # Set the rsync flags.
        self.rsync_running.set()
        self.rsync_finished.clear()

        #TODO: make this an int while checking config file
        max_stanza_size = int(config['server']['max_stanza_size'])

        # Build first stanza
        iq = self._build_iq(project, files)

        try:
            # Get the size of the stanza
            to_xml = tostring(iq.xml)
            size = sys.getsizeof(to_xml)

            # If it's bigger than the max_stanza_size, split it !
            if size >= max_stanza_size:
                iqs = self._split_iq(size, project, files)
                self.logger.warning('The xml stanza has been split %s stanzas.'
                                    % len(iqs))
            else:
                # Else the original iq will be the only element to send
                iqs = [iq]

            # Send elements in list
            for iq in iqs:
                iq.send()
                self.logger.debug('Sent (%d/%d)!' %
                                  (iqs.index(iq) + 1, len(iqs)))

        except IqError as e:
            self.rsync_error(e.iq['error']['text'])
        except Exception as e:
            self.rsync_error(e)
开发者ID:jplana,项目名称:baboon,代码行数:45,代码来源:transport.py


示例20: recv_header

    def recv_header(self, sto='',
                          sfrom='',
                          sid='',
                          stream_ns="http://etherx.jabber.org/streams",
                          default_ns="jabber:client",
                          version="1.0",
                          xml_header=False,
                          timeout=1):
        """
        Check that a given stream header was received.

        Arguments:
            sto        -- The recipient of the stream header.
            sfrom      -- The agent sending the stream header.
            sid        -- The stream's id. Set to None to ignore.
            stream_ns  -- The namespace of the stream's root element.
            default_ns -- The default stanza namespace.
            version    -- The stream version.
            xml_header -- Indicates if the XML version header should be
                          appended before the stream header.
            timeout    -- Length of time to wait in seconds for a
                          response.
        """
        header = self.make_header(sto, sfrom, sid,
                                  stream_ns=stream_ns,
                                  default_ns=default_ns,
                                  version=version,
                                  xml_header=xml_header)
        recv_header = self.xmpp.socket.next_recv(timeout)
        if recv_header is None:
            raise ValueError("Socket did not return data.")

        # Apply closing elements so that we can construct
        # XML objects for comparison.
        header2 = header + '</stream:stream>'
        recv_header2 = recv_header + '</stream:stream>'

        xml = self.parse_xml(header2)
        recv_xml = self.parse_xml(recv_header2)

        if sid is None:
            # Ignore the id sent by the server since
            # we can't know in advance what it will be.
            if 'id' in recv_xml.attrib:
                del recv_xml.attrib['id']

        # Ignore the xml:lang attribute for now.
        if 'xml:lang' in recv_xml.attrib:
            del recv_xml.attrib['xml:lang']
        xml_ns = 'http://www.w3.org/XML/1998/namespace'
        if '{%s}lang' % xml_ns in recv_xml.attrib:
            del recv_xml.attrib['{%s}lang' % xml_ns]

        if recv_xml.getchildren:
            # We received more than just the header
            for xml in recv_xml.getchildren():
                self.xmpp.socket.recv_data(tostring(xml))

            attrib = recv_xml.attrib
            recv_xml.clear()
            recv_xml.attrib = attrib

        self.failUnless(
            self.compare(xml, recv_xml),
            "Stream headers do not match:\nDesired:\n%s\nReceived:\n%s" % (
                '%s %s' % (xml.tag, xml.attrib),
                '%s %s' % (recv_xml.tag, recv_xml.attrib)))
开发者ID:philipmarivoet,项目名称:SleekXMPP,代码行数:67,代码来源:sleektest.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python slicer.qMRMLNodeComboBox函数代码示例发布时间:2022-05-27
下一篇:
Python xmlstream.XMLStream类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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