<s> """<STR_LIT>""" <EOL> __version__ = '<STR_LIT>' <EOL> import wikipedia as pywikibot <EOL> import re <EOL> def unescape ( s ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT:&>' not in s : <EOL> return s <EOL> s = s . replace ( "<STR_LIT>" , "<STR_LIT:<>" ) <EOL> s = s . replace ( "<STR_LIT>" , "<STR_LIT:>>" ) <EOL> s = s . replace ( "<STR_LIT>" , "<STR_LIT:'>" ) <EOL> s = s . replace ( "<STR_LIT>" , '<STR_LIT:">' ) <EOL> s = s . replace ( "<STR_LIT>" , "<STR_LIT:&>" ) <EOL> return s <EOL> def replaceExcept ( text , old , new , exceptions , caseInsensitive = False , <EOL> allowoverlap = False , marker = '<STR_LIT>' , site = None ) : <EOL> """<STR_LIT>""" <EOL> if site is None : <EOL> site = pywikibot . getSite ( ) <EOL> exceptionRegexes = { <EOL> '<STR_LIT>' : re . compile ( r'<STR_LIT>' ) , <EOL> '<STR_LIT>' : re . compile ( r'<STR_LIT>' ) , <EOL> '<STR_LIT>' : re . compile ( r'<STR_LIT>' ) , <EOL> '<STR_LIT:source>' : re . compile ( r'<STR_LIT>' ) , <EOL> '<STR_LIT>' : re . compile ( r'<STR_LIT>' ) , <EOL> '<STR_LIT>' : re . compile ( r'<STR_LIT>' ) , <EOL> '<STR_LIT>' : re . compile ( r'<STR_LIT>' ) , <EOL> '<STR_LIT>' : re . compile ( r'<STR_LIT>' ) , <EOL> '<STR_LIT>' : compileLinkR ( ) , <EOL> '<STR_LIT>' : re . compile ( r'<STR_LIT>' ) , <EOL> '<STR_LIT>' : re . compile ( r'<STR_LIT>' ) , <EOL> '<STR_LIT>' : re . compile ( r'<STR_LIT>' <EOL> % '<STR_LIT:|>' . join ( site . validLanguageLinks ( ) <EOL> + site . family . obsolete . keys ( ) ) <EOL> ) , <EOL> } <EOL> if type ( old ) in [ str , unicode ] : <EOL> if caseInsensitive : <EOL> old = re . compile ( old , re . IGNORECASE | re . UNICODE ) <EOL> else : <EOL> old = re . compile ( old ) <EOL> dontTouchRegexes = [ ] <EOL> for exc in exceptions : <EOL> if isinstance ( exc , str ) or isinstance ( exc , unicode ) : <EOL> if exc in exceptionRegexes : <EOL> dontTouchRegexes . append ( exceptionRegexes [ exc ] ) <EOL> else : <EOL> dontTouchRegexes . append ( re . compile ( r'<STR_LIT>' % ( exc , exc ) ) ) <EOL> if exc == '<STR_LIT:source>' : <EOL> dontTouchRegexes . append ( re . compile ( r'<STR_LIT>' ) ) <EOL> else : <EOL> dontTouchRegexes . append ( exc ) <EOL> index = <NUM_LIT:0> <EOL> markerpos = len ( text ) <EOL> while True : <EOL> match = old . search ( text , index ) <EOL> if not match : <EOL> break <EOL> nextExceptionMatch = None <EOL> for dontTouchR in dontTouchRegexes : <EOL> excMatch = dontTouchR . search ( text , index ) <EOL> if excMatch and ( <EOL> nextExceptionMatch is None or <EOL> excMatch . start ( ) < nextExceptionMatch . start ( ) ) : <EOL> nextExceptionMatch = excMatch <EOL> if nextExceptionMatch is not None and nextExceptionMatch . start ( ) <= match . start ( ) : <EOL> index = nextExceptionMatch . end ( ) <EOL> else : <EOL> if callable ( new ) : <EOL> replacement = new ( match ) <EOL> else : <EOL> new = new . replace ( '<STR_LIT>' , '<STR_LIT:\n>' ) <EOL> replacement = new <EOL> groupR = re . compile ( r'<STR_LIT>' ) <EOL> while True : <EOL> groupMatch = groupR . search ( replacement ) <EOL> if not groupMatch : <EOL> break <EOL> groupID = groupMatch . group ( '<STR_LIT:name>' ) or int ( groupMatch . group ( '<STR_LIT>' ) ) <EOL> replacement = replacement [ : groupMatch . start ( ) ] + match . group ( groupID ) + replacement [ groupMatch . end ( ) : ] <EOL> text = text [ : match . start ( ) ] + replacement + text [ match . end ( ) : ] <EOL> if allowoverlap : <EOL> index = match . start ( ) + <NUM_LIT:1> <EOL> else : <EOL> index = match . start ( ) + len ( replacement ) <EOL> markerpos = match . start ( ) + len ( replacement ) <EOL> text = text [ : markerpos ] + marker + text [ markerpos : ] <EOL> return text <EOL> def removeDisabledParts ( text , tags = [ '<STR_LIT:*>' ] ) : <EOL> """<STR_LIT>""" <EOL> regexes = { <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT:source>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> } <EOL> if '<STR_LIT:*>' in tags : <EOL> tags = regexes . keys ( ) <EOL> tags = set ( tags ) <EOL> if '<STR_LIT:source>' in tags : <EOL> tags . add ( '<STR_LIT>' ) <EOL> toRemoveR = re . compile ( '<STR_LIT:|>' . join ( [ regexes [ tag ] for tag in tags ] ) , <EOL> re . IGNORECASE | re . DOTALL ) <EOL> return toRemoveR . sub ( '<STR_LIT>' , text ) <EOL> def isDisabled ( text , index , tags = [ '<STR_LIT:*>' ] ) : <EOL> """<STR_LIT>""" <EOL> marker = findmarker ( text , '<STR_LIT>' , '<STR_LIT:@>' ) <EOL> text = text [ : index ] + marker + text [ index : ] <EOL> text = removeDisabledParts ( text , tags ) <EOL> return ( marker not in text ) <EOL> def findmarker ( text , startwith = u'<STR_LIT:@>' , append = u'<STR_LIT:@>' ) : <EOL> if len ( append ) <= <NUM_LIT:0> : <EOL> append = u'<STR_LIT:@>' <EOL> mymarker = startwith <EOL> while mymarker in text : <EOL> mymarker += append <EOL> return mymarker <EOL> def expandmarker ( text , marker = '<STR_LIT>' , separator = '<STR_LIT>' ) : <EOL> if separator : <EOL> firstinmarker = text . find ( marker ) <EOL> firstinseparator = firstinmarker <EOL> lenseparator = len ( separator ) <EOL> striploopcontinue = True <EOL> while firstinseparator > <NUM_LIT:0> and striploopcontinue : <EOL> striploopcontinue = False <EOL> if ( firstinseparator >= lenseparator ) and ( separator == text [ firstinseparator - lenseparator : firstinseparator ] ) : <EOL> firstinseparator -= lenseparator <EOL> striploopcontinue = True <EOL> elif text [ firstinseparator - <NUM_LIT:1> ] < '<STR_LIT:U+0020>' : <EOL> firstinseparator -= <NUM_LIT:1> <EOL> striploopcontinue = True <EOL> marker = text [ firstinseparator : firstinmarker ] + marker <EOL> return marker <EOL> def getLanguageLinks ( text , insite = None , pageLink = "<STR_LIT>" , template_subpage = False ) : <EOL> """<STR_LIT>""" <EOL> if insite is None : <EOL> insite = pywikibot . getSite ( ) <EOL> result = { } <EOL> tags = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:source>' ] <EOL> if not template_subpage : <EOL> tags += [ '<STR_LIT>' ] <EOL> text = removeDisabledParts ( text , tags ) <EOL> interwikiR = re . compile ( r'<STR_LIT>' ) <EOL> for lang , pagetitle in interwikiR . findall ( text ) : <EOL> lang = lang . lower ( ) <EOL> if lang in insite . family . obsolete : <EOL> lang = insite . family . obsolete [ lang ] <EOL> if lang in insite . validLanguageLinks ( ) : <EOL> if '<STR_LIT:|>' in pagetitle : <EOL> pagetitle = pagetitle [ : pagetitle . index ( '<STR_LIT:|>' ) ] <EOL> site = insite . getSite ( code = lang ) <EOL> try : <EOL> result [ site ] = pywikibot . Page ( site , pagetitle , insite = insite ) <EOL> except pywikibot . InvalidTitle : <EOL> pywikibot . output ( <EOL> u"<STR_LIT>" <EOL> % ( lang , pagetitle ) ) <EOL> continue <EOL> return result <EOL> def removeLanguageLinks ( text , site = None , marker = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if site is None : <EOL> site = pywikibot . getSite ( ) <EOL> if not site . validLanguageLinks ( ) : <EOL> return text <EOL> languages = '<STR_LIT:|>' . join ( site . validLanguageLinks ( ) + site . family . obsolete . keys ( ) ) <EOL> interwikiR = re . compile ( r'<STR_LIT>' <EOL> % languages , re . IGNORECASE ) <EOL> text = replaceExcept ( text , interwikiR , '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:source>' ] , <EOL> marker = marker ) <EOL> return text . strip ( ) <EOL> def removeLanguageLinksAndSeparator ( text , site = None , marker = '<STR_LIT>' , separator = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if separator : <EOL> mymarker = findmarker ( text , u'<STR_LIT>' ) <EOL> newtext = removeLanguageLinks ( text , site , mymarker ) <EOL> mymarker = expandmarker ( newtext , mymarker , separator ) <EOL> return newtext . replace ( mymarker , marker ) <EOL> else : <EOL> return removeLanguageLinks ( text , site , marker ) <EOL> def replaceLanguageLinks ( oldtext , new , site = None , addOnly = False , <EOL> template = False , template_subpage = False ) : <EOL> """<STR_LIT>""" <EOL> marker = findmarker ( oldtext , u'<STR_LIT>' ) <EOL> if site is None : <EOL> site = pywikibot . getSite ( ) <EOL> separator = site . family . interwiki_text_separator <EOL> cseparator = site . family . category_text_separator <EOL> separatorstripped = separator . strip ( ) <EOL> cseparatorstripped = cseparator . strip ( ) <EOL> if addOnly : <EOL> s2 = oldtext <EOL> else : <EOL> s2 = removeLanguageLinksAndSeparator ( oldtext , site = site , marker = marker , <EOL> separator = separatorstripped ) <EOL> s = interwikiFormat ( new , insite = site ) <EOL> if s : <EOL> if site . language ( ) in site . family . interwiki_attop : <EOL> newtext = s + separator + s2 . replace ( marker , '<STR_LIT>' ) . strip ( ) <EOL> else : <EOL> firstafter = s2 . find ( marker ) <EOL> if firstafter < <NUM_LIT:0> : <EOL> firstafter = len ( s2 ) <EOL> else : <EOL> firstafter += len ( marker ) <EOL> if "<STR_LIT>" in s2 [ firstafter : ] : <EOL> if separatorstripped : <EOL> s = separator + s <EOL> newtext = s2 [ : firstafter ] . replace ( marker , '<STR_LIT>' ) + s + s2 [ firstafter : ] <EOL> elif site . language ( ) in site . family . categories_last : <EOL> cats = getCategoryLinks ( s2 , site = site ) <EOL> s2 = removeCategoryLinksAndSeparator ( <EOL> s2 . replace ( marker , '<STR_LIT>' , cseparatorstripped ) . strip ( ) , <EOL> site ) + separator + s <EOL> newtext = replaceCategoryLinks ( s2 , cats , site = site , <EOL> addOnly = True ) <EOL> elif site . family . name == '<STR_LIT>' : <EOL> s = separator + s + separator <EOL> newtext = s2 [ : firstafter ] . replace ( marker , '<STR_LIT>' ) + s + s2 [ firstafter : ] <EOL> else : <EOL> if template or template_subpage : <EOL> if template_subpage : <EOL> includeOn = '<STR_LIT>' <EOL> includeOff = '<STR_LIT>' <EOL> else : <EOL> includeOn = '<STR_LIT>' <EOL> includeOff = '<STR_LIT>' <EOL> separator = '<STR_LIT>' <EOL> parts = s2 . split ( includeOff ) <EOL> lastpart = parts [ - <NUM_LIT:1> ] <EOL> if re . match ( '<STR_LIT>' % marker , lastpart ) : <EOL> regexp = re . compile ( '<STR_LIT>' % ( includeOff , marker ) ) <EOL> newtext = regexp . sub ( s + includeOff , s2 ) <EOL> else : <EOL> newtext = s2 . replace ( marker , '<STR_LIT>' ) . strip ( ) + separator + u'<STR_LIT>' % ( includeOn , s , includeOff ) <EOL> else : <EOL> newtext = s2 . replace ( marker , '<STR_LIT>' ) . strip ( ) + separator + s <EOL> else : <EOL> newtext = s2 . replace ( marker , '<STR_LIT>' ) <EOL> return newtext <EOL> def interwikiFormat ( links , insite = None ) : <EOL> """<STR_LIT>""" <EOL> if insite is None : <EOL> insite = pywikibot . getSite ( ) <EOL> if not links : <EOL> return '<STR_LIT>' <EOL> ar = interwikiSort ( links . keys ( ) , insite ) <EOL> s = [ ] <EOL> for site in ar : <EOL> try : <EOL> link = links [ site ] . aslink ( forceInterwiki = True ) . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> s . append ( link ) <EOL> except AttributeError : <EOL> s . append ( getSite ( site ) . linkto ( links [ site ] , othersite = insite ) ) <EOL> if insite . lang in insite . family . interwiki_on_one_line : <EOL> sep = u'<STR_LIT:U+0020>' <EOL> else : <EOL> sep = u'<STR_LIT:\r\n>' <EOL> s = sep . join ( s ) + u'<STR_LIT:\r\n>' <EOL> return s <EOL> def interwikiSort ( sites , insite = None ) : <EOL> if insite is None : <EOL> insite = pywikibot . getSite ( ) <EOL> if not sites : <EOL> return [ ] <EOL> sites . sort ( ) <EOL> putfirst = insite . interwiki_putfirst ( ) <EOL> if putfirst : <EOL> firstsites = [ ] <EOL> for code in putfirst : <EOL> if code in insite . family . obsolete : <EOL> code = insite . family . obsolete [ code ] <EOL> if code in insite . validLanguageLinks ( ) : <EOL> site = insite . getSite ( code = code ) <EOL> if site in sites : <EOL> del sites [ sites . index ( site ) ] <EOL> firstsites = firstsites + [ site ] <EOL> sites = firstsites + sites <EOL> if insite . interwiki_putfirst_doubled ( sites ) : <EOL> sites = insite . interwiki_putfirst_doubled ( sites ) + sites <EOL> return sites <EOL> def getCategoryLinks ( text , site ) : <EOL> import catlib <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> text = removeDisabledParts ( text ) <EOL> catNamespace = '<STR_LIT:|>' . join ( site . category_namespaces ( ) ) <EOL> R = re . compile ( r'<STR_LIT>' % catNamespace , re . I ) <EOL> for match in R . finditer ( text ) : <EOL> cat = catlib . Category ( site , <EOL> '<STR_LIT>' % ( match . group ( '<STR_LIT>' ) , <EOL> match . group ( '<STR_LIT>' ) ) , <EOL> sortKey = match . group ( '<STR_LIT>' ) ) <EOL> result . append ( cat ) <EOL> return result <EOL> def removeCategoryLinks ( text , site , marker = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> catNamespace = '<STR_LIT:|>' . join ( site . category_namespaces ( ) ) <EOL> categoryR = re . compile ( r'<STR_LIT>' % catNamespace , re . I ) <EOL> text = replaceExcept ( text , categoryR , '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:source>' ] , <EOL> marker = marker ) <EOL> if marker : <EOL> text = re . sub ( '<STR_LIT>' % re . escape ( marker ) , '<STR_LIT:\r\n>' + marker , <EOL> text . strip ( ) ) <EOL> return text . strip ( ) <EOL> def removeCategoryLinksAndSeparator ( text , site = None , marker = '<STR_LIT>' , separator = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if separator : <EOL> mymarker = findmarker ( text , u'<STR_LIT>' ) <EOL> newtext = removeCategoryLinks ( text , site , mymarker ) <EOL> mymarker = expandmarker ( newtext , mymarker , separator ) <EOL> return newtext . replace ( mymarker , marker ) <EOL> else : <EOL> return removeCategoryLinks ( text , site , marker ) <EOL> def replaceCategoryInPlace ( oldtext , oldcat , newcat , site = None ) : <EOL> """<STR_LIT>""" <EOL> if site is None : <EOL> site = pywikibot . getSite ( ) <EOL> catNamespace = '<STR_LIT:|>' . join ( site . category_namespaces ( ) ) <EOL> title = oldcat . titleWithoutNamespace ( ) <EOL> if not title : <EOL> return <EOL> title = re . escape ( title ) <EOL> if title [ <NUM_LIT:0> ] . isalpha ( ) and not site . nocapitalize : <EOL> title = "<STR_LIT>" % ( title [ <NUM_LIT:0> ] . upper ( ) , title [ <NUM_LIT:0> ] . lower ( ) ) + title [ <NUM_LIT:1> : ] <EOL> title = title . replace ( r"<STR_LIT>" , "<STR_LIT>" ) . replace ( r"<STR_LIT>" , "<STR_LIT>" ) <EOL> categoryR = re . compile ( r'<STR_LIT>' <EOL> % ( catNamespace , title ) , re . I ) <EOL> if newcat is None : <EOL> text = replaceExcept ( oldtext , categoryR , '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:source>' ] ) <EOL> else : <EOL> text = replaceExcept ( oldtext , categoryR , <EOL> '<STR_LIT>' % ( site . namespace ( <NUM_LIT> ) , <EOL> newcat . titleWithoutNamespace ( ) ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:source>' ] ) <EOL> return text <EOL> def replaceCategoryLinks ( oldtext , new , site = None , addOnly = False ) : <EOL> """<STR_LIT>""" <EOL> marker = findmarker ( oldtext , u'<STR_LIT>' ) <EOL> if site is None : <EOL> site = pywikibot . getSite ( ) <EOL> if site . sitename ( ) == '<STR_LIT>' and "<STR_LIT>" in oldtext : <EOL> raise Error ( """<STR_LIT>""" ) <EOL> separator = site . family . category_text_separator <EOL> iseparator = site . family . interwiki_text_separator <EOL> separatorstripped = separator . strip ( ) <EOL> iseparatorstripped = iseparator . strip ( ) <EOL> if addOnly : <EOL> s2 = oldtext <EOL> else : <EOL> s2 = removeCategoryLinksAndSeparator ( oldtext , site = site , marker = marker , <EOL> separator = separatorstripped ) <EOL> s = categoryFormat ( new , insite = site ) <EOL> if s : <EOL> if site . language ( ) in site . family . category_attop : <EOL> newtext = s + separator + s2 <EOL> else : <EOL> firstafter = s2 . find ( marker ) <EOL> if firstafter < <NUM_LIT:0> : <EOL> firstafter = len ( s2 ) <EOL> else : <EOL> firstafter += len ( marker ) <EOL> if "<STR_LIT>" in s2 [ firstafter : ] : <EOL> if separatorstripped : <EOL> s = separator + s <EOL> newtext = s2 [ : firstafter ] . replace ( marker , '<STR_LIT>' ) + s + s2 [ firstafter : ] <EOL> elif site . language ( ) in site . family . categories_last : <EOL> newtext = s2 . replace ( marker , '<STR_LIT>' ) . strip ( ) + separator + s <EOL> else : <EOL> interwiki = getLanguageLinks ( s2 ) <EOL> s2 = removeLanguageLinksAndSeparator ( s2 . replace ( marker , '<STR_LIT>' ) , site , '<STR_LIT>' , iseparatorstripped ) + separator + s <EOL> newtext = replaceLanguageLinks ( s2 , interwiki , site = site , <EOL> addOnly = True ) <EOL> else : <EOL> newtext = s2 . replace ( marker , '<STR_LIT>' ) <EOL> return newtext . strip ( ) <EOL> def categoryFormat ( categories , insite = None ) : <EOL> """<STR_LIT>""" <EOL> if not categories : <EOL> return '<STR_LIT>' <EOL> if insite is None : <EOL> insite = pywikibot . getSite ( ) <EOL> catLinks = [ category . aslink ( noInterwiki = True ) for category in categories ] <EOL> if insite . category_on_one_line ( ) : <EOL> sep = '<STR_LIT:U+0020>' <EOL> else : <EOL> sep = '<STR_LIT:\r\n>' <EOL> return sep . join ( catLinks ) + '<STR_LIT:\r\n>' <EOL> def compileLinkR ( withoutBracketed = False , onlyBracketed = False ) : <EOL> """<STR_LIT>""" <EOL> notAtEnd = '<STR_LIT>' <EOL> notInside = '<STR_LIT>' <EOL> regex = r'<STR_LIT>' + notInside + '<STR_LIT>' + notAtEnd + '<STR_LIT>' + notAtEnd + '<STR_LIT>' + notInside + '<STR_LIT>' + notAtEnd + '<STR_LIT>' <EOL> if withoutBracketed : <EOL> regex = r'<STR_LIT>' + regex <EOL> elif onlyBracketed : <EOL> regex = r'<STR_LIT>' + regex <EOL> linkR = re . compile ( regex ) <EOL> return linkR <EOL> def extract_templates_and_params ( text , get_redirect = False ) : <EOL> """<STR_LIT>""" <EOL> thistxt = removeDisabledParts ( text ) <EOL> marker = u'<STR_LIT>' <EOL> while marker in thistxt : <EOL> marker += u'<STR_LIT:@>' <EOL> marker2 = u'<STR_LIT>' <EOL> while marker2 in thistxt : <EOL> marker2 += u'<STR_LIT:#>' <EOL> marker3 = u'<STR_LIT>' <EOL> while marker2 in thistxt : <EOL> marker3 += u'<STR_LIT:%>' <EOL> result = [ ] <EOL> inside = { } <EOL> count = <NUM_LIT:0> <EOL> Rtemplate = re . compile ( <EOL> ur '<STR_LIT>' ) <EOL> Rmath = re . compile ( ur '<STR_LIT>' ) <EOL> Rmarker = re . compile ( ur '<STR_LIT>' % ( marker , marker ) ) <EOL> Rmarker2 = re . compile ( ur '<STR_LIT>' % ( marker2 , marker2 ) ) <EOL> Rmarker3 = re . compile ( ur '<STR_LIT>' % ( marker3 , marker3 ) ) <EOL> maths = { } <EOL> count = <NUM_LIT:0> <EOL> for m in Rmath . finditer ( thistxt ) : <EOL> count += <NUM_LIT:1> <EOL> text = m . group ( ) <EOL> thistxt = thistxt . replace ( text , '<STR_LIT>' % ( marker3 , count , marker3 ) ) <EOL> maths [ count ] = text <EOL> while Rtemplate . search ( thistxt ) is not None : <EOL> for m in Rtemplate . finditer ( thistxt ) : <EOL> count += <NUM_LIT:1> <EOL> text = m . group ( ) <EOL> thistxt = thistxt . replace ( text , <EOL> '<STR_LIT>' % ( marker , count , marker ) ) <EOL> for m2 in Rmarker . finditer ( text ) : <EOL> text = text . replace ( m2 . group ( ) , inside [ int ( m2 . group ( <NUM_LIT:1> ) ) ] ) <EOL> for m2 in Rmarker3 . finditer ( text ) : <EOL> text = text . replace ( m2 . group ( ) , maths [ int ( m2 . group ( <NUM_LIT:1> ) ) ] ) <EOL> inside [ count ] = text <EOL> name = m . group ( '<STR_LIT:name>' ) . strip ( ) <EOL> m2 = Rmarker . search ( name ) or Rmath . search ( name ) <EOL> if m2 is not None : <EOL> continue <EOL> paramString = m . group ( '<STR_LIT>' ) <EOL> params = { } <EOL> numbered_param = <NUM_LIT:1> <EOL> if paramString : <EOL> links = { } <EOL> count2 = <NUM_LIT:0> <EOL> for m2 in pywikibot . link_regex . finditer ( paramString ) : <EOL> count2 += <NUM_LIT:1> <EOL> text = m2 . group ( <NUM_LIT:0> ) <EOL> paramString = paramString . replace ( text , <EOL> '<STR_LIT>' % ( marker2 , count2 , marker2 ) ) <EOL> links [ count2 ] = text <EOL> markedParams = paramString . split ( '<STR_LIT:|>' ) <EOL> for param in markedParams : <EOL> if "<STR_LIT:=>" in param : <EOL> param_name , param_val = param . split ( "<STR_LIT:=>" , <NUM_LIT:1> ) <EOL> else : <EOL> param_name = unicode ( numbered_param ) <EOL> param_val = param <EOL> numbered_param += <NUM_LIT:1> <EOL> for m2 in Rmarker . finditer ( param_val ) : <EOL> param_val = param_val . replace ( m2 . group ( ) , <EOL> inside [ int ( m2 . group ( <NUM_LIT:1> ) ) ] ) <EOL> for m2 in Rmarker2 . finditer ( param_val ) : <EOL> param_val = param_val . replace ( m2 . group ( ) , <EOL> links [ int ( m2 . group ( <NUM_LIT:1> ) ) ] ) <EOL> for m2 in Rmarker3 . finditer ( param_val ) : <EOL> param_val = param_val . replace ( m2 . group ( ) , <EOL> maths [ int ( m2 . group ( <NUM_LIT:1> ) ) ] ) <EOL> params [ param_name . strip ( ) ] = param_val . strip ( ) <EOL> result . append ( ( name , params ) ) <EOL> return result <EOL> def _altlang ( code ) : <EOL> """<STR_LIT>""" <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' ] <EOL> if code == '<STR_LIT>' : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT:bar>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code == '<STR_LIT>' : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code == '<STR_LIT>' : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code == '<STR_LIT>' : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code == '<STR_LIT>' : <EOL> return [ '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code == [ '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code == '<STR_LIT>' : <EOL> return [ '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' ] <EOL> if code == '<STR_LIT>' : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code == '<STR_LIT>' : <EOL> return [ '<STR_LIT>' , '<STR_LIT:id>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code == '<STR_LIT>' : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' ] <EOL> if code == '<STR_LIT>' : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' ] <EOL> if code == [ '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code == '<STR_LIT>' : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code == '<STR_LIT>' : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code == '<STR_LIT>' : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code == '<STR_LIT>' : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code == '<STR_LIT>' : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if code in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> return [ ] <EOL> def translate ( code , xdict ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( code , '<STR_LIT>' ) : <EOL> code = code . lang <EOL> if '<STR_LIT>' in xdict : <EOL> if pywikibot . default_family in xdict : <EOL> xdict = xdict [ pywikibot . default_family ] <EOL> else : <EOL> xdict = xdict [ '<STR_LIT>' ] <EOL> if type ( xdict ) != dict : <EOL> return xdict <EOL> if code in xdict : <EOL> return xdict [ code ] <EOL> for alt in _altlang ( code ) : <EOL> if alt in xdict : <EOL> return xdict [ alt ] <EOL> if '<STR_LIT>' in xdict : <EOL> return xdict [ '<STR_LIT>' ] <EOL> elif '<STR_LIT>' in xdict : <EOL> return xdict [ '<STR_LIT>' ] <EOL> return xdict . values ( ) [ <NUM_LIT:0> ] </s>
