Package web :: Package web :: Module net
[hide private]
[frames] | no frames]

Module net

source code

Network Utilities (from web.py)

Functions [hide private]
 
validipaddr(address)
Returns True if `address` is a valid IPv4 address.
source code
 
validipport(port)
Returns True if `port` is a valid IPv4 port.
source code
 
validip(ip, defaultaddr='0.0.0.0', defaultport=8080)
Returns `(ip_address, port)` from string `ip_addr_port`
source code
 
validaddr(string_)
Returns either (ip_address, port) or "/path/to/socket" from string_
source code
 
urlquote(val)
Quotes a string for use in a URL.
source code
 
httpdate(date_obj)
Formats a datetime object for use in HTTP headers.
source code
 
parsehttpdate(string_)
Parses an HTTP date into a datetime object.
source code
 
htmlquote(text)
Encodes `text` for raw use in HTML.
source code
 
htmlunquote(text)
Decodes `text` that's HTML quoted.
source code
 
websafe(val)
Converts `val` so that it's safe for use in UTF-8 HTML.
source code
Variables [hide private]
  __package__ = 'web.web'
Function Details [hide private]

validipaddr(address)

source code 

Returns True if `address` is a valid IPv4 address.

>>> validipaddr('192.168.1.1')
True
>>> validipaddr('192.168.1.800')
False
>>> validipaddr('192.168.1')
False

validipport(port)

source code 

Returns True if `port` is a valid IPv4 port.

>>> validipport('9000')
True
>>> validipport('foo')
False
>>> validipport('1000000')
False

validaddr(string_)

source code 

Returns either (ip_address, port) or "/path/to/socket" from string_

>>> validaddr('/path/to/socket')
'/path/to/socket'
>>> validaddr('8000')
('0.0.0.0', 8000)
>>> validaddr('127.0.0.1')
('127.0.0.1', 8080)
>>> validaddr('127.0.0.1:8000')
('127.0.0.1', 8000)
>>> validaddr('fff')
Traceback (most recent call last):
    ...
ValueError: fff is not a valid IP address/port

urlquote(val)

source code 

Quotes a string for use in a URL.

>>> urlquote('://?f=1&j=1')
'%3A//%3Ff%3D1%26j%3D1'
>>> urlquote(None)
''
>>> urlquote(u'\u203d')
'%E2%80%BD'

httpdate(date_obj)

source code 

Formats a datetime object for use in HTTP headers.

>>> import datetime
>>> httpdate(datetime.datetime(1970, 1, 1, 1, 1, 1))
'Thu, 01 Jan 1970 01:01:01 GMT'

parsehttpdate(string_)

source code 

Parses an HTTP date into a datetime object.

>>> parsehttpdate('Thu, 01 Jan 1970 01:01:01 GMT')
datetime.datetime(1970, 1, 1, 1, 1, 1)

htmlquote(text)

source code 

Encodes `text` for raw use in HTML.

>>> htmlquote("<'&\">")
'&lt;&#39;&amp;&quot;&gt;'

htmlunquote(text)

source code 

Decodes `text` that's HTML quoted.

>>> htmlunquote('&lt;&#39;&amp;&quot;&gt;')
'<\'&">'

websafe(val)

source code 

Converts `val` so that it's safe for use in UTF-8 HTML.

>>> websafe("<'&\">")
'&lt;&#39;&amp;&quot;&gt;'
>>> websafe(None)
''
>>> websafe(u'\u203d')
'\xe2\x80\xbd'