本文整理匯總了Python中rhobot.components.storage.StoragePayload.add_flag方法的典型用法代碼示例。如果您正苦於以下問題:Python StoragePayload.add_flag方法的具體用法?Python StoragePayload.add_flag怎麽用?Python StoragePayload.add_flag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rhobot.components.storage.StoragePayload
的用法示例。
在下文中一共展示了StoragePayload.add_flag方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_unpack
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_flag [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)
示例2: test_pack_unpacked_payload
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_flag [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)
示例3: _update_interval
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_flag [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)
示例4: command_start
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_flag [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:
payload = StoragePayload(initial_session['payload'])
if logger.isEnabledFor(logging.DEBUG):
logger.debug('Find Node iq: %s' % iq)
logger.debug('Initial_session: %s' % initial_session)
logger.debug('about: %s' % payload.about)
logger.debug('relationships: %s' % payload.references)
logger.debug('properties: %s' % payload.properties)
logger.debug('types: %s' % payload.types)
created = False
nodes = self._command_handler.find_nodes(payload.types, **payload.properties)
if not nodes and FindFlags.CREATE_IF_MISSING.fetch_from(payload.flags):
node = self._command_handler.create_node(types=payload.types, properties=payload.properties,
relationships=payload.references)
created = True
nodes.append(node)
# Build up the form response containing the newly created uri
result_collection_payload = ResultCollectionPayload()
for node in nodes:
payload = ResultPayload(about=node.uri, types=node.labels)
if created:
payload.add_flag(FindResults.CREATED, True)
result_collection_payload.append(payload)
initial_session['payload'] = result_collection_payload.populate_payload()
return initial_session
示例5: _rdf_request_message
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_flag [as 別名]
def _rdf_request_message(self, rdf_payload):
"""
Find node to do work over.
:return:
"""
form = rdf_payload.get('form', None)
payload = StoragePayload(form)
if not self._process_payload(payload):
return None
translation_key = dict(json.loads(CypherFlags.TRANSLATION_KEY.default))
translation_key[str(SCHEMA.name)] = 'name'
translation_key[str(GRAPH.degree)] = 'rels'
logger.debug('Executing query: %s' % self.query)
payload = StoragePayload()
payload.add_property(key=NEO4J.cypher, value=self.query)
payload.add_flag(CypherFlags.TRANSLATION_KEY, json.dumps(translation_key))
promise = self._storage_client.execute_cypher(payload).then(self._process_results)
return promise