Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "wikidot"
version = "3.1.0dev10"
version = "3.1.0dev11"
authors = [{ name = "ukwhatn", email = "[email protected]" }]
description = "Wikidot Utility Library"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion src/wikidot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .module.client import Client

__all__ = ["Client"]
__version__ = "3.1.0dev10"
__version__ = "3.1.0dev11"


# 全クラス・モジュールを公開する
Expand Down
13 changes: 12 additions & 1 deletion src/wikidot/common/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def login_required(func):
1. client という名前の引数
2. Client クラスのインスタンスである引数
3. self.client(呼び出し元オブジェクトの属性)
4. selfが持つ属性が持つclientクラス(例:self.site.client)

Parameters
----------
Expand Down Expand Up @@ -52,9 +53,19 @@ def wrapper(*args, **kwargs):
break

# selfに存在するか?
if client is None:
if client is None and args:
if hasattr(args[0], "client"):
client = args[0].client
else:
# selfが持つ属性にclientが存在するか探索する
for attr_name in dir(args[0]):
if attr_name.startswith("_"):
continue
attr = getattr(args[0], attr_name)
if hasattr(attr, "client"):
client = getattr(attr, "client")
if isinstance(client, Client):
break

if client is None:
raise ValueError("Client is not found")
Expand Down