Skip to content

Commit

Permalink
Simplify further.
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarst committed Jul 24, 2015
1 parent d536844 commit b9b9017
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 32 deletions.
22 changes: 6 additions & 16 deletions examples/rometrip_actions.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
from __future__ import unicode_literals
from sys import stdout

from eliot import start_action, start_task, to_file
to_file(stdout)


class Person(object):
def __init__(self, name):
self.name = name


class Place(object):
def __init__(self, name, contained=()):
self.name = name
self.contained = contained

def visited(self, person):
with start_action(action_type="place:visited",
person=person.name,
place=self.name):
person=person, place=self.name):
for thing in self.contained:
thing.visited(person)


def honeymoon(family):
with start_task(action_type="honeymoon",
family=[person.name for person in family]):
rome = Place("Rome, Italy", [Place("Vatican Museum",
[Place("Statue #1"),
Place("Statue #2")])])
with start_task(action_type="honeymoon", family=family):
rome = Place("Rome, Italy",
[Place("Vatican Museum",
[Place("Statue #1"), Place("Statue #2")])])
for person in family:
rome.visited(person)


if __name__ == '__main__':
honeymoon([Person("Mrs. Casaubon"), Person("Mr. Casaubon")])
honeymoon(["Mrs. Casaubon", "Mr. Casaubon"])
22 changes: 6 additions & 16 deletions examples/rometrip_messages.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
from __future__ import unicode_literals
from sys import stdout

from eliot import Message, to_file
to_file(stdout)


class Person(object):
def __init__(self, name):
self.name = name


class Place(object):
def __init__(self, name, contained=()):
self.name = name
self.contained = contained

def visited(self, person):
Message.log(message_type="place:visited",
person=person.name,
place=self.name)
person=person, place=self.name)
for thing in self.contained:
thing.visited(person)


def honeymoon(family):
Message.log(message_type="honeymoon",
family=[person.name for person in family])
rome = Place("Rome, Italy", [Place("Vatican Museum",
[Place("Statue #1"),
Place("Statue #2")])])
Message.log(message_type="honeymoon", family=family)
rome = Place("Rome, Italy",
[Place("Vatican Museum",
[Place("Statue #1"), Place("Statue #2")])])
for person in family:
rome.visited(person)


if __name__ == '__main__':
honeymoon([Person("Mrs. Casaubon"), Person("Mr. Casaubon")])
honeymoon(["Mrs. Casaubon", "Mr. Casaubon"])

0 comments on commit b9b9017

Please sign in to comment.