5 Return a :class:`SerialisedSet` if given any non-empty string.
6 If given an empty string, return a :class:`DummySerialisedSet`.
9 return SerializedSet(seen_file)
11 return DummySerializedSet()
13 class ISerializedSet(object):
14 """A unique unordered collection of strings."""
16 """Adds a value into the set."""
17 raise NotImplementedError
19 class SerializedSet(ISerializedSet):
21 This set also records itself to a file, so that it
22 is persisted over multiple sessions.
24 def __init__(self, file):
26 if os.path.isfile(file):
27 for line in open(file, "r"):
28 self.set.add(line.rstrip())
29 self.file = open(file, "a")
30 def __contains__(self, name):
31 return name in self.set
33 """Adds a value into the set."""
35 self.file.write(name + "\n")
38 class DummySerializedSet(ISerializedSet):
40 Dummy object that doesn't actually cache anything and
41 claims that everything needs to be done.
43 def __contains__(self, name):
46 """Doesn't do anything."""