(attr, camel_killer=False)
return re.sub('_+', '_', out)
Convert a key into something that is accessible as an attribute
Convert a key into something that is accessible as an attribute
Convert a key into something that is accessible as an attribute
def safe_attr(attr, camel_killer=False):
    """Convert a key into something that is accessible as an attribute"""
    allowed = string.ascii_letters + string.digits + '_'

    attr = _safe_key(attr)

    if camel_killer:
        attr = _camel_killer(attr)

    attr = attr.replace(' ', '_')

    out = ''
    for character in attr:
        out += character if character in allowed else "_"
    out = out.strip("_")

    try:
        int(out[0])
    except (ValueError, IndexError):
        pass
    else:
        out = '{}{}'.format(DEFAULT_STARTING_CHAR, out)

    if out in ILLEGAL_ATTRIBUTES:
        out = '{}{}'.format(DEFAULT_STARTING_CHAR, out)

    return re.sub('_+', '_', out)
def safe_attr ( attr , camel_killer = False ) : allowed = string . ascii_letters + string . digits + '_' attr = _safe_key ( attr ) if camel_killer : attr = _camel_killer ( attr ) attr = attr . replace ( ' ' , '_' ) out = '' for character in attr : out += character if character in allowed else "_" out = out . strip ( "_" ) try : int ( out [ 0 ] ) except ( ValueError , IndexError ) : pass else : out = '{}{}' . format ( DEFAULT_STARTING_CHAR , out ) if out in ILLEGAL_ATTRIBUTES : out = '{}{}' . format ( DEFAULT_STARTING_CHAR , out ) return re . sub ( '_+' , '_' , out )