|
13 | 13 | from maelstro.common.exceptions import ParamError |
14 | 14 | from .georchestra import GeorchestraHandler |
15 | 15 | from .operations import raise_for_status |
16 | | - |
| 16 | +import xml.etree.ElementTree as ET |
17 | 17 |
|
18 | 18 | logger = logging.getLogger() |
19 | 19 |
|
@@ -356,25 +356,28 @@ def copy_layer( |
356 | 356 | ) |
357 | 357 | resource = gs_src.rest_client.get(xml_resource_route) |
358 | 358 |
|
| 359 | + # Clean <attributes> element to avoid "Custom attributes" checkbox being set |
| 360 | + # See issue #94 |
| 361 | + cleaned_content = self.remove_attributes_element(resource.content) |
359 | 362 | if has_resource.status_code == 200: |
360 | 363 | if has_layer.status_code != 200: |
361 | 364 | resp = self.gs_dst.rest_client.delete(resource_route) |
362 | 365 | raise_for_status(resp) |
363 | 366 | resp = self.gs_dst.rest_client.post( |
364 | 367 | resource_post_route, |
365 | | - data=resource.content, |
| 368 | + data=cleaned_content, |
366 | 369 | headers={"content-type": "application/xml"}, |
367 | 370 | ) |
368 | 371 | else: |
369 | 372 | resp = self.gs_dst.rest_client.put( |
370 | 373 | xml_resource_route, |
371 | | - data=resource.content, |
| 374 | + data=cleaned_content, |
372 | 375 | headers={"content-type": "application/xml"}, |
373 | 376 | ) |
374 | 377 | else: |
375 | 378 | resp = self.gs_dst.rest_client.post( |
376 | 379 | resource_post_route, |
377 | | - data=resource.content, |
| 380 | + data=cleaned_content, |
378 | 381 | headers={"content-type": "application/xml"}, |
379 | 382 | ) |
380 | 383 | if resp.status_code == 404: |
@@ -425,3 +428,13 @@ def copy_style( |
425 | 428 | headers={"content-type": style_def.headers["content-type"]}, |
426 | 429 | ) |
427 | 430 | raise_for_status(dst_style_def) |
| 431 | + |
| 432 | + def remove_attributes_element(self, xml_bytes: bytes) -> Any: |
| 433 | + root = ET.fromstring(xml_bytes) |
| 434 | + if root is not None: |
| 435 | + attributes = root.find("attributes") |
| 436 | + if attributes is not None: |
| 437 | + root.remove(attributes) |
| 438 | + return ET.tostring(root, encoding="utf-8") |
| 439 | + # If root is None, return the original bytes or handle as needed |
| 440 | + return ET.tostring(root, encoding="utf-8") |
0 commit comments