Example #1
0
def getStringIO(buf=None):
    '''unified StringIO instance interface'''
    return buf is not None and __StringIO(buf) or __StringIO()
Example #2
0
        from PIL import Image
    except ImportError:
        try:
            import Image
        except ImportError:
            Image = None
    haveImages = Image is not None

try:
    from io import StringIO as __StringIO
except ImportError:
    from io import StringIO as __StringIO
def getStringIO(buf=None):
    '''unified StringIO instance interface'''
    return buf is not None and __StringIO(buf) or __StringIO()
_StringIOKlass=__StringIO().__class__

class ArgvDictValue:
    '''A type to allow clients of getArgvDict to specify a conversion function'''
    def __init__(self,value,func):
        self.value = value
        self.func = func

def getArgvDict(**kw):
    ''' Builds a dictionary from its keyword arguments with overrides from sys.argv.
        Attempts to be smart about conversions, but the value can be an instance
        of ArgDictValue to allow specifying a conversion function.
    '''
    def handleValue(v,av,func):
        if func:
            v = func(av)