Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I have never heard of this problem, but just shooing from the hip, I think this will solve your problem. This creates a decorator which inspects all the inputs to calls to functions in the dyntools module and takes those which are unicode and converts them to strings.

import types
def UnicodeToStrDecorator(psseFunc):
    def callPsseFunc(*args, **kwargs):
        newArgs = []
        newKwargs = {}
        # Sanitize args and kwargs for unicode
        for a in args:
            if type(a) is unicode:
                newArgs.append(str(a))
            else:
                newArgs.append(a)

        for k, v in kwargs.items():
            if type(v) is unicode:
                newKwargs[k] = str(v)
            else:
                newKwargs[k] = v

        # Call origional psse function with new, sanitized arguments
        return psseFunc(*newArgs, **newKwargs)
    return callPsseFunc

import dyntools, psse_env_manager 

# Apply decorator the dyntools module
for k,v in vars(dyntools).items():
    if isinstance(v, types.FunctionType):
        vars(dyntools)[k] = UnicodeToStrDecorator(v)

# Apply decorator to psse_env_manager module
for k,v in vars(psse_env_manager).items():
    if isinstance(v, types.FunctionType):
        vars(psse_env_manager)[k] = UnicodeToStrDecorator(v)