@@ -280,6 +280,14 @@ def parse_separated_header(value: str) -> dict[str, str]:
280280 return dict (m .get_params ())
281281
282282
283+ def _force_text (s : str | bytes , encoding : str = 'utf-8' , errors : str = 'strict' ) -> str :
284+ if isinstance (s , str ):
285+ return s
286+ if isinstance (s , bytes ):
287+ return s .decode (encoding , errors )
288+ return str (s )
289+
290+
283291class Catalog :
284292 """Representation of a message catalog."""
285293
@@ -463,17 +471,10 @@ def _get_mime_headers(self) -> list[tuple[str, str]]:
463471 headers .append (("Generated-By" , f"Babel { VERSION } \n " ))
464472 return headers
465473
466- def _force_text (self , s : str | bytes , encoding : str = 'utf-8' , errors : str = 'strict' ) -> str :
467- if isinstance (s , str ):
468- return s
469- if isinstance (s , bytes ):
470- return s .decode (encoding , errors )
471- return str (s )
472-
473474 def _set_mime_headers (self , headers : Iterable [tuple [str , str ]]) -> None :
474475 for name , value in headers :
475- name = self . _force_text (name .lower (), encoding = self .charset )
476- value = self . _force_text (value , encoding = self .charset )
476+ name = _force_text (name .lower (), encoding = self .charset )
477+ value = _force_text (value , encoding = self .charset )
477478 if name == 'project-id-version' :
478479 parts = value .split (' ' )
479480 self .project = ' ' .join (parts [:- 1 ])
0 commit comments