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


Python wikipedia.replaceExcept函数代码示例

本文整理汇总了Python中wikipedia.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:Rodehi,项目名称:GFROS,代码行数:34,代码来源: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:Rodehi,项目名称:GFROS,代码行数: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:swertschak,项目名称:wikijournals-api,代码行数: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:electionr,项目名称:rootstriker-fec-bot,代码行数:56,代码来源:cosmetic_changes.py

示例5: 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:swertschak,项目名称:wikijournals-api,代码行数:10,代码来源:cosmetic_changes.py

示例6: 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:Protonk,项目名称:pywikipedia2,代码行数: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:yknip1207,项目名称:genewiki,代码行数: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,
                                        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, u'[ىي]', u'ی', exceptions)
     return text
     # replace persian/arabic digits
     ## deactivated due to bug #3539407
     for i in xrange(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 xrange(0, 10):
         text = pywikibot.replaceExcept(text, str(i), new[i], exceptions)
     return text
开发者ID:Rodehi,项目名称:GFROS,代码行数:60,代码来源:cosmetic_changes.py

示例9: 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-header}} ==", exceptions, True)
        text = pywikibot.replaceExcept(
            text,
            r"([\r\n])\=\= *(Licensing|License information|{{int:license}}) *\=\=",
            r"\1== {{int:license-header}} ==", 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-header}} *\=\=(?:[\r\n ]*)\=\= *{{int:license-header}} *\=\=',
            r'\1== {{int:license-header}} ==', exceptions, True)

        return text
开发者ID:SirComputer1,项目名称:SCBot,代码行数:49,代码来源: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:yknip1207,项目名称:genewiki,代码行数:15,代码来源:cosmetic_changes.py

示例11: translateAndCapitalizeNamespaces

    def translateAndCapitalizeNamespaces(self, text):
        """
        Makes sure that localized namespace names are used.
        """
        # arz uses english stylish codes
        if self.site.sitename() == 'wikipedia:arz':
            return text
        family = self.site.family
        # wiki links aren't parsed here.
        exceptions = ['nowiki', 'comment', 'math', 'pre']

        for nsNumber in family.namespaces:
            if not family.isDefinedNSLanguage(nsNumber, self.site.lang):
                # Skip undefined namespaces
                continue
            namespaces = list(self.site.namespace(nsNumber, all = True))
            thisNs = namespaces.pop(0)
            if nsNumber == 6 and family.name == 'wikipedia' and \
               self.site.lang in ('en', 'fr'):
                # do not change "Image" on en-wiki and fr-wiki
                for image in [u'Image', u'image']:
                    if image in namespaces:
                        namespaces.remove(image)
            # skip main (article) namespace
            if thisNs and namespaces:
                text = pywikibot.replaceExcept(text, r'\[\[\s*(' + '|'.join(namespaces) + ') *:(?P<nameAndLabel>.*?)\]\]', r'[[' + thisNs + ':\g<nameAndLabel>]]', exceptions)
        return text
开发者ID:yknip1207,项目名称:genewiki,代码行数:27,代码来源:cosmetic_changes.py

示例12: removeDeprecatedTemplates

 def removeDeprecatedTemplates(self, text):
     if deprecatedTemplates.has_key(self.site.family.name) and deprecatedTemplates[self.site.family.name].has_key(self.site.lang):
         for template in deprecatedTemplates[self.site.family.name][self.site.lang]:
             if not self.site.nocapitalize:
                 template = '[' + template[0].upper() + template[0].lower() + ']' + template[1:]
             text = wikipedia.replaceExcept(text, r'\{\{([mM][sS][gG]:)?' + template + '(?P<parameters>\|[^}]+|)}}', '', ['comment', 'math', 'nowiki', 'pre'])
     return text
开发者ID:pyropeter,项目名称:PyroBot-1G,代码行数:7,代码来源:cosmetic_changes.py

示例13: sort_by_country_subcat

