Skip to content
This repository was archived by the owner on Dec 26, 2025. It is now read-only.

Commit 36eaedb

Browse files
committed
Make deepcopy of data_dict on dump adi/adx to not change provided data
1 parent b5323d1 commit 36eaedb

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/adif_file/adi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Convert ADIF ADI content to dictionary and vice versa"""
22

33
import re
4+
import copy
45
import datetime
56
from collections.abc import Iterator
67

@@ -207,6 +208,8 @@ def dumpi(data_dict: dict, comment: str = 'ADIF export by ' + __proj_name__,
207208
:param spaces: Number of spaces between fields
208209
:return: an iterator of chunks of the ADI (header, record 1, ..., record n)"""
209210

211+
data_dict = copy.deepcopy(data_dict)
212+
210213
field_separator = ' ' * spaces if spaces >= 0 else ' '
211214

212215
if 'HEADER' in data_dict:

src/adif_file/adx.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Convert ADIF ADX content to dictionary and vice versa
22
The XML is validated against the XSD from ADIF.org"""
33

4+
import copy
45
import datetime
56
import os.path
67
import xml
@@ -92,7 +93,7 @@ def dump(file_name: str, data_dict: dict, raise_exc=True) -> list[Exception]:
9293
:return: list of validation exception (if not raised immediately)
9394
"""
9495

95-
data_dict = data_dict.copy()
96+
data_dict = copy.deepcopy(data_dict)
9697

9798
header = {
9899
'ADIF_VER': '3.1.4',

test/test_dumpadx.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,31 @@ def test_30_dump_no_change(self):
182182

183183
os.remove(temp_file)
184184

185+
def test_40_deepcopy(self):
186+
adx_dict = {
187+
'HEADER': {'PROGRAMVERSION': '1',
188+
'CREATED_TIMESTAMP': '20231204 100000',
189+
},
190+
'RECORDS': [{'CALL': 'XX1XXX',
191+
'QSO_DATE': '20231204',
192+
'TIME_ON': '1100',
193+
'QTH': 'Test'
194+
},
195+
{'CALL': 'YY1YYY',
196+
'QSO_DATE': '20231204',
197+
'TIME_ON': '1200',
198+
'QTH_INTL': 'Töst',
199+
}
200+
]
201+
}
202+
203+
temp_file = get_file_path('testdata/~test.adx')
204+
adif_file.adx.dump(temp_file, adx_dict)
205+
self.assertNotIn('ADIF_VER', adx_dict['HEADER'])
206+
self.assertNotIn('RECORD', adx_dict['RECORDS'])
207+
208+
os.remove(temp_file)
209+
185210

186211
if __name__ == '__main__':
187212
unittest.main()

0 commit comments

Comments
 (0)