Update of /cvsroot/monetdb/clients/src/python
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv28116

Modified Files:
      Tag: Clients_1-20
        mclient.py.in 
Log Message:
Use locale to determine encoding of stdin/stdout and use that
information to convert to/from utf-8.
Also provide a command line option --encode to override this.


Index: mclient.py.in
===================================================================
RCS file: /cvsroot/monetdb/clients/src/python/mclient.py.in,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -d -r1.2 -r1.2.2.1
--- mclient.py.in       11 Sep 2007 11:11:40 -0000      1.2
+++ mclient.py.in       4 Dec 2007 12:22:05 -0000       1.2.2.1
@@ -38,6 +38,7 @@
         ('language',None,'language','language','language (default: sql)'),
         ('database',None,'database','database','database (default: "")'),
         ('mapi_trace',None,'mapi_trace', None, 'mapi_trace'),
+        ('encoding',None,'encoding','encoding','character encoding'),
         ]
 
     try:
@@ -46,13 +47,20 @@
         # error parsing options
         sys.exit(1)
 
+    encoding = opt.get("encoding", None)
+    if encoding is None:
+        import locale
+        encoding = locale.getlocale()[1]
+        if encoding is None:
+            encoding = locale.getdefaultlocale()[1]
+
     s = server(opt.get("host", "localhost"),
                int(opt.get("mapi_port", 50000)),
                opt.get("user", "monetdb"),
                opt.get("passwd", "monetdb"),
                opt.get("language", "sql"),
                opt.get("database", ""),
-               opt.get("mapi_trace", None)!=None)
+               opt.get("mapi_trace", None) is not None)
     print "#mclient (python) connected to %s:%d as %s" % \
           (opt.get("host", "localhost"),
            int(opt.get("mapi_port", 50000)),
@@ -63,10 +71,17 @@
 
     sys.stdout.write(s.prompt.encode('utf-8'))
     line = fi.readline()
+    prompt = s.prompt
+    if encoding != 'utf-8':
+        prompt = unicode(prompt, 'utf-8').encode(encoding, 'replace')
     while line and line != "\q\n":
+        if encoding != 'utf-8':
+            line = unicode(line, encoding).encode('utf-8')
         res = s.cmd(line)
+        if encoding != 'utf-8':
+            res = unicode(res, 'utf-8').encode(encoding, 'replace')
         print res
-        sys.stdout.write(s.prompt.encode('utf-8'))
+        sys.stdout.write(prompt)
         line = fi.readline()
 
     s.disconnect()


-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to