Package svnmailer :: Module util
[show private | hide private]
[frames | no frames]

Module svnmailer.util

This module contains some utility functions and classes used in several places of the svnmailer. These functions have a quite general character and can be used easily outside of the svnmailer as well.


Classes
ReadOnlyDict Read only dictionary
SafeDict A dict, which returns '' on unknown keys or false values
Singleton Singleton base class
TempFile Tempfile container class
_LocaleFile Transform filenames according to locale
_Terminal Deal with terminal properties

Function Summary
tuple commonPaths(paths)
Returns the common component and the stripped paths
tuple or None extractX509User(author)
Returns user data extracted from x509 subject string
unicode filterForXml(value)
Replaces control characters with replace characters
any getGlobValue(globs, path)
Returns the value of the glob, where path matches
list getParentDirList(path)
Returns the directories up to a (posix) path
  inherit(cls, *bases)
Inherits class cls from *bases
any loadDotted(name)
Loads a dotted name
list splitCommand(command)
Split a command string with respect to quotes and such
basestring substitute(template, subst)
Returns a filled template
tuple parseContentType(value)
Parses a content type

Function Details

commonPaths(paths)

Returns the common component and the stripped paths

It expects that directories do always end with a trailing slash and paths never begin with a slash (except root).

Parameters:
paths - The list of paths ([str, str, ...])
           (type=list)
Returns:
The common component (always a directory) and the stripped paths ((str, [str, str, ...]))
           (type=tuple)

extractX509User(author)

Returns user data extracted from x509 subject string
Parameters:
author - The author string
           (type=basestring)
Returns:
user name, mail address (user name maybe None)
           (type=tuple or None)

filterForXml(value)

Replaces control characters with replace characters
Parameters:
value - The value to filter
           (type=unicode)
Returns:
The filtered value
           (type=unicode)

getGlobValue(globs, path)

Returns the value of the glob, where path matches
Parameters:
globs - The glob list ([(glob, associated value)])
           (type=sequence)
path - The path to match
           (type=str)
Returns:
The matched value or None
           (type=any)

getParentDirList(path)

Returns the directories up to a (posix) path
Parameters:
path - The path to process
           (type=str)
Returns:
The directory list
           (type=list)

inherit(cls, *bases)

Inherits class cls from *bases
Parameters:
cls - The class to inherit from bases
           (type=class)
bases - The base class(es)
           (type=tuple)

Note: cls needs a __dict__, so __slots__ is a nono

loadDotted(name)

Loads a dotted name

The dotted name can be anything, which is passively resolvable (i.e. without the invocation of a class to get their attributes or the like). For example, name could be 'svnmailer.util.loadDotted' and would return this very function. It's assumed that the first part of the name is always is a module.

If a dotted name was loaded successfully, the object will be cached and delivered from there the next time.

Parameters:
name - The dotted name to load
           (type=str)
Returns:
The loaded object
           (type=any)
Raises:
ImportError - A module in the path could not be loaded

splitCommand(command)

Split a command string with respect to quotes and such

The command string consists of several tokens:

  • whitespace: Those are separators except inside quoted items
  • unquoted items: every token that doesn't start with a double quote (")
  • quoted items: every token that starts with a double quote ("). Those items must be closed with a double quote and may contain whitespaces. The enclosing quotes are stripped. To put a double quote character inside such a token, it has to be escaped with a backslash (\). Therefore - backslashes themselves have to be escaped as well. The escapes are also stripped from the result.

Here's an example: r'foo bar "baz" "zo\"" "\\nk"' resolves to ['foo', 'bar', 'baz', 'zo"', r'\nk']

Parameters:
command - The command string
           (type=str)
Returns:
The splitted command
           (type=list)
Raises:
ValueError - The command string is not valid (unclosed quote or the like)

substitute(template, subst)

Returns a filled template

If the template is None, this function returns None as well.

Parameters:
template - The temlate to fill
           (type=basestring)
subst - The substitution parameters
           (type=dict)
Returns:
The filled template (The return type depends on the template and the parameters)
           (type=basestring)

parseContentType(value)

Parses a content type

(the email module unfortunately doesn't provide a public interface for this)

Parameters:
value - The value to parse - must be ascii compatible
           (type=basestring)
Returns:
The parsed header ((value, {key, [value, value, ...]})) or None
           (type=tuple)

Warning: comments are not recognized (yet?)


Generated by Epydoc 2.0 on Sun Sep 25 20:49:02 2005 http://epydoc.sf.net