@@ -205,10 +205,31 @@ class TextWrapper(textwrap.TextWrapper):
205205 r'(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))' , # em-dash
206206 )
207207
208+ # e.g. '\u2068foo bar.py\u2069:42'
209+ _enclosed_filename_re = re .compile (r'(\u2068[^\u2068]+?\u2069(?::-?\d+)?)' )
210+
211+ def _split (self , text ):
212+ """Splits the text into indivisible chunks while ensuring that file names
213+ containing spaces are not broken up.
214+ """
215+ enclosed_filename_start = '\u2068 '
216+ if enclosed_filename_start not in text :
217+ # There are no file names which contain spaces, fallback to the default implementation
218+ return super ()._split (text )
219+
220+ chunks = []
221+ for chunk in re .split (self ._enclosed_filename_re , text ):
222+ if chunk .startswith (enclosed_filename_start ):
223+ chunks .append (chunk )
224+ else :
225+ chunks .extend (super ()._split (chunk ))
226+ return [c for c in chunks if c ]
227+
208228
209229def wraptext (text : str , width : int = 70 , initial_indent : str = '' , subsequent_indent : str = '' ) -> list [str ]:
210230 """Simple wrapper around the ``textwrap.wrap`` function in the standard
211- library. This version does not wrap lines on hyphens in words.
231+ library. This version does not wrap lines on hyphens in words. It also
232+ does not wrap PO file locations containing spaces.
212233
213234 :param text: the text to wrap
214235 :param width: the maximum line width
0 commit comments