diff options
| author | Claude Paroz <claude@2xlibre.net> | 2012-05-05 19:47:03 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-05-05 21:41:44 +0200 |
| commit | d7dfab59ead97b35c6f6786784225f377783e376 (patch) | |
| tree | d357f2b94ef010d60e9ad6602bda5537f1a28b8d /docs | |
| parent | 1583d402240d88ad2a4acc024d348a21657ccaba (diff) | |
Replaced cStringIO.StringIO by io.BytesIO.
Also replaced StringIO.StringIO by BytesIO in some other appropriate
places. StringIO is not available in Python 3.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/howto/outputting-pdf.txt | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/docs/howto/outputting-pdf.txt b/docs/howto/outputting-pdf.txt index a30b10f7b5..55f80bb4cc 100644 --- a/docs/howto/outputting-pdf.txt +++ b/docs/howto/outputting-pdf.txt @@ -104,15 +104,11 @@ Complex PDFs ============ If you're creating a complex PDF document with ReportLab, consider using the -:mod:`cStringIO` library as a temporary holding place for your PDF file. This +:mod:`io` library as a temporary holding place for your PDF file. This library provides a file-like object interface that is particularly efficient. -Here's the above "Hello World" example rewritten to use :mod:`cStringIO`:: +Here's the above "Hello World" example rewritten to use :mod:`io`:: - # Fall back to StringIO in environments where cStringIO is not available - try: - from cStringIO import StringIO - except ImportError: - from StringIO import StringIO + from io import BytesIO from reportlab.pdfgen import canvas from django.http import HttpResponse @@ -121,9 +117,9 @@ Here's the above "Hello World" example rewritten to use :mod:`cStringIO`:: response = HttpResponse(mimetype='application/pdf') response['Content-Disposition'] = 'attachment; filename=somefilename.pdf' - buffer = StringIO() + buffer = BytesIO() - # Create the PDF object, using the StringIO object as its "file." + # Create the PDF object, using the BytesIO object as its "file." p = canvas.Canvas(buffer) # Draw things on the PDF. Here's where the PDF generation happens. @@ -134,7 +130,7 @@ Here's the above "Hello World" example rewritten to use :mod:`cStringIO`:: p.showPage() p.save() - # Get the value of the StringIO buffer and write it to the response. + # Get the value of the BytesIO buffer and write it to the response. pdf = buffer.getvalue() buffer.close() response.write(pdf) |
