Skip to content

Commit

Permalink
[general] remove dead Storage API methods (#1287)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschneier authored Sep 4, 2023
1 parent b02f7e2 commit abce92a
Show file tree
Hide file tree
Showing 12 changed files with 0 additions and 130 deletions.
7 changes: 0 additions & 7 deletions storages/backends/azure_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,6 @@ def get_modified_time(self, name):
# must convert it to settings time_zone
return properties.last_modified.astimezone(tz)

def modified_time(self, name):
"""Returns a naive datetime object containing the last modified time."""
mtime = self.get_modified_time(name)
if timezone.is_naive(mtime):
return mtime
return timezone.make_naive(mtime)

def list_all(self, path=''):
"""Return all files for a given path"""
if path:
Expand Down
8 changes: 0 additions & 8 deletions storages/backends/dropbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,6 @@ def size(self, name):
metadata = self.client.files_get_metadata(self._full_path(name))
return metadata.size

def modified_time(self, name):
metadata = self.client.files_get_metadata(self._full_path(name))
return metadata.server_modified

def accessed_time(self, name):
metadata = self.client.files_get_metadata(self._full_path(name))
return metadata.client_modified

def url(self, name):
try:
media = self.client.files_get_temporary_link(self._full_path(name))
Expand Down
15 changes: 0 additions & 15 deletions storages/backends/ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import ftplib
import io
import os
from datetime import datetime
from urllib.parse import urljoin
from urllib.parse import urlparse

Expand Down Expand Up @@ -181,20 +180,6 @@ def _get_dir_details(self, path):
except ftplib.all_errors:
raise FTPStorageException('Error getting listing for %s' % path)

def modified_time(self, name):
self._start_connection()
resp = self._connection.sendcmd('MDTM ' + name)
if resp[:3] == '213':
s = resp[3:].strip()
# workaround for broken FTP servers returning responses
# starting with e.g. 1904... instead of 2004...
if len(s) == 15 and s[:2] == '19':
s = str(1900 + int(s[2:5])) + s[5:]
return datetime.strptime(s, '%Y%m%d%H%M%S')
raise FTPStorageException(
'Error getting modification time of file %s' % name
)

def listdir(self, path):
self._start_connection()
try:
Expand Down
5 changes: 0 additions & 5 deletions storages/backends/gcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,6 @@ def size(self, name):
blob = self._get_blob(name)
return blob.size

def modified_time(self, name):
name = self._normalize_name(clean_name(name))
blob = self._get_blob(name)
return timezone.make_naive(blob.updated)

def get_modified_time(self, name):
name = self._normalize_name(clean_name(name))
blob = self._get_blob(name)
Expand Down
8 changes: 0 additions & 8 deletions storages/backends/s3boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from django.core.files.base import File
from django.utils.deconstruct import deconstructible
from django.utils.encoding import filepath_to_uri
from django.utils.timezone import is_naive
from django.utils.timezone import make_naive

from storages.base import BaseStorage
Expand Down Expand Up @@ -550,13 +549,6 @@ def get_modified_time(self, name):
else:
return make_naive(entry.last_modified)

def modified_time(self, name):
"""Returns a naive datetime object containing the last modified time."""
# If USE_TZ=False then get_modified_time will return a naive datetime
# so we just return that, else we have to localize and strip the tz
mtime = self.get_modified_time(name)
return mtime if is_naive(mtime) else make_naive(mtime)

def _strip_signing_parameters(self, url):
# Boto3 does not currently support generating URLs that are unsigned. Instead we
# take the signed URLs and strip any querystring params related to signing and expiration.
Expand Down
11 changes: 0 additions & 11 deletions storages/backends/sftpstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import os
import posixpath
import stat
from datetime import datetime
from urllib.parse import urljoin

import paramiko
Expand Down Expand Up @@ -181,16 +180,6 @@ def size(self, name):
remote_path = self._remote_path(name)
return self.sftp.stat(remote_path).st_size

def accessed_time(self, name):
remote_path = self._remote_path(name)
utime = self.sftp.stat(remote_path).st_atime
return datetime.fromtimestamp(utime)

def modified_time(self, name):
remote_path = self._remote_path(name)
utime = self.sftp.stat(remote_path).st_mtime
return datetime.fromtimestamp(utime)

def url(self, name):
if self._base_url is None:
raise ValueError("This file is not accessible via a URL.")
Expand Down
10 changes: 0 additions & 10 deletions tests/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,16 +416,6 @@ def test_size_of_file(self):
self.storage._client.get_blob_client.return_value = client_mock
self.assertEqual(12, self.storage.size("name"))

def test_last_modified_of_file(self):
props = BlobProperties()
accepted_time = datetime.datetime(2017, 5, 11, 8, 52, 4)
props.last_modified = accepted_time
client_mock = mock.MagicMock()
client_mock.get_blob_properties.return_value = props
self.storage._client.get_blob_client.return_value = client_mock
time = self.storage.modified_time("name")
self.assertEqual(accepted_time, time)

def test_override_settings(self):
with override_settings(AZURE_CONTAINER='foo1'):
storage = azure_storage.AzureStorage()
Expand Down
12 changes: 0 additions & 12 deletions tests/test_dropbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,6 @@ def test_size(self, *args):
size = self.storage.size('foo')
self.assertEqual(size, FILE_METADATA_MOCK.size)

@mock.patch('dropbox.Dropbox.files_get_metadata',
return_value=FILE_METADATA_MOCK)
def test_modified_time(self, *args):
mtime = self.storage.modified_time('foo')
self.assertEqual(mtime, FILE_DATE)

@mock.patch('dropbox.Dropbox.files_get_metadata',
return_value=FILE_METADATA_MOCK)
def test_accessed_time(self, *args):
mtime = self.storage.accessed_time('foo')
self.assertEqual(mtime, FILE_DATE)

def test_open(self, *args):
obj = self.storage._open('foo')
self.assertIsInstance(obj, File)
Expand Down
13 changes: 0 additions & 13 deletions tests/test_ftp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import io
from datetime import datetime
from unittest.mock import patch

from django.core.exceptions import ImproperlyConfigured
Expand Down Expand Up @@ -144,18 +143,6 @@ def test_read2(self, mock_ftp):
def test_save(self, mock_ftp):
self.storage._save('foo', File(io.BytesIO(b'foo'), 'foo'))

@patch('ftplib.FTP', **{'return_value.sendcmd.return_value': '213 20160727094506'})
def test_modified_time(self, mock_ftp):
self.storage._start_connection()
modif_date = self.storage.modified_time('foo')
self.assertEqual(modif_date, datetime(2016, 7, 27, 9, 45, 6))

@patch('ftplib.FTP', **{'return_value.sendcmd.return_value': '500'})
def test_modified_time_error(self, mock_ftp):
self.storage._start_connection()
with self.assertRaises(ftp.FTPStorageException):
self.storage.modified_time('foo')

@patch('ftplib.FTP', **{'return_value.retrlines': list_retrlines})
def test_listdir(self, mock_retrlines):
dirs, files = self.storage.listdir('/')
Expand Down
21 changes: 0 additions & 21 deletions tests/test_gcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,21 +252,6 @@ def test_size_no_file(self):

self.assertRaises(NotFound, self.storage.size, self.filename)

def test_modified_time(self):
naive_date = datetime.datetime(2017, 1, 2, 3, 4, 5, 678)
aware_date = timezone.make_aware(naive_date, datetime.timezone.utc)

self.storage._bucket = mock.MagicMock()
blob = mock.MagicMock()
blob.updated = aware_date
self.storage._bucket.get_blob.return_value = blob

with self.settings(TIME_ZONE='UTC'):
mt = self.storage.modified_time(self.filename)
self.assertTrue(timezone.is_naive(mt))
self.assertEqual(mt, naive_date)
self.storage._bucket.get_blob.assert_called_with(self.filename)

def test_get_modified_time(self):
naive_date = datetime.datetime(2017, 1, 2, 3, 4, 5, 678)
aware_date = timezone.make_aware(naive_date, datetime.timezone.utc)
Expand Down Expand Up @@ -311,12 +296,6 @@ def test_get_created_time(self):
self.assertEqual(mt, aware_date)
self.storage._bucket.get_blob.assert_called_with(self.filename)

def test_modified_time_no_file(self):
self.storage._bucket = mock.MagicMock()
self.storage._bucket.get_blob.return_value = None

self.assertRaises(NotFound, self.storage.modified_time, self.filename)

def test_url_public_object(self):
url = 'https://example.com/mah-bukkit/{}'.format(self.filename)
self.storage.default_acl = 'publicRead'
Expand Down
5 changes: 0 additions & 5 deletions tests/test_s3boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,11 +641,6 @@ def _test_storage_mtime(self, use_tz):
obj.last_modified = datetime.datetime.now(datetime.timezone.utc)

name = 'file.txt'
self.assertFalse(
is_aware(self.storage.modified_time(name)),
'Naive datetime object expected from modified_time()'
)

self.assertIs(
settings.USE_TZ,
is_aware(self.storage.get_modified_time(name)),
Expand Down
15 changes: 0 additions & 15 deletions tests/test_sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import socket
import stat
from datetime import datetime
from unittest.mock import MagicMock
from unittest.mock import patch

Expand Down Expand Up @@ -134,20 +133,6 @@ def test_listdir(self, mock_sftp):
def test_size(self, mock_sftp):
self.assertEqual(self.storage.size('foo'), 42)

@patch('storages.backends.sftpstorage.SFTPStorage.sftp', **{
'stat.return_value.st_atime': 1469674684.000000,
})
def test_accessed_time(self, mock_sftp):
self.assertEqual(self.storage.accessed_time('foo'),
datetime(2016, 7, 27, 21, 58, 4))

@patch('storages.backends.sftpstorage.SFTPStorage.sftp', **{
'stat.return_value.st_mtime': 1469674684.000000,
})
def test_modified_time(self, mock_sftp):
self.assertEqual(self.storage.modified_time('foo'),
datetime(2016, 7, 27, 21, 58, 4))

def test_url(self):
self.assertEqual(self.storage.url('foo'), '/media/foo')
# Test custom
Expand Down

0 comments on commit abce92a

Please sign in to comment.