本文整理匯總了Python中rhobot.components.storage.StoragePayload.about方法的典型用法代碼示例。如果您正苦於以下問題:Python StoragePayload.about方法的具體用法?Python StoragePayload.about怎麽用?Python StoragePayload.about使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rhobot.components.storage.StoragePayload
的用法示例。
在下文中一共展示了StoragePayload.about方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: store_results
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import about [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
示例2: test_basic_creation
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import about [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_publish_create
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import about [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)
示例4: test_pack_unpacked_payload
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import about [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)
示例5: test_unpack
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import about [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)
示例6: test_get_node
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import about [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))
示例7: _publish_update
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import about [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)
示例8: _get_node
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import about [as 別名]
def _get_node(self, uri):
"""
Retrieve the actual node.
:param uri:
:return:
"""
get_payload = StoragePayload()
get_payload.about = uri
return self._storage_client.get_node(get_payload)
示例9: publish_all_results
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import about [as 別名]
def publish_all_results(self, result_collection, created=True):
"""
Publish all of the results in the collection to the correct type.
:param result_collection: collection to publish the results of.
:return:
"""
for res in result_collection.results:
publish_payload = StoragePayload()
publish_payload.about = res.about
publish_payload.add_type(*res.types)
if created:
self.publish_create(publish_payload)
else:
self.publish_update(publish_payload)
示例10: _handle_create_and_update_session
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import about [as 別名]
def _handle_create_and_update_session(_result):
timeline = _result.results[0].about
update_payload = StoragePayload()
update_payload.about = timeline_map.about
update_payload.add_reference(TIMELINE.rangeTimeLine, timeline)
# Publish the create event
self._rdf_publish.publish_all_results(_result, created=True)
_promise = self._storage_client.update_node(update_payload)
_promise = _promise.then(
self._scheduler.generate_promise_handler(self._rdf_publish.publish_all_results, created=False)
)
_promise = _promise.then(lambda s: timeline)
return _promise
示例11: _update_interval
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import about [as 別名]
def _update_interval(self, session):
"""
Now that the timeline stuff has been found, update the interval as well.
:param session:
:return:
"""
def return_session(result):
self._rdf_publish.publish_all_results(result, created=False)
return session
update_payload = StoragePayload()
update_payload.about = session["node"].about
update_payload.add_reference(TIMELINE.timeline, session["timelines"])
update_payload.add_flag(UpdateFlags.REPLACE_DEFINED, True)
return self._storage_client.update_node(update_payload).then(return_session)
示例12: lookup_foursquare_content
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import about [as 別名]
def lookup_foursquare_content(self, node_uri, foursquare_identifier=None):
"""
Looks up the foursquare details of a venue.
:param node_uri: the uri of the node to look up.
:param foursquare_identifier: the identifier of the foursquare data. If this is not provided, the node will be
fetched and the first seeAlso property from the node will be used as this parameter.
:return:
"""
def update_venue_details(venue):
# No point in continuing this exercise if certain requirements are not resolved.
if not venue:
raise RuntimeError('Venue identifier is not defined')
if not self._foursquare_client:
raise RuntimeError('Foursquare client is not defined')
# Finished checking requirements, fetch the details and update.
logger.debug('Looking up venue: %s' % venue)
venue_details = self._foursquare_client.venues(venue)
# Translate the venue details into a rdf storage payload for sending to update.
if 'venue' in venue_details:
storage_payload = StoragePayload()
foursquare_to_storage(venue_details['venue'], storage_payload)
storage_payload.about = node_uri
storage_payload.add_reference(DCTERMS.creator, self._representation_manager.representation_uri)
return self._storage_client.update_node(storage_payload)
# Attempt to look up the venue id from the details in the node.
if foursquare_identifier is None:
search_payload = StoragePayload()
search_payload.about = node_uri
promise = self._storage_client.get_node(search_payload).then(self._handle_get_node)
else:
promise = self._scheduler.promise()
venue_identifier = get_foursquare_venue_from_url(foursquare_identifier)
promise.resolved(venue_identifier)
promise = promise.then(update_venue_details)
return promise
示例13: command_start
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import about [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
示例14: update_venue_details
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import about [as 別名]
def update_venue_details(venue):
# No point in continuing this exercise if certain requirements are not resolved.
if not venue:
raise RuntimeError('Venue identifier is not defined')
if not self._foursquare_client:
raise RuntimeError('Foursquare client is not defined')
# Finished checking requirements, fetch the details and update.
logger.debug('Looking up venue: %s' % venue)
venue_details = self._foursquare_client.venues(venue)
# Translate the venue details into a rdf storage payload for sending to update.
if 'venue' in venue_details:
storage_payload = StoragePayload()
foursquare_to_storage(venue_details['venue'], storage_payload)
storage_payload.about = node_uri
storage_payload.add_reference(DCTERMS.creator, self._representation_manager.representation_uri)
return self._storage_client.update_node(storage_payload)
示例15: _get_interval_properties
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import about [as 別名]
def _get_interval_properties(self, session):
"""
Fetch the properties of the the node stored in the session.
:param session:
:return:
"""
def _handle_get_results(_result):
if not _result.about:
# This is a weird case, and should never happen
raise Exception("Node does not exist")
session["node"] = _result
return session
payload = StoragePayload()
payload.about = session["node_uri"]
promise = self._storage_client.get_node(payload).then(_handle_get_results)
return promise