mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-07 00:00:58 +00:00
Merge pull request #445 from cjmayo/strformat
Remove unused code from strformat.py
This commit is contained in:
commit
09ae495cc5
2 changed files with 0 additions and 105 deletions
|
|
@ -24,9 +24,7 @@ necessarily optimised for large strings, so use with care.
|
|||
|
||||
import re
|
||||
import textwrap
|
||||
import codecs
|
||||
import os
|
||||
import math
|
||||
import time
|
||||
import urllib.parse
|
||||
import locale
|
||||
|
|
@ -72,23 +70,6 @@ def ascii_safe(s):
|
|||
return s
|
||||
|
||||
|
||||
def is_ascii(s):
|
||||
"""Test if a string can be encoded in ASCII."""
|
||||
try:
|
||||
s.encode('ascii', 'strict')
|
||||
return True
|
||||
except (UnicodeEncodeError, UnicodeDecodeError):
|
||||
return False
|
||||
|
||||
|
||||
def is_encoding(text):
|
||||
"""Check if string is a valid encoding."""
|
||||
try:
|
||||
return codecs.lookup(text)
|
||||
except (LookupError, ValueError):
|
||||
return False
|
||||
|
||||
|
||||
def url_unicode_split(url):
|
||||
"""Like urllib.parse.urlsplit(), but always returning unicode parts."""
|
||||
return [unicode_safe(s) for s in urllib.parse.urlsplit(url)]
|
||||
|
|
@ -152,37 +133,11 @@ def indent(text, indent_string=" "):
|
|||
return os.linesep.join("%s%s" % (indent_string, x) for x in text.splitlines())
|
||||
|
||||
|
||||
def get_line_number(s, index):
|
||||
r"""Return the line number of s[index] or zero on errors.
|
||||
Lines are assumed to be separated by the ASCII character '\n'."""
|
||||
i = 0
|
||||
if index < 0:
|
||||
return 0
|
||||
line = 1
|
||||
while i < index:
|
||||
if s[i] == '\n':
|
||||
line += 1
|
||||
i += 1
|
||||
return line
|
||||
|
||||
|
||||
def paginate(text):
|
||||
"""Print text in pages of lines."""
|
||||
pydoc.pager(text)
|
||||
|
||||
|
||||
_markup_re = re.compile("<.*?>", re.DOTALL)
|
||||
|
||||
|
||||
def remove_markup(s):
|
||||
"""Remove all <*> html markup tags from s."""
|
||||
mo = _markup_re.search(s)
|
||||
while mo:
|
||||
s = s[0:mo.start()] + s[mo.end():]
|
||||
mo = _markup_re.search(s)
|
||||
return s
|
||||
|
||||
|
||||
def strsize(b, grouping=True):
|
||||
"""Return human representation of bytes b. A negative number of bytes
|
||||
raises a value error."""
|
||||
|
|
@ -216,32 +171,6 @@ def strtime(t, func=time.localtime):
|
|||
return time.strftime("%Y-%m-%d %H:%M:%S", func(t)) + strtimezone()
|
||||
|
||||
|
||||
# from quodlibet
|
||||
def strduration(duration):
|
||||
"""Turn a time value in seconds into hh:mm:ss or mm:ss."""
|
||||
if duration < 0:
|
||||
duration = abs(duration)
|
||||
prefix = "-"
|
||||
else:
|
||||
prefix = ""
|
||||
duration = math.ceil(duration)
|
||||
if duration >= SECONDS_PER_HOUR: # 1 hour
|
||||
# time, in hours:minutes:seconds
|
||||
return "%s%02d:%02d:%02d" % (
|
||||
prefix,
|
||||
duration // SECONDS_PER_HOUR,
|
||||
(duration % SECONDS_PER_HOUR) // SECONDS_PER_MINUTE,
|
||||
duration % SECONDS_PER_MINUTE,
|
||||
)
|
||||
else:
|
||||
# time, in minutes:seconds
|
||||
return "%s%02d:%02d" % (
|
||||
prefix,
|
||||
duration // SECONDS_PER_MINUTE,
|
||||
duration % SECONDS_PER_MINUTE,
|
||||
)
|
||||
|
||||
|
||||
# from quodlibet
|
||||
def strduration_long(duration, do_translate=True):
|
||||
"""Turn a time value in seconds into x hours, x minutes, etc."""
|
||||
|
|
|
|||
|
|
@ -72,13 +72,6 @@ class TestStrFormat(unittest.TestCase):
|
|||
self.assertEqual(wrap(None, 10), None)
|
||||
self.assertFalse(linkcheck.strformat.get_paragraphs(None))
|
||||
|
||||
def test_remove_markup(self):
|
||||
# Test markup removing.
|
||||
self.assertEqual(linkcheck.strformat.remove_markup("<a>"), "")
|
||||
self.assertEqual(linkcheck.strformat.remove_markup("<>"), "")
|
||||
self.assertEqual(linkcheck.strformat.remove_markup("<<>"), "")
|
||||
self.assertEqual(linkcheck.strformat.remove_markup("a < b"), "a < b")
|
||||
|
||||
def test_strsize(self):
|
||||
# Test byte size strings.
|
||||
self.assertRaises(ValueError, linkcheck.strformat.strsize, -1)
|
||||
|
|
@ -93,10 +86,6 @@ class TestStrFormat(unittest.TestCase):
|
|||
self.assertEqual(linkcheck.strformat.strsize(1024 * 1024 * 1024), "1.00GB")
|
||||
self.assertEqual(linkcheck.strformat.strsize(1024 * 1024 * 1024 * 14), "14.0GB")
|
||||
|
||||
def test_is_ascii(self):
|
||||
self.assertTrue(linkcheck.strformat.is_ascii("abcd./"))
|
||||
self.assertTrue(not linkcheck.strformat.is_ascii("ä"))
|
||||
|
||||
def test_indent(self):
|
||||
s = "bla"
|
||||
self.assertEqual(linkcheck.strformat.indent(s, ""), s)
|
||||
|
|
@ -120,18 +109,6 @@ class TestStrFormat(unittest.TestCase):
|
|||
t = linkcheck.strformat.strtime(0, func=time.gmtime)
|
||||
self.assertEqual(t, "1970-01-01 00:00:00" + zone)
|
||||
|
||||
def test_duration(self):
|
||||
duration = linkcheck.strformat.strduration
|
||||
self.assertEqual(duration(-0.5), "-00:01")
|
||||
self.assertEqual(duration(0), "00:00")
|
||||
self.assertEqual(duration(0.9), "00:01")
|
||||
self.assertEqual(duration(1), "00:01")
|
||||
self.assertEqual(duration(2), "00:02")
|
||||
self.assertEqual(duration(60), "01:00")
|
||||
self.assertEqual(duration(120), "02:00")
|
||||
self.assertEqual(duration(60 * 60), "01:00:00")
|
||||
self.assertEqual(duration(60 * 60 * 24), "24:00:00")
|
||||
|
||||
def test_duration_long(self):
|
||||
def duration(s):
|
||||
return linkcheck.strformat.strduration_long(s, do_translate=False)
|
||||
|
|
@ -149,17 +126,6 @@ class TestStrFormat(unittest.TestCase):
|
|||
duration(60 * 60 * 24 * 365 + 60 * 60 * 24 + 2), "1 year, 1 day"
|
||||
)
|
||||
|
||||
def test_linenumber(self):
|
||||
get_line_number = linkcheck.strformat.get_line_number
|
||||
self.assertEqual(get_line_number("a", -5), 0)
|
||||
self.assertEqual(get_line_number("a", 0), 1)
|
||||
self.assertEqual(get_line_number("a\nb", 2), 2)
|
||||
|
||||
def test_encoding(self):
|
||||
is_encoding = linkcheck.strformat.is_encoding
|
||||
self.assertTrue(is_encoding("ascii"))
|
||||
self.assertFalse(is_encoding("hulla"))
|
||||
|
||||
def test_unicode_safe(self):
|
||||
unicode_safe = linkcheck.strformat.unicode_safe
|
||||
self.assertEqual(unicode_safe("a"), "a")
|
||||
|
|
|
|||
Loading…
Reference in a new issue