コード例 #1
0
    def __init__(self, password=None, sysop=False, site=None, user=None):
        """
        Initializer.

        All parameters default to defaults in user-config.

        @param site: Site object to log into
        @type site: BaseSite
        @param user: consumer key
        @type user: basestring
        @param password: consumer secret
        @type password: basestring
        @param sysop: login as sysop account.
            The sysop username is loaded from config.sysopnames.
        @type sysop: bool

        @raises NoUsername: No username is configured for the requested site.
        @raises OAuthImpossible: mwoauth isn't installed
        """
        if isinstance(mwoauth, ImportError):
            raise OAuthImpossible('mwoauth is not installed: %s.' % mwoauth)
        assert password is not None and user is not None
        assert sysop is False
        super(OauthLoginManager, self).__init__(None, False, site, None)
        if self.password:
            pywikibot.warn('Password exists in password file for %s:%s.'
                           'Password is unnecessary and should be removed '
                           'when OAuth enabled.' % (self.site, self.username))
        self._consumer_token = (user, password)
        self._access_token = None
コード例 #2
0
    def make_stats_object_arguments_for_page(self, page):
        all_templates_with_params = page.templatesWithParams()

        if self.template_name not in [template.title(with_ns=False) for (template, _) in all_templates_with_params]:
            msg = (
                "No start template '%s' found."
                "The likely explanation is that inteGraality was invoked from a page that transcludes the page with the template. "
                "Please invoke inteGraality directly from the page with the template." % self.template_name
            )
            raise NoStartTemplateException(msg)

        if self.end_template_name not in [template.title(with_ns=False) for (template, _) in all_templates_with_params]:
            raise NoEndTemplateException("No end template '%s' provided" % self.end_template_name)

        start_templates_with_params = [
            (template, params) for (template, params) in all_templates_with_params if
            template.title(with_ns=False) == self.template_name
        ]

        if len(start_templates_with_params) > 1:
            pywikibot.warn("More than one template on the page %s" % page.title())

        (template, params) = start_templates_with_params[0]
        parsed_config = self.parse_config_from_params(params)
        config = self.parse_config(parsed_config)
        key = self.make_cache_key(page.title())
        self.cache.set_cache_value(key, config)
        return config
コード例 #3
0
ファイル: login.py プロジェクト: KaiCode2/pywikibot-core
    def __init__(self, password=None, sysop=False, site=None, user=None):
        """
        Constructor.

        All parameters default to defaults in user-config.

        @param site: Site object to log into
        @type site: BaseSite
        @param user: consumer key
        @type user: basestring
        @param password: consumer secret
        @type password: basestring
        @param sysop: login as sysop account.
            The sysop username is loaded from config.sysopnames.
        @type sysop: bool

        @raises NoUsername: No username is configured for the requested site.
        @raises OAuthImpossible: mwoauth isn't installed
        """
        if isinstance(mwoauth, ImportError):
            raise OAuthImpossible('mwoauth is not installed: %s.' % mwoauth)
        assert password is not None and user is not None
        assert sysop is False
        super(OauthLoginManager, self).__init__(None, False, site, None)
        if self.password:
            pywikibot.warn('Password exists in password file for %s:%s.'
                           'Password is unnecessary and should be removed '
                           'when OAuth enabled.' % (self.site, self.username))
        self._consumer_token = (user, password)
        self._access_token = None
コード例 #4
0
    def make_stats_object_for_page(self, page):
        all_templates_with_params = page.templatesWithParams()

        if self.end_template_name not in [
                template.title(with_ns=False)
                for (template, _) in all_templates_with_params
        ]:
            raise NoEndTemplateException("No end template '%s' provided" %
                                         self.end_template_name)

        start_templates_with_params = [
            (template, params)
            for (template, params) in all_templates_with_params
            if template.title(with_ns=False) == self.template_name
        ]
        if len(start_templates_with_params) > 1:
            pywikibot.warn("More than one template on the page %s" %
                           page.title())

        (template, params) = start_templates_with_params[0]
        parsed_config = self.parse_config_from_params(params)
        config = self.parse_config(parsed_config)
        try:
            return PropertyStatistics(**config)
        except TypeError:
            raise ConfigException("The template parameters are incorrect.")
コード例 #5
0
ファイル: login.py プロジェクト: xqt/pywikibot
    def __init__(self,
                 password: Optional[str] = None,
                 site=None,
                 user: Optional[str] = None):
        """
        Initializer.

        All parameters default to defaults in user-config.

        @param site: Site object to log into
        @type site: BaseSite
        @param user: consumer key
        @param password: consumer secret

        @raises pywikibot.exceptions.NoUsernameError: No username is configured
            for the requested site.
        @raises ImportError: mwoauth isn't installed
        """
        if isinstance(mwoauth, ImportError):
            raise ImportError('mwoauth is not installed: {}.'.format(mwoauth))
        assert password is not None and user is not None
        super().__init__(password=None, site=site, user=None)
        if self.password:
            pywikibot.warn(
                'Password exists in password file for {login.site}:'
                '{login.username}. Password is unnecessary and '
                'should be removed if OAuth enabled.'.format(login=self))
        self._consumer_token = (user, password)
        self._access_token = None
コード例 #6
0
    def treat(self, page: pywikibot.Page) -> None:
        change = page._rcinfo
        if not (change["type"] == "edit" or change["type"] == "new"):
            return

        username = change["user"]
        greetedUserInfo = self.redisDb.getGreetedUserInfo(username)
        if greetedUserInfo:
            title = change["title"]
            newRevision = change["revision"]["new"]
            if change["timestamp"] < float(greetedUserInfo["time"]):
                # event before greeting
                pywikibot.warn(
                    f"Received event before greeting for user '{username}', rev id {newRevision}"
                )
                return
            if page.namespace() == 3 and title[title.index(":") +
                                               1:] == username:
                # user edited his own talk page for the first time after being greeted
                self.redisDb.removeGreetedUser(username)
                self.notifyGreeter(greetedUserInfo["greeter"], username,
                                   newRevision, True)
            elif greetedUserInfo["normalEditSeen"] == "0":
                # user edited somewhere else for the first time after being greeted
                greetedUserInfo["normalEditSeen"] = "1"
                self.redisDb.setGreetedUserInfo(username, greetedUserInfo)
                self.notifyGreeter(greetedUserInfo["greeter"], username,
                                   newRevision, False)
コード例 #7
0
    def make_stats_object_arguments_for_page(self, page):
        all_templates_with_params = page.templatesWithParams()

        if self.end_template_name not in [
                template.title(with_ns=False)
                for (template, _) in all_templates_with_params
        ]:
            raise NoEndTemplateException("No end template '%s' provided" %
                                         self.end_template_name)

        start_templates_with_params = [
            (template, params)
            for (template, params) in all_templates_with_params
            if template.title(with_ns=False) == self.template_name
        ]

        if not start_templates_with_params:
            msg = (
                "No start template '%s' found, which is an impossible situation. "
                "This is potentially an upstream pywikibot issue." %
                self.template_name)
            raise ConfigException(msg)

        if len(start_templates_with_params) > 1:
            pywikibot.warn("More than one template on the page %s" %
                           page.title())

        (template, params) = start_templates_with_params[0]
        parsed_config = self.parse_config_from_params(params)
        config = self.parse_config(parsed_config)
        key = self.make_cache_key(page.title())
        self.cache.set_cache_value(key, config)
        return config
コード例 #8
0
ファイル: replace.py プロジェクト: runt18/pywikibot-core
 def doReplacements(self, original_text, page=None):
     """Apply replacements to the given text and page."""
     if page is None:
         pywikibot.warn(
             'You must pass the target page as the "page" parameter to '
             'doReplacements().', DeprecationWarning, stacklevel=2)
     with warnings.catch_warnings():
         warnings.simplefilter('ignore', DeprecationWarning)
         new_text = self.apply_replacements(original_text, set(), page=page)
     return new_text
