(array)
return res
r"""Parse Postgres array and return list of items inside it.

    Examples:
    >>> parse_pgarray('{}')
    []
    >>> parse_pgarray('{a,b,null,"null"}')
    ['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']
r"""Parse Postgres array and return list of items inside it.
r Parse Postgres array and return list of items inside it .
def parse_pgarray(array):
    r"""Parse Postgres array and return list of items inside it.

    Examples:
    >>> parse_pgarray('{}')
    []
    >>> parse_pgarray('{a,b,null,"null"}')
    ['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 array is None:
        return None
    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:
            break
        pos2 = m.end()
        item = array[pos:pos2]
        if len(item) == 4 and item.upper() == "NULL":
            val = None
        else:
            if len(item) > 0 and item[0] == '"':
                if len(item) == 1 or item[-1] != '"':
                    raise Exception("bad array format: broken '\"'")
                item = item[1:-1]
            val = skytools.unescape(item)
        res.append(val)

        pos = pos2 + 1
        if array[pos2] == "}":
            break
        elif array[pos2] != ",":
            raise Exception("bad array format: expected ,} got " + repr(array[pos2]))
    if pos < len(array) - 1:
        raise Exception("bad array format: failed to parse completely (pos=%d len=%d)" % (pos, len(array)))
    return res
def parse_pgarray ( array ) : if array is None : return None 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 : break pos2 = m . end ( ) item = array [ pos : pos2 ] if len ( item ) == 4 and item . upper ( ) == "NULL" : val = None else : if len ( item ) > 0 and item [ 0 ] == '"' : if len ( item ) == 1 or item [ - 1 ] != '"' : raise Exception ( "bad array format: broken '\"'" ) item = item [ 1 : - 1 ] val = skytools . unescape ( item ) res . append ( val ) pos = pos2 + 1 if array [ pos2 ] == "}" : break elif array [ pos2 ] != "," : raise Exception ( "bad array format: expected ,} got " + repr ( array [ pos2 ] ) ) if pos < len ( array ) - 1 : raise Exception ( "bad array format: failed to parse completely (pos=%d len=%d)" % ( pos , len ( array ) ) ) return res