Skip to content

Commit c088564

Browse files
committed
dynamic style types
1 parent 71ec8a7 commit c088564

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/geoserver/catalog.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ def get_styles(self, names=None, workspaces=None):
10451045
# Add global styles
10461046
url = "{}/styles.xml".format(self.service_url)
10471047
styles = self.get_xml(url)
1048-
all_styles.extend([Style(self, s.find('name').text) for s in styles.findall("style")])
1048+
all_styles.extend(self.__build_style_list(styles))
10491049
workspaces = []
10501050
elif isinstance(workspaces, string_types):
10511051
workspaces = [s.strip() for s in workspaces.split(',') if s.strip()]
@@ -1069,8 +1069,7 @@ def get_styles(self, names=None, workspaces=None):
10691069
continue
10701070
else:
10711071
raise FailedRequestError("Failed to get styles: {}".format(e))
1072-
1073-
all_styles.extend([Style(self, s.find("name").text, _name(ws)) for s in styles.findall("style")])
1072+
all_styles.extend(self.__build_style_list(styles, ws))
10741073

10751074
if names is None:
10761075
names = []
@@ -1082,6 +1081,15 @@ def get_styles(self, names=None, workspaces=None):
10821081

10831082
return all_styles
10841083

1084+
def __build_style_list(self, styles_tree, ws=None):
1085+
all_styles = []
1086+
for s in styles_tree.findall("style"):
1087+
style_format = self.get_xml(s[1].attrib.get('href')).find('format').text
1088+
style_version = self.get_xml(s[1].attrib.get('href')).find('languageVersion').find(
1089+
'version').text.replace('.', '')[:-1]
1090+
all_styles.append(Style(self, s.find("name").text, _name(ws), style_format + style_version))
1091+
return all_styles
1092+
10851093
def get_style(self, name, workspace=None):
10861094
'''
10871095
returns a single style object.

src/geoserver/style.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919

2020

2121
class Style(ResourceInfo):
22-
supported_formats = ["sld10", "sld11", "zip"]
22+
supported_formats = ["sld10", "sld11", "zip10", "css10"]
2323
content_types = {
2424
"sld10": "application/vnd.ogc.sld+xml",
2525
"sld11": "application/vnd.ogc.se+xml",
26-
"zip": "application/zip"
26+
"zip10": "application/zip",
27+
"css10": "application/vnd.geoserver.geocss+css",
28+
2729
}
2830

2931
def __init__(self, catalog, name, workspace=None, style_format="sld10"):
@@ -114,6 +116,11 @@ def sld_body(self):
114116
resp = self.catalog.http_request(self.body_href)
115117
return resp.content
116118

119+
@property
120+
def body(self):
121+
resp = self.catalog.http_request(self._build_href('.{}'.format(self.style_format)))
122+
return resp.content
123+
117124
def update_body(self, body):
118125
headers = {"Content-Type": self.content_type}
119126
self.catalog.http.request(

0 commit comments

Comments
 (0)