当前位置: 首页>>代码示例>>Python>>正文


Python pywikibot.replaceExcept函数代码示例

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


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

示例1: fixSyntaxSave

    def fixSyntaxSave(self, text):
        exceptions = ['nowiki', 'comment', 'math', 'pre', 'source',
                      'startspace']
        # link to the wiki working on
        ## TODO: disable this for difflinks and titled links
        ## http://de.wikipedia.org/w/index.php?title=Wikipedia%3aVandalismusmeldung&diff=103109563&oldid=103109271
##        text = pywikibot.replaceExcept(text,
##                                       r'\[https?://%s\.%s\.org/wiki/(?P<link>\S+)\s+(?P<title>.+?)\s?\]'
##                                       % (self.site.lang, self.site.family.name),
##                                       r'[[\g<link>|\g<title>]]', exceptions)
        # external link in double brackets
        text = pywikibot.replaceExcept(text,
                                       r'\[\[(?P<url>https?://[^\]]+?)\]\]',
                                       r'[\g<url>]', exceptions)
        # external link starting with double bracket
        text = pywikibot.replaceExcept(text,
                                       r'\[\[(?P<url>https?://.+?)\]',
                                       r'[\g<url>]', exceptions)
        # external link and description separated by a dash, with
        # whitespace in front of the dash, so that it is clear that
        # the dash is not a legitimate part of the URL.
        text = pywikibot.replaceExcept(text,
                                       r'\[(?P<url>https?://[^\|\] \r\n]+?) +\| *(?P<label>[^\|\]]+?)\]',
                                       r'[\g<url> \g<label>]', exceptions)
        # dash in external link, where the correct end of the URL can
        # be detected from the file extension. It is very unlikely that
        # this will cause mistakes.
        text = pywikibot.replaceExcept(text,
                                       r'\[(?P<url>https?://[^\|\] ]+?(\.pdf|\.html|\.htm|\.php|\.asp|\.aspx|\.jsp)) *\| *(?P<label>[^\|\]]+?)\]',
                                       r'[\g<url> \g<label>]', exceptions)
        return text
开发者ID:edgarskos,项目名称:pywikipedia-rewrite,代码行数:31,代码来源:cosmetic_changes.py

示例2: removeUselessSpaces

 def removeUselessSpaces(self, text):
     multipleSpacesR = re.compile('  +')
     spaceAtLineEndR = re.compile(' $')
     exceptions = ['comment', 'math', 'nowiki', 'pre', 'startspace', 'table',
                   'template']
     text = pywikibot.replaceExcept(text, multipleSpacesR, ' ', exceptions)
     text = pywikibot.replaceExcept(text, spaceAtLineEndR, '', exceptions)
     return text
开发者ID:octobertech,项目名称:pywikibot-core,代码行数:8,代码来源:cosmetic_changes.py

示例3: commonsfiledesc

    def commonsfiledesc(self, text):
        # section headers to {{int:}} versions
        exceptions = ["comment", "includeonly", "math", "noinclude", "nowiki", "pre", "source", "ref", "timeline"]
        text = pywikibot.replaceExcept(
            text, r"([\r\n]|^)\=\= *Summary *\=\=", r"\1== {{int:filedesc}} ==", exceptions, True
        )
        text = pywikibot.replaceExcept(
            text,
            r"([\r\n])\=\= *\[\[Commons:Copyright tags\|Licensing\]\]: *\=\=",
            r"\1== {{int:license}} ==",
            exceptions,
            True,
        )
        text = pywikibot.replaceExcept(
            text,
            r"([\r\n])\=\= *(Licensing|License information|{{int:license-header}}) *\=\=",
            r"\1== {{int:license}} ==",
            exceptions,
            True,
        )

        # frequent field values to {{int:}} versions
        text = pywikibot.replaceExcept(
            text,
            r"([\r\n]\|[Ss]ource *\= *)(?:[Oo]wn work by uploader|[Oo]wn work|[Ee]igene [Aa]rbeit) *([\r\n])",
            r"\1{{own}}\2",
            exceptions,
            True,
        )
        text = pywikibot.replaceExcept(
            text, r"(\| *Permission *\=) *(?:[Ss]ee below|[Ss]iehe unten) *([\r\n])", r"\1\2", exceptions, True
        )

        # added to transwikied pages
        text = pywikibot.replaceExcept(text, r"__NOTOC__", "", exceptions, True)

        # tracker element for js upload form
        text = pywikibot.replaceExcept(text, r"<!-- *{{ImageUpload\|(?:full|basic)}} *-->", "", exceptions[1:], True)
        text = pywikibot.replaceExcept(text, r"{{ImageUpload\|(?:basic|full)}}", "", exceptions, True)

        # duplicated section headers
        text = pywikibot.replaceExcept(
            text,
            r"([\r\n]|^)\=\= *{{int:filedesc}} *\=\=(?:[\r\n ]*)\=\= *{{int:filedesc}} *\=\=",
            r"\1== {{int:filedesc}} ==",
            exceptions,
            True,
        )
        text = pywikibot.replaceExcept(
            text,
            r"([\r\n]|^)\=\= *{{int:license}} *\=\=(?:[\r\n ]*)\=\= *{{int:license}} *\=\=",
            r"\1== {{int:license}} ==",
            exceptions,
            True,
        )
        return text
