comparison mercurial/util.py @ 37082:736024df4498

util: mark MBTextWrapper as private Makes porting slightly easier.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 22 Mar 2018 21:13:31 +0900
parents b3079fea3838
children bad90b80b315
comparison
equal deleted inserted replaced
37081:b3079fea3838 37082:736024df4498
2772 def uirepr(s): 2772 def uirepr(s):
2773 # Avoid double backslash in Windows path repr() 2773 # Avoid double backslash in Windows path repr()
2774 return pycompat.byterepr(pycompat.bytestr(s)).replace(b'\\\\', b'\\') 2774 return pycompat.byterepr(pycompat.bytestr(s)).replace(b'\\\\', b'\\')
2775 2775
2776 # delay import of textwrap 2776 # delay import of textwrap
2777 def MBTextWrapper(**kwargs): 2777 def _MBTextWrapper(**kwargs):
2778 class tw(textwrap.TextWrapper): 2778 class tw(textwrap.TextWrapper):
2779 """ 2779 """
2780 Extend TextWrapper for width-awareness. 2780 Extend TextWrapper for width-awareness.
2781 2781
2782 Neither number of 'bytes' in any encoding nor 'characters' is 2782 Neither number of 'bytes' in any encoding nor 'characters' is
2871 if cur_line: 2871 if cur_line:
2872 lines.append(indent + r''.join(cur_line)) 2872 lines.append(indent + r''.join(cur_line))
2873 2873
2874 return lines 2874 return lines
2875 2875
2876 global MBTextWrapper 2876 global _MBTextWrapper
2877 MBTextWrapper = tw 2877 _MBTextWrapper = tw
2878 return tw(**kwargs) 2878 return tw(**kwargs)
2879 2879
2880 def wrap(line, width, initindent='', hangindent=''): 2880 def wrap(line, width, initindent='', hangindent=''):
2881 maxindent = max(len(hangindent), len(initindent)) 2881 maxindent = max(len(hangindent), len(initindent))
2882 if width <= maxindent: 2882 if width <= maxindent:
2886 pycompat.sysstr(encoding.encodingmode)) 2886 pycompat.sysstr(encoding.encodingmode))
2887 initindent = initindent.decode(pycompat.sysstr(encoding.encoding), 2887 initindent = initindent.decode(pycompat.sysstr(encoding.encoding),
2888 pycompat.sysstr(encoding.encodingmode)) 2888 pycompat.sysstr(encoding.encodingmode))
2889 hangindent = hangindent.decode(pycompat.sysstr(encoding.encoding), 2889 hangindent = hangindent.decode(pycompat.sysstr(encoding.encoding),
2890 pycompat.sysstr(encoding.encodingmode)) 2890 pycompat.sysstr(encoding.encodingmode))
2891 wrapper = MBTextWrapper(width=width, 2891 wrapper = _MBTextWrapper(width=width,
2892 initial_indent=initindent, 2892 initial_indent=initindent,
2893 subsequent_indent=hangindent) 2893 subsequent_indent=hangindent)
2894 return wrapper.fill(line).encode(pycompat.sysstr(encoding.encoding)) 2894 return wrapper.fill(line).encode(pycompat.sysstr(encoding.encoding))
2895 2895
2896 if (pyplatform.python_implementation() == 'CPython' and 2896 if (pyplatform.python_implementation() == 'CPython' and
2897 sys.version_info < (3, 0)): 2897 sys.version_info < (3, 0)):
2898 # There is an issue in CPython that some IO methods do not handle EINTR 2898 # There is an issue in CPython that some IO methods do not handle EINTR