def _assemble(nzf, path, dupe): if os.path.exists(path): unique_path = get_unique_filename(path) if dupe: path = unique_path else: renamer(path, unique_path) fout = open(path, 'ab') if cfg.quick_check(): md5 = new_md5() else: md5 = None _type = nzf.type decodetable = nzf.decodetable for articlenum in decodetable: sleep(0.001) article = decodetable[articlenum] data = ArticleCache.do.load_article(article) if not data: logging.info(T('%s missing'), article) else: # yenc data already decoded, flush it out if _type == 'yenc': fout.write(data) if md5: md5.update(data) # need to decode uu data now elif _type == 'uu': data = data.split('\r\n') chunks = [] for line in data: if not line: continue if line == '-- ' or line.startswith('Posted via '): continue try: tmpdata = binascii.a2b_uu(line) chunks.append(tmpdata) except binascii.Error, msg: # Workaround for broken uuencoders by # /Fredrik Lundh nbytes = (((ord(line[0]) - 32) & 63) * 4 + 5) / 3 try: tmpdata = binascii.a2b_uu(line[:nbytes]) chunks.append(tmpdata) except binascii.Error, msg: logging.info('Decode failed in part %s: %s', article.article, msg) data = ''.join(chunks) fout.write(data) if md5: md5.update(data)
def _assemble(nzf, path, dupe): if os.path.exists(path): unique_path = get_unique_filename(path) if dupe: path = unique_path else: renamer(path, unique_path) fout = open(path, "ab") if cfg.quick_check(): md5 = new_md5() else: md5 = None decodetable = nzf.decodetable for articlenum in decodetable: # Break if deleted during writing if nzf.nzo.status is Status.DELETED: break # Sleep to allow decoder/assembler switching sleep(0.001) article = decodetable[articlenum] data = ArticleCache.do.load_article(article) if not data: logging.info(T("%s missing"), article) else: # yenc data already decoded, flush it out fout.write(data) if md5: md5.update(data) fout.flush() fout.close() set_permissions(path) if md5: nzf.md5sum = md5.digest() del md5 return path
def _assemble(nzf, path, dupe): if os.path.exists(path): unique_path = get_unique_filename(path) if dupe: path = unique_path else: renamer(path, unique_path) fout = open(path, 'ab') if cfg.quick_check(): md5 = hashlib.md5() else: md5 = None decodetable = nzf.decodetable for articlenum in decodetable: # Break if deleted during writing if nzf.nzo.status is Status.DELETED: break # Sleep to allow decoder/assembler switching sleep(0.0001) article = decodetable[articlenum] data = ArticleCache.do.load_article(article) if not data: logging.info(T('%s missing'), article) else: # yenc data already decoded, flush it out fout.write(data) if md5: md5.update(data) fout.flush() fout.close() set_permissions(path) if md5: nzf.md5sum = md5.digest() del md5 return path