http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11028
Revision: 11028
Author: yurik
Date: 2013-02-05 06:20:56 +0000 (Tue, 05 Feb 2013)
Log Message:
-----------
UserAgent to match the main branch - "script/ver pywikipediabot/2.0"
Modified Paths:
--------------
branches/rewrite/pywikibot/comms/http.py
branches/rewrite/pywikibot/version.py
Modified: branches/rewrite/pywikibot/comms/http.py
===================================================================
--- branches/rewrite/pywikibot/comms/http.py 2013-02-04 07:36:21 UTC (rev 11027)
+++ branches/rewrite/pywikibot/comms/http.py 2013-02-05 06:20:56 UTC (rev 11028)
@@ -32,13 +32,22 @@
import pywikibot
import cookielib
import threadedhttp
+import pywikibot.version
_logger = "comm.http"
# global variables
-useragent = 'Pywikipediabot/2.0' # This should include some global version string
+# the User-agent: header. The default is
+# '<script>/<revision> Pywikipediabot/2.0', where '<script>' is the tail
+# path component and file name of the currently executing script and
+# revision is the SVN revision of Pywikipediabot.
+USER_AGENT_FORMAT = '{script}/r{version[rev]} Pywikipediabot/2.0'
+useragent = (USER_AGENT_FORMAT.format(
+ script=('-'.join(pywikibot.version.get_executing_script())),
+ version=pywikibot.version.getversiondict()
+))
numthreads = 1
threads = []
Modified: branches/rewrite/pywikibot/version.py
===================================================================
--- branches/rewrite/pywikibot/version.py 2013-02-04 07:36:21 UTC (rev 11027)
+++ branches/rewrite/pywikibot/version.py 2013-02-05 06:20:56 UTC (rev 11028)
@@ -12,6 +12,7 @@
import os
import time
import urllib
+import sys
cache = None
@@ -134,3 +135,16 @@
exec(line)
break
return __version__
+
+## Get the tail path component and file name of the currently executing
+# script. Returns a tuple.
+#
+def get_executing_script():
+ """Get the last path component and filename of the currently
+ executing script."""
+ try:
+ script = os.path.abspath(sys.modules['__main__'].__file__)
+ except (KeyError, AttributeError):
+ script = sys.executable
+ path, file = os.path.split(script)
+ return (os.path.basename(path), file)
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11027
Revision: 11027
Author: yurik
Date: 2013-02-04 07:36:21 +0000 (Mon, 04 Feb 2013)
Log Message:
-----------
Applied atdt patch - script info in the user agent
http://sourceforge.net/tracker/?func=detail&aid=3603143&group_id=93107&atid…
Modified Paths:
--------------
trunk/pywikipedia/pywikibot/version.py
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/pywikibot/version.py
===================================================================
--- trunk/pywikipedia/pywikibot/version.py 2013-02-02 13:08:58 UTC (rev 11026)
+++ trunk/pywikipedia/pywikibot/version.py 2013-02-04 07:36:21 UTC (rev 11027)
@@ -10,6 +10,7 @@
__version__ = '$Id$'
import os
+import sys
import time
import urllib
@@ -134,3 +135,16 @@
exec(line)
break
return __version__
+
+## Get the tail path component and file name of the currently executing
+# script. Returns a tuple.
+#
+def get_executing_script():
+ """Get the last path component and filename of the currently
+ executing script."""
+ try:
+ script = os.path.abspath(sys.modules['__main__'].__file__)
+ except (KeyError, AttributeError):
+ script = sys.executable
+ path, file = os.path.split(script)
+ return (os.path.basename(path), file)
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2013-02-02 13:08:58 UTC (rev 11026)
+++ trunk/pywikipedia/wikipedia.py 2013-02-04 07:36:21 UTC (rev 11027)
@@ -45,7 +45,10 @@
setAction(text): Use 'text' instead of "Wikipedia python library" in
edit summaries
setUserAgent(text): Sets the string being passed to the HTTP server as
- the User-agent: header. Defaults to 'Pywikipediabot/1.0'.
+ the User-agent: header. The default is
+ '<script>/<revision> Pywikipediabot/1.0', where '<script>' is the tail
+ path component and file name of the currently executing script and
+ revision is the SVN revision of Pywikipediabot.
output(text): Prints the text 'text' in the encoding of the user's
console. **Use this instead of "print" statements**
@@ -161,6 +164,9 @@
WIDEBUILD = False
+# Format string for the default user agent.
+USER_AGENT_FORMAT = '{script}/r{version[rev]} Pywikipediabot/1.0'
+
SaxError = xml.sax._exceptions.SAXParseException
# Pre-compile re expressions
@@ -5208,7 +5214,10 @@
useragent = s
# Default User-agent
-setUserAgent('PythonWikipediaBot/1.0')
+setUserAgent(USER_AGENT_FORMAT.format(
+ script=('-'.join(version.get_executing_script())),
+ version=version.getversiondict()
+))
def url2link(percentname, insite, site):
"""Convert urlname of a wiki page into interwiki link format.
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11026
Revision: 11026
Author: drtrigon
Date: 2013-02-02 13:08:58 +0000 (Sat, 02 Feb 2013)
Log Message:
-----------
bug fix; version page format changed once again
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2013-02-02 12:34:53 UTC (rev 11025)
+++ trunk/pywikipedia/wikipedia.py 2013-02-02 13:08:58 UTC (rev 11026)
@@ -8195,7 +8195,10 @@
# 2nd try is for mw >=1.17wmf1
versionlist.append(lambda: htmldata.body.table.findAll(
'td')[1].contents[0] )
- # 3rd uses family file which is not live
+ # 3rd try is for mw >=1.21
+ versionlist.append(lambda: htmldata.body.table.findAll(
+ 'td')[1].contents[0].contents[0] )
+ # 4th uses family file which is not live
versionlist.append(lambda: self.family.version(self.lang) )
for versionfunc in versionlist:
try: