##// END OF EJS Templates
cleanup: remove compatibility code for Python < 2.7.4...
Manuel Jacob -
r45404:3aed7d26 default
parent child Browse files
Show More
@@ -2844,7 +2844,7 b' if pyplatform.python_implementation() =='
2844 # [1]: fixed by changeset 67dc99a989cd in the cpython hg repo.
2844 # [1]: fixed by changeset 67dc99a989cd in the cpython hg repo.
2845 #
2845 #
2846 # Here we workaround the EINTR issue for fileobj.__iter__. Other methods
2846 # Here we workaround the EINTR issue for fileobj.__iter__. Other methods
2847 # like "read*" are ignored for now, as Python < 2.7.4 is a minority.
2847 # like "read*" work fine, as we do not support Python < 2.7.4.
2848 #
2848 #
2849 # Although we can workaround the EINTR issue for fp.__iter__, it is slower:
2849 # Although we can workaround the EINTR issue for fp.__iter__, it is slower:
2850 # "for x in fp" is 4x faster than "for x in iter(fp.readline, '')" in
2850 # "for x in fp" is 4x faster than "for x in iter(fp.readline, '')" in
@@ -2856,39 +2856,6 b' if pyplatform.python_implementation() =='
2856 # affects things like pipes, sockets, ttys etc. We treat "normal" (S_ISREG)
2856 # affects things like pipes, sockets, ttys etc. We treat "normal" (S_ISREG)
2857 # files approximately as "fast" files and use the fast (unsafe) code path,
2857 # files approximately as "fast" files and use the fast (unsafe) code path,
2858 # to minimize the performance impact.
2858 # to minimize the performance impact.
2859 if sys.version_info >= (2, 7, 4):
2860 # fp.readline deals with EINTR correctly, use it as a workaround.
2861 def _safeiterfile(fp):
2862 return iter(fp.readline, b'')
2863
2864 else:
2865 # fp.read* are broken too, manually deal with EINTR in a stupid way.
2866 # note: this may block longer than necessary because of bufsize.
2867 def _safeiterfile(fp, bufsize=4096):
2868 fd = fp.fileno()
2869 line = b''
2870 while True:
2871 try:
2872 buf = os.read(fd, bufsize)
2873 except OSError as ex:
2874 # os.read only raises EINTR before any data is read
2875 if ex.errno == errno.EINTR:
2876 continue
2877 else:
2878 raise
2879 line += buf
2880 if b'\n' in buf:
2881 splitted = line.splitlines(True)
2882 line = b''
2883 for l in splitted:
2884 if l[-1] == b'\n':
2885 yield l
2886 else:
2887 line = l
2888 if not buf:
2889 break
2890 if line:
2891 yield line
2892
2859
2893 def iterfile(fp):
2860 def iterfile(fp):
2894 fastpath = True
2861 fastpath = True
@@ -2897,7 +2864,8 b' if pyplatform.python_implementation() =='
2897 if fastpath:
2864 if fastpath:
2898 return fp
2865 return fp
2899 else:
2866 else:
2900 return _safeiterfile(fp)
2867 # fp.readline deals with EINTR correctly, use it as a workaround.
2868 return iter(fp.readline, b'')
2901
2869
2902
2870
2903 else:
2871 else:
General Comments 0
You need to be logged in to leave comments. Login now