Lino Website

code changes

New function ispure()

Sunday, 26. February 2006 13:31.

New function lino.misc.etc.ispure() tests whether a string is «pure»: either pure ASCII or Unicode, but not a simple string with non-ascii characters

def ispure(s):
    if s is None: return True
    if type(s) == types.UnicodeType:
        return True
    if type(s) == types.StringType:
        try:
            s.decode('ascii')
        except UnicodeDecodeError,e:
            return False
        return True
    return False

This is used at different places.

Refering articles:

Copyright 2001-2007 Luc Saffre.
http://lino.saffre-rumma.ee
Generated 2007-06-07 16:22:39