From 383cda4052a67563ce436b3c0b367795fca247f9 Mon Sep 17 00:00:00 2001 From: Michael Buesch Date: Sat, 4 Aug 2018 20:54:37 +0200 Subject: Add isiterable helper Signed-off-by: Michael Buesch --- cms/cms.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cms/cms.py b/cms/cms.py index 89fc5a6..e204ce4 100644 --- a/cms/cms.py +++ b/cms/cms.py @@ -38,6 +38,17 @@ UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' LOWERCASE = 'abcdefghijklmnopqrstuvwxyz' NUMBERS = '0123456789' +# Check if an object is iterable. +def isiterable(obj): + try: + iter(obj) + return True + except TypeError: + pass # obj is not an iterable. + except Exception: + raise CMSException(500, "isiterable: Unexpected exception.") + return False + # Find the index in 'string' that is _not_ in 'template'. # Start search at 'idx'. # Returns -1 on failure to find. -- cgit v1.2.3