Ticket #6499: 0046-Close-open-file-descriptors.patch

File 0046-Close-open-file-descriptors.patch, 1.1 KB (added by Bastian Kleineidam <calvin@…>, 17 years ago)
  • django/utils/text.py

    From 15a7cb8a27d80967894c51a9c3c992e4791f7643 Mon Sep 17 00:00:00 2001
    From: Bastian Kleineidam <calvin@debian.org>
    Date: Mon, 28 Jan 2008 10:52:58 +0100
    Subject: Close open file descriptors
    
    Close another file descriptor leak.
    
    Signed-off-by: Bastian Kleineidam <calvin@debian.org>
    
    diff --git a/django/utils/text.py b/django/utils/text.py
    index 4670ab4..1c78f99 100644
    a b  
    11import re
     2import gzip
     3from cStringIO import StringIO
    24from django.conf import settings
    35from django.utils.encoding import force_unicode
    46from django.utils.functional import allow_lazy
    phone2numeric = allow_lazy(phone2numeric)  
    168170# From http://www.xhaus.com/alan/python/httpcomp.html#gzip
    169171# Used with permission.
    170172def compress_string(s):
    171     import cStringIO, gzip
    172     zbuf = cStringIO.StringIO()
     173    zbuf = StringIO()
    173174    zfile = gzip.GzipFile(mode='wb', compresslevel=6, fileobj=zbuf)
    174     zfile.write(s)
    175     zfile.close()
     175    try:
     176        zfile.write(s)
     177    finally:
     178        zfile.close()
    176179    return zbuf.getvalue()
    177180
    178181ustring_re = re.compile(u"([\u0080-\uffff])")
Back to Top