From fa4e55d6778e7e32543731047664d0729e78aa79 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Fri, 15 Nov 2013 12:00:32 -0600 Subject: [PATCH] follow suit with the rax refactor and split out the slugify code --- library/cloud/rax_facts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/library/cloud/rax_facts b/library/cloud/rax_facts index 866c1ab97c..feb2000412 100644 --- a/library/cloud/rax_facts +++ b/library/cloud/rax_facts @@ -90,14 +90,16 @@ except ImportError: 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): instance = {} for key in dir(obj): value = getattr(obj, key) if (isinstance(value, NON_CALLABLES) and not key.startswith('_')): - key = 'rax_' + (re.sub('[^A-Za-z0-9\-]', '_', key) - .lower() - .lstrip('_')) + key = rax_slugify(key) instance[key] = value return instance