• 2712 views
  • 0 comments
  • loading...

Only checks the URL's syntax

Rejects a URL string if any of the following is true:
  • The string is empty or None
  • The string uses characters that are not allowed in a URL
  • The string breaks any of the HTTP syntactic rules
  • The URL scheme specified (if one is specified) is not 'http' or 'https'
  • The top-level domain (if a host name is specified) does not exist
(These rules are based on RFC 2616[RFC2616] )

This function only checks the URL's syntax. It does not check that the URL points to a real document, for example, or that it otherwise makes semantic sense. This function does automatically prepend 'http://' in front of a URL in the case of an abbreviated URL (e.g. 'google.ie').

IS_URL is compatible with the Internationalized Domain Name (IDN) standard specified in RFC 3490 ). As a result, URLs can be regular strings or unicode strings. If the URL's domain component (e.g. google.ie) contains non-US-ASCII letters, then the domain will be converted into Punycode (defined in RFC 3492 ). IS_URL goes a bit beyond the standards, and allows non-US-ASCII characters to be present in the path and query components of the URL as well. These non-US-ASCII characters will be encoded. For example, space will be encoded as'%20'. The unicode character with hex code 0x4e86 will become '%4e%86'.







requires = IS_URL())

requires = IS_URL(mode='generic')
requires = IS_URL(allowed_schemes=['https'])
requires = IS_URL(prepend_scheme='https')
requires = IS_URL(mode='generic',
allowed_schemes=['ftps', 'https'],
prepend_scheme='https')

Attributes / Arguments

If the parameter mode='generic' is used, then this function's behavior changes. It then rejects a URL string if any of the following is true:
  • The string is empty or None
  • The string uses characters that are not allowed in a URL
  • The URL scheme specified (if one is specified) is not valid
(These rules are based on RFC 2396 )

requires = IS_URL(mode='generic')

The list of allowed schemes is customizable with the allowed_schemes parameter. If you exclude None from the list, then abbreviated URLs (lacking a scheme such as 'http') will be rejected.

requires = IS_URL(allowed_schemes=['https'])

The default prepended scheme is customizable with the prepend_scheme parameter. If you set prepend_scheme to None, then prepending will be disabled. URLs that require prepending to parse will still be accepted, but the return value will not be modified.

requires = IS_URL(prepend_scheme='https')


loading...

Sources / Reference

" Web2py Book"


Comments

loading...

Powered by
Web2py

Hosted on
www.pythonanywhere.com
(affiliated link)