开发者ID:reza1615,项目名称:pywikipedia-rewrite,代码行数:56,代码来源:cosmetic_changes.py

示例4: fixArabicLetters

 def fixArabicLetters(self, text):
     if self.site.lang=='ckb' or self.site.lang=='fa':
         exceptions = [
             'gallery',
             'hyperlink',
             'interwiki',
             # but changes letters inside wikilinks
             #'link',
             'math',
             'pre',
             'template',
             'timeline',
             'ref',
             'source',
             'startspace',
             'inputbox',
         ]
         # do not change inside file links
         namespaces = list(self.site.namespace(6, all = True))
         pattern = re.compile(u'\[\[(' + '|'.join(namespaces) + '):.+?\..+?\]\]',
                              re.UNICODE)
         exceptions.append(pattern)
         text = pywikibot.replaceExcept(text, u',', u'،', exceptions)
         if self.site.lang=='ckb':
             text = pywikibot.replaceExcept(text,
                                            ur'ه([.،_<\]\s])',
                                            ur'ە\1', exceptions)
             text = pywikibot.replaceExcept(text, u'ه‌', u'ە', exceptions)
             text = pywikibot.replaceExcept(text, u'ه', u'ھ', exceptions)
         text = pywikibot.replaceExcept(text, u'ك', u'ک', exceptions)
         text = pywikibot.replaceExcept(text, ur'[ىي]', u'ی', exceptions)
         # replace persian digits
         for i in range(0,10):
             if self.site.lang=='ckb':
                 text = pywikibot.replaceExcept(text,
                                                u'۰۱۲۳۴۵۶۷۸۹'[i],
                                                u'٠١٢٣٤٥٦٧٨٩'[i], exceptions)
             else:
                 text = pywikibot.replaceExcept(text,
                                                u'٠١٢٣٤٥٦٧٨٩'[i],
                                                u'۰۱۲۳۴۵۶۷۸۹'[i], exceptions)
         # do not change digits in class, style and table params
         pattern = re.compile(u'=".*?"', re.UNICODE)
         exceptions.append(pattern)
         # do not change digits inside html-tags
         pattern = re.compile(u'<[/]*?[^</]+?[/]*?>', re.UNICODE)
         exceptions.append(pattern)
         exceptions.append('table') #exclude tables for now
         for i in range(0,10):
             if self.site.lang=='ckb':
                 text = pywikibot.replaceExcept(text, str(i),
                                                u'٠١٢٣٤٥٦٧٨٩'[i], exceptions)
             else:
                 text = pywikibot.replaceExcept(text, str(i),
                                                u'۰۱۲۳۴۵۶۷۸۹'[i], exceptions)
     return text
开发者ID:azatoth,项目名称:pywikipedia,代码行数:56,代码来源:cosmetic_changes.py

示例5: fixReferences

    def fixReferences(self, text):
        # http://en.wikipedia.org/wiki/User:AnomieBOT/source/tasks/OrphanReferenceFixer.pm
        exceptions = ["nowiki", "comment", "math", "pre", "source", "startspace"]

        # it should be name = " or name=" NOT name   ="
        text = re.sub(r'(?i)<ref +name(= *| *=)"', r'<ref name="', text)
        # remove empty <ref/>-tag
        text = pywikibot.replaceExcept(text, r"(?i)(<ref\s*/>|<ref *>\s*</ref>)", r"", exceptions)
        text = pywikibot.replaceExcept(text, r"(?i)<ref\s+([^>]+?)\s*>\s*</ref>", r"<ref \1/>", exceptions)
        return text
开发者ID:reza1615,项目名称:pywikipedia-rewrite,代码行数:10,代码来源:cosmetic_changes.py

