Package doapfiend :: Module utils
[hide private]
[frames] | no frames]

Module utils

source code

utils.py

Misc utilities for doapfiend

General purpose helper functions and classes for doapfiend You'll probably want to use doaplib for most cases.

License: BSD-2

Classes [hide private]
  NotFoundError
DOAP not found
Functions [hide private]
string
http_filesize(url)
Get the size of file without downloading it.
source code
boolean
http_exists(url)
A quick way to check if a file exists on the web.
source code
boolean
is_content_type(url_or_file, content_type)
Tells whether the URL or pseudofile from urllib.urlopen is of the required content type.
source code
string
fetch_file(url, proxy=None)
Download file by URL
source code
Variables [hide private]
  LOG = logging.getLogger("doapfiend")
  COLOR = {'black': '\x1b[30m', 'blink': '\x1b[5m', 'blue': '\x1...
Function Details [hide private]

http_filesize(url)

source code 

Get the size of file without downloading it. bla bla bla blaba

Parameters:
  • url (string) - URL of file
Returns: string
Size of file

Usage:

>>> http_filesize('http://trac.doapspace.org/test_file.txt')
'160'

http_exists(url)

source code 

A quick way to check if a file exists on the web.

Parameters:
  • url (string) - URL of the document
Returns: boolean
True or False

Usage:

>>> http_exists('http://www.python.org/')
True
>>> http_exists('http://www.python.org/PenguinOnTheTelly')
False

is_content_type(url_or_file, content_type)

source code 

Tells whether the URL or pseudofile from urllib.urlopen is of the required content type.

Parameters:
  • url_or_file (string) - URL or file path
  • content_type (string) - Content type we're looking for
Returns: boolean
True if it can return the Content type we want

Usage:

>>> is_content_type('http://doapspace.org/doap/sf/nlyrics.rdf',             'application/rdf+xml')
True
>>> is_content_type('http://doapspace.org/', 'application/rdf+xml')
False

fetch_file(url, proxy=None)

source code 

Download file by URL

Parameters:
  • url (string) - URL of a file
  • proxy (string) - URL of HTTP Proxy
Returns: string
File

Variables Details [hide private]

COLOR

Value:
{'black': '\x1b[30m',
 'blink': '\x1b[5m',
 'blue': '\x1b[34m',
 'bold': '\x1b[1m',
 'cyan': '\x1b[36m',
 'green': '\x1b[32m',
 'magenta': '\x1b[35m',
 'normal': '\x1b[0m',
...