• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python formatter.color_format函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pywikibot.tools.formatter.color_format函数的典型用法代码示例。如果您正苦于以下问题:Python color_format函数的具体用法?Python color_format怎么用?Python color_format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了color_format函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: cherry_pick

def cherry_pick(oldtext, newtext, n=0, by_letter=False):
    """Propose a list of changes for approval.

    Text with approved changes will be returned.
    n: int, line of context as defined in difflib.get_grouped_opcodes().
    by_letter: if text_a and text_b are single lines, comparison can be done

    """
    FORMAT = "{2}{lightpurple}{0:{1}^50}{default}{2}"

    patch = PatchManager(oldtext, newtext, n=n, by_letter=by_letter)
    pywikibot.output(color_format(FORMAT, "  ALL CHANGES  ", "*", "\n"))

    for hunk in patch.hunks:
        pywikibot.output(hunk.diff_text)
    pywikibot.output(color_format(FORMAT, "  REVIEW CHANGES  ", "*", "\n"))

    text_list = patch.apply()
    pywikibot.output(color_format(FORMAT, "  APPROVED CHANGES  ", "*", "\n"))

    if any(hunk.reviewed == hunk.APPR for hunk in patch.hunks):
        for hunk in patch.hunks:
            if hunk.reviewed == hunk.APPR:
                pywikibot.output(hunk.diff_text)
    else:
        pywikibot.output(color_format(FORMAT, "None.", "", ""))

    text = "".join(text_list)

    return text
开发者ID:PersianWikipedia,项目名称:pywikibot-core,代码行数:30,代码来源:diff.py


示例2: save

 def save(self, text, page, comment, minorEdit=True, botflag=True):
     """Save the text."""
     if text != page.text:
         # Show the title of the page we're working on.
         # Highlight the title in purple.
         pywikibot.output(color_format(
             '\n\n>>> {lightpurple}{0}{default} <<<', page.title()))
         # show what was changed
         pywikibot.showDiff(page.get(), text)
         pywikibot.output(u'Comment: %s' % comment)
         if not self.dry:
             if pywikibot.input_yn(
                     u'Do you want to accept these changes?',
                     default=False, automatic_quit=False):
                 page.text = text
                 try:
                     # Save the page
                     page.save(summary=comment, minorEdit=minorEdit,
                               botflag=botflag)
                 except pywikibot.LockedPage:
                     pywikibot.output(u"Page %s is locked; skipping."
                                      % page.title(asLink=True))
                 except pywikibot.EditConflict:
                     pywikibot.output(
                         u'Skipping %s because of edit conflict'
                         % (page.title()))
                 except pywikibot.SpamfilterError as error:
                     pywikibot.output(
                         u'Cannot change %s because of spam blacklist entry '
                         u'%s' % (page.title(), error.url))
                 else:
                     return True
开发者ID:KaiCode2,项目名称:pywikibot-core,代码行数:32,代码来源:blockreview.py


示例3: __init__

    def __init__(self, *arg):
        pywikibot.output(color_format("{lightgreen}* Initialization of bot{default}"))

        pywikibot.botirc.IRCBot.__init__(self, *arg)

        # init environment with minimal changes (try to do as less as possible)
        # - Lua -
        pywikibot.output("** Redirecting Lua print in order to catch it")
        lua.execute("__print = print")
        lua.execute("print = python.globals().pywikibot.output")
        # It may be useful in debugging to install the 'print' builtin
        # as the 'print' function in lua. To do this:
        # lua.execute('print = python.builtins().print')

        # init constants
        templ = pywikibot.Page(self.site, bot_config["ConfCSSshell"])
        cron = pywikibot.Page(self.site, bot_config["ConfCSScrontab"])

        self.templ = templ.title()
        self.cron = cron.title()
        self.refs = {self.templ: templ, self.cron: cron}
        pywikibot.output("** Pre-loading all relevant page contents")
        for item in self.refs:
            # security; first check if page is protected, reject any data if not
            if os.path.splitext(self.refs[item].title().lower())[1] not in [".css", ".js"]:
                raise ValueError(
                    "%s config %s = %s is not a secure page; "
                    "it should be a css or js userpage which are "
                    "automatically semi-protected." % (self.__class__.__name__, item, self.refs[item])
                )
            self.refs[item].get(force=True)  # load all page contents

        # init background timer
        pywikibot.output("** Starting crontab background timer thread")
        self.on_timer()
