本文整理汇总了Python中more_itertools.always_iterable方法的典型用法代码示例。如果您正苦于以下问题:Python more_itertools.always_iterable方法的具体用法?Python more_itertools.always_iterable怎么用?Python more_itertools.always_iterable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类more_itertools
的用法示例。
在下文中一共展示了more_itertools.always_iterable方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import always_iterable [as 别名]
def __init__(self, urls, status=None, encoding=None):
self.urls = abs_urls = [
# Note that urljoin will "do the right thing" whether url is:
# 1. a complete URL with host (e.g. "http://www.example.com/test")
# 2. a URL relative to root (e.g. "/dummy")
# 3. a URL relative to the current path
# Note that any query string in cherrypy.request is discarded.
urllib.parse.urljoin(
cherrypy.url(),
tonative(url, encoding or self.encoding),
)
for url in always_iterable(urls)
]
status = (
int(status)
if status is not None
else self.default_status
)
if not 300 <= status <= 399:
raise ValueError('status must be between 300 and 399.')
CherryPyException.__init__(self, abs_urls, status)
示例2: send_response
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import always_iterable [as 别名]
def send_response(req, status, headers, body, stream=False):
# Set response status
req.status = int(status[:3])
# Set response headers
req.content_type = 'text/plain'
for header, value in headers:
if header.lower() == 'content-type':
req.content_type = value
continue
req.headers_out.add(header, value)
if stream:
# Flush now so the status and headers are sent immediately.
req.flush()
# Set response body
for seg in always_iterable(body):
req.write(seg)
# --------------- Startup tools for CherryPy + mod_python --------------- #
示例3: test_base_type
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import always_iterable [as 别名]
def test_base_type(self):
dict_obj = {'a': 1, 'b': 2}
str_obj = '123'
# Default: dicts are iterable like they normally are
default_actual = list(mi.always_iterable(dict_obj))
default_expected = list(dict_obj)
self.assertEqual(default_actual, default_expected)
# Unitary types set: dicts are not iterable
custom_actual = list(mi.always_iterable(dict_obj, base_type=dict))
custom_expected = [dict_obj]
self.assertEqual(custom_actual, custom_expected)
# With unitary types set, strings are iterable
str_actual = list(mi.always_iterable(str_obj, base_type=None))
str_expected = list(str_obj)
self.assertEqual(str_actual, str_expected)
示例4: wait
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import always_iterable [as 别名]
def wait(self, state, interval=0.1, channel=None):
"""Poll for the given state(s) at intervals; publish to channel."""
states = set(always_iterable(state))
while self.state not in states:
time.sleep(interval)
self.publish(channel)
示例5: test_single
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import always_iterable [as 别名]
def test_single(self):
self.assertEqual(list(mi.always_iterable(1)), [1])
示例6: test_strings
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import always_iterable [as 别名]
def test_strings(self):
for obj in ['foo', b'bar', 'baz']:
actual = list(mi.always_iterable(obj))
expected = [obj]
self.assertEqual(actual, expected)
示例7: test_iterables
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import always_iterable [as 别名]
def test_iterables(self):
self.assertEqual(list(mi.always_iterable([0, 1])), [0, 1])
self.assertEqual(
list(mi.always_iterable([0, 1], base_type=list)), [[0, 1]]
)
self.assertEqual(
list(mi.always_iterable(iter('foo'))), ['f', 'o', 'o']
)
self.assertEqual(list(mi.always_iterable([])), [])
示例8: test_none
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import always_iterable [as 别名]
def test_none(self):
self.assertEqual(list(mi.always_iterable(None)), [])
示例9: list
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import always_iterable [as 别名]
def list(self, channels=None, server=""):
"""Send a LIST command."""
self.send_items('LIST', ','.join(always_iterable(channels)), server)
示例10: names
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import always_iterable [as 别名]
def names(self, channels=None):
"""Send a NAMES command."""
self.send_items('NAMES', ','.join(always_iterable(channels)))
示例11: part
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import always_iterable [as 别名]
def part(self, channels, message=""):
"""Send a PART command."""
self.send_items('PART', ','.join(always_iterable(channels)), message)
示例12: whois
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import always_iterable [as 别名]
def whois(self, targets):
"""Send a WHOIS command."""
self.send_items('WHOIS', ",".join(always_iterable(targets)))
示例13: from_doc
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import always_iterable [as 别名]
def from_doc(cls, doc):
"""
Load instances from the xmltodict result. Always return
an iterable, even if the result is a singleton.
"""
return map(cls, always_iterable(doc))
示例14: test_generator
# 需要导入模块: import more_itertools [as 别名]
# 或者: from more_itertools import always_iterable [as 别名]
def test_generator(self):
def _gen():
yield 0
yield 1
self.assertEqual(list(mi.always_iterable(_gen())), [0, 1])