Package spammcan :: Module util
[hide private]

Module util

source code

Miscellaneous utility functions.

Functions [hide private]
 
absolute_url(tgpath='/', params=None, **kw)
Returns absolute URL (including schema and host to this server).
source code
 
add_global_tmpl_vars(vars)
Add custom global template variables.
source code
 
code2html(code, format, style=None, cssclass='source', hl_lines=None, linenos=False)
Syntax highlight given code with Pygments and format as HTML.
source code
 
get_user_id()
Return id of current visitor.
source code
 
get_server_name()
Return name of the server this application runs on.
source code
 
get_static_content(name)
Read text file from static directory and convert it to HTML.
source code
 
message_of_the_day(filename='tipoftheday.txt')
Return random message of the day from a text file with one msg per line.
source code
 
txt2html(text, use_docutils=True)
Try to convert text into HTML with docutils.
source code
 
_wrap_line(s, width=100)
Wrap single paragraph of text with custom options.
source code
 
wrap_text(s, width=100)
Wrap each paragraph in s with wrap().
source code
Variables [hide private]
  log = logging.getLogger('spammcan.controllers')
  _static_dir = None
Function Details [hide private]

absolute_url(tgpath='/', params=None, **kw)

source code 

Returns absolute URL (including schema and host to this server).

Tries to account for 'Host' header and reverse proxing ('X-Forwarded-Host').

add_global_tmpl_vars(vars)

source code 

Add custom global template variables.

Adds the following variables:

``tg.motd`` - The message of the day as a plain string

get_user_id()

source code 

Return id of current visitor.

This will be a string with 32-char MD5 hash, which will be retrieved either from a request cookie or default to the visit_key of the current identity.

As a side affect this function sets a response cookie for the user ID called 'spammcan_uid' with an expiry time set by the 'spammcan.uid_cookie_expiry' config setting (defaults to 90 days).

get_server_name()

source code 

Return name of the server this application runs on.

Tries to account for 'Host' header and reverse proxing.

txt2html(text, use_docutils=True)

source code 

Try to convert text into HTML with docutils.

If conversion fails or using docutils is turned off by the configuration, return text wrapped in a PRE element with CSS class "plaintext".

wrap_text(s, width=100)

source code 

Wrap each paragraph in s with wrap().

Returns 2-item tuple with a list of line nummers of continuation lines, and the wrapped text.