本文整理匯總了Python中rhobot.components.storage.StoragePayload.populate_payload方法的典型用法代碼示例。如果您正苦於以下問題:Python StoragePayload.populate_payload方法的具體用法?Python StoragePayload.populate_payload怎麽用?Python StoragePayload.populate_payload使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rhobot.components.storage.StoragePayload
的用法示例。
在下文中一共展示了StoragePayload.populate_payload方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_pack_unpacked_payload
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import populate_payload [as 別名]
def test_pack_unpacked_payload(self):
form = Form()
payload = StoragePayload(form)
about = "urn:rho:identified_by:asdf"
see_also = "urn:rho.value"
mbox = "mailto:[email protected]"
create_if_missing = True
payload.about = about
payload.add_type(FOAF.Person)
payload.add_property(RDFS.seeAlso, see_also)
payload.add_reference(FOAF.mbox, mbox)
payload.add_flag(FindFlags.CREATE_IF_MISSING, create_if_missing)
content = payload.populate_payload()
second_payload = StoragePayload(content)
second_content = second_payload.populate_payload()
self.assertIsNotNone(second_content)
self.assertEqual(second_content.get_fields()[str(RDF.about)].get_value(), about)
self.assertEqual(second_content.get_fields()[str(RDFS.seeAlso)].get_value(), [see_also])
self.assertEqual(second_content.get_fields()[str(FOAF.mbox)].get_value(), [mbox])
self.assertEqual(second_content.get_fields()[FindFlags.CREATE_IF_MISSING.var].get_value(), create_if_missing)
示例2: test_basic_creation
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import populate_payload [as 別名]
def test_basic_creation(self):
message = self.Message()
payload = StoragePayload()
payload.about = 'urn:rho:instance:owner'
payload.add_type(FOAF.Person, RHO.Owner)
rdf = RDFStanza()
rdf['type'] = RDFStanzaType.CREATE.value
rdf.append(payload.populate_payload())
message.append(rdf)
self.check(message, """
<message>
<rdf xmlns="urn:rho:rdf" type="create">
<x xmlns="jabber:x:data" type="form">
<field var="%s" type="text-single">
<value>%s</value>
</field>
<field var="%s" type="list-multi">
<value>%s</value>
<value>%s</value>
</field>
</x>
</rdf>
</message>
""" % (str(RDF.about), payload.about,
str(RDF.type), str(FOAF.Person), str(RHO.Owner), ), use_values=False)
示例3: test_unpack
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import populate_payload [as 別名]
def test_unpack(self):
form = Form()
payload = StoragePayload(form)
about = "urn:rho:identified_by:asdf"
see_also = "urn:rho.value"
mbox = "mailto:[email protected]"
create_if_missing = True
payload.about = about
payload.add_type(FOAF.Person)
payload.add_property(RDFS.seeAlso, see_also)
payload.add_reference(FOAF.mbox, mbox)
payload.add_flag(FindFlags.CREATE_IF_MISSING, create_if_missing)
content = payload.populate_payload()
second_payload = StoragePayload(content)
self.assertEqual(second_payload.about, about)
self.assertIn(str(FOAF.Person), second_payload.types)
self.assertEqual(second_payload.properties[str(RDFS.seeAlso)], [see_also])
self.assertEqual(second_payload.references[str(FOAF.mbox)], [mbox])
self.assertEqual(FindFlags.CREATE_IF_MISSING.fetch_from(second_payload.flags), create_if_missing)
示例4: test_get_node
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import populate_payload [as 別名]
def test_get_node(self):
self.storage_client._store_found('[email protected]/storage')
payload = StoragePayload()
payload.about = 'http://www.example.org/instance/01'
payload.add_type(FOAF.Person)
payload.add_property(FOAF.name, 'Robert')
promise = self.storage_client.get_node(payload)
def handle_result(result):
self.session['result'] = result
promise.then(handle_result)
self.assertTrue(hasattr(promise, 'then'))
self.send("""
<iq type="set" to="[email protected]/storage" id="1">
<command xmlns="http://jabber.org/protocol/commands"
node="get_node"
action="execute">
<x xmlns="jabber:x:data" type="form">
<field var="http://www.w3.org/1999/02/22-rdf-syntax-ns#about" type="text-single">
<value>http://www.example.org/instance/01</value>
</field>
<field var="http://www.w3.org/1999/02/22-rdf-syntax-ns#type" type="list-multi">
<value>http://xmlns.com/foaf/0.1/Person</value>
</field>
<field var="http://xmlns.com/foaf/0.1/name" type="list-multi">
<value>Robert</value>
<validate xmlns="http://jabber.org/protocol/xdata-validate" datatype="xs:string" />
</field>
</x>
</command>
</iq>
""")
self.assertNotIn('result', self.session)
self.recv("""
<iq type='result' from='[email protected]/storage' to='[email protected]/full' id='1'>
<command xmlns='http://jabber.org/protocol/commands'
sessionid='list:20020923T213616Z-700'
node='get_node'
status='completed'>
%s
</command>
</iq>
""" % payload.populate_payload())
time.sleep(0.2)
self.assertIn('result', self.session)
result = self.session['result']
self.assertEqual(result.about, 'http://www.example.org/instance/01')
self.assertEquals(result.types[0], str(FOAF.Person))
示例5: command_start
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import populate_payload [as 別名]
def command_start(self, iq, initial_session):
"""
Starting point for creating a new node.
:param iq:
:param initial_session:
:return:
"""
if not initial_session['payload']:
initial_session['notes'] = [('error', 'Cannot execute without a payload')]
else:
logger.info('Get Node iq: %s' % iq)
logger.info('Initial_session: %s' % initial_session)
payload = StoragePayload(initial_session['payload'])
logger.debug('about: %s' % payload.about)
node = self._command_handler.get_node(payload.about, create=False)
if node:
result_payload = StoragePayload()
result_payload.about = node.uri
# Get the types into place.
for label in node.labels:
result_payload.add_type(label)
# Gather up all of the references
for relationship in node.match_outgoing():
result_payload.add_reference(relationship.type, relationship.end_node.uri)
# Gather up all of the properties
for key, value in node.properties.iteritems():
if isinstance(value, list):
for val in value:
result_payload.add_property(key, val)
else:
result_payload.add_property(key, value)
initial_session['payload'] = result_payload.populate_payload()
return initial_session