{"id":20613883,"url":"https://github.com/python-tools/pyproxypattern","last_synced_at":"2026-04-19T17:37:18.098Z","repository":{"id":62582765,"uuid":"315222940","full_name":"Python-Tools/pyproxypattern","owner":"Python-Tools","description":"根据peewee的proxy做的单独的python对象代理模式","archived":false,"fork":false,"pushed_at":"2021-01-13T06:15:48.000Z","size":3015,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-17T04:09:32.286Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Python-Tools.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-23T06:37:39.000Z","updated_at":"2021-01-13T06:12:42.000Z","dependencies_parsed_at":"2022-11-03T21:34:12.233Z","dependency_job_id":null,"html_url":"https://github.com/Python-Tools/pyproxypattern","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Python-Tools%2Fpyproxypattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Python-Tools%2Fpyproxypattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Python-Tools%2Fpyproxypattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Python-Tools%2Fpyproxypattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Python-Tools","download_url":"https://codeload.github.com/Python-Tools/pyproxypattern/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242268603,"owners_count":20100067,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T11:11:19.703Z","updated_at":"2026-04-19T17:37:18.069Z","avatar_url":"https://github.com/Python-Tools.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pyproxypattern\n\n根据peewee的proxy做的单独的python对象代理模式.\n\n## 特性\n\n+ 提供一个相对通用的代理类`Proxy`\n+ 提供用于检测代理对象类型的回调函数`attach_instance_check`\n+ 提供在初始化代理对象后的回调函数注册器`attach_callback`,回调函数回按注册的顺序执行\n+ 可以代理上下文对象,迭代器对象\n+ 可以代理异步上下文对象,异步迭代器对象\n\n## 安装\n\n`pip install pyproxypattern`\n\n## 使用\n\n两种方式:\n\n1. 直接使用`Proxy`的实例代理对象\n\n    ```python\n    class Test_B:\n        def get2(self) -\u003e int:\n            return 2\n    B = Test_B()\n    proxy = Proxy()\n    proxy.attach_instance_check(lambda x: isinstance(x, Test_B))\n    proxy.initialize(B)\n    proxy.get2() == 2\n    ```\n\n2. 将`Proxy`类作为父类构造一个更加负载的代理类,然后再用它的实例代理特定对象\n\n    ```python\n    class AredisProxy(Proxy):\n        \"\"\"aredis的代理类.\"\"\"\n        __slots__ = ('instance', \"_callbacks\", \"_instance_check\", \"url\")\n\n        def __init__(self, url: Optional[str] = None, decode_responses: bool = True, **kwargs: Any) -\u003e None:\n            if url:\n                instance = self.new_instance(url, decode_responses, **kwargs)\n                super().__init__(instance)\n            else:\n                super().__init__()\n\n        def new_instance(self, url: str, decode_responses: bool, **kwargs: Any) -\u003e Any:\n            self.url = url\n            return StrictRedis.from_url(url, decode_responses=decode_responses, **kwargs)\n\n        def initialize_from_url(self, url: str, *, decode_responses: bool = False, **kwargs: Any) -\u003e None:\n            \"\"\"初始化.\"\"\"\n            instance = self.new_instance(url, decode_responses, **kwargs)\n            self.initialize(instance)\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-tools%2Fpyproxypattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpython-tools%2Fpyproxypattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-tools%2Fpyproxypattern/lists"}