def sort_by_country_subcat(subcat, subject):
    print subcat
    subcat = subcat.replace("_", " ")
    subject = subject.replace("_", " ")
    if subcat.startswith(subject):
        temp1 = subcat[len(subject) :].lstrip()
        if temp1.startswith("from"):
            temp2 = temp1[len("from") :].lstrip()
        elif temp1.startswith("of"):
            temp2 = temp1[len("of") :].lstrip()
        elif temp1.startswith("in"):
            temp2 = temp1[len("in") :].lstrip()
        else:
            temp2 = ""
        if temp2:
            if temp2.startswith("the"):
                country = temp2[len("the") :].lstrip()
            else:
                country = temp2
            page = wikipedia.Page(wikipedia.getSite(), "Category:" + subcat)
            old = u"\[\[[cC]ategory:" + subject + u" by country[^\]]*\]\]"
            new = u"[[Category:" + subject + u" by country|" + country + u"]]"
            comment = u"Sorting [[:Category:" + subject + u" by country]]"
            newtext = wikipedia.replaceExcept(page.get(), old, new, [])
            wikipedia.showDiff(page.get(), newtext)
            page.put(newtext, comment)
开发者ID:bymerej,项目名称:ts-multichill-bot,代码行数:26,代码来源:sort_by_country_category.py

示例14: sort_by_country_subcat

def sort_by_country_subcat(subcat, subject):
    print subcat
    subcat = subcat.replace('_', ' ')
    subject = subject.replace('_', ' ')
    if subcat.startswith(subject):
	temp1 = subcat[len(subject):].lstrip()
	if temp1.startswith('from'):
	    temp2 = temp1[len('from'):].lstrip()
	elif temp1.startswith('of'):
            temp2 = temp1[len('of'):].lstrip()
        elif temp1.startswith('in'):
            temp2 = temp1[len('in'):].lstrip()
	else:
	    temp2 = ''
	if temp2:
	    if temp2.startswith('the'):
		country = temp2[len('the'):].lstrip() 
	    else:
		country = temp2
	    page = wikipedia.Page(wikipedia.getSite(), 'Category:' + subcat)
	    old = u'\[\[[cC]ategory:' + subject + u' by country[^\]]*\]\]'
	    new = u'[[Category:' + subject + u' by country|' + country + u']]'
	    comment = u'Sorting [[:Category:' + subject + u' by country]]'
	    newtext = wikipedia.replaceExcept(page.get(), old, new, [])
	    wikipedia.showDiff(page.get(), newtext)
	    page.put(newtext, comment)
开发者ID:multichill,项目名称:toollabs,代码行数:26,代码来源:sort_by_country_category.py

示例15: translateAndCapitalizeNamespaces

    def translateAndCapitalizeNamespaces(self, text):
        """
        Makes sure that localized namespace names are used.
        """
        # arz uses english stylish codes
        if self.site.sitename() == "wikipedia:arz":
            return text
        family = self.site.family
        # wiki links aren't parsed here.
        exceptions = ["nowiki", "comment", "math", "pre"]

        for nsNumber in family.namespaces:
            if not family.isDefinedNSLanguage(nsNumber, self.site.lang):
                # Skip undefined namespaces
                continue
            namespaces = list(self.site.namespace(nsNumber, all=True))
            thisNs = namespaces.pop(0)
            if nsNumber == 6 and family.name == "wikipedia" and self.site.lang in ("en", "fr"):
                # do not change "Image" on en-wiki and fr-wiki
                for image in [u"Image", u"image"]:
                    if image in namespaces:
                        namespaces.remove(image)
            # skip main (article) namespace
            if thisNs and namespaces:
                text = pywikibot.replaceExcept(
                    text,
                    r"\[\[\s*(" + "|".join(namespaces) + ") *:(?P<nameAndLabel>.*?)\]\]",
                    r"[[" + thisNs + ":\g<nameAndLabel>]]",
                    exceptions,
                )
        return text
开发者ID:swertschak,项目名称:wikijournals-api,代码行数:31,代码来源:cosmetic_changes.py


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