Package wtf :: Module webutil
[hide private]
[frames] | no frames]

Module webutil

source code

Certain utilities to make the life more easy.


Author: André Malo

Classes [hide private]
  URL
URL abstraction (RFC 1738)
  Query
Class for query string parsing and modification (stolen from svnmailer)
Functions [hide private]
basestring
escape_html(toescape, quotes=True)
Escape a string for HTML output
source code
str
escape_js(toescape)
Escape a string for JS output (to be inserted into a JS string)
source code
unicode
decode_simple(value)
Return unicode version of value
source code
str
quote(s, safe='/', encoding='utf-8', errors='strict', _orig=<function quote at 0x7fafe3082578>)
Replacement for urllib.quote, which also handles unicode.
source code
str
quote_plus(s, safe='/', encoding='utf-8', errors='strict', _orig=<function quote_plus at 0x7fafe30825f0>)
Replacement for urllib.quote_plus, which also handles unicode.
source code
Variables [hide private]
str PIXEL = 'GIF89a\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\xff\xf...
Transparent 1x1 pixel GIF.
  __package__ = 'wtf'
Function Details [hide private]

escape_html(toescape, quotes=True)

source code 
Escape a string for HTML output
Parameters:
  • toescape (basestring) - The string to escape
  • quotes (bool) - Escape quotes, too?
Returns: basestring
The escaped string

escape_js(toescape)

source code 

Escape a string for JS output (to be inserted into a JS string)

The output is always of type str.

Parameters:
  • toescape (basestring) - The string to escape
Returns: str
The escaped string

decode_simple(value)

source code 

Return unicode version of value

Simple heuristics: Try UTF-8 first, cp1252 then

Parameters:
  • value (str) - The value to decode
Returns: unicode
The decoded value

quote(s, safe='/', encoding='utf-8', errors='strict', _orig=<function quote at 0x7fafe3082578>)

source code 
Replacement for urllib.quote, which also handles unicode.
Parameters:
  • s (basestring) - The string to quote
  • safe (str) - safe characters (not quoted)
  • encoding (str) - Encoding to apply in case s is unicode
  • errors (str) - Error handling in case s is unicode
Returns: str
The quoted string
Raises:
  • UnicodeError - Encoding error

quote_plus(s, safe='/', encoding='utf-8', errors='strict', _orig=<function quote_plus at 0x7fafe30825f0>)

source code 
Replacement for urllib.quote_plus, which also handles unicode.
Parameters:
  • s (basestring) - The string to quote
  • safe (str) - safe characters (not quoted)
  • encoding (str) - Encoding to apply in case s is unicode
  • errors (str) - Error handling in case s is unicode
Returns: str
The quoted string
Raises:
  • UnicodeError - Encoding error

Variables Details [hide private]

PIXEL

Transparent 1x1 pixel GIF. Can be used for delivering webbugs etc. Usage: response.content_type('image/gif'); return [PIXEL]
Type:
str
Value:
'GIF89a\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\xff\xff\xff!\xf9\x04\x\
01\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x01D\x00;'