def canonical_url_static(url, domain_check=False): # False because of S3 """ Ensure that the url contains the `http://mysite.com/STATIC_URL` part, particularly for requests made on the local dev server """ if url.startswith('http') or url.startswith('//'): return url return canonical_url(os.path.join(settings.STATIC_URL, url), domain_check)
def reverse(self, url, args, kwargs): if '/' not in url: if url.startswith('.'): url = self.controller_name + url elif url.startswith('#'): url = self.controller_name + '.' + url[1:] url = reverse(url, args=args, kwargs=kwargs) return url
def clean(self): cleanedData = self.cleaned_data url = cleanedData.get('url') if url and not url.startswith('http://'): url = 'http://' + url cleanedData['url'] = url return cleanedData
def clean(self): cleanedData = self.cleaned_data url = cleanedData.get("url") if url and not url.startswith("http://"): url = "http://" + url cleanedData["url"] = url return cleanedData
def clean(self): cleaned_data = self.cleaned_data url = cleaned_data.get('url') if url and not url.startswith('http://'): url = 'http://' + url cleaned_data['url'] = url return cleaned_data
def _fetch_url(url): if not url.startswith('http://') and not url.startswith('https://'): if '://' not in url: url = 'http://' + url else: # Must at least prevent file://, better to whitelist than blacklist raise ServiceError("Only http/https links allowed") try: url_request = urllib2.Request(url) url_response = urllib2.urlopen(url_request) except (IOError, httplib.HTTPException, UnicodeEncodeError): raise ServiceError("Unable to download image.") if url_response.getcode() != 200: raise ServiceError("The requested image could not be downloaded. Please try a different image.") else: return url_response.read()
def test_custom_oauth_url(self): """测试设置了OAUTH_URL url后 不再向微信请求授权,转向第三方请求授权""" with mock.patch.object(WeChatOAuthClient, "authorize_url"): new_url = "new_url" self.app.configurations["OAUTH_URL"] = new_url hasattr(self.app, "_oauth") and delattr(self.app, "_oauth") url = self.app.oauth.authorize_url("redirect_url") self.assertTrue(url.startswith(new_url)) delattr(self.app, "_oauth") del self.app.configurations["OAUTH_URL"]
def extract_urls(text): if text is not None: urls = [] for url in _url_regex.findall(text): if not url.startswith('//'): urls.append(append_protocol(url)) return list(set(urls)) else: return []
def processPost(url): if url == "": form = "<form action='' method='POST'>\n" form += "Url a acortar: <input type='text' name='url' value=''><br>\n" form += "<input type='submit' value='enviar'>\n" form += "</form>\n" response = "<h1> Introduzca Url a acortar </h1></br></br>" + form return HttpResponse(response) elif not url.startswith("http://") and not url.startswith("https://"): url = "http://" + url try: new_Url = Urls_DB.objects.get(url=url) except Urls_DB.DoesNotExist: new_Url = Urls_DB(url=url) new_Url.save() response = "<p>url original: <a href=" + url + ">" + url + "</a></p>" response += "<p>url acortada: <a href=" + str(new_Url.id) + ">" +\ str(new_Url.id) + "</a></p>" return HttpResponse(response)
def canonical_url(url, domain_check=False): """ Ensure that the url contains the `http://mysite.com` part, particularly for requests made on the local dev server """ domain = get_current_site_domain() if not domain.startswith('http') and not domain.startswith('//'): domain = f"http://{domain}" if not url.startswith('http') and not url.startswith('//'): url = os.path.join(domain, url.lstrip('/')) if domain_check: url_parts = URL(url) current_site_parts = URL(URL().domain(domain).as_string()) if url_parts.subdomains()[-2:] != current_site_parts.subdomains()[-2:]: raise ValueError("Suspicious domain '%s' that differs from the " "current Site one '%s'" % (url_parts.domain(), current_site_parts.domain())) return url
def _cleanup_url(url): #remove leading "/" if any while url.startswith("/") : url= url[1:] #remove trailing "/" if any while url.endswith("/") : url= url[:-1] if url and not url.endswith("/"): url+="/" return url
def parse_url(request, url): """Parse url URL parameter.""" try: validate = URLValidator() validate(url) except ValidationError: if url.startswith('/'): host = request.get_host() scheme = 'https' if request.is_secure() else 'http' url = '{scheme}://{host}{uri}'.format(scheme=scheme, host=host, uri=url) else: url = request.build_absolute_uri(reverse(url)) return url
def verify_first_party_url(url): """ Also allows iTunes store URLs. """ if not url or not url.startswith('/'): parsed_url = urlparse.urlparse(url) try: protocol = parsed_url[0] domain = parsed_url[1] except IndexError: raise ServiceError("Invalid share url.") if protocol not in ['http', 'https'] or domain not in ['itunes.apple.com', 'example.com', 'staging.example.com']: # Only 1st party redirects, to avoid security holes that 3rd party redirects imply raise ServiceError("Invalid share url.")
def is_immutable_file(self, static_file, url): """ Determine whether given URL represents an immutable file (i.e. a file with a hash of its contents as part of its name) which can therefore be cached forever """ if not url.startswith(self.static_prefix): return False name = url[len(self.static_prefix):] name_without_hash = self.get_name_without_hash(name) if name == name_without_hash: return False static_url = self.get_static_url(name_without_hash) # If the static URL function maps the name without hash # back to the original URL, then we know we've got a # versioned filename if static_url and static_url.endswith(url): return True return False
def _build_urlmap(): """Creating a url map for all dojo modules (dojo-media directory), that are available within activated apps.""" seen = {} valid_urls = [] # keep the order! for app in dojo_media_apps: root_and_urls = dojo_media_library[app] for elem in root_and_urls: root, url = elem if url.startswith('/'): url = url[1:] if url in seen: continue valid_urls.append((url, root)) seen[url] = root base_url = dojango_settings.DOJO_MEDIA_URL # dojango_settings.BASE_MEDIA_URL if base_url.startswith('/'): base_url = base_url[1:] # all new modules need to be available next to dojo, so we need to allow a version-string in between # e.g. /dojo-media/1.3.1/mydojonamespace == /dojo-media/1.2.0/mydojonamespace valid_urls = [("%(base_url)s/([\w\d\.\-]*/)?%(url)s" % { 'base_url': base_url, 'url': m[0] }, m[1]) for m in valid_urls] valid_urls.append(("%(base_url)s/release/" % {'base_url': base_url}, path.join(dojango_settings.BASE_MEDIA_ROOT, "release"))) valid_urls.append(("%(base_url)s/" % {'base_url': base_url}, path.join(dojango_settings.BASE_MEDIA_ROOT, "src"))) return valid_urls
def external_url(url): if not url.startswith('http') and not url.startswith('//'): return f"http://{url}" return url
def redirect(self,url,**kwargs): if not self.is_ajax: return redirect(url) external = url.startswith("https") or url == self.get_done_url() return ajax_redirect(url,not external,**kwargs)
def append_protocol(url): if url: if not (url.startswith('http://') or url.startswith('https://')): url = f"http://{url}" return url
def ensure_absolute_url(self, request, url): if not (url.startswith('http://') or url.startswith('https://')): url = request.build_absolute_uri(url) return url