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

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

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
 
19
21
from itertools import chain
20
22
 
21
 
from .errors import BinaryFile
22
 
from .iterablefile import IterableFile
23
 
from .osutils import file_iterator
 
23
from bzrlib.errors import BinaryFile
 
24
from bzrlib.iterablefile import IterableFile
 
25
from bzrlib.osutils import file_iterator
24
26
 
25
27
 
26
28
def text_file(input):
28
30
    BinaryFile is raised if the file contains a NUL in the first 1024 bytes.
29
31
    """
30
32
    first_chunk = input.read(1024)
31
 
    if b'\x00' in first_chunk:
 
33
    if '\x00' in first_chunk:
32
34
        raise BinaryFile()
33
35
    return IterableFile(chain((first_chunk,), file_iterator(input)))
34
36
 
38
40
    Only the first 1024 characters are checked.
39
41
    """
40
42
    f = IterableFile(lines)
41
 
    if b'\x00' in f.read(1024):
 
43
    if '\x00' in f.read(1024):
42
44
        raise BinaryFile()
43
45
 
44
46
 
46
48
    """Check whether the supplied path is a text, not binary file.
47
49
    Raise BinaryFile if a NUL occurs in the first 1024 bytes.
48
50
    """
49
 
    with open(path, 'rb') as f:
 
51
    f = open(path, 'rb')
 
52
    try:
50
53
        text_file(f)
 
54
    finally:
 
55
        f.close()