From 7aaac10a00426fdbd89eb54ebdeecb061040a17a 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 --- cloud/rax_facts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cloud/rax_facts b/cloud/rax_facts index 866c1ab97c6..feb20004122 100644 --- a/cloud/rax_facts +++ b/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