Ticket #39: urlquote.patch
| File urlquote.patch, 2.6 kB (added by John Hampton <pacopablo@pacopablo.com>, 2 years ago) |
|---|
-
pyndexter/sources/file.py
old new 22 22 import os 23 23 from stat import * 24 24 from urlparse import urlsplit, urlunsplit 25 from urllib import quote, unquote 25 26 from pyndexter import * 26 27 27 28 … … 56 57 57 58 def matches(self, uri): 58 59 scheme, netloc, path, query, fragment = urlsplit(uri, 'file') 59 path = os.path.normpath(path) 60 path = os.path.normpath(unquote(path)) 61 print "matches: path = %s" % path 60 62 return scheme == 'file' and \ 61 63 path.startswith(self.path) and \ 62 64 self.predicate(path) … … 64 66 65 67 def fetch(self, uri): 66 68 path = self._uri2file(uri) 69 print "fetch: path = %s" % path 67 70 try: 68 71 stat = os.stat(path) 69 72 except Exception, e: … … 85 88 return codecs.open(path, encoding='utf-8', errors='replace').read() 86 89 87 90 def _file2uri(self, file): 88 return urlunsplit(('file', '', file, '', ''))91 return urlunsplit(('file', '', quote(file), '', '')) 89 92 90 93 def _uri2file(self, uri): 91 94 scheme, location, path, query, fragment = urlsplit(uri, 'file') 92 95 if scheme != 'file': 93 96 raise InvalidURI("URI scheme in '%s' not supported by FileSource" 94 97 % scheme) 95 path = os.path.normpath( path)98 path = os.path.normpath(unquote(path)) 96 99 if not path.startswith(self.path): 97 100 raise InvalidURI("Requested URI '%s' is not from this FileSource" 98 101 % uri) -
pyndexter/util.py
old new 7 7 # 8 8 9 9 import re 10 from StringIO import StringIO 10 11 try: 11 12 set = set 12 13 except: … … 35 36 def __init__(self, uri=None): 36 37 if uri is not None: 37 38 from cgi import parse_qs 39 from urllib import unquote_plus 38 40 39 41 match = self._pattern.match(uri) 40 42 if match is None: 41 43 raise ValueError('Invalid URI') 42 groups = match.groups() 43 groups = groups[0:5] + (parse_qs(groups[5] or ''),) + groups[6:] 44 groups = [group or '' for group in groups] 44 groups = [g or '' for g in match.groups()] 45 def uqc(gs): 46 return [unquote_plus(g) for g in gs] 47 groups = uqc(groups[0:5]) + [parse_qs(groups[5] or '')] + \ 48 uqc(groups[6:]) 45 49 else: 46 50 groups = [''] * 7 47 51
