Skip to content

Commit ca23d5e

Browse files
authored
Merge pull request #33 from ukwhatn/develop
Release v3.1.0dev11
2 parents 6ee7da1 + f481acb commit ca23d5e

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "wikidot"
3-
version = "3.1.0dev10"
3+
version = "3.1.0dev11"
44
authors = [{ name = "ukwhatn", email = "ukwhatn@gmail.com" }]
55
description = "Wikidot Utility Library"
66
readme = "README.md"

src/wikidot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .module.client import Client
1414

1515
__all__ = ["Client"]
16-
__version__ = "3.1.0dev10"
16+
__version__ = "3.1.0dev11"
1717

1818

1919
# 全クラス・モジュールを公開する

src/wikidot/common/decorators.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def login_required(func):
1919
1. client という名前の引数
2020
2. Client クラスのインスタンスである引数
2121
3. self.client(呼び出し元オブジェクトの属性)
22+
4. selfが持つ属性が持つclientクラス(例:self.site.client)
2223
2324
Parameters
2425
----------
@@ -52,9 +53,19 @@ def wrapper(*args, **kwargs):
5253
break
5354

5455
# selfに存在するか?
55-
if client is None:
56+
if client is None and args:
5657
if hasattr(args[0], "client"):
5758
client = args[0].client
59+
else:
60+
# selfが持つ属性にclientが存在するか探索する
61+
for attr_name in dir(args[0]):
62+
if attr_name.startswith("_"):
63+
continue
64+
attr = getattr(args[0], attr_name)
65+
if hasattr(attr, "client"):
66+
client = getattr(attr, "client")
67+
if isinstance(client, Client):
68+
break
5869

5970
if client is None:
6071
raise ValueError("Client is not found")

0 commit comments

Comments
 (0)