Skip to content

Commit 7cb67d5

Browse files
author
Jody McIntyre
committed
Move clean_name to utils
We want to use this in the Google Cloud Storage backend as well. This is a separate commit so we can verify the clean_name tests in s3boto still pass (before I move those as well).
1 parent 8105cba commit 7cb67d5

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

storages/backends/s3boto.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import posixpath
32
import mimetypes
43
from datetime import datetime
54
from gzip import GzipFile
@@ -24,7 +23,7 @@
2423
raise ImproperlyConfigured("Could not load Boto's S3 bindings.\n"
2524
"See https://github.com/boto/boto")
2625

27-
from storages.utils import setting
26+
from storages.utils import clean_name, setting
2827

2928
boto_version_info = tuple([int(i) for i in boto_version.split('-')[0].split('.')])
3029

@@ -348,15 +347,7 @@ def _clean_name(self, name):
348347
"""
349348
Cleans the name so that Windows style paths work
350349
"""
351-
# Normalize Windows style paths
352-
clean_name = posixpath.normpath(name).replace('\\', '/')
353-
354-
# os.path.normpath() can strip trailing slashes so we implement
355-
# a workaround here.
356-
if name.endswith('/') and not clean_name.endswith('/'):
357-
# Add a trailing slash as it was stripped.
358-
clean_name += '/'
359-
return clean_name
350+
return clean_name(name)
360351

361352
def _normalize_name(self, name):
362353
"""

storages/utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import posixpath
2+
13
from django.conf import settings
24
from django.core.exceptions import ImproperlyConfigured
35

@@ -20,3 +22,19 @@ def setting(name, default=None, strict=False):
2022
msg = "You must provide settings.%s" % name
2123
raise ImproperlyConfigured(msg)
2224
return getattr(settings, name, default)
25+
26+
27+
def clean_name(name):
28+
"""
29+
Cleans the name so that Windows style paths work
30+
"""
31+
# Normalize Windows style paths
32+
clean_name = posixpath.normpath(name).replace('\\', '/')
33+
34+
# os.path.normpath() can strip trailing slashes so we implement
35+
# a workaround here.
36+
if name.endswith('/') and not clean_name.endswith('/'):
37+
# Add a trailing slash as it was stripped.
38+
return clean_name + '/'
39+
else:
40+
return clean_name

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy