Changeset 648

Show
Ignore:
Timestamp:
03/28/07 08:35:47
Author:
cph
Message:

fixes #104:better compatability with mapserver attribute notation in filters

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • PCL/trunk/PCL-Core/cartography/data/postgis.py

    r631 r648  
    9898from zope.interface import implements 
    9999 
     100PATTERN_ATTR_WITHOUT_F=re.compile(r"[^f](\[[a-z 0-9_\"\']+\])|^(\[[a-z 0-9_\"\']+\])") 
     101PATTERN_ATTR=re.compile(r"\[([a-z 0-9_\"\']+)\]") 
    100102 
    101103# ============================================================================ 
     
    770772        self.hasfrontfilter = 0 
    771773        if filter is not None: 
     774            while 1: 
     775                match = PATTERN_ATTR_WITHOUT_F.search(filter) 
     776                if not match: 
     777                    break; 
     778                repl = match.group(1) or match.group(2) 
     779                attrMatch = PATTERN_ATTR.search(repl) 
     780                if attrMatch.group(1)[0] not in ["'", '"']: 
     781                    unquotedAttr = attrMatch.group(1) 
     782                    filter = filter.replace(repl,"f['"+unquotedAttr+"']") 
     783                else: 
     784                    filter = filter.replace(repl,"f"+repl) 
     785 
    772786            self._compiled_filter = compile(filter, 'string', 'eval') 
    773787            self._locals = {} 
  • PCL/trunk/PCL-Core/tests/testpgfeatures.py

    r544 r648  
    355355            i += 1 
    356356        self.assert_(i == 46, i) 
     357    def filter_test(self,subfilt): 
     358        b = BoundingBox(-10, 45, 10, 60) 
     359        source = self.store.source(TYPENAME0, bbox=b) 
     360        def func(s): 
     361            return s.lower() 
     362        ff = "func(%s) == 'uk'" % subfilt 
     363        fiter = source(filter=ff, func=func) 
     364        i = 0 
     365        for feature in fiter: 
     366            i += 1 
     367        self.assert_(i == 46, subfilt) 
     368    def test_filters(self): 
     369        for filt in ( "[fips_cntry]", "['fips_cntry']", '["fips_cntry"]',  
     370                        "f['fips_cntry']", "f.fips_cntry"): 
     371            self.filter_test(filt) 
    357372    def test_front_geom(self): 
    358373        b = BoundingBox(-10, 45, 10, 60)