/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/patches.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
 
 
18
 
from __future__ import absolute_import
19
 
 
20
 
from .errors import (
21
 
    BzrError,
22
 
    )
23
 
 
24
 
import os
25
17
import re
26
18
 
27
19
 
28
 
binary_files_re = b'Binary files (.*) and (.*) differ\n'
29
 
 
30
 
 
31
 
class PatchSyntax(BzrError):
32
 
    """Base class for patch syntax errors."""
33
 
 
34
 
 
35
 
class BinaryFiles(BzrError):
36
 
 
37
 
    _fmt = 'Binary files section encountered.'
 
20
binary_files_re = 'Binary files (.*) and (.*) differ\n'
 
21
 
 
22
 
 
23
class BinaryFiles(Exception):
38
24
 
39
25
    def __init__(self, orig_name, mod_name):
40
26
        self.orig_name = orig_name
41
27
        self.mod_name = mod_name
 
28
        Exception.__init__(self, 'Binary files section encountered.')
 
29
 
 
30
 
 
31
class PatchSyntax(Exception):
 
32
    def __init__(self, msg):
 
33
        Exception.__init__(self, msg)
42
34
 
43
35
 
44
36
class MalformedPatchHeader(PatchSyntax):
45
 
 
46
 
    _fmt = "Malformed patch header.  %(desc)s\n%(line)r"
47
 
 
48
 
    def __init__(self, desc, line):
49
 
        self.desc = desc
50
 
        self.line = line
 
37
    def __init__(self, desc, line):
 
38
        self.desc = desc
 
39
        self.line = line
 
40
        msg = "Malformed patch header.  %s\n%r" % (self.desc, self.line)
 
41
        PatchSyntax.__init__(self, msg)
 
42
 
 
43
 
 
44
class MalformedHunkHeader(PatchSyntax):
 
45
    def __init__(self, desc, line):
 
46
        self.desc = desc
 
47
        self.line = line
 
48
        msg = "Malformed hunk header.  %s\n%r" % (self.desc, self.line)
 
49
        PatchSyntax.__init__(self, msg)
51
50
 
52
51
 
53
52
class MalformedLine(PatchSyntax):
54
 
 
55
 
    _fmt = "Malformed line.  %(desc)s\n%(line)r"
56
 
 
57
53
    def __init__(self, desc, line):
58
54
        self.desc = desc
59
55
        self.line = line
60
 
 
61
 
 
62
 
class PatchConflict(BzrError):
63
 
 
64
 
    _fmt = ('Text contents mismatch at line %(line_no)d.  Original has '
65
 
            '"%(orig_line)s", but patch says it should be "%(patch_line)s"')
66
 
 
 
56
        msg = "Malformed line.  %s\n%s" % (self.desc, self.line)
 
57
        PatchSyntax.__init__(self, msg)
 
58
 
 
59
 
 
60
class PatchConflict(Exception):
67
61
    def __init__(self, line_no, orig_line, patch_line):
68
 
        self.line_no = line_no
69
 
        self.orig_line = orig_line.rstrip('\n')
70
 
        self.patch_line = patch_line.rstrip('\n')
71
 
 
72
 
 
73
 
class MalformedHunkHeader(PatchSyntax):
74
 
 
75
 
    _fmt = "Malformed hunk header.  %(desc)s\n%(line)r"
76
 
 
77
 
    def __init__(self, desc, line):
78
 
        self.desc = desc
79
 
        self.line = line
 
62
        orig = orig_line.rstrip('\n')
 
63
        patch = str(patch_line).rstrip('\n')
 
64
        msg = 'Text contents mismatch at line %d.  Original has "%s",'\
 
65
            ' but patch says it should be "%s"' % (line_no, orig, patch)
 
66
        Exception.__init__(self, msg)
80
67
 
81
68
 
82
69
def get_patch_names(iter_lines):
83
 
    line = next(iter_lines)
84
70
    try:
 
71
        line = iter_lines.next()
85
72
        match = re.match(binary_files_re, line)
86
73
        if match is not None:
87
74
            raise BinaryFiles(match.group(1), match.group(2))
88
 
        if not line.startswith(b"--- "):
 
75
        if not line.startswith("--- "):
89
76
            raise MalformedPatchHeader("No orig name", line)
90
77
        else:
91
 
            orig_name = line[4:].rstrip(b"\n")
 
78
            orig_name = line[4:].rstrip("\n")
92
79
    except StopIteration:
93
80
        raise MalformedPatchHeader("No orig line", "")
94
81
    try:
95
 
        line = next(iter_lines)
96
 
        if not line.startswith(b"+++ "):
 
82
        line = iter_lines.next()
 
83
        if not line.startswith("+++ "):
97
84
            raise PatchSyntax("No mod name")
98
85
        else:
99
 
            mod_name = line[4:].rstrip(b"\n")
 
86
            mod_name = line[4:].rstrip("\n")
100
87
    except StopIteration:
101
88
        raise MalformedPatchHeader("No mod line", "")
102
89
    return (orig_name, mod_name)
110
97
    :return: the position and range, as a tuple
111
98
    :rtype: (int, int)
112
99
    """
113
 
    tmp = textrange.split(b',')
 
100
    tmp = textrange.split(',')
114
101
    if len(tmp) == 1:
115
102
        pos = tmp[0]
116
 
        range = b"1"
 
103
        range = "1"
117
104
    else:
118
105
        (pos, range) = tmp
119
106
    pos = int(pos)
123
110
 
124
111
def hunk_from_header(line):
125
112
    import re
126
 
    matches = re.match(br'\@\@ ([^@]*) \@\@( (.*))?\n', line)
 
113
    matches = re.match(r'\@\@ ([^@]*) \@\@( (.*))?\n', line)
127
114
    if matches is None:
128
115
        raise MalformedHunkHeader("Does not match format.", line)
129
116
    try:
130
 
        (orig, mod) = matches.group(1).split(b" ")
131
 
    except (ValueError, IndexError) as e:
 
117
        (orig, mod) = matches.group(1).split(" ")
 
118
    except (ValueError, IndexError), e:
132
119
        raise MalformedHunkHeader(str(e), line)
133
 
    if not orig.startswith(b'-') or not mod.startswith(b'+'):
 
120
    if not orig.startswith('-') or not mod.startswith('+'):
134
121
        raise MalformedHunkHeader("Positions don't start with + or -.", line)
135
122
    try:
136
123
        (orig_pos, orig_range) = parse_range(orig[1:])
137
124
        (mod_pos, mod_range) = parse_range(mod[1:])
138
 
    except (ValueError, IndexError) as e:
 
125
    except (ValueError, IndexError), e:
139
126
        raise MalformedHunkHeader(str(e), line)
140
127
    if mod_range < 0 or orig_range < 0:
141
128
        raise MalformedHunkHeader("Hunk range is negative", line)
143
130
    return Hunk(orig_pos, orig_range, mod_pos, mod_range, tail)
144
131
 
145
132
 
146
 
class HunkLine(object):
147
 
 
 
133
class HunkLine:
148
134
    def __init__(self, contents):
149
135
        self.contents = contents
150
136
 
151
137
    def get_str(self, leadchar):
152
 
        if self.contents == b"\n" and leadchar == b" " and False:
153
 
            return b"\n"
154
 
        if not self.contents.endswith(b'\n'):
155
 
            terminator = b'\n' + NO_NL
 
138
        if self.contents == "\n" and leadchar == " " and False:
 
139
            return "\n"
 
140
        if not self.contents.endswith('\n'):
 
141
            terminator = '\n' + NO_NL
156
142
        else:
157
 
            terminator = b''
 
143
            terminator = ''
158
144
        return leadchar + self.contents + terminator
159
145
 
160
 
    def as_bytes(self):
161
 
        raise NotImplementedError
162
 
 
163
146
 
164
147
class ContextLine(HunkLine):
165
 
 
166
148
    def __init__(self, contents):
167
149
        HunkLine.__init__(self, contents)
168
150
 
169
 
    def as_bytes(self):
170
 
        return self.get_str(b" ")
 
151
    def __str__(self):
 
152
        return self.get_str(" ")
171
153
 
172
154
 
173
155
class InsertLine(HunkLine):
174
156
    def __init__(self, contents):
175
157
        HunkLine.__init__(self, contents)
176
158
 
177
 
    def as_bytes(self):
178
 
        return self.get_str(b"+")
 
159
    def __str__(self):
 
160
        return self.get_str("+")
179
161
 
180
162
 
181
163
class RemoveLine(HunkLine):
182
164
    def __init__(self, contents):
183
165
        HunkLine.__init__(self, contents)
184
166
 
185
 
    def as_bytes(self):
186
 
        return self.get_str(b"-")
187
 
 
188
 
 
189
 
NO_NL = b'\\ No newline at end of file\n'
190
 
__pychecker__ = "no-returnvalues"
191
 
 
 
167
    def __str__(self):
 
168
        return self.get_str("-")
 
169
 
 
170
NO_NL = '\\ No newline at end of file\n'
 
171
__pychecker__="no-returnvalues"
192
172
 
193
173
def parse_line(line):
194
 
    if line.startswith(b"\n"):
 
174
    if line.startswith("\n"):
195
175
        return ContextLine(line)
196
 
    elif line.startswith(b" "):
 
176
    elif line.startswith(" "):
197
177
        return ContextLine(line[1:])
198
 
    elif line.startswith(b"+"):
 
178
    elif line.startswith("+"):
199
179
        return InsertLine(line[1:])
200
 
    elif line.startswith(b"-"):
 
180
    elif line.startswith("-"):
201
181
        return RemoveLine(line[1:])
202
182
    else:
203
183
        raise MalformedLine("Unknown line type", line)
204
 
 
205
 
 
206
 
__pychecker__ = ""
207
 
 
208
 
 
209
 
class Hunk(object):
210
 
 
 
184
__pychecker__=""
 
185
 
 
186
 
 
187
class Hunk:
211
188
    def __init__(self, orig_pos, orig_range, mod_pos, mod_range, tail=None):
212
189
        self.orig_pos = orig_pos
213
190
        self.orig_range = orig_range
218
195
 
219
196
    def get_header(self):
220
197
        if self.tail is None:
221
 
            tail_str = b''
 
198
            tail_str = ''
222
199
        else:
223
 
            tail_str = b' ' + self.tail
224
 
        return b"@@ -%s +%s @@%s\n" % (self.range_str(self.orig_pos,
225
 
                                                      self.orig_range),
226
 
                                       self.range_str(self.mod_pos,
227
 
                                                      self.mod_range),
228
 
                                       tail_str)
 
200
            tail_str = ' ' + self.tail
 
201
        return "@@ -%s +%s @@%s\n" % (self.range_str(self.orig_pos,
 
202
                                                     self.orig_range),
 
203
                                      self.range_str(self.mod_pos,
 
204
                                                     self.mod_range),
 
205
                                      tail_str)
229
206
 
230
207
    def range_str(self, pos, range):
231
208
        """Return a file range, special-casing for 1-line files.
