Skip to content

Commit 67da127

Browse files
committed
CHAM-572 Remove the exclamation mark from yaml context
1 parent 990d6d6 commit 67da127

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

openformats/formats/yaml/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ def construct_mapping(self, node, deep=True):
222222
and self._is_custom_tag(value_node.tag)
223223
):
224224
tag = six.text_type(value_node.tag)
225+
# remove the exclamation mark from the tag
226+
tag = tag[1:] if tag.startswith('!') else tag
225227

226228
value = Node(value, start, end, style, tag)
227229
pairs.append((key, value))
@@ -349,8 +351,9 @@ def generate_yaml_dict(self, stringset):
349351
yaml_dict, keys, flags, se.string.get(rule), tag=None,
350352
)
351353
else:
354+
tag = '!' + se.context if se.context else se.context
352355
self._insert_translation_in_dict(
353-
yaml_dict, keys, flags, se.string, tag=se.context,
356+
yaml_dict, keys, flags, se.string, tag=tag,
354357
)
355358
return yaml_dict
356359

openformats/formats/yaml/yaml.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ def _compile_from_template(self, template, stringset, **kwargs):
404404
# it and apply a space afterwards so it doesn't get merged with the
405405
# string
406406
if string.context:
407-
transcriber.add(string.context)
407+
# add an exclamation mark to the context to make it a tag
408+
transcriber.add('!' + string.context)
408409
transcriber.add(' ')
409410
transcriber.add(translation)
410411
transcriber.skip(len(string.template_replacement))

openformats/tests/formats/yaml/files/1_tpl.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ alias_key:
6565
- ddc3cfcedcf1686d9e3ba6b99a0d091b_tr
6666

6767
# Custom tags
68-
foo: 3e4000f6f4cd8bb27db6fb82e1b50bb4_tr # Should treat as string and ignore leading spaces
69-
bar: 75ce597a505a4faf6369b66b885926c8_tr # Also a string
68+
foo: 023503fb466f78932b77209b6581156e_tr # Should treat as string and ignore leading spaces
69+
bar: fac8140a2ec031af14bc758e73f59017_tr # Also a string
7070
hello: b0ed9cf22c0a5186d1c5b483a910dd33_tr # Translatable
7171
number: !!int 123 # Should ignore
7272
bin: !!binary aGVsbG8= # Should ignore

openformats/tests/formats/yaml/test_yaml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def test_openstring_attributes(self):
144144
self.assertEqual(test_string.flags, '')
145145

146146
content_string = strings[1]
147-
self.assertEqual(content_string.context, '!tag')
147+
self.assertEqual(content_string.context, 'tag')
148148
self.assertEqual(content_string.flags, "'")
149149

150150
def test_parse_duplicate_keys(self):

0 commit comments

Comments
 (0)