本文整理匯總了Python中rhobot.components.storage.StoragePayload.add_type方法的典型用法代碼示例。如果您正苦於以下問題:Python StoragePayload.add_type方法的具體用法?Python StoragePayload.add_type怎麽用?Python StoragePayload.add_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rhobot.components.storage.StoragePayload
的用法示例。
在下文中一共展示了StoragePayload.add_type方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_response_received
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_type [as 別名]
def test_response_received(self):
publish_urn = 'rho:instances.owner'
payload = StoragePayload()
payload.add_type(FOAF.Person, RHO.Owner)
promise = self.rdf_publisher.send_out_request(payload)
args, kwargs = self.roster_plugin.send_message.call_args
payload = kwargs['payload']
thread_id = kwargs['thread_id']
response_payload = ResultCollectionPayload()
response_payload.append(ResultPayload(about=publish_urn, types=[FOAF.Person, RHO.Owner]))
self.rdf_publisher._send_message(RDFStanzaType.RESPONSE, response_payload, thread_id)
response_args, response_kwargs = self.roster_plugin.send_message.call_args
payload = response_kwargs['payload']
response_message = Message()
response_message.append(payload)
response_message['thread'] = response_kwargs['thread_id']
with mock.patch.object(promise, attribute='resolved') as mock_promise_resolve:
self.rdf_publisher._receive_message(response_message)
self.assertEqual(1, mock_promise_resolve.call_count)
args, kwargs = mock_promise_resolve.call_args
result = [rdf.about for rdf in args[0].results]
self.assertEqual(result, [publish_urn])
示例2: _create_interval
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_type [as 別名]
def _create_interval(self, session, form_payload):
"""
Convert the form payload into a storage payload for creating a new interval.
:param session:
:param form_payload:
:return:
"""
def _translate_search_to_about(result):
if result.results:
return result.results[0].about
raise RuntimeError('Interval was not created.')
# Handle the creation of the interval.
create_interval_payload = StoragePayload()
create_interval_payload.add_type(TIMELINE.Interval)
if 'event_start' in form_payload.get_values():
create_interval_payload.add_property(TIMELINE.start, form_payload.get_values()['event_start'])
if 'event_stop' in form_payload.get_values():
create_interval_payload.add_property(TIMELINE.end, form_payload.get_values()['event_stop'])
creator = self._representation_manager.representation_uri
if creator:
create_interval_payload.add_property(DCTERMS.creator, creator)
promise = self._storage_client.create_node(create_interval_payload)
promise = promise.then(_translate_search_to_about)
promise = promise.then(self._scheduler.generate_promise_handler(self._update_session, session, 'interval'))
return promise
示例3: test_basic_creation
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_type [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)
示例4: test_send_request
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_type [as 別名]
def test_send_request(self):
payload = StoragePayload()
payload.add_type(FOAF.Person, RHO.Owner)
request_promise = self.rdf_publisher.send_out_request(payload)
self.assertIsNotNone(request_promise)
self.assertTrue(hasattr(request_promise, 'then'))
# Verify the payload request.
self.assertEqual(1, self.roster_plugin.send_message.call_count)
args, kwargs = self.roster_plugin.send_message.call_args
self.assertIn('thread_id', kwargs)
self.assertIn('payload', kwargs)
# Must have a payload, and a thread_id
self.assertIsNotNone(kwargs['thread_id'])
self.assertIsNotNone(kwargs['payload'])
payload = kwargs['payload']
self.assertEqual(payload['type'], RDFStanzaType.REQUEST.value)
self.assertIn(str(FOAF.Person), payload['form'].get_fields()[str(RDF.type)].get_value())
self.assertIn(str(RHO.Owner), payload['form'].get_fields()[str(RDF.type)].get_value())
示例5: test_publish_create
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_type [as 別名]
def test_publish_create(self):
publish_urn = 'rho:instances.owner'
payload = StoragePayload()
payload.add_type(FOAF.Person, RHO.Owner)
payload.about = publish_urn
self.rdf_publisher.publish_create(payload)
self.assertEqual(1, self.roster_plugin.send_message.call_count)
args, kwargs = self.roster_plugin.send_message.call_args
self.assertIn('thread_id', kwargs)
self.assertIn('payload', kwargs)
self.assertIsNone(kwargs['thread_id'])
self.assertIsNotNone(kwargs['payload'])
payload = kwargs['payload']
self.assertEqual(payload['type'], RDFStanzaType.CREATE.value)
form = payload['form']
self.assertIsNotNone(form.get_fields()[str(RDF.type)])
values = form.get_fields()[str(RDF.type)].get_value()
self.assertIn(str(FOAF.Person), values)
self.assertIn(str(RHO.Owner), values)
self.assertIsNotNone(form.get_fields()[str(RDF.about)])
values = form.get_fields()[str(RDF.about)].get_value()
self.assertEqual(publish_urn, values)
示例6: test_pack_unpacked_payload
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_type [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)
示例7: test_get_node
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_type [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))
示例8: test_unpack
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_type [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)
示例9: convert_rdf_json_to_storage
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_type [as 別名]
def convert_rdf_json_to_storage(
definition, store_types=True, store_properties=True, store_bnodes=True, bnode_mappings=None
):
"""
Convert RDF JSON values into a storage payload.
:param definition: dictionary containing the json data.
:param store_types: should store the type values of the definition.
:param store_properties: should store the property values of the definition.
:param store_bnodes: should store the bnodes of the definition.
:param bnode_mappings: dictionary containing a translation key for the bnodes.
:return: newly created storage payload object.
"""
if not bnode_mappings:
bnode_mappings = {}
result = StoragePayload()
for node_uri, values in definition.iteritems():
if node_uri == str(RDF.type):
if store_types:
for value in values:
result.add_type(value["value"])
else:
for value in values:
if store_properties and value["type"] == "literal":
result.add_property(node_uri, value["value"])
elif store_bnodes and value["type"] == "bnode":
if value["value"] in bnode_mappings:
result.add_reference(node_uri, bnode_mappings[value["value"]])
else:
logger.error("Couldn't find bnode mapping for: %s" % value["value"])
return result
示例10: _create_event
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_type [as 別名]
def _create_event(self, session, form_payload):
"""
Convert the form payload into a storage payload for creating a new event.
:param session:
:param form_payload:
:return:
"""
create_event_payload = StoragePayload()
create_event_payload.add_type(EVENT.Event)
create_event_payload.add_reference(key=EVENT.agent, value=session['owner'])
create_event_payload.add_reference(key=DCTERMS.creator, value=self._representation_manager.representation_uri)
if 'title' in form_payload.get_values():
create_event_payload.add_property(key=DC.title, value=form_payload.get_values()['title'])
if 'description' in form_payload.get_values():
create_event_payload.add_property(key=DC.description, value=form_payload.get_values()['description'])
if session['location']:
create_event_payload.add_reference(key=EVENT.place, value=session['location'])
if session['interval']:
create_event_payload.add_reference(key=EVENT.time, value=session['interval'])
promise = self._storage_client.create_node(create_event_payload)
return promise
示例11: store_results
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_type [as 別名]
def store_results(self, payload, session):
"""
Store the results into the database.
:param payload:
:param session:
:return:
"""
logger.info('Payload: %s' % payload)
logger.info('Session: %s' % session)
storage_session = dict()
if 'locations' in payload.get_values():
storage_payload = StoragePayload()
storage_payload.about = payload.get_values()['locations']
storage_payload.add_type(WGS_84.SpatialThing)
promise = self._get_or_lookup(storage_payload).then(
self._scheduler.generate_promise_handler(self._update_session, storage_session, 'location'))
else:
promise = self._scheduler.defer(lambda: storage_session)
promise = promise.then(self._get_owner)
promise = promise.then(self._scheduler.generate_promise_handler(self._create_interval, payload))
promise = promise.then(self._scheduler.generate_promise_handler(self._create_event, payload))
promise = promise.then(lambda s: session)
session['payload'] = None
session['next'] = None
session['has_next'] = False
return promise
示例12: command_start
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_type [as 別名]
def command_start(self, request, initial_session):
"""
Provide the configuration details back to the requester and end the command.
:param request:
:param initial_session:
:return:
"""
storage = StoragePayload()
storage.add_type(FOAF.Person, RHO.Owner)
promise = self._storage_client.find_nodes(storage)
def find_nodes_processor(results):
"""
Process the results and place the payload into the initial session value.
:param results:
:return: the initial session value.
"""
initial_session['payload'] = results.populate_payload()
return initial_session
# Finish populating the rest of initial_session values.
initial_session['next'] = None
initial_session['has_next'] = False
return promise.then(find_nodes_processor)
示例13: _create_payload
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_type [as 別名]
def _create_payload(self):
update_payload = StoragePayload()
update_payload.add_type(FOAF.Agent, RDFS.Resource)
update_payload.add_property(RDFS.seeAlso, self.xmpp.get_uri())
update_payload.add_property(FOAF.name, self.xmpp.name)
return update_payload
示例14: test_handling
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_type [as 別名]
def test_handling(self):
payload = StoragePayload()
payload.add_type(WGS_84.SpatialThing)
self.assertTrue(self.search_handler._process_payload(payload))
payload.add_type(FOAF.Agent)
self.assertTrue(self.search_handler._process_payload(payload))
示例15: _publish_update
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_type [as 別名]
def _publish_update(self, storage_result):
publish_payload = StoragePayload()
publish_payload.about = storage_result.results[0].about
publish_payload.add_type(*storage_result.results[0].types)
self._node_id = publish_payload.about
self._rdf_publish.publish_update(publish_payload)