1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-25 12:12:34 +01:00

remove 'shorten_path()' and 'shorten_filename()'

This commit is contained in:
Mike Fährmann 2018-04-15 18:44:13 +02:00
parent 27eab4e467
commit 4ffa94f634
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 0 additions and 41 deletions

View File

@ -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'

View File

@ -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 = "<a><b>"
self.assertEqual(f(txt, "<", ">"), ("a", 3))