41
41
particular version is authentic but that it has other properties.
44
from cStringIO import StringIO
48
def contains_whitespace(s):
49
"""True if there are any whitespace characters in s."""
50
for ch in string.whitespace:
57
def contains_linebreaks(s):
58
"""True if there is any vertical whitespace in s."""
44
66
class Testament(object):
45
67
"""Reduced summary of a revision.
62
84
t.timezone = rev.timezone or 0
63
85
t.timestamp = rev.timestamp
64
86
t.message = rev.message
87
t.inventory = branch.get_inventory(revision_id)
90
def text_form_1_to_file(self, f):
91
"""Convert to externalizable text form.
93
The result is returned in utf-8, because it should be signed or
94
hashed in that encoding.
96
# TODO: Set right encoding
97
print >>f, 'bazaar-ng testament version 1'
98
assert not contains_whitespace(self.revision_id)
99
print >>f, 'revision-id:', self.revision_id
100
assert not contains_linebreaks(self.committer)
101
print >>f, 'committer:', self.committer
102
# TODO: perhaps write timestamp in a more readable form
103
print >>f, 'timestamp:', self.timestamp
104
print >>f, 'timezone:', self.timezone
105
# inventory length contains the root, which is not shown here
106
print >>f, 'entries:', len(self.inventory) - 1
107
print >>f, 'message:'
108
for l in self.message.splitlines():
111
def to_text_form_1(self):
113
self.text_form_1_to_file(s)