@@ -34,8 +34,23 @@ def plus_facet(
3434 ) -> "Snapshot" :
3535 if key == "" :
3636 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+ )
3954
4055 def subject_or_facet_maybe (self , key : str ) -> Union [SnapshotValue , None ]:
4156 return self ._subject if key == "" else self ._facet_data .get (key )
@@ -72,6 +87,6 @@ def items(self) -> Iterator[tuple[str, SnapshotValue]]:
7287 yield ("" , self ._subject )
7388 yield from self ._facet_data .items ()
7489
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