コード例 #9
0
ファイル: replace.py プロジェクト: wikimedia-kr/pywikibot
 def doReplacements(self, original_text, page=None):
     """Apply replacements to the given text and page."""
     if page is None:
         pywikibot.warn(
             'You must pass the target page as the "page" parameter to '
             'doReplacements().', DeprecationWarning, stacklevel=2)
     with warnings.catch_warnings():
         warnings.simplefilter('ignore', DeprecationWarning)
         new_text = self.apply_replacements(original_text, set(), page=page)
     return new_text
コード例 #10
0
    def apply_replacements(self, original_text, applied, page=None):
        """
        Apply all replacements to the given text.

        @rtype: unicode, set
        """
        def get_exceptions(exceptions):
            return exceptions.get('inside-tags', []) + exceptions.get(
                'inside', [])

        if page is None:
            pywikibot.warn(
                'You must pass the target page as the "page" parameter to '
                'apply_replacements().',
                DeprecationWarning,
                stacklevel=2)
        new_text = original_text
        exceptions = get_exceptions(self.exceptions)
        skipped_containers = set()
        for replacement in self.replacements:
            if self.sleep is not None:
                time.sleep(self.sleep)
            if (replacement.container
                    and replacement.container.name in skipped_containers):
                continue
            elif page is not None and self.isTitleExcepted(
                    page.title(), replacement.exceptions):
                if replacement.container:
                    pywikibot.output(
                        'Skipping fix "{0}" on {1} because the title is on the '
                        'exceptions list.'.format(replacement.container.name,
                                                  page.title(asLink=True)))
                    skipped_containers.add(replacement.container.name)
                else:
                    pywikibot.output(
                        'Skipping unnamed replacement ({0}) on {1} because the '
                        'title is on the exceptions list.'.format(
                            replacement.description, page.title(asLink=True)))
                continue
            old_text = new_text
            new_text = textlib.replaceExcept(
                new_text,
                replacement.old_regex,
                replacement.new,
                exceptions + get_exceptions(replacement.exceptions or {}),
                allowoverlap=self.allowoverlap,
                site=self.site)
            if old_text != new_text:
                applied.add(replacement)

        return new_text
コード例 #11
0
    def interface(self, code):
        """
        Return interface to use for code.

        :rtype: str or subclass of BaseSite
        """
        if code in self.interwiki_removals:
            if code in self.codes:
                pywikibot.warn('Interwiki removal {} is in {} codes'
                               .format(code, self))
            if code in self.closed_wikis:
                return 'ClosedSite'
            if code in self.removed_wikis:
                return 'RemovedSite'

        return config.site_interface
コード例 #12
0
    def apply_replacements(self, original_text, applied, page=None):
        """
        Apply all replacements to the given text.

        @rtype: unicode, set
        """
        if page is None:
            pywikibot.warn(
                'You must pass the target page as the "page" parameter to ' "apply_replacements().",
                DeprecationWarning,
                stacklevel=2,
            )
        new_text = original_text
        exceptions = _get_text_exceptions(self.exceptions)
        skipped_containers = set()
        for replacement in self.replacements:
            if self.sleep is not None:
                time.sleep(self.sleep)
            if replacement.container and replacement.container.name in skipped_containers:
                continue
            elif page is not None and self.isTitleExcepted(page.title(), replacement.exceptions):
                if replacement.container:
                    pywikibot.output(
                        'Skipping fix "{0}" on {1} because the title is on the '
                        "exceptions list.".format(replacement.container.name, page.title(asLink=True))
                    )
                    skipped_containers.add(replacement.container.name)
                else:
                    pywikibot.output(
                        "Skipping unnamed replacement ({0}) on {1} because the "
                        "title is on the exceptions list.".format(replacement.description, page.title(asLink=True))
                    )
                continue
            old_text = new_text
            new_text = textlib.replaceExcept(
                new_text,
                replacement.old_regex,
                replacement.new,
                exceptions + replacement.get_inside_exceptions(),
                allowoverlap=self.allowoverlap,
                site=self.site,
            )
            if old_text != new_text:
                applied.add(replacement)

        return new_text