From e22e165e4982053904b3606110d36aa3d757c2a5 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Tue, 10 Dec 2013 14:38:20 +0000 Subject: urllib: Convert URLs with non URL friendly characters into a valid format. --- morphlib/remoterepocache.py | 7 ++++--- morphlib/remoterepocache_tests.py | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/morphlib/remoterepocache.py b/morphlib/remoterepocache.py index ba4937d7..6c7cbd7f 100644 --- a/morphlib/remoterepocache.py +++ b/morphlib/remoterepocache.py @@ -19,6 +19,7 @@ import json import logging import urllib2 import urlparse +import urllib class ResolveRefError(cliapp.AppException): @@ -51,7 +52,7 @@ class RemoteRepoCache(object): self._resolver = resolver def resolve_ref(self, repo_name, ref): - repo_url = self._resolver.pull_url(repo_name) + repo_url = urllib.quote(self._resolver.pull_url(repo_name)) try: return self._resolve_ref_for_repo_url(repo_url, ref) except BaseException, e: @@ -59,7 +60,7 @@ class RemoteRepoCache(object): raise ResolveRefError(repo_name, ref) def cat_file(self, repo_name, ref, filename): - repo_url = self._resolver.pull_url(repo_name) + repo_url = urllib.quote(self._resolver.pull_url(repo_name)) try: return self._cat_file_for_repo_url(repo_url, ref, filename) except BaseException, e: @@ -67,7 +68,7 @@ class RemoteRepoCache(object): raise CatFileError(repo_name, ref, filename) def ls_tree(self, repo_name, ref): - repo_url = self._resolver.pull_url(repo_name) + repo_url = urllib.quote(self._resolver.pull_url(repo_name)) try: info = json.loads(self._ls_tree_for_repo_url(repo_url, ref)) return info['tree'].keys() diff --git a/morphlib/remoterepocache_tests.py b/morphlib/remoterepocache_tests.py index 5ef61f48..22c89bf9 100644 --- a/morphlib/remoterepocache_tests.py +++ b/morphlib/remoterepocache_tests.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012 Codethink Limited +# Copyright (C) 2012-2013 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,22 +17,23 @@ import json import unittest +import urllib import morphlib class RemoteRepoCacheTests(unittest.TestCase): def _resolve_ref_for_repo_url(self, repo_url, ref): - return self.sha1s[repo_url][ref] + return self.sha1s[urllib.unquote(repo_url)][ref] def _cat_file_for_repo_url(self, repo_url, sha1, filename): - return self.files[repo_url][sha1][filename] + return self.files[urllib.unquote(repo_url)][sha1][filename] def _ls_tree_for_repo_url(self, repo_url, sha1): return json.dumps({ 'repo': repo_url, 'ref': sha1, - 'tree': self.files[repo_url][sha1] + 'tree': self.files[urllib.unquote(repo_url)][sha1] }) def setUp(self): -- cgit v1.2.1