Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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 :py:obj:`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')
Exemplo n.º 7
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')