开发者ID:KaiCode2,项目名称:pywikibot-core,代码行数:35,代码来源:script_wui.py


示例4: test_marker

 def test_marker(self):
     r"""Test that the \03 marker is only allowed in front of colors."""
     self.assertEqual(formatter.color_format("{0}\03{black}", 42), "42\03{black}")
     # literal before a normal field
     self.assertRaisesRegex(ValueError, r".*\\03", formatter.color_format, "\03{0}{black}", 42)
     # literal before a color field
     self.assertRaisesRegex(ValueError, r".*\\03", formatter.color_format, "{0}\03before{black}", 42)
开发者ID:metakgp,项目名称:batman,代码行数:7,代码来源:tools_formatter_tests.py


示例5: main

def main():
    """Main function."""
    fg_colors = [col for col in colors if col != 'default']
    bg_colors = fg_colors[:]
    n_fg_colors = len(fg_colors)
    fg_colors.insert(3 * int(n_fg_colors / 4), 'default')
    fg_colors.insert(2 * int(n_fg_colors / 4), 'default')
    fg_colors.insert(int(n_fg_colors / 4), 'default')
    fg_colors.insert(0, 'default')

    # Max len of color names for padding.
    max_len_fg_colors = len(max(fg_colors, key=len))
    max_len_bc_color = len(max(bg_colors, key=len))

    for bg_col in bg_colors:
        # Three lines per each backgoung color.
        for fg_col_group in itergroup(fg_colors, n_fg_colors / 4 + 1):
            line = ''
            for fg_col in fg_col_group:
                line += ' '
                line += color_format('{color}{0}{default}',
                                     fg_col.ljust(max_len_fg_colors),
                                     color='%s;%s' % (fg_col, bg_col))

            line = '{0} {1}'.format(bg_col.ljust(max_len_bc_color), line)
            pywikibot.output(line)

        pywikibot.output('')
开发者ID:PersianWikipedia,项目名称:pywikibot-core,代码行数:28,代码来源:colors.py


示例6: useHashGenerator

 def useHashGenerator(self):
     """Use hash generator."""
     # https://toolserver.org/~multichill/nowcommons.php?language=it&page=2&filter=
     lang = self.site.lang
     num_page = 0
     word_to_skip_translated = i18n.translate(self.site, word_to_skip)
     images_processed = list()
     while 1:
         url = ('https://toolserver.org/~multichill/nowcommons.php?'
                'language=%s&page=%s&filter=') % (lang, num_page)
         HTML_text = self.site.getUrl(url, no_hostname=True)
         reg = r'<[Aa] href="(?P<urllocal>.*?)">(?P<imagelocal>.*?)</[Aa]> +?</td><td>\n\s*?'
         reg += r'<[Aa] href="(?P<urlcommons>http[s]?://commons.wikimedia.org/.*?)" \
                >Image:(?P<imagecommons>.*?)</[Aa]> +?</td><td>'
         regex = re.compile(reg, re.UNICODE)
         found_something = False
         change_page = True
         for x in regex.finditer(HTML_text):
             found_something = True
             image_local = x.group('imagelocal')
             image_commons = x.group('imagecommons')
             if image_local in images_processed:
                 continue
             change_page = False
             images_processed.append(image_local)
             # Skip images that have something in the title (useful for it.wiki)
             image_to_skip = False
             for word in word_to_skip_translated:
                 if word.lower() in image_local.lower():
                     image_to_skip = True
             if image_to_skip:
                 continue
             url_local = x.group('urllocal')
             url_commons = x.group('urlcommons')
             pywikibot.output(color_format(
                 '\n\n>>> {lightpurple}{0}{default} <<<',
                 image_local))
             pywikibot.output(u'Local: %s\nCommons: %s\n'
                              % (url_local, url_commons))
             webbrowser.open(url_local, 0, 1)
             webbrowser.open(url_commons, 0, 1)
             if image_local.split('Image:')[1] == image_commons:
                 choice = pywikibot.input_yn(
                     u'The local and the commons images have the same name, '
                     'continue?', default=False, automatic_quit=False)
             else:
                 choice = pywikibot.input_yn(
                     u'Are the two images equal?',
                     default=False, automatic_quit=False)
             if choice:
                 yield [image_local, image_commons]
             else:
                 continue
         # The page is dinamically updated, so we may don't need to change it
         if change_page:
             num_page += 1
         # If no image found means that there aren't anymore, break.
         if not found_something:
             break
