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


Python functools.partialmethod方法代碼示例

本文整理匯總了Python中functools.partialmethod方法的典型用法代碼示例。如果您正苦於以下問題:Python functools.partialmethod方法的具體用法?Python functools.partialmethod怎麽用?Python functools.partialmethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在functools的用法示例。


在下文中一共展示了functools.partialmethod方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: contribute_to_class

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import partialmethod [as 別名]
def contribute_to_class(self, cls, *args, **kwargs):
        super().contribute_to_class(cls, *args, **kwargs)

        # Add order related methods to model
        # Applying partialmethod() to already bound methods will retain self and add the model_instance bound to
        subs = {'name': self.name, 'model': self.model.__name__.lower()}
        setattr(cls, self.func_local_next % subs, partialmethod(self.get_next_or_previous_in_order, is_next=True))
        setattr(cls, self.func_local_previous % subs, partialmethod(self.get_next_or_previous_in_order, is_next=False))
        setattr(cls, self.func_local_get_set % subs, partialmethod(self.get_group_order))
        setattr(cls, self.func_local_set_set % subs, partialmethod(self.set_group_order))
        if self.unique_for_fields:
            # Declare that this field has dependencies
            self.has_dependencies = True
            # Queue rest of work for when model is fully loaded
            cls._meta.apps.lazy_model_operation(
                self._lazy_contribute_to_class,
                (cls._meta.app_label, cls._meta.model_name)) 
開發者ID:ashleywaite,項目名稱:django-more,代碼行數:19,代碼來源:orderbyfield.py

示例2: load_instruction

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import partialmethod [as 別名]
def load_instruction(cls, instruction, opcode, implementation):
        try:
            impl_name = implementation.__name__
        except AttributeError:
            if isinstance(implementation, functools.partialmethod):
                rand = os.urandom(4).hex()

                try:
                    impl_name = f"{implementation.func.__name__}_{rand}"
                except AttributeError:
                    # TODO: WTF is happening here? Eg. when wrapping a MagicMock
                    impl_name = rand
            else:
                # TODO: WTF is happening here? Eg. with a MagicMock
                impl_name = os.urandom(4).hex()

        concrete_name = f"i_{instruction.__name__}_{impl_name}"

        while concrete_name in cls.concrete_names:
            concrete_name += os.urandom(4).hex()

        cls.concrete_names.append(concrete_name)

        setattr(cls, concrete_name, implementation)
        cls.opcodes_names.setdefault(opcode, []).append(concrete_name) 
開發者ID:ForceBru,項目名稱:PyVM,代碼行數:27,代碼來源:util.py

示例3: __init__

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import partialmethod [as 別名]
def __init__(self):
        self.opcodes = {
            **{
                0xD8F0 + i: P(self.fdiv, i=i, reverse=True)
                for i in range(8)
            },
            **{
                0xDCF8 + i: P(self.fdiv, i=i, reverse=False)
                for i in range(8)
            },

            **{
                0xDEF8 + i: P(self.fdivp, i=i)
                for i in range(8)
            },
        } 
開發者ID:ForceBru,項目名稱:PyVM,代碼行數:18,代碼來源:floating.py

示例4: __init__

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import partialmethod [as 別名]
def __init__(self):
        self.opcodes = {
            **{
                o: self.r
                for o in range(0x50, 0x58)
                },
            0xFF  : self.rm,

            0x6A  : P(self.imm, _8bit=True),
            0x68  : P(self.imm, _8bit=False),

            0x0E  : P(self.sreg, 'CS'),
            0x16  : P(self.sreg, 'SS'),
            0x1E  : P(self.sreg, 'DS'),
            0x06  : P(self.sreg, 'ES'),

            0x0FA0: P(self.sreg, 'FS'),
            0x0FA8: P(self.sreg, 'GS')
            } 
開發者ID:ForceBru,項目名稱:PyVM,代碼行數:21,代碼來源:memory.py

示例5: __init__

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import partialmethod [as 別名]
def __init__(self):
        self.opcodes = {
            0xEB: P(self.rel, _8bit=True, jump=_JMP),
            0xE9: P(self.rel, _8bit=False, jump=_JMP),

            0xFF: self.rm_m,
            0xEA: P(self.ptr, _8bit=False),

            0xE3: P(self.rel, _8bit=True, jump=JCXZ),

            **{
                opcode: P(self.rel, _8bit=True, jump=JUMPS[opcode % 0x70])
                for opcode in range(0x70, 0x80)
            },

            **{
                opcode: P(self.rel, _8bit=False, jump=JUMPS[opcode % 0x0F80])
                for opcode in range(0x0F80, 0x0F90)
            }
        } 
開發者ID:ForceBru,項目名稱:PyVM,代碼行數:22,代碼來源:control.py

示例6: _get_function_source

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import partialmethod [as 別名]
def _get_function_source(func):
    if _PY34:
        func = inspect.unwrap(func)
    elif hasattr(func, '__wrapped__'):
        func = func.__wrapped__

    if inspect.isfunction(func):
        code = func.__code__
        return (code.co_filename, code.co_firstlineno)

    if isinstance(func, functools.partial):
        return _get_function_source(func.func)

    if _PY34 and isinstance(func, functools.partialmethod):
        return _get_function_source(func.func)
    return None 
開發者ID:hhstore,項目名稱:annotated-py-projects,代碼行數:18,代碼來源:events.py

示例7: test_partialmethod_basic

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import partialmethod [as 別名]
def test_partialmethod_basic(check_lru, loop):
    class Obj:
        async def _coro(self, val):
            return val

        coro = alru_cache(partialmethod(_coro, 2), loop=loop)

    obj = Obj()

    coros = [obj.coro() for _ in range(5)]

    check_lru(obj.coro, hits=0, misses=0, cache=0, tasks=0)

    ret = await asyncio.gather(*coros, loop=loop)

    check_lru(obj.coro, hits=4, misses=1, cache=1, tasks=0)

    assert ret == [2, 2, 2, 2, 2] 
開發者ID:aio-libs,項目名稱:async_lru,代碼行數:20,代碼來源:test_partialmethod.py

示例8: test_partialmethod_partial

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import partialmethod [as 別名]
def test_partialmethod_partial(check_lru, loop):
    class Obj:
        def __init__(self):
            self.coro = alru_cache(partial(self._coro, 2), loop=loop)

        async def __coro(self, val1, val2):
            return val1 + val2

        _coro = partialmethod(__coro, 1)

    obj = Obj()

    coros = [obj.coro() for _ in range(5)]

    check_lru(obj.coro, hits=0, misses=0, cache=0, tasks=0)

    ret = await asyncio.gather(*coros, loop=loop)

    check_lru(obj.coro, hits=4, misses=1, cache=1, tasks=0)

    assert ret == [3, 3, 3, 3, 3] 
開發者ID:aio-libs,項目名稱:async_lru,代碼行數:23,代碼來源:test_partialmethod.py

示例9: test_partialmethod_cls_loop

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import partialmethod [as 別名]
def test_partialmethod_cls_loop(check_lru, loop):
    class Obj:
        def __init__(self, loop):
            self._loop = loop

        async def _coro(self, val):
            return val

        coro = alru_cache(partialmethod(_coro, 2), cls=True, loop='_loop')

    obj = Obj(loop=loop)

    coros = [obj.coro() for _ in range(5)]

    check_lru(obj.coro, hits=0, misses=0, cache=0, tasks=0)

    ret = await asyncio.gather(*coros, loop=loop)

    check_lru(obj.coro, hits=4, misses=1, cache=1, tasks=0)

    assert ret == [2, 2, 2, 2, 2] 
開發者ID:aio-libs,項目名稱:async_lru,代碼行數:23,代碼來源:test_partialmethod.py

示例10: test_partialmethod_kwargs_loop

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import partialmethod [as 別名]
def test_partialmethod_kwargs_loop(check_lru, loop):
    class Obj:
        async def _coro(self, val, *, _loop):
            return val

        coro = alru_cache(partialmethod(_coro, 2), kwargs=True, loop='_loop')

    obj = Obj()

    coros = [obj.coro(_loop=loop) for _ in range(5)]

    check_lru(obj.coro, hits=0, misses=0, cache=0, tasks=0)

    ret = await asyncio.gather(*coros, loop=loop)

    check_lru(obj.coro, hits=4, misses=1, cache=1, tasks=0)

    assert ret == [2, 2, 2, 2, 2] 
開發者ID:aio-libs,項目名稱:async_lru,代碼行數:20,代碼來源:test_partialmethod.py

示例11: contribute_to_related_class

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import partialmethod [as 別名]
def contribute_to_related_class(self, cls, field):
        subs = {'name': self.name, 'model': self.model.__name__.lower(), 'remote_name': field.name}
        setattr(cls, self.func_remote_get_set % subs, partialmethod(self.get_group_order, field=field))
        setattr(cls, self.func_remote_set_set % subs, partialmethod(self.set_group_order, field=field)) 
開發者ID:ashleywaite,項目名稱:django-more,代碼行數:6,代碼來源:orderbyfield.py

示例12: make_foreign_order_accessors

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import partialmethod [as 別名]
def make_foreign_order_accessors(model, related_model):
    setattr(
        related_model,
        'get_%s_order' % model.__name__.lower(),
        partialmethod(method_get_order, model)
    )
    setattr(
        related_model,
        'set_%s_order' % model.__name__.lower(),
        partialmethod(method_set_order, model)
    )

########
# MISC #
######## 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:17,代碼來源:base.py

示例13: partialclass

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import partialmethod [as 別名]
def partialclass(cls, *args, **kwds):

    class NewCls(cls):
        __init__ = functools.partialmethod(cls.__init__, *args, **kwds)

    return NewCls 
開發者ID:vsitzmann,項目名稱:scene-representation-networks,代碼行數:8,代碼來源:hyperlayers.py

示例14: partialclass

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import partialmethod [as 別名]
def partialclass(cls, *args, **kwargs):

    class PartialClass(cls):
        __init__ = partialmethod(cls.__init__, *args, **kwargs)

    return PartialClass 
開發者ID:kenshohara,項目名稱:3D-ResNets-PyTorch,代碼行數:8,代碼來源:utils.py

示例15: test_download_single

# 需要導入模塊: import functools [as 別名]
# 或者: from functools import partialmethod [as 別名]
def test_download_single(run_cli, api, tmpdir, smallest_online_products, monkeypatch):
    # Change default arguments for quicker test.
    # Also, vcrpy is not threadsafe, so only one worker is used.
    monkeypatch.setattr(
        "sentinelsat.SentinelAPI.download_all",
        partialmethod(SentinelAPI.download_all, n_concurrent_dl=1, max_attempts=2),
    )

    product_id = smallest_online_products[0]["id"]
    command = ["--uuid", product_id, "--download", "--path", str(tmpdir)]

    run_cli(*command)

    # The file already exists, should not be re-downloaded
    run_cli(*command)

    # clean up
    for f in tmpdir.listdir():
        f.remove()

    # Prepare a response with an invalid checksum
    url = "https://scihub.copernicus.eu/apihub/odata/v1/Products('%s')?$format=json" % product_id
    json = api.session.get(url).json()
    json["d"]["Checksum"]["Value"] = "00000000000000000000000000000000"

    # Force the download to fail by providing an incorrect checksum
    with requests_mock.mock(real_http=True) as rqst:
        rqst.get(url, json=json)

        # md5 flag set (implicitly), should raise an exception
        run_cli(*command, must_raise=InvalidChecksumError)

    # clean up
    tmpdir.remove() 
開發者ID:sentinelsat,項目名稱:sentinelsat,代碼行數:36,代碼來源:test_cli.py


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