http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9492
Revision: 9492
Author: xqt
Date: 2011-09-03 11:04:34 +0000 (Sat, 03 Sep 2011)
Log Message:
-----------
revert r3148 due to bug #2989218; unsure what do wo with wikipedia.sectionencode() method
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2011-09-03 10:48:13 UTC (rev 9491)
+++ trunk/pywikipedia/wikipedia.py 2011-09-03 11:04:34 UTC (rev 9492)
@@ -385,11 +385,7 @@
raise InvalidTitle(u"Invalid section in category '%s'" % t)
else:
t, sec = t.split(u'#', 1)
- self._section = sec.lstrip()
- self._section = sectionencode(self._section,
- self._site.encoding())
- if not self._section:
- self._section = None
+ self._section = sec.lstrip() or None
t = t.rstrip()
elif sectionStart == 0:
raise InvalidTitle(u"Invalid title starting with a #: '%s'" % t)
@@ -456,8 +452,8 @@
before Category: and Image: links
@param as_filename: - not implemented yet -
- If underscore is True, replace all ' ' characters with '_'.
If savetitle is True, encode any wiki syntax in the title.
+
"""
title = self._title
if asLink:
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9491
Revision: 9491
Author: xqt
Date: 2011-09-03 10:48:13 +0000 (Sat, 03 Sep 2011)
Log Message:
-----------
update string asignement from rewrite; faster string formatting
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2011-09-03 10:33:51 UTC (rev 9490)
+++ trunk/pywikipedia/wikipedia.py 2011-09-03 10:48:13 UTC (rev 9491)
@@ -384,12 +384,13 @@
if self._namespace == 14:
raise InvalidTitle(u"Invalid section in category '%s'" % t)
else:
- self._section = t[sectionStart+1 : ].lstrip(" ")
+ t, sec = t.split(u'#', 1)
+ self._section = sec.lstrip()
self._section = sectionencode(self._section,
self._site.encoding())
if not self._section:
self._section = None
- t = t[ : sectionStart].rstrip(" ")
+ t = t.rstrip()
elif sectionStart == 0:
raise InvalidTitle(u"Invalid title starting with a #: '%s'" % t)
else:
@@ -401,7 +402,7 @@
# reassemble the title from its parts
if self._namespace != 0:
- t = self._site.namespace(self._namespace) + u':' + t
+ t = u'%s:%s' % (self._site.namespace(self._namespace), t)
if self._section:
t += u'#' + self._section
@@ -457,7 +458,6 @@
If underscore is True, replace all ' ' characters with '_'.
If savetitle is True, encode any wiki syntax in the title.
- If decode is True, decodes the section title
"""
title = self._title
if asLink:
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9488
Revision: 9488
Author: xqt
Date: 2011-09-03 08:32:33 +0000 (Sat, 03 Sep 2011)
Log Message:
-----------
raise invalidTitle f u'\ufffd' in title; minor updates from rewrite branch
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2011-09-03 08:23:27 UTC (rev 9487)
+++ trunk/pywikipedia/wikipedia.py 2011-09-03 08:32:33 UTC (rev 9488)
@@ -268,16 +268,14 @@
# restriction affects us or not
self._editrestriction = False
- if site is None:
- site = getSite()
- elif type(site) in [str, unicode]:
+ if site is None or isinstance(site, basestring):
site = getSite(site)
-
self._site = site
if not insite:
insite = site
+ # Clean up the name, it can come from anywhere.
# Convert HTML entities to unicode
t = html2unicode(title)
@@ -285,7 +283,7 @@
# Sometimes users copy the link to a site from one to another.
# Try both the source site and the destination site to decode.
try:
- t = url2unicode(t, site = insite, site2 = site)
+ t = url2unicode(t, site=insite, site2=site)
except UnicodeDecodeError:
raise InvalidTitle(u'Bad page title : %s' % t)
@@ -296,13 +294,15 @@
# (which might result in information loss).
t = unicodedata.normalize('NFC', t)
- # Clean up the name, it can come from anywhere.
- # Replace underscores by spaces, also multiple spaces and underscores with a single space
+ if u'\ufffd' in t:
+ raise InvalidTitle("Title contains illegal char (\\uFFFD)")
+
+ # Replace underscores by spaces
t = t.replace(u"_", u" ")
- while u" " in t:
- t = t.replace(u" ", u" ")
+ # replace multiple spaces a single space
+ while u" " in t: t = t.replace(u" ", u" ")
# Strip spaces at both ends
- t = t.strip(u" ")
+ t = t.strip()
# Remove left-to-right and right-to-left markers.
t = t.replace(u'\u200e', '').replace(u'\u200f', '')
# leading colon implies main namespace instead of the default
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9487
Revision: 9487
Author: xqt
Date: 2011-09-03 08:23:27 +0000 (Sat, 03 Sep 2011)
Log Message:
-----------
Format doc sting to PEP8
Modified Paths:
--------------
branches/rewrite/pywikibot/page.py
Modified: branches/rewrite/pywikibot/page.py
===================================================================
--- branches/rewrite/pywikibot/page.py 2011-09-01 14:47:27 UTC (rev 9486)
+++ branches/rewrite/pywikibot/page.py 2011-09-03 08:23:27 UTC (rev 9487)
@@ -2199,11 +2199,11 @@
# Convert URL-encoded characters to unicode
t = url2unicode(t, site=self._source)
- # Normalize unicode string to a NFC (composed) format to allow proper
- # string comparisons. According to
+ # Normalize unicode string to a NFC (composed) format to allow
+ # proper string comparisons. According to
# http://svn.wikimedia.org/viewvc/mediawiki/branches/REL1_6/phase3/includes/n…
- # the mediawiki code normalizes everything to NFC, not NFKC (which
- # might result in information loss).
+ # the mediawiki code normalizes everything to NFC, not NFKC
+ # (which might result in information loss).
t = unicodedata.normalize('NFC', t)
# This code was adapted from Title.php : secureAndSplit()
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9485
Revision: 9485
Author: xqt
Date: 2011-09-01 05:51:41 +0000 (Thu, 01 Sep 2011)
Log Message:
-----------
if a site is given instead of a code, use its language; update from trunk r9484
Modified Paths:
--------------
branches/rewrite/pywikibot/i18n.py
Modified: branches/rewrite/pywikibot/i18n.py
===================================================================
--- branches/rewrite/pywikibot/i18n.py 2011-09-01 05:50:47 UTC (rev 9484)
+++ branches/rewrite/pywikibot/i18n.py 2011-09-01 05:51:41 UTC (rev 9485)
@@ -325,6 +325,9 @@
param = None
if type(parameters) == dict:
param = parameters
+ # If a site is given instead of a code, use its language
+ if hasattr(code, 'lang'):
+ code = code.lang
# we send the code via list and get the alternate code back
code = [code]
trans = twtranslate(code, twtitle, None)
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9484
Revision: 9484
Author: xqt
Date: 2011-09-01 05:50:47 +0000 (Thu, 01 Sep 2011)
Log Message:
-----------
if a site is given instead of a code, use its language
Modified Paths:
--------------
trunk/pywikipedia/pywikibot/i18n.py
Modified: trunk/pywikipedia/pywikibot/i18n.py
===================================================================
--- trunk/pywikipedia/pywikibot/i18n.py 2011-08-29 19:17:43 UTC (rev 9483)
+++ trunk/pywikipedia/pywikibot/i18n.py 2011-09-01 05:50:47 UTC (rev 9484)
@@ -336,6 +336,9 @@
param = None
if type(parameters) == dict:
param = parameters
+ # If a site is given instead of a code, use its language
+ if hasattr(code, 'lang'):
+ code = code.lang
# we send the code via list and get the alternate code back
code = [code]
trans = twtranslate(code, twtitle, None)