##// END OF EJS Templates
worker: implement _blockingreader.readinto() (issue6444)...
Manuel Jacob -
r50128:52072252 default
parent child Browse files
Show More
@@ -79,35 +79,12 b' class _blockingreader:'
79 79 def __init__(self, wrapped):
80 80 self._wrapped = wrapped
81 81
82 # Do NOT implement readinto() by making it delegate to
83 # _wrapped.readinto(), since that is unbuffered. The unpickler is fine
84 # with just read() and readline(), so we don't need to implement it.
85
86 if (3, 8, 0) <= sys.version_info[:3] < (3, 8, 2):
87
88 # This is required for python 3.8, prior to 3.8.2. See issue6444.
89 def readinto(self, b):
90 pos = 0
91 size = len(b)
92
93 while pos < size:
94 ret = self._wrapped.readinto(b[pos:])
95 if not ret:
96 break
97 pos += ret
98
99 return pos
100
101 82 def readline(self):
102 83 return self._wrapped.readline()
103 84
104 # issue multiple reads until size is fulfilled (or EOF is encountered)
105 def read(self, size=-1):
106 if size < 0:
107 return self._wrapped.readall()
108
109 buf = bytearray(size)
85 def readinto(self, buf):
110 86 pos = 0
87 size = len(buf)
111 88
112 89 with memoryview(buf) as view:
113 90 while pos < size:
@@ -117,7 +94,16 b' class _blockingreader:'
117 94 break
118 95 pos += ret
119 96
120 del buf[pos:]
97 return pos
98
99 # issue multiple reads until size is fulfilled (or EOF is encountered)
100 def read(self, size=-1):
101 if size < 0:
102 return self._wrapped.readall()
103
104 buf = bytearray(size)
105 n_read = self.readinto(buf)
106 del buf[n_read:]
121 107 return bytes(buf)
122 108
123 109
General Comments 0
You need to be logged in to leave comments. Login now