[PATCH 3 of 6] added helper functions to encode/decode to/from local encodings
Andrey
grooz-work at gorodok.net
Sun Nov 12 17:49:26 UTC 2006
# HG changeset patch
# User Andrey <grooz-work at gorodok.net>
# Date 1163347690 -21600
# Node ID 96fdb63186b9baaaf3139cfcb127a36ee2602922
# Parent 97bdd52eb920740375a449a3bb55078d10f9a163
added helper functions to encode/decode to/from local encodings
diff -r 97bdd52eb920 -r 96fdb63186b9 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
@@ -369,6 +369,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):
if self.header:
More information about the Mercurial-devel
mailing list