Package amplee :: Package utils
[hide private]
[frames] | no frames]

Package utils

source code

Utility functions.

Synopsis
--------

Just a list of utility functions that help you for common tasks.



Submodules [hide private]
  • amplee.utils.isodate: isodate.py Functions for manipulating a subset of ISO8601 date, as specified by <http://www.w3.org/TR/NOTE-datetime> Exposes: - parse(s) s being a conforming (regular or unicode) string.
  • amplee.utils.mediatype: Helper to find the best matching media-types.

Functions [hide private]
 
generate_uuid(seed=None)
Returns a uuid value as specified in RFC 4122.
source code
 
generate_uri(scheme, authority, trail)
Builds an URI as an unicode object
source code
 
generate_uuid_uri(seed=None)
Returns an URN from uuid
source code
 
extract_uuid_from_urn(urn)
Returns the UUID value from a URN
source code
 
compute_etag(seed)
Returns a MD5 hash value of seed
source code
 
compute_etag_from_entry(entry)
Returns a MD5 hash value of the atom:id+app:edited content value
source code
 
compute_etag_from_feed(feed)
Returns a MD5 hash value of the atom:id+atom:updated content value
source code
 
handle_if_match(etag, conditions)
Raises a ResourceOperationException error if the If-Match condition is not met
source code
 
get_isodate(dt=None)
Returns a date respecting the ISO 8601 format
source code
 
parse_isodate(value)
Attempts to parse value as an ISO date and if succeeding returns a datetime object, ``None`` otherwise.
source code
 
decode_slug(slug)
Decodes and returns the provided slug value as a byte string.
source code
 
encode_slug(text, encoding='utf-8')
Returns a valid slug header as a byte string.
source code
 
strip_list(list_in)
Returns a list where empty elements are skipped
source code
 
safe_quote(text, encoding='utf-8') source code
 
safe_unquote(text, encoding='utf-8') source code
 
safe_url_join(tokens=None, encoding='utf-8')
Joins the different tokens.
source code
 
safe_path_join(*args) source code
 
extract_url_trail(url)
Returns the last part of an URL
source code
 
extract_url_path_info(url)
Returns the full path info of a given URL
source code
 
translate_environ(environ)
Translate CGI-environ header names to their HTTP lower cased equivalent
source code
 
parse_multiform_data(fileobj, headers)
Parses the content read from the ``fileobj`` as a multipart/form-data type.
source code
 
parse_query_string(querystring) source code
 
qname(local_name, prefix=None)
Builds and returns a qualified name
source code
 
extract_media_type(entry) source code
 
reencode(value, encoding='utf-8')
Encodes value in the given encoding.
source code
Variables [hide private]
  __doc__ = """Utility functio...
  ATOM10_PREFIX = u'atom'
  ATOMPUB_PREFIX = u'app'
  THR_PREFIX = u'thr'
  ATOM10_NS = u'http://www.w3.org/2005/Atom'
  ATOMPUB_NS = u'http://www.w3.org/2007/app'
  THR_NS = u'http://purl.org/syndication/thread/1.0'
  XML_NS = u'http://www.w3.org/XML/1998/namespace'
  XML_PREFIX = u'xml'
  XMLNS_NS = u'http://www.w3.org/2000/xmlns/'
  XMLNS_PREFIX = u'xmlns'
  XHTML1_NS = u'http://www.w3.org/1999/xhtml'
  XHTML1_PREFIX = u'xhtml'
  ENCODING = 'utf-8'
Function Details [hide private]

generate_uuid(seed=None)

source code 

Returns a uuid value as specified in RFC 4122.

The ``seed``, if provided, allows this function to be idempotent. When not provided a random value is returned each time.

generate_uri(scheme, authority, trail)

source code 

Builds an URI as an unicode object

The ``scheme`` is URI scheme (e.g. http) The ``authority`` is the hostname The ``trail`` is the URI path

generate_uuid_uri(seed=None)

source code 

Returns an URN from uuid

The ``seed``, if provided, allows this function to be idempotent. When not provided a random value is returned each time.

get_isodate(dt=None)

source code 

Returns a date respecting the ISO 8601 format

If ``dt`` is not provided the current UTC time is used.

parse_isodate(value)

source code 

Attempts to parse value as an ISO date and if succeeding returns a datetime object, ``None`` otherwise.

The ``value`` is a date in a string format.

decode_slug(slug)

source code 

Decodes and returns the provided slug value as a byte string.

For example: 'The Beach at S%C3%A8te' will return 'The Beach at Sète'

The ``slug`` is a percent-encoded utf-8 Unicode string that does not contain CR or LF.

encode_slug(text, encoding='utf-8')

source code 

Returns a valid slug header as a byte string.

The ``text`` is a unicode string or a bytes string of the text to encode. The ``encoding`` is encoding used on the ``text`` object

safe_url_join(tokens=None, encoding='utf-8')

source code 

Joins the different tokens. The safety comes from the fact that if one token is a unicode string it will be first encoded.

``tokens`` is a list of values to join.

The returned value is a unicode string

parse_multiform_data(fileobj, headers)

source code 

Parses the content read from the ``fileobj`` as a multipart/form-data type.

Returns a dictionnary of the keys and values of the form.

Do not use this function on a different media-type.

Variables Details [hide private]

__doc__

Value:
"""Utility functions.

Synopsis
--------

Just a list of utility functions that help you for common tasks.

"""