aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Buesch <m@bues.ch>2018-08-04 20:54:37 +0200
committerMichael Buesch <m@bues.ch>2018-08-04 20:54:37 +0200
commit383cda4052a67563ce436b3c0b367795fca247f9 (patch)
tree06b3558bf9354976fa499e336474444ac6b696ab
parentd6cc0b0910197e3455f56bc487e5cc1fae8aef6c (diff)
downloadcms-383cda4052a67563ce436b3c0b367795fca247f9.zip
cms-383cda4052a67563ce436b3c0b367795fca247f9.tar.xz
Add isiterable helper
Signed-off-by: Michael Buesch <m@bues.ch>
-rw-r--r--cms/cms.py11
1 files changed, 11 insertions, 0 deletions
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.
bues.ch cgit interface