Package brisa :: Package core :: Module network
[hide private]
[frames] | no frames]

Module network

source code

Network related functions, such as get_ip_address(), http_call(), parse_url() and others.

Functions [hide private]
string
get_ip_address(ifname)
Determine the IP address given the interface name
source code
list
get_active_ifaces()
Return a list of the active network interfaces
source code
 
http_call(method, url, body='', headers={})
Returns a HTTPResponse object for the given call.
source code
 
url_fetch(url, filename='', attempts=0, interval=0)
Fetches an URL into a file or returns a file descriptor.
source code
 
decode(text)
Converts an arbitrary string to byte string in UTF-8.
source code
ElementTree
parse_xml(data)
Parses XML data into an ElementTree.
source code
tuple
parse_http_response(data)
Parses HTTP response data into a tuple in the form (cmd, headers).
source code
tuple
parse_url(url)
Parse a URL into 6 components.
source code
Function Details [hide private]

get_ip_address(ifname)

source code 

Determine the IP address given the interface name

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/439094 (c) Paul Cannon Uses the Linux SIOCGIFADDR ioctl to find the IP address associated with a network interface, given the name of that interface, e.g. "eth0". The address is returned as a string containing a dotted quad.

Parameters:
  • ifname (string) - interface name
Returns: string
ip address in the interface specified

get_active_ifaces()

source code 

Return a list of the active network interfaces

Default route of /proc/net/route has the destination field set to 00000000

Returns: list
active network interfaces

http_call(method, url, body='', headers={})

source code 

Returns a HTTPResponse object for the given call.

Parameters:
  • method (string) - HTTP method (NOTIFY, POST, etc...)
  • url (string) - receiver URL
  • body (string) - body of the message
  • headers (dictionary) - additional headers

url_fetch(url, filename='', attempts=0, interval=0)

source code 

Fetches an URL into a file or returns a file descriptor. If attempts and interval are not specified, they get their values from brisa.url_fetch_attempts and brisa.url_fetch_attempts_interval.

Parameters:
  • url (string) - URL to be fetched
  • filename (string) - if specified fetch result gets written on this path
  • attempts (integer) - number of attempts
  • interval (float) - interval between attempts in seconds

decode(text)

source code 

Converts an arbitrary string to byte string in UTF-8. On failure returns the given string.

Parameters:
  • text (string) - string to be converted

parse_xml(data)

source code 

Parses XML data into an ElementTree.

Parameters:
  • data (string) - raw XML data
Returns: ElementTree

parse_http_response(data)

source code 

Parses HTTP response data into a tuple in the form (cmd, headers).

Parameters:
  • data (string) - HTTP response data
Returns: tuple
(cmd, headers) for the given data

parse_url(url)

source code 

Parse a URL into 6 components.

Parameters:
  • url (string) - scheme://netloc/path;params?query#fragment
Returns: tuple
a 6-tuple: (scheme, netloc, path, params, query, fragment). Note that we don't break the components up in smaller bits (e.g. netloc is a single string) and we don't expand % escapes.