def testUnderEscape(self): for x in range(0, 128): unescaped = chr(x) escaped = escaping.underscore_escape(unescaped) assert safe.match(escaped), escaped self.assertEqual(unescaped, escaping.ununderscore_escape(escaped)) self.assertEqual("_2e_", escaping.underscore_escape(".")) self.assertEqual("_2e_.", escaping.underscore_escape(".."))
def escape_interface_uri(uri): """Convert an interface URI to a list of path components. e.g. "http://example.com/foo.xml" becomes ["http", "example.com", "foo.xml"], while "file:///root/feed.xml" becomes ["file", "root__feed.xml"] The number of components is determined by the scheme (three for http, two for file). Uses L{support.escaping.underscore_escape} to escape each component. """ if uri.startswith('http://') or uri.startswith('https://'): scheme, rest = uri.split('://', 1) parts = rest.split('/', 1) else: assert os.path.isabs(uri), uri scheme = 'file' parts = [uri[1:]] return [scheme] + [escaping.underscore_escape(part) for part in parts]
def check(str): self.assertEqual(str, model.unescape(model.escape(str))) self.assertEqual(str, model.unescape(model._pretty_escape(str))) self.assertEqual(str, escaping.ununderscore_escape(escaping.underscore_escape(str)))