Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ environment:

# Test the lowest supported release of each major Python version.

# Pywikibot support matrix suggests 'should run' on Python 2.6.5+
# Only Python 2.6.6 is able to be set up on Appveyor.
# https://github.com/ogrisel/python-appveyor-demo/issues/10
# fwiw, Redhat Enterprise Linux ships with 2.6.6.

- PYTHON: "C:\\Python266-x64"
PYTHON_VERSION: "2.6.6"
PYTHON_ARCH: "64"

- PYTHON: "C:\\Python272"
PYTHON_VERSION: "2.7.2"
PYTHON_ARCH: "32"
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ language: python
sudo: false

python:
- '2.6'
- '2.7'
- '3.3'
- '3.4'
Expand Down Expand Up @@ -160,7 +159,7 @@ matrix:
env: LANGUAGE=test FAMILY=wikidata SITE_ONLY=1
- python: '3.4'
env: LANGUAGE=ar FAMILY=wiktionary PYWIKIBOT2_TEST_NO_RC=1
- python: '2.6'
- python: '2.7'
env: LANGUAGE=wikidata FAMILY=wikidata SITE_ONLY=1

notifications:
Expand Down
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Release history
Current release
---------------

* Desupport Python 2.6
* PendingDeprecationWarning: support for py2.6 and py3.3 will be dropped
* Bugfixes and improvements
* Localisation updates

Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Welcome to pywikibot!

Pywikibot is a full-stack framework for editing `MediaWiki <https://mediawiki.org>`_ wiki's. (more intro)

Pywikibot supports Python 2.6.5+, 2.7.2+ and 3.3+.
Pywikibot supports Python 2.7.2+ and 3.3+.

Pywikibot and this documentation are licensed under the :ref:`MIT license <licenses-MIT>`;
manual pages on mediawiki.org are licensed under the `CC-BY-SA 3.0`_ license.
Expand Down
21 changes: 13 additions & 8 deletions pwb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
and it will use the package directory to store all user files, will fix up
search paths so the package does not need to be installed, etc.
"""
# (C) Pywikibot team, 2015-2016
# (C) Pywikibot team, 2015-2018
#
# Distributed under the terms of the MIT license.
#
Expand All @@ -31,26 +31,25 @@

PYTHON_VERSION = sys.version_info[:3]
PY2 = (PYTHON_VERSION[0] == 2)
PY26 = (PYTHON_VERSION < (2, 7))
SUPPORT = 'supported under Python 2.7.2+ or 3.4+'

versions_required_message = """
Pywikibot not available on:
%s
{version}

Pywikibot is only supported under Python 2.6.5+, 2.7.2+ or 3.3+
Pywikibot is only {supported}.
"""


def python_is_supported():
"""Check that Python is supported."""
# Any change to this must be copied to setup.py
return (PYTHON_VERSION >= (3, 3, 0) or
(PY2 and PYTHON_VERSION >= (2, 7, 2)) or
(PY26 and PYTHON_VERSION >= (2, 6, 5)))
return PYTHON_VERSION >= (3, 3, 0) or PYTHON_VERSION >= (2, 7, 2)


if not python_is_supported():
print(versions_required_message % sys.version)
print(versions_required_message.format(version=sys.version,
supported=SUPPORT))
sys.exit(1)

pwb = None
Expand Down Expand Up @@ -200,6 +199,12 @@ def abspath(path):

def main():
"""Command line entry point."""
if PY2 or not PY2 and PYTHON_VERSION < (3, 4):
warn('\nPywikibot support for Python release {version} will be '
'dropped soon.\nPywikibot will be {supported} further.\n'
.format(version=sys.version, supported=SUPPORT),
PendingDeprecationWarning)

global filename
if filename:
file_package = None
Expand Down
4 changes: 2 additions & 2 deletions pywikibot/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ are not installed by default on some Linux distributions:
* python-tkinter (optional, used by some experimental GUI stuff)


You need to have at least python version `2.6.5 <http://www.python.org/download/>`_
You need to have at least python version `2.7.2 <http://www.python.org/download/>`_
or newer installed on your computer to be able to run any of the code in this
package, but not 3.0-3.2. It works fine with 3.3-3.4 versions of python installed.
package, but not 3.0-3.2. It works fine with 3.3+ versions of python installed.
Support for older versions of python is not planned. Some scripts could run with
older python releases. Please refer the manual at mediawiki for further details
and restrictions.
Expand Down
154 changes: 26 additions & 128 deletions pywikibot/backports.py
Original file line number Diff line number Diff line change
@@ -1,169 +1,67 @@
# -*- coding: utf-8 -*-
"""
This module contains backports to support older Python versions.
This module contained backports to support older Python versions.

