follow suit with the rax refactor and split out the slugify code

pull/4918/head
Matt Martz 11 years ago
parent 545aabaddc
commit fa4e55d677

@ -90,14 +90,16 @@ except ImportError:
NON_CALLABLES = (basestring, bool, dict, int, list, NoneType) NON_CALLABLES = (basestring, bool, dict, int, list, NoneType)
def rax_slugify(value):
return 'rax_%s' % (re.sub('[^\w-]', '_', value).lower().lstrip('_'))
def pyrax_object_to_dict(obj): def pyrax_object_to_dict(obj):
instance = {} instance = {}
for key in dir(obj): for key in dir(obj):
value = getattr(obj, key) value = getattr(obj, key)
if (isinstance(value, NON_CALLABLES) and not key.startswith('_')): if (isinstance(value, NON_CALLABLES) and not key.startswith('_')):
key = 'rax_' + (re.sub('[^A-Za-z0-9\-]', '_', key) key = rax_slugify(key)
.lower()
.lstrip('_'))
instance[key] = value instance[key] = value
return instance return instance

Loading…
Cancel
Save