示例6: removeUselessSpaces

    def removeUselessSpaces(self, text):
        result = []
        multipleSpacesR = re.compile("  +")
        spaceAtLineEndR = re.compile(" $")

        exceptions = ["comment", "math", "nowiki", "pre", "startspace", "table", "template"]
        text = pywikibot.replaceExcept(text, multipleSpacesR, " ", exceptions)
        text = pywikibot.replaceExcept(text, spaceAtLineEndR, "", exceptions)

        return text
开发者ID:reza1615,项目名称:pywikipedia-rewrite,代码行数:10,代码来源:cosmetic_changes.py

示例7: fixTypo

 def fixTypo(self, text):
     exceptions = ['nowiki', 'comment', 'math', 'pre', 'source', 'startspace', 'gallery', 'hyperlink', 'interwiki', 'link']
     # change <number> ccm -> <number> cm³
     text = pywikibot.replaceExcept(text, ur'(\d)\s*&nbsp;ccm', ur'\1&nbsp;cm³', exceptions)
     text = pywikibot.replaceExcept(text, ur'(\d)\s*ccm', ur'\1&nbsp;cm³', exceptions)
     # Solve wrong Nº sign with °C or °F
     # additional exception requested on fr-wiki for this stuff
     pattern = re.compile(u'«.*?»', re.UNICODE)
     exceptions.append(pattern)
     text = pywikibot.replaceExcept(text, ur'(\d)\s*&nbsp;[º°]([CF])', ur'\1&nbsp;°\2', exceptions)
     text = pywikibot.replaceExcept(text, ur'(\d)\s*[º°]([CF])', ur'\1&nbsp;°\2', exceptions)
     text = pywikibot.replaceExcept(text, ur'º([CF])', ur'°\1', exceptions)
     return text
开发者ID:azatoth,项目名称:pywikipedia,代码行数:13,代码来源:cosmetic_changes.py

示例8: fixArabicLetters

 def fixArabicLetters(self, text):
     exceptions = [
         'gallery',
         'hyperlink',
         'interwiki',
         # but changes letters inside wikilinks
         #'link',
         'math',
         'pre',
         'template',
         'timeline',
         'ref',
         'source',
         'startspace',
         'inputbox',
     ]
     # valid digits
     digits = {
         'ckb': u'٠١٢٣٤٥٦٧٨٩',
         'fa': u'۰۱۲۳۴۵۶۷۸۹',
     }
     faChrs = u'ءاآأإئؤبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیةيك' + digits['fa']
     new = digits.pop(self.site.lang)
     # This only works if there are only two items in digits dict
     old = digits[digits.keys()[0]]
     # do not change inside file links
     namespaces = list(self.site.namespace(6, all=True))
     pattern = re.compile(
         u'\[\[(' + '|'.join(namespaces) +
         '):.+?\.\w+? *(\|((\[\[.*?\]\])|.)*)?\]\]',
         re.UNICODE)
     #not to let bot edits in latin content
     exceptions.append(re.compile(u"[^%(fa)s] *?\"*? *?, *?[^%(fa)s]"
                                  % {'fa': faChrs}))
     exceptions.append(pattern)
     text = pywikibot.replaceExcept(text, u',', u'،', exceptions)
     if self.site.lang == 'ckb':
         text = pywikibot.replaceExcept(text,
                                        u'\u0647([.\u060c_<\\]\\s])',
                                        u'\u06d5\\1', exceptions)
         text = pywikibot.replaceExcept(text, u'ه‌', u'ە', exceptions)
         text = pywikibot.replaceExcept(text, u'ه', u'ھ', exceptions)
     text = pywikibot.replaceExcept(text, u'ك', u'ک', exceptions)
     text = pywikibot.replaceExcept(text, u'[ىي]', u'ی', exceptions)
     return text
     # replace persian/arabic digits
     ## deactivated due to bug #3539407
     for i in range(0, 10):
         text = pywikibot.replaceExcept(text, old[i], new[i], exceptions)
     # do not change digits in class, style and table params
     pattern = re.compile(u'\w+=(".+?"|\d+)', re.UNICODE)
     exceptions.append(pattern)
     # do not change digits inside html-tags
     pattern = re.compile(u'<[/]*?[^</]+?[/]*?>', re.UNICODE)
     exceptions.append(pattern)
     exceptions.append('table')  # exclude tables for now
     # replace digits
     for i in range(0, 10):
         text = pywikibot.replaceExcept(text, str(i), new[i], exceptions)
     return text
开发者ID:octobertech,项目名称:pywikibot-core,代码行数:60,代码来源:cosmetic_changes.py