237
214
        :return: a string in the format 1,4 except when range == pos == 1
238
215
        """
239
216
        if range == 1:
240
 
            return b"%i" % pos
 
217
            return "%i" % pos
241
218
        else:
242
 
            return b"%i,%i" % (pos, range)
 
219
            return "%i,%i" % (pos, range)
243
220
 
244
 
    def as_bytes(self):
 
221
    def __str__(self):
245
222
        lines = [self.get_header()]
246
223
        for line in self.lines:
247
 
            lines.append(line.as_bytes())
248
 
        return b"".join(lines)
249
 
 
250
 
    __bytes__ = as_bytes
 
224
            lines.append(str(line))
 
225
        return "".join(lines)
251
226
 
252
227
    def shift_to_mod(self, pos):
253
 
        if pos < self.orig_pos - 1:
 
228
        if pos < self.orig_pos-1:
254
229
            return 0
255
 
        elif pos > self.orig_pos + self.orig_range:
 
230
        elif pos > self.orig_pos+self.orig_range:
256
231
            return self.mod_range - self.orig_range
257
232
        else:
258
233
            return self.shift_to_mod_lines(pos)
259
234
 
260
235
    def shift_to_mod_lines(self, pos):
261
 
        position = self.orig_pos - 1
 
236
        position = self.orig_pos-1
262
237
        shift = 0
263
238
        for line in self.lines:
264
239
            if isinstance(line, InsertLine):
284
259
    '''
285
260
    hunk = None
286
261
    for line in iter_lines:
287
 
        if line == b"\n":
 
262
        if line == "\n":
288
263
            if hunk is not None:
289
264
                yield hunk
290
265
                hunk = None
303
278
        orig_size = 0
304
279
        mod_size = 0
305
280
        while orig_size < hunk.orig_range or mod_size < hunk.mod_range:
306
 
            hunk_line = parse_line(next(iter_lines))
 
281
            hunk_line = parse_line(iter_lines.next())
307
282
            hunk.lines.append(hunk_line)
308
283
            if isinstance(hunk_line, (RemoveLine, ContextLine)):
309
284
                orig_size += 1
314
289
 
315
290
 
316
291
class BinaryPatch(object):
317
 
 
318
292
    def __init__(self, oldname, newname):
319
293
        self.oldname = oldname
320
294
        self.newname = newname
321
295
 
322
 
    def as_bytes(self):
323
 
        return b'Binary files %s and %s differ\n' % (self.oldname, self.newname)
 
296
    def __str__(self):
 
297
        return 'Binary files %s and %s differ\n' % (self.oldname, self.newname)
324
298
 
325
299
 
326
300
class Patch(BinaryPatch):
329
303
        BinaryPatch.__init__(self, oldname, newname)
330
304
        self.hunks = []
331
305
 
332
 
    def as_bytes(self):
 
306
    def __str__(self):
333
307
        ret = self.get_header()
334
 
        ret += b"".join([h.as_bytes() for h in self.hunks])
 
308
        ret += "".join([str(h) for h in self.hunks])
335
309
        return ret
336
310
 
337
311
    def get_header(self):
338
 
        return b"--- %s\n+++ %s\n" % (self.oldname, self.newname)
 
312
        return "--- %s\n+++ %s\n" % (self.oldname, self.newname)
339
313
 
340
314
    def stats_values(self):
341
315
        """Calculate the number of inserts and removes."""
344
318
        for hunk in self.hunks:
345
319
            for line in hunk.lines:
346
320
                if isinstance(line, InsertLine):
347
 
                    inserts += 1
 
321
                     inserts+=1;
348
322
                elif isinstance(line, RemoveLine):
349
 
                    removes += 1
 
323
                     removes+=1;
350
324
        return (inserts, removes, len(self.hunks))
351
325
 
352
326
    def stats_str(self):
370
344
        :rtype: iterator of (int, InsertLine)
371
345
        """
372
346
        for hunk in self.hunks:
373
 
            pos = hunk.mod_pos - 1
 
347
            pos = hunk.mod_pos - 1;
374
348
            for line in hunk.lines:
375
349
                if isinstance(line, InsertLine):
376
350
                    yield (pos, line)
388
362
    iter_lines = iter_lines_handle_nl(iter_lines)
389
363
    try:
390
364
        (orig_name, mod_name) = get_patch_names(iter_lines)
391
 
    except BinaryFiles as e:
 
365
    except BinaryFiles, e:
392
366
        return BinaryPatch(e.orig_name, e.mod_name)
393
367
    else:
394
368
        patch = Patch(orig_name, mod_name)
397
371
        return patch
398
372
 
399
373
 
400
 
def iter_file_patch(iter_lines, allow_dirty=False, keep_dirty=False):
 
374
def iter_file_patch(iter_lines, allow_dirty=False):
401
375
    '''
402
376
    :arg iter_lines: iterable of lines to parse for patches
403
377
    :kwarg allow_dirty: If True, allow comments and other non-patch text
406
380
        first patch are stripped away in iter_hunks() if it is also passed
407
381
        allow_dirty=True.  Default False.
408
382
    '''
409
 
    # FIXME: Docstring is not quite true.  We allow certain comments no
 
383
    ### FIXME: Docstring is not quite true.  We allow certain comments no
