Jannis Leidel avatar Jannis Leidel committed 02afdf3 Merge

Merged in k_bx/django-storages-156-parse-date (pull request #63)

Fixes #156 added parsing of RFC1123 dates

Comments (0)

Files changed (2)

storages/backends/s3boto.py

 import os
 import mimetypes
 from gzip import GzipFile
+import datetime
 
 try:
     from cStringIO import StringIO
                                "higher.\nSee https://github.com/boto/boto")
 
 
+def parse_ts_extended(ts):
+    RFC1123 = '%a, %d %b %Y %H:%M:%S %Z'
+    rv = None
+    try:
+        rv = parse_ts(ts)
+    except ValueError:
+        rv = datetime.datetime.strptime(ts, RFC1123)
+    return rv
+
+
 def safe_join(base, *paths):
     """
     A version of django.utils._os.safe_join for S3 paths.
         if entry is None:
             entry = self.bucket.get_key(self._encode_name(name))
         # Parse the last_modified string to a local datetime object.
-        return parse_ts(entry.last_modified)
+        return parse_ts_extended(entry.last_modified)
 
     def url(self, name):
         name = self._normalize_name(self._clean_name(name))

storages/tests/s3boto.py

 import mock
 from uuid import uuid4
 from urllib2 import urlopen
+import datetime
 
 from django.test import TestCase
 from django.core.files.base import ContentFile
 from storages.backends import s3boto
 
 __all__ = (
+    'ParseTsExtendedCase',
     'SafeJoinTest',
     'S3BotoStorageTests',
     #'S3BotoStorageFileTests',
 )
 
+class ParseTsExtendedCase(TestCase):
+    def test_normal(self):
+        value = s3boto.parse_ts_extended("Wed, 13 Mar 2013 12:45:49 GMT")
+        self.assertEquals(value, datetime.datetime(2013, 3, 13, 12, 45, 49))
+
 class S3BotoTestCase(TestCase):
     @mock.patch('storages.backends.s3boto.S3Connection')
     def setUp(self, S3Connection):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.