示例9: fixReferences

    def fixReferences(self, text):
        #https://en.wikipedia.org/wiki/User:AnomieBOT/source/tasks/OrphanReferenceFixer.pm
        exceptions = ['nowiki', 'comment', 'math', 'pre', 'source',
                      'startspace']

        # it should be name = " or name=" NOT name   ="
        text = re.sub(r'(?i)<ref +name(= *| *=)"', r'<ref name="', text)
        #remove empty <ref/>-tag
        text = pywikibot.replaceExcept(text,
                                       r'(?i)(<ref\s*/>|<ref *>\s*</ref>)',
                                       r'', exceptions)
        text = pywikibot.replaceExcept(text,
                                       r'(?i)<ref\s+([^>]+?)\s*>\s*</ref>',
                                       r'<ref \1/>', exceptions)
        return text
开发者ID:APerson241,项目名称:pywikibot-core,代码行数:15,代码来源:cosmetic_changes.py

示例10: fixSyntaxSave

 def fixSyntaxSave(self, text):
     exceptions = ['nowiki', 'comment', 'math', 'pre', 'source', 'startspace']
     # external link in double brackets
     text = pywikibot.replaceExcept(text, r'\[\[(?P<url>https?://[^\]]+?)\]\]', r'[\g<url>]', exceptions)
     # external link starting with double bracket
     text = pywikibot.replaceExcept(text, r'\[\[(?P<url>https?://.+?)\]', r'[\g<url>]', exceptions)
     # external link and description separated by a dash, with
     # whitespace in front of the dash, so that it is clear that
     # the dash is not a legitimate part of the URL.
     text = pywikibot.replaceExcept(text, r'\[(?P<url>https?://[^\|\] \r\n]+?) +\| *(?P<label>[^\|\]]+?)\]', r'[\g<url> \g<label>]', exceptions)
     # dash in external link, where the correct end of the URL can
     # be detected from the file extension. It is very unlikely that
     # this will cause mistakes.
     text = pywikibot.replaceExcept(text, r'\[(?P<url>https?://[^\|\] ]+?(\.pdf|\.html|\.htm|\.php|\.asp|\.aspx|\.jsp)) *\| *(?P<label>[^\|\]]+?)\]', r'[\g<url> \g<label>]', exceptions)
     return text
开发者ID:azatoth,项目名称:pywikipedia,代码行数:15,代码来源:cosmetic_changes.py

示例11: commonsfiledesc

    def commonsfiledesc(self, text):
        # section headers to {{int:}} versions
        exceptions = ['comment', 'includeonly', 'math', 'noinclude', 'nowiki',
                      'pre', 'source', 'ref', 'timeline']
        text = pywikibot.replaceExcept(text,
                                       r"([\r\n]|^)\=\= *Summary *\=\=",
                                       r"\1== {{int:filedesc}} ==",
                                       exceptions, True)
        text = pywikibot.replaceExcept(
            text,
            r"([\r\n])\=\= *\[\[Commons:Copyright tags\|Licensing\]\]: *\=\=",
            r"\1== {{int:license}} ==", exceptions, True)
        text = pywikibot.replaceExcept(
            text,
            r"([\r\n])\=\= *(Licensing|License information|{{int:license-header}}) *\=\=",
            r"\1== {{int:license}} ==", exceptions, True)

        # frequent field values to {{int:}} versions
        text = pywikibot.replaceExcept(
            text,
            r'([\r\n]\|[Ss]ource *\= *)(?:[Oo]wn work by uploader|[Oo]wn work|[Ee]igene [Aa]rbeit) *([\r\n])',
            r'\1{{own}}\2', exceptions, True)
        text = pywikibot.replaceExcept(
            text,
            r'(\| *Permission *\=) *(?:[Ss]ee below|[Ss]iehe unten) *([\r\n])',
            r'\1\2', exceptions, True)

        # added to transwikied pages
        text = pywikibot.replaceExcept(text, r'__NOTOC__', '', exceptions, True)

        # tracker element for js upload form
        text = pywikibot.replaceExcept(
            text,
            r'<!-- *{{ImageUpload\|(?:full|basic)}} *-->',
            '', exceptions[1:], True)
        text = pywikibot.replaceExcept(text, r'{{ImageUpload\|(?:basic|full)}}',
                                       '', exceptions, True)

        # duplicated section headers
        text = pywikibot.replaceExcept(
            text,
            r'([\r\n]|^)\=\= *{{int:filedesc}} *\=\=(?:[\r\n ]*)\=\= *{{int:filedesc}} *\=\=',
            r'\1== {{int:filedesc}} ==', exceptions, True)
        text = pywikibot.replaceExcept(
            text,
            r'([\r\n]|^)\=\= *{{int:license}} *\=\=(?:[\r\n ]*)\=\= *{{int:license}} *\=\=',
            r'\1== {{int:license}} ==', exceptions, True)
        return text
