import unittest
def formatstr(formatDict):
    result=[]
    if formatDict['fill'] and formatDict['align']:
        result.append(str(formatDict['fill']))
    if formatDict['align']:
        result.append(str(formatDict['align']))
    if formatDict['sign']:
        result.append(str(formatDict['sign']))
    if formatDict['alternate']:
        result.append(str(formatDict['alternate']))
    if formatDict['zeropadding']:
        result.append(str(formatDict['zeropadding']))
    if formatDict['width']:
        result.append(str(formatDict['width']))
    if formatDict['precision']:
        result.append('.')
        result.append(str(formatDict['precision']))
    if formatDict['type']:
        result.append(str(formatDict['type']))
    return ''.join(result)
def uni2int(val,formatDict,*args,**kwargs):
    if type(val) not in [str,unicode]:
        return ('{0:'+formatstr(formatDict)+'}').format(val)
    return ord(val.strip())
def perc2float(val,formatDict,*args,**kwargs):
    if type(val)!=str:
        return ('{0:'+formatstr(formatDict)+'}').format(val)
    return float(val.rstrip('%'))/100.0
def floatparse(val,formatDict,*args,**kwargs):
    if type(val)!=str:
        return ('{0:'+formatstr(formatDict)+'}').format(val)
    sign=1
    if formatDict['sign']=='-':
        sign=-1 
    if val.isspace():
        return None
    if '?' in val:
        return None
    if not formatDict['precision']:    
        return sign*float(val.strip(' ').replace(' ','0'))
    else:
        try:
            return sign*float(val)
        except:
            pass   
        dec=int(formatDict['precision'])
        integer=int(len(val.replace('.','')))-dec
        return sign*(float('0'+val[:integer].strip(' '))+float('.'+val[-dec:]).strip(' ')+'0')
def intparse(val,formatDict,*args,**kwargs):
    if type(val)!=str:
        return ('{0:'+formatstr(formatDict)+'}').format(val)
    sign=1
    if formatDict['sign']=='-':
        sign=-1 
    return sign*int(val,*args)
def strparse(val,formatDict,*args,**kwargs):
    if type(val)!=str:
        return ('{0:'+formatstr(formatDict)+'}').format(val)