本文整理匯總了Python中wishbone.event.Event.set方法的典型用法代碼示例。如果您正苦於以下問題:Python Event.set方法的具體用法?Python Event.set怎麽用?Python Event.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wishbone.event.Event
的用法示例。
在下文中一共展示了Event.set方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: generateEvent
# 需要導入模塊: from wishbone.event import Event [as 別名]
# 或者: from wishbone.event.Event import set [as 別名]
def generateEvent(self, data={}, destination=None):
'''
Generates a new event.
This function can get overridden by
``wishbone.module.InputModule._generateNativeEvent``.
The provided ``data`` will be traversed in search of valid templates
which then will be rendered.
Args:
data (``data``): The payload to add to the event.
destination (None): The destination key to write the data to
Returns:
wishbone.event.Event: An event containing ``data`` as a payload.
'''
if destination in [None, "data"]:
event = Wishbone_Event(data)
event.renderField(destination, self.env_template)
else:
event = Wishbone_Event()
event.set(data, destination)
event.renderField(destination, self.env_template)
return event
示例2: processEvent
# 需要導入模塊: from wishbone.event import Event [as 別名]
# 或者: from wishbone.event.Event import set [as 別名]
def processEvent(self, data, meta, queue):
'''
The callback executed for each Wishbone event to be created out of a
single http request.
'''
e = Event(data)
e.set(meta, 'tmp.%s' % (self.name))
e.renderKwargs(self.kwargs_template)
self.submit(e, queue)
return self.getResponse(e, queue)
示例3: test_file_load
# 需要導入模塊: from wishbone.event import Event [as 別名]
# 或者: from wishbone.event.Event import set [as 別名]
def test_file_load():
import os
import yaml
import shutil
os.mkdir('/tmp/wishbone_tests')
actor_config = ActorConfig('match', 100, 1, {}, "")
match = Match(actor_config, location="/tmp/wishbone_tests")
match.pool.createQueue("file")
match.pool.queue.file.disableFallThrough()
match.pool.queue.inbox.disableFallThrough()
#Test 1
rule_1 = {
"condition": [
{"file": "re:.*?one.*"}
],
"queue": [
{"file": {}}
]
}
with open('/tmp/wishbone_tests/one.yaml', 'w') as one:
one.write(yaml.dump(rule_1, default_flow_style=False))
match.start()
sleep(1)
e = Event("test")
e.set({"file": "zero one two"})
match.pool.queue.inbox.put(e)
assert getter(match.pool.queue.file).get()["file"] == "zero one two"
# Test 2
rule_2 = {
"condition": [
{"file": "re:.*?two.*"}
],
"queue": [
{"file": {}}
]
}
with open('/tmp/wishbone_tests/two.yaml', 'w') as one:
one.write(yaml.dump(rule_2, default_flow_style=False))
sleep(1)
e = Event("test")
e.set({"file": "one two three"})
match.pool.queue.inbox.put(e)
assert getter(match.pool.queue.file).get()["file"] == "one two three"
shutil.rmtree('/tmp/wishbone_tests')
示例4: test_bigger_than
# 需要導入模塊: from wishbone.event import Event [as 別名]
# 或者: from wishbone.event.Event import set [as 別名]
def test_bigger_than():
rule = {"bigger": {
"condition": [
{"bigger": ">:10"}
],
"queue": [
{"bigger": {}}
]
}}
actor = generate_actor(rule)
e = Event("test")
e.set({"bigger": "100"})
actor.pool.queue.inbox.put(e)
assert getter(actor.pool.queue.bigger).get()["bigger"] == "100"
示例5: test_module_graphite
# 需要導入模塊: from wishbone.event import Event [as 別名]
# 或者: from wishbone.event.Event import set [as 別名]
def test_module_graphite():
actor_config = ActorConfig('graphite', 100, 1, {}, "")
graphite = Graphite(actor_config, template='{type}.{source}.{name} {value} {time}')
graphite.pool.queue.inbox.disableFallThrough()
graphite.pool.queue.outbox.disableFallThrough()
graphite.start()
e = Event('test')
m = Metric(1381002603.726132, "wishbone", "hostname", "queue.outbox.in_rate", 0, "", ())
e.set(m)
graphite.pool.queue.inbox.put(e)
one = getter(graphite.pool.queue.outbox)
assert one.get() == "wishbone.hostname.queue.outbox.in_rate 0 1381002603.73"
示例6: test_negative_list_membership
# 需要導入模塊: from wishbone.event import Event [as 別名]
# 或者: from wishbone.event.Event import set [as 別名]
def test_negative_list_membership():
rule = {"list_membership": {
"condition": [
{"list_membership": "!in:test"}
],
"queue": [
{"list_membership": {}}
]
}}
actor = generate_actor(rule)
one = Event("test")
one.set({"list_membership": ["one", "three", "two"]})
actor.pool.queue.inbox.put(one)
assert "test" not in getter(actor.pool.queue.list_membership).get()["list_membership"]
示例7: test_not_equal_to
# 需要導入模塊: from wishbone.event import Event [as 別名]
# 或者: from wishbone.event.Event import set [as 別名]
def test_not_equal_to():
rule = {"equal": {
"condition": [
{"equal": "!=:100"}
],
"queue": [
{"equal": {}}
]
}}
actor = generate_actor(rule)
one = Event("test")
one.set({"equal": "101"})
actor.pool.queue.inbox.put(one)
assert int(getter(actor.pool.queue.equal).get()["equal"]) == 101
示例8: test_smaller_than
# 需要導入模塊: from wishbone.event import Event [as 別名]
# 或者: from wishbone.event.Event import set [as 別名]
def test_smaller_than():
rule = {"smaller": {
"condition": [
{"smaller": "<:100"}
],
"queue": [
{"smaller": {}}
]
}}
actor = generate_actor(rule)
one = Event("test")
one.set({"smaller": "99"})
actor.pool.queue.inbox.put(one)
assert int(getter(actor.pool.queue.smaller).get()["smaller"]) < 100
示例9: test_negative_regex
# 需要導入模塊: from wishbone.event import Event [as 別名]
# 或者: from wishbone.event.Event import set [as 別名]
def test_negative_regex():
rule = {"neg_regex": {
"condition": [
{"neg_regex": "!re:.*?two.*"}
],
"queue": [
{"neg_regex": {}}
]
}}
actor = generate_actor(rule)
e = Event("test")
e.set({"neg_regex": "one twwo three"})
actor.pool.queue.inbox.put(e)
assert getter(actor.pool.queue.neg_regex).get()["neg_regex"] == "one twwo three"
示例10: countDown
# 需要導入模塊: from wishbone.event import Event [as 別名]
# 或者: from wishbone.event.Event import set [as 別名]
def countDown(self):
while self.loop():
if self._counter > 0:
self._counter -= 1
sleep(1)
else:
self.logging.info("Timeout of %s seconds expired. Generated timeout event." % (self.kwargs.timeout))
self._incoming = False
while self.loop() and not self._incoming:
e = Event()
e.set(self.kwargs.timeout_payload)
self.submit(e, self.pool.queue.timeout)
self._sleeper(self.kwargs.repeat_interval)
self.logging.info("Incoming data resumed. Sending recovery event.")
e = Event()
e.set(self.kwargs.recovery_payload)
self.submit(e, self.pool.queue.timeout)
示例11: test_smaller_than_equal_to
# 需要導入模塊: from wishbone.event import Event [as 別名]
# 或者: from wishbone.event.Event import set [as 別名]
def test_smaller_than_equal_to():
rule = {"smaller_equal": {
"condition": [
{"smaller_equal": "<=:100"}
],
"queue": [
{"smaller_equal": {}}
]
}}
actor = generate_actor(rule)
one = Event("test")
one.set({"smaller_equal": "100"})
two = Event("test")
two.set({"smaller_equal": "99"})
actor.pool.queue.inbox.put(one)
actor.pool.queue.inbox.put(two)
assert int(getter(actor.pool.queue.smaller_equal).get()["smaller_equal"]) == 100
assert int(getter(actor.pool.queue.smaller_equal).get()["smaller_equal"]) < 100
示例12: scheduler
# 需要導入模塊: from wishbone.event import Event [as 別名]
# 或者: from wishbone.event.Event import set [as 別名]
def scheduler(self, url):
while self.loop():
try:
response = requests.get(
url,
auth=(self.kwargs.username, self.kwargs.password),
allow_redirects=self.kwargs.allow_redirects,
timeout=self.kwargs.timeout
)
except requests.exceptions.Timeout:
self.logging.warning("Timeout occurred fetching resource.")
except Exception as err:
self.logging.warning("Problem requesting resource. Reason: %s" % (err))
sleep(1)
else:
event = Event(response.text)
event.set(response.status_code, "@tmp.%s.status_code" % (self.name))
event.set(response.url, "@tmp.%s.url" % (self.name))
self.submit(event, self.pool.queue.outbox)
sleep(self.kwargs.interval)
示例13: handleMessage
# 需要導入模塊: from wishbone.event import Event [as 別名]
# 或者: from wishbone.event.Event import set [as 別名]
def handleMessage(self, message):
e = Event("\n".join(message.arguments))
e.set(message.type, '@tmp.%s.type' % (self.name))
e.set(message.source, '@tmp.%s.source' % (self.name))
if message.type == "pubmsg":
e.set(message.target, '@tmp.%s.channel' % (self.name))
self.submit(e, getattr(self.pool.queue, message.target.strip('#').lower()))
elif message.type == "privmsg":
self.submit(e, getattr(self.pool.queue, "priv__%s" % (self.kwargs.nickname)))
self.submit(e.clone(), self.pool.queue.outbox)
示例14: test_event_set
# 需要導入模塊: from wishbone.event import Event [as 別名]
# 或者: from wishbone.event.Event import set [as 別名]
def test_event_set():
e = Event({"one": 1, "two": {"three": 3}})
e.set({"four": 4}, "data.two.three")
assert e.dump()["data"]["two"]["three"]["four"] == 4