MCPcopy Index your code
hub / github.com/python/cpython / supports_file2file_sendfile

Function supports_file2file_sendfile

Lib/test/test_shutil.py:128–154  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

126 return res
127
128def supports_file2file_sendfile():
129 # ...apparently Linux and Solaris are the only ones
130 if not hasattr(os, "sendfile"):
131 return False
132 srcname = None
133 dstname = None
134 try:
135 with tempfile.NamedTemporaryFile("wb", dir=os.getcwd(), delete=False) as f:
136 srcname = f.name
137 f.write(b"0123456789")
138
139 with open(srcname, "rb") as src:
140 with tempfile.NamedTemporaryFile("wb", dir=os.getcwd(), delete=False) as dst:
141 dstname = dst.name
142 infd = src.fileno()
143 outfd = dst.fileno()
144 try:
145 os.sendfile(outfd, infd, 0, 2)
146 except OSError:
147 return False
148 else:
149 return True
150 finally:
151 if srcname is not None:
152 os_helper.unlink(srcname)
153 if dstname is not None:
154 os_helper.unlink(dstname)
155
156
157SUPPORTS_SENDFILE = supports_file2file_sendfile()

Callers 1

test_shutil.pyFile · 0.85

Calls 5

openFunction · 0.50
writeMethod · 0.45
filenoMethod · 0.45
sendfileMethod · 0.45
unlinkMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…