开发者ID:AbdealiJK,项目名称:pywikibot-core,代码行数:59,代码来源:nowcommons.py


示例7: main

def main(*args):
    """
    Process command line arguments and invoke bot.

    If args is an empty list, sys.argv is used.

    @param args: command line arguments
    @type args: list of unicode
    """
    featured = False
    gen = None

    # Process global args and prepare generator args parser
    local_args = pywikibot.handle_args(args)
    genFactory = pagegenerators.GeneratorFactory()

    for arg in local_args:
        if arg == '-featured':
            featured = True
        elif genFactory.handleArg(arg):
            pass

    mysite = pywikibot.Site()
    if mysite.sitename == 'wikipedia:nl':
        pywikibot.output(color_format(
            '{lightred}There is consensus on the Dutch Wikipedia that '
            'bots should not be used to fix redirects.{default}'))
        return

    if featured:
        repo = mysite.data_repository()
        if repo:
            dp = pywikibot.ItemPage(repo, featured_articles)
            try:
                ref = pywikibot.Category(mysite, dp.getSitelink(mysite))
            except pywikibot.NoPage:
                pass
            else:
                gen = ref.articles(namespaces=0, content=True)
        if not gen:
            suggest_help(
                unknown_parameters=['-featured'],
                additional_text='Option is not available for this site.')
            return False
    else:
        gen = genFactory.getCombinedGenerator()
        if gen:
            gen = mysite.preloadpages(gen)
    if gen:
        bot = FixingRedirectBot(generator=gen)
        bot.run()
        return True
    else:
        suggest_help(missing_generator=True)
        return False
开发者ID:AbdealiJK,项目名称:pywikibot-core,代码行数:55,代码来源:fixing_redirects.py


示例8: _flush

def _flush(stop=True):
    """
    Drop this process from the throttle log, after pending threads finish.

    Wait for the page-putter to flush its queue. Also drop this process from the
    throttle log. Called automatically at Python exit.
    """
    _logger = "wiki"

    debug('_flush() called', _logger)

    def remaining():
        remainingPages = page_put_queue.qsize()
        if stop:
            # -1 because we added a None element to stop the queue
            remainingPages -= 1

        remainingSeconds = datetime.timedelta(
            seconds=(remainingPages * config.put_throttle))
        return (remainingPages, remainingSeconds)

    if stop:
        # None task element leaves async_manager
        page_put_queue.put((None, [], {}))

    num, sec = remaining()
    if num > 0 and sec.total_seconds() > config.noisysleep:
        output(color_format(
            '{lightblue}Waiting for {num} pages to be put. '
            'Estimated time remaining: {sec}{default}', num=num, sec=sec))

    while _putthread.isAlive() and page_put_queue.qsize() > 0:
        try:
            _putthread.join(1)
        except KeyboardInterrupt:
            if input_yn('There are {0} pages remaining in the queue. '
                        'Estimated time remaining: {1}\nReally exit?'
                        ''.format(*remaining()),
                        default=False, automatic_quit=False):
                return

    # only need one drop() call because all throttles use the same global pid
    try:
        list(_sites.values())[0].throttle.drop()
        log(u"Dropped throttle(s).")
    except IndexError:
        pass
