➕➖ Switch from awesome-slugify to python-slugify

This commit is contained in:
Gina Häußge committed 2020-06-03 15:13:00 +02:00
1 parent f88b5e8142
commit 73fbd15bca
4 files changed
+14 -11

No files matched your search

+1 -1
View File
@@ -58,7 +58,7 @@ INSTALL_REQUIRES = [
"semantic_version>=2.8.5,<3", "semantic_version>=2.8.5,<3",
"psutil>=5.7,<6", "psutil>=5.7,<6",
"Click>=7.1.2,<8", "Click>=7.1.2,<8",
"awesome-slugify>=1.6.5,<2", "python-slugify>=4,<5",
"feedparser>=5.2.1,<6", "feedparser>=5.2.1,<6",
"future>=0.18.2,<1", "future>=0.18.2,<1",
"websocket-client>=0.57,<1", "websocket-client>=0.57,<1",
+6 -4
View File
@@ -24,7 +24,7 @@ from contextlib import contextmanager
from past.builtins import basestring from past.builtins import basestring
from emoji import demojize from emoji import demojize
from slugify import Slugify import slugify
import octoprint.filemanager import octoprint.filemanager
@@ -456,15 +456,17 @@ class LocalFileStorage(StorageInterface):
def _no_unicode_variations(cls, text): def _no_unicode_variations(cls, text):
return cls._UNICODE_VARIATIONS.sub("", text) return cls._UNICODE_VARIATIONS.sub("", text)
_SLUGIFY = Slugify() _SLUGIFY_ALLOWED_REGEX = re.compile(r"[^-_.()[]a-zA-Z0-9]+")
_SLUGIFY.safe_chars = "-_.()[] "
@classmethod @classmethod
def _slugify(cls, text): def _slugify(cls, text):
text = to_unicode(text) text = to_unicode(text)
text = cls._no_unicode_variations(text) text = cls._no_unicode_variations(text)
text = demojize(text, delimiters=("", "")) text = demojize(text, delimiters=("", ""))
return cls._SLUGIFY(text) return slugify.slugify(text,
regex_pattern=cls._SLUGIFY_ALLOWED_REGEX,
separator="_",
lowercase=False)
def __init__(self, basefolder, create=False): def __init__(self, basefolder, create=False):
""" """
@@ -42,9 +42,9 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin,
self._cached_channel_configs = None self._cached_channel_configs = None
self._cached_channel_configs_mutex = threading.RLock() self._cached_channel_configs_mutex = threading.RLock()
from slugify import Slugify from slugify import slugify
self._slugify = Slugify() pattern = re.compile(r"^[-_.a-zA-Z0-9]+")
self._slugify.safe_chars = "-_." self._slugify = lambda x: slugify(x, regex_pattern=pattern)
# Additional permissions hook # Additional permissions hook
+4 -3
View File
@@ -55,7 +55,7 @@ class LocalStorageTest(unittest.TestCase):
def get_file_type(name): def get_file_type(name):
if name.lower().endswith(".stl"): if name.lower().endswith(".stl"):
return ["model", "stl"] return ["model", "stl"]
elif name.lower().endswith(".gco") or name.lower().endswith(".gcode") or name.lower.endswith(".g"): elif name.lower().endswith(".gco") or name.lower().endswith(".gcode") or name.lower().endswith(".g"):
return ["machinecode", "gcode"] return ["machinecode", "gcode"]
else: else:
return None return None
@@ -628,12 +628,13 @@ class LocalStorageTest(unittest.TestCase):
@data( @data(
("test", "test"), ("test", "test"),
("\u2764", "red_heart"), ("\u2764", "red_heart"),
("\u2764\ufe00", "red_heart") ("\u2764\ufe00", "red_heart"),
("Häußge", "Haussge")
) )
@unpack @unpack
def test_slugify(self, input, expected): def test_slugify(self, input, expected):
output = LocalFileStorage._slugify(input) output = LocalFileStorage._slugify(input)
self.assertEqual(output, expected) self.assertEqual(expected, output)
def _add_and_verify_file(self, path, expected_path, file_object, links=None, overwrite=False, display=None): def _add_and_verify_file(self, path, expected_path, file_object, links=None, overwrite=False, display=None):
"""Adds a file to the storage and verifies the sanitized path.""" """Adds a file to the storage and verifies the sanitized path."""