diff options
| author | Sergey M․ <dstftw@gmail.com> | 2014-09-13 20:59:16 +0700 | 
|---|---|---|
| committer | Sergey M․ <dstftw@gmail.com> | 2014-09-13 20:59:16 +0700 | 
| commit | d05cfe06006c4a44032e95dde047d5e12be8674c (patch) | |
| tree | c22a5e7c048e7dbef1155beb74fd2f51154c64f1 /youtube_dl/YoutubeDL.py | |
| parent | 37419b4f9937f11ed3ca3545a32ed3451eb734ee (diff) | |
[YoutubeDL/utils] Clarify rationale for URL escaping in comment, move escape routines to utils and add some tests
Diffstat (limited to 'youtube_dl/YoutubeDL.py')
| -rwxr-xr-x | youtube_dl/YoutubeDL.py | 20 | 
1 files changed, 7 insertions, 13 deletions
| diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 99cd05e65..9519594c9 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -28,7 +28,7 @@ from .utils import (      compat_str,      compat_urllib_error,      compat_urllib_request, -    compat_urllib_parse_urlparse, +    escape_url,      ContentTooShortError,      date_from_str,      DateRange, @@ -1243,20 +1243,14 @@ class YoutubeDL(object):      def urlopen(self, req):          """ Start an HTTP download """ +        # According to RFC 3986, URLs can not contain non-ASCII characters, however this is not +        # always respected by websites, some tend to give out URLs with non percent-encoded +        # non-ASCII characters (see telemb.py, ard.py [#3412])          # urllib chokes on URLs with non-ASCII characters (see http://bugs.python.org/issue3991) -        # Working around by replacing request's original URL with escaped one - +        # To work around aforementioned issue we will replace request's original URL with +        # percent-encoded one          url = req if isinstance(req, compat_str) else req.get_full_url() - -        def escape(component): -            return compat_cookiejar.escape_path(component.encode('utf-8')) - -        url_parsed = compat_urllib_parse_urlparse(url) -        url_escaped = url_parsed._replace( -            path=escape(url_parsed.path), -            query=escape(url_parsed.query), -            fragment=escape(url_parsed.fragment) -        ).geturl() +        url_escaped = escape_url(url)          # Substitute URL if any change after escaping          if url != url_escaped: | 
