/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 breezy/textfile.py

  • Committer: Jelmer Vernooij
  • Date: 2020-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Utilities for distinguishing binary files from text files"""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
from itertools import chain
22
20
 
23
21
from .errors import BinaryFile
30
28
    BinaryFile is raised if the file contains a NUL in the first 1024 bytes.
31
29
    """
32
30
    first_chunk = input.read(1024)
33
 
    if '\x00' in first_chunk:
 
31
    if b'\x00' in first_chunk:
34
32
        raise BinaryFile()
35
33
    return IterableFile(chain((first_chunk,), file_iterator(input)))
36
34
 
40
38
    Only the first 1024 characters are checked.
41
39
    """
42
40
    f = IterableFile(lines)
43
 
    if '\x00' in f.read(1024):
 
41
    if b'\x00' in f.read(1024):
44
42
        raise BinaryFile()
45
43
 
46
44
 
48
46
    """Check whether the supplied path is a text, not binary file.
49
47
    Raise BinaryFile if a NUL occurs in the first 1024 bytes.
50
48
    """
51
 
    f = open(path, 'rb')
52
 
    try:
 
49
    with open(path, 'rb') as f:
53
50
        text_file(f)
54
 
    finally:
55
 
        f.close()