开发者ID:Darkdadaah,项目名称:pywikibot-core,代码行数:47,代码来源:__init__.py


示例9: stopme

def stopme():
    """
    Drop this process from the throttle log, after pending threads finish.

    Can be called manually if desired, but if not, will be called automatically
    at Python exit.
    """
    global stopped
    _logger = "wiki"

    if not stopped:
        debug(u"stopme() called", _logger)

        def remaining():
            remainingPages = page_put_queue.qsize() - 1
            # -1 because we added a None element to stop the queue

            remainingSeconds = datetime.timedelta(
                seconds=(remainingPages * config.put_throttle))
            return (remainingPages, remainingSeconds)

        page_put_queue.put((None, [], {}))
        stopped = True

        if page_put_queue.qsize() > 1:
            num, sec = remaining()
            output(color_format(
                '{lightblue}Waiting for {num} pages to be put. '
                'Estimated time remaining: {sec}{default}', num=num, sec=sec))

        while(_putthread.isAlive()):
            try:
                _putthread.join(1)
            except KeyboardInterrupt:
                if input_yn('There are %i pages remaining in the queue. '
                            'Estimated time remaining: %s\nReally exit?'
                            % remaining(), default=False, automatic_quit=False):
                    return

    # only need one drop() call because all throttles use the same global pid
    try:
        list(_sites.values())[0].throttle.drop()
        log(u"Dropped throttle(s).")
    except IndexError:
        pass
开发者ID:amperser,项目名称:pywikibot-core,代码行数:45,代码来源:__init__.py


示例10: _ColorCodeWordScreen

 def _ColorCodeWordScreen(self, word):
     res = ''
     lastIsCyr = word[0] in self.localLtr
     if lastIsCyr:
         res += self.colorFormatLocalColor
     else:
         res += self.colorFormatLatinColor
     for l in word:
         if l in self.localLtr:
             if not lastIsCyr:
                 res += self.colorFormatLocalColor
                 lastIsCyr = True
         elif l in self.latLtr:
             if lastIsCyr:
                 res += self.colorFormatLatinColor
                 lastIsCyr = False
         res += l
     return formatter.color_format(res + self.colorFormatSuffix)
开发者ID:Tillsa,项目名称:pywikibot_test_wikidata,代码行数:18,代码来源:casechecker.py


示例11: __init__

    def __init__(self, *arg):
        """Constructor."""
        pywikibot.output(color_format(
            '{lightgreen}* Initialization of bot{default}'))

        pywikibot.botirc.IRCBot.__init__(self, *arg)

        # init environment with minimal changes (try to do as less as possible)
        # - Lua -
        pywikibot.output(u'** Redirecting Lua print in order to catch it')
        lua.execute('__print = print')
        lua.execute('print = python.globals().pywikibot.output')
        # It may be useful in debugging to install the 'print' builtin
        # as the 'print' function in lua. To do this:
        # lua.execute('print = python.builtins().print')

        # init constants
        templ = pywikibot.Page(self.site, bot_config['ConfCSSshell'])
        cron = pywikibot.Page(self.site, bot_config['ConfCSScrontab'])

        self.templ = templ.title()
        self.cron = cron.title()
        self.refs = {self.templ: templ,
                     self.cron: cron,
                     }
        pywikibot.output(u'** Pre-loading all relevant page contents')
        for item in self.refs:
            # First check if page is protected, reject any data if not
            parts = self.refs[item].title().lower().rsplit('.')
            if len(parts) == 1 or parts[1] not in ['.css', '.js']:
                raise ValueError('%s config %s = %s is not a secure page; '
                                 'it should be a css or js userpage which are '
                                 'automatically semi-protected.'
                                 % (self.__class__.__name__, item,
                                    self.refs[item]))
            try:
                self.refs[item].get(force=True)   # load all page contents
            except pywikibot.NoPage:
                pywikibot.error("The configuation page %s doesn't exists"
                                % self.refs[item].title(asLink=True))
                raise
        # init background timer
        pywikibot.output(u'** Starting crontab background timer thread')
        self.on_timer()
