當前位置: 首頁>>代碼示例>>Python>>正文


Python six.moves方法代碼示例

本文整理匯總了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) 
開發者ID:noahbenson,項目名稱:neuropythy,代碼行數:22,代碼來源:filemap.py

示例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 
開發者ID:openstack,項目名稱:pyeclib,代碼行數:19,代碼來源:test_pyeclib_api.py

示例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 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:24,代碼來源:raw_building.py

示例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 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:18,代碼來源:package_index.py

示例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 
開發者ID:Erotemic,項目名稱:ibeis,代碼行數:18,代碼來源:IBEISControl.py

示例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 
開發者ID:Erotemic,項目名稱:ibeis,代碼行數:25,代碼來源:appfuncs.py

示例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 
開發者ID:nttcom,項目名稱:eclcli,代碼行數:21,代碼來源:gettextutils.py

示例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 
開發者ID:aleju,項目名稱:imgaug,代碼行數:19,代碼來源:parameters.py

示例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) 
開發者ID:openstack,項目名稱:glance_store,代碼行數:27,代碼來源:test_swift_store_multibackend.py

示例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) 
開發者ID:openstack,項目名稱:glance_store,代碼行數:20,代碼來源:test_swift_store_multibackend.py

示例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')) 
開發者ID:openstack,項目名稱:glance_store,代碼行數:22,代碼來源:test_swift_store_multibackend.py

示例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')) 
開發者ID:openstack,項目名稱:glance_store,代碼行數:22,代碼來源:test_swift_store_multibackend.py

示例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) 
開發者ID:openstack,項目名稱:glance_store,代碼行數:20,代碼來源:test_swift_store_multibackend.py

示例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) 
開發者ID:openstack,項目名稱:glance_store,代碼行數:21,代碼來源:test_swift_store_multibackend.py

示例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) 
開發者ID:openstack,項目名稱:glance_store,代碼行數:25,代碼來源:test_swift_store.py


注:本文中的six.moves方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。