Exemplo n.º 1
0
"""Library module representing MediaWiki sites (wikis)."""
#
# (C) Pywikibot team, 2021
#
# Distributed under the terms of the MIT license.
#
from pywikibot.site._apisite import APISite
from pywikibot.site._basesite import BaseSite
from pywikibot.site._datasite import DataSite
from pywikibot.site._namespace import Namespace, NamespacesDict
from pywikibot.site._obsoletesites import ClosedSite, RemovedSite
from pywikibot.site._siteinfo import Siteinfo
from pywikibot.site._tokenwallet import TokenWallet
from pywikibot.tools import ModuleDeprecationWrapper


__all__ = ('APISite', 'BaseSite', 'ClosedSite', 'DataSite', 'RemovedSite',
           'Namespace', 'NamespacesDict', 'PageInUse', 'Siteinfo',
           'TokenWallet')

_logger = 'wiki.site'

wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr(
    'PageInUse',
    replacement_name='pywikibot.exceptions.PageInUseError',
    since='20210423',
    future_warning=True)
Exemplo n.º 2
0
    'InconsistentTitleReceived': 'InconsistentTitleError',
    'UnknownSite': 'UnknownSiteError',
    'UnknownFamily': 'UnknownFamilyError',
    'UnknownExtension': 'UnknownExtensionError',
    'IsRedirectPage': 'IsRedirectPageError',
    'IsNotRedirectPage': 'IsNotRedirectPageError',
    'CircularRedirect': 'CircularRedirectError',
    'InterwikiRedirectPage': 'InterwikiRedirectPageError',
    'InvalidTitle': 'InvalidTitleError',
    'LockedPage': 'LockedPageError',
    'LockedNoPage': 'LockedNoPageError',
    'CascadeLockedPage': 'CascadeLockedPageError',
    'EditConflict': 'EditConflictError',
    'PageDeletedConflict': 'PageDeletedConflictError',
    'PageCreatedConflict': 'PageCreatedConflictError',
    'ArticleExistsConflict': 'ArticleExistsConflictError',
    'AutoblockUser': '******',
    'NoWikibaseEntity': 'NoWikibaseEntityError',
    'CoordinateGlobeUnknownException': 'CoordinateGlobeUnknownError',
    'EntityTypeUnknownException': 'EntityTypeUnknownError',
}

wrapper = ModuleDeprecationWrapper(__name__)
module = sys.modules[__name__]

for old_name, new_name in DEPRECATED_EXCEPTIONS.items():
    setattr(module, old_name, getattr(module, new_name))
    wrapper.add_deprecated_attr(old_name,
                                replacement_name=new_name,
                                since='20210423')
Exemplo n.º 3
0
            if 'ver' in info:
                data[name] = info
            else:
                # Remove the entry from paths, so it isn't processed below
                del paths[info['path']]
        else:
            data[name] = info

    # Remove any pywikibot sub-modules which were loaded as a package.
    # e.g. 'wikipedia_family.py' is loaded as 'wikipedia'
    _program_dir = _get_program_dir()
    dir_parts = pathlib.Path(_program_dir).parts
    length = len(dir_parts)
    for path, name in paths.items():
        lib_parts = path.parts
        if dir_parts != lib_parts[:length]:
            continue
        if lib_parts[length] != '.tox':
            del data[name]

    return data


ParseError = VersionParseError

wrapper = ModuleDeprecationWrapper(__name__)
wrapper.add_deprecated_attr(
    'ParseError',
    replacement_name='pywikibot.exceptions.VersionParseError',
    since='20210423')
Exemplo n.º 4
0
            text = page.get()
        except pywikibot.NoPage:
            return
        except pywikibot.IsRedirectPage:
            return
        pywikibot.output(str((entry[0], name)))

    def on_dccmsg(self, c, e):
        """Ignore DCC message."""
        pass

    def on_dccchat(self, c, e):
        """Ignore DCC chat."""
        pass

    def do_command(self, e, cmd):
        """Ignore command request."""
        pass

    def on_quit(self, e, cmd):
        """Ignore quit request."""
        pass


wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr(
    'IRCBot',
    replacement_name=('irc.bot.SingleServerIRCBot from irc library '
                      'or EventStreams'),
    since='20190509')
        """Return a page object from page number."""
        try:
            return self._page_from_numbers[page_number]
        except KeyError:
            raise KeyError('Invalid page number: %s.' % page_number)

    @check_if_cached
    def pages(self) -> list:
        """Return the list of pages in Index, sorted by page number.

        @return: list of pages
        """
        return [
            self._page_from_numbers[i] for i in range(1, self.num_pages + 1)
        ]

    @check_if_cached
    def get_number(self, page):
        """Return a page number from page object."""
        try:
            return self._numbers_from_page[page]
        except KeyError:
            raise KeyError('Invalid page: {}.'.format(page))


wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr('Soup',
                             _bs4_soup,
                             replacement_name='_bs4_soup',
                             since='20181128')
Exemplo n.º 6
0
# -*- coding: utf-8  -*-
"""
WARNING: THIS MODULE EXISTS SOLELY TO PROVIDE BACKWARDS-COMPATIBILITY.

Do not use in new scripts; use the source to find the appropriate
function/method instead.

"""
#
# (C) Pywikibot team, 2008
#
# Distributed under the terms of the MIT license.
#
from __future__ import unicode_literals

__version__ = '$Id: 4ff7e781fce9afab97d89a91b3f03e7d82b904a4 $'


from pywikibot import User
from pywikibot.tools import ModuleDeprecationWrapper

__all__ = ('User',)

wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr('User', replacement_name='pywikibot.User')
Exemplo n.º 7
0
            text = page.get()
        except pywikibot.NoPage:
            return
        except pywikibot.IsRedirectPage:
            return
        pywikibot.output(str((entry[0], name)))

    def on_dccmsg(self, c, e):
        """Ignore DCC message."""
        pass

    def on_dccchat(self, c, e):
        """Ignore DCC chat."""
        pass

    def do_command(self, e, cmd):
        """Ignore command request."""
        pass

    def on_quit(self, e, cmd):
        """Ignore quit request."""
        pass


wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr(
    'IRCBot',
    replacement_name=('irc.bot.SingleServerIRCBot from irc library '
                      'or EventStreams'),
    since='20190509')
Exemplo n.º 8
0
    def unlink(self, target_page):
        """Unlink all links linking to the target page."""
        text = self.current_page.text
        while True:
            unlink_callback = self._create_callback()
            try:
                text = replace_links(text, unlink_callback, target_page.site)
            except EditReplacementError:
                new_text = TextEditor().edit(
                    unlink_callback.current_text,
                    jumpIndex=unlink_callback.current_range[0])
                # if user didn't press Cancel
                if new_text:
                    text = new_text
                else:
                    text = unlink_callback.current_text
            else:
                break

        self.put_current(text)


EditReplacement = EditReplacementError

wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr('EditReplacement',
                             replacement_name='EditReplacementError',
                             since='20210423',
                             future_warning=True)
Exemplo n.º 9
0
# -*- coding: utf-8 -*-
"""
WARNING: THIS MODULE EXISTS SOLELY TO PROVIDE BACKWARDS-COMPATIBILITY.

Do not use in new scripts; use the source to find the appropriate
function/method instead.

"""
#
# (C) Pywikibot team, 2008-2018
#
# Distributed under the terms of the MIT license.
#
from __future__ import absolute_import, division, unicode_literals

from pywikibot.page import User
from pywikibot.tools import ModuleDeprecationWrapper

__all__ = ('User',)

wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr('User',
                             replacement_name='pywikibot.User',
                             since='20141209')
Exemplo n.º 10
0

class LoggingFormatter(logging.Formatter):
    """Format LogRecords for output to file."""
    def format(self, record):
        """Strip trailing newlines before outputting text to file."""
        # Warnings captured from the warnings system are not processed by
        # logoutput(), so the 'context' variables are missing.
        if record.name == 'py.warnings' \
           and 'caller_file' not in record.__dict__:
            assert len(record.args) == 1, \
                'Arguments for record is not correctly set'
            msg = record.args[0]

            record.__dict__['caller_file'] = record.pathname
            record.__dict__['caller_name'] = record.module
            record.__dict__['caller_line'] = record.lineno

            record.args = (msg, )

        return super().format(record).rstrip()


wrapper = ModuleDeprecationWrapper(__name__)
wrapper.add_deprecated_attr(
    'RotatingFileHandler',
    _RotatingFileHandler,
    replacement_name=('logging.handlers.RotatingFileHandler '
                      'with your own namer'),
    since='6.5.0')
Exemplo n.º 11
0
    Family that automatically loads the site configuration.

    :param name: Name for the family
    :param url: API endpoint URL of the wiki
    :return: Generated family class
    :rtype: SingleSiteFamily
    """
    url = urlparse.urlparse(url)
    domain = url.netloc

    def protocol(self, code):
        """Return the protocol of the URL."""
        return self.url.scheme

    def scriptpath(self, code):
        """Extract the script path from the URL."""
        if self.url.path.endswith('/api.php'):
            return self.url.path[0:-8]

        # AutoFamily refers to the variable set below, not the function
        # but the reference must be given here
        return super(AutoFamily, self).scriptpath(code)

    AutoFamily = type('AutoFamily', (SingleSiteFamily,), locals())
    return AutoFamily()


wrapper = ModuleDeprecationWrapper(__name__)
wrapper.add_deprecated_attr('WikiaFamily', replacement=FandomFamily,
                            since='20190420')
Exemplo n.º 12
0
# -*- coding: utf-8 -*-
"""
WARNING: THIS MODULE EXISTS SOLELY TO PROVIDE COMPAT BACKWARDS-COMPATIBILITY.

IT IS DEPRECATED. DO NOT USE IT.

Do not use this module anymore; use pywikibot.User instead.
"""
#
# (C) Pywikibot team, 2008-2020
#
# Distributed under the terms of the MIT license.
#
from __future__ import absolute_import, division, unicode_literals

from pywikibot.page import User
from pywikibot.tools import ModuleDeprecationWrapper

__all__ = ('User', )

wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr('User',
                             replacement_name='pywikibot.User',
                             since='20141209',
                             future_warning=True)
Exemplo n.º 13
0
            result = encoding
        return result

    @deprecated('the `text` property', since='20201011', future_warning=True)
    def decode(self, encoding, errors='strict') -> str:  # pragma: no cover
        """Return the decoded response."""
        return self.content.decode(encoding,
                                   errors) if not self.exception else None

    @property
    def text(self) -> str:
        """Return the response decoded by the detected encoding."""
        return self.content.decode(self.encoding)

    @deprecated('the `text` property', since='20201011', future_warning=True)
    def __str__(self) -> str:  # pragma: no cover
        """Return the response decoded by the detected encoding."""
        return self.text

    @deprecated(since='20201011', future_warning=True)
    def __bytes__(self) -> Optional[bytes]:  # pragma: no cover
        """Return the undecoded response."""
        return self.content


wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr('HttpRequest',
                             replacement_name='',
                             since='20201226',
                             future_warning=True)
Exemplo n.º 14
0
    return wrapper


class PywikibotCookieJar(cookiejar.LWPCookieJar):
    """DEPRECATED. CookieJar which checks file permissions."""
    @deprecated(since='20181007', future_warning=True)
    def __init__(self, *args, **kwargs):
        """Initialize the class."""
        super().__init__(*args, **kwargs)

    @_mode_check_decorator
    def load(self, **kwargs):
        """Load cookies from file."""
        super().load()

    @_mode_check_decorator
    def save(self, **kwargs):
        """Save cookies to file."""
        super().save()


wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr('PywikibotCookieJar',
                             replacement_name='',
                             since='20181007',
                             future_warning=True)
wrapper._add_deprecated_attr('mode_check_decorator',
                             _mode_check_decorator,
                             since='20200724',
                             future_warning=True)
        return getattr(target_stream, '_hConsole', None) is not None

    def encounter_color(self, color, target_stream):
        """Set the new color."""
        fg, bg = self.divide_color(color)
        windows_color = windowsColors[fg]
        # Merge foreground/backgroung color if needed.
        if bg is not None:
            windows_color = windowsColors[bg] << 4 | windows_color
        ctypes.windll.kernel32.SetConsoleTextAttribute(
            target_stream._hConsole, windows_color)

    def _raw_input(self):
        data = self.stdin.readline()
        # data is in both Python versions str but '\x1a' is unicode in Python 2
        # so explicitly convert into str as it otherwise tries to decode data
        if str('\x1a') in data:
            raise EOFError()
        return data.strip()


Win32CtypesUI = Win32UI

wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr('Win32CtypesUI',
                             replacement_name='Win32UI',
                             since='20190217')
wrapper._add_deprecated_attr('Win32BaseUI',
                             replacement_name='Win32UI',
                             since='20190217')
Exemplo n.º 16
0
    def unlink(self, target_page):
        """Unlink all links linking to the target page."""
        text = self.current_page.text
        while True:
            unlink_callback = self._create_callback()
            try:
                text = replace_links(text, unlink_callback, target_page.site)
            except EditReplacementError:
                new_text = TextEditor().edit(
                    unlink_callback.current_text,
                    jumpIndex=unlink_callback.current_range[0])
                # if user didn't press Cancel
                if new_text:
                    text = new_text
                else:
                    text = unlink_callback.current_text
            else:
                break

        self.put_current(text)


EditReplacement = EditReplacementError

wrapper = ModuleDeprecationWrapper(__name__)
wrapper.add_deprecated_attr(
    'EditReplacement',
    replacement_name='EditReplacementError',
    since='20210423')
Exemplo n.º 17
0
        for page, referrers in self.subject.found_in.items():
            for refPage in referrers:
                self.addDirectedEdge(page, refPage)
        self.saveGraphFile()


def getFilename(page, extension: Optional[str] = None) -> str:
    """
    Create a filename that is unique for the page.

    :param page: page used to create the new filename
    :type page: pywikibot.page.Page
    :param extension: file extension
    :return: filename of <family>-<lang>-<page>.<ext>
    """
    filename = '-'.join((page.site.family.name,
                         page.site.code,
                         page.title(as_filename=True)))
    if extension:
        filename += '.{}'.format(extension)
    return filename


GraphImpossible = ImportError

wrapper = ModuleDeprecationWrapper(__name__)
wrapper.add_deprecated_attr(
    'GraphImpossible',
    replacement_name='ImportError',
    since='20210423')
Exemplo n.º 18
0
Do not use this module anymore; use pywikibot.Category class
or Page.change_category method instead.
"""
#
# (C) Pywikibot team, 2008-2020
#
# Distributed under the terms of the MIT license.
#
from __future__ import absolute_import, division, unicode_literals

from pywikibot import Category
from pywikibot.tools import ModuleDeprecationWrapper


def change_category(article, oldCat, newCat, comment=None, sortKey=None,
                    inPlace=True):
    """Change the category of the article."""
    return article.change_category(oldCat, newCat, comment, sortKey, inPlace)


__all__ = ('Category', 'change_category',)

wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr('Category',
                             replacement_name='pywikibot.Category',
                             since='20141209', future_warning=True)
wrapper._add_deprecated_attr('change_category',
                             replacement_name='Page.change_category',
                             since='20141209', future_warning=True)
Exemplo n.º 19
0
# -*- coding: utf-8  -*-
"""
WARNING: THIS MODULE EXISTS SOLELY TO PROVIDE BACKWARDS-COMPATIBILITY.

Do not use in new scripts; use the source to find the appropriate
function/method instead.

"""
#
# (C) Pywikibot team, 2008
#
# Distributed under the terms of the MIT license.
#
from __future__ import absolute_import, unicode_literals

__version__ = '$Id: 07dbaa5dfa09499fc356eda82f6201e40c5657be $'

from pywikibot.page import User
from pywikibot.tools import ModuleDeprecationWrapper

__all__ = ('User', )

wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr('User', replacement_name='pywikibot.User')
Exemplo n.º 20
0
        bot = CategoryListifyRobot(
            oldCatTitle,
            newCatTitle,
            editSummary,
            overwrite,
            showImages,
            subCats=True,
            talkPages=talkPages,
            recurse=recurse,
        )

    if bot:
        pywikibot.Site().login()

        try:
            bot.run()
        except pywikibot.Error:
            pywikibot.error("Fatal error:", exc_info=True)
        finally:
            if catDB:
                catDB.dump()
    else:
        pywikibot.showHelp()


if __name__ == "__main__":
    main()

wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr("AddCategory", CategoryAddBot)
Exemplo n.º 21
0
WARNING: THIS MODULE EXISTS SOLELY TO PROVIDE BACKWARDS-COMPATIBILITY.

Do not use in new scripts; use the source to find the appropriate
function/method instead.

"""
#
# (C) Pywikibot team, 2008
#
# Distributed under the terms of the MIT license.
#
from __future__ import unicode_literals

__version__ = '$Id: fe2aa5562be4d989a419c6e01fe86a26bbf3d4b9 $'


from pywikibot import Category
from pywikibot.tools import ModuleDeprecationWrapper


def change_category(article, oldCat, newCat, comment=None, sortKey=None,
                    inPlace=True):
    """Change the category of the article."""
    return article.change_category(oldCat, newCat, comment, sortKey, inPlace)

__all__ = ('Category', 'change_category',)

wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr('Category', replacement_name='pywikibot.Category')
wrapper._add_deprecated_attr('change_category', replacement_name='Page.change_category')
Exemplo n.º 22
0
    r'(([\dA-F]{1,4}(\4|:\b|$)|\2){2}|'
    r'(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\Z',
    re.IGNORECASE,
    'page.ip_regexp',
    'tools.is_IP',
    since='20150212')


def is_IP(IP):
    """
    Verify the IP address provided is valid.

    No logging is performed. Use ip_address instead to catch errors.

    @param IP: IP address
    @type IP: str
    @rtype: bool
    """
    try:
        ip_address(IP)
        return True
    except ValueError:
        return False


wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr('is_IP',
                             replacement_name='tools.is_IP',
                             future_warning=True,
                             since='20200120')
Exemplo n.º 23
0
            for refPage in referrers:
                self.addDirectedEdge(page, refPage)
        self.saveGraphFile()


def getFilename(page, extension: Optional[str] = None) -> str:
    """
    Create a filename that is unique for the page.

    @param page: page used to create the new filename
    @type page: pywikibot.page.Page
    @param extension: file extension
    @return: filename of <family>-<lang>-<page>.<ext>
    """
    filename = '-'.join((page.site.family.name,
                         page.site.code,
                         page.title(as_filename=True)))
    if extension:
        filename += '.{}'.format(extension)
    return filename


GraphImpossible = ImportError

wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr(
    'GraphImpossible',
    replacement_name='ImportError',
    since='20210423',
    future_warning=True)
Exemplo n.º 24
0
        self.graph.add_node(pydot.Node('start', shape='point'))
        self.graph.add_edge(pydot.Edge('start', firstLabel))
        for page, referrers in self.subject.found_in.items():
            for refPage in referrers:
                self.addDirectedEdge(page, refPage)
        self.saveGraphFile()


def getFilename(page, extension: Optional[str] = None) -> str:
    """
    Create a filename that is unique for the page.

    @param page: page used to create the new filename
    @type page: pywikibot.page.Page
    @param extension: file extension
    @return: filename of <family>-<lang>-<page>.<ext>
    """
    filename = '-'.join(
        (page.site.family.name, page.site.code, page.title(as_filename=True)))
    if extension:
        filename += '.{}'.format(extension)
    return filename


wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr(
    'pydotfound',
    replacement_name='"not isinstance(pydot, ImportError)"',
    since='2015125',
    future_warning=True)
Exemplo n.º 25
0
#
# Distributed under the terms of the MIT license.
#
from __future__ import unicode_literals

__version__ = '$Id: fe2aa5562be4d989a419c6e01fe86a26bbf3d4b9 $'

from pywikibot import Category
from pywikibot.tools import ModuleDeprecationWrapper


def change_category(article,
                    oldCat,
                    newCat,
                    comment=None,
                    sortKey=None,
                    inPlace=True):
    """Change the category of the article."""
    return article.change_category(oldCat, newCat, comment, sortKey, inPlace)


__all__ = (
    'Category',
    'change_category',
)

wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr('Category', replacement_name='pywikibot.Category')
wrapper._add_deprecated_attr('change_category',
                             replacement_name='Page.change_category')
Exemplo n.º 26
0
    try:
        BeautifulSoup('', 'lxml')
    except FeatureNotFound:
        _bs4_soup = partial(BeautifulSoup, features='html.parser')
    else:
        _bs4_soup = partial(BeautifulSoup, features='lxml')

import pywikibot
from pywikibot.comms import http
from pywikibot.data.api import Request
from pywikibot.exceptions import OtherPageSaveError
from pywikibot.tools import ModuleDeprecationWrapper

_logger = 'proofreadpage'

wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr('Soup', _bs4_soup, replacement_name='_bs4_soup',
                             since='20181128')


class FullHeader(object):

    """Header of a ProofreadPage object."""

    p_header = re.compile(
        r'<pagequality level="(?P<ql>\d)" user="******" />'
        r'(?P<has_div><div class="pagetext">)?(?P<header>.*)',
        re.DOTALL)

    TEMPLATE_V1 = ('<pagequality level="{0.ql}" user="******" />'
                   '<div class="pagetext">{0.header}\n\n\n')