Bugs item #1908157, was opened at 2008-03-05 12:08
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=1908157&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: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: AndreasJS (andreasjs)
Assigned to: Nobody/Anonymous (nobody)
Summary: Cannot edit large page in Python 2.5
Initial Comment:
Cannot edit large page in Python 2.5.
A socket error 35 occurs. It consistently occurs if the page is > about 30 kbyte.
Woks OK in python 2.3.
andreas-schwabs-computer:~/Desktop/pywikipedia andreas$ python basic.py -family:wikipedia -lang:en -page:User:AndreasJS/test
Checked for running processes. 1 processes currently running, including the current process.
Getting 1 pages from wikipedia:en...
>>> User:AndreasJS/test <<<
- Test Test [[image:Wikipedia.png|thumb|This is the [[logo]] of Wikinews]]
+ Test Test Test [[image:Wikipedia.png|thumb|This is the [[logo]] of Wikinews]]
Do you want to accept these changes? ([y]es, [N]o) y
Sleeping for 5.6 seconds, 2008-03-05 11:57:19
Changing page [[en:User:AndreasJS/test]]
Traceback (most recent call last):
File "/Users/andreas/Desktop/pywikipedia/wikipedia.py", line 1287, in _putPage
response, data = self.site().postForm(address, predata, sysop)
File "/Users/andreas/Desktop/pywikipedia/wikipedia.py", line 4014, in postForm
raise ServerError(e)
ServerError: (35, 'Resource temporarily unavailable')
Got a server error when putting [[User:AndreasJS/test]]; will retry in 1 minute.
Changing page [[en:User:AndreasJS/test]]
Traceback (most recent call last):
File "/Users/andreas/Desktop/pywikipedia/wikipedia.py", line 1287, in _putPage
response, data = self.site().postForm(address, predata, sysop)
File "/Users/andreas/Desktop/pywikipedia/wikipedia.py", line 4014, in postForm
raise ServerError(e)
ServerError: (35, 'Resource temporarily unavailable')
Got a server error when putting [[User:AndreasJS/test]]; will retry in 2 minutes.
Changing page [[en:User:AndreasJS/test]]
Traceback (most recent call last):
File "/Users/andreas/Desktop/pywikipedia/wikipedia.py", line 1287, in _putPage
response, data = self.site().postForm(address, predata, sysop)
File "/Users/andreas/Desktop/pywikipedia/wikipedia.py", line 4014, in postForm
raise ServerError(e)
ServerError: (35, 'Resource temporarily unavailable')
Got a server error when putting [[User:AndreasJS/test]]; will retry in 4 minutes.
----------
andreas-schwabs-computer:~/Desktop/pywikipedia andreas$ python
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
System Software Overview:
System Version: Mac OS X 10.4.11 (8S2167)
Kernel Version: Darwin 8.11.1
Boot Volume: Macintosh HD
Computer Name: Andreas Schwab’s Computer
User Name: Andreas Schwab (andreas)
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1908157&group_…
Hello
I use pywikipediabot for years and i've written some patches for it. Since i
get fresh version from svn i have some annoying conflicts and .mine files
spamming my bot directory. I would like to commit my work, is it here the
place for asking such permission ?
In attached file an example of the work i've done on fixing_redirects.py :
before the fixes the script was bogus on ~5% of pages (case artifacts, image
and categories not handled...), after the fixes, it was 100% success from
"-start:!" to end of allpages (yeah i'm quite perfectionist so i like
spotting *every* link leading to a redirect on the wiki i work on :
fr.wikibooks where there is 5000+ pages). I've also fixed several bugs
listed on sourceforge bug tracking system. Could i also have the permission
to tag them as closed ? (maybe should i ask elsewhere ?)
Marvus
Patches item #1907586, was opened at 2008-03-05 01:14
Message generated for change (Settings changed) made by purodha
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603140&aid=1907586&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: None
Group: None
Status: Open
Resolution: None
>Priority: 8
Private: No
Submitted By: Purodha B Blissenbach (purodha)
Assigned to: Nobody/Anonymous (nobody)
>Summary: Make edit tokens dynamic in wikipedia.py
Initial Comment:
Edit tokens in wikpedia.py were effectively constants up to this patch. When a token was outdated, a new one was not obtained, and edit access to the site never functioned again until the program was restarted.
The problem is described in more detail in:
https://sourceforge.net/tracker/index.php?func=detail&aid=1903113&group_id=…
The attached patch makes tokens a bit more dynamic, it allows loading of new ones when an edit page requires.
I have tested the code, with interwiki-py only, for about 20 hours in manually assisted mode in 3, sometimes 4, parallel sessions in verbose mode. The altered branch was executed several dozen times, no problems seen.
Nevertheless, I recommend a review. I am not knowledgeable enough to be sure that there are no sideffects. I am not a python expert, so maybe, I made it too complicated. Also, though I did run few other pywikipediabot programs which were using the altered wikipdia.py without apaprent problems, that cannot be called a valid test.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603140&aid=1907586&group_…
Patches item #1907586, was opened at 2008-03-05 01:14
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603140&aid=1907586&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: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Purodha B Blissenbach (purodha)
Assigned to: Nobody/Anonymous (nobody)
Summary: Make edit token dynamic in wikipedia.py
Initial Comment:
Edit tokens in wikpedia.py were effectively constants up to this patch. When a token was outdated, a new one was not obtained, and edit access to the site never functioned again until the program was restarted.
The problem is described in more detail in:
https://sourceforge.net/tracker/index.php?func=detail&aid=1903113&group_id=…
The attached patch makes tokens a bit more dynamic, it allows loading of new ones when an edit page requires.
I have tested the code, with interwiki-py only, for about 20 hours in manually assisted mode in 3, sometimes 4, parallel sessions in verbose mode. The altered branch was executed several dozen times, no problems seen.
Nevertheless, I recommend a review. I am not knowledgeable enough to be sure that there are no sideffects. I am not a python expert, so maybe, I made it too complicated. Also, though I did run few other pywikipediabot programs which were using the altered wikipdia.py without apaprent problems, that cannot be called a valid test.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603140&aid=1907586&group_…
Bugs item #1683927, was opened at 2007-03-19 15:54
Message generated for change (Settings changed) made by russblau
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1683927&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: solve_disambiguation
Group: None
>Status: Closed
>Resolution: Works For Me
Priority: 5
Private: No
Submitted By: Robin Green (greenrd)
Assigned to: Nobody/Anonymous (nobody)
Summary: Segmentation fault trying to edit Vocabulary
Initial Comment:
I typed 'e' in solve_disambiguation.py to edit the Vocabulary article, and got:
1922
Segmentation fault
The editing window appeared for a split-second and then disappeared.
----------------------------------------------------------------------
Comment By: Russell Blau (russblau)
Date: 2007-11-21 10:18
Message:
Logged In: YES
user_id=855050
Originator: NO
Works for me. If there is still a problem, please provide more details
(what site you were editing, what term you were disambiguating, etc.).
----------------------------------------------------------------------
Comment By: Leonardo Gregianin (leogregianin)
Date: 2007-06-20 10:40
Message:
Logged In: YES
user_id=1136737
Originator: NO
I never had this, still I happen this problem?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1683927&group_…
Bugs item #1633513, was opened at 2007-01-11 15:20
Message generated for change (Settings changed) made by russblau
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1633513&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: tuvic (tuvic)
Assigned to: Nobody/Anonymous (nobody)
Summary: Interwiki.py graphs when in autonomous mode
Initial Comment:
The interwiki-bot tries to make graphs when it's in autonomous mode, if you have the option interwiki-graphs switched on.
It shouldn't do that, because it destroys the autonomous behavior.
>>if config.interwiki_graph:<<
on line 745 of the code (r 1.343) should be changed to
>>if config.interwiki_graph and (not globalvar.autonomous):<<
Greetings, Tuvic
----------------------------------------------------------------------
Comment By: tuvic (tuvic)
Date: 2007-01-12 10:20
Message:
Logged In: YES
user_id=1557188
Originator: YES
I'm sorry, I forgot I had put in a little piece of code that first asks
before creating a graph.
So, it doesn't destroy the autonomous mode, but it will use up a lot
(sometimes a gigantic amount) of cpu unnecessary.
It creates graphs while you can't do anything with them at that point, and
most likely the situation will have changed when you run a manual bot the
next time.
Greetings, Tuvic
----------------------------------------------------------------------
Comment By: Daniel Herding (wikipedian)
Date: 2007-01-12 06:50
Message:
Logged In: YES
user_id=880694
Originator: NO
Why does it destroy autonomous behaviour? Creating graphs is done fully
automatic.
I think the real problem here is that creating graphs takes too long.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1633513&group_…
Revision: 5102
Author: russblau
Date: 2008-03-04 18:13:32 +0000 (Tue, 04 Mar 2008)
Log Message:
-----------
Improve initialization of Page objects; related changes to other modules
Modified Paths:
--------------
branches/rewrite/pywikibot/__init__.py
branches/rewrite/pywikibot/data/api.py
branches/rewrite/pywikibot/families/wikipedia_family.py
branches/rewrite/pywikibot/login.py
branches/rewrite/pywikibot/page.py
branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/__init__.py
===================================================================
--- branches/rewrite/pywikibot/__init__.py 2008-03-03 14:58:39 UTC (rev 5101)
+++ branches/rewrite/pywikibot/__init__.py 2008-03-04 18:13:32 UTC (rev 5102)
@@ -65,3 +65,6 @@
import getpass
return getpass.getpass(prompt)
return raw_input(prompt)
+
+import logging
+logging.getLogger().setLevel(logging.DEBUG)
Modified: branches/rewrite/pywikibot/data/api.py
===================================================================
--- branches/rewrite/pywikibot/data/api.py 2008-03-03 14:58:39 UTC (rev 5101)
+++ branches/rewrite/pywikibot/data/api.py 2008-03-04 18:13:32 UTC (rev 5102)
@@ -26,7 +26,7 @@
lagpattern = re.compile(r"Waiting for [\d.]+: (?P<lag>\d+) seconds? lagged")
-class APIError(Exception):
+class APIError(pywikibot.Error):
"""The wiki site returned an error message."""
def __init__(self, code, info, **kwargs):
"""Save error dict returned by MW API."""
@@ -39,7 +39,7 @@
return "%(code)s: %(info)s" % self.__dict__
-class TimeoutError(Exception):
+class TimeoutError(pywikibot.Error):
pass
Modified: branches/rewrite/pywikibot/families/wikipedia_family.py
===================================================================
--- branches/rewrite/pywikibot/families/wikipedia_family.py 2008-03-03 14:58:39 UTC (rev 5101)
+++ branches/rewrite/pywikibot/families/wikipedia_family.py 2008-03-04 18:13:32 UTC (rev 5102)
@@ -773,7 +773,7 @@
def get_known_families(self, site):
# In Swedish Wikipedia 's:' is part of page title not a family
# prefix for 'wikisource'.
- if site.lang == 'sv':
+ if site.language() == 'sv':
d = self.known_families.copy()
d.pop('s') ; d['src'] = 'wikisource'
return d
Modified: branches/rewrite/pywikibot/login.py
===================================================================
--- branches/rewrite/pywikibot/login.py 2008-03-03 14:58:39 UTC (rev 5101)
+++ branches/rewrite/pywikibot/login.py 2008-03-04 18:13:32 UTC (rev 5102)
@@ -48,7 +48,6 @@
import urllib2
import config
import pywikibot
-from pywikibot import Page
from pywikibot.exceptions import *
# On some wikis you are only allowed to run a bot if there is a link to
@@ -91,7 +90,7 @@
return True # DEBUG
if botList.has_key(self.site.family.name) and botList[self.site.family.name].has_key(self.site.language()):
botListPageTitle = botList[self.site.family.name][self.site.language()]
- botListPage = Page(self.site, botListPageTitle)
+ botListPage = pywikibot.Page(self.site, botListPageTitle)
for linkedPage in botListPage.linkedPages():
if linkedPage.titleWithoutNamespace() == self.username:
return True
Modified: branches/rewrite/pywikibot/page.py
===================================================================
--- branches/rewrite/pywikibot/page.py 2008-03-03 14:58:39 UTC (rev 5101)
+++ branches/rewrite/pywikibot/page.py 2008-03-04 18:13:32 UTC (rev 5102)
@@ -10,7 +10,7 @@
__version__ = '$Id: $'
import pywikibot
-from pywikibot.exceptions import *
+import pywikibot.site
import htmlentitydefs
import logging
@@ -28,109 +28,84 @@
reading from or writing to the wiki. All other methods are delegated
to the Site object.
- Methods available:
- - site: The wiki this page is in
- - title: The name of the page, with various presentation options
- - namespace: The namespace in which the page is found
- - section: The section of the page (the part of the title after '#', if
- any)
- - isAutoTitle: Title can be translated using the autoFormat method
- - autoFormat: Auto-format certain dates and other standard format page
- titles
- - isCategory: True if the page is a category
- - isDisambig (*): True if the page is a disambiguation page
- - isImage: True if the page is an image
- - isRedirectPage (*): True if the page is a redirect, false otherwise
- - getRedirectTarget (*): The page the page redirects to
- - isTalkPage: True if the page is in any "talk" namespace
- - toggleTalkPage: Return the talk page (if this is one, return the
- non-talk page)
- - get (*): The text of the page
- - latestRevision (*): The page's current revision id
- - userName: Last user to edit page
- - isIpEdit: True if last editor was unregistered
- - editTime: Timestamp of the last revision to the page
- - previousRevision (*): The revision id of the previous version
- - permalink (*): The url of the permalink of the current version
- - getOldVersion(id) (*): The text of a previous version of the page
- - getVersionHistory: Load the version history information from wiki
- - getVersionHistoryTable: Create a wiki table from the history data
- - fullVersionHistory: Return all past versions including wikitext
- - contributingUsers: Return set of users who have edited page
- - exists (*): True if the page actually exists, false otherwise
- - isEmpty (*): True if the page has 4 characters or less content, not
- counting interwiki and category links
- - interwiki (*): The interwiki links from the page (list of Pages)
- - categories (*): The categories the page is in (list of Pages)
- - linkedPages (*): The normal pages linked from the page (list of
- Pages)
- - imagelinks (*): The pictures on the page (list of ImagePages)
- - templates (*): All templates referenced on the page (list of Pages)
- - templatesWithParams(*): All templates on the page, with list of
- parameters
- - isDisambig (*): True if the page is a disambiguation page
- - getReferences: List of pages linking to the page
- - canBeEdited (*): True if page is unprotected or user has edit
- privileges
- - botMayEdit (*): True if bot is allowed to edit page
- - put(newtext): Saves the page
- - put_async(newtext): Queues the page to be saved asynchronously
- - move: Move the page to another title
- - delete: Deletes the page (requires being logged in)
- - protect: Protect or unprotect a page (requires sysop status)
- - removeImage: Remove all instances of an image from this page
- - replaceImage: Replace all instances of an image with another
- - loadDeletedRevisions: Load all deleted versions of this page
- - getDeletedRevision: Return a particular deleted revision
- - markDeletedRevision: Mark a version to be undeleted, or not
- - undelete: Undelete past version(s) of the page
+ """
+ def __init__(self, source, title=u"", ns=0, insite=None,
+ defaultNamespace=None):
+ """Instantiate a Page object.
- Deprecated methods (preserved for backwards-compatibility):
- - urlname: Title, in a form suitable for a URL
- - titleWithoutNamespace: Title, with the namespace part removed
- - sectionFreeTitle: Title, without the section part
- - aslink: Title in the form [[Title]] or [[lang:Title]]
- - encoding: The encoding of the page
+ Three calling formats are supported:
- (*) This loads the page if it has not been loaded before; permalink might
- even reload it if it has been loaded before
+ - If the first argument is a Page, create a copy of that object.
+ This can be used to convert an existing Page into a subclass
+ object, such as Category or ImagePage.
+ - If the first argument is a Site, create a Page on that Site
+ using the second argument as the title (may include a section),
+ and the third as the namespace number. The namespace number is
+ mandatory, even if the title includes the namespace prefix. This
+ is the preferred syntax when using an already-normalized title
+ obtained from api.php or a database dump. WARNING: may produce
+ invalid objects if page title isn't in normal form!
+ - If the first argument is a Link, create a Page from that link.
+ This is the preferred syntax when using a title scraped from
+ wikitext, URLs, or another non-normalized source.
- """
- def __init__(self, site, title, insite=None,
- defaultNamespace=0):
- """Parameters:
-
- @param site: the wikimedia Site on which the page resides
- @param title: title of the page
+ @param source: the source of the page
+ @type source: Link, Page (or subclass), or Site
+ @param title: normalized title of the page; required if source is a
+ Site, ignored otherwise
@type title: unicode
- @param insite: (optional) a wikimedia Site where this link was found
- (to help decode interwiki links)
- @param defaultNamespace: (optional) A namespace to use if the link
- does not contain one
- @type defaultNamespace: int
+ @param ns: namespace number; required if source is a Site, ignored
+ otherwise
+ @type ns: int
+ @param insite: DEPRECATED (use Link instead)
+ @param defaultNamespace: DEPRECATED (use Link instead)
"""
- if site == None:
- self._site = pywikibot.Site()
- elif isinstance(site, basestring):
- self._site = pywikibot.Site(site)
+ if insite is not None:
+ logging.debug(
+ "The 'insite' option in Page constructor is deprecated.")
+ if defaultNamespace is not None:
+ logging.debug(
+ "The 'defaultNamespace' option in Page constructor is deprecated.")
+ if isinstance(source, pywikibot.site.BaseSite):
+ self._site = source
+ if ns not in source.namespaces():
+ raise pywikibot.Error(
+ "Invalid namespace '%i' for site %s."
+ % (ns, source.sitename()))
+ self._ns = ns
+ if ns and not title.startswith(source.namespace(ns)+u":"):
+ title = source.namespace(ns) + u":" + title
+ elif not ns and u":" in title:
+ nsindex = source.getNamespaceIndex(title[ :title.index(u":")])
+ if nsindex:
+ self._ns = nsindex
+ if u"#" in title:
+ title, self._section = title.split(u"#", 1)
+ else:
+ self._section = None
+ if not title:
+ raise pywikibot.Error(
+ "Page object cannot be created from Site without title.")
+ self._title = title
+ elif isinstance(source, Page):
+ # copy all of source's attributes to this object
+ self.__dict__ = source.__dict__
+ elif isinstance(source, Link):
+ self._site = link.site
+ self._section = link.section
+ self._ns = link.namespace
+ self._title = link.title
+ # reassemble the canonical title from components
+ if self._ns:
+ self._title = "%s:%s" % (self.site().namespace(self._ns),
+ self._title)
else:
- self._site = site
-
- if not insite: insite = self._site
-
- # parse the title
- # this can throw various exceptions if the title is invalid
- link = Link(title, insite, defaultNamespace)
- self._site = link.site
- self._section = link.section
- self._ns = link.namespace
- self._title = link.title
- # reassemble the canonical title from components
+ raise pywikibot.Error(
+ "Invalid argument type '%s' in Page constructor: %s"
+ % (type(source), source))
if self._section is not None:
self._title = self._title + "#" + self._section
- if self._ns:
- self._title = self.site().namespace(self._ns) + ":" + self._title
self._revisions = {}
def site(self):
@@ -138,14 +113,7 @@
return self._site
def namespace(self):
- """Return the number of the namespace of the page.
-
- Only recognizes those namespaces defined in family.py.
- If not defined, it will return 0 (the main namespace).
-
- @return: int
-
- """
+ """Return the number of the namespace of the page."""
return self._ns
def title(self, underscore=False, savetitle=False, withNamespace=True,
@@ -186,13 +154,12 @@
allowInterwiki and self.site() != pywikibot.Site()):
if self.site().family() != pywikibot.Site().family() \
and self.site().family().name != self.site().language():
-# FIXME: Interwiki links shouldn't be fully urlencoded
return u'[[%s:%s:%s]]' % (self.site().family().name,
self.site().language(),
- self.title(asUrl=True))
+ self._title)
else:
return u'[[%s:%s]]' % (self.site().language(),
- self.title(asUrl=True))
+ self._title)
elif textlink and (self.isImage() or self.isCategory()):
return u'[[:%s]]' % title
else:
@@ -225,7 +192,12 @@
return u"%s(%s)" % (self.__class__.__name__, self.title())
def __cmp__(self, other):
- """Test for equality and inequality of Page objects"""
+ """Test for equality and inequality of Page objects.
+
+ Page objects are "equal" if and only if they are on the same site
+ and have the same normalized title, including section if any.
+
+ """
if not isinstance(other, Page):
# especially, return -1 if other is None
return -1
@@ -302,7 +274,7 @@
else:
# Make sure we re-raise an exception we got on an earlier attempt
if hasattr(self, '_redirarg') and not get_redirect:
- raise IsRedirectPage, self._redirarg
+ raise pywikibot.IsRedirectPage, self._redirarg
elif hasattr(self, '_getexception'):
raise self._getexception
if force or not hasattr(self, "_revid") \
@@ -517,7 +489,9 @@
return True
try:
templates = self.templatesWithParams();
- except (NoPage, IsRedirectPage, SectionError):
+ except (pywikibot.NoPage,
+ pywikibot.IsRedirectPage,
+ pywikibot.SectionError):
return True
for template in templates:
title = template[0].title(withNamespace=False)
@@ -980,8 +954,8 @@
usingPages : Iterate Pages on which the image is displayed.
"""
- def __init__(self, site, title, insite = None):
- Page.__init__(self, site, title, insite, defaultNamespace=6)
+ def __init__(self, source, title=u"", insite=None):
+ Page.__init__(self, source, title, 6)
if self.namespace() != 6:
raise ValueError(u"'%s' is not in the image namespace!" % title)
@@ -1065,17 +1039,16 @@
class Category(Page):
"""A page in the Category: namespace"""
- def __init__(self, site, title, insite=None, sortKey=None):
+ def __init__(self, source, title, insite=None, sortKey=None):
"""All parameters are the same as for Page() constructor, except:
@param sortKey: DEPRECATED (use .aslink() method instead)
"""
- Page.__init__(self, site=site, title=title, insite=insite,
- defaultNamespace=14)
if sortKey is not None:
logging.debug(
"The 'sortKey' option in Category constructor is deprecated.")
+ Page.__init__(self, source, title, 14)
if self.namespace() != 14:
raise ValueError(u"'%s' is not in the category namespace!"
% title)
@@ -1358,78 +1331,70 @@
# This code was adapted from Title.php : secureAndSplit()
#
if u'\ufffd' in t:
- raise Error("Title contains illegal char (\\uFFFD)")
+ raise pywikibot.Error("Title contains illegal char (\\uFFFD)")
self.namespace = defaultNamespace
# Replace underscores by spaces
- t = t.replace(u'_', u' ')
+ t = t.replace(u"_", u" ")
# replace multiple spaces and underscores with a single space
while u" " in t: t = t.replace(u" ", u" ")
# Strip spaces at both ends
- t = t.strip()
+ t = t.strip(" ")
# Remove left-to-right and right-to-left markers.
- t = t.replace(u'\u200e', u'').replace(u'\u200f', u'')
+ t = t.replace(u"\u200e", u"").replace(u"\u200f", u"")
- # Initial colon indicates main namespace rather than specified default
- if t.startswith(u':'):
- self.namespace = 0
- # remove the colon but continue processing
- # remove any subsequent whitespace
- t = t[1:].strip()
-
- # Namespace or interwiki prefix
firstPass = True
- while True:
- fam = self.site.family
+ while u":" in t:
+ # Initial colon indicates main namespace rather than default
+ if t.startswith(u":"):
+ self.namespace = 0
+ # remove the colon but continue processing
+ # remove any subsequent whitespace
+ t = t.lstrip(u":").lstrip(u" ")
+ continue
- m = Link.namespace_pattern.match(t)
- if m:
- pre = m.group(1).lower()
- ns = self.site.getNamespaceIndex(pre)
- if ns:
- # Ordinary namespace
- t = m.group(2)
- self.namespace = ns
- elif pre in fam.langs.keys()\
- or pre in fam.get_known_families(site=self.site):
-
- if not firstPass:
- # Can't make a local interwiki link to an interwiki link.
- # That's just crazy!
- raise Error("Improperly formatted interwiki link '%s'"
- % text)
-
- # Interwiki link
- t = m.group(2)
- if pre in fam.langs.keys():
- newsite = pywikibot.Site(pre, fam)
- else:
- otherlang = self.site.lang
- familyName = fam.get_known_families(site=self.site)[pre]
- if familyName in ['commons', 'meta']:
- otherlang = familyName
- try:
- newsite = pywikibot.Site(otherlang, familyName)
- except ValueError:
- raise Error("""\
+ fam = self.site.family()
+ prefix = t[ :t.index(u":")].lower()
+ ns = self.site.getNamespaceIndex(prefix)
+ if ns:
+ # Ordinary namespace
+ t = t[t.index(u":"): ].lstrip(u":").lstrip(u" ")
+ self.namespace = ns
+ break
+ if prefix in fam.langs.keys()\
+ or prefix in fam.get_known_families(site=self.site):
+ # looks like an interwiki link
+ if not firstPass:
+ # Can't make a local interwiki link to an interwiki link.
+ # That's just crazy!
+ raise pywikibot.Error(
+ "Improperly formatted interwiki link '%s'"
+ % text)
+ t = t[t.index(u":"): ].lstrip(u":").lstrip(u" ")
+ if prefix in fam.langs.keys():
+ newsite = pywikibot.Site(pre, fam)
+ else:
+ otherlang = self.site.lang
+ familyName = fam.get_known_families(site=self.site)[pre]
+ if familyName in ['commons', 'meta']:
+ otherlang = familyName
+ try:
+ newsite = pywikibot.Site(otherlang, familyName)
+ except ValueError:
+ raise pywikibot.Error("""\
%s is not a local page on %s, and the %s family is
not supported by PyWikiBot!"""
- % (title, self.site(), familyName))
+ % (title, self.site(), familyName))
- # Redundant interwiki prefix to the local wiki
- if newsite == self.site:
- if not t:
- # Can't have an empty self-link
- raise Error("Invalid link title: '%s'" % text)
- firstPass = False
- continue
- self.site = newsite
- # If there's an initial colon after the interwiki, that also
- # resets the default namespace
- if t.startswith(":"):
- self.namespace = 0
- t = t[1:]
- break
+ # Redundant interwiki prefix to the local wiki
+ if newsite == self.site:
+ if not t:
+ # Can't have an empty self-link
+ raise pywikibot.Error(
+ "Invalid link title: '%s'" % text)
+ firstPass = False
+ continue
+ self.site = newsite
if u"#" in t:
t, sec = t.split(u'#', 1)
@@ -1438,8 +1403,10 @@
self.section = None
# Reject illegal characters.
- if Link.illegal_titles_pattern.search(t):
- raise Error("Invalid title (contains illegal char(s)): '%s'" % text)
+ m = Link.illegal_titles_pattern.search(t)
+ if m:
+ raise pywikibot.Error(
+ "Invalid title: contains illegal char(s) '%s'" % m.group(0))
# Pages with "/./" or "/../" appearing in the URLs will
# often be unreachable due to the way web browsers deal
@@ -1454,15 +1421,16 @@
or t.endswith(u"/.")
or t.endswith(u"/..")
):
- raise Error("Invalid title (contains . / combinations): '%s'"
+ raise pywikibot.Error(
+ "Invalid title (contains . / combinations): '%s'"
% text)
# Magic tilde sequences? Nu-uh!
if u"~~~" in t:
- raise Error("Invalid title (contains ~~~): '%s'" % text)
+ raise pywikibot.Error("Invalid title (contains ~~~): '%s'" % text)
if self.namespace != -1 and len(t) > 255:
- raise Error("Invalid title (over 255 bytes): '%s'" % t)
+ raise pywikibot.Error("Invalid title (over 255 bytes): '%s'" % t)
if self.site.case() == 'first-letter':
t = t[:1].upper() + t[1:]
Modified: branches/rewrite/pywikibot/site.py
===================================================================
--- branches/rewrite/pywikibot/site.py 2008-03-03 14:58:39 UTC (rev 5101)
+++ branches/rewrite/pywikibot/site.py 2008-03-04 18:13:32 UTC (rev 5102)
@@ -106,15 +106,14 @@
return self._username
return None
- def __getattr__(self, attr):
+ def __getattr__(self, attr, *args, **kwargs):
"""Calls to methods not defined in this object are passed to Family."""
try:
method = getattr(self.family(), attr)
- return lambda self=self: method(self.language())
+ return lambda self=self: method(self.language(), *args, **kwargs)
except AttributeError:
raise AttributeError("%s instance has no attribute '%s'"
- % (self.__class__.__name__, attr)
- )
+ % (self.__class__.__name__, attr) )
def sitename(self):
"""Return string representing this Site's name and language."""
@@ -135,9 +134,18 @@
def getNamespaceIndex(self, namespace):
"""Given a namespace name, return its int index, or None if invalid."""
- return self.family().getNamespaceIndex(self.language(), namespace)
+ if self.case() == "first-letter":
+ namespace = namespace[:1].upper() + namespace[1:]
+ for ns in self._namespaces:
+ if namespace in self._namespaces[ns]:
+ return ns
+ return None
+ def namespaces(self):
+ """Return dict of valid namespaces on this wiki."""
+ return self._namespaces
+
class APISite(BaseSite):
"""API interface to MediaWiki site.
@@ -158,7 +166,6 @@
## postForm: Post form data to an address at this site.
## postData: Post encoded form data to an http address at this site.
##
-## namespace(num): Return local name of namespace 'num'.
## normalizeNamespace(value): Return preferred name for namespace 'value' in
## this Site's language.
## namespaces: Return list of canonical namespace names for this Site.
@@ -308,8 +315,9 @@
14: [u"Category"],
15: [u"Category talk"],
}
+ self.getsiteinfo()
return
-# START HERE
+# ANYTHING BELOW THIS POINT IS NOT YET IMPLEMENTED IN __init__()
self._mediawiki_messages = {}
self.nocapitalize = self._lang in self.family().nocapitalize
self._userData = [False, False]
@@ -451,7 +459,7 @@
"""
return self._namespaces[num][0]
-
+#### METHODS NOT IMPLEMENTED YET (but may be delegated to Family object) ####
class NotImplementedYet:
def isBlocked(self, sysop = False):
I thought it'd be of Pywikipediabot developers too.
Hojjat (aka Huji)
---------- Forwarded message ----------
From: Roan Kattouw <roan.kattouw(a)home.nl>
Date: Mon, Mar 3, 2008 at 11:33 PM
Subject: [Wikitech-l] API action=edit added
To: Wikimedia developers <wikitech-l(a)lists.wikimedia.org>
Earlier today, I added [1] the long-awaited action=edit module to the API.
Currently, all WMF wikis have $wgEnableWriteAPI = false; , so
action=edit won't be available on them (along with delete, move, etc.),
which is probably a good thing as long as these modules haven't been
tested extensively. However, I suggest this setting be enabled on
Testwiki [2] so it can be, well, tested. Maintainers of JS scripts that
use the API (like Twinkle, maintained by Carl Fürstenberg AKA AzaTht
whose repetitive bugging sped up the development of this module) could
probably help here: they'll need to modify their code to use the API
edit features at some point and will be able to use TestWiki for
testing, and in turn their requests will help testing at TestWiki.
If anyone runs into any issues with the API edit modules, feel free to
bug me at #mediawiki (where I'm known as RoanKattouw), file a bug report
at BugZilla (be sure to set component=API and assign it to
roan.kattouw(a)home.nl ) or send an e-mail to the mediawiki-api list [3].
Roan Kattouw (Catrope)
[1] http://svn.wikimedia.org/viewvc/mediawiki?view=rev&revision=31514
[2] http://test.wikipedia.org/
[3] mediawiki-api(a)lists.wikimedia.org
_______________________________________________
Wikitech-l mailing list
Wikitech-l(a)lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l