They contain the backported code originally developed for Python. It is
therefore distributed under the PSF license.
Their usage is deprecated and this module could be dropped.
"""
#
# (C) Python Software Foundation, 2001-2014
# (C) with modifications from Pywikibot team, 2015
# (C) Pywikibot team, 2018
#
# Distributed under the terms of the PSF license.
# Distributed under the terms of the MIT license.
#

from __future__ import absolute_import, unicode_literals

__license__ = """
PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
--------------------------------------------
1. This LICENSE AGREEMENT is between the Python Software Foundation
("PSF"), and the Individual or Organization ("Licensee") accessing and
otherwise using this software ("Python") in source or binary form and
its associated documentation.

2. Subject to the terms and conditions of this License Agreement, PSF hereby
grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
analyze, test, perform and/or display publicly, prepare derivative works,
distribute, and otherwise use Python alone or in any derivative version,
provided, however, that PSF's License Agreement and PSF's notice of copyright,
i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
2011, 2012, 2013, 2014 Python Software Foundation; All Rights Reserved" are
retained in Python alone or in any derivative version prepared by Licensee.

3. In the event Licensee prepares a derivative work that is based on
or incorporates Python or any part thereof, and wants to make
the derivative work available to others as provided herein, then
Licensee hereby agrees to include in any such work a brief summary of
the changes made to Python.

4. PSF is making Python available to Licensee on an "AS IS"
basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
INFRINGE ANY THIRD PARTY RIGHTS.

5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.

6. This License Agreement will automatically terminate upon a material
breach of its terms and conditions.

7. Nothing in this License Agreement shall be deemed to create any
relationship of agency, partnership, or joint venture between PSF and
Licensee. This License Agreement does not grant permission to use PSF
trademarks or trade name in a trademark sense to endorse or promote
products or services of Licensee, or any third party.

8. By copying, installing or otherwise using Python, Licensee
agrees to be bound by the terms and conditions of this License
Agreement.
"""

import logging
import warnings
from difflib import _format_range_unified

from pywikibot.tools import deprecated


@deprecated('difflib._format_range_unified')
def format_range_unified(start, stop):
"""
Convert range to the "ed" format.

Copied from C{difflib._format_range_unified()} which was introduced in
Python 2.7.2.

@see: https://hg.python.org/cpython/file/8527427914a2/Lib/difflib.py#l1147
DEPRECATED (Python 2.6 backport).
Use difflib._format_range_unified instead.
"""
# Per the diff spec at http://www.unix.org/single_unix_specification/
beginning = start + 1 # lines start numbering with one
length = stop - start
if length == 1:
return '{0}'.format(beginning)
if not length:
beginning -= 1 # empty ranges begin at line just before the range
return '{0},{1}'.format(beginning, length)
return _format_range_unified(start, stop)


# Logging/Warnings integration

_warnings_showwarning = None


class NullHandler(logging.Handler):
@deprecated('logging.NullHandler')
class NullHandler(logging.NullHandler):

"""
This handler does nothing.
"""This handler does nothing."""

It's intended to be used to avoid the "No handlers could be found for
logger XXX" one-off warning. This is important for library code, which
may contain code to log events. If a user of the library does not configure
logging, the one-off warning might be produced; to avoid this, the library
developer simply needs to instantiate a NullHandler and add it to the
top-level logger of the library module or package.
pass

Copied from C{logging.NullHandler} which was introduced in Python 2.7.

@see: http://bugs.python.org/issue4384
"""

def handle(self, record):
"""Dummy handling."""
pass

def emit(self, record):
"""Dummy handling."""
pass

def createLock(self):
"""Dummy handling."""
self.lock = None


def _showwarning(message, category, filename, lineno, file=None, line=None):
@deprecated('logging._showwarning')
def _showwarning(*args, **kwargs):
"""
Implementation of showwarnings which redirects to logging.

It will first check to see if the file parameter is None. If a file is
specified, it will delegate to the original warnings implementation of
showwarning. Otherwise, it will call warnings.formatwarning and will log
the resulting string to a warnings logger named "py.warnings" with level
logging.WARNING.

Copied from C{logging._showwarning} which was introduced in Python 2.7.

@see: http://bugs.python.org/issue4384
DEPRECATED (Python 2.6 backport).
Use logging._showwarning instead.
"""
if file is not None:
if _warnings_showwarning is not None:
_warnings_showwarning(message, category, filename, lineno, file, line)
else:
s = warnings.formatwarning(message, category, filename, lineno, line)
logger = logging.getLogger("py.warnings")
if not logger.handlers:
logger.addHandler(NullHandler())
logger.warning("%s", s)
logging._showwarning(*args, **kwargs)


@deprecated('logging.captureWarnings')
def captureWarnings(capture):
"""
Capture warnings into logging.

If capture is true, redirect all warnings to the logging package.
If capture is False, ensure that warnings are not redirected to logging
but to their original destinations.
DEPRECATED (Python 2.6 backport).
Use logging.captureWarnings instead.
"""
logging.captureWarnings(capture)

Copied from C{logging.captureWarnings} which was introduced in Python 2.7.

@see: http://bugs.python.org/issue4384
"""
global _warnings_showwarning
if capture:
if _warnings_showwarning is None:
_warnings_showwarning = warnings.showwarning
warnings.showwarning = _showwarning
else:
if _warnings_showwarning is not None:
warnings.showwarning = _warnings_showwarning
_warnings_showwarning = None
_warnings_showwarning = logging._warnings_showwarning
8 changes: 2 additions & 6 deletions pywikibot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
used.
"""
#
# (C) Pywikibot team, 2008-2017
# (C) Pywikibot team, 2008-2018
#
# Distributed under the terms of the MIT license.
#
Expand Down Expand Up @@ -80,7 +80,6 @@

import pywikibot

from pywikibot import backports
from pywikibot import config
from pywikibot import daemonize
from pywikibot import i18n
Expand Down Expand Up @@ -253,10 +252,7 @@ def init_handlers(strm=None):

# If there are command line warnings options, do not override them
if not sys.warnoptions:
if hasattr(logging, 'captureWarnings'):
logging.captureWarnings(True) # introduced in Python >= 2.7
else:
backports.captureWarnings(True)
logging.captureWarnings(True)

if config.debug_log or 'deprecation' in config.log:
warnings.filterwarnings("always")
Expand Down
4 changes: 2 additions & 2 deletions pywikibot/diff.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Diff module."""
#
# (C) Pywikibot team, 2014-2015
# (C) Pywikibot team, 2014-2018
#
# Distributed under the terms of the MIT license.
#
Expand All @@ -15,6 +15,7 @@
import sys

from collections import Sequence
from difflib import _format_range_unified as format_range_unified
if sys.version_info[0] > 2:
from itertools import zip_longest
else:
Expand All @@ -23,7 +24,6 @@
import pywikibot
from pywikibot.tools import chars

from pywikibot.backports import format_range_unified # introduced in 2.7.2
from pywikibot.tools import deprecated_args
from pywikibot.tools.formatter import color_format

Expand Down
Loading