开发者ID:magul,项目名称:pywikibot-core,代码行数:44,代码来源:script_wui.py


示例12: featuredArticles

    def featuredArticles(self, site, task, cache):
        articles = []
        info = globals()[task + '_name']
        if task == 'lists':
            code = site.code
        else:
            code = 'wikidata'
        try:
            method = info[code][0]
        except KeyError:
            pywikibot.error(
                u'language %s doesn\'t has %s category source.'
                % (code, task))
            return
        name = info[code][1]
        # hide #-sorted items on en-wiki
        try:
            hide = info[code][2]
        except IndexError:
            hide = None
        for p in method(site, name, hide):
            if p.namespace() == 0:  # Article
                articles.append(p)
            # Article talk (like in English)
            elif p.namespace() == 1 and site.code != 'el':
                articles.append(pywikibot.Page(p.site,
                                p.title(withNamespace=False)))
        pywikibot.output(color_format(
            '{lightred}** {0} has {1} {2} articles{default}',
            site, len(articles), task))
        while articles:
            p = articles.pop(0)
            if p.title() < self.getOption('afterpage'):
                continue

            if u"/" in p.title() and p.namespace() != 0:
                pywikibot.output(u"%s is a subpage" % p.title())
                continue

            if p.title() in cache:
                pywikibot.output(u"(cached) %s -> %s" % (p.title(),
                                                         cache[p.title()]))
                continue
            yield p
开发者ID:magul,项目名称:pywikibot-core,代码行数:44,代码来源:featured.py


示例13: treat_page

    def treat_page(self):
        """Do the magic."""
        # set origin
        origin = self.current_page.title()
        site = self.current_page.site

        # create redirect title
        if not self.getOption('reversed'):
            redir = pywikibot.Page(site, origin.replace('–', '-')
                                               .replace('—', '-'))
        else:
            redir = pywikibot.Page(site, origin.replace('-', '–'))

        # skip unchanged
        if redir.title() == origin:
            pywikibot.output('No need to process %s, skipping…'
                             % redir.title())
            # suggest -reversed parameter
            if '-' in origin and not self.getOption('reversed'):
                pywikibot.output('Consider using -reversed parameter '
                                 'for this particular page')
        else:
            # skip existing
            if redir.exists():
                pywikibot.output('%s already exists, skipping…'
                                 % redir.title())
            else:
                # confirm and save redirect
                if self.user_confirm(
                    color_format(
                        'Redirect from {lightblue}{0}{default} doesn\'t exist '
                        'yet.\nDo you want to create it?',
                        redir.title())):
                    # If summary option is None, it takes the default
                    # i18n summary from i18n subdirectory with summary key.
                    if self.getOption('summary'):
                        summary = self.getOption('summary')
                    else:
                        summary = i18n.twtranslate(site,
                                                   'ndashredir-create',
                                                   {'title': origin})
                    redir.set_redirect_target(self.current_page, create=True,
                                              summary=summary)
开发者ID:magul,项目名称:pywikibot-core,代码行数:43,代码来源:ndashredir.py


