@@ -180,7 +180,7 @@ def _snapshot_path_contents(self) -> dict[str, Optional[str]]:
180180 for name , src in self ._sources .items ():
181181 if isinstance (src , _PathSource ):
182182 try :
183- snapshot [name ] = Path (src .path ). read_text ( encoding = "utf-8" )
183+ snapshot [name ] = self . _read_path (src .path )
184184 except FileNotFoundError :
185185 snapshot [name ] = None
186186 return snapshot
@@ -232,12 +232,18 @@ def _cleanup_tmp_files(self) -> None:
232232 @staticmethod
233233 def _atomic_write_path (path : str , content : str ) -> None :
234234 tmp = path + ".tmp"
235- Path (tmp ).write_text (content , encoding = "utf-8" )
235+ with Path (tmp ).open ("w" , encoding = "utf-8" , newline = "" ) as prompt_file :
236+ prompt_file .write (content )
236237 os .replace (tmp , path )
237238
239+ @staticmethod
240+ def _read_path (path : str ) -> str :
241+ with Path (path ).open ("r" , encoding = "utf-8" , newline = "" ) as prompt_file :
242+ return prompt_file .read ()
243+
238244 async def _read_one (self , src : _Source ) -> str :
239245 if isinstance (src , _PathSource ):
240- return Path (src .path ). read_text ( encoding = "utf-8" )
246+ return self . _read_path (src .path )
241247 if isinstance (src , _CallbackSource ):
242248 return await src .read_fn ()
243249 raise TypeError (f"unknown source type: { type (src ).__name__ } " )
0 commit comments