本文整理汇总了Python中six.moves方法的典型用法代码示例。如果您正苦于以下问题:Python six.moves方法的具体用法?Python six.moves怎么用?Python six.moves使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six
的用法示例。
在下文中一共展示了six.moves方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: osf_crawl
# 需要导入模块: import six [as 别名]
# 或者: from six import moves [as 别名]
def osf_crawl(k, *pths, **kw):
'''
osf_crawl(k) crawls the osf repository k and returns a lazy nested map structure of the
repository's files. Folders have values that are maps of their contents while files have
values that are their download links.
osf_crawl(k1, k2, ...) is equivalent to osf_crawl(posixpath.join(k1, k2...)).
The optional named argument base (default: 'osfstorage') may be specified to search in a
non-standard storage position in the OSF URL; e.g. in the github storage.
'''
from six.moves import reduce
base = kw.pop('base', 'osfstorage')
root = kw.pop('root', None)
if len(kw) > 0: raise ValueError('Unknown optional parameters: %s' % (list(kw.keys()),))
if k.lower().startswith('osf:'): k = k[4:]
k = k.lstrip('/')
pths = [p.lstrip('/') for p in (k.split('/') + list(pths))]
(bpth, pths) = (pths[0].strip('/'), [p for p in pths[1:] if p != ''])
if root is None: root = _osf_tree(bpth, base=base)
return reduce(lambda m,k: m[k], pths, root)
示例2: test_import_error_in_the_error_handling
# 需要导入模块: import six [as 别名]
# 或者: from six import moves [as 别名]
def test_import_error_in_the_error_handling(self):
pyeclib_drivers = self.get_pyeclib_testspec()
self.assertGreater(len(pyeclib_drivers), 0)
pyeclib_driver = pyeclib_drivers[0]
from six.moves import builtins
real_import = builtins.__import__
def fake_import(*a, **kw):
raise ImportError
builtins.__import__ = fake_import
try:
with self.assertRaises(ImportError): # !!
pyeclib_driver.encode(3)
finally:
builtins.__import__ = real_import
示例3: _astroid_bootstrapping
# 需要导入模块: import six [as 别名]
# 或者: from six import moves [as 别名]
def _astroid_bootstrapping(astroid_builtin=None):
"""astroid boot strapping the builtins module"""
# this boot strapping is necessary since we need the Const nodes to
# inspect_build builtins, and then we can proxy Const
if astroid_builtin is None:
from six.moves import builtins
astroid_builtin = Astroid_BUILDER.inspect_build(builtins)
# pylint: disable=redefined-outer-name
for cls, node_cls in node_classes.CONST_CLS.items():
if cls is type(None):
proxy = build_class('NoneType')
proxy.parent = astroid_builtin
elif cls is type(NotImplemented):
proxy = build_class('NotImplementedType')
proxy.parent = astroid_builtin
else:
proxy = astroid_builtin.getattr(cls.__name__)[0]
if cls in (dict, list, set, tuple):
node_cls._proxied = proxy
else:
_CONST_PROXY[cls] = proxy
示例4: unique_everseen
# 需要导入模块: import six [as 别名]
# 或者: from six import moves [as 别名]
def unique_everseen(iterable, key=None):
"List unique elements, preserving order. Remember all elements ever seen."
# unique_everseen('AAAABBBCCDAABBB') --> A B C D
# unique_everseen('ABBCcAD', str.lower) --> A B C D
seen = set()
seen_add = seen.add
if key is None:
for element in six.moves.filterfalse(seen.__contains__, iterable):
seen_add(element)
yield element
else:
for element in iterable:
k = key(element)
if k not in seen:
seen_add(k)
yield element
示例5: __getstate__
# 需要导入模块: import six [as 别名]
# 或者: from six import moves [as 别名]
def __getstate__(ibs):
"""
Example:
>>> # ENABLE_DOCTEST
>>> import ibeis
>>> from six.moves import cPickle as pickle
>>> ibs = ibeis.opendb('testdb1')
>>> ibs_dump = pickle.dumps(ibs)
>>> ibs2 = pickle.loads(ibs_dump)
"""
# Hack to allow for ibeis objects to be pickled
state = {
'dbdir': ibs.get_dbdir(),
'machine_name': ut.get_computer_name(),
}
return state
示例6: embed_image_html
# 需要导入模块: import six [as 别名]
# 或者: from six import moves [as 别名]
def embed_image_html(imgBGR, target_width=TARGET_WIDTH, target_height=TARGET_HEIGHT):
""" Creates an image embedded in HTML base64 format. """
import cv2
from PIL import Image
if target_width is not None:
imgBGR = _resize(imgBGR, t_width=target_width)
elif target_height is not None:
imgBGR = _resize(imgBGR, t_height=target_height)
imgRGB = cv2.cvtColor(imgBGR, cv2.COLOR_BGR2RGB)
pil_img = Image.fromarray(imgRGB)
if six.PY2:
from six.moves import cStringIO as StringIO
string_buf = StringIO()
pil_img.save(string_buf, format='jpeg')
data = string_buf.getvalue().encode('base64').replace('\n', '')
else:
import io
byte_buf = io.BytesIO()
pil_img.save(byte_buf, format='jpeg')
byte_buf.seek(0)
img_bytes = base64.b64encode(byte_buf.read())
data = img_bytes.decode('ascii')
return 'data:image/jpeg;base64,' + data
示例7: install
# 需要导入模块: import six [as 别名]
# 或者: from six import moves [as 别名]
def install(domain):
"""Install a _() function using the given translation domain.
Given a translation domain, install a _() function using gettext's
install() function.
The main difference from gettext.install() is that we allow
overriding the default localedir (e.g. /usr/share/locale) using
a translation-domain-specific environment variable (e.g.
NOVA_LOCALEDIR).
Note that to enable lazy translation, enable_lazy must be
called.
:param domain: the translation domain
"""
from six import moves
tf = TranslatorFactory(domain)
moves.builtins.__dict__['_'] = tf.primary
示例8: _draw_samples
# 需要导入模块: import six [as 别名]
# 或者: from six import moves [as 别名]
def _draw_samples(self, size, random_state):
rngs = random_state.duplicate(3)
result = self.other_param.draw_samples(size, random_state=rngs[0])
if result.dtype.kind != "f":
result = result.astype(np.float32)
activated = self.activated.draw_sample(random_state=rngs[1])
threshold = self.threshold.draw_sample(random_state=rngs[2])
if activated > 0.5:
# threshold must be subtracted here, not added
# higher threshold = move threshold of sigmoid towards the right
# = make it harder to pass the threshold
# = more 0.0s / less 1.0s
# by subtracting a high value, it moves each x towards the left,
# leading to more values being left of the threshold, leading
# to more 0.0s
return 1 / (1 + np.exp(-(result * self.mul + self.add - threshold)))
return result
示例9: test_add_multi_store
# 需要导入模块: import six [as 别名]
# 或者: from six import moves [as 别名]
def test_add_multi_store(self):
conf = copy.deepcopy(SWIFT_CONF)
conf['default_swift_reference'] = 'store_2'
self.config(group="swift1", **conf)
moves.reload_module(swift)
self.mock_keystone_client()
self.store = Store(self.conf, backend="swift1")
self.store.configure()
expected_swift_size = FIVE_KB
expected_swift_contents = b"*" * expected_swift_size
expected_image_id = str(uuid.uuid4())
image_swift = six.BytesIO(expected_swift_contents)
global SWIFT_PUT_OBJECT_CALLS
SWIFT_PUT_OBJECT_CALLS = 0
loc = 'swift+config://store_2/glance/%s'
expected_location = loc % (expected_image_id)
location, size, checksum, arg = self.store.add(expected_image_id,
image_swift,
expected_swift_size)
self.assertEqual("swift1", arg['store'])
self.assertEqual(expected_location, location)
示例10: test_delete
# 需要导入模块: import six [as 别名]
# 或者: from six import moves [as 别名]
def test_delete(self):
"""
Test we can delete an existing image in the swift store
"""
conf = copy.deepcopy(SWIFT_CONF)
self.config(group="swift1", **conf)
moves.reload_module(swift)
self.mock_keystone_client()
self.store = Store(self.conf, backend="swift1")
self.store.configure()
uri = "swift://%s:key@authurl/glance/%s" % (
self.swift_store_user, FAKE_UUID)
loc = location.get_location_from_uri_and_backend(
uri, "swift1", conf=self.conf)
self.store.delete(loc)
self.assertRaises(exceptions.NotFound, self.store.get, loc)
示例11: test_delete_slo
# 需要导入模块: import six [as 别名]
# 或者: from six import moves [as 别名]
def test_delete_slo(self, mock_del_obj):
"""
Test we can delete an existing image stored as SLO, static large object
"""
conf = copy.deepcopy(SWIFT_CONF)
self.config(group="swift1", **conf)
moves.reload_module(swift)
self.store = Store(self.conf, backend="swift1")
self.store.configure()
uri = "swift://%s:key@authurl/glance/%s" % (self.swift_store_user,
FAKE_UUID2)
loc = location.get_location_from_uri_and_backend(
uri, "swift1", conf=self.conf)
self.store.delete(loc)
self.assertEqual(1, mock_del_obj.call_count)
_, kwargs = mock_del_obj.call_args
self.assertEqual('multipart-manifest=delete',
kwargs.get('query_string'))
示例12: test_delete_nonslo_not_deleted_as_slo
# 需要导入模块: import six [as 别名]
# 或者: from six import moves [as 别名]
def test_delete_nonslo_not_deleted_as_slo(self, mock_del_obj):
"""
Test that non-SLOs are not being deleted the SLO way
"""
conf = copy.deepcopy(SWIFT_CONF)
self.config(group="swift1", **conf)
moves.reload_module(swift)
self.mock_keystone_client()
self.store = Store(self.conf, backend="swift1")
self.store.configure()
uri = "swift://%s:key@authurl/glance/%s" % (self.swift_store_user,
FAKE_UUID)
loc = location.get_location_from_uri_and_backend(
uri, "swift1", conf=self.conf)
self.store.delete(loc)
self.assertEqual(1, mock_del_obj.call_count)
_, kwargs = mock_del_obj.call_args
self.assertIsNone(kwargs.get('query_string'))
示例13: test_delete_with_reference_params
# 需要导入模块: import six [as 别名]
# 或者: from six import moves [as 别名]
def test_delete_with_reference_params(self):
"""
Test we can delete an existing image in the swift store
"""
conf = copy.deepcopy(SWIFT_CONF)
self.config(group="swift1", **conf)
moves.reload_module(swift)
# mock client because v3 uses it to receive auth_info
self.mock_keystone_client()
self.store = Store(self.conf, backend="swift1")
self.store.configure()
uri = "swift+config://ref1/glance/%s" % (FAKE_UUID)
loc = location.get_location_from_uri_and_backend(
uri, "swift1", conf=self.conf)
self.store.delete(loc)
self.assertRaises(exceptions.NotFound, self.store.get, loc)
示例14: test_single_tenant_location
# 需要导入模块: import six [as 别名]
# 或者: from six import moves [as 别名]
def test_single_tenant_location(self):
conf = copy.deepcopy(SWIFT_CONF)
conf['swift_store_container'] = 'container'
conf_file = "glance-swift.conf"
self.swift_config_file = self.copy_data_file(conf_file, self.test_dir)
conf.update({'swift_store_config_file': self.swift_config_file})
conf['default_swift_reference'] = 'ref1'
self.config(group="swift1", **conf)
moves.reload_module(swift)
store = swift.SingleTenantStore(self.conf, backend="swift1")
store.configure()
location = store.create_location('image-id')
self.assertEqual('swift+https', location.scheme)
self.assertEqual('https://example.com', location.swift_url)
self.assertEqual('container', location.container)
self.assertEqual('image-id', location.obj)
self.assertEqual('tenant:user1', location.user)
self.assertEqual('key1', location.key)
示例15: test_add_multi_store
# 需要导入模块: import six [as 别名]
# 或者: from six import moves [as 别名]
def test_add_multi_store(self):
conf = copy.deepcopy(SWIFT_CONF)
conf['default_swift_reference'] = 'store_2'
self.config(**conf)
moves.reload_module(swift)
self.mock_keystone_client()
self.store = Store(self.conf)
self.store.configure()
expected_swift_size = FIVE_KB
expected_swift_contents = b"*" * expected_swift_size
expected_image_id = str(uuid.uuid4())
image_swift = six.BytesIO(expected_swift_contents)
global SWIFT_PUT_OBJECT_CALLS
SWIFT_PUT_OBJECT_CALLS = 0
loc = 'swift+config://store_2/glance/%s'
expected_location = loc % (expected_image_id)
location, size, checksum, multihash, arg = self.store.add(
expected_image_id, image_swift, expected_swift_size, HASH_ALGO)
self.assertEqual(expected_location, location)