Beispiel #1
0
def params_from_strings( params, param_values, app, ignore_errors=False ):
    """
    Convert a dictionary of strings as produced by `params_to_strings`
    back into parameter values (decode the json representation and then
    allow each parameter to convert the basic types into the parameters
    preferred form).
    """
    rval = dict()
    for key, value in param_values.iteritems():
        value = json_fix( loads( value ) )
        if key in params:
            value = params[ key ].value_from_basic( value, app, ignore_errors )
        rval[ key ] = value
    return rval
Beispiel #2
0
def params_from_strings(params, param_values, app, ignore_errors=False):
    """
    Convert a dictionary of strings as produced by `params_to_strings`
    back into parameter values (decode the json representation and then
    allow each parameter to convert the basic types into the parameters
    preferred form).
    """
    rval = dict()
    for key, value in param_values.iteritems():
        value = json_fix(loads(value))
        if key in params:
            value = params[key].value_from_basic(value, app, ignore_errors)
        rval[key] = value
    return rval
Beispiel #3
0
def tool_shed_decode( value ):
    # Extract and verify hash
    a, b = value.split( ":" )
    value = binascii.unhexlify( b )
    test = hmac_new( 'ToolShedAndGalaxyMustHaveThisSameKey', value )
    assert a == test
    # Restore from string
    values = None
    try:
        values = json.loads( value )
    except Exception, e:
        pass
    if values is not None:
        try:
            return json_fix( values )
        except Exception, e:
            log.debug( "Fixing decoded json values '%s' from tool shed threw exception: %s" % ( str( values ), str( e ) ) )
    if values is None:
        values = value
    return values


def tool_shed_encode( val ):
    if isinstance( val, dict ) or isinstance( val, list ):
        value = json.dumps( val )
    else:
        value = val
    a = hmac_new( 'ToolShedAndGalaxyMustHaveThisSameKey', value )
    b = binascii.hexlify( value )
    return "%s:%s" % ( a, b )
Beispiel #4
0
def tool_shed_decode(value):
    # Extract and verify hash
    a, b = value.split(":")
    value = binascii.unhexlify(b)
    test = hmac_new('ToolShedAndGalaxyMustHaveThisSameKey', value)
    assert a == test
    # Restore from string
    values = None
    try:
        values = json.loads(value)
    except Exception, e:
        pass
    if values is not None:
        try:
            return json_fix(values)
        except Exception, e:
            log.debug(
                "Fixing decoded json values '%s' from tool shed threw exception: %s"
                % (str(values), str(e)))
    if values is None:
        values = value
    return values


def tool_shed_encode(val):
    if isinstance(val, dict) or isinstance(val, list):
        value = json.dumps(val)
    else:
        value = val
    a = hmac_new('ToolShedAndGalaxyMustHaveThisSameKey', value)