diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-01-25 05:11:21 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-01-25 05:11:21 +0000 |
| commit | c8cab3395432983c2165dce196ad5204e420a900 (patch) | |
| tree | 3ef0a4b85c612513ac79779db28763f39e11907c /repoze/bfg/security.py | |
| parent | e5cf7dbec2ccda7d2e4d79815ac441acf2ab1061 (diff) | |
| download | pyramid-c8cab3395432983c2165dce196ad5204e420a900.tar.gz pyramid-c8cab3395432983c2165dce196ad5204e420a900.tar.bz2 pyramid-c8cab3395432983c2165dce196ad5204e420a900.zip | |
Optimize flatten a bit.
Diffstat (limited to 'repoze/bfg/security.py')
| -rw-r--r-- | repoze/bfg/security.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/repoze/bfg/security.py b/repoze/bfg/security.py index 4e61b0ed9..693f253d0 100644 --- a/repoze/bfg/security.py +++ b/repoze/bfg/security.py @@ -312,12 +312,15 @@ def flatten(x): [1, 2, [3, 4], (5, 6)] >>> flatten([[[1,2,3], (42,None)], [4,5], [6], 7, MyVector(8,9,10)]) [1, 2, 3, 42, None, 4, 5, 6, 7, 8, 9, 10]""" - if isinstance(x, basestring): + if not hasattr(x, '__iter__'): return [x] + return _flatten(x) + +def _flatten(iterable): result = [] - for el in x: - if hasattr(el, "__iter__") and not isinstance(el, basestring): - result.extend(flatten(el)) + for el in iterable: + if hasattr(el, "__iter__"): + result.extend(_flatten(el)) else: result.append(el) return result |
