[CalendarServer-changes] [12254] twext/trunk/twext/who/opendirectory/_service.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:18:32 PDT 2014
Revision: 12254
http://trac.calendarserver.org//changeset/12254
Author: wsanchez at apple.com
Date: 2014-01-06 19:49:51 -0800 (Mon, 06 Jan 2014)
Log Message:
-----------
Use unicode.translate() instead of several unicode.replace()s.
Modified Paths:
--------------
twext/trunk/twext/who/opendirectory/_service.py
Modified: twext/trunk/twext/who/opendirectory/_service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/_service.py 2014-01-07 03:30:42 UTC (rev 12253)
+++ twext/trunk/twext/who/opendirectory/_service.py 2014-01-07 03:49:51 UTC (rev 12254)
@@ -52,6 +52,27 @@
+LDAP_QUOTING_TABLE = {
+ ord(u"\\"): u"\\5C",
+ ord(u"/"): u"\\2F",
+
+ ord(u"("): u"\\28",
+ ord(u")"): u"\\29",
+ ord(u"*"): u"\\2A",
+
+ ord(u"<"): u"\\3C",
+ ord(u"="): u"\\3D",
+ ord(u">"): u"\\3E",
+ ord(u"~"): u"\\7E",
+
+ ord(u"&"): u"\\26",
+ ord(u"|"): u"\\7C",
+
+ ord(u"\0"): u"\\00",
+}
+
+
+
#
# Exceptions
#
@@ -266,29 +287,9 @@
)
value = expression.fieldValue
- value = unicode(value)
+ value = unicode(value) # We want unicode
+ value = value.translate(LDAP_QUOTING_TABLE) # Escape special chars
- # Do some quoting
- for character, replacement in (
- (u"\\", u"\\5C"), # Must be first.
- (u"/", u"\\2F"),
-
- (u"(", u"\\28"),
- (u")", u"\\29"),
- (u"*", u"\\2A"),
-
- (u"<", u"\\3C"),
- (u"=", u"\\3D"),
- (u">", u"\\3E"),
- (u"~", u"\\7E"),
-
- (u"&", u"\\26"),
- (u"|", u"\\7C"),
-
- (u"\0", u"\\00")
- ):
- value = value.replace(character, replacement)
-
return matchType.queryString.format(
notOp=notOp, attribute=odAttr.value, value=value
)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/a5ae07c7/attachment.html>
More information about the calendarserver-changes
mailing list