From 4ffa94f634cbdd6d566defb2bcaf97b418e08c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 15 Apr 2018 18:44:13 +0200 Subject: [PATCH] remove 'shorten_path()' and 'shorten_filename()' --- gallery_dl/text.py | 14 -------------- test/test_text.py | 27 --------------------------- 2 files changed, 41 deletions(-) diff --git a/gallery_dl/text.py b/gallery_dl/text.py index 9ce7ef1f..4bed863a 100644 --- a/gallery_dl/text.py +++ b/gallery_dl/text.py @@ -8,7 +8,6 @@ """Collection of functions that work in strings/text""" -import sys import re import os.path import html @@ -78,19 +77,6 @@ def clean_path_posix(path): return "" -def shorten_path(path, limit=255, encoding=sys.getfilesystemencoding()): - """Shorten a path segment to at most 'limit' bytes""" - return (path.encode(encoding)[:limit]).decode(encoding, "ignore") - - -def shorten_filename(fname, limit=255, encoding=sys.getfilesystemencoding()): - """Shorten filename to at most 'limit' bytes while preserving extension""" - name, extension = os.path.splitext(fname) - bext = extension.encode(encoding) - bname = name.encode(encoding)[:limit-len(bext)] - return bname.decode(encoding, "ignore") + extension - - def extract(txt, begin, end, pos=0): """Extract the text between 'begin' and 'end' from 'txt' diff --git a/test/test_text.py b/test/test_text.py index 4afa058d..b07dff10 100644 --- a/test/test_text.py +++ b/test/test_text.py @@ -8,7 +8,6 @@ # published by the Free Software Foundation. import unittest -import sys from gallery_dl import text @@ -118,32 +117,6 @@ class TestText(unittest.TestCase): for value in INVALID: self.assertEqual(f(value), "") - def test_shorten_path(self): - cases = { - "dirname": "dirname", - "X"*255: "X"*255, - "X"*256: "X"*255, - "Ä"*255: "Ä"*127, - } - enc = sys.getfilesystemencoding() - for case, result in cases.items(): - self.assertEqual(text.shorten_path(case), result) - self.assertTrue(len(text.shorten_path(case).encode(enc)) <= 255) - - def test_shorten_filename(self): - self.maxDiff = None - cases = { - "filename.ext": "filename.ext", - "X"*251 + ".ext": "X"*251 + ".ext", - "X"*255 + ".ext": "X"*251 + ".ext", - "Ä"*251 + ".ext": "Ä"*125 + ".ext", - } - enc = sys.getfilesystemencoding() - for case, result in cases.items(): - fname = text.shorten_filename(case) - self.assertEqual(fname, result) - self.assertTrue(len(fname.encode(enc)) <= 255) - def test_extract(self, f=text.extract): txt = "" self.assertEqual(f(txt, "<", ">"), ("a", 3))