summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2020-05-04 21:35:58 -0700
committerPete Zaitcev <zaitcev@kotori.zaitcev.us>2021-02-23 17:52:25 -0600
commitd1b997889de06f8bcbeb38d0192fa4391465bc47 (patch)
treeab438b264469b99012b969e8b1e5c1d883998745
parent1b3b776964651acae6c17f581855b0fc7094acee (diff)
downloadswift-d1b997889de06f8bcbeb38d0192fa4391465bc47.tar.gz
py27: Suppress UnicodeWarnings in ShardRange setters
Previously, we'd see warnings like UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal when setting lower/upper bounds with non-ascii byte strings. Cherry-Picked-From: I328f297a5403d7e59db95bc726428a3f92df88e1 Change-Id: I133c2524460ae9df779077d160ed6fc2858c08cc
-rw-r--r--swift/common/utils.py13
-rw-r--r--test/unit/common/test_utils.py13
2 files changed, 18 insertions, 8 deletions
diff --git a/swift/common/utils.py b/swift/common/utils.py
index 12550fb87..cdd55e570 100644
--- a/swift/common/utils.py
+++ b/swift/common/utils.py
@@ -48,6 +48,7 @@ import ctypes.util
from copy import deepcopy
from optparse import OptionParser
import traceback
+import warnings
from tempfile import gettempdir, mkstemp, NamedTemporaryFile
import glob
@@ -5009,8 +5010,10 @@ class ShardRange(object):
@lower.setter
def lower(self, value):
- if value in (None, b'', u''):
- value = ShardRange.MIN
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', UnicodeWarning)
+ if value in (None, b'', u''):
+ value = ShardRange.MIN
try:
value = self._encode_bound(value)
except TypeError as err:
@@ -5035,8 +5038,10 @@ class ShardRange(object):
@upper.setter
def upper(self, value):
- if value in (None, b'', u''):
- value = ShardRange.MAX
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', UnicodeWarning)
+ if value in (None, b'', u''):
+ value = ShardRange.MAX
try:
value = self._encode_bound(value)
except TypeError as err:
diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py
index b3f10503e..ad91df812 100644
--- a/test/unit/common/test_utils.py
+++ b/test/unit/common/test_utils.py
@@ -44,6 +44,7 @@ import sys
import json
import math
import inspect
+import warnings
import six
from six import StringIO
@@ -7595,8 +7596,10 @@ class TestShardRange(unittest.TestCase):
expected = u'\N{SNOWMAN}'
if six.PY2:
expected = expected.encode('utf-8')
- do_test(u'\N{SNOWMAN}', expected)
- do_test(u'\N{SNOWMAN}'.encode('utf-8'), expected)
+ with warnings.catch_warnings(record=True) as captured_warnings:
+ do_test(u'\N{SNOWMAN}', expected)
+ do_test(u'\N{SNOWMAN}'.encode('utf-8'), expected)
+ self.assertFalse(captured_warnings)
sr = utils.ShardRange('a/c', utils.Timestamp.now(), 'b', 'y')
sr.lower = ''
@@ -7643,8 +7646,10 @@ class TestShardRange(unittest.TestCase):
expected = u'\N{SNOWMAN}'
if six.PY2:
expected = expected.encode('utf-8')
- do_test(u'\N{SNOWMAN}', expected)
- do_test(u'\N{SNOWMAN}'.encode('utf-8'), expected)
+ with warnings.catch_warnings(record=True) as captured_warnings:
+ do_test(u'\N{SNOWMAN}', expected)
+ do_test(u'\N{SNOWMAN}'.encode('utf-8'), expected)
+ self.assertFalse(captured_warnings)
sr = utils.ShardRange('a/c', utils.Timestamp.now(), 'b', 'y')
sr.upper = ''