summaryrefslogtreecommitdiff
path: root/python/skytools/parsing.py
diff options
context:
space:
mode:
authorMarko Kreen2010-03-12 12:17:31 +0000
committerMarko Kreen2010-03-12 12:17:31 +0000
commita80e9efe2f7b74b99be95a2bcf011e20eb706a01 (patch)
treeec5ca48d2676ebf425cf4de2a865eccf075da137 /python/skytools/parsing.py
parent897266c35d343dfef3640bfd8db7831ded5aee77 (diff)
skytools.parse_pgarray(): ignore dimension prefix
Diffstat (limited to 'python/skytools/parsing.py')
-rw-r--r--python/skytools/parsing.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/python/skytools/parsing.py b/python/skytools/parsing.py
index 4b92306e..908f7f09 100644
--- a/python/skytools/parsing.py
+++ b/python/skytools/parsing.py
@@ -12,7 +12,6 @@ __all__ = [
_rc_listelem = re.compile(r'( [^,"}]+ | ["] ( [^"\\]+ | [\\]. )* ["] )', re.X)
-# _parse_pgarray
def parse_pgarray(array):
r"""Parse Postgres array and return list of items inside it.
@@ -23,11 +22,18 @@ def parse_pgarray(array):
['a', 'b', None, 'null']
>>> parse_pgarray(r'{"a,a","b\"b","c\\c"}')
['a,a', 'b"b', 'c\\c']
+ >>> parse_pgarray("[0,3]={1,2,3}")
+ ['1', '2', '3']
"""
- if not array or array[0] != "{" or array[-1] != '}':
+ if not array or array[0] not in ("{", "[") or array[-1] != '}':
raise Exception("bad array format: must be surrounded with {}")
res = []
pos = 1
+ # skip optional dimensions descriptor "[a,b]={...}"
+ if array[0] == "[":
+ pos = array.find('{') + 1
+ if pos < 1:
+ raise Exception("bad array format: must be surrounded with {}")
while 1:
m = _rc_listelem.search(array, pos)
if not m: