Commits

David Ziegler  committed 0293592

better var naming, only import gzip if using gzip

  • Participants
  • Parent commits 8ee7ba3

Comments (0)

Files changed (2)

File backends/s3.py

 QUERYSTRING_EXPIRE= getattr(settings, 'AWS_QUERYSTRING_EXPIRE', 60)
 SECURE_URLS= getattr(settings, 'AWS_S3_SECURE_URLS', False)
 
-AWS_GZIP = getattr(settings, 'AWS_GZIP', False)
+IS_GZIPPED= getattr(settings, 'AWS_IS_GZIPPED', False) 
 GZIP_CONTENT_TYPES = (
     'text/css',
     'application/javascript',
 )
 GZIP_CONTENT_TYPES = getattr(settings, 'GZIP_CONTENT_TYPES', GZIP_CONTENT_TYPES)
 
+if IS_GZIPPED:
+    from gzip import GzipFile
 
 class S3Storage(Storage):
     """Amazon Simple Storage Service"""
     def __init__(self, bucket=settings.AWS_STORAGE_BUCKET_NAME,
             access_key=None, secret_key=None, acl=DEFAULT_ACL,
             calling_format=settings.AWS_CALLING_FORMAT, encrypt=False,
-            gzip=AWS_GZIP, gzip_content_types=GZIP_CONTENT_TYPES):
+            gzip=IS_GZIPPED, gzip_content_types=GZIP_CONTENT_TYPES):
         self.bucket = bucket
         self.acl = acl
         self.encrypt = encrypt
 
     def _compress_string(self, s):
         """Gzip a given string."""
-        from gzip import GzipFile
         zbuf = StringIO()
         zfile = GzipFile(mode='wb', compresslevel=6, fileobj=zbuf)
         zfile.write(s)

File backends/s3boto.py

 DEFAULT_ACL     = 'AWS_DEFAULT_ACL'
 QUERYSTRING_AUTH = 'AWS_QUERYSTRING_AUTH'
 QUERYSTRING_EXPIRE = 'AWS_QUERYSTRING_EXPIRE'
+IS_GZIPPED = 'AWS_IS_GZIPPED'
 
 BUCKET_PREFIX     = getattr(settings, BUCKET_NAME, {})
 HEADERS           = getattr(settings, HEADERS, {})
 DEFAULT_ACL       = getattr(settings, DEFAULT_ACL, 'public-read')
 QUERYSTRING_AUTH  = getattr(settings, QUERYSTRING_AUTH, True)
 QUERYSTRING_EXPIRE= getattr(settings, QUERYSTRING_EXPIRE, 3600)
-AWS_GZIP           = getattr(settings, 'AWS_GZIP', False)
+IS_GZIPPED        = getattr(settings, IS_GZIPPED, False) 
 GZIP_CONTENT_TYPES = (
     'text/css',
     'application/javascript',
 )
 GZIP_CONTENT_TYPES = getattr(settings, 'GZIP_CONTENT_TYPES', GZIP_CONTENT_TYPES)
 
+if IS_GZIPPED:
+    from gzip import GzipFile
 
 class S3BotoStorage(Storage):
     """Amazon Simple Storage Service using Boto"""
     
     def __init__(self, bucket="root", bucketprefix=BUCKET_PREFIX, 
             access_key=None, secret_key=None, acl=DEFAULT_ACL, headers=HEADERS,
-            gzip=AWS_GZIP, gzip_content_types=GZIP_CONTENT_TYPES):
+            gzip=IS_GZIPPED, gzip_content_types=GZIP_CONTENT_TYPES):
         self.acl = acl
         self.headers = headers
         self.gzip = gzip
 
     def _compress_content(self, content):
         """Gzip a given string."""
-        from gzip import GzipFile
         zbuf = StringIO()
         zfile = GzipFile(mode='wb', compresslevel=6, fileobj=zbuf)
         zfile.write(content.read())