Coverage for gws-app/gws/base/layer/ows.py: 88%

40 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-05 13:35 +0200

1"""Layer OWS binding.""" 

2 

3from typing import Optional 

4 

5import gws 

6import gws.lib.xmlx 

7import gws.config.util 

8 

9 

10class Config(gws.Config): 

11 """OWS service settings for a layer.""" 

12 

13 allowedServices: Optional[list[str]] 

14 """UIDs of OWS services allowed to publish this layer.""" 

15 deniedServices: Optional[list[str]] 

16 """UIDs of OWS services that must not publish this layer.""" 

17 featureName: str = '' 

18 """Feature type name in WFS.""" 

19 geometryName: str = '' 

20 """Name of the geometry element in WFS and GML output.""" 

21 layerName: str = '' 

22 """Layer name in WMS and WMTS services.""" 

23 xmlns: Optional[str] 

24 """XML namespace prefix for the layer's features.""" 

25 models: Optional[list[gws.ext.config.model]] 

26 """Data models for OWS output.""" 

27 

28 

29class Object(gws.LayerOwsBinding): 

30 """Binding of a layer to OWS services.""" 

31 

32 def configure(self): 

33 self.allowedServiceUids = self.cfg('allowedServices', default=[]) 

34 self.deniedServiceUids = self.cfg('deniedServices', default=[]) 

35 self.xmlNamespace = None 

36 

37 p = self.cfg('xmlns') 

38 if p: 

39 self.xmlNamespace = self._namespace(p) 

40 

41 self.layerName = self._configure_name('layerName') or self.cfg('_defaultName') 

42 self.featureName = self._configure_name('featureName') or self.cfg('_defaultName') 

43 # NB geometryName might come from a model later on 

44 self.geometryName = self._configure_name('geometryName') or '' 

45 

46 gws.config.util.configure_models_for(self) 

47 

48 def _configure_name(self, key): 

49 """Read a name from the config and set the XML namespace from its prefix, if any.""" 

50 p = self.cfg(key) 

51 if not p: 

52 return 

53 _, prefix, pname = gws.lib.xmlx.namespace.parse_name(p) 

54 if prefix: 

55 self.xmlNamespace = self._namespace(prefix) 

56 return pname 

57 

58 def _namespace(self, prefix): 

59 """Find a known XML namespace by its prefix or raise a configuration error.""" 

60 ns = gws.lib.xmlx.namespace.find_by_prefix(prefix) 

61 if not ns: 

62 raise gws.ConfigurationError(f'unknown XML namespace {prefix!r}') 

63 return ns