@@ -34,8 +34,23 @@ def plus_facet(
34
34
) -> "Snapshot" :
35
35
if key == "" :
36
36
raise ValueError ("The empty string is reserved for the subject." )
37
- new_facet_data = self ._facet_data .plus (key , SnapshotValue .of (value ))
38
- return Snapshot (self ._subject , new_facet_data )
37
+ return Snapshot (
38
+ self ._subject ,
39
+ self ._facet_data .plus (_unix_newlines (key ), SnapshotValue .of (value )),
40
+ )
41
+
42
+ def plus_or_replace (
43
+ self , key : str , value : Union [bytes , str , SnapshotValue ]
44
+ ) -> "Snapshot" :
45
+ if key == "" :
46
+ return Snapshot (SnapshotValue .of (value ), self ._facet_data )
47
+ else :
48
+ return Snapshot (
49
+ self ._subject ,
50
+ self ._facet_data .plus_or_noop_or_replace (
51
+ _unix_newlines (key ), SnapshotValue .of (value )
52
+ ),
53
+ )
39
54
40
55
def subject_or_facet_maybe (self , key : str ) -> Union [SnapshotValue , None ]:
41
56
return self ._subject if key == "" else self ._facet_data .get (key )
@@ -72,6 +87,6 @@ def items(self) -> Iterator[tuple[str, SnapshotValue]]:
72
87
yield ("" , self ._subject )
73
88
yield from self ._facet_data .items ()
74
89
75
- @ staticmethod
76
- def _unix_newlines (string : str ) -> str :
77
- return string .replace ("\\ r\\ n" , "\\ n" )
90
+
91
+ def _unix_newlines (string : str ) -> str :
92
+ return string .replace ("\\ r\\ n" , "\\ n" )
0 commit comments