mercurial/encoding.py
changeset 36797 d4c760c997cd
parent 36549 3696efeab66f
child 37946 57b0c7221dba
child 38615 443029011990
equal deleted inserted replaced
36796:aa0fc12743c7 36797:d4c760c997cd
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 from __future__ import absolute_import, print_function
     8 from __future__ import absolute_import, print_function
     9 
     9 
    10 import io
       
    11 import locale
    10 import locale
    12 import os
    11 import os
    13 import unicodedata
    12 import unicodedata
    14 
    13 
    15 from . import (
    14 from . import (
   579         # unescape U+DCxx characters
   578         # unescape U+DCxx characters
   580         if "\xed\xb0\x80" <= c <= "\xed\xb3\xbf":
   579         if "\xed\xb0\x80" <= c <= "\xed\xb3\xbf":
   581             c = pycompat.bytechr(ord(c.decode("utf-8", _utf8strict)) & 0xff)
   580             c = pycompat.bytechr(ord(c.decode("utf-8", _utf8strict)) & 0xff)
   582         r += c
   581         r += c
   583     return r
   582     return r
   584 
       
   585 if pycompat.ispy3:
       
   586     class strio(io.TextIOWrapper):
       
   587         """Wrapper around TextIOWrapper that respects hg's encoding assumptions.
       
   588 
       
   589         Also works around Python closing streams.
       
   590         """
       
   591 
       
   592         def __init__(self, buffer):
       
   593             super(strio, self).__init__(buffer, encoding=_sysstr(encoding))
       
   594 
       
   595         def __del__(self):
       
   596             """Override __del__ so it doesn't close the underlying stream."""
       
   597 else:
       
   598     strio = pycompat.identity