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

Module amplee.utils

Utility functions.

Synopsis
--------

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

Function Summary
  compute_etag_from_entry(entry)
Returns a MD5 hash value of the atom:id+app:edited content value
  compute_etag_from_feed(feed)
Returns a MD5 hash value of the atom:id+atom:updated content value
  decode_slug(slug)
Decodes and returns the provided slug value as a byte string.
  encode_slug(text, encoding)
Returns a valid slug header as a byte string.
  extract_url_trail(url)
Returns the last part of an URL
  extract_uuid_from_urn(urn)
Returns the UUID value from a URN
  generate_uri(scheme, authority, trail)
Builds an URI as an unicode object
  generate_uuid(seed)
Returns a uuid value as specified in RFC 4122.
  generate_uuid_uri(seed)
Returns an URN from uuid
  get_isodate(dt)
Returns a date respecting the ISO 8601 format
  handle_if_match(etag, conditions)
Raises a ResourceOperationException error if the If-Match condition is not met
  parse_isodate(value)
Attempts to parse value as an ISO date and if succeeding returns a datetime object, ``None`` otherwise.
  parse_multiform_data(fileobj, headers)
Parses the content read from the ``fileobj`` as a multipart/form-data type.
  parse_query_string(querystring)
  safe_path_join(*args)
  safe_quote(text, encoding)
  safe_unquote(text, encoding)
  safe_url_join(tokens, encoding, start_at)
Joins the different tokens.
  strip_list(list_in)
Returns a list where empty elements are skipped

Function Details

compute_etag_from_entry(entry)

Returns a MD5 hash value of the atom:id+app:edited content value

compute_etag_from_feed(feed)

Returns a MD5 hash value of the atom:id+atom:updated content value

decode_slug(slug)

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')

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

extract_url_trail(url)

Returns the last part of an URL

extract_uuid_from_urn(urn)

Returns the UUID value from a URN

generate_uri(scheme, authority, trail)

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(seed=None)

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_uuid_uri(seed=None)

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)

Returns a date respecting the ISO 8601 format

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

handle_if_match(etag, conditions)

Raises a ResourceOperationException error if the If-Match condition is not met

parse_isodate(value)

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.

parse_multiform_data(fileobj, headers)

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.

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

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 ``start_at`` parameter specifies at which index of ``tokens`` the quoting of each token should start. This is handy when the first token is of the form http://host:port/.

The returned value is a unicode string

strip_list(list_in)

Returns a list where empty elements are skipped

Generated by Epydoc 2.1 on Thu Jul 19 15:32:16 2007 http://epydoc.sf.net