2239 def wrap(line, width, initindent='', hangindent=''): |
2239 def wrap(line, width, initindent='', hangindent=''): |
2240 maxindent = max(len(hangindent), len(initindent)) |
2240 maxindent = max(len(hangindent), len(initindent)) |
2241 if width <= maxindent: |
2241 if width <= maxindent: |
2242 # adjust for weird terminal size |
2242 # adjust for weird terminal size |
2243 width = max(78, maxindent + 1) |
2243 width = max(78, maxindent + 1) |
2244 line = line.decode(encoding.encoding, encoding.encodingmode) |
2244 line = line.decode(pycompat.sysstr(encoding.encoding), |
2245 initindent = initindent.decode(encoding.encoding, encoding.encodingmode) |
2245 pycompat.sysstr(encoding.encodingmode)) |
2246 hangindent = hangindent.decode(encoding.encoding, encoding.encodingmode) |
2246 initindent = initindent.decode(pycompat.sysstr(encoding.encoding), |
|
2247 pycompat.sysstr(encoding.encodingmode)) |
|
2248 hangindent = hangindent.decode(pycompat.sysstr(encoding.encoding), |
|
2249 pycompat.sysstr(encoding.encodingmode)) |
2247 wrapper = MBTextWrapper(width=width, |
2250 wrapper = MBTextWrapper(width=width, |
2248 initial_indent=initindent, |
2251 initial_indent=initindent, |
2249 subsequent_indent=hangindent) |
2252 subsequent_indent=hangindent) |
2250 return wrapper.fill(line).encode(encoding.encoding) |
2253 return wrapper.fill(line).encode(pycompat.sysstr(encoding.encoding)) |
2251 |
2254 |
2252 if (pyplatform.python_implementation() == 'CPython' and |
2255 if (pyplatform.python_implementation() == 'CPython' and |
2253 sys.version_info < (3, 0)): |
2256 sys.version_info < (3, 0)): |
2254 # There is an issue in CPython that some IO methods do not handle EINTR |
2257 # There is an issue in CPython that some IO methods do not handle EINTR |
2255 # correctly. The following table shows what CPython version (and functions) |
2258 # correctly. The following table shows what CPython version (and functions) |