[Pywikipedia-l] SVN: [6064] branches/rewrite/pywikibot
russblau at svn.wikimedia.org
russblau at svn.wikimedia.org
Wed Nov 5 20:27:14 UTC 2008
Revision: 6064
Author: russblau
Date: 2008-11-05 20:27:13 +0000 (Wed, 05 Nov 2008)
Log Message:
-----------
update imports
Modified Paths:
--------------
branches/rewrite/pywikibot/__init__.py
branches/rewrite/pywikibot/comms/http.py
branches/rewrite/pywikibot/data/api.py
branches/rewrite/pywikibot/families/wikibooks_family.py
branches/rewrite/pywikibot/families/wikinews_family.py
branches/rewrite/pywikibot/families/wikipedia_family.py
branches/rewrite/pywikibot/families/wikiquote_family.py
branches/rewrite/pywikibot/families/wikisource_family.py
branches/rewrite/pywikibot/families/wikiversity_family.py
branches/rewrite/pywikibot/families/wiktionary_family.py
branches/rewrite/pywikibot/family.py
branches/rewrite/pywikibot/login.py
branches/rewrite/pywikibot/page.py
branches/rewrite/pywikibot/tests/site_tests.py
branches/rewrite/pywikibot/throttle.py
Removed Paths:
-------------
branches/rewrite/pywikibot/config.py
Modified: branches/rewrite/pywikibot/__init__.py
===================================================================
--- branches/rewrite/pywikibot/__init__.py 2008-11-05 20:25:44 UTC (rev 6063)
+++ branches/rewrite/pywikibot/__init__.py 2008-11-05 20:27:13 UTC (rev 6064)
@@ -13,7 +13,7 @@
import logging
from exceptions import *
-import config
+import config2
def deprecate_arg(old_arg, new_arg):
@@ -46,8 +46,8 @@
_sites = {}
-default_family = config.family
-default_code = config.mylang
+default_family = config2.family
+default_code = config2.mylang
@deprecate_arg("persistent_http", None)
@@ -72,16 +72,16 @@
fam = default_family
if user is None:
try:
- user = config.usernames[fam][code]
+ user = config2.usernames[fam][code]
except KeyError:
user = None
if sysop is None:
try:
- sysop = config.sysopnames[fam][code]
+ sysop = config2.sysopnames[fam][code]
except KeyError:
sysop = None
if interface is None:
- interface = config.site_interface
+ interface = config2.site_interface
try:
exec "from site import %s as __Site" % interface
except ImportError:
Modified: branches/rewrite/pywikibot/comms/http.py
===================================================================
--- branches/rewrite/pywikibot/comms/http.py 2008-11-05 20:25:44 UTC (rev 6063)
+++ branches/rewrite/pywikibot/comms/http.py 2008-11-05 20:27:13 UTC (rev 6064)
@@ -27,7 +27,7 @@
import logging
import atexit
-import config
+import config2
import cookielib
import threadedhttp
@@ -44,10 +44,10 @@
http_queue = Queue.Queue()
cookie_jar = threadedhttp.LockableCookieJar(
- config.datafilepath("%s-%s-%s.lwp"
- % (config.family,
- config.mylang,
- config.usernames[config.family][config.mylang])))
+ config2.datafilepath("%s-%s-%s.lwp"
+ % (config2.family,
+ config2.mylang,
+ config2.usernames[config2.family][config2.mylang])))
try:
cookie_jar.load()
except (IOError, cookielib.LoadError):
Deleted: branches/rewrite/pywikibot/config.py
===================================================================
--- branches/rewrite/pywikibot/config.py 2008-11-05 20:25:44 UTC (rev 6063)
+++ branches/rewrite/pywikibot/config.py 2008-11-05 20:27:13 UTC (rev 6064)
@@ -1,574 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# (C) Rob W.W. Hooft, 2003
-#
-# Distributed under the terms of the MIT license.
-#
-__version__ = '$Id$'
-
-import os, re
-import sys as __sys
-
-# IMPORTANT:
-# Do not change any of the variables in this file. Instead, make
-# a file user-config.py, and overwrite values in there.
-
-# Note: all variables defined in this module are made available to bots as
-# configuration settings, *except* variable names beginning with an
-# underscore (example: _variable). Be sure to use an underscore on any
-# variables that are intended only for internal use and not to be exported
-# to other modules.
-
-############## ACCOUNT SETTINGS ##############
-
-# The family of sites we are working on. wikipedia.py will import
-# families/xxx_family.py so if you want to change this variable,
-# you need to write such a file.
-family = 'wikipedia'
-# The language code of the site we're working on.
-mylang = 'language'
-# The default interface for communicating with the site
-# currently the only defined interface is 'APISite', so don't change this!
-site_interface = 'APISite'
-# The dictionary usernames should contain a username for each site where you
-# have a bot account. Please set your usernames by adding such lines to your
-# user-config.py:
-#
-# usernames['wikipedia']['de'] = 'myGermanUsername'
-# usernames['wiktionary']['en'] = 'myEnglishUsername'
-#
-# If you have a sysop account on some wikis, this will be used to delete pages
-# or to edit locked pages if you add such lines to your
-# user-config.py:
-#
-# sysopnames['wikipedia']['de'] = 'myGermanUsername'
-# sysopnames['wiktionary']['en'] = 'myEnglishUsername'
-usernames = {}
-sysopnames = {}
-disambiguation_comment = {}
-gdab_namespaces = {}
-
-# Solve captchas in the webbrowser. Setting this to False will result in the
-# exception CaptchaError be thrown if a captcha is encountered.
-solve_captcha = True
-
-# Some sites will require password identication to access the HTML pages at
-# the site. If you have any such site, add lines to your user-config.py of
-# the following form:
-#
-# authenticate['en.wikipedia.org'] = ('John','XXXXX')
-#
-# where John is your login name, and XXXXX your password.
-# Note:
-# 1. This is only for sites that use authentication in the form that gives
-# you a popup for name and password when you try to access any data, NOT
-# for, for example, wiki usernames
-# 2. You must use the hostname of the site, not its family/language pair
-authenticate = {}
-
-# password_file = ".passwd"
-# A password file with default passwords. For more information, please
-# see LoginManager.readPassword in login.py.
-# By default you are asked for a password on the terminal.
-password_file = None
-
-# Get the names of all known families, and initialize
-# with empty dictionaries
-def _get_base_dir():
- """Return the directory in which user-specific information is stored.
-
- This is determined in the following order -
- 1. If the script was called with a -dir: argument, use the directory
- provided in this argument
- 2. If the user has a PYWIKIBOT2_DIR environment variable, use the value
- of it
- 3. Use (and if necessary create) a 'pywikibot' folder (Windows) or
- '.pywikibot' directory (Unix and similar) under the user's home
- directory.
-
- """
- NAME = "pywikibot"
- for arg in __sys.argv[1:]:
- if arg.startswith("-dir:"):
- base_dir = arg[5:]
- __sys.argv.remove(arg)
- break
- else:
- if os.environ.has_key("PYWIKIBOT2_DIR"):
- base_dir = os.environ["PYWIKIBOT2_DIR"]
- else:
- is_windows = __sys.platform == 'win32'
- home = os.path.expanduser("~")
- if is_windows:
- base_dir = os.path.join(home, "Application Data", NAME)
- else:
- base_dir = os.path.join(home, "."+NAME)
- if not os.path.isdir(base_dir):
- os.makedirs(base_dir, mode=0700)
- if not os.path.isabs(base_dir):
- base_dir = os.path.normpath(os.path.join(os.getcwd(), base_dir))
- # make sure this path is valid and that it contains user-config file
- if not os.path.isdir(base_dir):
- raise RuntimeError("Directory '%(base_dir)s' does not exist."
- % locals())
- if not os.path.exists(os.path.join(base_dir, "user-config.py")):
- raise RuntimeError("No user-config.py found in directory '%(base_dir)s'."
- % locals())
- return base_dir
-
-_base_dir = _get_base_dir()
-# families/ is a subdirectory of the directory in which config.py is found
-for _filename in os.listdir(
- os.path.join(os.path.dirname(__file__), 'families')):
- if _filename.endswith("_family.py"):
- familyName = _filename[ : -len("_family.py")]
- usernames[familyName] = {}
- sysopnames[familyName] = {}
- disambiguation_comment[familyName] = {}
-
-# Set to True to override the {{bots}} exclusion protocol (at your own risk!)
-ignore_bot_templates = False
-
-############## USER INTERFACE SETTINGS ##############
-
-# The encoding that's used in the user's console, i.e. how strings are encoded
-# when they are read by raw_input(). On Windows systems' DOS box, this should
-# be 'cp850' ('cp437' for older versions). Linux users might try 'iso-8859-1'
-# or 'utf-8'.
-# This default code should work fine, so you don't have to think about it.
-# TODO: consider getting rid of this config variable.
-try:
- console_encoding = __sys.stdout.encoding
-except:
- #When using pywikipedia inside a daemonized twisted application,
- #we get "StdioOnnaStick instance has no attribute 'encoding'"
- console_encoding = None
-
-# The encoding in which textfiles are stored, which contain lists of page titles.
-textfile_encoding = 'utf-8'
-
-# tkinter isn't yet ready
-userinterface = 'terminal'
-
-# Should we transliterate characters that do not exist in the console
-# character set?
-# True: whenever possible
-# False: never - always replace them by question marks
-# Currently only works if interface 'terminal' is set.
-transliterate = True
-
-# Should the system bell be ringed if the bot expects user input?
-ring_bell = False
-
-# Colorization can be used to markup important text parts of the output.
-# On Linux/Unix terminals, ANSI escape codes are used for this. On Windows,
-# it is done by a DLL call via ctypes. ctypes is only available since
-# Python 2.5, so if you're using Python 2.4 or lower on Windows, you should
-# upgrade.
-# Set this to False if you're using Linux and your tty doesn't support
-# ANSI colors.
-try:
- # Don't print colorized when the output is, for example, piped to a file.
- colorized_output = __sys.stdout.isatty()
-except:
- colorized_output = False
-
-############## EXTERNAL EDITOR SETTINGS ##############
-# The command for the editor you want to use. If set to None, a simple Tkinter
-# editor will be used.
-# On Windows systems, this script tries to determine the default text editor.
-if __sys.platform=='win32':
- try:
- import _winreg
- _key1 = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\OpenWithProgids')
- _progID = _winreg.EnumValue(_key1, 1)[0]
- _key2 = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '%s\shell\open\command' % _progID)
- _cmd = _winreg.QueryValueEx(_key2, None)[0]
- editor = _cmd.replace('%1', '')
- # Notepad is even worse than our Tkinter editor.
- if editor.lower().endswith('notepad.exe'):
- editor = None
- except:
- #raise
- editor = None
-else:
- editor = None
-
-# Warning: DO NOT use an editor which doesn't support Unicode to edit pages!
-# You will BREAK non-ASCII symbols!
-editor_encoding = 'utf-8'
-
-# The temporary file name extension can be set in order to use syntax
-# highlighting in your text editor.
-editor_filename_extension = 'wiki'
-
-############## LOGFILE SETTINGS ##############
-
-# Defines for which scripts a logfile should be enabled. Logfiles will be
-# saved in the 'logs' subdirectory.
-# Example:
-# log = ['interwiki', 'weblinkchecker', 'table2wiki']
-# It is also possible to enable logging for all scripts, using this line:
-# log = ['*']
-# To disable all logging, use this:
-# log = []
-# Per default, logging of interwiki.py is enabled because its logfiles can
-# be used to generate so-called warnfiles.
-# This setting can be overridden by the -log or -nolog command-line arguments.
-log = ['interwiki']
-
-############## INTERWIKI SETTINGS ##############
-
-# Should interwiki.py report warnings for missing links between foreign
-# languages?
-interwiki_backlink = True
-
-# Should interwiki.py display every new link it discovers?
-interwiki_shownew = True
-
-# Should interwiki.py output a graph PNG file on conflicts?
-# You need pydot for this: http://dkbza.org/pydot.html
-interwiki_graph = False
-
-# Specifies that the robot should process that amount of subjects at a time,
-# only starting to load new pages in the original language when the total
-# falls below that number. Default is to process (at least) 100 subjects at
-# once.
-interwiki_min_subjects = 100
-
-# If interwiki graphs are enabled, which format(s) should be used?
-# Supported formats include png, jpg, ps, and svg. See:
-# http://www.graphviz.org/doc/info/output.html
-# If you want to also dump the dot files, you can use this in your
-# user-config.py:
-# interwiki_graph_formats = ['dot', 'png']
-# If you need a PNG image with an HTML image map, use this:
-# interwiki_graph_formats = ['png', 'cmap']
-# If you only need SVG images, use:
-# interwiki_graph_formats = ['svg']
-interwiki_graph_formats = ['png']
-
-# You can post the contents of your autonomous_problems.dat to the wiki,
-# e.g. to http://de.wikipedia.org/wiki/Wikipedia:Interwiki-Konflikte .
-# This allows others to assist you in resolving interwiki problems.
-# To help these people, you can upload the interwiki graphs to your
-# webspace somewhere. Set the base URL here, e.g.:
-# 'http://www.example.org/~yourname/interwiki-graphs/'
-interwiki_graph_url = None
-
-# Save file with local articles without interwikis.
-without_interwiki = False
-
-############## SOLVE_DISAMBIGUATION SETTINGS ############
-#
-# Set disambiguation_comment[FAMILY][LANG] to a non-empty string to override
-# the default edit comment for the solve_disambiguation bot.
-# Use %s to represent the name of the disambiguation page being treated.
-# Example:
-#
-# disambiguation_comment['wikipedia']['en'] = \
-# "Robot-assisted disambiguation ([[WP:DPL|you can help!]]): %s"
-
-sort_ignore_case = False
-
-############## IMAGE RELATED SETTINGS ##############
-# If you set this to True, images will be uploaded to Wikimedia
-# Commons by default.
-upload_to_commons = False
-
-############## SETTINGS TO AVOID SERVER OVERLOAD ##############
-
-# Slow down the robot such that it never requests a second page within
-# 'minthrottle' seconds. This can be lengthened if the server is slow,
-# but never more than 'maxthrottle' seconds. However - if you are running
-# more than one bot in parallel the times are lengthened.
-# By default, the get_throttle is turned off, and 'maxlag' is used to
-# control the rate of server access. Set minthrottle to non-zero to use a
-# throttle on read access.
-minthrottle = 0
-maxthrottle = 10
-
-# Slow down the robot such that it never makes a second page edit within
-# 'put_throttle' seconds.
-put_throttle = 10
-
-# Sometimes you want to know when a delay is inserted. If a delay is larger
-# than 'noisysleep' seconds, it is logged on the screen.
-noisysleep = 3.0
-
-# Defer bot edits during periods of database server lag. For details, see
-# http://www.mediawiki.org/wiki/Maxlag_parameter
-# You can set this variable to a number of seconds, or to None (or 0) to
-# disable this behavior. Higher values are more aggressive in seeking
-# access to the wiki.
-# Non-Wikimedia wikis may or may not support this feature; for families
-# that do not use it, it is recommended to set minthrottle (above) to
-# at least 1 second.
-maxlag = 5
-
-# Maximum of pages which can be retrieved by special pages. Increase this if
-# you heavily use redirect.py with action "double", and especially if you're
-# running solve_disambiguation.py with the -primary argument.
-special_page_limit = 500
-
-############## TABLE CONVERSION BOT SETTINGS ##############
-
-# will split long paragraphs for better reading the source.
-# only table2wiki.py use it by now
-splitLongParagraphs = False
-# sometimes HTML-tables are indented for better reading.
-# That can do very ugly results.
-deIndentTables = True
-# table2wiki.py works quite stable, so you might switch to True
-table2wikiAskOnlyWarnngs = True
-table2wikiSkipWarnings = False
-
-############## WEBLINK CHECKER SETTINGS ##############
-
-# How many external links should weblinkchecker.py check at the same time?
-# If you have a fast connection, you might want to increase this number so
-# that slow servers won't slow you down.
-max_external_links = 50
-
-report_dead_links_on_talk = False
-
-############## DATABASE SETTINGS ##############
-db_hostname = 'localhost'
-db_username = 'wikiuser'
-db_password = ''
-
-############## SEARCH ENGINE SETTINGS ##############
-
-# Some scripts allow querying Google via the Google Web API. To use this feature,
-# you must install the pyGoogle module from http://pygoogle.sf.net/ and have a
-# Google Web API license key. Note that Google doesn't give out license keys
-# anymore.
-google_key = ''
-
-# Some scripts allow using the Yahoo! Search Web Services. To use this feature,
-# you must install the pYsearch module from http://pysearch.sourceforge.net/
-# and get a Yahoo AppID from http://developer.yahoo.com
-yahoo_appid = ''
-
-# To use Windows Live Search web service you must get an AppID from
-# http://search.msn.com/developer
-msn_appid = ''
-
-############## COPYRIGHT SETTINGS ##############
-
-# Enable/disable search engine in copyright.py script
-copyright_google = True
-copyright_yahoo = True
-copyright_msn = False
-
-# Perform a deep check, loading URLs to search if 'Wikipedia' is present.
-# This may be useful to improve number of correct results. If you haven't
-# a fast connection, you might want to keep they disabled.
-copyright_check_in_source_google = False
-copyright_check_in_source_yahoo = False
-copyright_check_in_source_msn = False
-
-# Web pages may content a Wikipedia text without 'Wikipedia' word but with
-# typical '[edit]' tag result of copy & paste procedure. You can want no
-# report for this kind of URLs, even if they are copyright violation.
-# However, when enabled these URLs are logged in a file.
-
-copyright_check_in_source_section_names = False
-
-# Limit number of queries for page.
-copyright_max_query_for_page = 25
-
-# Skip a specified number of queries
-copyright_skip_query = 0
-
-# Number of attempts on connection error.
-copyright_connection_tries = 10
-
-# Behavior if an exceeded error occur.
-#
-# Possibilities:
-#
-# 0 = None
-# 1 = Disable search engine
-# 2 = Sleep (default)
-# 3 = Stop
-
-copyright_exceeded_in_queries = 2
-copyright_exceeded_in_queries_sleep_hours = 6
-
-# Append last modified date of URL to script result
-copyright_show_date = True
-
-# Append length of URL to script result
-copyright_show_length = True
-
-# By default the script try to identify and skip text that contents a wide
-# comma separated list or only numbers. But sometimes that might be the
-# only part unmodified of a slightly edited and not otherwise reported
-# copyright violation. You can disable this feature to try to increase
-# number of results.
-
-copyright_economize_query = True
-
-############## HTTP SETTINGS ##############
-# Use a persistent http connection. An http connection has to be established
-# only once per site object, making stuff a whole lot faster. Do NOT EVER
-# use this if you share Site objects across threads without proper locking.
-## DISABLED FUNCTION. Setting this variable will not have any effect.
-persistent_http = False
-
-# Default socket timeout. Set to None to disable timeouts.
-socket_timeout = 120 # set a pretty long timeout just in case...
-
-
-############## FURTHER SETTINGS ##############
-
-# The bot can make some additional changes to each page it edits, e.g. fix
-# whitespace or positioning of interwiki and category links.
-
-# This is an experimental feature; handle with care and consider re-checking
-# each bot edit if enabling this!
-cosmetic_changes = False
-
-# If cosmetic changes are switched on, and you also have several accounts at
-# projects where you're not familiar with the local conventions, you probably
-# only want the bot to do cosmetic changes on your "home" wiki which you
-# specified in config.mylang and config.family.
-# If you want the bot to also do cosmetic changes when editing a page on a
-# foreign wiki, set cosmetic_changes_mylang_only to False, but be careful!
-cosmetic_changes_mylang_only = True
-
-# End of configuration section
-# ============================
-# System-level and User-level changes.
-# Store current variables and their types.
-_glv={}
-_glv.update(globals())
-_gl=_glv.keys()
-_tp={}
-for _key in _gl:
- if _key[0]!='_':
- _tp[_key]=type(globals()[_key])
-
-# Get the user files
-_thislevel=0
-_fns=[os.path.join(_base_dir, "user-config.py")]
-for _filename in _fns:
- _thislevel += 1
- if os.path.exists(_filename):
- _filestatus=os.stat(_filename)
- _filemode=_filestatus[0]
- _fileuid=_filestatus[4]
- if (__sys.platform=='win32' or _fileuid==os.getuid() or _fileuid==0):
- if __sys.platform=='win32' or _filemode&002==0:
- execfile(_filename)
- else:
- print "WARNING: Skipped '%(fn)s': writeable by others."\
- % {'fn' :_filename}
- else:
- print "WARNING: Skipped '%(fn)s': owned by someone else."\
- % {'fn' :_filename}
-
-# Test for obsoleted and/or unknown variables.
-for _key in globals().keys():
- if _key[0]=='_':
- pass
- elif _key in _gl:
- nt=type(globals()[_key])
- ot=_tp[_key]
- if nt==ot or nt==type(None) or ot==type(None):
- pass
- elif nt==type(1) and ot==type(1.0):
- pass
- elif ot==type(1) and nt==type(1.0):
- pass
- elif nt==type(1) and ot==type(True):
- pass
- elif ot==type(1) and nt==type(True):
- pass
- else:
- print "WARNING: Type of '%(_key)s' changed" % locals()
- print " %(was)s: %(old)s" % {'was': "Was", 'old': ot}
- print " %(was)s: %(new)s" % {'now': "Now", 'new': nt}
- del nt,ot
- else:
- logger.warn(
- "Configuration variable %(_key)r is defined but unknown. Misspelled?"
- % locals())
-
-# Fix up default console_encoding
-if console_encoding == None:
- if __sys.platform=='win32':
- console_encoding = 'cp850'
- else:
- console_encoding = 'iso-8859-1'
-
-# Save base_dir for use by other modules
-base_dir = _base_dir
-
-def makepath(path):
- """Return a normalized absolute version of the path argument.
-
- - if the given path already exists in the filesystem
- the filesystem is not modified.
-
- - otherwise makepath creates directories along the given path
- using the dirname() of the path. You may append
- a '/' to the path if you want it to be a directory path.
-
- from holger at trillke.net 2002/03/18
-
- """
- from os import makedirs
- from os.path import normpath, dirname, exists, abspath
-
- dpath = normpath(dirname(path))
- if not exists(dpath): makedirs(dpath)
- return normpath(abspath(path))
-
-def datafilepath(*filename):
- """Return an absolute path to a data file in a standard location.
-
- Argument(s) are zero or more directory names, optionally followed by a
- data file name. The return path is offset to config.base_dir. Any
- directories in the path that do not already exist are created.
-
- """
- import os
- return makepath(os.path.join(base_dir, *filename))
-
-def shortpath(path):
- """Return a file path relative to config.base_dir."""
- import os
- if path.startswith(base_dir):
- return path[len(base_dir) + len(os.path.sep) : ]
- return path
-
-#
-# When called as main program, list all configuration variables
-#
-if __name__=="__main__":
- import types
- _all=1
- for _arg in __sys.argv[1:]:
- if _arg=="modified":
- _all=0
- else:
- print "Unknown arg %(_arg)s ignored" % locals()
- _k=globals().keys()
- _k.sort()
- for _name in _k:
- if _name[0]!='_':
- if not type(globals()[_name]) in [types.FunctionType, types.ModuleType]:
- if _all or _glv[_name]!=globals()[_name]:
- print _name,"=",repr(globals()[_name])
-
-# cleanup all locally-defined variables
-
-for __var in globals().keys():
- if __var.startswith("_") and not __var.startswith("__"):
- del __sys.modules[__name__].__dict__[__var]
-
-del __var, __sys
-del os, re
-
Modified: branches/rewrite/pywikibot/data/api.py
===================================================================
--- branches/rewrite/pywikibot/data/api.py 2008-11-05 20:25:44 UTC (rev 6063)
+++ branches/rewrite/pywikibot/data/api.py 2008-11-05 20:27:13 UTC (rev 6064)
@@ -19,7 +19,6 @@
import urllib
import warnings
-import config
import pywikibot
from pywikibot import login
from pywikibot.exceptions import *
@@ -160,7 +159,7 @@
info = set(info + ["protection", "talkid", "subjectid"])
self.params["info"] = list(info)
if "maxlag" not in self.params:
- self.params["maxlag"] = [str(config.maxlag)]
+ self.params["maxlag"] = [str(pywikibot.config2.maxlag)]
if "format" not in self.params:
self.params["format"] = ["json"]
if self.params['format'] != ["json"]:
Modified: branches/rewrite/pywikibot/families/wikibooks_family.py
===================================================================
--- branches/rewrite/pywikibot/families/wikibooks_family.py 2008-11-05 20:25:44 UTC (rev 6063)
+++ branches/rewrite/pywikibot/families/wikibooks_family.py 2008-11-05 20:27:13 UTC (rev 6064)
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import urllib
from pywikibot import family
-import config
__version__ = '$Id$'
Modified: branches/rewrite/pywikibot/families/wikinews_family.py
===================================================================
--- branches/rewrite/pywikibot/families/wikinews_family.py 2008-11-05 20:25:44 UTC (rev 6063)
+++ branches/rewrite/pywikibot/families/wikinews_family.py 2008-11-05 20:27:13 UTC (rev 6064)
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import urllib
from pywikibot import family
-import config
__version__ = '$Id$'
Modified: branches/rewrite/pywikibot/families/wikipedia_family.py
===================================================================
--- branches/rewrite/pywikibot/families/wikipedia_family.py 2008-11-05 20:25:44 UTC (rev 6063)
+++ branches/rewrite/pywikibot/families/wikipedia_family.py 2008-11-05 20:27:13 UTC (rev 6064)
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import urllib
from pywikibot import family
-import config
__version__ = '$Id$'
Modified: branches/rewrite/pywikibot/families/wikiquote_family.py
===================================================================
--- branches/rewrite/pywikibot/families/wikiquote_family.py 2008-11-05 20:25:44 UTC (rev 6063)
+++ branches/rewrite/pywikibot/families/wikiquote_family.py 2008-11-05 20:27:13 UTC (rev 6064)
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import urllib
from pywikibot import family
-import config
__version__ = '$Id$'
Modified: branches/rewrite/pywikibot/families/wikisource_family.py
===================================================================
--- branches/rewrite/pywikibot/families/wikisource_family.py 2008-11-05 20:25:44 UTC (rev 6063)
+++ branches/rewrite/pywikibot/families/wikisource_family.py 2008-11-05 20:27:13 UTC (rev 6064)
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import urllib
from pywikibot import family
-import config
__version__ = '$Id$'
Modified: branches/rewrite/pywikibot/families/wikiversity_family.py
===================================================================
--- branches/rewrite/pywikibot/families/wikiversity_family.py 2008-11-05 20:25:44 UTC (rev 6063)
+++ branches/rewrite/pywikibot/families/wikiversity_family.py 2008-11-05 20:27:13 UTC (rev 6064)
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import urllib
from pywikibot import family
-import config
__version__ = '$Id$'
Modified: branches/rewrite/pywikibot/families/wiktionary_family.py
===================================================================
--- branches/rewrite/pywikibot/families/wiktionary_family.py 2008-11-05 20:25:44 UTC (rev 6063)
+++ branches/rewrite/pywikibot/families/wiktionary_family.py 2008-11-05 20:27:13 UTC (rev 6064)
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import urllib
from pywikibot import family
-import config
__version__ = '$Id$'
Modified: branches/rewrite/pywikibot/family.py
===================================================================
--- branches/rewrite/pywikibot/family.py 2008-11-05 20:25:44 UTC (rev 6063)
+++ branches/rewrite/pywikibot/family.py 2008-11-05 20:27:13 UTC (rev 6064)
@@ -2,7 +2,7 @@
__version__='$Id$'
-import config
+import config2 as config
import logging
import re
import urllib
@@ -19,31 +19,33 @@
# Updated from http://meta.wikimedia.org/wiki/Interwiki_sorting_order
self.alphabetic = [
'aa', 'af', 'ak', 'als', 'am', 'ang', 'ab', 'ar', 'an', 'arc',
- 'roa-rup', 'frp', 'as', 'ast', 'gn', 'av', 'ay', 'az', 'bm', 'bn',
- 'zh-min-nan', 'map-bms', 'ba', 'be', 'be-x-old', 'bh', 'bcl', 'bi', 'bar', 'bo',
- 'bs', 'br', 'bg', 'bxr', 'ca', 'cv', 'ceb', 'cs', 'ch', 'ny',
- 'sn', 'tum', 'cho', 'co', 'za', 'cy', 'da', 'pdc', 'de', 'dv',
- 'nv', 'dsb', 'dz', 'mh', 'et', 'el', 'eml', 'en', 'myv', 'es', 'eo',
- 'ext', 'eu', 'ee', 'fa', 'fo', 'hif', 'fr', 'fy', 'ff', 'fur', 'ga', 'gan', 'gv',
- 'gd', 'gl', 'ki', 'glk', 'gu', 'got', 'zh-classical', 'hak', 'xal', 'ko',
+ 'roa-rup', 'frp', 'as', 'ast', 'gn', 'av', 'ay', 'az', 'bm',
+ 'bn', 'zh-min-nan', 'map-bms', 'ba', 'be', 'be-x-old', 'bh',
+ 'bcl', 'bi', 'bar', 'bo', 'bs', 'br', 'bg', 'bxr', 'ca', 'cv',
+ 'ceb', 'cs', 'ch', 'ny', 'sn', 'tum', 'cho', 'co', 'za', 'cy',
+ 'da', 'pdc', 'de', 'dv', 'nv', 'dsb', 'dz', 'mh', 'et', 'el',
+ 'eml', 'en', 'myv', 'es', 'eo', 'ext', 'eu', 'ee', 'fa', 'fo',
+ 'hif', 'fr', 'fy', 'ff', 'fur', 'ga', 'gan', 'gv', 'gd', 'gl',
+ 'ki', 'glk', 'gu', 'got', 'zh-classical', 'hak', 'xal', 'ko',
'ha', 'haw', 'hy', 'hi', 'ho', 'hsb', 'hr', 'io', 'ig', 'ilo',
'bpy', 'id', 'ia', 'ie', 'iu', 'ik', 'os', 'xh', 'zu', 'is',
'it', 'he', 'jv', 'kl', 'pam', 'kn', 'kr', 'ka', 'ks', 'csb',
'kk', 'kw', 'rw', 'ky', 'rn', 'sw', 'kv', 'kg', 'ht', 'kj',
'ku', 'lad', 'lbe', 'lo', 'la', 'lv', 'lb', 'lt', 'lij', 'li',
'ln', 'jbo', 'lg', 'lmo', 'hu', 'mk', 'mg', 'ml', 'mt', 'mi',
- 'mr', 'mzn', 'ms', 'cdo', 'mdf', 'mo', 'mn', 'mus', 'my', 'nah', 'na',
- 'fj', 'nl', 'nds-nl', 'cr', 'ne', 'new', 'ja', 'nap', 'ce', 'pih',
- 'no', 'nn', 'nrm', 'nov', 'oc', 'or', 'om', 'ng', 'hz', 'ug',
- 'uz', 'pa', 'pi', 'pag', 'pap', 'ps', 'km', 'pms', 'nds', 'pl',
- 'pt', 'kaa', 'crh', 'ty', 'ksh', 'ro', 'rmy', 'rm', 'qu', 'ru', 'sah', 'se',
- 'sm', 'sa', 'sg', 'sc', 'sco', 'stq', 'st', 'tn', 'sq', 'scn', 'si',
- 'simple', 'sd', 'ss', 'sk', 'cu', 'sl', 'szl', 'so', 'sr', 'sh',
- 'srn', 'su', 'fi', 'sv', 'tl', 'ta', 'kab', 'roa-tara', 'tt', 'te', 'tet',
- 'th', 'vi', 'ti', 'tg', 'tpi', 'to', 'chr', 'chy', 've', 'tr',
- 'tk', 'tw', 'udm', 'bug', 'uk', 'ur', 'vec', 'vo', 'fiu-vro', 'wa',
- 'vls', 'war', 'wo', 'wuu', 'ts', 'ii', 'yi', 'yo', 'zh-yue', 'cbk-zam',
- 'diq', 'zea', 'bat-smg', 'zh',
+ 'mr', 'mzn', 'ms', 'cdo', 'mdf', 'mo', 'mn', 'mus', 'my', 'nah',
+ 'na', 'fj', 'nl', 'nds-nl', 'cr', 'ne', 'new', 'ja', 'nap',
+ 'ce', 'pih', 'no', 'nn', 'nrm', 'nov', 'oc', 'or', 'om', 'ng',
+ 'hz', 'ug', 'uz', 'pa', 'pi', 'pag', 'pap', 'ps', 'km', 'pms',
+ 'nds', 'pl', 'pt', 'kaa', 'crh', 'ty', 'ksh', 'ro', 'rmy', 'rm',
+ 'qu', 'ru', 'sah', 'se', 'sm', 'sa', 'sg', 'sc', 'sco', 'stq',
+ 'st', 'tn', 'sq', 'scn', 'si', 'simple', 'sd', 'ss', 'sk', 'cu',
+ 'sl', 'szl', 'so', 'sr', 'sh', 'srn', 'su', 'fi', 'sv', 'tl',
+ 'ta', 'kab', 'roa-tara', 'tt', 'te', 'tet', 'th', 'vi', 'ti',
+ 'tg', 'tpi', 'to', 'chr', 'chy', 've', 'tr', 'tk', 'tw', 'udm',
+ 'bug', 'uk', 'ur', 'vec', 'vo', 'fiu-vro', 'wa', 'vls', 'war',
+ 'wo', 'wuu', 'ts', 'ii', 'yi', 'yo', 'zh-yue', 'cbk-zam', 'diq',
+ 'zea', 'bat-smg', 'zh',
]
self.langs = {}
@@ -52,7 +54,8 @@
# timedelta(hours=+1)
self.servergmtoffset = timedelta()
- # letters that can follow a wikilink and are regarded as part of this link
+ # letters that can follow a wikilink and are regarded as part of
+ # this link
# This depends on the linktrail setting in LanguageXx.php and on
# [[MediaWiki:Linktrail]].
# Note: this is a regular expression.
@@ -501,19 +504,20 @@
# When both at the bottom should categories come after interwikilinks?
self.categories_last = []
- # Which languages have a special order for putting interlanguage links,
- # and what order is it? If a language is not in interwiki_putfirst,
- # alphabetical order on language code is used. For languages that are in
- # interwiki_putfirst, interwiki_putfirst is checked first, and
- # languages are put in the order given there. All other languages are put
- # after those, in code-alphabetical order.
+ # Which languages have a special order for putting interlanguage
+ # links, and what order is it? If a language is not in
+ # interwiki_putfirst, alphabetical order on language code is used.
+ # For languages that are in interwiki_putfirst, interwiki_putfirst
+ # is checked first, and languages are put in the order given there.
+ # All other languages are put after those, in code-alphabetical
+ # order.
self.interwiki_putfirst = {}
- # Languages in interwiki_putfirst_doubled should have a number plus a list
- # of languages. If there are at least the number of interwiki links, all
- # languages in the list should be placed at the front as well as in the
- # normal list.
- self.interwiki_putfirst_doubled = {}
+ # Languages in interwiki_putfirst_doubled should have a number plus
+ # a list of languages. If there are at least the number of interwiki
+ # links, all languages in the list should be placed at the front as
+ # well as in the normal list.
+ self.interwiki_putfirst_doubled = {} # THIS APPEARS TO BE UNUSED!
# Some families, e. g. commons and meta, are not multilingual and
# forward interlanguage links to another family (wikipedia).
@@ -521,10 +525,10 @@
# family.
self.interwiki_forward = None
- # Which language codes do no longer exist and by which language code should
- # they be replaced. If for example the language with code xx: now should get
- # code yy:, add {'xx':'yy'} to obsolete.
- # If all links to language xx: shall be removed, add {'xx': None}.
+ # Which language codes no longer exist and by which language code
+ # should they be replaced. If for example the language with code xx:
+ # now should get code yy:, add {'xx':'yy'} to obsolete. If all
+ # links to language xx: should be removed, add {'xx': None}.
self.obsolete = {}
# Language codes of the largest wikis. They should be roughly sorted
@@ -548,33 +552,37 @@
],
# languages that use the cyrillic alphabet
'cyril': [
- 'ab', 'av', 'ba', 'be', 'be-x-old', 'bg', 'bxr', 'ce', 'cu', 'cv', 'kv',
- 'ky', 'mk', 'lbe', 'mdf', 'mn', 'mo', 'myv', 'os', 'ru', 'sah', 'tg',
- 'tk', 'udm', 'uk', 'xal',
+ 'ab', 'av', 'ba', 'be', 'be-x-old', 'bg', 'bxr', 'ce', 'cu',
+ 'cv', 'kv', 'ky', 'mk', 'lbe', 'mdf', 'mn', 'mo', 'myv',
+ 'os', 'ru', 'sah', 'tg', 'tk', 'udm', 'uk', 'xal',
# languages using multiple scripts, including cyrillic
'ha', 'kk', 'sh', 'sr', 'tt'
],
# languages that use the latin alphabet
'latin': [
- 'aa', 'af', 'ak', 'als', 'an', 'ang', 'ast', 'ay', 'bar', 'bat-smg',
- 'bcl', 'bi', 'bm', 'br', 'bs', 'ca', 'cbk-zam', 'cdo', 'ceb', 'ch',
- 'cho', 'chy', 'co', 'crh', 'cs', 'csb', 'cy', 'da', 'de', 'diq', 'dsb',
- 'ee', 'eml', 'en', 'eo', 'es', 'et', 'eu', 'ext', 'ff', 'fi', 'fiu-vro',
- 'fj', 'fo', 'fr', 'frp', 'fur', 'fy', 'ga', 'gd', 'gl', 'gn', 'gv',
- 'hak', 'haw', 'hif', 'ho', 'hr', 'hsb', 'ht', 'hu', 'hz', 'ia', 'id',
- 'ie', 'ig', 'ik', 'ilo', 'io', 'is', 'it', 'jbo', 'jv', 'kaa', 'kab',
- 'kg', 'ki', 'kj', 'kl', 'kr', 'ksh', 'kw', 'la', 'lad', 'lb', 'lg',
- 'li', 'lij', 'lmo', 'ln', 'lt', 'lv', 'map-bms', 'mg', 'mh', 'mi', 'ms',
- 'mt', 'mus', 'na', 'nah', 'nap', 'nds', 'nds-nl', 'ng', 'nl', 'nn',
- 'no', 'nov', 'nrm', 'nv', 'ny', 'oc', 'om', 'pag', 'pam', 'pap', 'pdc',
- 'pih', 'pl', 'pms', 'pt', 'qu', 'rm', 'rn', 'ro', 'roa-rup', 'roa-tara',
- 'rw', 'sc', 'scn', 'sco', 'se', 'sg', 'simple', 'sk', 'sl', 'sm', 'sn',
- 'so', 'sq', 'srn', 'ss', 'st', 'stq', 'su', 'sv', 'sw', 'szl', 'tet',
- 'tl', 'tn', 'to', 'tpi', 'tr', 'ts', 'tum', 'tw', 'ty', 'uz', 've',
- 'vec', 'vi', 'vls', 'vo', 'wa', 'war', 'wo', 'xh', 'yo', 'zea',
- 'zh-min-nan', 'zu',
+ 'aa', 'af', 'ak', 'als', 'an', 'ang', 'ast', 'ay', 'bar',
+ 'bat-smg', 'bcl', 'bi', 'bm', 'br', 'bs', 'ca', 'cbk-zam',
+ 'cdo', 'ceb', 'ch', 'cho', 'chy', 'co', 'crh', 'cs', 'csb',
+ 'cy', 'da', 'de', 'diq', 'dsb', 'ee', 'eml', 'en', 'eo',
+ 'es', 'et', 'eu', 'ext', 'ff', 'fi', 'fiu-vro', 'fj', 'fo',
+ 'fr', 'frp', 'fur', 'fy', 'ga', 'gd', 'gl', 'gn', 'gv',
+ 'hak', 'haw', 'hif', 'ho', 'hr', 'hsb', 'ht', 'hu', 'hz',
+ 'ia', 'id', 'ie', 'ig', 'ik', 'ilo', 'io', 'is', 'it',
+ 'jbo', 'jv', 'kaa', 'kab', 'kg', 'ki', 'kj', 'kl', 'kr',
+ 'ksh', 'kw', 'la', 'lad', 'lb', 'lg', 'li', 'lij', 'lmo',
+ 'ln', 'lt', 'lv', 'map-bms', 'mg', 'mh', 'mi', 'ms', 'mt',
+ 'mus', 'na', 'nah', 'nap', 'nds', 'nds-nl', 'ng', 'nl',
+ 'nn', 'no', 'nov', 'nrm', 'nv', 'ny', 'oc', 'om', 'pag',
+ 'pam', 'pap', 'pdc', 'pih', 'pl', 'pms', 'pt', 'qu', 'rm',
+ 'rn', 'ro', 'roa-rup', 'roa-tara', 'rw', 'sc', 'scn', 'sco',
+ 'se', 'sg', 'simple', 'sk', 'sl', 'sm', 'sn', 'so', 'sq',
+ 'srn', 'ss', 'st', 'stq', 'su', 'sv', 'sw', 'szl', 'tet',
+ 'tl', 'tn', 'to', 'tpi', 'tr', 'ts', 'tum', 'tw', 'ty',
+ 'uz', 've', 'vec', 'vi', 'vls', 'vo', 'wa', 'war', 'wo',
+ 'xh', 'yo', 'zea', 'zh-min-nan', 'zu',
# languages using multiple scripts, including latin
- 'az', 'chr', 'ha', 'iu', 'kk', 'ku', 'rmy', 'sh', 'sr', 'tt', 'ug', 'za'
+ 'az', 'chr', 'ha', 'iu', 'kk', 'ku', 'rmy', 'sh', 'sr',
+ 'tt', 'ug', 'za'
],
# Scandinavian languages
'scand': [
@@ -592,8 +600,8 @@
# values are dicts where:
# keys are the originating langcode, or _default
# values are dicts where:
- # keys are the languages that can be linked to from the lang+ns, or _default
- # values are a list of namespace numbers
+ # keys are the languages that can be linked to from the lang+ns, or
+ # '_default'; values are a list of namespace numbers
self.crossnamespace = {}
#### Examples :
## Allowing linking to pt' 102 NS from any other lang' 0 NS is
@@ -609,10 +617,10 @@
"""Add a new language to the langs and namespaces of the family.
This is supposed to be called in the constructor of the family."""
self.langs[code] = location
+##
+## for num, val in namespaces.items():
+## self.namespaces[num][code]=val
- for num, val in namespaces.items():
- self.namespaces[num][code]=val
-
def get_known_families(self, site):
return self.known_families
@@ -626,122 +634,122 @@
"ERROR: linktrail in language %(language_code)s unknown"
% {'language_code': code})
- def namespace(self, code, ns_number, fallback='_default', all=False):
- if not self.isDefinedNS(ns_number):
- raise KeyError(
-'ERROR: Unknown namespace %(ns_number)d for %(language_code)s:%(ns_name)s'
- % {'ns_number': ns_number,
- 'language_code': code,
- 'ns_name': self.name})
- elif self.isNsI18N(ns_number, code):
- v = self.namespaces[ns_number][code]
- if type(v) is not list:
- v = [v,]
- if all and self.isNsI18N(ns_number, fallback):
- v2 = self.namespaces[ns_number][fallback]
- if type(v2) is list:
- v.extend(v2)
- else:
- v.append(v2)
- elif fallback and self.isNsI18N(ns_number, fallback):
- v = self.namespaces[ns_number][fallback]
- if type(v) is not list:
- v = [v,]
- else:
- raise KeyError(
-'ERROR: title for namespace %(ns_number)d in language %(language_code)s unknown'
- % {'ns_number': ns_number,
- 'language_code': code})
- if all:
- namespaces = list(set(v))
- # Lowercase versions of namespaces
- if code not in self.nocapitalize:
- namespaces.extend([ns[0].lower() + ns[1:]
- for ns in namespaces
- if ns and ns[0].lower() != ns[0].upper()])
- # Underscore versions of namespaces
- namespaces.extend([ns.replace(' ', '_')
- for ns in namespaces if ns and ' ' in ns])
- return tuple(namespaces)
- else:
- return v[0]
-
- def isDefinedNS(self, ns_number):
- """Return True if the namespace has been defined in this family."""
-
- return self.namespaces.has_key(ns_number)
-
- def isNsI18N(self, ns_number, code):
- """Return True if the namespace has been internationalized.
-
- (it has a custom entry for a given language)
-
- """
- return self.namespaces[ns_number].has_key(code)
-
- def isDefinedNSLanguage(self, ns_number, code, fallback='_default'):
- """Return True if the namespace has been defined in this family
- for this language or its fallback.
- """
- if not self.isDefinedNS(ns_number):
- return False
- elif self.isNsI18N(ns_number, code):
- return True
- elif fallback and self.isNsI18N(ns_number, fallback):
- return True
- else:
- return False
-
- def normalizeNamespace(self, code, value):
- """Given a value, attempt to match it with all available namespaces,
- with default and localized versions. Sites may have more than one
- way to write the same namespace - choose the first one in the list.
- If nothing can be normalized, return the original value.
- """
- for ns, items in self.namespaces.iteritems():
- if items.has_key(code):
- v = items[code]
- elif items.has_key('_default'):
- v = items['_default']
- else:
- continue
- if type(v) is list:
- if value in v: return v[0]
- else:
- if value == v: return v
- try:
- if value == self.namespace('_default', ns):
- return self.namespace(code, ns)
- except KeyError:
- pass
- return value
-
- def getNamespaceIndex(self, lang, namespace):
- """Given a namespace, attempt to match it with all available
- namespaces. Sites may have more than one way to write the same
- namespace - choose the first one in the list. Returns namespace
- index or None.
- """
- namespace = namespace.lower()
- for n in self.namespaces.keys():
- try:
- nslist = self.namespaces[n][lang]
- if type(nslist) != type([]):
- nslist = [nslist]
- for ns in nslist:
- if ns.lower() == namespace:
- return n
- except (KeyError,AttributeError):
- # The namespace has no localized name defined
- pass
- if lang != '_default':
- # This is not a localized namespace. Try if it
- # is a default (English) namespace.
- return self.getNamespaceIndex('_default', namespace)
- else:
- # give up
- return None
-
+## def namespace(self, code, ns_number, fallback='_default', all=False):
+## if not self.isDefinedNS(ns_number):
+## raise KeyError(
+##'ERROR: Unknown namespace %(ns_number)d for %(language_code)s:%(ns_name)s'
+## % {'ns_number': ns_number,
+## 'language_code': code,
+## 'ns_name': self.name})
+## elif self.isNsI18N(ns_number, code):
+## v = self.namespaces[ns_number][code]
+## if type(v) is not list:
+## v = [v,]
+## if all and self.isNsI18N(ns_number, fallback):
+## v2 = self.namespaces[ns_number][fallback]
+## if type(v2) is list:
+## v.extend(v2)
+## else:
+## v.append(v2)
+## elif fallback and self.isNsI18N(ns_number, fallback):
+## v = self.namespaces[ns_number][fallback]
+## if type(v) is not list:
+## v = [v,]
+## else:
+## raise KeyError(
+##'ERROR: title for namespace %(ns_number)d in language %(language_code)s unknown'
+## % {'ns_number': ns_number,
+## 'language_code': code})
+## if all:
+## namespaces = list(set(v))
+## # Lowercase versions of namespaces
+## if code not in self.nocapitalize:
+## namespaces.extend([ns[0].lower() + ns[1:]
+## for ns in namespaces
+## if ns and ns[0].lower() != ns[0].upper()])
+## # Underscore versions of namespaces
+## namespaces.extend([ns.replace(' ', '_')
+## for ns in namespaces if ns and ' ' in ns])
+## return tuple(namespaces)
+## else:
+## return v[0]
+##
+## def isDefinedNS(self, ns_number):
+## """Return True if the namespace has been defined in this family."""
+##
+## return self.namespaces.has_key(ns_number)
+##
+## def isNsI18N(self, ns_number, code):
+## """Return True if the namespace has been internationalized.
+##
+## (it has a custom entry for a given language)
+##
+## """
+## return self.namespaces[ns_number].has_key(code)
+##
+## def isDefinedNSLanguage(self, ns_number, code, fallback='_default'):
+## """Return True if the namespace has been defined in this family
+## for this language or its fallback.
+## """
+## if not self.isDefinedNS(ns_number):
+## return False
+## elif self.isNsI18N(ns_number, code):
+## return True
+## elif fallback and self.isNsI18N(ns_number, fallback):
+## return True
+## else:
+## return False
+##
+## def normalizeNamespace(self, code, value):
+## """Given a value, attempt to match it with all available namespaces,
+## with default and localized versions. Sites may have more than one
+## way to write the same namespace - choose the first one in the list.
+## If nothing can be normalized, return the original value.
+## """
+## for ns, items in self.namespaces.iteritems():
+## if items.has_key(code):
+## v = items[code]
+## elif items.has_key('_default'):
+## v = items['_default']
+## else:
+## continue
+## if type(v) is list:
+## if value in v: return v[0]
+## else:
+## if value == v: return v
+## try:
+## if value == self.namespace('_default', ns):
+## return self.namespace(code, ns)
+## except KeyError:
+## pass
+## return value
+##
+## def getNamespaceIndex(self, lang, namespace):
+## """Given a namespace, attempt to match it with all available
+## namespaces. Sites may have more than one way to write the same
+## namespace - choose the first one in the list. Returns namespace
+## index or None.
+## """
+## namespace = namespace.lower()
+## for n in self.namespaces.keys():
+## try:
+## nslist = self.namespaces[n][lang]
+## if type(nslist) != type([]):
+## nslist = [nslist]
+## for ns in nslist:
+## if ns.lower() == namespace:
+## return n
+## except (KeyError,AttributeError):
+## # The namespace has no localized name defined
+## pass
+## if lang != '_default':
+## # This is not a localized namespace. Try if it
+## # is a default (English) namespace.
+## return self.getNamespaceIndex('_default', namespace)
+## else:
+## # give up
+## return None
+##
def disambig(self, code, fallback = '_default'):
if self.disambiguationTemplates.has_key(code):
return self.disambiguationTemplates[code]
@@ -752,38 +760,6 @@
"ERROR: title for disambig template in language %(language_code)s unknown"
% {'language_code': code})
- # Returns the title of the special namespace in language 'code', taken from
- # dictionary above.
- # If the dictionary doesn't contain a translation, it will use language
- # 'fallback' (or, if fallback isn't given, MediaWiki default).
- # If you want the bot to crash in case of an unknown namespace name, use
- # fallback = None.
- def special_namespace(self, code, fallback = '_default'):
- return self.namespace(code, -1, fallback)
-
- def special_namespace_url(self, code, fallback = '_default'):
- encoded_title = self.namespace(code, -1, fallback).encode(self.code2encoding(code))
- return urllib.quote(encoded_title)
-
- def image_namespace(self, code, fallback = '_default'):
- return self.namespace(code, 6, fallback)
-
- def image_namespace_url(self, code, fallback = '_default'):
- encoded_title = self.namespace(code, 6, fallback).encode(self.code2encoding(code))
- return urllib.quote(encoded_title)
-
- def mediawiki_namespace(self, code, fallback = '_default'):
- return self.namespace(code, 8, fallback)
-
- def template_namespace(self, code, fallback = '_default'):
- return self.namespace(code, 10, fallback)
-
- def category_namespace(self, code, fallback = '_default'):
- return self.namespace(code, 14, fallback)
-
- def category_namespaces(self, code):
- return self.namespace(code, 14, all = True)
-
# Redirect code can be translated.
# Note that redirect codes are case-insensitive, so it is enough
# to enter the code in lowercase here.
@@ -809,11 +785,11 @@
'mzn': [u'تغییرمسیر'],
'nl': [u'DOORVERWIJZING'],
'nn': [u'omdiriger'],
- 'ru': [u'REDIRECT', u'перенаправление', u'перенапр'], # localised version is not
- # so usual, so put the default
- # one as the most used.
+ 'ru': [u'REDIRECT', # localised version is not
+ u'перенаправление', # so usual, so put the default
+ u'перенапр'], # one as the most used.
'sk': [u'presmeruj'],
- 'sr': [u'преусмери',u'Преусмери'], # Using lowercase only doesn't work?
+ 'sr': [u'преусмери', u'Преусмери'], # lowercase only doesn't work?
'su': [u'redirected', u'alih'],
'tt': [u'yünältü'],
'yi': [u'ווייטערפירן']
@@ -926,180 +902,6 @@
return 10
return 1000 * int(M.group(1)) + int(M.group(2)) - 1000
- def page_action_address(self, code, name, action):
- return '%s?title=%s&action=%s' % (self.path(code), name, action)
-
- def put_address(self, code, name):
- return '%s?title=%s&action=submit' % (self.path(code), name)
-
- def get_address(self, code, name):
- return '%s?title=%s&redirect=no' % (self.path(code), name)
-
- # The URL to get a page, in the format indexed by Google.
- def nice_get_address(self, code, name):
- return '/wiki/%s' % (name)
-
- def edit_address(self, code, name):
- return '%s?title=%s&action=edit' % (self.path(code), name)
-
- def purge_address(self, code, name):
- return '%s?title=%s&redirect=no&action=purge' % (self.path(code), name)
-
- def references_address(self, code, name):
- return '%s?title=%s:Whatlinkshere&target=%s&limit=%d' % (self.path(code), self.special_namespace_url(code), name, config.special_page_limit)
-
- def upload_address(self, code):
- return '%s?title=%s:Upload' % (self.path(code), self.special_namespace_url(code))
-
- def double_redirects_address(self, code, default_limit = True):
- if default_limit:
- return '%s?title=%s:DoubleRedirects' % (self.path(code), self.special_namespace_url(code))
- else:
- return '%s?title=%s:DoubleRedirects&limit=%d' % (self.path(code), self.special_namespace_url(code), config.special_page_limit)
-
- def broken_redirects_address(self, code, default_limit = True):
- if default_limit:
- return '%s?title=%s:BrokenRedirects' % (self.path(code), self.special_namespace_url(code))
- else:
- return '%s?title=%s:BrokenRedirects&limit=%d' % (self.path(code), self.special_namespace_url(code), config.special_page_limit)
-
- def allmessages_address(self, code):
- return "%s?title=%s:Allmessages&ot=html" % (self.path(code), self.special_namespace_url(code))
-
- def login_address(self, code):
- return '%s?title=%s:Userlogin' % (self.path(code), self.special_namespace_url(code))
-
- def captcha_image_address(self, code, id):
- return '%s?title=%s:Captcha/image&wpCaptchaId=%s' % (self.path(code), self.special_namespace_url(code), id)
-
- def watchlist_address(self, code):
- return '%s?title=%s:Watchlist/edit' % (self.path(code), self.special_namespace_url(code))
-
- def contribs_address(self, code, target, limit=500, offset=''):
- return '%s?title=%s:Contributions&target=%s&limit=%s&offset=%s' % (self.path(code), self.special_namespace_url(code), target, limit, offset)
-
- def move_address(self, code):
- return '%s?title=%s:Movepage&action=submit' % (self.path(code), self.special_namespace_url(code))
-
- def delete_address(self, code, name):
- return '%s?title=%s&action=delete' % (self.path(code), name)
-
- def undelete_view_address(self, code, name, ts=''):
- return '%s?title=%s:Undelete&target=%s×tamp=%s' % (self.path(code), self.special_namespace_url(code), name, ts)
-
- def undelete_address(self, code):
- return '%s?title=%s:Undelete&action=submit' % (self.path(code), self.special_namespace_url(code))
-
- def protect_address(self, code, name):
- return '%s?title=%s&action=protect' % (self.path(code), name)
-
- def unprotect_address(self, code, name):
- return '%s?title=%s&action=unprotect' % (self.path(code), name)
-
- def block_address(self, code):
- return '%s?title=%s:Blockip&action=submit' % (self.path(code), self.special_namespace_url(code))
-
- def unblock_address(self, code):
- return '%s?title=%s:Ipblocklist&action=submit' % (self.path(code), self.special_namespace_url(code))
-
- def blocksearch_address(self, code, name):
- return '%s?title=%s:Ipblocklist&action=search&ip=%s' % (self.path(code), self.special_namespace_url(code), name)
-
- def linksearch_address(self, code, link, limit=500, offset=0):
- return '%s?title=%s:Linksearch&limit=%d&offset=%d&target=%s' % (self.path(code), self.special_namespace_url(code), limit, offset, link)
-
- def version_history_address(self, code, name, limit = config.special_page_limit):
- return '%s?title=%s&action=history&limit=%d' % (self.path(code), name, limit)
-
- def export_address(self, code):
- return '%s?title=%s:Export' % (self.path(code), self.special_namespace_url('_default'))
-
- def query_address(self, code):
- return '%s?' % self.querypath(code)
-
- def api_address(self, code):
- return '%s?' % self.apipath(code)
-
- def search_address(self, code, query, limit=100, namespaces = None):
- """
- Constructs a URL for searching using Special:Search
- 'namespaces' may be an int or a list; an empty list selects
- all namespaces. Defaults to namespace 0
- """
- namespace_params = ''
- if namespaces is not None:
- if isinstance(namespaces, int):
- namespace_params = "&ns%d=1" % namespaces
- elif isinstance (namespaces, list):
- if len(namespaces) == 0:
- # add all namespaces
- namespaces = self.namespaces.keys()
- for i in namespaces:
- if i > 0:
- namespace_params = namespace_params + '&ns%d=1' % i
-
- return "%s?title=%s:Search&search=%s&limit=%d%s&fulltext=1" % (self.path(code),
- self.special_namespace_url(code),
- query,
- limit,
- namespace_params)
-
- def allpages_address(self, code, start, namespace = 0):
- if self.version(code)=="1.2":
- return '%s?title=%s:Allpages&printable=yes&from=%s' % (
- self.path(code), self.special_namespace_url(code), start)
- else:
- return '%s?title=%s:Allpages&from=%s&namespace=%s' % (
- self.path(code), self.special_namespace_url(code), start, namespace)
-
- def log_address(self, code, limit=50, mode = ''):
- return "%s?title=Special:Log&type=%s&user=&page=&limit=%d" % (self.path(code), mode, limit)
-
- def newpages_address(self, code, limit=50):
- return "%s?title=%s:Newpages&limit=%d" % (self.path(code), self.special_namespace_url(code), limit)
-
- def longpages_address(self, code, limit=500):
- return "%s?title=%s:Longpages&limit=%d" % (self.path(code), self.special_namespace_url(code), limit)
-
- def shortpages_address(self, code, limit=500):
- return "%s?title=%s:Shortpages&limit=%d" % (self.path(code), self.special_namespace_url(code), limit)
-
- def categories_address(self, code, limit=500):
- return "%s?title=%s:Categories&limit=%d" % (self.path(code), self.special_namespace_url(code), limit)
-
- def unusedfiles_address(self, code, limit=500):
- return "%s?title=%s:Unusedimages&limit=%d" % (self.path(code), self.special_namespace_url(code), limit)
-
- def deadendpages_address(self, code, limit=500):
- return "%s?title=%s:Deadendpages&limit=%d" % (self.path(code), self.special_namespace_url(code), limit)
-
- def ancientpages_address(self, code, limit=500):
- return "%s?title=%s:Ancientpages&limit=%d" % (self.path(code), self.special_namespace_url(code), limit)
-
- def lonelypages_address(self, code, limit=500):
- return "%s?title=%s:Lonelypages&limit=%d" % (self.path(code), self.special_namespace_url(code), limit)
-
- def protectedpages_address(self, code, limit=500):
- return "%s?title=%s:ProtectedPages&limit=%d" % (self.path(code), self.special_namespace_url(code), limit)
-
- def unwatchedpages_address(self, code, limit=500):
- return "%s?title=%s:Unwatchedpages&limit=%d" % (self.path(code), self.special_namespace_url(code), limit)
-
- def uncategorizedcategories_address(self, code, limit=500):
- return "%s?title=%s:Uncategorizedcategories&limit=%d" % (self.path(code), self.special_namespace_url(code), limit)
-
- def uncategorizedimages_address(self, code, limit=500):
- return "%s?title=%s:Uncategorizedimages&limit=%d" % (self.path(code), self.special_namespace_url(code), limit)
-
- def uncategorizedpages_address(self, code, limit=500):
- return "%s?title=%s:Uncategorizedpages&limit=%d" % (self.path(code), self.special_namespace_url(code), limit)
-
- def unusedcategories_address(self, code, limit=500):
- return "%s?title=%s:Unusedcategories&limit=%d" % (self.path(code), self.special_namespace_url(code), limit)
-
- def withoutinterwiki_address(self, code, limit=500):
- return "%s?title=%s:Withoutinterwiki&limit=%d" % (self.path(code), self.special_namespace_url(code), limit)
-
def code2encoding(self, code):
"""Return the encoding for a specific language wiki"""
return 'utf-8'
Modified: branches/rewrite/pywikibot/login.py
===================================================================
--- branches/rewrite/pywikibot/login.py 2008-11-05 20:25:44 UTC (rev 6063)
+++ branches/rewrite/pywikibot/login.py 2008-11-05 20:27:13 UTC (rev 6064)
@@ -15,12 +15,11 @@
several sites and use the same password for all of them.
Asks you for the password, then logs in on all given sites.
- -pass:XXXX Uses XXXX as password. Be careful if you use this
- parameter because your password will be shown on your
- screen, and will probably be saved in your command line
- history. This is NOT RECOMMENDED for use on computers
- where others have either physical or remote access.
- Use -pass instead.
+ -pass:XXXX Uses XXXX as password. Be careful if you use this parameter
+ because your password will be shown on your screen, and will
+ probably be saved in your command line history. This is NOT
+ RECOMMENDED for use on computers where others have either
+ physical or remote access. Use -pass instead.
-sysop Log in with your sysop account.
@@ -47,7 +46,6 @@
import logging
import re
import urllib2
-import config
import pywikibot
from pywikibot.exceptions import *
@@ -79,7 +77,7 @@
self.username = user
elif sysop:
try:
- self.username = config.sysopnames\
+ self.username = pywikibot.config2.sysopnames\
[self.site.family.name][self.site.code]
except KeyError:
raise NoUsername(
@@ -91,7 +89,7 @@
'wiki_code': self.site.code})
else:
try:
- self.username = config.usernames\
+ self.username = pywikibot.config2.usernames\
[self.site.family.name][self.site.code]
except:
raise NoUsername(
@@ -102,7 +100,7 @@
% {'fam_name': self.site.family.name,
'wiki_code': self.site.code})
self.password = password
- if getattr(config, 'password_file', ''):
+ if getattr(pywikibot.config2, 'password_file', ''):
self.readPassword()
def botAllowed(self):
@@ -142,10 +140,9 @@
The argument data is the raw data, as returned by getCookie().
"""
- filename = config.datafilepath('%s-%s-%s-login.data'
- % (self.site.family.name,
- self.site.code,
- self.username))
+ filename = pywikibot.config2.datafilepath('%s-%s-%s-login.data'
+ % (self.site.family.name, self.site.code,
+ self.username))
f = open(filename, 'w')
f.write(data)
f.close()
@@ -166,7 +163,7 @@
("en", "wikipedia", "my_en_user", "my_en_pass")
"""
- file = open(config.password_file)
+ file = open(pywikibot.config2.password_file)
for line in file:
if not line.strip(): continue
entry = eval(line)
@@ -241,9 +238,9 @@
return
if logall:
if sysop:
- namedict = config.sysopnames
+ namedict = pywikibot.config2.sysopnames
else:
- namedict = config.usernames
+ namedict = pywikibot.config2.usernames
for familyName in namedict.iterkeys():
for lang in namedict[familyName].iterkeys():
try:
Modified: branches/rewrite/pywikibot/page.py
===================================================================
--- branches/rewrite/pywikibot/page.py 2008-11-05 20:25:44 UTC (rev 6063)
+++ branches/rewrite/pywikibot/page.py 2008-11-05 20:27:13 UTC (rev 6064)
@@ -567,7 +567,7 @@
user_config.py, or using page.put(force=True).
""" # TODO: move this to Site object?
- if config.ignore_bot_templates: #Check the "master ignore switch"
+ if pywikibot.config2.ignore_bot_templates: #Check the "master ignore switch"
return True
try:
templates = self.templatesWithParams();
Modified: branches/rewrite/pywikibot/tests/site_tests.py
===================================================================
--- branches/rewrite/pywikibot/tests/site_tests.py 2008-11-05 20:25:44 UTC (rev 6063)
+++ branches/rewrite/pywikibot/tests/site_tests.py 2008-11-05 20:27:13 UTC (rev 6064)
@@ -29,17 +29,17 @@
def testBaseMethods(self):
"""Test cases for BaseSite methods"""
- self.assertEqual(mysite.family.name, pywikibot.config.family)
- self.assertEqual(mysite.code, pywikibot.config.mylang)
+ self.assertEqual(mysite.family.name, pywikibot.config2.family)
+ self.assertEqual(mysite.code, pywikibot.config2.mylang)
self.assertType(mysite.lang, basestring)
self.assertType(mysite == pywikibot.Site("en", "wikipedia"), bool)
self.assertType(mysite.user(), (basestring, type(None)))
self.assertEqual(mysite.sitename(),
- "%s:%s" % (pywikibot.config.family,
- pywikibot.config.mylang))
+ "%s:%s" % (pywikibot.config2.family,
+ pywikibot.config2.mylang))
self.assertEqual(repr(mysite),
'Site("%s", "%s")'
- % (pywikibot.config.mylang, pywikibot.config.family))
+ % (pywikibot.config2.mylang, pywikibot.config2.family))
self.assertType(mysite.linktrail(), basestring)
self.assertType(mysite.redirect(default=True), basestring)
self.assertType(mysite.disambcategory(), pywikibot.Category)
Modified: branches/rewrite/pywikibot/throttle.py
===================================================================
--- branches/rewrite/pywikibot/throttle.py 2008-11-05 20:25:44 UTC (rev 6063)
+++ branches/rewrite/pywikibot/throttle.py 2008-11-05 20:27:13 UTC (rev 6064)
@@ -9,8 +9,8 @@
#
__version__ = '$Id: $'
-import config
import pywikibot
+from pywikibot import config2 as config
import logging
import math
More information about the Pywikipedia-l
mailing list