Python đọc tệp trong bộ đệm
Phương thức
0 thay đổi vị trí tệp hiện tại. Đối số offset cho biết số byte được di chuyển từ đầu tệpdef read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()Chuyển đến nội dung chính
Show
Python trung gianNâng cao kỹ năng khoa học dữ liệu của bạn bằng cách tạo trực quan hóa bằng Matplotlib và thao tác với DataFrames bằng gấu trúcMột số đối tượng có sẵn trong Python bao bọc quyền truy cập vào một mảng bộ nhớ cơ bản hoặc bộ đệm. Các đối tượng như vậy bao gồm def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen6 và def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen7 tích hợp sẵn và một số loại tiện ích mở rộng như def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen8. Các thư viện của bên thứ ba có thể xác định các loại của riêng họ cho các mục đích đặc biệt, chẳng hạn như xử lý hình ảnh hoặc phân tích số Mặc dù mỗi loại này có ngữ nghĩa riêng, nhưng chúng có chung đặc điểm là được hỗ trợ bởi bộ đệm bộ nhớ lớn có thể. Sau đó, trong một số trường hợp, mong muốn truy cập trực tiếp vào bộ đệm đó và không cần sao chép trung gian Python cung cấp một tiện ích như vậy ở cấp độ C dưới dạng giao thức đệm . Giao thức này có hai mặt.
Các đối tượng đơn giản như def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen6 và def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen7 hiển thị bộ đệm cơ bản của chúng ở dạng hướng byte. Các hình thức khác là có thể; Một người tiêu dùng mẫu của giao diện bộ đệm là phương thức def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen2 của các đối tượng tệp. bất kỳ đối tượng nào có thể xuất một loạt byte thông qua giao diện bộ đệm đều có thể được ghi vào một tệp. Trong khi def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen2 chỉ cần quyền truy cập chỉ đọc vào nội dung bên trong của đối tượng được truyền cho nó, các phương thức khác như def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen1 cần quyền ghi vào nội dung đối số của chúng. Giao diện bộ đệm cho phép các đối tượng cho phép hoặc từ chối xuất có chọn lọc bộ đệm đọc-ghi và chỉ đọc Có hai cách để người tiêu dùng giao diện bộ đệm có được bộ đệm trên đối tượng đích
Trong cả hai trường hợp, def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen7 phải được gọi khi bộ đệm không còn cần thiết nữa. Không làm như vậy có thể dẫn đến các vấn đề khác nhau như rò rỉ tài nguyên Cấu trúc bộ đệm¶Cấu trúc bộ đệm (hoặc đơn giản là “bộ đệm”) rất hữu ích như một cách để hiển thị dữ liệu nhị phân từ một đối tượng khác cho lập trình viên Python. Chúng cũng có thể được sử dụng như một cơ chế cắt không sao chép. Sử dụng khả năng tham chiếu một khối bộ nhớ của họ, có thể hiển thị bất kỳ dữ liệu nào cho lập trình viên Python khá dễ dàng. Bộ nhớ có thể là một mảng lớn, không đổi trong phần mở rộng C, nó có thể là một khối bộ nhớ thô để thao tác trước khi chuyển đến thư viện hệ điều hành hoặc nó có thể được sử dụng để chuyển dữ liệu có cấu trúc ở định dạng trong bộ nhớ gốc của nó Trái với hầu hết các kiểu dữ liệu được trình thông dịch Python đưa ra, bộ đệm không phải là con trỏ def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen8 mà là cấu trúc C khá đơn giản. Điều này cho phép chúng được tạo và sao chép rất đơn giản. Khi cần một trình bao bọc chung quanh bộ đệm, một đối tượng memoryview có thể được tạo. Để biết hướng dẫn ngắn về cách viết đối tượng xuất, hãy xem Cấu trúc đối tượng bộ đệm . Để lấy bộ đệm, xem def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen2. loại Py_buffer ¶ Một phần của ABI ổn định< . 11. (including all members) since version 3.11.void *buf ¶ A . Đây có thể là bất kỳ vị trí nào trong khối bộ nhớ vật lý bên dưới của trình xuất. Ví dụ: với giá trị âm def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()10 có thể trỏ đến cuối khối bộ nhớ. Đối với các mảng tiếp giáp , giá trị trỏ đến phần đầu của khối bộ nhớ. PyObject *obj ¶Một tham chiếu mới đến . Tham chiếu thuộc sở hữu của người tiêu dùng và tự động giảm dần và được đặt thành def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()11 bởi def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen7. Trường này tương đương với giá trị trả về của bất kỳ hàm C-API tiêu chuẩn nào. Trong trường hợp đặc biệt, đối với bộ đệm tạm thời được bao bọc bởi def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()13 hoặc def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()14, trường này là def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()11. Nói chung, xuất các đối tượng KHÔNG ĐƯỢC sử dụng sơ đồ nàyPy_ssize_t len ¶ def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()16. Đối với các mảng liền kề, đây là độ dài của khối bộ nhớ bên dưới. Đối với các mảng không liền kề, đó là độ dài mà cấu trúc logic sẽ có nếu nó được sao chép sang một biểu diễn liền kề. Truy cập def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()17 chỉ hợp lệ nếu bộ đệm đã được lấy theo yêu cầu đảm bảo tính liên tục. Trong hầu hết các trường hợp, một yêu cầu như vậy sẽ là def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()18 hoặc def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()19int chỉ đọc ¶ Chỉ báo cho biết bộ đệm có ở chế độ chỉ đọc hay không. Trường này được kiểm soát bởi cờ def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()19. Py_ssize_t itemsize ¶ Kích thước mục tính theo byte của một phần tử. Tương tự như giá trị của def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen61 được gọi trên các giá trị không phải ______111 def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen63. ngoại lệ quan trọng. Nếu người tiêu dùng yêu cầu bộ đệm không có cờ def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen64, thì def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen63 sẽ được đặt thành def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()11, nhưng def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen67 vẫn có giá trị cho định dạng ban đầu Nếu có mặt def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen68, đẳng thức def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen69 vẫn giữ và người tiêu dùng có thể sử dụng def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen67 để điều hướng bộ đệm Nếu def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen68 là def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()11 do yêu cầu của def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()18 hoặc def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()19, người tiêu dùng phải bỏ qua def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen67 và cho rằng def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen76const ký tự *định dạng ¶ A NUL terminated string in def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen77 module style syntax describing the contents of a single item. If this is def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()11, def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen79 (unsigned bytes) is assumed. Trường này được kiểm soát bởi cờ def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen64int ndim ¶ Số thứ nguyên mà bộ nhớ biểu thị dưới dạng mảng n chiều. Nếu là def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen81, thì def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen82 trỏ đến một mục duy nhất đại diện cho vô hướng. Trong trường hợp này, def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen68, def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()10 và def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen85 PHẢI là def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()11. Macro def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen87 giới hạn số lượng kích thước tối đa là 64. Các nhà xuất khẩu PHẢI tôn trọng giới hạn này, người tiêu dùng bộ đệm đa chiều NÊN có khả năng xử lý tối đa def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen87 kích thướcPy_ssize_t *shape ¶ Một mảng gồm def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen89 của . Lưu ý rằng def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen61 PHẢI bằng def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen62. Giá trị hình dạng được giới hạn ở def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen63. Trường hợp def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen64 cần được chú ý đặc biệt. Xem các mảng phức tạp để biết thêm thông tin Mảng hình dạng chỉ đọc cho người tiêu dùng Py_ssize_t *strids ¶Một mảng gồm def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen89 của . Giá trị sải chân có thể là bất kỳ số nguyên nào. Đối với các mảng thông thường, các bước tiến thường là tích cực, nhưng người tiêu dùng PHẢI có khả năng xử lý trường hợp def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen67. Xem các mảng phức tạp để biết thêm thông tin Mảng sải chân chỉ đọc cho người tiêu dùng Py_ssize_t *suboffsets ¶Một mảng gồm def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen89 của . Nếu def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen70, các giá trị được lưu trữ dọc theo chiều thứ n là các con trỏ và giá trị bù trừ con cho biết cần thêm bao nhiêu byte vào mỗi con trỏ sau khi bỏ tham chiếu. Giá trị bù trừ con âm cho biết rằng không xảy ra tham chiếu lại (dải trong khối bộ nhớ liền kề). Nếu tất cả các phần bù con đều âm (i. e. không cần hủy tham chiếu), thì trường này phải là def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()11 (giá trị mặc định) Kiểu biểu diễn mảng này được sử dụng bởi Thư viện hình ảnh Python (PIL). Xem các mảng phức tạp để biết thêm thông tin về cách truy cập các phần tử của một mảng như vậy Mảng suboffsets chỉ đọc cho người tiêu dùng void *nội bộ ¶Điều này được sử dụng nội bộ . Ví dụ: điều này có thể được nhà xuất khẩu truyền lại dưới dạng số nguyên và được sử dụng để lưu trữ các cờ về việc có hay không giải phóng các mảng hình dạng, bước tiến và tập con khi bộ đệm được giải phóng. Người tiêu dùng KHÔNG ĐƯỢC thay đổi giá trị này. Các loại yêu cầu bộ đệm¶Bộ đệm thường có được bằng cách gửi yêu cầu bộ đệm tới đối tượng xuất thông qua def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen2. Vì độ phức tạp của cấu trúc logic của bộ nhớ có thể thay đổi đáng kể, nên người tiêu dùng sử dụng đối số flags để chỉ định loại bộ đệm chính xác mà nó có thể xử lý Tất cả các trường def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen73 được xác định rõ ràng theo loại yêu cầu các trường độc lập với yêu cầu¶Các trường sau đây không bị ảnh hưởng bởi cờ và phải luôn được điền đúng giá trị. def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen74, def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen82, def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen62, def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen67, def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen60 chỉ đọc, định dạng¶
def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()19 có thể là. 'd vào bất kỳ cờ nào trong phần tiếp theo. Vì def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()18 được định nghĩa là 0, nên có thể sử dụng def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()19 như một cờ độc lập để yêu cầu một bộ đệm có thể ghi đơn giản def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen64 có thể là. 'd với bất kỳ cờ nào ngoại trừ def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()18. Cái sau đã ngụ ý định dạng def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen87 (byte không dấu) hình dạng, bước tiến, suboffsets¶Các cờ kiểm soát cấu trúc logic của bộ nhớ được liệt kê theo thứ tự phức tạp giảm dần. Lưu ý rằng mỗi cờ chứa tất cả các bit của các cờ bên dưới nó Lời yêu cầu hình dạng sải bước bù trừ PyBUF_INDIRECT ¶có Vâng Nếu cần thiết PyBUF_STRIDES ¶có Vâng VÔ GIÁ TRỊ PyBUF_ND ¶có VÔ GIÁ TRỊ VÔ GIÁ TRỊ PyBUF_SIMPLE ¶NULL VÔ GIÁ TRỊ VÔ GIÁ TRỊ yêu cầu tiếp giáp¶C hoặc Fortran sự liền kề có thể được yêu cầu rõ ràng, có và không có thông tin sải chân. Không có thông tin sải chân, bộ đệm phải là C-tiếp giáp. Lời yêu cầu hình dạng sải bước bù trừ tiếp giáp PyBUF_C_CONTIGUOUS ¶có Vâng VÔ GIÁ TRỊ C PyBUF_F_CONTIGUOUS ¶có Vâng VÔ GIÁ TRỊ F PyBUF_ANY_CONTIGUOUS ¶có Vâng VÔ GIÁ TRỊ C hoặc F def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen88 Vâng VÔ GIÁ TRỊ VÔ GIÁ TRỊ C yêu cầu ghép¶Tất cả các yêu cầu có thể được xác định đầy đủ bởi một số kết hợp của các cờ trong phần trước. Để thuận tiện, giao thức bộ đệm cung cấp các kết hợp được sử dụng thường xuyên dưới dạng các cờ đơn Trong bảng sau U là viết tắt của tiếp giáp không xác định. Người tiêu dùng sẽ phải gọi def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen89 để xác định sự tiếp giáp Lời yêu cầu hình dạng sải bước bù trừ tiếp giáp chỉ đọc định dạng PyBUF_FULL ¶có Vâng Nếu cần thiết U 0 Vâng PyBUF_FULL_RO ¶có Vâng Nếu cần thiết U 1 hoặc 0 Vâng PyBUF_RECORDS ¶có Vâng VÔ GIÁ TRỊ U 0 Vâng PyBUF_RECORDS_RO ¶có Vâng VÔ GIÁ TRỊ U 1 hoặc 0 Vâng PyBUF_STRIDED ¶có Vâng VÔ GIÁ TRỊ U 0 VÔ GIÁ TRỊ PyBUF_STRIDED_RO ¶có Vâng VÔ GIÁ TRỊ U 1 hoặc 0 VÔ GIÁ TRỊ PyBUF_CONTIG ¶có VÔ GIÁ TRỊ VÔ GIÁ TRỊ C 0 VÔ GIÁ TRỊ PyBUF_CONTIG_RO ¶có VÔ GIÁ TRỊ VÔ GIÁ TRỊ C 1 hoặc 0 VÔ GIÁ TRỊ Mảng phức¶kiểu NumPy. hình dạng và bước tiến¶Cấu trúc logic của mảng kiểu NumPy được xác định bởi def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen67, def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen60, def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen68 và def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()10 Nếu def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen24, vị trí bộ nhớ được trỏ tới bởi def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen82 được hiểu là vô hướng có kích thước def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen67. Trong trường hợp đó, cả def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen68 và def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()10 đều là def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()11 Nếu def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()10 là def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()11, mảng được hiểu là mảng C chiều n chiều tiêu chuẩn. Mặt khác, người tiêu dùng phải truy cập vào một mảng n chiều như sau def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen2 Như đã lưu ý ở trên, def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen82 có thể trỏ đến bất kỳ vị trí nào trong khối bộ nhớ thực tế. Nhà xuất khẩu có thể kiểm tra tính hợp lệ của bộ đệm bằng chức năng này def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen kiểu PIL. hình dạng, sải chân và suboffsets¶Ngoài các mục thông thường, các mảng kiểu PIL có thể chứa các con trỏ phải được theo sau để đến phần tử tiếp theo trong một thứ nguyên. Ví dụ, mảng ba chiều C thông thường def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen03 cũng có thể được xem như một mảng gồm 2 con trỏ tới 2 mảng hai chiều. def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen04. Trong biểu diễn suboffsets, hai con trỏ đó có thể được nhúng ở đầu def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen82, trỏ đến hai mảng def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen06 có thể được định vị ở bất kỳ đâu trong bộ nhớ Đây là một hàm trả về một con trỏ tới phần tử trong một mảng N-D được trỏ tới bởi một chỉ mục N chiều khi có cả hai bước tiến và tập con không phải là ____111 def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()1 Các chức năng liên quan đến bộ đệm¶int PyObject_CheckBuffer(PyObject *obj)¶Part of the Stable ABI since version 3.11. Trả lại def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen08 nếu obj hỗ trợ giao diện bộ đệm nếu không thì def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen81. Khi def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen08 được trả lại, điều đó không đảm bảo rằng def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen2 sẽ thành công. Chức năng này luôn thành côngint PyObject_GetBuffer(PyObject *exporter, Py_buffer *view, int flags)¶ Part of the Stable ABI since version 3.11. Gửi yêu cầu đến nhà xuất khẩu để điền vào chế độ xem theo chỉ định của cờ. Nếu nhà xuất khẩu không thể cung cấp bộ đệm của loại chính xác, nó PHẢI tăng def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen12, đặt def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen13 thành def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()11 và trả lại def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen15 Khi thành công, hãy điền vào chế độ xem, đặt def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen13 thành tham chiếu mới cho nhà xuất khẩu và trả về 0. Trong trường hợp các nhà cung cấp bộ đệm chuỗi chuyển hướng yêu cầu đến một đối tượng duy nhất, thì def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen13 CÓ THỂ tham chiếu đến đối tượng này thay vì nhà xuất khẩu (Xem Cấu trúc đối tượng bộ đệm ). Các cuộc gọi thành công đến def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen2 phải được ghép nối với các cuộc gọi đến def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen7, tương tự như def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen20 và def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen21. Do đó, sau khi người tiêu dùng thực hiện xong bộ đệm, def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen7 phải được gọi chính xác một lầnvoid PyBuffer_Release(Py_buffer *view)¶ Part of the Stable ABI since version 3.11. Giải phóng chế độ xem bộ đệm và giảm số lượng tham chiếu cho def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen13. Chức năng này PHẢI được gọi khi bộ đệm không còn được sử dụng, nếu không có thể xảy ra rò rỉ tham chiếu Có lỗi khi gọi chức năng này trên bộ đệm không được lấy qua def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen2Py_ssize_t PyBuffer_SizeFromFormat(const char *format)¶ Part of the Stable ABI since version 3.11. Trả lại def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen67 ngụ ý từ def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen63. Khi gặp lỗi, hãy đưa ra một ngoại lệ và trả về -1 Mới trong phiên bản 3. 9 int PyBuffer_IsContiguous(const Py_buffer *view, char order)¶Part of the Stable ABI since version 3.11. Trả về def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen08 nếu bộ nhớ được xác định bởi dạng xem là kiểu C (thứ tự là def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen28) hoặc kiểu Fortran (thứ tự là def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen29) tiếp giáp or either one (order is def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen30). Return def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen81 otherwise. This function always succeeds.void *PyBuffer_GetPointer(const Py_buffer *view, const Py_ssize_t *indices)¶ Part of the Stable ABI since version 3.11. Lấy vùng bộ nhớ được trỏ đến bởi các chỉ số bên trong chế độ xem đã cho. các chỉ số phải trỏ đến một mảng gồm def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen32 chỉ sốint PyBuffer_FromContiguous(const Py_buffer *view, const void *buf, Py_ssize_t len, char fort)¶ Part of the Stable ABI since version 3.11. Sao chép các byte len liền kề từ buf để xem. fort có thể là def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen28 hoặc def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen29 (đối với thứ tự kiểu C hoặc kiểu Fortran). def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen81 được trả về khi thành công, def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen15 khi gặp lỗiint PyBuffer_ToContiguous(void *buf, const Py_buffer *src, Py_ssize_t len, char order)¶ Part of the Stable ABI since version 3.11. Sao chép len byte từ src sang biểu diễn liền kề của nó trong buf. thứ tự có thể là def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen28 hoặc def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen29 hoặc def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen30 (đối với thứ tự kiểu C hoặc kiểu Fortran hoặc một trong hai). def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen81 được trả về khi thành công, def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen15 khi gặp lỗi Chức năng này không thành công nếu len. = src-> len int PyObject_CopyData(Py_buffer *dest, Py_buffer *src)¶Part of the Stable ABI since version 3.11. Sao chép dữ liệu từ src vào bộ đệm đích. Có thể chuyển đổi giữa bộ đệm kiểu C và hoặc kiểu Fortran def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen81 được trả về khi thành công, def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen15 khi gặp lỗivoid PyBuffer_FillContiguousStrides(int ndims, Py_ssize_t *shape, Py_ssize_t *strides, int itemsize, char order)¶ Part of the Stable ABI since version 3.11. Điền vào mảng các bước với các bước sải byte của một liền kề (kiểu C nếu thứ tự là def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen28 hoặc kiểu Fortran nếu thứ tự là def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen29 . int PyBuffer_FillInfo(Py_buffer *view, PyObject *exporter, void *buf, Py_ssize_t len, int readonly, int flags)¶ Part of the Stable ABI since version 3.11. Xử lý các yêu cầu bộ đệm cho một nhà xuất khẩu muốn hiển thị buf có kích thước len với khả năng ghi được đặt theo chỉ đọc. buf được hiểu là một chuỗi các byte không dấu Đối số flags cho biết loại yêu cầu. Chức năng này luôn lấp đầy chế độ xem như được chỉ định bởi cờ, trừ khi buf được chỉ định là chỉ đọc và def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()19 được đặt trong cờ Khi thành công, hãy đặt def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen13 thành tham chiếu mới cho nhà xuất khẩu và trả về 0. Mặt khác, tăng def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen12, đặt def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen13 thành def read_from_buffer(self, pos, numbytes = None): vs = self.videostatus piece_index, piece_offset = self.piecepos_from_bytepos(vs, pos) if DEBUG: log('vod::read_from_buffer: pos', pos, 'numbytes', numbytes, 'piece_index', piece_index, 'piece_offset', piece_offset) data = '' for i in xrange(piece_index, vs.last_piece + 1): piece = self.get_piece(i) if piece is None: break if piece_offset > 0: chunk = piece[piece_offset:] piece_offset = 0 else: chunk = piece data += chunk pos += len(chunk) if DEBUG: log('vod::read_from_buffer: got whole piece: index', i, 'chunk_len', len(piece), 'data_len', len(data), 'pos', pos) if numbytes is not None and len(data) >= numbytes: if DEBUG: log('vod::read_from_buffer: got enough data: numbytes', numbytes, 'data_len', len(data)) return data self.proxy_cond.acquire() try: for bstart, bdata in self.proxy_buf.iteritems(): bend = bstart + len(bdata) - 1 if bstart <= pos <= bend: offset_from = pos - bstart if numbytes is None: chunk = bdata[offset_from:] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read whole data: pos', pos, 'bstart', bstart, 'bend', bend, 'chunk:[%d:]:%d' % (offset_from, len(chunk)), 'data_len', len(data)) else: offset_to = offset_from + numbytes - len(data) chunk = bdata[offset_from:offset_to] data += chunk if DEBUG: log('vod::read_from_buffer: got data from proxy buffer, read data slice: pos', pos, 'bstart', bstart, 'bend', bend, 'numbytes', numbytes, 'chunk:[%d:%d]:%d' % (offset_from, offset_to, len(chunk)), 'data_len', len(data)) break return data finally: self.proxy_cond.release()11 và trả về def verify_structure(memlen, itemsize, ndim, shape, strides, offset): """Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem """ if offset % itemsize: return False if offset < 0 or offset+itemsize > memlen: return False if any(v % itemsize for v in strides): return False if ndim <= 0: return ndim == 0 and not shape and not strides if 0 in shape: return True imin = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] <= 0) imax = sum(strides[j]*(shape[j]-1) for j in range(ndim) if strides[j] > 0) return 0 <= offset+imin and offset+imax+itemsize <= memlen15; Bộ đệm trong xử lý tệp Python là gì?Cấu trúc bộ đệm (hoặc đơn giản là “bộ đệm”) hữu ích vì một cách để hiển thị dữ liệu nhị phân từ một đối tượng khác cho lập trình viên Python . Chúng cũng có thể được sử dụng như một cơ chế cắt không sao chép. Sử dụng khả năng tham chiếu một khối bộ nhớ của họ, có thể hiển thị bất kỳ dữ liệu nào cho lập trình viên Python khá dễ dàng.
Làm cách nào để đọc tệp dữ liệu trong Python?Để đọc một tệp văn bản trong Python, bạn làm theo các bước sau. Đầu tiên, mở một tệp văn bản để đọc bằng hàm open(). Thứ hai, đọc văn bản từ tệp văn bản bằng phương thức tệp read() , readline() hoặc readlines() của đối tượng tệp. Thứ ba, đóng tệp bằng phương thức đóng tệp ()
Arraybuffer trong Python là gì?bộ đệm mảng là Thư viện python được MIT cấp phép . Nó triển khai các kiểu Arraybuffer và Arraybuffer_dsc để tạo hiệu quả các dạng xem bộ nhớ đã nhập và các mảng đa chiều. bộ đệm mảng là bộ đệm cho các mảng đa chiều và các lần xem bộ nhớ đã nhập.
TextIOWrapper Python là gì?TextIOWrapper , mở rộng TextIOBase , là giao diện văn bản được đệm cho luồng thô được đệm ( BufferedIOBase ). Cuối cùng, StringIO là luồng trong bộ nhớ cho văn bản. |