[NEW PATCH] Rewrote the _filterXmlChars after a code review. (via gerrit-bot)
Gal Hammer
ghammer at redhat.com
Thu Sep 8 09:40:49 UTC 2011
New patch submitted by Gal Hammer (ghammer at redhat.com)
You can review this change at: http://gerrit.usersys.redhat.com/907
commit 952c906433bf0df3bb84ff27afc32fb4dec489c2
Author: Gal Hammer <ghammer at redhat.com>
Date: Wed Sep 7 14:57:39 2011 +0300
Rewrote the _filterXmlChars after a code review.
Using constant to generate restricted characters only once and a little speed improvment when returning the filtered string.
Change-Id: I217bb9f440469ecb1c4195ca11368eb47aa5b77c
diff --git a/vdsm/guestIF.py b/vdsm/guestIF.py
index c3290d2..bd501b4 100644
--- a/vdsm/guestIF.py
+++ b/vdsm/guestIF.py
@@ -26,22 +26,26 @@ from config import config
import utils
import constants
+__RESTRICTED_CHARS = set(range(8+1)).union(
+ set(range(0xB,0xC+1))).union(
+ set(range(0xE,0x1F+1))).union(
+ set(range(0x7F,0x84+1))).union(
+ set(range(0x86,0x9F+1)))
+
def _filterXmlChars(u):
"""
- Filter out restarted xml chars from unicode string
+ Filter out restarted xml chars from unicode string. Not using
+ Python's xmlcharrefreplace because it accepts '\x01', which
+ the spec frown upon.
Set taken from http://www.w3.org/TR/xml11/#NT-RestrictedChar
"""
- restricted = set(range(8+1)).union(
- set(range(0xB,0xC+1))).union(
- set(range(0xE,0x1F+1))).union(
- set(range(0x7F,0x84+1))).union(
- set(range(0x86,0x9F+1)))
+
def maskRestricted(c):
- if ord(c) in restricted: return '?'
+ if ord(c) in __RESTRICTED_CHARS: return '?'
else: return c
- return ''.join([maskRestricted(c) for c in u])
+ return ''.join(maskRestricted(c) for c in u)
class GuestAgent (threading.Thread):
def __init__(self, socketName, log, user='Unknown', ips='', connect=True):
More information about the vdsm-patches
mailing list