Skip to content

Commit

Permalink
add flattenSequence to PythonUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
hefischer committed Jul 6, 2015
1 parent 85b9d03 commit 26edc95
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion arelle/PythonUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,20 @@ def pyTypeName(object):
fullname += '-dateTime'
return fullname
except:
return str(type(object))
return str(type(object))

SEQUENCE_TYPES = (tuple,list,set)
def flattenSequence(x, sequence=None):
if sequence is None:
if not isinstance(x, SEQUENCE_TYPES):
if x is None:
return [] # none as atomic value is an empty sequence in xPath semantics
return [x]
sequence = []
for el in x:
if isinstance(el, SEQUENCE_TYPES):
flattenSequence(el, sequence)
else:
sequence.append(el)
return sequence

0 comments on commit 26edc95

Please sign in to comment.