generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move pom parser to parsers module (#863)
Signed-off-by: Ben Selwyn-Smith <[email protected]>
- Loading branch information
Showing
2 changed files
with
37 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (c) 2024 - 2024, Oracle and/or its affiliates. All rights reserved. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. | ||
|
||
"""This module contains the parser for POM files.""" | ||
import logging | ||
from xml.etree.ElementTree import Element # nosec | ||
|
||
import defusedxml.ElementTree | ||
from defusedxml.ElementTree import fromstring | ||
|
||
logger: logging.Logger = logging.getLogger(__name__) | ||
|
||
|
||
def parse_pom_string(pom_string: str) -> Element | None: | ||
""" | ||
Parse the passed POM string using defusedxml. | ||
Parameters | ||
---------- | ||
pom_string : str | ||
The contents of a POM file as a string. | ||
Returns | ||
------- | ||
Element | None | ||
The parsed element representing the POM's XML hierarchy. | ||
""" | ||
try: | ||
# Stored here first to help with type checking. | ||
pom: Element = fromstring(pom_string) | ||
return pom | ||
except defusedxml.ElementTree.ParseError as error: | ||
logger.debug("Failed to parse XML: %s", error) | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters