本文整理汇总了Python中redis._compat.u函数的典型用法代码示例。如果您正苦于以下问题:Python u函数的具体用法?Python u怎么用?Python u使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了u函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unicode_channel_message_handler
def test_unicode_channel_message_handler(self, r):
p = r.pubsub(ignore_subscribe_messages=True)
channel = u('uni') + unichr(4456) + u('code')
channels = {channel: self.message_handler}
p.subscribe(**channels)
assert r.publish(channel, 'test message') == 1
assert wait_for_message(p) is None
assert self.message == make_message('message', channel, 'test message')
示例2: test_unicode_pattern_message_handler
def test_unicode_pattern_message_handler(self, r):
p = r.pubsub(ignore_subscribe_messages=True)
pattern = u('uni') + unichr(4456) + u('*')
channel = u('uni') + unichr(4456) + u('code')
p.psubscribe(**{pattern: self.message_handler})
assert r.publish(channel, 'test message') == 1
assert wait_for_message(p) is None
assert self.message == make_message('pmessage', channel,
'test message', pattern=pattern)
示例3: test_simple_encoding
def test_simple_encoding(self):
unicode_string = unichr(3456) + u('abcd') + unichr(3421)
self.client.set('unicode-string', unicode_string)
cached_val = self.client.get('unicode-string')
self.assertEquals(
unicode.__name__, type(cached_val).__name__,
'Cache returned value with type "%s", expected "%s"' %
(type(cached_val).__name__, unicode.__name__))
self.assertEqual(unicode_string, cached_val)
示例4: make_subscribe_test_data
def make_subscribe_test_data(pubsub, type):
if type == 'channel':
return {
'p': pubsub,
'sub_type': 'subscribe',
'unsub_type': 'unsubscribe',
'sub_func': pubsub.subscribe,
'unsub_func': pubsub.unsubscribe,
'keys': ['foo', 'bar', u('uni') + unichr(4456) + u('code')]
}
elif type == 'pattern':
return {
'p': pubsub,
'sub_type': 'psubscribe',
'unsub_type': 'punsubscribe',
'sub_func': pubsub.psubscribe,
'unsub_func': pubsub.punsubscribe,
'keys': ['f*', 'b*', u('uni') + unichr(4456) + u('*')]
}
assert False, 'invalid subscribe type: %s' % type
示例5: test_list_or_args
def test_list_or_args(self):
bfoo = b('foo')
ufoo = u('foo')
# first record is a text instance
self.assertEquals(list_or_args(ufoo, []), [ufoo])
self.assertEquals(list_or_args(ufoo, [ufoo]), [ufoo, ufoo])
# first record is a list
self.assertEquals(list_or_args([ufoo], [ufoo]), [ufoo, ufoo])
# first record is a binary instance
self.assertEquals(list_or_args(bfoo, []), [bfoo])
self.assertEquals(list_or_args(bfoo, [bfoo]), [bfoo, bfoo])
示例6: test_get_and_set
def test_get_and_set(self, r):
# get and set can't be tested independently of each other
assert r.get("a") is None
byte_string = b("value")
integer = 5
unicode_string = unichr(3456) + u("abcd") + unichr(3421)
assert r.set("byte_string", byte_string)
assert r.set("integer", 5)
assert r.set("unicode_string", unicode_string)
assert r.get("byte_string") == byte_string
assert r.get("integer") == b(str(integer))
assert r.get("unicode_string").decode("utf-8") == unicode_string
示例7: test_exec_error_in_no_transaction_pipeline_unicode_command
def test_exec_error_in_no_transaction_pipeline_unicode_command(self, r):
key = unichr(3456) + u('abcd') + unichr(3421)
r[key] = 1
with r.pipeline(transaction=False) as pipe:
pipe.llen(key)
pipe.expire(key, 100)
with pytest.raises(ResponseError) as ex:
pipe.execute()
expected = unicode('Command # 1 (LLEN {0}) of pipeline caused error: ').format(key)
assert unicode(ex.value).startswith(expected)
assert r[key] == b('1')
示例8: test_exec_error_in_no_transaction_pipeline_unicode_command
def test_exec_error_in_no_transaction_pipeline_unicode_command(self):
key = unichr(3456) + u('abcd') + unichr(3421)
self.rc[key] = 1
with self.rc.pipeline(transaction=False) as pipe:
pipe.llen(key)
pipe.expire(key, 100)
with pytest.raises(redis.ResponseError) as ex:
pipe.execute()
print ex.value
expected = unicode('Command # 1 (LLEN %s) of pipeline caused '
'error: ') % key
assert unicode(ex.value).startswith(expected)
assert self.rc[key] == b('1')
示例9: test_exec_error_in_no_transaction_pipeline_unicode_command
def test_exec_error_in_no_transaction_pipeline_unicode_command(self):
key = unichr(3456) + u('abcd') + unichr(3421)
yield self.client.set(key, 1)
with self.client.pipeline(transaction=False) as pipe:
pipe.llen(key)
pipe.expire(key, 100)
expected = unicode('Command # 1 (LLEN %s) of pipeline caused '
'error: ') % key
try :
yield pipe.execute()
except redis.ResponseError as ex:
self.assertTrue(unicode(ex).startswith(expected))
res = yield self.client.get(key)
self.assertEqual(res, b('1'))
示例10: test_channel_message_handler
def test_channel_message_handler(self, r):
p = r.pubsub(ignore_subscribe_messages=True)
p.subscribe(**{self.channel: self.message_handler})
r.publish(self.channel, self.data)
assert wait_for_message(p) is None
assert self.message == self.make_message('message', self.channel,
self.data)
# test that we reconnected to the correct channel
p.connection.disconnect()
assert wait_for_message(p) is None # should reconnect
new_data = self.data + u('new data')
r.publish(self.channel, new_data)
assert wait_for_message(p) is None
assert self.message == self.make_message('message', self.channel,
new_data)
示例11: test_get_and_set
def test_get_and_set(self):
# get and set can't be tested independently of each other
r = self.r
res = yield r.get('a')
self.assertTrue(res is None)
byte_string = b('value')
integer = 5
unicode_string = unichr(3456) + u('abcd') + unichr(3421)
yield r.set('byte_string', byte_string)
yield r.set('integer', 5)
yield r.set('unicode_string', unicode_string)
res = yield r.get('byte_string')
self.assertEqual(res, byte_string)
res = yield r.get('integer')
self.assertEqual(res, b(str(integer)))
res = yield r.get('unicode_string')
self.assertEqual(res.decode('utf-8'), unicode_string)
示例12: test_slowlog_get
def test_slowlog_get(self, r, slowlog):
assert r.slowlog_reset()
unicode_string = unichr(3456) + u('abcd') + unichr(3421)
r.get(unicode_string)
slowlog = r.slowlog_get()
assert isinstance(slowlog, list)
assert len(slowlog) == 2
get_command = slowlog[0]
assert isinstance(get_command['start_time'], int)
assert isinstance(get_command['duration'], int)
assert get_command['command'] == \
b(' ').join((b('GET'), unicode_string.encode('utf-8')))
slowlog_reset_command = slowlog[1]
assert isinstance(slowlog_reset_command['start_time'], int)
assert isinstance(slowlog_reset_command['duration'], int)
assert slowlog_reset_command['command'] == b('SLOWLOG RESET')
示例13: test_pattern_message_handler
def test_pattern_message_handler(self, o):
p = o.pubsub(ignore_subscribe_messages=True)
p.psubscribe(**{self.pattern: self.message_handler})
o.publish(self.channel, self.data)
assert wait_for_message(p) is None
assert self.message == self.make_message('pmessage', self.channel,
self.data,
pattern=self.pattern)
# test that we reconnected to the correct pattern
p.connection.disconnect()
assert wait_for_message(p) is None # should reconnect
new_data = self.data + u('new data')
o.publish(self.channel, new_data)
assert wait_for_message(p) is None
assert self.message == self.make_message('pmessage', self.channel,
new_data,
pattern=self.pattern)
示例14: test_slowlog_get
def test_slowlog_get(self, r, slowlog):
assert r.slowlog_reset()
unicode_string = unichr(3456) + u('abcd') + unichr(3421)
r.get(unicode_string)
slowlog = r.slowlog_get()
assert isinstance(slowlog, list)
commands = [log['command'] for log in slowlog]
get_command = b(' ').join((b('GET'), unicode_string.encode('utf-8')))
assert get_command in commands
assert b('SLOWLOG RESET') in commands
# the order should be ['GET <uni string>', 'SLOWLOG RESET'],
# but if other clients are executing commands at the same time, there
# could be commands, before, between, or after, so just check that
# the two we care about are in the appropriate order.
assert commands.index(get_command) < commands.index(b('SLOWLOG RESET'))
# make sure other attributes are typed correctly
assert isinstance(slowlog[0]['start_time'], int)
assert isinstance(slowlog[0]['duration'], int)
示例15: test_slowlog_get
def test_slowlog_get(self, r):
# fail on purpose on travis
assert [
r.config_get('slowlog-log-slower-than'),
r.config_get('slowlog-max-len')] == [-10, -10]
assert r.slowlog_reset()
unicode_string = unichr(3456) + u('abcd') + unichr(3421)
r.get(unicode_string)
slowlog = r.slowlog_get()
assert isinstance(slowlog, list)
assert len(slowlog) == 2
get_command = slowlog[0]
assert isinstance(get_command['start_time'], int)
assert isinstance(get_command['duration'], int)
assert get_command['command'] == \
b(' ').join((b('GET'), unicode_string.encode('utf-8')))
slowlog_reset_command = slowlog[1]
assert isinstance(slowlog_reset_command['start_time'], int)
assert isinstance(slowlog_reset_command['duration'], int)
assert slowlog_reset_command['command'] == b('SLOWLOG RESET')