Redaktor:Atomobot/atomobot misc.py

z Wikipédie, slobodnej encyklopédie
#!/usr/bin/python2.4
# -*- coding: utf-8  -*-


def matches_list( text, lst ):
    for rexp in lst:
        m = rexp.match( text )
        if m:
            return True
    return False


def lowercase_sort( lst ):
    lst2 = [ ( item.lower(), item ) for item in lst ]
    lst2.sort()
    return [ item for litem, item in lst2 ]


def dewikize( text ):
    if text.startswith( '[[' ) and text.endswith( ']]' ):
        return text[ 2:-2 ]
    return text


def dequotize( text ):
    if text.startswith( '"' ) and text.endswith( '"' ):
        return text[ 1:-1 ]
    return text