mercurial/encoding.py
changeset 31447 067add650129
parent 30622 ce36fa9b140c
child 31448 6419cd243017
equal deleted inserted replaced
31446:9a94239e4f12 31447:067add650129
   193     except UnicodeDecodeError as inst:
   193     except UnicodeDecodeError as inst:
   194         sub = s[max(0, inst.start - 10):inst.start + 10]
   194         sub = s[max(0, inst.start - 10):inst.start + 10]
   195         raise error.Abort("decoding near '%s': %s!" % (sub, inst))
   195         raise error.Abort("decoding near '%s': %s!" % (sub, inst))
   196     except LookupError as k:
   196     except LookupError as k:
   197         raise error.Abort(k, hint="please check your locale settings")
   197         raise error.Abort(k, hint="please check your locale settings")
       
   198 
       
   199 def unitolocal(u):
       
   200     """Convert a unicode string to a byte string of local encoding"""
       
   201     return tolocal(u.encode('utf-8'))
       
   202 
       
   203 def unifromlocal(s):
       
   204     """Convert a byte string of local encoding to a unicode string"""
       
   205     return fromlocal(s).decode('utf-8')
   198 
   206 
   199 if not _nativeenviron:
   207 if not _nativeenviron:
   200     # now encoding and helper functions are available, recreate the environ
   208     # now encoding and helper functions are available, recreate the environ
   201     # dict to be exported to other modules
   209     # dict to be exported to other modules
   202     environ = dict((tolocal(k.encode(u'utf-8')), tolocal(v.encode(u'utf-8')))
   210     environ = dict((tolocal(k.encode(u'utf-8')), tolocal(v.encode(u'utf-8')))