当前位置: 首页>>代码示例>>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;未经允许,请勿转载。