49 Ví dụ về mã Python được tìm thấy liên quan đến "URL sạch". Bạn có thể bỏ phiếu cho những người bạn thích hoặc bỏ phiếu cho những người bạn không thích và đi đến dự án gốc hoặc tệp nguồn bằng cách theo các liên kết trên mỗi ví dụ. clean url". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
ví dụ 1
def clean_url[url, base_url=None]: """Add base netloc and path to internal URLs and remove www, fragments.""" parsed_url = urlparse[url] fragment = "{url.fragment}".format[url=parsed_url] if fragment: url = url.split[fragment][0] # Identify internal URLs and fix their format netloc = "{url.netloc}".format[url=parsed_url] if base_url is not None and not netloc: parsed_base = urlparse[base_url] split_base = "{url.scheme}://{url.netloc}{url.path}/".format[url=parsed_base] url = urljoin[split_base, url] netloc = "{url.netloc}".format[url=urlparse[url]] if "www." in netloc: url = url.replace[netloc, netloc.replace["www.", ""]] return url.rstrip[string.punctuation]
Ví dụ 2
def clean_url[self]: url = self.cleaned_data['url'] if self.check_is_empty[url]: raise forms.ValidationError["No URL given."] if self.component.prefix: # check that the URL starts with the provided prefix if not url.startswith[self.component.prefix]: raise forms.ValidationError['Submitted URL must start with "%s".' % [self.component.prefix]] if self.component.check: # instructor asked to check that URLs really exist: do it. validator = QuickURLValidator[] try: validator[url] # throws ValidationError if there's a problem except forms.ValidationError: # re-throw to produce a better error message raise forms.ValidationError["The submitted URL doesn't seem to exist: please check the URL and resubmit."] return url
Ví dụ 3
def clean_keyserver_url[self]: url = self.cleaned_data.get["keyserver_url", ""] if url: try: res = requests.get[url] except: self.add_error["keyserver_url", _["Could not access the specified url"]] return url begin = res.text.find["-----BEGIN PGP PUBLIC KEY BLOCK-----"] end = res.text.find["-----END PGP PUBLIC KEY BLOCK-----"] if 200 = 0 and end > begin: self.pub_key = res.text[begin:end + 34] else: self.add_error["keyserver_url", _['This url does not have a pgp key']] return url
Ví dụ 4
def clean_url[url, encoding='utf-8']: # percent-encode illegal URI characters # Trying to come up with test cases for this gave me a headache, revisit # when do switch to unicode. # Somebody else's comments [lost the attribution]: # - IE will return you the url in the encoding you send it # - Mozilla/Firefox will send you latin-1 if there's no non latin-1 # characters in your link. It will send you utf-8 however if there are... is_unicode = not isinstance[url, bytes] if not is_unicode: url = url.decode[encoding, "replace"] url = url.strip[] # for second param to urllib.quote[], we want URI_CHARS, minus the # 'always_safe' characters that urllib.quote[] never percent-encodes ans = quote[url.encode[encoding], "!*'[];:@&=+$,/?%#[]~"] if is_unicode and isinstance[ans, bytes]: ans = ans.decode[encoding] return ans
Ví dụ 5
def clean_url[url]: """Remove extraneous characters from URL. Params: - url: [type: string] URL to clean. Returns: - url: [type: string] clean URL. """ if url is None: return None if '??' in url: url = url.split['??'][0] if url.endswith['?']: url = url[:-1] if '`' in url: url = url.replace['`', ''] return url
Ví dụ 6
def clean_url[url, encoding='utf-8']: # percent-encode illegal URI characters # Trying to come up with test cases for this gave me a headache, revisit # when do switch to unicode. # Somebody else's comments [lost the attribution]: # - IE will return you the url in the encoding you send it # - Mozilla/Firefox will send you latin-1 if there's no non latin-1 # characters in your link. It will send you utf-8 however if there are... is_unicode = not isinstance[url, bytes] if not is_unicode: url = url.decode[encoding, "replace"] url = url.strip[] # for second param to urllib.quote[], we want URI_CHARS, minus the # 'always_safe' characters that urllib.quote[] never percent-encodes ans = quote[url.encode[encoding], "!*'[];:@&=+$,/?%#[]~"] if is_unicode and isinstance[ans, bytes]: ans = ans.decode[encoding] return ans
Ví dụ 7
def clean_api_url_response[url_response]: """ clean the string to a valid URL field [used with API data, because sometimes there are multiple or entries """ clean_response = url_response.strip[] if url_response != "": clean_response = clean_response if ";" not in clean_response else clean_response.split[";"][0] clean_response = clean_response if " or //" not in clean_response \ else clean_response.split[" or //"][0] clean_response = clean_response if " and //" not in clean_response \ else clean_response.split[" and //"][0] clean_response = clean_response if " //" not in clean_response \ else clean_response.split[" //"][0] clean_response = clean_response if " and //" not in clean_response \ else clean_response.split[" and //"][0] clean_response = clean_response if " or //" not in clean_response \ else clean_response.split[" or //"][0] clean_response = clean_response if " //" not in clean_response \ else clean_response.split[" //"][0] return clean_response
Ví dụ 8
def clean_url[self] -> str: url = self.cleaned_data.get['url'] url = normalize_url[url] # TODO: This is not a real validity check if '.' not in url: raise ValidationError[_['The url is not valid.']] return url
Ví dụ 9
def cleanUrl[text]: url = text.replace[' ', '%20'] # replace spaces with %20 return url # Function: generateApiQuery # Date Created: 29/03/2017 # Author: Todd Johnson # # Description: Generates an API Query that is compatible with Sonarr. # # @param endpoint | STR | The Sonarr API endpoint for query # @param parameters | DICT | Add any parameters to query # @return url | STR | HTTP api query string
Ví dụ 10
def cleanRequestURL[url]: """Clean a URL from a Request line.""" url.transport = None url.maddr = None url.ttl = None url.headers = {}
Ví dụ 11
def clean_url[self]: url = self.cleaned_data['url'] if self.check_is_empty[url]: raise forms.ValidationError["No URL given."] if self.component.prefix: # check that the URL starts with the provided prefix if not url.startswith[self.component.prefix]: raise forms.ValidationError['Submitted URL must start with "%s".' % [self.component.prefix]] if self.component.check: # instructor asked to check that URLs really exist: do it. validator = QuickURLValidator[] try: validator[url] # throws ValidationError if there's a problem except forms.ValidationError: # re-throw to produce a better error message raise forms.ValidationError["The submitted URL doesn't seem to exist: please check the URL and resubmit."] return url0
Ví dụ 12
def clean_url[self]: url = self.cleaned_data['url'] if self.check_is_empty[url]: raise forms.ValidationError["No URL given."] if self.component.prefix: # check that the URL starts with the provided prefix if not url.startswith[self.component.prefix]: raise forms.ValidationError['Submitted URL must start with "%s".' % [self.component.prefix]] if self.component.check: # instructor asked to check that URLs really exist: do it. validator = QuickURLValidator[] try: validator[url] # throws ValidationError if there's a problem except forms.ValidationError: # re-throw to produce a better error message raise forms.ValidationError["The submitted URL doesn't seem to exist: please check the URL and resubmit."] return url1
Ví dụ 13
def clean_url[self]: url = self.cleaned_data['url'] if self.check_is_empty[url]: raise forms.ValidationError["No URL given."] if self.component.prefix: # check that the URL starts with the provided prefix if not url.startswith[self.component.prefix]: raise forms.ValidationError['Submitted URL must start with "%s".' % [self.component.prefix]] if self.component.check: # instructor asked to check that URLs really exist: do it. validator = QuickURLValidator[] try: validator[url] # throws ValidationError if there's a problem except forms.ValidationError: # re-throw to produce a better error message raise forms.ValidationError["The submitted URL doesn't seem to exist: please check the URL and resubmit."] return url2
Ví dụ 14
def clean_url[self]: url = self.cleaned_data['url'] if self.check_is_empty[url]: raise forms.ValidationError["No URL given."] if self.component.prefix: # check that the URL starts with the provided prefix if not url.startswith[self.component.prefix]: raise forms.ValidationError['Submitted URL must start with "%s".' % [self.component.prefix]] if self.component.check: # instructor asked to check that URLs really exist: do it. validator = QuickURLValidator[] try: validator[url] # throws ValidationError if there's a problem except forms.ValidationError: # re-throw to produce a better error message raise forms.ValidationError["The submitted URL doesn't seem to exist: please check the URL and resubmit."] return url3
Ví dụ 15
def clean_url[self]: url = self.cleaned_data['url'] if self.check_is_empty[url]: raise forms.ValidationError["No URL given."] if self.component.prefix: # check that the URL starts with the provided prefix if not url.startswith[self.component.prefix]: raise forms.ValidationError['Submitted URL must start with "%s".' % [self.component.prefix]] if self.component.check: # instructor asked to check that URLs really exist: do it. validator = QuickURLValidator[] try: validator[url] # throws ValidationError if there's a problem except forms.ValidationError: # re-throw to produce a better error message raise forms.ValidationError["The submitted URL doesn't seem to exist: please check the URL and resubmit."] return url4
Ví dụ 16
def clean_url[self]: url = self.cleaned_data['url'] if self.check_is_empty[url]: raise forms.ValidationError["No URL given."] if self.component.prefix: # check that the URL starts with the provided prefix if not url.startswith[self.component.prefix]: raise forms.ValidationError['Submitted URL must start with "%s".' % [self.component.prefix]] if self.component.check: # instructor asked to check that URLs really exist: do it. validator = QuickURLValidator[] try: validator[url] # throws ValidationError if there's a problem except forms.ValidationError: # re-throw to produce a better error message raise forms.ValidationError["The submitted URL doesn't seem to exist: please check the URL and resubmit."] return url5
Ví dụ 17
def clean_url[self]: url = self.cleaned_data['url'] if self.check_is_empty[url]: raise forms.ValidationError["No URL given."] if self.component.prefix: # check that the URL starts with the provided prefix if not url.startswith[self.component.prefix]: raise forms.ValidationError['Submitted URL must start with "%s".' % [self.component.prefix]] if self.component.check: # instructor asked to check that URLs really exist: do it. validator = QuickURLValidator[] try: validator[url] # throws ValidationError if there's a problem except forms.ValidationError: # re-throw to produce a better error message raise forms.ValidationError["The submitted URL doesn't seem to exist: please check the URL and resubmit."] return url6
Ví dụ 18
def clean_url[self]: url = self.cleaned_data['url'] if self.check_is_empty[url]: raise forms.ValidationError["No URL given."] if self.component.prefix: # check that the URL starts with the provided prefix if not url.startswith[self.component.prefix]: raise forms.ValidationError['Submitted URL must start with "%s".' % [self.component.prefix]] if self.component.check: # instructor asked to check that URLs really exist: do it. validator = QuickURLValidator[] try: validator[url] # throws ValidationError if there's a problem except forms.ValidationError: # re-throw to produce a better error message raise forms.ValidationError["The submitted URL doesn't seem to exist: please check the URL and resubmit."] return url7
Ví dụ 19
def clean_url[self]: url = self.cleaned_data['url'] if self.check_is_empty[url]: raise forms.ValidationError["No URL given."] if self.component.prefix: # check that the URL starts with the provided prefix if not url.startswith[self.component.prefix]: raise forms.ValidationError['Submitted URL must start with "%s".' % [self.component.prefix]] if self.component.check: # instructor asked to check that URLs really exist: do it. validator = QuickURLValidator[] try: validator[url] # throws ValidationError if there's a problem except forms.ValidationError: # re-throw to produce a better error message raise forms.ValidationError["The submitted URL doesn't seem to exist: please check the URL and resubmit."] return url8
Ví dụ 20
def clean_url[self]: url = self.cleaned_data['url'] if self.check_is_empty[url]: raise forms.ValidationError["No URL given."] if self.component.prefix: # check that the URL starts with the provided prefix if not url.startswith[self.component.prefix]: raise forms.ValidationError['Submitted URL must start with "%s".' % [self.component.prefix]] if self.component.check: # instructor asked to check that URLs really exist: do it. validator = QuickURLValidator[] try: validator[url] # throws ValidationError if there's a problem except forms.ValidationError: # re-throw to produce a better error message raise forms.ValidationError["The submitted URL doesn't seem to exist: please check the URL and resubmit."] return url9
Ví dụ 21
def clean_keyserver_url[self]: url = self.cleaned_data.get["keyserver_url", ""] if url: try: res = requests.get[url] except: self.add_error["keyserver_url", _["Could not access the specified url"]] return url begin = res.text.find["-----BEGIN PGP PUBLIC KEY BLOCK-----"] end = res.text.find["-----END PGP PUBLIC KEY BLOCK-----"] if 200 = 0 and end > begin: self.pub_key = res.text[begin:end + 34] else: self.add_error["keyserver_url", _['This url does not have a pgp key']] return url0
Ví dụ 22
def clean_keyserver_url[self]: url = self.cleaned_data.get["keyserver_url", ""] if url: try: res = requests.get[url] except: self.add_error["keyserver_url", _["Could not access the specified url"]] return url begin = res.text.find["-----BEGIN PGP PUBLIC KEY BLOCK-----"] end = res.text.find["-----END PGP PUBLIC KEY BLOCK-----"] if 200 = 0 and end > begin: self.pub_key = res.text[begin:end + 34] else: self.add_error["keyserver_url", _['This url does not have a pgp key']] return url1
Ví dụ 23
def clean_url[self]: url = self.cleaned_data['url'] if self.check_is_empty[url]: raise forms.ValidationError["No URL given."] if self.component.prefix: # check that the URL starts with the provided prefix if not url.startswith[self.component.prefix]: raise forms.ValidationError['Submitted URL must start with "%s".' % [self.component.prefix]] if self.component.check: # instructor asked to check that URLs really exist: do it. validator = QuickURLValidator[] try: validator[url] # throws ValidationError if there's a problem except forms.ValidationError: # re-throw to produce a better error message raise forms.ValidationError["The submitted URL doesn't seem to exist: please check the URL and resubmit."] return url8
Ví dụ 24
def clean_keyserver_url[self]: url = self.cleaned_data.get["keyserver_url", ""] if url: try: res = requests.get[url] except: self.add_error["keyserver_url", _["Could not access the specified url"]] return url begin = res.text.find["-----BEGIN PGP PUBLIC KEY BLOCK-----"] end = res.text.find["-----END PGP PUBLIC KEY BLOCK-----"] if 200 = 0 and end > begin: self.pub_key = res.text[begin:end + 34] else: self.add_error["keyserver_url", _['This url does not have a pgp key']] return url3
Ví dụ 25
def clean_keyserver_url[self]: url = self.cleaned_data.get["keyserver_url", ""] if url: try: res = requests.get[url] except: self.add_error["keyserver_url", _["Could not access the specified url"]] return url begin = res.text.find["-----BEGIN PGP PUBLIC KEY BLOCK-----"] end = res.text.find["-----END PGP PUBLIC KEY BLOCK-----"] if 200 = 0 and end > begin: self.pub_key = res.text[begin:end + 34] else: self.add_error["keyserver_url", _['This url does not have a pgp key']] return url4
Ví dụ 26
def clean_keyserver_url[self]: url = self.cleaned_data.get["keyserver_url", ""] if url: try: res = requests.get[url] except: self.add_error["keyserver_url", _["Could not access the specified url"]] return url begin = res.text.find["-----BEGIN PGP PUBLIC KEY BLOCK-----"] end = res.text.find["-----END PGP PUBLIC KEY BLOCK-----"] if 200 = 0 and end > begin: self.pub_key = res.text[begin:end + 34] else: self.add_error["keyserver_url", _['This url does not have a pgp key']] return url5
Ví dụ 27
def clean_url[self]: url = self.cleaned_data['url'] if self.check_is_empty[url]: raise forms.ValidationError["No URL given."] if self.component.prefix: # check that the URL starts with the provided prefix if not url.startswith[self.component.prefix]: raise forms.ValidationError['Submitted URL must start with "%s".' % [self.component.prefix]] if self.component.check: # instructor asked to check that URLs really exist: do it. validator = QuickURLValidator[] try: validator[url] # throws ValidationError if there's a problem except forms.ValidationError: # re-throw to produce a better error message raise forms.ValidationError["The submitted URL doesn't seem to exist: please check the URL and resubmit."] return url0
Ví dụ 28
def clean_keyserver_url[self]: url = self.cleaned_data.get["keyserver_url", ""] if url: try: res = requests.get[url] except: self.add_error["keyserver_url", _["Could not access the specified url"]] return url begin = res.text.find["-----BEGIN PGP PUBLIC KEY BLOCK-----"] end = res.text.find["-----END PGP PUBLIC KEY BLOCK-----"] if 200 = 0 and end > begin: self.pub_key = res.text[begin:end + 34] else: self.add_error["keyserver_url", _['This url does not have a pgp key']] return url3
Ví dụ 29
def clean_keyserver_url[self]: url = self.cleaned_data.get["keyserver_url", ""] if url: try: res = requests.get[url] except: self.add_error["keyserver_url", _["Could not access the specified url"]] return url begin = res.text.find["-----BEGIN PGP PUBLIC KEY BLOCK-----"] end = res.text.find["-----END PGP PUBLIC KEY BLOCK-----"] if 200 = 0 and end > begin: self.pub_key = res.text[begin:end + 34] else: self.add_error["keyserver_url", _['This url does not have a pgp key']] return url8
Ví dụ 30
def clean_keyserver_url[self]: url = self.cleaned_data.get["keyserver_url", ""] if url: try: res = requests.get[url] except: self.add_error["keyserver_url", _["Could not access the specified url"]] return url begin = res.text.find["-----BEGIN PGP PUBLIC KEY BLOCK-----"] end = res.text.find["-----END PGP PUBLIC KEY BLOCK-----"] if 200 = 0 and end > begin: self.pub_key = res.text[begin:end + 34] else: self.add_error["keyserver_url", _['This url does not have a pgp key']] return url9
Ví dụ 31
def clean_url[url, encoding='utf-8']: # percent-encode illegal URI characters # Trying to come up with test cases for this gave me a headache, revisit # when do switch to unicode. # Somebody else's comments [lost the attribution]: # - IE will return you the url in the encoding you send it # - Mozilla/Firefox will send you latin-1 if there's no non latin-1 # characters in your link. It will send you utf-8 however if there are... is_unicode = not isinstance[url, bytes] if not is_unicode: url = url.decode[encoding, "replace"] url = url.strip[] # for second param to urllib.quote[], we want URI_CHARS, minus the # 'always_safe' characters that urllib.quote[] never percent-encodes ans = quote[url.encode[encoding], "!*'[];:@&=+$,/?%#[]~"] if is_unicode and isinstance[ans, bytes]: ans = ans.decode[encoding] return ans0
Ví dụ 32
def clean_url[url, encoding='utf-8']: # percent-encode illegal URI characters # Trying to come up with test cases for this gave me a headache, revisit # when do switch to unicode. # Somebody else's comments [lost the attribution]: # - IE will return you the url in the encoding you send it # - Mozilla/Firefox will send you latin-1 if there's no non latin-1 # characters in your link. It will send you utf-8 however if there are... is_unicode = not isinstance[url, bytes] if not is_unicode: url = url.decode[encoding, "replace"] url = url.strip[] # for second param to urllib.quote[], we want URI_CHARS, minus the # 'always_safe' characters that urllib.quote[] never percent-encodes ans = quote[url.encode[encoding], "!*'[];:@&=+$,/?%#[]~"] if is_unicode and isinstance[ans, bytes]: ans = ans.decode[encoding] return ans1
Ví dụ 33
def clean_url[url, encoding='utf-8']: # percent-encode illegal URI characters # Trying to come up with test cases for this gave me a headache, revisit # when do switch to unicode. # Somebody else's comments [lost the attribution]: # - IE will return you the url in the encoding you send it # - Mozilla/Firefox will send you latin-1 if there's no non latin-1 # characters in your link. It will send you utf-8 however if there are... is_unicode = not isinstance[url, bytes] if not is_unicode: url = url.decode[encoding, "replace"] url = url.strip[] # for second param to urllib.quote[], we want URI_CHARS, minus the # 'always_safe' characters that urllib.quote[] never percent-encodes ans = quote[url.encode[encoding], "!*'[];:@&=+$,/?%#[]~"] if is_unicode and isinstance[ans, bytes]: ans = ans.decode[encoding] return ans2
Ví dụ 34
def clean_url[url, encoding='utf-8']: # percent-encode illegal URI characters # Trying to come up with test cases for this gave me a headache, revisit # when do switch to unicode. # Somebody else's comments [lost the attribution]: # - IE will return you the url in the encoding you send it # - Mozilla/Firefox will send you latin-1 if there's no non latin-1 # characters in your link. It will send you utf-8 however if there are... is_unicode = not isinstance[url, bytes] if not is_unicode: url = url.decode[encoding, "replace"] url = url.strip[] # for second param to urllib.quote[], we want URI_CHARS, minus the # 'always_safe' characters that urllib.quote[] never percent-encodes ans = quote[url.encode[encoding], "!*'[];:@&=+$,/?%#[]~"] if is_unicode and isinstance[ans, bytes]: ans = ans.decode[encoding] return ans3
Ví dụ 35
def clean_url[url, encoding='utf-8']: # percent-encode illegal URI characters # Trying to come up with test cases for this gave me a headache, revisit # when do switch to unicode. # Somebody else's comments [lost the attribution]: # - IE will return you the url in the encoding you send it # - Mozilla/Firefox will send you latin-1 if there's no non latin-1 # characters in your link. It will send you utf-8 however if there are... is_unicode = not isinstance[url, bytes] if not is_unicode: url = url.decode[encoding, "replace"] url = url.strip[] # for second param to urllib.quote[], we want URI_CHARS, minus the # 'always_safe' characters that urllib.quote[] never percent-encodes ans = quote[url.encode[encoding], "!*'[];:@&=+$,/?%#[]~"] if is_unicode and isinstance[ans, bytes]: ans = ans.decode[encoding] return ans4
Ví dụ 36
def clean_url[self]: url = self.cleaned_data['url'] if self.check_is_empty[url]: raise forms.ValidationError["No URL given."] if self.component.prefix: # check that the URL starts with the provided prefix if not url.startswith[self.component.prefix]: raise forms.ValidationError['Submitted URL must start with "%s".' % [self.component.prefix]] if self.component.check: # instructor asked to check that URLs really exist: do it. validator = QuickURLValidator[] try: validator[url] # throws ValidationError if there's a problem except forms.ValidationError: # re-throw to produce a better error message raise forms.ValidationError["The submitted URL doesn't seem to exist: please check the URL and resubmit."] return url1
Ví dụ 37
def clean_url[self]: url = self.cleaned_data['url'] if self.check_is_empty[url]: raise forms.ValidationError["No URL given."] if self.component.prefix: # check that the URL starts with the provided prefix if not url.startswith[self.component.prefix]: raise forms.ValidationError['Submitted URL must start with "%s".' % [self.component.prefix]] if self.component.check: # instructor asked to check that URLs really exist: do it. validator = QuickURLValidator[] try: validator[url] # throws ValidationError if there's a problem except forms.ValidationError: # re-throw to produce a better error message raise forms.ValidationError["The submitted URL doesn't seem to exist: please check the URL and resubmit."] return url3
Ví dụ 38
def clean_url[url, encoding='utf-8']: # percent-encode illegal URI characters # Trying to come up with test cases for this gave me a headache, revisit # when do switch to unicode. # Somebody else's comments [lost the attribution]: # - IE will return you the url in the encoding you send it # - Mozilla/Firefox will send you latin-1 if there's no non latin-1 # characters in your link. It will send you utf-8 however if there are... is_unicode = not isinstance[url, bytes] if not is_unicode: url = url.decode[encoding, "replace"] url = url.strip[] # for second param to urllib.quote[], we want URI_CHARS, minus the # 'always_safe' characters that urllib.quote[] never percent-encodes ans = quote[url.encode[encoding], "!*'[];:@&=+$,/?%#[]~"] if is_unicode and isinstance[ans, bytes]: ans = ans.decode[encoding] return ans7
Ví dụ 39
def clean_url[url, encoding='utf-8']: # percent-encode illegal URI characters # Trying to come up with test cases for this gave me a headache, revisit # when do switch to unicode. # Somebody else's comments [lost the attribution]: # - IE will return you the url in the encoding you send it # - Mozilla/Firefox will send you latin-1 if there's no non latin-1 # characters in your link. It will send you utf-8 however if there are... is_unicode = not isinstance[url, bytes] if not is_unicode: url = url.decode[encoding, "replace"] url = url.strip[] # for second param to urllib.quote[], we want URI_CHARS, minus the # 'always_safe' characters that urllib.quote[] never percent-encodes ans = quote[url.encode[encoding], "!*'[];:@&=+$,/?%#[]~"] if is_unicode and isinstance[ans, bytes]: ans = ans.decode[encoding] return ans8
Ví dụ 40
def clean_url[self]: url = self.cleaned_data['url'] if self.check_is_empty[url]: raise forms.ValidationError["No URL given."] if self.component.prefix: # check that the URL starts with the provided prefix if not url.startswith[self.component.prefix]: raise forms.ValidationError['Submitted URL must start with "%s".' % [self.component.prefix]] if self.component.check: # instructor asked to check that URLs really exist: do it. validator = QuickURLValidator[] try: validator[url] # throws ValidationError if there's a problem except forms.ValidationError: # re-throw to produce a better error message raise forms.ValidationError["The submitted URL doesn't seem to exist: please check the URL and resubmit."] return url5
Ví dụ 41
def clean_url[url]: """Remove extraneous characters from URL. Params: - url: [type: string] URL to clean. Returns: - url: [type: string] clean URL. """ if url is None: return None if '??' in url: url = url.split['??'][0] if url.endswith['?']: url = url[:-1] if '`' in url: url = url.replace['`', ''] return url0
Ví dụ 42
def clean_url[url]: """Remove extraneous characters from URL. Params: - url: [type: string] URL to clean. Returns: - url: [type: string] clean URL. """ if url is None: return None if '??' in url: url = url.split['??'][0] if url.endswith['?']: url = url[:-1] if '`' in url: url = url.replace['`', ''] return url1
Ví dụ 43
def clean_url[url]: """Remove extraneous characters from URL. Params: - url: [type: string] URL to clean. Returns: - url: [type: string] clean URL. """ if url is None: return None if '??' in url: url = url.split['??'][0] if url.endswith['?']: url = url[:-1] if '`' in url: url = url.replace['`', ''] return url2
Ví dụ 44
def clean_url[url]: """Remove extraneous characters from URL. Params: - url: [type: string] URL to clean. Returns: - url: [type: string] clean URL. """ if url is None: return None if '??' in url: url = url.split['??'][0] if url.endswith['?']: url = url[:-1] if '`' in url: url = url.replace['`', ''] return url3
Ví dụ 45
def clean_url[url, encoding='utf-8']: # percent-encode illegal URI characters # Trying to come up with test cases for this gave me a headache, revisit # when do switch to unicode. # Somebody else's comments [lost the attribution]: # - IE will return you the url in the encoding you send it # - Mozilla/Firefox will send you latin-1 if there's no non latin-1 # characters in your link. It will send you utf-8 however if there are... is_unicode = not isinstance[url, bytes] if not is_unicode: url = url.decode[encoding, "replace"] url = url.strip[] # for second param to urllib.quote[], we want URI_CHARS, minus the # 'always_safe' characters that urllib.quote[] never percent-encodes ans = quote[url.encode[encoding], "!*'[];:@&=+$,/?%#[]~"] if is_unicode and isinstance[ans, bytes]: ans = ans.decode[encoding] return ans4
Ví dụ 46
def clean_url[url]: """Remove extraneous characters from URL. Params: - url: [type: string] URL to clean. Returns: - url: [type: string] clean URL. """ if url is None: return None if '??' in url: url = url.split['??'][0] if url.endswith['?']: url = url[:-1] if '`' in url: url = url.replace['`', ''] return url5
Ví dụ 47
def clean_url[url]: """Remove extraneous characters from URL. Params: - url: [type: string] URL to clean. Returns: - url: [type: string] clean URL. """ if url is None: return None if '??' in url: url = url.split['??'][0] if url.endswith['?']: url = url[:-1] if '`' in url: url = url.replace['`', ''] return url6
Ví dụ 48
def clean_url[url]: """Remove extraneous characters from URL. Params: - url: [type: string] URL to clean. Returns: - url: [type: string] clean URL. """ if url is None: return None if '??' in url: url = url.split['??'][0] if url.endswith['?']: url = url[:-1] if '`' in url: url = url.replace['`', ''] return url7
Ví dụ 49
def cleanRequestURL[url]: """Clean a URL from a Request line.""" url.transport = None url.maddr = None url.ttl = None url.headers = {}