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


Python tostring.tostring函数代码示例

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


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


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