Skip to content

Commit

Permalink
adds postinit
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Oct 23, 2024
1 parent 204b88b commit eef7363
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion tests/test_wikiuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def testCommandLine(self):
]
wikibot3rd.wikiuser_cmd.main(args)
finally:
if self.debug:
debug=self.debug
debug=True
if debug:
print(open(path, "r").read())
props = WikiUser.readPropertyFile(path)
rUser = WikiUser.ofDict(props, encrypted=True)
Expand Down
2 changes: 2 additions & 0 deletions wikibot3rd/wikiclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def of_wiki_id(
"""
wiki_user = WikiUser.ofWikiId(wiki_id, lenient=lenient)
wikibot = WikiClient(wiki_user, debug=debug)
wikibot.is_smw_enabled=wiki_user.is_smw
return wikibot

@staticmethod
Expand All @@ -257,6 +258,7 @@ def of_wiki_user(wiki_user: WikiUser,debug:bool=False) -> "WikiClient":
WikiClient: A WikiClient instance for the given WikiUser.
"""
wikibot = WikiClient(wiki_user,debug=debug)
wikibot.is_smw_enabled=wiki_user.is_smw
return wikibot

@staticmethod
Expand Down
13 changes: 12 additions & 1 deletion wikibot3rd/wikiuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ class WikiUserData(WikiCredentials):
email: str = None
is_smw: bool = True

def __post_init__(self):
WikiCredentials.__post_init__(self)
if isinstance(self.is_smw, str):
normalized_value = self.is_smw.strip().lower()
if normalized_value in {"yes", "y", "true"}:
self.is_smw = True
elif normalized_value in {"no", "n", "false"}:
self.is_smw = False
else:
raise ValueError(f"Invalid value for is_smw: {self.is_smw}")

@dataclass
class WikiUser(WikiUserData):
Expand Down Expand Up @@ -294,7 +304,8 @@ def ofDict(cls, userDict: dict, encrypted=True, lenient=False, encrypt=True):
WikiUser: the WikiUser created from the dictionary
"""
if "url" in userDict and userDict["url"] is not None:
userDict["url"] = userDict["url"].replace("\:", ":")
# fix broken escapes e.g. http\://waihekepedia.bitplan.com
userDict["url"] = userDict["url"].replace(r"\:", ":")

is_encrypted = "password" not in userDict

Expand Down

0 comments on commit eef7363

Please sign in to comment.