|
From: <bov...@us...> - 2007-01-30 18:57:53
|
Revision: 1347
http://svn.sourceforge.net/pywebsvcs/?rev=1347&view=rev
Author: boverhof
Date: 2007-01-30 10:57:47 -0800 (Tue, 30 Jan 2007)
Log Message:
-----------
A test/test_URI.py
M test/test_zsi.py
M test/test_zsi_net.py
M ZSI/TC.py
[ 1520092 ] URI Bug: urllib.quote escaping reserved chars
added "safe" keyword arg to urlencode, and "reserved" attribute to URI.
Modified Paths:
--------------
trunk/zsi/ZSI/TC.py
trunk/zsi/test/test_zsi.py
trunk/zsi/test/test_zsi_net.py
Added Paths:
-----------
trunk/zsi/test/test_URI.py
Modified: trunk/zsi/ZSI/TC.py
===================================================================
--- trunk/zsi/ZSI/TC.py 2007-01-30 17:32:19 UTC (rev 1346)
+++ trunk/zsi/ZSI/TC.py 2007-01-30 18:57:47 UTC (rev 1347)
@@ -724,10 +724,15 @@
class URI(String):
'''A URI.
+ Class data:
+ reserved -- urllib.quote will escape all reserved characters
+ regardless of whether they are used for the reserved purpose.
+
'''
parselist = [ (None,'anyURI'),(SCHEMA.XSD3, 'anyURI')]
type = (SCHEMA.XSD3, 'anyURI')
logger = _GetLogger('ZSI.TC.URI')
+ reserved = ";/?:@&=+$,"
def text_to_data(self, text, elt, ps):
'''text --> typecode specific data.
@@ -739,10 +744,9 @@
'''typecode data --> text
'''
pyobj = String.get_formatted_content(self, pyobj)
- return urlencode(pyobj)
+ return urlencode(pyobj, safe=self.reserved)
-
class QName(String):
'''A QName type
'''
Added: trunk/zsi/test/test_URI.py
===================================================================
--- trunk/zsi/test/test_URI.py (rev 0)
+++ trunk/zsi/test/test_URI.py 2007-01-30 18:57:47 UTC (rev 1347)
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+import unittest, sys, tests_good, tests_bad, time
+from ZSI import *
+try:
+ import cStringIO as StringIO
+except ImportError:
+ import StringIO
+
+
+"""Bug [ 1520092 ] URI Bug: urllib.quote escaping reserved chars
+
+From rfc2396:
+
+"If the data for a URI component would conflict with the reserved
+purpose, then the conflicting data must be escaped before forming the
+URI."
+
+reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
+"$" | ","
+
+
+
+This implies that if ":" is used for a reserved purpose,
+
+if scheme is defined then
+append scheme to result
+append ":" to result
+
+, then it should not be escaped.
+"""
+
+
+class TestCase(unittest.TestCase):
+ def check_uri_quoting(self):
+ """ all reserved characters used for reserved purpose.
+ """
+ sw1 = SoapWriter(envelope=False)
+ tc1= TC.URI('sourceforge')
+ orig = 'https://sourceforge.net/tracker/index.php?func=detail&aid=1520092&group_id=26590&atid=387667'
+ sw1.serialize(orig, typecode=tc1, typed=False)
+ s1 = str(sw1)
+
+ sw2 = SoapWriter(envelope=False)
+ tc2= TC.String('sourceforge')
+ sw2.serialize(orig, typecode=tc2, typed=False)
+ s2 = str(sw2)
+
+ print s1
+ print s2
+ self.failUnless(s1 == s2,
+ 'reserved characters used for reserved purpose should not be escaped.')
+
+ ps = ParsedSoap(s2, envelope=False)
+ pyobj = ps.Parse(tc2)
+
+ self.failUnless(pyobj == orig, 'parsed object should be equivalent to original')
+
+
+
+#
+# Creates permutation of test options: "check", "check_any", etc
+#
+_SEP = '_'
+for t in [i[0].split(_SEP) for i in filter(lambda i: callable(i[1]), TestCase.__dict__.items())]:
+ test = ''
+ for f in t:
+ test += f
+ if globals().has_key(test): test += _SEP; continue
+ def _closure():
+ name = test
+ def _makeTestSuite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TestCase, name))
+ return suite
+ return _makeTestSuite
+
+ globals()[test] = _closure()
+ test += _SEP
+
+
+makeTestSuite = check
+def main():
+ unittest.main(defaultTest="makeTestSuite")
+if __name__ == "__main__" : main()
+
+
Modified: trunk/zsi/test/test_zsi.py
===================================================================
--- trunk/zsi/test/test_zsi.py 2007-01-30 17:32:19 UTC (rev 1346)
+++ trunk/zsi/test/test_zsi.py 2007-01-30 18:57:47 UTC (rev 1347)
@@ -11,6 +11,7 @@
import test_union
import test_list
import test_TCtimes
+import test_URI
import test_rfc2617
def makeTestSuite():
Modified: trunk/zsi/test/test_zsi_net.py
===================================================================
--- trunk/zsi/test/test_zsi_net.py 2007-01-30 17:32:19 UTC (rev 1346)
+++ trunk/zsi/test/test_zsi_net.py 2007-01-30 18:57:47 UTC (rev 1347)
@@ -11,6 +11,7 @@
import test_t9
import test_union
import test_TCtimes
+import test_URI
import test_list
import test_rfc2617
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|