@@ -16,6 +16,16 @@ class Category(Page): | |||||
members -- returns a list of titles in the category | members -- returns a list of titles in the category | ||||
""" | """ | ||||
def __repr__(self): | |||||
"""Returns the canonical string representation of the Category.""" | |||||
res = ", ".join(("Category(title={0!r}", "follow_redirects={1!r}", | |||||
"site={2!r})")) | |||||
return res.format(self._title, self._follow_redirects, self._site) | |||||
def __str__(self): | |||||
"""Returns a nice string representation of the Category.""" | |||||
return '<Category "{0}" of {1}>'.format(self.title(), str(self._site)) | |||||
def members(self, limit=50): | def members(self, limit=50): | ||||
"""Returns a list of titles in the category. | """Returns a list of titles in the category. | ||||
@@ -81,6 +81,16 @@ class Page(object): | |||||
else: | else: | ||||
self._is_talkpage = self._namespace % 2 == 1 | self._is_talkpage = self._namespace % 2 == 1 | ||||
def __repr__(self): | |||||
"""Returns the canonical string representation of the Page.""" | |||||
res = ", ".join(("Page(title={0!r}", "follow_redirects={1!r}", | |||||
"site={2!r})")) | |||||
return res.format(self._title, self._follow_redirects, self._site) | |||||
def __str__(self): | |||||
"""Returns a nice string representation of the Page.""" | |||||
return '<Page "{0}" of {1}>'.format(self.title(), str(self._site)) | |||||
def _force_validity(self): | def _force_validity(self): | ||||
"""Used to ensure that our page's title is valid. | """Used to ensure that our page's title is valid. | ||||
@@ -96,6 +96,31 @@ class Site(object): | |||||
if logged_in_as is None or name != logged_in_as: | if logged_in_as is None or name != logged_in_as: | ||||
self._login(login) | self._login(login) | ||||
def __repr__(self): | |||||
"""Returns the canonical string representation of the Site.""" | |||||
res = ", ".join(( | |||||
"Site(name={_name!r}", "project={_project!r}", "lang={_lang!r}", | |||||
"base_url={_base_url!r}", "article_path={_article_path!r}", | |||||
"script_path={_script_path!r}", "assert_edit={_assert_edit!r}", | |||||
"maxlag={_maxlag!r}", "sql={_sql!r}", "login={0}", | |||||
"user_agent={2!r}", "cookiejar={1})" | |||||
)) | |||||
name, password = self._login_info | |||||
login = "({0}, {1})".format(repr(name), "hidden" if password else None) | |||||
cookies = self._cookiejar.__class__.__name__ | |||||
try: | |||||
cookies += "({0!r})".format(self._cookiejar.filename) | |||||
except AttributeError: | |||||
cookies += "()" | |||||
agent = self._opener.addheaders[0][1] | |||||
return res.format(login, cookies, agent, **self.__dict__) | |||||
def __str__(self): | |||||
"""Returns a nice string representation of the Site.""" | |||||
res = "<Site {0} ({1}:{2}) at {3}>" | |||||
return res.format(self.name(), self.project(), self.lang(), | |||||
self.domain()) | |||||
def _api_query(self, params, tries=0, wait=5): | def _api_query(self, params, tries=0, wait=5): | ||||
"""Do an API query with `params` as a dict of parameters. | """Do an API query with `params` as a dict of parameters. | ||||
@@ -45,6 +45,14 @@ class User(object): | |||||
self._site = site | self._site = site | ||||
self._name = name | self._name = name | ||||
def __repr__(self): | |||||
"""Returns the canonical string representation of the User.""" | |||||
return "User(name={0!r}, site={1!r})".format(self._name, self._site) | |||||
def __str__(self): | |||||
"""Returns a nice string representation of the User.""" | |||||
return '<User "{0}" of {1}>'.format(self.name(), str(self._site)) | |||||
def _get_attribute(self, attr, force): | def _get_attribute(self, attr, force): | ||||
"""Internally used to get an attribute by name. | """Internally used to get an attribute by name. | ||||