Skip to content

Commit

Permalink
Fixes #156 added parsing of RFC1123 dates
Browse files Browse the repository at this point in the history
  • Loading branch information
k-bx committed Mar 21, 2013
1 parent dfd3a2b commit 5a87f64
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion storages/backends/s3boto.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import mimetypes
from gzip import GzipFile
import datetime

try:
from cStringIO import StringIO
Expand Down Expand Up @@ -31,6 +32,16 @@
"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.
Expand Down Expand Up @@ -441,7 +452,7 @@ def modified_time(self, name):
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))
Expand Down
7 changes: 7 additions & 0 deletions storages/tests/s3boto.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import mock
from uuid import uuid4
from urllib2 import urlopen
import datetime

from django.test import TestCase
from django.core.files.base import ContentFile
Expand All @@ -13,11 +14,17 @@
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):
Expand Down

0 comments on commit 5a87f64

Please sign in to comment.