Skip to main content

pyproxypattern

根据peewee的proxy做的单独的python对象代理模式.

特性

  • 提供一个相对通用的代理类Proxy
  • 提供用于检测代理对象类型的回调函数attach_instance_check
  • 提供在初始化代理对象后的回调函数注册器attach_callback,回调函数回按注册的顺序执行
  • 可以代理上下文对象,迭代器对象
  • 可以代理异步上下文对象,异步迭代器对象

安装

pip install pyproxypattern

使用

两种方式:

  1. 直接使用Proxy的实例代理对象

    class Test_B:
        def get2(self) -> int:
            return 2
    B = Test_B()
    proxy = Proxy()
    proxy.attach_instance_check(lambda x: isinstance(x, Test_B))
    proxy.initialize(B)
    proxy.get2() == 2
    
  2. 将Proxy类作为父类构造一个更加负载的代理类,然后再用它的实例代理特定对象

    class AredisProxy(Proxy):
        """aredis的代理类."""
        __slots__ = ('instance', "_callbacks", "_instance_check", "url")
    
        def __init__(self, url: Optional[str] = None, decode_responses: bool = True, **kwargs: Any) -> None:
            if url:
                instance = self.new_instance(url, decode_responses, **kwargs)
                super().__init__(instance)
            else:
                super().__init__()
    
        def new_instance(self, url: str, decode_responses: bool, **kwargs: Any) -> Any:
            self.url = url
            return StrictRedis.from_url(url, decode_responses=decode_responses, **kwargs)
    
        def initialize_from_url(self, url: str, *, decode_responses: bool = False, **kwargs: Any) -> None:
            """初始化."""
            instance = self.new_instance(url, decode_responses, **kwargs)
            self.initialize(instance)
    

0.0.1

项目创建 MIT License

Copyright (c) 2020 Python-Tools

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Release files for pyproxypattern 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyproxypattern 0.0.1
File Size Uploaded Provenance Actions
pyproxypattern-0.0.1.tar.gz 4.2 kB Without provenance Details for pyproxypattern-0.0.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pyproxypattern 0.0.1
File Interpreter ABI Platform Actions
pyproxypattern-0.0.1-py3.9.egg Legacy Egg format - - Details for pyproxypattern-0.0.1-py3.9.egg
pyproxypattern-0.0.1-py3-none-any.whl Python 3 none any Details for pyproxypattern-0.0.1-py3-none-any.whl

Total release size: 13.0 kB

Release files / pyproxypattern-0.0.1.tar.gz

Download URL pyproxypattern-0.0.1.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a7cfd6ceeb4f40ec7109ed3b004e6170f3fec30d42197a304c73d08851d9cdc5
BLAKE2b-256 checksum
How to use checksums
1d5509010e89c034a325dde267cee6fb15ab2c086365a83f1ee312660015ff19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

Release files / pyproxypattern-0.0.1-py3.9.egg

Download URL pyproxypattern-0.0.1-py3.9.egg
Size 3.9 kB
Tags Egg
SHA-256 checksum
How to use checksums
9300b3c34e89e15e6841122562c125522852fc726fe36cd074be9617ea69f959
BLAKE2b-256 checksum
How to use checksums
d68292400c3e78231916fd8e6b1543d27eb49ef112fb978c22590900c5c24c56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

Release files / pyproxypattern-0.0.1-py3-none-any.whl

Download URL pyproxypattern-0.0.1-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f47e3e96ca1ea39a4561e16d7144a334fd9007c0598f063a33f235741392717
BLAKE2b-256 checksum
How to use checksums
ca2c42c02dca721f9e64cd2d6a5c9d3c211a66d37a42b536dc2ffb18f4272ef4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

Security for pyproxypattern 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

3 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page