[PATCH 3 of 8] added helper functions to encode/decode to/from local encodings

Andrey grooz-work at gorodok.net
Mon Nov 20 04:29:53 CST 2006


# HG changeset patch
# User Andrey <grooz-work at gorodok.net>
# Date 1163347690 -21600
# Node ID 2e2cc18a4e6dd837305f247ff5e2046084e77960
# Parent  cba3d15b1f26aafaa0a4b4d3e90c0529f18ebfd9
added helper functions to encode/decode to/from local encodings

diff -r cba3d15b1f26 -r 2e2cc18a4e6d mercurial/ui.py
--- a/mercurial/ui.py	Sun Nov 12 21:23:32 2006 +0600
+++ b/mercurial/ui.py	Sun Nov 12 22:08:10 2006 +0600
@@ -376,6 +376,16 @@ class ui(object):
         if not path and default is not None:
             path = self.config("paths", default)
         return path or loc
+
+    def encode(self, s, encoding='default', errors='replace'):
+        if isinstance(s, unicode):
+            return s.encode(self.encodings[encoding], errors)
+        return str(s)
+
+    def decode(self, s, encoding='default', errors='replace'):
+        if isinstance(s, unicode):
+            return s
+        return s.decode(self.encodings[encoding], errors)
 
     def write(self, *args):
         for a in args:


More information about the Mercurial-devel mailing list