These functions are not dependent on Flask. They implement common patterns in Flask-based applications.
Return a new random id that is exactly 22 characters long. See http://en.wikipedia.org/wiki/Base64#Variants_summary_table for URL-safe Base64
>>> len(newid())
22
>>> newid() == newid()
False
>>> isinstance(newid(), unicode)
True
Compare a reference password with the user attempt.
>>> check_password('{PLAIN}foo', 'foo')
True
>>> check_password(u'{PLAIN}bar', 'bar')
True
>>> check_password(u'{UNKNOWN}baz', 'baz')
False
>>> check_password(u'no-encoding', u'no-encoding')
False
>>> check_password(u'{SSHA}q/uVU8r15k/9QhRi92CWUwMJu2DM6TUSpp25', u're-foo')
True
>>> check_password('{SSHA}q/uVU8r15k/9QhRi92CWUwMJu2DM6TUSpp25', 're-foo')
True
Return a number suitably formatted for display as currency, with thousands separated by commas and up to two decimal points.
>>> format_currency(1000)
'1,000'
>>> format_currency(100)
'100'
>>> format_currency(999.95)
'999.95'
>>> format_currency(99.95)
'99.95'
>>> format_currency(100000)
'100,000'
>>> format_currency(1000.00)
'1,000'
>>> format_currency(1000.41)
'1,000.41'
>>> format_currency(23.21, decimals=3)
'23.210'
>>> format_currency(123456789.123456789)
'123,456,789.12'
Return the domain component of an email address. Returns None if the provided string cannot be parsed as an email address.
>>> get_email_domain('jace@pobox.com')
'pobox.com'
>>> get_email_domain('jace+test@pobox.com')
'pobox.com'
>>> get_email_domain('foobar')
Returns a boolean from any of a range of values. Returns None for unrecognized values. Numbers other than 0 and 1 are considered unrecognized.
>>> getbool(True)
True
>>> getbool(1)
True
>>> getbool('1')
True
>>> getbool('t')
True
>>> getbool(2)
>>> getbool(0)
False
>>> getbool(False)
False
>>> getbool('n')
False
Generate a Unicode name slug. If a checkused filter is provided, it will be called with the candidate. If it returns True, make_name will add counter numbers starting from 1 until a suitable candidate is found.
>>> make_name('This is a title')
u'this-is-a-title'
>>> make_name('Invalid URL/slug here')
u'invalid-url-slug-here'
>>> make_name('this.that')
u'this-that'
>>> make_name('this:that')
u'this-that'
>>> make_name("How 'bout this?")
u'how-bout-this'
>>> make_name(u"How’s that?")
u'hows-that'
>>> make_name(u'K & D')
u'k-d'
>>> make_name('billion+ pageviews')
u'billion-pageviews'
>>> make_name(u'हिन्दी slug!') == u'हिन्दी-slug'
True
>>> make_name(u'__name__', delim=u'_')
u'name'
>>> make_name(u'how_about_this', delim=u'_')
u'how_about_this'
>>> make_name(u'and-that', delim=u'_')
u'and_that'
>>> make_name('Candidate', checkused=lambda c: c in ['candidate', 'candidate1'])
u'candidate2'
>>> make_name('Long title, but snipped', maxlength=20)
u'long-title-but-snipp'
>>> len(make_name('Long title, but snipped', maxlength=20))
20
>>> make_name('Long candidate', maxlength=10, checkused=lambda c: c in ['long-candi', 'long-cand1'])
u'long-cand2'
Make a password with PLAIN or SSHA encoding.
>>> make_password('foo', encoding='PLAIN')
u'{PLAIN}foo'
>>> make_password(u'bar', encoding='PLAIN')
u'{PLAIN}bar'
>>> make_password(u're-foo')[:6]
u'{SSHA}'
>>> make_password('bar-foo')[:6]
u'{SSHA}'
>>> make_password('foo') == make_password('foo')
False
>>> check_password(make_password('ascii'), 'ascii')
True
>>> check_password(make_password('mixed'), u'mixed')
True
>>> check_password(make_password(u'unicode'), u'unicode')
True
Return md5sum of data as a 32-character string.
>>> md5sum('random text')
'd9b9bec3f4cc5482e7c5ef43143e563a'
>>> md5sum(u'random text')
'd9b9bec3f4cc5482e7c5ef43143e563a'
>>> len(md5sum('random text'))
32
Return a new random id that is exactly 22 characters long. See http://en.wikipedia.org/wiki/Base64#Variants_summary_table for URL-safe Base64
>>> len(newid())
22
>>> newid() == newid()
False
>>> isinstance(newid(), unicode)
True
Return a random numeric string with the specified number of digits, default 4.
>>> len(newpin())
4
>>> len(newpin(5))
5
>>> isinstance(int(newpin()), int)
True
Make a secret key for email confirmation and all that stuff.
>>> len(newsecret())
44
>>> newsecret() == newsecret()
False
Strips unwanted markup out of HTML.
Deprecated since version 0.2.5: Use the bleach library instead.
Simplify text to allow comparison.
>>> simplify_text("Awesome Coder wanted at Awesome Company")
'awesome coder wanted at awesome company'
>>> simplify_text("Awesome Coder, wanted at Awesome Company! ")
'awesome coder wanted at awesome company'
>>> simplify_text(u"Awesome Coder, wanted at Awesome Company! ")
u'awesome coder wanted at awesome company'