from babel.core import Locale
from babel.messages.catalog import Catalog, Message
-from babel.util import _cmp, wraptext
+from babel.util import TextWrapper, _cmp
if TYPE_CHECKING:
from typing import IO, AnyStr
# provide the same behaviour
comment_width = width if width and width > 0 else 76
+ comment_wrapper = TextWrapper(width=comment_width)
+ header_wrapper = TextWrapper(width=width, subsequent_indent="# ")
+
def _format_comment(comment, prefix=''):
- for line in wraptext(comment, comment_width):
+ for line in comment_wrapper.wrap(comment):
yield f"#{prefix} {line.strip()}\n"
def _format_message(message, prefix=''):
if width and width > 0:
lines = []
for line in comment_header.splitlines():
- lines += wraptext(line, width=width,
- subsequent_indent='# ')
+ lines += header_wrapper.wrap(line)
comment_header = '\n'.join(lines)
yield f"{comment_header}\n"
import os
import re
import textwrap
+import warnings
from collections.abc import Generator, Iterable
from typing import IO, Any, TypeVar
:param subsequent_indent: string that will be prepended to all lines save
the first of wrapped output
"""
+ warnings.warn(
+ "`babel.util.wraptext` is deprecated and will be removed in a future version of Babel. "
+ "If you need this functionality, use the `babel.util.TextWrapper` class directly.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
wrapper = TextWrapper(width=width, initial_indent=initial_indent,
subsequent_indent=subsequent_indent,
break_long_words=False)