Package web2py :: Package gluon :: Module validators
[hide private]
[frames] | no frames]

Module validators

source code

This file is part of the web2py Web Framework Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu> License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)

Thanks to ga2arch for help with IS_IN_DB and IS_NOT_IN_DB on GAE

Classes [hide private]
  Validator
Root for all validators, mainly for documentation purposes.
  IS_MATCH
example:
  IS_EQUAL_TO
example:
  IS_EXPR
example:
  IS_LENGTH
Checks if length of field's value fits between given boundaries.
  IS_IN_SET
example:
  IS_IN_DB
example:
  IS_NOT_IN_DB
example:
  IS_INT_IN_RANGE
Determine that the argument is (or can be represented as) an int, and that it falls within the specified range.
  IS_FLOAT_IN_RANGE
Determine that the argument is (or can be represented as) a float, and that it falls within the specified inclusive range.
  IS_DECIMAL_IN_RANGE
Determine that the argument is (or can be represented as) a Python Decimal, and that it falls within the specified inclusive range.
  IS_NOT_EMPTY
example:
  IS_ALPHANUMERIC
example:
  IS_EMAIL
Checks if field's value is a valid email address.
  IS_GENERIC_URL
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 Based on RFC 2396: http://www.faqs.org/rfcs/rfc2396.html This function only checks the URL's syntax.
  IS_HTTP_URL
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 Based on RFC 2616: http://www.faqs.org/rfcs/rfc2616.html This function only checks the URL's syntax.
  IS_URL
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: http://www.faqs.org/rfcs/rfc2616.html) This function only checks the URL's syntax.
  IS_TIME
example:
  IS_DATE
example:
  IS_DATETIME
example:
  IS_DATE_IN_RANGE
example:
  IS_DATETIME_IN_RANGE
example:
  IS_LIST_OF
  IS_LOWER
convert to lower case
  IS_UPPER
convert to upper case
  IS_SLUG
convert arbitrary text string to a slug
  IS_EMPTY_OR
dummy class for testing IS_EMPTY_OR
  IS_NULL_OR
dummy class for testing IS_EMPTY_OR
  CLEANUP
example:
  CRYPT
example:
  IS_STRONG
example:
  IS_IN_SUBSET
  IS_IMAGE
Checks if file uploaded through file input was saved in one of selected image formats and has dimensions (width and height) within given boundaries.
  IS_UPLOAD_FILENAME
Checks if name and extension of file uploaded through file input matches given criteria.
  IS_IPV4
Checks if field's value is an IP version 4 address in decimal form.
Functions [hide private]
 
translate(text) source code
 
options_sorter(x, y) source code
 
is_empty(value, empty_regex=1)
test empty field
source code
 
escape_unicode(string)
Converts a unicode string into US-ASCII, using a simple conversion scheme.
source code
 
unicode_to_ascii_authority(authority)
Follows the steps in RFC 3490, Section 4 to convert a unicode authority string into its ASCII equivalent.
source code
 
unicode_to_ascii_url(url, prepend_scheme)
Converts the inputed unicode url into a US-ASCII equivalent.
source code
 
urlify(value, maxlen=80, keep_underscores=True)
Convert incoming string to a simplified ASCII subset.
source code
Variables [hide private]
  regex1 = re.compile(r'[\w_]+\.[\w_]+')
  regex2 = re.compile(r'%\((?P<name>[^\)]+)\)s')
  official_url_schemes = ['aaa', 'aaas', 'acap', 'cap', 'cid', '...
  unofficial_url_schemes = ['about', 'adiumxtra', 'aim', 'afp', ...
  all_url_schemes = [None, 'aaa', 'aaas', 'acap', 'cap', 'cid', ...
  http_schemes = [None, 'http', 'https']
  url_split_regex = re.compile(r'^(([^:/\?#]+):)?(//([^/\?#]*))?...
  label_split_regex = re.compile(r'[\.\u3002\uff0e\uff61]')
  official_top_level_domains = ['ac', 'ad', 'ae', 'aero', 'af', ...
  regex_time = re.compile(r'((?P<h>[0-9]+))([^0-9 ]+(?P<m>[0-9 ]...
Function Details [hide private]

escape_unicode(string)

source code 

Converts a unicode string into US-ASCII, using a simple conversion scheme.
Each unicode character that does not have a US-ASCII equivalent is
converted into a URL escaped form based on its hexadecimal value.
For example, the unicode character '\u4e86' will become the string '%4e%86'

:param string: unicode string, the unicode string to convert into an
    escaped US-ASCII form
:returns: the US-ASCII escaped form of the inputted string
:rtype: string

@author: Jonathan Benn

unicode_to_ascii_authority(authority)

source code 

Follows the steps in RFC 3490, Section 4 to convert a unicode authority
string into its ASCII equivalent.
For example, u'www.Alliancefrançaise.nu' will be converted into
'www.xn--alliancefranaise-npb.nu'

:param authority: unicode string, the URL authority component to convert,
                  e.g. u'www.Alliancefrançaise.nu'
:returns: the US-ASCII character equivalent to the inputed authority,
         e.g. 'www.xn--alliancefranaise-npb.nu'
:rtype: string
:raises Exception: if the function is not able to convert the inputed
    authority

@author: Jonathan Benn

unicode_to_ascii_url(url, prepend_scheme)

source code 

Converts the inputed unicode url into a US-ASCII equivalent. This function
goes a little beyond RFC 3490, which is limited in scope to the domain name
(authority) only. Here, the functionality is expanded to what was observed
on Wikipedia on 2009-Jan-22:

   Component    Can Use Unicode?
   ---------    ----------------
   scheme       No
   authority    Yes
   path         Yes
   query        Yes
   fragment     No

The authority component gets converted to punycode, but occurrences of
unicode in other components get converted into a pair of URI escapes (we
assume 4-byte unicode). E.g. the unicode character U+4E2D will be
converted into '%4E%2D'. Testing with Firefox v3.0.5 has shown that it can
understand this kind of URI encoding.

:param url: unicode string, the URL to convert from unicode into US-ASCII
:param prepend_scheme: string, a protocol scheme to prepend to the URL if
    we're having trouble parsing it.
    e.g. "http". Input None to disable this functionality
:returns: a US-ASCII equivalent of the inputed url
:rtype: string

@author: Jonathan Benn

urlify(value, maxlen=80, keep_underscores=True)

source code 
Convert incoming string to a simplified ASCII subset. if (keep_underscores): underscores are retained in the string else: underscores are translated to hyphens (default)

Variables Details [hide private]

official_url_schemes

Value:
['aaa',
 'aaas',
 'acap',
 'cap',
 'cid',
 'crid',
 'data',
 'dav',
...

unofficial_url_schemes

Value:
['about',
 'adiumxtra',
 'aim',
 'afp',
 'aw',
 'callto',
 'chrome',
 'cvs',
...

all_url_schemes

Value:
[None,
 'aaa',
 'aaas',
 'acap',
 'cap',
 'cid',
 'crid',
 'data',
...

url_split_regex

Value:
re.compile(r'^(([^:/\?#]+):)?(//([^/\?#]*))?([^\?#]*)(\?([^#]*))?(#(.*\
))?')

official_top_level_domains

Value:
['ac',
 'ad',
 'ae',
 'aero',
 'af',
 'ag',
 'ai',
 'al',
...

regex_time

Value:
re.compile(r'((?P<h>[0-9]+))([^0-9 ]+(?P<m>[0-9 ]+))?([^0-9ap ]+(?P<s>\
[0-9]*))?((?P<d>[ap]m))?')