/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: John Arbash Meinel
  • Date: 2006-04-25 15:05:42 UTC
  • mfrom: (1185.85.85 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060425150542-c7b518dca9928691
[merge] the old bzr-encoding changes, reparenting them on bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006 by Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
"""Utilities for distinguishing binary files from text files"""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
 
from itertools import chain
22
 
 
23
 
from .errors import BinaryFile
24
 
from .iterablefile import IterableFile
25
 
from .osutils import file_iterator
 
19
from itertools import chain 
 
20
 
 
21
from bzrlib.errors import BinaryFile
 
22
from bzrlib.iterablefile import IterableFile
 
23
from bzrlib.osutils import file_iterator
26
24
 
27
25
 
28
26
def text_file(input):
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 b'\x00' in first_chunk:
 
31
    if '\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 b'\x00' in f.read(1024):
 
41
    if '\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
 
    with open(path, 'rb') as f:
52
 
        text_file(f)
 
49
    text_file(open(path, 'rb'))