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

Module svnmailer.util

Utilities

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
TempFile Tempfile container class

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
popen2.Popen4 or _DummyPopen4 getPipe4(command)
Returns a pipe object (Popen4 or _DummyPopen4 on win32)
str or list getSuitableCommandLine(command, _platform)
Return the revised command suitable for being exec'd
  inherit(cls, *bases)
Inherits class cls from *bases
  modifyQuery(query, rem, add, set, delim)
Returns a modified query string
dict parseQuery(query)
Parses a query string
list splitCommand(command)
Split a command string with respect to quotes and such
str or unicode substitute(template, subst)
Returns a filled template

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=str)
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=list of tuple)
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)

getPipe4(command)

Returns a pipe object (Popen4 or _DummyPopen4 on win32)
Parameters:
command - The command list (the first item is the command itself, the rest represents the arguments)
           (type=list)
Returns:
The pipe object
           (type=popen2.Popen4 or _DummyPopen4)

getSuitableCommandLine(command, _platform=None)

Return the revised command suitable for being exec'd

Currently this means, it's escaped and converted to a string only for Win32, because on this system the shell is called. For other systems the list is just returned.
Parameters:
command - The command to escape
           (type=list)
_platform - A platform string (for testing purposes only)
           (type=str)
Returns:
The escaped command string or the original list
           (type=str or list)

Note:

This is more or less the same as the stuff in svn.fs._escape_msvcrt_shell_command/arg. But it belongs somewhere else - e.g. into a util module...

Perhaps once a day the whole package goes directly into the subversion distribution and then it's all cool.

inherit(cls, *bases)

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

Note: cls needs a __dict__, so __slots__ is tabu

modifyQuery(query, rem=None, add=None, set=None, delim='&')

Returns a modified query string
Parameters:
query - The query string to modify
           (type=str or dict)
rem - parameters to remove (if present)
           (type=list of str)
add - parameters to add
           (type=list of tuple)
set - parameters to override
           (type=list of tuple)
delim - Delimiter to use when rebuilding the query string
           (type=str)

Warning: query parameters containing no = character are silently dropped.

Note: set is a convenience parameter, it's actually a combination of rem and add. The order of processing is:

  1. append the set parameters to rem and add
  2. apply rem
  3. apply add

parseQuery(query)

Parses a query string
Parameters:
query - The query string to parse
           (type=str)
Returns:
The parsed query ({key: [values]})
           (type=dict)

Warning: query parameters containing no = character are silently dropped.

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=unicode)
subst - The substitution parameters
           (type=dict)
Returns:
The filled template (The return type depends on the template and the parameters)
           (type=str or unicode)

Generated by Epydoc 2.1 on Mon Apr 17 12:39:11 2006 http://epydoc.sf.net