1 """This module provides core functions for handling unicode and UNIX quirks
3 OSX and others are known to interrupt system calls
5 http://en.wikipedia.org/wiki/PCLSRing
6 http://en.wikipedia.org/wiki/Unix_philosophy#Worse_is_better
8 The {read,write,wait}_nointr functions handle this situation
12 # Some files are not in UTF-8; some other aren't in any codification.
13 # Remember that GIT doesn't care about encodings (saves binary data)
19 # <-- add encodings here
23 """decode(encoded_string) returns an unencoded unicode string
25 for encoding
in _encoding_tests
:
27 return unicode(enc
.decode(encoding
))
30 # this shouldn't ever happen... FIXME
34 """encode(unencoded_string) returns a string encoded in utf-8
36 return unenc
.encode('utf-8', 'replace')
39 """Read from a filehandle and retry when interrupted"""
45 if e
.errno
== errno
.EINTR
:
49 if e
.errno
== errno
.EINTR
:
54 def write_nointr(fh
, content
):
55 """Write to a filehandle and retry when interrupted"""
58 content
= fh
.write(content
)
61 if e
.errno
== errno
.EINTR
:
65 if e
.errno
== errno
.EINTR
:
70 def wait_nointr(proc
):
71 """Wait on a subprocess and retry when interrupted"""
77 if e
.errno
== errno
.EINTR
:
81 if e
.errno
== errno
.EINTR
: