Exemplo n.º 1
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.º 2
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)
        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')
        """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.º 5
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)
Exemplo n.º 6
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.º 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
# -*- 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.º 9
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.º 10
0
        try:
            return self._page_from_numbers[page_number]
        except KeyError:
            raise KeyError('Invalid page number: {}.'.format(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',
                             future_warning=True)
Exemplo n.º 11
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.º 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)
        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()
        if '\x1a' in data:
            raise EOFError()
        return data.strip()


Win32CtypesUI = Win32UI

wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr('Win32CtypesUI',
                             replacement_name='Win32UI',
                             since='20190217',
                             future_warning=True)
wrapper._add_deprecated_attr('Win32BaseUI',
                             replacement_name='Win32UI',
                             since='20190217',
                             future_warning=True)
Exemplo n.º 14
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.º 15
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.º 16
0
          password: bool = False,
          fallback_prompt: Optional[str] = None) -> str:
    """
    Ask the user a question, return the user's answer.

    The prompt message is retrieved via L{twtranslate} and uses the
    config variable 'userinterface_lang'.

    @param twtitle: The TranslateWiki string title, in <package>-<key> format
    @param parameters: The values which will be applied to the translated text
    @param password: Hides the user's input (for password entry)
    @param fallback_prompt: The English prompt if i18n is not available.
    """
    if messages_available():
        code = config.userinterface_lang
        prompt = twtranslate(code, twtitle, parameters)
    elif fallback_prompt:
        prompt = fallback_prompt
    else:
        raise pywikibot.exceptions.TranslationError(
            'Unable to load messages package {} for bundle {}'
            .format(_messages_package_name, twtitle))
    return pywikibot.input(prompt, password)


wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr(
    'TranslationError',
    replacement_name='pywikibot.exceptions.TranslationError',
    since='20210423', future_warning=True)
Exemplo n.º 17
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.º 18
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.º 19
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.º 20
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.º 21
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.º 22
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.º 23
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.º 24
0
        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')
    TEMPLATE_V2 = ('<pagequality level="{0.ql}" user="******" />'
                   '{0.header}')