Skip to content

Commit 8e12f54

Browse files
akxtomasr8
andauthored
Mark wraptext deprecated; use TextWrapper directly in write_po (#1140)
* Mark `wraptext` deprecated; use `TextWrapper` directly in `write_po` Co-authored-by: Tomas R. <[email protected]>
1 parent e956b28 commit 8e12f54

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

babel/messages/pofile.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from babel.core import Locale
1919
from babel.messages.catalog import Catalog, Message
20-
from babel.util import _cmp, wraptext
20+
from babel.util import TextWrapper, _cmp
2121

2222
if TYPE_CHECKING:
2323
from typing import IO, AnyStr
@@ -637,8 +637,11 @@ def generate_po(
637637
# provide the same behaviour
638638
comment_width = width if width and width > 0 else 76
639639

640+
comment_wrapper = TextWrapper(width=comment_width)
641+
header_wrapper = TextWrapper(width=width, subsequent_indent="# ")
642+
640643
def _format_comment(comment, prefix=''):
641-
for line in wraptext(comment, comment_width):
644+
for line in comment_wrapper.wrap(comment):
642645
yield f"#{prefix} {line.strip()}\n"
643646

644647
def _format_message(message, prefix=''):
@@ -668,8 +671,7 @@ def _format_message(message, prefix=''):
668671
if width and width > 0:
669672
lines = []
670673
for line in comment_header.splitlines():
671-
lines += wraptext(line, width=width,
672-
subsequent_indent='# ')
674+
lines += header_wrapper.wrap(line)
673675
comment_header = '\n'.join(lines)
674676
yield f"{comment_header}\n"
675677

babel/util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import re
1717
import textwrap
18+
import warnings
1819
from collections.abc import Generator, Iterable
1920
from typing import IO, Any, TypeVar
2021

@@ -217,6 +218,12 @@ def wraptext(text: str, width: int = 70, initial_indent: str = '', subsequent_in
217218
:param subsequent_indent: string that will be prepended to all lines save
218219
the first of wrapped output
219220
"""
221+
warnings.warn(
222+
"`babel.util.wraptext` is deprecated and will be removed in a future version of Babel. "
223+
"If you need this functionality, use the `babel.util.TextWrapper` class directly.",
224+
DeprecationWarning,
225+
stacklevel=2,
226+
)
220227
wrapper = TextWrapper(width=width, initial_indent=initial_indent,
221228
subsequent_indent=subsequent_indent,
222229
break_long_words=False)

0 commit comments

Comments
 (0)