Merge branch 'fix/slugifyFilenames' into devel

Conflicts:
	setup.py
This commit is contained in:
Gina Häußge 2016-01-11 16:43:38 +01:00
commit e4828450c9
3 changed files with 12 additions and 11 deletions

View file

@ -35,7 +35,8 @@ INSTALL_REQUIRES = [
"requests>=2.7,<2.8",
"semantic_version>=2.4.2,<2.5",
"psutil>=3.2.1,<3.3",
"Click>=5.1,<5.2"
"Click>=5.1,<5.2",
"awesome-slugify>=1.6.5,<1.7"
]
# Additional requirements for optional install options

View file

@ -388,6 +388,10 @@ class LocalFileStorage(StorageInterface):
self._metadata_cache = pylru.lrucache(10)
from slugify import Slugify
self._slugify = Slugify()
self._slugify.safe_chars = "-_.() "
self._old_metadata = None
self._initialize_metadata()
@ -743,9 +747,9 @@ class LocalFileStorage(StorageInterface):
def sanitize_name(self, name):
"""
Raises a :class:`ValueError` for a ``name`` containing ``/`` or ``\``. Otherwise strips any characters from the
given ``name`` that are not any of the ASCII characters, digits, ``-``, ``_``, ``.``, ``(``, ``)`` or space and
replaces and spaces with ``_``.
Raises a :class:`ValueError` for a ``name`` containing ``/`` or ``\``. Otherwise
slugifies the given ``name`` by converting it to ASCII, leaving ``-``, ``_``, ``.``,
``(``, and ``)`` as is.
"""
if name is None:
return None
@ -753,11 +757,7 @@ class LocalFileStorage(StorageInterface):
if "/" in name or "\\" in name:
raise ValueError("name must not contain / or \\")
import string
valid_chars = "-_.() {ascii}{digits}".format(ascii=string.ascii_letters, digits=string.digits)
sanitized_name = ''.join(c for c in name if c in valid_chars)
sanitized_name = sanitized_name.replace(" ", "_")
return sanitized_name
return self._slugify(name).replace(" ", "_")
def sanitize_path(self, path):
"""

View file

@ -455,8 +455,8 @@ class LocalStorageTest(unittest.TestCase):
@data(
("some_file.gco", "some_file.gco"),
("some_file with (parentheses) and ümläuts and digits 123.gco", "some_file_with_(parentheses)_and_mluts_and_digits_123.gco"),
("pengüino pequeño.stl", "pengino_pequeo.stl")
("some_file with (parentheses) and ümläuts and digits 123.gco", "some_file_with_(parentheses)_and_umlauts_and_digits_123.gco"),
("pengüino pequeño.stl", "penguino_pequeno.stl")
)
@unpack
def test_sanitize_name(self, input, expected):