def slice_upload(self):
self.is_slice_upload = True<EOL>fid = self.row[FID_COL]<EOL>slice_start = self.row[CURRSIZE_COL]<EOL>slice_end = self.row[CURRSIZE_COL]<EOL>file_size = os.path.getsize(self.row[SOURCEPATH_COL])<EOL>if file_size < slice_start:<EOL><INDENT>self.emit('<STR_LIT>', fid)<EOL>return<EOL><DEDENT>elif file_size == slice_start and slice_start == self.row[SIZE_COL]:<EOL><INDENT>self.emit('<STR_LIT>', fid)<EOL>return<EOL><DEDENT>fh = open(self.row[SOURCEPATH_COL], '<STR_LIT:rb>')<EOL>fh.seek(slice_start)<EOL>while self.row[STATE_COL] == State.UPLOADING:<EOL><INDENT>if slice_end >= file_size:<EOL><INDENT>self.emit('<STR_LIT>', self.row[FID_COL])<EOL>break<EOL><DEDENT>slice_start = slice_end<EOL>slice_end = min(slice_start + self.row[THRESHOLD_COL], file_size)<EOL>data = fh.read(slice_end - slice_start)<EOL>slice_end = slice_start + len(data)<EOL>info = pcs.slice_upload(self.cookie, data)<EOL>if info and '<STR_LIT>' in info:<EOL><INDENT>self.emit('<STR_LIT>', fid, slice_end, info['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>self.emit('<STR_LIT>', fid)<EOL>break<EOL><DEDENT><DEDENT>if not fh.closed:<EOL><INDENT>fh.close()<EOL><DEDENT>return<EOL>
分片上传