Revision: 5903
Author: russblau
Date: 2008-09-17 14:50:45 +0000 (Wed, 17 Sep 2008)
Log Message:
-----------
leverage use of Link objects
Modified Paths:
--------------
branches/rewrite/pywikibot/page.py
branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/page.py
===================================================================
--- branches/rewrite/pywikibot/page.py 2008-09-17 12:15:09 UTC (rev 5902)
+++ branches/rewrite/pywikibot/page.py 2008-09-17 14:50:45 UTC (rev 5903)
@@ -1439,7 +1439,7 @@
"""
self._text = text
- self.source = source
+ self._source = source
self._defaultns = defaultNamespace
def parse(self):
@@ -1451,9 +1451,9 @@
else:
self._anchor = None
- if self.source is None:
- self.source = pywikibot.Site()
- self._site = self.source
+ if self._source is None:
+ self._source = pywikibot.Site()
+ self._site = self._source
# Clean up the name, it can come from anywhere.
# Convert HTML entities to unicode
@@ -1580,7 +1580,7 @@
# Can't make a link to a namespace alone...
# "empty" local links can only be self-links
# with a fragment identifier.
- if not t and self._site == self.source and self._namespace != 0:
+ if not t and self._site == self._source and self._namespace != 0:
raise ValueError("Invalid link (no page title): '%s'" % self._text)
self._title = t
@@ -1617,8 +1617,38 @@
self.parse()
return self._anchor
+ def astext(self, onsite=None):
+ """Return a text representation of the link.
+ @param onsite: if specified, present as a (possibly interwiki) link
+ from the given site; otherwise, present as an internal link on
+ the source site.
+ """
+ if onsite is None:
+ onsite = self.site
+ title = self.title
+ if self.namespace:
+ title = onsite.namespace(self.namespace) + ":" + title
+ if self.section:
+ title = title + "#" + self.section
+ if onsite == self.site:
+ return u'[[%s]]' % title
+ if onsite.family == self.site.family:
+ return u'[[%s:%s]]' % (self.site.code, title)
+ if self.site.family.name == self.site.code:
+ # use this form for sites like commons, where the
+ # code is the same as the family name
+ return u'[[%s:%s]]' % (self.site.code,
+ title)
+ return u'[[%s:%s:%s]]' % (self.site.family.name,
+ self.site.code,
+ title)
+
+ def __str__(self):
+ return self.astext()
+
+
# Utility functions for parsing page titles
def html2unicode(text, ignore = []):
Modified: branches/rewrite/pywikibot/site.py
===================================================================
--- branches/rewrite/pywikibot/site.py 2008-09-17 12:15:09 UTC (rev 5902)
+++ branches/rewrite/pywikibot/site.py 2008-09-17 14:50:45 UTC (rev 5903)
@@ -306,46 +306,17 @@
Use optional Site argument 'othersite' to generate an interwiki link.
"""
- # TODO convert to Link method, deprecate
- if othersite and othersite.code != self.code:
- return u'[[%s:%s]]' % (self.code, title)
- else:
- return u'[[%s]]' % title
+ logger.debug("Site.linkto() method is deprecated; use pywikibot.Link")
+ return pywikibot.Link(title, self).astext(othersite)
def isInterwikiLink(self, s):
"""Return True if s is in the form of an interwiki link.
- Interwiki links have the form "foo:bar" or ":foo:bar" where foo is a
- known language code or family. Called recursively if the first part
- of the link refers to this site's own family and/or language. Do
- not include brackets around the link!
+ If a link object constructed using "s" as the link text parses as
+ belonging to a different site, this method returns True.
"""
- # TODO: convert to Link method
- s = s.strip().lstrip(":")
- if not ':' in s:
- return False
- first, rest = s.split(':',1)
- # interwiki codes are case-insensitive
- first = first.lower().strip()
- # commons: forwards interlanguage links to wikipedia:, etc.
- if self.family.interwiki_forward:
- interlangTargetFamily = pywikibot.Family(self.family.interwiki_forward)
- else:
- interlangTargetFamily = self.family
- if self.ns_index(first):
- return False
- if first in interlangTargetFamily.langs:
- if first == self.code:
- return self.isInterwikiLink(rest)
- else:
- return True
- if first in self.family.get_known_families(site = self):
- if first == self.family.name:
- return self.isInterwikiLink(rest)
- else:
- return True
- return False
+ return (pywikibot.Link(s, self).site != self)
def redirectRegex(self):
"""Return a compiled regular expression matching on redirect pages.
@@ -916,6 +887,7 @@
% (page.title(withSection=False, asLink=True),
item['title']))
api.update_page(page, item)
+ logging.debug(str(item))
return item[tokentype + "token"]
# following group of methods map more-or-less directly to API queries
Bugs item #2114866, was opened at 2008-09-16 22:50
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2114866&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: interwiki
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Luca Landucci (kaspo)
Assigned to: Nobody/Anonymous (nobody)
Summary: wrong interwiki
Initial Comment:
The script interwiki has replaced in two pages "ofe" with "".
These are the edits:
http://it.wikipedia.org/w/index.php?title=Professor_Elm&diff=18818854&oldid… and http://it.wikipedia.org/w/index.php?title=Professor_Oak&diff=18818865&oldid…
I try again work in these page and the script give me:
[[Professor Elm]]: [[it:Professor Elm]] gives new interwiki [[en:List of characters in the Pokmon anime series#Prssor Elm]]
My versions:
Pywikipedia nightly:pywikipedia (r5858, Aug 28 2008, 11:35:51)
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)]
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2114866&group_…
Revision: 5900
Author: russblau
Date: 2008-09-16 20:03:23 +0000 (Tue, 16 Sep 2008)
Log Message:
-----------
allow for "generator=" in QueryGenerator
Modified Paths:
--------------
branches/rewrite/pywikibot/data/api.py
Modified: branches/rewrite/pywikibot/data/api.py
===================================================================
--- branches/rewrite/pywikibot/data/api.py 2008-09-16 15:09:00 UTC (rev 5899)
+++ branches/rewrite/pywikibot/data/api.py 2008-09-16 20:03:23 UTC (rev 5900)
@@ -306,9 +306,12 @@
self.prefix = "g" + self.prefix
self.request = Request(**kwargs)
self.limit = None
- self.resultkey = self.module # this is the name of the "query"
- # subelement to look for when iterating
-
+ if "generator" in kwargs:
+ self.resultkey = "pages" # name of the "query"
+ else: # subelement key
+ self.resultkey = self.module # to look for when iterating
+
+
def get_module(self):
"""Query api on self.site for paraminfo on querymodule=self.module"""