410
384
    # matter what, If they startwith '===', '***', or '#' Someone should
411
385
    # reexamine this logic and decide if we should include those in
412
386
    # allow_dirty or restrict those to only being before the patch is found
413
387
    # (as allow_dirty does).
414
388
    regex = re.compile(binary_files_re)
415
389
    saved_lines = []
416
 
    dirty_head = []
417
390
    orig_range = 0
418
391
    beginning = True
419
 
 
420
392
    for line in iter_lines:
421
 
        if line.startswith(b'=== '):
422
 
            if len(saved_lines) > 0:
423
 
                if keep_dirty and len(dirty_head) > 0:
424
 
                    yield {'saved_lines': saved_lines,
425
 
                           'dirty_head': dirty_head}
426
 
                    dirty_head = []
427
 
                else:
428
 
                    yield saved_lines
429
 
                saved_lines = []
430
 
            dirty_head.append(line)
431
 
            continue
432
 
        if line.startswith(b'*** '):
433
 
            continue
434
 
        if line.startswith(b'#'):
 
393
        if line.startswith('=== ') or line.startswith('*** '):
 
394
            continue
 
395
        if line.startswith('#'):
435
396
            continue
436
397
        elif orig_range > 0:
437
 
            if line.startswith(b'-') or line.startswith(b' '):
 
398
            if line.startswith('-') or line.startswith(' '):
438
399
                orig_range -= 1
439
 
        elif line.startswith(b'--- ') or regex.match(line):
 
400
        elif line.startswith('--- ') or regex.match(line):
440
401
            if allow_dirty and beginning:
441
402
                # Patches can have "junk" at the beginning
442
403
                # Stripping junk from the end of patches is handled when we
443
404
                # parse the patch
444
405
                beginning = False
445
406
            elif len(saved_lines) > 0:
446
 
                if keep_dirty and len(dirty_head) > 0:
447
 
                    yield {'saved_lines': saved_lines,
448
 
                           'dirty_head': dirty_head}
449
 
                    dirty_head = []
450
 
                else:
451
 
                    yield saved_lines
 
407
                yield saved_lines
452
408
            saved_lines = []
453
 
        elif line.startswith(b'@@'):
 
409
        elif line.startswith('@@'):
454
410
            hunk = hunk_from_header(line)
455
411
            orig_range = hunk.orig_range
456
412
        saved_lines.append(line)
457
413
    if len(saved_lines) > 0:
458
 
        if keep_dirty and len(dirty_head) > 0:
459
 
            yield {'saved_lines': saved_lines,
460
 
                   'dirty_head': dirty_head}
461
 
        else:
462
 
            yield saved_lines
 
414
        yield saved_lines
463
415
 
464
416
 
465
417
def iter_lines_handle_nl(iter_lines):
472
424
    last_line = None
473
425
    for line in iter_lines:
474
426
        if line == NO_NL:
475
 
            if not last_line.endswith(b'\n'):
 
427
            if not last_line.endswith('\n'):
476
428
                raise AssertionError()
477
429
            last_line = last_line[:-1]
478
430
            line = None
483
435
        yield last_line
484
436
 
485
437
 
486
 
def parse_patches(iter_lines, allow_dirty=False, keep_dirty=False):
 
438
def parse_patches(iter_lines, allow_dirty=False):
487
439
    '''
488
440
    :arg iter_lines: iterable of lines to parse for patches
489
441
    :kwarg allow_dirty: If True, allow text that's not part of the patch at
490
442
        selected places.  This includes comments before and after a patch
491
443
        for instance.  Default False.
492
 
    :kwarg keep_dirty: If True, returns a dict of patches with dirty headers.
493
 
        Default False.
494
444
    '''
495
 
    for patch_lines in iter_file_patch(iter_lines, allow_dirty, keep_dirty):
496
 
        if 'dirty_head' in patch_lines:
497
 
            yield ({'patch': parse_patch(patch_lines['saved_lines'], allow_dirty),
498
 
                    'dirty_head': patch_lines['dirty_head']})
499
 
        else:
500
 
            yield parse_patch(patch_lines, allow_dirty)
 
