host.get_log() : clean log of non-printable characters
PATCH 1/1 host.get_log() : clean log of non-printable characters
When retrieving the log via host.get_log() the python parser on the receiving side gets upset about non-printable characters ("\b"). Those stem from libxc/xc_domain_restore:xc_domain_restore().
--- xen-unstable.hg/tools/python/xen/xend/XendAPI.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
xen-unstable.hg/tools/python/xen/xend/XendAPI.py +10 -1
@@ -995,7 +995,16 @@ class XendAPI(object): log_file = open(XendLogging.getLogFilename()) log_buffer = log_file.read() log_file.close() - return xen_api_success(log_buffer) + i = 0 + res = "" + while i < len(log_buffer): + c = ord(log_buffer[i]) + if (c < 32 or c > 126) and (c < 10 or c > 13): + res += " " + else: + res += log_buffer[i] + i += 1 + return xen_api_success(res) def host_send_debug_keys(self, _, host_ref, keys): node = XendNode.instance()
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Stefan Berger writes ("[Xen-devel] [PATCH] [Xend] host.get_log() : clean log of non-printable characters"):
Quoted 3 lines
When retrieving the log via
host.get_log()the python parser on the receiving side gets upset about non-printable characters ("\b"). Those stem from libxc/xc_domain_restore:xc_domain_restore().
It is a shame that we are forced into writing a lossy log retrieval method by braindamage in XMLRPC and XML 1.0. Perhaps we should in future think about a get_log_lossless function which uses a binary encoding. It'd have to be base64 :-/.
Review
Quoted 11 lines
(quoted diff) +10
-1- return xen_api_success(log_buffer) + i = 0 + res = "" + while i < len(log_buffer): + c = ord(log_buffer[i]) + if (c < 32 or c > 126) and (c < 10 or c > 13): + res += " " + else: + res += log_buffer[i] + i += 1 + return xen_api_success(res)
This is a strange way of doing things and will be quite slow. It's also wrong in that it replaces tabs.
In theory it would be best to try to map away all Unicode characters which are not in XML 1.0's Char. However, this would involve explicitly interpreting the logfile as UTF-8 and it's not clear to me that it always is. If it isn't, it's probably better to let the caller get whatever the logfile byte string is and hope they don't choke - at least until we know under what circumstances this arises.
So it's better just to map away the character we know is causing problems. \r will be OK because it's allowed in XML as an encoding of newline, which will do. I've chosen below to replace \f as well since I suspect they may appear at some point.
Ian.
tools/python/xen/xend/XendAPI.py +2 -0
@@ -994,6 +994,8 @@ class XendAPI(object): def host_get_log(self, session, host_ref): log_file = open(XendLogging.getLogFilename()) log_buffer = log_file.read() + log_buffer = log_buffer.replace('\b',' ') + log_buffer = log_buffer.replace('\f','\n') return xen_api_success(log_buffer) def host_send_debug_keys(self, _, host_ref, keys):
[email protected] wrote on 11/15/2007 09:38:37 AM:
Quoted 23 lines
Stefan Berger writes ("[Xen-devel] [PATCH] [Xend]
host.get_log():
clean log of non-printable characters"):Quoted 3 lines
When retrieving the log via
host.get_log()the python parser on the receiving side gets upset about non-printable characters ("\b"). Those stem from libxc/xc_domain_restore:xc_domain_restore().It is a shame that we are forced into writing a lossy log retrieval method by braindamage in XMLRPC and XML 1.0. Perhaps we should in future think about a
get_log_losslessfunction which uses a binary encoding. It'd have to be base64 :-/.Review
Quoted 11 lines
(quoted diff) +10
-1- return xen_api_success(log_buffer) + i = 0 + res = "" + while i < len(log_buffer): + c = ord(log_buffer[i]) + if (c < 32 or c > 126) and (c < 10 or c > 13): + res += " " + else: + res += log_buffer[i] + i += 1 + return xen_api_success(res)
Quoted 1 line
This is a strange way of doing things and will be quite slow.
I agree. log_buffer[i] = ' ' unfortunately does not wokr with python. The solution you show below is
probably the right one.
Stefan
Quoted 29 lines
It's also wrong in that it replaces tabs.
In theory it would be best to try to map away all Unicode characters which are not in XML 1.0's Char. However, this would involve explicitly interpreting the logfile as UTF-8 and it's not clear to me that it always is. If it isn't, it's probably better to let the caller get whatever the logfile byte string is and hope they don't choke - at least until we know under what circumstances this arises.
So it's better just to map away the character we know is causing problems. \r will be OK because it's allowed in XML as an encoding of newline, which will do. I've chosen below to replace \f as well since I suspect they may appear at some point.
Ian.
diff -r
ba69fe2dce91tools/python/xen/xend/XendAPI.pytools/python/xen/xend/XendAPI.py Thu Nov 15 14:32:33 2007 +0000 renamed from tools/python/xen/xend/XendAPI.py Tue Nov 13 20:13:50 2007 +0000 +2
-0@@ -994,6 +994,8 @@ class XendAPI(object): def host_get_log(self, session, host_ref): log_file = open(XendLogging.getLogFilename()) log_buffer = log_file.read() + log_buffer = log_buffer.replace('\b',' ') + log_buffer = log_buffer.replace('\f','\n') return xen_api_success(log_buffer) def host_send_debug_keys(self, _, host_ref, keys):
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel