launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #25772
[Merge] ~cjwatson/launchpad:unused-services-utils into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:unused-services-utils into launchpad:master.
Commit message:
Remove unused functions from lp.services.utils
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/394714
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:unused-services-utils into launchpad:master.
diff --git a/lib/lp/services/tests/test_utils.py b/lib/lp/services/tests/test_utils.py
index 333a612..959f718 100644
--- a/lib/lp/services/tests/test_utils.py
+++ b/lib/lp/services/tests/test_utils.py
@@ -1,4 +1,4 @@
-# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2020 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for lp.services.utils."""
@@ -8,7 +8,6 @@ __metaclass__ = type
from contextlib import contextmanager
from datetime import datetime
from functools import partial
-import hashlib
import itertools
import os
import sys
@@ -25,9 +24,7 @@ from testtools.matchers import (
from lp.services.utils import (
AutoDecorate,
- base,
CachingIterator,
- compress_hash,
decorate_with,
docstring_dedent,
file_exists,
@@ -88,46 +85,6 @@ class TestAutoDecorate(TestCase):
self.assertEqual([2, 1, 'b'], self.log)
-class TestBase(TestCase):
-
- def test_simple_base(self):
- # 35 in base 36 is lowercase 'z'
- self.assertEqual('z', base(35, 36))
-
- def test_extended_base(self):
- # There is no standard representation for numbers in bases above 36
- # (all the digits, all the letters of the English alphabet). However,
- # we can represent bases up to 62 by using upper case letters on top
- # of lower case letters. This is useful as a cheap compression
- # algorithm.
- self.assertEqual('A', base(36, 62))
- self.assertEqual('B', base(37, 62))
- self.assertEqual('Z', base(61, 62))
-
- def test_negative_numbers(self):
- # We don't convert negative numbers at all.
- self.assertRaises(ValueError, base, -43, 62)
-
- def test_base_matches_builtin_hex(self):
- # We get identical results to the hex builtin, without the 0x prefix
- numbers = list(range(5000))
- using_hex = [hex(i)[2:] for i in numbers]
- using_base = [base(i, 16) for i in numbers]
- self.assertEqual(using_hex, using_base)
-
- def test_compress_md5_hash(self):
- # compress_hash compresses MD5 hashes down to 22 URL-safe characters.
- compressed = compress_hash(hashlib.md5('foo'))
- self.assertEqual('5fX649Stem9fET0lD46zVe', compressed)
- self.assertEqual(22, len(compressed))
-
- def test_compress_sha1_hash(self):
- # compress_hash compresses SHA1 hashes down to 27 URL-safe characters.
- compressed = compress_hash(hashlib.sha1('foo'))
- self.assertEqual('1HyPQr2xj1nmnkQXBCJXUdQoy5l', compressed)
- self.assertEqual(27, len(compressed))
-
-
class TestIterateSplit(TestCase):
"""Tests for iter_split."""
diff --git a/lib/lp/services/utils.py b/lib/lp/services/utils.py
index 1d481d4..a9dcd75 100644
--- a/lib/lp/services/utils.py
+++ b/lib/lp/services/utils.py
@@ -1,4 +1,4 @@
-# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2020 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Generic Python utilities.
@@ -10,9 +10,7 @@ stuff.
__metaclass__ = type
__all__ = [
'AutoDecorate',
- 'base',
'CachingIterator',
- 'compress_hash',
'decorate_with',
'docstring_dedent',
'file_exists',
@@ -40,7 +38,6 @@ from itertools import (
)
import os
import re
-import string
import sys
from textwrap import dedent
from types import FunctionType
@@ -81,44 +78,6 @@ def AutoDecorate(*decorators):
return AutoDecorateMetaClass
-def base(number, radix):
- """Convert 'number' to an arbitrary base numbering scheme, 'radix'.
-
- This function is based on work from the Python Cookbook and is under the
- Python licence.
-
- Inverse function to int(str, radix) and long(str, radix)
- """
- if not 2 <= radix <= 62:
- raise ValueError("radix must be between 2 and 62: %s" % (radix,))
-
- if number < 0:
- raise ValueError("number must be non-negative: %s" % (number,))
-
- result = []
- addon = result.append
- if number == 0:
- addon('0')
-
- ABC = string.digits + string.ascii_letters
- while number:
- number, rdigit = divmod(number, radix)
- addon(ABC[rdigit])
-
- result.reverse()
- return ''.join(result)
-
-
-def compress_hash(hash_obj):
- """Compress a hash_obj using `base`.
-
- Given an ``md5`` or ``sha1`` hash object, compress it down to either 22 or
- 27 characters in a way that's safe to be used in URLs. Takes the hex of
- the hash and converts it to base 62.
- """
- return base(int(hash_obj.hexdigest(), 16), 62)
-
-
def iter_split(string, splitter, splits=None):
"""Iterate over ways to split 'string' in two with 'splitter'.