445
    return [parse_patch(f.__iter__(), allow_dirty) for f in
 
446
                        iter_file_patch(iter_lines, allow_dirty)]
501
447
 
502
448
 
503
449
def difference_index(atext, btext):
515
461
        length = len(btext)
516
462
    for i in range(length):
517
463
        if atext[i] != btext[i]:
518
 
            return i
 
464
            return i;
519
465
    return None
520
466
 
521
467
 
541
487
        orig_lines = iter(orig_lines)
542
488
    for hunk in hunks:
543
489
        while line_no < hunk.orig_pos:
544
 
            orig_line = next(orig_lines)
 
490
            orig_line = orig_lines.next()
545
491
            yield orig_line
546
492
            line_no += 1
547
493
        for hunk_line in hunk.lines:
548
 
            seen_patch.append(hunk_line.contents)
 
494
            seen_patch.append(str(hunk_line))
549
495
            if isinstance(hunk_line, InsertLine):
550
496
                yield hunk_line.contents
551
497
            elif isinstance(hunk_line, (ContextLine, RemoveLine)):
552
 
                orig_line = next(orig_lines)
 
498
                orig_line = orig_lines.next()
553
499
                if orig_line != hunk_line.contents:
554
 
                    raise PatchConflict(line_no, orig_line,
555
 
                                        b''.join(seen_patch))
 
500
                    raise PatchConflict(line_no, orig_line, "".join(seen_patch))
556
501
                if isinstance(hunk_line, ContextLine):
557
502
                    yield orig_line
558
503
                else:
562
507
    if orig_lines is not None:
563
508
        for line in orig_lines:
564
509
            yield line
565
 
 
566
 
 
567
 
def apply_patches(tt, patches, prefix=1):
568
 
    """Apply patches to a TreeTransform.
569
 
 
570
 
    :param tt: TreeTransform instance
571
 
    :param patches: List of patches
572
 
    :param prefix: Number leading path segments to strip
573
 
    """
574
 
    def strip_prefix(p):
575
 
        return '/'.join(p.split('/')[1:])
576
 
 
577
 
    from breezy.bzr.generate_ids import gen_file_id
578
 
    # TODO(jelmer): Extract and set mode
579
 
    for patch in patches:
580
 
        if patch.oldname == b'/dev/null':
581
 
            trans_id = None
582
 
            orig_contents = b''
583
 
        else:
584
 
            oldname = strip_prefix(patch.oldname.decode())
585
 
            trans_id = tt.trans_id_tree_path(oldname)
586
 
            orig_contents = tt._tree.get_file_text(oldname)
587
 
            tt.delete_contents(trans_id)
588
 
 
589
 
        if patch.newname != b'/dev/null':
590
 
            newname = strip_prefix(patch.newname.decode())
591
 
            new_contents = iter_patched_from_hunks(
592
 
                orig_contents.splitlines(True), patch.hunks)
593
 
            if trans_id is None:
594
 
                parts = os.path.split(newname)
595
 
                trans_id = tt.root
596
 
                for part in parts[1:-1]:
597
 
                    trans_id = tt.new_directory(part, trans_id)
598
 
                tt.new_file(
599
 
                    parts[-1], trans_id, new_contents,
600
 
                    file_id=gen_file_id(newname))
601
 
            else:
602
 
                tt.create_file(new_contents, trans_id)
603
 
 
604
 
 
605
 
class AppliedPatches(object):
606
 
    """Context that provides access to a tree with patches applied.
607
 
    """
608
 
 
609
 
    def __init__(self, tree, patches, prefix=1):
610
 
        self.tree = tree
611
 
        self.patches = patches
612
 
        self.prefix = prefix
613
 
 
614
 
    def __enter__(self):
615
 
        from .transform import TransformPreview
616
 
        self._tt = TransformPreview(self.tree)
617
 
        apply_patches(self._tt, self.patches, prefix=self.prefix)
618
 
        return self._tt.get_preview_tree()
619
 
 
620
 
    def __exit__(self, exc_type, exc_value, exc_tb):
621
 
        self._tt.finalize()
622
 
        return False