/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/testament.py

  • Committer: Vincent Ladeuil
  • Date: 2007-11-24 14:20:59 UTC
  • mto: (3928.1.1 bzr.integration)
  • mto: This revision was merged to the branch mainline in revision 3929.
  • Revision ID: v.ladeuil+lp@free.fr-20071124142059-2114qtsgfdv8g9p1
Ssl files needed for the test https server.

* bzrlib/tests/ssl_certs/create_ssls.py: 
Script to create the ssl keys and certificates.

* bzrlib/tests/ssl_certs/server.crt: 
Server certificate signed by the certificate authority.

* bzrlib/tests/ssl_certs/server.csr: 
Server certificate signing request.

* bzrlib/tests/ssl_certs/server_without_pass.key: 
Server key usable without password.

* bzrlib/tests/ssl_certs/server_with_pass.key: 
Server key.

* bzrlib/tests/ssl_certs/ca.key: 
Certificate authority private key.

* bzrlib/tests/ssl_certs/ca.crt: 
Certificate authority certificate.

* bzrlib/tests/ssl_certs/__init__.py: 
Provide access to ssl files (keys and certificates). 

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Testament - a summary of a revision for signing.
18
18
 
19
 
A testament can be defined as "something that serves as tangible
 
19
A testament can be defined as "something that serves as tangible 
20
20
proof or evidence."  In bzr we use them to allow people to certify
21
 
particular revisions as authentic.
 
21
particular revisions as authentic.  
22
22
 
23
23
The goal is that if two revisions are semantically equal, then they will
24
24
have a byte-for-byte equal testament.  We can define different versions of
61
61
 
62
62
# XXX: At the moment, clients trust that the graph described in a weave
63
63
# is accurate, but that's not covered by the testament.  Perhaps the best
64
 
# fix is when verifying a revision to make sure that every file mentioned
 
64
# fix is when verifying a revision to make sure that every file mentioned 
65
65
# in the revision has compatible ancestry links.
66
66
 
67
67
# TODO: perhaps write timestamp in a more readable form
81
81
class Testament(object):
82
82
    """Reduced summary of a revision.
83
83
 
84
 
    Testaments can be
 
84
    Testaments can be 
85
85
 
86
86
      - produced from a revision
87
87
      - written to a stream
109
109
        self.parent_ids = rev.parent_ids[:]
110
110
        self.inventory = inventory
111
111
        self.revprops = copy(rev.properties)
112
 
        if contains_whitespace(self.revision_id):
113
 
            raise ValueError(self.revision_id)
114
 
        if contains_linebreaks(self.committer):
115
 
            raise ValueError(self.committer)
 
112
        assert not contains_whitespace(self.revision_id)
 
113
        assert not contains_linebreaks(self.committer)
116
114
 
117
115
    def as_text_lines(self):
118
116
        """Yield text form as a sequence of lines.
130
128
        # inventory length contains the root, which is not shown here
131
129
        a('parents:\n')
132
130
        for parent_id in sorted(self.parent_ids):
133
 
            if contains_whitespace(parent_id):
134
 
                raise ValueError(parent_id)
 
131
            assert not contains_whitespace(parent_id)
135
132
            a('  %s\n' % parent_id)
136
133
        a('message:\n')
137
134
        for l in self.message.splitlines():
140
137
        for path, ie in self._get_entries():
141
138
            a(self._entry_to_line(path, ie))
142
139
        r.extend(self._revprops_to_lines())
 
140
        if __debug__:
 
141
            for l in r:
 
142
                assert isinstance(l, basestring), \
 
143
                    '%r of type %s is not a plain string' % (l, type(l))
143
144
        return [line.encode('utf-8') for line in r]
144
145
 
145
146
    def _get_entries(self):
148
149
        return entries
149
150
 
150
151
    def _escape_path(self, path):
151
 
        if contains_linebreaks(path):
152
 
            raise ValueError(path)
 
152
        assert not contains_linebreaks(path)
153
153
        return unicode(path.replace('\\', '/').replace(' ', '\ '))
154
154
 
155
155
    def _entry_to_line(self, path, ie):
156
156
        """Turn an inventory entry into a testament line"""
157
 
        if contains_whitespace(ie.file_id):
158
 
            raise ValueError(ie.file_id)
 
157
        assert not contains_whitespace(ie.file_id)
 
158
 
159
159
        content = ''
160
160
        content_spacer=''
161
161
        if ie.kind == 'file':
162
162
            # TODO: avoid switching on kind
163
 
            if not ie.text_sha1:
164
 
                raise AssertionError()
 
163
            assert ie.text_sha1
165
164
            content = ie.text_sha1
166
165
            content_spacer = ' '
167
166
        elif ie.kind == 'symlink':
168
 
            if not ie.symlink_target:
169
 
                raise AssertionError()
 
167
            assert ie.symlink_target
170
168
            content = self._escape_path(ie.symlink_target)
171
169
            content_spacer = ' '
172
170
 
180
178
 
181
179
    def as_short_text(self):
182
180
        """Return short digest-based testament."""
183
 
        return (self.short_header +
 
181
        return (self.short_header + 
184
182
                'revision-id: %s\n'
185
183
                'sha1: %s\n'
186
184
                % (self.revision_id, self.as_sha1()))
191
189
            return []
192
190
        r = ['properties:\n']
193
191
        for name, value in sorted(self.revprops.items()):
194
 
            if contains_whitespace(name):
195
 
                raise ValueError(name)
 
192
            assert isinstance(name, str)
 
193
            assert not contains_whitespace(name)
196
194
            r.append('  %s:\n' % name)
197
195
            for line in value.splitlines():
198
196
                r.append(u'    %s\n' % line)
218
216
 
219
217
class StrictTestament3(StrictTestament):
220
218
    """This testament format is for use as a checksum in bundle format 0.9+
221
 
 
 
219
    
222
220
    It differs from StrictTestament by including data about the tree root.
223
221
    """
224
222
 
228
226
        return self.inventory.iter_entries()
229
227
 
230
228
    def _escape_path(self, path):
231
 
        if contains_linebreaks(path):
232
 
            raise ValueError(path)
 
229
        assert not contains_linebreaks(path)
233
230
        if path == '':
234
231
            path = '.'
235
232
        return unicode(path.replace('\\', '/').replace(' ', '\ '))