예제 #1
0
    def __init__(self, name='', array=None, maps=None, attributes=None):
        self.name = quote(name)
        self.array = array
        self.maps = maps or odict()
        self.attributes = attributes or {}

        self._id = name
        self._filters = []
예제 #2
0
def parse_querystring(query):
    """
    Parse a query_string returning the requested variables, dimensions, and CEs.

        >>> parse_querystring('a,b')
        ({'a': (slice(None, None, None),), 'b': (slice(None, None, None),)}, [])
        >>> parse_querystring('a[0],b[1]')
        ({'a': (slice(0, 1, 1),), 'b': (slice(1, 2, 1),)}, [])
        >>> parse_querystring('a[0],b[1]&foo.bar>1')
        ({'a': (slice(0, 1, 1),), 'b': (slice(1, 2, 1),)}, ['foo.bar>1'])
        >>> parse_querystring('a[0],b[1]&foo.bar>1&LAYERS=SST')
        ({'a': (slice(0, 1, 1),), 'b': (slice(1, 2, 1),)}, ['foo.bar>1', 'LAYERS=SST'])
        >>> parse_querystring('foo.bar>1&LAYERS=SST')
        ({}, ['foo.bar>1', 'LAYERS=SST'])

    """
    if query is None:  return {}, []

    query = unquote(query)
    constraints = query.split('&')

    # Check if the first item is either a list of variables (projection)
    # or a selection.
    relops = ['<', '<=', '>', '>=', '=', '!=',' =~']
    for relop in relops:
        if relop in constraints[0]:
            vars_ = []
            queries = constraints[:]
            break
    else:
        vars_ = constraints[0].split(',')
        queries = constraints[1:]
    
    fields = odict()
    p = re.compile(r'(?P<name>[^[]+)(?P<shape>(\[[^\]]+\])*)')
    for var in vars_:
        if var:
            # Check if the var has a slice.
            c = p.match(var).groupdict()
            id_ = quote(c['name'])
            fields[id_] = getslice(c['shape'])

    return fields, queries