Skip to content

Commit

Permalink
Coverage/enhance (#46)
Browse files Browse the repository at this point in the history
* remove `extract_namespaces` function

* `CHANGELOG.md` updated

* remove unused imports

* run `autopep8.sh`
  • Loading branch information
AHReccese authored Jan 8, 2025
1 parent d5349f1 commit 9e88132
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Removed
- `extract_namespaces` function in `util.py`
### Added
- `DMetaBaseError` added to `dmeta/__init__.py`
### Changed
Expand Down
3 changes: 1 addition & 2 deletions dmeta/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def clear(microsoft_file_name, in_place=False):
xml_element.text = ""
e_app.write(app_xml_path)


modified = microsoft_file_name
if not in_place:
modified = microsoft_file_name[:microsoft_file_name.rfind('.')] + "_cleared" + "." + microsoft_format
Expand All @@ -58,7 +57,7 @@ def clear(microsoft_file_name, in_place=False):
def clear_all(in_place=False):
"""
Clear all the editable metadata in any microsoft file in the current directory.
:param in_place: the `in_place` flag applies the changes directly to the original file
:type in_place: bool
:return: None
Expand Down
22 changes: 0 additions & 22 deletions dmeta/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,11 @@
import json
from shutil import rmtree
from zipfile import ZipFile
import defusedxml.ElementTree as ET
from .params import SUPPORTED_MICROSOFT_FORMATS, NOT_IMPLEMENTED_ERROR, \
FILE_FORMAT_DOES_NOT_EXIST_ERROR, INVALID_CONFIG_FILE_NAME_ERROR, CONFIG_FILE_DOES_NOT_EXIST_ERROR
from .errors import DMetaBaseError


def extract_namespaces(xml_file_path):
"""
Return used namespaces in the associated xml file.
:param xml_file_path: path to the xml file
:type xml_file_path: str
:return: dict of namespaces[name: value]
"""
namespaces = {}
tree = ET.parse(xml_file_path)
root = tree.getroot()
# Extract namespaces from the root element
for key, value in root.attrib.items():
if key.startswith('xmlns:'):
_, _, cropped_name = key.partition(':')
namespaces[cropped_name] = value
elif key == 'xmlns':
namespaces['xmlns'] = value
return namespaces


def get_microsoft_format(file_name):
"""
Extract format from the end of the given microsoft file name.
Expand Down

0 comments on commit 9e88132

Please sign in to comment.