开发者ID:azatoth,项目名称:pywikipedia,代码行数:48,代码来源:cosmetic_changes.py

示例12: translateMagicWords

 def translateMagicWords(self, text):
     """
     Makes sure that localized namespace names are used.
     """
     # not wanted at ru
     # arz uses english stylish codes
     if self.site.lang not in ["arz", "ru"]:
         exceptions = ["nowiki", "comment", "math", "pre"]
         for magicWord in [
             "img_thumbnail",
             "img_left",
             "img_center",
             "img_right",
             "img_none",
             "img_framed",
             "img_frameless",
             "img_border",
             "img_upright",
         ]:
             aliases = self.site.getmagicwords(magicWord)
             if not aliases:
                 continue
             text = pywikibot.replaceExcept(
                 text,
                 r"\[\[(?P<left>.+?:.+?\..+?\|) *(" + "|".join(aliases) + ") *(?P<right>(\|.*?)?\]\])",
                 r"[[\g<left>" + aliases[0] + "\g<right>",
                 exceptions,
             )
     return text
开发者ID:reza1615,项目名称:pywikipedia-rewrite,代码行数:29,代码来源:cosmetic_changes.py

示例13: majUneSeuleListe

	def majUneSeuleListe(self, listePages, titrePageRandomArticles):
		pageAsLinkBoolean = True
		if titrePageRandomArticles in blackList:
			pageAsLinkBoolean = False
			
		exceptions = []
	
		texteARajouter = u""
		x = 0
		
		# Création d'un texte contenant la liste des pages
		for page in listePages:
			x = x + 1
			texteARajouter = texteARajouter + u"\n|" + str(x) + u"=" + page.title(asLink=pageAsLinkBoolean)
		
		nbPages = x
		
		pageRandomArticles = pywikibot.Page(self.site, titrePageRandomArticles)
		text = pageRandomArticles.get()

		pywikibot.output(u"\n> \03{lightblue}Traitement de %s\03{default} <" % pageRandomArticles.title())
		
		text = self.suppressionAncienneListe(text)
		
		old = re.compile(u"\{\{#switch:\{\{rand\|(1\||2=)[0-9]*\}\}")
		new = (u"{{#switch:{{rand|1|%i}}%s" % (nbPages, texteARajouter))
		text = pywikibot.replaceExcept(text, old, new, exceptions)
		
		if not self.save(text, pageRandomArticles, self.summary):
			pywikibot.output(u'Aucun changement nécessaire')
开发者ID:Toto-Azero,项目名称:Wikipedia,代码行数:30,代码来源:random_pages_portails.py

示例14: markActiveTables

    def markActiveTables(self, text):
        """
        Mark all table start and end tags that are not disabled by nowiki tags, comments etc.

        We will then later only work on these marked tags.
        """
        tableStartTagR = re.compile("<table", re.IGNORECASE)
        tableEndTagR = re.compile("</table>", re.IGNORECASE)

        text = pywikibot.replaceExcept(text, tableStartTagR, "<##table##",
                                       exceptions=['comment', 'math',
                                                   'nowiki', 'pre', 'source'])
        text = pywikibot.replaceExcept(text, tableEndTagR, "</##table##>",
                                       exceptions=['comment', 'math',
                                                   'nowiki', 'pre', 'source'])
        return text
开发者ID:hasteur,项目名称:g13bot_tools_new,代码行数:16,代码来源:table2wiki.py

示例15: suppressionAncienneListe

	def suppressionAncienneListe(self, text, nombreCrochets=2):
		exceptions = []
		#old = re.compile(u"(\n\|[0-9]{1,} *= *[\[\{]{2}.*[\]\}]{2}|\n[0-9]{1,} *= *[\[\{]{2}.*[\]\}]{2}\|)")
		old = re.compile(u"(\n\|[0-9]{1,} *= *[\[\{]{0,2}.*[\]\}]{0,2}|\n[0-9]{1,} *= *[\[\{]{0,2}.*[\]\}]{0,2}\|)")
		new = u""
		text = pywikibot.replaceExcept(text, old, new, exceptions)
		return text
开发者ID:Toto-Azero,项目名称:Wikipedia,代码行数:7,代码来源:random_pages_portails.py


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