Home | Trees | Indices | Help |
|
---|
|
| 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)
Template helpers --------------------------------------------
|
|||
XmlComponent Abstract root for all Html components |
|||
XML use it to wrap a string that contains XML/HTML so that it will not be escaped by the template |
|||
DIV HTML helper, for easy generating and manipulating a DOM structure. |
|||
CAT | |||
__tag_div__ | |||
__TAG__ TAG factory |
|||
HTML There are four predefined document type definitions. |
|||
XHTML This is XHTML version of the HTML helper. |
|||
HEAD | |||
TITLE | |||
META | |||
LINK | |||
SCRIPT | |||
STYLE | |||
IMG | |||
SPAN | |||
BODY | |||
H1 | |||
H2 | |||
H3 | |||
H4 | |||
H5 | |||
H6 | |||
P Will replace ``\n`` by ``<br />`` if the `cr2br` attribute is provided. |
|||
STRONG | |||
B | |||
BR | |||
HR | |||
A Generates an A() link. |
|||
BUTTON | |||
EM | |||
EMBED | |||
TT | |||
PRE | |||
CENTER | |||
CODE Displays code in HTML with syntax highlighting. |
|||
LABEL | |||
LI | |||
UL UL Component. |
|||
OL | |||
TD | |||
TH | |||
TR TR Component. |
|||
__TRHEAD__ __TRHEAD__ Component, internal only |
|||
THEAD | |||
TBODY | |||
TFOOT | |||
COL | |||
COLGROUP | |||
TABLE TABLE Component. |
|||
I | |||
IFRAME | |||
INPUT INPUT Component |
|||
TEXTAREA Examples: |
|||
OPTION | |||
OBJECT | |||
OPTGROUP | |||
SELECT Examples: |
|||
FIELDSET | |||
LEGEND | |||
FORM Examples: |
|||
BEAUTIFY Turns any list, dictionary, etc into decent looking html. |
|||
MENU Used to build menus |
|||
web2pyHTMLParser obj = web2pyHTMLParser(text) parses and html/xml text into web2py helpers. |
|||
MARKMIN For documentation: http://web2py.com/examples/static/markmin.html |
|
|||
string |
|
||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|
|||
regex_crlf = re.compile(r'
|
|||
entitydefs =
|
|||
ON = True
|
|||
TAG = __TAG__()
|
|||
__package__ =
|
|
Return a string which is the concatenation of the strings in the iterable. The separator between elements is S.
|
Returns an escaped string of the provided data Args: data: the data to be escaped quote: optional (default False) |
generates a url '/a/c/f' corresponding to application a, controller c and function f. If r=request is passed, a, c, f are set, respectively, to r.application, r.controller, r.function. The more typical usage is: URL('index') that generates a url for the index function within the present application and controller. Args: a: application (default to current if r is given) c: controller (default to current if r is given) f: function (default to current if r is given) r: request (optional) args: any arguments (optional). Additional "path" elements vars: any variables (optional). Querystring elements anchor: anchorname, without # (optional) extension: force an extension hmac_key: key to use when generating hmac signature (optional) hash_vars: which of the vars to include in our hmac signature True (default) - hash all vars, False - hash none of the vars, iterable - hash only the included vars ['key1','key2'] salt: salt hashing with this string user_signature: signs automatically the URL in such way that only the user can access the URL (use with `URL.verify` or `auth.requires_signature()`) scheme: URI scheme (True, 'http' or 'https', etc); forces absolute URL (optional) host: string to force absolute URL with host (True means http_host) port: optional port number (forces absolute URL) encode_embedded_slash: encode slash characters included in args url_encode: encode characters included in vars Raises: SyntaxError: when no application, controller or function is available or when a CRLF is found in the generated url Examples: >>> str(URL(a='a', c='c', f='f', args=['x', 'y', 'z'], ... vars={'p':1, 'q':2}, anchor='1')) '/a/c/f/x/y/z?p=1&q=2#1' >>> str(URL(a='a', c='c', f='f', args=['x', 'y', 'z'], ... vars={'p':(1,3), 'q':2}, anchor='1')) '/a/c/f/x/y/z?p=1&p=3&q=2#1' >>> str(URL(a='a', c='c', f='f', args=['x', 'y', 'z'], ... vars={'p':(3,1), 'q':2}, anchor='1')) '/a/c/f/x/y/z?p=3&p=1&q=2#1' >>> str(URL(a='a', c='c', f='f', anchor='1+2')) '/a/c/f#1%2B2' >>> str(URL(a='a', c='c', f='f', args=['x', 'y', 'z'], ... vars={'p':(1,3), 'q':2}, anchor='1', hmac_key='key')) '/a/c/f/x/y/z?p=1&p=3&q=2&_signature=a32530f0d0caa80964bb92aad2bedf8a4486a31f#1' >>> str(URL(a='a', c='c', f='f', args=['w/x', 'y/z'])) '/a/c/f/w/x/y/z' >>> str(URL(a='a', c='c', f='f', args=['w/x', 'y/z'], encode_embedded_slash=True)) '/a/c/f/w%2Fx/y%2Fz' >>> str(URL(a='a', c='c', f='f', args=['%(id)d'], url_encode=False)) '/a/c/f/%(id)d' >>> str(URL(a='a', c='c', f='f', args=['%(id)d'], url_encode=True)) '/a/c/f/%25%28id%29d' >>> str(URL(a='a', c='c', f='f', vars={'id' : '%(id)d' }, url_encode=False)) '/a/c/f?id=%(id)d' >>> str(URL(a='a', c='c', f='f', vars={'id' : '%(id)d' }, url_encode=True)) '/a/c/f?id=%25%28id%29d' >>> str(URL(a='a', c='c', f='f', anchor='%(id)d', url_encode=False)) '/a/c/f#%(id)d' >>> str(URL(a='a', c='c', f='f', anchor='%(id)d', url_encode=True)) '/a/c/f#%25%28id%29d' |
Verifies that a request's args & vars have not been tampered with by the user :param request: web2py's request object :param hmac_key: the key to authenticate with, must be the same one previously used when calling URL() :param hash_vars: which vars to include in our hashing. (Optional) Only uses the 1st value currently True (or undefined) means all, False none, an iterable just the specified keys do not call directly. Use instead: URL.verify(hmac_key='...') the key has to match the one used to generate the URL. >>> r = Storage() >>> gv = Storage(p=(1,3),q=2,_signature='a32530f0d0caa80964bb92aad2bedf8a4486a31f') >>> r.update(dict(application='a', controller='c', function='f', extension='html')) >>> r['args'] = ['x', 'y', 'z'] >>> r['get_vars'] = gv >>> verifyURL(r, 'key') True >>> verifyURL(r, 'kay') False >>> r.get_vars.p = (3, 1) >>> verifyURL(r, 'key') True >>> r.get_vars.p = (3, 2) >>> verifyURL(r, 'key') False |
helper to encode the provided (binary) data into base64. Args: filename: if provided, opens and reads this file in 'rb' mode file: if provided, reads this file data: if provided, uses the provided data |
Example: >>> from validators import * >>> print DIV(A('click me', _href=URL(a='a', c='b', f='c')), BR(), HR(), DIV(SPAN("World"), _class='unknown')).xml() <div><a href="/a/b/c">click me</a><br /><hr /><div class="unknown"><span>World</span></div></div> >>> print DIV(UL("doc","cat","mouse")).xml() <div><ul><li>doc</li><li>cat</li><li>mouse</li></ul></div> >>> print DIV(UL("doc", LI("cat", _class='feline'), 18)).xml() <div><ul><li>doc</li><li class="feline">cat</li><li>18</li></ul></div> >>> print TABLE(['a', 'b', 'c'], TR('d', 'e', 'f'), TR(TD(1), TD(2), TD(3))).xml() <table><tr><td>a</td><td>b</td><td>c</td></tr><tr><td>d</td><td>e</td><td>f</td></tr><tr><td>1</td><td>2</td><td>3</td></tr></table> >>> form=FORM(INPUT(_type='text', _name='myvar', requires=IS_EXPR('int(value)<10'))) >>> print form.xml() <form action="#" enctype="multipart/form-data" method="post"><input name="myvar" type="text" /></form> >>> print form.accepts({'myvar':'34'}, formname=None) False >>> print form.xml() <form action="#" enctype="multipart/form-data" method="post"><input class="invalidinput" name="myvar" type="text" value="34" /><div class="error_wrapper"><div class="error" id="myvar__error">Invalid expression</div></div></form> >>> print form.accepts({'myvar':'4'}, formname=None, keepvalues=True) True >>> print form.xml() <form action="#" enctype="multipart/form-data" method="post"><input name="myvar" type="text" value="4" /></form> >>> form=FORM(SELECT('cat', 'dog', _name='myvar')) >>> print form.accepts({'myvar':'dog'}, formname=None, keepvalues=True) True >>> print form.xml() <form action="#" enctype="multipart/form-data" method="post"><select name="myvar"><option value="cat">cat</option><option selected="selected" value="dog">dog</option></select></form> >>> form=FORM(INPUT(_type='text', _name='myvar', requires=IS_MATCH('^\w+$', 'only alphanumeric!'))) >>> print form.accepts({'myvar':'as df'}, formname=None) False >>> print form.xml() <form action="#" enctype="multipart/form-data" method="post"><input class="invalidinput" name="myvar" type="text" value="as df" /><div class="error_wrapper"><div class="error" id="myvar__error">only alphanumeric!</div></div></form> >>> session={} >>> form=FORM(INPUT(value="Hello World", _name="var", requires=IS_MATCH('^\w+$'))) >>> isinstance(form.as_dict(), dict) True >>> form.as_dict(flat=True).has_key("vars") True >>> isinstance(form.as_json(), basestring) and len(form.as_json(sanitize=False)) > 0 True >>> if form.accepts({}, session,formname=None): print 'passed' >>> if form.accepts({'var':'test ', '_formkey': session['_formkey[None]']}, session, formname=None): print 'passed' |
|
entitydefs
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sun Mar 16 02:36:10 2014 | http://epydoc.sourceforge.net |