summaryrefslogtreecommitdiff
path: root/django/utils/text.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2005-07-18 17:23:04 +0000
committerAdrian Holovaty <adrian@holovaty.com>2005-07-18 17:23:04 +0000
commit912253371d58a27427719d50aa5cf140153f78df (patch)
tree307bcfb082e0f361a6db5a64291f6d8dee1d80bf /django/utils/text.py
parentb68c478aa5d890e76aae6e2f695220505618c8e0 (diff)
Moved django.views.decorators.cache.compress_string into django.utils.text
git-svn-id: http://code.djangoproject.com/svn/django/trunk@175 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/text.py')
-rw-r--r--django/utils/text.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/django/utils/text.py b/django/utils/text.py
index cb9e9454d7..a0d106bb31 100644
--- a/django/utils/text.py
+++ b/django/utils/text.py
@@ -106,3 +106,13 @@ def phone2numeric(phone):
's': '7', 'r': '7', 'u': '8', 't': '8', 'w': '9', 'v': '8',
'y': '9', 'x': '9'}.get(m.group(0).lower())
return letters.sub(char2number, phone)
+
+# From http://www.xhaus.com/alan/python/httpcomp.html#gzip
+# Used with permission.
+def compress_string(s):
+ import cStringIO, gzip
+ zbuf = cStringIO.StringIO()
+ zfile = gzip.GzipFile(mode='wb', compresslevel=6, fileobj=zbuf)
+ zfile.write(s)
+ zfile.close()
+ return zbuf.getvalue()