示例14: revert

 def revert(self, item):
     """Revert a single item."""
     page = pywikibot.Page(self.site, item["title"])
     history = list(page.revisions(total=2))
     if len(history) > 1:
         rev = history[1]
     else:
         return False
     comment = i18n.twtranslate(
         self.site, "revertbot-revert", {"revid": rev.revid, "author": rev.user, "timestamp": rev.timestamp}
     )
     if self.comment:
         comment += ": " + self.comment
     pywikibot.output(
         color_format(
             "\n\n>>> {lightpurple}{0}{default} <<<", page.title(asLink=True, forceInterwiki=True, textlink=True)
         )
     )
     if not self.rollback:
         old = page.text
         page.text = rev.text
         pywikibot.showDiff(old, page.text)
         page.save(comment)
         return comment
     try:
         pywikibot.data.api.Request(
             self.site,
             parameters={
                 "action": "rollback",
                 "title": page,
                 "user": self.user,
                 "token": rev.rollbacktoken,
                 "markbot": True,
             },
         ).submit()
     except pywikibot.data.api.APIError as e:
         if e.code == "badtoken":
             pywikibot.error("There was an API token error rollbacking the edit")
         else:
             pywikibot.exception()
         return False
     return "The edit(s) made in %s by %s was rollbacked" % (page.title(), self.user)
开发者ID:h4ck3rm1k3,项目名称:pywikibot-core,代码行数:42,代码来源:revertbot.py


示例15: showStatus

def showStatus(n=0):
    """Output colorized status."""
    staColor = {
        0: 'lightpurple',
        1: 'lightaqua',
        2: 'lightgreen',
        3: 'lightyellow',
        4: 'lightred',
        5: 'lightblue'
    }
    staMsg = {
        0: 'MSG',
        1: 'NoAct',
        2: 'Match',
        3: 'Skip',
        4: 'Warning',
        5: 'Done',
    }
    pywikibot.output(color_format('{color}[{0:5}]{default} ',
                                  staMsg[n], color=staColor[n]), newline=False)
开发者ID:PersianWikipedia,项目名称:pywikibot-core,代码行数:20,代码来源:welcome.py


示例16: revert

 def revert(self, item):
     """Revert a single item."""
     page = pywikibot.Page(self.site, item['title'])
     history = list(page.revisions(total=2))
     if len(history) > 1:
         rev = history[1]
     else:
         return False
     comment = i18n.twtranslate(
         self.site, 'revertbot-revert',
         {'revid': rev.revid,
          'author': rev.user,
          'timestamp': rev.timestamp})
     if self.comment:
         comment += ': ' + self.comment
     pywikibot.output(color_format(
         '\n\n>>> {lightpurple}{0}{default} <<<',
         page.title(asLink=True, forceInterwiki=True, textlink=True)))
     if not self.rollback:
         old = page.text
         page.text = page.getOldVersion(rev.revid)
         pywikibot.showDiff(old, page.text)
         page.save(comment)
         return comment
     try:
         pywikibot.data.api.Request(
             self.site, parameters={'action': 'rollback',
                                    'title': page,
                                    'user': self.user,
                                    'token': rev.rollbacktoken,
                                    'markbot': True}).submit()
     except pywikibot.data.api.APIError as e:
         if e.code == 'badtoken':
             pywikibot.error(
                 'There was an API token error rollbacking the edit')
         else:
             pywikibot.exception()
         return False
     return 'The edit(s) made in %s by %s was rollbacked' % (page.title(),
                                                             self.user)
开发者ID:hasteur,项目名称:g13bot_tools_new,代码行数:40,代码来源:revertbot.py


示例17: summary_hook

    def summary_hook(self, match, replaced):
        def underscores(string):
            if string.startswith(' '):
                string = '_' + string[1:]
            if string.endswith(' '):
                string = string[:-1] + '_'
            return string

        new = old = match.group()
        if self.needsDecision():
            options = [('keep', 'k')]
            replacements = []
            for i, repl in enumerate(self.replacements, start=1):
                replacement = match.expand(repl)
                replacements.append(replacement)
                options.append(
                    ('%s %s' % (i, underscores(replacement)), str(i))
                )
            text = match.string
            pre = text[max(0, match.start() - 30):match.start()].rpartition('\n')[2]
            post = text[match.end():match.end() + 30].partition('\n')[0]
            pywikibot.output(color_format('{0}{lightred}{1}{default}{2}',
                                          pre, old, post))
            choice = pywikibot.input_choice('Choose the best replacement',
                                            options, automatic_quit=False,
                                            default='k')
            if choice != 'k':
                new = replacements[int(choice) - 1]
        else:
            new = match.expand(self.replacements[0])
            if old == new:
                pywikibot.warning('No replacement done in string "%s"' % old)

        if old != new:
            fragment = ' → '.join(underscores(re.sub('\n', r'\\n', i))
                                  for i in (old, new))
            if fragment.lower() not in map(methodcaller('lower'), replaced):
                replaced.append(fragment)
        return new
开发者ID:matejsuchanek,项目名称:pywikibot-scripts,代码行数:39,代码来源:typoloader.py


示例18: _generate_diff

    def _generate_diff(self, hunks):
        """Generate a diff text for the given hunks."""
        def extend_context(start, end):
            """Add context lines."""
            return ''.join('  {0}\n'.format(line.rstrip())
                           for line in self.a[start:end])

        context_range = self._get_context_range(hunks)

        output = color_format('{aqua}{0}{default}\n{1}',
                              Hunk.get_header_text(*context_range),
                              extend_context(context_range[0][0],
                                             hunks[0].a_rng[0]))
        previous_hunk = None
        for hunk in hunks:
            if previous_hunk:
                output += extend_context(previous_hunk.a_rng[1], hunk.a_rng[0])
            previous_hunk = hunk
            output += hunk.diff_text
        output += extend_context(hunks[-1].a_rng[1], context_range[0][1])
        if self._replace_invisible:
            output = chars.replace_invisible(output)
        return output
开发者ID:Zeffar,项目名称:Elobot,代码行数:23,代码来源:diff.py


示例19: treat_page

 def treat_page(self):
     """Process a single page."""
     text = self.current_page.text
     if self.spam_external_url not in text:
         return
     lines = text.split('\n')
     newpage = []
     lastok = ""
     for line in lines:
         if self.spam_external_url in line:
             if lastok:
                 pywikibot.output(lastok)
             pywikibot.output(color_format('{lightred}{0}{default}', line))
             lastok = None
         else:
             newpage.append(line)
             if line.strip():
                 if lastok is None:
                     pywikibot.output(line)
                 lastok = line
     if self.getOption('always'):
         answer = "y"
     else:
         answer = pywikibot.input_choice(
             u'\nDelete the red lines?',
             [('yes', 'y'), ('no', 'n'), ('edit', 'e')],
             'n', automatic_quit=False)
     if answer == "n":
         return
     elif answer == "e":
         editor = TextEditor()
         newtext = editor.edit(text, highlight=self.spam_external_url,
                               jumpIndex=text.find(self.spam_external_url))
     else:
         newtext = "\n".join(newpage)
     if newtext != text:
         self.put_current(newtext, summary=self.getOption('summary'))
开发者ID:magul,项目名称:pywikibot-core,代码行数:37,代码来源:spamremove.py


示例20: assert_format

 def assert_format(self, format_string, expected, *args, **kwargs):
     """Assert that color_format returns the expected string and type."""
     result = formatter.color_format(format_string, *args, **kwargs)
     self.assertEqual(result, expected)
     self.assertIsInstance(result, type(expected))
开发者ID:AbdealiJK,项目名称:pywikibot-core,代码行数:5,代码来源:tools_formatter_tests.py



注:本文中的pywikibot.tools.formatter.color_format函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pywin32_testutil.str2bytes函数代码示例发布时间:2022-05-26
下一篇:
Python tools.issue_deprecation_warning函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap