/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: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

Show diffs side-by-side

added added

removed removed

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