|
49 | 49 | from django.http import HttpResponse |
50 | 50 | from django.shortcuts import render, redirect |
51 | 51 | from django.contrib.sites.models import Site |
| 52 | +from django.utils.encoding import force_bytes |
52 | 53 | #from django.views.decorators.cache import cache_page |
53 | 54 | #from django.views.decorators.vary import vary_on_cookie |
54 | 55 |
|
@@ -454,22 +455,22 @@ def telechat_docs_tarfile(request, date): |
454 | 455 |
|
455 | 456 | tarstream = tarfile.open('', 'w:gz', response) |
456 | 457 |
|
457 | | - manifest = io.StringIO() |
| 458 | + manifest = io.BytesIO() |
458 | 459 |
|
459 | 460 | for doc in docs: |
460 | | - doc_path = os.path.join(doc.get_file_path(), doc.name + "-" + doc.rev + ".txt") |
| 461 | + doc_path = force_bytes(os.path.join(doc.get_file_path(), doc.name + "-" + doc.rev + ".txt")) |
461 | 462 | if os.path.exists(doc_path): |
462 | 463 | try: |
463 | 464 | tarstream.add(doc_path, str(doc.name + "-" + doc.rev + ".txt")) |
464 | | - manifest.write("Included: %s\n" % doc_path) |
| 465 | + manifest.write(b"Included: %s\n" % doc_path) |
465 | 466 | except Exception as e: |
466 | | - manifest.write("Failed (%s): %s\n" % (e, doc_path)) |
| 467 | + manifest.write(b"Failed (%s): %s\n" % (force_bytes(e), doc_path)) |
467 | 468 | else: |
468 | | - manifest.write("Not found: %s\n" % doc_path) |
| 469 | + manifest.write(b"Not found: %s\n" % doc_path) |
469 | 470 |
|
470 | 471 | manifest.seek(0) |
471 | 472 | t = tarfile.TarInfo(name="manifest.txt") |
472 | | - t.size = len(manifest.buf) |
| 473 | + t.size = len(manifest.getvalue()) |
473 | 474 | t.mtime = time.time() |
474 | 475 | tarstream.addfile(t, manifest) |
475 | 476 |
|
|
0 commit comments