Created
March 14, 2013 08:43
-
-
Save FelixSchwarz/5159842 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def validate_python(self, value, state): | |
import logging | |
log = logging.getLogger(__name__) | |
log.info('URIValidator: %r' % value) | |
try: | |
splitted_url = urlsplit(value) | |
except: | |
self.raise_error_bad_url(value, state) | |
scheme = splitted_url[0] # '.scheme' in Python 2.5+ | |
netloc = splitted_url[1] # '.netloc' in Python 2.5+ | |
path = splitted_url[2] # '.path' in Python 2.5+ | |
log.info('scheme: %r - netloc: %r - path: %r' % (scheme, netloc, path)) | |
# Python 2.4 does not fill netloc when parsing urls with unknown | |
# schemes (e.g. 'rtmp://') | |
netloc_given = (len(netloc) > 0) or (path.startswith('//') and path != '//') | |
log.info('netloc_given? %r' % netloc_given) | |
if (scheme == '') or not netloc_given: | |
self.raise_error_bad_url(value, state) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment